[pypy-svn] r34839 - in pypy/dist/pypy: jit/timeshifter jit/timeshifter/test lang/automata rpython rpython/lltypesystem
arigo at codespeak.net
arigo at codespeak.net
Tue Nov 21 19:10:01 CET 2006
Author: arigo
Date: Tue Nov 21 19:09:56 2006
New Revision: 34839
Modified:
pypy/dist/pypy/jit/timeshifter/oop.py
pypy/dist/pypy/jit/timeshifter/test/test_portal.py
pypy/dist/pypy/jit/timeshifter/transform.py
pypy/dist/pypy/jit/timeshifter/vdict.py
pypy/dist/pypy/lang/automata/dfa.py
pypy/dist/pypy/rpython/annlowlevel.py
pypy/dist/pypy/rpython/lltypesystem/rdict.py
pypy/dist/pypy/rpython/rbuiltin.py
Log:
(pedronis, arre, arigo)
A new DFA test, this time with a recognizer main loop that's quite of
close to the original.
Modified: pypy/dist/pypy/jit/timeshifter/oop.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/oop.py (original)
+++ pypy/dist/pypy/jit/timeshifter/oop.py Tue Nov 21 19:09:56 2006
@@ -89,7 +89,7 @@
ARGS = FUNCTYPE.ARGS
argpos = unrolling_iterable(enumerate(self.argpositions))
- def do_call(rgenop, argboxes):
+ def do_call(jitstate, argboxes):
args = (None,)*nb_args
for i, pos in argpos:
if pos >= 0:
@@ -99,8 +99,7 @@
result = fnptr(*args)
if FUNCTYPE.RESULT == lltype.Void:
return None
- gv_result = rgenop.genconst(result)
- return redboxbuilder(result_kind, gv_result)
+ return rvalue.ll_fromvalue(jitstate, result)
self.do_call = do_call
@@ -117,7 +116,7 @@
fold &= gv_arg.is_const
if fold:
try:
- return self.do_call(builder.rgenop, argboxes)
+ return self.do_call(jitstate, argboxes)
except Exception, e:
jitstate.residual_exception(e)
return self.errorbox
Modified: pypy/dist/pypy/jit/timeshifter/test/test_portal.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_portal.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_portal.py Tue Nov 21 19:09:56 2006
@@ -3,6 +3,7 @@
from pypy.jit.timeshifter.test.test_timeshift import hannotate, getargtypes
from pypy.jit.timeshifter.hrtyper import HintRTyper
from pypy.jit.timeshifter.test.test_timeshift import P_NOVIRTUAL
+from pypy.jit.timeshifter.test.test_vlist import P_OOPSPEC
from pypy.rpython.llinterp import LLInterpreter
from pypy.objspace.flow.model import checkgraph, summary
from pypy.rlib.objectmodel import hint
@@ -171,6 +172,21 @@
res = self.timeshift_from_portal(main, recognizeparts, [1, 0], policy=P_NOVIRTUAL)
assert not res
+ def test_dfa_compile3(self):
+ from pypy.lang.automata.dfa import getautomaton, recognize3
+ def main(gets):
+ auto = getautomaton()
+ s = ["aaaaaaaaaab", "aaaa"][gets]
+ return recognize3(auto, s)
+
+ res = self.timeshift_from_portal(main, recognize3, [0],
+ policy=P_OOPSPEC)
+ assert res
+
+ res = self.timeshift_from_portal(main, recognize3, [1],
+ policy=P_OOPSPEC)
+ assert not res
+
def test_method_call_promote(self):
class Base(object):
pass
Modified: pypy/dist/pypy/jit/timeshifter/transform.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/transform.py (original)
+++ pypy/dist/pypy/jit/timeshifter/transform.py Tue Nov 21 19:09:56 2006
@@ -442,7 +442,8 @@
if spaceop.opname == 'direct_call':
c_func = spaceop.args[0]
fnobj = c_func.value._obj
- if hasattr(fnobj._callable, 'oopspec'):
+ if (hasattr(fnobj._callable, 'oopspec') and
+ getattr(self.hannotator.policy, 'oopspec', False)):
return 'oopspec'
for v in spaceop.args:
Modified: pypy/dist/pypy/jit/timeshifter/vdict.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/vdict.py (original)
+++ pypy/dist/pypy/jit/timeshifter/vdict.py Tue Nov 21 19:09:56 2006
@@ -253,3 +253,17 @@
return oopspecdesc.residual_call(jitstate, [selfbox, keybox],
deepfrozen=deepfrozen)
oop_dict_getitem.couldfold = True
+
+def oop_dict_contains(jitstate, oopspecdesc, deepfrozen, selfbox, keybox):
+ content = selfbox.content
+ if isinstance(content, AbstractVirtualDict) and keybox.is_constant():
+ try:
+ content.getitem(keybox)
+ res = True
+ except KeyError:
+ res = False
+ return rvalue.ll_fromvalue(jitstate, res)
+ else:
+ return oopspecdesc.residual_call(jitstate, [selfbox, keybox],
+ deepfrozen=deepfrozen)
+oop_dict_contains.couldfold = True
Modified: pypy/dist/pypy/lang/automata/dfa.py
==============================================================================
--- pypy/dist/pypy/lang/automata/dfa.py (original)
+++ pypy/dist/pypy/lang/automata/dfa.py Tue Nov 21 19:09:56 2006
@@ -31,7 +31,7 @@
def __repr__(self):
from pprint import pformat
return "DFA%s" % (pformat(
- self.num_states, self.transitions, self.final_states))
+ (self.num_states, self.transitions, self.final_states)))
def getautomaton():
" simple example of handcrafted dfa "
@@ -130,3 +130,24 @@
res = hint(res, concrete=True)
res = hint(res, variable=True)
return res
+
+# a version of recognize() full of hints, but otherwise not too modified
+
+def recognize3(automaton, s):
+ automaton = hint(automaton, deepfreeze=True)
+ hint(automaton, concrete=True)
+ state = 0
+
+ index = 0
+ while index < len(s):
+ hint(None, global_merge_point=True)
+ char = s[index]
+ index += 1
+ char = hint(char, promote=True)
+ try:
+ state = automaton.get_transition(state, char)
+ except KeyError:
+ return False
+ state = hint(state, promote=True)
+
+ return state in automaton.final_states
Modified: pypy/dist/pypy/rpython/annlowlevel.py
==============================================================================
--- pypy/dist/pypy/rpython/annlowlevel.py (original)
+++ pypy/dist/pypy/rpython/annlowlevel.py Tue Nov 21 19:09:56 2006
@@ -349,6 +349,7 @@
def cast_instance_to_base_ptr(instance):
return cast_object_to_ptr(base_ptr_lltype(), instance)
+cast_instance_to_base_ptr._annspecialcase_ = 'specialize:argtype(0)'
def base_ptr_lltype():
from pypy.rpython.lltypesystem.rclass import OBJECTPTR
Modified: pypy/dist/pypy/rpython/lltypesystem/rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rdict.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/rdict.py Tue Nov 21 19:09:56 2006
@@ -735,3 +735,4 @@
def ll_contains(d, key):
entry = ll_dict_lookup(d, key, d.keyhash(key))
return entry.valid()
+ll_contains.oopspec = 'dict.contains(d, key)'
Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/rbuiltin.py Tue Nov 21 19:09:56 2006
@@ -624,6 +624,7 @@
hints[key[2:]] = s_value.const
v = hop.inputarg(hop.args_r[0], arg=0)
c_hint = hop.inputconst(lltype.Void, hints)
+ hop.exception_cannot_occur()
return hop.genop('hint', [v, c_hint], resulttype=v.concretetype)
BUILTIN_TYPER[objectmodel.hint] = rtype_hint
More information about the Pypy-commit
mailing list