[pypy-svn] r7494 - in pypy/trunk/src/pypy: interpreter objspace/flow objspace/std translator

arigo at codespeak.net arigo at codespeak.net
Sat Nov 20 11:38:17 CET 2004


Author: arigo
Date: Sat Nov 20 11:38:17 2004
New Revision: 7494

Modified:
   pypy/trunk/src/pypy/interpreter/extmodule.py
   pypy/trunk/src/pypy/interpreter/gateway.py
   pypy/trunk/src/pypy/interpreter/pycode.py
   pypy/trunk/src/pypy/objspace/flow/objspace.py
   pypy/trunk/src/pypy/objspace/std/fake.py
   pypy/trunk/src/pypy/objspace/std/stdtypedef.py
   pypy/trunk/src/pypy/translator/genc.py
Log:
- next bunch of NOT_RPYTHON annotations.
- support for built-in methods in genc.py.



Modified: pypy/trunk/src/pypy/interpreter/extmodule.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/extmodule.py	(original)
+++ pypy/trunk/src/pypy/interpreter/extmodule.py	Sat Nov 20 11:38:17 2004
@@ -17,6 +17,10 @@
 class BuiltinModule(Module):
     """A Module subclass specifically for built-in modules."""
 
+    # '__builtins__' is stored in self.__dict__ by
+    # self.interplevel{exec,eval,execfile}()
+    NOT_RPYTHON_ATTRIBUTES = ['__builtins__']
+
     def __init__(self, space, modulename, w_dict=None, sourcefile=None):
         """Load the named built-in module, by default from the source file
         'pypy/module/<name>module.py', which is app-level Python code

Modified: pypy/trunk/src/pypy/interpreter/gateway.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/gateway.py	(original)
+++ pypy/trunk/src/pypy/interpreter/gateway.py	Sat Nov 20 11:38:17 2004
@@ -24,6 +24,7 @@
     # you get the functionality of CPython's built-in function type.
 
     def __init__(self, func, ismethod=None, spacearg=None):
+        "NOT_RPYTHON"
         # 'implfunc' is the interpreter-level function.
         # Note that this uses a lot of (construction-time) introspection.
         eval.Code.__init__(self, func.__name__)
@@ -176,6 +177,8 @@
         #   _staticglobals 
         #   _staticdefs 
 
+    NOT_RPYTHON_ATTRIBUTES = ['_staticglobals', '_staticdefs']
+
     def __spacebind__(self, space):
         # to wrap a Gateway, we first make a real Function object out of it
         # and the result is a wrapped version of this Function.
@@ -187,6 +190,7 @@
                                    self.getcache(space))
 
     def build_all_functions(self, space):
+        "NOT_RPYTHON"
         # the construction is supposed to be done only once in advance,
         # but must be done lazily when needed only, because
         #   1) it depends on the object space
@@ -216,6 +220,7 @@
         return space._gatewaycache 
 
     def _build_function(self, space, w_globals):
+        "NOT_RPYTHON"
         cache = self.getcache(space) 
         try: 
             return cache.content[self] 
@@ -243,6 +248,7 @@
 class app2interp(Gateway):
     """Build a Gateway that calls 'app' at app-level."""
     def __init__(self, app, app_name=None):
+        "NOT_RPYTHON"
         Gateway.__init__(self)
         # app must be a function whose name starts with 'app_'.
         if not isinstance(app, types.FunctionType):
@@ -259,6 +265,7 @@
         self._staticdefs = list(app.func_defaults or ())
 
     def getdefaults(self, space):
+        "NOT_RPYTHON"
         return [space.wrap(val) for val in self._staticdefs]
 
     def __call__(self, space, *args_w):
@@ -268,6 +275,7 @@
         return space.call_function(space.wrap(fn), *args_w)
 
     def __get__(self, obj, cls=None):
+        "NOT_RPYTHON"
         if obj is None:
             return self
         else:
@@ -280,6 +288,7 @@
 class interp2app(Gateway):
     """Build a Gateway that calls 'f' at interp-level."""
     def __init__(self, f, app_name=None):
+        "NOT_RPYTHON"
         Gateway.__init__(self)
         # f must be a function whose name does NOT starts with 'app_'
         if not isinstance(f, types.FunctionType):
@@ -295,10 +304,11 @@
         self._staticglobals = None
 
     def getdefaults(self, space):
+        "NOT_RPYTHON"
         return self._staticdefs
 
 def exportall(d, temporary=False):
-    """Publish every function from a dict."""
+    """NOT_RPYTHON: Publish every function from a dict."""
     if temporary:
         i2a = interp2app_temp
     else:
@@ -318,6 +328,7 @@
                 d['app_'+name] = i2a(obj, name)
 
 def export_values(space, dic, w_namespace):
+    "NOT_RPYTHON"
     for name, w_value in dic.items():
         if name.startswith('w_'):
             if name == 'w_dict':
@@ -329,7 +340,7 @@
             space.setitem(w_namespace, w_name, w_value)
 
 def importall(d, temporary=False):
-    """Import all app_-level functions as Gateways into a dict."""
+    """NOT_RPYTHON: Import all app_-level functions as Gateways into a dict."""
     if temporary:
         a2i = app2interp_temp
     else:
@@ -340,7 +351,8 @@
                 d[name[4:]] = a2i(obj, name[4:])
 
 def build_dict(d, space):
-    """Search all Gateways and put them into a wrapped dictionary."""
+    """NOT_RPYTHON:
+    Search all Gateways and put them into a wrapped dictionary."""
     w_globals = space.newdict([])
     for value in d.itervalues():
         if isinstance(value, Gateway):
@@ -356,12 +368,14 @@
 # 
 # the next gateways are to be used only for 
 # temporary/initialization purposes 
-class app2interp_temp(app2interp): 
+class app2interp_temp(app2interp):
+    "NOT_RPYTHON"
     def getcache(self, space): 
         return self.__dict__.setdefault(space, Cache())
         #                               ^^^^^
         #                          armin suggested this 
      
 class interp2app_temp(interp2app): 
+    "NOT_RPYTHON"
     def getcache(self, space): 
         return self.__dict__.setdefault(space, Cache())

Modified: pypy/trunk/src/pypy/interpreter/pycode.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/pycode.py	(original)
+++ pypy/trunk/src/pypy/interpreter/pycode.py	Sat Nov 20 11:38:17 2004
@@ -38,7 +38,8 @@
         self.co_lnotab = ""          # string: encoding addr<->lineno mapping
 
     def _from_code(self, code):
-        """ Initialize the code object from a real (CPython) one.
+        """ NOT_RPYTHON
+            Initialize the code object from a real (CPython) one.
             This is just a hack, until we have our own compile.
             At the moment, we just fake this.
             This method is called by our compile builtin function.

Modified: pypy/trunk/src/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/objspace.py	(original)
+++ pypy/trunk/src/pypy/objspace/flow/objspace.py	Sat Nov 20 11:38:17 2004
@@ -115,7 +115,7 @@
     def build_flow(self, func, constargs={}):
         """
         """
-        if func.func_doc and func.func_doc.startswith('NOT_RPYTHON'):
+        if func.func_doc and func.func_doc.lstrip().startswith('NOT_RPYTHON'):
             raise Exception, "%r is tagged as NOT_RPYTHON" % (func,)
         code = func.func_code
         code = PyCode()._from_code(code)

Modified: pypy/trunk/src/pypy/objspace/std/fake.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/fake.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/fake.py	Sat Nov 20 11:38:17 2004
@@ -37,6 +37,7 @@
     return _fake_type_cache.getorbuild(cpy_type, really_build_fake_type, None)
 
 def really_build_fake_type(cpy_type, ignored):
+    "NOT_RPYTHON (not remotely so!)."
     print 'faking %r'%(cpy_type,)
     kw = {}
     for s, v in cpy_type.__dict__.items():

Modified: pypy/trunk/src/pypy/objspace/std/stdtypedef.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/stdtypedef.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/stdtypedef.py	Sat Nov 20 11:38:17 2004
@@ -12,10 +12,12 @@
 class StdTypeDef(TypeDef):
 
     def __init__(self, __name, __base=None, **rawdict):
+        "NOT_RPYTHON: initialization-time only."
         TypeDef.__init__(self, __name, __base, **rawdict)
         self.local_multimethods = []
 
     def registermethods(self, namespace):
+        "NOT_RPYTHON: initialization-time only."
         self.local_multimethods += hack_out_multimethods(namespace)
 
 def issubtypedef(a, b):
@@ -30,6 +32,7 @@
 
 
 def newmethod(descr_new):
+    "NOT_RPYTHON: initialization-time only."
     # this is turned into a static method by the constructor of W_TypeObject.
     return gateway.interp2app(descr_new)
 
@@ -40,6 +43,7 @@
 #
 
 def buildtypeobject(typedef, space):
+    "NOT_RPYTHON: initialization-time only."
     # build a W_TypeObject from this StdTypeDef
     from pypy.objspace.std.typeobject import W_TypeObject
     from pypy.objspace.std.objecttype import object_typedef
@@ -76,6 +80,7 @@
                         overridetypedef=typedef, forcedict=False)
 
 def hack_out_multimethods(ns):
+    "NOT_RPYTHON: initialization-time only."
     result = []
     for value in ns.itervalues():
         if isinstance(value, MultiMethod):
@@ -115,6 +120,7 @@
     """A code object that invokes a multimethod."""
     
     def __init__(self, multimethod, framecls, typeclass, bound_position=0):
+        "NOT_RPYTHON: initialization-time only."
         eval.Code.__init__(self, multimethod.operatorsymbol)
         self.basemultimethod = multimethod
         self.typeclass = typeclass
@@ -131,6 +137,7 @@
         self.sig = argnames, varargname, kwargname
 
     def computeslice(self, space):
+        "NOT_RPYTHON: initialization-time only."
         if self.typeclass is None:
             slice = self.basemultimethod
         else:

Modified: pypy/trunk/src/pypy/translator/genc.py
==============================================================================
--- pypy/trunk/src/pypy/translator/genc.py	(original)
+++ pypy/trunk/src/pypy/translator/genc.py	Sat Nov 20 11:38:17 2004
@@ -196,7 +196,8 @@
                 print "NOT GENERATING", printable_name
                 return self.skipped_function(func)
         else:
-            if func.func_doc and func.func_doc.startswith('NOT_RPYTHON'):
+            if (func.func_doc and
+                func.func_doc.lstrip().startswith('NOT_RPYTHON')):
                 print "skipped", printable_name
                 return self.skipped_function(func)
             print "nameof", printable_name
@@ -243,8 +244,9 @@
     def should_translate_attr(self, pbc, attr):
         ann = self.translator.annotator
         if ann is None:
-            if attr.startswith('_'):
-                return False   # ignore _xyz and __xyz__ attributes
+            ignore = getattr(pbc.__class__, 'NOT_RPYTHON_ATTRIBUTES', [])
+            if attr in ignore:
+                return False
             else:
                 return "probably"   # True
         if attr in ann.getpbcattrs(pbc):
@@ -277,18 +279,28 @@
 
     def nameof_builtin_function_or_method(self, func):
         import __builtin__
-        assert func is getattr(__builtin__, func.__name__, None), (
-            '%r is not from __builtin__' % (func,))
-        name = self.uniquename('gbltin_' + func.__name__)
-        self.globaldecl.append('static PyObject* %s;' % name)
-        self.initcode.append('INITCHK(%s = PyMapping_GetItemString('
-                             'PyEval_GetBuiltins(), "%s"))' % (
-            name, func.__name__))
-        self.initglobals.append('REGISTER_GLOBAL(%s)' % (name,))
+        if func.__self__ is None:
+            # builtin function
+            assert func is getattr(__builtin__, func.__name__, None), (
+                '%r is not from __builtin__' % (func,))
+            name = self.uniquename('gbltin_' + func.__name__)
+            self.globaldecl.append('static PyObject* %s;' % name)
+            self.initcode.append('INITCHK(%s = PyMapping_GetItemString('
+                                 'PyEval_GetBuiltins(), "%s"))' % (
+                name, func.__name__))
+            self.initglobals.append('REGISTER_GLOBAL(%s)' % (name,))
+        else:
+            # builtin (bound) method
+            name = self.uniquename('gbltinmethod_' + func.__name__)
+            self.globaldecl.append('static PyObject* %s;' % name)
+            self.initcode.append('INITCHK(%s = PyObject_GetAttrString('
+                                 '%s, "%s"))' % (
+                name, self.nameof(func.__self__), func.__name__))
+            self.initglobals.append('REGISTER_GLOBAL(%s)' % (name,))
         return name
 
     def nameof_classobj(self, cls):
-        if cls.__doc__ and cls.__doc__.startswith('NOT_RPYTHON'):
+        if cls.__doc__ and cls.__doc__.lstrip().startswith('NOT_RPYTHON'):
             raise Exception, "%r should never be reached" % (cls,)
 
         if issubclass(cls, Exception):
@@ -465,7 +477,7 @@
             self.gen_cfunction(func)
             # collect more of the latercode after each function
             while self.latercode:
-                gen, self.debugstack = self.latercode.pop(0)
+                gen, self.debugstack = self.latercode.pop()
                 #self.initcode.extend(gen) -- eats TypeError! bad CPython!
                 for line in gen:
                     self.initcode.append(line)



More information about the Pypy-commit mailing list