[pypy-svn] r45409 - in pypy/dist/pypy/rpython: . test
fijal at codespeak.net
fijal at codespeak.net
Fri Jul 27 19:01:19 CEST 2007
Author: fijal
Date: Fri Jul 27 19:01:17 2007
New Revision: 45409
Modified:
pypy/dist/pypy/rpython/extfunc.py
pypy/dist/pypy/rpython/test/test_extfunc.py
Log:
A first approach to lazily evaluate registration functions (to
avoid explosion at import time)
Modified: pypy/dist/pypy/rpython/extfunc.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunc.py (original)
+++ pypy/dist/pypy/rpython/extfunc.py Fri Jul 27 19:01:17 2007
@@ -4,7 +4,21 @@
from pypy.annotation.model import unionof
from pypy.annotation.signature import annotation
-import py
+import py, sys
+
+def lazy_register(func, register_func):
+ """ Lazily register external function. Will create a function,
+ which explodes when llinterpd/translated, but does not explode
+ earlier
+ """
+ try:
+ register_func()
+ except:
+ exc, exc_inst, tb = sys.exc_info()
+ class ExtRaisingEntry(ExtRegistryEntry):
+ _about_ = func
+ def compute_result_annotation(self, *args_s):
+ raise exc, exc_inst, tb
class genericcallable(object):
""" A way to specify the callable annotation, but deferred until
Modified: pypy/dist/pypy/rpython/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_extfunc.py (original)
+++ pypy/dist/pypy/rpython/test/test_extfunc.py Fri Jul 27 19:01:17 2007
@@ -1,6 +1,6 @@
from pypy.rpython.extfunc import ExtFuncEntry, register_external,\
- is_external
+ is_external, lazy_register
from pypy.annotation import model as annmodel
from pypy.annotation.annrpython import RPythonAnnotator
from pypy.annotation.policy import AnnotatorPolicy
@@ -154,12 +154,18 @@
s = a.build_types(f, [])
assert isinstance(s, annmodel.SomeString)
-#def test_is_external():
-# assert is_external(BTestFuncEntry)
-# def f():
-# pass
-# assert not is_external(f)
-# f.suggested_primitive = True
-# assert is_external(f)
-# f.suggested_primitive = False
-# assert not is_external(f)
+def test_lazy_register():
+ def f():
+ return 3
+
+ def g():
+ return f()
+
+ def reg_func():
+ 1/0
+
+ lazy_register(f, reg_func)
+
+ from pypy.rpython.test.test_llinterp import interpret
+
+ interpret(g, [])
More information about the Pypy-commit
mailing list