[pypy-svn] r22592 - in pypy/dist/pypy/rpython/l3interp: . test

ac at codespeak.net ac at codespeak.net
Tue Jan 24 14:53:54 CET 2006


Author: ac
Date: Tue Jan 24 14:53:54 2006
New Revision: 22592

Modified:
   pypy/dist/pypy/rpython/l3interp/convertgraph.py
   pypy/dist/pypy/rpython/l3interp/l3interp.py
   pypy/dist/pypy/rpython/l3interp/model.py
   pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py
Log:
(mwh, arre)
Implement setarrayitem + tests.


Modified: pypy/dist/pypy/rpython/l3interp/convertgraph.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/convertgraph.py	(original)
+++ pypy/dist/pypy/rpython/l3interp/convertgraph.py	Tue Jan 24 14:53:54 2006
@@ -152,6 +152,20 @@
 
             offset = ItemOffset(spaceop.result.concretetype)
             insns.append(getoffset(offset))
+        elif spaceop.opname == 'setarrayitem':
+            array, index, value = spaceop.args
+            opname = spaceop.opname + '_' + \
+                     getaccesskind(value.concretetype)
+            insns.append(model.very_low_level_opcode[opname])
+            insns.append(get(array))
+            insns.append(get(index))
+
+            offset = ArrayItemsOffset(array.concretetype)
+            insns.append(getoffset(offset))
+
+            offset = ItemOffset(value.concretetype)
+            insns.append(getoffset(offset))
+            insns.append(get(value))
         else:
             insns.append(model.very_low_level_opcode[spaceop.opname])
             for v in spaceop.args:

Modified: pypy/dist/pypy/rpython/l3interp/l3interp.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/l3interp.py	(original)
+++ pypy/dist/pypy/rpython/l3interp/l3interp.py	Tue Jan 24 14:53:54 2006
@@ -212,6 +212,30 @@
         v = (a + items_offset + s * i).signed[0]
         self.stack_int.append(v)
         
+    def op_getarrayitem_ptr(self):
+        a = self.getptr()
+        i = self.getint()
+        items_offset = self.getoffset()
+        s = self.getoffset()
+        v = (a + items_offset + s * i).address[0]
+        self.stack_ptr.append(v)
+        
+    def op_setarrayitem_int(self):
+        a = self.getptr()
+        i = self.getint()
+        items_offset = self.getoffset()
+        s = self.getoffset()
+        v = self.getint()
+        (a + items_offset + s * i).signed[0] = v
+        
+    def op_setarrayitem_ptr(self):
+        a = self.getptr()
+        i = self.getint()
+        items_offset = self.getoffset()
+        s = self.getoffset()
+        v = self.getptr()
+        (a + items_offset + s * i).address[0] = v
+        
     def op_flavored_malloc(self):
         self.stack_ptr.append(constant_fakeaddress)
 

Modified: pypy/dist/pypy/rpython/l3interp/model.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/model.py	(original)
+++ pypy/dist/pypy/rpython/l3interp/model.py	Tue Jan 24 14:53:54 2006
@@ -38,7 +38,8 @@
 
     #array operations:
     'getarrayitem_int', 'getarrayitem_ptr',
-    'getarraysize', 'getarraysubstruct', 'setarrayitem',
+    'getarraysize', 'getarraysubstruct',
+    'setarrayitem_int', ' setarrayitem_ptr',
 
     #struct operations:
     'getfield_int', 'getfield_char', 'getfield_dbl', 'getfield_ptr', 

Modified: pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py	(original)
+++ pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py	Tue Jan 24 14:53:54 2006
@@ -189,8 +189,8 @@
 
     fn = translate(entry_point, [int])
 
-    assert fn(-3) == 0
-    assert fn(0) == -3
+    assert fn(9) == 0
+    assert fn(0) == 9
 
 
         
@@ -266,3 +266,71 @@
     for arg in 0,1,2:
         assert fn(arg) == f(arg)
 
+def test_setitem():
+    from pypy.rpython.lltypesystem import lltype 
+
+    A = lltype.GcArray(lltype.Signed)
+    a = lltype.malloc(A, 3)
+    a[0] = 1
+    a[1] = 2
+    a[2] = 3
+    
+
+    def f(index, value):
+        if value:
+            a[index] = value
+            return 0
+        return a[index]
+
+    l3graph = l3ify(f, [int, int])
+    def entry_point(x, y):
+        value = l3interp.l3interpret(l3graph, [x, y], [], [])
+        assert isinstance(value, l3interp.L3Integer)
+        return value.intval
+
+    entry_point(1, 42)
+    assert entry_point(1, 0) == 42
+    
+    fn = translate(entry_point, [int, int])
+        
+    entry_point(1, 65)
+    assert entry_point(1, 0) == 65
+
+def test_getsetitem_complex():
+    from pypy.rpython.lltypesystem import lltype 
+
+    A = lltype.GcArray(lltype.Signed)
+    AA = lltype.GcArray(lltype.Ptr(A))
+    a = lltype.malloc(AA, 3)
+    a[0] = lltype.malloc(A, 1)
+    a[1] = lltype.malloc(A, 2)
+    a[2] = lltype.malloc(A, 3)
+    a[0][0] = 1
+
+    a[1][0] = 2
+    a[1][1] = 3
+
+    a[2][0] = 4
+    a[2][1] = 5
+    a[2][2] = 6
+
+    def f(x, y, value):
+        if value:
+            a[x][y] = value
+            return 0
+        return a[x][y]
+    
+    l3graph = l3ify(f, [int, int, int])
+    def entry_point(x, y, value):
+        value = l3interp.l3interpret(l3graph, [x, y, value], [], [])
+        assert isinstance(value, l3interp.L3Integer)
+        return value.intval
+
+    for x,y,value in (0,0,0), (0,0,9), (0,0,0), (2,1,0), (2,1,14), (2,1,0):
+        assert entry_point(x, y, value) == f(x, y, value)
+
+    
+    fn = translate(entry_point, [int, int, int])
+
+    for x,y,value in (0,0,0), (0,0,11), (0,0,0), (2,1,0), (2,1,26), (2,1,0):
+        assert fn(x, y, value) == f(x, y, value)



More information about the Pypy-commit mailing list