# HG changeset patch # User Michael Pavone # Date 1406347416 25200 # Node ID 451043a65ff79ddc1f7defe5977e5714d06b4b16 # Parent 1c6d4f2642d0c66ca6f82d14470f5d57a09c8b64 Add support for while:do. Fix lambda expressions. Fix function call expressions diff -r 1c6d4f2642d0 -r 451043a65ff7 code/lmc.tp --- a/code/lmc.tp Fri Jul 25 19:19:07 2014 -0700 +++ b/code/lmc.tp Fri Jul 25 21:03:36 2014 -0700 @@ -17,9 +17,11 @@ missing } label <- "" + comment <- "" string <- { (if: label != "" { ";" . label . "\n " } else: { " " } - ) . name . " " . (args join: " ") + ) . name . " " . (args join: " ") . ( + if: comment = "" { "" } else: { " ;" . comment}) } } } @@ -151,6 +153,31 @@ } prog setLabel: elabel } + _funHandlers set: "while:do" :args syms { + top <- prog makeLabel: "loop_top" + body <- prog makeLabel: "loop_body" + end <- prog makeLabel: "loop_end" + cond <- args value + prog setLabel: top + foreach: (cond expressions) :idx expr { + compileExpr: expr syms: syms + } + prog add: (inst: "TSEL" #[ + body + end + ]) + prog setLabel: body + blambda <- (args tail) value + foreach: (blambda expressions) :idx expr { + compileExpr: expr syms: syms + } + prog add: (inst: "LDC" #[1]) + prog add: (inst: "TSEL" #[ + top + top + ]) + prog setLabel: end + } _funHandlers set: "isInteger?" :args syms { compileExpr: (args value) syms: syms prog add: (inst: "ATOM" #[]) @@ -184,12 +211,12 @@ } } if: normal { - compileExpr: tc syms: syms num <- 0 foreach: (expr args) :idx arg { compileExpr: arg syms: syms num <- num + 1 } + compileExpr: tc syms: syms prog add: (inst: "AP" #[num]) } } @@ -270,6 +297,7 @@ ]) compileLambda: fname expr syms: syms prog setLabel: end + prog add: (inst: "LDF" #[fname]) } #{ compile <- :code {