[pypy-svn] r10980 - in pypy/dist/pypy: interpreter module/builtin module/parser objspace/std tool translator

tismer at codespeak.net tismer at codespeak.net
Thu Apr 21 18:40:17 CEST 2005


Author: tismer
Date: Thu Apr 21 18:18:12 2005
New Revision: 10980

Modified:
   pypy/dist/pypy/interpreter/gateway.py
   pypy/dist/pypy/interpreter/pyopcode.py
   pypy/dist/pypy/module/builtin/operation.py
   pypy/dist/pypy/module/parser/pyparser.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/tool/sourcetools.py
   pypy/dist/pypy/translator/geninterplevel.py
Log:
added name prefixes to the _cache/files
as far as possible.

Modified: pypy/dist/pypy/interpreter/gateway.py
==============================================================================
--- pypy/dist/pypy/interpreter/gateway.py	(original)
+++ pypy/dist/pypy/interpreter/gateway.py	Thu Apr 21 18:18:12 2005
@@ -7,7 +7,7 @@
 
 """
 
-import types, sys, md5
+import types, sys, md5, os
 
 from pypy.tool import hack
 from pypy.interpreter.error import OperationError 
@@ -16,7 +16,9 @@
 from pypy.interpreter.baseobjspace import W_Root,ObjSpace, BaseWrappable, Wrappable
 from pypy.interpreter.argument import Arguments
 from pypy.tool.cache import Cache 
-from pypy.tool.compile import compile2 
+from pypy.tool.compile import compile2
+from pypy.tool.sourcetools import NiceCompile
+
 # internal non-translatable parts: 
 from pypy.tool.getpy import py  # XXX from interpreter/ we get py.py 
 
@@ -492,8 +494,8 @@
         "NOT_RPYTHON"
         if filename is None: 
             self.code = py.code.Source(source).compile()
-        else: 
-            self.code = compile(source, filename, 'exec') 
+        else:
+            self.code = NiceCompile(filename)(source)
         
     def getwdict(self, space):
         return space.loadfromcache(self, self.__class__._builddict,
@@ -640,11 +642,14 @@
         from pypy.translator.geninterplevel import translate_as_module
         scramble = md5.new(self.seed)
         scramble.update(self.source)
-        key = scramble.digest()
+        key = scramble.hexdigest()
         initfunc = self.known_source.get(key)
         if not initfunc:
             # try to get it from file
-            name = scramble.hexdigest()
+            name = '_' + key
+            if self.filename:
+                prename = os.path.splitext(os.path.basename(self.filename))[0]
+                name = prename + name
             try:
                 __import__("pypy._cache."+name)
             except ImportError, x:
@@ -656,7 +661,6 @@
             # build it and put it into a file
             initfunc, newsrc = translate_as_module(
                 self.source, self.filename, self.modname, self.do_imports)
-            name = scramble.hexdigest()
             fname = self.cache_path.join(name+".py").strpath
             f = file(fname, "w")
             print >> f, """\

Modified: pypy/dist/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyopcode.py	(original)
+++ pypy/dist/pypy/interpreter/pyopcode.py	Thu Apr 21 18:18:12 2005
@@ -862,7 +862,7 @@
         else: # prog is a string
             co = compile(prog,'<string>','exec', compile_flags, 1)
             return (co, globals, locals)
-''')
+''', filename=__file__)
 
 sys_stdout      = app.interphook('sys_stdout')
 print_expr      = app.interphook('print_expr')

Modified: pypy/dist/pypy/module/builtin/operation.py
==============================================================================
--- pypy/dist/pypy/module/builtin/operation.py	(original)
+++ pypy/dist/pypy/module/builtin/operation.py	Thu Apr 21 18:18:12 2005
@@ -124,7 +124,7 @@
             raise TypeError, 'iter(v, w): v must be callable'
         return iter_generator(callable_, sentinel)
 
-''').interphook("iter_sentinel")
+''', filename=__file__).interphook("iter_sentinel")
 
 def iter(space, w_collection_or_callable, w_sentinel=NoneNotWrapped):
     if w_sentinel is None:

Modified: pypy/dist/pypy/module/parser/pyparser.py
==============================================================================
--- pypy/dist/pypy/module/parser/pyparser.py	(original)
+++ pypy/dist/pypy/module/parser/pyparser.py	Thu Apr 21 18:18:12 2005
@@ -116,7 +116,7 @@
     def modcompile(compileAST): 
         gen = compiler.pycodegen.ModuleCodeGenerator(compileAST)
         return gen.getCode() 
-""") 
+""", filename=__file__) 
 
 mycompile = app.interphook("mycompile") 
 exprcompile = app.interphook("exprcompile") 

Modified: pypy/dist/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictobject.py	(original)
+++ pypy/dist/pypy/objspace/std/dictobject.py	Thu Apr 21 18:18:12 2005
@@ -262,7 +262,7 @@
                     del currently_in_repr[dict_id]
                 except:
                     pass
-''')
+''', filename=__file__)
 
 dictstr = app.interphook("dictstr")
 

Modified: pypy/dist/pypy/objspace/std/dicttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dicttype.py	(original)
+++ pypy/dist/pypy/objspace/std/dicttype.py	Thu Apr 21 18:18:12 2005
@@ -71,7 +71,7 @@
 
     def itervalues(d):
         return iter(d.values())
-''')
+''', filename=__file__)
 #XXX what about dict.fromkeys()?
 
 dict_update__ANY_ANY         = app.interphook("update")

Modified: pypy/dist/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/floatobject.py	(original)
+++ pypy/dist/pypy/objspace/std/floatobject.py	Thu Apr 21 18:18:12 2005
@@ -72,7 +72,7 @@
                 return r
         else:
             return r + '.0'    
-''') 
+''', filename=__file__) 
 repr__Float = app.interphook('repr__Float') 
 str__Float = app.interphook('str__Float') 
 

Modified: pypy/dist/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listobject.py	(original)
+++ pypy/dist/pypy/objspace/std/listobject.py	Thu Apr 21 18:18:12 2005
@@ -319,7 +319,7 @@
                 del currently_in_repr[list_id]
             except:
                 pass
-""") 
+""", filename=__file__) 
 
 listrepr = app.interphook("listrepr")
 

Modified: pypy/dist/pypy/objspace/std/listtype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listtype.py	(original)
+++ pypy/dist/pypy/objspace/std/listtype.py	Thu Apr 21 18:18:12 2005
@@ -22,7 +22,7 @@
         for index in range(len(lst)-1, -1, -1):
             yield lst[index]
 
-''').interphook('reversed')
+''', filename=__file__).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	Thu Apr 21 18:18:12 2005
@@ -127,7 +127,7 @@
     if not isinstance(slotnames, list) and slotnames is not None:
         raise TypeError, "copy_reg._slotnames didn't return a list or None"
     return slotnames
-''')
+''', filename=__file__)
 
 reduce_1 = app.interphook('reduce_1') 
 reduce_2 = app.interphook('reduce_2')

Modified: pypy/dist/pypy/objspace/std/sliceobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/sliceobject.py	(original)
+++ pypy/dist/pypy/objspace/std/sliceobject.py	Thu Apr 21 18:18:12 2005
@@ -27,7 +27,7 @@
 repr__Slice = gateway.applevel("""
     def repr__Slice(aslice):
         return 'slice(%r, %r, %r)' % (aslice.start, aslice.stop, aslice.step)
-""").interphook("repr__Slice")
+""", filename=__file__).interphook("repr__Slice")
 
 def eq__Slice_Slice(space, w_slice1, w_slice2):
     # We need this because CPython considers that slice1 == slice1

Modified: pypy/dist/pypy/objspace/std/slicetype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/slicetype.py	(original)
+++ pypy/dist/pypy/objspace/std/slicetype.py	Thu Apr 21 18:18:12 2005
@@ -64,7 +64,7 @@
             slicelength = 0
 
         return start, stop, step, slicelength
-""")
+""", filename=__file__)
 
 slice_indices__ANY_ANY = app.interphook("indices")
 slice_indices3         = slice_indices__ANY_ANY

Modified: pypy/dist/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringobject.py	(original)
+++ pypy/dist/pypy/objspace/std/stringobject.py	Thu Apr 21 18:18:12 2005
@@ -1017,7 +1017,7 @@
             return codecs.getdecoder(encoding)(str)[0]
         else:
             return codecs.getdecoder(encoding)(str, errors)[0]
-''') 
+''', filename=__file__) 
 
 # this one should do the import of _formatting:
 app2 = gateway.applevel('''
@@ -1031,7 +1031,7 @@
                 return _formatting.format(format, (values,), values)
             else:
                 return _formatting.format(format, (values,), None)
-''', do_imports=True)
+''', filename=__file__, do_imports=True)
 
 str_translate__String_ANY_ANY = app.interphook('str_translate__String_ANY_ANY') 
 str_decode__String_ANY_ANY = app.interphook('str_decode__String_ANY_ANY') 

Modified: pypy/dist/pypy/objspace/std/tupleobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/tupleobject.py	(original)
+++ pypy/dist/pypy/objspace/std/tupleobject.py	Thu Apr 21 18:18:12 2005
@@ -118,7 +118,7 @@
             return "(" + repr(t[0]) + ",)"
         else:
             return "(" + ", ".join([repr(x) for x in t]) + ')'
-""") 
+""", filename=__file__) 
 
 repr__Tuple = app.interphook('repr__Tuple') 
 

Modified: pypy/dist/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/typeobject.py	Thu Apr 21 18:18:12 2005
@@ -290,7 +290,7 @@
                 fill_mro(base)
         fill_mro(klass)
         return mro
-""").interphook("abstract_mro")
+""", filename=__file__).interphook("abstract_mro")
 
 def get_mro(space, klass):
     if isinstance(klass, W_TypeObject):

Modified: pypy/dist/pypy/tool/sourcetools.py
==============================================================================
--- pypy/dist/pypy/tool/sourcetools.py	(original)
+++ pypy/dist/pypy/tool/sourcetools.py	Thu Apr 21 18:18:12 2005
@@ -32,8 +32,11 @@
         are happy. We provide correct line numbers and a real
         __file__ attribute.
     """
-    def __init__(self, namespace):
-        srcname = namespace.get('__file__')
+    def __init__(self, namespace_or_filename):
+        if type(namespace_or_filename) is str:
+            srcname = namespace_or_filename
+        else:
+            srcname = namespace_or_filename.get('__file__')
         if not srcname:
             # assume the module was executed from the
             # command line.
@@ -48,7 +51,7 @@
             # missing source, what to do?
             self.srctext = None
 
-    def __call__(self, src, args={}):
+    def __call__(self, src, args=None):
         """ instance NiceCompile (src, args) -- formats src with args
             and returns a code object ready for exec. Instead of <string>,
             the code object has correct co_filename and line numbers.
@@ -69,13 +72,17 @@
             # fake a block
             prelines -= 1
             src = 'if 1:\n' + src
-        src = '\n' * prelines + src % args
+        if args is not None:
+            src = '\n' * prelines + src % args
+        else:
+            src = '\n' * prelines + src
         c = compile(src, self.srcname, "exec")
         # preserve the arguments of the code in an attribute
         # of the code's co_filename
         if self.srcname:
             srcname = MyStr(self.srcname)
-            srcname.__sourceargs__ = args
+            if args is not None:
+                srcname.__sourceargs__ = args
             c = newcode_withfilename(c, srcname)
         return c
 

Modified: pypy/dist/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/dist/pypy/translator/geninterplevel.py	(original)
+++ pypy/dist/pypy/translator/geninterplevel.py	Thu Apr 21 18:18:12 2005
@@ -33,7 +33,7 @@
 from pypy.translator.translator import Translator
 from pypy.objspace.flow import FlowObjSpace
 
-from pypy.tool.sourcetools import render_docstr
+from pypy.tool.sourcetools import render_docstr, NiceCompile
 
 from pypy.translator.gensupp import ordered_blocks, UniqueList, builtin_base, \
      c_string, uniquemodulename, C_IDENTIFIER, NameManager
@@ -1525,7 +1525,7 @@
     if filename is None: 
         code = py.code.Source(sourcetext).compile()
     else: 
-        code = compile(sourcetext, filename, 'exec')
+        code = NiceCompile(filename)(sourcetext)
     dic = {'__name__': modname}
     exec code in dic
     #del dic['__builtins__']



More information about the Pypy-commit mailing list