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

SCM Repository

[diderot] Diff of /trunk/src/compiler/simplify/eval.sml
ViewVC logotype

Diff of /trunk/src/compiler/simplify/eval.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2488, Mon Oct 21 19:20:12 2013 UTC revision 2489, Mon Oct 21 19:43:32 2013 UTC
# Line 19  Line 19 
19        | IV of IntInf.int        | IV of IntInf.int
20        | RV of real        | RV of real
21        | TV of value list        (* tensors: values will either be RV or TV *)        | TV of value list        (* tensors: values will either be RV or TV *)
22        | ImgV of ImageInfo.info * SimpleVar.var        | ImgV of ImageInfo.info * Var.var
23    
24      val evalStatics : SimpleVar.Set.set * Simple.block -> value SimpleVar.Map.map      val evalStatics : Var.Set.set * Simple.block -> value Var.Map.map
25    
26    end = struct    end = struct
27    
28      structure Ty = SimpleTypes      structure Ty = Types
29      structure BV = BasisVars      structure BV = BasisVars
30      structure S = Simple      structure S = Simple
31      structure VMap = SimpleVar.Map      structure VMap = Var.Map
32      structure VSet = SimpleVar.Set      structure VSet = Var.Set
33      structure VTbl = Var.Tbl      structure VTbl = Var.Tbl
34    
35      exception Error of string list      exception Error of string list
# Line 41  Line 41 
41  (* FIXME: we probably should use FloatLit.float values instead of reals! *)  (* FIXME: we probably should use FloatLit.float values instead of reals! *)
42        | RV of real        | RV of real
43        | TV of value list        (* tensors: values will either be RV or TV *)        | TV of value list        (* tensors: values will either be RV or TV *)
44        | ImgV of ImageInfo.info * Simple.var        | ImgV of ImageInfo.info * Var.var
45    
46      fun toString (BV b) = Bool.toString b      fun toString (BV b) = Bool.toString b
47        | toString (IV i) = IntInf.toString i        | toString (IV i) = IntInf.toString i
# Line 130  Line 130 
130              tbl              tbl
131            end            end
132    
133      fun loadImage ([Ty.DIM d, Ty.SHAPE dd], SV filename) = let      fun loadImage ([Ty.DIM dim, Ty.SHAPE shp], SV filename) = let
134              val Ty.DimConst d = TypeUtil.resolveDim dim
135              val dd = let
136                    val Ty.Shape dd = TypeUtil.resolveShape shp
137                    fun doDim (Ty.DimConst d) = d
138                      | doDim (Ty.DimVar d) = let val Ty.DimConst d = TypeUtil.resolveDim d in d end
139                    in
140                      List.map doDim dd
141                    end
142            val info as ImageInfo.ImgInfo{dim, ty=(rng, _), ...} = ImageInfo.getInfo filename            val info as ImageInfo.ImgInfo{dim, ty=(rng, _), ...} = ImageInfo.getInfo filename
143            fun rngToS [] = "real"            fun rngToS [] = "real"
144              | rngToS dd = concat["tensor[", String.concatWith "," (List.map Int.toString dd), "]"]              | rngToS dd = concat["tensor[", String.concatWith "," (List.map Int.toString dd), "]"]
# Line 148  Line 156 
156    
157      fun evalVar env x = (case VMap.find (env, x)      fun evalVar env x = (case VMap.find (env, x)
158             of SOME v => v             of SOME v => v
159              | NONE => raise Fail("undefined variable " ^ SimpleVar.uniqueNameOf x)              | NONE => raise Fail("undefined variable " ^ Var.uniqueNameOf x)
160            (* end case *))            (* end case *))
161    
   (* apply Diderot builtin function *)  
162      fun apply (env, f, mvs, xs) =      fun apply (env, f, mvs, xs) =
163            if List.all (fn x => VMap.inDomain(env, x)) xs            if List.all (fn x => VMap.inDomain(env, x)) xs
164              then (* try *)(              then (* try *)(
# Line 169  Line 176 
176                         | ex => (                         | ex => (
177                             TextIO.output (TextIO.stdErr, concat [                             TextIO.output (TextIO.stdErr, concat [
178                                 Var.uniqueNameOf f, "(",                                 Var.uniqueNameOf f, "(",
179                                 String.concatWith "," (List.map SimpleVar.uniqueNameOf xs),                                 String.concatWith "," (List.map Var.uniqueNameOf xs),
180                                 ") fails with exception ", exnName ex, "\n"                                 ") fails with exception ", exnName ex, "\n"
181                               ]);                               ]);
182                raise ex)                raise ex)
# Line 182  Line 189 
189              | S.E_Lit(Literal.String s) => SOME(SV s)              | S.E_Lit(Literal.String s) => SOME(SV s)
190              | S.E_Lit(Literal.Bool b) => SOME(BV b)              | S.E_Lit(Literal.Bool b) => SOME(BV b)
191              | S.E_Tuple _ => raise Fail "E_Tuple"              | S.E_Tuple _ => raise Fail "E_Tuple"
192              | S.E_Apply _ => NONE              | S.E_Apply(f, mvs, xs, _) => apply(env, f, mvs, xs)
             | S.E_Prim(f, mvs, xs, _) => apply(env, f, mvs, xs)  
193              | S.E_Cons xs => (case evalArgs(env, xs)              | S.E_Cons xs => (case evalArgs(env, xs)
194                   of NONE => NONE                   of NONE => NONE
195                    | SOME vs => SOME(TV vs)                    | SOME vs => SOME(TV vs)
# Line 217  Line 223 
223              eval (args, [])              eval (args, [])
224            end            end
225    
226      fun getInput (ty : Ty.ty, name, optDefault) = (case ty      fun getInput (ty, name, optDefault) = (case ty
227             of Ty.T_Bool =>             of Ty.T_Bool =>
228                  CmdLineInputs.getInput(name, (Option.map BV) o Bool.fromString, optDefault)                  Inputs.getInput(name, (Option.map BV) o Bool.fromString, optDefault)
229              | Ty.T_Int =>              | Ty.T_Int =>
230                  CmdLineInputs.getInput(name, (Option.map IV) o IntInf.fromString, optDefault)                  Inputs.getInput(name, (Option.map IV) o IntInf.fromString, optDefault)
231              | Ty.T_String => CmdLineInputs.getInput(name, fn s => SOME(SV s), optDefault)              | Ty.T_String => Inputs.getInput(name, fn s => SOME(SV s), optDefault)
232              | Ty.T_Tensor[] =>              | Ty.T_Tensor(Ty.Shape[]) =>
233                  CmdLineInputs.getInput(name, (Option.map RV) o Real.fromString, optDefault)                  Inputs.getInput(name, (Option.map RV) o Real.fromString, optDefault)
234              | Ty.T_Tensor[d] => let              | Ty.T_Tensor(Ty.Shape[Ty.DimConst d]) => let
235                  fun fromString s = let                  fun fromString s = let
236                      (* first split into fields by "," *)                      (* first split into fields by "," *)
237                        val flds = String.fields (fn #"," => true | _ => false) s                        val flds = String.fields (fn #"," => true | _ => false) s
# Line 240  Line 246 
246                        end                        end
247                        handle _ => NONE                        handle _ => NONE
248                  in                  in
249                    CmdLineInputs.getInput(name, fromString, optDefault)                    Inputs.getInput(name, fromString, optDefault)
250                  end                  end
251              | Ty.T_Tensor shp => raise Fail "TODO: general tensor inputs"              | Ty.T_Tensor shp => raise Fail "TODO: general tensor inputs"
252              | _ => raise Fail(concat[              | _ => raise Fail(concat[
253                    "input ", name, " has invalid type ", Ty.toString ty                    "input ", name, " has invalid type ", TypeUtil.toString ty
254                  ])                  ])
255            (* end case *))            (* end case *))
256    
# Line 267  Line 273 
273                                else env                                else env
274                          | S.S_Assign(x, e) => (case evalExp(env, e)                          | S.S_Assign(x, e) => (case evalExp(env, e)
275                               of SOME v =>                               of SOME v =>
276  (Log.msg(concat["eval assignment: ", SimpleVar.uniqueNameOf x, " = ", toString v, "\n"]);  (Log.msg(concat["eval assignment: ", Var.uniqueNameOf x, " = ", toString v, "\n"]);
277                                  VMap.insert(env, x, v)                                  VMap.insert(env, x, v)
278  )  )
279                                | NONE => env                                | NONE => env

Legend:
Removed from v.2488  
changed lines
  Added in v.2489

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