235 |
(* end case *) |
(* end case *) |
236 |
end |
end |
237 |
|
|
238 |
|
(* is a CONS inline? *) |
239 |
|
fun isInlineCons ty = (case ty |
240 |
|
of Ty.SeqTy(Ty.IntTy, _) => true |
241 |
|
| Ty.TensorTy dd => Target.inlineCons(List.length dd) |
242 |
|
| Ty.SeqTy _ => false |
243 |
|
| Ty.DynSeqTy ty => false |
244 |
|
| _ => raise Fail(concat["invalid CONS<", Ty.toString ty, ">"]) |
245 |
|
(* end case *)) |
246 |
|
|
247 |
(* translate input-variable initialization to a TreeIL expression *) |
(* translate input-variable initialization to a TreeIL expression *) |
248 |
fun trInitialization (InP.String s) = ([], T.E_Lit(Literal.String s)) |
fun trInitialization (InP.String s) = ([], T.E_Lit(Literal.String s)) |
249 |
| trInitialization (InP.Int n) = ([], T.E_Lit(Literal.Int n)) |
| trInitialization (InP.Int n) = ([], T.E_Lit(Literal.Int n)) |
250 |
| trInitialization (InP.Real f) = ([], T.E_Lit(Literal.Float f)) |
| trInitialization (InP.Real f) = ([], T.E_Lit(Literal.Float f)) |
251 |
| trInitialization (InP.Bool b) = ([], T.E_Lit(Literal.Bool b)) |
| trInitialization (InP.Bool b) = ([], T.E_Lit(Literal.Bool b)) |
252 |
| trInitialization (InP.Tensor(shp, vs)) = raise Fail "trInitialization: Tensor" |
| trInitialization (InP.Tensor(shp, vs)) = let |
253 |
|
fun mk i = T.E_Lit(Literal.Float(Vector.sub(vs, i))) |
254 |
|
fun mkCons (i, [d]) = |
255 |
|
(T.E_Cons(Ty.TensorTy[d], List.tabulate(d, fn j => mk(i+j))), i+d) |
256 |
|
| mkCons (i, d::dd) = let |
257 |
|
fun f (i, j, args) = if (j < d) |
258 |
|
then let |
259 |
|
val (arg, i) = mkCons(i, dd) |
260 |
|
in |
261 |
|
f (i, j+1, arg::args) |
262 |
|
end |
263 |
|
else (List.rev args, i) |
264 |
|
val (args, i) = f (i, 0, []) |
265 |
|
val cons = T.E_Cons(Ty.TensorTy(d::dd), args) |
266 |
|
in |
267 |
|
if Target.inlineCons(List.length dd + 1) |
268 |
|
then (cons, i) |
269 |
|
else raise Fail "non-inline initialization not supported yet" |
270 |
|
end |
271 |
|
val (exp, _) = mkCons(0, shp) |
272 |
|
in |
273 |
|
([], exp) |
274 |
|
end |
275 |
| trInitialization (InP.Seq vs) = raise Fail "trInitialization: Seq" |
| trInitialization (InP.Seq vs) = raise Fail "trInitialization: Seq" |
276 |
| trInitialization _ = raise Fail "trInitialization: impossible" |
| trInitialization _ = raise Fail "trInitialization: impossible" |
277 |
|
|
346 |
| IL.APPLY(f, args) => |
| IL.APPLY(f, args) => |
347 |
bind (env, lhs, T.E_Apply(f, List.map (useVar env) args)) |
bind (env, lhs, T.E_Apply(f, List.map (useVar env) args)) |
348 |
| IL.CONS(ty, args) => let |
| IL.CONS(ty, args) => let |
|
val inline = (case ty |
|
|
of Ty.SeqTy(Ty.IntTy, _) => true |
|
|
| Ty.TensorTy dd => Target.inlineCons(List.length dd) |
|
|
| Ty.SeqTy _ => false |
|
|
| Ty.DynSeqTy ty => false |
|
|
| _ => raise Fail(concat["invalid CONS<", Ty.toString ty, ">"]) |
|
|
(* end case *)) |
|
349 |
val exp = T.E_Cons(ty, List.map (useVar env) args) |
val exp = T.E_Cons(ty, List.map (useVar env) args) |
350 |
in |
in |
351 |
if inline |
if isInlineCons ty |
352 |
then bind (env, lhs, exp) |
then bind (env, lhs, exp) |
353 |
else assignExp (env, exp) |
else assignExp (env, exp) |
354 |
end |
end |
562 |
walk (IL.CFG.entry globalInit, Nd.dummy, []) |
walk (IL.CFG.entry globalInit, Nd.dummy, []) |
563 |
end |
end |
564 |
|
|
|
(* |
|
|
(* translate an input initialization *) |
|
|
fun trInitialization init = let |
|
|
in |
|
|
case init |
|
|
of Inputs.String s => ([], CL.mkStr s) |
|
|
| Inputs.Bool b => ([], CL.mkBool b) |
|
|
| Inputs.Int n => ([], CL.mkIntTy(n, !N.gIntTy)) |
|
|
| Inputs.Real f => ([], CL.mkFlt(f, !N.gRealTy)) |
|
|
| Inputs.Tensor([d], vs) => let |
|
|
val ty = !gRealTy |
|
|
fun mk i = fn i => CL.mkFlt(Vector.sub(vs, i), ty) |
|
|
in |
|
|
case shp |
|
|
of [d] => ([], CL.mkApply(N.mkVec d, List.tabulate(d, mk))) |
|
|
| _ => raise Fail "FIXME" |
|
|
(* end case *) |
|
|
end |
|
|
| Inputs.Seq vs => |
|
|
| Inputs.DynSeq nrrd => |
|
|
| Inputs.Proxy(nrrd, info) => |
|
|
| Inputs. |
|
|
(* end case *) |
|
|
end |
|
|
*) |
|
|
|
|
565 |
fun translate prog = let |
fun translate prog = let |
566 |
(* first we do a variable analysis pass on the Low IL *) |
(* first we do a variable analysis pass on the Low IL *) |
567 |
val prog as IL.Program{props, globalInit, initially, strands} = VA.optimize prog |
val prog as IL.Program{props, globalInit, initially, strands} = VA.optimize prog |