[pypy-svn] r47410 - in pypy/dist/pypy: rlib rpython rpython/lltypesystem rpython/test translator/c translator/c/src
arigo at codespeak.net
arigo at codespeak.net
Fri Oct 12 19:14:22 CEST 2007
Author: arigo
Date: Fri Oct 12 19:14:20 2007
New Revision: 47410
Modified:
pypy/dist/pypy/rlib/objectmodel.py
pypy/dist/pypy/rpython/llinterp.py
pypy/dist/pypy/rpython/lltypesystem/lloperation.py
pypy/dist/pypy/rpython/test/test_rbuiltin.py
pypy/dist/pypy/translator/c/funcgen.py
pypy/dist/pypy/translator/c/src/support.h
Log:
Introduce a symbolic and an operation: running_on_llinterp and
debug_llinterpcall. Together, they allow flow graphs to do
completely different things on top of the llinterp and in a
real backend.
Modified: pypy/dist/pypy/rlib/objectmodel.py
==============================================================================
--- pypy/dist/pypy/rlib/objectmodel.py (original)
+++ pypy/dist/pypy/rlib/objectmodel.py Fri Oct 12 19:14:20 2007
@@ -92,6 +92,8 @@
return lltype.Signed
malloc_zero_filled = CDefinedIntSymbolic('MALLOC_ZERO_FILLED', default=0)
+running_on_llinterp = CDefinedIntSymbolic('RUNNING_ON_LLINTERP', default=1)
+# running_on_llinterp is meant to have the value 0 in all backends
# ____________________________________________________________
@@ -145,6 +147,35 @@
hop.genop('debug_assert', vlist)
+def debug_llinterpcall(RESTYPE, pythonfunction, *args):
+ """When running on the llinterp, this causes the llinterp to call to
+ the provided Python function with the run-time value of the given args.
+ The Python function should return a low-level object of type RESTYPE.
+ This should never be called after translation: use this only if
+ running_on_llinterp is true.
+ """
+ raise NotImplementedError
+
+class Entry(ExtRegistryEntry):
+ _about_ = debug_llinterpcall
+
+ def compute_result_annotation(self, s_RESTYPE, s_pythonfunction, *args_s):
+ from pypy.annotation import model as annmodel
+ assert s_RESTYPE.is_constant()
+ assert s_pythonfunction.is_constant()
+ return annmodel.lltype_to_annotation(s_RESTYPE.const)
+
+ def specialize_call(self, hop):
+ from pypy.rpython.lltypesystem import lltype
+ RESTYPE= hop.args_s[0].const
+ pythonfunction = hop.args_s[1].const
+ c_pythonfunction = hop.inputconst(lltype.Void, pythonfunction)
+ args_v = [hop.inputarg(hop.args_r[i], arg=i)
+ for i in range(2, hop.nb_args)]
+ return hop.genop('debug_llinterpcall', [c_pythonfunction] + args_v,
+ resulttype=RESTYPE)
+
+
def hlinvoke(repr, llcallable, *args):
raise TypeError, "hlinvoke is meant to be rtyped and not called direclty"
Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py (original)
+++ pypy/dist/pypy/rpython/llinterp.py Fri Oct 12 19:14:20 2007
@@ -507,6 +507,9 @@
ll_exc_type = lltype.cast_pointer(rclass.OBJECTPTR, ll_exc).typeptr
raise LLFatalError(msg, LLException(ll_exc_type, ll_exc))
+ def op_debug_llinterpcall(self, pythonfunction, *args_ll):
+ return pythonfunction(*args_ll)
+
def op_instrument_count(self, ll_tag, ll_label):
pass # xxx for now
Modified: pypy/dist/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/lloperation.py Fri Oct 12 19:14:20 2007
@@ -440,6 +440,8 @@
'debug_pdb': LLOp(),
'debug_assert': LLOp(tryfold=True),
'debug_fatalerror': LLOp(),
+ 'debug_llinterpcall': LLOp(), # Python func call 'res=arg[0](*arg[1:])'
+ # in backends, abort() or whatever is fine
# __________ instrumentation _________
'instrument_count': LLOp(),
Modified: pypy/dist/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/test/test_rbuiltin.py Fri Oct 12 19:14:20 2007
@@ -1,6 +1,7 @@
from pypy.translator.translator import graphof
from pypy.rpython.test import test_llinterp
from pypy.rlib.objectmodel import instantiate, we_are_translated
+from pypy.rlib.objectmodel import running_on_llinterp, debug_llinterpcall
from pypy.rpython.lltypesystem import lltype
from pypy.tool import udir
from pypy.rlib.rarithmetic import r_uint, intmask
@@ -401,6 +402,26 @@
res = self.interpret(fn, [3.25])
assert res == 7.25
+ def test_debug_llinterpcall(self):
+ S = lltype.Struct('S', ('m', lltype.Signed))
+ SPTR = lltype.Ptr(S)
+ def foo(n):
+ "NOT_RPYTHON"
+ s = lltype.malloc(S, immortal=True)
+ s.m = eval("n*6", locals())
+ return s
+ def fn(n):
+ if running_on_llinterp:
+ return debug_llinterpcall(SPTR, foo, n).m
+ else:
+ return 321
+ res = self.interpret(fn, [7])
+ assert res == 42
+ from pypy.translator.c.test.test_genc import compile
+ f = compile(fn, [int])
+ res = f(7)
+ assert res == 321
+
class TestLLtype(BaseTestRbuiltin, LLRtypeMixin):
def test_isinstance_obj(self):
Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py (original)
+++ pypy/dist/pypy/translator/c/funcgen.py Fri Oct 12 19:14:20 2007
@@ -712,6 +712,9 @@
return 'fprintf(stderr, "%%s\\n", %s); abort();' % msg
+ def OP_DEBUG_LLINTERPCALL(self, op):
+ return 'abort(); /* debug_llinterpcall should be unreachable */'
+
def OP_INSTRUMENT_COUNT(self, op):
counter_label = op.args[1].value
self.db.instrument_ncounter = max(self.db.instrument_ncounter,
Modified: pypy/dist/pypy/translator/c/src/support.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/support.h (original)
+++ pypy/dist/pypy/translator/c/src/support.h Fri Oct 12 19:14:20 2007
@@ -9,6 +9,8 @@
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif /* MIN */
+#define RUNNING_ON_LLINTERP 0
+
#define FAIL_EXCEPTION(exc, msg) \
{ \
RPyRaiseSimpleException(exc, msg); \
More information about the Pypy-commit
mailing list