comparison python/ppci/c3/codegenerator.py @ 315:084cccaa5deb

Added console and screen
author Windel Bouwman
date Sat, 21 Dec 2013 10:03:01 +0100
parents 04cf4d26a3bc
children 56e6ff84f646
comparison
equal deleted inserted replaced
314:38f5f298ce0e 315:084cccaa5deb
108 pass 108 pass
109 elif type(code) is ast.Assignment: 109 elif type(code) is ast.Assignment:
110 lval = self.genExprCode(code.lval) 110 lval = self.genExprCode(code.lval)
111 rval = self.genExprCode(code.rval) 111 rval = self.genExprCode(code.rval)
112 if not self.equalTypes(code.lval.typ, code.rval.typ): 112 if not self.equalTypes(code.lval.typ, code.rval.typ):
113 msg = 'Cannot assign {} to {}'.format(code.lval.typ, code.rval.typ) 113 msg = 'Cannot assign {} to {}'.format(code.rval.typ, code.lval.typ)
114 raise SemanticError(msg, code.loc) 114 raise SemanticError(msg, code.loc)
115 if not code.lval.lvalue: 115 if not code.lval.lvalue:
116 raise SemanticError('No valid lvalue {}'.format(code.lval), code.lval.loc) 116 raise SemanticError('No valid lvalue {}'.format(code.lval), code.lval.loc)
117 self.emit(ir.Move(lval, rval)) 117 self.emit(ir.Move(lval, rval))
118 elif type(code) is ast.ExpressionStatement: 118 elif type(code) is ast.ExpressionStatement:
144 self.gen_cond_code(code.condition, bbdo, te) 144 self.gen_cond_code(code.condition, bbdo, te)
145 self.setBlock(bbdo) 145 self.setBlock(bbdo)
146 self.genCode(code.statement) 146 self.genCode(code.statement)
147 self.emit(ir.Jump(bbtest)) 147 self.emit(ir.Jump(bbtest))
148 self.setBlock(te) 148 self.setBlock(te)
149 elif type(code) is ast.For:
150 bbdo = self.newBlock()
151 bbtest = self.newBlock()
152 te = self.newBlock()
153 self.genCode(code.init)
154 self.emit(ir.Jump(bbtest))
155 self.setBlock(bbtest)
156 self.gen_cond_code(code.condition, bbdo, te)
157 self.setBlock(bbdo)
158 self.genCode(code.statement)
159 self.emit(ir.Jump(bbtest))
160 self.setBlock(te)
149 else: 161 else:
150 raise NotImplementedError('Unknown stmt {}'.format(code)) 162 raise NotImplementedError('Unknown stmt {}'.format(code))
151 163
152 def gen_cond_code(self, expr, bbtrue, bbfalse): 164 def gen_cond_code(self, expr, bbtrue, bbfalse):
153 """ Generate conditional logic. 165 """ Generate conditional logic.