comparison python/c3/codegenerator.py @ 169:ee0d30533dae

Added more tests and improved the diagnostic update
author Windel Bouwman
date Sat, 23 Mar 2013 18:34:41 +0100
parents 0b5b2ee6b435
children 4348da5ca307
comparison
equal deleted inserted replaced
168:49f1ab80d040 169:ee0d30533dae
71 tmp = unique() 71 tmp = unique()
72 ins = ir.BinaryOperator(tmp, op, a, b) 72 ins = ir.BinaryOperator(tmp, op, a, b)
73 bb.Instructions.append(ins) 73 bb.Instructions.append(ins)
74 return tmp 74 return tmp
75 else: 75 else:
76 print('Unknown binop') 76 print('Unknown binop {0}'.format(code))
77 bb.Instructions.append(ir.BinaryOperator('unk2', code.op, a, b)) 77 bb.Instructions.append(ir.BinaryOperator('unk2', code.op, a, b))
78 return 'unk2' 78 return 'unk2'
79 elif type(code) is astnodes.Constant: 79 elif type(code) is astnodes.Constant:
80 tmp = unique() 80 tmp = unique()
81 bb.Instructions.append(ir.LoadInstruction(tmp, code.value)) 81 bb.Instructions.append(ir.LoadInstruction(tmp, code.value))
82 return tmp 82 return tmp
83 elif type(code) is astnodes.VariableUse: 83 elif type(code) is astnodes.VariableUse:
84 tmp = unique() 84 tmp = unique()
85 ins = ir.LoadInstruction(tmp, code.target.name) 85 ins = ir.LoadInstruction(tmp, code.target.name)
86 return tmp
87 elif type(code) is astnodes.Literal:
88 tmp = unique()
89 ins = ir.LoadInstruction(tmp, code.val)
86 return tmp 90 return tmp
87 else: 91 else:
88 print('Unknown expr:', code) 92 print('Unknown expr:', code)
89 return 'unk' 93 return 'unk'
90 94