Mercurial > repos > icfp2014
comparison code/lmc.tp @ 6:0ab6eb5f0190
Implement not, < and <=
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 25 Jul 2014 11:46:34 -0700 |
parents | 80e224fff567 |
children | afd55b32549b |
comparison
equal
deleted
inserted
replaced
5:80e224fff567 | 6:0ab6eb5f0190 |
---|---|
111 compileExpr: (expr left) | 111 compileExpr: (expr left) |
112 } | 112 } |
113 _opNames ifget: (expr op) :i { | 113 _opNames ifget: (expr op) :i { |
114 prog add: (inst: i #[]) | 114 prog add: (inst: i #[]) |
115 } else: { | 115 } else: { |
116 error: "operator " . (expr op) . " is not supported" | 116 if: (expr op) = "<" { |
117 prog add: (inst: "CGTE" #[]) | |
118 prog add: (inst: "LDC" #[0]) | |
119 prog add: (inst: "CEQ" #[]) | |
120 } else: { | |
121 if: (expr op) = "<=" { | |
122 prog add: (inst: "CGT" #[]) | |
123 prog add: (inst: "LDC" #[0]) | |
124 prog add: (inst: "CEQ" #[]) | |
125 } else: { | |
126 error: "operator " . (expr op) . " is not supported" | |
127 } | |
128 } | |
117 } | 129 } |
118 } | 130 } |
119 | 131 |
120 _funHandlers <- dict hash | 132 _funHandlers <- dict hash |
121 _funHandlers set: "if:else" :args { | 133 _funHandlers set: "if:else" :args { |
153 prog add: (inst: "CAR" #[]) | 165 prog add: (inst: "CAR" #[]) |
154 } | 166 } |
155 _funHandlers set: "tail" :args { | 167 _funHandlers set: "tail" :args { |
156 compileExpr: (args value) | 168 compileExpr: (args value) |
157 prog add: (inst: "CDR" #[]) | 169 prog add: (inst: "CDR" #[]) |
170 } | |
171 _funHandlers set: "not" :args { | |
172 compileExpr: (args value) | |
173 prog add: (inst: "LDC" #[0]) | |
174 prog add: (inst: "CEQ" #[]) | |
158 } | 175 } |
159 | 176 |
160 _exprHandlers set: (ast call) :expr { | 177 _exprHandlers set: (ast call) :expr { |
161 tc <- (expr tocall) | 178 tc <- (expr tocall) |
162 if: (tc nodeType) = (ast sym) { | 179 if: (tc nodeType) = (ast sym) { |