[pypy-svn] r18553 - in pypy/branch/hl-backend/pypy: annotation rpython/ootypesystem rpython/ootypesystem/test

bert at codespeak.net bert at codespeak.net
Fri Oct 14 16:51:27 CEST 2005


Author: bert
Date: Fri Oct 14 16:51:27 2005
New Revision: 18553

Modified:
   pypy/branch/hl-backend/pypy/annotation/unaryop.py
   pypy/branch/hl-backend/pypy/rpython/ootypesystem/ootype.py
   pypy/branch/hl-backend/pypy/rpython/ootypesystem/rootype.py
   pypy/branch/hl-backend/pypy/rpython/ootypesystem/test/test_ooann.py
   pypy/branch/hl-backend/pypy/rpython/ootypesystem/test/test_oortype.py
Log:
added rtyper operations oogetfield, oosetfield, oosend (bert, arre, samuele)


Modified: pypy/branch/hl-backend/pypy/annotation/unaryop.py
==============================================================================
--- pypy/branch/hl-backend/pypy/annotation/unaryop.py	(original)
+++ pypy/branch/hl-backend/pypy/annotation/unaryop.py	Fri Oct 14 16:51:27 2005
@@ -603,6 +603,12 @@
             return SomeOOBoundMeth(r.ootype, s_attr.const)
         return ll_to_annotation(v)
 
+    def setattr(r, s_attr, s_value): 
+        assert s_attr.is_constant(), "setattr on ref %r with non-constant field-name" % r.ootype
+        v = annotation_to_lltype(s_value)
+        setattr(r.ootype._example(), s_attr.const,
+                v._example())
+
 class __extend__(SomeOOBoundMeth):
     def simple_call(m, *args_s):
         llargs = [annotation_to_lltype(arg_s)._example() for arg_s in args_s]

Modified: pypy/branch/hl-backend/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/branch/hl-backend/pypy/rpython/ootypesystem/ootype.py	Fri Oct 14 16:51:27 2005
@@ -4,9 +4,9 @@
 from pypy.tool.uid import Hashable
 from pypy.tool.tls import tlsobject
 from types import NoneType
-from pypy.rpython.lltype import LowLevelType, Signed, Unsigned, Float, Char
-from pypy.rpython.lltype import Bool, Void, UniChar, typeOf, Primitive
-from pypy.rpython.lltype import frozendict
+from pypy.rpython.lltypesystem.lltype import LowLevelType, Signed, Unsigned, Float, Char
+from pypy.rpython.lltypesystem.lltype import Bool, Void, UniChar, typeOf, Primitive
+from pypy.rpython.lltypesystem.lltype import frozendict
 
 class OOType(LowLevelType):
     pass
@@ -207,13 +207,9 @@
 
 class _bound_meth(object):
     def __init__(self, inst, meth):
-        #self._TYPE = self
         self.inst = inst
         self.meth = meth
 
-    #def _example(self):
-    #    return self
-    
     def __call__(self, *args):
         return self.meth._checkargs(args)(self.inst, *args)
 

Modified: pypy/branch/hl-backend/pypy/rpython/ootypesystem/rootype.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/ootypesystem/rootype.py	(original)
+++ pypy/branch/hl-backend/pypy/rpython/ootypesystem/rootype.py	Fri Oct 14 16:51:27 2005
@@ -1,5 +1,7 @@
 from pypy.annotation import model as annmodel
 from pypy.rpython.rmodel import Repr
+from pypy.rpython.ootypesystem.ootype import Void
+from pypy.annotation.pairtype import pairtype
 
 class __extend__(annmodel.SomeOOInstance):
     def rtyper_makerepr(self, rtyper):
@@ -7,15 +9,47 @@
     def rtyper_makekey(self):
         return self.__class__, self.ootype
 
+class __extend__(annmodel.SomeOOBoundMeth):
+    def rtyper_makerepr(self, rtyper):
+        return OOBoundMethRepr(self.ootype, self.name)
+    def rtyper_makekey(self):
+        return self.__class__, self.ootype, self.name
+
 class OOInstanceRepr(Repr):
     def __init__(self, ootype):
         self.lowleveltype = ootype
 
-class __extend__(annmodel.SomeOOClass):
-    pass
+    def rtype_getattr(self, hop):
+        attr = hop.args_s[1].const
+	s_inst = hop.args_s[0]
+	meth = self.lowleveltype._lookup(attr)
+	if meth is not None:
+	    # just return instance - will be handled by simple_call
+	    return hop.inputarg(hop.r_result, arg=0)
+	self.lowleveltype._check_field(attr)
+	vlist = hop.inputargs(self, Void)
+	return hop.genop("oogetfield", vlist,
+			 resulttype = hop.r_result.lowleveltype)
 
-class __extend__(annmodel.SomeOOBoundMeth):
-    pass
+    def rtype_setattr(self, hop):
+        attr = hop.args_s[1].const
+	self.lowleveltype._check_field(attr)
+        vlist = hop.inputargs(self, Void, hop.args_r[2])
+        return hop.genop('oosetfield', vlist)
+
+class OOBoundMethRepr(Repr):
+    def __init__(self, ootype, name):
+        self.lowleveltype = ootype
+	self.name = name
+
+    def rtype_simple_call(self, hop):
+	vlist = hop.inputargs(self, *hop.args_r[1:])
+        cname = hop.inputconst(Void, self.name)
+	return hop.genop("oosend", [cname]+vlist,
+			 resulttype = hop.r_result.lowleveltype)
+	
+
+class __extend__(pairtype(OOInstanceRepr, OOBoundMethRepr)):
 
-class __extend__(annmodel.SomeOOStaticMeth):
-    pass
+    def convert_from_to(_, v, llops):
+        return v

Modified: pypy/branch/hl-backend/pypy/rpython/ootypesystem/test/test_ooann.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/ootypesystem/test/test_ooann.py	(original)
+++ pypy/branch/hl-backend/pypy/rpython/ootypesystem/test/test_ooann.py	Fri Oct 14 16:51:27 2005
@@ -9,6 +9,7 @@
     
     def oof():
         c = new(C)
+        c.a = 5
         return c.a
 
     a = RPythonAnnotator()

Modified: pypy/branch/hl-backend/pypy/rpython/ootypesystem/test/test_oortype.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/ootypesystem/test/test_oortype.py	(original)
+++ pypy/branch/hl-backend/pypy/rpython/ootypesystem/test/test_oortype.py	Fri Oct 14 16:51:27 2005
@@ -4,12 +4,14 @@
 from pypy.objspace.flow import FlowObjSpace
 from pypy.translator.translator import Translator
 
-def gengraph(f, *args):
+def gengraph(f, args=[], viewBefore=False, viewAfter=False):
     t = Translator(f)
     t.annotate(args)
-    #t.view()
+    if viewBefore:
+        t.view()
     t.specialize(type_system="ootype")
-    #t.view()
+    if viewAfter:
+        t.view()
     return t.flowgraphs[f]
 
 def test_simple_class():
@@ -23,3 +25,30 @@
     rettype = g.getreturnvar().concretetype
     assert rettype == C
     
+def test_simple_field():
+    C = Instance("test", None, {'a': (Signed, 3)})
+    
+    def f():
+        c = new(C)
+        c.a = 5
+        return c.a
+
+    g = gengraph(f)
+    rettype = g.getreturnvar().concretetype
+    assert rettype == Signed
+    
+def test_simple_method():
+    C = Instance("test", None, {'a': (Signed, 3)})
+    M = Meth([], Signed)
+    def m_(self):
+       return self.a
+    m = meth(M, _name="m", _callable=m_)
+    addMethods(C, {"m": m})
+    
+    def f():
+        c = new(C)
+        return c.m()
+
+    g = gengraph(f)
+    rettype = g.getreturnvar().concretetype
+    assert rettype == Signed



More information about the Pypy-commit mailing list