diff python/c3/codegenerator.py @ 220:3f6c30a5d234

Major change in expression parsing to enable pointers and structs
author Windel Bouwman
date Sat, 06 Jul 2013 21:32:20 +0200
parents 8b2e5f3cd579
children 848c4b15fd0b
line wrap: on
line diff
--- a/python/c3/codegenerator.py	Sat Jul 06 12:38:09 2013 +0200
+++ b/python/c3/codegenerator.py	Sat Jul 06 21:32:20 2013 +0200
@@ -1,6 +1,7 @@
 import ir
 from . import astnodes
 from .scope import boolType
+from ppci import CompilerError
    
 class CodeGenerator:
     """ Generates intermediate code from a package """
@@ -54,6 +55,7 @@
             self.genCode(s)
       elif type(code) is astnodes.Assignment:
          re = self.genExprCode(code.rval)
+         # TODO: Handle pointers
          loc = self.varMap[code.lval.target]
          self.builder.addIns(ir.Store(loc, re))
       elif type(code) is astnodes.IfStatement:
@@ -137,6 +139,15 @@
             tmp = self.builder.newTmp()
             # TODO
             return tmp
+      elif type(expr) is astnodes.Unop:
+         if expr.op == '&':
+            # Address of operator
+            ra = self.genExprCode(expr.a)
+            tmp = self.builder.newTmp('addr')
+            return tmp
+            #self.builder.addIns(ins)
+         else:
+            print('Unknown {0}'.format(expr))
       elif type(expr) is astnodes.Constant:
          tmp = self.builder.newTmp()
          # TODO
@@ -163,5 +174,5 @@
          self.builder.addIns(ins)
          return tmp
       else:
-         print('Unknown expr:', code)
+         raise CompilerError('Unknown expr {}'.format(expr))