[pypy-svn] r23788 - in pypy/dist/pypy/rpython: . lltypesystem ootypesystem test
nik at codespeak.net
nik at codespeak.net
Tue Feb 28 22:40:09 CET 2006
Author: nik
Date: Tue Feb 28 22:40:03 2006
New Revision: 23788
Modified:
pypy/dist/pypy/rpython/llinterp.py
pypy/dist/pypy/rpython/lltypesystem/rpbc.py
pypy/dist/pypy/rpython/ootypesystem/rclass.py
pypy/dist/pypy/rpython/ootypesystem/rpbc.py
pypy/dist/pypy/rpython/rmodel.py
pypy/dist/pypy/rpython/rpbc.py
pypy/dist/pypy/rpython/test/test_rpbc.py
pypy/dist/pypy/rpython/typesystem.py
Log:
(nik, mwh, pedronis around a bit)
Move MethodOfFrozenPBCRepr up into rpython.rpbc.
Simplify quite a bit the handling of 'is' in the ootypesytem.
Enable more rpbc tests for the ootypesystem.
Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py (original)
+++ pypy/dist/pypy/rpython/llinterp.py Tue Feb 28 22:40:03 2006
@@ -779,11 +779,16 @@
assert isinstance(inst, ootype._instance)
return bool(inst)
- def op_oois(self, inst1, inst2):
- assert isinstance(inst1, ootype._instance)
- assert isinstance(inst2, ootype._instance)
- return inst1 == inst2 # NB. differently-typed NULLs must be equal
-
+ def op_oois(self, obj1, obj2):
+ if isinstance(obj1, ootype._instance):
+ assert isinstance(obj2, ootype._instance)
+ return obj1 == obj2 # NB. differently-typed NULLs must be equal
+ elif isinstance(obj1, ootype._class):
+ assert isinstance(obj2, ootype._class)
+ return obj1 is obj2
+ else:
+ assert False, "oois on something silly"
+
def op_instanceof(self, inst, INST):
return ootype.instanceof(inst, INST)
@@ -793,11 +798,6 @@
def op_subclassof(self, class1, class2):
return ootype.subclassof(class1, class2)
- def op_oosameclass(self, class1, class2):
- assert isinstance(class1, ootype._class)
- assert isinstance(class2, ootype._class)
- return class1 is class2
-
def op_ooidentityhash(self, inst):
return ootype.ooidentityhash(inst)
Modified: pypy/dist/pypy/rpython/lltypesystem/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rpbc.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/rpbc.py Tue Feb 28 22:40:03 2006
@@ -13,7 +13,7 @@
from pypy.rpython.rpbc import samesig,\
commonbase, allattributenames, adjust_shape, FunctionsPBCRepr, \
AbstractClassesPBCRepr, AbstractMethodsPBCRepr, OverriddenFunctionPBCRepr, \
- AbstractMultipleFrozenPBCRepr
+ AbstractMultipleFrozenPBCRepr, MethodOfFrozenPBCRepr
from pypy.rpython.lltypesystem import rclass
from pypy.tool.sourcetools import has_varargs
@@ -54,80 +54,6 @@
# ____________________________________________________________
-
-class MethodOfFrozenPBCRepr(Repr):
- """Representation selected for a PBC of method object(s) of frozen PBCs.
- It assumes that all methods are the same function bound to different PBCs.
- The low-level representation can then be a pointer to that PBC."""
-
- def __init__(self, rtyper, s_pbc):
- self.rtyper = rtyper
- self.funcdesc = s_pbc.descriptions.keys()[0].funcdesc
-
- # a hack to force the underlying function to show up in call_families
- # (generally not needed, as normalizecalls() should ensure this,
- # but needed for bound methods that are ll helpers)
- # XXX sort this out
- #call_families = rtyper.annotator.getpbccallfamilies()
- #call_families.find((None, self.function))
-
- if s_pbc.can_be_none():
- raise TyperError("unsupported: variable of type "
- "method-of-frozen-PBC or None")
-
- im_selves = []
- for desc in s_pbc.descriptions:
- assert desc.funcdesc is self.funcdesc
- im_selves.append(desc.frozendesc)
-
- self.s_im_self = annmodel.SomePBC(im_selves)
- self.r_im_self = rtyper.getrepr(self.s_im_self)
- self.lowleveltype = self.r_im_self.lowleveltype
-
- def get_s_callable(self):
- return annmodel.SomePBC([self.funcdesc])
-
- def get_r_implfunc(self):
- r_func = self.rtyper.getrepr(self.get_s_callable())
- return r_func, 1
-
- def convert_desc(self, mdesc):
- if mdesc.funcdesc is not self.funcdesc:
- raise TyperError("not a method bound on %r: %r" % (self.funcdesc,
- mdesc))
- return self.r_im_self.convert_desc(mdesc.frozendesc)
-
- def convert_const(self, method):
- mdesc = self.rtyper.annotator.bookkeeper.getdesc(method)
- return self.convert_desc(mdesc)
-
- def rtype_simple_call(self, hop):
- return self.redispatch_call(hop, call_args=False)
-
- def rtype_call_args(self, hop):
- return self.redispatch_call(hop, call_args=True)
-
- def redispatch_call(self, hop, call_args):
- # XXX obscure, try to refactor...
- s_function = annmodel.SomePBC([self.funcdesc])
- hop2 = hop.copy()
- hop2.args_s[0] = self.s_im_self # make the 1st arg stand for 'im_self'
- hop2.args_r[0] = self.r_im_self # (same lowleveltype as 'self')
- if isinstance(hop2.args_v[0], Constant):
- boundmethod = hop2.args_v[0].value
- hop2.args_v[0] = Constant(boundmethod.im_self)
- if call_args:
- hop2.swap_fst_snd_args()
- _, s_shape = hop2.r_s_popfirstarg() # temporarely remove shape
- adjust_shape(hop2, s_shape)
- # a marker that would crash if actually used...
- c = Constant("obscure-don't-use-me")
- hop2.v_s_insertfirstarg(c, s_function) # insert 'function'
- # now hop2 looks like simple_call(function, self, args...)
- return hop2.dispatch()
-
-# ____________________________________________________________
-
class MethodsPBCRepr(AbstractMethodsPBCRepr):
"""Representation selected for a PBC of the form {func: classdef...}.
It assumes that all the methods come from the same name in a base
Modified: pypy/dist/pypy/rpython/ootypesystem/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rclass.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/rclass.py Tue Feb 28 22:40:03 2006
@@ -27,21 +27,6 @@
vlist = hop.inputargs(class_repr, class_repr)
return hop.genop('subclassof', vlist, resulttype=ootype.Bool)
-
- def rtype_is_((r_cls1, r_cls2), hop):
- class_repr = get_type_repr(self.rtyper)
- vlist = hop.inputargs(class_repr, class_repr)
- return hop.genop('oosameclass', vlist, resulttype=ootype.Bool)
-
-
-def rtype_classes_is_(_, hop):
- class_repr = get_type_repr(hop.rtyper)
- vlist = hop.inputargs(class_repr, class_repr)
- return hop.genop('oosameclass', vlist, resulttype=ootype.Bool)
-
-class __extend__(pairtype(ClassRepr, ClassRepr)):
- rtype_is_ = rtype_classes_is_
-
# ____________________________________________________________
def mangle(name):
Modified: pypy/dist/pypy/rpython/ootypesystem/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rpbc.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/rpbc.py Tue Feb 28 22:40:03 2006
@@ -1,12 +1,12 @@
from pypy.rpython.rmodel import CanBeNull, Repr, inputconst
from pypy.rpython.rpbc import AbstractClassesPBCRepr, AbstractMethodsPBCRepr, \
- AbstractMultipleFrozenPBCRepr
+ AbstractMultipleFrozenPBCRepr, MethodOfFrozenPBCRepr
from pypy.rpython.rclass import rtype_new_instance, getinstancerepr
from pypy.rpython.rpbc import get_concrete_calltable
from pypy.rpython import callparse
from pypy.rpython.ootypesystem import ootype
from pypy.rpython.ootypesystem.rclass import ClassRepr, InstanceRepr
-from pypy.rpython.ootypesystem.rclass import rtype_classes_is_, mangle
+from pypy.rpython.ootypesystem.rclass import mangle
from pypy.annotation import model as annmodel
from pypy.annotation import description
from pypy.annotation.pairtype import pairtype
@@ -125,14 +125,6 @@
def convert_from_to(_, v, llops):
return v
-
-class __extend__(pairtype(ClassRepr, ClassesPBCRepr)):
- rtype_is_ = rtype_classes_is_
-
-class __extend__(pairtype(ClassesPBCRepr, ClassRepr)):
- rtype_is_ = rtype_classes_is_
-
-
class MultipleFrozenPBCRepr(AbstractMultipleFrozenPBCRepr):
"""Representation selected for multiple non-callable pre-built constants."""
def __init__(self, rtyper, access_set):
Modified: pypy/dist/pypy/rpython/rmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/rmodel.py (original)
+++ pypy/dist/pypy/rpython/rmodel.py Tue Feb 28 22:40:03 2006
@@ -235,22 +235,7 @@
def rtype_is_((robj1, robj2), hop):
if hop.s_result.is_constant():
return inputconst(Bool, hop.s_result.const)
- roriginal1 = robj1
- roriginal2 = robj2
- if robj1.lowleveltype is Void:
- robj1 = robj2
- elif robj2.lowleveltype is Void:
- robj2 = robj1
- if (not isinstance(robj1.lowleveltype, Ptr) or
- not isinstance(robj2.lowleveltype, Ptr)):
- raise TyperError('is of instances of the non-pointers: %r, %r' % (
- roriginal1, roriginal2))
- if robj1.lowleveltype != robj2.lowleveltype:
- raise TyperError('is of instances of different pointer types: %r, %r' % (
- roriginal1, roriginal2))
-
- v_list = hop.inputargs(robj1, robj2)
- return hop.genop('ptr_eq', v_list, resulttype=Bool)
+ return hop.rtyper.type_system.generic_is(robj1, robj2, hop)
# ____________________________________________________________
Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py (original)
+++ pypy/dist/pypy/rpython/rpbc.py Tue Feb 28 22:40:03 2006
@@ -447,6 +447,78 @@
return inputdesc(r_pbc2, frozendesc1)
return NotImplemented
+
+class MethodOfFrozenPBCRepr(Repr):
+ """Representation selected for a PBC of method object(s) of frozen PBCs.
+ It assumes that all methods are the same function bound to different PBCs.
+ The low-level representation can then be a pointer to that PBC."""
+
+ def __init__(self, rtyper, s_pbc):
+ self.rtyper = rtyper
+ self.funcdesc = s_pbc.descriptions.keys()[0].funcdesc
+
+ # a hack to force the underlying function to show up in call_families
+ # (generally not needed, as normalizecalls() should ensure this,
+ # but needed for bound methods that are ll helpers)
+ # XXX sort this out
+ #call_families = rtyper.annotator.getpbccallfamilies()
+ #call_families.find((None, self.function))
+
+ if s_pbc.can_be_none():
+ raise TyperError("unsupported: variable of type "
+ "method-of-frozen-PBC or None")
+
+ im_selves = []
+ for desc in s_pbc.descriptions:
+ assert desc.funcdesc is self.funcdesc
+ im_selves.append(desc.frozendesc)
+
+ self.s_im_self = annmodel.SomePBC(im_selves)
+ self.r_im_self = rtyper.getrepr(self.s_im_self)
+ self.lowleveltype = self.r_im_self.lowleveltype
+
+ def get_s_callable(self):
+ return annmodel.SomePBC([self.funcdesc])
+
+ def get_r_implfunc(self):
+ r_func = self.rtyper.getrepr(self.get_s_callable())
+ return r_func, 1
+
+ def convert_desc(self, mdesc):
+ if mdesc.funcdesc is not self.funcdesc:
+ raise TyperError("not a method bound on %r: %r" % (self.funcdesc,
+ mdesc))
+ return self.r_im_self.convert_desc(mdesc.frozendesc)
+
+ def convert_const(self, method):
+ mdesc = self.rtyper.annotator.bookkeeper.getdesc(method)
+ return self.convert_desc(mdesc)
+
+ def rtype_simple_call(self, hop):
+ return self.redispatch_call(hop, call_args=False)
+
+ def rtype_call_args(self, hop):
+ return self.redispatch_call(hop, call_args=True)
+
+ def redispatch_call(self, hop, call_args):
+ # XXX obscure, try to refactor...
+ s_function = annmodel.SomePBC([self.funcdesc])
+ hop2 = hop.copy()
+ hop2.args_s[0] = self.s_im_self # make the 1st arg stand for 'im_self'
+ hop2.args_r[0] = self.r_im_self # (same lowleveltype as 'self')
+ if isinstance(hop2.args_v[0], Constant):
+ boundmethod = hop2.args_v[0].value
+ hop2.args_v[0] = Constant(boundmethod.im_self)
+ if call_args:
+ hop2.swap_fst_snd_args()
+ _, s_shape = hop2.r_s_popfirstarg() # temporarely remove shape
+ adjust_shape(hop2, s_shape)
+ # a marker that would crash if actually used...
+ c = Constant("obscure-don't-use-me")
+ hop2.v_s_insertfirstarg(c, s_function) # insert 'function'
+ # now hop2 looks like simple_call(function, self, args...)
+ return hop2.dispatch()
+
# __ None ____________________________________________________
class NoneFrozenPBCRepr(SingleFrozenPBCRepr):
Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py (original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py Tue Feb 28 22:40:03 2006
@@ -148,71 +148,71 @@
res = interpret(f, [-1], type_system=self.ts)
assert res == 6
-def test_call_frozen_pbc_simple():
- fr1 = Freezing()
- fr1.x = 5
- def f(n):
- return fr1.mymethod(n)
- res = interpret(f, [6])
- assert res == 11
-
-def test_call_frozen_pbc_simple_w_kwds():
- fr1 = Freezing()
- fr1.x = 5
- def f(n):
- return fr1.mymethod(y=n)
- res = interpret(f, [6])
- assert res == 11
-
-def test_call_frozen_pbc_multiple():
- fr1 = Freezing()
- fr2 = Freezing()
- fr1.x = 5
- fr2.x = 6
- def f(n):
- if n > 0:
- fr = fr1
- else:
- fr = fr2
- return fr.mymethod(n)
- res = interpret(f, [1])
- assert res == 6
- res = interpret(f, [-1])
- assert res == 5
+ def test_call_frozen_pbc_simple(self):
+ fr1 = Freezing()
+ fr1.x = 5
+ def f(n):
+ return fr1.mymethod(n)
+ res = interpret(f, [6], type_system=self.ts)
+ assert res == 11
+
+ def test_call_frozen_pbc_simple_w_kwds(self):
+ fr1 = Freezing()
+ fr1.x = 5
+ def f(n):
+ return fr1.mymethod(y=n)
+ res = interpret(f, [6], type_system=self.ts)
+ assert res == 11
+
+ def test_call_frozen_pbc_multiple(self):
+ fr1 = Freezing()
+ fr2 = Freezing()
+ fr1.x = 5
+ fr2.x = 6
+ def f(n):
+ if n > 0:
+ fr = fr1
+ else:
+ fr = fr2
+ return fr.mymethod(n)
+ res = interpret(f, [1], type_system=self.ts)
+ assert res == 6
+ res = interpret(f, [-1], type_system=self.ts)
+ assert res == 5
-def test_call_frozen_pbc_multiple_w_kwds():
- fr1 = Freezing()
- fr2 = Freezing()
- fr1.x = 5
- fr2.x = 6
- def f(n):
- if n > 0:
- fr = fr1
- else:
- fr = fr2
- return fr.mymethod(y=n)
- res = interpret(f, [1])
- assert res == 6
- res = interpret(f, [-1])
- assert res == 5
+ def test_call_frozen_pbc_multiple_w_kwds(self):
+ fr1 = Freezing()
+ fr2 = Freezing()
+ fr1.x = 5
+ fr2.x = 6
+ def f(n):
+ if n > 0:
+ fr = fr1
+ else:
+ fr = fr2
+ return fr.mymethod(y=n)
+ res = interpret(f, [1], type_system=self.ts)
+ assert res == 6
+ res = interpret(f, [-1], type_system=self.ts)
+ assert res == 5
-def test_is_among_frozen():
- fr1 = Freezing()
- fr2 = Freezing()
- def givefr1():
- return fr1
- def givefr2():
- return fr2
- def f(i):
- if i == 1:
- fr = givefr1()
- else:
- fr = givefr2()
- return fr is fr1
- res = interpret(f, [0])
- assert res is False
- res = interpret(f, [1])
- assert res is True
+ def test_is_among_frozen(self):
+ fr1 = Freezing()
+ fr2 = Freezing()
+ def givefr1():
+ return fr1
+ def givefr2():
+ return fr2
+ def f(i):
+ if i == 1:
+ fr = givefr1()
+ else:
+ fr = givefr2()
+ return fr is fr1
+ res = interpret(f, [0], type_system=self.ts)
+ assert res is False
+ res = interpret(f, [1], type_system=self.ts)
+ assert res is True
def test_unbound_method():
def f():
Modified: pypy/dist/pypy/rpython/typesystem.py
==============================================================================
--- pypy/dist/pypy/rpython/typesystem.py (original)
+++ pypy/dist/pypy/rpython/typesystem.py Tue Feb 28 22:40:03 2006
@@ -5,6 +5,7 @@
from pypy.rpython.ootypesystem import ootype
from pypy.rpython.lltypesystem import lltype
+from pypy.rpython import error
class TypeSystem(object):
__metaclass__ = extendabletype
@@ -92,6 +93,24 @@
def isCompatibleType(self, t1, t2):
return lltype.isCompatibleType(t1, t2)
+ def generic_is(self, robj1, robj2, hop):
+ roriginal1 = robj1
+ roriginal2 = robj2
+ if robj1.lowleveltype is lltype.Void:
+ robj1 = robj2
+ elif robj2.lowleveltype is lltype.Void:
+ robj2 = robj1
+ if (not isinstance(robj1.lowleveltype, lltype.Ptr) or
+ not isinstance(robj2.lowleveltype, lltype.Ptr)):
+ raise TyperError('is of instances of the non-pointers: %r, %r' % (
+ roriginal1, roriginal2))
+ if robj1.lowleveltype != robj2.lowleveltype:
+ raise TyperError('is of instances of different pointer types: %r, %r' % (
+ roriginal1, roriginal2))
+
+ v_list = hop.inputargs(robj1, robj2)
+ return hop.genop('ptr_eq', v_list, resulttype=lltype.Bool)
+
class ObjectOrientedTypeSystem(TypeSystem):
name = "ootypesystem"
callable_trait = (ootype.StaticMethod, ootype.static_meth)
@@ -106,6 +125,23 @@
def isCompatibleType(self, t1, t2):
return ootype.isCompatibleType(t1, t2)
+ def generic_is(self, robj1, robj2, hop):
+ roriginal1 = robj1
+ roriginal2 = robj2
+ if robj1.lowleveltype is lltype.Void:
+ robj1 = robj2
+ elif robj2.lowleveltype is lltype.Void:
+ robj2 = robj1
+ if (not isinstance(robj1.lowleveltype, ootype.Instance) or
+ not isinstance(robj2.lowleveltype, ootype.Instance)) and \
+ (robj1.lowleveltype is not ootype.Class or
+ robj2.lowleveltype is not ootype.Class):
+ raise error.TyperError('is of instances of the non-instances: %r, %r' % (
+ roriginal1, roriginal2))
+
+ v_list = hop.inputargs(robj1, robj2)
+ return hop.genop('oois', v_list, resulttype=lltype.Bool)
+
# All typesystems are singletons
LowLevelTypeSystem.instance = LowLevelTypeSystem()
ObjectOrientedTypeSystem.instance = ObjectOrientedTypeSystem()
More information about the Pypy-commit
mailing list