[pypy-svn] r10351 - in pypy/dist/pypy: interpreter interpreter/test module/builtin module/sys2 objspace/std translator

tismer at codespeak.net tismer at codespeak.net
Tue Apr 5 22:02:50 CEST 2005


Author: tismer
Date: Tue Apr  5 22:02:50 2005
New Revision: 10351

Modified:
   pypy/dist/pypy/interpreter/gateway.py
   pypy/dist/pypy/interpreter/pyframe.py
   pypy/dist/pypy/interpreter/pyopcode.py
   pypy/dist/pypy/interpreter/test/test_appinterp.py
   pypy/dist/pypy/module/builtin/app_complex.py
   pypy/dist/pypy/module/builtin/app_descriptor.py
   pypy/dist/pypy/module/builtin/app_functional.py
   pypy/dist/pypy/module/builtin/app_help.py
   pypy/dist/pypy/module/builtin/app_inspect.py
   pypy/dist/pypy/module/builtin/app_io.py
   pypy/dist/pypy/module/builtin/operation.py
   pypy/dist/pypy/module/sys2/app.py
   pypy/dist/pypy/objspace/std/dictobject.py
   pypy/dist/pypy/objspace/std/dicttype.py
   pypy/dist/pypy/objspace/std/floatobject.py
   pypy/dist/pypy/objspace/std/listobject.py
   pypy/dist/pypy/objspace/std/listtype.py
   pypy/dist/pypy/objspace/std/objecttype.py
   pypy/dist/pypy/objspace/std/sliceobject.py
   pypy/dist/pypy/objspace/std/slicetype.py
   pypy/dist/pypy/objspace/std/stringobject.py
   pypy/dist/pypy/objspace/std/tupleobject.py
   pypy/dist/pypy/objspace/std/typeobject.py
   pypy/dist/pypy/translator/geninterplevel.py
Log:
translated almost all possible code pieces to interp level.

reversed the change to applevelinterp in the source files.

applevel is now a function that figures out whether it can
translate the code or not.
All code snippets have been inspected for translatability
and marked with NOT_RPYTHON if necessary.
Some can be easily enabled, some are hard (using yield)

Modified: pypy/dist/pypy/interpreter/gateway.py
==============================================================================
--- pypy/dist/pypy/interpreter/gateway.py	(original)
+++ pypy/dist/pypy/interpreter/gateway.py	Tue Apr  5 22:02:50 2005
@@ -479,7 +479,7 @@
 # and now for something completely different ... 
 #
 
-class applevel:
+class ApplevelClass:
     """A container for app-level source code that should be executed
     as a module in the object space;  interphook() builds a static
     interp-level function that invokes the callable with the given
@@ -496,7 +496,7 @@
             self.code = compile(source, filename, 'exec') 
         
     def getwdict(self, space):
-        return space.loadfromcache(self, applevel._builddict,
+        return space.loadfromcache(self, self.__class__._builddict,
                                    space._gatewaycache)
 
     def buildmodule(self, space, name='applevel'):
@@ -536,7 +536,7 @@
     def _freeze_(self):
         return True  # hint for the annotator: applevel instances are constants
 
-class applevelinterp(applevel):
+class ApplevelInterpClass(ApplevelClass):
     """ similar to applevel, but using translation to interp-level.
     """
     NOT_RPYTHON_ATTRIBUTES = []
@@ -548,10 +548,6 @@
         self.modname = modname
         self.do_imports = do_imports
 
-    def getwdict(self, space):
-        return space.loadfromcache(self, applevelinterp._builddict,
-                                   space._gatewaycache)
-
     def _builddict(self, space):
         "NOT_RPYTHON"
         from pypy.translator.geninterplevel import translate_as_module
@@ -560,10 +556,20 @@
         w_glob = initfunc(space)
         return w_glob
 
+def applevel(source, filename = None,
+                   modname = 'applevelinterp', do_imports=False):
+    # look at the first three lines
+    first = source.split("\n", 3)[:3]
+    klass = ApplevelInterpClass
+    for line in first:
+        if "NOT_RPYTHON" in line:
+            klass = ApplevelClass
+    return klass(source, filename, modname, do_imports)
+
 # comment this out to check against applevel without translation
-##applevelinterp = applevel
+##ApplevelInterpClass = ApplevelClass
 
-def appdef(source, applevel=applevel):
+def appdef(source, applevel=ApplevelClass):
     """ NOT_RPYTHON: build an app-level helper function, like for example:
     myfunc = appdef('''myfunc(x, y):
                            return x+y
@@ -583,13 +589,12 @@
 app2interp = appdef   # backward compatibility
 
 
-# the following two will probably get merged into one
-class applevel_temp(applevel):
+class applevel_temp(ApplevelClass):
     hidden_applevel = False
     def getwdict(self, space):
         return self._builddict(space)   # no cache
 
-class applevelinterp_temp(applevelinterp):
+class applevelinterp_temp(ApplevelInterpClass):
     hidden_applevel = False
     def getwdict(self, space):
         return self._builddict(space)   # no cache

Modified: pypy/dist/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyframe.py	(original)
+++ pypy/dist/pypy/interpreter/pyframe.py	Tue Apr  5 22:02:50 2005
@@ -419,7 +419,7 @@
 import types, __builtin__
 __builtin__._classobj = types.ClassType
 
-app = gateway.applevelinterp('''
+app = gateway.applevel('''
     def normalize_exception(etype, value, tb):
         """Normalize an (exc_type, exc_value) pair:
         exc_value will be an exception instance and exc_type its class.

Modified: pypy/dist/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyopcode.py	(original)
+++ pypy/dist/pypy/interpreter/pyopcode.py	Tue Apr  5 22:02:50 2005
@@ -740,6 +740,7 @@
 # class above.
 
 app = gateway.applevel(r'''
+    # NOT_RPYTHON   (but should be, soon)
 
     import sys
 

Modified: pypy/dist/pypy/interpreter/test/test_appinterp.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_appinterp.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_appinterp.py	Tue Apr  5 22:02:50 2005
@@ -1,6 +1,6 @@
 
 import py
-from pypy.interpreter.gateway import appdef, applevel, applevelinterp
+from pypy.interpreter.gateway import appdef, ApplevelClass, ApplevelInterpClass
 
 def test_execwith_novars(space): 
     val = space.appexec([], """ 
@@ -70,7 +70,7 @@
     w_result = app(space) 
     assert space.eq_w(w_result, space.wrap(42))
 
-def test_applevel_functions(space, applevel=applevel):
+def test_applevel_functions(space, applevel=ApplevelClass):
     app = applevel('''
         def f(x, y):
             return x-y
@@ -82,9 +82,9 @@
     assert space.eq_w(w_res, space.wrap(-9))
 
 def test_applevelinterp_functions(space):
-    test_applevel_functions(space, applevel=applevelinterp)
+    test_applevel_functions(space, applevel=ApplevelInterpClass)
 
-def test_applevel_class(space, applevel=applevel):
+def test_applevel_class(space, applevel=ApplevelClass):
     app = applevel('''
         class C: 
             clsattr = 42 
@@ -99,7 +99,7 @@
     assert space.eq_w(w_clsattr, space.wrap(17))
 
 def test_applevelinterp_class(space):
-    test_applevel_class(space, applevel=applevelinterp)
+    test_applevel_class(space, applevel=ApplevelInterpClass)
 
 def app_test_something_at_app_level(): 
     x = 2

Modified: pypy/dist/pypy/module/builtin/app_complex.py
==============================================================================
--- pypy/dist/pypy/module/builtin/app_complex.py	(original)
+++ pypy/dist/pypy/module/builtin/app_complex.py	Tue Apr  5 22:02:50 2005
@@ -1,3 +1,4 @@
+# NOT_RPYTHON yet
 """
 Plain Python definition of the 'complex' type.
 """

Modified: pypy/dist/pypy/module/builtin/app_descriptor.py
==============================================================================
--- pypy/dist/pypy/module/builtin/app_descriptor.py	(original)
+++ pypy/dist/pypy/module/builtin/app_descriptor.py	Tue Apr  5 22:02:50 2005
@@ -1,3 +1,5 @@
+# NOT_RPYTHON  -- there is a problem with initialising a property's __doc__
+# XXX but it *should* work
 """
 Plain Python definition of the builtin descriptors.
 """
@@ -27,10 +29,11 @@
     def __get__(self, obj, klass=None):
         if klass is None:
             klass = type(obj)
-        def newfunc(*args, **kwargs):
-            return self._f(klass, *args, **kwargs)
-        return newfunc
+        return MethodType(self._f, klass)
 
+def dummy(): pass
+MethodType = type(dummy.__get__(42))
+del dummy
 
 # It's difficult to have a class that has both a docstring and a slot called
 # '__doc__', but not impossible...

Modified: pypy/dist/pypy/module/builtin/app_functional.py
==============================================================================
--- pypy/dist/pypy/module/builtin/app_functional.py	(original)
+++ pypy/dist/pypy/module/builtin/app_functional.py	Tue Apr  5 22:02:50 2005
@@ -1,3 +1,4 @@
+# NOT_RPYTHON because yield is used
 """
 Plain Python definition of the builtin functions oriented towards
 functional programming.

Modified: pypy/dist/pypy/module/builtin/app_help.py
==============================================================================
--- pypy/dist/pypy/module/builtin/app_help.py	(original)
+++ pypy/dist/pypy/module/builtin/app_help.py	Tue Apr  5 22:02:50 2005
@@ -1,3 +1,5 @@
+# NOT_RPYTHON    - because print is used
+# XXX work on enabling print for flow space
 """
 Plain Python definition of the builtin interactive help functions.
 """

Modified: pypy/dist/pypy/module/builtin/app_inspect.py
==============================================================================
--- pypy/dist/pypy/module/builtin/app_inspect.py	(original)
+++ pypy/dist/pypy/module/builtin/app_inspect.py	Tue Apr  5 22:02:50 2005
@@ -102,33 +102,6 @@
         return local_names
 
     import types
-    def _classdir(klass):
-        """Return a dict of the accessible attributes of class/type klass.
-
-        This includes all attributes of klass and all of the
-        base classes recursively.
-
-        The values of this dict have no meaning - only the keys have
-        meaning.  
-        """
-        Dict = {}
-        try:
-            Dict.update(klass.__dict__)
-        except AttributeError: pass 
-        try:
-            # XXX - Use of .__mro__ would be suggested, if the existance
-            #   of that attribute could be guarranted.
-            bases = klass.__bases__
-        except AttributeError: pass
-        else:
-            try:
-                #Note that since we are only interested in the keys,
-                #  the order we merge classes is unimportant
-                for base in bases:
-                    Dict.update(_classdir(base))
-            except TypeError: pass
-        return Dict
-    #End _classdir
 
     obj = args[0]
 
@@ -169,3 +142,30 @@
         result = Dict.keys()
         result.sort()
         return result
+
+def _classdir(klass):
+    """Return a dict of the accessible attributes of class/type klass.
+
+    This includes all attributes of klass and all of the
+    base classes recursively.
+
+    The values of this dict have no meaning - only the keys have
+    meaning.  
+    """
+    Dict = {}
+    try:
+        Dict.update(klass.__dict__)
+    except AttributeError: pass 
+    try:
+        # XXX - Use of .__mro__ would be suggested, if the existance
+        #   of that attribute could be guarranted.
+        bases = klass.__bases__
+    except AttributeError: pass
+    else:
+        try:
+            #Note that since we are only interested in the keys,
+            #  the order we merge classes is unimportant
+            for base in bases:
+                Dict.update(_classdir(base))
+        except TypeError: pass
+    return Dict

Modified: pypy/dist/pypy/module/builtin/app_io.py
==============================================================================
--- pypy/dist/pypy/module/builtin/app_io.py	(original)
+++ pypy/dist/pypy/module/builtin/app_io.py	Tue Apr  5 22:02:50 2005
@@ -1,3 +1,4 @@
+# NOT_RPYTHON (but maybe soon)
 """
 Plain Python definition of the builtin I/O-related functions.
 """

Modified: pypy/dist/pypy/module/builtin/operation.py
==============================================================================
--- pypy/dist/pypy/module/builtin/operation.py	(original)
+++ pypy/dist/pypy/module/builtin/operation.py	Tue Apr  5 22:02:50 2005
@@ -71,7 +71,8 @@
 
 # ____________________________________________________________
 
-app = gateway.applevel('''
+iter_sentinel = gateway.applevel('''
+    # NOT_RPYTHON  -- uses yield
     # App-level implementation of the iter(callable,sentinel) operation.
 
     def iter_generator(callable_, sentinel):
@@ -86,8 +87,7 @@
             raise TypeError, 'iter(v, w): v must be callable'
         return iter_generator(callable_, sentinel)
 
-''')
-iter_sentinel = app.interphook("iter_sentinel")
+''').interphook("iter_sentinel")
 
 def iter(space, w_collection_or_callable, w_sentinel=NoneNotWrapped):
     if w_sentinel is None:

Modified: pypy/dist/pypy/module/sys2/app.py
==============================================================================
--- pypy/dist/pypy/module/sys2/app.py	(original)
+++ pypy/dist/pypy/module/sys2/app.py	Tue Apr  5 22:02:50 2005
@@ -1,3 +1,6 @@
+# NOT_RPYTHON   -- flowing results in
+# AttributeError:   << 'FlowObjSpace' object has no attribute 'w_AttributeError'
+# XXX investigate!
 """
 The 'sys' module.
 """

Modified: pypy/dist/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictobject.py	(original)
+++ pypy/dist/pypy/objspace/std/dictobject.py	Tue Apr  5 22:02:50 2005
@@ -242,7 +242,7 @@
     else:
         return w_default
 
-app = gateway.applevelinterp('''
+app = gateway.applevel('''
     def dictstr(currently_in_repr, d):
         # Now we only handle one implementation of dicts, this one.
         # The fix is to move this to dicttype.py, and do a

Modified: pypy/dist/pypy/objspace/std/dicttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dicttype.py	(original)
+++ pypy/dist/pypy/objspace/std/dicttype.py	Tue Apr  5 22:02:50 2005
@@ -21,7 +21,7 @@
 
 # default application-level implementations for some operations
 # gateway is imported in the stdtypedef module
-app = gateway.applevelinterp('''
+app = gateway.applevel('''
 
     def update(d, o):
         for k in o.keys():

Modified: pypy/dist/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/floatobject.py	(original)
+++ pypy/dist/pypy/objspace/std/floatobject.py	Tue Apr  5 22:02:50 2005
@@ -56,7 +56,7 @@
 def float_w__Float(space, w_float):
     return w_float.floatval
 
-app = gateway.applevelinterp(''' 
+app = gateway.applevel(''' 
     def repr__Float(f):
         r = "%.17g"%f
         for c in r:

Modified: pypy/dist/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listobject.py	(original)
+++ pypy/dist/pypy/objspace/std/listobject.py	Tue Apr  5 22:02:50 2005
@@ -305,7 +305,7 @@
         items[start+i*step] = sequence2[i]
     return space.w_None
 
-app = gateway.applevelinterp("""
+app = gateway.applevel("""
     def listrepr(currently_in_repr, l):
         'The app-level part of repr().'
         list_id = id(l)

Modified: pypy/dist/pypy/objspace/std/listtype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listtype.py	(original)
+++ pypy/dist/pypy/objspace/std/listtype.py	Tue Apr  5 22:02:50 2005
@@ -15,15 +15,15 @@
 list_reversed = MultiMethod('__reversed__', 1)
 
 # gateway is imported in the stdtypedef module
-app = gateway.applevel('''
+list_reversed__ANY = gateway.applevel('''
+    # NOT_RPYTHON -- uses yield
 
     def reversed(lst):
         for index in range(len(lst)-1, -1, -1):
             yield lst[index]
 
-''')
+''').interphook('reversed')
 
-list_reversed__ANY = app.interphook('reversed')
 register_all(vars(), globals())
 
 # ____________________________________________________________

Modified: pypy/dist/pypy/objspace/std/objecttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objecttype.py	(original)
+++ pypy/dist/pypy/objspace/std/objecttype.py	Tue Apr  5 22:02:50 2005
@@ -61,7 +61,7 @@
     w_proto = space.wrap(proto)
     return reduce_1(space, w_obj, w_proto)
 
-app = gateway.applevelinterp(r'''
+app = gateway.applevel(r'''
 def reduce_1(obj, proto):
     import copy_reg
     return copy_reg._reduce_ex(obj, proto)

Modified: pypy/dist/pypy/objspace/std/sliceobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/sliceobject.py	(original)
+++ pypy/dist/pypy/objspace/std/sliceobject.py	Tue Apr  5 22:02:50 2005
@@ -24,7 +24,7 @@
 
 registerimplementation(W_SliceObject)
 
-repr__Slice = gateway.applevelinterp("""
+repr__Slice = gateway.applevel("""
     def repr__Slice(aslice):
         return 'slice(%r, %r, %r)' % (aslice.start, aslice.stop, aslice.step)
 """).interphook("repr__Slice")

Modified: pypy/dist/pypy/objspace/std/slicetype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/slicetype.py	(original)
+++ pypy/dist/pypy/objspace/std/slicetype.py	Tue Apr  5 22:02:50 2005
@@ -7,7 +7,7 @@
 
 # default application-level implementations for some operations
 # gateway is imported in the stdtypedef module
-app = gateway.applevelinterp("""
+app = gateway.applevel("""
 
     def indices(slice, length):
         # this is used internally, analogous to CPython's PySlice_GetIndicesEx

Modified: pypy/dist/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringobject.py	(original)
+++ pypy/dist/pypy/objspace/std/stringobject.py	Tue Apr  5 22:02:50 2005
@@ -964,7 +964,7 @@
                        "of length %d found"%(len(w_str._value),)))
     return space.wrap(ord(u_str))
    
-app = gateway.applevelinterp(r'''
+app = gateway.applevel(r'''
     import codecs
     
     def str_translate__String_ANY_ANY(s, table, deletechars=''):
@@ -1010,7 +1010,7 @@
 ''') 
 
 # this one should do the import of _formatting:
-app2 = gateway.applevelinterp('''
+app2 = gateway.applevel('''
 
     def mod__String_ANY(format, values):
         import _formatting

Modified: pypy/dist/pypy/objspace/std/tupleobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/tupleobject.py	(original)
+++ pypy/dist/pypy/objspace/std/tupleobject.py	Tue Apr  5 22:02:50 2005
@@ -112,7 +112,7 @@
     # No more items to compare -- compare sizes
     return space.newbool(len(items1) > len(items2))
 
-app = gateway.applevelinterp("""
+app = gateway.applevel("""
     def repr__Tuple(t):
         if len(t) == 1:
             return "(" + repr(t[0]) + ",)"

Modified: pypy/dist/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/typeobject.py	Tue Apr  5 22:02:50 2005
@@ -277,7 +277,7 @@
 # ____________________________________________________________
 
 
-abstract_mro = gateway.applevelinterp("""
+abstract_mro = gateway.applevel("""
     def abstract_mro(klass):
         # abstract/classic mro
         mro = []

Modified: pypy/dist/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/dist/pypy/translator/geninterplevel.py	(original)
+++ pypy/dist/pypy/translator/geninterplevel.py	Tue Apr  5 22:02:50 2005
@@ -50,8 +50,8 @@
     self.initcode.append1(
         'def %s(expr):\n'
         '    dic = space.newdict([])\n'
-        '    space.exec_("import types", dic, dic)\n'
-        '    return space.eval(expr, dic, dic)' % unique)
+        '    space.exec_("", dic, dic)\n'
+        '    return space.eval(expr, dic, dic)' % (unique, ))
     self.initcode.append1('%s = %s(%r)' % (name, unique, expr))
     return name
 
@@ -120,6 +120,11 @@
 
         # catching all builtins in advance, to avoid problems
         # with modified builtins
+
+        # add a dummy _issubtype() to builtins
+        def _issubtype(cls1, cls2):
+            raise TypeError, "this dummy should *not* be reached"
+        __builtin__._issubtype = _issubtype
         
         class bltinstub:
             def __init__(self, name):
@@ -261,6 +266,12 @@
         if goto <= blocknum[block]:
             yield 'continue'
 
+    def register_early(self, obj, name):
+        # this was needed for recursive lists.
+        # note that self.latercode led to too late initialization.
+        key = Constant(obj).key
+        self.rpynames[key] = name
+
     def nameof(self, obj, debug=None, namehint=None):
         key = Constant(obj).key
         try:
@@ -590,6 +601,7 @@
             # metaclass = 'space.w_classobj'
 
         basenames = [self.nameof(base) for base in cls.__bases__]
+
         def initclassobj():
             content = cls.__dict__.items()
             content.sort()
@@ -658,15 +670,15 @@
         complex:'space.wrap(types.ComplexType)',
         unicode:'space.w_unicode',
         file:   (eval_helper, 'file', 'file'),
-        type(None): (eval_helper, 'NoneType', 'types.NoneType'),
-        CodeType: (eval_helper, 'code', 'types.CodeType'),
+        type(None): (eval_helper, 'NoneType', 'type(None)'),
+        CodeType: (eval_helper, 'code', 'type((lambda:42).func_code)'),
         ModuleType: (eval_helper, 'ModuleType', 'types.ModuleType'),
-        xrange: (eval_helper, 'xrange', 'types.XRangeType'),
+        xrange: (eval_helper, 'xrange', 'xrange'),
 
         ##r_int:  'space.w_int',
         ##r_uint: 'space.w_int',
 
-        type(len): (eval_helper, 'FunctionType', 'types.FunctionType'),
+        type(len): (eval_helper, 'FunctionType', 'type(lambda:42)'),
         # type 'method_descriptor':
         # XXX small problem here:
         # XXX with space.eval, we get <W_TypeObject(method)>
@@ -678,15 +690,17 @@
         # type 'getset_descriptor':
         # XXX here we get <W_TypeObject(FakeDescriptor)>,
         # while eval gives us <W_TypeObject(GetSetProperty)>
-        type(type.__dict__['__dict__']): (eval_helper, "getset_descriptor", '\
-            ' "type(type.__dict__[\'__dict__\'])"),
+        type(type.__dict__['__dict__']): (eval_helper, "getset_descriptor",
+            "type(type.__dict__[\'__dict__\'])"),
         # type 'member_descriptor':
         # XXX this does not work in eval!
         # type(type.__dict__['__basicsize__']): "cannot eval type(type.__dict__['__basicsize__'])",
         # XXX there seems to be no working support for member descriptors ???
         type(types.GeneratorType.gi_frame):
-            (eval_helper, "member_descriptor", 'type(types.GeneratorType.gi_frame)'),
+            (eval_helper, "member_descriptor", 'type(property.fdel)'),
         types.ClassType: 'space.w_classobj',
+        types.MethodType: (eval_helper, "instancemethod",
+            "type((lambda:42).__get__(42))"),
     }
 
     def nameof_type(self, cls):
@@ -697,7 +711,8 @@
             return ret
         assert cls.__module__ != '__builtin__', (
             "built-in class %r not found in typename_mapping "
-            "while compiling %s" % (cls, self.currentfunc.__name__))
+            "while compiling %s" % (cls, self.currentfunc and
+                                    self.currentfunc.__name__ or "*no function at all*"))
         return self.nameof_classobj(cls)
 
     def nameof_tuple(self, tup):
@@ -709,14 +724,14 @@
 
     def nameof_list(self, lis):
         name = self.uniquename('g%dlist' % len(lis))
-        def initlist():
-            for i in range(len(lis)):
-                item = self.nameof(lis[i])
-                yield 'space.setitem(%s, %s, %s);' % (
-                    name, self.nameof(i), item)
-        self.initcode.append1('%s = space.newlist([space.w_None])' % (name,))
-        self.initcode.append1('%s = space.mul(%s, %s)' % (name, name, self.nameof(len(lis))))
-        self.later(initlist())
+        # note that self.latercode led to too late initialization.
+        self.register_early(lis, name)
+        self.initcode.append('%s = space.newlist([space.w_None])' % (name,))
+        self.initcode.append('%s = space.mul(%s, %s)' % (name, name, self.nameof(len(lis))))
+        for i in range(len(lis)):
+            item = self.nameof(lis[i])
+            self.initcode.append('space.setitem(%s, %s, %s);' % (
+                name, self.nameof(i), item))
         return name
 
     def nameof_dict(self, dic):
@@ -724,12 +739,11 @@
         assert '__builtins__' not in dic, 'Seems to be the globals of %s' % (
             dic.get('__name__', '?'),)
         name = self.uniquename('g%ddict' % len(dic))
-        def initdict():
-            for k in dic:
-                yield ('space.setitem(%s, %s, %s)'%(
-                            name, self.nameof(k), self.nameof(dic[k])))
-        self.initcode.append1('%s = space.newdict([])' % (name,))
-        self.later(initdict())
+        self.register_early(dic, name)
+        self.initcode.append('%s = space.newdict([])' % (name,))
+        for k in dic:
+            self.initcode.append('space.setitem(%s, %s, %s)'%(
+                name, self.nameof(k), self.nameof(dic[k])))
         return name
 
     # strange prebuilt instances below, don't look too closely
@@ -825,7 +839,7 @@
             # make sure it is not rendered again
             key = Constant(doc).key
             self.rpynames[key] = "__doc__"
-            self.initcode.append1("__doc__ = space.wrap(globals()['__doc__'])")
+            self.initcode.append("__doc__ = space.wrap('__doc__')")
 
         # header """def initmodule(space):"""
         print >> f, self.RPY_INIT_HEADER % info
@@ -1474,10 +1488,15 @@
     # and now use the members of the dict
     """
     # create something like a module
+    # the following code will be removed when app_descriptor works
+    ##print 80*"T", sourcetext
+    if "class property" in sourcetext:
+        # debugging app_descriptor.py
+        tmpname = "/tmp/look.py"
     if filename is None: 
         code = py.code.Source(sourcetext).compile()
     else: 
-        code = compile(sourcetext, filename, 'exec') 
+        code = compile(sourcetext, filename, 'exec')
     dic = {'__name__': modname}
     exec code in dic
     del dic['__builtins__']



More information about the pypy-svn mailing list