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

change types
author Windel Bouwman
date Sun, 03 Mar 2013 15:50:34 +0100
parents b28a11c01dbe
children 8f3924b6076e
line wrap: on
line source

import ir
from . import astnodes

def genModule(pkg):
   m = ir.Module(pkg.name)
   for s in pkg.scope:
      if type(s) is astnodes.Variable:
         genGlobal(m, s)
      elif type(s) is astnodes.Function:
         genFunction(m, s)
      else:
         print(s)
   return m

def genGlobal(m, var):
   v = ir.Value()
   v.name = var.name
   m.Globals.append(v)

def genFunction(m, fnc):
   f = ir.Function()
   m.Globals.append(f)

class CodeGenerator:
   """ Generates intermediate code """
   def gencode(self, ast):
      print('Code generator')
      assert type(ast) is astnodes.Package
      return genModule(ast)