[pypy-commit] pypy sepcomp2: Functions can be @exported without specifying argument types,
amauryfa
noreply at buildbot.pypy.org
Wed Feb 22 00:34:13 CET 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: sepcomp2
Changeset: r52748:ce2d7e8a1b42
Date: 2012-02-21 23:28 +0100
http://bitbucket.org/pypy/pypy/changeset/ce2d7e8a1b42/
Log: Functions can be @exported without specifying argument types, as
long as they are annotated in some other way.
diff --git a/pypy/translator/c/exportinfo.py b/pypy/translator/c/exportinfo.py
--- a/pypy/translator/c/exportinfo.py
+++ b/pypy/translator/c/exportinfo.py
@@ -1,4 +1,4 @@
-from pypy.annotation import description
+from pypy.annotation import model, description
from pypy.rpython.typesystem import getfunctionptr
from pypy.translator.tool.cbuild import ExternalCompilationInfo
from pypy.rpython.lltypesystem import lltype, rffi
@@ -70,6 +70,20 @@
complete_now=False)
annotator.complete()
+ # Ensure that functions without signature are not constant-folded
+ for funcname, func in self.functions.items():
+ if not hasattr(func, 'argtypes'):
+ # build a list of arguments where constants are erased
+ newargs = []
+ desc = bk.getdesc(func)
+ if isinstance(desc, description.FunctionDesc):
+ graph = desc.getuniquegraph()
+ for arg in graph.startblock.inputargs:
+ newarg = model.not_const(annotator.binding(arg))
+ newargs.append(newarg)
+ # and reflow
+ annotator.build_types(func, newargs)
+
def get_lowlevel_functions(self, annotator):
"""Builds a map of low_level objects."""
bk = annotator.bookkeeper
diff --git a/pypy/translator/c/test/test_export.py b/pypy/translator/c/test/test_export.py
--- a/pypy/translator/c/test/test_export.py
+++ b/pypy/translator/c/test/test_export.py
@@ -7,8 +7,11 @@
class TestExportFunctions:
def setup_method(self, method):
self.additional_PATH = []
+ # Uniquify: use the method name without the 'test' prefix.
+ self.module_suffix = method.__name__[4:]
def compile_module(self, modulename, **exports):
+ modulename += self.module_suffix
export_info = ModuleExportInfo()
for name, obj in exports.items():
export_info.add_function(name, obj)
@@ -51,3 +54,20 @@
secondmodule = self.compile_module("second", g=g)
assert secondmodule.g() == 54.3
+
+ def test_implied_signature(self):
+ @export # No explicit signature here.
+ def f(x):
+ return x + 1.5
+ @export() # This is an explicit signature, with no argument.
+ def f2():
+ f(1.0)
+ firstmodule = self.compile_module("first", f=f, f2=f2)
+
+ @export()
+ def g():
+ return firstmodule.f(41)
+ secondmodule = self.compile_module("second", g=g)
+
+ assert secondmodule.g() == 42.5
+
More information about the pypy-commit
mailing list