[pypy-svn] r50573 - in pypy/branch/fixed-list-ootype/pypy/translator: js oosupport
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Jan 14 00:33:17 CET 2008
Author: cfbolz
Date: Mon Jan 14 00:33:16 2008
New Revision: 50573
Modified:
pypy/branch/fixed-list-ootype/pypy/translator/js/asmgen.py
pypy/branch/fixed-list-ootype/pypy/translator/js/database.py
pypy/branch/fixed-list-ootype/pypy/translator/js/function.py
pypy/branch/fixed-list-ootype/pypy/translator/js/jsbuiltin.py
pypy/branch/fixed-list-ootype/pypy/translator/js/jts.py
pypy/branch/fixed-list-ootype/pypy/translator/js/opcodes.py
pypy/branch/fixed-list-ootype/pypy/translator/oosupport/metavm.py
Log:
add array support to the js backend
Modified: pypy/branch/fixed-list-ootype/pypy/translator/js/asmgen.py
==============================================================================
--- pypy/branch/fixed-list-ootype/pypy/translator/js/asmgen.py (original)
+++ pypy/branch/fixed-list-ootype/pypy/translator/js/asmgen.py Mon Jan 14 00:33:16 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/pypy/translator/js/database.py
==============================================================================
--- pypy/branch/fixed-list-ootype/pypy/translator/js/database.py (original)
+++ pypy/branch/fixed-list-ootype/pypy/translator/js/database.py Mon Jan 14 00:33:16 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/pypy/translator/js/function.py
==============================================================================
--- pypy/branch/fixed-list-ootype/pypy/translator/js/function.py (original)
+++ pypy/branch/fixed-list-ootype/pypy/translator/js/function.py Mon Jan 14 00:33:16 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/pypy/translator/js/jsbuiltin.py
==============================================================================
--- pypy/branch/fixed-list-ootype/pypy/translator/js/jsbuiltin.py (original)
+++ pypy/branch/fixed-list-ootype/pypy/translator/js/jsbuiltin.py Mon Jan 14 00:33:16 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/pypy/translator/js/jts.py
==============================================================================
--- pypy/branch/fixed-list-ootype/pypy/translator/js/jts.py (original)
+++ pypy/branch/fixed-list-ootype/pypy/translator/js/jts.py Mon Jan 14 00:33:16 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):
Modified: pypy/branch/fixed-list-ootype/pypy/translator/js/opcodes.py
==============================================================================
--- pypy/branch/fixed-list-ootype/pypy/translator/js/opcodes.py (original)
+++ pypy/branch/fixed-list-ootype/pypy/translator/js/opcodes.py Mon Jan 14 00:33:16 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/pypy/translator/oosupport/metavm.py
==============================================================================
--- pypy/branch/fixed-list-ootype/pypy/translator/oosupport/metavm.py (original)
+++ pypy/branch/fixed-list-ootype/pypy/translator/oosupport/metavm.py Mon Jan 14 00:33:16 2008
@@ -214,6 +214,13 @@
Stack: ... -> newobj, ... """
raise NotImplementedError
+ def oonewarray(self, TYPE, length):
+ """ Creates a new array of the given type with the given length.
+
+ Stack: ... -> newobj, ... """
+ raise NotImplementedError
+
+
def push_null(self, TYPE):
""" Push a NULL value onto the stack (the NULL value represents
a pointer to an instance of OOType TYPE, if it matters to you). """
@@ -413,6 +420,14 @@
return
generator.new(op.args[0].value)
+
+class _OONewArray(MicroInstruction):
+ def render(self, generator, op):
+ if op.args[0].value is ootype.Void:
+ return
+ generator.oonewarray(op.args[0].value, op.args[1])
+
+
class BranchUnconditionally(MicroInstruction):
def __init__(self, label):
self.label = label
@@ -497,6 +512,7 @@
generator.isinstance(class_name)
New = _New()
+OONewArray = _OONewArray()
PushAllArgs = _PushAllArgs()
StoreResult = _StoreResult()
More information about the Pypy-commit
mailing list