[pypy-svn] r17670 - pypy/dist/pypy/rpython
arigo at codespeak.net
arigo at codespeak.net
Mon Sep 19 20:38:55 CEST 2005
Author: arigo
Date: Mon Sep 19 20:38:52 2005
New Revision: 17670
Modified:
pypy/dist/pypy/rpython/rclass.py
pypy/dist/pypy/rpython/rfloat.py
pypy/dist/pypy/rpython/rint.py
pypy/dist/pypy/rpython/rlist.py
pypy/dist/pypy/rpython/rmodel.py
pypy/dist/pypy/rpython/rpbc.py
pypy/dist/pypy/rpython/rstr.py
pypy/dist/pypy/rpython/rtyper.py
Log:
Makes calling ll-helpers on Repr instances look less hackish:
we can now call them as bound methods (where the 'self' plays
the role of a specialization argument). Changed ll_str() to
be such a bound method now. The plan is to have many more
such ll-helpers on Reprs. They allow us to have nice interfaces
to manipulate the low-level structures in a way that doesn't
depend so much on the details of the low-level structures in
question.
Modified: pypy/dist/pypy/rpython/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/rclass.py (original)
+++ pypy/dist/pypy/rpython/rclass.py Mon Sep 19 20:38:52 2005
@@ -647,7 +647,7 @@
vinst, = hop.inputargs(self)
return hop.genop('ptr_nonzero', [vinst], resulttype=Bool)
- def ll_str(i, r): # doesn't work for non-gc classes!
+ def ll_str(self, i): # doesn't work for non-gc classes!
instance = cast_pointer(OBJECTPTR, i)
from pypy.rpython import rstr
nameLen = len(instance.typeptr.name)
@@ -659,7 +659,6 @@
return rstr.ll_strconcat(rstr.instance_str_prefix,
rstr.ll_strconcat(nameString,
rstr.instance_str_suffix))
- ll_str = staticmethod(ll_str)
class __extend__(pairtype(InstanceRepr, InstanceRepr)):
Modified: pypy/dist/pypy/rpython/rfloat.py
==============================================================================
--- pypy/dist/pypy/rpython/rfloat.py (original)
+++ pypy/dist/pypy/rpython/rfloat.py Mon Sep 19 20:38:52 2005
@@ -134,7 +134,7 @@
rtype_float = rtype_pos
- def ll_str(f, repr):
+ def ll_str(self, f):
pyfloat = pyfloat_fromdouble_ptr(f)
pystring = pyobject_str_ptr(pyfloat)
stringsize = pystring_size_ptr(pystring)
@@ -144,8 +144,6 @@
tollchararray_ptr(pystring, ret.chars)
return ret
-
- ll_str = staticmethod(ll_str)
PyObjectPtr = Ptr(PyObject)
Modified: pypy/dist/pypy/rpython/rint.py
==============================================================================
--- pypy/dist/pypy/rpython/rint.py (original)
+++ pypy/dist/pypy/rpython/rint.py Mon Sep 19 20:38:52 2005
@@ -289,7 +289,7 @@
vlist = hop.inputargs(Float)
return vlist[0]
- def ll_str(i, repr):
+ def ll_str(self, i):
from pypy.rpython.rstr import STR
temp = malloc(CHAR_ARRAY, 20)
len = 0
@@ -316,7 +316,6 @@
result.chars[j] = temp[len-j-1]
j += 1
return result
- ll_str = staticmethod(ll_str)
def rtype_hex(_, hop):
varg = hop.inputarg(hop.args_r[0], 0)
Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py (original)
+++ pypy/dist/pypy/rpython/rlist.py Mon Sep 19 20:38:52 2005
@@ -170,15 +170,15 @@
def make_iterator_repr(self):
return ListIteratorRepr(self)
- def ll_str(l, listrepr):
+ def ll_str(self, l):
items = l.items
length = l.length
- item_repr = listrepr.item_repr
+ item_repr = self.item_repr
temp = malloc(TEMP, length)
i = 0
while i < length:
- temp[i] = item_repr.ll_str(items[i], item_repr)
+ temp[i] = item_repr.ll_str(items[i])
i += 1
return rstr.ll_strconcat(
@@ -187,8 +187,7 @@
length,
temp),
rstr.list_str_close_bracket))
- ll_str = staticmethod(ll_str)
-
+
class __extend__(pairtype(ListRepr, Repr)):
Modified: pypy/dist/pypy/rpython/rmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/rmodel.py (original)
+++ pypy/dist/pypy/rpython/rmodel.py Mon Sep 19 20:38:52 2005
@@ -129,8 +129,7 @@
raise TyperError("getattr() with a non-constant attribute name")
def rtype_str(self, hop):
- vrepr = inputconst(Void, self)
- return hop.gendirectcall(self.ll_str, hop.args_v[0], vrepr)
+ return hop.gendirectcall(self.ll_str, hop.args_v[0])
def rtype_nonzero(self, hop):
return self.rtype_is_true(hop) # can call a subclass' rtype_is_true()
Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py (original)
+++ pypy/dist/pypy/rpython/rpbc.py Mon Sep 19 20:38:52 2005
@@ -282,6 +282,11 @@
def __init__(self, rtyper, s_pbc):
self.rtyper = rtyper
self.function = s_pbc.prebuiltinstances.keys()[0].im_func
+ # 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)
+ call_families = rtyper.annotator.getpbccallfamilies()
+ call_families.find((None, self.function))
im_selves = {}
for pbc, not_a_classdef in s_pbc.prebuiltinstances.items():
if pbc is None:
Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py (original)
+++ pypy/dist/pypy/rpython/rstr.py Mon Sep 19 20:38:52 2005
@@ -203,13 +203,9 @@
hop.exception_is_here()
return hop.gendirectcall(ll_int, v_str, v_base)
- def ll_str(s, r):
- if typeOf(s) == Char:
- return ll_chr2str(s)
- else:
- return s
- ll_str = staticmethod(ll_str)
-
+ def ll_str(self, s):
+ return s
+
def make_iterator_repr(self):
return string_iterator_repr
@@ -341,17 +337,16 @@
if isinstance(thing, tuple):
code = thing[0]
vitem, r_arg = argsiter.next()
- rep = inputconst(Void, r_arg)
if not hasattr(r_arg, 'll_str'):
raise TyperError("ll_str unsupported for: %r" % r_arg)
if code == 's' or (code == 'r' and isinstance(r_arg, InstanceRepr)):
- vchunk = hop.gendirectcall(r_arg.ll_str, vitem, rep)
+ vchunk = hop.gendirectcall(r_arg.ll_str, vitem)
elif code == 'd':
assert isinstance(r_arg, IntegerRepr)
- vchunk = hop.gendirectcall(r_arg.ll_str, vitem, rep)
+ vchunk = hop.gendirectcall(r_arg.ll_str, vitem)
elif code == 'f':
#assert isinstance(r_arg, FloatRepr)
- vchunk = hop.gendirectcall(r_arg.ll_str, vitem, rep)
+ vchunk = hop.gendirectcall(r_arg.ll_str, vitem)
elif code == 'x':
assert isinstance(r_arg, IntegerRepr)
vchunk = hop.gendirectcall(rint.ll_int2hex, vitem,
@@ -399,6 +394,9 @@
def get_ll_hash_function(self):
return ll_char_hash
+ def ll_str(self, ch):
+ return ll_chr2str(ch)
+
def rtype_len(_, hop):
return hop.inputconst(Signed, 1)
Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py (original)
+++ pypy/dist/pypy/rpython/rtyper.py Mon Sep 19 20:38:52 2005
@@ -728,6 +728,10 @@
self.rtyper.call_all_setups() # compute ForwardReferences now
dontcare, spec_function = annotate_lowlevel_helper(rtyper.annotator, ll_function, args_s)
+ # hack for bound methods
+ if hasattr(ll_function, 'im_func'):
+ newargs_v.insert(0, inputconst(Void, ll_function.im_self))
+
# build the 'direct_call' operation
f = self.rtyper.getfunctionptr(spec_function)
c = inputconst(typeOf(f), f)
More information about the Pypy-commit
mailing list