[pypy-svn] r39409 - in pypy/dist/pypy/rpython: . test
fijal at codespeak.net
fijal at codespeak.net
Mon Feb 26 12:21:14 CET 2007
Author: fijal
Date: Mon Feb 26 12:21:12 2007
New Revision: 39409
Modified:
pypy/dist/pypy/rpython/extfunc.py
pypy/dist/pypy/rpython/test/test_extfunc.py
Log:
Add a possibility to specify None as args, which does not enforce arguments
for external functions. Note that than this is backend responsibility for
caring about arguments.
Modified: pypy/dist/pypy/rpython/extfunc.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunc.py (original)
+++ pypy/dist/pypy/rpython/extfunc.py Mon Feb 26 12:21:12 2007
@@ -5,6 +5,7 @@
from pypy.annotation.model import unionof
from pypy.annotation.signature import annotation
from pypy.annotation import model as annmodel
+import py
class _callable(object):
""" A way to specify the callable annotation, but deferred until
@@ -25,16 +26,21 @@
class ExtFuncEntry(ExtRegistryEntry):
def compute_result_annotation(self, *args_s):
- assert len(args_s) == len(self.signature_args),\
- "Argument number mismatch"
- for arg, expected in zip(args_s, self.signature_args):
- arg = unionof(arg, expected)
- assert expected.contains(arg)
+ if self.signature_args is not None:
+ assert len(args_s) == len(self.signature_args),\
+ "Argument number mismatch"
+ for arg, expected in zip(args_s, self.signature_args):
+ arg = unionof(arg, expected)
+ assert expected.contains(arg)
return self.signature_result
def specialize_call(self, hop):
rtyper = hop.rtyper
- args_r = [rtyper.getrepr(s_arg) for s_arg in self.signature_args]
+ if self.signature_args is None:
+ iter_args = hop.args_s
+ else:
+ iter_args = self.signature_args
+ args_r = [rtyper.getrepr(s_arg) for s_arg in iter_args]
args_ll = [r_arg.lowleveltype for r_arg in args_r]
r_result = rtyper.getrepr(self.signature_result)
ll_result = r_result.lowleveltype
@@ -56,7 +62,10 @@
class FunEntry(ExtFuncEntry):
_about_ = function
- signature_args = [annotation(arg) for arg in args]
+ if args is None:
+ signature_args = None
+ else:
+ signature_args = [annotation(arg) for arg in args]
signature_result = annotation(result)
name=export_name
if llimpl:
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 Mon Feb 26 12:21:12 2007
@@ -1,5 +1,6 @@
-from pypy.rpython.extfunc import ExtFuncEntry, _callable, register_external
+from pypy.rpython.extfunc import ExtFuncEntry, _callable, register_external,\
+ is_external
from pypy.annotation import model as annmodel
from pypy.annotation.annrpython import RPythonAnnotator
from pypy.annotation.policy import AnnotatorPolicy
@@ -113,3 +114,28 @@
# Not a very good assertion, but at least it means _something_ happened.
assert isinstance(s, annmodel.SomeInteger)
+
+def function_withspecialcase(arg):
+ return repr(arg)
+register_external(function_withspecialcase, args=None, result=str)
+
+def test_register_external_specialcase():
+ def f():
+ x = function_withspecialcase
+ return x(33) + x("aaa") + x([]) + "\n"
+
+ policy = AnnotatorPolicy()
+ policy.allow_someobjects = False
+ a = RPythonAnnotator(policy=policy)
+ 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)
More information about the Pypy-commit
mailing list