[pypy-svn] r18429 - in pypy/branch/hl-backend/pypy: annotation rpython/ootype rpython/ootype/test

bert at codespeak.net bert at codespeak.net
Tue Oct 11 19:56:43 CEST 2005


Author: bert
Date: Tue Oct 11 19:56:37 2005
New Revision: 18429

Modified:
   pypy/branch/hl-backend/pypy/annotation/builtin.py
   pypy/branch/hl-backend/pypy/annotation/model.py
   pypy/branch/hl-backend/pypy/rpython/ootype/ootype.py
   pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ooann.py
   pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ootype.py
Log:
(Bert, Arre)
- made Class hashable
- introduced SomeRef (subclass of SomePtr for now)
- new builtins: new(), instanceof()


Modified: pypy/branch/hl-backend/pypy/annotation/builtin.py
==============================================================================
--- pypy/branch/hl-backend/pypy/annotation/builtin.py	(original)
+++ pypy/branch/hl-backend/pypy/annotation/builtin.py	Tue Oct 11 19:56:37 2005
@@ -364,6 +364,24 @@
 BUILTIN_ANALYZERS[lltype.getRuntimeTypeInfo] = getRuntimeTypeInfo
 BUILTIN_ANALYZERS[lltype.runtime_type_info] = runtime_type_info
 
+# ootype
+from pypy.annotation.model import SomeRef
+from pypy.rpython.ootype import ootype
+
+def new(C):
+    assert C.is_constant()
+    i = ootype.new(C.const)
+    r = SomeRef(ootype.typeOf(i))
+    return r
+
+def instanceof(c, C):
+    assert C.is_constant()
+    assert isinstance(C.const, ootype.Class)
+    return SomeBool()
+
+BUILTIN_ANALYZERS[ootype.instanceof] = instanceof
+BUILTIN_ANALYZERS[ootype.new] = new
+
 #________________________________
 # non-gc objects
 

Modified: pypy/branch/hl-backend/pypy/annotation/model.py
==============================================================================
--- pypy/branch/hl-backend/pypy/annotation/model.py	(original)
+++ pypy/branch/hl-backend/pypy/annotation/model.py	Tue Oct 11 19:56:37 2005
@@ -431,6 +431,9 @@
     def can_be_none(self):
         return False
 
+class SomeRef(SomePtr):
+    pass
+
 from pypy.rpython import lltype
 
 annotation_to_ll_map = [

Modified: pypy/branch/hl-backend/pypy/rpython/ootype/ootype.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/ootype/ootype.py	(original)
+++ pypy/branch/hl-backend/pypy/rpython/ootype/ootype.py	Tue Oct 11 19:56:37 2005
@@ -6,6 +6,7 @@
 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
 
 class OOType(LowLevelType):
     pass
@@ -15,8 +16,8 @@
     def __init__(self, name, superclass, fields, methods={}):
         self._superclass = superclass
 
-	self._methods = {}
-        self._fields = {}
+	self._methods = frozendict()
+        self._fields = frozendict()
 
 	self._add_fields(fields)
 	self._add_methods(methods)
@@ -26,6 +27,9 @@
     def _defl(self):
         return self._null
 
+    def _example(self):
+        return new(self)
+
     def _add_fields(self, fields):
         for name, defn in fields.iteritems():
             if self._lookup(name) is not None:

Modified: pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ooann.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ooann.py	(original)
+++ pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ooann.py	Tue Oct 11 19:56:37 2005
@@ -4,14 +4,28 @@
 from pypy.translator.annrpython import RPythonAnnotator
 
 
-def test_simple():
+def test_simple_new():
     C = Class("test", None, {'a': Signed})
-
+    
     def oof():
     	c = new(C)
 	return c.a
 
     a =	RPythonAnnotator()
     s = a.build_types(oof, [])
+    #a.translator.view()
+
     assert s.knowntype == int
 
+def test_simple_instanceof():
+    C = Class("test", None, {'a': Signed})
+    
+    def oof():
+    	c = new(C)
+	return instanceof(c, C)
+
+    a =	RPythonAnnotator()
+    s = a.build_types(oof, [])
+    #a.translator.view()
+
+    assert s.knowntype == bool

Modified: pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ootype.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ootype.py	(original)
+++ pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ootype.py	Tue Oct 11 19:56:37 2005
@@ -4,6 +4,14 @@
 def test_simple():
     assert typeOf(1) is Signed
 
+def test_class_hash():
+    M = Meth([Signed], Signed)
+    def m_(self, b):
+       return self.a + b
+    m = meth(M, _name="m", _callable=m_)
+    C = Class("test", None, {"a": Signed}, {"m": m})
+    assert type(hash(C)) == int
+
 def test_simple_class():
     C = Class("test", None, {"a": Signed})
 



More information about the Pypy-commit mailing list