[pypy-svn] r73009 - in pypy/branch/cpython-extension/pypy: config rlib translator translator/c translator/c/test
xoraxax at codespeak.net
xoraxax at codespeak.net
Sun Mar 28 01:44:38 CET 2010
Author: xoraxax
Date: Sun Mar 28 01:44:37 2010
New Revision: 73009
Added:
pypy/branch/cpython-extension/pypy/rlib/entrypoint.py (contents, props changed)
Modified:
pypy/branch/cpython-extension/pypy/config/translationoption.py
pypy/branch/cpython-extension/pypy/translator/c/genc.py
pypy/branch/cpython-extension/pypy/translator/c/test/test_genc.py
pypy/branch/cpython-extension/pypy/translator/driver.py
Log:
Implement support for secondary entrypoints.
Modified: pypy/branch/cpython-extension/pypy/config/translationoption.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/config/translationoption.py (original)
+++ pypy/branch/cpython-extension/pypy/config/translationoption.py Sun Mar 28 01:44:37 2010
@@ -138,6 +138,9 @@
ArbitraryOption("instrumentctl", "internal",
default=None),
StrOption("output", "Output file name", cmdline="--output"),
+ StrOption("secondaryentrypoints",
+ "Comma separated list of keys choosing secondary entrypoints",
+ cmdline="--entrypoints", default=""),
BoolOption("dump_static_data_info", "Dump static data info",
cmdline="--dump_static_data_info",
Added: pypy/branch/cpython-extension/pypy/rlib/entrypoint.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/rlib/entrypoint.py Sun Mar 28 01:44:37 2010
@@ -0,0 +1,11 @@
+secondary_entrypoints = {}
+
+
+def entrypoint(key, argtypes, c_name=None):
+ def deco(func):
+ secondary_entrypoints.setdefault(key, []).append((func, argtypes))
+ if c_name is not None:
+ func.c_name = c_name
+ return func
+ return deco
+
Modified: pypy/branch/cpython-extension/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/genc.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/genc.py Sun Mar 28 01:44:37 2010
@@ -103,7 +103,8 @@
modulename = None
split = False
- def __init__(self, translator, entrypoint, config, gcpolicy=None):
+ def __init__(self, translator, entrypoint, config, gcpolicy=None,
+ secondary_entrypoints=()):
self.translator = translator
self.entrypoint = entrypoint
self.entrypoint_name = getattr(self.entrypoint, 'func_name', None)
@@ -113,6 +114,7 @@
if gcpolicy is not None and gcpolicy.requires_stackless:
config.translation.stackless = True
self.eci = self.get_eci()
+ self.secondary_entrypoints = secondary_entrypoints
def get_eci(self):
pypy_include_dir = py.path.local(autopath.pypydir).join('translator', 'c')
@@ -159,6 +161,11 @@
self.c_entrypoint_name = None
else:
pfname = db.get(pf)
+
+ for func, _ in self.secondary_entrypoints:
+ bk = translator.annotator.bookkeeper
+ db.get(getfunctionptr(bk.getdesc(func).getuniquegraph()))
+
self.c_entrypoint_name = pfname
db.complete()
Modified: pypy/branch/cpython-extension/pypy/translator/c/test/test_genc.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/test/test_genc.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/test/test_genc.py Sun Mar 28 01:44:37 2010
@@ -12,6 +12,7 @@
from pypy.translator.gensupp import uniquemodulename
from pypy.translator.backendopt.all import backend_optimizations
from pypy.translator.interactive import Translation
+from pypy.rlib.entrypoint import entrypoint
def compile(fn, argtypes, view=False, gcpolicy="ref", backendopt=True,
annotatorpolicy=None):
@@ -396,3 +397,20 @@
if py.test.config.option.view:
t.view()
assert 'pypy_xyz_f' in t.driver.cbuilder.c_source_filename.read()
+
+def test_entrypoints():
+ def f():
+ return 3
+
+ key = "test_entrypoints42"
+ @entrypoint(key, [int], "foobar")
+ def g(x):
+ return x + 42
+
+ t = Translation(f, [], backend="c", secondaryentrypoints="test_entrypoints42")
+ t.annotate()
+ compiled_fn = t.compile_c()
+ if py.test.config.option.view:
+ t.view()
+ assert 'foobar' in t.driver.cbuilder.c_source_filename.read()
+
Modified: pypy/branch/cpython-extension/pypy/translator/driver.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/driver.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/driver.py Sun Mar 28 01:44:37 2010
@@ -12,6 +12,7 @@
import optparse
from pypy.tool.udir import udir
from pypy.rlib.jit import DEBUG_OFF, DEBUG_DETAILED, DEBUG_PROFILE, DEBUG_STEPS
+from pypy.rlib.entrypoint import secondary_entrypoints
import py
from pypy.tool.ansi_print import ansi_log
@@ -210,12 +211,22 @@
self.entry_point = entry_point
self.translator = translator
self.libdef = None
+ self.secondary_entrypoints = []
+ for key in self.config.translation.secondaryentrypoints.split(","):
+ try:
+ points = secondary_entrypoints[key]
+ except KeyError:
+ raise KeyError("Entrypoints not found. I only know the keys %r." %
+ (", ".join(secondary_entrypoints.keys()), ))
+ self.secondary_entrypoints.extend(points)
self.translator.driver_instrument_result = self.instrument_result
def setup_library(self, libdef, policy=None, extra={}, empty_translator=None):
+ """ Used by carbon python only. """
self.setup(None, None, policy, extra, empty_translator)
self.libdef = libdef
+ self.secondary_entrypoints = libdef.functions
def instrument_result(self, args):
backend, ts = self.get_backend_and_type_system()
@@ -305,20 +316,21 @@
if self.entry_point:
s = annotator.build_types(self.entry_point, self.inputtypes)
- self.sanity_check_annotation()
- if self.standalone and s.knowntype != int:
- raise Exception("stand-alone program entry point must return an "
- "int (and not, e.g., None or always raise an "
- "exception).")
- annotator.simplify()
- return s
else:
- assert self.libdef is not None
- for func, inputtypes in self.libdef.functions:
- annotator.build_types(func, inputtypes)
- func.c_name = func.func_name
- self.sanity_check_annotation()
- annotator.simplify()
+ s = None
+ if self.secondary_entrypoints is not None:
+ for func, inputtypes in self.secondary_entrypoints:
+ if inputtypes == Ellipsis:
+ continue
+ rettype = annotator.build_types(func, inputtypes)
+
+ self.sanity_check_annotation()
+ if self.entry_point and self.standalone and s.knowntype != int:
+ raise Exception("stand-alone program entry point must return an "
+ "int (and not, e.g., None or always raise an "
+ "exception).")
+ annotator.simplify()
+
#
task_annotate = taskdef(task_annotate, [], "Annotating&simplifying")
@@ -453,7 +465,8 @@
else:
from pypy.translator.c.genc import CExtModuleBuilder as CBuilder
cbuilder = CBuilder(self.translator, self.entry_point,
- config=self.config)
+ config=self.config,
+ secondary_entrypoints=self.secondary_entrypoints)
cbuilder.stackless = self.config.translation.stackless
if not standalone: # xxx more messy
cbuilder.modulename = self.extmod_name
More information about the Pypy-commit
mailing list