[pypy-svn] r52944 - in pypy/branch/jit-hotpath/pypy/jit: codegen/llgraph rainbow rainbow/test timeshifter

antocuni at codespeak.net antocuni at codespeak.net
Tue Mar 25 22:19:17 CET 2008


Author: antocuni
Date: Tue Mar 25 22:19:16 2008
New Revision: 52944

Modified:
   pypy/branch/jit-hotpath/pypy/jit/codegen/llgraph/rgenop.py
   pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py
   pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py
   pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py
   pypy/branch/jit-hotpath/pypy/jit/rainbow/typesystem.py
   pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py
Log:
port VirtualStructure to ootype. test_degenerate_with_voids passes



Modified: pypy/branch/jit-hotpath/pypy/jit/codegen/llgraph/rgenop.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/codegen/llgraph/rgenop.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/codegen/llgraph/rgenop.py	Tue Mar 25 22:19:16 2008
@@ -246,6 +246,13 @@
         return LLVar(llimpl.genop(self.b, 'malloc_varsize', vars_gv,
                                   gv_PTRTYPE.v))
 
+    def genop_new(self, (gv_TYPE, gv_OBJTYPE)):
+        ll_assert(self.rgenop.currently_writing is self,
+                     "genop_new: bad currently_writing")
+        vars_gv = [gv_TYPE.v]
+        return LLVar(llimpl.genop(self.b, 'new', vars_gv,
+                                  gv_OBJTYPE.v))
+
     def genop_same_as(self, gv_TYPE, gv_value):
         ll_assert(self.rgenop.currently_writing is self,
                      "genop_same_as: bad currently_writing")

Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py	Tue Mar 25 22:19:16 2008
@@ -187,7 +187,6 @@
 
     def make_bytecode(self, graph, is_portal=True):
         self.transformer.transform_graph(graph)
-        #graph.show()
         if is_portal:
             bytecode = JitCode.__new__(JitCode)
             bytecode.name = graph.name     # for dump()
@@ -1207,25 +1206,6 @@
         newop = flowmodel.SpaceOperation(opname, args, op.result)
         self.serialize_op(newop)
 
-    def serialize_op_malloc(self, op):
-        index = self.structtypedesc_position(op.args[0].value)
-        self.emit("red_malloc", index)
-        self.register_redvar(op.result)
-
-    def serialize_op_malloc_varsize(self, op):
-        PTRTYPE = op.result.concretetype
-        TYPE = PTRTYPE.TO
-        v_size = op.args[2]
-        sizeindex = self.serialize_oparg("red", v_size)
-        if isinstance(TYPE, lltype.Struct):
-            index = self.structtypedesc_position(op.args[0].value)
-            self.emit("red_malloc_varsize_struct")
-        else:
-            index = self.arrayfielddesc_position(TYPE)
-            self.emit("red_malloc_varsize_array")
-        self.emit(index, sizeindex)
-        self.register_redvar(op.result)
-
     def serialize_op_zero_gc_pointers_inside(self, op):
         pass # XXX is that right?
 
@@ -1603,6 +1583,25 @@
 
     def serialize_op_setfield(self, op):
         return self.serialize_op_setfield_impl(op)
+ 
+    def serialize_op_malloc(self, op):
+        index = self.structtypedesc_position(op.args[0].value)
+        self.emit("red_malloc", index)
+        self.register_redvar(op.result)
+
+    def serialize_op_malloc_varsize(self, op):
+        PTRTYPE = op.result.concretetype
+        TYPE = PTRTYPE.TO
+        v_size = op.args[2]
+        sizeindex = self.serialize_oparg("red", v_size)
+        if isinstance(TYPE, lltype.Struct):
+            index = self.structtypedesc_position(op.args[0].value)
+            self.emit("red_malloc_varsize_struct")
+        else:
+            index = self.arrayfielddesc_position(TYPE)
+            self.emit("red_malloc_varsize_array")
+        self.emit(index, sizeindex)
+        self.register_redvar(op.result)
 
 
 class OOTypeBytecodeWriter(BytecodeWriter):
@@ -1619,6 +1618,11 @@
     def serialize_op_oosetfield(self, op):
         return self.serialize_op_setfield_impl(op)
 
+    def serialize_op_new(self, op):
+        index = self.structtypedesc_position(op.args[0].value)
+        self.emit("red_new", index)
+        self.register_redvar(op.result)
+
 
 class GraphTransformer(object):
     def __init__(self, hannotator):

Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/interpreter.py	Tue Mar 25 22:19:16 2008
@@ -1038,6 +1038,10 @@
         rtimeshift.gensetfield(self.jitstate, fielddesc, destbox,
                                valuebox)
 
+    @arguments("structtypedesc", returns="red")
+    def opimpl_red_new(self, structtypedesc):
+        return structtypedesc.factory()
+
 
 class DebugTrace(object):
     def __init__(self, *args):

Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py	Tue Mar 25 22:19:16 2008
@@ -100,7 +100,7 @@
         return lltype.Ptr(T)
 
     @staticmethod
-    def Struct(name, *fields, **kwds):
+    def GcStruct(name, *fields, **kwds):
         S = lltype.GcStruct(name, *fields, **kwds)
         return S
 
@@ -684,10 +684,10 @@
         
 
     def test_simple_struct(self):
-        S = self.Struct('helloworld',
-                        ('hello', lltype.Signed),
-                        ('world', lltype.Signed),
-                        hints={'immutable': True})
+        S = self.GcStruct('helloworld',
+                          ('hello', lltype.Signed),
+                          ('world', lltype.Signed),
+                          hints={'immutable': True})
         malloc = self.malloc
         
         def ll_function(s):
@@ -790,6 +790,7 @@
     def test_degenerated_before_return(self):
         S = lltype.GcStruct('S', ('n', lltype.Signed))
         T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
+        malloc = self.malloc
 
         def ll_function(flag):
             t = lltype.malloc(T)
@@ -865,10 +866,11 @@
         assert res == 4 * 4
 
     def test_degenerate_with_voids(self):
-        S = lltype.GcStruct('S', ('y', lltype.Void),
-                                 ('x', lltype.Signed))
+        S = self.GcStruct('S', ('y', lltype.Void),
+                               ('x', lltype.Signed))
+        malloc = self.malloc
         def ll_function():
-            s = lltype.malloc(S)
+            s = malloc(S)
             s.x = 123
             return s
         res = self.interpret(ll_function, [], [])
@@ -1066,7 +1068,7 @@
 
 
     def test_green_with_side_effects(self):
-        S = self.Struct('S', ('flag', lltype.Bool))
+        S = self.GcStruct('S', ('flag', lltype.Bool))
         s = self.malloc(S)
         s.flag = False
         def ll_set_flag(s):
@@ -1987,7 +1989,7 @@
         return T
 
     @staticmethod
-    def Struct(name, *fields, **kwds):
+    def GcStruct(name, *fields, **kwds):
         if 'hints' in kwds:
             kwds['_hints'] = kwds['hints']
             del kwds['hints']
@@ -2019,7 +2021,6 @@
     test_degenerated_before_return_2 = _skip
     test_degenerated_at_return = _skip
     test_degenerated_via_substructure = _skip
-    test_degenerate_with_voids = _skip
     test_plus_minus = _skip
     test_red_virtual_container = _skip
     test_red_array = _skip

Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/typesystem.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/typesystem.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/typesystem.py	Tue Mar 25 22:19:16 2008
@@ -21,7 +21,6 @@
     def _freeze_(self):
         return True
 
-
 class LLTypeHelper(TypeSystemHelper):
 
     name = 'lltype'
@@ -30,6 +29,8 @@
     def get_typeptr(self, obj):
         return obj.typeptr
 
+    def genop_malloc_fixedsize(self, builder, alloctoken):
+        return builder.genop_malloc_fixedsize(alloctoken)
 
 class OOTypeHelper(TypeSystemHelper):
 
@@ -39,6 +40,9 @@
     def get_typeptr(self, obj):
         return obj.meta
 
+    def genop_malloc_fixedsize(self, builder, alloctoken):
+        return builder.genop_new(alloctoken)
+
 
 llhelper = LLTypeHelper()
 oohelper = OOTypeHelper()

Modified: pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py	Tue Mar 25 22:19:16 2008
@@ -857,7 +857,7 @@
                 return
         debug_print(lltype.Void, "FORCE CONTAINER: "+ typedesc.TYPE._name)
         #debug_pdb(lltype.Void)
-        genvar = builder.genop_malloc_fixedsize(typedesc.alloctoken)
+        genvar = jitstate.ts.genop_malloc_fixedsize(builder, typedesc.alloctoken)
         # force the box pointing to this VirtualStruct
         self.setforced(genvar)
         fielddescs = typedesc.fielddescs
@@ -1284,6 +1284,7 @@
 
 # patching VirtualStructCls
 StructTypeDesc.VirtualStructCls = VirtualStruct
+InstanceTypeDesc.VirtualStructCls = VirtualStruct
 VirtualizableStructTypeDesc.VirtualStructCls = VirtualizableStruct
 
 


More information about the pypy-svn mailing list