141 |
|
|
142 |
fun block (outS, blk) = (ppBlock ((outS, 0), blk); pr ((outS, 0), "\n")) |
fun block (outS, blk) = (ppBlock ((outS, 0), blk); pr ((outS, 0), "\n")) |
143 |
|
|
144 |
|
fun ppInitially (out, {isArray, iterPrefix, iters, createPrefix, strand, args}) = let |
145 |
|
fun ppBlock (out, IL.Block{locals, body}, inside) = let |
146 |
|
val out' = incIndent out |
147 |
|
in |
148 |
|
pr (out, "{\n"); |
149 |
|
List.app (ppVarDecl out') locals; |
150 |
|
List.app (fn stm => ppStm(out', stm)) body; |
151 |
|
inside out'; |
152 |
|
indent out; pr (out, "}") |
153 |
|
end |
154 |
|
fun ppCreate out = let |
155 |
|
fun ppNew out = prln(out, [argsToString("new "^Atom.toString strand, args), ";\n"]) |
156 |
|
in |
157 |
|
indent out; ppBlock (out, createPrefix, ppNew); pr(out, "\n") |
158 |
|
end |
159 |
|
fun ppIters out = let |
160 |
|
fun ppIter (out, []) = ppCreate out |
161 |
|
| ppIter (out, (i, lo, hi)::iters) = ( |
162 |
|
prln(out, ["for ", Var.name i, " = ", expToString lo, " .. ", expToString hi, "\n"]); |
163 |
|
ppIter (incIndent out, iters)) |
164 |
|
in |
165 |
|
ppIter (out, iters) |
166 |
|
end |
167 |
|
in |
168 |
|
indent out; pr(out, if isArray then "ARRAY " else "COLLECTION "); |
169 |
|
ppBlock (out, iterPrefix, ppIters) |
170 |
|
end |
171 |
|
|
172 |
fun program (outS, IL.Program{props, globals, globalInit, strands, initially}) = let |
fun program (outS, IL.Program{props, globals, globalInit, strands, initially}) = let |
173 |
val out = (outS, 0) |
val out = (outS, 0) |
174 |
val out' = incIndent out |
val out' = incIndent out |
184 |
indent out'; ppBlock (out', globalInit); pr (out, "\n"); |
indent out'; ppBlock (out', globalInit); pr (out, "\n"); |
185 |
prln(out, ["//***** STRANDS *****\n"]); |
prln(out, ["//***** STRANDS *****\n"]); |
186 |
List.app (ppStrand out) strands; |
List.app (ppStrand out) strands; |
187 |
prln(out, ["//***** INITIALLY *****\n"]) |
prln(out, ["//***** INITIALLY *****\n"]); |
188 |
(* FIXME: print initially stuff *) |
ppInitially (out', initially) |
189 |
end |
end |
190 |
|
|
191 |
end |
end |