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 2475, Sat Oct 12 17:45:57 2013 UTC revision 2476, Mon Oct 14 09:36:13 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 * Var.var        | ImgV of ImageInfo.info * SimpleVar.var
23    
24      val evalStatics : Var.Set.set * Simple.block -> value Var.Map.map      val evalStatics : SimpleVar.Set.set * Simple.block -> value SimpleVar.Map.map
25    
26    end = struct    end = struct
27    
28      structure Ty = Types      structure Ty = SimpleTypes
29      structure BV = BasisVars      structure BV = BasisVars
30      structure S = Simple      structure S = Simple
31      structure VMap = Var.Map      structure VMap = SimpleVar.Map
32      structure VSet = Var.Set      structure VSet = SimpleVar.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 * Var.var        | ImgV of ImageInfo.info * Simple.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 dim, Ty.SHAPE shp], SV filename) = let      fun loadImage ([Ty.DIM d, Ty.SHAPE dd], SV filename) = let
           val Ty.DimConst d = TypeUtil.resolveDim dim  
           val dd = let  
                 val Ty.Shape dd = TypeUtil.resolveShape shp  
                 fun doDim (Ty.DimConst d) = d  
                   | doDim (Ty.DimVar d) = let val Ty.DimConst d = TypeUtil.resolveDim d in d end  
                 in  
                   List.map doDim dd  
                 end  
134            val info as ImageInfo.ImgInfo{dim, ty=(rng, _), ...} = ImageInfo.getInfo filename            val info as ImageInfo.ImgInfo{dim, ty=(rng, _), ...} = ImageInfo.getInfo filename
135            fun rngToS [] = "real"            fun rngToS [] = "real"
136              | rngToS dd = concat["tensor[", String.concatWith "," (List.map Int.toString dd), "]"]              | rngToS dd = concat["tensor[", String.concatWith "," (List.map Int.toString dd), "]"]
# Line 156  Line 148 
148    
149      fun evalVar env x = (case VMap.find (env, x)      fun evalVar env x = (case VMap.find (env, x)
150             of SOME v => v             of SOME v => v
151              | NONE => raise Fail("undefined variable " ^ Var.uniqueNameOf x)              | NONE => raise Fail("undefined variable " ^ SimpleVar.uniqueNameOf x)
152            (* end case *))            (* end case *))
153    
154      (* apply Diderot builtin function *)
155      fun apply (env, f, mvs, xs) =      fun apply (env, f, mvs, xs) =
156            if List.all (fn x => VMap.inDomain(env, x)) xs            if List.all (fn x => VMap.inDomain(env, x)) xs
157              then (* try *)(              then (* try *)(
# Line 176  Line 169 
169                         | ex => (                         | ex => (
170                             TextIO.output (TextIO.stdErr, concat [                             TextIO.output (TextIO.stdErr, concat [
171                                 Var.uniqueNameOf f, "(",                                 Var.uniqueNameOf f, "(",
172                                 String.concatWith "," (List.map Var.uniqueNameOf xs),                                 String.concatWith "," (List.map SimpleVar.uniqueNameOf xs),
173                                 ") fails with exception ", exnName ex, "\n"                                 ") fails with exception ", exnName ex, "\n"
174                               ]);                               ]);
175                raise ex)                raise ex)
# Line 189  Line 182 
182              | S.E_Lit(Literal.String s) => SOME(SV s)              | S.E_Lit(Literal.String s) => SOME(SV s)
183              | S.E_Lit(Literal.Bool b) => SOME(BV b)              | S.E_Lit(Literal.Bool b) => SOME(BV b)
184              | S.E_Tuple _ => raise Fail "E_Tuple"              | S.E_Tuple _ => raise Fail "E_Tuple"
185              | S.E_Apply(f, mvs, xs, _) => apply(env, f, mvs, xs)              | S.E_Apply _ => NONE
186                | S.E_Prim(f, mvs, xs, _) => apply(env, f, mvs, xs)
187              | S.E_Cons xs => (case evalArgs(env, xs)              | S.E_Cons xs => (case evalArgs(env, xs)
188                   of NONE => NONE                   of NONE => NONE
189                    | SOME vs => SOME(TV vs)                    | SOME vs => SOME(TV vs)
# Line 223  Line 217 
217              eval (args, [])              eval (args, [])
218            end            end
219    
220      fun getInput (ty, name, optDefault) = (case ty      fun getInput (ty : Ty.ty, name, optDefault) = (case ty
221             of Ty.T_Bool =>             of Ty.T_Bool =>
222                  CmdLineInputs.getInput(name, (Option.map BV) o Bool.fromString, optDefault)                  CmdLineInputs.getInput(name, (Option.map BV) o Bool.fromString, optDefault)
223              | Ty.T_Int =>              | Ty.T_Int =>
224                  CmdLineInputs.getInput(name, (Option.map IV) o IntInf.fromString, optDefault)                  CmdLineInputs.getInput(name, (Option.map IV) o IntInf.fromString, optDefault)
225              | Ty.T_String => CmdLineInputs.getInput(name, fn s => SOME(SV s), optDefault)              | Ty.T_String => CmdLineInputs.getInput(name, fn s => SOME(SV s), optDefault)
226              | Ty.T_Tensor(Ty.Shape[]) =>              | Ty.T_Tensor[] =>
227                  CmdLineInputs.getInput(name, (Option.map RV) o Real.fromString, optDefault)                  CmdLineInputs.getInput(name, (Option.map RV) o Real.fromString, optDefault)
228              | Ty.T_Tensor(Ty.Shape[Ty.DimConst d]) => let              | Ty.T_Tensor[d] => let
229                  fun fromString s = let                  fun fromString s = let
230                      (* first split into fields by "," *)                      (* first split into fields by "," *)
231                        val flds = String.fields (fn #"," => true | _ => false) s                        val flds = String.fields (fn #"," => true | _ => false) s
# Line 250  Line 244 
244                  end                  end
245              | Ty.T_Tensor shp => raise Fail "TODO: general tensor inputs"              | Ty.T_Tensor shp => raise Fail "TODO: general tensor inputs"
246              | _ => raise Fail(concat[              | _ => raise Fail(concat[
247                    "input ", name, " has invalid type ", TypeUtil.toString ty                    "input ", name, " has invalid type ", Ty.toString ty
248                  ])                  ])
249            (* end case *))            (* end case *))
250    
# Line 273  Line 267 
267                                else env                                else env
268                          | S.S_Assign(x, e) => (case evalExp(env, e)                          | S.S_Assign(x, e) => (case evalExp(env, e)
269                               of SOME v =>                               of SOME v =>
270  (Log.msg(concat["eval assignment: ", Var.uniqueNameOf x, " = ", toString v, "\n"]);  (Log.msg(concat["eval assignment: ", SimpleVar.uniqueNameOf x, " = ", toString v, "\n"]);
271                                  VMap.insert(env, x, v)                                  VMap.insert(env, x, v)
272  )  )
273                                | NONE => env                                | NONE => env

Legend:
Removed from v.2475  
changed lines
  Added in v.2476

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