equal
deleted
inserted
replaced
151 i"return" ++ |
151 i"return" ++ |
152 m".end method\n" |
152 m".end method\n" |
153 } |
153 } |
154 } |
154 } |
155 |
155 |
156 // main compilation function |
156 // the main compilation function |
157 def compile(prog: List[Decl], class_name: String) : String = { |
157 def compile(prog: List[Decl], class_name: String) : String = { |
158 val instructions = prog.map(compile_decl).mkString |
158 val instructions = prog.map(compile_decl).mkString |
159 (library + instructions).replaceAllLiterally("XXX", class_name) |
159 (library + instructions).replaceAllLiterally("XXX", class_name) |
160 } |
160 } |
161 |
161 |
162 |
162 |
163 |
163 |
164 |
164 |
165 // example program (factorials) |
165 // An example program (factorials) |
166 |
166 |
167 val test_prog = |
167 val test_prog = |
168 List(Def("fact", List("n"), |
168 List(Def("fact", List("n"), |
169 If(Bop("==",Var("n"),Num(0)), |
169 If(Bop("==",Var("n"),Num(0)), |
170 Num(1), |
170 Num(1), |