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

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Oct 15 19:22:47 CEST 2005


Author: cfbolz
Date: Sat Oct 15 19:22:45 2005
New Revision: 18653

Added:
   pypy/dist/pypy/rpython/test/test_ootype_llinterp.py
Modified:
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/test/test_llinterp.py
Log:
(bert, cfbolz):

extended the llinterpreter to understand some first operations of the ootype
system. test.


Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Sat Oct 15 19:22:45 2005
@@ -6,6 +6,7 @@
 from pypy.rpython.rmodel import getfunctionptr
 from pypy.rpython.memory import lladdress
 from pypy.rpython.objectmodel import free_non_gc_object
+from pypy.rpython.ootypesystem import ootype
 
 import math
 import py
@@ -619,6 +620,22 @@
         func = opimpls['ne']
         return func(x, y)
 
+    #Operation of ootype
+
+    def op_new(self, INST):
+        assert isinstance(INST, ootype.Instance)
+        return ootype.new(INST)
+
+    def op_oosetfield(self, inst, name, value):
+        assert isinstance(inst, ootype._instance)
+        assert isinstance(name, str)
+        setattr(inst, name, value)
+
+    def op_oogetfield(self, inst, name):
+        assert isinstance(inst, ootype._instance)
+        assert isinstance(name, str)
+        return getattr(inst, name)
+    
 # by default we route all logging messages to nothingness
 # e.g. tests can then switch on logging to get more help
 # for failing tests

Modified: pypy/dist/pypy/rpython/test/test_llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_llinterp.py	(original)
+++ pypy/dist/pypy/rpython/test/test_llinterp.py	Sat Oct 15 19:22:45 2005
@@ -19,7 +19,6 @@
 def teardown_module(mod):
     py.log._setstate(mod.logstate)
 
-
 def find_exception(exc, interp):
     assert isinstance(exc, LLException)
     import exceptions
@@ -41,7 +40,8 @@
     #print "%.2f secs" %(elapsed,)
     return res 
 
-def gengraph(func, argtypes=[], viewbefore=False, policy=None):
+def gengraph(func, argtypes=[], viewbefore=False, policy=None,
+             type_system="lltype"):
     t = Translator(func)
 
     timelog("annotating", t.annotate, argtypes, policy=policy)
@@ -49,7 +49,7 @@
         t.annotator.simplify()
         t.view()
     global typer # we need it for find_exception
-    typer = RPythonTyper(t.annotator)
+    typer = RPythonTyper(t.annotator, type_system=type_system)
     timelog("rtyper-specializing", typer.specialize) 
     #t.view()
     timelog("checking graphs", t.checkgraphs) 
@@ -57,7 +57,8 @@
 
 _lastinterpreted = []
 _tcache = {}
-def get_interpreter(func, values, view=False, viewbefore=False, policy=None, someobjects=False):
+def get_interpreter(func, values, view=False, viewbefore=False, policy=None,
+                    someobjects=False, type_system="lltype"):
     key = (func,) + tuple([typeOf(x) for x in values])+ (someobjects,)
     try: 
         (t, interp) = _tcache[key]
@@ -72,7 +73,8 @@
                 return lltype_to_annotation(T)
         
         t, typer = gengraph(func, [annotation(x)
-                      for x in values], viewbefore, policy)
+                                       for x in values],
+                            viewbefore, policy, type_system=type_system)
         interp = LLInterpreter(t.flowgraphs, typer)
         _tcache[key] = (t, interp)
         # keep the cache small 
@@ -84,14 +86,15 @@
     return interp
 
 def interpret(func, values, view=False, viewbefore=False, policy=None,
-              someobjects=False):
+              someobjects=False, type_system="lltype"):
     interp = get_interpreter(func, values, view, viewbefore, policy,
-                             someobjects)
+                             someobjects, type_system=type_system)
     return interp.eval_function(func, values)
 
-def interpret_raises(exc, func, values, view=False, viewbefore=False, policy=None, someobjects=False):
+def interpret_raises(exc, func, values, view=False, viewbefore=False,
+                     policy=None, someobjects=False, type_system="lltype"):
     interp = get_interpreter(func, values, view, viewbefore, policy,
-                             someobjects)
+                             someobjects, type_system=type_system)
     info = py.test.raises(LLException, "interp.eval_function(func, values)")
     assert find_exception(info.value, interp) is exc, "wrong exception type"
 

Added: pypy/dist/pypy/rpython/test/test_ootype_llinterp.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/test/test_ootype_llinterp.py	Sat Oct 15 19:22:45 2005
@@ -0,0 +1,14 @@
+from pypy.rpython.ootypesystem.ootype import *
+from pypy.rpython.test.test_llinterp import interpret
+
+def test_simple_field():
+    C = Instance("test", None, {'a': (Signed, 3)})
+    
+    def f():
+        c = new(C)
+        c.a = 5
+        return c.a
+
+    result = interpret(f, [], type_system="ootype")
+    assert result == 5
+ 



More information about the Pypy-commit mailing list