[pypy-svn] r20403 - in pypy/branch/somepbc-refactoring/pypy/translator/c: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Nov 29 17:22:34 CET 2005
Author: arigo
Date: Tue Nov 29 17:22:33 2005
New Revision: 20403
Modified:
pypy/branch/somepbc-refactoring/pypy/translator/c/pyobj.py
pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_notype.py
pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_operation.py
pypy/branch/somepbc-refactoring/pypy/translator/c/wrapper.py
Log:
Fixed the case of completely unannotated graphs in genc.
We are down to two failures...
Modified: pypy/branch/somepbc-refactoring/pypy/translator/c/pyobj.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/c/pyobj.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/c/pyobj.py Tue Nov 29 17:22:33 2005
@@ -160,15 +160,28 @@
self.initcode.append(' raise NotImplementedError')
return name
+ def shouldskipfunc(self, func):
+ if isinstance(func, (staticmethod, classmethod)):
+ func = func.__get__(42)
+ try: func = func.im_func
+ except AttributeError: pass
+ if isinstance(func, FunctionType):
+ ann = self.translator.annotator
+ if ann is None:
+ if (func.func_doc and
+ func.func_doc.lstrip().startswith('NOT_RPYTHON')):
+ return "NOT_RPYTHON" # True
+ else:
+ if not ann.bookkeeper.getdesc(func).querycallfamily():
+ return True
+ return False
+
def nameof_function(self, func):
assert self.translator is not None, (
"the Translator must be specified to build a PyObject "
"wrapper for %r" % (func,))
# look for skipped functions
- if not self.translator.annotator.bookkeeper.getdesc(func).querycallfamily():
- return self.skipped_function(func)
- if (func.func_doc and
- func.func_doc.lstrip().startswith('NOT_RPYTHON')):
+ if self.shouldskipfunc(func):
return self.skipped_function(func)
from pypy.translator.c.wrapper import gen_wrapper
@@ -311,20 +324,13 @@
continue
# XXX some __NAMES__ are important... nicer solution sought
#raise Exception, "unexpected name %r in class %s"%(key, cls)
- bk = self.translator.annotator.bookkeeper
- if isinstance(value, staticmethod) and not bk.getdesc(value.__get__(41)).querycallfamily():
- log.WARNING("skipped staticmethod: %s" % value)
- continue
- if isinstance(value, classmethod):
- doc = value.__get__(cls).__doc__
- if doc and doc.lstrip().startswith("NOT_RPYTHON"):
- continue
- if isinstance(value, FunctionType) and not bk.getdesc(value).querycallfamily():
- log.WARNING("skipped class function: %s" % value)
- continue
if key in ignore:
continue
-
+ skip = self.shouldskipfunc(value)
+ if skip:
+ if skip != 'NOT_RPYTHON':
+ log.WARNING("skipped class function: %r" % value)
+ continue
yield '%s.%s = %s' % (name, key, self.nameof(value))
baseargs = ", ".join(basenames)
Modified: pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_notype.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_notype.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_notype.py Tue Nov 29 17:22:33 2005
@@ -1,7 +1,7 @@
import autopath
from pypy.translator.tool.cbuild import skip_missing_compiler
-from pypy.translator.translator import Translator
-from pypy.objspace.flow import FlowObjSpace
+from pypy.translator.translator import TranslationContext
+from pypy.translator.c import genc
from pypy.translator.test import snippet
@@ -10,17 +10,15 @@
cbuild.enable_fast_compilation()
class TestNoTypeCGenTestCase:
- def setup_class(cls):
- cls.space = FlowObjSpace()
-
- def build_cfunc(self, func, *morefuncs):
+ def build_cfunc(self, func):
try: func = func.im_func
except AttributeError: pass
- t = Translator(func)
- for fn in morefuncs:
- t.getflowgraph(fn)
- t.simplify()
- return skip_missing_compiler(t.ccompile)
+ t = TranslationContext()
+ builder = genc.CExtModuleBuilder(t, func)
+ builder.generate_source()
+ skip_missing_compiler(builder.compile)
+ builder.import_module()
+ return builder.get_entry_point()
def test_simple_func(self):
cfunc = self.build_cfunc(snippet.simple_func)
@@ -154,8 +152,7 @@
assert call_with_keyword(100) == 82
def test_call_very_complex(self):
- call_very_complex = self.build_cfunc(snippet.call_very_complex,
- snippet.default_args)
+ call_very_complex = self.build_cfunc(snippet.call_very_complex)
assert call_very_complex(5, (3,), {}) == -12
assert call_very_complex(5, (), {'y': 3}) == -12
raises(TypeError, call_very_complex, 5, (3,), {'y': 4})
Modified: pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_operation.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_operation.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_operation.py Tue Nov 29 17:22:33 2005
@@ -1,9 +1,9 @@
import autopath
from pypy.objspace.flow.model import *
from pypy.objspace.flow.operation import FunctionByName
-from pypy.objspace.flow import FlowObjSpace
from pypy.translator.tool.cbuild import skip_missing_compiler
-from pypy.translator.translator import Translator
+from pypy.translator.translator import TranslationContext
+from pypy.translator.c import genc
# XXX this tries to make compiling faster for full-scale testing
from pypy.translator.tool import cbuild
@@ -96,15 +96,14 @@
class TestOperations:
- def setup_class(cls):
- cls.space = FlowObjSpace()
-
def build_cfunc(self, graph):
- t = Translator()
- t.entrypoint = operationtestfn
- t.functions.append(operationtestfn)
- t.flowgraphs[operationtestfn] = graph
- return skip_missing_compiler(t.ccompile)
+ t = TranslationContext()
+ t._prebuilt_graphs[operationtestfn] = graph
+ builder = genc.CExtModuleBuilder(t, operationtestfn)
+ builder.generate_source()
+ skip_missing_compiler(builder.compile)
+ builder.import_module()
+ return builder.get_entry_point()
def test_operations(self):
expected = []
Modified: pypy/branch/somepbc-refactoring/pypy/translator/c/wrapper.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/c/wrapper.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/c/wrapper.py Tue Nov 29 17:22:33 2005
@@ -24,9 +24,16 @@
nb_positional_args = func.func_code.co_argcount
vararg = bool(func.func_code.co_flags & CO_VARARGS)
- bk = translator.annotator.bookkeeper
+ if translator.annotator is None:
+ # get the graph from the translator, "push it back" so that it's
+ # still available for further buildflowgraph() calls
+ graph = translator.buildflowgraph(func)
+ translator._prebuilt_graphs[func] = graph
+ else:
+ bk = translator.annotator.bookkeeper
+ graph = bk.getdesc(func).cachedgraph(None)
- f = getfunctionptr(bk.getdesc(func).cachedgraph(None))
+ f = getfunctionptr(graph)
FUNCTYPE = typeOf(f).TO
assert len(FUNCTYPE.ARGS) == nb_positional_args + vararg
More information about the Pypy-commit
mailing list