[pypy-svn] r4833 - pypy/branch/src-newobjectmodel/pypy/interpreter

arigo at codespeak.net arigo at codespeak.net
Wed Jun 2 19:27:49 CEST 2004


Author: arigo
Date: Wed Jun  2 19:27:47 2004
New Revision: 4833

Modified:
   pypy/branch/src-newobjectmodel/pypy/interpreter/eval.py
   pypy/branch/src-newobjectmodel/pypy/interpreter/function.py
   pypy/branch/src-newobjectmodel/pypy/interpreter/module.py
   pypy/branch/src-newobjectmodel/pypy/interpreter/pycode.py
   pypy/branch/src-newobjectmodel/pypy/interpreter/pyframe.py
   pypy/branch/src-newobjectmodel/pypy/interpreter/typedef.py
Log:
Initial typedefs for most internal types.


Modified: pypy/branch/src-newobjectmodel/pypy/interpreter/eval.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/interpreter/eval.py	(original)
+++ pypy/branch/src-newobjectmodel/pypy/interpreter/eval.py	Wed Jun  2 19:27:47 2004
@@ -2,9 +2,11 @@
 This module defines the abstract base classes that support execution:
 Code and Frame.
 """
-from error import OperationError
+from pypy.interpreter.error import OperationError
+from pypy.interpreter.baseobjspace import Wrappable
 
-class Code(object):
+
+class Code(Wrappable):
     """A code is a compiled version of some source code.
     Abstract base class."""
 
@@ -48,7 +50,7 @@
 UNDEFINED = object()  # marker for undefined local variables
 
 
-class Frame(object):
+class Frame(Wrappable):
     """A frame is an environment supporting the execution of a code object.
     Abstract base class."""
 

Modified: pypy/branch/src-newobjectmodel/pypy/interpreter/function.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/interpreter/function.py	(original)
+++ pypy/branch/src-newobjectmodel/pypy/interpreter/function.py	Wed Jun  2 19:27:47 2004
@@ -8,7 +8,6 @@
 
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.baseobjspace import Wrappable
-from pypy.interpreter.typedef import attrproperty, attrproperty_w, TypeDef
 from pypy.interpreter.gateway import interp2app 
 
 class Function(Wrappable):
@@ -167,16 +166,6 @@
         else:
             return wrap(Method(space, wrap(self), None, w_cls))
 
-    typedef = TypeDef("function", { 
-        '__call__' : interp2app(call),
-        '__get__' : interp2app(descr_function_get),
-        'func_code' : attrproperty('code'), 
-        'func_doc' : attrproperty('doc'), 
-        'func_name' : attrproperty('name'), 
-        'func_dict' : attrproperty_w('w_func_dict'), 
-        '__dict__' : attrproperty_w('w_func_dict'), 
-        # XXX getattribute/setattribute etc.pp 
-        })
 
 class Method(object):
     """A method is a function bound to a specific instance or class."""
@@ -204,35 +193,3 @@
                 raise OperationError(self.space.w_TypeError,
                                      self.space.wrap(msg))
         return self.space.call(self.w_function, w_args, w_kwds)
-
-
-    typedef = TypeDef("method", { 
-        '__call__': interp2app(call),
-        'im_func' :  attrproperty_w('w_function'), 
-        'im_self' :  attrproperty_w('w_instance'), 
-        'im_class':  attrproperty_w('w_class'), 
-        # XXX getattribute/setattribute etc.pp 
-#        it['__name__'] = it['func_name']
-#        it['__doc__'] = it['func_doc']
-#        it['__dict__'] = it['func_dict']
-#        it['__call__'] = space.wrap(self)
-        })
-
-#    def app_visible(self):  
-#        space = self.space
-#        def makedict(**kw):
-#            return kw
-#        #print "APPVISI", self.code, "INTO", space.wrap(self.code)
-#        it = makedict(
-#                func_defaults = self.defs_w and space.newtuple(self.defs_w) or space.w_None,
-#                func_code = space.wrap(self.code),
-#                func_dict = self.w_func_dict,
-#                func_doc = space.wrap(self.doc),
-#                func_name = space.wrap(self.name),
-#                func_globals = self.w_func_globals,
-#                func_closure = space.wrap(self.closure))
-#        it['__name__'] = it['func_name']
-#        it['__doc__'] = it['func_doc']
-#        it['__dict__'] = it['func_dict']
-#        it['__call__'] = space.wrap(self)
-#        return it.items()

Modified: pypy/branch/src-newobjectmodel/pypy/interpreter/module.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/interpreter/module.py	(original)
+++ pypy/branch/src-newobjectmodel/pypy/interpreter/module.py	Wed Jun  2 19:27:47 2004
@@ -3,13 +3,6 @@
 """
 
 from pypy.interpreter.baseobjspace import Wrappable
-from pypy.interpreter.error import OperationError
-
-def _checkattrtype(space, w_attr):
-    attr = space.unwrap(w_attr)
-    if not isinstance(attr, str):
-        raise OperationError(space.w_TypeError,
-                  space.wrap('attribute name must be string'))
 
 class Module(Wrappable):
     """A module."""
@@ -21,32 +14,3 @@
         self.w_dict = w_dict
         self.w_name = w_name
         space.setitem(w_dict, space.wrap('__name__'), w_name)
-
-    def pypy_getattr(self, w_attr):
-        space = self.space
-        _checkattrtype(space, w_attr)
-        if space.is_true(space.eq(w_attr, space.wrap('__dict__'))):
-            return self.w_dict
-        try:
-            return space.getitem(self.w_dict, w_attr)
-        except OperationError, e:
-            if not e.match(space, space.w_KeyError):
-                raise
-            # XXX fix error message
-            raise OperationError(space.w_AttributeError, w_attr)
-
-    def pypy_setattr(self, w_attr, w_value):
-        space = self.space
-        _checkattrtype(space, w_attr)
-        space.setitem(self.w_dict, w_attr, w_value)
-
-    def pypy_delattr(self, w_attr):
-        space = self.space
-        _checkattrtype(space, w_attr)
-        try:
-            space.delitem(self.w_dict, w_attr)
-        except OperationError, e:
-            if not e.match(space, space.w_KeyError):
-                raise
-            # XXX fix error message
-            raise OperationError(space.w_AttributeError, w_attr)

Modified: pypy/branch/src-newobjectmodel/pypy/interpreter/pycode.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/interpreter/pycode.py	(original)
+++ pypy/branch/src-newobjectmodel/pypy/interpreter/pycode.py	Wed Jun  2 19:27:47 2004
@@ -7,7 +7,6 @@
 import dis
 from pypy.interpreter import eval
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.baseobjspace import Wrappable
 
 
 # code object contants, for co_flags below
@@ -18,33 +17,6 @@
 CO_NESTED       = 0x0010
 CO_GENERATOR    = 0x0020
 
-class AppPyCode(Wrappable):
-    """ applevel representation of a PyCode object. """
-    def __init__(self, pycode, space):
-        self.space = space
-        self.pycode = pycode
-
-    def __unwrap__(self):
-        return self.pycode
-        
-    def pypy_id(self):
-        # XXX we need a type system for internal objects!
-        return id(self.pycode)
-
-    def pypy_type(self):
-        # XXX we need a type system for internal objects!
-        return self.space.wrap(self.__class__)
-       
-    def app_visible(self):
-
-        # XXX change that if we have type objects ...
-        l = []
-        for name,value in self.pycode.__dict__.items():
-            if name.startswith('co_'):
-                l.append( (name, self.space.wrap(value)))
-        l.append(('__class__', self.pypy_type()))
-        return l
-
 class PyCode(eval.Code):
     "CPython-style code objects."
     
@@ -66,9 +38,6 @@
         self.co_firstlineno = 0      # first source line number
         self.co_lnotab = ""          # string: encoding addr<->lineno mapping
 
-    def __wrap__(self, space):
-        return space.wrap(AppPyCode(self, space))
-
     def _from_code(self, code):
         """ Initialize the code object from a real (CPython) one.
             This is just a hack, until we have our own compile.

Modified: pypy/branch/src-newobjectmodel/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/interpreter/pyframe.py	(original)
+++ pypy/branch/src-newobjectmodel/pypy/interpreter/pyframe.py	Wed Jun  2 19:27:47 2004
@@ -7,7 +7,7 @@
 from pypy.interpreter import pytraceback
 
 
-class PyFrame(eval.Frame, baseobjspace.Wrappable):
+class PyFrame(eval.Frame):
     """Represents a frame for a regular Python function
     that needs to be interpreted.
 

Modified: pypy/branch/src-newobjectmodel/pypy/interpreter/typedef.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/interpreter/typedef.py	(original)
+++ pypy/branch/src-newobjectmodel/pypy/interpreter/typedef.py	Wed Jun  2 19:27:47 2004
@@ -5,9 +5,9 @@
 from pypy.interpreter.gateway import interp2app 
 
 class TypeDef:
-    def __init__(self, name, rawdict):
-        self.name = name
-        self.rawdict = rawdict 
+    def __init__(self, __name, **rawdict):
+        self.name = __name
+        self.rawdict = rawdict
 
     def mro(self, space):
         return [self, space.object_typedef]
@@ -22,9 +22,9 @@
     def descr_property_get(space, w_property, w_obj, w_ignored):
         return space.unwrap(w_property).fget(space, w_obj)
 
-    typedef = TypeDef("GetSetProperty", { 
-        '__get__' : interp2app(descr_property_get),
-    })
+    typedef = TypeDef("GetSetProperty",
+        __get__ = interp2app(descr_property_get),
+        )
 
 def attrproperty(name):
     def fget(space, w_obj):
@@ -42,3 +42,68 @@
             return w_value 
 
     return GetSetProperty(fget)
+
+# ____________________________________________________________
+#
+# Definition of the type's descriptors for all the internal types
+
+from pypy.interpreter.eval import Code, Frame
+from pypy.interpreter.pycode import PyCode
+from pypy.interpreter.pyframe import PyFrame
+from pypy.interpreter.module import Module
+from pypy.interpreter.function import Function, Method
+
+Code.typedef = TypeDef('internal-code',
+    co_name = attrproperty('co_name'),
+    # XXX compute more co_xxx from the methods in Code
+    )
+
+Frame.typedef = TypeDef('internal-frame',
+    f_code = attrproperty('code'),
+    #f_locals = GetSetProperty(getdictscope, setdictscope), XXX
+    f_globals = attrproperty_w('w_globals'),
+    )
+
+PyCode.typedef = TypeDef('code',
+    co_argcount = attrproperty('co_argcount'),
+    co_nlocals = attrproperty('co_nlocals'),
+    co_stacksize = attrproperty('co_stacksize'),
+    co_flags = attrproperty('co_flags'),
+    co_code = attrproperty('co_code'),
+    co_consts = attrproperty('co_consts'),
+    co_names = attrproperty('co_names'),
+    co_varnames = attrproperty('co_varnames'),
+    co_freevars = attrproperty('co_freevars'),
+    co_cellvars = attrproperty('co_cellvars'),
+    co_filename = attrproperty('co_filename'),
+    co_name = attrproperty('co_name'),
+    co_firstlineno = attrproperty('co_firstlineno'),
+    co_lnotab = attrproperty('co_lnotab'),
+    )
+
+PyFrame.typedef = TypeDef('frame',
+    f_builtins = attrproperty_w('w_builtins'),
+    **Frame.typedef.rawdict)
+
+Module.typedef = TypeDef("module",
+    __dict__ = attrproperty_w('w_dict'), 
+    )
+
+Function.typedef = TypeDef("function",
+    __call__ = interp2app(Function.call.im_func),
+    __get__ = interp2app(Function.descr_function_get.im_func),
+    func_code = attrproperty('code'), 
+    func_doc = attrproperty('doc'), 
+    func_name = attrproperty('name'), 
+    func_dict = attrproperty_w('w_func_dict'), 
+    __dict__ = attrproperty_w('w_func_dict'), 
+    # XXX func_closure, __name__, __doc__, etc.pp
+    )
+
+Method.typedef = TypeDef("method",
+    __call__ = interp2app(Method.call.im_func),
+    im_func  = attrproperty_w('w_function'), 
+    im_self  = attrproperty_w('w_instance'), 
+    im_class = attrproperty_w('w_class'),
+    # XXX getattribute/setattribute etc.pp 
+    )



More information about the Pypy-commit mailing list