[pypy-svn] r20224 - in pypy/branch/somepbc-refactoring/pypy/rpython: . lltypesystem
pedronis at codespeak.net
pedronis at codespeak.net
Fri Nov 25 00:43:01 CET 2005
Author: pedronis
Date: Fri Nov 25 00:43:00 2005
New Revision: 20224
Modified:
pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/rpbc.py
pypy/branch/somepbc-refactoring/pypy/rpython/rmodel.py
pypy/branch/somepbc-refactoring/pypy/rpython/rpbc.py
Log:
start implementing convert_const for PBC reprs, as a pair convert_const/convert_desc with the former delegating
to the latter. Now convert_desc just takes a desc.
Have an inputdesc taking a desc parallel to inputconst helper.
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/rpbc.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/rpbc.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/rpbc.py Fri Nov 25 00:43:00 2005
@@ -6,7 +6,8 @@
from pypy.rpython.lltypesystem.lltype import \
typeOf, Void, ForwardReference, Struct, Bool, \
Ptr, malloc, nullptr
-from pypy.rpython.rmodel import Repr, TyperError, inputconst, warning, mangle
+from pypy.rpython.rmodel import Repr, TyperError, inputconst, inputdesc
+from pypy.rpython.rmodel import warning, mangle
from pypy.rpython import robject
from pypy.rpython import rtuple
from pypy.rpython.rpbc import SingleFrozenPBCRepr, samesig,\
@@ -28,9 +29,10 @@
class MultipleFrozenPBCRepr(MultiplePBCRepr):
"""Representation selected for multiple non-callable pre-built constants."""
- def __init__(self, rtyper, access_set):
+ def __init__(self, rtyper, frozendescs):
self.rtyper = rtyper
- self.access_set = access_set
+ self.descs = frozendescs
+ self.access_set = frozendescs[0].queryattrfamily()
self.pbc_type = ForwardReference()
self.lowleveltype = Ptr(self.pbc_type)
self.pbc_cache = {}
@@ -50,25 +52,20 @@
self.pbc_type.become(Struct('pbc', *llfields))
self.llfieldmap = llfieldmap
- def convert_const(self, pbc):
- if pbc is None:
- return nullptr(self.pbc_type)
- if isinstance(pbc, types.MethodType) and pbc.im_self is None:
- value = pbc.im_func # unbound method -> bare function
-## if pbc not in self.access_set.objects:
-## raise TyperError("not found in PBC set: %r" % (pbc,))
+ def convert_desc(self, frozendesc):
+ if frozendesc not in self.descs:
+ raise TyperError("not found in PBC set: %r" % (frozendesc,))
try:
- return self.pbc_cache[pbc]
+ return self.pbc_cache[frozendesc]
except KeyError:
self.setup()
result = malloc(self.pbc_type, immortal=True)
- desc = self.rtyper.annotator.bookkeeper.getdesc(pbc)
- self.pbc_cache[pbc] = result
+ self.pbc_cache[frozendesc] = result
for attr, (mangled_name, r_value) in self.llfieldmap.items():
if r_value.lowleveltype is Void:
continue
try:
- thisattrvalue = desc.read_attribute(attr)
+ thisattrvalue = frozendesc.read_attribute(attr)
except AttributeError:
warning("PBC %r has no attribute %r" % (pbc, attr))
continue
@@ -76,6 +73,14 @@
setattr(result, mangled_name, llvalue)
return result
+ def convert_const(self, pbc):
+ if pbc is None:
+ return nullptr(self.pbc_type)
+ if isinstance(pbc, types.MethodType) and pbc.im_self is None:
+ value = pbc.im_func # unbound method -> bare function
+ frozendesc = self.rtyper.annotator.bookkeeper.getdesc(pbc)
+ return self.convert_desc(frozendesc)
+
def rtype_getattr(self, hop):
attr = hop.args_s[1].const
vpbc, vattr = hop.inputargs(self, Void)
@@ -98,7 +103,7 @@
frozendesc1 = r_pbc1.frozendesc
access = frozendesc1.queryattrfamily()
if access is r_pbc2.access_set:
- return r_pbc1.convert_desc(r_pbc2, frozendesc1)
+ return inputdesc(r_pbc2, frozendesc1)
return NotImplemented
# ____________________________________________________________
@@ -140,12 +145,15 @@
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)
- if mdesc.funcdesc is not self.funcdesc:
- raise TyperError("not a method bound on %r: %r" % (self.funcdesc,
- method))
- return self.r_im_self.convert_const(method.im_self)
+ return self.convert_desc(mdesc)
def rtype_simple_call(self, hop):
return self.redispatch_call(hop, call_args=False)
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/rmodel.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/rmodel.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/rmodel.py Fri Nov 25 00:43:00 2005
@@ -90,14 +90,14 @@
def _freeze_(self):
return True
- def convert_desc_or_const(self, value):
- if isinstance(self, description.Desc):
- return self.convert_desc(self, value)
- elif isinstance(value, flowmodel.Constant):
- return self.convert_const(value.value)
+ def convert_desc_or_const(self, desc_or_const):
+ if isinstance(desc_or_const, description.Desc):
+ return self.convert_desc(desc_or_const)
+ elif isinstance(desc_or_const, flowmodel.Constant):
+ return self.convert_const(desc_or_const.value)
else:
raise TyperError("convert_desc_or_const expects a Desc"
- "or Constant: %r" % value)
+ "or Constant: %r" % desc_or_const)
def convert_const(self, value):
"Convert the given constant value to the low-level repr of 'self'."
@@ -286,6 +286,17 @@
# ____________________________________________________________
+def inputdesc(reqtype, desc):
+ """Return a Constant for the given desc, of the requested type,
+ which can only be a Repr.
+ """
+ assert isinstance(reqtype, Repr)
+ value = reqtype.convert_desc(desc)
+ lltype = reqtype.lowleveltype
+ c = Constant(value)
+ c.concretetype = lltype
+ return c
+
def inputconst(reqtype, value):
"""Return a Constant with the given value, of the requested type,
which can be a Repr instance or a low-level type.
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/rpbc.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/rpbc.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/rpbc.py Fri Nov 25 00:43:00 2005
@@ -200,16 +200,10 @@
## assert self._function_signatures
## return self._function_signatures
- def convert_const(self, value):
- if isinstance(value, types.MethodType) and value.im_self is None:
- value = value.im_func # unbound method -> bare function
- if self.lowleveltype is Void:
- return inputconst(Void, value)
- null = nullptr(self.lowleveltype.TO)
- if value is None:
- return null
+ def convert_desc(self, funcdesc):
# get the whole "column" of the call table corresponding to this desc
- funcdesc = self.rtyper.annotator.bookkeeper.getdesc(value)
+ if self.lowleveltype is Void:
+ return funcdesc.pyobj
llfns = {}
found_anything = False
for row in self.uniquerows:
@@ -220,13 +214,24 @@
llfn = null
llfns[row.attrname] = llfn
if not found_anything:
- raise TyperError("%r not in %r" % (value,
+ raise TyperError("%r not in %r" % (funcdesc,
self.s_pbc.descriptions))
if len(self.uniquerows) == 1:
return llfn # from the loop above
else:
XXX_later
+ def convert_const(self, value):
+ if isinstance(value, types.MethodType) and value.im_self is None:
+ value = value.im_func # unbound method -> bare function
+ if self.lowleveltype is Void:
+ return value
+ null = nullptr(self.lowleveltype.TO)
+ if value is None:
+ return null
+ funcdesc = self.rtyper.annotator.bookkeeper.getdesc(value)
+ return self.convert_desc(funcdesc)
+
def convert_to_concrete_llfn(self, v, shape, index, llop):
"""Convert the variable 'v' to a variable referring to a concrete
low-level function. In case the call table contains multiple rows,
@@ -292,7 +297,7 @@
try:
return rtyper.pbc_reprs[access]
except KeyError:
- result = rtyper.type_system.rpbc.MultipleFrozenPBCRepr(rtyper, access)
+ result = rtyper.type_system.rpbc.MultipleFrozenPBCRepr(rtyper, descs)
rtyper.pbc_reprs[access] = result
rtyper.add_pendingsetup(result)
return result
@@ -310,10 +315,6 @@
raise TyperError("getattr on a constant PBC returns a non-constant")
return hop.inputconst(hop.r_result, hop.s_result.const)
- def convert_desc(self, to_repr, frozendesc):
- assert self.frozendesc is frozendesc
- return inputconst(to_repr, frozendesc.pyobj)
-
# __ None ____________________________________________________
class NoneFrozenPBCRepr(SingleFrozenPBCRepr):
More information about the Pypy-commit
mailing list