changeset 303:be7f60545368

Final fixups
author Windel Bouwman
date Fri, 06 Dec 2013 12:37:48 +0100
parents 2ef2247f8dda
children fa99f36fabb5
files python/asm.py python/ppci/c3/codegenerator.py python/ppci/ir.py test/grind.py test/testc3.py
diffstat 5 files changed, 30 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/python/asm.py	Fri Dec 06 12:09:35 2013 +0100
+++ b/python/asm.py	Fri Dec 06 12:37:48 2013 +0100
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
+
 import re, argparse
 import pyyacc
 from ppci import Token, CompilerError, SourceLocation
--- a/python/ppci/c3/codegenerator.py	Fri Dec 06 12:09:35 2013 +0100
+++ b/python/ppci/c3/codegenerator.py	Fri Dec 06 12:37:48 2013 +0100
@@ -97,14 +97,12 @@
             self.emit(ir.Jump(te))
             self.setBlock(te)
         elif type(code) is astnodes.ReturnStatement:
-            if code.expr:
-                re = self.genExprCode(code.expr)
-                self.emit(ir.Move(self.fn.return_value, re))
-                self.emit(ir.Jump(self.fn.epiloog))
-                b = self.newBlock()
-                self.setBlock(b)
-            else:
-                self.builder.addIns(ir.Return())
+            assert code.expr
+            re = self.genExprCode(code.expr)
+            self.emit(ir.Move(self.fn.return_value, re))
+            self.emit(ir.Jump(self.fn.epiloog))
+            b = self.newBlock()
+            self.setBlock(b)
         elif type(code) is astnodes.WhileStatement:
             bbdo = self.newBlock()
             bbtest = self.newBlock()
--- a/python/ppci/ir.py	Fri Dec 06 12:09:35 2013 +0100
+++ b/python/ppci/ir.py	Fri Dec 06 12:37:48 2013 +0100
@@ -290,6 +290,7 @@
 def Div(a, b):
     return Binop(a, '/', b)
 
+
 class Eseq(Expression):
     """ Sequence of instructions where the last is an expression """
     def __init__(self, stmt, e):
@@ -473,5 +474,3 @@
         if not self.bb:
             raise Exception('No basic block')
         self.bb.addInstruction(i)
-
-
--- a/test/grind.py	Fri Dec 06 12:09:35 2013 +0100
+++ b/test/grind.py	Fri Dec 06 12:37:48 2013 +0100
@@ -1,3 +1,4 @@
+#!/usr/bin/python
 
 import cProfile
 import unittest
--- a/test/testc3.py	Fri Dec 06 12:09:35 2013 +0100
+++ b/test/testc3.py	Fri Dec 06 12:37:48 2013 +0100
@@ -104,6 +104,26 @@
         """
         self.expectErrors(snippet, [5, 6])
 
+    def testReturn(self):
+        snippet = """
+         module testreturn;
+         function void t()
+         {
+            return;
+         }
+        """
+        self.expectOK(snippet)
+
+    def testReturn2(self):
+        snippet = """
+         module testreturn;
+         function int t()
+         {
+            return 2;
+         }
+        """
+        self.expectOK(snippet)
+
     def testExpressions(self):
         snippet = """
          module test;