[pypy-svn] rev 426 - in pypy/trunk/src/pypy: interpreter objspace/std

tismer at codespeak.net tismer at codespeak.net
Mon May 26 12:50:04 CEST 2003


Author: tismer
Date: Mon May 26 12:50:03 2003
New Revision: 426

Modified:
   pypy/trunk/src/pypy/interpreter/pycode.py
   pypy/trunk/src/pypy/objspace/std/funcobject.py
   pypy/trunk/src/pypy/objspace/std/objspace.py
Log:
generalizing functions. They all redirect to their specific code object

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 12:50:03 2003
@@ -1,64 +1,74 @@
-"""
-PyCode class implementation.
-
-This class is similar to the built-in code objects.
-It avoids wrapping existing code object, instead,
-it plays its role without exposing real code objects.
-SInce in C Python the only way to crate a code object
-by somehow call into the builtin compile, we implement
-the creation of our code object by defining out own compile,
-wich ()at the moment) calls back into the real compile,
-hijacks the code object and creates our code object from that.
-compile is found in the builtin.py file.
-"""
-
-# XXX todo:
-# look at this if it makes sense
-# think of a proper base class???
-
-import baseobjspace
-from appfile import AppFile
-
-# no appfile neede, yet
-#appfile = AppFile(__name__, ["interpreter"])
-
-class PyCode:
-    """Represents a code object, in the way we need it.
-
-    Public fields:
-    to be done
-    """
-
-    def __init__(self):
-        """ initialize all attributes to just something. """
-        self.co_argcount = 0
-        self.co_nlocals = 0
-        self.co_stacksize = 0
-        self.co_flags = 0
-        self.co_code = None
-        self.co_consts = None
-        self.co_names = None
-        self.co_varnames = None
-        self.co_freevars = None
-        self.co_cellvars = None
-        # The rest doesn't count for hash/cmp
-        self.co_filename = ""
-        self.co_name = ""
-        self.co_firstlineno = 0 #first source line number
-        self.co_lnotab = "" # string (encoding addr<->lineno mapping)
-        
-    ### codeobject initialization ###
-
-    def _from_code(self, code):
-        """ Initialize the code object from a real 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.
-        """
-        import types
-        assert(type(code is types.CodeType))
-        # simply try to suck in all attributes we know of
-        for name in self.__dict__.keys():
-            value = getattr(code, name)
-            setattr(self, name, value)
-
+"""
+PyCode class implementation.
+
+This class is similar to the built-in code objects.
+It avoids wrapping existing code object, instead,
+it plays its role without exposing real code objects.
+SInce in C Python the only way to crate a code object
+by somehow call into the builtin compile, we implement
+the creation of our code object by defining out own compile,
+wich ()at the moment) calls back into the real compile,
+hijacks the code object and creates our code object from that.
+compile is found in the builtin.py file.
+"""
+
+# XXX todo:
+# look at this if it makes sense
+# think of a proper base class???
+
+import baseobjspace
+from appfile import AppFile
+
+# no appfile neede, yet
+#appfile = AppFile(__name__, ["interpreter"])
+
+class PyBaseCode:
+    def __init__(self):
+        self.co_filename = ""
+        self.co_name = ""
+        
+class PyByteCode(PyBaseCode):
+    """Represents a code object for Python functions.
+
+    Public fields:
+    to be done
+    """
+
+    def __init__(self):
+        """ initialize all attributes to just something. """
+        self.co_argcount = 0
+        self.co_nlocals = 0
+        self.co_stacksize = 0
+        self.co_flags = 0
+        self.co_code = None
+        self.co_consts = None
+        self.co_names = None
+        self.co_varnames = None
+        self.co_freevars = None
+        self.co_cellvars = None
+        # The rest doesn't count for hash/cmp
+        self.co_firstlineno = 0 #first source line number
+        self.co_lnotab = "" # string (encoding addr<->lineno mapping)
+        
+    ### codeobject initialization ###
+
+    def _from_code(self, code):
+        """ Initialize the code object from a real 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.
+        """
+        import types
+        assert(type(code is types.CodeType))
+        # simply try to suck in all attributes we know of
+        for name in self.__dict__.keys():
+            value = getattr(code, name)
+            setattr(self, name, value)
+
+    def eval_code(self, space, w_globals, w_locals):
+        frame = pypy.interpreter.pyframe.PyFrame(space, self,
+                                             w_globals, w_locals)
+        ec = space.getexecutioncontext()
+        w_ret = ec.eval_frame(frame)
+        return w_ret
+    

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 12:50:03 2003
@@ -26,14 +26,13 @@
 
 def func_call(space, w_function, w_arguments, w_keywords):
     ec = space.getexecutioncontext()
-    bytecode = space.unwrap(w_function.w_code)
+    somecode = space.unwrap(w_function.w_code)
     w_locals = space.newdict([])
-    frame = pypy.interpreter.pyframe.PyFrame(space, bytecode,
-                                             w_function.w_globals, w_locals)
-    frame.setargs(w_arguments, w_keywords,
+    w_globals = w_function.w_globals
+    w_locals = buildargs(w_arguments, w_keywords,
                   w_defaults = w_function.w_defaultarguments,
                   w_closure = w_function.w_closure)
-    w_result = ec.eval_frame(frame)
-    return w_result
+    w_ret = somecode.eval_code(space, w_globals, w_locals)
+    return w_ret
 
 StdObjSpace.call.register(func_call, W_FuncObject, W_ANY, W_ANY)

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 12:50:03 2003
@@ -81,9 +81,9 @@
         import sliceobject
         return sliceobject.W_SliceObject(w_start, w_end, w_step)
 
-    def newfunction(self, w_code, w_globals, w_defaultarguments, w_closure=None):
+    def newfunction(self, code, w_globals, w_defaultarguments, w_closure=None):
         import funcobject
-        return funcobject.W_FuncObject(w_code, w_globals,
+        return funcobject.W_FuncObject(code, w_globals,
                                        w_defaultarguments, w_closure)
 
     def newmodule(self, w_name):


More information about the Pypy-commit mailing list