[pypy-svn] rev 454 - in pypy/trunk/src/pypy: interpreter module objspace/std objspace/std/test

arigo at codespeak.net arigo at codespeak.net
Mon May 26 16:53:34 CEST 2003


Author: arigo
Date: Mon May 26 16:53:34 2003
New Revision: 454

Modified:
   pypy/trunk/src/pypy/interpreter/appfile.py
   pypy/trunk/src/pypy/interpreter/baseobjspace.py
   pypy/trunk/src/pypy/interpreter/extmodule.py   (props changed)
   pypy/trunk/src/pypy/interpreter/main.py
   pypy/trunk/src/pypy/interpreter/opcode.py
   pypy/trunk/src/pypy/interpreter/pycode.py
   pypy/trunk/src/pypy/interpreter/pyframe.py
   pypy/trunk/src/pypy/module/builtin.py
   pypy/trunk/src/pypy/objspace/std/funcobject.py
   pypy/trunk/src/pypy/objspace/std/moduleobject.py   (props changed)
   pypy/trunk/src/pypy/objspace/std/objspace.py
   pypy/trunk/src/pypy/objspace/std/test/test_moduleobject.py   (props changed)
   pypy/trunk/src/pypy/objspace/std/test/test_noneobject.py   (props changed)
Log:
If strings knew their length, we'd have acheived our goal for today.
Now sort out your conflicts (evil cackle).


Modified: pypy/trunk/src/pypy/interpreter/appfile.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/appfile.py	(original)
+++ pypy/trunk/src/pypy/interpreter/appfile.py	Mon May 26 16:53:34 2003
@@ -29,7 +29,7 @@
         f = open(filename, 'r')
         src = f.read()
         f.close()
-        print filename
+        #print filename
         self.bytecode = compile(src, filename, 'exec')
 
 
@@ -57,8 +57,11 @@
         # initialize the module by running the bytecode in a new
         # dictionary, in a new execution context
         from pyframe import PyFrame
+        from pycode import PyByteCode
         ec = self.space.getexecutioncontext()
-        frame = PyFrame(self.space, bytecode,
+        res = PyByteCode()
+        res._from_code(bytecode)
+        frame = PyFrame(self.space, res,
                                 self.w_namespace, self.w_namespace)
         ec.eval_frame(frame)
 

Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/trunk/src/pypy/interpreter/baseobjspace.py	Mon May 26 16:53:34 2003
@@ -1,5 +1,6 @@
 from executioncontext import ExecutionContext, OperationError, NoValue
 import pyframe
+import pypy.module.builtin
 
 __all__ = ['ObjSpace', 'OperationError', 'NoValue', 'PyPyError']
 
@@ -16,12 +17,15 @@
 
     def __init__(self):
         "Basic initialization of objects."
-        self.w_builtins = self.newdict([])
-        self.w_modules  = self.newdict([])
+        self.w_modules = self.newdict([])
         self.appfile_helpers = {}
         self.initialize()
-        #import builtins
-        #builtins.init(self)
+
+    def make_builtins(self):
+        self.builtin = pypy.module.builtin.Builtin(self)
+        w_builtin = self.builtin.wrap_me()
+        self.w_builtins = self.getattr(w_builtin, self.wrap("__dict__"))
+        self.setitem(self.w_modules, self.wrap("__builtin__"), w_builtin)
 
     def initialize(self):
         """Abstract method that should put some minimal content into the

Modified: pypy/trunk/src/pypy/interpreter/main.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/main.py	(original)
+++ pypy/trunk/src/pypy/interpreter/main.py	Mon May 26 16:53:34 2003
@@ -1,23 +1,25 @@
 from pypy.objspace.std import StdObjSpace
-from pypy.objspace.trivial import TrivialObjSpace
-import executioncontext, baseobjspace, pyframe
-
+from pypy.module.builtin import Builtin
+from pypy.interpreter import executioncontext, baseobjspace, pyframe
 import sys
 
 def run_string(source, fname):
     try:
         space = StdObjSpace()
+
         compile = space.builtin.compile
         w=space.wrap
-        code = compile(w(source), w(fname), w('exec'))
+        w_code = compile(w(source), w(fname), w('exec'),
+                         w(0), w(0))
+
         ec = executioncontext.ExecutionContext(space)
 
         w_mainmodule = space.newmodule(space.wrap("__main__"))
         w_globals = space.getattr(w_mainmodule, space.wrap("__dict__"))
-        space.setitem(w_globals, space.wrap("__builtins__"),
-                      ec.get_w_builtins())
+        space.setitem(w_globals, space.wrap("__builtins__"), space.w_builtins)
         
-        frame = pyframe.PyFrame(space, code, w_globals, w_globals)
+        frame = pyframe.PyFrame(space, space.unwrap(w_code),
+                                w_globals, w_globals)
     except baseobjspace.OperationError, operationerr:
         raise baseobjspace.PyPyError(space, operationerr)
     else:

Modified: pypy/trunk/src/pypy/interpreter/opcode.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/opcode.py	(original)
+++ pypy/trunk/src/pypy/interpreter/opcode.py	Mon May 26 16:53:34 2003
@@ -626,7 +626,8 @@
     defaultarguments = [f.valuestack.pop() for i in range(numdefaults)]
     defaultarguments.reverse()
     w_defaultarguments = f.space.newtuple(defaultarguments)
-    w_func = f.space.newfunction(w_codeobj, f.w_globals, w_defaultarguments)
+    w_func = f.space.newfunction(f.space.unwrap(w_codeobj),
+                                 f.w_globals, w_defaultarguments)
     f.valuestack.push(w_func)
 
 def MAKE_CLOSURE(f, numdefaults):
@@ -639,8 +640,8 @@
     defaultarguments = [f.valuestack.pop() for i in range(numdefaults)]
     defaultarguments.reverse()
     w_defaultarguments = f.space.newtuple(defaultarguments)
-    w_func = f.space.newfunction(w_codeobj, f.w_globals, w_defaultarguments,
-                                 w_freevars)
+    w_func = f.space.newfunction(f.space.unwrap(w_codeobj),
+                                 f.w_globals, w_defaultarguments, w_freevars)
     f.valuestack.push(w_func)
 
 def BUILD_SLICE(f, numargs):

Modified: pypy/trunk/src/pypy/interpreter/pycode.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/pycode.py	(original)
+++ pypy/trunk/src/pypy/interpreter/pycode.py	Mon May 26 16:53:34 2003
@@ -21,6 +21,10 @@
 
 appfile = AppFile(__name__, ["interpreter"])
 
+CO_VARARGS     = 0x0004
+CO_VARKEYWORDS = 0x0008
+
+
 class PyBaseCode:
     def __init__(self):
         self.co_name = ""
@@ -97,6 +101,15 @@
         for name in self.__dict__.keys():
             value = getattr(code, name)
             setattr(self, name, value)
+        newconsts = ()
+        for const in code.co_consts:
+            if isinstance(const, types.CodeType):
+                newc = PyByteCode()
+                newc._from_code(const)
+                newconsts = newconsts + (newc,)
+            else:
+                newconsts = newconsts + (const,)
+        self.co_consts = newconsts
 
     def eval_code(self, space, w_globals, w_locals):
         frame = pyframe.PyFrame(space, self, w_globals, w_locals)

Modified: pypy/trunk/src/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/pyframe.py	(original)
+++ pypy/trunk/src/pypy/interpreter/pyframe.py	Mon May 26 16:53:34 2003
@@ -11,9 +11,6 @@
 
 appfile = AppFile(__name__, ["interpreter"])
 
-CO_VARARGS     = 0x0004
-CO_VARKEYWORDS = 0x0008
-
 
 class PyFrame:
     """Represents a frame for a regular Python function

Modified: pypy/trunk/src/pypy/module/builtin.py
==============================================================================
--- pypy/trunk/src/pypy/module/builtin.py	(original)
+++ pypy/trunk/src/pypy/module/builtin.py	Mon May 26 16:53:34 2003
@@ -21,6 +21,7 @@
 
     def compile(self, w_str, w_filename, w_startstr,
                 w_supplied_flags, w_dont_inherit):
+        space = self.space
         str = space.unwrap(w_str)
         filename = space.unwrap(w_filename)
         startstr = space.unwrap(w_startstr)

Modified: pypy/trunk/src/pypy/objspace/std/funcobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/funcobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/funcobject.py	Mon May 26 16:53:34 2003
@@ -4,8 +4,8 @@
 
 
 class W_FuncObject(object):
-    def __init__(w_self, w_code, w_globals, w_defaultarguments, w_closure):
-        w_self.w_code = w_code
+    def __init__(w_self, code, w_globals, w_defaultarguments, w_closure):
+        w_self.code = code
         w_self.w_globals = w_globals
         w_self.w_defaultarguments = w_defaultarguments
         w_self.w_closure = w_closure
@@ -25,7 +25,8 @@
 
 
 def func_call(space, w_function, w_arguments, w_keywords):
-    somecode = space.unwrap(w_function.w_code)
+    somecode = w_function.code
+    print somecode
     w_globals = w_function.w_globals
     w_locals = somecode.build_arguments(space, w_arguments, w_keywords,
                   w_defaults = w_function.w_defaultarguments,

Modified: pypy/trunk/src/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/objspace.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/objspace.py	Mon May 26 16:53:34 2003
@@ -27,6 +27,7 @@
         self.w_None  = W_NoneObject()
         self.w_False = W_BoolObject(False)
         self.w_True  = W_BoolObject(True)
+        self.make_builtins()
         # hack in the exception classes
         import __builtin__, types
         for n, c in __builtin__.__dict__.iteritems():


More information about the Pypy-commit mailing list