[pypy-svn] r53327 - in pypy/branch/fixed-list-ootype-2/pypy: annotation rpython rpython/lltypesystem rpython/ootypesystem rpython/test translator/cli translator/cli/src translator/cli/test translator/js translator/jvm translator/jvm/src/pypy translator/jvm/test translator/oosupport
niko at codespeak.net
niko at codespeak.net
Fri Apr 4 13:18:59 CEST 2008
Author: niko
Date: Fri Apr 4 13:18:57 2008
New Revision: 53327
Added:
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/src/pypy/VoidArray.java
- copied unchanged from r53282, pypy/branch/fixed-list-ootype/pypy/translator/jvm/src/pypy/VoidArray.java
Modified:
pypy/branch/fixed-list-ootype-2/pypy/annotation/builtin.py
pypy/branch/fixed-list-ootype-2/pypy/rpython/llinterp.py
pypy/branch/fixed-list-ootype-2/pypy/rpython/lltypesystem/lloperation.py
pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/ootype.py
pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rbuiltin.py
pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rdict.py
pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rlist.py
pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rstr.py
pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rtuple.py
pypy/branch/fixed-list-ootype-2/pypy/rpython/test/test_rlist.py
pypy/branch/fixed-list-ootype-2/pypy/rpython/test/tool.py
pypy/branch/fixed-list-ootype-2/pypy/translator/cli/constant.py
pypy/branch/fixed-list-ootype-2/pypy/translator/cli/cts.py
pypy/branch/fixed-list-ootype-2/pypy/translator/cli/entrypoint.py
pypy/branch/fixed-list-ootype-2/pypy/translator/cli/gencli.py
pypy/branch/fixed-list-ootype-2/pypy/translator/cli/ilgenerator.py
pypy/branch/fixed-list-ootype-2/pypy/translator/cli/metavm.py
pypy/branch/fixed-list-ootype-2/pypy/translator/cli/oopspec.py
pypy/branch/fixed-list-ootype-2/pypy/translator/cli/opcodes.py
pypy/branch/fixed-list-ootype-2/pypy/translator/cli/src/pypylib.cs
pypy/branch/fixed-list-ootype-2/pypy/translator/cli/test/test_list.py
pypy/branch/fixed-list-ootype-2/pypy/translator/js/asmgen.py
pypy/branch/fixed-list-ootype-2/pypy/translator/js/database.py
pypy/branch/fixed-list-ootype-2/pypy/translator/js/function.py
pypy/branch/fixed-list-ootype-2/pypy/translator/js/jsbuiltin.py
pypy/branch/fixed-list-ootype-2/pypy/translator/js/jts.py
pypy/branch/fixed-list-ootype-2/pypy/translator/js/opcodes.py
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/builtin.py
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/cmpopcodes.py
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/constant.py
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/database.py
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/generator.py
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/metavm.py
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/methods.py
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/node.py
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/opcodes.py
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/prebuiltnodes.py
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/src/pypy/PyPy.java
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/test/test_class.py
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/test/test_list.py
pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/typesystem.py
pypy/branch/fixed-list-ootype-2/pypy/translator/oosupport/constant.py
pypy/branch/fixed-list-ootype-2/pypy/translator/oosupport/genoo.py
pypy/branch/fixed-list-ootype-2/pypy/translator/oosupport/metavm.py
Log:
merge the fixed-list-ootype branch onto this branch
(svn merge -r 50568:HEAD https://codespeak.net/svn/pypy/branch/fixed-list-ootype/pypy pypy)
Modified: pypy/branch/fixed-list-ootype-2/pypy/annotation/builtin.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/annotation/builtin.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/annotation/builtin.py Fri Apr 4 13:18:57 2008
@@ -516,6 +516,10 @@
r = SomeOOInstance(ootype.typeOf(i))
return r
+def oonewarray(s_type, length):
+ assert s_type.is_constant()
+ return SomeOOInstance(s_type.const)
+
def null(I_OR_SM):
assert I_OR_SM.is_constant()
null = ootype.null(I_OR_SM.const)
@@ -563,6 +567,7 @@
BUILTIN_ANALYZERS[ootype.instanceof] = instanceof
BUILTIN_ANALYZERS[ootype.new] = new
+BUILTIN_ANALYZERS[ootype.oonewarray] = oonewarray
BUILTIN_ANALYZERS[ootype.null] = null
BUILTIN_ANALYZERS[ootype.runtimenew] = runtimenew
BUILTIN_ANALYZERS[ootype.classof] = classof
Modified: pypy/branch/fixed-list-ootype-2/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/rpython/llinterp.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/rpython/llinterp.py Fri Apr 4 13:18:57 2008
@@ -1035,6 +1035,11 @@
def op_new(self, INST):
assert isinstance(INST, (ootype.Instance, ootype.BuiltinType))
return ootype.new(INST)
+
+ def op_oonewarray(self, ARRAY, length):
+ assert isinstance(ARRAY, ootype.Array)
+ assert isinstance(length, int)
+ return ootype.oonewarray(ARRAY, length)
def op_runtimenew(self, class_):
return ootype.runtimenew(class_)
Modified: pypy/branch/fixed-list-ootype-2/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/rpython/lltypesystem/lloperation.py Fri Apr 4 13:18:57 2008
@@ -465,6 +465,7 @@
'new': LLOp(oo=True, canraise=(Exception,)),
'runtimenew': LLOp(oo=True, canraise=(Exception,)),
'oonewcustomdict': LLOp(oo=True, canraise=(Exception,)),
+ 'oonewarray': LLOp(oo=True, canraise=(Exception,)),
'oosetfield': LLOp(oo=True),
'oogetfield': LLOp(oo=True, sideeffects=False),
'oosend': LLOp(oo=True, canraise=(Exception,)),
Modified: pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/ootype.py Fri Apr 4 13:18:57 2008
@@ -364,7 +364,7 @@
"ll_upper": Meth([], self.SELFTYPE_T),
"ll_lower": Meth([], self.SELFTYPE_T),
"ll_substring": Meth([Signed, Signed], self.SELFTYPE_T), # ll_substring(start, count)
- "ll_split_chr": Meth([self.CHAR], List(self.SELFTYPE_T)),
+ "ll_split_chr": Meth([self.CHAR], Array(self.SELFTYPE_T)),
"ll_contains": Meth([self.CHAR], Bool),
"ll_replace_chr_chr": Meth([self.CHAR, self.CHAR], self.SELFTYPE_T),
})
@@ -464,7 +464,7 @@
ITEMTYPE_T = object()
def __init__(self, ITEMTYPE=None):
- self._ITEMTYPE = ITEMTYPE
+ self.ITEM = ITEMTYPE
self._null = _null_list(self)
if ITEMTYPE is not None:
self._init_methods()
@@ -475,13 +475,9 @@
# 'ITEMTYPE_T' is used as a placeholder for indicating
# arguments that should have ITEMTYPE type. 'SELFTYPE_T' indicates 'self'
- # XXX clean-up later! Rename _ITEMTYPE to ITEM. For now they are
- # just synonyms, please use ITEM in new code.
- self.ITEM = self._ITEMTYPE
-
generic_types = {
self.SELFTYPE_T: self,
- self.ITEMTYPE_T: self._ITEMTYPE,
+ self.ITEMTYPE_T: self.ITEM,
}
# the methods are named after the ADT methods of lltypesystem's lists
@@ -514,7 +510,7 @@
return True
if not isinstance(other, List):
return False
- if self._ITEMTYPE is None or other._ITEMTYPE is None:
+ if self.ITEM is None or other.ITEM is None:
raise TypeError("Can't compare uninitialized List type.")
return BuiltinADTType.__eq__(self, other)
@@ -522,28 +518,114 @@
return not (self == other)
def __hash__(self):
- if self._ITEMTYPE is None:
+ if self.ITEM is None:
raise TypeError("Can't hash uninitialized List type.")
return BuiltinADTType.__hash__(self)
def __str__(self):
return '%s(%s)' % (self.__class__.__name__,
- saferecursive(str, "...")(self._ITEMTYPE))
+ saferecursive(str, "...")(self.ITEM))
def _get_interp_class(self):
return _list
def _specialize(self, generic_types):
- ITEMTYPE = self._specialize_type(self._ITEMTYPE, generic_types)
+ ITEMTYPE = self._specialize_type(self.ITEM, generic_types)
return self.__class__(ITEMTYPE)
def _defl(self):
return self._null
def _set_itemtype(self, ITEMTYPE):
- self._ITEMTYPE = ITEMTYPE
+ self.ITEM = ITEMTYPE
self._init_methods()
+ def ll_convert_from_array(self, array):
+ length = array.ll_length()
+ result = self.ll_newlist(length)
+ for n in range(length):
+ result.ll_setitem_fast(n, array.ll_getitem_fast(n))
+ return result
+
+class Array(BuiltinADTType):
+ # placeholders for types
+ # make sure that each derived class has his own SELFTYPE_T
+ # placeholder, because we want backends to distinguish that.
+
+ SELFTYPE_T = object()
+ ITEMTYPE_T = object()
+
+ def __init__(self, ITEMTYPE=None):
+ self.ITEM = ITEMTYPE
+ self._null = _null_array(self)
+ if ITEMTYPE is not None:
+ self._init_methods()
+
+ def _init_methods(self):
+ # This defines the abstract list interface that backends will
+ # have to map to their native list implementations.
+ # 'ITEMTYPE_T' is used as a placeholder for indicating
+ # arguments that should have ITEMTYPE type. 'SELFTYPE_T' indicates 'self'
+
+ generic_types = {
+ self.SELFTYPE_T: self,
+ self.ITEMTYPE_T: self.ITEM,
+ }
+
+ # the methods are named after the ADT methods of lltypesystem's lists
+ self._GENERIC_METHODS = frozendict({
+ # "name": Meth([ARGUMENT1_TYPE, ARGUMENT2_TYPE, ...], RESULT_TYPE)
+ "ll_length": Meth([], Signed),
+ "ll_getitem_fast": Meth([Signed], self.ITEMTYPE_T),
+ "ll_setitem_fast": Meth([Signed, self.ITEMTYPE_T], Void),
+ })
+
+ self._setup_methods(generic_types)
+
+ def __eq__(self, other):
+ if self is other:
+ return True
+ if not isinstance(other, Array):
+ return False
+ if self.ITEM is None or other.ITEM is None:
+ raise TypeError("Can't compare uninitialized List type.")
+ return BuiltinADTType.__eq__(self, other)
+
+ def __ne__(self, other):
+ return not (self == other)
+
+ def __hash__(self):
+ if self.ITEM is None:
+ raise TypeError("Can't hash uninitialized List type.")
+ return BuiltinADTType.__hash__(self)
+
+ def __str__(self):
+ return '%s(%s)' % (self.__class__.__name__,
+ saferecursive(str, "...")(self.ITEM))
+
+ def _get_interp_class(self):
+ return _array
+
+ def _specialize(self, generic_types):
+ ITEMTYPE = self._specialize_type(self.ITEM, generic_types)
+ return self.__class__(ITEMTYPE)
+
+ def _defl(self):
+ return self._null
+
+ def _example(self):
+ return oonewarray(self, 1)
+
+ def _set_itemtype(self, ITEMTYPE):
+ self.ITEM = ITEMTYPE
+ self._init_methods()
+
+ def ll_newlist(self, length):
+ from pypy.rpython.ootypesystem import rlist
+ return rlist.ll_newarray(self, length)
+
+ def ll_convert_from_array(self, array):
+ return array
class Dict(BuiltinADTType):
# placeholders for types
@@ -1201,8 +1283,9 @@
def ll_split_chr(self, ch):
# NOT_RPYTHON
- res = _list(List(self._TYPE))
- res._list = [self.make_string(s) for s in self._str.split(ch)]
+ l = [self.make_string(s) for s in self._str.split(ch)]
+ res = _array(Array(self._TYPE), len(l))
+ res._array[:] = l
return res
def ll_contains(self, ch):
@@ -1278,6 +1361,8 @@
def __init__(self, WEAK_REFERENCE):
self.__dict__["_TYPE"] = WEAK_REFERENCE
+
+
class _list(_builtin_type):
def __init__(self, LIST):
self._TYPE = LIST
@@ -1295,7 +1380,7 @@
# NOT_RPYTHON
if len(self._list) < length:
diff = length - len(self._list)
- self._list += [self._TYPE._ITEMTYPE._defl()] * diff
+ self._list += [self._TYPE.ITEM._defl()] * diff
assert len(self._list) >= length
def _ll_resize_le(self, length):
@@ -1320,7 +1405,7 @@
def ll_setitem_fast(self, index, item):
# NOT_RPYTHON
- assert self._TYPE._ITEMTYPE is Void or typeOf(item) == self._TYPE._ITEMTYPE
+ assert self._TYPE.ITEM is Void or typeOf(item) == self._TYPE.ITEM
assert typeOf(index) == Signed
assert index >= 0
self._list[index] = item
@@ -1330,6 +1415,33 @@
def __init__(self, LIST):
self.__dict__["_TYPE"] = LIST
+class _array(_builtin_type):
+ def __init__(self, ARRAY, length):
+ self._TYPE = ARRAY
+ self._array = [ARRAY.ITEM._defl()] * length
+
+ def ll_length(self):
+ # NOT_RPYTHON
+ return len(self._array)
+
+ def ll_getitem_fast(self, index):
+ # NOT_RPYTHON
+ assert typeOf(index) == Signed
+ assert index >= 0
+ return self._array[index]
+
+ def ll_setitem_fast(self, index, item):
+ # NOT_RPYTHON
+ assert self._TYPE.ITEM is Void or typeOf(item) == self._TYPE.ITEM
+ assert typeOf(index) == Signed
+ assert index >= 0
+ self._array[index] = item
+
+class _null_array(_null_mixin(_array), _array):
+
+ def __init__(self, ARRAY):
+ self.__dict__["_TYPE"] = ARRAY
+
class _dict(_builtin_type):
def __init__(self, DICT):
self._TYPE = DICT
@@ -1497,10 +1609,15 @@
return TYPE._get_interp_class()(TYPE)
def oonewcustomdict(DICT, ll_eq, ll_hash):
+ """NOT_RPYTHON"""
d = new(DICT)
d.ll_set_functions(ll_eq, ll_hash)
return d
+def oonewarray(ARRAY, length):
+ """NOT_RPYTHON"""
+ return _array(ARRAY, length)
+
def runtimenew(class_):
assert isinstance(class_, _class)
assert class_ is not nullruntimeclass
@@ -1626,7 +1743,7 @@
return LIST._set_itemtype(ITEMTYPE)
def hasItemType(LIST):
- return LIST._ITEMTYPE is not None
+ return LIST.ITEM is not None
def setDictTypes(DICT, KEYTYPE, VALUETYPE):
return DICT._set_types(KEYTYPE, VALUETYPE)
Modified: pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rbuiltin.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rbuiltin.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rbuiltin.py Fri Apr 4 13:18:57 2008
@@ -12,6 +12,13 @@
return hop.genop('new', vlist,
resulttype = hop.r_result.lowleveltype)
+def rtype_oonewarray(hop):
+ assert hop.args_s[0].is_constant()
+ vlist = hop.inputarg(ootype.Void, arg=0)
+ vlength = hop.inputarg(ootype.Signed, arg=1)
+ return hop.genop('oonewarray', [vlist, vlength],
+ resulttype = hop.r_result.lowleveltype)
+
def rtype_null(hop):
assert hop.args_s[0].is_constant()
TYPE = hop.args_s[0].const
@@ -105,6 +112,7 @@
BUILTIN_TYPER = {}
BUILTIN_TYPER[ootype.new] = rtype_new
+BUILTIN_TYPER[ootype.oonewarray] = rtype_oonewarray
BUILTIN_TYPER[ootype.null] = rtype_null
BUILTIN_TYPER[ootype.classof] = rtype_classof
BUILTIN_TYPER[ootype.subclassof] = rtype_subclassof
Modified: pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rdict.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rdict.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rdict.py Fri Apr 4 13:18:57 2008
@@ -323,7 +323,7 @@
def ll_dict_kvi(d, LIST, func):
length = d.ll_length()
- result = ll_newlist(LIST, length)
+ result = LIST.ll_newlist(length)
it = d.ll_get_items_iterator()
i = 0
while it.ll_go_next():
@@ -332,7 +332,7 @@
elif func is dum_values:
result.ll_setitem_fast(i, it.ll_current_value())
if func is dum_items:
- r = ootype.new(LIST._ITEMTYPE)
+ r = ootype.new(LIST.ITEM)
r.item0 = it.ll_current_key() # TODO: do we need casting?
r.item1 = it.ll_current_value()
result.ll_setitem_fast(i, r)
Modified: pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rlist.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rlist.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rlist.py Fri Apr 4 13:18:57 2008
@@ -1,6 +1,6 @@
from pypy.tool.pairtype import pairtype
from pypy.rpython.rlist import AbstractBaseListRepr, AbstractListRepr, \
- AbstractListIteratorRepr, rtype_newlist, rtype_alloc_and_set
+ AbstractListIteratorRepr, AbstractFixedSizeListRepr, rtype_newlist, rtype_alloc_and_set
from pypy.rpython.rmodel import Repr, IntegerRepr
from pypy.rpython.rmodel import inputconst, externalvsinternal
from pypy.rpython.lltypesystem.lltype import Signed, Void
@@ -21,15 +21,12 @@
else:
self.external_item_repr, self.item_repr = \
externalvsinternal(rtyper, item_repr)
- self.LIST = ootype.List()
+ self.LIST = self._make_empty_type()
self.lowleveltype = self.LIST
self.listitem = listitem
self.list_cache = {}
# setup() needs to be called to finish this initialization
- def _externalvsinternal(self, rtyper, item_repr):
- return item_repr, item_repr
-
def _setup_repr(self):
if 'item_repr' not in self.__dict__:
self.external_item_repr, self.item_repr = \
@@ -37,13 +34,9 @@
if not ootype.hasItemType(self.lowleveltype):
ootype.setItemType(self.lowleveltype, self.item_repr.lowleveltype)
- def null_const(self):
- return self.LIST._null
-
- def prepare_const(self, n):
- result = self.LIST.ll_newlist(n)
- return result
-
+ def _externalvsinternal(self, rtyper, item_repr):
+ return item_repr, item_repr
+
def send_message(self, hop, message, can_raise=False, v_args=None):
if v_args is None:
v_args = hop.inputargs(self, *hop.args_r[1:])
@@ -56,9 +49,6 @@
def get_eqfunc(self):
return inputconst(Void, self.item_repr.get_ll_eq_function())
- def make_iterator_repr(self):
- return ListIteratorRepr(self)
-
def rtype_hint(self, hop):
hints = hop.args_s[-1].const
if 'maxlength' in hints:
@@ -71,10 +61,26 @@
class ListRepr(AbstractListRepr, BaseListRepr):
+ def null_const(self):
+ return self.LIST._null
+
+ def prepare_const(self, n):
+ result = self.LIST.ll_newlist(n)
+ return result
+
+ def make_iterator_repr(self):
+ return ListIteratorRepr(self)
- pass
+ def _make_empty_type(self):
+ return ootype.List()
-FixedSizeListRepr = ListRepr
+ def _generate_newlist(self, llops, items_v, v_sizehint):
+ c_list = inputconst(ootype.Void, self.lowleveltype)
+ v_result = llops.genop("new", [c_list], resulttype=self.lowleveltype)
+ c_resize = inputconst(ootype.Void, "_ll_resize")
+ c_length = inputconst(ootype.Signed, len(items_v))
+ llops.genop("oosend", [c_resize, v_result, c_length], resulttype=ootype.Void)
+ return v_result
class __extend__(pairtype(BaseListRepr, BaseListRepr)):
@@ -87,11 +93,7 @@
def newlist(llops, r_list, items_v, v_sizehint=None):
# XXX do something about v_sizehint
- c_list = inputconst(ootype.Void, r_list.lowleveltype)
- v_result = llops.genop("new", [c_list], resulttype=r_list.lowleveltype)
- c_resize = inputconst(ootype.Void, "_ll_resize")
- c_length = inputconst(ootype.Signed, len(items_v))
- llops.genop("oosend", [c_resize, v_result, c_length], resulttype=ootype.Void)
+ v_result = r_list._generate_newlist(llops, items_v, v_sizehint)
c_setitem = inputconst(ootype.Void, "ll_setitem_fast")
for i, v_item in enumerate(items_v):
@@ -104,6 +106,31 @@
lst._ll_resize(length)
return lst
+# Fixed-size list
+class FixedSizeListRepr(AbstractFixedSizeListRepr, BaseListRepr):
+ def compact_repr(self):
+ return 'FixedSizeListR %s' % (self.item_repr.compact_repr(),)
+
+ def _make_empty_type(self):
+ return ootype.Array()
+
+ def null_const(self):
+ return self.LIST._null
+
+ def prepare_const(self, n):
+ return ll_newarray(self.LIST, n)
+
+ def make_iterator_repr(self):
+ return ListIteratorRepr(self)
+
+ def _generate_newlist(self, llops, items_v, v_sizehint):
+ c_array = inputconst(ootype.Void, self.lowleveltype)
+ c_length = inputconst(ootype.Signed, len(items_v))
+ v_result = llops.genop("oonewarray", [c_array, c_length], resulttype=self.lowleveltype)
+ return v_result
+
+def ll_newarray(ARRAY, length):
+ return ootype.oonewarray(ARRAY, length)
# ____________________________________________________________
#
Modified: pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rstr.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rstr.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rstr.py Fri Apr 4 13:18:57 2008
@@ -170,7 +170,7 @@
return buf.ll_build()
def ll_join_chars(length_dummy, lst):
- if typeOf(lst)._ITEMTYPE == Char:
+ if typeOf(lst).ITEM == Char:
buf = ootype.new(ootype.StringBuilder)
else:
buf = ootype.new(ootype.UnicodeBuilder)
@@ -183,7 +183,7 @@
return buf.ll_build()
def ll_join_strs(length_dummy, lst):
- if typeOf(lst)._ITEMTYPE == ootype.String:
+ if typeOf(lst).ITEM == ootype.String:
buf = ootype.new(ootype.StringBuilder)
else:
buf = ootype.new(ootype.UnicodeBuilder)
@@ -209,8 +209,8 @@
def ll_stringslice_minusone(s):
return s.ll_substring(0, s.ll_strlen()-1)
- def ll_split_chr(LIST, s, c):
- return s.ll_split_chr(c)
+ def ll_split_chr(RESULT, s, c):
+ return RESULT.ll_convert_from_array(s.ll_split_chr(c))
def ll_int(s, base):
if not 2 <= base <= 36:
Modified: pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rtuple.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rtuple.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/rpython/ootypesystem/rtuple.py Fri Apr 4 13:18:57 2008
@@ -36,13 +36,19 @@
def rtype_bltn_list(self, hop):
from pypy.rpython.ootypesystem import rlist
v_tup = hop.inputarg(self, 0)
- LIST = hop.r_result.lowleveltype
- c_list = inputconst(ootype.Void, LIST)
- v_list = hop.genop('new', [c_list], resulttype=LIST)
- c_resize = inputconst(ootype.Void, '_ll_resize')
- c_setitem = inputconst(ootype.Void, 'll_setitem_fast')
+ RESULT = hop.r_result.lowleveltype
+ c_resulttype = inputconst(ootype.Void, RESULT)
c_length = inputconst(ootype.Signed, len(self.items_r))
- hop.genop('oosend', [c_resize, v_list, c_length], resulttype=ootype.Void)
+ if isinstance(RESULT, ootype.Array):
+ v_list = hop.genop('oonewarray', [c_resulttype, c_length], resulttype=RESULT)
+ else:
+ assert isinstance(RESULT, ootype.List)
+ v_list = hop.genop('new', [c_resulttype], resulttype=RESULT)
+ c_resize = inputconst(ootype.Void, '_ll_resize')
+ hop.genop('oosend', [c_resize, v_list, c_length], resulttype=ootype.Void)
+
+ c_setitem = inputconst(ootype.Void, 'll_setitem_fast')
+
for index in range(len(self.items_r)):
name = self.fieldnames[index]
r_item = self.items_r[index]
@@ -51,6 +57,7 @@
v_item = hop.llops.convertvar(v_item, r_item, hop.r_result.item_repr)
c_index = inputconst(ootype.Signed, index)
hop.genop('oosend', [c_setitem, v_list, c_index, v_item], resulttype=ootype.Void)
+
return v_list
Modified: pypy/branch/fixed-list-ootype-2/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/rpython/test/test_rlist.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/rpython/test/test_rlist.py Fri Apr 4 13:18:57 2008
@@ -498,7 +498,6 @@
assert self.class_name(res) == 'A'
#''.join(res.super.typeptr.name) == 'A\00'
-
def test_reverse(self):
def dummyfn():
l = [5, 3, 2]
@@ -517,15 +516,15 @@
assert res == 235
def test_prebuilt_list(self):
- klist = ['a', 'd', 'z', 'k']
+ klist = [6, 7, 8, 9]
def dummyfn(n):
return klist[n]
res = self.interpret(dummyfn, [0])
- assert res == 'a'
+ assert res == 6
res = self.interpret(dummyfn, [3])
- assert res == 'k'
+ assert res == 9
res = self.interpret(dummyfn, [-2])
- assert res == 'z'
+ assert res == 8
klist = ['a', 'd', 'z']
def mkdummyfn():
Modified: pypy/branch/fixed-list-ootype-2/pypy/rpython/test/tool.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/rpython/test/tool.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/rpython/test/tool.py Fri Apr 4 13:18:57 2008
@@ -107,7 +107,9 @@
return OOSupport.to_runicode(u)
def ll_to_list(self, l):
- return l._list[:]
+ if hasattr(l, '_list'):
+ return l._list[:]
+ return l._array[:]
def ll_unpack_tuple(self, t, length):
return tuple([getattr(t, 'item%d' % i) for i in range(length)])
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/cli/constant.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/cli/constant.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/cli/constant.py Fri Apr 4 13:18:57 2008
@@ -28,7 +28,7 @@
from pypy.translator.oosupport.constant import \
push_constant, WeakRefConst, StaticMethodConst, CustomDictConst, \
ListConst, ClassConst, InstanceConst, RecordConst, DictConst, \
- BaseConstantGenerator, AbstractConst
+ BaseConstantGenerator, AbstractConst, ArrayConst
from pypy.translator.cli.ilgenerator import CLIBaseGenerator
from pypy.rpython.ootypesystem import ootype
from pypy.translator.cli.comparer import EqualityComparer
@@ -373,9 +373,25 @@
def create_pointer(self, gen):
self.db.const_count.inc('List')
- self.db.const_count.inc('List', self.value._TYPE._ITEMTYPE)
+ self.db.const_count.inc('List', self.value._TYPE.ITEM)
self.db.const_count.inc('List', len(self.value._list))
- super(CLIListConst, self).create_pointer(gen)
+ super(CLIListConst, self).create_pointer(gen)
+
+
+class CLIArrayConst(CLIBaseConstMixin, ArrayConst):
+
+ def _do_not_initialize(self):
+ # Check if it is an array of all zeroes:
+ try:
+ if self.value._list == [0] * len(self.value._list):
+ return True
+ except:
+ pass
+ return super(CLIArrayConst, self)._do_not_initialize()
+
+ def _setitem(self, SELFTYPE, gen):
+ gen.array_setitem(SELFTYPE)
+
class CLIDictConst(CLIDictMixin, DictConst):
def create_pointer(self, gen):
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/cli/cts.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/cli/cts.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/cli/cts.py Fri Apr 4 13:18:57 2008
@@ -95,6 +95,14 @@
arglist = ', '.join([arg.typename() for arg in self.arg_types])
return '[%s]%s`%d<%s>' % (assembly, name, numparam, arglist)
+class CliArrayType(CliType):
+
+ def __init__(self, itemtype):
+ self.itemtype = itemtype
+
+ def typename(self):
+ return '%s[]' % self.itemtype.typename()
+
T = CliPrimitiveType
class types:
@@ -249,8 +257,13 @@
elif isinstance(t, ootype.StaticMethod):
delegate = self.db.record_delegate(t)
return CliClassType(None, delegate)
+ elif isinstance(t, ootype.Array):
+ item_type = self.lltype_to_cts(t.ITEM)
+ if item_type == types.void: # special case: Array of Void
+ return types.list_of_void
+ return CliArrayType(item_type)
elif isinstance(t, ootype.List):
- item_type = self.lltype_to_cts(t._ITEMTYPE)
+ item_type = self.lltype_to_cts(t.ITEM)
if item_type == types.void: # special case: List of Void
return types.list_of_void
return types.list.specialize(item_type)
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/cli/entrypoint.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/cli/entrypoint.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/cli/entrypoint.py Fri Apr 4 13:18:57 2008
@@ -9,7 +9,7 @@
ARG0 = graph.getargs()[0].concretetype
except IndexError:
ARG0 = None
- if isinstance(ARG0, ootype.List) and ARG0._ITEMTYPE is ootype.String:
+ if isinstance(ARG0, ootype.List) and ARG0.ITEM is ootype.String:
return StandaloneEntryPoint(graph)
else:
return TestEntryPoint(graph)
@@ -45,7 +45,7 @@
ARG0 = self.graph.getargs()[0].concretetype
except IndexError:
ARG0 = None
- assert isinstance(ARG0, ootype.List) and ARG0._ITEMTYPE is ootype.String,\
+ assert isinstance(ARG0, ootype.List) and ARG0.ITEM is ootype.String,\
'Wrong entry point signature: List(String) expected'
ilasm.begin_function('main', [('string[]', 'argv')], 'void', True, 'static')
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/cli/gencli.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/cli/gencli.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/cli/gencli.py Fri Apr 4 13:18:57 2008
@@ -31,6 +31,7 @@
RecordConst = constant.CLIRecordConst
ClassConst = constant.CLIClassConst
ListConst = constant.CLIListConst
+ ArrayConst = constant.CLIArrayConst
StaticMethodConst = constant.CLIStaticMethodConst
CustomDictConst = constant.CLICustomDictConst
DictConst = constant.CLIDictConst
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/cli/ilgenerator.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/cli/ilgenerator.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/cli/ilgenerator.py Fri Apr 4 13:18:57 2008
@@ -417,3 +417,31 @@
def dup(self, TYPE):
self.ilasm.opcode('dup')
+
+ def oonewarray(self, TYPE, length):
+ if TYPE.ITEM is ootype.Void:
+ self.new(TYPE)
+ self.ilasm.opcode('dup')
+ self.load(length)
+ self.ilasm.call_method('void [pypylib]pypy.runtime.ListOfVoid::_ll_resize(int32)', virtual=False)
+ else:
+ clitype = self.cts.lltype_to_cts(TYPE)
+ self.load(length)
+ self.ilasm.opcode('newarr', clitype.itemtype.typename())
+
+ def _array_suffix(self, ARRAY, erase_unsigned=False):
+ from pypy.translator.cli.metavm import OOTYPE_TO_MNEMONIC
+ suffix = OOTYPE_TO_MNEMONIC.get(ARRAY.ITEM, 'ref')
+ if erase_unsigned:
+ suffix = suffix.replace('u', 'i')
+ return suffix
+
+ def array_setitem(self, ARRAY):
+ suffix = self._array_suffix(ARRAY, erase_unsigned=True)
+ self.ilasm.opcode('stelem.%s' % suffix)
+
+ def array_getitem(self, ARRAY):
+ self.ilasm.opcode('ldelem.%s' % self._array_suffix(ARRAY))
+
+ def array_length(self, ARRAY):
+ self.ilasm.opcode('ldlen')
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/cli/metavm.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/cli/metavm.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/cli/metavm.py Fri Apr 4 13:18:57 2008
@@ -68,6 +68,17 @@
arg_list = ', '.join(arg_types)
signature = '%s %s::%s(%s)' % (ret_type, STRING_HELPER_CLASS, method_name, arg_list)
generator.call_signature(signature)
+ elif isinstance(this.concretetype, ootype.Array) and this.concretetype.ITEM is not ootype.Void:
+ v_array = args[0]
+ ARRAY = v_array.concretetype
+ if method_name == 'll_setitem_fast':
+ generator.array_setitem(ARRAY)
+ elif method_name == 'll_getitem_fast':
+ generator.array_getitem(ARRAY)
+ elif method_name == 'll_length':
+ generator.array_length(ARRAY)
+ else:
+ assert False
else:
generator.call_method(this.concretetype, method_name)
@@ -251,10 +262,14 @@
OOTYPE_TO_MNEMONIC = {
+ ootype.Bool: 'i1',
+ ootype.Char: 'i2',
+ ootype.UniChar: 'i2',
ootype.Signed: 'i4',
ootype.SignedLongLong: 'i8',
ootype.Unsigned: 'u4',
ootype.UnsignedLongLong: 'u8',
+ ootype.Float: 'r8',
}
class _CastPrimitive(MicroInstruction):
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/cli/oopspec.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/cli/oopspec.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/cli/oopspec.py Fri Apr 4 13:18:57 2008
@@ -31,9 +31,9 @@
def get_method(TYPE, name):
try:
- # special case: when having List of Void, look at the concrete
- # methods, not the generic ones
- if isinstance(TYPE, ootype.List) and TYPE._ITEMTYPE is ootype.Void:
+ # special case: when having List of Void, or an Array, look at
+ # the concrete methods, not the generic ones
+ if isinstance(TYPE, ootype.Array) or (isinstance(TYPE, ootype.List) and TYPE.ITEM is ootype.Void):
return TYPE._METHODS[name]
else:
return TYPE._GENERIC_METHODS[name]
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/cli/opcodes.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/cli/opcodes.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/cli/opcodes.py Fri Apr 4 13:18:57 2008
@@ -4,7 +4,7 @@
TypeOf, CastPrimitive, EventHandler, GetStaticField, SetStaticField,\
FieldInfoForConst
from pypy.translator.oosupport.metavm import PushArg, PushAllArgs, StoreResult, InstructionList,\
- New, RuntimeNew, CastTo, PushPrimitive, OOString, OOUnicode
+ New, RuntimeNew, CastTo, PushPrimitive, OOString, OOUnicode, OONewArray
from pypy.translator.cli.cts import WEAKREF
from pypy.rpython.ootypesystem import ootype
@@ -58,6 +58,7 @@
'ooparse_int': [PushAllArgs, 'call int32 [pypylib]pypy.runtime.Utils::OOParseInt(string, int32)'],
'ooparse_float': [PushAllArgs, 'call float64 [pypylib]pypy.runtime.Utils::OOParseFloat(string)'],
'oonewcustomdict': [NewCustomDict],
+ 'oonewarray': [OONewArray, StoreResult],
'hint': [PushArg(0), StoreResult],
'direct_call': [Call],
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/cli/src/pypylib.cs (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/cli/src/pypylib.cs Fri Apr 4 13:18:57 2008
@@ -35,10 +35,28 @@
public static string ToPython(object x) {
if (x == null)
return "None";
+ else if (x is Array)
+ return ArrayToPython((Array)x);
else
return x.ToString();
}
+ private static string ArrayToPython(Array array)
+ {
+ string res = "[";
+ foreach(object item in array) {
+ if (item != null && item.GetType() == typeof(string)) {
+ object tmp = (object)item;
+ res += ToPython((string)tmp) + ",";
+ }
+ else
+ res += ToPython(item) + ",";
+
+ }
+ res += "]";
+ return res;
+ }
+
public static string InstanceToPython(object obj)
{
return string.Format("InstanceWrapper('{0}')", obj.GetType().FullName);
@@ -373,11 +391,9 @@
return s.Substring(start, count);
}
- public static List<string> ll_split_chr(string s, char ch)
+ public static string[] ll_split_chr(string s, char ch)
{
- List<string> res = new List<string>();
- res.AddRange(s.Split(ch));
- return res;
+ return s.Split(ch);
}
public static bool ll_contains(string s, char ch)
@@ -417,7 +433,7 @@
res += pypy.test.Result.ToPython((string)tmp) + ",";
}
else
- res += item.ToString() + ","; // XXX: doesn't work for chars
+ res += pypy.test.Result.ToPython(item) + ",";
}
res += "]";
return res;
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/cli/test/test_list.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/cli/test/test_list.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/cli/test/test_list.py Fri Apr 4 13:18:57 2008
@@ -1,6 +1,7 @@
import py
from pypy.translator.cli.test.runtest import CliTest
from pypy.rpython.test.test_rlist import BaseTestRlist
+from pypy.rlib.rarithmetic import r_uint
class TestCliList(CliTest, BaseTestRlist):
def test_recursive(self):
@@ -8,3 +9,19 @@
def test_getitem_exc(self):
py.test.skip('fixme!')
+
+ def test_list_unsigned(self):
+ def fn(x):
+ lst = [r_uint(0), r_uint(1)]
+ lst[0] = r_uint(x)
+ return lst[0]
+ res = self.interpret(fn, [42])
+ assert res == 42
+
+ def test_list_bool(self):
+ def fn(x):
+ lst = [True, False]
+ lst[0] = x
+ return lst[0]
+ res = self.interpret(fn, [False])
+ assert res == False
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/js/asmgen.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/js/asmgen.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/js/asmgen.py Fri Apr 4 13:18:57 2008
@@ -219,6 +219,9 @@
def runtimenew(self):
self.right_hand.append("new %s()" % self.right_hand.pop())
+ def oonewarray(self, obj, length):
+ self.right_hand.append("new %s(%s)" % (obj, length))
+
def load_self(self):
self.right_hand.append("this")
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/js/database.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/js/database.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/js/database.py Fri Apr 4 13:18:57 2008
@@ -227,6 +227,8 @@
return InstanceConst(db, const, static_type)
elif isinstance(const, ootype._list):
return ListConst(db, const)
+ elif isinstance(const, ootype._array):
+ return ListConst(db, const)
elif isinstance(const, ootype._record):
return RecordConst(db, const)
elif isinstance(const, ootype._string):
@@ -355,6 +357,13 @@
class ListConst(AbstractConst):
+ def _get_list(self):
+ if isinstance(self.const, ootype._list):
+ return self.const._list
+ else:
+ return self.const._array
+
+
def get_name(self):
return "const_list"
@@ -368,7 +377,7 @@
if not self.const:
return
- for i in self.const._list:
+ for i in self._get_list():
name = self.db.record_const(i, None, 'const')
if name is not None:
self.depends.add(name)
@@ -381,9 +390,10 @@
if not self.const:
return
- for i in xrange(len(self.const._list)):
+ l = self._get_list()
+ for i in xrange(len(l)):
ilasm.load_str("%s.%s"%(const_var.name, name))
- el = self.const._list[i]
+ el = l[i]
self.db.load_const(typeOf(el), el, ilasm)
self.db.load_const(typeOf(i), i, ilasm)
ilasm.list_setitem()
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/js/function.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/js/function.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/js/function.py Fri Apr 4 13:18:57 2008
@@ -73,6 +73,9 @@
def new(self, obj):
self.ilasm.new(self.cts.obj_name(obj))
+ def oonewarray(self, obj, length):
+ self.ilasm.oonewarray(self.cts.obj_name(obj), length)
+
def set_field(self, obj, name):
self.ilasm.set_field(obj, name)
#self.ilasm.set_field(self.field_name(obj,name))
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/js/jsbuiltin.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/js/jsbuiltin.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/js/jsbuiltin.py Fri Apr 4 13:18:57 2008
@@ -59,6 +59,11 @@
'_ll_resize_le' : list_resize,
'll_length' : _GetPredefinedField('length'),
},
+ ootype.Array: {
+ 'll_setitem_fast' : ListSetitem,
+ 'll_getitem_fast' : ListGetitem,
+ 'll_length' : _GetPredefinedField('length'),
+ },
ootype.Dict: {
'll_get' : ListGetitem,
'll_set' : ListSetitem,
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/js/jts.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/js/jts.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/js/jts.py Fri Apr 4 13:18:57 2008
@@ -43,6 +43,8 @@
return self.escape_name(t._name)
elif isinstance(t, ootype.List):
return "Array"
+ elif isinstance(t, ootype.Array):
+ return "Array"
elif isinstance(t, lltype.Primitive):
return "var"
elif isinstance(t, ootype.Record):
@@ -135,7 +137,7 @@
## elif isinstance(t, ootype.StaticMethod):
## return 'void' # TODO: is it correct to ignore StaticMethod?
## elif isinstance(t, ootype.List):
-## item_type = self.lltype_to_cts(t._ITEMTYPE)
+## item_type = self.lltype_to_cts(t.ITEM)
## return self.__class(PYPY_LIST % item_type, include_class)
## elif isinstance(t, ootype.Dict):
## key_type = self.lltype_to_cts(t._KEYTYPE)
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/js/opcodes.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/js/opcodes.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/js/opcodes.py Fri Apr 4 13:18:57 2008
@@ -2,7 +2,8 @@
"""
from pypy.translator.oosupport.metavm import PushArg, PushAllArgs, StoreResult,\
- InstructionList, New, GetField, MicroInstruction, RuntimeNew, PushPrimitive
+ InstructionList, New, GetField, MicroInstruction, RuntimeNew, PushPrimitive,\
+ OONewArray
from pypy.translator.oosupport.metavm import _GetFieldDispatcher, _SetFieldDispatcher, \
_CallDispatcher, _MethodDispatcher, SetField
@@ -119,6 +120,7 @@
'indirect_call' : [IndirectCall],
'same_as' : CopyName,
'new' : [New],
+ 'oonewarray' : [OONewArray],
'runtimenew' : [RuntimeNew],
'instanceof' : [IsInstance],
#'subclassof' : [IsSubclassOf],
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/builtin.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/builtin.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/builtin.py Fri Apr 4 13:18:57 2008
@@ -1,5 +1,4 @@
-from pypy.translator.jvm import typesystem as jvmtype
-from pypy.translator.jvm import generator as jvmgen
+import pypy.translator.jvm.typesystem as jvm
from pypy.rpython.ootypesystem import ootype
from pypy.translator.jvm.typesystem import \
jInt, jVoid, jStringBuilder, jString, jPyPy, jChar, jArrayList, jObject, \
@@ -9,7 +8,7 @@
# ______________________________________________________________________
# Mapping of built-in OOTypes to JVM types
-class JvmBuiltInType(jvmtype.JvmClassType):
+class JvmBuiltInType(jvm.JvmClassType):
"""
Represents built-in types to JVM. May optionally be associated
@@ -18,7 +17,7 @@
"""
def __init__(self, db, classty, OOTYPE):
- jvmtype.JvmClassType.__init__(self, classty.name)
+ jvm.JvmClassType.__init__(self, classty.name)
self.db = db
self.OOTYPE = OOTYPE
self.gen = Generifier(OOTYPE)
@@ -30,14 +29,14 @@
return hash(self.name)
def lookup_field(self, fieldnm):
- """ Given a field name, returns a jvmgen.Field object """
+ """ Given a field name, returns a jvm.Field object """
_, FIELDTY = self.OOTYPE._lookup_field(fieldnm)
jfieldty = self.db.lltype_to_cts(FIELDTY)
- return jvmgen.Field(
+ return jvm.Field(
self.descriptor.class_name(), fieldnm, jfieldty, False)
def lookup_method(self, methodnm):
- """ Given the method name, returns a jvmgen.Method object """
+ """ Given the method name, returns a jvm.Method object """
# Look for a shortcut method in our table of remappings:
try:
@@ -56,14 +55,14 @@
if self.OOTYPE.__class__ in bridged_objects:
# Bridged objects are ones where we have written a java class
# that has methods with the correct names and types already
- return jvmgen.Method.v(self, methodnm, jargtypes, jrettype)
+ return jvm.Method.v(self, methodnm, jargtypes, jrettype)
else:
# By default, we assume it is a static method on the PyPy
# object, that takes an instance of this object as the first
# argument. The other arguments we just convert to java versions,
# except for generics.
jargtypes = [self] + jargtypes
- return jvmgen.Method.s(jPyPy, methodnm, jargtypes, jrettype)
+ return jvm.Method.s(jPyPy, methodnm, jargtypes, jrettype)
# When we lookup a method on a BuiltInClassNode, we first check the
# 'built_in_methods' and 'bridged_objects' tables. This allows us to
@@ -80,73 +79,73 @@
# .__class__ is required
(ootype.StringBuilder.__class__, "ll_allocate"):
- jvmgen.Method.v(jStringBuilder, "ensureCapacity", (jInt,), jVoid),
+ jvm.Method.v(jStringBuilder, "ensureCapacity", (jInt,), jVoid),
(ootype.StringBuilder.__class__, "ll_build"):
- jvmgen.Method.v(jStringBuilder, "toString", (), jString),
+ jvm.Method.v(jStringBuilder, "toString", (), jString),
(ootype.String.__class__, "ll_streq"):
- jvmgen.Method.v(jString, "equals", (jObject,), jBool),
+ jvm.Method.v(jString, "equals", (jObject,), jBool),
(ootype.String.__class__, "ll_strlen"):
- jvmgen.Method.v(jString, "length", (), jInt),
+ jvm.Method.v(jString, "length", (), jInt),
(ootype.String.__class__, "ll_stritem_nonneg"):
- jvmgen.Method.v(jString, "charAt", (jInt,), jChar),
+ jvm.Method.v(jString, "charAt", (jInt,), jChar),
(ootype.String.__class__, "ll_startswith"):
- jvmgen.Method.v(jString, "startsWith", (jString,), jBool),
+ jvm.Method.v(jString, "startsWith", (jString,), jBool),
(ootype.String.__class__, "ll_endswith"):
- jvmgen.Method.v(jString, "endsWith", (jString,), jBool),
+ jvm.Method.v(jString, "endsWith", (jString,), jBool),
(ootype.String.__class__, "ll_strcmp"):
- jvmgen.Method.v(jString, "compareTo", (jString,), jInt),
+ jvm.Method.v(jString, "compareTo", (jString,), jInt),
(ootype.String.__class__, "ll_upper"):
- jvmgen.Method.v(jString, "toUpperCase", (), jString),
+ jvm.Method.v(jString, "toUpperCase", (), jString),
(ootype.String.__class__, "ll_lower"):
- jvmgen.Method.v(jString, "toLowerCase", (), jString),
+ jvm.Method.v(jString, "toLowerCase", (), jString),
(ootype.String.__class__, "ll_replace_chr_chr"):
- jvmgen.Method.v(jString, "replace", (jChar, jChar), jString),
+ jvm.Method.v(jString, "replace", (jChar, jChar), jString),
(ootype.Dict, "ll_set"):
- jvmgen.Method.v(jHashMap, "put", (jObject, jObject), jObject),
+ jvm.Method.v(jHashMap, "put", (jObject, jObject), jObject),
(ootype.Dict, "ll_get"):
- jvmgen.Method.v(jHashMap, "get", (jObject,), jObject),
+ jvm.Method.v(jHashMap, "get", (jObject,), jObject),
(ootype.Dict, "ll_contains"):
- jvmgen.Method.v(jHashMap, "containsKey", (jObject,), jBool),
+ jvm.Method.v(jHashMap, "containsKey", (jObject,), jBool),
(ootype.Dict, "ll_length"):
- jvmgen.Method.v(jHashMap, "size", (), jInt),
+ jvm.Method.v(jHashMap, "size", (), jInt),
(ootype.Dict, "ll_clear"):
- jvmgen.Method.v(jHashMap, "clear", (), jVoid),
+ jvm.Method.v(jHashMap, "clear", (), jVoid),
(ootype.CustomDict, "ll_set"):
- jvmgen.Method.v(jPyPyCustomDict, "put", (jObject, jObject), jObject),
+ jvm.Method.v(jPyPyCustomDict, "put", (jObject, jObject), jObject),
(ootype.CustomDict, "ll_get"):
- jvmgen.Method.v(jPyPyCustomDict, "get", (jObject,), jObject),
+ jvm.Method.v(jPyPyCustomDict, "get", (jObject,), jObject),
(ootype.CustomDict, "ll_contains"):
- jvmgen.Method.v(jPyPyCustomDict, "containsKey", (jObject,), jBool),
+ jvm.Method.v(jPyPyCustomDict, "containsKey", (jObject,), jBool),
(ootype.CustomDict, "ll_length"):
- jvmgen.Method.v(jPyPyCustomDict, "size", (), jInt),
+ jvm.Method.v(jPyPyCustomDict, "size", (), jInt),
(ootype.CustomDict, "ll_clear"):
- jvmgen.Method.v(jPyPyCustomDict, "clear", (), jVoid),
+ jvm.Method.v(jPyPyCustomDict, "clear", (), jVoid),
(ootype.List, "ll_length"):
- jvmgen.Method.v(jArrayList, "size", (), jInt),
+ jvm.Method.v(jArrayList, "size", (), jInt),
(ootype.List, "ll_getitem_fast"):
- jvmgen.Method.v(jArrayList, "get", (jInt,), jObject),
+ jvm.Method.v(jArrayList, "get", (jInt,), jObject),
}
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/cmpopcodes.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/cmpopcodes.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/cmpopcodes.py Fri Apr 4 13:18:57 2008
@@ -1,9 +1,11 @@
-from pypy.translator.jvm.generator import \
+from pypy.translator.jvm.typesystem import \
IFLT, IFLE, IFEQ, IFNE, IFGT, IFGE, \
IFNONNULL, IF_ACMPEQ, GOTO, ICONST, \
DCONST_0, DCMPG, LCONST_0, LCMP, \
IF_ICMPLT, IF_ICMPLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPGT, IF_ICMPGE, \
- PYPYUINTCMP, PYPYULONGCMP, \
+ PYPYUINTCMP, PYPYULONGCMP
+
+from pypy.translator.jvm.generator import \
Label
##### Branch directly as the result of a comparison
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/constant.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/constant.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/constant.py Fri Apr 4 13:18:57 2008
@@ -1,15 +1,14 @@
from pypy.rpython.ootypesystem import ootype
from pypy.objspace.flow import model as flowmodel
-from pypy.translator.jvm.generator import \
- Field, Method, CUSTOMDICTMAKE
+import pypy.translator.jvm.typesystem as jvm
+from pypy.translator.jvm.typesystem import \
+ jVoid, Method, Field
from pypy.translator.oosupport.constant import \
BaseConstantGenerator, RecordConst, InstanceConst, ClassConst, \
StaticMethodConst, CustomDictConst, WeakRefConst, push_constant, \
MAX_CONST_PER_STEP
-from pypy.translator.jvm.typesystem import \
- jObject, jVoid, jPyPyWeakRef, JvmClassType
-jPyPyConstantInit = JvmClassType('pypy.ConstantInit')
+jPyPyConstantInit = jvm.JvmClassType('pypy.ConstantInit')
jPyPyConstantInitMethod = Method.s(jPyPyConstantInit, 'init', [], jVoid)
# ___________________________________________________________________________
@@ -51,7 +50,7 @@
# This prevents any one class from getting too big.
if (self.num_constants % MAX_CONST_PER_STEP) == 0:
cc_num = len(self.ccs)
- self.ccs.append(JvmClassType('pypy.Constant_%d' % cc_num))
+ self.ccs.append(jvm.JvmClassType('pypy.Constant_%d' % cc_num))
self.num_constants += 1
const.fieldobj = Field(self.ccs[-1].name, const.name, jfieldty, True)
@@ -99,7 +98,7 @@
except KeyError:
constants_by_cls[const.fieldobj.class_name] = [const]
for cc in self.ccs:
- ilasm.begin_class(cc, jObject)
+ ilasm.begin_class(cc, jvm.jObject)
for const in constants_by_cls[cc.name]:
ilasm.add_field(const.fieldobj)
ilasm.end_class()
@@ -122,8 +121,9 @@
self._push_constant_during_init(gen, const)
def _declare_step(self, gen, stepnum):
- self.step_classes.append(JvmClassType('pypy.ConstantInit_%d' % stepnum))
- gen.begin_class(self.step_classes[-1], jObject)
+ self.step_classes.append(jvm.JvmClassType(
+ 'pypy.ConstantInit_%d' % stepnum))
+ gen.begin_class(self.step_classes[-1], jvm.jObject)
gen.begin_function('constant_init', [], [], jVoid, True)
def _close_step(self, gen, stepnum):
@@ -132,7 +132,7 @@
gen.end_class() # end pypy.ConstantInit_NNN
def _end_gen_constants(self, gen, numsteps):
- gen.begin_class(jPyPyConstantInit, jObject)
+ gen.begin_class(jPyPyConstantInit, jvm.jObject)
gen.begin_j_function(jPyPyConstantInit, jPyPyConstantInitMethod)
for cls in self.step_classes:
m = Method.s(cls, "constant_init", [], jVoid)
@@ -156,7 +156,7 @@
if self.delegate_impl:
gen.new_with_jtype(self.delegate_impl)
else:
- gen.push_null(jObject)
+ gen.push_null(jvm.jObject)
def initialize_data(self, constgen, gen):
return
@@ -180,7 +180,7 @@
def create_pointer(self, gen):
gen.new_with_jtype(self.eq_jcls)
gen.new_with_jtype(self.hash_jcls)
- gen.emit(CUSTOMDICTMAKE)
+ gen.emit(jvm.CUSTOMDICTMAKE)
class JVMWeakRefConst(WeakRefConst):
@@ -188,7 +188,7 @@
PRIORITY = 200
def jtype(self):
- return jPyPyWeakRef
+ return jvm.jPyPyWeakRef
def create_pointer(self, gen):
if not self.value:
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/database.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/database.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/database.py Fri Apr 4 13:18:57 2008
@@ -7,21 +7,15 @@
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.ootypesystem import ootype, rclass
from pypy.rpython.ootypesystem.module import ll_os
-from pypy.translator.jvm import typesystem as jvmtype
from pypy.translator.jvm import node, methods
from pypy.translator.jvm.option import getoption
-import pypy.translator.jvm.generator as jvmgen
-from pypy.translator.jvm.generator import Method, Property, Field
-import pypy.translator.jvm.constant as jvmconst
-from pypy.translator.jvm.typesystem import \
- jStringBuilder, jInt, jVoid, jString, jChar, jObject, \
- jThrowable, JvmNativeClass, jPyPy, JvmClassType
from pypy.translator.jvm.builtin import JvmBuiltInType
-
from pypy.translator.oosupport.database import Database as OODatabase
from pypy.rpython.ootypesystem.bltregistry import ExternalType
from pypy.annotation.signature import annotation
from pypy.annotation.model import annotation_to_lltype
+import pypy.translator.jvm.constant as jvmconst
+import pypy.translator.jvm.typesystem as jvm
# ______________________________________________________________________
# Database object
@@ -34,7 +28,7 @@
self._jasmin_files = [] # list of strings --- .j files we made
self._classes = {} # Maps ootype class objects to node.Class objects,
# and JvmType objects as well
- self._functions = {} # graph -> jvmgen.Method
+ self._functions = {} # graph -> jvm.Method
# (jargtypes, jrettype) -> node.StaticMethodInterface
self._delegates = {}
@@ -44,7 +38,7 @@
self._function_names = {} # graph --> function_name
- self._constants = {} # flowmodel.Variable --> jvmgen.Const
+ self._constants = {} # flowmodel.Variable --> jvm.Const
# Special fields for the Object class, see _translate_Object
self._object_interf = None
@@ -65,11 +59,11 @@
#
# These are public attributes that are referenced from
# elsewhere in the code using
- # jvmgen.Generator.push_interlink() and .push_pypy().
- self.jPyPyMain = JvmClassType(self._pkg('Main'))
- self.pypy_field = jvmgen.Field.s(self.jPyPyMain, 'pypy', jPyPy)
- self.interlink_field = jvmgen.Field.s(self.jPyPyMain, 'ilink',
- jvmtype.jPyPyInterlink)
+ # jvm.Generator.push_interlink() and .push_pypy().
+ self.jPyPyMain = jvm.JvmClassType(self._pkg('Main'))
+ self.pypy_field = jvm.Field.s(self.jPyPyMain, 'pypy', jvm.jPyPy)
+ self.interlink_field = jvm.Field.s(self.jPyPyMain, 'ilink',
+ jvm.jPyPyInterlink)
# _________________________________________________________________
# Java String vs Byte Array
@@ -93,7 +87,7 @@
def class_name(self, TYPE):
jtype = self.lltype_to_cts(TYPE)
- assert isinstance(jtype, jvmtype.JvmClassType)
+ assert isinstance(jtype, jvm.JvmClassType)
return jtype.name
def add_jasmin_file(self, jfile):
@@ -120,14 +114,14 @@
like.
The 'methods' argument should be a dictionary whose keys are
- method names and whose entries are jvmgen.Method objects which
+ method names and whose entries are jvm.Method objects which
the corresponding method should invoke. """
nm = self._pkg(self._uniq('InterlinkImplementation'))
- cls = node.Class(nm, supercls=jObject)
+ cls = node.Class(nm, supercls=jvm.jObject)
for method_name, helper in methods.items():
cls.add_method(node.InterlinkFunction(cls, method_name, helper))
- cls.add_interface(jvmtype.jPyPyInterlink)
+ cls.add_interface(jvm.jPyPyInterlink)
self.jInterlinkImplementation = cls
self.pending_node(cls)
@@ -169,7 +163,7 @@
# Create the class object first
clsnm = self._pkg(self._uniq('Record'))
- clsobj = node.Class(clsnm, jObject)
+ clsobj = node.Class(clsnm, jvm.jObject)
self._classes[OOTYPE] = clsobj
# Add fields:
@@ -205,8 +199,8 @@
def gen_name(): return self._pkg(self._uniq(OBJ._name))
internm, implnm, exc_implnm = gen_name(), gen_name(), gen_name()
self._object_interf = node.Interface(internm)
- self._object_impl = node.Class(implnm, supercls=jObject)
- self._object_exc_impl = node.Class(exc_implnm, supercls=jThrowable)
+ self._object_impl = node.Class(implnm, supercls=jvm.jObject)
+ self._object_exc_impl = node.Class(exc_implnm, supercls=jvm.jThrowable)
self._object_impl.add_interface(self._object_interf)
self._object_exc_impl.add_interface(self._object_interf)
@@ -220,12 +214,12 @@
methodnm = "_jvm_"+fieldnm
def getter_method_obj(node):
- return Method.v(node, methodnm+"_g", [], fieldty)
+ return jvm.Method.v(node, methodnm+"_g", [], fieldty)
def putter_method_obj(node):
- return Method.v(node, methodnm+"_p", [fieldty], jVoid)
+ return jvm.Method.v(node, methodnm+"_p", [fieldty], jvm.jVoid)
# Add get/put methods to the interface:
- prop = Property(
+ prop = jvm.Property(
fieldnm,
getter_method_obj(self._object_interf),
putter_method_obj(self._object_interf),
@@ -235,7 +229,7 @@
# Generate implementations:
def generate_impl(clsobj):
clsnm = clsobj.name
- fieldobj = Field(clsnm, fieldnm, fieldty, False, FIELDOOTY)
+ fieldobj = jvm.Field(clsnm, fieldnm, fieldty, False, FIELDOOTY)
clsobj.add_field(fieldobj, fielddef)
clsobj.add_method(node.GetterFunction(
self, clsobj, getter_method_obj(clsobj), fieldobj))
@@ -296,7 +290,7 @@
arglist = [self.lltype_to_cts(ARG) for ARG in METH.ARGS
if ARG is not ootype.Void]
returntype = self.lltype_to_cts(METH.RESULT)
- clsobj.add_abstract_method(jvmgen.Method.v(
+ clsobj.add_abstract_method(jvm.Method.v(
clsobj, mname, arglist, returntype))
else:
# if the first argument's type is not a supertype of
@@ -323,7 +317,7 @@
if FIELDOOTY is ootype.Void: continue
fieldty = self.lltype_to_cts(FIELDOOTY)
clsobj.add_field(
- jvmgen.Field(clsobj.name, fieldnm, fieldty, False, FIELDOOTY),
+ jvm.Field(clsobj.name, fieldnm, fieldty, False, FIELDOOTY),
fielddef)
def pending_class(self, OOTYPE):
@@ -334,7 +328,7 @@
This is invoked when a standalone function is to be compiled.
It creates a class named after the function with a single
method, invoke(). This class is added to the worklist.
- Returns a jvmgen.Method object that allows this function to be
+ Returns a jvm.Method object that allows this function to be
invoked.
"""
if graph in self._functions:
@@ -366,7 +360,7 @@
"""
Like record_delegate, but the signature is in terms of java
types. jargs is a list of JvmTypes, one for each argument,
- and jret is a JvmType. Note that jargs does NOT include an
+ and jret is a Jvm. Note that jargs does NOT include an
entry for the this pointer of the resulting object.
"""
key = (jargs, jret)
@@ -424,17 +418,17 @@
# any type.
_toString_methods = {
- ootype.Signed:jvmgen.INTTOSTRINGI,
- ootype.Unsigned:jvmgen.PYPYSERIALIZEUINT,
- ootype.SignedLongLong:jvmgen.LONGTOSTRINGL,
- ootype.UnsignedLongLong: jvmgen.PYPYSERIALIZEULONG,
- ootype.Float:jvmgen.DOUBLETOSTRINGD,
- ootype.Bool:jvmgen.PYPYSERIALIZEBOOLEAN,
- ootype.Void:jvmgen.PYPYSERIALIZEVOID,
- ootype.Char:jvmgen.PYPYESCAPEDCHAR,
- ootype.UniChar:jvmgen.PYPYESCAPEDUNICHAR,
- ootype.String:jvmgen.PYPYESCAPEDSTRING,
- ootype.Unicode:jvmgen.PYPYESCAPEDUNICODE,
+ ootype.Signed:jvm.INTTOSTRINGI,
+ ootype.Unsigned:jvm.PYPYSERIALIZEUINT,
+ ootype.SignedLongLong:jvm.LONGTOSTRINGL,
+ ootype.UnsignedLongLong: jvm.PYPYSERIALIZEULONG,
+ ootype.Float:jvm.DOUBLETOSTRINGD,
+ ootype.Bool:jvm.PYPYSERIALIZEBOOLEAN,
+ ootype.Void:jvm.PYPYSERIALIZEVOID,
+ ootype.Char:jvm.PYPYESCAPEDCHAR,
+ ootype.UniChar:jvm.PYPYESCAPEDUNICHAR,
+ ootype.String:jvm.PYPYESCAPEDSTRING,
+ ootype.Unicode:jvm.PYPYESCAPEDUNICODE,
}
def toString_method_for_ootype(self, OOTYPE):
@@ -451,7 +445,7 @@
to print the value of 'var'.
"""
- return self._toString_methods.get(OOTYPE, jvmgen.PYPYSERIALIZEOBJECT)
+ return self._toString_methods.get(OOTYPE, jvm.PYPYSERIALIZEOBJECT)
# _________________________________________________________________
# Type translation functions
@@ -471,46 +465,51 @@
# Dictionary for scalar types; in this case, if we see the key, we
# will return the value
ootype_to_scalar = {
- ootype.Void: jvmtype.jVoid,
- ootype.Signed: jvmtype.jInt,
- ootype.Unsigned: jvmtype.jInt,
- ootype.SignedLongLong: jvmtype.jLong,
- ootype.UnsignedLongLong: jvmtype.jLong,
- ootype.Bool: jvmtype.jBool,
- ootype.Float: jvmtype.jDouble,
- ootype.Char: jvmtype.jChar, # byte would be sufficient, but harder
- ootype.UniChar: jvmtype.jChar,
- ootype.Class: jvmtype.jClass,
- ootype.ROOT: jvmtype.jObject, # treat like a scalar
+ ootype.Void: jvm.jVoid,
+ ootype.Signed: jvm.jInt,
+ ootype.Unsigned: jvm.jInt,
+ ootype.SignedLongLong: jvm.jLong,
+ ootype.UnsignedLongLong: jvm.jLong,
+ ootype.Bool: jvm.jBool,
+ ootype.Float: jvm.jDouble,
+ ootype.Char: jvm.jChar, # byte would be sufficient, but harder
+ ootype.UniChar: jvm.jChar,
+ ootype.Class: jvm.jClass,
+ ootype.ROOT: jvm.jObject, # treat like a scalar
}
# Dictionary for non-scalar types; in this case, if we see the key, we
# will return a JvmBuiltInType based on the value
ootype_to_builtin = {
- ootype.String: jvmtype.jString,
- ootype.Unicode: jvmtype.jString,
- ootype.StringBuilder: jvmtype.jStringBuilder,
- ootype.UnicodeBuilder: jvmtype.jStringBuilder,
- ootype.List: jvmtype.jArrayList,
- ootype.Dict: jvmtype.jHashMap,
- ootype.DictItemsIterator:jvmtype.jPyPyDictItemsIterator,
- ootype.CustomDict: jvmtype.jPyPyCustomDict,
- ootype.WeakReference: jvmtype.jPyPyWeakRef,
- ll_os.STAT_RESULT: jvmtype.jPyPyStatResult,
+ ootype.String: jvm.jString,
+ ootype.Unicode: jvm.jString,
+ ootype.StringBuilder: jvm.jStringBuilder,
+ ootype.UnicodeBuilder: jvm.jStringBuilder,
+ ootype.List: jvm.jArrayList,
+ ootype.Dict: jvm.jHashMap,
+ ootype.DictItemsIterator:jvm.jPyPyDictItemsIterator,
+ ootype.CustomDict: jvm.jPyPyCustomDict,
+ ootype.WeakReference: jvm.jPyPyWeakRef,
+ ll_os.STAT_RESULT: jvm.jPyPyStatResult,
# These are some configured records that are generated by Java
# code.
#ootype.Record({"item0": ootype.Signed, "item1": ootype.Signed}):
- #jvmtype.jPyPyRecordSignedSigned,
+ #jvm.jPyPyRecordSignedSigned,
#ootype.Record({"item0": ootype.Float, "item1": ootype.Signed}):
- #jvmtype.jPyPyRecordFloatSigned,
+ #jvm.jPyPyRecordFloatSigned,
#ootype.Record({"item0": ootype.Float, "item1": ootype.Float}):
- #jvmtype.jPyPyRecordFloatFloat,
+ #jvm.jPyPyRecordFloatFloat,
#ootype.Record({"item0": ootype.String, "item1": ootype.String}):
- #jvmtype.jPyPyRecordStringString,
+ #jvm.jPyPyRecordStringString,
}
def lltype_to_cts(self, OOT):
+ import sys
+ res = self._lltype_to_cts(OOT)
+ return res
+
+ def _lltype_to_cts(self, OOT):
""" Returns an instance of JvmType corresponding to
the given OOType """
@@ -519,9 +518,11 @@
return self.ootype_to_scalar[OOT]
if (isinstance(OOT, lltype.Ptr) and
isinstance(OOT.TO, lltype.OpaqueType)):
- return jObject
+ return jvm.jObject
if OOT in self.ootype_to_builtin:
return JvmBuiltInType(self, self.ootype_to_builtin[OOT], OOT)
+ if isinstance(OOT, ootype.Array):
+ return self._array_type(OOT.ITEM)
if OOT.__class__ in self.ootype_to_builtin:
return JvmBuiltInType(
self, self.ootype_to_builtin[OOT.__class__], OOT)
@@ -538,10 +539,26 @@
# handle externals
if isinstance(OOT, ExternalType):
- return JvmNativeClass(self, OOT)
+ return jvm.JvmNativeClass(self, OOT)
assert False, "Untranslatable type %s!" % OOT
+ ooitemtype_to_array = {
+ ootype.Signed : jvm.jIntArray,
+ ootype.Unsigned : jvm.jIntArray,
+ ootype.Char : jvm.jCharArray,
+ ootype.Bool : jvm.jBoolArray,
+ ootype.UniChar : jvm.jCharArray,
+ ootype.String : jvm.jStringArray,
+ ootype.Float : jvm.jDoubleArray,
+ ootype.Void : jvm.jVoidArray,
+ }
+
+ def _array_type(self, ITEM):
+ if ITEM in self.ooitemtype_to_array:
+ return self.ooitemtype_to_array[ITEM]
+ return jvm.jObjectArray
+
def annotation_to_cts(self, _tp):
s_tp = annotation(_tp)
TP = annotation_to_lltype(s_tp)
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/generator.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/generator.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/generator.py Fri Apr 4 13:18:57 2008
@@ -12,231 +12,11 @@
from pypy.rlib.objectmodel import CDefinedIntSymbolic
from pypy.rlib.rarithmetic import isnan, isinf
from pypy.translator.oosupport.constant import push_constant
-import pypy.translator.jvm.typesystem as jvmtype
-from pypy.translator.jvm.typesystem import \
- JvmType, jString, jInt, jLong, jDouble, jBool, jString, \
- jPyPy, jVoid, jMath, desc_for_method, jPrintStream, jClass, jChar, \
- jObject, jByteArray, jPyPyExcWrap, jIntegerClass, jLongClass, \
- jDoubleClass, jCharClass, jStringBuilder, JvmScalarType, jArrayList, \
- jObjectArray, jPyPyInterlink, jPyPyCustomDict, jPyPyEquals, \
- jPyPyHashCode, jMap, jPyPyWeakRef, jSystem, jll_os, jPyPyInterlink
-
-
-# ___________________________________________________________________________
-# JVM Opcodes:
-#
-# Map from symbolic name to an instance of the Opcode class
-
-class Opcode(object):
- def __init__(self, jvmstr):
- """
- flags is a set of flags (see above) that describe opcode #UPDATE
- jvmstr is the name for jasmin printouts
- """
- self.jvmstr = jvmstr
- self.flags = None #Should flags be added to args?
-
- def __repr__(self):
- return "<Opcode %s:%x>" % (self.jvmstr, self.flags)
-
- def specialize(self, args):
- """ Process the argument list according to the various flags.
- Returns a tuple (OPCODE, ARGS) where OPCODE is a string representing
- the new opcode, and ARGS is a list of arguments or empty tuple.
- Most of these do not do anything. """
- return (self.jvmstr, args)
-
-class IntConstOpcode(Opcode):
- """ The ICONST opcode specializes itself for small integer opcodes. """
- def specialize(self, args):
- assert len(args) == 1
- if args[0] == -1:
- return self.jvmstr + "_m1", ()
- elif args[0] >= 0 and args[0] <= 5:
- return self.jvmstr + "_" + str(args[0]), ()
- # Non obvious: convert ICONST to LDC if the constant is out of
- # range
- return "ldc", args
-
-class VarOpcode(Opcode):
- """ An Opcode which takes a variable index as an argument; specialized
- to small integer indices. """
- def specialize(self, args):
- assert len(args) == 1
- if args[0] >= 0 and args[0] <= 3:
- return self.jvmstr + "_" + str(args[0]), ()
- return Opcode.specialize(self, args)
-
-class IntClassNameOpcode(Opcode):
- """ An opcode which takes an internal class name as its argument;
- the actual argument will be a JvmType instance. """
- def specialize(self, args):
- args = [args[0].descriptor.int_class_name()]
- return self.jvmstr, args
-
-class OpcodeFamily(object):
- """
- Many opcodes in JVM have variants that depend on the type of the
- operands; for example, one must choose the correct ALOAD, ILOAD,
- or DLOAD depending on whether one is loading a reference, integer,
- or double variable respectively. Each instance of this class
- defines one 'family' of opcodes, such as the LOAD family shown
- above, and produces Opcode objects specific to a particular type.
- """
- def __init__(self, opcclass, suffix):
- """
- opcclass is the opcode subclass to use (see above) when
- instantiating a particular opcode
-
- jvmstr is the name for jasmin printouts
- """
- self.opcode_class = opcclass
- self.suffix = suffix
- self.cache = {}
-
- def _o(self, prefix):
- try:
- return self.cache[prefix]
- except KeyError:
- self.cache[prefix] = obj = self.opcode_class(
- prefix+self.suffix)
- return obj
-
- def for_type(self, argtype):
- """ Returns a customized opcode of this family appropriate to
- 'argtype', a JvmType object. """
-
- desc = argtype.descriptor
-
- # These are always true:
- if desc[0] == 'L': return self._o("a") # Objects
- if desc[0] == '[': return self._o("a") # Arrays
- if desc == 'I': return self._o("i") # Integers
- if desc == 'J': return self._o("l") # Integers
- if desc == 'D': return self._o("d") # Doubles
- if desc == 'V': return self._o("") # Void [used by RETURN]
-
- # Chars/Bytes/Booleans are normally represented as ints
- # in the JVM, but some opcodes are different. They use a
- # different OpcodeFamily (see ArrayOpcodeFamily for ex)
- if desc == 'C': return self._o("i") # Characters
- if desc == 'B': return self._o("i") # Bytes
- if desc == 'Z': return self._o("i") # Boolean
+import pypy.translator.jvm.typesystem as jvm
- assert False, "Unknown argtype=%s" % repr(argtype)
- raise NotImplementedError
-
-class ArrayOpcodeFamily(OpcodeFamily):
- """ Opcode family specialized for array access instr """
- def for_type(self, argtype):
- desc = argtype.descriptor
- if desc == 'J': return self._o("l") # Integers
- if desc == 'D': return self._o("d") # Doubles
- if desc == 'C': return self._o("c") # Characters
- if desc == 'B': return self._o("b") # Bytes
- if desc == 'Z': return self._o("b") # Boolean (access as bytes)
- return OpcodeFamily.for_type(self, argtype)
-
-# Define the opcodes for IFNE, IFEQ, IFLT, IF_ICMPLT, etc. The IFxx
-# variants compare a single integer arg against 0, and the IF_ICMPxx
-# variants compare 2 integer arguments against each other.
-for cmpop in ('ne', 'eq', 'lt', 'gt', 'le', 'ge'):
- ifop = "if%s" % cmpop
- if_icmpop = "if_icmp%s" % cmpop
- globals()[ifop.upper()] = Opcode(ifop)
- globals()[if_icmpop.upper()] = Opcode(if_icmpop)
-
-# Compare references, either against NULL or against each other
-IFNULL = Opcode('ifnull')
-IFNONNULL = Opcode('ifnonnull')
-IF_ACMPEQ = Opcode('if_acmpeq')
-IF_ACMPNE = Opcode('if_acmpne')
-
-# Method invocation
-INVOKESTATIC = Opcode('invokestatic')
-INVOKEVIRTUAL = Opcode('invokevirtual')
-INVOKESPECIAL = Opcode('invokespecial')
-INVOKEINTERFACE = Opcode('invokeinterface')
-
-# Other opcodes
-LDC = Opcode('ldc') # single-word types
-LDC2 = Opcode('ldc2_w') # double-word types: doubles and longs
-GOTO = Opcode('goto')
-ICONST = IntConstOpcode('iconst')
-ICONST_0 = Opcode('iconst_0') # sometimes convenient to refer to this directly
-ACONST_NULL=Opcode('aconst_null')
-DCONST_0 = Opcode('dconst_0')
-DCONST_1 = Opcode('dconst_1')
-LCONST_0 = Opcode('lconst_0')
-LCONST_1 = Opcode('lconst_1')
-GETFIELD = Opcode('getfield')
-PUTFIELD = Opcode('putfield')
-GETSTATIC = Opcode('getstatic')
-PUTSTATIC = Opcode('putstatic')
-CHECKCAST = IntClassNameOpcode('checkcast')
-INEG = Opcode('ineg')
-IXOR = Opcode('ixor')
-IADD = Opcode('iadd')
-ISUB = Opcode('isub')
-IMUL = Opcode('imul')
-IDIV = Opcode('idiv')
-IREM = Opcode('irem')
-IAND = Opcode('iand')
-IOR = Opcode('ior')
-ISHL = Opcode('ishl')
-ISHR = Opcode('ishr')
-IUSHR = Opcode('iushr')
-LCMP = Opcode('lcmp')
-DCMPG = Opcode('dcmpg')
-DCMPL = Opcode('dcmpl')
-NOP = Opcode('nop')
-I2D = Opcode('i2d')
-I2L = Opcode('i2l')
-D2I= Opcode('d2i')
-#D2L= Opcode('d2l') #PAUL
-L2I = Opcode('l2i')
-L2D = Opcode('l2d')
-ATHROW = Opcode('athrow')
-DNEG = Opcode('dneg')
-DADD = Opcode('dadd')
-DSUB = Opcode('dsub')
-DMUL = Opcode('dmul')
-DDIV = Opcode('ddiv')
-DREM = Opcode('drem')
-LNEG = Opcode('lneg')
-LADD = Opcode('ladd')
-LSUB = Opcode('lsub')
-LMUL = Opcode('lmul')
-LDIV = Opcode('ldiv')
-LREM = Opcode('lrem')
-LAND = Opcode('land')
-LOR = Opcode('lor')
-LXOR = Opcode('lxor')
-LSHL = Opcode('lshl')
-LSHR = Opcode('lshr')
-LUSHR = Opcode('lushr')
-NEW = IntClassNameOpcode('new')
-DUP = Opcode('dup')
-DUP2 = Opcode('dup2')
-DUP_X1 = Opcode('dup_x1')
-POP = Opcode('pop')
-POP2 = Opcode('pop2')
-SWAP = Opcode('swap')
-INSTANCEOF= IntClassNameOpcode('instanceof')
-# Loading/storing local variables
-LOAD = OpcodeFamily(VarOpcode, "load")
-STORE = OpcodeFamily(VarOpcode, "store")
-RETURN = OpcodeFamily(Opcode, "return")
-
-# Loading/storing from arrays
-# *NOTE*: This family is characterized by the type of the ELEMENT,
-# not the type of the ARRAY.
-#
-# Also: here I break from convention by naming the objects ARRLOAD
-# rather than ALOAD, even though the suffix is 'aload'. This is to
-# avoid confusion with the ALOAD opcode.
-ARRLOAD = ArrayOpcodeFamily(Opcode, "aload")
-ARRSTORE = ArrayOpcodeFamily(Opcode, "astore")
+# Load a few commonly used names, but prefer to use 'jvm.Name'
+from pypy.translator.jvm.typesystem import \
+ jPyPy, jString, jInt, jVoid
# ___________________________________________________________________________
# Labels
@@ -257,244 +37,6 @@
return self.label
# ___________________________________________________________________________
-# Methods
-#
-# "Method" objects describe all the information needed to invoke a
-# method. We create one for each node.Function object, as well as for
-# various helper methods (defined below). To invoke a method, you
-# push its arguments and then use generator.emit(methobj) where
-# methobj is its Method instance.
-
-class Method(object):
-
- # Create a constructor:
- def c(classty, argtypes):
- return Method(classty.name, "<init>", argtypes, jVoid,
- opcode=INVOKESPECIAL)
- c = staticmethod(c)
-
- # Create a virtual or interface method:
- def v(classty, methnm, argtypes, rettype):
- """
- Shorthand to create a virtual method.
- 'class' - JvmType object for the class
- 'methnm' - name of the method (Python string)
- 'argtypes' - list of JvmType objects, one for each argument but
- not the this ptr
- 'rettype' - JvmType for return type
- """
- assert argtypes is not None
- assert rettype is not None
- classnm = classty.name
- if isinstance(classty, jvmtype.JvmInterfaceType):
- opc = INVOKEINTERFACE
- else:
- assert isinstance(classty, jvmtype.JvmClassType)
- opc = INVOKEVIRTUAL
- return Method(classnm, methnm, argtypes, rettype, opcode=opc)
- v = staticmethod(v)
-
- # Create a static method:
- def s(classty, methnm, argtypes, rettype):
- """
- Shorthand to create a static method.
- 'class' - JvmType object for the class
- 'methnm' - name of the method (Python string)
- 'argtypes' - list of JvmType objects, one for each argument but
- not the this ptr
- 'rettype' - JvmType for return type
- """
- assert isinstance(classty, JvmType)
- classnm = classty.name
- return Method(classnm, methnm, argtypes, rettype)
- s = staticmethod(s)
-
- def __init__(self, classnm, methnm, argtypes, rettype, opcode=INVOKESTATIC):
- self.opcode = opcode
- self.class_name = classnm # String, ie. "java.lang.Math"
- self.method_name = methnm # String "abs"
- self.argument_types = argtypes # List of jvmtypes
- self.return_type = rettype # jvmtype
-
- # Compute the method descriptior, which is a string like "()I":
- argtypesdesc = [a.descriptor for a in argtypes]
- rettypedesc = rettype.descriptor
- self.descriptor = desc_for_method(argtypesdesc, rettypedesc)
- def invoke(self, gen):
- gen._instr(self.opcode, self)
- def is_static(self):
- return self.opcode == INVOKESTATIC
- def jasmin_syntax(self):
- res = "%s/%s%s" % (self.class_name.replace('.','/'),
- self.method_name,
- self.descriptor)
- # A weird, inexplicable quirk of Jasmin syntax is that it requires
- # the number of arguments after an invokeinterface call:
- if self.opcode == INVOKEINTERFACE:
- res += " %d" % (len(self.argument_types)+1,)
- return res
-
-OBJHASHCODE = Method.v(jObject, 'hashCode', (), jInt)
-OBJTOSTRING = Method.v(jObject, 'toString', (), jString)
-OBJEQUALS = Method.v(jObject, 'equals', (jObject,), jBool)
-SYSTEMGC = Method.s(jSystem, 'gc', (), jVoid)
-INTTOSTRINGI = Method.s(jIntegerClass, 'toString', (jInt,), jString)
-LONGTOSTRINGL = Method.s(jLongClass, 'toString', (jLong,), jString)
-DOUBLETOSTRINGD = Method.s(jDoubleClass, 'toString', (jDouble,), jString)
-CHARTOSTRINGC = Method.s(jCharClass, 'toString', (jChar,), jString)
-MATHIABS = Method.s(jMath, 'abs', (jInt,), jInt)
-IABSOVF = Method.v(jPyPy, 'abs_ovf', (jInt,), jInt)
-MATHLABS = Method.s(jMath, 'abs', (jLong,), jLong)
-LABSOVF = Method.v(jPyPy, 'abs_ovf', (jLong,), jLong)
-MATHDABS = Method.s(jMath, 'abs', (jDouble,), jDouble)
-INEGOVF = Method.v(jPyPy, 'negate_ovf', (jInt,), jInt)
-LNEGOVF = Method.v(jPyPy, 'negate_ovf', (jLong,), jLong)
-IADDOVF = Method.v(jPyPy, 'add_ovf', (jInt, jInt), jInt)
-LADDOVF = Method.v(jPyPy, 'add_ovf', (jLong, jLong), jLong)
-ISUBOVF = Method.v(jPyPy, 'subtract_ovf', (jInt, jInt), jInt)
-LSUBOVF = Method.v(jPyPy, 'subtract_ovf', (jLong, jLong), jLong)
-IMULOVF = Method.v(jPyPy, 'multiply_ovf', (jInt, jInt), jInt)
-LMULOVF = Method.v(jPyPy, 'multiply_ovf', (jLong, jLong), jLong)
-MATHFLOOR = Method.s(jMath, 'floor', (jDouble,), jDouble)
-IFLOORDIVOVF = Method.v(jPyPy, 'floordiv_ovf', (jInt, jInt), jInt)
-LFLOORDIVOVF = Method.v(jPyPy, 'floordiv_ovf', (jLong, jLong), jLong)
-IFLOORDIVZEROVF = Method.v(jPyPy, 'floordiv_zer_ovf', (jInt, jInt), jInt)
-LFLOORDIVZEROVF = Method.v(jPyPy, 'floordiv_zer_ovf', (jLong, jLong), jLong)
-IREMOVF = Method.v(jPyPy, 'mod_ovf', (jInt, jInt), jInt)
-LREMOVF = Method.v(jPyPy, 'mod_ovf', (jLong, jLong), jLong)
-ISHLOVF = Method.v(jPyPy, 'lshift_ovf', (jInt, jInt), jInt)
-LSHLOVF = Method.v(jPyPy, 'lshift_ovf', (jLong, jLong), jLong)
-MATHDPOW = Method.s(jMath, 'pow', (jDouble, jDouble), jDouble)
-PRINTSTREAMPRINTSTR = Method.v(jPrintStream, 'print', (jString,), jVoid)
-CLASSFORNAME = Method.s(jClass, 'forName', (jString,), jClass)
-CLASSISASSIGNABLEFROM = Method.v(jClass, 'isAssignableFrom', (jClass,), jBool)
-STRINGBUILDERAPPEND = Method.v(jStringBuilder, 'append',
- (jString,), jStringBuilder)
-PYPYUINTCMP = Method.s(jPyPy, 'uint_cmp', (jInt,jInt,), jInt)
-PYPYULONGCMP = Method.s(jPyPy, 'ulong_cmp', (jLong,jLong), jInt)
-PYPYUINTMOD = Method.v(jPyPy, 'uint_mod', (jInt, jInt), jInt)
-PYPYUINTMUL = Method.v(jPyPy, 'uint_mul', (jInt, jInt), jInt)
-PYPYUINTDIV = Method.v(jPyPy, 'uint_div', (jInt, jInt), jInt)
-PYPYULONGMOD = Method.v(jPyPy, 'ulong_mod', (jLong, jLong), jLong)
-PYPYUINTTODOUBLE = Method.s(jPyPy, 'uint_to_double', (jInt,), jDouble)
-PYPYDOUBLETOUINT = Method.s(jPyPy, 'double_to_uint', (jDouble,), jInt)
-PYPYDOUBLETOLONG = Method.v(jPyPy, 'double_to_long', (jDouble,), jLong) #PAUL
-PYPYLONGBITWISENEGATE = Method.v(jPyPy, 'long_bitwise_negate', (jLong,), jLong)
-PYPYSTRTOINT = Method.v(jPyPy, 'str_to_int', (jString,), jInt)
-PYPYSTRTOUINT = Method.v(jPyPy, 'str_to_uint', (jString,), jInt)
-PYPYSTRTOLONG = Method.v(jPyPy, 'str_to_long', (jString,), jLong)
-PYPYSTRTOULONG = Method.v(jPyPy, 'str_to_ulong', (jString,), jLong)
-PYPYSTRTOBOOL = Method.v(jPyPy, 'str_to_bool', (jString,), jBool)
-PYPYSTRTODOUBLE = Method.v(jPyPy, 'str_to_double', (jString,), jDouble)
-PYPYSTRTOCHAR = Method.v(jPyPy, 'str_to_char', (jString,), jChar)
-PYPYBOOLTODOUBLE = Method.v(jPyPy, 'bool_to_double', (jBool,), jDouble)
-PYPYDUMP = Method.s(jPyPy, 'dump', (jString,), jVoid)
-PYPYDUMPEXCWRAPPER = Method.s(jPyPy, 'dump_exc_wrapper', (jObject,), jVoid)
-PYPYSERIALIZEBOOLEAN = Method.s(jPyPy, 'serialize_boolean', (jBool,), jString)
-PYPYSERIALIZEUINT = Method.s(jPyPy, 'serialize_uint', (jInt,), jString)
-PYPYSERIALIZEULONG = Method.s(jPyPy, 'serialize_ulonglong', (jLong,),jString)
-PYPYSERIALIZEVOID = Method.s(jPyPy, 'serialize_void', (), jString)
-PYPYESCAPEDCHAR = Method.s(jPyPy, 'escaped_char', (jChar,), jString)
-PYPYESCAPEDUNICHAR = Method.s(jPyPy, 'escaped_unichar', (jChar,), jString)
-PYPYESCAPEDSTRING = Method.s(jPyPy, 'escaped_string', (jString,), jString)
-PYPYESCAPEDUNICODE = Method.s(jPyPy, 'escaped_unicode', (jString,), jString)
-PYPYSERIALIZEOBJECT = Method.s(jPyPy, 'serializeObject', (jObject,), jString)
-PYPYRUNTIMENEW = Method.s(jPyPy, 'RuntimeNew', (jClass,), jObject)
-PYPYSTRING2BYTES = Method.s(jPyPy, 'string2bytes', (jString,), jByteArray)
-PYPYARRAYTOLIST = Method.s(jPyPy, 'array_to_list', (jObjectArray,), jArrayList)
-PYPYOOPARSEFLOAT = Method.v(jPyPy, 'ooparse_float', (jString,), jDouble)
-OBJECTGETCLASS = Method.v(jObject, 'getClass', (), jClass)
-CLASSGETNAME = Method.v(jClass, 'getName', (), jString)
-CUSTOMDICTMAKE = Method.s(jPyPyCustomDict, 'make',
- (jPyPyEquals, jPyPyHashCode), jPyPyCustomDict)
-PYPYWEAKREFCREATE = Method.s(jPyPyWeakRef, 'create', (jObject,), jPyPyWeakRef)
-PYPYWEAKREFGET = Method.s(jPyPyWeakRef, 'll_get', (), jObject)
-
-# ___________________________________________________________________________
-# Fields
-#
-# Field objects encode information about fields.
-
-class Field(object):
-
- @staticmethod
- def i(classty, fieldnm, fieldty, OOTYPE=None):
- """
- Shorthand to create an instance field.
- 'class' - JvmType object for the class containing the field
- 'fieldnm' - name of the field (Python string)
- 'fieldty' - JvmType object for the type of the field
- 'OOTYPE' - optional OOTYPE object for the type of the field
- """
- return Field(classty.name, fieldnm, fieldty, False, OOTYPE)
-
- @staticmethod
- def s(classty, fieldnm, fieldty, OOTYPE=None):
- """
- Shorthand to create a static field.
- 'class' - JvmType object for the class containing the field
- 'fieldnm' - name of the field (Python string)
- 'fieldty' - JvmType object for the type of the field
- 'OOTYPE' - optional OOTYPE object for the type of the field
- """
- return Field(classty.name, fieldnm, fieldty, True, OOTYPE)
-
- def __init__(self, classnm, fieldnm, jtype, static, OOTYPE=None):
- # All fields are public
- self.class_name = classnm # String, ie. "java.lang.Math"
- self.field_name = fieldnm # String "someField"
- self.OOTYPE = OOTYPE # OOTYPE equivalent of JvmType, may be None
- self.jtype = jtype # JvmType
- self.is_static = static # True or False
- def load(self, gen):
- if self.is_static:
- gen._instr(GETSTATIC, self)
- else:
- gen._instr(GETFIELD, self)
- def store(self, gen):
- if self.is_static:
- gen._instr(PUTSTATIC, self)
- else:
- gen._instr(PUTFIELD, self)
- def jasmin_syntax(self):
- return "%s/%s %s" % (
- self.class_name.replace('.','/'),
- self.field_name,
- self.jtype.descriptor)
-
-class Property(object):
- """
- An object which acts like a Field, but when a value is loaded or
- stored it actually invokes accessor methods.
- """
- def __init__(self, field_name, get_method, put_method, OOTYPE=None):
- self.get_method = get_method
- self.put_method = put_method
- self.field_name = field_name
- self.OOTYPE = OOTYPE
-
- # Synthesize the Field attributes from the get_method/put_method:
- self.class_name = get_method.class_name
- assert put_method.class_name == self.class_name
- self.jtype = get_method.return_type
- self.is_static = get_method.is_static
- def load(self, gen):
- self.get_method.invoke(gen)
- def store(self, gen):
- self.put_method.invoke(gen)
- # jasmin_syntax is not needed, since this object itself never appears
- # as an argument an Opcode
-
-SYSTEMOUT = Field.s(jSystem, 'out', jPrintStream)
-SYSTEMERR = Field.s(jSystem, 'err', jPrintStream)
-DOUBLENAN = Field.s(jDoubleClass, 'NaN', jDouble)
-DOUBLEPOSINF = Field.s(jDoubleClass, 'POSITIVE_INFINITY', jDouble)
-DOUBLENEGINF = Field.s(jDoubleClass, 'NEGATIVE_INFINITY', jDouble)
-
-PYPYINTERLINK= Field.i(jPyPy, 'interlink', jPyPyInterlink)
-PYPYOS = Field.i(jPyPy, 'os', jll_os)
-
-# ___________________________________________________________________________
# Generator State
class ClassState(object):
@@ -625,8 +167,7 @@
"""
self.begin_function("<init>", [], [self.current_type()], jVoid)
self.load_jvm_var(self.current_type(), 0)
- jmethod = Method(self.curclass.superclass_type.name, "<init>",
- (), jVoid, opcode=INVOKESPECIAL)
+ jmethod = jvm.Method.c(self.curclass.superclass_type, ())
jmethod.invoke(self)
def end_constructor(self):
@@ -700,14 +241,14 @@
def return_val(self, jtype):
""" Returns a value from top of stack of the JvmType 'jtype' """
- self._instr(RETURN.for_type(jtype))
+ self._instr(jvm.RETURN.for_type(jtype))
def load_class_name(self):
""" Loads the name of the *Java* class of the object on the top of
the stack as a Java string. Note that the result for a PyPy
generated class will look something like 'pypy.some.pkg.cls' """
- self.emit(OBJECTGETCLASS)
- self.emit(CLASSGETNAME)
+ self.emit(jvm.OBJECTGETCLASS)
+ self.emit(jvm.CLASSGETNAME)
def load_string(self, str):
""" Pushes a Java version of a Python string onto the stack.
@@ -724,7 +265,7 @@
'"')
# Use LDC to load the Java version:
# XXX --- support byte arrays here? Would be trickier!
- self._instr(LDC, res)
+ self._instr(jvm.LDC, res)
def load_jvm_var(self, jvartype, varidx):
""" Loads from jvm slot #varidx, which is expected to hold a value of
@@ -732,20 +273,20 @@
assert varidx < self.curfunc.next_offset
if jvartype is jVoid:
return
- opc = LOAD.for_type(jvartype)
+ opc = jvm.LOAD.for_type(jvartype)
self._instr(opc, varidx)
def store_jvm_var(self, vartype, varidx):
""" Loads from jvm slot #varidx, which is expected to hold a value of
type vartype """
- self._instr(STORE.for_type(vartype), varidx)
+ self._instr(jvm.STORE.for_type(vartype), varidx)
def load_from_array(self, elemtype):
""" Loads something from an array; the result will be of type 'elemtype'
(and hence the array is of type 'array_of(elemtype)'), where
'elemtype' is a JvmType. Assumes that the array ref and index are
already pushed onto stack (in that order). """
- self._instr(ARRLOAD.for_type(elemtype))
+ self._instr(jvm.ARRLOAD.for_type(elemtype))
def store_to_array(self, elemtype):
""" Stores something into an array; the result will be of type
@@ -753,7 +294,7 @@
'array_of(elemtype)'), where 'elemtype' is a JvmType. Assumes
that the array ref, index, and value are already pushed onto
stack (in that order)."""
- self._instr(ARRLOAD.for_type(elemtype))
+ self._instr(jvm.ARRLOAD.for_type(elemtype))
def unique_label(self, desc, mark=False):
""" Returns an opaque, unique label object that can be passed an
@@ -773,7 +314,7 @@
def load_this_ptr(self):
""" Convenience method. Be sure you only call it from a
virtual method, not static methods. """
- self.load_jvm_var(jObject, 0)
+ self.load_jvm_var(jvm.jObject, 0)
def load_function_argument(self, index):
""" Convenience method. Loads function argument #index; note that
@@ -786,9 +327,9 @@
self.prepare_generic_argument_with_jtype(jty)
def prepare_generic_argument_with_jtype(self, jty):
- if jty is jvmtype.jVoid:
- self.emit(ACONST_NULL)
- elif isinstance(jty, JvmScalarType):
+ if jty is jVoid:
+ self.emit(jvm.ACONST_NULL)
+ elif isinstance(jty, jvm.JvmScalarType):
self.box_value(jty)
def prepare_generic_result(self, ITEMTYPE):
@@ -796,9 +337,9 @@
self.prepare_generic_result_with_jtype(jresty)
def prepare_generic_result_with_jtype(self, jresty):
- if jresty is jvmtype.jVoid:
- self.emit(POP)
- elif isinstance(jresty, JvmScalarType):
+ if jresty is jVoid:
+ self.emit(jvm.POP)
+ elif isinstance(jresty, jvm.JvmScalarType):
# Perform any un-boxing required:
self.downcast_jtype(jresty.box_type)
self.unbox_value(jresty)
@@ -810,20 +351,21 @@
""" Assuming that an value of type jscalartype is on the stack,
boxes it into an Object. """
jclasstype = jscalartype.box_type
- jmethod = Method.s(jclasstype, 'valueOf', (jscalartype,), jclasstype)
+ jmethod = jvm.Method.s(
+ jclasstype, 'valueOf', (jscalartype,), jclasstype)
self.emit(jmethod)
def unbox_value(self, jscalartype):
""" Assuming that a boxed value of type jscalartype is on the stack,
unboxes it. """
jclasstype = jscalartype.box_type
- jmethod = Method.v(
+ jmethod = jvm.Method.v(
jclasstype, jscalartype.unbox_method, (), jscalartype)
self.emit(jmethod)
def swap(self):
""" Swaps the two words highest on the stack. """
- self.emit(SWAP)
+ self.emit(jvm.SWAP)
# __________________________________________________________________
# Exception Handling
@@ -869,14 +411,14 @@
_equals = {
ootype.Void: (None,None),
- ootype.SignedLongLong: (LCMP,IFEQ),
- ootype.UnsignedLongLong: (LCMP,IFEQ),
- ootype.Float: (DCMPG,IFEQ),
- ootype.Signed: (None,IF_ICMPNE),
- ootype.Unsigned: (None,IF_ICMPNE),
- ootype.Bool: (None,IF_ICMPNE),
- ootype.Char: (None,IF_ICMPNE),
- ootype.UniChar: (None,IF_ICMPNE),
+ ootype.SignedLongLong: (jvm.LCMP, jvm.IFEQ),
+ ootype.UnsignedLongLong: (jvm.LCMP, jvm.IFEQ),
+ ootype.Float: (jvm.DCMPG, jvm.IFEQ),
+ ootype.Signed: (None,jvm.IF_ICMPNE),
+ ootype.Unsigned: (None,jvm.IF_ICMPNE),
+ ootype.Bool: (None,jvm.IF_ICMPNE),
+ ootype.Char: (None,jvm.IF_ICMPNE),
+ ootype.UniChar: (None,jvm.IF_ICMPNE),
}
def compare_values(self, OOTYPE, unequal_lbl):
""" Assumes that two instances of OOTYPE are pushed on the stack;
@@ -886,14 +428,14 @@
if i1: self.emit(i1)
if i2: self.emit(i2, unequal_lbl)
return
- self.emit(OBJEQUALS)
- self.emit(IFEQ, unequal_lbl)
+ self.emit(jvm.OBJEQUALS)
+ self.emit(jvm.IFEQ, unequal_lbl)
_hash = {
- ootype.Void: ICONST_0,
- ootype.SignedLongLong: L2I,
- ootype.UnsignedLongLong: L2I,
- ootype.Float: D2I,
+ ootype.Void: jvm.ICONST_0,
+ ootype.SignedLongLong: jvm.L2I,
+ ootype.UnsignedLongLong: jvm.L2I,
+ ootype.Float: jvm.D2I,
ootype.Signed: None,
ootype.Unsigned: None,
ootype.Bool: None,
@@ -907,7 +449,7 @@
i1 = self._hash[OOTYPE]
if i1: self.emit(i1)
return
- self.emit(OBJHASHCODE)
+ self.emit(jvm.OBJHASHCODE)
# __________________________________________________________________
# Generator methods and others that are invoked by MicroInstructions
@@ -919,16 +461,19 @@
it is the name of a method to invoke, or an Opcode/Method
object (defined above)."""
+ if instr is None:
+ return
+
if isinstance(instr, str):
return getattr(self, instr)(*args)
- if isinstance(instr, Opcode):
+ if isinstance(instr, jvm.Opcode):
return self._instr(instr, *args)
- if isinstance(instr, Method):
+ if isinstance(instr, jvm.BaseMethod):
return instr.invoke(self)
- if isinstance(instr, Field) or isinstance(instr, Property):
+ if isinstance(instr, jvm.Field) or isinstance(instr, jvm.Property):
return instr.load(self)
raise Exception("Unknown object in call to emit(): "+repr(instr))
@@ -936,6 +481,7 @@
def _var_data(self, v):
# Determine java type:
jty = self.db.lltype_to_cts(v.concretetype)
+ import sys
# Determine index in stack frame slots:
# note that arguments and locals can be treated the same here
return jty, self.curfunc.var_offset(v, jty)
@@ -989,11 +535,11 @@
self.downcast_jtype(jtype)
def downcast_jtype(self, jtype):
- self._instr(CHECKCAST, jtype)
+ self._instr(jvm.CHECKCAST, jtype)
def instanceof(self, TYPE):
jtype = self.db.lltype_to_cts(TYPE)
- self._instr(INSTANCEOF, jtype)
+ self._instr(jvm.INSTANCEOF, jtype)
# included for compatibility with oosupport, but instanceof_jtype
# follows our naming convention better
@@ -1001,22 +547,22 @@
return self.instanceof_jtype(jtype)
def instanceof_jtype(self, jtype):
- self._instr(INSTANCEOF, jtype)
+ self._instr(jvm.INSTANCEOF, jtype)
def branch_unconditionally(self, target_label):
self.goto(target_label)
def branch_conditionally(self, cond, target_label):
if cond:
- self._instr(IFNE, target_label)
+ self._instr(jvm.IFNE, target_label)
else:
- self._instr(IFEQ, target_label)
+ self._instr(jvm.IFEQ, target_label)
def branch_if_equal(self, target_label):
- self._instr(IF_ICMPEQ, target_label)
+ self._instr(jvm.IF_ICMPEQ, target_label)
def branch_if_not_equal(self, target_label):
- self._instr(IF_ICMPNE, target_label)
+ self._instr(jvm.IF_ICMPNE, target_label)
def call_graph(self, graph):
mthd = self.db.pending_function(graph)
@@ -1028,7 +574,7 @@
mthd.invoke(self)
# Check if we have to convert the result type at all:
- gener = jvmtype.Generifier(OOCLASS)
+ gener = jvm.Generifier(OOCLASS)
RETTYPE = gener.full_types(method_name)[1]
jrettype = self.db.lltype_to_cts(RETTYPE)
if jrettype != mthd.return_type:
@@ -1043,7 +589,7 @@
# If necessary, load the ll_os object pointer instead:
if module == 'll_os':
- PYPYOS.load(self)
+ jvm.PYPYOS.load(self)
def call_primitive(self, op, module, name):
callee = op.args[0].value
@@ -1052,7 +598,7 @@
# Determine what class the primitive is implemented in:
if module == 'll_os':
- jcls = jll_os
+ jcls = jvm.jll_os
else:
jcls = jPyPy
@@ -1062,9 +608,9 @@
# the method cannot directly refer to the Java type in
# .java source, as its name is not yet known.
if jrettype.is_generated():
- mthd = Method.v(jcls, name, jargtypes, jObject)
+ mthd = jvm.Method.v(jcls, name, jargtypes, jvm.jObject)
else:
- mthd = Method.v(jcls, name, jargtypes, jrettype)
+ mthd = jvm.Method.v(jcls, name, jargtypes, jrettype)
# Invoke the method
self.emit(mthd)
@@ -1081,13 +627,13 @@
cts_type = self.db.lltype_to_cts(OOTYPE)
# treat all objects the same:
- if isinstance(cts_type, jvmtype.JvmClassType):
- cts_type = jObject
+ if isinstance(cts_type, jvm.JvmClassType):
+ cts_type = jvm.jObject
- mthd = Method.v(jPyPy, 'oostring', [cts_type, jInt], jString)
+ mthd = jvm.Method.v(jPyPy, 'oostring', [cts_type, jInt], jString)
self.emit(mthd)
if self.db.using_byte_array:
- self.emit(PYPYSTRING2BYTES)
+ self.emit(jvm.PYPYSTRING2BYTES)
def prepare_call_oounicode(self, OOTYPE):
# Load the PyPy object pointer onto the stack:
@@ -1095,10 +641,10 @@
def call_oounicode(self, OOTYPE):
cts_type = self.db.lltype_to_cts(OOTYPE)
- mthd = Method.v(jPyPy, 'oounicode', [cts_type], jString)
+ mthd = jvm.Method.v(jPyPy, 'oounicode', [cts_type], jString)
self.emit(mthd)
if self.db.using_byte_array:
- self.emit(PYPYSTRING2BYTES)
+ self.emit(jvm.PYPYSTRING2BYTES)
def new(self, TYPE):
jtype = self.db.lltype_to_cts(TYPE)
@@ -1106,38 +652,43 @@
def new_with_jtype(self, jtype, ctor=None):
if ctor is None:
- ctor = Method.c(jtype, ())
- self.emit(NEW, jtype)
- self.emit(DUP)
+ ctor = jvm.Method.c(jtype, ())
+ self.emit(jvm.NEW, jtype)
+ self.emit(jvm.DUP)
self.emit(ctor)
+ def oonewarray(self, TYPE, length):
+ jtype = self.db.lltype_to_cts(TYPE)
+ self.load(length)
+ jtype.make(self)
+
def instantiate(self):
- self.emit(PYPYRUNTIMENEW)
+ self.emit(jvm.PYPYRUNTIMENEW)
def getclassobject(self, OOINSTANCE):
- jvmtype = self.db.lltype_to_cts(OOINSTANCE)
- self.load_string(jvmtype.name)
- CLASSFORNAME.invoke(self)
+ jtype = self.db.lltype_to_cts(OOINSTANCE)
+ self.load_string(jtype.name)
+ jvm.CLASSFORNAME.invoke(self)
def dup(self, OOTYPE):
- jvmtype = self.db.lltype_to_cts(OOTYPE)
- self.dup_jtype(jvmtype)
+ jtype = self.db.lltype_to_cts(OOTYPE)
+ self.dup_jtype(jtype)
- def dup_jtype(self, jvmtype):
- if jvmtype.descriptor.type_width() == 1:
- self.emit(DUP)
+ def dup_jtype(self, jtype):
+ if jtype.descriptor.type_width() == 1:
+ self.emit(jvm.DUP)
else:
- self.emit(DUP2)
+ self.emit(jvm.DUP2)
def pop(self, OOTYPE):
- jvmtype = self.db.lltype_to_cts(OOTYPE)
- if jvmtype.descriptor.type_width() == 1:
- self.emit(POP)
+ jtype = self.db.lltype_to_cts(OOTYPE)
+ if jtype.descriptor.type_width() == 1:
+ self.emit(jvm.POP)
else:
- self.emit(POP2)
+ self.emit(jvm.POP2)
def push_null(self, OOTYPE):
- self.emit(ACONST_NULL)
+ self.emit(jvm.ACONST_NULL)
# we can't assume MALLOC_ZERO_FILLED, because for scalar type the
# default item for ArrayList is null, not e.g. Integer(0) or
@@ -1150,16 +701,16 @@
if TYPE is ootype.Void:
return
elif isinstance(value, CDefinedIntSymbolic):
- self.emit(ICONST, self.DEFINED_INT_SYMBOLICS[value.expr])
+ self.emit(jvm.ICONST, self.DEFINED_INT_SYMBOLICS[value.expr])
elif TYPE in (ootype.Bool, ootype.Signed):
- self.emit(ICONST, int(value))
+ self.emit(jvm.ICONST, int(value))
elif TYPE is ootype.Unsigned:
# Converts the unsigned int into its corresponding signed value:
if value > 0x7FFFFFFF:
value = -((int(value) ^ 0xFFFFFFFF)+1)
- self.emit(ICONST, value)
+ self.emit(jvm.ICONST, value)
elif TYPE is ootype.Char or TYPE is ootype.UniChar:
- self.emit(ICONST, ord(value))
+ self.emit(jvm.ICONST, ord(value))
elif TYPE is ootype.SignedLongLong:
self._push_long_constant(long(value))
elif TYPE is ootype.UnsignedLongLong:
@@ -1171,7 +722,7 @@
self._push_double_constant(float(value))
elif TYPE in (ootype.String, ootype.Unicode):
if value == ootype.null(TYPE):
- self.emit(ACONST_NULL)
+ self.emit(jvm.ACONST_NULL)
else:
self.load_string(value._str)
else:
@@ -1179,25 +730,25 @@
def _push_long_constant(self, value):
if value == 0:
- self.emit(LCONST_0)
+ self.emit(jvm.LCONST_0)
elif value == 1:
- self.emit(LCONST_1)
+ self.emit(jvm.LCONST_1)
else:
- self.emit(LDC2, value)
+ self.emit(jvm.LDC2, value)
def _push_double_constant(self, value):
if isnan(value):
- DOUBLENAN.load(self)
+ jvm.DOUBLENAN.load(self)
elif isinf(value):
- if value > 0: DOUBLEPOSINF.load(self)
- else: DOUBLENEGINF.load(self)
+ if value > 0: jvm.DOUBLEPOSINF.load(self)
+ else: jvm.DOUBLENEGINF.load(self)
elif value == 0.0:
- self.emit(DCONST_0)
+ self.emit(jvm.DCONST_0)
elif value == 1.0:
- self.emit(DCONST_1)
+ self.emit(jvm.DCONST_1)
else:
# Big hack to avoid exponential notation:
- self.emit(LDC2, "%22.22f" % value)
+ self.emit(jvm.LDC2, "%22.22f" % value)
def create_weakref(self, OOTYPE):
"""
@@ -1207,7 +758,7 @@
The result will be that at the top of the stack is a weak reference.
"""
self.prepare_generic_argument(OOTYPE)
- self.emit(PYPYWEAKREFCREATE)
+ self.emit(jvm.PYPYWEAKREFCREATE)
def deref_weakref(self, OOTYPE):
"""
@@ -1215,7 +766,7 @@
that this weak ref is a pointer to. OOTYPE is the kind of object
you had a weak reference to.
"""
- self.emit(PYPYWEAKREFGET)
+ self.emit(jvm.PYPYWEAKREFGET)
self.prepare_generic_result(OOTYPE)
# __________________________________________________________________
@@ -1223,30 +774,30 @@
def throw(self):
""" Throw the object from top of the stack as an exception """
- self._instr(ATHROW)
+ self._instr(jvm.ATHROW)
def iabs(self):
- MATHIABS.invoke(self)
+ jvm.MATHIABS.invoke(self)
def dbl_abs(self):
- MATHDABS.invoke(self)
+ jvm.MATHDABS.invoke(self)
def bitwise_negate(self):
""" Invert all the bits in the "int" on the top of the stack """
- self._instr(ICONST, -1)
- self._instr(IXOR)
+ self._instr(jvm.ICONST, -1)
+ self._instr(jvm.IXOR)
def goto(self, label):
""" Jumps unconditionally """
- self._instr(GOTO, label)
+ self._instr(jvm.GOTO, label)
def goto_if_true(self, label):
""" Jumps if the top of stack is true """
- self._instr(IFNE, label)
+ self._instr(jvm.IFNE, label)
def goto_if_false(self, label):
""" Jumps if the top of stack is false """
- self._instr(IFEQ, label)
+ self._instr(jvm.IFEQ, label)
class JasminGenerator(JVMGenerator):
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/metavm.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/metavm.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/metavm.py Fri Apr 4 13:18:57 2008
@@ -1,8 +1,7 @@
from pypy.rpython.ootypesystem import ootype
from pypy.translator.oosupport.metavm import MicroInstruction
from pypy.translator.jvm.typesystem import JvmScalarType, JvmClassType
-import pypy.translator.jvm.generator as jvmgen
-import pypy.translator.jvm.typesystem as jvmtype
+import pypy.translator.jvm.typesystem as jvm
from pypy.translator.jvm.builtin import JvmBuiltInType
from pypy.translator.jvm import cmpopcodes
@@ -86,13 +85,13 @@
def render(self, generator, op):
self._load_func(generator, *op.args[1:4])
self._load_func(generator, *op.args[4:7])
- generator.emit(jvmgen.CUSTOMDICTMAKE)
+ generator.emit(jvm.CUSTOMDICTMAKE)
NewCustomDict = _NewCustomDict()
CASTS = {
# FROM TO
- (ootype.Signed, ootype.UnsignedLongLong): jvmgen.I2L,
- (ootype.SignedLongLong, ootype.Signed): jvmgen.L2I,
+ (ootype.Signed, ootype.UnsignedLongLong): jvm.I2L,
+ (ootype.SignedLongLong, ootype.Signed): jvm.L2I,
(ootype.UnsignedLongLong, ootype.SignedLongLong): None,
}
@@ -118,9 +117,9 @@
truelbl = generator.unique_label('load_comparision_result_true')
endlbl = generator.unique_label('load_comparision_result_end')
cmpopcodes.branch_if(generator, op.opname, truelbl)
- generator.emit(jvmgen.ICONST, 0)
+ generator.emit(jvm.ICONST, 0)
generator.goto(endlbl)
generator.mark(truelbl)
- generator.emit(jvmgen.ICONST, 1)
+ generator.emit(jvm.ICONST, 1)
generator.mark(endlbl)
PushComparisonResult = _PushComparisonResult()
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/methods.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/methods.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/methods.py Fri Apr 4 13:18:57 2008
@@ -7,8 +7,7 @@
"""
-import pypy.translator.jvm.generator as jvmgen
-import pypy.translator.jvm.typesystem as jvmtype
+import pypy.translator.jvm.typesystem as jvm
from pypy.rpython.ootypesystem import ootype, rclass
class BaseDumpMethod(object):
@@ -19,7 +18,7 @@
self.clsobj = clsobj
self.name = "toString"
self.jargtypes = [clsobj]
- self.jrettype = jvmtype.jString
+ self.jrettype = jvm.jString
def _print_field_value(self, fieldnm, FIELDOOTY):
self.gen.load_this_ptr()
@@ -27,21 +26,21 @@
fieldobj.load(self.gen)
dumpmethod = self.db.toString_method_for_ootype(FIELDOOTY)
self.gen.emit(dumpmethod)
- self.gen.emit(jvmgen.STRINGBUILDERAPPEND)
+ self.gen.emit(jvm.STRINGBUILDERAPPEND)
def _print(self, str):
self.gen.load_string(str)
- self.gen.emit(jvmgen.STRINGBUILDERAPPEND)
+ self.gen.emit(jvm.STRINGBUILDERAPPEND)
def render(self, gen):
self.gen = gen
gen.begin_function(
self.name, (), self.jargtypes, self.jrettype, static=False)
- gen.new_with_jtype(jvmtype.jStringBuilder)
+ gen.new_with_jtype(jvm.jStringBuilder)
self._render_guts(gen)
- gen.emit(jvmgen.OBJTOSTRING)
- gen.emit(jvmgen.RETURN.for_type(jvmtype.jString))
+ gen.emit(jvm.OBJTOSTRING)
+ gen.emit(jvm.RETURN.for_type(jvm.jString))
gen.end_function()
self.gen = None
@@ -117,8 +116,8 @@
self.OOCLASS = OOCLASS
self.clsobj = clsobj
self.name = "equals"
- self.jargtypes = [clsobj, jvmtype.jObject]
- self.jrettype = jvmtype.jBool
+ self.jargtypes = [clsobj, jvm.jObject]
+ self.jrettype = jvm.jBool
def render(self, gen):
self.gen = gen
@@ -156,10 +155,10 @@
# Return true or false as appropriate
gen.push_primitive_constant(ootype.Bool, True)
- gen.return_val(jvmtype.jBool)
+ gen.return_val(jvm.jBool)
gen.mark(unequal_lbl)
gen.push_primitive_constant(ootype.Bool, False)
- gen.return_val(jvmtype.jBool)
+ gen.return_val(jvm.jBool)
gen.end_function()
@@ -171,7 +170,7 @@
self.clsobj = clsobj
self.name = "hashCode"
self.jargtypes = [clsobj]
- self.jrettype = jvmtype.jInt
+ self.jrettype = jvm.jInt
def render(self, gen):
self.gen = gen
@@ -194,10 +193,10 @@
gen.hash_value(FIELDOOTY)
# XOR that with the main hash
- gen.emit(jvmgen.IXOR)
+ gen.emit(jvm.IXOR)
# Return the final hash
- gen.return_val(jvmtype.jInt)
+ gen.return_val(jvm.jInt)
gen.end_function()
Modified: pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/node.py
==============================================================================
--- pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/node.py (original)
+++ pypy/branch/fixed-list-ootype-2/pypy/translator/jvm/node.py Fri Apr 4 13:18:57 2008
@@ -39,8 +39,7 @@
from pypy.translator.jvm.cmpopcodes import \
can_branch_directly, branch_if
-import py
-import pypy.translator.jvm.generator as jvmgen
+import pypy.translator.jvm.typesystem as jvm
import pypy.translator.jvm.typesystem as jvmtype
from pypy.translator.jvm.log import log
@@ -86,14 +85,14 @@
# XXX --- perhaps this table would be better placed in typesystem.py
# so as to constrain the knowledge of lltype and ootype
_type_conversion_methods = {
- ootype.Signed:jvmgen.PYPYSTRTOINT,
- ootype.Unsigned:jvmgen.PYPYSTRTOUINT,
- lltype.SignedLongLong:jvmgen.PYPYSTRTOLONG,
- lltype.UnsignedLongLong:jvmgen.PYPYSTRTOULONG,
- ootype.Bool:jvmgen.PYPYSTRTOBOOL,
- ootype.Float:jvmgen.PYPYSTRTODOUBLE,
- ootype.Char:jvmgen.PYPYSTRTOCHAR,
- ootype.UniChar:jvmgen.PYPYSTRTOCHAR,
+ ootype.Signed:jvm.PYPYSTRTOINT,
+ ootype.Unsigned:jvm.PYPYSTRTOUINT,
+ lltype.SignedLongLong:jvm.PYPYSTRTOLONG,
+ lltype.UnsignedLongLong:jvm.PYPYSTRTOULONG,
+ ootype.Bool:jvm.PYPYSTRTOBOOL,
+ ootype.Float:jvm.PYPYSTRTODOUBLE,
+ ootype.Char:jvm.PYPYSTRTOCHAR,
+ ootype.UniChar:jvm.PYPYSTRTOCHAR,
ootype.String:None
}
@@ -109,14 +108,13 @@
#
# 2. Run the initialization method for the constant class.
#
- gen.begin_function(
- '<clinit>', (), [], jVoid, static=True)
- gen.emit(jvmgen.NEW, jPyPy)
- gen.emit(jvmgen.DUP)
+ gen.begin_function('<clinit>', (), [], jVoid, static=True)
+ gen.emit(jvm.NEW, jPyPy)
+ gen.emit(jvm.DUP)
gen.new_with_jtype(gen.db.jInterlinkImplementation)
- gen.emit(jvmgen.DUP)
+ gen.emit(jvm.DUP)
gen.db.interlink_field.store(gen)
- gen.emit(jvmgen.Method.c(jPyPy, [jPyPyInterlink]))
+ gen.emit(jvm.Method.c(jPyPy, [jPyPyInterlink]))
gen.db.pypy_field.store(gen)
gen.db.constant_generator.runtime_init(gen)
gen.return_val(jVoid)
@@ -143,7 +141,7 @@
conv = self._type_conversion_methods[arg.concretetype]
if conv: gen.push_pypy()
gen.load_jvm_var(jStringArray, 0)
- gen.emit(jvmgen.ICONST, i)
+ gen.emit(jvm.ICONST, i)
gen.load_from_array(jString)
if conv: gen.emit(conv)
else:
@@ -151,9 +149,9 @@
# python method expects
arg0 = self.graph.getargs()[0]
assert isinstance(arg0.concretetype, ootype.List), str(arg0.concretetype)
- assert arg0.concretetype._ITEMTYPE is ootype.String
+ assert arg0.concretetype.ITEM is ootype.String
gen.load_jvm_var(jStringArray, 0)
- gen.emit(jvmgen.PYPYARRAYTOLIST)
+ gen.emit(jvm.PYPYARRAYTOLIST)
# Generate a call to this method
gen.emit(self.db.pending_function(self.graph))
@@ -171,13 +169,13 @@
gen.add_comment('Invoking dump method for result of type '
+str(RESOOTYPE))
gen.emit(dumpmethod) # generate the string
- gen.emit(jvmgen.PYPYDUMP) # dump to stdout
+ gen.emit(jvm.PYPYDUMP) # dump to stdout
gen.goto(done_printing)
gen.end_try()
jexc = self.db.exception_root_object()
gen.begin_catch(jexc)
- gen.emit(jvmgen.PYPYDUMPEXCWRAPPER) # dumps to stdout
+ gen.emit(jvm.PYPYDUMPEXCWRAPPER) # dumps to stdout
gen.end_catch()
gen.mark(done_printing)
@@ -198,12 +196,12 @@
name = None
def render(self, gen):
- """ Uses the gen argument, a jvmgen.Generator, to create the
+ """ Uses the gen argument, a jvm.Generator, to create the
appropriate JVM assembly for this method. """
raise NotImplementedError
def method(self):
- """ Returns a jvmgen.Method object that would allow this
+ """ Returns a jvm.Method object that would allow this
function to be invoked. """
raise NotImplementedError
@@ -272,12 +270,12 @@
return self.generator.unique_label(prefix)
def method(self):
- """ Returns a jvmgen.Method that can invoke this function """
+ """ Returns a jvm.Method that can invoke this function """
if not self.is_method:
- ctor = jvmgen.Method.s
+ ctor = jvm.Method.s
startidx = 0
else:
- ctor = jvmgen.Method.v
+ ctor = jvm.Method.v
startidx = 1
return ctor(self.classty, self.name,
self.jargtypes[startidx:], self.jrettype)
@@ -359,11 +357,11 @@
# exception to be caught by the normal handlers.
self.ilasm.begin_catch(jexcty)
self.ilasm.push_interlink()
- interlink_method = jvmgen.Method.v(
+ interlink_method = jvm.Method.v(
jPyPyInterlink, "throw"+pyexccls.__name__, [], jVoid)
self.ilasm.emit(interlink_method)
- self.ilasm.emit(jvmgen.ACONST_NULL)
- self.ilasm.emit(jvmgen.ATHROW)
+ self.ilasm.emit(jvm.ACONST_NULL) # "inform" the verifier...
+ self.ilasm.emit(jvm.ATHROW) # ...that we throw here
self.ilasm.end_try()
def begin_catch(self, llexitcase):
@@ -386,7 +384,7 @@
else:
# the exception value is on the stack, store it in the proper place
if isinstance(link.last_exception, flowmodel.Variable):
- self.ilasm.emit(jvmgen.DUP)
+ self.ilasm.emit(jvm.DUP)
self.ilasm.store(link.last_exc_value)
fld = self.db.lltype_to_cts(rclass.OBJECT).lookup_field('meta')
self.ilasm.emit(fld)
@@ -517,9 +515,9 @@
def _trace(self, str, writeline=False):
if writeline:
str += '\n'
- jvmgen.SYSTEMERR.load(self.generator)
+ jvm.SYSTEMERR.load(self.generator)
self.generator.load_string(str)
- jvmgen.PRINTSTREAMPRINTSTR.invoke(self.generator)
+ jvm.PRINTSTREAMPRINTSTR.invoke(self.generator)
def _is_printable(self, res):
@@ -554,10 +552,10 @@
res.concretetype)
self._trace(" "+prompt+": ")
- self.generator.emit(jvmgen.SYSTEMERR)
+ self.generator.emit(jvm.SYSTEMERR)
self.generator.load(res)
self.generator.emit(jmethod)
- self.generator.emit(jvmgen.PRINTSTREAMPRINTSTR)
+ self.generator.emit(jvm.PRINTSTREAMPRINTSTR)
self._trace("\n")
def _trace_enabled(self):
@@ -596,7 +594,7 @@
self.java_return_type = jrettype
self.dump_method = Constan