[pypy-svn] r62589 - in pypy/branch/pyjitpl5/pypy/jit/backend/llgraph: . test
arigo at codespeak.net
arigo at codespeak.net
Thu Mar 5 16:23:32 CET 2009
Author: arigo
Date: Thu Mar 5 16:23:32 2009
New Revision: 62589
Modified:
pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/test/test_llgraph.py
Log:
getarrayitem. Phew, will take a while.
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py Thu Mar 5 16:23:32 2009
@@ -440,19 +440,10 @@
return res
def as_int(self, x):
- TP = lltype.typeOf(x)
- if isinstance(TP, lltype.Ptr):
- assert TP.TO._gckind == 'raw'
- return cast_adr_to_int(self.memocast, llmemory.cast_ptr_to_adr(x))
- if TP == llmemory.Address:
- return cast_adr_to_int(self.memocast, x)
- return lltype.cast_primitive(lltype.Signed, x)
-
+ return cast_to_int(x, self.memocast)
+
def as_ptr(self, x):
- if isinstance(lltype.typeOf(x), lltype.Ptr):
- return lltype.cast_opaque_ptr(llmemory.GCREF, x)
- else:
- return x
+ return cast_to_ptr(x)
def log_progress(self):
count = sum(_stats.exec_counters.values())
@@ -460,6 +451,22 @@
log.trace('ran %d operations, %d jumps' % (count, count_jumps))
+def cast_to_int(x, memocast):
+ TP = lltype.typeOf(x)
+ if isinstance(TP, lltype.Ptr):
+ assert TP.TO._gckind == 'raw'
+ return cast_adr_to_int(memocast, llmemory.cast_ptr_to_adr(x))
+ if TP == llmemory.Address:
+ return cast_adr_to_int(memocast, x)
+ return lltype.cast_primitive(lltype.Signed, x)
+
+def cast_to_ptr(x):
+ if isinstance(lltype.typeOf(x), lltype.Ptr):
+ return lltype.cast_opaque_ptr(llmemory.GCREF, x)
+ else:
+ return x
+
+
def new_frame(memocast):
frame = Frame(memocast)
return _to_opaque(frame)
@@ -895,6 +902,14 @@
str = lltype.cast_opaque_ptr(lltype.Ptr(rstr.STR), string)
return ord(str.chars[index])
+def do_getarrayitem_gc_int(array, index, memocast):
+ array = array._obj.container
+ return cast_to_int(array.getitem(index), memocast)
+
+def do_getarrayitem_gc_ptr(array, index):
+ array = array._obj.container
+ return cast_to_ptr(array.getitem(index))
+
# ____________________________________________________________
@@ -979,3 +994,5 @@
setannotation(do_arraylen_gc, annmodel.SomeInteger())
setannotation(do_strlen, annmodel.SomeInteger())
setannotation(do_strgetitem, annmodel.SomeInteger())
+setannotation(do_getarrayitem_gc_int, annmodel.SomeInteger())
+setannotation(do_getarrayitem_gc_ptr, annmodel.SomePtr(llmemory.GCREF))
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py Thu Mar 5 16:23:32 2009
@@ -313,15 +313,25 @@
array = args[0].getptr_base()
return history.BoxInt(llimpl.do_arraylen_gc(array))
- def do_strlen(cpu, args):
+ def do_strlen(self, args):
string = args[0].getptr_base()
return history.BoxInt(llimpl.do_strlen(string))
- def do_strgetitem(cpu, args):
+ def do_strgetitem(self, args):
string = args[0].getptr_base()
index = args[1].getint()
return history.BoxInt(llimpl.do_strgetitem(string, index))
+ def do_getarrayitem_gc(self, args):
+ array = args[0].getptr_base()
+ arraydescr = args[1].getint()
+ index = args[2].getint()
+ if self.typefor(arraydescr) == 'ptr':
+ return history.BoxPtr(llimpl.do_getarrayitem_gc_ptr(array, index))
+ else:
+ return history.BoxInt(llimpl.do_getarrayitem_gc_int(array, index,
+ self.memo_cast))
+
class GuardFailed(object):
returns = False
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/test/test_llgraph.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/test/test_llgraph.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/test/test_llgraph.py Thu Mar 5 16:23:32 2009
@@ -157,13 +157,28 @@
def test_do_operations(self):
cpu = CPU(None)
#
- A = lltype.GcArray(lltype.Signed)
+ A = lltype.GcArray(lltype.Char)
+ descrbox_A = ConstInt(cpu.arraydescrof(A))
a = lltype.malloc(A, 5)
- descrbox = ConstInt(cpu.arraydescrof(A))
x = cpu.do_arraylen_gc(
- [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, a)), descrbox])
+ [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, a)), descrbox_A])
assert x.value == 5
#
+ a[2] = 'Y'
+ x = cpu.do_getarrayitem_gc(
+ [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, a)), descrbox_A,
+ BoxInt(2)])
+ assert x.value == ord('Y')
+ #
+ B = lltype.GcArray(lltype.Ptr(A))
+ descrbox_B = ConstInt(cpu.arraydescrof(B))
+ b = lltype.malloc(B, 4)
+ b[3] = a
+ x = cpu.do_getarrayitem_gc(
+ [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, b)), descrbox_B,
+ BoxInt(3)])
+ assert x.getptr(lltype.Ptr(A)) == a
+ #
s = rstr.mallocstr(6)
x = cpu.do_strlen(
[BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s))])
More information about the Pypy-commit
mailing list