[pypy-svn] r13040 - pypy/branch/rpython-refactoring
arigo at codespeak.net
arigo at codespeak.net
Fri Jun 3 22:10:36 CEST 2005
Author: arigo
Date: Fri Jun 3 22:10:35 2005
New Revision: 13040
Modified:
pypy/branch/rpython-refactoring/rbuiltin.py
pypy/branch/rpython-refactoring/rint.py
pypy/branch/rpython-refactoring/rlist.py
pypy/branch/rpython-refactoring/robject.py
pypy/branch/rpython-refactoring/rpbc.py
pypy/branch/rpython-refactoring/rptr.py
pypy/branch/rpython-refactoring/rtyper.py
Log:
Intermediate check-in.
Modified: pypy/branch/rpython-refactoring/rbuiltin.py
==============================================================================
--- pypy/branch/rpython-refactoring/rbuiltin.py (original)
+++ pypy/branch/rpython-refactoring/rbuiltin.py Fri Jun 3 22:10:35 2005
@@ -3,65 +3,86 @@
from pypy.rpython.lltype import malloc, typeOf, nullptr, nullgcptr
from pypy.rpython.lltype import Void, Signed
from pypy.rpython.rtyper import TyperError
-from pypy.rpython.rlist import rtype_builtin_range
+from pypy.rpython.rrange import rtype_builtin_range
+from pypy.rpython.rmodel import Repr, TyperError
-class __extend__(SomeBuiltin):
-
- def lowleveltype(s_blt):
- if s_blt.s_self is None:
- assert s_blt.is_constant()
- return Void
- else:
- # methods of a known name are implemented as just their 'self'
- assert s_blt.methodname is not None
- return s_blt.s_self.lowleveltype()
-
- def rtype_simple_call(s_blt, hop):
- if s_blt.s_self is None:
- if not s_blt.is_constant():
- raise TyperError("non-constant built-in")
- try:
- bltintyper = BUILTIN_TYPER[s_blt.const]
- except KeyError:
- raise TyperError("don't know about built-in function %r" % (
- s_blt.const,))
- hop.s_popfirstarg()
+class __extend__(annmodel.SomeBuiltin):
+ def rtyper_makerepr(self, rtyper):
+ if self.s_self is None:
+ # built-in function case
+ if not self.is_constant():
+ raise TyperError("non-constant built-in function!")
+ return BuiltinFunctionRepr(self.const)
else:
- # methods: look up the rtype_method_xxx()
- name = 'rtype_method_' + s_blt.methodname
- try:
- bltintyper = getattr(s_blt.s_self, name)
- except AttributeError:
- raise TyperError("missing %s.%s" % (
- s_blt.s_self.__class__.__name__, name))
+ # built-in method case
+ assert self.methodname is not None
+ return BuiltinMethodRepr(rtyper.getrepr(self.s_self),
+ self.methodname)
+
+
+class BuiltinFunctionRepr(Repr):
+ lowleveltype = Void
+
+ def __init__(self, builtinfunc):
+ self.builtinfunc = builtinfunc
+
+ def rtype_simple_call(self, hop):
+ try:
+ bltintyper = BUILTIN_TYPER[self.builtinfunc]
+ except KeyError:
+ raise TyperError("don't know about built-in function %r" % (
+ self.builtinfunc,))
+ hop.r_s_popfirstarg()
+ return bltintyper(hop)
+
+
+class BuiltinMethodRepr(Repr):
+
+ def __init__(self, self_repr, methodname):
+ self.self_repr = self_repr
+ self.methodname = methodname
+ # methods of a known name are implemented as just their 'self'
+ self.lowleveltype = self_repr.lowleveltype
+
+ def rtype_simple_call(self, hop):
+ # methods: look up the rtype_method_xxx()
+ name = 'rtype_method_' + self.methodname
+ try:
+ bltintyper = getattr(self.self_repr, name)
+ except AttributeError:
+ raise TyperError("missing %s.%s" % (
+ self.self_repr.__class__.__name__, name))
+ # hack based on the fact that 'lowleveltype == self_repr.lowleveltype'
+ assert hop.args_r[0] is self
+ hop.args_r[0] = self.self_repr
return bltintyper(hop)
-class __extend__(pairtype(SomeBuiltin, SomeObject)):
+##class __extend__(pairtype(SomeBuiltin, SomeObject)):
- def rtype_convert_from_to((s_blt, s_to), v, llops):
- if s_blt.s_self is None:
- raise TyperError("conversion requested on a built-in function")
- return llops.convertvar(v, s_blt.s_self, s_to)
+## def rtype_convert_from_to((s_blt, s_to), v, llops):
+## if s_blt.s_self is None:
+## raise TyperError("conversion requested on a built-in function")
+## return llops.convertvar(v, s_blt.s_self, s_to)
# ____________________________________________________________
def rtype_builtin_bool(hop):
assert hop.nb_args == 1
- return hop.args_s[0].rtype_is_true(hop)
+ return hop.args_r[0].rtype_is_true(hop)
def rtype_builtin_int(hop):
- if isinstance(hop.args_s[0], SomeString):
+ if isinstance(hop.args_s[0], annmodel.SomeString):
raise TyperError('int("string") not supported')
assert hop.nb_args == 1
- return hop.args_s[0].rtype_int(hop)
+ return hop.args_r[0].rtype_int(hop)
def rtype_builtin_float(hop):
assert hop.nb_args == 1
- return hop.args_s[0].rtype_float(hop)
+ return hop.args_r[0].rtype_float(hop)
-#def rtype_builtin_range(hop): see rlist.py
+#def rtype_builtin_range(hop): see rrange.py
# collect all functions
@@ -79,11 +100,11 @@
if hop.nb_args == 1:
vlist = hop.inputargs(Void)
return hop.genop('malloc', vlist,
- resulttype = hop.s_result.lowleveltype())
+ resulttype = hop.r_result.lowleveltype)
else:
vlist = hop.inputargs(Void, Signed)
return hop.genop('malloc_varsize', vlist,
- resulttype = hop.s_result.lowleveltype())
+ resulttype = hop.r_result.lowleveltype)
def rtype_const_result(hop):
return hop.inputconst(Void, hop.s_result.const)
Modified: pypy/branch/rpython-refactoring/rint.py
==============================================================================
--- pypy/branch/rpython-refactoring/rint.py (original)
+++ pypy/branch/rpython-refactoring/rint.py Fri Jun 3 22:10:35 2005
@@ -214,8 +214,8 @@
vlist = hop.inputargs(Signed)
return vlist[0]
- def rtype_int(s_int, hop):
- if s_int.unsigned:
+ def rtype_int(r_int, hop):
+ if r_int.lowleveltype == Unsigned:
raise TyperError("use intmask() instead of int(r_uint(...))")
vlist = hop.inputargs(Signed)
return vlist[0]
Modified: pypy/branch/rpython-refactoring/rlist.py
==============================================================================
--- pypy/branch/rpython-refactoring/rlist.py (original)
+++ pypy/branch/rpython-refactoring/rlist.py Fri Jun 3 22:10:35 2005
@@ -34,6 +34,7 @@
self.LIST = GcForwardReference()
self.lowleveltype = GcPtr(self.LIST)
self.item_repr = item_repr # possibly uncomputed at this point!
+ # setup() needs to be called to finish this initialization
def setup(self):
if callable(self.item_repr):
@@ -111,14 +112,14 @@
def rtype_newlist(hop):
nb_args = hop.nb_args
- s_list = hop.s_result
- s_listitem = s_list.get_s_items()
- c1 = hop.inputconst(Void, s_list.lowleveltype())
+ r_list = hop.r_result
+ r_listitem = r_list.item_repr
+ c1 = hop.inputconst(Void, r_list.lowleveltype)
c2 = hop.inputconst(Signed, nb_args)
v_result = hop.gendirectcall(ll_newlist, c1, c2)
for i in range(nb_args):
ci = hop.inputconst(Signed, i)
- v_item = hop.inputarg(s_listitem, arg=i)
+ v_item = hop.inputarg(r_listitem, arg=i)
hop.gendirectcall(ll_setitem_nonneg, v_result, ci, v_item)
return v_result
Modified: pypy/branch/rpython-refactoring/robject.py
==============================================================================
--- pypy/branch/rpython-refactoring/robject.py (original)
+++ pypy/branch/rpython-refactoring/robject.py Fri Jun 3 22:10:35 2005
@@ -8,7 +8,7 @@
class __extend__(annmodel.SomeObject):
def rtyper_makerepr(self, rtyper):
if self.is_constant():
- return constobj_repr
+ return constpyobj_repr
if self.knowntype is type:
return rclass.type_repr
else:
@@ -21,7 +21,7 @@
pyobj_repr = PyObjRepr()
-class ConstObjRepr(Repr):
+class ConstPyObjRepr(Repr):
lowleveltype = Void
-constobj_repr = ConstObjRepr()
+constpyobj_repr = ConstPyObjRepr()
Modified: pypy/branch/rpython-refactoring/rpbc.py
==============================================================================
--- pypy/branch/rpython-refactoring/rpbc.py (original)
+++ pypy/branch/rpython-refactoring/rpbc.py Fri Jun 3 22:10:35 2005
@@ -1,21 +1,31 @@
import types
from pypy.annotation.pairtype import pairtype
from pypy.annotation import model as annmodel
-from pypy.rpython.lltype import typeOf
-from pypy.rpython import rclass
+from pypy.rpython.lltype import typeOf, Void
+from pypy.rpython.rmodel import Repr, TyperError
+#from pypy.rpython import rclass
-class __extend__(SomePBC):
+class __extend__(annmodel.SomePBC):
+ def rtyper_makerepr(self, rtyper):
+ return PBCRepr(self.prebuiltinstances)
+
+
+class PBCRepr(Repr):
+
+ def __init__(self, prebuiltinstances):
+ self.prebuiltinstances = prebuiltinstances
+ assert len(prebuiltinstances) == 1, "Not Implemented: multiPBCs"
+ self.lowleveltype = Void
def rtype_getattr(_, hop):
- attr = hop.args_s[1].const
if hop.s_result.is_constant():
- return hop.inputconst(hop.s_result, hop.s_result.const)
+ return hop.inputconst(hop.r_result, hop.s_result.const)
else:
NotImplementedYet
def rtype_simple_call(_, hop):
- s_func = hop.s_popfirstarg()
+ r_func, s_func = hop.r_s_popfirstarg()
if not s_func.is_constant():
NotImplementedYet
func = s_func.const
@@ -23,9 +33,14 @@
# XXX hackish
f = hop.rtyper.getfunctionptr(func)
FUNCPTR = typeOf(f)
- args_v = hop.inputargs(*FUNCPTR.TO.ARGS)
+ rinputs = [hop.rtyper.bindingrepr(v) for v in f.graph.getargs()]
+ if FUNCPTR.TO.RESULT == Void:
+ rresult = Void
+ else:
+ rresult = hop.rtyper.bindingrepr(f.graph.getreturnvar())
+ args_v = hop.inputargs(*rinputs)
c = hop.inputconst(FUNCPTR, f)
return hop.genop('direct_call', [c] + args_v,
- resulttype = FUNCPTR.TO.RESULT)
+ resulttype = rresult)
elif isinstance(func, (types.ClassType, type)):
return rclass.rtype_new_instance(s_func, hop)
Modified: pypy/branch/rpython-refactoring/rptr.py
==============================================================================
--- pypy/branch/rpython-refactoring/rptr.py (original)
+++ pypy/branch/rpython-refactoring/rptr.py Fri Jun 3 22:10:35 2005
@@ -1,58 +1,97 @@
from pypy.annotation.pairtype import pairtype
from pypy.annotation import model as annmodel
+from pypy.rpython.lltype import _PtrType, _ptr
from pypy.rpython.lltype import ContainerType, Void, Signed, Bool
+from pypy.rpython.rmodel import Repr, TyperError, IntegerRepr, inputconst
-class __extend__(SomePtr):
-
- def lowleveltype(s_ptr):
- if s_ptr.is_constant(): # constant NULL
- return Void
+class __extend__(annmodel.SomePtr):
+ def rtyper_makerepr(self, rtyper):
+ if self.is_constant(): # constant NULL
+ return nullptr_repr
else:
- return s_ptr.ll_ptrtype
+ return PtrRepr(self.ll_ptrtype)
+
+
+class PtrRepr(Repr):
+
+ def __init__(self, ptrtype):
+ assert isinstance(ptrtype, _PtrType)
+ self.lowleveltype = ptrtype
- def rtype_getattr(s_ptr, hop):
+ def rtype_getattr(self, hop):
attr = hop.args_s[1].const
- FIELD_TYPE = getattr(s_ptr.ll_ptrtype.TO, attr)
+ FIELD_TYPE = getattr(self.lowleveltype.TO, attr)
if isinstance(FIELD_TYPE, ContainerType):
newopname = 'getsubstruct'
else:
newopname = 'getfield'
- vlist = hop.inputargs(s_ptr, Void)
+ vlist = hop.inputargs(self, Void)
return hop.genop(newopname, vlist,
- resulttype = hop.s_result.lowleveltype())
+ resulttype = hop.r_result.lowleveltype)
- def rtype_setattr(s_ptr, hop):
+ def rtype_setattr(self, hop):
attr = hop.args_s[1].const
- FIELD_TYPE = getattr(s_ptr.ll_ptrtype.TO, attr)
+ FIELD_TYPE = getattr(self.lowleveltype.TO, attr)
assert not isinstance(FIELD_TYPE, ContainerType)
- vlist = hop.inputargs(s_ptr, Void, FIELD_TYPE)
+ vlist = hop.inputargs(self, Void, hop.args_r[2])
hop.genop('setfield', vlist)
- def rtype_len(s_ptr, hop):
- vlist = hop.inputargs(s_ptr)
+ def rtype_len(self, hop):
+ vlist = hop.inputargs(self)
return hop.genop('getarraysize', vlist,
- resulttype = hop.s_result.lowleveltype())
+ resulttype = hop.r_result.lowleveltype)
- def rtype_is_true(s_ptr, hop):
- vlist = hop.inputargs(s_ptr)
+ def rtype_is_true(self, hop):
+ vlist = hop.inputargs(self)
return hop.genop('ptr_nonzero', vlist, resulttype=Bool)
-class __extend__(pairtype(SomePtr, SomeInteger)):
+class __extend__(pairtype(PtrRepr, IntegerRepr)):
- def rtype_getitem((s_ptr, s_int), hop):
- vlist = hop.inputargs(s_ptr, Signed)
+ def rtype_getitem((r_ptr, r_int), hop):
+ vlist = hop.inputargs(r_ptr, Signed)
return hop.genop('getarrayitem', vlist,
- resulttype = hop.s_result.lowleveltype())
+ resulttype = hop.r_result.lowleveltype)
+
+# ____________________________________________________________
+#
+# Null Pointers
+
+class NullPtrRepr(Repr):
+ lowleveltype = Void
+
+ def rtype_is_true(self, hop):
+ return hop.inputconst(Bool, False)
+
+nullptr_repr = NullPtrRepr()
+
+class __extend__(pairtype(NullPtrRepr, PtrRepr)):
+ def convert_from_to((r_null, r_ptr), v, llops):
+ # nullptr to general pointer
+ return inputconst(r_ptr, _ptr(r_ptr.lowleveltype, None))
+
+# ____________________________________________________________
+#
+# Comparisons
+
+class __extend__(pairtype(PtrRepr, Repr)):
+
+ def rtype_eq((r_ptr, r_any), hop):
+ vlist = hop.inputargs(r_ptr, r_ptr)
+ return hop.genop('ptr_eq', vlist, resulttype=Bool)
+
+ def rtype_ne((r_ptr, r_any), hop):
+ vlist = hop.inputargs(r_ptr, r_ptr)
+ return hop.genop('ptr_ne', vlist, resulttype=Bool)
-class __extend__(pairtype(SomePtr, SomePtr)):
+class __extend__(pairtype(Repr, PtrRepr)):
- def rtype_eq(_, hop):
- vlist = hop.inputargs(SomePtr(), SomePtr())
+ def rtype_eq((r_any, r_ptr), hop):
+ vlist = hop.inputargs(r_ptr, r_ptr)
return hop.genop('ptr_eq', vlist, resulttype=Bool)
- def rtype_ne(_, hop):
- vlist = hop.inputargs(SomePtr(), SomePtr())
+ def rtype_ne((r_any, r_ptr), hop):
+ vlist = hop.inputargs(r_ptr, r_ptr)
return hop.genop('ptr_ne', vlist, resulttype=Bool)
Modified: pypy/branch/rpython-refactoring/rtyper.py
==============================================================================
--- pypy/branch/rpython-refactoring/rtyper.py (original)
+++ pypy/branch/rpython-refactoring/rtyper.py Fri Jun 3 22:10:35 2005
@@ -36,7 +36,7 @@
def getrepr(self, s_obj):
# s_objs are not hashable... try hard to find a hash anyway
try:
- return self.reprs_by_id[id(s_obj)]
+ result, s_obj = self.reprs_by_id[id(s_obj)]
except KeyError:
key = [s_obj.__class__]
items = s_obj.__dict__.items()
@@ -55,8 +55,8 @@
"of %s:\n%r" % (s_obj, result.lowleveltype))
self.reprs_by_content[key] = result
result.setup()
- self.reprs_by_id[id(s_obj)] = result
- return result
+ self.reprs_by_id[id(s_obj)] = result, s_obj
+ return result
def binding(self, var):
s_obj = self.annotator.binding(var, True)
@@ -244,12 +244,12 @@
"""Make a functionptr from the given Python function."""
a = self.annotator
graph = a.translator.getflowgraph(func)
- llinputs = [a.binding(v).lowleveltype() for v in graph.getargs()]
+ llinputs = [self.bindingrepr(v).lowleveltype for v in graph.getargs()]
s_output = a.binding(graph.getreturnvar(), None)
if s_output is None:
lloutput = Void
else:
- lloutput = s_output.lowleveltype()
+ lloutput = self.getrepr(s_output).lowleveltype
FT = FuncType(llinputs, lloutput)
return functionptr(FT, func.func_name, graph = graph, _callable = func)
@@ -307,12 +307,11 @@
def gendirectcall(self, ll_function, *args_v):
return self.llops.gendirectcall(ll_function, *args_v)
- def s_popfirstarg(self):
+ def r_s_popfirstarg(self):
"Return and discard the first argument."
self.nb_popped += 1
self.nb_args -= 1
- self.args_r.pop(0)
- return self.args_s.pop(0)
+ return self.args_r.pop(0), self.args_s.pop(0)
# ____________________________________________________________
@@ -351,9 +350,9 @@
spec_name = [ll_function.func_name]
args_s = []
for v in args_v:
- r_value = rtyper.bindingrepr(v)
if v.concretetype == Void:
- if not r_value.s_obj.is_constant():
+ s_value = rtyper.binding(v)
+ if not s_value.is_constant():
raise TyperError("non-constant variable of type Void")
key = s_value.const # specialize by constant value
args_s.append(s_value)
@@ -372,8 +371,8 @@
name = '_'.join(spec_name)
spec_function = func_with_new_name(ll_function, name)
# flow and annotate (the copy of) the low-level function
- spec_graph = annotator.translator.getflowgraph(spec_function)
- annotator.build_types(spec_function, args_s)
+ spec_graph = rtyper.annotator.translator.getflowgraph(spec_function)
+ rtyper.annotator.build_types(spec_function, args_s)
# cache the result
self.rtyper.specialized_ll_functions[spec_key] = spec_function
@@ -397,5 +396,5 @@
from pypy.rpython import robject
from pypy.rpython import rint, rbool, rfloat
from pypy.rpython import rlist#, rstr
-#from pypy.rpython import rbuiltin, rpbc
-#from pypy.rpython import rptr
+from pypy.rpython import rbuiltin, rpbc
+from pypy.rpython import rptr
More information about the Pypy-commit
mailing list