[pypy-svn] r13480 - in pypy/dist/pypy/rpython: . test
arigo at codespeak.net
arigo at codespeak.net
Thu Jun 16 17:32:22 CEST 2005
Author: arigo
Date: Thu Jun 16 17:32:19 2005
New Revision: 13480
Modified:
pypy/dist/pypy/rpython/rclass.py
pypy/dist/pypy/rpython/rtyper.py
pypy/dist/pypy/rpython/test/test_rclass.py
Log:
- Use cast_pointer more explicitely in rclass.py. Required for
prebuilt instances to work -- but there was no test for them.
- Docstring of rtyper module.
Modified: pypy/dist/pypy/rpython/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/rclass.py (original)
+++ pypy/dist/pypy/rpython/rclass.py Thu Jun 16 17:32:19 2005
@@ -391,33 +391,31 @@
raise MissingRTypeAttribute(attr)
return self.rbase.getfieldrepr(attr)
- def getfield(self, vinst, attr, llops, start_repr=None):
+ def getfield(self, vinst, attr, llops, force_cast=False):
"""Read the given attribute (or __class__ for the type) of 'vinst'."""
- if start_repr is None:
- start_repr = self
if attr in self.fields:
mangled_name, r = self.fields[attr]
cname = inputconst(Void, mangled_name)
- vinst = llops.convertvar(vinst, start_repr, self)
+ if force_cast:
+ vinst = llops.genop('cast_pointer', [vinst], resulttype=self)
return llops.genop('getfield', [vinst, cname], resulttype=r)
else:
if self.classdef is None:
raise MissingRTypeAttribute(attr)
- return self.rbase.getfield(vinst, attr, llops, start_repr=start_repr)
+ return self.rbase.getfield(vinst, attr, llops, force_cast=True)
- def setfield(self, vinst, attr, vvalue, llops, start_repr=None):
+ def setfield(self, vinst, attr, vvalue, llops, force_cast=False):
"""Write the given attribute (or __class__ for the type) of 'vinst'."""
- if start_repr is None:
- start_repr = self
if attr in self.fields:
mangled_name, r = self.fields[attr]
cname = inputconst(Void, mangled_name)
- vinst = llops.convertvar(vinst, start_repr, self)
+ if force_cast:
+ vinst = llops.genop('cast_pointer', [vinst], resulttype=self)
llops.genop('setfield', [vinst, cname, vvalue])
else:
if self.classdef is None:
raise MissingRTypeAttribute(attr)
- self.rbase.setfield(vinst, attr, vvalue, llops, start_repr=start_repr)
+ self.rbase.setfield(vinst, attr, vvalue, llops, force_cast=True)
def new_instance(self, llops):
"""Build a new instance, without calling __init__."""
Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py (original)
+++ pypy/dist/pypy/rpython/rtyper.py Thu Jun 16 17:32:19 2005
@@ -1,3 +1,16 @@
+"""
+RTyper: converts high-level operations into low-level operations in flow graphs.
+
+The main class, with code to walk blocks and dispatch individual operations
+to the care of the rtype_*() methods implemented in the other r* modules.
+For each high-level operation 'hop', the rtype_*() methods produce low-level
+operations that are collected in the 'llops' list defined here. When necessary,
+convertions are inserted.
+
+This logic borrows a bit from pypy.translator.annrpython, without the fixpoint
+computation part.
+"""
+
from __future__ import generators
import sys
from pypy.annotation.pairtype import pair
@@ -19,9 +32,6 @@
debug = False
crash_on_first_typeerror = True
-# XXX copied from pypy.translator.typer and modified.
-# We'll remove pypy.translator.typer at some point.
-# It also borrows a bit from pypy.translator.annrpython.
class RPythonTyper:
Modified: pypy/dist/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rclass.py (original)
+++ pypy/dist/pypy/rpython/test/test_rclass.py Thu Jun 16 17:32:19 2005
@@ -48,3 +48,22 @@
x.xyzzy += 1
return x.xyzzy
rtype(dummyfn)
+
+def test_prebuilt_instance():
+ a = EmptyBase()
+ a.x = 5
+ def dummyfn():
+ a.x += 1
+ return a.x
+ rtype(dummyfn)
+
+def WORKING_ON_test_recursive_prebuilt_instance():
+ a = EmptyBase()
+ b = EmptyBase()
+ a.x = 5
+ b.x = 6
+ a.peer = b
+ b.peer = a
+ def dummyfn():
+ return a.peer.x
+ rtype(dummyfn)
More information about the Pypy-commit
mailing list