[pypy-svn] r31501 - in pypy/dist/pypy: annotation jit/codegen/i386 jit/codegen/i386/test

arigo at codespeak.net arigo at codespeak.net
Tue Aug 22 19:26:16 CEST 2006


Author: arigo
Date: Tue Aug 22 19:26:13 2006
New Revision: 31501

Modified:
   pypy/dist/pypy/annotation/binaryop.py
   pypy/dist/pypy/jit/codegen/i386/ri386genop.py
   pypy/dist/pypy/jit/codegen/i386/test/test_ri386genop.py
Log:
(pedronis, arigo)

Passing the first test that produces a C program doing run-time code
generation.



Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py	(original)
+++ pypy/dist/pypy/annotation/binaryop.py	Tue Aug 22 19:26:13 2006
@@ -334,7 +334,11 @@
         return SomeString(can_be_None=str1.can_be_None or str2.can_be_None)
 
     def add((str1, str2)):
-        return SomeString()
+        # propagate const-ness to help getattr(obj, 'prefix' + const_name)
+        result = SomeString()
+        if str1.is_immutable_constant() and str2.is_immutable_constant():
+            result.const = str1.const + str2.const
+        return result
 
 class __extend__(pairtype(SomeChar, SomeChar)):
 

Modified: pypy/dist/pypy/jit/codegen/i386/ri386genop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/ri386genop.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/ri386genop.py	Tue Aug 22 19:26:13 2006
@@ -46,6 +46,12 @@
             return IMM32(self.value)
 
 
+class FnPtrConst(IntConst):
+    def __init__(self, value, mc):
+        self.value = value
+        self.mc = mc    # to keep it alive
+
+
 class Block(object):
     def __init__(self, mc):
         self.argcount = 0
@@ -120,4 +126,10 @@
         for i in range(block.argcount):
             prologue.mc.PUSH(operand)
         prologue.mc.JMP(rel32(block.startaddr))
-        return IntConst(prologue.startaddr)
+        return FnPtrConst(prologue.startaddr, prologue.mc)
+
+    def revealconst(T, gv_const):
+        assert isinstance(gv_const, IntConst)    # for now
+        return lltype.cast_int_to_ptr(T, gv_const.value)
+    revealconst._annspecialcase_ = 'specialize:arg(0)'
+    revealconst = staticmethod(revealconst)

Modified: pypy/dist/pypy/jit/codegen/i386/test/test_ri386genop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/test/test_ri386genop.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/test/test_ri386genop.py	Tue Aug 22 19:26:13 2006
@@ -1,6 +1,7 @@
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython import llinterp
 from pypy.rpython.test.test_llinterp import interpret
+from pypy.rpython.objectmodel import keepalive_until_here
 from pypy.translator.c.test.test_genc import compile
 from pypy.jit.codegen.i386.ri386genop import RI386GenOp
 
@@ -29,7 +30,9 @@
     rgenop = RI386GenOp()
     gv_add_x = make_adder(rgenop, x)
     add_x = rgenop.revealconst(lltype.Ptr(FUNC), gv_add_x)
-    return add_x(y)
+    res = add_x(y)
+    keepalive_until_here(gv_add_x)    # to keep the 'add_x' fnptr alive
+    return res
 
 # ____________________________________________________________
 
@@ -42,7 +45,6 @@
     assert res == 42
 
 def test_adder_compile():
-    import py; py.test.skip("in-progress")
     fn = compile(runner, [int, int])
     res = fn(9080983, -9080941)
     assert res == 42



More information about the Pypy-commit mailing list