[pypy-svn] r50674 - in pypy/dist/pypy: jit/codegen jit/codegen/llgraph jit/codegen/llgraph/test jit/timeshifter jit/timeshifter/test rpython rpython/lltypesystem rpython/ootypesystem rpython/test translator
antocuni at codespeak.net
antocuni at codespeak.net
Wed Jan 16 16:20:08 CET 2008
Author: antocuni
Date: Wed Jan 16 16:20:07 2008
New Revision: 50674
Modified:
pypy/dist/pypy/jit/codegen/graph2rgenop.py
pypy/dist/pypy/jit/codegen/llgraph/llimpl.py
pypy/dist/pypy/jit/codegen/llgraph/rgenop.py
pypy/dist/pypy/jit/codegen/llgraph/test/test_graph2rgenop.py
pypy/dist/pypy/jit/timeshifter/exception.py
pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
pypy/dist/pypy/rpython/annlowlevel.py
pypy/dist/pypy/rpython/lltypesystem/rclass.py
pypy/dist/pypy/rpython/ootypesystem/ootype.py
pypy/dist/pypy/rpython/rclass.py
pypy/dist/pypy/rpython/test/test_llann.py
pypy/dist/pypy/rpython/typesystem.py
pypy/dist/pypy/translator/simplify.py
Log:
(antocuni, arigo)
whack and hack until test_timeshift.test_very_simple passes for ootype
Modified: pypy/dist/pypy/jit/codegen/graph2rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/graph2rgenop.py (original)
+++ pypy/dist/pypy/jit/codegen/graph2rgenop.py Wed Jan 16 16:20:07 2008
@@ -7,7 +7,7 @@
import random
-def rcompile(rgenop, entrypoint, argtypes, random_seed=0):
+def rcompile(rgenop, entrypoint, argtypes, random_seed=0, type_system='lltype'):
from pypy.translator.translator import TranslationContext
from pypy.annotation.policy import AnnotatorPolicy
from pypy import conftest
@@ -15,7 +15,7 @@
policy = AnnotatorPolicy()
policy.allow_someobjects = False
t.buildannotator(policy=policy).build_types(entrypoint, argtypes)
- t.buildrtyper().specialize()
+ t.buildrtyper(type_system = type_system).specialize()
# note that backend optimizations will constant-fold simple operations,
# which is required by some backends that don't accept calls like
Modified: pypy/dist/pypy/jit/codegen/llgraph/llimpl.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llgraph/llimpl.py (original)
+++ pypy/dist/pypy/jit/codegen/llgraph/llimpl.py Wed Jan 16 16:20:07 2008
@@ -5,13 +5,14 @@
"""
from pypy.rpython.lltypesystem import lltype, llmemory, rtupletype
+from pypy.rpython.ootypesystem import ootype
from pypy.objspace.flow import model as flowmodel
from pypy.translator.simplify import eliminate_empty_blocks
from pypy.translator.unsimplify import varoftype
-from pypy.rpython.module.support import LLSupport
+from pypy.rpython.module.support import LLSupport, OOSupport
from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.rpython.llinterp import LLInterpreter
-from pypy.rpython.lltypesystem.rclass import fishllattr
+from pypy.rpython.rclass import fishllattr
from pypy.rpython.lltypesystem.lloperation import llop
def _from_opaque(opq):
@@ -34,11 +35,18 @@
block = flowmodel.Block([])
return _to_opaque(block)
+def from_opaque_string(s):
+ if isinstance(s, str):
+ return s
+ elif isinstance(s, ootype._string):
+ return OOSupport.from_rstr(s)
+ else:
+ return LLSupport.from_rstr(s)
+
def newgraph(gv_FUNCTYPE, name):
FUNCTYPE = _from_opaque(gv_FUNCTYPE).value
# 'name' is just a way to track things
- if not isinstance(name, str):
- name = LLSupport.from_rstr(name)
+ name = from_opaque_string(name)
inputargs = []
erasedinputargs = []
for ARG in FUNCTYPE.ARGS:
@@ -103,9 +111,8 @@
newvars = []
if not isinstance(vars, list):
n = vars.ll_length()
- vars = vars.ll_items()
for i in range(n):
- v = vars[i]
+ v = vars.ll_getitem_fast(i)
if not v:
v = dummy_placeholder
else:
@@ -156,8 +163,7 @@
def genop(block, opname, vars_gv, gv_RESULT_TYPE):
# 'opname' is a constant string
# gv_RESULT_TYPE comes from constTYPE
- if not isinstance(opname, str):
- opname = LLSupport.from_rstr(opname)
+ opname = from_opaque_string(opname)
block = _from_opaque(block)
assert block.exits == [], "block already closed"
opvars = _inputvars(vars_gv)
@@ -222,10 +228,15 @@
return _to_opaque(c)
def _generalcast(T, value):
- if isinstance(T, lltype.Ptr):
+ if lltype.typeOf(value) == T:
+ return value
+ elif isinstance(T, lltype.Ptr):
return lltype.cast_pointer(T, value)
elif T == llmemory.Address:
return llmemory.cast_ptr_to_adr(value)
+ elif isinstance(T, ootype.StaticMethod):
+ fn = value._obj
+ return ootype._static_meth(T, graph=fn.graph, _callable=fn._callable)
else:
T1 = lltype.typeOf(value)
if T1 is llmemory.Address:
@@ -243,6 +254,8 @@
def revealconstrepr(gv_value):
c = _from_opaque(gv_value)
+ # XXX: what to do with ootype?
+ #import pdb;pdb.set_trace()
return LLSupport.to_rstr(repr(c.value))
def isconst(gv_value):
@@ -654,12 +667,18 @@
else:
# specialize as direct_call
def specialize_call(self, hop):
- FUNCTYPE = lltype.FuncType([r.lowleveltype for r in hop.args_r],
- hop.r_result.lowleveltype)
+ ARGS = [r.lowleveltype for r in hop.args_r]
+ RESULT = hop.r_result.lowleveltype
+ if hop.rtyper.type_system.name == 'lltypesystem':
+ FUNCTYPE = lltype.FuncType(ARGS, RESULT)
+ funcptr = lltype.functionptr(FUNCTYPE, func.__name__,
+ _callable=func, _debugexc=True)
+ cfunc = hop.inputconst(lltype.Ptr(FUNCTYPE), funcptr)
+ else:
+ FUNCTYPE = ootype.StaticMethod(ARGS, RESULT)
+ sm = ootype._static_meth(FUNCTYPE, _name=func.__name__, _callable=func)
+ cfunc = hop.inputconst(FUNCTYPE, sm)
args_v = hop.inputargs(*hop.args_r)
- funcptr = lltype.functionptr(FUNCTYPE, func.__name__,
- _callable=func, _debugexc=True)
- cfunc = hop.inputconst(lltype.Ptr(FUNCTYPE), funcptr)
return hop.genop('direct_call', [cfunc] + args_v, hop.r_result)
# annotations
Modified: pypy/dist/pypy/jit/codegen/llgraph/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llgraph/rgenop.py (original)
+++ pypy/dist/pypy/jit/codegen/llgraph/rgenop.py Wed Jan 16 16:20:07 2008
@@ -1,10 +1,11 @@
from pypy.rlib.objectmodel import specialize
from pypy.rlib.debug import ll_assert
from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.ootypesystem import ootype
from pypy.jit.codegen.model import AbstractRGenOp, GenLabel, GenBuilder
from pypy.jit.codegen.model import GenVar, GenConst, CodeGenSwitch
from pypy.jit.codegen.llgraph import llimpl
-from pypy.rpython.lltypesystem.rclass import fishllattr
+from pypy.rpython.rclass import fishllattr
from pypy.rpython.module.support import LLSupport
@@ -380,6 +381,19 @@
place.absorbed = True
return place.v
+def getfieldtype(T, name):
+ if isinstance(T, ootype.OOType):
+ _, TYPE = T._lookup_field(name)
+ return TYPE
+ else:
+ assert name in T._flds
+ return getattr(T, name)
+
+def getptr(T):
+ if isinstance(T, ootype.OOType):
+ return T
+ else:
+ return lltype.Ptr(T)
class RGenOp(AbstractRGenOp):
gv_Void = gv_Void
@@ -410,19 +424,18 @@
@staticmethod
@specialize.memo()
def fieldToken(T, name):
- assert name in T._flds
- FIELDTYPE = getattr(T, name)
+ FIELDTYPE = getfieldtype(T, name)
if isinstance(FIELDTYPE, lltype.ContainerType):
- FIELDTYPE = lltype.Ptr(FIELDTYPE)
+ FIELDTYPE = getptr(FIELDTYPE)
return (LLConst(llimpl.constFieldName(name)),
- gv_TYPE(lltype.Ptr(T)),
+ gv_TYPE(getptr(T)),
gv_TYPE(FIELDTYPE))
@staticmethod
@specialize.memo()
def allocToken(TYPE):
return (gv_TYPE(TYPE),
- gv_TYPE(lltype.Ptr(TYPE)))
+ gv_TYPE(getptr(TYPE)))
varsizeAllocToken = allocToken
@@ -431,7 +444,7 @@
def arrayToken(A):
ITEMTYPE = A.OF
if isinstance(ITEMTYPE, lltype.ContainerType):
- ITEMTYPE = lltype.Ptr(ITEMTYPE)
+ ITEMTYPE = getptr(ITEMTYPE)
return gv_TYPE(ITEMTYPE)
@staticmethod
Modified: pypy/dist/pypy/jit/codegen/llgraph/test/test_graph2rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llgraph/test/test_graph2rgenop.py (original)
+++ pypy/dist/pypy/jit/codegen/llgraph/test/test_graph2rgenop.py Wed Jan 16 16:20:07 2008
@@ -1,9 +1,9 @@
from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.ootypesystem import ootype
from pypy.jit.codegen.graph2rgenop import rcompile
from pypy.jit.codegen.llgraph.rgenop import rgenop
from pypy.jit.codegen.llgraph.llimpl import testgengraph
-
def demo(n):
result = 1
while n > 1:
@@ -12,11 +12,33 @@
n -= 1
return result
+class BaseTest:
+ type_system = None
+ FuncType = None
+ Ptr = None
+
+ def test_demo(self):
+ gv = rcompile(rgenop, demo, [int], type_system=self.type_system)
+ F1 = self.FuncType([lltype.Signed], lltype.Signed)
+ func = gv.revealconst(self.Ptr(F1))
+
+ res = testgengraph(self.deref(func).graph, [10])
+ assert res == demo(10) == 945
+
+class TestLLType(BaseTest):
+ type_system = 'lltype'
+ FuncType = lltype.FuncType
+ Ptr = lltype.Ptr
+
+ def deref(self, ptr):
+ return ptr._obj
+
+class TestOOType(BaseTest):
+ type_system = 'ootype'
+ FuncType = ootype.StaticMethod
-def test_demo():
- gv = rcompile(rgenop, demo, [int])
- F1 = lltype.FuncType([lltype.Signed], lltype.Signed)
- ptr = gv.revealconst(lltype.Ptr(F1))
+ def Ptr(self, x):
+ return x
- res = testgengraph(ptr._obj.graph, [10])
- assert res == demo(10) == 945
+ def deref(self, obj):
+ return obj
Modified: pypy/dist/pypy/jit/timeshifter/exception.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/exception.py (original)
+++ pypy/dist/pypy/jit/timeshifter/exception.py Wed Jan 16 16:20:07 2008
@@ -12,22 +12,30 @@
self.gv_excdata = RGenOp.constPrebuiltGlobal(self.exc_data_ptr)
EXCDATA = self.etrafo.EXCDATA
+ LL_EXC_TYPE = self.etrafo.lltype_of_exception_type
+ LL_EXC_VALUE = self.etrafo.lltype_of_exception_value
self.exc_type_token = RGenOp.fieldToken(EXCDATA, 'exc_type')
self.exc_value_token = RGenOp.fieldToken(EXCDATA, 'exc_value')
- self.exc_type_kind = RGenOp.kindToken(EXCDATA.exc_type)
- self.exc_value_kind = RGenOp.kindToken(EXCDATA.exc_value)
+ self.exc_type_kind = RGenOp.kindToken(LL_EXC_TYPE)
+ self.exc_value_kind = RGenOp.kindToken(LL_EXC_VALUE)
- LL_EXC_TYPE = EXCDATA.exc_type
- LL_EXC_VALUE = EXCDATA.exc_value
-
- self.gv_null_exc_type = RGenOp.constPrebuiltGlobal(
- lltype.nullptr(LL_EXC_TYPE.TO))
- self.gv_null_exc_value = RGenOp.constPrebuiltGlobal(
- lltype.nullptr(LL_EXC_VALUE.TO))
- self.null_exc_type_box = rvalue.PtrRedBox(self.exc_type_kind,
- self.gv_null_exc_type)
- self.null_exc_value_box = rvalue.PtrRedBox(self.exc_value_kind,
- self.gv_null_exc_value)
+ null_exc_type = self.etrafo.c_null_etype.value
+ null_exc_value = self.etrafo.c_null_evalue.value
+ self.gv_null_exc_type = RGenOp.constPrebuiltGlobal(null_exc_type)
+ self.gv_null_exc_value = RGenOp.constPrebuiltGlobal(null_exc_value)
+
+ if hrtyper.rtyper.type_system.name == 'lltypesystem':
+ self.null_exc_type_box = rvalue.PtrRedBox(self.exc_type_kind,
+ self.gv_null_exc_type)
+ self.null_exc_value_box = rvalue.PtrRedBox(self.exc_value_kind,
+ self.gv_null_exc_value)
+ else:
+ # XXX: think more about exceptions
+ self.null_exc_type_box = rvalue.PtrRedBox(self.exc_type_kind,
+ RGenOp.constPrebuiltGlobal(llmemory.NULL))
+ self.null_exc_value_box = rvalue.IntRedBox(self.exc_value_kind,
+ RGenOp.constPrebuiltGlobal(llmemory.NULL))
+
self.lazy_exception_path = lazy_exception_path
def _freeze_(self):
Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py Wed Jan 16 16:20:07 2008
@@ -47,35 +47,6 @@
t = annmodel.lltype_to_annotation(T)
return a.typeannotation(t)
-def hannotate(func, values, policy=None, inline=None, backendoptimize=False,
- portal=None):
- # build the normal ll graphs for ll_function
- t = TranslationContext()
- a = t.buildannotator()
- argtypes = getargtypes(a, values)
- a.build_types(func, argtypes)
- rtyper = t.buildrtyper()
- rtyper.specialize()
- if inline:
- auto_inlining(t, threshold=inline)
- if backendoptimize:
- from pypy.translator.backendopt.all import backend_optimizations
- backend_optimizations(t, inline_threshold=inline or 0)
- if portal is None:
- portal = func
- if hasattr(policy, "seetranslator"):
- policy.seetranslator(t)
- graph1 = graphof(t, portal)
- # build hint annotator types
- hannotator = HintAnnotator(base_translator=t, policy=policy)
- hs = hannotator.build_types(graph1, [SomeLLAbstractConstant(v.concretetype,
- {OriginFlags(): True})
- for v in graph1.getargs()])
- hannotator.simplify()
- if conftest.option.view:
- hannotator.translator.view()
- return hs, hannotator, rtyper
-
class TimeshiftingTests(object):
RGenOp = LLRGenOp
@@ -94,6 +65,46 @@
del cls._cache
del cls._cache_order
+ def hannotate(self, func, values, policy=None, inline=None, backendoptimize=False,
+ portal=None):
+ # build the normal ll graphs for ll_function
+ t = TranslationContext()
+ a = t.buildannotator()
+ argtypes = getargtypes(a, values)
+ a.build_types(func, argtypes)
+ rtyper = t.buildrtyper(type_system = self.type_system)
+ rtyper.specialize()
+ if inline:
+ auto_inlining(t, threshold=inline)
+ if backendoptimize:
+ from pypy.translator.backendopt.all import backend_optimizations
+ backend_optimizations(t, inline_threshold=inline or 0)
+ if portal is None:
+ portal = func
+
+ policy = self.fixpolicy(policy)
+ if hasattr(policy, "seetranslator"):
+ policy.seetranslator(t)
+ graph1 = graphof(t, portal)
+ # build hint annotator types
+ hannotator = HintAnnotator(base_translator=t, policy=policy)
+ hs = hannotator.build_types(graph1, [SomeLLAbstractConstant(v.concretetype,
+ {OriginFlags(): True})
+ for v in graph1.getargs()])
+ hannotator.simplify()
+ if conftest.option.view:
+ hannotator.translator.view()
+ return hs, hannotator, rtyper
+
+ def fixpolicy(self, policy):
+ import copy
+ if self.type_system == 'ootype' and policy is not None:
+ newpolicy = copy.copy(policy)
+ newpolicy.oopspec = False
+ return newpolicy
+ else:
+ return policy
+
def timeshift_cached(self, ll_function, values, inline=None, policy=None,
check_raises='ignored anyway',
backendoptimize=False):
@@ -115,9 +126,9 @@
if len(self._cache_order) >= 3:
del self._cache[self._cache_order.pop(0)]
- hs, ha, rtyper = hannotate(ll_function, values,
- inline=inline, policy=policy,
- backendoptimize=backendoptimize)
+ hs, ha, rtyper = self.hannotate(ll_function, values,
+ inline=inline, policy=policy,
+ backendoptimize=backendoptimize)
# make the timeshifted graphs
hrtyper = HintRTyper(ha, rtyper, self.RGenOp)
@@ -367,7 +378,7 @@
assert count == expected_count
-class TestTimeshift(TimeshiftingTests):
+class BaseTestTimeshift(TimeshiftingTests):
def test_simple_fixed(self):
py.test.skip("green return not working")
@@ -1778,3 +1789,11 @@
hint(None, global_merge_point=True)
return g(n)
py.test.raises(AssertionError, self.timeshift, f, [7], [])
+
+class TestLLType(BaseTestTimeshift):
+ type_system = 'lltype'
+
+# skip it for now, only test_very_simple works
+class xTestOOType(BaseTestTimeshift):
+ type_system = 'ootype'
+
Modified: pypy/dist/pypy/rpython/annlowlevel.py
==============================================================================
--- pypy/dist/pypy/rpython/annlowlevel.py (original)
+++ pypy/dist/pypy/rpython/annlowlevel.py Wed Jan 16 16:20:07 2008
@@ -8,8 +8,10 @@
from pypy.annotation.policy import AnnotatorPolicy, Sig
from pypy.annotation.specialize import flatten_star_args
from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.ootypesystem import ootype
from pypy.rpython import extregistry
from pypy.objspace.flow.model import Constant
+from pypy.translator.simplify import get_functype
class KeyComp(object):
def __init__(self, val):
@@ -175,13 +177,19 @@
return Constant(p, lltype.typeOf(p))
def graph2delayed(self, graph, FUNCTYPE=None):
- if FUNCTYPE is None:
- FUNCTYPE = lltype.ForwardReference()
- # obscure hack: embed the name of the function in the string, so
- # that the genc database can get it even before the delayedptr
- # is really computed
- name = "delayed!%s" % (graph.name,)
- delayedptr = lltype._ptr(lltype.Ptr(FUNCTYPE), name, solid=True)
+ if self.rtyper.type_system.name == 'lltypesystem':
+ if FUNCTYPE is None:
+ FUNCTYPE = lltype.ForwardReference()
+ # obscure hack: embed the name of the function in the string, so
+ # that the genc database can get it even before the delayedptr
+ # is really computed
+ name = "delayed!%s" % (graph.name,)
+ delayedptr = lltype._ptr(lltype.Ptr(FUNCTYPE), name, solid=True)
+ else:
+ if FUNCTYPE is None:
+ FUNCTYPE = ootype.ForwardReference()
+ name = "delayed!%s" % (graph.name,)
+ delayedptr = ootype._forward_static_meth(FUNCTYPE, _name=name)
self.delayedfuncs.append((delayedptr, graph))
return delayedptr
@@ -270,9 +278,9 @@
for p, graph in self.delayedfuncs:
self.newgraphs[graph] = True
real_p = rtyper.getcallable(graph)
- REAL = lltype.typeOf(real_p).TO
- FUNCTYPE = lltype.typeOf(p).TO
- if isinstance(FUNCTYPE, lltype.ForwardReference):
+ REAL = get_functype(lltype.typeOf(real_p))
+ FUNCTYPE = get_functype(lltype.typeOf(p))
+ if isinstance(FUNCTYPE, (lltype.ForwardReference, ootype.ForwardReference)):
FUNCTYPE.become(REAL)
assert FUNCTYPE == REAL
p._become(real_p)
@@ -320,9 +328,10 @@
p = self.instance.llfnptr
TYPE = lltype.typeOf(p)
c_func = Constant(p, TYPE)
- for r_arg, ARGTYPE in zip(args_r, TYPE.TO.ARGS):
+ FUNCTYPE = get_functype(TYPE)
+ for r_arg, ARGTYPE in zip(args_r, FUNCTYPE.ARGS):
assert r_arg.lowleveltype == ARGTYPE
- assert r_res.lowleveltype == TYPE.TO.RESULT
+ assert r_res.lowleveltype == FUNCTYPE.RESULT
hop.exception_is_here()
return hop.genop('direct_call', [c_func] + vlist, resulttype = r_res)
Modified: pypy/dist/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rclass.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/rclass.py Wed Jan 16 16:20:07 2008
@@ -720,24 +720,6 @@
# ____________________________________________________________
-_missing = object()
-
-def fishllattr(inst, name, default=_missing):
- p = widest = lltype.normalizeptr(inst)
- while True:
- try:
- return getattr(p, 'inst_' + name)
- except AttributeError:
- pass
- try:
- p = p.super
- except AttributeError:
- break
- if default is _missing:
- raise AttributeError("%s has no field %s" % (lltype.typeOf(widest),
- name))
- return default
-
def feedllattr(inst, name, llvalue):
p = widest = lltype.normalizeptr(inst)
while True:
Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py Wed Jan 16 16:20:07 2008
@@ -31,6 +31,18 @@
raise TypeError
+class ForwardReference(OOType):
+ def become(self, realtype):
+ if not isinstance(realtype, OOType):
+ raise TypeError("ForwardReference can only be to an OOType, "
+ "not %r" % (realtype,))
+ self.__class__ = realtype.__class__
+ self.__dict__ = realtype.__dict__
+
+ def __hash__(self):
+ raise TypeError("%r object is not hashable" % self.__class__.__name__)
+
+
class Class(OOType):
def _defl(self):
@@ -219,7 +231,6 @@
raise NotImplementedError
class StaticMethod(SpecializableType):
- __slots__ = ['_null']
def __init__(self, args, result):
self.ARGS = tuple(args)
@@ -924,9 +935,10 @@
class _static_meth(_callable):
+ allowed_types = (StaticMethod,)
def __init__(self, STATICMETHOD, **attrs):
- assert isinstance(STATICMETHOD, StaticMethod)
+ assert isinstance(STATICMETHOD, self.allowed_types)
_callable.__init__(self, STATICMETHOD, **attrs)
def __call__(self, *args):
@@ -936,6 +948,18 @@
def __repr__(self):
return 'sm %s' % self._name
+class _forward_static_meth(_static_meth):
+ allowed_types = (StaticMethod, ForwardReference)
+
+ def __eq__(self, other):
+ return self is other
+
+ def __hash__(self):
+ return id(self)
+
+ def _become(self, other):
+ assert isinstance(other, _static_meth)
+ self.__dict__ = other.__dict__
class _bound_meth(object):
def __init__(self, DEFINST, inst, meth):
Modified: pypy/dist/pypy/rpython/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/rclass.py (original)
+++ pypy/dist/pypy/rpython/rclass.py Wed Jan 16 16:20:07 2008
@@ -193,3 +193,33 @@
def rtype_new_instance(rtyper, classdef, llops, classcallhop=None):
rinstance = getinstancerepr(rtyper, classdef)
return rinstance.new_instance(llops, classcallhop)
+
+
+_missing = object()
+
+def fishllattr(inst, name, default=_missing):
+ from pypy.rpython.lltypesystem import lltype
+ from pypy.rpython.ootypesystem import ootype
+ if isinstance(inst, (ootype._instance, ootype._view)):
+ # XXX: we need to call ootypesystem.rclass.mangle, but we
+ # can't because we don't have a config object
+ mangled = 'o' + name
+ if default is _missing:
+ return getattr(inst, mangled)
+ else:
+ return getattr(inst, mangled, default)
+ else:
+ p = widest = lltype.normalizeptr(inst)
+ while True:
+ try:
+ return getattr(p, 'inst_' + name)
+ except AttributeError:
+ pass
+ try:
+ p = p.super
+ except AttributeError:
+ break
+ if default is _missing:
+ raise AttributeError("%s has no field %s" % (lltype.typeOf(widest),
+ name))
+ return default
Modified: pypy/dist/pypy/rpython/test/test_llann.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_llann.py (original)
+++ pypy/dist/pypy/rpython/test/test_llann.py Wed Jan 16 16:20:07 2008
@@ -1,5 +1,5 @@
from pypy.rpython.lltypesystem.lltype import *
-from pypy.rpython.lltypesystem.rclass import OBJECTPTR, fishllattr
+from pypy.rpython.rclass import OBJECTPTR, fishllattr
from pypy.translator.translator import TranslationContext
from pypy.annotation import model as annmodel
from pypy.rpython.annlowlevel import annotate_lowlevel_helper
Modified: pypy/dist/pypy/rpython/typesystem.py
==============================================================================
--- pypy/dist/pypy/rpython/typesystem.py (original)
+++ pypy/dist/pypy/rpython/typesystem.py Wed Jan 16 16:20:07 2008
@@ -153,6 +153,9 @@
vlist = hop.inputargs(repr)
return hop.genop('oononnull', vlist, resulttype=ootype.Bool)
+ def getconcretetype(self, v):
+ return v.concretetype
+
def null_callable(self, T):
return ootype.null(T)
Modified: pypy/dist/pypy/translator/simplify.py
==============================================================================
--- pypy/dist/pypy/translator/simplify.py (original)
+++ pypy/dist/pypy/translator/simplify.py Wed Jan 16 16:20:07 2008
@@ -25,7 +25,7 @@
def get_functype(TYPE):
if isinstance(TYPE, lltype.Ptr):
return TYPE.TO
- elif isinstance(TYPE, ootype.StaticMethod):
+ elif isinstance(TYPE, (ootype.StaticMethod, ootype.ForwardReference)):
return TYPE
assert False
More information about the pypy-svn
mailing list