[pypy-svn] r18662 - in pypy/dist/pypy: rpython rpython/ootypesystem translator/squeak translator/squeak/test
bert at codespeak.net
bert at codespeak.net
Sat Oct 15 20:01:44 CEST 2005
Author: bert
Date: Sat Oct 15 20:01:44 2005
New Revision: 18662
Modified:
pypy/dist/pypy/rpython/ootypesystem/rootype.py
pypy/dist/pypy/rpython/rbuiltin.py
pypy/dist/pypy/translator/squeak/gensqueak.py
pypy/dist/pypy/translator/squeak/test/test_oo.py
Log:
implement classof and runtimenew
Modified: pypy/dist/pypy/rpython/ootypesystem/rootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rootype.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/rootype.py Sat Oct 15 20:01:44 2005
@@ -1,8 +1,14 @@
from pypy.annotation import model as annmodel
from pypy.rpython.rmodel import Repr
-from pypy.rpython.ootypesystem.ootype import Void
+from pypy.rpython.ootypesystem.ootype import Void, Class
from pypy.annotation.pairtype import pairtype
+class __extend__(annmodel.SomeOOClass):
+ def rtyper_makerepr(self, rtyper):
+ return ooclass_repr
+ def rtyper_makekey(self):
+ return self.__class__,
+
class __extend__(annmodel.SomeOOInstance):
def rtyper_makerepr(self, rtyper):
return OOInstanceRepr(self.ootype)
@@ -15,6 +21,10 @@
def rtyper_makekey(self):
return self.__class__, self.ootype, self.name
+class OOClassRepr(Repr):
+ lowleveltype = Class
+ooclass_repr = OOClassRepr()
+
class OOInstanceRepr(Repr):
def __init__(self, ootype):
self.lowleveltype = ootype
Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/rbuiltin.py Sat Oct 15 20:01:44 2005
@@ -270,6 +270,16 @@
return hop.genop('new', vlist,
resulttype = hop.r_result.lowleveltype)
+def rtype_classof(hop):
+ assert isinstance(hop.args_s[0], annmodel.SomeOOInstance)
+ return hop.genop('classof', hop.args_v,
+ resulttype = ootype.Class)
+
+def rtype_runtimenew(hop):
+ assert isinstance(hop.args_s[0], annmodel.SomeOOClass)
+ return hop.genop('runtimenew', hop.args_v,
+ resulttype = hop.r_result.lowleveltype)
+
BUILTIN_TYPER[lltype.malloc] = rtype_malloc
BUILTIN_TYPER[lltype.cast_pointer] = rtype_cast_pointer
BUILTIN_TYPER[lltype.cast_ptr_to_int] = rtype_cast_ptr_to_int
@@ -284,6 +294,8 @@
BUILTIN_TYPER[objectmodel.hlinvoke] = rtype_hlinvoke
BUILTIN_TYPER[ootype.new] = rtype_new
+BUILTIN_TYPER[ootype.classof] = rtype_classof
+BUILTIN_TYPER[ootype.runtimenew] = rtype_runtimenew
from pypy.rpython import extfunctable
Modified: pypy/dist/pypy/translator/squeak/gensqueak.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/gensqueak.py (original)
+++ pypy/dist/pypy/translator/squeak/gensqueak.py Sat Oct 15 20:01:44 2005
@@ -10,6 +10,8 @@
'setitem:with:': 'at:put:',
'getitem:': 'at:',
'new': 'new',
+ 'runtimenew': 'new',
+ 'classof': 'class',
'sameAs': 'yourself',
'intAdd:': '+',
}
Modified: pypy/dist/pypy/translator/squeak/test/test_oo.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/test/test_oo.py (original)
+++ pypy/dist/pypy/translator/squeak/test/test_oo.py Sat Oct 15 20:01:44 2005
@@ -23,24 +23,35 @@
m = meth(M, _name="m", _callable=m_)
addMethods(C, {"m": m})
-def f_new():
- return new(C)
-
-def f_meth():
- c = new(C)
- return c.m(5)
-
-def f_fields():
- c = new(C)
- x = c.a + 1
- c.a = x
- return x
-
def test_simple_new():
+ def f_new():
+ return new(C)
build_sqfunc(f_new)
def test_simple_meth():
+ def f_meth():
+ c = new(C)
+ return c.m(5)
build_sqfunc(f_meth)
def test_simple_fields():
+ def f_fields():
+ c = new(C)
+ x = c.a + 1
+ c.a = x
+ return x
build_sqfunc(f_fields, view=False)
+
+def test_simple_classof():
+ def f_classof():
+ c = new(C)
+ return classof(c)
+ build_sqfunc(f_classof)
+
+def test_simple_runtimenew():
+ def f_runtimenew():
+ c = new(C)
+ m = classof(c)
+ i = runtimenew(m)
+ return i.a
+ build_sqfunc(f_runtimenew)
More information about the Pypy-commit
mailing list