comparison python/c3/codegenerator.py @ 156:1b4a85bdd99c

change types
author Windel Bouwman
date Sun, 03 Mar 2013 15:50:34 +0100
parents b28a11c01dbe
children 8f3924b6076e
comparison
equal deleted inserted replaced
155:b28a11c01dbe 156:1b4a85bdd99c
2 from . import astnodes 2 from . import astnodes
3 3
4 def genModule(pkg): 4 def genModule(pkg):
5 m = ir.Module(pkg.name) 5 m = ir.Module(pkg.name)
6 for s in pkg.scope: 6 for s in pkg.scope:
7 print(s)
8 if type(s) is astnodes.Variable: 7 if type(s) is astnodes.Variable:
9 genGlobal(m, s) 8 genGlobal(m, s)
9 elif type(s) is astnodes.Function:
10 genFunction(m, s)
11 else:
12 print(s)
10 return m 13 return m
11 14
12 def genGlobal(m, var): 15 def genGlobal(m, var):
13 v = ir.Value() 16 v = ir.Value()
14 v.name = var.name 17 v.name = var.name
15 m.Globals.append(v) 18 m.Globals.append(v)
19
20 def genFunction(m, fnc):
21 f = ir.Function()
22 m.Globals.append(f)
16 23
17 class CodeGenerator: 24 class CodeGenerator:
18 """ Generates intermediate code """ 25 """ Generates intermediate code """
19 def gencode(self, ast): 26 def gencode(self, ast):
20 print('Code generator') 27 print('Code generator')