80 |
|
|
81 |
and ppArgs (ppStrm, args) = ppList ppVar ("(", ",", ")") (ppStrm, args) |
and ppArgs (ppStrm, args) = ppList ppVar ("(", ",", ")") (ppStrm, args) |
82 |
|
|
83 |
fun ppBlock (ppStrm, vars, stms) = let |
fun ppBlock (ppStrm, vars, S.Block stms) = let |
84 |
fun sp () = PP.space ppStrm 1 |
fun sp () = PP.space ppStrm 1 |
85 |
fun nl () = PP.newline ppStrm |
fun nl () = PP.newline ppStrm |
86 |
val string = PP.string ppStrm |
val string = PP.string ppStrm |
87 |
fun var x = string(Var.uniqueNameOf x) |
fun var x = string(Var.uniqueNameOf x) |
88 |
fun ppStmt stmt = (case stmt |
fun ppStmt stmt = (case stmt |
89 |
of S.S_Block stms => ppBlock (ppStrm, [], stms) |
of S.S_Assign(x, e) => ( |
|
| S.S_Assign(x, e) => ( |
|
90 |
PP.openHBox ppStrm; |
PP.openHBox ppStrm; |
91 |
var x; sp(); string "="; sp(); ppExp(ppStrm, e); string ";"; |
var x; sp(); string "="; sp(); ppExp(ppStrm, e); string ";"; |
92 |
PP.closeBox ppStrm; |
PP.closeBox ppStrm; |
93 |
nl()) |
nl()) |
94 |
| S.S_IfThenElse(x, S.S_Block stms, S.S_Block[]) => ( |
| S.S_IfThenElse(x, S.Block[s1], S.Block[]) => ( |
|
PP.openHBox ppStrm; |
|
|
string "if"; sp(); ppVar(ppStrm, x); |
|
|
sp(); ppBlock (ppStrm, [], stms); |
|
|
PP.closeBox ppStrm) |
|
|
| S.S_IfThenElse(x, s1, S.S_Block[]) => ( |
|
95 |
PP.openVBox ppStrm indent; |
PP.openVBox ppStrm indent; |
96 |
PP.openHBox ppStrm; |
PP.openHBox ppStrm; |
97 |
string "if"; sp(); ppVar(ppStrm, x); |
string "if"; sp(); ppVar(ppStrm, x); |
100 |
ppStmt s1; |
ppStmt s1; |
101 |
PP.closeBox ppStrm; |
PP.closeBox ppStrm; |
102 |
nl()) |
nl()) |
103 |
| S.S_IfThenElse(x, S.S_Block stms1, S.S_Block stms2) => ( |
| S.S_IfThenElse(x, blk, S.Block[]) => ( |
104 |
PP.openHBox ppStrm; |
PP.openHBox ppStrm; |
105 |
string "if"; sp(); ppVar(ppStrm, x); |
string "if"; sp(); ppVar(ppStrm, x); |
106 |
sp(); ppBlock (ppStrm, [], stms1); |
sp(); ppBlock (ppStrm, [], blk); |
|
PP.closeBox ppStrm; |
|
|
PP.openHBox ppStrm; |
|
|
string "else"; sp(); ppBlock (ppStrm, [], stms2); |
|
107 |
PP.closeBox ppStrm) |
PP.closeBox ppStrm) |
108 |
| S.S_IfThenElse(x, S.S_Block stms1, s2) => raise Fail "FIXME" |
| S.S_IfThenElse(x, S.Block[s1], S.Block[s2]) => ( |
|
| S.S_IfThenElse(x, s1, S.S_Block stms2) => raise Fail "FIXME" |
|
|
| S.S_IfThenElse(x, s1, s2) => ( |
|
109 |
PP.openVBox ppStrm indent; |
PP.openVBox ppStrm indent; |
110 |
PP.openHBox ppStrm; |
PP.openHBox ppStrm; |
111 |
string "if"; sp(); ppVar(ppStrm, x); |
string "if"; sp(); ppVar(ppStrm, x); |
119 |
ppStmt s2; |
ppStmt s2; |
120 |
PP.closeBox ppStrm; |
PP.closeBox ppStrm; |
121 |
nl()) |
nl()) |
122 |
|
| S.S_IfThenElse(x, blk1, blk2) => ( |
123 |
|
PP.openHBox ppStrm; |
124 |
|
string "if"; sp(); ppVar(ppStrm, x); |
125 |
|
sp(); ppBlock (ppStrm, [], blk1); |
126 |
|
PP.closeBox ppStrm; |
127 |
|
PP.openHBox ppStrm; |
128 |
|
string "else"; sp(); ppBlock (ppStrm, [], blk2); |
129 |
|
PP.closeBox ppStrm) |
130 |
| S.S_New(actor, args) => ( |
| S.S_New(actor, args) => ( |
131 |
PP.openHBox ppStrm; |
PP.openHBox ppStrm; |
132 |
string "new"; sp(); string(Atom.toString actor); sp(); |
string "new"; sp(); string(Atom.toString actor); sp(); |
147 |
PP.closeBox ppStrm |
PP.closeBox ppStrm |
148 |
end |
end |
149 |
|
|
|
fun ppVarsAndStmt (ppStrm, vars, S.S_Block stms) = ppBlock(ppStrm, vars, stms) |
|
|
| ppVarsAndStmt (ppStrm, vars, stm) = ppBlock(ppStrm, vars, [stm]) |
|
|
|
|
150 |
fun ppActor ppStrm (S.Actor{name, params, state, stateInit, methods}) = let |
fun ppActor ppStrm (S.Actor{name, params, state, stateInit, methods}) = let |
151 |
fun sp () = PP.space ppStrm 1 |
fun sp () = PP.space ppStrm 1 |
152 |
fun nl () = PP.newline ppStrm |
fun nl () = PP.newline ppStrm |
153 |
val string = PP.string ppStrm |
val string = PP.string ppStrm |
154 |
fun var x = string(Var.nameOf x) |
fun var x = string(Var.nameOf x) |
155 |
fun ppMethod (S.M_Method(name, body)) = ( |
fun ppMethod (S.Method(name, body)) = ( |
156 |
nl(); string(Atom.toString name); nl(); ppVarsAndStmt (ppStrm, [], body)) |
nl(); string(Atom.toString name); nl(); ppBlock (ppStrm, [], body)) |
157 |
in |
in |
158 |
PP.openHBox ppStrm; |
PP.openHBox ppStrm; |
159 |
string "actor"; sp(); string(Atom.toString name); sp(); |
string "actor"; sp(); string(Atom.toString name); sp(); |
163 |
nl(); |
nl(); |
164 |
PP.openVBox ppStrm indent; |
PP.openVBox ppStrm indent; |
165 |
string "{"; |
string "{"; |
166 |
ppVarsAndStmt (ppStrm, state, stateInit); |
ppBlock (ppStrm, state, stateInit); |
167 |
List.app ppMethod methods; |
List.app ppMethod methods; |
168 |
PP.closeBox ppStrm; |
PP.closeBox ppStrm; |
169 |
nl(); |
nl(); |
175 |
in |
in |
176 |
PP.openVBox ppStrm (PP.Abs 0); |
PP.openVBox ppStrm (PP.Abs 0); |
177 |
PP.string ppStrm "/* Simplified Program start */"; PP.newline ppStrm; |
PP.string ppStrm "/* Simplified Program start */"; PP.newline ppStrm; |
178 |
ppVarsAndStmt (ppStrm, globals, globalInit); |
ppBlock (ppStrm, globals, globalInit); |
179 |
List.app (ppActor ppStrm) actors; |
List.app (ppActor ppStrm) actors; |
180 |
PP.string ppStrm "/* Program end */"; PP.newline ppStrm; |
PP.string ppStrm "/* Program end */"; PP.newline ppStrm; |
181 |
PP.closeBox ppStrm; |
PP.closeBox ppStrm; |