[pypy-svn] r10191 - in pypy/dist/pypy: interpreter objspace/std translator

tismer at codespeak.net tismer at codespeak.net
Wed Mar 30 23:35:23 CEST 2005


Author: tismer
Date: Wed Mar 30 23:35:23 2005
New Revision: 10191

Modified:
   pypy/dist/pypy/interpreter/gateway.py
   pypy/dist/pypy/objspace/std/floatobject.py
   pypy/dist/pypy/objspace/std/objecttype.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/translator/geninterplevel.py
Log:
applevelinterp-lified a lot more modules.
Besides those which are not R-Pythonic due to yield,
there are some things left:

_formatting cannot be inlined yet, since flowspace has a problem
with pow and three arguments.

pyopcode.py needs a little more support by me to get at the sys objects.

pyparser is not supported since it cannot be imported. Something was
not checked in by the one who added it.


Modified: pypy/dist/pypy/interpreter/gateway.py
==============================================================================
--- pypy/dist/pypy/interpreter/gateway.py	(original)
+++ pypy/dist/pypy/interpreter/gateway.py	Wed Mar 30 23:35:23 2005
@@ -543,11 +543,12 @@
     """
     NOT_RPYTHON_ATTRIBUTES = []
 
-    def __init__(self, source, filename = None, modname = 'applevelinterp'):
+    def __init__(self, source, filename = None, modname = 'applevelinterp', do_imports=False):
         "NOT_RPYTHON"
         self.filename = filename
         self.source = source
         self.modname = modname
+        self.do_imports = do_imports
 
     def getwdict(self, space):
         return space.loadfromcache(self, applevelinterp._builddict,
@@ -557,7 +558,7 @@
         "NOT_RPYTHON"
         from pypy.translator.geninterplevel import translate_as_module
         initfunc = translate_as_module(self.source, self.filename,
-                                       self.modname, tmpname="/tmp/look.py")
+                                       self.modname, self.do_imports)
         w_glob = initfunc(space)
         return w_glob
 

Modified: pypy/dist/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/floatobject.py	(original)
+++ pypy/dist/pypy/objspace/std/floatobject.py	Wed Mar 30 23:35:23 2005
@@ -56,7 +56,7 @@
 def float_w__Float(space, w_float):
     return w_float.floatval
 
-app = gateway.applevel(''' 
+app = gateway.applevelinterp(''' 
     def repr__Float(f):
         r = "%.17g"%f
         for c in r:

Modified: pypy/dist/pypy/objspace/std/objecttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objecttype.py	(original)
+++ pypy/dist/pypy/objspace/std/objecttype.py	Wed Mar 30 23:35:23 2005
@@ -61,7 +61,7 @@
     w_proto = space.wrap(proto)
     return reduce_1(space, w_obj, w_proto)
 
-app = gateway.applevel(r'''
+app = gateway.applevelinterp(r'''
 def reduce_1(obj, proto):
     import copy_reg
     return copy_reg._reduce_ex(obj, proto)

Modified: pypy/dist/pypy/objspace/std/slicetype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/slicetype.py	(original)
+++ pypy/dist/pypy/objspace/std/slicetype.py	Wed Mar 30 23:35:23 2005
@@ -7,7 +7,7 @@
 
 # default application-level implementations for some operations
 # gateway is imported in the stdtypedef module
-app = gateway.applevel("""
+app = gateway.applevelinterp("""
 
     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	Wed Mar 30 23:35:23 2005
@@ -964,7 +964,7 @@
                        "of length %d found"%(len(w_str._value),)))
     return space.wrap(ord(u_str))
    
-app = gateway.applevel(r'''
+app = gateway.applevelinterp(r'''
     import codecs
     
     def str_translate__String_ANY_ANY(s, table, deletechars=''):
@@ -1000,6 +1000,18 @@
         repr += quote
         return repr
 
+    def str_decode__String_ANY_ANY(str, encoding=None, errors=None):
+        if encoding is None and errors is None:
+            return unicode(str)
+        elif errors is None:
+            return codecs.getdecoder(encoding)(str)[0]
+        else:
+            return codecs.getdecoder(encoding)(str, errors)[0]
+''') 
+
+# this one should do the import of _formatting:
+app2 = gateway.applevelinterp('''
+
     def mod__String_ANY(format, values):
         import _formatting
         if isinstance(values, tuple):
@@ -1009,20 +1021,12 @@
                 return _formatting.format(format, (values,), values)
             else:
                 return _formatting.format(format, (values,), None)
-
-    def str_decode__String_ANY_ANY(str, encoding=None, errors=None):
-        if encoding is None and errors is None:
-            return unicode(str)
-        elif errors is None:
-            return codecs.getdecoder(encoding)(str)[0]
-        else:
-            return codecs.getdecoder(encoding)(str, errors)[0]
-''') 
+''')## XXX not yet, error in pow:   , do_imports=('_formatting', '_float_formatting'))
 
 str_translate__String_ANY_ANY = app.interphook('str_translate__String_ANY_ANY') 
 str_decode__String_ANY_ANY = app.interphook('str_decode__String_ANY_ANY') 
-mod__String_ANY = app.interphook('mod__String_ANY') 
 repr__String = app.interphook('repr__String') 
+mod__String_ANY = app2.interphook('mod__String_ANY') 
 
 # register all methods
 from pypy.objspace.std import stringtype

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

Modified: pypy/dist/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/dist/pypy/translator/geninterplevel.py	(original)
+++ pypy/dist/pypy/translator/geninterplevel.py	Wed Mar 30 23:35:23 2005
@@ -310,11 +310,12 @@
         return name
 
     def nameof_module(self, value):
-        assert value is os or not hasattr(value, "__file__") or \
-               not (value.__file__.endswith('.pyc') or
-                    value.__file__.endswith('.py') or
-                    value.__file__.endswith('.pyo')), \
-               "%r is not a builtin module (probably :)"%value
+        #assert value is os or not hasattr(value, "__file__") or \
+        #       not (value.__file__.endswith('.pyc') or
+        #            value.__file__.endswith('.py') or
+        #            value.__file__.endswith('.pyo')), \
+        #       "%r is not a builtin module (probably :)"%value
+        # assume that we get a faked module
         name = self.uniquename('mod_%s' % value.__name__)
         self.initcode.append1('import %s as _tmp' % value.__name__)
         self.initcode.append1('%s = space.wrap(_tmp)' % (name))
@@ -1350,7 +1351,7 @@
                 test_complex,
                 test_NoneType,
                 all_entries)
-entrypoint = entrypoints[-2]
+entrypoint = entrypoints[5]
 
 if False and __name__ == "__main__":
     # XXX TODO:
@@ -1425,7 +1426,8 @@
     def close(self):
         pass
 
-def translate_as_module(sourcetext, filename=None, modname="app2interpexec", tmpname=None):
+def translate_as_module(sourcetext, filename=None, modname="app2interpexec",
+                        do_imports=None, tmpname=None):
     """ compile sourcetext as a module, translating to interp level.
     The result is the init function that creates the wrapped module dict.
     This init function needs a space as argument.
@@ -1434,18 +1436,31 @@
     Example:
 
     initfunc = translate_as_module(text)
-    from pypy.objspace.stdimport Space
+    from pypy.objspace.std import Space
     space = Space()
     dic = ini(space)
     # and now use the members of the dict
     """
     # create something like a module
+    if "_formatting" in sourcetext: tmpname="/tmp/look.py"
     if filename is None: 
         code = py.code.Source(sourcetext).compile()
     else: 
         code = compile(sourcetext, filename, 'exec') 
     dic = {'__name__': modname}
     exec code in dic
+    print do_imports
+    if do_imports:
+        # add lib folder to path
+        hold = sys.path
+        sys.path.insert(0, os.path.join(pypy.__path__[0], "lib"))
+        for modname in do_imports:
+            print 100*modname
+            mod = __import__(modname)
+            try: del mod.__builtins__
+            except:pass
+            dic.update(mod.__dict__)
+        sys.path = hold
     del dic['__builtins__']
     entrypoint = dic
     t = Translator(None, verbose=False, simplifying=True,



More information about the Pypy-commit mailing list