Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/vis15/src/compiler/options/cmd-line-constants.sml
ViewVC logotype

View of /branches/vis15/src/compiler/options/cmd-line-constants.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3405 - (download) (annotate)
Wed Nov 11 14:46:13 2015 UTC (4 years, 1 month ago) by jhr
File size: 1769 byte(s)
working on merge
(* cmd-line-constants.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 *
 * Support for processing constant-variable defintions from the command line.
 *)

structure CmdLineConstants : sig

  (* returns true if the argument has the form of a command-line constant specification *)
    val isCmdLineConst : string -> bool

  (* initialize the table from the command-line arguments; returns false if there was
   * an error processing an argument.
   *)
    val initFromArgs : string list -> bool

  (* `getConst name` gets the value of the named input if it was defined on the
   * command line.
   *)
    val getConst : Atom.atom -> string option

  end = struct

    structure Tbl = AtomTable

    val inputs : string AtomTable.hash_table = AtomTable.mkTable(32, Fail "input table")

    fun notEq #"=" = false | notEq _ = true

    fun isCmdLineConst s = (case String.fields (fn #"=" => true | _ => false) s
	   of [s1, s2] => (size s1 > 2) andalso String.isPrefix "-D" s1 andalso (size s2 > 0)
	    | _ => false
	  (* end case *))

    fun initFromArgs args = let
	  fun doArg arg = let
		val arg = Substring.full arg
		in
		  if Substring.isPrefix "-D" arg
		    then let
		      val arg = Substring.triml 2 arg
		      val (name, rest) = Substring.splitl notEq arg
		      in
			if (Substring.size name > 0) andalso (Substring.size rest > 1)
			  then (
			    AtomTable.insert inputs
			      (Atom.atom' name, Substring.string(Substring.triml 1 rest));
			    true)
			  else false
		      end
		    else true
		end
	  in
	    AtomTable.clear inputs;
	    List.all doArg args
	  end

    fun getConst name = AtomTable.find inputs name

  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0