Mercurial > repos > icfp2014
changeset 72:a2a5d80abaa0
Add and as a function to gqc to work around parser limitations
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 28 Jul 2014 00:42:21 -0700 |
parents | 920f02a880fc |
children | 91e7a30a9e27 |
files | code/gqc.tp |
diffstat | 1 files changed, 28 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/code/gqc.tp Mon Jul 28 00:41:59 2014 -0700 +++ b/code/gqc.tp Mon Jul 28 00:42:21 2014 -0700 @@ -275,6 +275,26 @@ prog add: (inst: "INT" #[7]) reg: 0 } + //new Quiche parser doesn't support and/or/xor operators yet :( + _funHandlers set: "and" :args syms { + l <- 0 + r <- preserveTemps: { + l <- compileExpr: (args value) syms: syms + compileExpr: ((args tail) value) syms: syms + } + dest <- getTemp: + if: dest != l { + prog add: (inst: "MOV" #[ + dest + l + ]) + } + prog add: (inst: "AND" #[ + dest + r + ]) + dest + } //allow access to raw instructions foreach: #["MOV" "INC" "DEC" "ADD" "SUB" "MUL" "DIV" "AND" "OR" "XOR" "JLT" "JEQ" "JGT" "HLT"] :idx instName { @@ -780,7 +800,14 @@ functions set: sym def syms define: sym sym } else: { - compileExpr: msg syms: syms + if: (def nodeType) != (ast intlit) || (def val) != 0{ + preserveTemps: { + compileExpr: msg syms: syms + } + } else: { + syms define: sym (mem: _nextVar) + _nextVar <- _nextVar + 1 + } } } else: { error: "Only assignments are allowed at the top level"