43 |
ppList ppTyArg ("<", ";", ">") (ppStrm, mvs) |
ppList ppTyArg ("<", ";", ">") (ppStrm, mvs) |
44 |
end |
end |
45 |
|
|
46 |
fun ppVar ppStrm x = PP.string ppStrm (Var.uniqueNameOf x) |
fun ppVar (ppStrm, x) = PP.string ppStrm (Var.uniqueNameOf x) |
47 |
|
|
48 |
fun ppVarDecl ppStrm = let |
fun ppVarDecl ppStrm = let |
49 |
fun sp () = PP.space ppStrm 1 |
fun sp () = PP.space ppStrm 1 |
80 |
|
|
81 |
and ppArgs (ppStrm, args) = ppList ppVar ("(", ",", ")") (ppStrm, args) |
and ppArgs (ppStrm, args) = ppList ppVar ("(", ",", ")") (ppStrm, args) |
82 |
|
|
83 |
fun ppBlock (ppStrm, stms) = let |
fun ppBlock (ppStrm, vars, 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.nameOf x) |
fun var x = string(Var.uniqueNameOf x) |
88 |
fun ppStmt stmt = (case stmt |
fun ppStmt stmt = (case stmt |
89 |
of AST.S_Block stms => ppBlock (ppStrm, stms) |
of S.S_Block stms => ppBlock (ppStrm, [], stms) |
90 |
| AST.S_Decl vdcl => (ppVarDecl ppStrm vdcl; nl()) |
| S.S_Assign(x, e) => ( |
91 |
| AST.S_IfThenElse(e, AST.S_Block stms, AST.S_Block[]) => ( |
PP.openHBox ppStrm; |
92 |
|
var x; sp(); string "="; sp(); ppExp(ppStrm, e); string ";"; |
93 |
|
PP.closeBox ppStrm; |
94 |
|
nl()) |
95 |
|
| S.S_IfThenElse(x, S.S_Block stms, S.S_Block[]) => ( |
96 |
PP.openHBox ppStrm; |
PP.openHBox ppStrm; |
97 |
string "if"; sp(); ppExp(ppStrm, e); |
string "if"; sp(); ppVar(ppStrm, x); |
98 |
sp(); ppBlock (ppStrm, stms); |
sp(); ppBlock (ppStrm, [], stms); |
99 |
PP.closeBox ppStrm) |
PP.closeBox ppStrm) |
100 |
| AST.S_IfThenElse(e, s1, AST.S_Block[]) => ( |
| S.S_IfThenElse(x, s1, S.S_Block[]) => ( |
101 |
PP.openVBox ppStrm indent; |
PP.openVBox ppStrm indent; |
102 |
PP.openHBox ppStrm; |
PP.openHBox ppStrm; |
103 |
string "if"; sp(); ppExp(ppStrm, e); |
string "if"; sp(); ppVar(ppStrm, x); |
104 |
PP.closeBox ppStrm; |
PP.closeBox ppStrm; |
105 |
nl(); |
nl(); |
106 |
ppStmt s1; |
ppStmt s1; |
107 |
PP.closeBox ppStrm; |
PP.closeBox ppStrm; |
108 |
nl()) |
nl()) |
109 |
| AST.S_IfThenElse(e, AST.S_Block stms1, AST.S_Block stms2) => ( |
| S.S_IfThenElse(x, S.S_Block stms1, S.S_Block stms2) => ( |
110 |
PP.openHBox ppStrm; |
PP.openHBox ppStrm; |
111 |
string "if"; sp(); ppExp(ppStrm, e); |
string "if"; sp(); ppVar(ppStrm, x); |
112 |
sp(); ppBlock (ppStrm, stms1); |
sp(); ppBlock (ppStrm, [], stms1); |
113 |
PP.closeBox ppStrm; |
PP.closeBox ppStrm; |
114 |
PP.openHBox ppStrm; |
PP.openHBox ppStrm; |
115 |
string "else"; sp(); ppBlock (ppStrm, stms2); |
string "else"; sp(); ppBlock (ppStrm, [], stms2); |
116 |
PP.closeBox ppStrm) |
PP.closeBox ppStrm) |
117 |
| AST.S_IfThenElse(e, AST.S_Block stms1, s2) => raise Fail "FIXME" |
| S.S_IfThenElse(x, S.S_Block stms1, s2) => raise Fail "FIXME" |
118 |
| AST.S_IfThenElse(e, s1, AST.S_Block stms2) => raise Fail "FIXME" |
| S.S_IfThenElse(x, s1, S.S_Block stms2) => raise Fail "FIXME" |
119 |
| AST.S_IfThenElse(e, s1, s2) => ( |
| S.S_IfThenElse(x, s1, s2) => ( |
120 |
PP.openVBox ppStrm indent; |
PP.openVBox ppStrm indent; |
121 |
PP.openHBox ppStrm; |
PP.openHBox ppStrm; |
122 |
string "if"; sp(); ppExp(ppStrm, e); |
string "if"; sp(); ppVar(ppStrm, x); |
123 |
PP.closeBox ppStrm; |
PP.closeBox ppStrm; |
124 |
nl(); |
nl(); |
125 |
ppStmt s1; |
ppStmt s1; |
130 |
ppStmt s2; |
ppStmt s2; |
131 |
PP.closeBox ppStrm; |
PP.closeBox ppStrm; |
132 |
nl()) |
nl()) |
133 |
| AST.S_Assign(x, e) => ( |
| S.S_New(actor, args) => ( |
|
PP.openHBox ppStrm; |
|
|
var x; sp(); string "="; sp(); ppExp(ppStrm, e); string ";"; |
|
|
PP.closeBox ppStrm; |
|
|
nl()) |
|
|
| AST.S_New(actor, args) => ( |
|
134 |
PP.openHBox ppStrm; |
PP.openHBox ppStrm; |
135 |
string "new"; sp(); string(Atom.toString actor); sp(); |
string "new"; sp(); string(Atom.toString actor); sp(); |
136 |
ppArgs (ppStrm, args); string ";"; |
ppArgs (ppStrm, args); string ";"; |
137 |
PP.closeBox ppStrm; |
PP.closeBox ppStrm; |
138 |
nl()) |
nl()) |
139 |
| AST.S_Die => (string "die;"; nl()) |
| S.S_Die => (string "die;"; nl()) |
140 |
| AST.S_Stabilize => (string "stabilize;"; nl()) |
| S.S_Stabilize => (string "stabilize;"; nl()) |
141 |
(* end case *)) |
(* end case *)) |
142 |
in |
in |
143 |
PP.openVBox ppStrm (PP.Abs 0); |
PP.openVBox ppStrm (PP.Abs 0); |
144 |
string "{"; nl(); |
string "{"; nl(); |
145 |
PP.openVBox ppStrm indent; |
PP.openVBox ppStrm indent; |
146 |
|
List.app (fn vdcl => (ppVarDecl ppStrm vdcl; nl())) vars; |
147 |
List.app ppStmt stms; |
List.app ppStmt stms; |
148 |
PP.closeBox ppStrm; |
PP.closeBox ppStrm; |
149 |
string "}"; nl(); |
string "}"; nl(); |
150 |
PP.closeBox ppStrm |
PP.closeBox ppStrm |
151 |
end |
end |
152 |
|
|
153 |
fun ppActor (ppStrm, S.Actor{name, params, state, stateInit, methods}) = let |
fun ppVarsAndStmt (ppStrm, vars, S.S_Block stms) = ppBlock(ppStrm, vars, stms) |
154 |
|
| ppVarsAndStmt (ppStrm, vars, stm) = ppBlock(ppStrm, vars, [stm]) |
155 |
|
|
156 |
|
fun ppActor ppStrm (S.Actor{name, params, state, stateInit, methods}) = let |
157 |
fun sp () = PP.space ppStrm 1 |
fun sp () = PP.space ppStrm 1 |
158 |
fun nl () = PP.newline ppStrm |
fun nl () = PP.newline ppStrm |
159 |
val string = PP.string ppStrm |
val string = PP.string ppStrm |
160 |
fun var x = string(Var.nameOf x) |
fun var x = string(Var.nameOf x) |
161 |
fun ppMethod (AST.M_Method(name, AST.S_Block stms)) = ( |
fun ppMethod (S.M_Method(name, body)) = ( |
162 |
nl(); string(Atom.toString name); nl(); ppBlock (ppStrm, stms)) |
nl(); string(Atom.toString name); nl(); ppVarsAndStmt (ppStrm, [], body)) |
|
| ppMethod (AST.M_Method(name, stm)) = ( |
|
|
nl(); string(Atom.toString name); nl(); ppBlock (ppStrm, [stm])) |
|
163 |
in |
in |
164 |
PP.openHBox ppStrm; |
PP.openHBox ppStrm; |
165 |
string "actor"; sp(); string(Atom.toString name); sp(); |
string "actor"; sp(); string(Atom.toString name); sp(); |
169 |
nl(); |
nl(); |
170 |
PP.openVBox ppStrm indent; |
PP.openVBox ppStrm indent; |
171 |
string "{"; |
string "{"; |
172 |
List.app (fn vdcl => (nl(); ppStateVarDecl ppStrm vdcl)) state; |
ppVarsAndStmt (ppStrm, state, stateInit); |
173 |
List.app ppMethod methods; |
List.app ppMethod methods; |
174 |
PP.closeBox ppStrm; |
PP.closeBox ppStrm; |
175 |
nl(); |
nl(); |
180 |
val ppStrm = PP.openOut {dst = outS, wid = 120} |
val ppStrm = PP.openOut {dst = outS, wid = 120} |
181 |
in |
in |
182 |
PP.openVBox ppStrm (PP.Abs 0); |
PP.openVBox ppStrm (PP.Abs 0); |
183 |
PP.string ppStrm "/* Program start */"; PP.newline ppStrm; |
PP.string ppStrm "/* Simplified Program start */"; PP.newline ppStrm; |
184 |
List.app (ppDecl ppStrm) decls; |
ppVarsAndStmt (ppStrm, globals, globalInit); |
185 |
|
List.app (ppActor ppStrm) actors; |
186 |
PP.string ppStrm "/* Program end */"; PP.newline ppStrm; |
PP.string ppStrm "/* Program end */"; PP.newline ppStrm; |
187 |
PP.closeBox ppStrm; |
PP.closeBox ppStrm; |
188 |
PP.closeStream ppStrm |
PP.closeStream ppStrm |