[pypy-svn] r18616 - in pypy/dist/pypy/rpython: . ootypesystem ootypesystem/test

boria at codespeak.net boria at codespeak.net
Sat Oct 15 13:32:14 CEST 2005


Author: boria
Date: Sat Oct 15 13:32:12 2005
New Revision: 18616

Added:
   pypy/dist/pypy/rpython/ootypesystem/rclass.py   (contents, props changed)
   pypy/dist/pypy/rpython/ootypesystem/rpbc.py   (contents, props changed)
Modified:
   pypy/dist/pypy/rpython/ootypesystem/test/test_ooclean.py
   pypy/dist/pypy/rpython/typesystem.py
Log:
(pedronis, boria)
* Further work on ootypesystem.
* Initial support for classes.
* test_simple_empty_base() in ootypesystem/test/test_ooclean.py now passes.


Added: pypy/dist/pypy/rpython/ootypesystem/rclass.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/ootypesystem/rclass.py	Sat Oct 15 13:32:12 2005
@@ -0,0 +1,40 @@
+from pypy.rpython.rmodel import inputconst
+from pypy.rpython.rclass import AbstractClassRepr, AbstractInstanceRepr
+from pypy.rpython.ootypesystem import ootype
+
+CLASSTYPE = ootype.Class
+
+class ClassRepr(AbstractClassRepr):
+    def __init__(self, rtyper, classdef):
+        AbstractClassRepr.__init__(self, rtyper, classdef)
+
+        self.lowleveltype = ootype.Class
+
+    def _setup_repr(self):
+        # FIXME to be completed
+        pass
+
+    def convert_const(self):
+        # FIXME
+        pass
+
+class InstanceRepr(AbstractInstanceRepr):
+    def __init__(self, rtyper, classdef, does_need_gc=True):
+        AbstractInstanceRepr.__init__(self, rtyper, classdef)
+
+        self.lowleveltype = ootype.Instance(classdef.cls.__name__, None, {}, {})
+        self.prebuiltinstances = {}   # { id(x): (x, _ptr) }
+
+    def _setup_repr(self):
+        # FIXME fields, methods
+        pass
+
+    def convert_const(self):
+        # FIXME
+        pass
+
+    def new_instance(self, llops):
+        """Build a new instance, without calling __init__."""
+
+        return llops.genop("new",
+            [inputconst(ootype.Void, self.lowleveltype)], self.lowleveltype)

Added: pypy/dist/pypy/rpython/ootypesystem/rpbc.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/ootypesystem/rpbc.py	Sat Oct 15 13:32:12 2005
@@ -0,0 +1,12 @@
+from pypy.rpython.rpbc import AbstractClassesPBCRepr
+from pypy.rpython.rclass import rtype_new_instance
+from pypy.rpython.ootypesystem import ootype
+
+class ClassesPBCRepr(AbstractClassesPBCRepr):
+    def rtype_simple_call(self, hop):
+        if self.lowleveltype is not ootype.Void:
+            raise NotImplementedError()
+
+        klass = self.s_pbc.const
+        v_instance = rtype_new_instance(hop.rtyper, klass, hop.llops)
+        return v_instance

Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_ooclean.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_ooclean.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_ooclean.py	Sat Oct 15 13:32:12 2005
@@ -38,7 +38,7 @@
 class EmptyBase(object):
     pass
 
-def inprogress_test_simple_empty_base():
+def test_simple_empty_base():
     def dummyfn():
         x = EmptyBase()
         return x

Modified: pypy/dist/pypy/rpython/typesystem.py
==============================================================================
--- pypy/dist/pypy/rpython/typesystem.py	(original)
+++ pypy/dist/pypy/rpython/typesystem.py	Sat Oct 15 13:32:12 2005
@@ -9,6 +9,27 @@
 class TypeSystem(object):
     __metaclass__ = extendabletype
 
+    def __getattr__(self, name):
+        """Lazy import to avoid circular dependencies."""
+        def load(modname):
+            try:
+                return __import__("pypy.rpython.%s.%s" % (self.name, modname),
+                                  None, None, ['__doc__'])
+            except ImportError:
+                return None
+        if name in ('rclass', 'rpbc'):
+            mod = load(name)
+            if mod is not None:
+                setattr(self, name, mod)
+                return mod
+        elif name == "BUILTIN_TYPER":
+            rbuiltin = load('rbuiltin')
+            if rbuiltin is not None:
+                self.BUILTIN_TYPER = rbuiltin.BUILTIN_TYPER
+                return self.BUILTIN_TYPER
+
+        raise AttributeError(name)
+
     def deref(self, obj):
         """Dereference `obj' to concrete object."""
         raise NotImplementedError()
@@ -38,29 +59,9 @@
         raise NotImplementedError()
 
 class LowLevelTypeSystem(TypeSystem):
+    name = "lltypesystem"
     callable_trait = (lltype.FuncType, lltype.functionptr)
 
-    def __getattr__(self, name):
-        """Lazy import to avoid circular dependencies."""
-        # FIXME refactor into TypeSystem
-        if name == "rclass":
-            from pypy.rpython.lltypesystem import rclass
-            self.rclass = rclass
-
-            return rclass
-        elif name == "rpbc":
-            from pypy.rpython.lltypesystem import rpbc
-            self.rpbc = rpbc
-
-            return rpbc
-        elif name == "BUILTIN_TYPER":
-            from pypy.rpython.lltypesystem import rbuiltin
-            self.BUILTIN_TYPER = rbuiltin.BUILTIN_TYPER
-
-            return self.BUILTIN_TYPER
-        else:
-            raise AttributeError(name)
-
     def deref(self, obj):
         assert isinstance(lltype.typeOf(obj), lltype.Ptr)
         return obj._obj
@@ -74,6 +75,7 @@
         return getattr(v, 'concretetype', lltype.Ptr(lltype.PyObject))
 
 class ObjectOrientedTypeSystem(TypeSystem):
+    name = "ootypesystem"
     callable_trait = (ootype.StaticMethod, ootype.static_meth)
 
     # FIXME rclass



More information about the Pypy-commit mailing list