[pypy-svn] r20173 - pypy/branch/somepbc-refactoring/pypy/rpython
pedronis at codespeak.net
pedronis at codespeak.net
Tue Nov 22 22:35:35 CET 2005
Author: pedronis
Date: Tue Nov 22 22:35:34 2005
New Revision: 20173
Modified:
pypy/branch/somepbc-refactoring/pypy/rpython/callparse.py
pypy/branch/somepbc-refactoring/pypy/rpython/rpbc.py
Log:
(pedronis, arigo)
slow progress. no increase in tests passing.
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/callparse.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/callparse.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/callparse.py Tue Nov 22 22:35:34 2005
@@ -29,13 +29,21 @@
raise CallPatternTooComplex, "'*' argument must be a tuple"
-def callparse(op, graph, rinputs, hop):
+def callparse(rtyper, graph, hop, opname):
+ """Parse the arguments of 'hop' when calling the given 'graph'.
+ Return a list of low-level variables and the repr of the result.
+ """
+ rinputs = [rtyper.bindingrepr(v) for v in graph.getargs()]
+ if graph.getreturnvar() in rtyper.annotator.bindings:
+ rresult = rtyper.bindingrepr(graph.getreturnvar())
+ else:
+ rresult = Void
space = RPythonCallsSpace()
def args_h(start):
return [VarHolder(i, hop.args_s[i]) for i in range(start, hop.nb_args)]
- if op == "simple_call":
+ if opname == "simple_call":
arguments = Arguments(space, args_h(1))
- elif op == "call_args":
+ elif opname == "call_args":
arguments = Arguments.fromshape(space, hop.args_s[1].const, # shape
args_h(2))
# parse the arguments according to the function we are calling
@@ -54,7 +62,7 @@
for h,r in zip(holders, rinputs):
v = h.emit(r, hop)
vlist.append(v)
- return vlist
+ return vlist, rresult
class Holder(object):
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 Tue Nov 22 22:35:34 2005
@@ -76,7 +76,7 @@
self.s_pbc = s_pbc
self._function_signatures = None
self.callfamily = s_pbc.descriptions.iterkeys().next().getcallfamily()
- if len(s_pbc.descriptions) == 1:
+ if len(s_pbc.descriptions) == 1 and not s_pbc.can_be_None:
# a single function
self.lowleveltype = Void
else:
@@ -102,27 +102,45 @@
rtyper = self.rtyper
return [rtyper.binding(arg) for arg in graph.getargs()], rtyper.binding(graph.getreturnvar())
- def function_signatures(self):
- if self._function_signatures is None:
- self._function_signatures = {}
- for func in self.s_pbc.prebuiltinstances:
- if func is not None:
- self._function_signatures[func] = getsignature(self.rtyper,
- func)
- assert self._function_signatures
- return self._function_signatures
+## def function_signatures(self):
+## if self._function_signatures is None:
+## self._function_signatures = {}
+## for func in self.s_pbc.prebuiltinstances:
+## if func is not None:
+## self._function_signatures[func] = getsignature(self.rtyper,
+## func)
+## assert self._function_signatures
+## return self._function_signatures
def convert_const(self, value):
if value is None:
return nullptr(self.lowleveltype.TO)
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)
+ XXX
if value not in self.function_signatures():
raise TyperError("%r not in %r" % (value,
self.s_pbc.prebuiltinstances))
f, rinputs, rresult = self.function_signatures()[value]
return f
+ def get_concrete_llfn(self, v, index, shape):
+ """Convert the variable 'v' to a variable referring to a concrete
+ low-level function. In case the call table contains multiple rows,
+ 'index' and 'shape' tells which of its items we are interested in."""
+ assert index == 0 # for now
+ if self.lowleveltype is Void:
+ table = self.callfamily.calltables[shape]
+ row = table[index]
+ assert len(row) == 1 # lowleveltype wouldn't be Void otherwise
+ graph, = row.values()
+ f = self.rtyper.getcallable(graph)
+ return inputconst(typeOf(f), f)
+ else:
+ Baoum
+
def rtype_simple_call(self, hop):
bk = self.rtyper.annotator.bookkeeper
args = bk.build_args("simple_call", hop.args_s[1:])
@@ -130,14 +148,11 @@
row = description.FunctionDesc.row_to_consider(descs, args)
index, merged = self.callfamily.calltable_lookup_row(args.rawshape(),
row)
- assert len(merged) == 1 # for now
- [(funcdesc, graph)] = merged.items()
- llfnobj = self.rtyper.getcallable(graph)
- vlist = [hop.inputconst(typeOf(llfnobj), llfnobj)]
- rinputs = [self.rtyper.bindingrepr(graph.getargs()[i])
- for i in range(len(graph.getargs()))]
- vlist += callparse.callparse('simple_call', graph, rinputs, hop)
- rresult = self.rtyper.bindingrepr(graph.getreturnvar())
+ graph = merged.itervalues().next() # pick any witness
+ vlist, rresult = callparse.callparse(self.rtyper, graph,
+ hop, 'simple_call')
+ vfn = hop.inputarg(self, arg=0)
+ vlist.insert(0, self.get_concrete_llfn(vfn, index, args.rawshape()))
hop.exception_is_here()
v = hop.genop('direct_call', vlist, resulttype = rresult)
return hop.llops.convertvar(v, rresult, hop.r_result)
@@ -392,15 +407,15 @@
# ____________________________________________________________
-def getsignature(rtyper, func):
- f = rtyper.getcallable(func)
- graph = rtyper.type_system_deref(f).graph
- rinputs = [rtyper.bindingrepr(v) for v in graph.getargs()]
- if graph.getreturnvar() in rtyper.annotator.bindings:
- rresult = rtyper.bindingrepr(graph.getreturnvar())
- else:
- rresult = Void
- return f, rinputs, rresult
+##def getsignature(rtyper, func):
+## f = rtyper.getcallable(func)
+## graph = rtyper.type_system_deref(f).graph
+## rinputs = [rtyper.bindingrepr(v) for v in graph.getargs()]
+## if graph.getreturnvar() in rtyper.annotator.bindings:
+## rresult = rtyper.bindingrepr(graph.getreturnvar())
+## else:
+## rresult = Void
+## return f, rinputs, rresult
def samesig(funcs):
import inspect
More information about the Pypy-commit
mailing list