[pypy-svn] r73788 - in pypy/trunk/pypy/jit/tl: . test

fijal at codespeak.net fijal at codespeak.net
Thu Apr 15 21:47:32 CEST 2010


Author: fijal
Date: Thu Apr 15 21:47:31 2010
New Revision: 73788

Modified:
   pypy/trunk/pypy/jit/tl/test/test_tinyframe.py
   pypy/trunk/pypy/jit/tl/tinyframe.py
Log:
finish calls, fun


Modified: pypy/trunk/pypy/jit/tl/test/test_tinyframe.py
==============================================================================
--- pypy/trunk/pypy/jit/tl/test/test_tinyframe.py	(original)
+++ pypy/trunk/pypy/jit/tl/test/test_tinyframe.py	Thu Apr 15 21:47:31 2010
@@ -44,7 +44,6 @@
         assert ret.val == 100
 
     def test_function(self):
-        py.test.skip("in progress")
         code = compile('''
         func: # arg comes in r0
         LOAD 1 => r1

Modified: pypy/trunk/pypy/jit/tl/tinyframe.py
==============================================================================
--- pypy/trunk/pypy/jit/tl/tinyframe.py	(original)
+++ pypy/trunk/pypy/jit/tl/tinyframe.py	Thu Apr 15 21:47:31 2010
@@ -109,7 +109,16 @@
         self.code += [JUMP_IF_ABOVE, self.rint(arg0.strip()),
                       self.rint(arg1.strip()), self.labels[label[1:]]]
 
-    #def compile_LOAD_FUNCTION(self, 
+    def compile_LOAD_FUNCTION(self, args):
+        name, res = args.split("=>")
+        no, code = self.functions[name.strip()]
+        self.code += [LOAD_FUNCTION, no, self.rint(res.strip())]
+
+    def compile_CALL(self, args):
+        args, res = args.split("=>")
+        arg0, arg1 = args.strip().split(" ")
+        self.code += [CALL, self.rint(arg0.strip()), self.rint(arg1.strip()),
+                      self.rint(res.strip())]
 
 def compile(strrepr):
     parser = Parser()
@@ -138,6 +147,15 @@
     def gt(self, other):
         return self.val > other.val
 
+class Func(Object):
+    def __init__(self, code):
+        self.code = code
+
+    def call(self, arg):
+        f = Frame(self.code)
+        f.registers[0] = arg
+        return f.interpret()
+
 class Frame(object):
     def __init__(self, code):
         self.code = code
@@ -166,6 +184,16 @@
                     i = tgt
                 else:
                     i += 4
+            elif opcode == LOAD_FUNCTION:
+                f = self.code.functions[ord(code[i + 1])]
+                self.registers[ord(code[i + 2])] = Func(f)
+                i += 3
+            elif opcode == CALL:
+                f = self.registers[ord(code[i + 1])]
+                arg = self.registers[ord(code[i + 2])]
+                assert isinstance(f, Func)
+                self.registers[ord(code[i + 3])] = f.call(arg)
+                i += 4
             else:
                 raise Exception("unimplemented opcode %s" % opcodes[opcode])
 



More information about the Pypy-commit mailing list