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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/inputs/inputs.sml
ViewVC logotype

View of /branches/vis15/src/compiler/inputs/inputs.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3504 - (download) (annotate)
Thu Dec 17 23:56:09 2015 UTC (4 years, 3 months ago) by jhr
File size: 3091 byte(s)
working on merge
(* inputs.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.
 *)

structure Inputs : sig

  (* input initialization *)
    datatype input_init
      = NoDefault			(* uninitialized input *)
      | ConstExpr			(* initialized to constant.  The actual initialization
					 * is handled in code.
					 *)
      | LoadSeq of string		(* load a sequence from a file *)
      | Proxy of string * ImageInfo.info (* input image specified by proxy *)
      | Image of ImageInfo.info		(* input image w/o proxy *)

    datatype 'var input = INP of {
        var : 'var,			(* the global input variable *)
        name : string,			(* the source-language input name *)
        desc : string option,		(* the optional description *)
        init : input_init		(* the default initialization (or NoDefault) *)
      }

    val same : 'a input * 'a input -> bool

    val hash : 'a input -> word

    val initToString : input_init -> string

    val toString : 'ty input -> string

    val imageInfo : 'ty input -> ImageInfo.info option

  (* type conversion *)
    val map : ('a -> 'b) -> 'a input -> 'b input

  end = struct

    datatype input_init
      = NoDefault			(* uninitialized input *)
      | ConstExpr			(* initialized to constant.  The actual initialization
					 * is handled in the constInit block.
					 *)
      | LoadSeq of string		(* load a sequence from a file *)
      | Proxy of string * ImageInfo.info (* input image specified by proxy *)
      | Image of ImageInfo.info		(* input image w/o proxy *)

    datatype 'var input = INP of {
        var : 'var,			(* the global input variable *)
        name : string,			(* the source-language input name *)
        desc : string option,		(* the optional description *)
        init : input_init		(* the default initialization (or NoDefault) *)
      }

    fun same (INP{name=n1, ...}, INP{name=n2, ...}) = (n1 = n2)

    fun hash (INP{name, ...}) = HashString.hashString name

    fun initToString NoDefault = "<no-default>"
      | initToString ConstExpr = "<default>"
      | initToString (LoadSeq name) = String.concat["load(\"", name, "\")"]
      | initToString (Proxy(name, _)) = String.concat["image(\"", name, "\")"]
      | initToString (Image info) = ImageInfo.toString info

    fun toString (INP{name, desc=NONE, init=NoDefault, ...}) = name
      | toString (INP{name, desc=SOME desc, init=NoDefault, ...}) =
          String.concat[name, "(\"", String.toString desc, "\")"]
      | toString (INP{name, desc=NONE, init, ...}) =
          String.concat[name, " = ", initToString init]
      | toString (INP{name, desc=SOME desc, init, ...}) =
          String.concat[name, "(\"", String.toString desc, "\") = ", initToString init]

    fun imageInfo (INP{init=Proxy(_, info), ...}) = SOME info
      | imageInfo (INP{init=Image info, ...}) = SOME info
      | imageInfo _ = NONE

  (* type conversion *)
    fun map f (INP{var, name, desc, init}) = INP{var = f var, name = name, desc = desc, init = init}

  end

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