[pypy-svn] r20897 - in pypy/dist/pypy/jit: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Dec 8 14:58:19 CET 2005
Author: cfbolz
Date: Thu Dec 8 14:58:18 2005
New Revision: 20897
Modified:
pypy/dist/pypy/jit/llabstractinterp.py
pypy/dist/pypy/jit/test/test_llabstractinterp.py
Log:
(cfbolz; arigo, pedronis floating around)
Make the first arraytest pass by adding some operations
Modified: pypy/dist/pypy/jit/llabstractinterp.py
==============================================================================
--- pypy/dist/pypy/jit/llabstractinterp.py (original)
+++ pypy/dist/pypy/jit/llabstractinterp.py Thu Dec 8 14:58:18 2005
@@ -288,6 +288,9 @@
self.residual_operations.append(op)
def residualize(self, op, args_a, constant_op=None):
+ RESULT = op.result.concretetype
+ if RESULT is lltype.Void:
+ return XXX_later
if constant_op:
a_result = self.constantfold(constant_op, args_a)
if a_result is not None:
@@ -313,6 +316,12 @@
def op_int_gt(self, op, a1, a2):
return self.residualize(op, [a1, a2], operator.gt)
+ def op_int_lt(self, op, a1, a2):
+ return self.residualize(op, [a1, a2], operator.lt)
+
+ def op_cast_char_to_int(self, op, a):
+ return self.residualize(op, [a], ord)
+
def op_same_as(self, op, a):
return a
@@ -343,22 +352,31 @@
return a_result
def op_getfield(self, op, a_ptr, a_attrname):
+ constant_op = None
T = a_ptr.getconcretetype().TO
- attrname = a_attrname.getvarorconst().value
- RESULT = getattr(T, attrname)
- if RESULT is lltype.Void:
- return XXX_later
v_ptr = a_ptr.getvarorconst()
if isinstance(v_ptr, Constant):
if T._hints.get('immutable', False):
- concreteresult = getattr(v_ptr.value, attrname)
- if isinstance(a_ptr, LLConcreteValue):
- a_result = LLConcreteValue(concreteresult)
- else:
- c_result = Constant(concreteresult)
- c_result.concretetype = lltype.typeOf(concreteresult)
- a_result = LLRuntimeValue(c_result)
- return a_result
- a_result = LLRuntimeValue(op.result)
- self.residual("getfield", [a_ptr, a_attrname], a_result)
- return a_result
+ constant_op = getattr
+ return self.residualize(op, [a_ptr, a_attrname], constant_op)
+ op_getsubstruct = op_getfield
+
+ def op_getarraysize(self, op, a_ptr):
+ constant_op = None
+ T = a_ptr.getconcretetype().TO
+ v_ptr = a_ptr.getvarorconst()
+ if isinstance(v_ptr, Constant):
+ if T._hints.get('immutable', False):
+ constant_op = len
+ return self.residualize(op, [a_ptr], constant_op)
+
+ def op_getarrayitem(self, op, a_ptr, a_index):
+ constant_op = None
+ T = a_ptr.getconcretetype().TO
+ v_ptr = a_ptr.getvarorconst()
+ if isinstance(v_ptr, Constant):
+ if T._hints.get('immutable', False):
+ constant_op = operator.getitem
+ return self.residualize(op, [a_ptr, a_index], constant_op)
+
+
Modified: pypy/dist/pypy/jit/test/test_llabstractinterp.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_llabstractinterp.py (original)
+++ pypy/dist/pypy/jit/test/test_llabstractinterp.py Thu Dec 8 14:58:18 2005
@@ -153,3 +153,19 @@
return s.hello * s.world
graph2, insns = abstrinterp(ll_function, [s], [0])
assert insns == {}
+
+def test_simple_array():
+ A = lltype.Array(lltype.Char,
+ hints={'immutable': True})
+ S = lltype.GcStruct('str', ('chars', A),
+ hints={'immutable': True})
+ s = lltype.malloc(S, 11)
+ for i, c in enumerate("hello world"):
+ s.chars[i] = c
+ def ll_function(s, i, total):
+ while i < len(s.chars):
+ total += ord(s.chars[i])
+ i += 1
+ return total
+ graph2, insns = abstrinterp(ll_function, [s, 0, 0], [0, 1, 2])
+ assert insns == {}
More information about the Pypy-commit
mailing list