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

mwh at codespeak.net mwh at codespeak.net
Mon Jan 23 19:27:33 CET 2006


Author: mwh
Date: Mon Jan 23 19:27:30 2006
New Revision: 22546

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:
(arre,mwh)
A test and support for the l3 operation 'setfield_int'.
We were *extremely* surprised that this passed when it did :)


Modified: pypy/dist/pypy/rpython/l3interp/convertgraph.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/convertgraph.py	(original)
+++ pypy/dist/pypy/rpython/l3interp/convertgraph.py	Mon Jan 23 19:27:30 2006
@@ -125,6 +125,22 @@
                 res = len(clist)
                 clist.append(offset)
             insns.append(res)
+        elif spaceop.opname == 'setfield':
+            v0, v1, v2 = spaceop.args
+            opname = spaceop.opname + '_' + \
+                     getaccesskind(v2.concretetype)
+            insns.append(model.very_low_level_opcode[opname])
+            insns.append(get(v0))
+
+            offset = OffsetOf(v0.concretetype, v1.value)
+            clist = constants['offset']
+            try:
+                res = clist.index(offset)
+            except ValueError:
+                res = len(clist)
+                clist.append(offset)
+            insns.append(res)
+            insns.append(get(v2))
         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	Mon Jan 23 19:27:30 2006
@@ -193,6 +193,12 @@
         o = self.getoffset()
         self.stack_int.append((p + o).signed[0])
 
+    def op_setfield_int(self):
+        p = self.getptr()
+        o = self.getoffset()
+        v = self.getint()
+        (p + o).signed[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	Mon Jan 23 19:27:30 2006
@@ -41,7 +41,8 @@
 
     #struct operations:
     'getfield_int', 'getfield_char', 'getfield_dbl', 'getfield_ptr', 
-    'getsubstruct', 'setfield', 
+    'getsubstruct',
+    'setfield_int', 'setfield_char', 'setfield_dbl', 'setfield_ptr',
 
     #integer operations:
     'int_abs', 'int_abs_ovf', 'int_add', 'int_add_ovf', 'int_and',

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	Mon Jan 23 19:27:30 2006
@@ -155,8 +155,42 @@
         assert isinstance(value, l3interp.L3Integer)
         return value.intval
 
+    assert entry_point(3) == f(3)
+    assert entry_point(0) == f(0)
+
     fn = translate(entry_point, [int])
 
     assert fn(3) == f(3)
     assert fn(0) == f(0)
         
+
+def test_setfield():
+    class C:
+        def __init__(self, x):
+            self.x = x
+    c = C(1)
+
+    def getorset(n):
+        if n:
+            c.x = n
+            return 0
+        else:
+            return c.x
+
+    getorsetgraph = l3ify(getorset, [int])
+    
+    def entry_point(x):
+        value = l3interp.l3interpret(getorsetgraph, [x], [], [])
+        assert isinstance(value, l3interp.L3Integer)
+        return value.intval
+    
+    assert entry_point(-3) == 0
+    assert entry_point(0) == -3
+
+    fn = translate(entry_point, [int])
+
+    assert fn(-3) == 0
+    assert fn(0) == -3
+
+
+        



More information about the Pypy-commit mailing list