# HG changeset patch # User Windel Bouwman # Date 1386329868 -3600 # Node ID be7f6054536891898ada4ddb9346bb978a76f07b # Parent 2ef2247f8ddaf2482d0b9fac6ed85fac2046e2fd Final fixups diff -r 2ef2247f8dda -r be7f60545368 python/asm.py --- 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 diff -r 2ef2247f8dda -r be7f60545368 python/ppci/c3/codegenerator.py --- 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() diff -r 2ef2247f8dda -r be7f60545368 python/ppci/ir.py --- 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) - - diff -r 2ef2247f8dda -r be7f60545368 test/grind.py --- 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 diff -r 2ef2247f8dda -r be7f60545368 test/testc3.py --- 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;