comparison python/c3/codegenerator.py @ 269:5f8c04a8d26b

Towards better modularity
author Windel Bouwman
date Sun, 18 Aug 2013 17:43:18 +0200
parents 5ec7580976d9
children e64bae57cda8
comparison
equal deleted inserted replaced
268:5ec7580976d9 269:5f8c04a8d26b
38 raise NotImplementedError(str(s)) 38 raise NotImplementedError(str(s))
39 39
40 def genFunction(self, fn): 40 def genFunction(self, fn):
41 # TODO: handle arguments 41 # TODO: handle arguments
42 f = self.funcMap[fn] 42 f = self.funcMap[fn]
43 # TODO reserve room for stack, this can be done at later point?
43 self.setFunction(f) 44 self.setFunction(f)
45 l2 = self.newBlock()
46 self.emit(ir.Jump(l2))
47 self.setBlock(l2)
44 # generate room for locals: 48 # generate room for locals:
45 49
46 for sym in fn.innerScope: 50 for sym in fn.innerScope:
47 # TODO: handle parameters different 51 # TODO: handle parameters different
48 v = self.newTemp() 52 v = self.newTemp()
49 # TODO: make this ssa here?? 53 # TODO: make this ssa here??
50 self.varMap[sym] = v 54 self.varMap[sym] = v
51 55
52 self.genCode(fn.body) 56 self.genCode(fn.body)
53 # TODO handle return? 57 # TODO handle return?
54 self.emit(ir.Return(ir.Const(0))) 58 self.emit(ir.Jump(f.epiloog))
59 #self.emit(ir.Return(ir.Const(0)))
55 self.setFunction(None) 60 self.setFunction(None)
56 61
57 def genCode(self, code): 62 def genCode(self, code):
58 assert isinstance(code, astnodes.Statement) 63 assert isinstance(code, astnodes.Statement)
59 self.setLoc(code.loc) 64 self.setLoc(code.loc)