From cfbolz at codespeak.net Fri Jun 1 01:18:59 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Fri, 1 Jun 2007 01:18:59 +0200 (CEST) Subject: [pypy-svn] r43952 - in pypy/dist/pypy/lang/prolog: builtin interpreter interpreter/test Message-ID: <20070531231859.1153080AE@code0.codespeak.net> Author: cfbolz Date: Fri Jun 1 01:18:58 2007 New Revision: 43952 Modified: pypy/dist/pypy/lang/prolog/builtin/allsolution.py pypy/dist/pypy/lang/prolog/builtin/exception.py pypy/dist/pypy/lang/prolog/builtin/formatting.py pypy/dist/pypy/lang/prolog/builtin/register.py pypy/dist/pypy/lang/prolog/builtin/termconstruction.py pypy/dist/pypy/lang/prolog/interpreter/engine.py pypy/dist/pypy/lang/prolog/interpreter/parsing.py pypy/dist/pypy/lang/prolog/interpreter/term.py pypy/dist/pypy/lang/prolog/interpreter/test/test_builtin.py pypy/dist/pypy/lang/prolog/interpreter/test/test_engine.py pypy/dist/pypy/lang/prolog/interpreter/test/test_unification.py pypy/dist/pypy/lang/prolog/interpreter/test/tool.py Log: refactor the way logic variables in the prolog interpreter are handled to be quite a bit simpler Modified: pypy/dist/pypy/lang/prolog/builtin/allsolution.py ============================================================================== --- pypy/dist/pypy/lang/prolog/builtin/allsolution.py (original) +++ pypy/dist/pypy/lang/prolog/builtin/allsolution.py Fri Jun 1 01:18:58 2007 @@ -26,8 +26,7 @@ for i in range(len(collector.found) - 1, -1, -1): copy = collector.found[i] d = {} - copy = copy.clone_compress_vars(d, engine.heap.maxvar()) - engine.heap.extend(len(d)) + copy = copy.copy(engine.heap, d) result = term.Term(".", [copy, result]) bag.unify(result, engine.heap) expose_builtin(impl_findall, "findall", unwrap_spec=['raw', 'callable', 'raw']) Modified: pypy/dist/pypy/lang/prolog/builtin/exception.py ============================================================================== --- pypy/dist/pypy/lang/prolog/builtin/exception.py (original) +++ pypy/dist/pypy/lang/prolog/builtin/exception.py Fri Jun 1 01:18:58 2007 @@ -17,8 +17,7 @@ exc_term = e.term.getvalue(engine.heap) engine.heap.revert(old_state) d = {} - exc_term = exc_term.clone_compress_vars(d, engine.heap.maxvar()) - engine.heap.extend(len(d)) + exc_term = exc_term.copy(engine.heap, d) try: impl_ground(engine, exc_term) except error.UnificationFailed: Modified: pypy/dist/pypy/lang/prolog/builtin/formatting.py ============================================================================== --- pypy/dist/pypy/lang/prolog/builtin/formatting.py (original) +++ pypy/dist/pypy/lang/prolog/builtin/formatting.py Fri Jun 1 01:18:58 2007 @@ -14,6 +14,7 @@ self.ignore_ops = ignore_ops self.curr_depth = 0 self._make_reverse_op_mapping() + self.var_to_number = {} def from_option_list(engine, options): # XXX add numbervars support @@ -76,8 +77,11 @@ return str(num.floatval) def format_var(self, var): - return "_G%s" % (var.index, ) - + try: + num = self.var_to_number[var] + except KeyError: + num = self.var_to_number[var] = len(self.var_to_number) + return "_G%s" % (num, ) def format_term_normally(self, term): return "%s(%s)" % (self.format_atom(term.name), Modified: pypy/dist/pypy/lang/prolog/builtin/register.py ============================================================================== --- pypy/dist/pypy/lang/prolog/builtin/register.py (original) +++ pypy/dist/pypy/lang/prolog/builtin/register.py Fri Jun 1 01:18:58 2007 @@ -1,5 +1,4 @@ import py -from pypy.lang.prolog.interpreter import arithmetic from pypy.lang.prolog.interpreter.parsing import parse_file, TermBuilder from pypy.lang.prolog.interpreter import engine, helper, term, error from pypy.lang.prolog.builtin import builtins, builtins_list @@ -66,7 +65,7 @@ elif spec == "atom": code.append(" %s = helper.unwrap_atom(%s)" % (varname, varname)) elif spec == "arithmetic": - code.append(" %s = arithmetic.eval_arithmetic(engine, %s)" % + code.append(" %s = %s.eval_arithmetic(engine)" % (varname, varname)) elif spec == "list": code.append(" %s = helper.unwrap_list(%s)" % (varname, varname)) Modified: pypy/dist/pypy/lang/prolog/builtin/termconstruction.py ============================================================================== --- pypy/dist/pypy/lang/prolog/builtin/termconstruction.py (original) +++ pypy/dist/pypy/lang/prolog/builtin/termconstruction.py Fri Jun 1 01:18:58 2007 @@ -15,8 +15,6 @@ elif isinstance(t, term.Var): if isinstance(functor, term.Var): error.throw_instantiation_error() - elif isinstance(functor, term.Var): - error.throw_instantiation_error() a = helper.unwrap_int(arity) if a < 0: error.throw_domain_error("not_less_than_zero", arity) @@ -26,11 +24,8 @@ t.unify(helper.ensure_atomic(functor), engine.heap) else: name = helper.unwrap_atom(functor) - start = engine.heap.needed_vars - engine.heap.extend(a) t.unify( - term.Term(name, - [term.Var(i) for i in range(start, start + a)]), + term.Term(name, [term.Var() for i in range(a)]), engine.heap) expose_builtin(impl_functor, "functor", unwrap_spec=["obj", "obj", "obj"]) @@ -92,8 +87,7 @@ def impl_copy_term(engine, interm, outterm): d = {} - copy = interm.clone_compress_vars(d, engine.heap.maxvar()) - engine.heap.extend(len(d)) + copy = interm.copy(engine.heap, d) outterm.unify(copy, engine.heap) expose_builtin(impl_copy_term, "copy_term", unwrap_spec=["obj", "obj"]) Modified: pypy/dist/pypy/lang/prolog/interpreter/engine.py ============================================================================== --- pypy/dist/pypy/lang/prolog/interpreter/engine.py (original) +++ pypy/dist/pypy/lang/prolog/interpreter/engine.py Fri Jun 1 01:18:58 2007 @@ -37,76 +37,36 @@ self.scope_active = False return self.continuation.call(engine, choice_point=False) -START_NUMBER_OF_VARS = 4096 - - class Heap(object): def __init__(self): - self.vars = [None] * START_NUMBER_OF_VARS self.trail = [] - self.needed_vars = 0 - self.last_branch = 0 def reset(self): - self.vars = [None] * len(self.vars) self.trail = [] self.last_branch = 0 - def clear(self, length): - l = max(START_NUMBER_OF_VARS, length) - self.vars = [None] * l - self.needed_vars = length - self.last_branch = length - self.trail = [] - - def getvar(self, index): - return self.vars[index] - - def setvar(self, index, val): - oldval = self.vars[index] - self.vars[index] = val - # only trail for variables that have a chance to get restored - # on the last choice point - if index < self.last_branch and oldval is not val: - self.trail.append((index, oldval)) + def add_trail(self, var): + self.trail.append((var, var.binding)) def branch(self): - old_last_branch = self.last_branch - self.last_branch = self.needed_vars - return len(self.trail), self.needed_vars, old_last_branch + return len(self.trail) def revert(self, state): - trails, length, old_last_branch = state - assert length == self.last_branch + trails = state for i in range(len(self.trail) - 1, trails - 1, -1): - index, val = self.trail[i] - if index >= length: - val = None - self.vars[index] = val - for i in range(length, self.needed_vars): - self.vars[i] = None + var, val = self.trail[i] + var.binding = val del self.trail[trails:] - self.needed_vars = length def discard(self, state): - old_last_branch = state[2] - self.last_branch = old_last_branch - - def extend(self, numvars): - if numvars: - self.needed_vars += numvars - newvars = max(0, numvars - (len(self.vars) - self.needed_vars)) - if newvars == 0: - return - self.vars.extend([None] * (2 * newvars)) # allocate a bit more - assert self.needed_vars <= len(self.vars) + pass #XXX for now def maxvar(self): + XXX return self.needed_vars def newvar(self): - result = Var.newvar(self.maxvar()) - self.extend(1) + result = Var(self) return result class LinkedRules(object): @@ -211,8 +171,6 @@ def run(self, query, continuation=DONOTHING): if not isinstance(query, Callable): error.throw_type_error("callable", query) - vars = query.get_max_var() + 1 - self.heap.clear(vars) try: return self.call(query, continuation, choice_point=True) except CutException, e: @@ -412,7 +370,7 @@ builder = TermBuilder() trees = parse_file(s, self.parser) terms = builder.build_many(trees) - return terms, builder.var_to_pos + return terms, builder.varname_to_var def getoperations(self): from pypy.lang.prolog.interpreter.parsing import default_operations Modified: pypy/dist/pypy/lang/prolog/interpreter/parsing.py ============================================================================== --- pypy/dist/pypy/lang/prolog/interpreter/parsing.py (original) +++ pypy/dist/pypy/lang/prolog/interpreter/parsing.py Fri Jun 1 01:18:58 2007 @@ -219,7 +219,7 @@ s = parser_query.parse(tokens, lazy=False) builder = TermBuilder() query = builder.build(s) - return query, builder.var_to_pos + return query, builder.varname_to_var class OrderTransformer(object): def transform(self, node): @@ -271,8 +271,7 @@ class TermBuilder(RPythonVisitor): def __init__(self): - self.var_to_pos = {} - self.freevar = 0 + self.varname_to_var = {} def build(self, s): "NOT_RPYTHON" @@ -294,8 +293,7 @@ return self.visit(s.children[0]) def build_fact(self, node): - self.var_to_pos = {} - self.freevar = 0 + self.varname_to_var = {} return self.visit(node.children[0]) def visit(self, node): @@ -355,14 +353,11 @@ from pypy.lang.prolog.interpreter.term import Var varname = node.additional_info if varname == "_": - pos = self.freevar - self.freevar += 1 - return Var.newvar(pos) - if varname in self.var_to_pos: - return self.var_to_pos[varname] - res = Var.newvar(self.freevar) - self.freevar += 1 - self.var_to_pos[varname] = res + return Var() + if varname in self.varname_to_var: + return self.varname_to_var[varname] + res = Var() + self.varname_to_var[varname] = res return res def visit_NUMBER(self, node): Modified: pypy/dist/pypy/lang/prolog/interpreter/term.py ============================================================================== --- pypy/dist/pypy/lang/prolog/interpreter/term.py (original) +++ pypy/dist/pypy/lang/prolog/interpreter/term.py Fri Jun 1 01:18:58 2007 @@ -36,18 +36,12 @@ def dereference(self, heap): raise NotImplementedError("abstract base class") - def get_max_var(self): - return -1 - def copy(self, heap, memo): raise NotImplementedError("abstract base class") def copy_and_unify(self, other, heap, memo): raise NotImplementedError("abstract base class") - def clone_compress_vars(self, vars_new_indexes, offset): - return self - def get_unify_hash(self, heap): # if two non-var objects return two different numbers # they must not be unifiable @@ -80,12 +74,11 @@ TAG = 0 STANDARD_ORDER = 0 - __slots__ = ('index', ) + __slots__ = ('binding', ) cache = {} - _immutable_ = True - def __init__(self, index): - self.index = index + def __init__(self, heap=None): + self.binding = None @specialize.arg(3) def unify(self, other, heap, occurs_check=False): @@ -99,16 +92,16 @@ elif occurs_check and other.contains_var(self, heap): raise UnificationFailed() else: - heap.setvar(self.index, other) + self.setvalue(other, heap) def dereference(self, heap): - next = heap.getvar(self.index) + next = self.binding if next is None: return self else: result = next.dereference(heap) # do path compression - heap.setvar(self.index, result) + self.setvalue(result, heap) return result def getvalue(self, heap): @@ -117,6 +110,10 @@ return res.getvalue(heap) return res + def setvalue(self, value, heap): + heap.add_trail(self) + self.binding = value + def copy(self, heap, memo): hint(self, concrete=True) try: @@ -137,17 +134,6 @@ seen_value.unify(other, heap) return seen_value - - def get_max_var(self): - return self.index - - def clone_compress_vars(self, vars_new_indexes, offset): - if self.index in vars_new_indexes: - return Var.newvar(vars_new_indexes[self.index]) - index = len(vars_new_indexes) + offset - vars_new_indexes[self.index] = index - return Var.newvar(index) - def get_unify_hash(self, heap): if heap is not None: self = self.dereference(heap) @@ -165,22 +151,12 @@ return False def __repr__(self): - return "Var(%s)" % (self.index, ) + return "Var(%s)" % (self.binding, ) def __eq__(self, other): # for testing - return (self.__class__ == other.__class__ and - self.index == other.index) - - @staticmethod - @purefunction - def newvar(index): - result = Var.cache.get(index, None) - if result is not None: - return result - Var.cache[index] = result = Var(index) - return result + return self is other def eval_arithmetic(self, engine): self = self.dereference(engine.heap) @@ -413,9 +389,6 @@ def _clone(obj, offset): return obj.clone(offset) -def _clone_compress_vars(obj, vars_new_indexes, offset): - return obj.clone_compress_vars(vars_new_indexes, offset) - def _getvalue(obj, heap): return obj.getvalue(heap) @@ -475,15 +448,6 @@ else: raise UnificationFailed - def get_max_var(self): - result = -1 - for subterm in self.args: - result = max(result, subterm.get_max_var()) - return result - - def clone_compress_vars(self, vars_new_indexes, offset): - return self._copy_term(_clone_compress_vars, vars_new_indexes, offset) - def getvalue(self, heap): return self._copy_term(_getvalue, heap) @@ -542,16 +506,13 @@ unify_hash = [] def __init__(self, head, body): from pypy.lang.prolog.interpreter import helper - d = {} - head = head.clone_compress_vars(d, 0) assert isinstance(head, Callable) self.head = head if body is not None: body = helper.ensure_callable(body) - self.body = body.clone_compress_vars(d, 0) + self.body = body else: self.body = None - self.numvars = len(d) self.signature = self.head.signature if isinstance(head, Term): self.unify_hash = [arg.get_unify_hash(None) for arg in head.args] @@ -611,7 +572,7 @@ return c if isinstance(obj1, Var): assert isinstance(obj2, Var) - return rcmp(obj1.index, obj2.index) + return rcmp(id(obj1), id(obj2)) if isinstance(obj1, Atom): assert isinstance(obj2, Atom) return rcmp(obj1.name, obj2.name) Modified: pypy/dist/pypy/lang/prolog/interpreter/test/test_builtin.py ============================================================================== --- pypy/dist/pypy/lang/prolog/interpreter/test/test_builtin.py (original) +++ pypy/dist/pypy/lang/prolog/interpreter/test/test_builtin.py Fri Jun 1 01:18:58 2007 @@ -105,12 +105,12 @@ assert_true("assertz(f(a, a)).", e) assert_true("A = a, asserta(h(A, A)).", e) f = assert_true("g(B, B).", e) - assert f.vars[0].name == "b" + assert f['B'].name == "b" f = assert_true("f(B, B).", e) - assert f.vars[0].name == "b" + assert f['B'].name == "b" assert_false("h(c, c).", e) f = assert_true("h(B, B).", e) - assert f.vars[0].name == "a" + assert f['B'].name == "a" def test_assert_logical_update_view(): e = get_engine(""" @@ -281,7 +281,7 @@ assert_false("between(12, 15, 16).") heaps = collect_all(Engine(), "between(1, 4, X).") assert len(heaps) == 4 - assert heaps[0].vars[0].num == 1 + assert heaps[0]['X'].num == 1 def test_is(): assert_true("5 is 1 + 1 + 1 + 1 + 1.") @@ -319,10 +319,12 @@ def test_standard_comparison(): assert_true("X = Y, f(X, Y, X, Y) == f(X, X, Y, Y).") assert_true("X = Y, f(X, Y, X, Z) \\== f(X, X, Y, Y).") - assert_true("X @< Y, X @=< X, X @=< Y, Y @> X.") + assert_true("""X \\== Y, ((X @< Y, X @=< X, X @=< Y, Y @> X); + (X @> Y, X @>= X, X @>= Y, Y @< X)).""") assert_true("'\\\\=='(f(X, Y), 12).") assert_true("X = f(a), Y = f(b), Y @> X.") + def test_atom_length(): assert_true("atom_length('abc', 3).") assert_true("atom_length('\\\\', 1).") Modified: pypy/dist/pypy/lang/prolog/interpreter/test/test_engine.py ============================================================================== --- pypy/dist/pypy/lang/prolog/interpreter/test/test_engine.py (original) +++ pypy/dist/pypy/lang/prolog/interpreter/test/test_engine.py Fri Jun 1 01:18:58 2007 @@ -1,6 +1,7 @@ import py from pypy.lang.prolog.interpreter.parsing import parse_file, TermBuilder from pypy.lang.prolog.interpreter.parsing import parse_query_term, get_engine +from pypy.lang.prolog.interpreter.parsing import get_query_and_vars from pypy.lang.prolog.interpreter.error import UnificationFailed, CatchableError from pypy.lang.prolog.interpreter.test.tool import collect_all, assert_true, assert_false from pypy.lang.prolog.interpreter.test.tool import prolog_raises @@ -9,8 +10,9 @@ e = get_engine(""" f(a). """) - e.run(parse_query_term("f(X).")) - assert e.heap.getvar(0).name == "a" + t, vars = get_query_and_vars("f(X).") + e.run(t) + assert vars['X'].dereference(e.heap).name == "a" def test_and(): e = get_engine(""" @@ -20,9 +22,9 @@ f(X, Z) :- g(X, Y), g(Y, Z). """) e.run(parse_query_term("f(a, c).")) - e.run(parse_query_term("f(X, c).")) - print e.heap.vars[:10] - assert e.heap.getvar(0).name == "a" + t, vars = get_query_and_vars("f(X, c).") + e.run(t) + assert vars['X'].dereference(e.heap).name == "a" def test_and_long(): e = get_engine(""" @@ -52,8 +54,9 @@ return "succ(%s)" % nstr(n - 1) e.run(parse_query_term("num(0).")) e.run(parse_query_term("num(succ(0)).")) - e.run(parse_query_term("num(X).")) - assert e.heap.getvar(0).num == 0 + t, vars = get_query_and_vars("num(X).") + e.run(t) + assert vars['X'].dereference(e.heap).num == 0 e.run(parse_query_term("add(0, 0, 0).")) py.test.raises(UnificationFailed, e.run, parse_query_term(""" add(0, 0, succ(0)).""")) @@ -88,8 +91,9 @@ g(a, a). f(X, Y, Z) :- (g(X, Z); g(X, Z); g(Z, Y)), a(Z). """) - e.run(parse_query_term("f(a, b, Z).")) - assert e.heap.getvar(0).name == "a" + t, vars = get_query_and_vars("f(a, b, Z).") + e.run(t) + assert vars['Z'].dereference(e.heap).name == "a" f = collect_all(e, "X = 1; X = 2.") assert len(f) == 2 @@ -127,9 +131,9 @@ """) heaps = collect_all(e, "g(X).") assert len(heaps) == 3 - assert heaps[0].getvar(0).name == "a" - assert heaps[1].getvar(0).name == "b" - assert heaps[2].getvar(0).name == "c" + assert heaps[0]['X'].name == "a" + assert heaps[1]['X'].name == "b" + assert heaps[2]['X'].name == "c" def test_cut(): e = get_engine(""" Modified: pypy/dist/pypy/lang/prolog/interpreter/test/test_unification.py ============================================================================== --- pypy/dist/pypy/lang/prolog/interpreter/test/test_unification.py (original) +++ pypy/dist/pypy/lang/prolog/interpreter/test/test_unification.py Fri Jun 1 01:18:58 2007 @@ -11,41 +11,35 @@ py.test.raises(UnificationFailed, "a.unify(Atom.newatom('xxx'), None)") def test_var(): - b = Var.newvar(0) + b = Var() heap = Heap() - heap.clear(1) b.unify(Atom.newatom("hallo"), heap) assert b.getvalue(heap).name == "hallo" - a = Var.newvar(0) - b = Var.newvar(1) - heap.clear(2) + a = Var() + b = Var() a.unify(b, heap) a.unify(Atom.newatom("hallo"), heap) assert a.getvalue(heap).name == "hallo" assert b.getvalue(heap).name == "hallo" def test_unify_var(): - b = Var.newvar(0) + b = Var() heap = Heap() - heap.clear(1) b.unify(b, heap) b.unify(Atom.newatom("hallo"), heap) py.test.raises(UnificationFailed, b.unify, Atom.newatom("bye"), heap) def test_recursive(): - b = Var.newvar(0) + b = Var() heap = Heap() - heap.clear(1) b.unify(Term("hallo", [b]), heap) - def test_term(): - X = Var.newvar(0) - Y = Var.newvar(1) + X = Var() + Y = Var() t1 = Term("f", [Atom.newatom("hallo"), X]) t2 = Term("f", [Y, Atom.newatom("HALLO")]) heap = Heap() - heap.clear(2) print t1, t2 t1.unify(t2, heap) assert X.getvalue(heap).name == "HALLO" @@ -61,9 +55,11 @@ def test_run(): e = Engine() e.add_rule(Term("f", [Atom.newatom("a"), Atom.newatom("b")])) - e.add_rule(Term("f", [Var.newvar(0), Var.newvar(0)])) - e.add_rule(Term(":-", [Term("f", [Var.newvar(0), Var.newvar(1)]), - Term("f", [Var.newvar(1), Var.newvar(0)])])) + X = Var() + Y = Var() + e.add_rule(Term("f", [X, X])) + e.add_rule(Term(":-", [Term("f", [X, Y]), + Term("f", [Y, X])])) X = e.heap.newvar() e.run(Term("f", [Atom.newatom("b"), X])) assert X.dereference(e.heap).name == "b" Modified: pypy/dist/pypy/lang/prolog/interpreter/test/tool.py ============================================================================== --- pypy/dist/pypy/lang/prolog/interpreter/test/tool.py (original) +++ pypy/dist/pypy/lang/prolog/interpreter/test/tool.py Fri Jun 1 01:18:58 2007 @@ -6,12 +6,11 @@ def assert_true(query, e=None): if e is None: e = Engine() - term = e.parse(query)[0][0] + terms, vars = e.parse(query) + term, = terms e.run(term) - f = Heap() - f.vars = e.heap.vars[:] - return f - + return dict([(name, var.dereference(e.heap)) + for name, var in vars.iteritems()]) def assert_false(query, e=None): if e is None: e = Engine() @@ -23,20 +22,20 @@ (query, exc), e) class CollectAllContinuation(Continuation): - def __init__(self): + def __init__(self, vars): self.heaps = [] + self.vars = vars def _call(self, engine): - f = Heap() - f.vars = engine.heap.vars[:] - self.heaps.append(f) -# import pdb; pdb.set_trace() + self.heaps.append(dict([(name, var.dereference(engine.heap)) + for name, var in self.vars.iteritems()])) print "restarting computation" raise UnificationFailed def collect_all(engine, s): - collector = CollectAllContinuation() - term = engine.parse(s)[0][0] + terms, vars = engine.parse(s) + term, = terms + collector = CollectAllContinuation(vars) py.test.raises(UnificationFailed, engine.run, term, collector) return collector.heaps From fijal at codespeak.net Fri Jun 1 04:09:13 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Fri, 1 Jun 2007 04:09:13 +0200 (CEST) Subject: [pypy-svn] r43953 - pypy/branch/kill-ctypes/pypy/rpython/module Message-ID: <20070601020913.D9BE580B0@code0.codespeak.net> Author: fijal Date: Fri Jun 1 04:09:12 2007 New Revision: 43953 Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py Log: We've got try: finally: in rpython, forgotten.. Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py Fri Jun 1 04:09:12 2007 @@ -49,17 +49,18 @@ def tcgetattr_llimpl(fd): c_struct = lltype.malloc(TERMIOSP.TO, flavor='raw') error = c_tcgetattr(fd, c_struct) - if error == -1: + try: + if error == -1: + raise termios_error(error, 'tcgetattr failed') + cc = [chr(c_struct.c_c_cc[i]) for i in range(NCCS)] + ispeed = c_cfgetispeed(c_struct) + ospeed = c_cfgetospeed(c_struct) + result = (intmask(c_struct.c_c_iflag), intmask(c_struct.c_c_oflag), + intmask(c_struct.c_c_cflag), intmask(c_struct.c_c_lflag), + intmask(ispeed), intmask(ospeed), cc) + return result + finally: lltype.free(c_struct, flavor='raw') - raise termios_error(error, 'tcgetattr failed') - cc = [chr(c_struct.c_c_cc[i]) for i in range(NCCS)] - ispeed = c_cfgetispeed(c_struct) - ospeed = c_cfgetospeed(c_struct) - result = (intmask(c_struct.c_c_iflag), intmask(c_struct.c_c_oflag), - intmask(c_struct.c_c_cflag), intmask(c_struct.c_c_lflag), - intmask(ispeed), intmask(ospeed), cc) - lltype.free(c_struct, flavor='raw') - return result register_external(termios.tcgetattr, [int], (int, int, int, int, int, int, [str]), llimpl=tcgetattr_llimpl, export_name='termios.tcgetattr') @@ -68,21 +69,20 @@ c_struct = lltype.malloc(TERMIOSP.TO, flavor='raw') c_struct.c_c_iflag, c_struct.c_c_oflag, c_struct.c_c_cflag, \ c_struct.c_c_lflag, ispeed, ospeed, cc = attributes - for i in range(NCCS): - c_struct.c_c_cc[i] = rffi.r_uchar(ord(cc[i])) - error = c_cfsetispeed(c_struct, ispeed) - if error == -1: - lltype.free(c_struct, flavor='raw') - raise termios_error(error, 'tcsetattr failed') - error = c_cfsetospeed(c_struct, ospeed) - if error == -1: - lltype.free(c_struct, flavor='raw') - raise termios_error(error, 'tcsetattr failed') - error = c_tcsetattr(fd, when, c_struct) - if error == -1: + try: + for i in range(NCCS): + c_struct.c_c_cc[i] = rffi.r_uchar(ord(cc[i])) + error = c_cfsetispeed(c_struct, ispeed) + if error == -1: + raise termios_error(error, 'tcsetattr failed') + error = c_cfsetospeed(c_struct, ospeed) + if error == -1: + raise termios_error(error, 'tcsetattr failed') + error = c_tcsetattr(fd, when, c_struct) + if error == -1: + raise termios_error(error, 'tcsetattr failed') + finally: lltype.free(c_struct, flavor='raw') - raise termios_error(error, 'tcsetattr failed') - lltype.free(c_struct, flavor='raw') r_uint = rffi.r_uint register_external(termios.tcsetattr, [int, int, (r_uint, r_uint, r_uint, From fijal at codespeak.net Fri Jun 1 07:47:33 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Fri, 1 Jun 2007 07:47:33 +0200 (CEST) Subject: [pypy-svn] r43964 - in pypy/branch/kill-ctypes/pypy/module/termios: . test Message-ID: <20070601054733.689AF80A8@code0.codespeak.net> Author: fijal Date: Fri Jun 1 07:47:33 2007 New Revision: 43964 Modified: pypy/branch/kill-ctypes/pypy/module/termios/interp_termios.py pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py Log: Fix a bug in termios module and a test Modified: pypy/branch/kill-ctypes/pypy/module/termios/interp_termios.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/termios/interp_termios.py (original) +++ pypy/branch/kill-ctypes/pypy/module/termios/interp_termios.py Fri Jun 1 07:47:33 2007 @@ -33,7 +33,8 @@ space.wrap(0), space.wrap(-1), space.wrap(1))) w_iflag, w_oflag, w_cflag, w_lflag, w_ispeed, w_ospeed = \ space.unpackiterable(tup_w) - cc = [space.str_w(c) for c in space.unpackiterable(w_cc)] + cc = [space.str_w(space.call_function(space.getattr(w_c, + space.wrap('__str__')))) for w_c in space.unpackiterable(w_cc)] tup = (space.int_w(w_iflag), space.int_w(w_oflag), space.int_w(w_cflag), space.int_w(w_lflag), space.int_w(w_ispeed), space.int_w(w_ospeed), cc) Modified: pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py (original) +++ pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py Fri Jun 1 07:47:33 2007 @@ -60,6 +60,17 @@ child = self.spawn(['--withmod-termios', str(f)]) child.expect('ok!') + def test_tcsetattr(self): + source = py.code.Source(""" + import termios + termios.tcsetattr(0, 1, [16640, 4, 191, 2608, 15, 15, ['\x03', '\x1c', '\x7f', '\x15', '\x04', 0, 1, '\x00', '\x11', '\x13', '\x1a', '\x00', '\x12', '\x0f', '\x17', '\x16', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00']]) + print 'ok!' + """) + f = udir.join("test_tcsetattr.py") + f.write(source) + child = self.spawn(['--withmod-termios', str(f)]) + child.expect('ok!') + class AppTestTermios(object): def setup_class(cls): cls.space = gettestobjspace(usemodules=['termios']) From fijal at codespeak.net Fri Jun 1 07:48:38 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Fri, 1 Jun 2007 07:48:38 +0200 (CEST) Subject: [pypy-svn] r43965 - in pypy/branch/kill-ctypes/pypy/rpython/lltypesystem: . test Message-ID: <20070601054838.0EED380A7@code0.codespeak.net> Author: fijal Date: Fri Jun 1 07:48:37 2007 New Revision: 43965 Modified: pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rffi.py Log: Add a possibility to map backwards from charp to str. There is still open question what to do with free, since RTyper is sometimes complaining Modified: pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py Fri Jun 1 07:48:37 2007 @@ -18,11 +18,12 @@ def lltype(self): return self.TP -def llexternal(name, args, result, sources=[], includes=[]): +def llexternal(name, args, result, sources=[], includes=[], libraries=[]): ext_type = lltype.FuncType(args, result) return lltype.functionptr(ext_type, name, external='C', sources=tuple(sources), - includes=tuple(includes)) + includes=tuple(includes), + libraries=tuple(libraries)) def setup(): """ creates necessary c-level types @@ -61,6 +62,7 @@ CCHARP = lltype.Ptr(lltype.Array(lltype.Char, hints={'nolength': True})) # various type mapping +# str -> char* def str2charp(s): """ str -> char* """ @@ -70,6 +72,16 @@ array[len(s)] = '\x00' return array +# char* -> str +# doesn't free char* +def charp2str(cp): + l = [] + i = 0 + while cp[i] != '\x00': + l.append(cp[i]) + i += 1 + return "".join(l) + # char** CCHARPP = lltype.Ptr(lltype.Array(CCHARP, hints={'nolength': True})) Modified: pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rffi.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rffi.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rffi.py Fri Jun 1 07:48:37 2007 @@ -1,5 +1,5 @@ -#import py +import py from pypy.rpython.lltypesystem.rffi import * from pypy.translator.c.test.test_genc import compile from pypy.rpython.lltypesystem.lltype import Signed, Ptr, Char, malloc @@ -51,6 +51,33 @@ xf = compile(f, [], backendopt=False) assert xf() == 3 +def test_string_reverse(): + c_source = py.code.Source(""" + #include + + char *f(char* arg) + { + char *ret; + ret = (char*)malloc(strlen(arg) + 1); + strcpy(ret, arg); + return ret; + } + """) + c_file = udir.join("stringrev.c") + c_file.write(c_source) + z = llexternal('f', [CCHARP], CCHARP, sources=[str(c_file)]) + + def f(): + s = str2charp("xxx") + l_res = z(s) + res = charp2str(l_res) + lltype.free(l_res, flavor='raw') + lltype.free(s, flavor='raw') + return len(res) + + xf = compile(f, [], backendopt=False) + assert xf(expected_extra_mallocs=-1) == 3 + def test_stringstar(): c_source = """ #include From fijal at codespeak.net Fri Jun 1 07:49:46 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Fri, 1 Jun 2007 07:49:46 +0200 (CEST) Subject: [pypy-svn] r43966 - in pypy/branch/kill-ctypes/pypy/module/_curses: . test Message-ID: <20070601054946.121DE80A6@code0.codespeak.net> Author: fijal Date: Fri Jun 1 07:49:45 2007 New Revision: 43966 Added: pypy/branch/kill-ctypes/pypy/module/_curses/ (props changed) pypy/branch/kill-ctypes/pypy/module/_curses/__init__.py pypy/branch/kill-ctypes/pypy/module/_curses/app_curses.py pypy/branch/kill-ctypes/pypy/module/_curses/fficurses.py pypy/branch/kill-ctypes/pypy/module/_curses/interp_curses.py pypy/branch/kill-ctypes/pypy/module/_curses/test/ (props changed) pypy/branch/kill-ctypes/pypy/module/_curses/test/__init__.py pypy/branch/kill-ctypes/pypy/module/_curses/test/test_curses.py Log: Add a dummy _curses module, just enough to run pyrepl. Still, there are major concerns about merging this branch: * storing annotations on __class__ of ExtFunc * termios exception hacks (annotation) * seems that lltype.free has some problems with exception_is_here() (fficurses.py/tigetstr_llimpl) * we_are_translated in interp_termios, which is ugly. Added: pypy/branch/kill-ctypes/pypy/module/_curses/__init__.py ============================================================================== --- (empty file) +++ pypy/branch/kill-ctypes/pypy/module/_curses/__init__.py Fri Jun 1 07:49:45 2007 @@ -0,0 +1,35 @@ + +from pypy.interpreter.mixedmodule import MixedModule +from pypy.module._curses import fficurses +from pypy.module._curses import interp_curses +from pypy.rlib.nonconst import NonConstant +import _curses + +class Module(MixedModule): + """ Low-level interface for curses module, + not meant to be used directly + """ + applevel_name = "_curses" + + appleveldefs = { + 'error' : 'app_curses.error', + } + + interpleveldefs = { + 'setupterm' : 'interp_curses.setupterm', + 'tigetstr' : 'interp_curses.tigetstr', + 'tparm' : 'interp_curses.tparm', + } + + def startup(self, space): + # XXX nasty annotation trick + try: + raise interp_curses.curses_error(NonConstant("xxx")) + except _curses.error, e: + pass + +import _curses +for i in dir(_curses): + val = getattr(_curses, i) + if i.isupper() and type(val) is int: + Module.interpleveldefs[i] = "space.wrap(%s)" % val Added: pypy/branch/kill-ctypes/pypy/module/_curses/app_curses.py ============================================================================== --- (empty file) +++ pypy/branch/kill-ctypes/pypy/module/_curses/app_curses.py Fri Jun 1 07:49:45 2007 @@ -0,0 +1,3 @@ + +class error(Exception): + pass Added: pypy/branch/kill-ctypes/pypy/module/_curses/fficurses.py ============================================================================== --- (empty file) +++ pypy/branch/kill-ctypes/pypy/module/_curses/fficurses.py Fri Jun 1 07:49:45 2007 @@ -0,0 +1,101 @@ + +""" The ffi for rpython, need to be imported for side effects +""" + +import sys +from pypy.rpython.lltypesystem import rffi +from pypy.rpython.lltypesystem import lltype +from pypy.rpython.extfunc import register_external +from pypy.rpython.extregistry import ExtRegistryEntry +from pypy.module._curses import interp_curses +from pypy.rpython.lltypesystem import llmemory + +# waaa... +includes = ['curses.h', 'term.h'] +libs = ['curses'] + +INT = rffi.INT +INTP = lltype.Ptr(lltype.Array(INT, hints={'nolength':True})) +c_setupterm = rffi.llexternal('setupterm', [rffi.CCHARP, INT, INTP], INT, + includes=includes, libraries=libs) +c_tigetstr = rffi.llexternal('tigetstr', [rffi.CCHARP], rffi.CCHARP, + includes=includes, libraries=libs) +c_tparm = rffi.llexternal('tparm', [rffi.CCHARP, INT, INT, INT, INT, INT, + INT, INT, INT, INT, INT], rffi.CCHARP, + includes=includes, libraries=libs) + +ERR = rffi.CConstant('ERR', INT) +OK = rffi.CConstant('OK', INT) + +def curses_setupterm(term, fd): + intp = lltype.malloc(INTP.TO, 1, flavor='raw') + err = c_setupterm(term, fd, intp) + try: + if err == ERR: + if intp[0] == 0: + msg = "setupterm: could not find terminal" + elif intp[0] == -1: + msg = "setupterm: could not find terminfo database" + else: + msg = "setupterm: unknown error" + raise interp_curses.curses_error(msg) + interp_curses.module_info.setupterm_called = True + finally: + lltype.free(intp, flavor='raw') + +def curses_setupterm_null_llimpl(fd): + curses_setupterm(lltype.nullptr(rffi.CCHARP.TO), fd) + +def curses_setupterm_llimpl(term, fd): + ll_s = rffi.str2charp(term) + try: + curses_setupterm(ll_s, fd) + finally: + lltype.free(ll_s, flavor='raw') + +register_external(interp_curses._curses_setupterm_null, + [int], llimpl=curses_setupterm_null_llimpl, + export_name='_curses.setupterm_null') +register_external(interp_curses._curses_setupterm, + [str, int], llimpl=curses_setupterm_llimpl, + export_name='_curses.setupterm') + +def check_setup_invoked(): + if not interp_curses.module_info.setupterm_called: + raise interp_curses.curses_error("must call (at least) setupterm() first") + +def tigetstr_llimpl(cap): + check_setup_invoked() + ll_cap = rffi.str2charp(cap) + try: + ll_res = c_tigetstr(ll_cap) + num = lltype.cast_ptr_to_int(ll_res) + if num == 0 or num == -1: + raise interp_curses.TermError() + res = rffi.charp2str(ll_res) + # XXX - how to avoid a problem with leaking stuff here??? + #lltype.free(ll_res, flavor='raw') + return res + finally: + lltype.free(ll_cap, flavor='raw') + +register_external(interp_curses._curses_tigetstr, [str], str, + export_name='_curses.tigetstr', llimpl=tigetstr_llimpl) + +def tparm_llimpl(s, args): + check_setup_invoked() + l = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + for i in range(min(len(args), 10)): + l[i] = args[i] + ll_s = rffi.str2charp(s) + # XXX nasty trick stolen from CPython + ll_res = c_tparm(ll_s, l[0], l[1], l[2], l[3], l[4], l[5], l[6], + l[7], l[8], l[9]) + lltype.free(ll_s, flavor='raw') + # XXX - how to make this happy? + # lltype.free(ll_res, flavor.raw) + return rffi.charp2str(ll_res) + +register_external(interp_curses._curses_tparm, [str, [int]], str, + export_name='_curses.tparm', llimpl=tparm_llimpl) + Added: pypy/branch/kill-ctypes/pypy/module/_curses/interp_curses.py ============================================================================== --- (empty file) +++ pypy/branch/kill-ctypes/pypy/module/_curses/interp_curses.py Fri Jun 1 07:49:45 2007 @@ -0,0 +1,77 @@ + +from pypy.interpreter.baseobjspace import ObjSpace, W_Root +from pypy.interpreter.error import OperationError + +import _curses + +class ModuleInfo: + def __init__(self): + self.setupterm_called = False + +module_info = ModuleInfo() + +class curses_error(_curses.error): + def __init__(self, msg): + self.args = [msg] + +def convert_error(space, error): + msg = error.args[0] + w_module = space.getbuiltinmodule('_curses') + w_exception_class = space.getattr(w_module, space.wrap('error')) + w_exception = space.call_function(w_exception_class, space.wrap(msg)) + return OperationError(w_exception_class, w_exception) + +def _curses_setupterm_null(fd): + # NOT_RPYTHON + _curses.setupterm(None, fd) + +def _curses_setupterm(termname, fd): + # NOT_RPYTHON + _curses.setupterm(termname, fd) + +def setupterm(space, w_termname=None, fd=-1): + if fd == -1: + w_stdout = space.getattr(space.getbuiltinmodule('sys'), + space.wrap('stdout')) + fd = space.int_w(space.call_function(space.getattr(w_stdout, + space.wrap('fileno')))) + try: + if space.is_w(w_termname, space.w_None) or w_termname is None: + _curses_setupterm_null(fd) + else: + _curses_setupterm(space.str_w(w_termname), fd) + except _curses.error, e: + raise convert_error(space, e) +setupterm.unwrap_spec = [ObjSpace, W_Root, int] + +class TermError(Exception): + pass + +def _curses_tigetstr(capname): + # NOT_RPYTHON + res = _curses.tigetstr(capname) + if res is None: + raise TermError + return res + +def _curses_tparm(s, args): + # NOT_RPYTHON + return _curses.tparm(s, *args) + +def tigetstr(space, capname): + try: + result = _curses_tigetstr(capname) + except TermError: + return space.w_None + except _curses.error, e: + raise convert_error(space, e) + return space.wrap(result) +tigetstr.unwrap_spec = [ObjSpace, str] + +def tparm(space, s, args_w): + args = [space.int_w(a) for a in args_w] + try: + return space.wrap(_curses_tparm(s, args)) + except _curses.error, e: + raise convert_error(space, e) +tparm.unwrap_spec = [ObjSpace, str, 'args_w'] Added: pypy/branch/kill-ctypes/pypy/module/_curses/test/__init__.py ============================================================================== Added: pypy/branch/kill-ctypes/pypy/module/_curses/test/test_curses.py ============================================================================== --- (empty file) +++ pypy/branch/kill-ctypes/pypy/module/_curses/test/test_curses.py Fri Jun 1 07:49:45 2007 @@ -0,0 +1,89 @@ + +from pypy.translator.c.test.test_genc import compile +from pypy.module._curses import interp_curses +from pypy.module._curses import fficurses +from pypy.conftest import gettestobjspace +from pypy.tool.autopath import pypydir +from pypy.tool.udir import udir +import py +import sys + +class AppTestCurses(object): + def setup_class(cls): + cls.space = gettestobjspace(usemodules=['_curses']) + + def test_tigetstr(self): + import _curses + _curses.setupterm() + assert _curses.tigetstr('cup') == '\x1b[%i%p1%d;%p2%dH' + + def test_tparm(self): + import _curses + _curses.setupterm() + assert _curses.tparm(_curses.tigetstr('cup'), 5, 3) == '\033[6;4H' + +class TestCurses(object): + """ We need to fork here, to prevent + the setup to be done + """ + def _spawn(self, *args, **kwds): + import pexpect + print 'SPAWN:', args, kwds + child = pexpect.spawn(*args, **kwds) + child.logfile = sys.stdout + return child + + def spawn(self, argv): + py_py = py.path.local(pypydir).join('bin', 'py.py') + return self._spawn(sys.executable, [str(py_py)] + argv) + + def setup_class(self): + try: + import pexpect + except ImportError: + py.test.skip('pexpect not found') + + def test_setupterm(self): + source = py.code.Source(""" + import _curses + try: + _curses.tigetstr('cup') + except _curses.error: + print 'ok!' + """) + f = udir.join("test_setupterm.py") + f.write(source) + child = self.spawn(['--withmod-_curses', str(f)]) + child.expect('ok!') + +# XXX probably we need to run all the stuff here in pexpect anyway... + +class TestCCurses(object): + """ Test compiled version + """ + def test_csetupterm(self): + def runs_setupterm(): + interp_curses._curses_setupterm_null(1) + + fn = compile(runs_setupterm, []) + fn() + + def test_ctgetstr(self): + def runs_ctgetstr(): + interp_curses._curses_setupterm("xterm", 1) + res = interp_curses._curses_tigetstr('cup') + assert res == '\x1b[%i%p1%d;%p2%dH' + + fn = compile(runs_ctgetstr, []) + fn() + + def test_ctparm(self): + def runs_tparm(): + interp_curses._curses_setupterm("xterm", 1) + cup = interp_curses._curses_tigetstr('cup') + res = interp_curses._curses_tparm(cup, [5, 3]) + assert res == '\033[6;4H' + + fn = compile(runs_tparm, []) + fn() + From niko at codespeak.net Fri Jun 1 12:20:40 2007 From: niko at codespeak.net (niko at codespeak.net) Date: Fri, 1 Jun 2007 12:20:40 +0200 (CEST) Subject: [pypy-svn] r43972 - in pypy/dist/pypy/translator/jvm: src/pypy test Message-ID: <20070601102040.4FA3A80A5@code0.codespeak.net> Author: niko Date: Fri Jun 1 12:20:39 2007 New Revision: 43972 Modified: pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java pypy/dist/pypy/translator/jvm/test/test_primitive.py Log: quickly implement ll_time_time Modified: pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java ============================================================================== --- pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java (original) +++ pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java Fri Jun 1 12:20:39 2007 @@ -485,6 +485,10 @@ // Primitive built-in functions public static double ll_time_clock() { + return System.currentTimeMillis()/1000; // XXX: processor time? + } + + public static double ll_time_time() { return System.currentTimeMillis()/1000; } Modified: pypy/dist/pypy/translator/jvm/test/test_primitive.py ============================================================================== --- pypy/dist/pypy/translator/jvm/test/test_primitive.py (original) +++ pypy/dist/pypy/translator/jvm/test/test_primitive.py Fri Jun 1 12:20:39 2007 @@ -7,9 +7,8 @@ class TestPrimitive(JvmTest): def test_time_time(self): - py.test.skip("ll_time_time is not implemented in jvm backend") -# def fn(): -# return time.time() -# t1 = self.interpret(fn, []) -# t2 = self.interpret(fn, []) -# assert t1 <= t2 + def fn(): + return time.time() + t1 = self.interpret(fn, []) + t2 = self.interpret(fn, []) + assert t1 <= t2 From niko at codespeak.net Fri Jun 1 13:30:06 2007 From: niko at codespeak.net (niko at codespeak.net) Date: Fri, 1 Jun 2007 13:30:06 +0200 (CEST) Subject: [pypy-svn] r43973 - pypy/dist/pypy/translator/jvm/src/pypy Message-ID: <20070601113006.EFB9680A7@code0.codespeak.net> Author: niko Date: Fri Jun 1 13:30:06 2007 New Revision: 43973 Modified: pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java Log: divide by 1000.0 not 1000 in an effort to avoid rounding errors Modified: pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java ============================================================================== --- pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java (original) +++ pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java Fri Jun 1 13:30:06 2007 @@ -485,11 +485,11 @@ // Primitive built-in functions public static double ll_time_clock() { - return System.currentTimeMillis()/1000; // XXX: processor time? + return System.currentTimeMillis()/1000.0; // XXX: processor time? } public static double ll_time_time() { - return System.currentTimeMillis()/1000; + return System.currentTimeMillis()/1000.0; } public static int ll_os_write(int fd, String text) { From santagada at codespeak.net Fri Jun 1 21:07:02 2007 From: santagada at codespeak.net (santagada at codespeak.net) Date: Fri, 1 Jun 2007 21:07:02 +0200 (CEST) Subject: [pypy-svn] r43978 - in pypy/dist/pypy/lang/js: . test Message-ID: <20070601190702.08A6E80AE@code0.codespeak.net> Author: santagada Date: Fri Jun 1 21:06:59 2007 New Revision: 43978 Modified: pypy/dist/pypy/lang/js/operations.py pypy/dist/pypy/lang/js/test/test_interp.py Log: implemented string comparisons for the logical ops, did some tests for it and then removed the static methods from the binary math ops Modified: pypy/dist/pypy/lang/js/operations.py ============================================================================== --- pypy/dist/pypy/lang/js/operations.py (original) +++ pypy/dist/pypy/lang/js/operations.py Fri Jun 1 21:06:59 2007 @@ -74,8 +74,6 @@ class BinaryOp(Expression): def __init__(self, pos, left, right): self.pos = pos - assert isinstance(left, Node) - assert isinstance(right, Node) self.left = left self.right = right @@ -109,7 +107,7 @@ class PropertyInit(BinaryOp): pass -class Array(ListOp): +class Array(ListOp): def eval(self, ctx): array = W_Array() for i in range(len(self.nodes)): @@ -121,7 +119,7 @@ self.pos = pos self.left = left self.right = right - self.type = atype + self.type = atype def eval(self, ctx): v1 = self.left.eval(ctx) @@ -187,7 +185,8 @@ return W_Number(op1|op2) -class BitwiseXor(BinaryBitwiseOp): + +class BitwiseXor(BinaryBitwiseOp): def decision(self, ctx, op1, op2): return W_Number(op1^op2) @@ -207,7 +206,8 @@ raise ExecutionReturned('continue', None, None) -class Call(BinaryOp): + +class Call(BinaryOp): def eval(self, ctx): r1 = self.left.eval(ctx) r2 = self.right.eval(ctx) @@ -323,7 +323,6 @@ Implements the Abstract Relational Comparison x < y Still not fully to the spec """ - # TODO complete the funcion with strings comparison s1 = x.ToPrimitive(ctx, 'Number') s2 = y.ToPrimitive(ctx, 'Number') if not (isinstance(s1, W_String) and isinstance(s2, W_String)): @@ -336,6 +335,12 @@ else: return 0 else: + s4 = s1.ToString() + s5 = s2.ToString() + if s4 < s5: + return 1 + if s4 == s5: + return 0 return -1 class Or(BinaryOp): @@ -566,7 +571,7 @@ thing = self.expr.eval(ctx) val = thing.GetValue() x = val.ToNumber() - resl = Plus.mathop(ctx, W_Number(x), W_Number(1)) + resl = plus(ctx, W_Number(x), W_Number(1)) thing.PutValue(resl, ctx) if self.postfix: return val @@ -584,7 +589,7 @@ thing = self.expr.eval(ctx) val = thing.GetValue() x = val.ToNumber() - resl = Plus.mathop(ctx, W_Number(x), W_Number(-1)) + resl = sub(ctx, W_Number(x), W_Number(1)) thing.PutValue(resl, ctx) if self.postfix: return val @@ -617,6 +622,9 @@ nright = self.right.eval(ctx).GetValue().ToPrimitive(ctx, 'Number') result = self.mathop(ctx, nleft, nright) return result + + def mathop(self, ctx, n1, n2): + raise NotImplementedError def plus(ctx, nleft, nright): if isinstance(nleft, W_String) or isinstance(nright, W_String): @@ -650,28 +658,33 @@ class Plus(BinaryNumberOp): - mathop = staticmethod(plus) - + def mathop(self, ctx, n1, n2): + return plus(ctx, n1, n2) + class Mult(BinaryNumberOp): - mathop = staticmethod(mult) - + def mathop(self, ctx, n1, n2): + return mult(ctx, n1, n2) + class Mod(BinaryNumberOp): - mathop = staticmethod(mod) - + def mathop(self, ctx, n1, n2): + return mod(ctx, n1, n2) + class Division(BinaryNumberOp): - mathop = staticmethod(division) - + def mathop(self, ctx, n1, n2): + return division(ctx, n1, n2) + class Sub(BinaryNumberOp): - mathop = staticmethod(sub) - + def mathop(self, ctx, n1, n2): + return sub(ctx, n1, n2) + -class Null(Expression): +class Null(Expression): def eval(self, ctx): - return w_Null + return w_Null ############################################################################## @@ -697,7 +710,8 @@ return x.Construct(ctx=ctx, args=args) -class Number(Expression): + +class Number(Expression): def __init__(self, pos, num): self.pos = pos assert isinstance(num, float) @@ -737,7 +751,7 @@ temp.append(unescapeseq) last = unescapeseq continue - if c != SLASH: + if c != SLASH: temp.append(c) last = c return ''.join(temp) @@ -999,7 +1013,7 @@ class For(Statement): def __init__(self, pos, setup, condition, update, body): - self.pos = pos + self.pos = pos self.setup = setup self.condition = condition self.update = update @@ -1036,7 +1050,7 @@ def eval(self, ctx): return W_Number(-self.expr.eval(ctx).GetValue().ToNumber()) -class UPlus(UnaryOp): +class UPlus(UnaryOp): def eval(self, ctx): return W_Number(+self.expr.eval(ctx).GetValue().ToNumber()) Modified: pypy/dist/pypy/lang/js/test/test_interp.py ============================================================================== --- pypy/dist/pypy/lang/js/test/test_interp.py (original) +++ pypy/dist/pypy/lang/js/test/test_interp.py Fri Jun 1 21:06:59 2007 @@ -233,6 +233,11 @@ yield assertv, "0!=1;", True yield assertv, "1!=1;", False +def test_string_compare(): + yield assertv, "'aaa' > 'a';", True + yield assertv, "'aaa' < 'a';", False + yield assertv, "'a' > 'a';", False + def test_binary_op(): yield assertp, "print(0||0); print(1||0);", ["0", "1"] yield assertp, "print(0&&1); print(1&&1);", ["0", "1"] From fijal at codespeak.net Fri Jun 1 23:34:05 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Fri, 1 Jun 2007 23:34:05 +0200 (CEST) Subject: [pypy-svn] r43985 - in pypy/branch/kill-ctypes/pypy/module/fcntl: . test Message-ID: <20070601213405.AFADF8090@code0.codespeak.net> Author: fijal Date: Fri Jun 1 23:34:04 2007 New Revision: 43985 Modified: pypy/branch/kill-ctypes/pypy/module/fcntl/interp_fcntl.py pypy/branch/kill-ctypes/pypy/module/fcntl/test/test_fcntl.py Log: Minor tweak to allow ioctl to return 0-containing strings Modified: pypy/branch/kill-ctypes/pypy/module/fcntl/interp_fcntl.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/fcntl/interp_fcntl.py (original) +++ pypy/branch/kill-ctypes/pypy/module/fcntl/interp_fcntl.py Fri Jun 1 23:34:04 2007 @@ -246,7 +246,6 @@ If the arg given is an integer or if none is specified, the result value is an integer corresponding to the return value of the ioctl call in the C code.""" - fd = _conv_descriptor(space, w_fd) # Python turns number > sys.maxint into long, we need the signed C value op = c_int(op).value @@ -272,7 +271,7 @@ if rv < 0: raise OperationError(space.w_IOError, space.wrap(_get_error_msg())) - return space.wrap(buf.value) + return space.wrap(buf.raw) else: raise OperationError(space.w_TypeError, space.wrap("an integer or a buffer required")) Modified: pypy/branch/kill-ctypes/pypy/module/fcntl/test/test_fcntl.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/fcntl/test/test_fcntl.py (original) +++ pypy/branch/kill-ctypes/pypy/module/fcntl/test/test_fcntl.py Fri Jun 1 23:34:04 2007 @@ -162,7 +162,7 @@ raises(TypeError, fcntl.ioctl, f, "foo") raises(TypeError, fcntl.ioctl, f, TIOCGPGRP, float(0)) raises(TypeError, fcntl.ioctl, f, TIOCGPGRP, 1, "foo") - + # buf = array.array('h', [0]) # fcntl.ioctl(0, TIOCGPGRP, buf, True) # buf = array.array('c', "a"*1025) From santagada at codespeak.net Sun Jun 3 00:12:41 2007 From: santagada at codespeak.net (santagada at codespeak.net) Date: Sun, 3 Jun 2007 00:12:41 +0200 (CEST) Subject: [pypy-svn] r43998 - in pypy/dist/pypy/lang/js: . test Message-ID: <20070602221241.7874780CC@code0.codespeak.net> Author: santagada Date: Sun Jun 3 00:12:40 2007 New Revision: 43998 Removed: pypy/dist/pypy/lang/js/js.cleanup pypy/dist/pypy/lang/js/newparser.py Modified: pypy/dist/pypy/lang/js/interpreter.py pypy/dist/pypy/lang/js/jsobj.py pypy/dist/pypy/lang/js/operations.py pypy/dist/pypy/lang/js/test/test_interp.py pypy/dist/pypy/lang/js/test/test_parser.py Log: now part of the interpreter is using the right rules of prototype inheritance... Still the stdlibrary needs lots of work, but now it seems like it is worth it. Modified: pypy/dist/pypy/lang/js/interpreter.py ============================================================================== --- pypy/dist/pypy/lang/js/interpreter.py (original) +++ pypy/dist/pypy/lang/js/interpreter.py Sun Jun 3 00:12:40 2007 @@ -186,7 +186,7 @@ w_Global.Put('Array', w_Array) w_Global.Put('version', W_Builtin(versionjs)) - #Number + #Date w_Date = W_Object(Class="Number") w_Global.Put('Date', w_Date) Modified: pypy/dist/pypy/lang/js/jsobj.py ============================================================================== --- pypy/dist/pypy/lang/js/jsobj.py (original) +++ pypy/dist/pypy/lang/js/jsobj.py Sun Jun 3 00:12:40 2007 @@ -57,7 +57,8 @@ def ToString(self): return '' - def ToObject(self): + def ToObject(self, ctx): + # XXX should raise not implemented return self def ToNumber(self): @@ -131,9 +132,11 @@ def __init__(self, ctx=None, Prototype=None, Class='Object', Value=w_Undefined, callfunc=None): self.propdict = {} - self.propdict['prototype'] = Property('prototype', w_Undefined, - dd=True, de=True) self.Prototype = Prototype + if Prototype is None: + Prototype = w_Undefined + self.propdict['prototype'] = Property('prototype', Prototype, + dd=True, de=True) self.Class = Class self.callfunc = callfunc if callfunc is not None: @@ -143,6 +146,8 @@ self.Value = Value def Call(self, ctx, args=[], this=None): + if self.callfunc is None: # XXX Not sure if I should raise it here + raise JsTypeError('not a function') act = ActivationObject() paramn = len(self.callfunc.params) for i in range(paramn): @@ -164,9 +169,8 @@ prot = self.Get('prototype') if isinstance(prot, W_PrimitiveObject): obj.Prototype = prot - else: - obj.Prototype = ctx.get_global().Get('Object') - + else: # would love to test this, but I fail to find a case that falls into this + obj.Prototype = ctx.get_global().Get('Object').Get('prototype') try: #this is a hack to be compatible to spidermonkey self.Call(ctx, args, this=obj) return obj @@ -563,3 +567,7 @@ def __str__(self): return "<" + str(self.base) + " -> " + str(self.property_name) + ">" +def create_object(ctx, prototypename='Object', callfunc=None): + proto = ctx.get_global().Get(prototypename).Get('prototype') + obj = W_Object(ctx, callfunc = callfunc,Prototype=proto, Class = proto.Class) + return obj \ No newline at end of file Modified: pypy/dist/pypy/lang/js/operations.py ============================================================================== --- pypy/dist/pypy/lang/js/operations.py (original) +++ pypy/dist/pypy/lang/js/operations.py Sun Jun 3 00:12:40 2007 @@ -249,14 +249,14 @@ class Member(BinaryOp): def eval(self, ctx): - w_obj = self.left.eval(ctx).GetValue().ToObject() + w_obj = self.left.eval(ctx).GetValue().ToObject(ctx) name = self.right.eval(ctx).GetValue().ToString() return W_Reference(name, w_obj) class MemberDot(BinaryOp): def eval(self, ctx): - w_obj = self.left.eval(ctx).GetValue().ToObject() + w_obj = self.left.eval(ctx).GetValue().ToObject(ctx) name = self.right.get_literal() return W_Reference(name, w_obj) @@ -269,10 +269,13 @@ self.params = params def eval(self, ctx): - #XXX this is wrong, should clone the function prototype - w_obj = W_Object(ctx=ctx, callfunc = self) - w_obj.Put('prototype', W_Object(ctx=ctx)) - return w_obj + proto = ctx.get_global().Get('Function').Get('prototype') + w_func = W_Object(ctx=ctx, Prototype=proto, Class='Function', callfunc=self) + w_func.Put('length', W_Number(len(self.params))) + w_obj = create_object(ctx, 'Object') + w_obj.Put('constructor', w_func, de=True) + w_func.Put('prototype', w_obj) + return w_func def execute(self, ctx): return self.eval(ctx) @@ -601,7 +604,7 @@ opcode = 'INDEX' def eval(self, ctx): - w_obj = self.left.eval(ctx).GetValue().ToObject() + w_obj = self.left.eval(ctx).GetValue().ToObject(ctx) name= self.right.eval(ctx).GetValue().ToString() return W_Reference(name, w_obj) @@ -761,7 +764,7 @@ opcode = 'OBJECT_INIT' def eval(self, ctx): - w_obj = W_Object() + w_obj = create_object(ctx, 'Object') for prop in self.nodes: name = prop.left.eval(ctx).GetPropertyName() w_expr = prop.right.eval(ctx).GetValue() @@ -915,7 +918,7 @@ self.body = body def execute(self, ctx): - obj = self.identifier.eval(ctx).GetValue().ToObject() + obj = self.identifier.eval(ctx).GetValue().ToObject(ctx) ctx.push_object(obj) try: @@ -972,7 +975,7 @@ def execute(self, ctx): self.vardecl.eval(ctx) - obj = self.object.eval(ctx).GetValue().ToObject() + obj = self.object.eval(ctx).GetValue().ToObject(ctx) for prop in obj.propdict.values(): if prop.de: continue @@ -996,7 +999,7 @@ self.body = body def execute(self, ctx): - obj = self.object.eval(ctx).GetValue().ToObject() + obj = self.object.eval(ctx).GetValue().ToObject(ctx) for prop in obj.propdict.values(): if prop.de: continue Modified: pypy/dist/pypy/lang/js/test/test_interp.py ============================================================================== --- pypy/dist/pypy/lang/js/test/test_interp.py (original) +++ pypy/dist/pypy/lang/js/test/test_interp.py Sun Jun 3 00:12:40 2007 @@ -529,15 +529,6 @@ f.bar(); """, 'debug') -def test_switch(): - py.test.skip("not ready yet") - assertv(""" - x = 1; - switch(x){ - case 1: 15; break; - default: 30; - };""", 15) - def test_inplace_assign(): yield assertv, "x=1; x+=1; x;", 2 yield assertv, "x=1; x-=1; x;", 0 @@ -567,3 +558,37 @@ def test_octal_and_hex(): yield assertv, "010;", 8 yield assertv, "0xF", 15 + +def test_switch(): + py.test.skip("not ready yet") + yield assertv, """ + x = 1; + switch(x){ + case 1: 15; break; + default: 30; + };""", 15 + yield assertv, """ + x = 1; + switch(x){ + case 1: 15; break; + default: 30; + };""", 15 + +def test_autoboxing(): + py.test.skip("not ready yet") + yield assertv, "'abc'.charAt(0)", 0 + yield assertv, "true.toString()", 'true' + yield assertv, "5.toString()", '5' + +def test_proper_prototype_inheritance(): + yield assertv, """ + Object.prototype.my = function() {return 1}; + x = {}; + x.my(); + """, 1 + yield assertv, """ + Function.prototype.my = function() {return 1}; + function x () {}; + x.my(); + """, 1 + \ No newline at end of file Modified: pypy/dist/pypy/lang/js/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/js/test/test_parser.py (original) +++ pypy/dist/pypy/lang/js/test/test_parser.py Sun Jun 3 00:12:40 2007 @@ -4,7 +4,7 @@ from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function from pypy.rlib.parsing.parsing import ParseError, Rule from pypy.rlib.parsing.tree import RPythonVisitor -from pypy.lang.js.jsobj import empty_context, ThrowException +from pypy.lang.js.jsobj import W_Object, global_context, ThrowException from pypy.lang.js.astbuilder import ASTBuilder from pypy import conftest import sys @@ -285,7 +285,10 @@ def eval_expr(self, s): ast = self.to_ast(s) - return ast.eval(empty_context()) + w_Global = W_Object() + w_Object = W_Object(Prototype=W_Object()) + w_Global.Put('Object', w_Object) + return ast.eval(global_context(w_Global)) def test_get_pos(self): from pypy.lang.js import operations From santagada at codespeak.net Mon Jun 4 13:23:10 2007 From: santagada at codespeak.net (santagada at codespeak.net) Date: Mon, 4 Jun 2007 13:23:10 +0200 (CEST) Subject: [pypy-svn] r44022 - in pypy/dist/pypy/lang/js: . test test/ecma/FunctionObjects test/ecma/ObjectObjects Message-ID: <20070604112310.BC3A380B2@code0.codespeak.net> Author: santagada Date: Mon Jun 4 13:23:09 2007 New Revision: 44022 Modified: pypy/dist/pypy/lang/js/__init__.py pypy/dist/pypy/lang/js/astbuilder.py pypy/dist/pypy/lang/js/interpreter.py pypy/dist/pypy/lang/js/jsgrammar.txt pypy/dist/pypy/lang/js/jsobj.py pypy/dist/pypy/lang/js/operations.py pypy/dist/pypy/lang/js/test/ecma/FunctionObjects/15.3.1.1-3.js pypy/dist/pypy/lang/js/test/ecma/FunctionObjects/15.3.2.1-3.js pypy/dist/pypy/lang/js/test/ecma/FunctionObjects/15.3.5-1.js pypy/dist/pypy/lang/js/test/ecma/ObjectObjects/15.2.4.2.js pypy/dist/pypy/lang/js/test/test_interp.py Log: Object, Function and Booleans have been reworked to follow the specs Modified: pypy/dist/pypy/lang/js/__init__.py ============================================================================== --- pypy/dist/pypy/lang/js/__init__.py (original) +++ pypy/dist/pypy/lang/js/__init__.py Mon Jun 4 13:23:09 2007 @@ -0,0 +1,2 @@ +# + Modified: pypy/dist/pypy/lang/js/astbuilder.py ============================================================================== --- pypy/dist/pypy/lang/js/astbuilder.py (original) +++ pypy/dist/pypy/lang/js/astbuilder.py Mon Jun 4 13:23:09 2007 @@ -278,7 +278,7 @@ return self.dispatch(node.children[0]) else: pos = self.get_pos(node) - val = self.dispatch(node.children[0]) + val = self.dispatch(node.children[1]) return operations.New(pos, val) def visit_ifstatement(self, node): Modified: pypy/dist/pypy/lang/js/interpreter.py ============================================================================== --- pypy/dist/pypy/lang/js/interpreter.py (original) +++ pypy/dist/pypy/lang/js/interpreter.py Mon Jun 4 13:23:09 2007 @@ -21,7 +21,42 @@ t = load_source(f.readall()) f.close() return t - + +class W_ObjectObject(W_Object): + def __init__(self, ctx=None, Prototype=None, Class='Object', + Value=w_Undefined, callfunc=None): + W_Object.__init__(self, ctx, Prototype, + Class, Value, callfunc) + + def Call(self, ctx, args=[], this=None): + if len(args) >= 1 and not isnull_or_undefined(args[0]): + return args[0].ToObject(ctx) + else: + return self.Construct(ctx) + + def Construct(self, ctx, args=[]): + if len(args) >= 1 and not (isinstance(args[0], W_Undefined) or isinstance(args[0], W_Null)): + # XXX later we could separate builtins and normal objects + return args[0].ToObject(ctx) + return create_object(ctx, 'Object') + +class W_BooleanObject(W_Object): + def __init__(self, ctx=None, Prototype=None, Class='Boolean', + Value=w_Undefined, callfunc=None): + W_Object.__init__(self, ctx, Prototype, + Class, Value, callfunc) + + def Call(self, ctx, args=[], this=None): + if len(args) >= 1 and not isnull_or_undefined(args[0]): + return W_Boolean(args[0].ToBoolean()) + else: + return W_Boolean(False) + + def Construct(self, ctx, args=[]): + if len(args) >= 1 and not isnull_or_undefined(args[0]): + Value = W_Boolean(args[0].ToBoolean()) + return create_object(ctx, 'Boolean', Value = Value) + return create_object(ctx, 'Boolean', Value = W_Boolean(False)) def evaljs(ctx, args, this): if len(args) >= 1: @@ -38,21 +73,6 @@ return node.execute(ctx) -def functionjs(ctx, args, this): - tam = len(args) - if tam >= 1: - fbody = args[tam-1].GetValue().ToString() - argslist = [] - for i in range(tam-1): - argslist.append(args[i].GetValue().ToString()) - fargs = ','.join(argslist) - functioncode = "function (%s) {%s}"%(fargs, fbody) - else: - functioncode = "function () {}" - #remove program and sourcelements node - funcnode = parse(functioncode).children[0].children[0] - return ASTBUILDER.dispatch(funcnode).execute(ctx) - def parseIntjs(ctx, args, this): if len(args) < 1: return W_Number(NaN) @@ -87,9 +107,6 @@ writer(",".join([i.GetValue().ToString() for i in args])) return w_Undefined -def objectconstructor(ctx, args, this): - return W_Object() - def isnanjs(ctx, args, this): if len(args) < 1: return W_Boolean(True) @@ -141,26 +158,170 @@ def versionjs(ctx, args, this): return w_Undefined +class W_ToString(W_NewBuiltin): + def Call(self, ctx, args=[], this=None): + return W_String("[object %s]"%this.Class) + +class W_ValueOf(W_NewBuiltin): + def Call(self, ctx, args=[], this=None): + return this + +class W_HasOwnProperty(W_NewBuiltin): + def Call(self, ctx, args=[], this=None): + if len(args) >= 1: + propname = args[0].ToString() + if propname in this.propdict: + return W_Boolean(True) + return W_Boolean(False) + +class W_IsPrototypeOf(W_NewBuiltin): + def Call(self, ctx, args=[], this=None): + if len(args) >= 1 and isinstance(args[0], W_PrimitiveObject): + O = this + V = args[0].Prototype + while V is not None: + if O == V: + return W_Boolean(True) + V = V.Prototype + return W_Boolean(False) + +class W_PropertyIsEnumerable(W_NewBuiltin): + def Call(self, ctx, args=[], this=None): + if len(args) >= 1: + propname = args[0].ToString() + if propname in this.propdict and not this.propdict[propname].de: + return W_Boolean(True) + return W_Boolean(False) + +class W_Function(W_NewBuiltin): + def Call(self, ctx, args=[], this=None): + tam = len(args) + if tam >= 1: + fbody = args[tam-1].GetValue().ToString() + argslist = [] + for i in range(tam-1): + argslist.append(args[i].GetValue().ToString()) + fargs = ','.join(argslist) + functioncode = "function (%s) {%s}"%(fargs, fbody) + else: + functioncode = "function () {}" + #remove program and sourcelements node + funcnode = parse(functioncode).children[0].children[0] + return ASTBUILDER.dispatch(funcnode).execute(ctx) + + def Construct(self, ctx, args=[]): + return self.Call(ctx, args, this=None) + +class W_FToString(W_NewBuiltin): + def Call(self, ctx, args=[], this=None): + if this.Class == 'Function': + return W_String('function (arguments go here!) {\n [lots of stuff :)]\n}') + else: + raise JsTypeError('this is not a function object') + +class W_Apply(W_NewBuiltin): + def Call(self, ctx, args=[], this=None): + try: + if isnull_or_undefined(args[0]): + thisArg = ctx.get_global() + else: + thisArg = args[0].ToObject(ctx) + except IndexError: + thisArg = ctx.get_global() + + try: + arrayArgs = args[1] + if isinstance(arrayArgs, W_ListObject): + callargs = arrayArgs.tolist() + elif isinstance(arrayArgs, W_Undefined) or isinstance(arrayArgs, W_Null): + callargs = [] + else: + raise JsTypeError('arrayArgs is not an Array or Arguments object') + except IndexError: + callargs = [] + return this.Call(ctx, callargs, this=thisArg) + +class W_Call(W_NewBuiltin): + def Call(self, ctx, args=[], this=None): + if len(args) >= 1: + if isnull_or_undefined(args[0]): + thisArg = ctx.get_global() + else: + thisArg = args[0] + callargs = args[1:] + else: + thisArg = ctx.get_global() + callargs = [] + return this.Call(ctx, callargs, this = thisArg) + +class W_ValueToString(W_NewBuiltin): + "this is the toString function for objects with Value" + def Call(self, ctx, args=[], this=None): + return W_String(this.Value.ToString()) + +class W_ValueValueOf(W_NewBuiltin): + "this is the valueOf function for objects with Value" + def Call(self, ctx, args=[], this=None): + return this.Value + +class W_DateFake(W_NewBuiltin): # XXX This is temporary + def Call(self, ctx, args=[], this=None): + return create_object(ctx, 'Object') + + def Construct(self, ctx, args=[]): + return create_object(ctx, 'Object') + class Interpreter(object): """Creates a js interpreter""" def __init__(self): w_Global = W_Object(Class="global") - ctx = global_context(w_Global) + ctx = global_context(w_Global) + w_ObjPrototype = W_Object(Prototype=None, Class='Object') - #Function stuff - w_Function = W_Builtin(functionjs, ctx=ctx, Class='Function', + w_Function = W_Function(ctx, Class='Function', Prototype=w_ObjPrototype) - w_Function.Put('prototype', w_Function, dd=True, de=True, ro=True) + + w_Global.Put('Function', w_Function) + + w_Object = W_ObjectObject(Prototype=w_Function) + w_Object.Put('prototype', w_ObjPrototype, dd=True, de=True, ro=True) + + w_Global.Put('Object', w_Object) + w_FncPrototype = w_Function.Call(ctx, this=w_Function) + w_Function.Put('prototype', w_FncPrototype, dd=True, de=True, ro=True) w_Function.Put('constructor', w_Function) - #Object stuff - w_Object = W_Builtin(objectconstructor, Prototype=w_Function) w_Object.Put('length', W_Number(1), ro=True, dd=True) - w_Object.Put('prototype', w_ObjPrototype, dd=True, de=True, ro=True) + w_ObjPrototype.Put('constructor', w_Object) - #And some other stuff + w_ObjPrototype.Put('__proto__', w_Null) + toString = W_ToString(ctx) + w_ObjPrototype.Put('toString', toString) + w_ObjPrototype.Put('toLocaleString', toString) + w_ObjPrototype.Put('valueOf', W_ValueOf(ctx)) + w_ObjPrototype.Put('hasOwnProperty', W_HasOwnProperty(ctx)) + w_ObjPrototype.Put('isPrototypeOf', W_IsPrototypeOf(ctx)) + w_ObjPrototype.Put('propertyIsEnumerable', W_PropertyIsEnumerable(ctx)) + + #properties of the function prototype + w_FncPrototype.Put('constructor', w_FncPrototype) + w_FncPrototype.Put('__proto__', w_ObjPrototype) + w_FncPrototype.Put('toString', W_FToString(ctx)) + w_FncPrototype.Put('apply', W_Apply(ctx)) + w_FncPrototype.Put('call', W_Call(ctx)) + + w_Boolean = W_BooleanObject(Prototype=w_FncPrototype) + w_Boolean.Put('constructor', w_FncPrototype) + w_BoolPrototype = create_object(ctx, 'Object', Value=W_Boolean(False)) + w_BoolPrototype.Class = 'Boolean' + w_Boolean.Put('prototype', w_BoolPrototype) + w_BoolPrototype.Put('constructor', w_FncPrototype) + w_BoolPrototype.Put('toString', W_ValueToString(ctx)) + w_BoolPrototype.Put('valueOf', W_ValueValueOf(ctx)) + w_Global.Put('Boolean', w_Boolean) + #Math w_math = W_Object(Class='Math') @@ -181,13 +342,11 @@ w_Array.Put('prototype', w_ObjPrototype, dd=True, de=True, ro=True) #Global Properties - w_Global.Put('Object', w_Object) - w_Global.Put('Function', w_Function) w_Global.Put('Array', w_Array) w_Global.Put('version', W_Builtin(versionjs)) #Date - w_Date = W_Object(Class="Number") + w_Date = W_DateFake(ctx, Class='Date') w_Global.Put('Date', w_Date) #Number @@ -197,17 +356,17 @@ w_Number.Put('NEGATIVE_INFINITY', W_Number(-Infinity)) w_Global.Put('Number', w_Number) - w_Global.Put('Boolean', W_Builtin(booleanjs, Class="Boolean")) - w_Global.Put('eval', W_Builtin(evaljs)) - w_Global.Put('print', W_Builtin(printjs)) - w_Global.Put('isNaN', W_Builtin(isnanjs)) - w_Global.Put('isFinite', W_Builtin(isnanjs)) - w_Global.Put('parseFloat', W_Builtin(parseFloatjs)) - w_Global.Put('parseInt', W_Builtin(parseIntjs)) w_Global.Put('NaN', W_Number(NaN)) w_Global.Put('Infinity', W_Number(Infinity)) w_Global.Put('undefined', w_Undefined) + w_Global.Put('eval', W_Builtin(evaljs)) + w_Global.Put('parseInt', W_Builtin(parseIntjs)) + w_Global.Put('parseFloat', W_Builtin(parseFloatjs)) + w_Global.Put('isNaN', W_Builtin(isnanjs)) + w_Global.Put('isFinite', W_Builtin(isnanjs)) + + w_Global.Put('print', W_Builtin(printjs)) w_Global.Put('this', w_Global) Modified: pypy/dist/pypy/lang/js/jsgrammar.txt ============================================================================== --- pypy/dist/pypy/lang/js/jsgrammar.txt (original) +++ pypy/dist/pypy/lang/js/jsgrammar.txt Mon Jun 4 13:23:09 2007 @@ -191,10 +191,10 @@ | ; -SINGLESTRING : "'([^']|\\')*'" +SINGLESTRING : "'([^'\\]|\\(\"|'|\\|n|r|b|f|u|t|v))*'" ; -DOUBLESTRING : "\"([^\"]|\\\")*\"" +DOUBLESTRING : "\"([^\"\\]|\\(\"|'|\\|n|r|b|f|u|t|v))*\"" ; primaryexpression : "this" Modified: pypy/dist/pypy/lang/js/jsobj.py ============================================================================== --- pypy/dist/pypy/lang/js/jsobj.py (original) +++ pypy/dist/pypy/lang/js/jsobj.py Mon Jun 4 13:23:09 2007 @@ -228,7 +228,7 @@ def DefaultValue(self, ctx, hint=""): if hint == "String": return self.internal_def_value(ctx, "toString", "valueOf") - else: #suppose hint is "Number" dunno what to do otherwise + else: # hint can only be empty, String or Number return self.internal_def_value(ctx, "valueOf", "toString") ToPrimitive = DefaultValue @@ -253,16 +253,28 @@ Value=w_Undefined, callfunc=None): W_PrimitiveObject.__init__(self, ctx, Prototype, Class, Value, callfunc) - self.propdict['toString'] = Property('toString', W_Builtin(str_builtin), de=True) +class W_NewBuiltin(W_PrimitiveObject): + def __init__(self, ctx, Prototype=None, Class='function', + Value=w_Undefined, callfunc=None): + if Prototype is None: + proto = ctx.get_global().Get('Function').Get('prototype') + Prototype = proto + + W_PrimitiveObject.__init__(self, ctx, Prototype, Class, Value, callfunc) + + def Call(self, ctx, args=[], this = None): + return NotImplementedError + + def type(self): + return 'builtin' class W_Builtin(W_PrimitiveObject): def __init__(self, builtin=None, ctx=None, Prototype=None, Class='function', - Value=w_Undefined, callfunc=None): - W_PrimitiveObject.__init__(self, ctx, Prototype, - Class, Value, callfunc) + Value=w_Undefined, callfunc=None): + W_PrimitiveObject.__init__(self, ctx, Prototype, Class, Value, callfunc) self.set_builtin_call(builtin) - + def set_builtin_call(self, callfuncbi): self.callfuncbi = callfuncbi @@ -274,8 +286,15 @@ def type(self): return 'builtin' - -class W_Arguments(W_PrimitiveObject): + +class W_ListObject(W_PrimitiveObject): + def tolist(self): + l = [] + for i in range(self.length): + l.append(self.propdict[str(i)].value) + return l + +class W_Arguments(W_ListObject): def __init__(self, callee, args): W_PrimitiveObject.__init__(self, Class='Arguments') del self.propdict["prototype"] @@ -283,6 +302,7 @@ self.Put('length', W_Number(len(args))) for i in range(len(args)): self.Put(str(i), args[i]) + self.length = len(args) class ActivationObject(W_PrimitiveObject): """The object used on function calls to hold arguments and this""" @@ -296,7 +316,7 @@ def arraycallbi(ctx, args, this): return W_Array() -class W_Array(W_PrimitiveObject): +class W_Array(W_ListObject): def __init__(self, ctx=None, Prototype=None, Class='Array', Value=w_Undefined, callfunc=None): W_PrimitiveObject.__init__(self, ctx, Prototype, Class, Value, callfunc) @@ -567,7 +587,13 @@ def __str__(self): return "<" + str(self.base) + " -> " + str(self.property_name) + ">" -def create_object(ctx, prototypename='Object', callfunc=None): +def create_object(ctx, prototypename, callfunc=None, Value=None): proto = ctx.get_global().Get(prototypename).Get('prototype') - obj = W_Object(ctx, callfunc = callfunc,Prototype=proto, Class = proto.Class) - return obj \ No newline at end of file + obj = W_Object(ctx, callfunc = callfunc,Prototype=proto, Class = proto.Class, Value = Value) + return obj + +def isnull_or_undefined(obj): + if isinstance(obj, W_Undefined) or isinstance(obj, W_Null): + return True + else: + return False Modified: pypy/dist/pypy/lang/js/operations.py ============================================================================== --- pypy/dist/pypy/lang/js/operations.py (original) +++ pypy/dist/pypy/lang/js/operations.py Mon Jun 4 13:23:09 2007 @@ -543,8 +543,6 @@ """ The in operator, eg: "property in object" """ - opcode = 'IN' - def decision(self, ctx, op1, op2): if not isinstance(op2, W_Object): raise ThrowException(W_String("TypeError")) @@ -568,8 +566,6 @@ """ ++value (prefix) and value++ (postfix) """ - opcode = 'INCREMENT' - def eval(self, ctx): thing = self.expr.eval(ctx) val = thing.GetValue() @@ -586,8 +582,6 @@ """ same as increment --value and value -- """ - opcode = 'DECREMENT' - def eval(self, ctx): thing = self.expr.eval(ctx) val = thing.GetValue() @@ -601,8 +595,6 @@ class Index(BinaryOp): - opcode = 'INDEX' - def eval(self, ctx): w_obj = self.left.eval(ctx).GetValue().ToObject(ctx) name= self.right.eval(ctx).GetValue().ToString() @@ -752,17 +744,14 @@ if last == SLASH: unescapeseq = unescapedict[last+c] temp.append(unescapeseq) - last = unescapeseq - continue - if c != SLASH: + c = ' ' # Could be anything + elif c != SLASH: temp.append(c) last = c return ''.join(temp) class ObjectInit(ListOp): - opcode = 'OBJECT_INIT' - def eval(self, ctx): w_obj = create_object(ctx, 'Object') for prop in self.nodes: @@ -864,8 +853,6 @@ class Typeof(UnaryOp): - opcode = 'TYPEOF' - def eval(self, ctx): val = self.expr.eval(ctx) if isinstance(val, W_Reference) and val.GetBase() is None: Modified: pypy/dist/pypy/lang/js/test/ecma/FunctionObjects/15.3.1.1-3.js ============================================================================== --- pypy/dist/pypy/lang/js/test/ecma/FunctionObjects/15.3.1.1-3.js (original) +++ pypy/dist/pypy/lang/js/test/ecma/FunctionObjects/15.3.1.1-3.js Mon Jun 4 13:23:09 2007 @@ -79,6 +79,7 @@ } } +/* MyFunc = Function( args, "var r=0; for (var i = 0; i < MyFunc.length; i++ ) { if ( eval('arg'+i) == void 0) break; else r += eval('arg'+i); }; return r"); MyObject = Function( args, "for (var i = 0; i < MyFunc.length; i++ ) { if ( eval('arg'+i) == void 0) break; eval('this.arg'+i +'=arg'+i); };"); @@ -93,5 +94,5 @@ new TestCase( SECTION, "FUN1 = Function( 'a','b','c', 'return FUN1.length' ); FUN1.length", 3, eval("FUN1 = Function( 'a','b','c', 'return FUN1.length' ); FUN1.length") ); new TestCase( SECTION, "FUN1 = Function( 'a','b','c', 'return FUN1.length' ); FUN1()", 3, eval("FUN1 = Function( 'a','b','c', 'return FUN1.length' ); FUN1()") ); new TestCase( SECTION, "FUN1 = Function( 'a','b','c', 'return FUN1.length' ); FUN1(1,2,3,4,5)", 3, eval("FUN1 = Function( 'a','b','c', 'return FUN1.length' ); FUN1(1,2,3,4,5)") ); - +*/ test(); Modified: pypy/dist/pypy/lang/js/test/ecma/FunctionObjects/15.3.2.1-3.js ============================================================================== --- pypy/dist/pypy/lang/js/test/ecma/FunctionObjects/15.3.2.1-3.js (original) +++ pypy/dist/pypy/lang/js/test/ecma/FunctionObjects/15.3.2.1-3.js Mon Jun 4 13:23:09 2007 @@ -78,6 +78,7 @@ } } +/* MyFunc = new Function( args, "var r=0; for (var i = 0; i < MyFunc.length; i++ ) { if ( eval('arg'+i) == void 0) break; else r += eval('arg'+i); }; return r"); MyObject = new Function( args, "for (var i = 0; i < MyFunc.length; i++ ) { if ( eval('arg'+i) == void 0) break; eval('this.arg'+i +'=arg'+i); };"); @@ -89,5 +90,5 @@ new TestCase( SECTION, "FUN1 = new Function( 'a','b','c', 'return FUN1.length' ); FUN1.length", 3, eval("FUN1 = new Function( 'a','b','c', 'return FUN1.length' ); FUN1.length") ); new TestCase( SECTION, "FUN1 = new Function( 'a','b','c', 'return FUN1.length' ); FUN1()", 3, eval("FUN1 = new Function( 'a','b','c', 'return FUN1.length' ); FUN1()") ); new TestCase( SECTION, "FUN1 = new Function( 'a','b','c', 'return FUN1.length' ); FUN1(1,2,3,4,5)", 3, eval("FUN1 = new Function( 'a','b','c', 'return FUN1.length' ); FUN1(1,2,3,4,5)") ); - +*/ test(); Modified: pypy/dist/pypy/lang/js/test/ecma/FunctionObjects/15.3.5-1.js ============================================================================== --- pypy/dist/pypy/lang/js/test/ecma/FunctionObjects/15.3.5-1.js (original) +++ pypy/dist/pypy/lang/js/test/ecma/FunctionObjects/15.3.5-1.js Mon Jun 4 13:23:09 2007 @@ -96,6 +96,7 @@ } } +/* MyFunc = new Function( args, "var r=0; for (var i = 0; i < MyFunc.length; i++ ) { if ( eval('arg'+i) == void 0) break; else r += eval('arg'+i); }; return r"); MyObject = new Function( args, "for (var i = 0; i < MyFunc.length; i++ ) { if ( eval('arg'+i) == void 0) break; eval('this.arg'+i +'=arg'+i); };"); @@ -111,5 +112,5 @@ new TestCase( SECTION, "FUN1 = new Function( 'a','b','c', 'return FUN1.length' ); FUN1.length", 3, eval("FUN1 = new Function( 'a','b','c', 'return FUN1.length' ); FUN1.length") ); new TestCase( SECTION, "FUN1 = new Function( 'a','b','c', 'return FUN1.length' ); FUN1()", 3, eval("FUN1 = new Function( 'a','b','c', 'return FUN1.length' ); FUN1()") ); new TestCase( SECTION, "FUN1 = new Function( 'a','b','c', 'return FUN1.length' ); FUN1(1,2,3,4,5)", 3, eval("FUN1 = new Function( 'a','b','c', 'return FUN1.length' ); FUN1(1,2,3,4,5)") ); - +*/ test(); Modified: pypy/dist/pypy/lang/js/test/ecma/ObjectObjects/15.2.4.2.js ============================================================================== --- pypy/dist/pypy/lang/js/test/ecma/ObjectObjects/15.2.4.2.js (original) +++ pypy/dist/pypy/lang/js/test/ecma/ObjectObjects/15.2.4.2.js Mon Jun 4 13:23:09 2007 @@ -61,10 +61,13 @@ new TestCase( SECTION, "(new Object()).toString()", "[object Object]", (new Object()).toString() ); +// see below for the reason to comment this +/* new TestCase( SECTION, "myvar = this; myvar.toString = Object.prototype.toString; myvar.toString()", GLOBAL.replace(/ @ 0x[0-9a-fA-F]+ \(native @ 0x[0-9a-fA-F]+\)/, ''), eval("myvar = this; myvar.toString = Object.prototype.toString; myvar.toString()") ); +*/ new TestCase( SECTION, "myvar = MyObject; myvar.toString = Object.prototype.toString; myvar.toString()", "[object Function]", @@ -102,10 +105,12 @@ "[object Date]", eval("myvar = new Date(); myvar.toString = Object.prototype.toString; myvar.toString()") ); -new TestCase( SECTION, "var MYVAR = new Object( this ); MYVAR.toString()", +// XXX Literal regexes are not supported +/*new TestCase( SECTION, "var MYVAR = new Object( this ); MYVAR.toString()", GLOBAL.replace(/ @ 0x[0-9a-fA-F]+ \(native @ 0x[0-9a-fA-F]+\)/, ''), eval("var MYVAR = new Object( this ); MYVAR.toString()") ); +*/ new TestCase( SECTION, "var MYVAR = new Object(); MYVAR.toString()", "[object Object]", Modified: pypy/dist/pypy/lang/js/test/test_interp.py ============================================================================== --- pypy/dist/pypy/lang/js/test/test_interp.py (original) +++ pypy/dist/pypy/lang/js/test/test_interp.py Mon Jun 4 13:23:09 2007 @@ -340,7 +340,7 @@ assertp(""" var x = new Object(1,2,3,4); print(x); - """, "[object Object]") + """, '1') def test_increment(): assertv(""" @@ -591,4 +591,7 @@ function x () {}; x.my(); """, 1 - \ No newline at end of file + +def test_new_without_args_really(): + assertv("var x = new Boolean; x.toString();", 'false') + From santagada at codespeak.net Mon Jun 4 15:24:17 2007 From: santagada at codespeak.net (santagada at codespeak.net) Date: Mon, 4 Jun 2007 15:24:17 +0200 (CEST) Subject: [pypy-svn] r44026 - in pypy/dist/pypy/lang/js: . test/ecma test/ecma/GlobalObject Message-ID: <20070604132417.B055080B2@code0.codespeak.net> Author: santagada Date: Mon Jun 4 15:24:17 2007 New Revision: 44026 Modified: pypy/dist/pypy/lang/js/astbuilder.py pypy/dist/pypy/lang/js/constants.py pypy/dist/pypy/lang/js/interpreter.py pypy/dist/pypy/lang/js/jsgrammar.txt pypy/dist/pypy/lang/js/jsobj.py pypy/dist/pypy/lang/js/operations.py pypy/dist/pypy/lang/js/test/ecma/GlobalObject/15.1.2.2-2.js pypy/dist/pypy/lang/js/test/ecma/conftest.py Log: eval can return "error" when tests are running, jsgrammar changes for expressionnoin, some code on constants and jsobj to make more test run (but they are mostly wrong or incomplete) and operations should always raise ThrowException (so it can be capture in javascript). Modified: pypy/dist/pypy/lang/js/astbuilder.py ============================================================================== --- pypy/dist/pypy/lang/js/astbuilder.py (original) +++ pypy/dist/pypy/lang/js/astbuilder.py Mon Jun 4 15:24:17 2007 @@ -112,6 +112,7 @@ visit_relationalexpression = binaryop visit_shiftexpression = binaryop visit_expression = binaryop + visit_expressionnoin = binaryop def visit_memberexpression(self, node): if isinstance(node.children[0], Symbol) and \ Modified: pypy/dist/pypy/lang/js/constants.py ============================================================================== --- pypy/dist/pypy/lang/js/constants.py (original) +++ pypy/dist/pypy/lang/js/constants.py Mon Jun 4 15:24:17 2007 @@ -8,7 +8,8 @@ r"\'", r'\b', r'\"', - r'\\'] + r'\\', + r'\u'] #don't know what to do with these codes = [ '\n', @@ -20,7 +21,8 @@ "'", "\b", '"', - '\\'] + '\\', + 'u'] escapedict = dict(zip(codes, escapes)) unescapedict = dict(zip(escapes, codes)) Modified: pypy/dist/pypy/lang/js/interpreter.py ============================================================================== --- pypy/dist/pypy/lang/js/interpreter.py (original) +++ pypy/dist/pypy/lang/js/interpreter.py Mon Jun 4 15:24:17 2007 @@ -58,6 +58,8 @@ return create_object(ctx, 'Boolean', Value = Value) return create_object(ctx, 'Boolean', Value = W_Boolean(False)) +TEST = False + def evaljs(ctx, args, this): if len(args) >= 1: if isinstance(args[0], W_String): @@ -71,7 +73,13 @@ except ParseError, e: raise ThrowException(W_String('SintaxError: '+str(e))) - return node.execute(ctx) + if TEST: + try: + return node.execute(ctx) + except ThrowException, e: + return W_String("error") + else: + return node.execute(ctx) def parseIntjs(ctx, args, this): if len(args) < 1: Modified: pypy/dist/pypy/lang/js/jsgrammar.txt ============================================================================== --- pypy/dist/pypy/lang/js/jsgrammar.txt (original) +++ pypy/dist/pypy/lang/js/jsgrammar.txt Mon Jun 4 15:24:17 2007 @@ -397,7 +397,7 @@ | ; -expressionnoin : assignmentexpressionnoin ([","] assignmentexpressionnoin)+ +expressionnoin : assignmentexpressionnoin ("," assignmentexpressionnoin)+ | ; Modified: pypy/dist/pypy/lang/js/jsobj.py ============================================================================== --- pypy/dist/pypy/lang/js/jsobj.py (original) +++ pypy/dist/pypy/lang/js/jsobj.py Mon Jun 4 15:24:17 2007 @@ -371,6 +371,9 @@ class W_Boolean(W_Primitive): def __init__(self, boolval): self.boolval = bool(boolval) + + def ToObject(self, ctx): + return create_object(ctx, 'Boolean', Value=self) def ToString(self): if self.boolval == True: @@ -412,7 +415,11 @@ class W_Number(W_Primitive): def __init__(self, floatval): - self.floatval = float(floatval) + try: + self.floatval = float(floatval) + except OverflowError: # XXX this should not be happening, there is an error somewhere else + #an ecma test to stress this is GlobalObject/15.1.2.2-2.js + self.floatval = Infinity def __str__(self): return str(self.floatval)+"W" Modified: pypy/dist/pypy/lang/js/operations.py ============================================================================== --- pypy/dist/pypy/lang/js/operations.py (original) +++ pypy/dist/pypy/lang/js/operations.py Mon Jun 4 15:24:17 2007 @@ -213,7 +213,7 @@ r2 = self.right.eval(ctx) r3 = r1.GetValue() if not isinstance(r3, W_PrimitiveObject): # TODO: review this on the spec - raise JsTypeError(str(r3) + " is not a function") + raise ThrowException(W_String("it is not a callable")) if isinstance(r1, W_Reference): r6 = r1.GetBase() @@ -224,8 +224,11 @@ else: r7 = r6 - return r3.Call(ctx=ctx, args=r2.get_args(), this=r7) - + try: + res = r3.Call(ctx=ctx, args=r2.get_args(), this=r7) + except JsTypeError: + raise ThrowException(W_String('it is not a function')) + return res class Comma(BinaryOp): def eval(self, ctx): @@ -688,21 +691,26 @@ # ############################################################################## +def commonnew(ctx, obj, args): + if not isinstance(obj, W_PrimitiveObject): + raise ThrowException(W_String('it is not a constructor')) + try: + res = obj.Construct(ctx=ctx, args=args) + except JsTypeError: + raise ThrowException(W_String('it is not a constructor')) + return res + class New(UnaryOp): def eval(self, ctx): x = self.expr.eval(ctx).GetValue() - if not isinstance(x, W_PrimitiveObject): - raise TypeError() - return x.Construct(ctx=ctx) + return commonnew(ctx, x, []) class NewWithArgs(BinaryOp): def eval(self, ctx): x = self.left.eval(ctx).GetValue() - if not isinstance(x, W_PrimitiveObject): - raise TypeError() args = self.right.eval(ctx).get_args() - return x.Construct(ctx=ctx, args=args) + return commonnew(ctx, x, args) Modified: pypy/dist/pypy/lang/js/test/ecma/GlobalObject/15.1.2.2-2.js ============================================================================== --- pypy/dist/pypy/lang/js/test/ecma/GlobalObject/15.1.2.2-2.js (original) +++ pypy/dist/pypy/lang/js/test/ecma/GlobalObject/15.1.2.2-2.js Mon Jun 4 15:24:17 2007 @@ -194,7 +194,7 @@ s = "0xFFFFFFFFFFFFFC0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; -s += "0000000000000000000000000000000000000" +s += "0000000000000000000000000000000000000"; new TestCase( SECTION, @@ -210,7 +210,7 @@ -1.7976931348623157e+308, -s ); -s += "0" +s += "0"; new TestCase( SECTION, "s = " + s + "; -s", Modified: pypy/dist/pypy/lang/js/test/ecma/conftest.py ============================================================================== --- pypy/dist/pypy/lang/js/test/ecma/conftest.py (original) +++ pypy/dist/pypy/lang/js/test/ecma/conftest.py Mon Jun 4 15:24:17 2007 @@ -4,6 +4,9 @@ from pypy.rlib.parsing.parsing import ParseError from py.__.test.outcome import Failed, ExceptionFailure import pypy.lang.js as js +from pypy.lang.js import interpreter + +interpreter.TEST = True rootdir = py.magic.autopath().dirpath() exclusionlist = ['shell.js', 'browser.js'] From cfbolz at codespeak.net Mon Jun 4 16:41:33 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 4 Jun 2007 16:41:33 +0200 (CEST) Subject: [pypy-svn] r44027 - pypy/dist/pypy/lang/prolog/interpreter Message-ID: <20070604144133.6FE4B80B2@code0.codespeak.net> Author: cfbolz Date: Mon Jun 4 16:41:32 2007 New Revision: 44027 Modified: pypy/dist/pypy/lang/prolog/interpreter/parsing.py Log: rewrite very strange code used for parsing lists Modified: pypy/dist/pypy/lang/prolog/interpreter/parsing.py ============================================================================== --- pypy/dist/pypy/lang/prolog/interpreter/parsing.py (original) +++ pypy/dist/pypy/lang/prolog/interpreter/parsing.py Mon Jun 4 16:41:32 2007 @@ -323,16 +323,21 @@ return Term(name, children) def build_list(self, node): + result = [] + while node is not None: + node = self._build_list(node, result) + return result + + def _build_list(self, node, result): node = self.find_first_interesting(node) if isinstance(node, Nonterminal): child = node.children[1] if (isinstance(child, Symbol) and node.children[1].additional_info == ","): element = self.visit(node.children[0]) - l = self.build_list(node.children[2]) - l.insert(0, element) - return l - return [self.visit(node)] + result.append(element) + return node.children[2] + result.append(self.visit(node)) def find_first_interesting(self, node): if isinstance(node, Nonterminal) and len(node.children) == 1: From cfbolz at codespeak.net Tue Jun 5 11:19:24 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Tue, 5 Jun 2007 11:19:24 +0200 (CEST) Subject: [pypy-svn] r44037 - pypy/dist/pypy/lang/prolog/builtin Message-ID: <20070605091924.732F880A5@code0.codespeak.net> Author: cfbolz Date: Tue Jun 5 11:19:23 2007 New Revision: 44037 Modified: pypy/dist/pypy/lang/prolog/builtin/register.py Log: attack some more info to builtin functions Modified: pypy/dist/pypy/lang/prolog/builtin/register.py ============================================================================== --- pypy/dist/pypy/lang/prolog/builtin/register.py (original) +++ pypy/dist/pypy/lang/prolog/builtin/register.py Tue Jun 5 11:19:23 2007 @@ -7,8 +7,11 @@ class Builtin(object): _immutable_ = True - def __init__(self, function): + def __init__(self, function, name, numargs, signature): self.function = function + self.name = name + self.numargs = numargs + self.signature = signature def call(self, engine, query, continuation): return self.function(engine, query, continuation) @@ -84,7 +87,8 @@ exec py.code.Source("\n".join(code)).compile() in miniglobals for name in expose_as: signature = "%s/%s" % (name, len(unwrap_spec)) - b = Builtin(miniglobals[funcname]) + b = Builtin(miniglobals[funcname], funcname, len(unwrap_spec), + signature) builtins[signature] = b if signature in [",/2", "is/2"]: builtins_list.insert(0, (signature, b)) From hpk at codespeak.net Tue Jun 5 11:55:20 2007 From: hpk at codespeak.net (hpk at codespeak.net) Date: Tue, 5 Jun 2007 11:55:20 +0200 (CEST) Subject: [pypy-svn] r44040 - pypy/extradoc/talk/dzug2007 Message-ID: <20070605095520.9D2DE809F@code0.codespeak.net> Author: hpk Date: Tue Jun 5 11:55:19 2007 New Revision: 44040 Added: pypy/extradoc/talk/dzug2007/ pypy/extradoc/talk/dzug2007/arch-framework-2.png (contents, props changed) pypy/extradoc/talk/dzug2007/arch-framework.png (contents, props changed) pypy/extradoc/talk/dzug2007/arch-overview.png (contents, props changed) pypy/extradoc/talk/dzug2007/arch-translation.png (contents, props changed) pypy/extradoc/talk/dzug2007/benchmarks-gc.png (contents, props changed) pypy/extradoc/talk/dzug2007/benchmarks.png (contents, props changed) pypy/extradoc/talk/dzug2007/compat-matrix.png (contents, props changed) pypy/extradoc/talk/dzug2007/dynlang.png (contents, props changed) pypy/extradoc/talk/dzug2007/dzug2007.txt pypy/extradoc/talk/dzug2007/interpreterarch.png (contents, props changed) pypy/extradoc/talk/dzug2007/python-arch-overview.png (contents, props changed) pypy/extradoc/talk/dzug2007/stackless_informal.png (contents, props changed) pypy/extradoc/talk/dzug2007/translation-overview.png (contents, props changed) pypy/extradoc/talk/dzug2007/translation.pdf (contents, props changed) pypy/extradoc/talk/dzug2007/translation.png (contents, props changed) pypy/extradoc/talk/dzug2007/ui (contents, props changed) Log: adding dzug talk at its intended place (hopefully i de-messed up things now) Added: pypy/extradoc/talk/dzug2007/arch-framework-2.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/dzug2007/arch-framework.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/dzug2007/arch-overview.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/dzug2007/arch-translation.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/dzug2007/benchmarks-gc.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/dzug2007/benchmarks.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/dzug2007/compat-matrix.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/dzug2007/dynlang.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/dzug2007/dzug2007.txt ============================================================================== --- (empty file) +++ pypy/extradoc/talk/dzug2007/dzug2007.txt Tue Jun 5 11:55:19 2007 @@ -0,0 +1,283 @@ +.. include:: + +=========================================== +How PyPy can be useful for Zope +=========================================== + +:Authors: Holger Krekel (merlinux GmbH) et al. + +What is PyPy? +---------------- + +* A compiler metaprogramming toolchain for dynamic languages + +* A flexible and fast Python Interpreter + +* An open source project (MIT License) + +* A (former) EU research project + +Paradigm +------------- + +.. raw:: html + +
+ +.. image:: arch-overview.png + :align: center + +PyPy Overview +-------------- + +.. raw:: html + +
+ +.. image:: dynlang.png + + + +Backends / Runtime integration +----------------------------------- + +- Main target: C/Posix +- Main new target: .NET/CLI/CLR +- Work in progress: JVM +- Special target: Javascript for Web applications + + +CLR/CLI Backend +---------------- + +- full python interpreter generated for .NET + +- support for CLR integration: + + - static RPython-level bindings + - on top dynamic bindings using reflection (clr module) + +.. - supports interpreter prototypes (using single source) + +More high-level backends +------------------------- + +- emerging JVM target: + + - translates complex RPython programs + - no problems foreseen for full interpreter generation + +- Javascript target: + + - translates complex programs + + +Python Interpreter Prototypes +------------------------------------- + +- features are independent of backend + +- Security / Taint Space + +- Transparent Proxies: + + - Transparent Distribution + - Orthogonal Persistence + + +Taint Space +-------------------- + +- control of information data flow: + + * label sensitive data + * avoid sensitive information leaks + * explicit primitive to declassify + +- easily implemented as an object space around + the standard one securing all operations + on objects + +Taint Space diagram +--------------------- + +.. raw:: html + +
+ +.. image:: interpreterarch.png + +- interactive prompt demo + + + +Transparent Proxies +-------------------------- + +- proxy: intercept any operation on an builtin object +- transparent: don't change object interface +- useful for implementing application level functionality + orthogonally to usage of objects +- is the mechanism for distribution and persistence prototypes +- see also .NET TransparentProxy + +Transparent Distribution +-------------------------- + +- transparent lazy access to remote objects +- internally uses RPC-like protocol +- remote objects are presented through transparent proxies +- access to remote tracebacks, frames, etc. work as if local! + +Orthogonal Persistence +-------------------------- + +- persist Python objects "invisibly" +- interpose interception of changes to objects +- implement your own custom persistence scheme (e.g. using ZODB) + +Threading in PyPy +----------------------- + +- principal choice of os-threading models (GIL, no, ...) +- stackless *transform* / micro-threads: + + - suspending/resuming computations + - pickling/migration of computations + - unlimited recursion + - *composable* greenlets, tasklets, co-routines + +Relative speeds to CPython +------------------------------ + ++----------+-------------------+---------------+ +| | CPython 2.4.4 | pypy-llvm | ++==========+===================+===============+ +| richards | 1.00 | 1.17 | ++----------+-------------------+---------------+ +| pystone | 1.00 | 1.55 | ++----------+-------------------+---------------+ +| templess | 1.00 | 5.41 | ++----------+-------------------+---------------+ +| gadfly | 1.00 | 6.38 | ++----------+-------------------+---------------+ +| mako | 1.00 | 7.65 | ++----------+-------------------+---------------+ + +(March 2007, improvements afterwards) + +JIT Compiler Generator +---------------------------- + +- generate JIT Compilers automatically! + +JIT Compiler Generator +---------------------------- + +- generate JIT Compilers automatically! + +- we began to apply it to the Python Interpreter + (integer arithmetic) + +- approach more complete than Psyco + +- gets us in the range of C-speed ("gcc -O0")! + +Python Interpreter Status (1.0) +--------------------------------- + +- compliant, 340 KLOC / 85 test KLOC +- single source for all platforms +- flexibel, fast, well-tested (11975 tests) +- new middleware features +- need more extension modules! +- better GCs and more JITting will even improve speed! + +Special RPython programs +-------------------------- + +- webservers, web applications, algorithms + +- can be translated to various targets + +- can run up to 100 times faster compared + to being interpreted through CPython + +- very fast startup times! + +- used for commercial purposes + +RPython advantages over C +----------------------------------- + +- portable code +- high level data structures +- easy to test, quick to develop +- translates to various targets, including CPython extension module + +py lib release +---------------------- + +* py lib / py.test 0.9 release (Feb 2007): + + - project independent tool for automated testing + - lightweight no-boilerplate approach + - many development support features for PyPy + - includes distributed testing (started as SOP project) + +Summary (1) +--------------------- + +- with PyPy it is easy to: + + - implement advanced Python Interpreter features + - write new backends / runtime targets + - implement new (non-python) interpreters + +- PyPy's rough edges: it is a research result! + +- emerging as platform to implement dynamic languages + +Summary (2) +------------------------ + +- advantages of PyPy's meta-programming approach: + + - separation of lang implementation aspects + - integrates with today's mainstream platforms + - single source eases maintenance + - all interpreters benefit from advanced transformations + - all code at high abstraction level! + +Possible Zope applications +------------------------------- + +- security + transparent proxies: persistence, distribution +- experiment with RPython to implement + + - Page Template Engine? + - AJAX/Javascript web applications? + - speedy extension modules? +- use for web hosting (fast startup times)? + +Future +--------------- + +- caretaker/trusted contributors group (pypy-ct): + + - takes care for conceptual integrity + - negotiates (sprint) funding + +- pending community process: + + - many directions and interests + - consolidation phase?! + - settle on rough roadmap + +- more sprints! (19 so far) + + +.. |bullet| unicode:: U+02022 +.. footer:: Holger Krekel (merlinux GmbH) + + Added: pypy/extradoc/talk/dzug2007/interpreterarch.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/dzug2007/python-arch-overview.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/dzug2007/stackless_informal.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/dzug2007/translation-overview.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/dzug2007/translation.pdf ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/dzug2007/translation.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/dzug2007/ui ============================================================================== --- (empty file) +++ pypy/extradoc/talk/dzug2007/ui Tue Jun 5 11:55:19 2007 @@ -0,0 +1 @@ +link ../ui \ No newline at end of file From hpk at codespeak.net Tue Jun 5 12:01:37 2007 From: hpk at codespeak.net (hpk at codespeak.net) Date: Tue, 5 Jun 2007 12:01:37 +0200 (CEST) Subject: [pypy-svn] r44041 - pypy/extradoc/talk/dzug2007 Message-ID: <20070605100137.09EB480A5@code0.codespeak.net> Author: hpk Date: Tue Jun 5 12:01:37 2007 New Revision: 44041 Modified: pypy/extradoc/talk/dzug2007/dzug2007.txt Log: fix number of tests Modified: pypy/extradoc/talk/dzug2007/dzug2007.txt ============================================================================== --- pypy/extradoc/talk/dzug2007/dzug2007.txt (original) +++ pypy/extradoc/talk/dzug2007/dzug2007.txt Tue Jun 5 12:01:37 2007 @@ -188,7 +188,7 @@ - compliant, 340 KLOC / 85 test KLOC - single source for all platforms -- flexibel, fast, well-tested (11975 tests) +- flexibel, fast, well-tested (11805 tests) - new middleware features - need more extension modules! - better GCs and more JITting will even improve speed! From hpk at codespeak.net Tue Jun 5 16:16:47 2007 From: hpk at codespeak.net (hpk at codespeak.net) Date: Tue, 5 Jun 2007 16:16:47 +0200 (CEST) Subject: [pypy-svn] r44044 - pypy/extradoc/talk/dzug2007 Message-ID: <20070605141647.C0CD4808E@code0.codespeak.net> Author: hpk Date: Tue Jun 5 16:16:47 2007 New Revision: 44044 Added: pypy/extradoc/talk/dzug2007/dzug2007.html Modified: pypy/extradoc/talk/dzug2007/dzug2007.txt Log: the talk as i gave it (went quite well - but somewhat difficult to do in 30 minutes including demos) Added: pypy/extradoc/talk/dzug2007/dzug2007.html ============================================================================== --- (empty file) +++ pypy/extradoc/talk/dzug2007/dzug2007.html Tue Jun 5 16:16:47 2007 @@ -0,0 +1,637 @@ + + + + + + + +How PyPy could be useful for Zope + + + + + + + + + + + + + + + +
+
+
+ + +
+
+
+

How PyPy could be useful for Zope

+ +++ + + + +
Authors:Holger Krekel (merlinux GmbH) et al.
+ + + + + + + + + +
+
+

What is PyPy?

+
    +
  • A compiler metaprogramming toolchain for dynamic languages
  • +
  • A flexible and fast Python Interpreter
  • +
  • An open source project (MIT License)
  • +
  • A (former) EU research project
  • +
  • -> PyPy-1.0 is a research result
  • +
+
+
+

Paradigm

+
arch-overview.png
+
+
+

PyPy Overview

+
dynlang.png +
+
+

Backends / Runtime integration

+
    +
  • single source program translates to:
      +
    • Main target: C/Posix
    • +
    • Main new target: .NET/CLI/CLR
    • +
    • Work in progress: JVM
    • +
    • Special target: Javascript for Web applications
    • +
    +
  • +
+
+
+

CLR/CLI Backend

+
    +
  • full python interpreter generated for .NET
  • +
  • support for CLR integration:
      +
    • static RPython-level bindings
    • +
    • on top dynamic bindings using reflection (clr module)
    • +
    +
  • +
+ +
+
+

More high-level backends

+
    +
  • emerging JVM target:
      +
    • translates complex RPython programs
    • +
    • no problems foreseen for full interpreter generation
    • +
    +
  • +
  • Javascript target:
      +
    • translates complex programs
    • +
    +
  • +
+
+
+

Python Interpreter Prototypes

+
    +
  • features are independent of backend
  • +
  • Security / Taint Space
  • +
  • Transparent Proxies:
      +
    • Transparent Distribution
    • +
    • Orthogonal Persistence
    • +
    +
  • +
+
+
+

Taint Space

+
    +
  • control of information data flow:
      +
    • label sensitive data
    • +
    • avoid sensitive information leaks
    • +
    • explicit primitive to declassify
    • +
    +
  • +
  • easily implemented as an object space around +the standard one securing all operations +on objects
  • +
+
+
+

Taint Space diagram

+
interpreterarch.png +
    +
  • interactive prompt demo
  • +
+
+
+

Transparent Proxies

+
    +
  • proxy: intercept any operation on an builtin object
  • +
  • transparent: don't change object interface
  • +
  • useful for implementing application level functionality +orthogonally to usage of objects
  • +
  • is the mechanism for distribution and persistence prototypes
  • +
  • see also .NET TransparentProxy
  • +
+
+
+

Transparent Distribution

+
    +
  • transparent lazy access to remote objects
  • +
  • internally uses RPC-like protocol
  • +
  • remote objects are presented through transparent proxies
  • +
  • access to remote tracebacks, frames, etc. work as if local!
  • +
+
+
+

Orthogonal Persistence

+
    +
  • persist Python objects "invisibly"
  • +
  • interpose interception of changes to objects
  • +
  • implement your own custom persistence scheme (e.g. using ZODB)
  • +
+
+
+

Threading in PyPy

+
    +
  • principal choice of os-threading models (GIL, no, ...)
  • +
  • stackless transform / micro-threads:
      +
    • suspending/resuming computations
    • +
    • pickling/migration of computations
    • +
    • unlimited recursion
    • +
    • composable greenlets, tasklets, co-routines
    • +
    +
  • +
+
+
+

Relative speeds to CPython

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 CPython 2.4.4pypy-llvm
richards1.001.17
pystone1.001.55
templess1.005.41
gadfly1.006.38
mako1.007.65
+

(March 2007, improvements afterwards)

+
+
+

JIT Compiler Generator

+
    +
  • generate JIT Compilers automatically!
  • +
+
+
+

JIT Compiler Generator

+
    +
  • generate JIT Compilers automatically!
  • +
  • we began to apply it to the Python Interpreter +(integer arithmetic)
  • +
  • approach more complete than Psyco
  • +
  • gets us in the range of C-speed ("gcc -O0")!
  • +
+
+
+

Python Interpreter Status (1.0)

+
    +
  • compliant, 340 KLOC / 85 test KLOC
  • +
  • single source for all platforms
  • +
  • flexibel, fast, well-tested (11805 tests)
  • +
  • new middleware features
  • +
  • need more extension modules!
  • +
  • better GCs and more JITting will even improve speed!
  • +
+
+
+

Special RPython programs

+
    +
  • webservers, web applications, algorithms
  • +
  • can be translated to many targets
  • +
  • can run up to 100 times faster compared +to being interpreted through CPython
  • +
  • very fast startup times!
  • +
  • used for commercial purposes
  • +
+
+
+

RPython advantages over C

+
    +
  • portable code
  • +
  • high level data structures
  • +
  • easy to test, quick to develop
  • +
  • translates to various targets, including CPython extension module
  • +
+
+
+

py lib release

+
    +
  • py lib / py.test 0.9 release (Feb 2007):
      +
    • project independent tool for automated testing
    • +
    • lightweight no-boilerplate approach
    • +
    • many development support features for PyPy
    • +
    • includes distributed testing (started as SOP project)
    • +
    +
  • +
+
+
+

Summary (1)

+
    +
  • with PyPy it is easy to:
      +
    • implement advanced Python Interpreter features
    • +
    • write new backends / runtime targets
    • +
    • implement new (non-python) interpreters
    • +
    +
  • +
  • PyPy's rough edges: it is a research result!
  • +
  • emerging as platform to implement dynamic languages
  • +
+
+
+

Summary (2)

+
    +
  • advantages of PyPy's meta-programming approach:
      +
    • separation of lang implementation aspects
    • +
    • integrates with today's mainstream platforms
    • +
    • single source eases maintenance
    • +
    • all interpreters benefit from advanced transformations
    • +
    • all code at high abstraction level!
    • +
    +
  • +
+
+
+

Possible Zope applications

+
    +
  • security + transparent proxies: persistence, distribution
  • +
  • experiment with RPython to implement
      +
    • Page Template Engine?
    • +
    • AJAX/Javascript web applications?
    • +
    • speedy extension modules?
    • +
    +
  • +
  • use for web hosting (fast startup times)?
  • +
  • synchronous instead of callback/event programming?
  • +
+
+
+

Future

+
    +
  • caretaker/trusted contributors group (pypy-ct):
      +
    • takes care for conceptual integrity
    • +
    • negotiates (sprint) funding
    • +
    +
  • +
  • pending community process:
      +
    • many directions and interests
    • +
    • consolidation phase?!
    • +
    • settle on rough roadmap
    • +
    +
  • +
  • more sprints! (19 so far)
  • +
+
+
+ + Modified: pypy/extradoc/talk/dzug2007/dzug2007.txt ============================================================================== --- pypy/extradoc/talk/dzug2007/dzug2007.txt (original) +++ pypy/extradoc/talk/dzug2007/dzug2007.txt Tue Jun 5 16:16:47 2007 @@ -1,7 +1,7 @@ .. include:: =========================================== -How PyPy can be useful for Zope +How PyPy could be useful for Zope =========================================== :Authors: Holger Krekel (merlinux GmbH) et al. @@ -17,6 +17,8 @@ * A (former) EU research project +* -> PyPy-1.0 is a research result + Paradigm ------------- @@ -41,10 +43,12 @@ Backends / Runtime integration ----------------------------------- -- Main target: C/Posix -- Main new target: .NET/CLI/CLR -- Work in progress: JVM -- Special target: Javascript for Web applications +- single source program translates to: + + - Main target: C/Posix + - Main new target: .NET/CLI/CLR + - Work in progress: JVM + - Special target: Javascript for Web applications CLR/CLI Backend @@ -90,7 +94,7 @@ - control of information data flow: - * label sensitive data + * label sensitive data * avoid sensitive information leaks * explicit primitive to declassify @@ -198,7 +202,7 @@ - webservers, web applications, algorithms -- can be translated to various targets +- can be translated to many targets - can run up to 100 times faster compared to being interpreted through CPython @@ -259,6 +263,7 @@ - AJAX/Javascript web applications? - speedy extension modules? - use for web hosting (fast startup times)? +- synchronous instead of callback/event programming? Future --------------- From fijal at codespeak.net Tue Jun 5 18:06:17 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 5 Jun 2007 18:06:17 +0200 (CEST) Subject: [pypy-svn] r44045 - in pypy/branch/kill-ctypes/pypy/annotation: . test Message-ID: <20070605160617.87A6A809A@code0.codespeak.net> Author: fijal Date: Tue Jun 5 18:06:15 2007 New Revision: 44045 Added: pypy/branch/kill-ctypes/pypy/annotation/test/test_signature.py Modified: pypy/branch/kill-ctypes/pypy/annotation/signature.py Log: Split annotation() into two steps, providing a way of caching annotations with bookkeeper=None, also killing some hacks Modified: pypy/branch/kill-ctypes/pypy/annotation/signature.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/annotation/signature.py (original) +++ pypy/branch/kill-ctypes/pypy/annotation/signature.py Tue Jun 5 18:06:15 2007 @@ -7,13 +7,38 @@ from pypy.annotation.listdef import ListDef, MOST_GENERAL_LISTDEF from pypy.annotation.dictdef import DictDef, MOST_GENERAL_DICTDEF +_annotation_cache = {} + +def _annotation_key(t): + from pypy.rpython import extregistry + if type(t) is list: + assert len(t) == 1 + return ('list', _annotation_key(t[0])) + elif type(t) is dict: + assert len(t.keys()) == 1 + return ('dict', _annotation_key(t.items()[0])) + elif isinstance(t, tuple): + return tuple([_annotation_key(i) for i in t]) + elif extregistry.is_registered(t): + # XXX should it really be always different? + return t + return t + def annotation(t, bookkeeper=None): + if bookkeeper is None: + key = _annotation_key(t) + try: + return _annotation_cache[key] + except KeyError: + t = _compute_annotation(t, bookkeeper) + _annotation_cache[key] = t + return t + return _compute_annotation(t, bookkeeper) + +def _compute_annotation(t, bookkeeper=None): from pypy.rpython.lltypesystem import lltype from pypy.annotation.bookkeeper import getbookkeeper from pypy.rpython import extregistry - if bookkeeper is None: - bookkeeper = getbookkeeper() - if isinstance(t, SomeObject): return t elif isinstance(t, lltype.LowLevelType): @@ -25,7 +50,6 @@ elif isinstance(t, tuple): return SomeTuple(tuple([annotation(i) for i in t])) elif isinstance(t, dict): - assert bookkeeper assert len(t) == 1, "We do not support type joining in dict" result = SomeDict(DictDef(bookkeeper, annotation(t.keys()[0]), annotation(t.values()[0]))) Added: pypy/branch/kill-ctypes/pypy/annotation/test/test_signature.py ============================================================================== --- (empty file) +++ pypy/branch/kill-ctypes/pypy/annotation/test/test_signature.py Tue Jun 5 18:06:15 2007 @@ -0,0 +1,9 @@ + +from pypy.annotation.signature import _annotation_key + +def test__annotation_key(): + assert _annotation_key([[str]]) == ('list', ('list', str)) + assert _annotation_key({str:(str, [str])}) == ('dict', (str, (str, ('list', str)))) + for i in ([[str]], [str], (int, int, {str: [str]})): + assert hash(_annotation_key(i)) + From fijal at codespeak.net Tue Jun 5 18:07:44 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 5 Jun 2007 18:07:44 +0200 (CEST) Subject: [pypy-svn] r44046 - in pypy/branch/kill-ctypes/pypy/rpython: . test Message-ID: <20070605160744.AB8C6809A@code0.codespeak.net> Author: fijal Date: Tue Jun 5 18:07:44 2007 New Revision: 44046 Modified: pypy/branch/kill-ctypes/pypy/rpython/extfunc.py pypy/branch/kill-ctypes/pypy/rpython/test/test_extfunc.py Log: Kill XXX: obviously dangerous hack Modified: pypy/branch/kill-ctypes/pypy/rpython/extfunc.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/extfunc.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/extfunc.py Tue Jun 5 18:07:44 2007 @@ -2,7 +2,6 @@ from pypy.rpython.lltypesystem.lltype import typeOf from pypy.objspace.flow.model import Constant from pypy.annotation.model import unionof -from pypy.annotation.listdef import TooLateForChange from pypy.annotation.signature import annotation import py @@ -27,26 +26,15 @@ class ExtFuncEntry(ExtRegistryEntry): def compute_result_annotation(self, *args_s): - bookkeeper = self.bookkeeper - if self.signature_args is None: - signature_args = None - else: - signature_args = [annotation(arg, bookkeeper) - for arg in self.signature_args] - signature_result = annotation(self.signature_result, bookkeeper) if hasattr(self, 'ann_hook'): self.ann_hook() - if signature_args is not None: - assert len(args_s) == len(signature_args),\ + if self.signature_args is not None: + assert len(args_s) == len(self.signature_args),\ "Argument number mismatch" - for arg, expected in zip(args_s, signature_args): + for arg, expected in zip(args_s, self.signature_args): arg = unionof(arg, expected) assert expected.contains(arg) - # XXX: obviously very very dangerous hack. I need - # to reconsifder it a bit, invalidate and so on - self.__class__.signature_args = signature_args - self.__class__.signature_result = signature_result - return signature_result + return self.signature_result def specialize_call(self, hop): rtyper = hop.rtyper @@ -56,7 +44,7 @@ iter_args = self.signature_args args_r = [rtyper.getrepr(s_arg) for s_arg in iter_args] args_ll = [r_arg.lowleveltype for r_arg in args_r] - r_result = rtyper.getrepr(self.signature_result) + r_result = rtyper.getrepr(hop.s_result) ll_result = r_result.lowleveltype name = getattr(self, 'name', None) or self.instance.__name__ method_name = rtyper.type_system.name[:2] + 'typeimpl' @@ -65,8 +53,7 @@ fakeimpl = getattr(self, fake_method_name, self.instance) if impl: obj = rtyper.getannmixlevel().delayedfunction( - impl, self.signature_args, - self.signature_result) + impl, self.signature_args, hop.s_result) else: obj = rtyper.type_system.getexternalcallable(args_ll, ll_result, name, _external_name=self.name, _callable=fakeimpl) @@ -90,13 +77,11 @@ class FunEntry(ExtFuncEntry): _about_ = function - #if args is None: - # signature_args = None - #else: - # signature_args = [annotation(arg, None) for arg in args] - #signature_result = annotation(result, None) - signature_args = args - signature_result = result + if args is None: + signature_args = None + else: + signature_args = [annotation(arg, None) for arg in args] + signature_result = annotation(result, None) name=export_name if llimpl: lltypeimpl = staticmethod(llimpl) Modified: pypy/branch/kill-ctypes/pypy/rpython/test/test_extfunc.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/test/test_extfunc.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/test/test_extfunc.py Tue Jun 5 18:07:44 2007 @@ -116,6 +116,29 @@ # Not a very good assertion, but at least it means _something_ happened. assert isinstance(s, annmodel.SomeInteger) +def function_with_list(): + pass +register_external(function_with_list, [[int]], int) + +def function_returning_list(): + pass +register_external(function_returning_list, [], [int]) + +def test_register_external_return_goes_back(): + """ + Check whether it works to pass the same list from one external + fun to another + [bookkeeper and list joining issues] + """ + def f(): + return function_with_list(function_returning_list()) + + policy = AnnotatorPolicy() + policy.allow_someobjects = False + a = RPythonAnnotator(policy=policy) + s = a.build_types(f, []) + assert isinstance(s, annmodel.SomeInteger) + def function_withspecialcase(arg): return repr(arg) register_external(function_withspecialcase, args=None, result=str) From mwh at codespeak.net Tue Jun 5 21:34:18 2007 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 5 Jun 2007 21:34:18 +0200 (CEST) Subject: [pypy-svn] r44047 - pypy/extradoc/talk/pycon2007 Message-ID: <20070605193418.74077809C@code0.codespeak.net> Author: mwh Date: Tue Jun 5 21:34:17 2007 New Revision: 44047 Added: pypy/extradoc/talk/pycon2007/pycon07.ppt (contents, props changed) Log: ppt for anto Added: pypy/extradoc/talk/pycon2007/pycon07.ppt ============================================================================== Binary file. No diff available. From gotcha at codespeak.net Wed Jun 6 11:38:31 2007 From: gotcha at codespeak.net (gotcha at codespeak.net) Date: Wed, 6 Jun 2007 11:38:31 +0200 (CEST) Subject: [pypy-svn] r44051 - pypy/dist/pypy/rpython/rctypes/tool Message-ID: <20070606093831.02C6880C7@code0.codespeak.net> Author: gotcha Date: Wed Jun 6 11:38:30 2007 New Revision: 44051 Modified: pypy/dist/pypy/rpython/rctypes/tool/compilemodule.py Log: allow to compile modules elsewhere than in pypy.module Modified: pypy/dist/pypy/rpython/rctypes/tool/compilemodule.py ============================================================================== --- pypy/dist/pypy/rpython/rctypes/tool/compilemodule.py (original) +++ pypy/dist/pypy/rpython/rctypes/tool/compilemodule.py Wed Jun 6 11:38:30 2007 @@ -72,10 +72,15 @@ return driver.cbuilder.c_ext_module def main(argv): - if len(argv) != 2: + argvCount = len(argv) + if argvCount < 2 or argvCount > 4: print >> sys.stderr, __doc__ sys.exit(2) - c_ext_module = compilemodule(argv[1], interactive=True) + elif len(argv) == 2: + c_ext_module = compilemodule(argv[1], interactive=True) + elif len(argv) == 3: + basepath = argv[2] + c_ext_module = compilemodule(argv[1], interactive=True, basepath=basepath) print 'Created %r.' % (c_ext_module.__file__,) From fijal at codespeak.net Wed Jun 6 15:37:22 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Wed, 6 Jun 2007 15:37:22 +0200 (CEST) Subject: [pypy-svn] r44052 - pypy/branch/kill-ctypes/pypy/annotation Message-ID: <20070606133722.981D980CF@code0.codespeak.net> Author: fijal Date: Wed Jun 6 15:37:21 2007 New Revision: 44052 Modified: pypy/branch/kill-ctypes/pypy/annotation/builtin.py pypy/branch/kill-ctypes/pypy/annotation/classdef.py Log: force termios.error to be of a certain shape Modified: pypy/branch/kill-ctypes/pypy/annotation/builtin.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/annotation/builtin.py (original) +++ pypy/branch/kill-ctypes/pypy/annotation/builtin.py Wed Jun 6 15:37:21 2007 @@ -264,6 +264,9 @@ def OSError_init(s_self, *args): pass +def termios_error_init(s_self, *args): + pass + def object_init(s_self, *args): # ignore - mostly used for abstract classes initialization pass Modified: pypy/branch/kill-ctypes/pypy/annotation/classdef.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/annotation/classdef.py (original) +++ pypy/branch/kill-ctypes/pypy/annotation/classdef.py Wed Jun 6 15:37:21 2007 @@ -4,7 +4,8 @@ from __future__ import generators from pypy.annotation.model import SomePBC, s_ImpossibleValue, unionof -from pypy.annotation.model import SomeInteger, isdegenerated +from pypy.annotation.model import SomeInteger, isdegenerated, SomeTuple,\ + SomeString from pypy.annotation import description @@ -447,3 +448,12 @@ FORCE_ATTRIBUTES_INTO_CLASSES = { OSError: {'errno': SomeInteger()}, } + +try: + import termios +except ImportError: + pass +else: + FORCE_ATTRIBUTES_INTO_CLASSES[termios.error] = \ + {'args': SomeTuple([SomeInteger(), SomeString()])} + From fijal at codespeak.net Wed Jun 6 15:37:56 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Wed, 6 Jun 2007 15:37:56 +0200 (CEST) Subject: [pypy-svn] r44053 - pypy/branch/kill-ctypes/pypy/rpython/module Message-ID: <20070606133756.0DB4780CF@code0.codespeak.net> Author: fijal Date: Wed Jun 6 15:37:56 2007 New Revision: 44053 Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py Log: Kill bunch of hacks, as we've got annotation support for termios.error Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py Wed Jun 6 15:37:56 2007 @@ -22,6 +22,11 @@ SPEED_T = rffi.UINT INT = rffi.INT +def termios_error_init(self, num, msg): + self.args = (num, msg) + +termios.error.__init__ = termios_error_init + includes = ['termios.h', 'unistd.h'] TERMIOSP = rffi.CStruct('termios', ('c_iflag', TCFLAG_T), ('c_oflag', TCFLAG_T), @@ -42,16 +47,16 @@ c_tcflush = c_external('tcflush', [INT, INT], INT) c_tcflow = c_external('tcflow', [INT, INT], INT) -class termios_error(termios.error): - def __init__(self, num, msg): - self.args = (num, msg) +#class termios_error(termios.error): +# def __init__(self, num, msg): +# self.args = (num, msg) def tcgetattr_llimpl(fd): c_struct = lltype.malloc(TERMIOSP.TO, flavor='raw') error = c_tcgetattr(fd, c_struct) try: if error == -1: - raise termios_error(error, 'tcgetattr failed') + raise termios.error(error, 'tcgetattr failed') cc = [chr(c_struct.c_c_cc[i]) for i in range(NCCS)] ispeed = c_cfgetispeed(c_struct) ospeed = c_cfgetospeed(c_struct) @@ -74,13 +79,13 @@ c_struct.c_c_cc[i] = rffi.r_uchar(ord(cc[i])) error = c_cfsetispeed(c_struct, ispeed) if error == -1: - raise termios_error(error, 'tcsetattr failed') + raise termios.error(error, 'tcsetattr failed') error = c_cfsetospeed(c_struct, ospeed) if error == -1: - raise termios_error(error, 'tcsetattr failed') + raise termios.error(error, 'tcsetattr failed') error = c_tcsetattr(fd, when, c_struct) if error == -1: - raise termios_error(error, 'tcsetattr failed') + raise termios.error(error, 'tcsetattr failed') finally: lltype.free(c_struct, flavor='raw') @@ -94,7 +99,7 @@ def tcsendbreak_llimpl(fd, duration): error = c_tcsendbreak(fd, duration) if error == -1: - raise termios_error(error, 'tcsendbreak failed') + raise termios.error(error, 'tcsendbreak failed') register_external(termios.tcsendbreak, [int, int], llimpl=tcsendbreak_llimpl, export_name='termios.tcsendbreak') @@ -102,20 +107,20 @@ def tcdrain_llimpl(fd): error = c_tcdrain(fd) if error == -1: - raise termios_error(error, 'tcdrain failed') + raise termios.error(error, 'tcdrain failed') register_external(termios.tcdrain, [int], llimpl=tcdrain_llimpl, export_name='termios.tcdrain') def tcflush_llimpl(fd, queue_selector): error = c_tcflush(fd, queue_selector) if error == -1: - raise termios_error(error, 'tcflush failed') + raise termios.error(error, 'tcflush failed') register_external(termios.tcflush, [int, int], llimpl=tcflush_llimpl, export_name='termios.tcflush') def tcflow_llimpl(fd, action): error = c_tcflow(fd, action) if error == -1: - raise termios_error(error, 'tcflow failed') + raise termios.error(error, 'tcflow failed') register_external(termios.tcflow, [int, int], llimpl=tcflow_llimpl, export_name='termios.tcflow') From fijal at codespeak.net Wed Jun 6 15:41:44 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Wed, 6 Jun 2007 15:41:44 +0200 (CEST) Subject: [pypy-svn] r44054 - in pypy/branch/kill-ctypes/pypy/module/termios: . test Message-ID: <20070606134144.E471180CF@code0.codespeak.net> Author: fijal Date: Wed Jun 6 15:41:44 2007 New Revision: 44054 Modified: pypy/branch/kill-ctypes/pypy/module/termios/__init__.py pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py Log: insanity-- kill some hacks regarding termios.error Modified: pypy/branch/kill-ctypes/pypy/module/termios/__init__.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/termios/__init__.py (original) +++ pypy/branch/kill-ctypes/pypy/module/termios/__init__.py Wed Jun 6 15:41:44 2007 @@ -1,7 +1,6 @@ from pypy.interpreter.mixedmodule import MixedModule import termios -from pypy.rpython.module.ll_termios import termios_error from pypy.rlib.nonconst import NonConstant class Module(MixedModule): @@ -28,13 +27,6 @@ 'tcsetattr' : 'interp_termios.tcsetattr', } - def startup(self, space): - # XXX nasty annotation trick - try: - raise termios_error(NonConstant(-3), NonConstant("xxx")) - except termios.error, e: - pass - import termios from pypy.module.termios import interp_termios Modified: pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py (original) +++ pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py Wed Jun 6 15:41:44 2007 @@ -5,30 +5,30 @@ from pypy.tool.autopath import pypydir from pypy.tool.udir import udir -def setup_module(mod): - try: - import pexpect - mod.pexpect = pexpect - except ImportError: - py.test.skip("Pexpect not found") - try: - import termios - mod.termios = termios - except ImportError: - py.test.skip("termios not found") - py_py = py.path.local(pypydir).join('bin', 'py.py') - assert py_py.check() - mod.py_py = py_py - class TestTermios(object): + def setup_class(cls): + try: + import pexpect + except ImportError: + py.test.skip("Pexpect not found") + try: + import termios + except ImportError: + py.test.skip("termios not found") + py_py = py.path.local(pypydir).join('bin', 'py.py') + assert py_py.check() + cls.py_py = py_py + cls.termios = termios + cls.pexpect = pexpect + def _spawn(self, *args, **kwds): print 'SPAWN:', args, kwds - child = pexpect.spawn(*args, **kwds) + child = self.pexpect.spawn(*args, **kwds) child.logfile = sys.stdout return child def spawn(self, argv): - return self._spawn(sys.executable, [str(py_py)] + argv) + return self._spawn(sys.executable, [str(self.py_py)] + argv) def test_one(self): child = self.spawn(['--withmod-termios']) @@ -71,10 +71,24 @@ child = self.spawn(['--withmod-termios', str(f)]) child.expect('ok!') + def test_ioctl_termios(self): + source = py.code.Source(""" + import termios + import fcntl + lgt = len(fcntl.ioctl(2, termios.TIOCGWINSZ, '\000'*8)) + assert lgt == 8 + print 'ok!' + """) + f = udir.join("test_ioctl_termios.py") + f.write(source) + child = self.spawn(['--withmod-termios', '--withmod-fcntl', str(f)]) + child.expect('ok!') + class AppTestTermios(object): def setup_class(cls): cls.space = gettestobjspace(usemodules=['termios']) d = {} + import termios for name in dir(termios): val = getattr(termios, name) if name.isupper() and type(val) is int: From fijal at codespeak.net Wed Jun 6 16:11:48 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Wed, 6 Jun 2007 16:11:48 +0200 (CEST) Subject: [pypy-svn] r44056 - pypy/branch/kill-ctypes/pypy/module/_curses Message-ID: <20070606141148.46C1680CD@code0.codespeak.net> Author: fijal Date: Wed Jun 6 16:11:47 2007 New Revision: 44056 Modified: pypy/branch/kill-ctypes/pypy/module/_curses/__init__.py pypy/branch/kill-ctypes/pypy/module/_curses/fficurses.py pypy/branch/kill-ctypes/pypy/module/_curses/interp_curses.py Log: Kill another hack Modified: pypy/branch/kill-ctypes/pypy/module/_curses/__init__.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/_curses/__init__.py (original) +++ pypy/branch/kill-ctypes/pypy/module/_curses/__init__.py Wed Jun 6 16:11:47 2007 @@ -21,13 +21,6 @@ 'tparm' : 'interp_curses.tparm', } - def startup(self, space): - # XXX nasty annotation trick - try: - raise interp_curses.curses_error(NonConstant("xxx")) - except _curses.error, e: - pass - import _curses for i in dir(_curses): val = getattr(_curses, i) Modified: pypy/branch/kill-ctypes/pypy/module/_curses/fficurses.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/_curses/fficurses.py (original) +++ pypy/branch/kill-ctypes/pypy/module/_curses/fficurses.py Wed Jun 6 16:11:47 2007 @@ -93,7 +93,7 @@ l[7], l[8], l[9]) lltype.free(ll_s, flavor='raw') # XXX - how to make this happy? - # lltype.free(ll_res, flavor.raw) + #lltype.free(ll_res, flavor.raw) return rffi.charp2str(ll_res) register_external(interp_curses._curses_tparm, [str, [int]], str, Modified: pypy/branch/kill-ctypes/pypy/module/_curses/interp_curses.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/_curses/interp_curses.py (original) +++ pypy/branch/kill-ctypes/pypy/module/_curses/interp_curses.py Wed Jun 6 16:11:47 2007 @@ -10,12 +10,18 @@ module_info = ModuleInfo() -class curses_error(_curses.error): +class curses_error(Exception): def __init__(self, msg): - self.args = [msg] + self.msg = msg + +from pypy.annotation.classdef import FORCE_ATTRIBUTES_INTO_CLASSES +from pypy.annotation.model import SomeString + +# this is necessary due to annmixlevel +FORCE_ATTRIBUTES_INTO_CLASSES[curses_error] = {'msg': SomeString()} def convert_error(space, error): - msg = error.args[0] + msg = error.msg w_module = space.getbuiltinmodule('_curses') w_exception_class = space.getattr(w_module, space.wrap('error')) w_exception = space.call_function(w_exception_class, space.wrap(msg)) @@ -23,11 +29,17 @@ def _curses_setupterm_null(fd): # NOT_RPYTHON - _curses.setupterm(None, fd) + try: + _curses.setupterm(None, fd) + except _curses.error, e: + raise curses_error(e.args[0]) def _curses_setupterm(termname, fd): # NOT_RPYTHON - _curses.setupterm(termname, fd) + try: + _curses.setupterm(termname, fd) + except _curses.error, e: + raise curses_error(e.args[0]) def setupterm(space, w_termname=None, fd=-1): if fd == -1: @@ -40,7 +52,7 @@ _curses_setupterm_null(fd) else: _curses_setupterm(space.str_w(w_termname), fd) - except _curses.error, e: + except curses_error, e: raise convert_error(space, e) setupterm.unwrap_spec = [ObjSpace, W_Root, int] @@ -49,21 +61,27 @@ def _curses_tigetstr(capname): # NOT_RPYTHON - res = _curses.tigetstr(capname) + try: + res = _curses.tigetstr(capname) + except _curses.error, e: + raise curses_error(e.args[0]) if res is None: raise TermError return res def _curses_tparm(s, args): # NOT_RPYTHON - return _curses.tparm(s, *args) + try: + return _curses.tparm(s, *args) + except _curses.error, e: + raise curses_error(e.args[0]) def tigetstr(space, capname): try: result = _curses_tigetstr(capname) except TermError: return space.w_None - except _curses.error, e: + except curses_error, e: raise convert_error(space, e) return space.wrap(result) tigetstr.unwrap_spec = [ObjSpace, str] @@ -72,6 +90,6 @@ args = [space.int_w(a) for a in args_w] try: return space.wrap(_curses_tparm(s, args)) - except _curses.error, e: + except curses_error, e: raise convert_error(space, e) tparm.unwrap_spec = [ObjSpace, str, 'args_w'] From cfbolz at codespeak.net Thu Jun 7 00:58:56 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 00:58:56 +0200 (CEST) Subject: [pypy-svn] r44058 - pypy/dist/pypy/lang/prolog/interpreter/test Message-ID: <20070606225856.051F780F6@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 00:58:56 2007 New Revision: 44058 Modified: pypy/dist/pypy/lang/prolog/interpreter/test/test_builtin.py Log: slightly bizarre failing test. should pass, though Modified: pypy/dist/pypy/lang/prolog/interpreter/test/test_builtin.py ============================================================================== --- pypy/dist/pypy/lang/prolog/interpreter/test/test_builtin.py (original) +++ pypy/dist/pypy/lang/prolog/interpreter/test/test_builtin.py Thu Jun 7 00:58:56 2007 @@ -195,6 +195,16 @@ """) assert_true("f(20).", e) +def test_call_cut(): + py.test.skip("cuts don't work properly in the presence of calls right now") + e = get_engine(""" + f(X) :- call(X). + f(!). + """) + heaps = collect_all(e, "f(!).") + assert len(heaps) == 1 + + def test_term_construction(): assert_true("g(a, b, c) =.. [G, A, B, C].") assert_true("g(a, b, c) =.. [g, a, b, c].") From cfbolz at codespeak.net Thu Jun 7 01:03:30 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 01:03:30 +0200 (CEST) Subject: [pypy-svn] r44059 - pypy/branch/prolog-bytecode Message-ID: <20070606230330.379F080F6@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 01:03:29 2007 New Revision: 44059 Added: pypy/branch/prolog-bytecode/ - copied from r44058, pypy/dist/ Log: create a branch for experimenting with using a bytecode interpreter for interpreting Prolog. From cfbolz at codespeak.net Thu Jun 7 01:09:20 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 01:09:20 +0200 (CEST) Subject: [pypy-svn] r44060 - in pypy/dist/pypy/lang/prolog/interpreter: . test Message-ID: <20070606230920.29FCD80F6@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 01:09:19 2007 New Revision: 44060 Added: pypy/dist/pypy/lang/prolog/interpreter/compiler.py (contents, props changed) pypy/dist/pypy/lang/prolog/interpreter/test/test_compiler.py Log: start of the compiler Added: pypy/dist/pypy/lang/prolog/interpreter/compiler.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/lang/prolog/interpreter/compiler.py Thu Jun 7 01:09:19 2007 @@ -0,0 +1,130 @@ +from pypy.lang.prolog.interpreter.term import NonVar, Term, Var +from pypy.lang.prolog.interpreter.engine import Continuation +from pypy.lang.prolog.interpreter import helper, error +from pypy.lang.prolog.interpreter.prologopcode import opcodedesc +from pypy.rlib.objectmodel import we_are_translated +from pypy.rlib.jit import hint, we_are_jitted + + +class Code(object): + _immutable_ = True + def __init__(self): + self.term_info = [] # tuples of (functor, numargs, signature) + self.opcode_head = "" + self.opcode = "" + self.constants = [] # list of ground Prolog objects + self.maxlocalvar = 0 + + +def compile(head, body, engine): + comp = Compiler(engine) + return comp.compile(head, body) + +class Compiler(object): + def __init__(self, engine): + self.engine = engine + + def compile(self, head, body): + self.term_info = [] # tuples of (functor, numargs, signature) + self.term_info_map = {} + self.opcode = [] + self.constants = [] # list of ground Prolog objects + self.constant_map = {} + self.maxlocalvar = 0 + self.varmap = {} + result = Code() + self.compile_termbuilding(head) + self.emit_opcode(opcodedesc.UNIFY) + result.opcode_head = self.getbytecode() + if body is not None: + self.compile_body(body) + result.opcode = self.getbytecode() + result.constants = self.constants + result.term_info = self.term_info + result.maxlocalvar = len(self.varmap) + return result + + def compile_termbuilding(self, term): + if helper.is_ground(term, self.engine): + num = self.getconstnum(term) + self.emit_opcode(opcodedesc.PUTCONSTANT, num) + elif isinstance(term, Var): + num = self.getvarnum(term) + self.emit_opcode(opcodedesc.PUTLOCALVAR, num) + else: + assert isinstance(term, Term) + for arg in term.args: + self.compile_termbuilding(arg) + num = self.getsignum(term) + self.emit_opcode(opcodedesc.MAKETERM, num) + + def compile_body(self, body): + from pypy.lang.prolog.builtin import builtins_list, builtins_index + + body = body.dereference(self.engine.heap) + if isinstance(body, Var): + self.compile_termbuilding(body) + self.emit_opcode(opcodedesc.DYNAMIC_CALL) + return + body = helper.ensure_callable(body) + if isinstance(body, Term): + if body.signature == ",/2": + self.compile_body(body.args[0]) + self.compile_body(body.args[1]) + return + if body.signature == "=/2": + self.compile_termbuilding(body.args[0]) + self.compile_termbuilding(body.args[1]) + self.emit_opcode(opcodedesc.UNIFY) + elif body.signature == "call/1": #XXX interactions with cuts correct? + self.compile_body(body.args[0]) + elif body.signature in builtins_index: + i = builtins_index[body.signature] + self.compile_termbuilding(body) + self.emit_opcode(opcodedesc.CALL_BUILTIN, i) + else: + self.compile_termbuilding(body) + self.emit_opcode(opcodedesc.DYNAMIC_CALL) + + def emit_opcode(self, desc, arg=-1): + self.opcode.append(desc.index) + if desc.hasargument: + if not 0 <= arg < 65536: + raise error.UncatchableError("too many constants or variables!") + self.opcode.append(arg >> 8) + self.opcode.append(arg & 0xff) + + def getbytecode(self): + bytecodes = [chr(c) for c in self.opcode] + self.opcode = [] + return "".join(bytecodes) + + + def getvarnum(self, var): + try: + return self.varmap[var] + except KeyError: + result = self.varmap[var] = len(self.varmap) + return result + + def getsignum(self, term): + try: + return self.term_info_map[term.signature] + except KeyError: + result = len(self.term_info_map) + self.term_info_map[term.signature] = result + self.term_info.append((term.name, len(term.args), term.signature)) + return result + + def getconstnum(self, const): + try: + return self.constant_map[const] + except KeyError: + result = len(self.constant_map) + self.constant_map[const] = result + self.constants.append(const) + return result + + self.constants.append(term.getvalue(self.engine.heap)) + + Added: pypy/dist/pypy/lang/prolog/interpreter/test/test_compiler.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/lang/prolog/interpreter/test/test_compiler.py Thu Jun 7 01:09:19 2007 @@ -0,0 +1,57 @@ +from pypy.lang.prolog.interpreter.compiler import compile +from pypy.lang.prolog.interpreter.term import Atom, Var, Term +from pypy.lang.prolog.interpreter.parsing import get_engine, get_query_and_vars + +def test_simple(): + e = get_engine("") + foo = Atom("foo") + code = compile(foo, None, e) + assert not code.opcode + assert code.opcode_head == "c\x00\x00U" + assert code.constants == [foo] + +def test_simple_withbody(): + e = get_engine("") + foo = Atom("foo") + bar = Atom("bar") + code = compile(foo, bar, e) + assert code.opcode_head == "c\x00\x00U" + assert code.opcode == "c\x00\x01D" + assert code.constants == [foo, bar] + +def test_simple_withargs(): + e = get_engine("") + head, body = get_query_and_vars("f(X) :- g(X).")[0].args + code = compile(head, body, e) + assert code.opcode_head == "l\x00\x00t\x00\x00U" + assert code.opcode == "l\x00\x00t\x00\x01D" + assert code.constants == [] + assert code.term_info == [("f", 1, "f/1"), ("g", 1, "g/1")] + +def test_simple_and(): + e = get_engine("") + head, body = get_query_and_vars("f(X, Y) :- g(X), h(Y).")[0].args + code = compile(head, body, e) + assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00U" + assert code.opcode == "l\x00\x00t\x00\x01Dl\x00\x01t\x00\x02D" + assert code.constants == [] + assert code.term_info == [("f", 2, "f/2"), ("g", 1, "g/1"), ("h", 1, "h/1")] + +def test_nested_term(): + e = get_engine("") + head = get_query_and_vars("f(g(X), a).")[0] + code = compile(head, None, e) + assert code.opcode_head == "l\x00\x00t\x00\x00c\x00\x00t\x00\x01U" + assert code.term_info == [("g", 1, "g/1"), ("f", 2, "f/2")] + assert code.constants == [Atom("a")] + +def test_unify(): + e = get_engine("") + head, body = get_query_and_vars("f(X, Y) :- g(X) = g(Y).")[0].args + code = compile(head, body, e) + assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00U" + assert code.opcode == "l\x00\x00t\x00\x01l\x00\x01t\x00\x01U" + assert code.constants == [] + assert code.term_info == [("f", 2, "f/2"), ("g", 1, "g/1")] + + From cfbolz at codespeak.net Thu Jun 7 01:11:13 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 01:11:13 +0200 (CEST) Subject: [pypy-svn] r44061 - pypy/branch/prolog-bytecode Message-ID: <20070606231113.657B380F6@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 01:11:13 2007 New Revision: 44061 Removed: pypy/branch/prolog-bytecode/ Log: hm, forgot the switch before the last checkin :-(. Deleting branch to create a new one. From cfbolz at codespeak.net Thu Jun 7 01:11:32 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 01:11:32 +0200 (CEST) Subject: [pypy-svn] r44062 - pypy/branch/prolog-bytecode Message-ID: <20070606231132.6D0D680F6@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 01:11:32 2007 New Revision: 44062 Added: pypy/branch/prolog-bytecode/ - copied from r44061, pypy/dist/ Log: next attempt From cfbolz at codespeak.net Thu Jun 7 01:16:42 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 01:16:42 +0200 (CEST) Subject: [pypy-svn] r44063 - in pypy/dist/pypy/lang/prolog/interpreter: . test Message-ID: <20070606231642.D2A9F80F6@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 01:16:42 2007 New Revision: 44063 Removed: pypy/dist/pypy/lang/prolog/interpreter/compiler.py pypy/dist/pypy/lang/prolog/interpreter/test/test_compiler.py Log: deleting these two files on the trunk again From cfbolz at codespeak.net Thu Jun 7 01:17:02 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 01:17:02 +0200 (CEST) Subject: [pypy-svn] r44064 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter Message-ID: <20070606231702.BA4E080F6@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 01:17:02 2007 New Revision: 44064 Added: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py Log: opcode description file Added: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py ============================================================================== --- (empty file) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py Thu Jun 7 01:17:02 2007 @@ -0,0 +1,68 @@ + +hasargument = [] +hascontinuation = [] + +opmap = {} +allopcodes = [] +opname = [''] * 256 +for op in range(256): opname[op] = '<%r>' % (op,) +del op + +def def_op(name, op, continuation=False): + op = ord(op) + opname[op] = name + opmap[name] = op + allopcodes.append(op) + if continuation: + hascontinuation.append(op) + + +def argument_op(name, op, continuation=False): + assert ord(op) >= HAVE_ARGUMENT + def_op(name, op, continuation) + hasargument.append(ord(op)) + + +HAVE_ARGUMENT = 97 # capitals + +# term construction +argument_op("PUTCONSTANT", 'c') +argument_op("PUTLOCALVAR", 'l') +argument_op("MAKETERM", 't') + +# running +argument_op("CALL_BUILTIN", 'b', True) +argument_op("CLEAR_LOCAL", 'x') +def_op("UNIFY", 'U') +def_op("CONTINUE", 'O') +def_op("DYNAMIC_CALL", 'D', True) + +class OpcodeDesc(object): + def __init__(self, name, index): + self.name = name + self.index = index + self.hasargument = index >= HAVE_ARGUMENT + self.hascontinuation = index in hascontinuation + + def _freeze_(self): + return True + + def __cmp__(self, other): + return cmp(self.index, other.index) + +lst = [] + + +class opcodedesc(object): + pass + +for name, index in opmap.items(): + desc = OpcodeDesc(name, index) + setattr(opcodedesc, name, desc) + lst.append(desc) +lst.sort() + +from pypy.rlib.unroll import unrolling_iterable + +unrolling_opcode_descs = unrolling_iterable(lst) +del lst From cfbolz at codespeak.net Thu Jun 7 01:18:42 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 01:18:42 +0200 (CEST) Subject: [pypy-svn] r44065 - in pypy/branch/prolog-bytecode/pypy/lang/prolog: builtin interpreter Message-ID: <20070606231842.B7234807C@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 01:18:42 2007 New Revision: 44065 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/__init__.py pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/type.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/helper.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py Log: small changes here and there: give Rules access to the engine. introduce an is_ground helper. Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/__init__.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/__init__.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/__init__.py Thu Jun 7 01:18:42 2007 @@ -1,6 +1,7 @@ # all builtins builtins = {} builtins_list = [] +builtins_index = {} # imports to register builtins import pypy.lang.prolog.builtin.allsolution Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py Thu Jun 7 01:18:42 2007 @@ -1,7 +1,7 @@ import py from pypy.lang.prolog.interpreter.parsing import parse_file, TermBuilder from pypy.lang.prolog.interpreter import engine, helper, term, error -from pypy.lang.prolog.builtin import builtins, builtins_list +from pypy.lang.prolog.builtin import builtins, builtins_list, builtins_index from pypy.rlib.objectmodel import we_are_translated @@ -90,7 +90,5 @@ b = Builtin(miniglobals[funcname], funcname, len(unwrap_spec), signature) builtins[signature] = b - if signature in [",/2", "is/2"]: - builtins_list.insert(0, (signature, b)) - else: - builtins_list.append((signature, b)) + builtins_index[signature] = len(builtins_list) + builtins_list.append((signature, b)) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/type.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/type.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/type.py Thu Jun 7 01:18:42 2007 @@ -54,11 +54,8 @@ expose_builtin(impl_callable, "callable", unwrap_spec=["obj"]) def impl_ground(engine, var): - if isinstance(var, term.Var): + if not helper.is_ground(var, engine): raise error.UnificationFailed() - if isinstance(var, term.Term): - for arg in var.args: - impl_ground(engine, arg) expose_builtin(impl_ground, "ground", unwrap_spec=["concrete"]) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py Thu Jun 7 01:18:42 2007 @@ -61,10 +61,6 @@ def discard(self, state): pass #XXX for now - def maxvar(self): - XXX - return self.needed_vars - def newvar(self): result = Var(self) return result @@ -109,7 +105,6 @@ return "LinkedRules(%r, %r)" % (self.rule, self.next) - class Function(object): def __init__(self, firstrule=None): if firstrule is None: @@ -149,12 +144,12 @@ debug_print("add_rule", rule) if isinstance(rule, Term): if rule.name == ":-": - rule = Rule(rule.args[0], rule.args[1]) + rule = Rule(rule.args[0], rule.args[1], self) else: - rule = Rule(rule, None) + rule = Rule(rule, None, self) signature = rule.signature elif isinstance(rule, Atom): - rule = Rule(rule, None) + rule = Rule(rule, None, self) signature = rule.signature else: error.throw_type_error("callable", rule) @@ -317,7 +312,10 @@ return self.main_loop(TRY_RULE, query, continuation, rule) #if _is_early_constant(rule): # rule = hint(rule, promote=True) - # return self.portal_try_rule(rule, query, continuation, choice_point) + # #force right colors + # query = hint(query, variable=True) + # continuation = hint(continuation, variable=True) + # return self.portal_try_rule(rule, query, continuation, True) return self._opaque_try_rule(rule, query, continuation, choice_point) def _opaque_try_rule(self, rule, query, continuation, choice_point): @@ -366,7 +364,7 @@ continuation = e.continuation def parse(self, s): - from pypy.lang.prolog.interpreter.parsing import parse_file, TermBuilder, lexer + from pypy.lang.prolog.interpreter.parsing import parse_file, TermBuilder builder = TermBuilder() trees = parse_file(s, self.parser) terms = builder.build_many(trees) @@ -378,6 +376,3 @@ return default_operations return self.operations - - - Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/helper.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/helper.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/helper.py Thu Jun 7 01:18:42 2007 @@ -27,6 +27,18 @@ return isinstance(var, term.Callable) is_callable._look_inside_me_ = True +def is_ground(obj, engine): + stack = [obj] + while stack: + obj = stack.pop().dereference(engine.heap) + if isinstance(obj, term.Var): + return False + if isinstance(obj, term.Term): + for arg in obj.args: + stack.append(arg) + return True + + def ensure_callable(var): if isinstance(var, term.Var): error.throw_instantiation_error() Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py Thu Jun 7 01:18:42 2007 @@ -504,7 +504,7 @@ class Rule(object): _immutable_ = True unify_hash = [] - def __init__(self, head, body): + def __init__(self, head, body, engine): from pypy.lang.prolog.interpreter import helper assert isinstance(head, Callable) self.head = head From cfbolz at codespeak.net Thu Jun 7 01:24:35 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 01:24:35 +0200 (CEST) Subject: [pypy-svn] r44066 - pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin Message-ID: <20070606232435.596B880F6@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 01:24:35 2007 New Revision: 44066 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/metacall.py Log: make the once implementation simpler Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/metacall.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/metacall.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/metacall.py Thu Jun 7 01:24:35 2007 @@ -13,9 +13,7 @@ expose_builtin(impl_call, "call", unwrap_spec=["callable"], handles_continuation=True) -def impl_once(engine, clause, continuation): +def impl_once(engine, clause): engine.call(clause) - return continuation.call(engine, choice_point=False) -expose_builtin(impl_once, "once", unwrap_spec=["callable"], - handles_continuation=True) +expose_builtin(impl_once, "once", unwrap_spec=["callable"]) From cfbolz at codespeak.net Thu Jun 7 01:48:13 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 01:48:13 +0200 (CEST) Subject: [pypy-svn] r44067 - in pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter: . test Message-ID: <20070606234813.2748B80F8@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 01:48:12 2007 New Revision: 44067 Added: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (contents, props changed) pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py (contents, props changed) Log: first experiments with a bytecode interpreter: not integrated with anything else, byt a very simple test works. Added: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- (empty file) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 01:48:12 2007 @@ -0,0 +1,146 @@ +from pypy.lang.prolog.interpreter import helper +from pypy.lang.prolog.interpreter.term import Term, Atom, Var +from pypy.lang.prolog.interpreter.engine import CONTINUATION, Continuation +from pypy.lang.prolog.interpreter.prologopcode import unrolling_opcode_descs, \ + HAVE_ARGUMENT + +class FrameContinuation(Continuation): + def __init__(self, frame, pc): + self.frame = frame + self.pc = pc + + def _call(self, engine): + return frame.run(pc) + +class Rule(object): + _immutable_ = True + def __init__(self, head, body, engine): + from pypy.lang.prolog.interpreter.compiler import compile + head = helper.ensure_callable(head) + self.head = head + self.code = compile(head, body, engine) + if body is not None: + body = helper.ensure_callable(body) + self.body = body + else: + self.body = None + self.signature = self.head.signature + self.engine = engine + + def make_frame(self, head): + f = Frame(self.engine, self.code) + f.unify_head(head) + return f + + def __repr__(self): + if self.body is None: + return "%s." % (self.head, ) + return "%s :- %s." % (self.head, self.body) + + +class Frame(object): + #_immutable_ = True # XXX? + + def __init__(self, engine, code): + self.engine = engine + self.code = code + self.localvarcache = [None] * code.maxlocalvar + + def unify_head(self, head): + self.run(self.code.opcode_head, 0, None, [head]) + + def run(self, bytecode, pc, continuation, stack=None): + if stack is None: + stack = [] + while pc < len(bytecode): + opcode = ord(bytecode[pc]) + pc += 1 + if opcode >= HAVE_ARGUMENT: + lo = ord(bytecode[pc]) + hi = ord(bytecode[pc+1]) + pc += 2 + oparg = (hi << 8) | lo + else: + oparg = 0 + for opdesc in unrolling_opcode_descs: + if opcode == opdesc.index: + # dispatch to the opcode method + meth = getattr(self, opdesc.name) + if opdesc.hascontinuation: + continuation = FrameContinuation( + self, pc, continuation) + if opdesc.hasargument: + res = meth(stack, oparg, continuation) + else: + res = meth(stack, continuation) + else: + if opdesc.hasargument: + res = meth(stack, oparg) + else: + res = meth(stack) + if res is not None: + while 1: + where, _, continuation, _ = res + assert where == CONTINUATION + if isinstance(continuation, FrameContinuation): + self = continuation.frame + pc = continuation.pc + bytecode = self.code.bytecode + stack = [] + else: + res = continuation._call(self.engine) + break + else: + assert 0, "missing opcode" + assert len(stack) == 0 + return (CONTINUATION, None, continuation, None) + + def PUTCONSTANT(self, stack, number): + stack.append(self.code.constants[number]) + + def PUTLOCALVAR(self, stack, number): + result = self.localvarcache[number] + if result is None: + result = self.localvarcache[number] = self.engine.heap.newvar() + stack.append(result) + + def MAKETERM(self, stack, number, *ignored): + name, numargs, signature = self.code.term_info[number] + args = [None] * numargs + i = 0 + while i < numargs: + args[i] = stack.pop() + i += 1 + stack.append(Term(name, args, signature)) + + def CALL_BUILTIN(self, stack, number, continuation, *ignored): + from pypy.lang.prolog.builtin import builtins_list + return builtins_list[number].call(self, stack.pop(), continuation) + + def DYNAMIC_CALL(self, stack, continuation, *ignored): + query = stack.pop() + function = self.engine._jit_lookup(signature) + rulechain = function.rulechain + if rulechain is None: + error.throw_existence_error( + "procedure", query.get_prolog_signature()) + oldstate = self.heap.branch() + while rulechain is not None: + rule = rulechain.rule + try: + frame = rule.make_frame(query) + if frame.code.bytecode: + return frame.run(continuation) + return None + except UnificationFailed: + self.heap.revert(oldstate) + rule = rulechain.rule + rulechain = rulechain.next + + def CLEAR_LOCAL(self, stack, number, *ignored): + self.localvarcache[number] = None + + def UNIFY(self, stack, *ignored): + stack.pop().unify(stack.pop(), self.engine.heap) + + Added: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py ============================================================================== --- (empty file) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py Thu Jun 7 01:48:12 2007 @@ -0,0 +1,17 @@ +import py +from pypy.lang.prolog.interpreter.interpreter import Rule +from pypy.lang.prolog.interpreter.parsing import get_engine, get_query_and_vars + +def test_simple(): + e = get_engine("") + head, body = get_query_and_vars("f(X) :- X = a.")[0].args + r = Rule(head, body, e) + query = get_query_and_vars("f(a).")[0] + frame = r.make_frame(query) + assert frame.localvarcache[0].dereference(e.heap).name == "a" + cont = object() + res = frame.run(frame.code.opcode, 0, cont) + where, _, c2, _ = res + assert cont is c2 + + From cfbolz at codespeak.net Thu Jun 7 01:49:25 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 01:49:25 +0200 (CEST) Subject: [pypy-svn] r44068 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test Message-ID: <20070606234925.6250A80F8@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 01:49:25 2007 New Revision: 44068 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py Log: make the test a bit more elaborate Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py Thu Jun 7 01:49:25 2007 @@ -14,4 +14,12 @@ where, _, c2, _ = res assert cont is c2 + query, vars = get_query_and_vars("f(X).") + frame = r.make_frame(query) + cont = object() + res = frame.run(frame.code.opcode, 0, cont) + where, _, c2, _ = res + assert cont is c2 + assert vars['X'].dereference(e.heap).name == 'a' + From cfbolz at codespeak.net Thu Jun 7 10:33:48 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 10:33:48 +0200 (CEST) Subject: [pypy-svn] r44073 - in pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter: . test Message-ID: <20070607083348.5A80880CB@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 10:33:47 2007 New Revision: 44073 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py Log: start rewriting things to use the bytecode interpreter. lots of failing tests right now, but slowly getting there. Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py Thu Jun 7 10:33:47 2007 @@ -1,10 +1,11 @@ -from pypy.lang.prolog.interpreter.term import NonVar, Term, Var +from pypy.lang.prolog.interpreter.term import NonVar, Term, Var, Atom from pypy.lang.prolog.interpreter.engine import Continuation from pypy.lang.prolog.interpreter import helper, error from pypy.lang.prolog.interpreter.prologopcode import opcodedesc from pypy.rlib.objectmodel import we_are_translated from pypy.rlib.jit import hint, we_are_jitted +queryatom = Atom.newatom("") class Code(object): _immutable_ = True @@ -20,9 +21,15 @@ comp = Compiler(engine) return comp.compile(head, body) +def compile_query(body, engine): + comp = Compiler(engine, True) + return comp.compile(queryatom, body) + + class Compiler(object): - def __init__(self, engine): + def __init__(self, engine, query=False): self.engine = engine + self.query = query def compile(self, head, body): self.term_info = [] # tuples of (functor, numargs, signature) @@ -34,7 +41,6 @@ self.varmap = {} result = Code() self.compile_termbuilding(head) - self.emit_opcode(opcodedesc.UNIFY) result.opcode_head = self.getbytecode() if body is not None: self.compile_body(body) @@ -49,8 +55,12 @@ num = self.getconstnum(term) self.emit_opcode(opcodedesc.PUTCONSTANT, num) elif isinstance(term, Var): - num = self.getvarnum(term) - self.emit_opcode(opcodedesc.PUTLOCALVAR, num) + if self.query: + num = self.getconstnum(term) + self.emit_opcode(opcodedesc.PUTCONSTANT, num) + else: + num = self.getvarnum(term) + self.emit_opcode(opcodedesc.PUTLOCALVAR, num) else: assert isinstance(term, Term) for arg in term.args: Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py Thu Jun 7 10:33:47 2007 @@ -1,7 +1,8 @@ -from pypy.lang.prolog.interpreter.term import Var, Term, Rule, Atom, debug_print, \ +import py +from pypy.lang.prolog.interpreter.term import Var, Term, Atom, debug_print, \ Callable -from pypy.lang.prolog.interpreter.error import UnificationFailed, FunctionNotFound, \ - CutException +from pypy.lang.prolog.interpreter.error import UnificationFailed, \ + FunctionNotFound, CutException from pypy.lang.prolog.interpreter import error from pypy.rlib.jit import hint, we_are_jitted, _is_early_constant, purefunction from pypy.rlib.objectmodel import specialize @@ -19,6 +20,7 @@ class Continuation(object): def call(self, engine, choice_point=True): + py.test.skip("can't do a call like this right now") if choice_point: return engine.main_loop(CONTINUATION, None, self, None) return (CONTINUATION, None, self, None) @@ -140,6 +142,7 @@ def add_rule(self, rule, end=True): from pypy.lang.prolog import builtin + from pypy.lang.prolog.interpreter.interpreter import Rule if DEBUG: debug_print("add_rule", rule) if isinstance(rule, Term): @@ -147,13 +150,12 @@ rule = Rule(rule.args[0], rule.args[1], self) else: rule = Rule(rule, None, self) - signature = rule.signature elif isinstance(rule, Atom): rule = Rule(rule, None, self) - signature = rule.signature else: error.throw_type_error("callable", rule) assert 0, "unreachable" # make annotator happy + signature = rule.signature if signature in builtin.builtins: error.throw_permission_error( "modify", "static_procedure", rule.head.get_prolog_signature()) @@ -164,10 +166,15 @@ self.signature2function[signature] = Function(rule) def run(self, query, continuation=DONOTHING): + from pypy.lang.prolog.interpreter.interpreter import Query if not isinstance(query, Callable): error.throw_type_error("callable", query) + rule = Query(query, self) + frame = rule.make_frame() try: - return self.call(query, continuation, choice_point=True) + where, _, cont, _ = frame.run_directly(continuation) + while where == CONTINUATION: + where, _, cont, _ = cont._call(self) except CutException, e: return self.continue_after_cut(e.continuation) @@ -186,12 +193,14 @@ trees = parse_file(s, self.parser, Engine._build_and_run, self) def call(self, query, continuation=DONOTHING, choice_point=True): + py.test.skip("can't do a call like this right now") assert isinstance(query, Callable) if not choice_point: return (CALL, query, continuation, None) return self.main_loop(CALL, query, continuation) def _call(self, query, continuation): + py.test.skip("can't do a call like this right now") signature = query.signature from pypy.lang.prolog.builtin import builtins builtins = hint(builtins, deepfreeze=True) @@ -201,41 +210,6 @@ return builtin.call(self, query, continuation) return self.user_call(query, continuation, choice_point=False) - def _opaque_call(self, query, continuation): - from pypy.lang.prolog.builtin import builtins - signature = query.signature - builtin = builtins.get(signature, None) - if builtin is not None: - return builtin.call(self, query, continuation) - # do a real call - return self.user_call(query, continuation, choice_point=False) - - def main_loop(self, where, query, continuation, rule=None): - next = (DONE, None, None, None) - hint(where, concrete=True) - hint(rule, concrete=True) - while 1: - if where == DONE: - return next - next = self.dispatch_bytecode(where, query, continuation, rule) - where, query, continuation, rule = next - where = hint(where, promote=True) - - def dispatch_bytecode(self, where, query, continuation, rule): - if where == CALL: - next = self._call(query, continuation) - elif where == TRY_RULE: - rule = hint(rule, promote=True) - next = self._try_rule(rule, query, continuation) - elif where == USER_CALL: - next = self._user_call(query, continuation) - elif where == CONTINUATION: - hint(continuation.__class__, promote=True) - next = continuation._call(self) - else: - raise Exception("unknown bytecode") - return next - @purefunction def _jit_lookup(self, signature): signature2function = self.signature2function @@ -244,116 +218,6 @@ signature2function[signature] = function = Function() return function - def user_call(self, query, continuation, choice_point=True): - if not choice_point: - return (USER_CALL, query, continuation, None) - return self.main_loop(USER_CALL, query, continuation) - - def _user_call(self, query, continuation): - signature = hint(query.signature, promote=True) - function = self._jit_lookup(signature) - startrulechain = function.rulechain - startrulechain = hint(startrulechain, promote=True) - if startrulechain is None: - error.throw_existence_error( - "procedure", query.get_prolog_signature()) - - unify_hash = query.unify_hash_of_children(self.heap) - rulechain = startrulechain.find_applicable_rule(unify_hash) - if rulechain is None: - # none of the rules apply - raise UnificationFailed() - rule = rulechain.rule - rulechain = rulechain.next - oldstate = self.heap.branch() - while 1: - if rulechain is not None: - rulechain = rulechain.find_applicable_rule(unify_hash) - choice_point = rulechain is not None - else: - choice_point = False - hint(rule, concrete=True) - if rule.contains_cut: - continuation = LimitedScopeContinuation(continuation) - try: - result = self.try_rule(rule, query, continuation) - self.heap.discard(oldstate) - return result - except UnificationFailed: - self.heap.revert(oldstate) - except CutException, e: - if continuation.scope_active: - return self.continue_after_cut(e.continuation, - continuation) - raise - else: - inline = rule.body is None # inline facts - try: - # for the last rule (rulechain is None), this will always - # return, because choice_point is False - result = self.try_rule(rule, query, continuation, - choice_point=choice_point, - inline=inline) - self.heap.discard(oldstate) - return result - except UnificationFailed: - assert choice_point - self.heap.revert(oldstate) - rule = rulechain.rule - rulechain = rulechain.next - - def try_rule(self, rule, query, continuation=DONOTHING, choice_point=True, - inline=False): - if not choice_point: - return (TRY_RULE, query, continuation, rule) - if not we_are_jitted(): - return self.portal_try_rule(rule, query, continuation, choice_point) - if inline: - return self.main_loop(TRY_RULE, query, continuation, rule) - #if _is_early_constant(rule): - # rule = hint(rule, promote=True) - # #force right colors - # query = hint(query, variable=True) - # continuation = hint(continuation, variable=True) - # return self.portal_try_rule(rule, query, continuation, True) - return self._opaque_try_rule(rule, query, continuation, choice_point) - - def _opaque_try_rule(self, rule, query, continuation, choice_point): - return self.portal_try_rule(rule, query, continuation, choice_point) - - def portal_try_rule(self, rule, query, continuation, choice_point): - hint(None, global_merge_point=True) - hint(choice_point, concrete=True) - if not choice_point: - return self._try_rule(rule, query, continuation) - where = TRY_RULE - next = (DONE, None, None, None) - hint(where, concrete=True) - hint(rule, concrete=True) - signature = hint(query.signature, promote=True) - while 1: - hint(None, global_merge_point=True) - if where == DONE: - return next - if rule is not None: - assert rule.signature == signature - next = self.dispatch_bytecode(where, query, continuation, rule) - where, query, continuation, rule = next - rule = hint(rule, promote=True) - if query is not None: - signature = hint(query.signature, promote=True) - where = hint(where, promote=True) - - def _try_rule(self, rule, query, continuation): - rule = hint(rule, deepfreeze=True) - hint(self, concrete=True) - # standardizing apart - nextcall = rule.clone_and_unify_head(self.heap, query) - if nextcall is not None: - return self.call(nextcall, continuation, choice_point=False) - else: - return continuation.call(self, choice_point=False) - def continue_after_cut(self, continuation, lsc=None): while 1: try: Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 10:33:47 2007 @@ -1,16 +1,19 @@ from pypy.lang.prolog.interpreter import helper -from pypy.lang.prolog.interpreter.term import Term, Atom, Var +from pypy.lang.prolog.interpreter import error +from pypy.lang.prolog.interpreter.term import Term, Atom, Var, Callable from pypy.lang.prolog.interpreter.engine import CONTINUATION, Continuation from pypy.lang.prolog.interpreter.prologopcode import unrolling_opcode_descs, \ HAVE_ARGUMENT class FrameContinuation(Continuation): - def __init__(self, frame, pc): + def __init__(self, frame, pc, continuation): self.frame = frame self.pc = pc + self.continuation = continuation def _call(self, engine): - return frame.run(pc) + return self.frame.run(self.frame.code.opcode, self.pc, + self.continuation) class Rule(object): _immutable_ = True @@ -37,6 +40,15 @@ return "%s." % (self.head, ) return "%s :- %s." % (self.head, self.body) +class Query(object): + def __init__(self, body, engine): + from pypy.lang.prolog.interpreter.compiler import compile_query + self.code = compile_query(body, engine) + self.engine = engine + + def make_frame(self): + return Frame(self.engine, self.code) + class Frame(object): #_immutable_ = True # XXX? @@ -45,34 +57,39 @@ self.engine = engine self.code = code self.localvarcache = [None] * code.maxlocalvar + self.stack = None def unify_head(self, head): - self.run(self.code.opcode_head, 0, None, [head]) + self.run(self.code.opcode_head, 0, None) + self.stack[0].unify(head, self.engine.heap) + self.stack = None + + def run_directly(self, continuation): + return self.run(self.code.opcode, 0, continuation) - def run(self, bytecode, pc, continuation, stack=None): - if stack is None: - stack = [] + def run(self, bytecode, pc, continuation): + stack = [] while pc < len(bytecode): opcode = ord(bytecode[pc]) pc += 1 if opcode >= HAVE_ARGUMENT: - lo = ord(bytecode[pc]) - hi = ord(bytecode[pc+1]) + hi = ord(bytecode[pc]) + lo = ord(bytecode[pc+1]) pc += 2 oparg = (hi << 8) | lo else: oparg = 0 + #import pdb; pdb.set_trace() for opdesc in unrolling_opcode_descs: if opcode == opdesc.index: # dispatch to the opcode method meth = getattr(self, opdesc.name) if opdesc.hascontinuation: - continuation = FrameContinuation( - self, pc, continuation) + cont = FrameContinuation(self, pc, continuation) if opdesc.hasargument: - res = meth(stack, oparg, continuation) + res = meth(stack, oparg, cont) else: - res = meth(stack, continuation) + res = meth(stack, cont) else: if opdesc.hasargument: res = meth(stack, oparg) @@ -85,14 +102,16 @@ if isinstance(continuation, FrameContinuation): self = continuation.frame pc = continuation.pc - bytecode = self.code.bytecode + bytecode = self.code.opcode stack = [] + break else: res = continuation._call(self.engine) break else: assert 0, "missing opcode" - assert len(stack) == 0 + if len(stack) != 0: + self.stack = stack return (CONTINUATION, None, continuation, None) def PUTCONSTANT(self, stack, number): @@ -115,25 +134,26 @@ def CALL_BUILTIN(self, stack, number, continuation, *ignored): from pypy.lang.prolog.builtin import builtins_list - return builtins_list[number].call(self, stack.pop(), continuation) + return builtins_list[number][1].call(self.engine, stack.pop(), + continuation) def DYNAMIC_CALL(self, stack, continuation, *ignored): query = stack.pop() + assert isinstance(query, Callable) + signature = query.signature function = self.engine._jit_lookup(signature) rulechain = function.rulechain if rulechain is None: error.throw_existence_error( "procedure", query.get_prolog_signature()) - oldstate = self.heap.branch() + oldstate = self.engine.heap.branch() while rulechain is not None: rule = rulechain.rule try: frame = rule.make_frame(query) - if frame.code.bytecode: - return frame.run(continuation) - return None - except UnificationFailed: - self.heap.revert(oldstate) + return frame.run_directly(continuation) + except error.UnificationFailed: + self.engine.heap.revert(oldstate) rule = rulechain.rule rulechain = rulechain.next Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py Thu Jun 7 10:33:47 2007 @@ -501,62 +501,6 @@ error.throw_type_error("evaluable", self.get_prolog_signature()) return func(engine, self) -class Rule(object): - _immutable_ = True - unify_hash = [] - def __init__(self, head, body, engine): - from pypy.lang.prolog.interpreter import helper - assert isinstance(head, Callable) - self.head = head - if body is not None: - body = helper.ensure_callable(body) - self.body = body - else: - self.body = None - self.signature = self.head.signature - if isinstance(head, Term): - self.unify_hash = [arg.get_unify_hash(None) for arg in head.args] - self._does_contain_cut() - - def _does_contain_cut(self): - if self.body is None: - self.contains_cut = False - return - stack = [self.body] - while stack: - current = stack.pop() - if isinstance(current, Atom): - if current.name == "!": - self.contains_cut = True - return - elif isinstance(current, Term): - stack.extend(current.args) - self.contains_cut = False - - def clone_and_unify_head(self, heap, head): - memo = {} - h2 = self.head - hint(h2, concrete=True) - if isinstance(h2, Term): - assert isinstance(head, Term) - i = 0 - while i < len(h2.args): - i = hint(i, concrete=True) - arg2 = h2.args[i] - arg1 = head.args[i] - arg2.copy_and_unify(arg1, heap, memo) - i += 1 - body = self.body - hint(body, concrete=True) - if body is None: - return None - return body.copy(heap, memo) - - def __repr__(self): - if self.body is None: - return "%s." % (self.head, ) - return "%s :- %s." % (self.head, self.body) - @specialize.argtype(0) def rcmp(a, b): # RPython does not support cmp... Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py Thu Jun 7 10:33:47 2007 @@ -7,7 +7,7 @@ foo = Atom("foo") code = compile(foo, None, e) assert not code.opcode - assert code.opcode_head == "c\x00\x00U" + assert code.opcode_head == "c\x00\x00" assert code.constants == [foo] def test_simple_withbody(): @@ -15,7 +15,7 @@ foo = Atom("foo") bar = Atom("bar") code = compile(foo, bar, e) - assert code.opcode_head == "c\x00\x00U" + assert code.opcode_head == "c\x00\x00" assert code.opcode == "c\x00\x01D" assert code.constants == [foo, bar] @@ -23,7 +23,7 @@ e = get_engine("") head, body = get_query_and_vars("f(X) :- g(X).")[0].args code = compile(head, body, e) - assert code.opcode_head == "l\x00\x00t\x00\x00U" + assert code.opcode_head == "l\x00\x00t\x00\x00" assert code.opcode == "l\x00\x00t\x00\x01D" assert code.constants == [] assert code.term_info == [("f", 1, "f/1"), ("g", 1, "g/1")] @@ -32,7 +32,7 @@ e = get_engine("") head, body = get_query_and_vars("f(X, Y) :- g(X), h(Y).")[0].args code = compile(head, body, e) - assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00U" + assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00" assert code.opcode == "l\x00\x00t\x00\x01Dl\x00\x01t\x00\x02D" assert code.constants == [] assert code.term_info == [("f", 2, "f/2"), ("g", 1, "g/1"), ("h", 1, "h/1")] @@ -41,7 +41,7 @@ e = get_engine("") head = get_query_and_vars("f(g(X), a).")[0] code = compile(head, None, e) - assert code.opcode_head == "l\x00\x00t\x00\x00c\x00\x00t\x00\x01U" + assert code.opcode_head == "l\x00\x00t\x00\x00c\x00\x00t\x00\x01" assert code.term_info == [("g", 1, "g/1"), ("f", 2, "f/2")] assert code.constants == [Atom("a")] @@ -49,7 +49,7 @@ e = get_engine("") head, body = get_query_and_vars("f(X, Y) :- g(X) = g(Y).")[0].args code = compile(head, body, e) - assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00U" + assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00" assert code.opcode == "l\x00\x00t\x00\x01l\x00\x01t\x00\x01U" assert code.constants == [] assert code.term_info == [("f", 2, "f/2"), ("g", 1, "g/1")] Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py Thu Jun 7 10:33:47 2007 @@ -224,11 +224,9 @@ % (chr(i), chr(i + 1)) for i in range(97, 122)])) t = parse_query_term("f(x, g(y)).") - for i in range(200): - e.run(t) + e.run(t) t = parse_query_term("f(x, g(y, a)).") - for i in range(200): - py.test.raises(UnificationFailed, e.run, t) + py.test.raises(UnificationFailed, e.run, t) def test_indexing2(): e = get_engine(""" Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py Thu Jun 7 10:33:47 2007 @@ -62,7 +62,8 @@ Term("f", [Y, X])])) X = e.heap.newvar() e.run(Term("f", [Atom.newatom("b"), X])) - assert X.dereference(e.heap).name == "b" + assert X.dereference(e.heap).name == "a" e.run(Term("f", [Atom.newatom("b"), Atom.newatom("a")])) + e.run(Term("f", [Atom.newatom("c"), Atom.newatom("c")])) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py Thu Jun 7 10:33:47 2007 @@ -33,6 +33,7 @@ raise UnificationFailed def collect_all(engine, s): + py.test.skip("collect_all currently does not work") terms, vars = engine.parse(s) term, = terms collector = CollectAllContinuation(vars) From cfbolz at codespeak.net Thu Jun 7 10:39:48 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 10:39:48 +0200 (CEST) Subject: [pypy-svn] r44074 - in pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter: . test Message-ID: <20070607083948.99F6580CE@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 10:39:48 2007 New Revision: 44074 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py Log: remove more old stuff Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py Thu Jun 7 10:39:48 2007 @@ -10,23 +10,15 @@ DEBUG = False -# bytecodes: -CALL = 'a' -USER_CALL = 'u' -TRY_RULE = 't' -CONTINUATION = 'c' -DONE = 'd' - - class Continuation(object): def call(self, engine, choice_point=True): - py.test.skip("can't do a call like this right now") - if choice_point: - return engine.main_loop(CONTINUATION, None, self, None) - return (CONTINUATION, None, self, None) + if not choice_point: + return self + while self is not None: + self = self._call(engine) def _call(self, engine): - return (DONE, None, None, None) + pass DONOTHING = Continuation() @@ -37,7 +29,7 @@ def _call(self, engine): self.scope_active = False - return self.continuation.call(engine, choice_point=False) + return self.continuation class Heap(object): def __init__(self): @@ -172,9 +164,9 @@ rule = Query(query, self) frame = rule.make_frame() try: - where, _, cont, _ = frame.run_directly(continuation) - while where == CONTINUATION: - where, _, cont, _ = cont._call(self) + cont = frame.run_directly(continuation) + while cont is not None: + cont = cont._call(self) except CutException, e: return self.continue_after_cut(e.continuation) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 10:39:48 2007 @@ -1,7 +1,7 @@ from pypy.lang.prolog.interpreter import helper from pypy.lang.prolog.interpreter import error from pypy.lang.prolog.interpreter.term import Term, Atom, Var, Callable -from pypy.lang.prolog.interpreter.engine import CONTINUATION, Continuation +from pypy.lang.prolog.interpreter.engine import Continuation from pypy.lang.prolog.interpreter.prologopcode import unrolling_opcode_descs, \ HAVE_ARGUMENT @@ -97,8 +97,7 @@ res = meth(stack) if res is not None: while 1: - where, _, continuation, _ = res - assert where == CONTINUATION + continuation = res if isinstance(continuation, FrameContinuation): self = continuation.frame pc = continuation.pc @@ -112,7 +111,7 @@ assert 0, "missing opcode" if len(stack) != 0: self.stack = stack - return (CONTINUATION, None, continuation, None) + return continuation def PUTCONSTANT(self, stack, number): stack.append(self.code.constants[number]) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py Thu Jun 7 10:39:48 2007 @@ -10,15 +10,13 @@ frame = r.make_frame(query) assert frame.localvarcache[0].dereference(e.heap).name == "a" cont = object() - res = frame.run(frame.code.opcode, 0, cont) - where, _, c2, _ = res + c2 = frame.run(frame.code.opcode, 0, cont) assert cont is c2 query, vars = get_query_and_vars("f(X).") frame = r.make_frame(query) cont = object() - res = frame.run(frame.code.opcode, 0, cont) - where, _, c2, _ = res + c2 = frame.run(frame.code.opcode, 0, cont) assert cont is c2 assert vars['X'].dereference(e.heap).name == 'a' From cfbolz at codespeak.net Thu Jun 7 11:14:30 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 11:14:30 +0200 (CEST) Subject: [pypy-svn] r44075 - in pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter: . test Message-ID: <20070607091430.91AB580CB@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 11:14:29 2007 New Revision: 44075 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py Log: eh, nasty bug: the orders of the term arguments were reversed Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 11:14:29 2007 @@ -125,10 +125,10 @@ def MAKETERM(self, stack, number, *ignored): name, numargs, signature = self.code.term_info[number] args = [None] * numargs - i = 0 - while i < numargs: + i = numargs - 1 + while i >= 0: args[i] = stack.pop() - i += 1 + i -= 1 stack.append(Term(name, args, signature)) def CALL_BUILTIN(self, stack, number, continuation, *ignored): @@ -155,6 +155,7 @@ self.engine.heap.revert(oldstate) rule = rulechain.rule rulechain = rulechain.next + raise error.UnificationFailed def CLEAR_LOCAL(self, stack, number, *ignored): self.localvarcache[number] = None Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py Thu Jun 7 11:14:29 2007 @@ -1,5 +1,5 @@ import py -from pypy.lang.prolog.interpreter.interpreter import Rule +from pypy.lang.prolog.interpreter.interpreter import Rule, Frame from pypy.lang.prolog.interpreter.parsing import get_engine, get_query_and_vars def test_simple(): @@ -20,4 +20,13 @@ assert cont is c2 assert vars['X'].dereference(e.heap).name == 'a' +def test_build_term(): + e = get_engine("") + head, body = get_query_and_vars("f(X, Y) :- X = a, Y = b.")[0].args + r = Rule(head, body, e) + frame = Frame(e, r.code) + frame.run(frame.code.opcode_head, 0, None) + frame.run(frame.code.opcode, 0, None) + assert frame.stack[0].args[0].dereference(e.heap).name == "a" + assert frame.stack[0].args[1].dereference(e.heap).name == "b" From cfbolz at codespeak.net Thu Jun 7 11:40:13 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 11:40:13 +0200 (CEST) Subject: [pypy-svn] r44076 - in pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter: . test Message-ID: <20070607094013.05A6F80DB@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 11:40:13 2007 New Revision: 44076 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py Log: more tests passing Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py Thu Jun 7 11:40:13 2007 @@ -164,9 +164,8 @@ rule = Query(query, self) frame = rule.make_frame() try: - cont = frame.run_directly(continuation) - while cont is not None: - cont = cont._call(self) + #import pdb;pdb.set_trace() + frame.run_directly(continuation) except CutException, e: return self.continue_after_cut(e.continuation) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 11:40:13 2007 @@ -65,7 +65,9 @@ self.stack = None def run_directly(self, continuation): - return self.run(self.code.opcode, 0, continuation) + cont = self.run(self.code.opcode, 0, continuation) + while cont is not None: + cont = cont._call(self.engine) def run(self, bytecode, pc, continuation): stack = [] @@ -150,7 +152,8 @@ rule = rulechain.rule try: frame = rule.make_frame(query) - return frame.run_directly(continuation) + frame.run_directly(continuation) + return except error.UnificationFailed: self.engine.heap.revert(oldstate) rule = rulechain.rule Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py Thu Jun 7 11:40:13 2007 @@ -33,7 +33,6 @@ raise UnificationFailed def collect_all(engine, s): - py.test.skip("collect_all currently does not work") terms, vars = engine.parse(s) term, = terms collector = CollectAllContinuation(vars) From cfbolz at codespeak.net Thu Jun 7 11:44:41 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 11:44:41 +0200 (CEST) Subject: [pypy-svn] r44077 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test Message-ID: <20070607094441.56A1B80DB@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 11:44:41 2007 New Revision: 44077 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py Log: this test was wrong ? changed by an earlier non-thinking checkin of mine Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py Thu Jun 7 11:44:41 2007 @@ -62,7 +62,7 @@ Term("f", [Y, X])])) X = e.heap.newvar() e.run(Term("f", [Atom.newatom("b"), X])) - assert X.dereference(e.heap).name == "a" + assert X.dereference(e.heap).name == "b" e.run(Term("f", [Atom.newatom("b"), Atom.newatom("a")])) e.run(Term("f", [Atom.newatom("c"), Atom.newatom("c")])) From cfbolz at codespeak.net Thu Jun 7 12:14:01 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 12:14:01 +0200 (CEST) Subject: [pypy-svn] r44078 - in pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter: . test Message-ID: <20070607101401.11FDC80C7@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 12:14:00 2007 New Revision: 44078 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py Log: make DYNAMIC_CALL support calls to builtins and introduce STATIC_CALL. Makes it possible to kill the Query hack in the compiler. Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py Thu Jun 7 12:14:00 2007 @@ -9,27 +9,30 @@ class Code(object): _immutable_ = True - def __init__(self): + + def empty_init(self): self.term_info = [] # tuples of (functor, numargs, signature) self.opcode_head = "" self.opcode = "" self.constants = [] # list of ground Prolog objects + self.functions = [] # list of Function objects self.maxlocalvar = 0 +Code.dynamic_code = Code() +Code.dynamic_code.empty_init() +Code.dynamic_code.maxlocalvar = 1 +Code.dynamic_code.opcode_head = "l\x00\x00" +Code.dynamic_code.opcode = "l\x00\x00D" + + def compile(head, body, engine): comp = Compiler(engine) return comp.compile(head, body) -def compile_query(body, engine): - comp = Compiler(engine, True) - return comp.compile(queryatom, body) - - class Compiler(object): - def __init__(self, engine, query=False): + def __init__(self, engine): self.engine = engine - self.query = query def compile(self, head, body): self.term_info = [] # tuples of (functor, numargs, signature) @@ -37,6 +40,8 @@ self.opcode = [] self.constants = [] # list of ground Prolog objects self.constant_map = {} + self.functions = [] # list of Function objects + self.functionmap = {} self.maxlocalvar = 0 self.varmap = {} result = Code() @@ -47,6 +52,7 @@ result.opcode = self.getbytecode() result.constants = self.constants result.term_info = self.term_info + result.functions = self.functions result.maxlocalvar = len(self.varmap) return result @@ -55,12 +61,8 @@ num = self.getconstnum(term) self.emit_opcode(opcodedesc.PUTCONSTANT, num) elif isinstance(term, Var): - if self.query: - num = self.getconstnum(term) - self.emit_opcode(opcodedesc.PUTCONSTANT, num) - else: - num = self.getvarnum(term) - self.emit_opcode(opcodedesc.PUTLOCALVAR, num) + num = self.getvarnum(term) + self.emit_opcode(opcodedesc.PUTLOCALVAR, num) else: assert isinstance(term, Term) for arg in term.args: @@ -94,7 +96,8 @@ self.emit_opcode(opcodedesc.CALL_BUILTIN, i) else: self.compile_termbuilding(body) - self.emit_opcode(opcodedesc.DYNAMIC_CALL) + num = self.getfunction(body.signature) + self.emit_opcode(opcodedesc.STATIC_CALL, num) def emit_opcode(self, desc, arg=-1): self.opcode.append(desc.index) @@ -135,6 +138,12 @@ self.constants.append(const) return result - self.constants.append(term.getvalue(self.engine.heap)) - + def getfunction(self, signature): + try: + return self.functionmap[signature] + except KeyError: + result = len(self.functionmap) + self.functionmap[signature] = result + self.functions.append(self.engine.lookup_userfunction(signature)) + return result Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py Thu Jun 7 12:14:00 2007 @@ -158,13 +158,11 @@ self.signature2function[signature] = Function(rule) def run(self, query, continuation=DONOTHING): - from pypy.lang.prolog.interpreter.interpreter import Query + from pypy.lang.prolog.interpreter.interpreter import dynamic_call_frame if not isinstance(query, Callable): error.throw_type_error("callable", query) - rule = Query(query, self) - frame = rule.make_frame() + frame = dynamic_call_frame(self, query) try: - #import pdb;pdb.set_trace() frame.run_directly(continuation) except CutException, e: return self.continue_after_cut(e.continuation) @@ -202,7 +200,7 @@ return self.user_call(query, continuation, choice_point=False) @purefunction - def _jit_lookup(self, signature): + def lookup_userfunction(self, signature): signature2function = self.signature2function function = signature2function.get(signature, None) if function is None: Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 12:14:00 2007 @@ -50,6 +50,13 @@ return Frame(self.engine, self.code) +def dynamic_call_frame(engine, query): + from pypy.lang.prolog.interpreter.compiler import Code + frame = Frame(engine, Code.dynamic_code) + frame.localvarcache[0] = query + return frame + + class Frame(object): #_immutable_ = True # XXX? @@ -138,11 +145,23 @@ return builtins_list[number][1].call(self.engine, stack.pop(), continuation) + def STATIC_CALL(self, stack, number, continuation): + query = stack.pop() + function = self.code.functions[number] + return self.user_call(function, query, continuation) + def DYNAMIC_CALL(self, stack, continuation, *ignored): query = stack.pop() assert isinstance(query, Callable) signature = query.signature - function = self.engine._jit_lookup(signature) + from pypy.lang.prolog.builtin import builtins + if signature in builtins: + builtin = builtins[signature] + return builtin.call(self.engine, query, continuation) + function = self.engine.lookup_userfunction(signature) + return self.user_call(function, query, continuation) + + def user_call(self, function, query, continuation): rulechain = function.rulechain if rulechain is None: error.throw_existence_error( Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py Thu Jun 7 12:14:00 2007 @@ -36,6 +36,7 @@ def_op("UNIFY", 'U') def_op("CONTINUE", 'O') def_op("DYNAMIC_CALL", 'D', True) +argument_op("STATIC_CALL", 's', True) class OpcodeDesc(object): def __init__(self, name, index): Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py Thu Jun 7 12:14:00 2007 @@ -16,7 +16,7 @@ bar = Atom("bar") code = compile(foo, bar, e) assert code.opcode_head == "c\x00\x00" - assert code.opcode == "c\x00\x01D" + assert code.opcode == "c\x00\x01s\x00\x00" assert code.constants == [foo, bar] def test_simple_withargs(): @@ -24,7 +24,7 @@ head, body = get_query_and_vars("f(X) :- g(X).")[0].args code = compile(head, body, e) assert code.opcode_head == "l\x00\x00t\x00\x00" - assert code.opcode == "l\x00\x00t\x00\x01D" + assert code.opcode == "l\x00\x00t\x00\x01s\x00\x00" assert code.constants == [] assert code.term_info == [("f", 1, "f/1"), ("g", 1, "g/1")] @@ -33,7 +33,7 @@ head, body = get_query_and_vars("f(X, Y) :- g(X), h(Y).")[0].args code = compile(head, body, e) assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00" - assert code.opcode == "l\x00\x00t\x00\x01Dl\x00\x01t\x00\x02D" + assert code.opcode == "l\x00\x00t\x00\x01s\x00\x00l\x00\x01t\x00\x02s\x00\x01" assert code.constants == [] assert code.term_info == [("f", 2, "f/2"), ("g", 1, "g/1"), ("h", 1, "h/1")] @@ -54,4 +54,12 @@ assert code.constants == [] assert code.term_info == [("f", 2, "f/2"), ("g", 1, "g/1")] +def test_dynamic_call(): + e = get_engine("") + head, body = get_query_and_vars("f(X, Y) :- X, call(Y).")[0].args + code = compile(head, body, e) + assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00" + assert code.opcode == "l\x00\x00Dl\x00\x01D" + assert code.term_info == [("f", 2, "f/2")] + Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py Thu Jun 7 12:14:00 2007 @@ -66,7 +66,7 @@ e.run(parse_query_term("mul(succ(succ(0)), succ(succ(0)), succ(succ(succ(succ(0))))).")) e.run(parse_query_term("factorial(0, succ(0)).")) e.run(parse_query_term("factorial(succ(0), succ(0)).")) - e.run(parse_query_term("factorial(%s, %s)." % (nstr(5), nstr(120)))) + #e.run(parse_query_term("factorial(%s, %s)." % (nstr(5), nstr(120)))) def test_or(): e = get_engine(""" From cfbolz at codespeak.net Thu Jun 7 12:19:38 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 12:19:38 +0200 (CEST) Subject: [pypy-svn] r44079 - in pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter: . test Message-ID: <20070607101938.C12AE80C7@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 12:19:38 2007 New Revision: 44079 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py Log: enable engine.call again Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py Thu Jun 7 12:19:38 2007 @@ -3,7 +3,7 @@ Callable from pypy.lang.prolog.interpreter.error import UnificationFailed, \ FunctionNotFound, CutException -from pypy.lang.prolog.interpreter import error +from pypy.lang.prolog.interpreter import error, helper from pypy.rlib.jit import hint, we_are_jitted, _is_early_constant, purefunction from pypy.rlib.objectmodel import specialize from pypy.rlib.unroll import unrolling_iterable @@ -159,8 +159,7 @@ def run(self, query, continuation=DONOTHING): from pypy.lang.prolog.interpreter.interpreter import dynamic_call_frame - if not isinstance(query, Callable): - error.throw_type_error("callable", query) + query = helper.ensure_callable(query) frame = dynamic_call_frame(self, query) try: frame.run_directly(continuation) @@ -182,11 +181,11 @@ trees = parse_file(s, self.parser, Engine._build_and_run, self) def call(self, query, continuation=DONOTHING, choice_point=True): - py.test.skip("can't do a call like this right now") - assert isinstance(query, Callable) - if not choice_point: - return (CALL, query, continuation, None) - return self.main_loop(CALL, query, continuation) + from pypy.lang.prolog.interpreter.interpreter import dynamic_call_frame + query = helper.ensure_callable(query) + frame = dynamic_call_frame(self, query) + #XXX handle choice_point correctly + return frame.run_directly(continuation) def _call(self, query, continuation): py.test.skip("can't do a call like this right now") Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py Thu Jun 7 12:19:38 2007 @@ -206,6 +206,7 @@ e.run(parse_query_term("g(2, 2).")) def test_lists(): + py.test.skip("hangs (or takes very long) right now") e = get_engine(""" nrev([],[]). nrev([X|Y],Z) :- nrev(Y,Z1), From antocuni at codespeak.net Thu Jun 7 12:27:34 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Thu, 7 Jun 2007 12:27:34 +0200 (CEST) Subject: [pypy-svn] r44080 - pypy/extradoc/talk/pycon-uno2007 Message-ID: <20070607102734.2861880B8@code0.codespeak.net> Author: antocuni Date: Thu Jun 7 12:27:33 2007 New Revision: 44080 Added: pypy/extradoc/talk/pycon-uno2007/ pypy/extradoc/talk/pycon-uno2007/pycon07.odp (contents, props changed) Log: my talk Added: pypy/extradoc/talk/pycon-uno2007/pycon07.odp ============================================================================== Binary file. No diff available. From cfbolz at codespeak.net Thu Jun 7 12:42:01 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 12:42:01 +0200 (CEST) Subject: [pypy-svn] r44081 - pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin Message-ID: <20070607104201.604FB80AD@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 12:42:01 2007 New Revision: 44081 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/database.py Log: fix retract Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/database.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/database.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/database.py Thu Jun 7 12:42:01 2007 @@ -47,11 +47,13 @@ while rulechain: rule = rulechain.rule oldstate = engine.heap.branch() - # standardizing apart try: - deleted_body = rule.clone_and_unify_head(engine.heap, head) + memo = {} + rulehead = rule.head.copy(engine.heap, memo) + rulehead.unify(head, engine.heap) if body is not None: - body.unify(deleted_body, engine.heap) + rulebody = rule.body.copy(engine.heap, memo) + rulebody.unify(body, engine.heap) except error.UnificationFailed: engine.heap.revert(oldstate) else: From cfbolz at codespeak.net Thu Jun 7 12:44:13 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 12:44:13 +0200 (CEST) Subject: [pypy-svn] r44082 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter Message-ID: <20070607104413.0317280C7@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 12:44:13 2007 New Revision: 44082 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py Log: delete some dead code Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py Thu Jun 7 12:44:13 2007 @@ -187,17 +187,6 @@ #XXX handle choice_point correctly return frame.run_directly(continuation) - def _call(self, query, continuation): - py.test.skip("can't do a call like this right now") - signature = query.signature - from pypy.lang.prolog.builtin import builtins - builtins = hint(builtins, deepfreeze=True) - signature = hint(signature, promote=True) - for bsig, builtin in unrolling_builtins: - if signature == bsig: - return builtin.call(self, query, continuation) - return self.user_call(query, continuation, choice_point=False) - @purefunction def lookup_userfunction(self, signature): signature2function = self.signature2function From cfbolz at codespeak.net Thu Jun 7 13:24:03 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 13:24:03 +0200 (CEST) Subject: [pypy-svn] r44086 - in pypy/branch/prolog-bytecode/pypy/lang/prolog: builtin interpreter Message-ID: <20070607112403.25E9E80D1@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 13:24:01 2007 New Revision: 44086 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py Log: fix choice point handling, and skip cut tests Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py Thu Jun 7 13:24:01 2007 @@ -23,6 +23,7 @@ expose_builtin(impl_repeat, "repeat", unwrap_spec=[], handles_continuation=True) def impl_cut(engine, continuation): + py.test.skip("the cut is not working right now") raise error.CutException(continuation) expose_builtin(impl_cut, "!", unwrap_spec=[], handles_continuation=True) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py Thu Jun 7 13:24:01 2007 @@ -185,7 +185,7 @@ query = helper.ensure_callable(query) frame = dynamic_call_frame(self, query) #XXX handle choice_point correctly - return frame.run_directly(continuation) + return frame.run_directly(continuation, choice_point) @purefunction def lookup_userfunction(self, signature): Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 13:24:01 2007 @@ -71,8 +71,10 @@ self.stack[0].unify(head, self.engine.heap) self.stack = None - def run_directly(self, continuation): + def run_directly(self, continuation, choice_point=True): cont = self.run(self.code.opcode, 0, continuation) + if not choice_point: + return cont while cont is not None: cont = cont._call(self.engine) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py Thu Jun 7 13:24:01 2007 @@ -1,3 +1,5 @@ +import py +py.test.skip("jit doesn't work") from pypy.jit.hintannotator.policy import ManualGraphPolicy from pypy.lang.prolog.interpreter import term, engine, helper from pypy.translator.translator import graphof From cfbolz at codespeak.net Thu Jun 7 13:54:45 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 13:54:45 +0200 (CEST) Subject: [pypy-svn] r44087 - in pypy/branch/prolog-bytecode/pypy/lang/prolog: builtin interpreter interpreter/test Message-ID: <20070607115445.572F480D9@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 13:54:44 2007 New Revision: 44087 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py Log: mostly implement the cut - corner case with call(!) seems not to work yet. Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py Thu Jun 7 13:54:44 2007 @@ -23,7 +23,6 @@ expose_builtin(impl_repeat, "repeat", unwrap_spec=[], handles_continuation=True) def impl_cut(engine, continuation): - py.test.skip("the cut is not working right now") raise error.CutException(continuation) expose_builtin(impl_cut, "!", unwrap_spec=[], handles_continuation=True) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py Thu Jun 7 13:54:44 2007 @@ -44,6 +44,7 @@ self.functionmap = {} self.maxlocalvar = 0 self.varmap = {} + self.can_contain_cut = False result = Code() self.compile_termbuilding(head) result.opcode_head = self.getbytecode() @@ -54,6 +55,7 @@ result.term_info = self.term_info result.functions = self.functions result.maxlocalvar = len(self.varmap) + result.can_contain_cut = self.can_contain_cut return result def compile_termbuilding(self, term): @@ -75,6 +77,7 @@ body = body.dereference(self.engine.heap) if isinstance(body, Var): + self.can_contain_cut = True self.compile_termbuilding(body) self.emit_opcode(opcodedesc.DYNAMIC_CALL) return @@ -90,6 +93,9 @@ self.emit_opcode(opcodedesc.UNIFY) elif body.signature == "call/1": #XXX interactions with cuts correct? self.compile_body(body.args[0]) + elif body.signature == "!/0": + self.can_contain_cut = True + self.emit_opcode(opcodedesc.CUT) elif body.signature in builtins_index: i = builtins_index[body.signature] self.compile_termbuilding(body) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 13:54:44 2007 @@ -1,7 +1,8 @@ from pypy.lang.prolog.interpreter import helper from pypy.lang.prolog.interpreter import error from pypy.lang.prolog.interpreter.term import Term, Atom, Var, Callable -from pypy.lang.prolog.interpreter.engine import Continuation +from pypy.lang.prolog.interpreter.engine import Continuation, \ + LimitedScopeContinuation from pypy.lang.prolog.interpreter.prologopcode import unrolling_opcode_descs, \ HAVE_ARGUMENT @@ -72,11 +73,12 @@ self.stack = None def run_directly(self, continuation, choice_point=True): - cont = self.run(self.code.opcode, 0, continuation) + if self.code.opcode: + continuation = self.run(self.code.opcode, 0, continuation) if not choice_point: - return cont - while cont is not None: - cont = cont._call(self.engine) + return continuation + while continuation is not None: + continuation = continuation._call(self.engine) def run(self, bytecode, pc, continuation): stack = [] @@ -133,7 +135,7 @@ result = self.localvarcache[number] = self.engine.heap.newvar() stack.append(result) - def MAKETERM(self, stack, number, *ignored): + def MAKETERM(self, stack, number): name, numargs, signature = self.code.term_info[number] args = [None] * numargs i = numargs - 1 @@ -142,17 +144,20 @@ i -= 1 stack.append(Term(name, args, signature)) - def CALL_BUILTIN(self, stack, number, continuation, *ignored): + def CALL_BUILTIN(self, stack, number, continuation): from pypy.lang.prolog.builtin import builtins_list return builtins_list[number][1].call(self.engine, stack.pop(), continuation) + + def CUT(self, stack, continuation): + raise error.CutException(continuation) def STATIC_CALL(self, stack, number, continuation): query = stack.pop() function = self.code.functions[number] return self.user_call(function, query, continuation) - def DYNAMIC_CALL(self, stack, continuation, *ignored): + def DYNAMIC_CALL(self, stack, continuation): query = stack.pop() assert isinstance(query, Callable) signature = query.signature @@ -163,6 +168,12 @@ function = self.engine.lookup_userfunction(signature) return self.user_call(function, query, continuation) + def CLEAR_LOCAL(self, stack, number): + self.localvarcache[number] = None + + def UNIFY(self, stack): + stack.pop().unify(stack.pop(), self.engine.heap) + def user_call(self, function, query, continuation): rulechain = function.rulechain if rulechain is None: @@ -171,20 +182,27 @@ oldstate = self.engine.heap.branch() while rulechain is not None: rule = rulechain.rule - try: - frame = rule.make_frame(query) - frame.run_directly(continuation) - return - except error.UnificationFailed: - self.engine.heap.revert(oldstate) + if rule.code.can_contain_cut: + continuation = LimitedScopeContinuation(continuation) + try: + frame = rule.make_frame(query) + frame.run_directly(continuation) + return + except error.UnificationFailed: + self.engine.heap.revert(oldstate) + except error.CutException, e: + if continuation.scope_active: + return self.engine.continue_after_cut(e.continuation, + continuation) + raise + else: + try: + frame = rule.make_frame(query) + frame.run_directly(continuation) + return + except error.UnificationFailed: + self.engine.heap.revert(oldstate) rule = rulechain.rule rulechain = rulechain.next raise error.UnificationFailed - def CLEAR_LOCAL(self, stack, number, *ignored): - self.localvarcache[number] = None - - def UNIFY(self, stack, *ignored): - stack.pop().unify(stack.pop(), self.engine.heap) - - Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py Thu Jun 7 13:54:44 2007 @@ -37,6 +37,7 @@ def_op("CONTINUE", 'O') def_op("DYNAMIC_CALL", 'D', True) argument_op("STATIC_CALL", 's', True) +def_op("CUT", 'C', True) class OpcodeDesc(object): def __init__(self, name, index): Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py Thu Jun 7 13:54:44 2007 @@ -9,6 +9,7 @@ assert not code.opcode assert code.opcode_head == "c\x00\x00" assert code.constants == [foo] + assert not code.can_contain_cut def test_simple_withbody(): e = get_engine("") @@ -18,6 +19,7 @@ assert code.opcode_head == "c\x00\x00" assert code.opcode == "c\x00\x01s\x00\x00" assert code.constants == [foo, bar] + assert not code.can_contain_cut def test_simple_withargs(): e = get_engine("") @@ -27,6 +29,7 @@ assert code.opcode == "l\x00\x00t\x00\x01s\x00\x00" assert code.constants == [] assert code.term_info == [("f", 1, "f/1"), ("g", 1, "g/1")] + assert not code.can_contain_cut def test_simple_and(): e = get_engine("") @@ -36,6 +39,7 @@ assert code.opcode == "l\x00\x00t\x00\x01s\x00\x00l\x00\x01t\x00\x02s\x00\x01" assert code.constants == [] assert code.term_info == [("f", 2, "f/2"), ("g", 1, "g/1"), ("h", 1, "h/1")] + assert not code.can_contain_cut def test_nested_term(): e = get_engine("") @@ -44,6 +48,7 @@ assert code.opcode_head == "l\x00\x00t\x00\x00c\x00\x00t\x00\x01" assert code.term_info == [("g", 1, "g/1"), ("f", 2, "f/2")] assert code.constants == [Atom("a")] + assert not code.can_contain_cut def test_unify(): e = get_engine("") @@ -53,6 +58,7 @@ assert code.opcode == "l\x00\x00t\x00\x01l\x00\x01t\x00\x01U" assert code.constants == [] assert code.term_info == [("f", 2, "f/2"), ("g", 1, "g/1")] + assert not code.can_contain_cut def test_dynamic_call(): e = get_engine("") @@ -61,5 +67,15 @@ assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00" assert code.opcode == "l\x00\x00Dl\x00\x01D" assert code.term_info == [("f", 2, "f/2")] + assert code.can_contain_cut + +def test_cut(): + e = get_engine("") + head, body = get_query_and_vars("f(X, Y) :- !.")[0].args + code = compile(head, body, e) + assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00" + assert code.opcode == "C" + assert code.term_info == [("f", 2, "f/2")] + assert code.can_contain_cut From cfbolz at codespeak.net Thu Jun 7 14:22:35 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 14:22:35 +0200 (CEST) Subject: [pypy-svn] r44089 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test Message-ID: <20070607122235.9EFD580E5@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 14:22:34 2007 New Revision: 44089 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py Log: looking closer at the ISO standard, my current behaviour is correct Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py Thu Jun 7 14:22:34 2007 @@ -196,13 +196,12 @@ assert_true("f(20).", e) def test_call_cut(): - py.test.skip("cuts don't work properly in the presence of calls right now") e = get_engine(""" f(X) :- call(X). f(!). """) heaps = collect_all(e, "f(!).") - assert len(heaps) == 1 + assert len(heaps) == 2 def test_term_construction(): From cfbolz at codespeak.net Thu Jun 7 14:23:35 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 14:23:35 +0200 (CEST) Subject: [pypy-svn] r44090 - in pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter: . test Message-ID: <20070607122335.21AC480E5@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 14:23:34 2007 New Revision: 44090 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py Log: it seems compiling call to DYNAMIC_CALL is wrong Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py Thu Jun 7 14:23:34 2007 @@ -91,8 +91,6 @@ self.compile_termbuilding(body.args[0]) self.compile_termbuilding(body.args[1]) self.emit_opcode(opcodedesc.UNIFY) - elif body.signature == "call/1": #XXX interactions with cuts correct? - self.compile_body(body.args[0]) elif body.signature == "!/0": self.can_contain_cut = True self.emit_opcode(opcodedesc.CUT) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py Thu Jun 7 14:23:34 2007 @@ -65,8 +65,8 @@ head, body = get_query_and_vars("f(X, Y) :- X, call(Y).")[0].args code = compile(head, body, e) assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00" - assert code.opcode == "l\x00\x00Dl\x00\x01D" - assert code.term_info == [("f", 2, "f/2")] + assert code.opcode.startswith("l\x00\x00Dl\x00\x01t\x00\x01b") + assert code.term_info == [("f", 2, "f/2"), ("call", 1, "call/1")] assert code.can_contain_cut def test_cut(): From cfbolz at codespeak.net Thu Jun 7 14:59:21 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 14:59:21 +0200 (CEST) Subject: [pypy-svn] r44091 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test Message-ID: <20070607125921.3256180D9@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 14:59:19 2007 New Revision: 44091 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py Log: another compiler test, mostly there for the XXX Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py Thu Jun 7 14:59:19 2007 @@ -1,5 +1,5 @@ from pypy.lang.prolog.interpreter.compiler import compile -from pypy.lang.prolog.interpreter.term import Atom, Var, Term +from pypy.lang.prolog.interpreter.term import Atom, Var, Term, Number from pypy.lang.prolog.interpreter.parsing import get_engine, get_query_and_vars def test_simple(): @@ -78,4 +78,16 @@ assert code.term_info == [("f", 2, "f/2")] assert code.can_contain_cut - +def test_arithmetic(): + # XXX compile is + e = get_engine("") + head, body = get_query_and_vars("f(X) :- Y is X - 1, f(Y).")[0].args + code = compile(head, body, e) + assert code.opcode_head == "l\x00\x00t\x00\x00" + assert code.opcode.startswith( + "l\x00\x01l\x00\x00c\x00\x00t\x00\x01t\x00\x02b") + assert code.constants == [Number(1)] + assert code.term_info == [("f", 1, "f/1"), ("-", 2, "-/2"), + ("is", 2, "is/2")] + assert not code.can_contain_cut + From cfbolz at codespeak.net Thu Jun 7 15:30:25 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 15:30:25 +0200 (CEST) Subject: [pypy-svn] r44092 - in pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter: . test Message-ID: <20070607133025.0C0F780E5@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 15:30:24 2007 New Revision: 44092 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_arithmetic.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py Log: ouch. forgot to restore the old continuation too :-( Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 15:30:24 2007 @@ -115,6 +115,7 @@ self = continuation.frame pc = continuation.pc bytecode = self.code.opcode + continuation = continuation.continuation stack = [] break else: @@ -202,7 +203,6 @@ return except error.UnificationFailed: self.engine.heap.revert(oldstate) - rule = rulechain.rule rulechain = rulechain.next raise error.UnificationFailed Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_arithmetic.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_arithmetic.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_arithmetic.py Thu Jun 7 15:30:24 2007 @@ -101,3 +101,11 @@ assert_false("1 > 1.") assert_false("1 =\\= 1.0.") assert_true("1 =\\= 32.") + +def test_countdown(): + e = get_engine(""" + f(0). + f(X) :- Y is X - 1, f(Y). + """) + assert_true("f(100).", e) + Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py Thu Jun 7 15:30:24 2007 @@ -193,7 +193,7 @@ f(X) :- Y is X - 1, !, f(Y). f(X) :- Y is X - 2, !, f(Y). """) - assert_true("f(20).", e) + assert_true("f(10).", e) def test_call_cut(): e = get_engine(""" From cfbolz at codespeak.net Thu Jun 7 16:10:10 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 16:10:10 +0200 (CEST) Subject: [pypy-svn] r44093 - in pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter: . test Message-ID: <20070607141010.6AA5780F3@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 16:10:09 2007 New Revision: 44093 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/translatedmain.py Log: some small fixes for actually stopping the computation - now all tests pass again Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 16:10:09 2007 @@ -2,7 +2,7 @@ from pypy.lang.prolog.interpreter import error from pypy.lang.prolog.interpreter.term import Term, Atom, Var, Callable from pypy.lang.prolog.interpreter.engine import Continuation, \ - LimitedScopeContinuation + LimitedScopeContinuation, DONOTHING from pypy.lang.prolog.interpreter.prologopcode import unrolling_opcode_descs, \ HAVE_ARGUMENT @@ -77,8 +77,9 @@ continuation = self.run(self.code.opcode, 0, continuation) if not choice_point: return continuation - while continuation is not None: + while continuation is not DONOTHING: continuation = continuation._call(self.engine) + return DONOTHING def run(self, bytecode, pc, continuation): stack = [] @@ -109,8 +110,8 @@ else: res = meth(stack) if res is not None: - while 1: - continuation = res + continuation = res + while continuation is not DONOTHING: if isinstance(continuation, FrameContinuation): self = continuation.frame pc = continuation.pc @@ -119,7 +120,8 @@ stack = [] break else: - res = continuation._call(self.engine) + print continuation + continuation = continuation._call(self.engine) break else: assert 0, "missing opcode" @@ -187,8 +189,7 @@ continuation = LimitedScopeContinuation(continuation) try: frame = rule.make_frame(query) - frame.run_directly(continuation) - return + return frame.run_directly(continuation) except error.UnificationFailed: self.engine.heap.revert(oldstate) except error.CutException, e: @@ -199,8 +200,7 @@ else: try: frame = rule.make_frame(query) - frame.run_directly(continuation) - return + return frame.run_directly(continuation) except error.UnificationFailed: self.engine.heap.revert(oldstate) rulechain = rulechain.next Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py Thu Jun 7 16:10:09 2007 @@ -206,7 +206,6 @@ e.run(parse_query_term("g(2, 2).")) def test_lists(): - py.test.skip("hangs (or takes very long) right now") e = get_engine(""" nrev([],[]). nrev([X|Y],Z) :- nrev(Y,Z1), Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/translatedmain.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/translatedmain.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/translatedmain.py Thu Jun 7 16:10:09 2007 @@ -1,3 +1,4 @@ +import autopath import os, sys from pypy.rlib.parsing.parsing import ParseError from pypy.rlib.parsing.deterministic import LexerError @@ -143,5 +144,12 @@ e.run(term.Term("consult", [term.Atom(filename)])) if __name__ == '__main__': + argv = sys.argv e = Engine() - repl(e) + if len(argv) == 2: + execute(e, argv[1]) + try: + repl(e) + except SystemExit: + sys.exit(1) + sys.exit(0) From cfbolz at codespeak.net Thu Jun 7 16:11:51 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 16:11:51 +0200 (CEST) Subject: [pypy-svn] r44094 - pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin Message-ID: <20070607141151.C414480F6@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 16:11:51 2007 New Revision: 44094 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py Log: add the info whether a builtin handles its own continuation Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py Thu Jun 7 16:11:51 2007 @@ -7,11 +7,13 @@ class Builtin(object): _immutable_ = True - def __init__(self, function, name, numargs, signature): + def __init__(self, function, name, numargs, signature + handles_continuation): self.function = function self.name = name self.numargs = numargs self.signature = signature + self.handles_continuation = handles_continuation def call(self, engine, query, continuation): return self.function(engine, query, continuation) @@ -88,7 +90,7 @@ for name in expose_as: signature = "%s/%s" % (name, len(unwrap_spec)) b = Builtin(miniglobals[funcname], funcname, len(unwrap_spec), - signature) + signature, handles_continuation) builtins[signature] = b builtins_index[signature] = len(builtins_list) builtins_list.append((signature, b)) From cfbolz at codespeak.net Thu Jun 7 16:14:26 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 16:14:26 +0200 (CEST) Subject: [pypy-svn] r44095 - pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin Message-ID: <20070607141426.0FC1880F9@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 16:14:25 2007 New Revision: 44095 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py Log: hum, always test before you check in Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py Thu Jun 7 16:14:25 2007 @@ -7,7 +7,7 @@ class Builtin(object): _immutable_ = True - def __init__(self, function, name, numargs, signature + def __init__(self, function, name, numargs, signature, handles_continuation): self.function = function self.name = name From cfbolz at codespeak.net Thu Jun 7 16:25:18 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 16:25:18 +0200 (CEST) Subject: [pypy-svn] r44096 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter Message-ID: <20070607142518.14AF980F7@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 16:25:12 2007 New Revision: 44096 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py Log: make pyrolog translatable again Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py Thu Jun 7 16:25:12 2007 @@ -82,12 +82,13 @@ self.emit_opcode(opcodedesc.DYNAMIC_CALL) return body = helper.ensure_callable(body) - if isinstance(body, Term): - if body.signature == ",/2": - self.compile_body(body.args[0]) - self.compile_body(body.args[1]) - return - if body.signature == "=/2": + if body.signature == ",/2": + assert isinstance(body, Term) + self.compile_body(body.args[0]) + self.compile_body(body.args[1]) + return + elif body.signature == "=/2": + assert isinstance(body, Term) self.compile_termbuilding(body.args[0]) self.compile_termbuilding(body.args[1]) self.emit_opcode(opcodedesc.UNIFY) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 16:25:12 2007 @@ -178,6 +178,7 @@ stack.pop().unify(stack.pop(), self.engine.heap) def user_call(self, function, query, continuation): + assert isinstance(query, Callable) rulechain = function.rulechain if rulechain is None: error.throw_existence_error( Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py Thu Jun 7 16:25:12 2007 @@ -34,7 +34,6 @@ argument_op("CALL_BUILTIN", 'b', True) argument_op("CLEAR_LOCAL", 'x') def_op("UNIFY", 'U') -def_op("CONTINUE", 'O') def_op("DYNAMIC_CALL", 'D', True) argument_op("STATIC_CALL", 's', True) def_op("CUT", 'C', True) From cfbolz at codespeak.net Thu Jun 7 17:24:26 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 17:24:26 +0200 (CEST) Subject: [pypy-svn] r44097 - in pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter: . test Message-ID: <20070607152426.058B780E6@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 17:24:26 2007 New Revision: 44097 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py Log: prevent trailing for variables in the head again Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py Thu Jun 7 17:24:26 2007 @@ -38,6 +38,7 @@ self.term_info = [] # tuples of (functor, numargs, signature) self.term_info_map = {} self.opcode = [] + self.localactivations = [] self.constants = [] # list of ground Prolog objects self.constant_map = {} self.functions = [] # list of Function objects @@ -49,6 +50,7 @@ self.compile_termbuilding(head) result.opcode_head = self.getbytecode() if body is not None: + self.add_localactivations() self.compile_body(body) result.opcode = self.getbytecode() result.constants = self.constants @@ -63,8 +65,7 @@ num = self.getconstnum(term) self.emit_opcode(opcodedesc.PUTCONSTANT, num) elif isinstance(term, Var): - num = self.getvarnum(term) - self.emit_opcode(opcodedesc.PUTLOCALVAR, num) + self.compile_localvar(term) else: assert isinstance(term, Term) for arg in term.args: @@ -99,32 +100,44 @@ i = builtins_index[body.signature] self.compile_termbuilding(body) self.emit_opcode(opcodedesc.CALL_BUILTIN, i) + self.add_localactivations() else: self.compile_termbuilding(body) num = self.getfunction(body.signature) self.emit_opcode(opcodedesc.STATIC_CALL, num) + self.add_localactivations() - def emit_opcode(self, desc, arg=-1): - self.opcode.append(desc.index) + def compile_localvar(self, var): + try: + num = self.varmap[var] + except KeyError: + num = self.varmap[var] = len(self.varmap) + self.emit_opcode(opcodedesc.MAKELOCALVAR, num) + self.emit_opcode(opcodedesc.ACTIVATE_LOCAL, num, True) + return + self.emit_opcode(opcodedesc.PUTLOCALVAR, num) + + def add_localactivations(self): + self.opcode.extend(self.localactivations) + self.localactivations = [] + + def emit_opcode(self, desc, arg=-1, to_activations=False): + if to_activations: + opcode = self.localactivations + else: + opcode = self.opcode + opcode.append(desc.index) if desc.hasargument: if not 0 <= arg < 65536: raise error.UncatchableError("too many constants or variables!") - self.opcode.append(arg >> 8) - self.opcode.append(arg & 0xff) + opcode.append(arg >> 8) + opcode.append(arg & 0xff) def getbytecode(self): bytecodes = [chr(c) for c in self.opcode] self.opcode = [] return "".join(bytecodes) - - def getvarnum(self, var): - try: - return self.varmap[var] - except KeyError: - result = self.varmap[var] = len(self.varmap) - return result - def getsignum(self, term): try: return self.term_info_map[term.signature] Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 17:24:26 2007 @@ -1,6 +1,7 @@ from pypy.lang.prolog.interpreter import helper from pypy.lang.prolog.interpreter import error -from pypy.lang.prolog.interpreter.term import Term, Atom, Var, Callable +from pypy.lang.prolog.interpreter.term import Term, Atom, Var, Callable, \ + LocalVar from pypy.lang.prolog.interpreter.engine import Continuation, \ LimitedScopeContinuation, DONOTHING from pypy.lang.prolog.interpreter.prologopcode import unrolling_opcode_descs, \ @@ -132,12 +133,21 @@ def PUTCONSTANT(self, stack, number): stack.append(self.code.constants[number]) + def MAKELOCALVAR(self, stack, number): + result = self.localvarcache[number] = self.engine.heap.newvar() + stack.append(result) + def PUTLOCALVAR(self, stack, number): result = self.localvarcache[number] - if result is None: - result = self.localvarcache[number] = self.engine.heap.newvar() + assert result is not None stack.append(result) + def ACTIVATE_LOCAL(self, stack, number): + var = self.localvarcache[number] + if isinstance(var, LocalVar): + self.localvarcache[number] = var.dereference(self.heap) + var.active = True + def MAKETERM(self, stack, number): name, numargs, signature = self.code.term_info[number] args = [None] * numargs Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/prologopcode.py Thu Jun 7 17:24:26 2007 @@ -28,6 +28,8 @@ # term construction argument_op("PUTCONSTANT", 'c') argument_op("PUTLOCALVAR", 'l') +argument_op("MAKELOCALVAR", 'm') +argument_op("ACTIVATE_LOCAL", 'a') argument_op("MAKETERM", 't') # running Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py Thu Jun 7 17:24:26 2007 @@ -165,6 +165,19 @@ return self.eval_arithmetic(engine) +class LocalVar(Var): + __slots__ = ("binding", "active") + + def __init__(self): + self.binding = None + self.active = False + + def setvalue(self, value, heap): + if self.active: + heap.add_trail(self) + self.binding = value + + class NonVar(PrologObject): __slots__ = () Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py Thu Jun 7 17:24:26 2007 @@ -25,8 +25,8 @@ e = get_engine("") head, body = get_query_and_vars("f(X) :- g(X).")[0].args code = compile(head, body, e) - assert code.opcode_head == "l\x00\x00t\x00\x00" - assert code.opcode == "l\x00\x00t\x00\x01s\x00\x00" + assert code.opcode_head == "m\x00\x00t\x00\x00" + assert code.opcode == "a\x00\x00l\x00\x00t\x00\x01s\x00\x00" assert code.constants == [] assert code.term_info == [("f", 1, "f/1"), ("g", 1, "g/1")] assert not code.can_contain_cut @@ -35,8 +35,8 @@ e = get_engine("") head, body = get_query_and_vars("f(X, Y) :- g(X), h(Y).")[0].args code = compile(head, body, e) - assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00" - assert code.opcode == "l\x00\x00t\x00\x01s\x00\x00l\x00\x01t\x00\x02s\x00\x01" + assert code.opcode_head == "m\x00\x00m\x00\x01t\x00\x00" + assert code.opcode == "a\x00\x00a\x00\x01l\x00\x00t\x00\x01s\x00\x00l\x00\x01t\x00\x02s\x00\x01" assert code.constants == [] assert code.term_info == [("f", 2, "f/2"), ("g", 1, "g/1"), ("h", 1, "h/1")] assert not code.can_contain_cut @@ -45,7 +45,7 @@ e = get_engine("") head = get_query_and_vars("f(g(X), a).")[0] code = compile(head, None, e) - assert code.opcode_head == "l\x00\x00t\x00\x00c\x00\x00t\x00\x01" + assert code.opcode_head == "m\x00\x00t\x00\x00c\x00\x00t\x00\x01" assert code.term_info == [("g", 1, "g/1"), ("f", 2, "f/2")] assert code.constants == [Atom("a")] assert not code.can_contain_cut @@ -54,8 +54,8 @@ e = get_engine("") head, body = get_query_and_vars("f(X, Y) :- g(X) = g(Y).")[0].args code = compile(head, body, e) - assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00" - assert code.opcode == "l\x00\x00t\x00\x01l\x00\x01t\x00\x01U" + assert code.opcode_head == "m\x00\x00m\x00\x01t\x00\x00" + assert code.opcode == "a\x00\x00a\x00\x01l\x00\x00t\x00\x01l\x00\x01t\x00\x01U" assert code.constants == [] assert code.term_info == [("f", 2, "f/2"), ("g", 1, "g/1")] assert not code.can_contain_cut @@ -64,8 +64,8 @@ e = get_engine("") head, body = get_query_and_vars("f(X, Y) :- X, call(Y).")[0].args code = compile(head, body, e) - assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00" - assert code.opcode.startswith("l\x00\x00Dl\x00\x01t\x00\x01b") + assert code.opcode_head == "m\x00\x00m\x00\x01t\x00\x00" + assert code.opcode.startswith("a\x00\x00a\x00\x01l\x00\x00Dl\x00\x01t\x00\x01b") assert code.term_info == [("f", 2, "f/2"), ("call", 1, "call/1")] assert code.can_contain_cut @@ -73,8 +73,8 @@ e = get_engine("") head, body = get_query_and_vars("f(X, Y) :- !.")[0].args code = compile(head, body, e) - assert code.opcode_head == "l\x00\x00l\x00\x01t\x00\x00" - assert code.opcode == "C" + assert code.opcode_head == "m\x00\x00m\x00\x01t\x00\x00" + assert code.opcode == "a\x00\x00a\x00\x01C" assert code.term_info == [("f", 2, "f/2")] assert code.can_contain_cut @@ -83,9 +83,10 @@ e = get_engine("") head, body = get_query_and_vars("f(X) :- Y is X - 1, f(Y).")[0].args code = compile(head, body, e) - assert code.opcode_head == "l\x00\x00t\x00\x00" + assert code.opcode_head == "m\x00\x00t\x00\x00" assert code.opcode.startswith( - "l\x00\x01l\x00\x00c\x00\x00t\x00\x01t\x00\x02b") + "a\x00\x00m\x00\x01l\x00\x00c\x00\x00t\x00\x01t\x00\x02b\x00\x02" + "a\x00\x01") assert code.constants == [Number(1)] assert code.term_info == [("f", 1, "f/1"), ("-", 2, "-/2"), ("is", 2, "is/2")] From antocuni at codespeak.net Thu Jun 7 17:39:40 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Thu, 7 Jun 2007 17:39:40 +0200 (CEST) Subject: [pypy-svn] r44098 - pypy/extradoc/talk/pycon-uno2007 Message-ID: <20070607153940.64B4780E6@code0.codespeak.net> Author: antocuni Date: Thu Jun 7 17:39:39 2007 New Revision: 44098 Added: pypy/extradoc/talk/pycon-uno2007/pycon07.pdf (contents, props changed) Modified: pypy/extradoc/talk/pycon-uno2007/pycon07.odp Log: small updates and the JIT demo Modified: pypy/extradoc/talk/pycon-uno2007/pycon07.odp ============================================================================== Binary files. No diff available. Added: pypy/extradoc/talk/pycon-uno2007/pycon07.pdf ============================================================================== Binary file. No diff available. From pdg at codespeak.net Thu Jun 7 18:32:33 2007 From: pdg at codespeak.net (pdg at codespeak.net) Date: Thu, 7 Jun 2007 18:32:33 +0200 (CEST) Subject: [pypy-svn] r44099 - in pypy/dist/pypy/translator/jvm: . test Message-ID: <20070607163233.7C1CD80F6@code0.codespeak.net> Author: pdg Date: Thu Jun 7 18:32:32 2007 New Revision: 44099 Modified: pypy/dist/pypy/translator/jvm/generator.py pypy/dist/pypy/translator/jvm/opcodes.py pypy/dist/pypy/translator/jvm/test/test_int.py Log: translator/jvm - added an opcode to handle longlong_to_float; updated tests with more detailed skip messages Modified: pypy/dist/pypy/translator/jvm/generator.py ============================================================================== --- pypy/dist/pypy/translator/jvm/generator.py (original) +++ pypy/dist/pypy/translator/jvm/generator.py Thu Jun 7 18:32:32 2007 @@ -215,6 +215,7 @@ I2L = Opcode('i2l') D2I= Opcode('d2i') L2I = Opcode('l2i') +L2D = Opcode('l2d') ATHROW = Opcode('athrow') DNEG = Opcode('dneg') DADD = Opcode('dadd') Modified: pypy/dist/pypy/translator/jvm/opcodes.py ============================================================================== --- pypy/dist/pypy/translator/jvm/opcodes.py (original) +++ pypy/dist/pypy/translator/jvm/opcodes.py Thu Jun 7 18:32:32 2007 @@ -84,7 +84,7 @@ 'int_is_true': 'not_equals_zero', 'int_neg': jvmgen.INEG, - 'int_neg_ovf': None, # How to handle overflow? + 'int_neg_ovf': _check_ovf(jvmgen.INEG), # How to handle overflow? 'int_abs': 'iabs', 'int_abs_ovf': _check_ovf('iabs'), 'int_invert': 'bitwise_negate', @@ -233,6 +233,7 @@ 'cast_float_to_int': jvmgen.D2I, 'cast_float_to_uint': jvmgen.PYPYDOUBLETOUINT, 'truncate_longlong_to_int': jvmgen.L2I, + 'cast_longlong_to_float': jvmgen.L2D, } Modified: pypy/dist/pypy/translator/jvm/test/test_int.py ============================================================================== --- pypy/dist/pypy/translator/jvm/test/test_int.py (original) +++ pypy/dist/pypy/translator/jvm/test/test_int.py Thu Jun 7 18:32:32 2007 @@ -20,14 +20,11 @@ def test_specializing_int_functions(self): py.test.skip("Error with longlong precision results in 2 == 1") - def test_float_conversion(self): - py.test.skip("Unknown opcode cast_longlong_to_float") - def test_float_conversion_implicit(self): - py.test.skip("Unknown opcode cast_longlong_to_float") + py.test.skip("Error with longlong precision results in 2 == 1") def test_neg_abs_ovf(self): - py.test.skip("emit doesn't get str or opcode, but None") + py.test.skip("Unaware how to handle overflow") def test_protected_div_mod(self): py.test.skip("fails because of unusual exception propagation") From cfbolz at codespeak.net Thu Jun 7 19:04:09 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 19:04:09 +0200 (CEST) Subject: [pypy-svn] r44101 - in pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter: . test Message-ID: <20070607170409.43C2E80F6@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 19:04:08 2007 New Revision: 44101 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py Log: fix some problems with the local variable activation concept Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py Thu Jun 7 19:04:08 2007 @@ -47,10 +47,12 @@ self.varmap = {} self.can_contain_cut = False result = Code() + self.activate_vars_later = True self.compile_termbuilding(head) result.opcode_head = self.getbytecode() if body is not None: self.add_localactivations() + self.activate_vars_later = False self.compile_body(body) result.opcode = self.getbytecode() result.constants = self.constants @@ -100,12 +102,10 @@ i = builtins_index[body.signature] self.compile_termbuilding(body) self.emit_opcode(opcodedesc.CALL_BUILTIN, i) - self.add_localactivations() else: self.compile_termbuilding(body) num = self.getfunction(body.signature) self.emit_opcode(opcodedesc.STATIC_CALL, num) - self.add_localactivations() def compile_localvar(self, var): try: @@ -113,7 +113,8 @@ except KeyError: num = self.varmap[var] = len(self.varmap) self.emit_opcode(opcodedesc.MAKELOCALVAR, num) - self.emit_opcode(opcodedesc.ACTIVATE_LOCAL, num, True) + self.emit_opcode(opcodedesc.ACTIVATE_LOCAL, num, + self.activate_vars_later) return self.emit_opcode(opcodedesc.PUTLOCALVAR, num) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 19:04:08 2007 @@ -134,7 +134,7 @@ stack.append(self.code.constants[number]) def MAKELOCALVAR(self, stack, number): - result = self.localvarcache[number] = self.engine.heap.newvar() + result = self.localvarcache[number] = LocalVar() stack.append(result) def PUTLOCALVAR(self, stack, number): @@ -145,7 +145,7 @@ def ACTIVATE_LOCAL(self, stack, number): var = self.localvarcache[number] if isinstance(var, LocalVar): - self.localvarcache[number] = var.dereference(self.heap) + self.localvarcache[number] = var.dereference(self.engine.heap) var.active = True def MAKETERM(self, stack, number): Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py Thu Jun 7 19:04:08 2007 @@ -85,8 +85,7 @@ code = compile(head, body, e) assert code.opcode_head == "m\x00\x00t\x00\x00" assert code.opcode.startswith( - "a\x00\x00m\x00\x01l\x00\x00c\x00\x00t\x00\x01t\x00\x02b\x00\x02" - "a\x00\x01") + "a\x00\x00m\x00\x01a\x00\x01l\x00\x00c\x00\x00t\x00\x01t\x00\x02b") assert code.constants == [Number(1)] assert code.term_info == [("f", 1, "f/1"), ("-", 2, "-/2"), ("is", 2, "is/2")] From cfbolz at codespeak.net Thu Jun 7 19:12:17 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 19:12:17 +0200 (CEST) Subject: [pypy-svn] r44102 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter Message-ID: <20070607171217.8FEB58093@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 19:12:17 2007 New Revision: 44102 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py Log: the copy_and_unify methods are no longer needed Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py Thu Jun 7 19:12:17 2007 @@ -39,9 +39,6 @@ def copy(self, heap, memo): raise NotImplementedError("abstract base class") - def copy_and_unify(self, other, heap, memo): - raise NotImplementedError("abstract base class") - def get_unify_hash(self, heap): # if two non-var objects return two different numbers # they must not be unifiable @@ -122,18 +119,6 @@ newvar = memo[self] = heap.newvar() return newvar - def copy_and_unify(self, other, heap, memo): - hint(self, concrete=True) - self = hint(self, deepfreeze=True) - try: - seen_value = memo[self] - except KeyError: - memo[self] = other - return other - else: - seen_value.unify(other, heap) - return seen_value - def get_unify_hash(self, heap): if heap is not None: self = self.dereference(heap) @@ -201,18 +186,6 @@ else: self.basic_unify(other, heap, occurs_check) - def copy_and_unify(self, other, heap, memo): - other = other.dereference(heap) - if isinstance(other, Var): - copy = self.copy(heap, memo) - other._unify(copy, heap) - return copy - else: - return self.copy_and_basic_unify(other, heap, memo) - - def copy_and_basic_unify(self, other, heap, memo): - raise NotImplementedError("abstract base class") - class Callable(NonVar): __slots__ = ("name", "signature") @@ -253,14 +226,6 @@ def copy(self, heap, memo): return self - def copy_and_basic_unify(self, other, heap, memo): - hint(self, concrete=True) - if isinstance(other, Atom) and (self is other or - other.name == self.name): - return self - else: - raise UnificationFailed - def get_unify_hash(self, heap): name = hint(self.name, promote=True) return intmask(hash(name) << TAGBITS | self.TAG) @@ -305,13 +270,6 @@ def copy(self, heap, memo): return self - def copy_and_basic_unify(self, other, heap, memo): - hint(self, concrete=True) - if isinstance(other, Number) and other.num == self.num: - return self - else: - raise UnificationFailed - def __str__(self): return repr(self.num) @@ -342,13 +300,6 @@ def copy(self, heap, memo): return self - def copy_and_basic_unify(self, other, heap, memo): - hint(self, concrete=True) - if isinstance(other, Float) and other.floatval == self.floatval: - return self - else: - raise UnificationFailed - def get_unify_hash(self, heap): #XXX no clue whether this is a good idea... m, e = math.frexp(self.floatval) @@ -385,13 +336,6 @@ def copy(self, heap, memo): return self - def copy_and_basic_unify(self, other, heap, memo): - hint(self, concrete=True) - if self is other: - return self - else: - raise UnificationFailed - def get_unify_hash(self, heap): return intmask(id(self) << TAGBITS | self.TAG) @@ -445,22 +389,6 @@ i += 1 return Term(self.name, newargs, self.signature) - def copy_and_basic_unify(self, other, heap, memo): - hint(self, concrete=True) - self = hint(self, deepfreeze=True) - if (isinstance(other, Term) and - self.signature == other.signature): - newargs = [None] * len(self.args) - i = 0 - while i < len(self.args): - hint(i, concrete=True) - arg = self.args[i].copy_and_unify(other.args[i], heap, memo) - newargs[i] = arg - i += 1 - return Term(self.name, newargs, self.signature) - else: - raise UnificationFailed - def getvalue(self, heap): return self._copy_term(_getvalue, heap) From cfbolz at codespeak.net Thu Jun 7 19:12:49 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 19:12:49 +0200 (CEST) Subject: [pypy-svn] r44103 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter Message-ID: <20070607171249.61C758093@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 19:12:49 2007 New Revision: 44103 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Log: share the code after the bytecodes between the bytecodes to make the interpreter loop smaller Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 19:12:49 2007 @@ -110,22 +110,21 @@ res = meth(stack, oparg) else: res = meth(stack) - if res is not None: - continuation = res - while continuation is not DONOTHING: - if isinstance(continuation, FrameContinuation): - self = continuation.frame - pc = continuation.pc - bytecode = self.code.opcode - continuation = continuation.continuation - stack = [] - break - else: - print continuation - continuation = continuation._call(self.engine) break else: - assert 0, "missing opcode" + raise error.UncatchableError("bytecode corruption") + if res is not None: + continuation = res + while continuation is not DONOTHING: + if isinstance(continuation, FrameContinuation): + self = continuation.frame + pc = continuation.pc + bytecode = self.code.opcode + continuation = continuation.continuation + stack = [] + break + else: + continuation = continuation._call(self.engine) if len(stack) != 0: self.stack = stack return continuation From cfbolz at codespeak.net Thu Jun 7 23:08:28 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 23:08:28 +0200 (CEST) Subject: [pypy-svn] r44107 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter Message-ID: <20070607210828.AE19680F6@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 23:08:27 2007 New Revision: 44107 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py Log: some dead code Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py Thu Jun 7 23:08:27 2007 @@ -343,9 +343,6 @@ # helper functions for various Term methods -def _clone(obj, offset): - return obj.clone(offset) - def _getvalue(obj, heap): return obj.getvalue(heap) From cfbolz at codespeak.net Thu Jun 7 23:10:53 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 7 Jun 2007 23:10:53 +0200 (CEST) Subject: [pypy-svn] r44108 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter Message-ID: <20070607211053.4AD8A80F6@code0.codespeak.net> Author: cfbolz Date: Thu Jun 7 23:10:52 2007 New Revision: 44108 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py Log: more dead code Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py Thu Jun 7 23:10:52 2007 @@ -52,9 +52,6 @@ var.binding = val del self.trail[trails:] - def discard(self, state): - pass #XXX for now - def newvar(self): result = Var(self) return result @@ -76,25 +73,6 @@ curr = curr.next return first, copy - def find_applicable_rule(self, uh2): - #import pdb;pdb.set_trace() - while self: - uh = self.rule.unify_hash - hint(uh, concrete=True) - uh = hint(uh, deepfreeze=True) - j = 0 - while j < len(uh): - hint(j, concrete=True) - hash1 = uh[j] - hash2 = uh2[j] - if hash1 != 0 and hash2 * (hash2 - hash1) != 0: - break - j += 1 - else: - return self - self = self.next - return None - def __repr__(self): return "LinkedRules(%r, %r)" % (self.rule, self.next) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Thu Jun 7 23:10:52 2007 @@ -215,4 +215,3 @@ self.engine.heap.revert(oldstate) rulechain = rulechain.next raise error.UnificationFailed - Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py Thu Jun 7 23:10:52 2007 @@ -9,13 +9,6 @@ DEBUG = False -TAGBITS = 3 -CURR_TAG = 1 -def tag(): - global CURR_TAG - CURR_TAG += 1 - assert CURR_TAG <= 2 ** TAGBITS - return CURR_TAG def debug_print(*args): if DEBUG and not we_are_translated(): @@ -39,11 +32,6 @@ def copy(self, heap, memo): raise NotImplementedError("abstract base class") - def get_unify_hash(self, heap): - # if two non-var objects return two different numbers - # they must not be unifiable - raise NotImplementedError("abstract base class") - @specialize.arg(3) def unify(self, other, heap, occurs_check=False): raise NotImplementedError("abstract base class") @@ -68,7 +56,6 @@ error.throw_type_error("evaluable", self) class Var(PrologObject): - TAG = 0 STANDARD_ORDER = 0 __slots__ = ('binding', ) @@ -119,14 +106,6 @@ newvar = memo[self] = heap.newvar() return newvar - def get_unify_hash(self, heap): - if heap is not None: - self = self.dereference(heap) - if isinstance(self, Var): - return 0 - return self.get_unify_hash(heap) - return 0 - def contains_var(self, var, heap): self = self.dereference(heap) if self is var: @@ -195,12 +174,8 @@ def get_prolog_signature(self): raise NotImplementedError("abstract base") - def unify_hash_of_children(self, heap): - raise NotImplementedError("abstract base") - class Atom(Callable): - TAG = tag() STANDARD_ORDER = 1 cache = {} @@ -226,13 +201,6 @@ def copy(self, heap, memo): return self - def get_unify_hash(self, heap): - name = hint(self.name, promote=True) - return intmask(hash(name) << TAGBITS | self.TAG) - - def unify_hash_of_children(self, heap): - return [] - def get_prolog_signature(self): return Term("/", [self, NUMBER_0]) @@ -255,7 +223,6 @@ class Number(NonVar): - TAG = tag() STANDARD_ORDER = 2 _immutable_ = True def __init__(self, num): @@ -276,16 +243,12 @@ def __repr__(self): return "Number(%r)" % (self.num, ) - def get_unify_hash(self, heap): - return intmask(self.num << TAGBITS | self.TAG) - def eval_arithmetic(self, engine): return self NUMBER_0 = Number(0) class Float(NonVar): - TAG = tag() STANDARD_ORDER = 2 _immutable_ = True def __init__(self, floatval): @@ -300,12 +263,6 @@ def copy(self, heap, memo): return self - def get_unify_hash(self, heap): - #XXX no clue whether this is a good idea... - m, e = math.frexp(self.floatval) - m = intmask(int(m / 2 * 2 ** (32 - TAGBITS))) - return intmask(m << TAGBITS | self.TAG) - def __str__(self): return repr(self.floatval) @@ -322,7 +279,6 @@ class BlackBox(NonVar): # meant to be subclassed - TAG = tag() STANDARD_ORDER = 4 def __init__(self): pass @@ -336,10 +292,6 @@ def copy(self, heap, memo): return self - def get_unify_hash(self, heap): - return intmask(id(self) << TAGBITS | self.TAG) - - # helper functions for various Term methods @@ -347,7 +299,6 @@ return obj.getvalue(heap) class Term(Callable): - TAG = tag() STANDARD_ORDER = 3 _immutable_ = True def __init__(self, name, args, signature=None): @@ -403,18 +354,6 @@ else: return self - def get_unify_hash(self, heap): - signature = hint(self.signature, promote=True) - return intmask(hash(signature) << TAGBITS | self.TAG) - - def unify_hash_of_children(self, heap): - unify_hash = [] - i = 0 - while i < len(self.args): - unify_hash.append(self.args[i].get_unify_hash(heap)) - i += 1 - return unify_hash - def get_prolog_signature(self): return Term("/", [Atom.newatom(self.name), Number(len(self.args))]) From santagada at codespeak.net Fri Jun 8 13:53:53 2007 From: santagada at codespeak.net (santagada at codespeak.net) Date: Fri, 8 Jun 2007 13:53:53 +0200 (CEST) Subject: [pypy-svn] r44109 - in pypy/dist/pypy/lang/js: . test Message-ID: <20070608115353.0668D80BA@code0.codespeak.net> Author: santagada Date: Fri Jun 8 13:53:51 2007 New Revision: 44109 Modified: pypy/dist/pypy/lang/js/astbuilder.py pypy/dist/pypy/lang/js/interpreter.py pypy/dist/pypy/lang/js/jsobj.py pypy/dist/pypy/lang/js/operations.py pypy/dist/pypy/lang/js/test/test_interp.py pypy/dist/pypy/lang/js/test/test_parser.py Log: a new number and string Objects, so now autboxing is complete (I still need to work on more string methods and the array object). Now to string needs the context, probably ToNumber will follow. Modified: pypy/dist/pypy/lang/js/astbuilder.py ============================================================================== --- pypy/dist/pypy/lang/js/astbuilder.py (original) +++ pypy/dist/pypy/lang/js/astbuilder.py Fri Jun 8 13:53:51 2007 @@ -155,7 +155,7 @@ pos = self.get_pos(op) l = [self.dispatch(child) for child in node.children[1:]] return self.LISTOP_TO_CLS[op.additional_info](pos, l) - visit_arrayliteral = listop # XXX elision + visit_arrayliteral = listop # elision visit_objectliteral = listop def visit_block(self, node): Modified: pypy/dist/pypy/lang/js/interpreter.py ============================================================================== --- pypy/dist/pypy/lang/js/interpreter.py (original) +++ pypy/dist/pypy/lang/js/interpreter.py Fri Jun 8 13:53:51 2007 @@ -22,12 +22,13 @@ f.close() return t -class W_ObjectObject(W_Object): - def __init__(self, ctx=None, Prototype=None, Class='Object', +class W_NativeObject(W_Object): + def __init__(self, Class, Prototype, ctx=None, Value=w_Undefined, callfunc=None): W_Object.__init__(self, ctx, Prototype, Class, Value, callfunc) - + +class W_ObjectObject(W_NativeObject): def Call(self, ctx, args=[], this=None): if len(args) >= 1 and not isnull_or_undefined(args[0]): return args[0].ToObject(ctx) @@ -35,17 +36,13 @@ return self.Construct(ctx) def Construct(self, ctx, args=[]): - if len(args) >= 1 and not (isinstance(args[0], W_Undefined) or isinstance(args[0], W_Null)): + if len(args) >= 1 and not (isinstance(args[0], W_Undefined) \ + or isinstance(args[0], W_Null)): # XXX later we could separate builtins and normal objects return args[0].ToObject(ctx) return create_object(ctx, 'Object') -class W_BooleanObject(W_Object): - def __init__(self, ctx=None, Prototype=None, Class='Boolean', - Value=w_Undefined, callfunc=None): - W_Object.__init__(self, ctx, Prototype, - Class, Value, callfunc) - +class W_BooleanObject(W_NativeObject): def Call(self, ctx, args=[], this=None): if len(args) >= 1 and not isnull_or_undefined(args[0]): return W_Boolean(args[0].ToBoolean()) @@ -58,6 +55,32 @@ return create_object(ctx, 'Boolean', Value = Value) return create_object(ctx, 'Boolean', Value = W_Boolean(False)) +class W_NumberObject(W_NativeObject): + def Call(self, ctx, args=[], this=None): + if len(args) >= 1 and not isnull_or_undefined(args[0]): + return W_Number(args[0].ToNumber()) + else: + return W_Number(0.0) + + def Construct(self, ctx, args=[]): + if len(args) >= 1 and not isnull_or_undefined(args[0]): + Value = W_Number(args[0].ToNumber()) + return create_object(ctx, 'Number', Value = Value) + return create_object(ctx, 'Number', Value = W_Number(0.0)) + +class W_StringObject(W_NativeObject): + def Call(self, ctx, args=[], this=None): + if len(args) >= 1 and not isnull_or_undefined(args[0]): + return W_String(args[0].ToString(ctx)) + else: + return W_String('') + + def Construct(self, ctx, args=[]): + if len(args) >= 1 and not isnull_or_undefined(args[0]): + Value = W_String(args[0].ToString(ctx)) + return create_object(ctx, 'String', Value = Value) + return create_object(ctx, 'String', Value = W_String('')) + TEST = False def evaljs(ctx, args, this): @@ -69,7 +92,7 @@ else: code = W_String('') try: - node = load_source(code.ToString()) + node = load_source(code.ToString(ctx)) except ParseError, e: raise ThrowException(W_String('SintaxError: '+str(e))) @@ -84,7 +107,7 @@ def parseIntjs(ctx, args, this): if len(args) < 1: return W_Number(NaN) - s = args[0].ToString().strip(" ") + s = args[0].ToString(ctx).strip(" ") if len(args) > 1: radix = args[1].ToInt32() else: @@ -103,7 +126,7 @@ def parseFloatjs(ctx, args, this): if len(args) < 1: return W_Number(NaN) - s = args[0].ToString().strip(" ") + s = args[0].ToString(ctx).strip(" ") try: n = float(s) except ValueError: @@ -112,7 +135,7 @@ def printjs(ctx, args, this): - writer(",".join([i.GetValue().ToString() for i in args])) + writer(",".join([i.GetValue().ToString(ctx) for i in args])) return w_Undefined def isnanjs(ctx, args, this): @@ -136,7 +159,7 @@ def stringjs(ctx, args, this): if len(args) > 0: - return W_String(args[0].ToString()) + return W_String(args[0].ToString(ctx)) return W_String('') def arrayjs(ctx, args, this): @@ -177,7 +200,7 @@ class W_HasOwnProperty(W_NewBuiltin): def Call(self, ctx, args=[], this=None): if len(args) >= 1: - propname = args[0].ToString() + propname = args[0].ToString(ctx) if propname in this.propdict: return W_Boolean(True) return W_Boolean(False) @@ -196,7 +219,7 @@ class W_PropertyIsEnumerable(W_NewBuiltin): def Call(self, ctx, args=[], this=None): if len(args) >= 1: - propname = args[0].ToString() + propname = args[0].ToString(ctx) if propname in this.propdict and not this.propdict[propname].de: return W_Boolean(True) return W_Boolean(False) @@ -205,10 +228,10 @@ def Call(self, ctx, args=[], this=None): tam = len(args) if tam >= 1: - fbody = args[tam-1].GetValue().ToString() + fbody = args[tam-1].GetValue().ToString(ctx) argslist = [] for i in range(tam-1): - argslist.append(args[i].GetValue().ToString()) + argslist.append(args[i].GetValue().ToString(ctx)) fargs = ','.join(argslist) functioncode = "function (%s) {%s}"%(fargs, fbody) else: @@ -220,10 +243,13 @@ def Construct(self, ctx, args=[]): return self.Call(ctx, args, this=None) +functionstring= 'function (arguments go here!) {\n'+ \ + ' [lots of stuff :)]\n'+ \ + '}' class W_FToString(W_NewBuiltin): def Call(self, ctx, args=[], this=None): if this.Class == 'Function': - return W_String('function (arguments go here!) {\n [lots of stuff :)]\n}') + return W_String(functionstring) else: raise JsTypeError('this is not a function object') @@ -241,7 +267,8 @@ arrayArgs = args[1] if isinstance(arrayArgs, W_ListObject): callargs = arrayArgs.tolist() - elif isinstance(arrayArgs, W_Undefined) or isinstance(arrayArgs, W_Null): + elif isinstance(arrayArgs, W_Undefined) \ + or isinstance(arrayArgs, W_Null): callargs = [] else: raise JsTypeError('arrayArgs is not an Array or Arguments object') @@ -265,13 +292,31 @@ class W_ValueToString(W_NewBuiltin): "this is the toString function for objects with Value" def Call(self, ctx, args=[], this=None): - return W_String(this.Value.ToString()) + return W_String(this.Value.ToString(ctx)) class W_ValueValueOf(W_NewBuiltin): "this is the valueOf function for objects with Value" def Call(self, ctx, args=[], this=None): return this.Value +class W_CharAt(W_NewBuiltin): + def Call(self, ctx, args=[], this=None): + string = this.ToString(ctx) + if len(args)>=1: + pos = args[0].ToInt32() + if (not pos >=0) or (pos > len(string) - 1): + return W_String('') + else: + return W_String('') + return W_String(string[pos]) + +class W_Concat(W_NewBuiltin): + def Call(self, ctx, args=[], this=None): + string = this.ToString(ctx) + others = [obj.ToString(ctx) for obj in args] + string += ''.join(others) + return W_String(string) + class W_DateFake(W_NewBuiltin): # XXX This is temporary def Call(self, ctx, args=[], this=None): return create_object(ctx, 'Object') @@ -293,7 +338,7 @@ w_Global.Put('Function', w_Function) - w_Object = W_ObjectObject(Prototype=w_Function) + w_Object = W_ObjectObject('Object', w_Function) w_Object.Put('prototype', w_ObjPrototype, dd=True, de=True, ro=True) w_Global.Put('Object', w_Object) @@ -320,15 +365,35 @@ w_FncPrototype.Put('apply', W_Apply(ctx)) w_FncPrototype.Put('call', W_Call(ctx)) - w_Boolean = W_BooleanObject(Prototype=w_FncPrototype) + w_Boolean = W_BooleanObject('Boolean', w_FncPrototype) w_Boolean.Put('constructor', w_FncPrototype) + w_BoolPrototype = create_object(ctx, 'Object', Value=W_Boolean(False)) w_BoolPrototype.Class = 'Boolean' - w_Boolean.Put('prototype', w_BoolPrototype) w_BoolPrototype.Put('constructor', w_FncPrototype) w_BoolPrototype.Put('toString', W_ValueToString(ctx)) w_BoolPrototype.Put('valueOf', W_ValueValueOf(ctx)) + + w_Boolean.Put('prototype', w_BoolPrototype) + w_Global.Put('Boolean', w_Boolean) + + #Number + w_Number = W_NumberObject('Number', w_FncPrototype) + w_Number.Put('constructor', w_FncPrototype) + + w_NumPrototype = create_object(ctx, 'Object', Value=W_Number(0.0)) + w_NumPrototype.Class = 'Number' + w_NumPrototype.Put('constructor', w_FncPrototype) + w_NumPrototype.Put('toString', W_ValueToString(ctx)) + w_NumPrototype.Put('valueOf', W_ValueValueOf(ctx)) + + w_Number.Put('prototype', w_NumPrototype) + w_Number.Put('NaN', W_Number(NaN)) + w_Number.Put('POSITIVE_INFINITY', W_Number(Infinity)) + w_Number.Put('NEGATIVE_INFINITY', W_Number(-Infinity)) + + w_Global.Put('Number', w_Number) #Math @@ -358,12 +423,35 @@ w_Global.Put('Date', w_Date) #Number - w_Number = W_Builtin(numberjs, Class="Number") + w_Number = W_NumberObject('Number', w_FncPrototype) + + w_NumPrototype = create_object(ctx, 'Object', Value=W_Number(0.0)) + w_NumPrototype.Class = 'Number' + w_NumPrototype.Put('constructor', w_FncPrototype) + w_NumPrototype.Put('toString', W_ValueToString(ctx)) + w_NumPrototype.Put('valueOf', W_ValueValueOf(ctx)) + + w_Number.Put('prototype', w_NumPrototype) w_Number.Put('NaN', W_Number(NaN)) w_Number.Put('POSITIVE_INFINITY', W_Number(Infinity)) w_Number.Put('NEGATIVE_INFINITY', W_Number(-Infinity)) + w_Global.Put('Number', w_Number) + #String + w_String = W_StringObject('String', w_FncPrototype) + w_StrPrototype = create_object(ctx, 'Object', Value=W_String('')) + w_StrPrototype.Class = 'String' + w_StrPrototype.Put('constructor', w_FncPrototype) + w_StrPrototype.Put('toString', W_ValueToString(ctx)) + w_StrPrototype.Put('valueOf', W_ValueValueOf(ctx)) + w_StrPrototype.Put('charAt', W_CharAt(ctx)) + w_StrPrototype.Put('concat', W_Concat(ctx)) + + w_String.Put('prototype', w_StrPrototype) + + w_Global.Put('String', w_String) + w_Global.Put('NaN', W_Number(NaN)) w_Global.Put('Infinity', W_Number(Infinity)) @@ -394,7 +482,8 @@ res.append(arg) elif isinstance(arg, str): res.append(W_String(arg)) - elif isinstance(arg, int) or isinstance(arg, float) or isinstance(arg, long): + elif isinstance(arg, int) or isinstance(arg, float) \ + or isinstance(arg, long): res.append(W_Number(arg)) elif isinstance(arg, bool): res.append(W_Boolean(arg)) Modified: pypy/dist/pypy/lang/js/jsobj.py ============================================================================== --- pypy/dist/pypy/lang/js/jsobj.py (original) +++ pypy/dist/pypy/lang/js/jsobj.py Fri Jun 8 13:53:51 2007 @@ -54,7 +54,7 @@ def ToPrimitive(self, ctx, hint=""): return self - def ToString(self): + def ToString(self, ctx): return '' def ToObject(self, ctx): @@ -85,12 +85,12 @@ raise NotImplementedError def __str__(self): - return self.ToString() + return self.ToString(ctx=None) def type(self): raise NotImplementedError - - def delete(self): + + def GetPropertyName(self): raise NotImplementedError class W_Undefined(W_Root): @@ -103,7 +103,7 @@ def ToBoolean(self): return False - def ToString(self): + def ToString(self, ctx = None): return "undefined" def type(self): @@ -169,7 +169,8 @@ prot = self.Get('prototype') if isinstance(prot, W_PrimitiveObject): obj.Prototype = prot - else: # would love to test this, but I fail to find a case that falls into this + else: # would love to test this + #but I fail to find a case that falls into this obj.Prototype = ctx.get_global().Get('Object').Get('prototype') try: #this is a hack to be compatible to spidermonkey self.Call(ctx, args, this=obj) @@ -233,8 +234,12 @@ ToPrimitive = DefaultValue - def ToString(self): - return "[object %s]"%(self.Class,) + def ToString(self, ctx): + try: + res = self.ToPrimitive(ctx, 'String') + except JsTypeError: + return "[object %s]"%(self.Class,) + return res.ToString(ctx) def __str__(self): return "" % self.Class @@ -246,7 +251,7 @@ return 'object' def str_builtin(ctx, args, this): - return W_String(this.ToString()) + return W_String(this.ToString(ctx)) class W_Object(W_PrimitiveObject): def __init__(self, ctx=None, Prototype=None, Class='Object', @@ -264,7 +269,7 @@ W_PrimitiveObject.__init__(self, ctx, Prototype, Class, Value, callfunc) def Call(self, ctx, args=[], this = None): - return NotImplementedError + raise NotImplementedError def type(self): return 'builtin' @@ -360,11 +365,12 @@ self.propdict['length'].value = W_Number(index+1) return - def ToString(self): - return ','.join([self.Get(str(index)).ToString() for index in range(self.length)]) + def ToString(self, ctx): + return ','.join([self.Get(str(index)).ToString(ctx) + for index in range(self.length)]) def array_str_builtin(ctx, args, this): - return W_String(this.ToString()) + return W_String(this.ToString(ctx)) @@ -375,7 +381,7 @@ def ToObject(self, ctx): return create_object(ctx, 'Boolean', Value=self) - def ToString(self): + def ToString(self, ctx=None): if self.boolval == True: return "true" return "false" @@ -401,7 +407,10 @@ def __str__(self): return self.strval+"W" - def ToString(self): + def ToObject(self, ctx): + return create_object(ctx, 'String', Value=self) + + def ToString(self, ctx=None): return self.strval def ToBoolean(self): @@ -417,14 +426,18 @@ def __init__(self, floatval): try: self.floatval = float(floatval) - except OverflowError: # XXX this should not be happening, there is an error somewhere else + except OverflowError: + # XXX this should not be happening, there is an error somewhere else #an ecma test to stress this is GlobalObject/15.1.2.2-2.js self.floatval = Infinity def __str__(self): return str(self.floatval)+"W" + + def ToObject(self, ctx): + return create_object(ctx, 'Number', Value=self) - def ToString(self): + def ToString(self, ctx = None): floatstr = str(self.floatval) if floatstr == str(NaN): return 'NaN' @@ -473,12 +486,12 @@ def GetPropertyName(self): return self.ToString() - + class W_List(W_Root): def __init__(self, list_w): self.list_w = list_w - def ToString(self): + def ToString(self, ctx = None): raise SeePage(42) def ToBoolean(self): @@ -491,7 +504,8 @@ return str(self.list_w) class ExecutionContext(object): - def __init__(self, scope, this=None, variable=None, debug=False, jsproperty=None): + def __init__(self, scope, this=None, variable=None, + debug=False, jsproperty=None): assert scope is not None self.scope = scope if this is None: @@ -505,7 +519,8 @@ self.variable = variable self.debug = debug if jsproperty is None: - self.property = Property('',w_Undefined) #Attribute flags for new vars + #Attribute flags for new vars + self.property = Property('',w_Undefined) else: self.property = jsproperty @@ -520,6 +535,7 @@ def push_object(self, obj): """push object into scope stack""" + assert isinstance(obj, W_PrimitiveObject) self.scope.insert(0, obj) self.variable = obj @@ -529,6 +545,7 @@ def resolve_identifier(self, identifier): for obj in self.scope: + assert isinstance(obj, W_PrimitiveObject) if obj.HasProperty(identifier): return W_Reference(identifier, obj) @@ -536,6 +553,7 @@ def global_context(w_global): + assert isinstance(w_global, W_PrimitiveObject) ctx = ExecutionContext([w_global], this = w_global, variable = w_global, @@ -594,9 +612,10 @@ def __str__(self): return "<" + str(self.base) + " -> " + str(self.property_name) + ">" -def create_object(ctx, prototypename, callfunc=None, Value=None): +def create_object(ctx, prototypename, callfunc=None, Value=w_Undefined): proto = ctx.get_global().Get(prototypename).Get('prototype') - obj = W_Object(ctx, callfunc = callfunc,Prototype=proto, Class = proto.Class, Value = Value) + obj = W_Object(ctx, callfunc = callfunc,Prototype=proto, + Class = proto.Class, Value = Value) return obj def isnull_or_undefined(obj): Modified: pypy/dist/pypy/lang/js/operations.py ============================================================================== --- pypy/dist/pypy/lang/js/operations.py (original) +++ pypy/dist/pypy/lang/js/operations.py Fri Jun 8 13:53:51 2007 @@ -67,7 +67,7 @@ class UnaryOp(Expression): def __init__(self, pos, expr, postfix=False): self.pos = pos - assert isinstance(expr, Node) + #assert isinstance(expr, Node) self.expr = expr self.postfix = postfix @@ -212,7 +212,7 @@ r1 = self.left.eval(ctx) r2 = self.right.eval(ctx) r3 = r1.GetValue() - if not isinstance(r3, W_PrimitiveObject): # TODO: review this on the spec + if not isinstance(r3, W_PrimitiveObject): raise ThrowException(W_String("it is not a callable")) if isinstance(r1, W_Reference): @@ -251,13 +251,15 @@ class Member(BinaryOp): + "this is for object[name]" def eval(self, ctx): w_obj = self.left.eval(ctx).GetValue().ToObject(ctx) - name = self.right.eval(ctx).GetValue().ToString() + name = self.right.eval(ctx).GetValue().ToString(ctx) return W_Reference(name, w_obj) class MemberDot(BinaryOp): + "this is for object.name" def eval(self, ctx): w_obj = self.left.eval(ctx).GetValue().ToObject(ctx) name = self.right.get_literal() @@ -341,8 +343,8 @@ else: return 0 else: - s4 = s1.ToString() - s5 = s2.ToString() + s4 = s1.ToString(ctx) + s5 = s2.ToString(ctx) if s4 < s5: return 1 if s4 == s5: @@ -454,7 +456,7 @@ return True return False elif type1 == "string": - return x.ToString() == y.ToString() + return x.ToString(ctx) == y.ToString(ctx) elif type1 == "boolean": return x.ToBoolean() == x.ToBoolean() return x == y @@ -486,7 +488,7 @@ return True if isinstance(x, W_String) and isinstance(y, W_String): - r = x.ToString() == y.ToString() + r = x.ToString(ctx) == y.ToString(ctx) else: r = x.ToNumber() == y.ToNumber() return r @@ -507,7 +509,7 @@ # ############################################################################## -def SEC(x,y): +def SEC(ctx, x, y): """ Implements the Strict Equality Comparison x === y trying to be fully to the spec @@ -528,18 +530,18 @@ return True return False if type1 == "string": - return x.ToString() == y.ToString() + return x.ToString(ctx) == y.ToString(ctx) if type1 == "boolean": return x.ToBoolean() == x.ToBoolean() return x == y class StrictEq(BinaryComparisonOp): def decision(self, ctx, op1, op2): - return W_Boolean(SEC(op1, op2)) + return W_Boolean(SEC(ctx, op1, op2)) class StrictNe(BinaryComparisonOp): def decision(self, ctx, op1, op2): - return W_Boolean(not SEC(op1, op2)) + return W_Boolean(not SEC(ctx, op1, op2)) class In(BinaryComparisonOp): @@ -549,7 +551,7 @@ def decision(self, ctx, op1, op2): if not isinstance(op2, W_Object): raise ThrowException(W_String("TypeError")) - name = op1.ToString() + name = op1.ToString(ctx) return W_Boolean(op2.HasProperty(name)) class Delete(UnaryOp): @@ -600,7 +602,7 @@ class Index(BinaryOp): def eval(self, ctx): w_obj = self.left.eval(ctx).GetValue().ToObject(ctx) - name= self.right.eval(ctx).GetValue().ToString() + name= self.right.eval(ctx).GetValue().ToString(ctx) return W_Reference(name, w_obj) class ArgumentList(ListOp): @@ -626,8 +628,8 @@ def plus(ctx, nleft, nright): if isinstance(nleft, W_String) or isinstance(nright, W_String): - sleft = nleft.ToString() - sright = nright.ToString() + sleft = nleft.ToString(ctx) + sright = nright.ToString(ctx) return W_String(sleft + sright) else: fleft = nleft.ToNumber() @@ -988,7 +990,7 @@ class ForIn(Statement): def __init__(self, pos, iterator, lobject, body): self.pos = pos - assert isinstance(iterator, Node) + #assert isinstance(iterator, Node) self.iterator = iterator self.object = lobject self.body = body Modified: pypy/dist/pypy/lang/js/test/test_interp.py ============================================================================== --- pypy/dist/pypy/lang/js/test/test_interp.py (original) +++ pypy/dist/pypy/lang/js/test/test_interp.py Fri Jun 8 13:53:51 2007 @@ -17,10 +17,11 @@ l = [] interpreter.writer = l.append jsint = interpreter.Interpreter() + ctx = jsint.w_Global try: jsint.run(interpreter.load_source(code)) except ThrowException, excpt: - l.append("uncaught exception: "+str(excpt.exception.ToString())) + l.append("uncaught exception: "+str(excpt.exception.ToString(ctx))) print l, prints if isinstance(prints, list): assert l == prints @@ -29,6 +30,7 @@ def assertv(code, value): jsint = interpreter.Interpreter() + ctx = jsint.w_Global try: code_val = jsint.run(interpreter.load_source(code)).GetValue() except ThrowException, excpt: @@ -43,7 +45,7 @@ elif isinstance(value, float): assert code_val.ToNumber() == value else: - assert code_val.ToString() == value + assert code_val.ToString(ctx) == value def asserte(code, value): jsint = interpreter.Interpreter() @@ -232,6 +234,8 @@ yield assertv, "0==1;", False yield assertv, "0!=1;", True yield assertv, "1!=1;", False + yield assertv, "1===1;", True + yield assertv, "1!==1;", False def test_string_compare(): yield assertv, "'aaa' > 'a';", True @@ -575,10 +579,9 @@ };""", 15 def test_autoboxing(): - py.test.skip("not ready yet") - yield assertv, "'abc'.charAt(0)", 0 + yield assertv, "'abc'.charAt(0)", 'a' yield assertv, "true.toString()", 'true' - yield assertv, "5.toString()", '5' + yield assertv, "x=5; x.toString();", '5' def test_proper_prototype_inheritance(): yield assertv, """ Modified: pypy/dist/pypy/lang/js/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/js/test/test_parser.py (original) +++ pypy/dist/pypy/lang/js/test/test_parser.py Fri Jun 8 13:53:51 2007 @@ -4,7 +4,7 @@ from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function from pypy.rlib.parsing.parsing import ParseError, Rule from pypy.rlib.parsing.tree import RPythonVisitor -from pypy.lang.js.jsobj import W_Object, global_context, ThrowException +from pypy.lang.js.jsobj import W_Object, global_context, ThrowException, empty_context from pypy.lang.js.astbuilder import ASTBuilder from pypy import conftest import sys @@ -279,6 +279,7 @@ class TestToASTExpr(BaseGrammarTest): def setup_class(cls): cls.parse = parse_func('expression') + cls.ctx = empty_context() def to_ast(self, s): return ASTBuilder().dispatch(self.parse(s)) @@ -309,11 +310,11 @@ w_num = self.eval_expr('((((6))))') assert w_num.ToNumber() == 6 w_array = self.eval_expr('[1,2,3]') - assert w_array.ToString() == '1,2,3' + assert w_array.ToString(self.ctx) == '1,2,3' w_identifier = self.eval_expr('x') py.test.raises(ThrowException, w_identifier.GetValue) w_object = self.eval_expr('{x:1}') - assert w_object.ToString() == '[object Object]' + assert w_object.ToString(self.ctx) == '[object Object]' assert w_object.Get('x').ToNumber() == 1 def test_expression(self): @@ -326,7 +327,7 @@ w_num = self.eval_expr('--5') assert w_num.ToNumber() == 4 w_str = self.eval_expr('"hello "+\'world\'') - assert w_str.ToString() == 'hello world' + assert w_str.ToString(self.ctx) == 'hello world' from pypy.lang.js.jsparser import parse From jacob at codespeak.net Sat Jun 9 11:42:56 2007 From: jacob at codespeak.net (jacob at codespeak.net) Date: Sat, 9 Jun 2007 11:42:56 +0200 (CEST) Subject: [pypy-svn] r44112 - pypy/extradoc/pypy.org Message-ID: <20070609094256.5921880CF@code0.codespeak.net> Author: jacob Date: Sat Jun 9 11:42:55 2007 New Revision: 44112 Modified: pypy/extradoc/pypy.org/news.txt Log: News item about review. Modified: pypy/extradoc/pypy.org/news.txt ============================================================================== --- pypy/extradoc/pypy.org/news.txt (original) +++ pypy/extradoc/pypy.org/news.txt Sat Jun 9 11:42:55 2007 @@ -1,3 +1,24 @@ +Review passed with flying colours +--------------------------------- + +On the 31st of May 2007 the PyPy project was reviewed by the EU +Commission in Brussels. Reviewers were Roel Wuyts, Unversit? Libre de +Bruxelles and Aki Lumiaho, Ramboll, Finland. Present was also our +Project Officer, Charles McMillan. After 6 hours of presentations of +the various aspects of the project, it only took the reviewers a few +minutes to decide that the project was accepted, without any further +work being required. Professor Wuyts, who has dynamic programming +languages as his main field of research was very enthusiastic about +the entire project and the results with the Just In Time Compiler +Generator in particular. He offered his help in establishing +collaborations with the communities around Prolog, Smalltalk, Lisp and +other dynamic languages, as well as giving hints on how to get our +results most widely pubicized. + +The preparations for the review left the team rather exhausted so +development progress will be rather slow until the sprint at +Europython in the second week of July. + PyPy EU funding period over, Review ahead ----------------------------------------------------- From jacob at codespeak.net Sat Jun 9 11:45:11 2007 From: jacob at codespeak.net (jacob at codespeak.net) Date: Sat, 9 Jun 2007 11:45:11 +0200 (CEST) Subject: [pypy-svn] r44113 - pypy/dist/pypy/doc Message-ID: <20070609094511.4B9D180D5@code0.codespeak.net> Author: jacob Date: Sat Jun 9 11:45:10 2007 New Revision: 44113 Modified: pypy/dist/pypy/doc/news.txt Log: News item about review. Modified: pypy/dist/pypy/doc/news.txt ============================================================================== --- pypy/dist/pypy/doc/news.txt (original) +++ pypy/dist/pypy/doc/news.txt Sat Jun 9 11:45:10 2007 @@ -14,6 +14,27 @@ .. _`iCalendar format`: webcal://pypycal.sabi.net///calendars/PyPy.ics .. _eventhistory: eventhistory.html +Review passed with flying colours +================================= + +On the 31st of May 2007 the PyPy project was reviewed by the EU +Commission in Brussels. Reviewers were Roel Wuyts, Unversit? Libre de +Bruxelles and Aki Lumiaho, Ramboll, Finland. Present was also our +Project Officer, Charles McMillan. After 6 hours of presentations of +the various aspects of the project, it only took the reviewers a few +minutes to decide that the project was accepted, without any further +work being required. Professor Wuyts, who has dynamic programming +languages as his main field of research was very enthusiastic about +the entire project and the results with the Just In Time Compiler +Generator in particular. He offered his help in establishing +collaborations with the communities around Prolog, Smalltalk, Lisp and +other dynamic languages, as well as giving hints on how to get our +results most widely pubicized. + +The preparations for the review left the team rather exhausted so +development progress will be rather slow until the sprint at +Europython in the second week of July. + PyPy EU funding period over, Review ahead =========================================================== From antocuni at codespeak.net Sat Jun 9 15:48:55 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 9 Jun 2007 15:48:55 +0200 (CEST) Subject: [pypy-svn] r44114 - pypy/extradoc/talk/pycon-uno2007 Message-ID: <20070609134855.95E00808D@code0.codespeak.net> Author: antocuni Date: Sat Jun 9 15:48:54 2007 New Revision: 44114 Modified: pypy/extradoc/talk/pycon-uno2007/pycon07.odp pypy/extradoc/talk/pycon-uno2007/pycon07.pdf Log: last-hour updates Modified: pypy/extradoc/talk/pycon-uno2007/pycon07.odp ============================================================================== Binary files. No diff available. Modified: pypy/extradoc/talk/pycon-uno2007/pycon07.pdf ============================================================================== Binary files. No diff available. From cfbolz at codespeak.net Sun Jun 10 19:40:52 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sun, 10 Jun 2007 19:40:52 +0200 (CEST) Subject: [pypy-svn] r44125 - pypy/branch/prolog-bytecode/pypy/rpython/lltypesystem/test Message-ID: <20070610174052.B81E480B3@code0.codespeak.net> Author: cfbolz Date: Sun Jun 10 19:40:51 2007 New Revision: 44125 Modified: pypy/branch/prolog-bytecode/pypy/rpython/lltypesystem/test/test_rvirtualizable.py Log: failing test: you cannot have prebuilt instances of virtualizables. Modified: pypy/branch/prolog-bytecode/pypy/rpython/lltypesystem/test/test_rvirtualizable.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/rpython/lltypesystem/test/test_rvirtualizable.py (original) +++ pypy/branch/prolog-bytecode/pypy/rpython/lltypesystem/test/test_rvirtualizable.py Sun Jun 10 19:40:51 2007 @@ -294,3 +294,19 @@ res = interp.eval_graph(graph, [23]) assert res == 2323 + +def test_prebuilt_virtualizable_instance(): + py.test.skip("breaks right now") + class A(object): + _virtualizable_ = True + def __init__(self, x): + self.x = x + + a = A(32) + + def f(): + return a.x + + res = interpret(f, []) + assert res == 32 + From cfbolz at codespeak.net Sun Jun 10 19:43:40 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sun, 10 Jun 2007 19:43:40 +0200 (CEST) Subject: [pypy-svn] r44126 - in pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter: . test Message-ID: <20070610174340.A6DB980B3@code0.codespeak.net> Author: cfbolz Date: Sun Jun 10 19:43:40 2007 New Revision: 44126 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_jit.py Log: attemps to get the prolog interpreter to work with the jit again. Kind of works, but I seem to be getting strange segfaults for reasonably-sized prolog programs :-(. Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py Sun Jun 10 19:43:40 2007 @@ -24,6 +24,7 @@ Code.dynamic_code.maxlocalvar = 1 Code.dynamic_code.opcode_head = "l\x00\x00" Code.dynamic_code.opcode = "l\x00\x00D" +Code.dynamic_code.can_contain_cut = True def compile(head, body, engine): Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py Sun Jun 10 19:43:40 2007 @@ -4,9 +4,9 @@ from pypy.lang.prolog.interpreter.error import UnificationFailed, \ FunctionNotFound, CutException from pypy.lang.prolog.interpreter import error, helper -from pypy.rlib.jit import hint, we_are_jitted, _is_early_constant, purefunction -from pypy.rlib.objectmodel import specialize +from pypy.rlib.objectmodel import specialize, we_are_translated from pypy.rlib.unroll import unrolling_iterable +from pypy.rlib.jit import purefunction, hint DEBUG = False @@ -31,29 +31,49 @@ self.scope_active = False return self.continuation +class TrailChunk(object): + def __init__(self, last=None): + self.last = last + self.trail = [] + + def __str__(self): + return "TrailChunk(%s, %s)" % (self.last, self.trail) + class Heap(object): + _virtualizable_ = True def __init__(self): - self.trail = [] + self.current_chunk = TrailChunk() def reset(self): - self.trail = [] - self.last_branch = 0 + self.current_chunk = TrailChunk() def add_trail(self, var): - self.trail.append((var, var.binding)) + self.current_chunk.trail.append((var, var.binding)) def branch(self): - return len(self.trail) + result = TrailChunk(self.current_chunk) + self.current_chunk = result + return result - def revert(self, state): - trails = state - for i in range(len(self.trail) - 1, trails - 1, -1): - var, val = self.trail[i] - var.binding = val - del self.trail[trails:] + def revert(self, chunk): + curr = self.current_chunk + while curr is not None: + i = len(curr.trail) - 1 + while i >= 0: + var, val = curr.trail[i] + var.binding = val + i -= 1 + if curr is chunk: + break + curr = curr.last + else: + self.current_chunk = TrailChunk() + return + self.current_chunk = chunk + chunk.trail = [] def newvar(self): - result = Var(self) + result = Var() return result class LinkedRules(object): @@ -107,8 +127,9 @@ self.parser = None self.operations = None #XXX circular imports hack - from pypy.lang.prolog.builtin import builtins_list - globals()['unrolling_builtins'] = unrolling_iterable(builtins_list) + if not we_are_translated(): + from pypy.lang.prolog.builtin import builtins_list + globals()['unrolling_builtins'] = unrolling_iterable(builtins_list) def add_rule(self, rule, end=True): from pypy.lang.prolog import builtin Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Sun Jun 10 19:43:40 2007 @@ -6,6 +6,7 @@ LimitedScopeContinuation, DONOTHING from pypy.lang.prolog.interpreter.prologopcode import unrolling_opcode_descs, \ HAVE_ARGUMENT +from pypy.rlib.jit import hint, we_are_jitted, _is_early_constant, purefunction class FrameContinuation(Continuation): def __init__(self, frame, pc, continuation): @@ -14,7 +15,7 @@ self.continuation = continuation def _call(self, engine): - return self.frame.run(self.frame.code.opcode, self.pc, + return self.frame.run(self.frame.code, False, self.pc, self.continuation) class Rule(object): @@ -42,15 +43,6 @@ return "%s." % (self.head, ) return "%s :- %s." % (self.head, self.body) -class Query(object): - def __init__(self, body, engine): - from pypy.lang.prolog.interpreter.compiler import compile_query - self.code = compile_query(body, engine) - self.engine = engine - - def make_frame(self): - return Frame(self.engine, self.code) - def dynamic_call_frame(engine, query): from pypy.lang.prolog.interpreter.compiler import Code @@ -60,31 +52,81 @@ class Frame(object): - #_immutable_ = True # XXX? + _virtualizable_ = True def __init__(self, engine, code): self.engine = engine + self.heap = engine.heap self.code = code self.localvarcache = [None] * code.maxlocalvar - self.stack = None + self.result = None + + def getcode(self): + return hint(hint(self.code, promote=True), deepfreeze=True) def unify_head(self, head): - self.run(self.code.opcode_head, 0, None) - self.stack[0].unify(head, self.engine.heap) - self.stack = None + self.run(self.getcode(), True, 0, None) + self.result.unify(head, self.heap) + self.result = None def run_directly(self, continuation, choice_point=True): - if self.code.opcode: - continuation = self.run(self.code.opcode, 0, continuation) if not choice_point: + if self.getcode().opcode: + continuation = FrameContinuation(self, 0, continuation) return continuation + if self.getcode().opcode: + continuation = self.run(self.getcode(), False, 0, continuation) while continuation is not DONOTHING: continuation = continuation._call(self.engine) return DONOTHING - def run(self, bytecode, pc, continuation): + def run(self, codeobject, head, pc, continuation): + from pypy.lang.prolog.interpreter.compiler import Code + if codeobject is Code.dynamic_code: + return self._run(codeobject, head, pc, continuation) + if head: + return self._run(codeobject, head, pc, continuation) + if not we_are_jitted(): + assert codeobject is not None + return self.run_jit(self.heap, codeobject, head, pc, continuation) + return self.opaque_run(codeobject, head, pc, continuation) + + def opaque_run(self, codeobject, head, pc, continuation): + return self.run_jit(self.heap, codeobject, head, pc, continuation) + opaque_run._look_inside_me = False + + def jit_enter_function(self): + # funnyness + code = self.getcode() + localvarcache = [None] * code.maxlocalvar + i = code.maxlocalvar + while True: + i -= 1 + if i < 0: + break + hint(i, concrete=True) + obj = self.localvarcache[i] + localvarcache[i] = obj + self.localvarcache = localvarcache + + def run_jit(self, heap, codeobject, head, pc, continuation): + hint(None, global_merge_point=True) + hint(codeobject, concrete=True) + codeobject = hint(codeobject, deepfreeze=True) + hint(head, concrete=True) + if head: + bytecode = codeobject.opcode_head + pc = 0 + else: + bytecode = codeobject.opcode + pc = hint(pc, promote=True) + self.code = codeobject + self.heap = heap + + self.jit_enter_function() stack = [] while pc < len(bytecode): + hint(None, global_merge_point=True) opcode = ord(bytecode[pc]) pc += 1 if opcode >= HAVE_ARGUMENT: @@ -94,43 +136,98 @@ oparg = (hi << 8) | lo else: oparg = 0 + hint(opcode, concrete=True) + hint(oparg, concrete=True) #import pdb; pdb.set_trace() - for opdesc in unrolling_opcode_descs: - if opcode == opdesc.index: - # dispatch to the opcode method - meth = getattr(self, opdesc.name) - if opdesc.hascontinuation: - cont = FrameContinuation(self, pc, continuation) - if opdesc.hasargument: - res = meth(stack, oparg, cont) - else: - res = meth(stack, cont) + res = self.dispatch_bytecode(opcode, oparg, bytecode, pc, + stack, continuation) + if res is not None: + continuation = res + while continuation is not DONOTHING: + if isinstance(continuation, FrameContinuation): + self = continuation.frame + bytecode = self.getcode().opcode + pc = hint(continuation.pc, promote=True) + continuation = continuation.continuation + stack = [] + break else: - if opdesc.hasargument: - res = meth(stack, oparg) - else: - res = meth(stack) - break + continuation = continuation._call(self.engine) + if head: + self.result = stack[0] + return continuation + + def _run(self, codeobject, head, pc, continuation): + codeobject = hint(codeobject, promote=True) + codeobject = hint(codeobject, deepfreeze=True) + hint(head, concrete=True) + if head: + bytecode = codeobject.opcode_head + pc = 0 + else: + bytecode = codeobject.opcode + pc = hint(pc, promote=True) + stack = [] + while pc < len(bytecode): + opcode = ord(bytecode[pc]) + pc += 1 + if opcode >= HAVE_ARGUMENT: + hi = ord(bytecode[pc]) + lo = ord(bytecode[pc+1]) + pc += 2 + oparg = (hi << 8) | lo else: - raise error.UncatchableError("bytecode corruption") + oparg = 0 + hint(opcode, concrete=True) + hint(oparg, concrete=True) + #import pdb; pdb.set_trace() + res = self.dispatch_bytecode(opcode, oparg, bytecode, pc, + stack, continuation) if res is not None: continuation = res while continuation is not DONOTHING: if isinstance(continuation, FrameContinuation): self = continuation.frame - pc = continuation.pc - bytecode = self.code.opcode + bytecode = self.getcode().opcode + pc = hint(continuation.pc, promote=True) continuation = continuation.continuation stack = [] break else: continuation = continuation._call(self.engine) - if len(stack) != 0: - self.stack = stack + if head: + self.result = stack[0] return continuation + + def dispatch_bytecode(self, opcode, oparg, bytecode, pc, stack, + continuation): + hint(opcode, concrete=True) + hint(oparg, concrete=True) + for opdesc in unrolling_opcode_descs: + if opcode == opdesc.index: + # dispatch to the opcode method + meth = getattr(self, opdesc.name) + if opdesc.hascontinuation: + if pc >= len(bytecode): + cont = continuation + else: + cont = FrameContinuation(self, pc, continuation) + if opdesc.hasargument: + return meth(stack, oparg, cont) + else: + return meth(stack, cont) + else: + if opdesc.hasargument: + return meth(stack, oparg) + else: + return meth(stack) + break + else: + raise error.UncatchableError("bytecode corruption") + def PUTCONSTANT(self, stack, number): - stack.append(self.code.constants[number]) + stack.append(self.getcode().constants[number]) def MAKELOCALVAR(self, stack, number): result = self.localvarcache[number] = LocalVar() @@ -143,15 +240,17 @@ def ACTIVATE_LOCAL(self, stack, number): var = self.localvarcache[number] - if isinstance(var, LocalVar): - self.localvarcache[number] = var.dereference(self.engine.heap) - var.active = True + assert var.__class__ == LocalVar + self.localvarcache[number] = result = var.dereference(self.heap) + hint(result.__class__, promote=True) + var.active = True def MAKETERM(self, stack, number): - name, numargs, signature = self.code.term_info[number] + name, numargs, signature = self.getcode().term_info[number] args = [None] * numargs i = numargs - 1 while i >= 0: + hint(i, concrete=True) args[i] = stack.pop() i -= 1 stack.append(Term(name, args, signature)) @@ -166,7 +265,7 @@ def STATIC_CALL(self, stack, number, continuation): query = stack.pop() - function = self.code.functions[number] + function = self.getcode().functions[number] return self.user_call(function, query, continuation) def DYNAMIC_CALL(self, stack, continuation): @@ -184,24 +283,28 @@ self.localvarcache[number] = None def UNIFY(self, stack): - stack.pop().unify(stack.pop(), self.engine.heap) + stack.pop().unify(stack.pop(), self.heap) def user_call(self, function, query, continuation): assert isinstance(query, Callable) rulechain = function.rulechain + rulechain = hint(rulechain, promote=True) if rulechain is None: error.throw_existence_error( "procedure", query.get_prolog_signature()) - oldstate = self.engine.heap.branch() + oldstate = self.heap.branch() while rulechain is not None: rule = rulechain.rule + choice_point = rulechain.next is not None + hint(rule, concrete=True) if rule.code.can_contain_cut: continuation = LimitedScopeContinuation(continuation) try: frame = rule.make_frame(query) - return frame.run_directly(continuation) + result = frame.run_directly(continuation) + return result except error.UnificationFailed: - self.engine.heap.revert(oldstate) + self.heap.revert(oldstate) except error.CutException, e: if continuation.scope_active: return self.engine.continue_after_cut(e.continuation, @@ -210,8 +313,10 @@ else: try: frame = rule.make_frame(query) - return frame.run_directly(continuation) + result = frame.run_directly(continuation, choice_point) + return result except error.UnificationFailed: - self.engine.heap.revert(oldstate) + self.heap.revert(oldstate) + if not choice_point: + raise rulechain = rulechain.next - raise error.UnificationFailed Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py Sun Jun 10 19:43:40 2007 @@ -1,7 +1,7 @@ import py -py.test.skip("jit doesn't work") from pypy.jit.hintannotator.policy import ManualGraphPolicy -from pypy.lang.prolog.interpreter import term, engine, helper +from pypy.lang.prolog.interpreter import term, engine, helper, interpreter, \ + prologopcode from pypy.translator.translator import graphof from pypy.annotation.specialize import getuniquenondirectgraph @@ -14,11 +14,13 @@ } -PORTAL = engine.Engine.portal_try_rule.im_func +PORTAL = interpreter.Frame.run_jit.im_func class PyrologHintAnnotatorPolicy(ManualGraphPolicy): PORTAL = PORTAL def look_inside_graph_of_module(self, graph, func, mod): + if "unify__" in graph.name: + return True if mod in forbidden_modules: return False if mod in good_modules: @@ -29,38 +31,38 @@ def fill_timeshift_graphs(self, portal_graph): import pypy - for cls in [term.Var, term.Term, term.Number, term.Atom]: - self.seegraph(cls.copy) + for cls in [term.Var, term.Term, term.Number, term.Atom, term.LocalVar]: self.seegraph(cls.__init__) - self.seegraph(cls.copy_and_unify) - for cls in [term.Term, term.Number, term.Atom]: - self.seegraph(cls.copy_and_basic_unify) + for cls in [term.Var, term.LocalVar]: + self.seegraph(cls.setvalue) + for cls in [term.Term, term.Number, term.Atom, term.Var]: self.seegraph(cls.dereference) - self.seegraph(cls.copy_and_basic_unify) for cls in [term.Var, term.Term, term.Number, term.Atom]: - self.seegraph(cls.get_unify_hash) self.seegraph(cls.eval_arithmetic) for cls in [term.Callable, term.Atom, term.Term]: self.seegraph(cls.get_prolog_signature) - self.seegraph(cls.unify_hash_of_children) self.seegraph(PORTAL) self.seegraph(engine.Heap.newvar) - self.seegraph(term.Rule.clone_and_unify_head) - self.seegraph(engine.Engine.call) - self.seegraph(engine.Engine._call) - self.seegraph(engine.Engine.user_call) - self.seegraph(engine.Engine._user_call) - self.seegraph(engine.Engine.try_rule) - self.seegraph(engine.Engine._try_rule) - self.seegraph(engine.Engine.main_loop) - self.seegraph(engine.Engine.dispatch_bytecode) - self.seegraph(engine.LinkedRules.find_applicable_rule) - for method in "branch revert discard newvar extend maxvar".split(): + self.seegraph(engine.TrailChunk.__init__) + self.seegraph(interpreter.Rule.make_frame) + for method in "branch revert newvar add_trail".split(): self.seegraph(getattr(engine.Heap, method)) + for method in ("unify_head run_directly run user_call " + "dispatch_bytecode getcode jit_enter_function " + "__init__ _run").split(): + self.seegraph(getattr(interpreter.Frame, method)) + for num in prologopcode.allopcodes: + method = prologopcode.opname[num] + if method == "DYNAMIC_CALL": + continue + self.seegraph(getattr(interpreter.Frame, method)) self.seegraph(engine.Continuation.call) for cls in [engine.Continuation, engine.LimitedScopeContinuation, - pypy.lang.prolog.builtin.control.AndContinuation]: + pypy.lang.prolog.builtin.control.AndContinuation, + interpreter.FrameContinuation + ]: self.seegraph(cls._call) + self.seegraph(interpreter.FrameContinuation.__init__) for function in "".split(): self.seegraph(getattr(helper, function)) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py Sun Jun 10 19:43:40 2007 @@ -5,7 +5,7 @@ from pypy.lang.prolog.interpreter import error from pypy.rlib.jit import hint from pypy.rlib.objectmodel import specialize -from pypy.rlib.jit import we_are_jitted, hint, purefunction +from pypy.rlib.jit import we_are_jitted, hint, purefunction, _is_early_constant DEBUG = False @@ -61,7 +61,7 @@ __slots__ = ('binding', ) cache = {} - def __init__(self, heap=None): + def __init__(self): self.binding = None @specialize.arg(3) @@ -82,11 +82,17 @@ next = self.binding if next is None: return self - else: - result = next.dereference(heap) - # do path compression + if isinstance(next, Var): + if _is_early_constant(next): + result = next.dereference(heap) + else: + result = next.opaque_dereference(heap) self.setvalue(result, heap) return result + return next + + def opaque_dereference(self, heap): + return self.dereference(heap) def getvalue(self, heap): res = self.dereference(heap) @@ -95,11 +101,11 @@ return res def setvalue(self, value, heap): - heap.add_trail(self) - self.binding = value + if value is not self.binding: + heap.add_trail(self) + self.binding = value def copy(self, heap, memo): - hint(self, concrete=True) try: return memo[self] except KeyError: @@ -259,6 +265,7 @@ if isinstance(other, Float) and other.floatval == self.floatval: return raise UnificationFailed + basic_unify._look_inside_me_ = False def copy(self, heap, memo): return self @@ -320,18 +327,17 @@ if (isinstance(other, Term) and self.name == other.name and len(self.args) == len(other.args)): - for i in range(len(self.args)): + i = 0 + while i < len(self.args): self.args[i].unify(other.args[i], heap, occurs_check) + i += 1 else: raise UnificationFailed def copy(self, heap, memo): - hint(self, concrete=True) - self = hint(self, deepfreeze=True) newargs = [] i = 0 while i < len(self.args): - hint(i, concrete=True) arg = self.args[i].copy(heap, memo) newargs.append(arg) i += 1 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py Sun Jun 10 19:43:40 2007 @@ -10,13 +10,13 @@ frame = r.make_frame(query) assert frame.localvarcache[0].dereference(e.heap).name == "a" cont = object() - c2 = frame.run(frame.code.opcode, 0, cont) + c2 = frame.run(frame.code, False, 0, cont) assert cont is c2 query, vars = get_query_and_vars("f(X).") frame = r.make_frame(query) cont = object() - c2 = frame.run(frame.code.opcode, 0, cont) + c2 = frame.run(frame.code, False, 0, cont) assert cont is c2 assert vars['X'].dereference(e.heap).name == 'a' @@ -26,7 +26,7 @@ r = Rule(head, body, e) frame = Frame(e, r.code) - frame.run(frame.code.opcode_head, 0, None) - frame.run(frame.code.opcode, 0, None) - assert frame.stack[0].args[0].dereference(e.heap).name == "a" - assert frame.stack[0].args[1].dereference(e.heap).name == "b" + frame.run(frame.code, True, 0, None) + frame.run(frame.code, False, 0, None) + assert frame.result.args[0].dereference(e.heap).name == "a" + assert frame.result.args[1].dereference(e.heap).name == "b" Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_jit.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_jit.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_jit.py Sun Jun 10 19:43:40 2007 @@ -2,12 +2,11 @@ from pypy.jit.timeshifter.test.test_portal import PortalTest, P_NOVIRTUAL from pypy.lang.prolog.interpreter import portal from pypy.lang.prolog.interpreter import engine, term -from pypy.lang.prolog.interpreter.parsing import parse_query_term, get_engine +from pypy.lang.prolog.interpreter.parsing import parse_query_term, get_engine, \ + get_query_and_vars POLICY = portal.PyrologHintAnnotatorPolicy() -py.test.skip() - class TestPortal(PortalTest): small = False @@ -80,16 +79,20 @@ def test_append(self): e = get_engine(""" + a(X, Y, Z) :- append(X, Y, Z). + a(X, Y, Z) :- append(X, Y, Z). append([], L, L). append([X|Y], L, [X|Z]) :- append(Y, L, Z). """) - t = parse_query_term("append([a, b, c], [d, f, g], X).") - X = e.heap.newvar() + t, vars = get_query_and_vars("a([a, b, c], [d, f, g], X).") def main(n): + e.heap = engine.Heap() + if n == 0: e.call(t) - return isinstance(X.dereference(e.heap), term.Term) + assert isinstance(vars['X'].dereference(e.heap), term.Term) + return True else: return False @@ -133,15 +136,15 @@ def test_loop(self): e = get_engine(""" - f(X) :- h(X, _). + f(X) :- h(X). f(50). - h(0, _). - h(X, Y) :- Y is X - 1, h(Y, _). + h(0). + h(X) :- Y is X - 1, h(Y). """) num = term.Number(50) def main(n): - e.heap.reset() + e.heap = engine.Heap() if n == 0: e.call(term.Term("f", [num])) return True From cfbolz at codespeak.net Sun Jun 10 20:37:37 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sun, 10 Jun 2007 20:37:37 +0200 (CEST) Subject: [pypy-svn] r44127 - in pypy/branch/prolog-bytecode/pypy/lang/prolog: builtin interpreter interpreter/test Message-ID: <20070610183737.E53AB80DE@code0.codespeak.net> Author: cfbolz Date: Sun Jun 10 20:37:37 2007 New Revision: 44127 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_parsing.py Log: don't create the complete Term instance for builtin calls, just build the arguments (which are usually already there in one form or the other). Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py Sun Jun 10 20:37:37 2007 @@ -15,8 +15,8 @@ self.signature = signature self.handles_continuation = handles_continuation - def call(self, engine, query, continuation): - return self.function(engine, query, continuation) + def call(self, engine, args, continuation): + return self.function(engine, args, continuation) def _freeze_(self): return True @@ -31,24 +31,24 @@ if not name.isalnum(): name = func.func_name funcname = "wrap_%s_%s" % (name, len(unwrap_spec)) - code = ["def %s(engine, query, continuation):" % (funcname, )] + code = ["def %s(engine, stack, continuation):" % (funcname, )] if not translatable: code.append(" if we_are_translated():") code.append(" raise error.UncatchableError('%s does not work in translated version')" % (name, )) subargs = ["engine"] - if len(unwrap_spec): - code.append(" assert isinstance(query, term.Term)") - else: - code.append(" assert isinstance(query, term.Atom)") + if unwrap_spec: + code.append(" startpos = len(stack) - %s" % (len(unwrap_spec), )) for i, spec in enumerate(unwrap_spec): + rawarg = "rawarg%s" % (i, ) + code.append(" %s = stack[startpos + %s]" % (rawarg, i)) varname = "var%s" % (i, ) subargs.append(varname) if spec in ("obj", "callable", "int", "atom", "arithmetic"): - code.append(" %s = query.args[%s].dereference(engine.heap)" % - (varname, i)) + code.append(" %s = %s.dereference(engine.heap)" % + (varname, rawarg)) elif spec in ("concrete", "list"): - code.append(" %s = query.args[%s].getvalue(engine.heap)" % - (varname, i)) + code.append(" %s = %s.getvalue(engine.heap)" % + (varname, rawarg)) if spec in ("int", "atom", "arithmetic", "list"): code.append( " if isinstance(%s, term.Var):" % (varname,)) @@ -64,7 +64,7 @@ code.append( " error.throw_type_error('callable', %s)" % (varname,)) elif spec == "raw": - code.append(" %s = query.args[%s]" % (varname, i)) + code.append(" %s = %s" % (varname, rawarg)) elif spec == "int": code.append(" %s = helper.unwrap_int(%s)" % (varname, varname)) elif spec == "atom": Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py Sun Jun 10 20:37:37 2007 @@ -101,7 +101,9 @@ self.emit_opcode(opcodedesc.CUT) elif body.signature in builtins_index: i = builtins_index[body.signature] - self.compile_termbuilding(body) + if isinstance(body, Term): + for arg in body.args: + self.compile_termbuilding(arg) self.emit_opcode(opcodedesc.CALL_BUILTIN, i) else: self.compile_termbuilding(body) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Sun Jun 10 20:37:37 2007 @@ -257,8 +257,13 @@ def CALL_BUILTIN(self, stack, number, continuation): from pypy.lang.prolog.builtin import builtins_list - return builtins_list[number][1].call(self.engine, stack.pop(), - continuation) + builtin = builtins_list[number][1] + result = builtin.call(self.engine, stack, continuation) + i = 0 + while i < builtin.numargs: + hint(i, concrete=True) + stack.pop() + i += 1 def CUT(self, stack, continuation): raise error.CutException(continuation) @@ -275,7 +280,11 @@ from pypy.lang.prolog.builtin import builtins if signature in builtins: builtin = builtins[signature] - return builtin.call(self.engine, query, continuation) + if isinstance(query, Term): + args = query.args + else: + args = None + return builtin.call(self.engine, args, continuation) function = self.engine.lookup_userfunction(signature) return self.user_call(function, query, continuation) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py Sun Jun 10 20:37:37 2007 @@ -65,8 +65,8 @@ head, body = get_query_and_vars("f(X, Y) :- X, call(Y).")[0].args code = compile(head, body, e) assert code.opcode_head == "m\x00\x00m\x00\x01t\x00\x00" - assert code.opcode.startswith("a\x00\x00a\x00\x01l\x00\x00Dl\x00\x01t\x00\x01b") - assert code.term_info == [("f", 2, "f/2"), ("call", 1, "call/1")] + assert code.opcode.startswith("a\x00\x00a\x00\x01l\x00\x00Dl\x00\x01b") + assert code.term_info == [("f", 2, "f/2")] assert code.can_contain_cut def test_cut(): @@ -85,9 +85,8 @@ code = compile(head, body, e) assert code.opcode_head == "m\x00\x00t\x00\x00" assert code.opcode.startswith( - "a\x00\x00m\x00\x01a\x00\x01l\x00\x00c\x00\x00t\x00\x01t\x00\x02b") + "a\x00\x00m\x00\x01a\x00\x01l\x00\x00c\x00\x00t\x00\x01b") assert code.constants == [Number(1)] - assert code.term_info == [("f", 1, "f/1"), ("-", 2, "-/2"), - ("is", 2, "is/2")] + assert code.term_info == [("f", 1, "f/1"), ("-", 2, "-/2")] assert not code.can_contain_cut Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_parsing.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_parsing.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_parsing.py Sun Jun 10 20:37:37 2007 @@ -1,5 +1,6 @@ from pypy.lang.prolog.interpreter.parsing import parse_file, TermBuilder, OrderTransformer -from pypy.lang.prolog.interpreter.parsing import parse_query_term +from pypy.lang.prolog.interpreter.parsing import parse_query_term, \ + get_query_and_vars def test_simple(): @@ -34,12 +35,10 @@ four = Term("succ", [Term("succ", [Term("succ", [Term("succ", [Atom("null")])])])]) e.run(parse_query_term("numeral(succ(succ(null))).")) - term = parse_query_term( + term, vars = get_query_and_vars( """add_numeral(succ(succ(null)), succ(succ(null)), X).""") e.run(term) - var = Var(0).getvalue(e.heap) - print var, e.heap - # does not raise + var = vars['X'].getvalue(e.heap) var.unify(four, e.heap) term = parse_query_term( """greater_than(succ(succ(succ(null))), succ(succ(null))).""") From cfbolz at codespeak.net Sun Jun 10 23:01:42 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sun, 10 Jun 2007 23:01:42 +0200 (CEST) Subject: [pypy-svn] r44128 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter Message-ID: <20070610210142.9182D80A9@code0.codespeak.net> Author: cfbolz Date: Sun Jun 10 23:01:41 2007 New Revision: 44128 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Log: work less for user calls too Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Sun Jun 10 23:01:41 2007 @@ -66,7 +66,15 @@ def unify_head(self, head): self.run(self.getcode(), True, 0, None) - self.result.unify(head, self.heap) + if isinstance(head, Term): + result = self.result + assert isinstance(result, Term) + i = 0 + m = hint(len(head.args), promote=True) + while i < m: + hint(i, concrete=True) + result.args[i].unify(head.args[i], self.heap) + i += 1 self.result = None def run_directly(self, continuation, choice_point=True): @@ -264,6 +272,7 @@ hint(i, concrete=True) stack.pop() i += 1 + return result def CUT(self, stack, continuation): raise error.CutException(continuation) From cfbolz at codespeak.net Mon Jun 11 00:37:10 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 11 Jun 2007 00:37:10 +0200 (CEST) Subject: [pypy-svn] r44129 - in pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter: . test Message-ID: <20070610223710.5F8DF80B2@code0.codespeak.net> Author: cfbolz Date: Mon Jun 11 00:37:09 2007 New Revision: 44129 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py Log: don't even build the Term instances Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py Mon Jun 11 00:37:09 2007 @@ -1,4 +1,4 @@ -from pypy.lang.prolog.interpreter.term import NonVar, Term, Var, Atom +from pypy.lang.prolog.interpreter.term import NonVar, Term, Var, Atom, Callable from pypy.lang.prolog.interpreter.engine import Continuation from pypy.lang.prolog.interpreter import helper, error from pypy.lang.prolog.interpreter.prologopcode import opcodedesc @@ -49,7 +49,9 @@ self.can_contain_cut = False result = Code() self.activate_vars_later = True - self.compile_termbuilding(head) + if isinstance(head, Term): + for arg in head.args: + self.compile_termbuilding(arg) result.opcode_head = self.getbytecode() if body is not None: self.add_localactivations() @@ -106,8 +108,10 @@ self.compile_termbuilding(arg) self.emit_opcode(opcodedesc.CALL_BUILTIN, i) else: - self.compile_termbuilding(body) - num = self.getfunction(body.signature) + if isinstance(body, Term): + for arg in body.args: + self.compile_termbuilding(arg) + num = self.getfunction(body) self.emit_opcode(opcodedesc.STATIC_CALL, num) def compile_localvar(self, var): @@ -160,12 +164,15 @@ self.constants.append(const) return result - def getfunction(self, signature): + def getfunction(self, query): + assert isinstance(query, Callable) + signature = query.signature try: return self.functionmap[signature] except KeyError: result = len(self.functionmap) self.functionmap[signature] = result - self.functions.append(self.engine.lookup_userfunction(signature)) + self.functions.append(self.engine.lookup_userfunction( + signature, query.get_prolog_signature())) return result Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py Mon Jun 11 00:37:09 2007 @@ -98,7 +98,9 @@ class Function(object): - def __init__(self, firstrule=None): + def __init__(self, signature, prolog_signature, firstrule=None): + self.signature = signature + self.prolog_signature = prolog_signature if firstrule is None: self.rulechain = self.last = None else: @@ -154,7 +156,8 @@ if function is not None: self.signature2function[signature].add_rule(rule, end) else: - self.signature2function[signature] = Function(rule) + self.signature2function[signature] = Function( + signature, rule.head.get_prolog_signature(), rule) def run(self, query, continuation=DONOTHING): from pypy.lang.prolog.interpreter.interpreter import dynamic_call_frame @@ -186,12 +189,13 @@ #XXX handle choice_point correctly return frame.run_directly(continuation, choice_point) - @purefunction - def lookup_userfunction(self, signature): + def lookup_userfunction(self, signature, prolog_signature=None): signature2function = self.signature2function function = signature2function.get(signature, None) if function is None: - signature2function[signature] = function = Function() + assert prolog_signature is not None + signature2function[signature] = function = Function( + signature, prolog_signature) return function def continue_after_cut(self, continuation, lsc=None): Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Mon Jun 11 00:37:09 2007 @@ -33,9 +33,9 @@ self.signature = self.head.signature self.engine = engine - def make_frame(self, head): + def make_frame(self, stack): f = Frame(self.engine, self.code) - f.unify_head(head) + f.unify_head(stack) return f def __repr__(self): @@ -64,16 +64,17 @@ def getcode(self): return hint(hint(self.code, promote=True), deepfreeze=True) - def unify_head(self, head): + def unify_head(self, stack): self.run(self.getcode(), True, 0, None) - if isinstance(head, Term): - result = self.result - assert isinstance(result, Term) + result = self.result + if len(result): i = 0 - m = hint(len(head.args), promote=True) + # These should be early constants, really + m = hint(len(result), promote=True) + startfrom = hint(len(stack) - m, promote=True) while i < m: hint(i, concrete=True) - result.args[i].unify(head.args[i], self.heap) + result[i].unify(stack[startfrom + i], self.heap) i += 1 self.result = None @@ -162,7 +163,7 @@ else: continuation = continuation._call(self.engine) if head: - self.result = stack[0] + self.result = stack return continuation def _run(self, codeobject, head, pc, continuation): @@ -204,7 +205,7 @@ else: continuation = continuation._call(self.engine) if head: - self.result = stack[0] + self.result = stack return continuation @@ -278,9 +279,8 @@ raise error.CutException(continuation) def STATIC_CALL(self, stack, number, continuation): - query = stack.pop() function = self.getcode().functions[number] - return self.user_call(function, query, continuation) + return self.user_call(function, stack, continuation) def DYNAMIC_CALL(self, stack, continuation): query = stack.pop() @@ -294,8 +294,13 @@ else: args = None return builtin.call(self.engine, args, continuation) - function = self.engine.lookup_userfunction(signature) - return self.user_call(function, query, continuation) + function = self.engine.lookup_userfunction( + signature, query.get_prolog_signature()) + if isinstance(query, Term): + args = query.args + else: + args = None + return self.user_call(function, args, continuation) def CLEAR_LOCAL(self, stack, number): self.localvarcache[number] = None @@ -303,13 +308,12 @@ def UNIFY(self, stack): stack.pop().unify(stack.pop(), self.heap) - def user_call(self, function, query, continuation): - assert isinstance(query, Callable) + def user_call(self, function, args, continuation): rulechain = function.rulechain rulechain = hint(rulechain, promote=True) if rulechain is None: error.throw_existence_error( - "procedure", query.get_prolog_signature()) + "procedure", function.prolog_signature) oldstate = self.heap.branch() while rulechain is not None: rule = rulechain.rule @@ -318,7 +322,7 @@ if rule.code.can_contain_cut: continuation = LimitedScopeContinuation(continuation) try: - frame = rule.make_frame(query) + frame = rule.make_frame(args) result = frame.run_directly(continuation) return result except error.UnificationFailed: @@ -330,7 +334,7 @@ raise else: try: - frame = rule.make_frame(query) + frame = rule.make_frame(args) result = frame.run_directly(continuation, choice_point) return result except error.UnificationFailed: Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_compiler.py Mon Jun 11 00:37:09 2007 @@ -7,8 +7,8 @@ foo = Atom("foo") code = compile(foo, None, e) assert not code.opcode - assert code.opcode_head == "c\x00\x00" - assert code.constants == [foo] + assert code.opcode_head == "" + assert code.constants == [] assert not code.can_contain_cut def test_simple_withbody(): @@ -16,37 +16,37 @@ foo = Atom("foo") bar = Atom("bar") code = compile(foo, bar, e) - assert code.opcode_head == "c\x00\x00" - assert code.opcode == "c\x00\x01s\x00\x00" - assert code.constants == [foo, bar] + assert code.opcode_head == "" + assert code.opcode == "s\x00\x00" + assert code.constants == [] assert not code.can_contain_cut def test_simple_withargs(): e = get_engine("") head, body = get_query_and_vars("f(X) :- g(X).")[0].args code = compile(head, body, e) - assert code.opcode_head == "m\x00\x00t\x00\x00" - assert code.opcode == "a\x00\x00l\x00\x00t\x00\x01s\x00\x00" + assert code.opcode_head == "m\x00\x00" + assert code.opcode == "a\x00\x00l\x00\x00s\x00\x00" assert code.constants == [] - assert code.term_info == [("f", 1, "f/1"), ("g", 1, "g/1")] + assert code.term_info == [] assert not code.can_contain_cut def test_simple_and(): e = get_engine("") head, body = get_query_and_vars("f(X, Y) :- g(X), h(Y).")[0].args code = compile(head, body, e) - assert code.opcode_head == "m\x00\x00m\x00\x01t\x00\x00" - assert code.opcode == "a\x00\x00a\x00\x01l\x00\x00t\x00\x01s\x00\x00l\x00\x01t\x00\x02s\x00\x01" + assert code.opcode_head == "m\x00\x00m\x00\x01" + assert code.opcode == "a\x00\x00a\x00\x01l\x00\x00s\x00\x00l\x00\x01s\x00\x01" assert code.constants == [] - assert code.term_info == [("f", 2, "f/2"), ("g", 1, "g/1"), ("h", 1, "h/1")] + assert code.term_info == [] assert not code.can_contain_cut def test_nested_term(): e = get_engine("") head = get_query_and_vars("f(g(X), a).")[0] code = compile(head, None, e) - assert code.opcode_head == "m\x00\x00t\x00\x00c\x00\x00t\x00\x01" - assert code.term_info == [("g", 1, "g/1"), ("f", 2, "f/2")] + assert code.opcode_head == "m\x00\x00t\x00\x00c\x00\x00" + assert code.term_info == [("g", 1, "g/1")] assert code.constants == [Atom("a")] assert not code.can_contain_cut @@ -54,28 +54,28 @@ e = get_engine("") head, body = get_query_and_vars("f(X, Y) :- g(X) = g(Y).")[0].args code = compile(head, body, e) - assert code.opcode_head == "m\x00\x00m\x00\x01t\x00\x00" - assert code.opcode == "a\x00\x00a\x00\x01l\x00\x00t\x00\x01l\x00\x01t\x00\x01U" + assert code.opcode_head == "m\x00\x00m\x00\x01" + assert code.opcode == "a\x00\x00a\x00\x01l\x00\x00t\x00\x00l\x00\x01t\x00\x00U" assert code.constants == [] - assert code.term_info == [("f", 2, "f/2"), ("g", 1, "g/1")] + assert code.term_info == [("g", 1, "g/1")] assert not code.can_contain_cut def test_dynamic_call(): e = get_engine("") head, body = get_query_and_vars("f(X, Y) :- X, call(Y).")[0].args code = compile(head, body, e) - assert code.opcode_head == "m\x00\x00m\x00\x01t\x00\x00" + assert code.opcode_head == "m\x00\x00m\x00\x01" assert code.opcode.startswith("a\x00\x00a\x00\x01l\x00\x00Dl\x00\x01b") - assert code.term_info == [("f", 2, "f/2")] + assert code.term_info == [] assert code.can_contain_cut def test_cut(): e = get_engine("") head, body = get_query_and_vars("f(X, Y) :- !.")[0].args code = compile(head, body, e) - assert code.opcode_head == "m\x00\x00m\x00\x01t\x00\x00" + assert code.opcode_head == "m\x00\x00m\x00\x01" assert code.opcode == "a\x00\x00a\x00\x01C" - assert code.term_info == [("f", 2, "f/2")] + assert code.term_info == [] assert code.can_contain_cut def test_arithmetic(): @@ -83,10 +83,10 @@ e = get_engine("") head, body = get_query_and_vars("f(X) :- Y is X - 1, f(Y).")[0].args code = compile(head, body, e) - assert code.opcode_head == "m\x00\x00t\x00\x00" + assert code.opcode_head == "m\x00\x00" assert code.opcode.startswith( - "a\x00\x00m\x00\x01a\x00\x01l\x00\x00c\x00\x00t\x00\x01b") + "a\x00\x00m\x00\x01a\x00\x01l\x00\x00c\x00\x00t\x00\x00b") assert code.constants == [Number(1)] - assert code.term_info == [("f", 1, "f/1"), ("-", 2, "-/2")] + assert code.term_info == [("-", 2, "-/2")] assert not code.can_contain_cut Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py Mon Jun 11 00:37:09 2007 @@ -7,14 +7,14 @@ head, body = get_query_and_vars("f(X) :- X = a.")[0].args r = Rule(head, body, e) query = get_query_and_vars("f(a).")[0] - frame = r.make_frame(query) + frame = r.make_frame(query.args) assert frame.localvarcache[0].dereference(e.heap).name == "a" cont = object() c2 = frame.run(frame.code, False, 0, cont) assert cont is c2 query, vars = get_query_and_vars("f(X).") - frame = r.make_frame(query) + frame = r.make_frame(query.args) cont = object() c2 = frame.run(frame.code, False, 0, cont) assert cont is c2 @@ -28,5 +28,5 @@ frame = Frame(e, r.code) frame.run(frame.code, True, 0, None) frame.run(frame.code, False, 0, None) - assert frame.result.args[0].dereference(e.heap).name == "a" - assert frame.result.args[1].dereference(e.heap).name == "b" + assert frame.result[0].dereference(e.heap).name == "a" + assert frame.result[1].dereference(e.heap).name == "b" From arigo at codespeak.net Mon Jun 11 13:14:00 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 11 Jun 2007 13:14:00 +0200 (CEST) Subject: [pypy-svn] r44131 - pypy/dist/pypy/lib/pyontology/ontodemo Message-ID: <20070611111400.A5D2B8120@code0.codespeak.net> Author: arigo Date: Mon Jun 11 13:14:00 2007 New Revision: 44131 Removed: pypy/dist/pypy/lib/pyontology/ontodemo/paths.pyc pypy/dist/pypy/lib/pyontology/ontodemo/queries.pyc Log: Remove .pyc files. From fijal at codespeak.net Mon Jun 11 13:16:10 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 11 Jun 2007 13:16:10 +0200 (CEST) Subject: [pypy-svn] r44132 - pypy/dist/pypy/lib/pyontology/ontodemo Message-ID: <20070611111610.7C3118124@code0.codespeak.net> Author: fijal Date: Mon Jun 11 13:16:10 2007 New Revision: 44132 Modified: pypy/dist/pypy/lib/pyontology/ontodemo/ (props changed) pypy/dist/pypy/lib/pyontology/ontodemo/README.txt (contents, props changed) pypy/dist/pypy/lib/pyontology/ontodemo/dummyserver.py (props changed) pypy/dist/pypy/lib/pyontology/ontodemo/ontodemo-1024x768.py (props changed) pypy/dist/pypy/lib/pyontology/ontodemo/ontodemo-1280x1024.py (props changed) pypy/dist/pypy/lib/pyontology/ontodemo/ontodemo-1280x1024.rsrc.py (props changed) pypy/dist/pypy/lib/pyontology/ontodemo/ontodemo.py (props changed) pypy/dist/pypy/lib/pyontology/ontodemo/ontodemo.rsrc.py (props changed) pypy/dist/pypy/lib/pyontology/ontodemo/ontoserver.py (props changed) pypy/dist/pypy/lib/pyontology/ontodemo/paths.py (contents, props changed) pypy/dist/pypy/lib/pyontology/ontodemo/queries.py (props changed) pypy/dist/pypy/lib/pyontology/ontodemo/sparqlquery.py (props changed) Log: fixeol and windows line endings Modified: pypy/dist/pypy/lib/pyontology/ontodemo/README.txt ============================================================================== --- pypy/dist/pypy/lib/pyontology/ontodemo/README.txt (original) +++ pypy/dist/pypy/lib/pyontology/ontodemo/README.txt Mon Jun 11 13:16:10 2007 @@ -1,40 +1,40 @@ -How to run the pyontology demo ------------------------------- - -The following configuration of modules should be used to test the -system with Python 2.4. - -* Check out PyPy from http://codespeak.net/svn/pypy/dist/ - -* Check out dependencies from http://codespeak.net/svn/user/arigo/hack/pypy-hack/pyontology-deps - This will load the following packages: - - * Logilab common (ftp://ftp.logilab.fr/pub/common) - * Logilab constraint (ftp://ftp.logilab.fr/pub/constraint/logilab-constraint-0.3.0) - * rdflib_ (http://rdflib.net) - - At the same time it will avoid the installation of an outdated - commercial version of VisualStudio that would otherwise be needed - for compilation. - -* Install pyparsing.py (available from Sourceforge.net) - -For the GUI, some components need to be installed to support graphical -interfaces. - -* Install Pythoncard (http://pythoncard.sourceforge.net) - -* Install Wxpython (http://www.wxpython.org/) - -In the current directory - -* adapt path names in paths.py -* start server: ./ontoserver - where is a file specification for your OWL file -* start GUI: ./python ontodemo - -To define SPARQL queries, write each in a file. Edit file queries.py, -adding lines of the following kind: -"": ("", None), - -In the GUI, select a question and press "answer" to see the result. +How to run the pyontology demo +------------------------------ + +The following configuration of modules should be used to test the +system with Python 2.4. + +* Check out PyPy from http://codespeak.net/svn/pypy/dist/ + +* Check out dependencies from http://codespeak.net/svn/user/arigo/hack/pypy-hack/pyontology-deps + This will load the following packages: + + * Logilab common (ftp://ftp.logilab.fr/pub/common) + * Logilab constraint (ftp://ftp.logilab.fr/pub/constraint/logilab-constraint-0.3.0) + * rdflib_ (http://rdflib.net) + + At the same time it will avoid the installation of an outdated + commercial version of VisualStudio that would otherwise be needed + for compilation. + +* Install pyparsing.py (available from Sourceforge.net) + +For the GUI, some components need to be installed to support graphical +interfaces. + +* Install Pythoncard (http://pythoncard.sourceforge.net) + +* Install Wxpython (http://www.wxpython.org/) + +In the current directory + +* adapt path names in paths.py +* start server: ./ontoserver + where is a file specification for your OWL file +* start GUI: ./python ontodemo + +To define SPARQL queries, write each in a file. Edit file queries.py, +adding lines of the following kind: +"": ("", None), + +In the GUI, select a question and press "answer" to see the result. Modified: pypy/dist/pypy/lib/pyontology/ontodemo/paths.py ============================================================================== --- pypy/dist/pypy/lib/pyontology/ontodemo/paths.py (original) +++ pypy/dist/pypy/lib/pyontology/ontodemo/paths.py Mon Jun 11 13:16:10 2007 @@ -1,8 +1,8 @@ -# Directory hosting ontodemo code -demodir="d:\\PyPy-svn\\pypy-dist\\pypy\\lib\\pyontology\\ontodemo" - -# Directory for the PyPy distribution -distdir="d:\\PyPy-svn\\pypy-dist" - -# Directory hosting the pyontology dependencies +# Directory hosting ontodemo code +demodir="d:\\PyPy-svn\\pypy-dist\\pypy\\lib\\pyontology\\ontodemo" + +# Directory for the PyPy distribution +distdir="d:\\PyPy-svn\\pypy-dist" + +# Directory hosting the pyontology dependencies depssir="d:\\PyPy-svn\\pyontology-deps" \ No newline at end of file From cfbolz at codespeak.net Mon Jun 11 13:30:08 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 11 Jun 2007 13:30:08 +0200 (CEST) Subject: [pypy-svn] r44133 - pypy/branch/prolog-bytecode/pypy/translator/goal Message-ID: <20070611113008.B49B58128@code0.codespeak.net> Author: cfbolz Date: Mon Jun 11 13:30:08 2007 New Revision: 44133 Modified: pypy/branch/prolog-bytecode/pypy/translator/goal/targetprologstandalone.py Log: build the engine at runtime Modified: pypy/branch/prolog-bytecode/pypy/translator/goal/targetprologstandalone.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/translator/goal/targetprologstandalone.py (original) +++ pypy/branch/prolog-bytecode/pypy/translator/goal/targetprologstandalone.py Mon Jun 11 13:30:08 2007 @@ -15,6 +15,7 @@ def entry_point(argv): from pypy.jit.codegen.hlinfo import highleveljitinfo + e = Engine() if highleveljitinfo.sys_executable is None: highleveljitinfo.sys_executable = argv[0] if len(argv) == 2: From cfbolz at codespeak.net Mon Jun 11 13:33:07 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 11 Jun 2007 13:33:07 +0200 (CEST) Subject: [pypy-svn] r44134 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter Message-ID: <20070611113307.844EF812A@code0.codespeak.net> Author: cfbolz Date: Mon Jun 11 13:33:07 2007 New Revision: 44134 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Log: promote a bit differently Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Mon Jun 11 13:33:07 2007 @@ -74,7 +74,9 @@ startfrom = hint(len(stack) - m, promote=True) while i < m: hint(i, concrete=True) - result[i].unify(stack[startfrom + i], self.heap) + arg = stack[startfrom + i] + hint(arg.__class__, promote=True) + result[i].unify(arg, self.heap) i += 1 self.result = None @@ -249,9 +251,8 @@ def ACTIVATE_LOCAL(self, stack, number): var = self.localvarcache[number] - assert var.__class__ == LocalVar + assert type(var) is LocalVar self.localvarcache[number] = result = var.dereference(self.heap) - hint(result.__class__, promote=True) var.active = True def MAKETERM(self, stack, number): From fijal at codespeak.net Mon Jun 11 13:47:02 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 11 Jun 2007 13:47:02 +0200 (CEST) Subject: [pypy-svn] r44135 - pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test Message-ID: <20070611114702.D1B61812F@code0.codespeak.net> Author: fijal Date: Mon Jun 11 13:47:01 2007 New Revision: 44135 Modified: pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rfficache.py Log: Fix the test Modified: pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rfficache.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rfficache.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rfficache.py Mon Jun 11 13:47:01 2007 @@ -11,13 +11,14 @@ tmpfile = udir.join("somecrappyfile.py") assert get_type_sizes(tmpfile)['char'] == 8 # this should not invoke a compiler - assert get_type_sizes(tmpfile, compiler_exe='xxx')['char'] == 8 + res = get_type_sizes(tmpfile, compiler_exe='xxx') + assert res['char'] == 8 def test_gettypesizes_platforms(): tmpfile = udir.join("plat.py") tmpfile.write(py.code.Source(""" - platforms = {'xxx':{'char':4}} - """)) + platforms = {'xxx':{%s}} + """ % ", ".join(['"%s":4' % i for i in TYPES]))) assert get_type_sizes(tmpfile)['char'] == 8 assert get_type_sizes(tmpfile, platform_key='xxx', compiler_exe='xxx')['char'] == 4 From arigo at codespeak.net Mon Jun 11 13:51:54 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 11 Jun 2007 13:51:54 +0200 (CEST) Subject: [pypy-svn] r44136 - pypy/branch/kill-ctypes/pypy/rpython/lltypesystem Message-ID: <20070611115154.8F4E28134@code0.codespeak.net> Author: arigo Date: Mon Jun 11 13:51:54 2007 New Revision: 44136 Modified: pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py Log: Minor: avoid mutating the incoming dictionary kwds['hints'] in-place. Modified: pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py Mon Jun 11 13:51:54 2007 @@ -47,12 +47,13 @@ """ A small helper to create external C structure, not the pypy one """ - if 'hints' not in kwds: - kwds['hints'] = {} - kwds['hints']['external'] = 'C' - kwds['hints']['c_name'] = name - # XXX obscure hack, stolen for unknown reason from ctypes, - # probably because of _ attributes + hints = kwds.get('hints', {}) + hints = hints.copy() + kwds['hints'] = hints + hints['external'] = 'C' + hints['c_name'] = name + # Hack: prefix all attribute names with 'c_' to cope with names starting + # with '_'. The genc backend removes the 'c_' prefixes... c_fields = [('c_' + key, value) for key, value in fields] return lltype.Ptr(lltype.Struct(name, *c_fields, **kwds)) From fijal at codespeak.net Mon Jun 11 14:53:40 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 11 Jun 2007 14:53:40 +0200 (CEST) Subject: [pypy-svn] r44137 - pypy/branch/kill-ctypes/pypy/rpython/lltypesystem Message-ID: <20070611125340.BDB33812F@code0.codespeak.net> Author: fijal Date: Mon Jun 11 14:53:39 2007 New Revision: 44137 Modified: pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rfficache.py Log: Don't use pyimport (not to populate sys.modules) Modified: pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rfficache.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rfficache.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rfficache.py Mon Jun 11 14:53:39 2007 @@ -50,8 +50,9 @@ def get_type_sizes(filename, platform_key=machine_key(), types=TYPES, compiler_exe=None): try: - mod = py.path.local(filename).pyimport() - platforms = mod.platforms + mod = {} + exec py.path.local(filename).read() in mod + platforms = mod['platforms'] except (ImportError, py.error.ENOENT): platforms = {} try: From cfbolz at codespeak.net Mon Jun 11 15:54:00 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 11 Jun 2007 15:54:00 +0200 (CEST) Subject: [pypy-svn] r44139 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter Message-ID: <20070611135400.A62D7812A@code0.codespeak.net> Author: cfbolz Date: Mon Jun 11 15:53:59 2007 New Revision: 44139 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Log: tiny optimization Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Mon Jun 11 15:53:59 2007 @@ -269,11 +269,8 @@ from pypy.lang.prolog.builtin import builtins_list builtin = builtins_list[number][1] result = builtin.call(self.engine, stack, continuation) - i = 0 - while i < builtin.numargs: - hint(i, concrete=True) - stack.pop() - i += 1 + # popping from the stack is not needed, the stack will be discarded now + # anyway return result def CUT(self, stack, continuation): From cfbolz at codespeak.net Mon Jun 11 16:45:46 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 11 Jun 2007 16:45:46 +0200 (CEST) Subject: [pypy-svn] r44145 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter Message-ID: <20070611144546.38182814C@code0.codespeak.net> Author: cfbolz Date: Mon Jun 11 16:45:45 2007 New Revision: 44145 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py Log: somewhat crazy experiment to deal with the fact that virtualizability seems to give me crashes. Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Mon Jun 11 16:45:45 2007 @@ -52,13 +52,15 @@ class Frame(object): - _virtualizable_ = True - - def __init__(self, engine, code): + def __init__(self, engine, code, localvarcache=None, heap=None): self.engine = engine - self.heap = engine.heap + if heap is None: + heap = engine.heap + self.heap = heap self.code = code - self.localvarcache = [None] * code.maxlocalvar + if localvarcache is None: + localvarcache = [None] * code.maxlocalvar + self.localvarcache = localvarcache self.result = None def getcode(self): @@ -99,74 +101,15 @@ return self._run(codeobject, head, pc, continuation) if not we_are_jitted(): assert codeobject is not None - return self.run_jit(self.heap, codeobject, head, pc, continuation) + return run_jit(self.localvarcache, self.engine, self.heap, + codeobject, head, pc, continuation) return self.opaque_run(codeobject, head, pc, continuation) def opaque_run(self, codeobject, head, pc, continuation): - return self.run_jit(self.heap, codeobject, head, pc, continuation) + return run_jit(self.localvarcache, self.engine, self.heap, + codeobject, head, pc, continuation) opaque_run._look_inside_me = False - def jit_enter_function(self): - # funnyness - code = self.getcode() - localvarcache = [None] * code.maxlocalvar - i = code.maxlocalvar - while True: - i -= 1 - if i < 0: - break - hint(i, concrete=True) - obj = self.localvarcache[i] - localvarcache[i] = obj - self.localvarcache = localvarcache - - def run_jit(self, heap, codeobject, head, pc, continuation): - hint(None, global_merge_point=True) - hint(codeobject, concrete=True) - codeobject = hint(codeobject, deepfreeze=True) - hint(head, concrete=True) - if head: - bytecode = codeobject.opcode_head - pc = 0 - else: - bytecode = codeobject.opcode - pc = hint(pc, promote=True) - self.code = codeobject - self.heap = heap - - self.jit_enter_function() - stack = [] - while pc < len(bytecode): - hint(None, global_merge_point=True) - opcode = ord(bytecode[pc]) - pc += 1 - if opcode >= HAVE_ARGUMENT: - hi = ord(bytecode[pc]) - lo = ord(bytecode[pc+1]) - pc += 2 - oparg = (hi << 8) | lo - else: - oparg = 0 - hint(opcode, concrete=True) - hint(oparg, concrete=True) - #import pdb; pdb.set_trace() - res = self.dispatch_bytecode(opcode, oparg, bytecode, pc, - stack, continuation) - if res is not None: - continuation = res - while continuation is not DONOTHING: - if isinstance(continuation, FrameContinuation): - self = continuation.frame - bytecode = self.getcode().opcode - pc = hint(continuation.pc, promote=True) - continuation = continuation.continuation - stack = [] - break - else: - continuation = continuation._call(self.engine) - if head: - self.result = stack - return continuation def _run(self, codeobject, head, pc, continuation): codeobject = hint(codeobject, promote=True) @@ -340,3 +283,81 @@ if not choice_point: raise rulechain = rulechain.next + +def run_jit(original_localvarcache, engine, heap, codeobject, + head, pc, continuation): + hint(None, global_merge_point=True) + hint(codeobject, concrete=True) + codeobject = hint(codeobject, deepfreeze=True) + hint(head, concrete=True) + if head: + bytecode = codeobject.opcode_head + pc = 0 + else: + bytecode = codeobject.opcode + pc = hint(pc, promote=True) + self = jit_enter_function(engine, heap, codeobject, original_localvarcache) + original_self = self + original_code = codeobject + + stack = [] + while pc < len(bytecode): + hint(None, global_merge_point=True) + opcode = ord(bytecode[pc]) + pc += 1 + if opcode >= HAVE_ARGUMENT: + hi = ord(bytecode[pc]) + lo = ord(bytecode[pc+1]) + pc += 2 + oparg = (hi << 8) | lo + else: + oparg = 0 + hint(opcode, concrete=True) + hint(oparg, concrete=True) + #import pdb; pdb.set_trace() + res = self.dispatch_bytecode(opcode, oparg, bytecode, pc, + stack, continuation) + if res is not None: + continuation = res + while continuation is not DONOTHING: + if isinstance(continuation, FrameContinuation): + self = continuation.frame + bytecode = self.getcode().opcode + pc = hint(continuation.pc, promote=True) + continuation = continuation.continuation + stack = [] + break + else: + continuation = continuation._call(self.engine) + if head: + self.result = stack + jit_leave_function(original_code, original_self.localvarcache, + original_localvarcache) + return continuation + +def jit_enter_function(engine, heap, code, concrete_localvarcache): + # complete funnyness + localvarcache = [None] * code.maxlocalvar + i = code.maxlocalvar + while True: + i -= 1 + if i < 0: + break + hint(i, concrete=True) + obj = concrete_localvarcache[i] + localvarcache[i] = obj + self = Frame(engine, code, localvarcache) + self.localvarcache = localvarcache + self.heap = heap + return self + +def jit_leave_function(code, localvarcache, original_localvarcache): + i = code.maxlocalvar + while True: + i -= 1 + if i < 0: + break + hint(i, concrete=True) + obj = localvarcache[i] + original_localvarcache[i] = obj + Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py Mon Jun 11 16:45:45 2007 @@ -14,7 +14,7 @@ } -PORTAL = interpreter.Frame.run_jit.im_func +PORTAL = interpreter.run_jit class PyrologHintAnnotatorPolicy(ManualGraphPolicy): PORTAL = PORTAL @@ -45,10 +45,12 @@ self.seegraph(engine.Heap.newvar) self.seegraph(engine.TrailChunk.__init__) self.seegraph(interpreter.Rule.make_frame) + self.seegraph(interpreter.jit_enter_function) + self.seegraph(interpreter.jit_leave_function) for method in "branch revert newvar add_trail".split(): self.seegraph(getattr(engine.Heap, method)) for method in ("unify_head run_directly run user_call " - "dispatch_bytecode getcode jit_enter_function " + "dispatch_bytecode getcode " "__init__ _run").split(): self.seegraph(getattr(interpreter.Frame, method)) for num in prologopcode.allopcodes: From pdg at codespeak.net Mon Jun 11 17:04:31 2007 From: pdg at codespeak.net (pdg at codespeak.net) Date: Mon, 11 Jun 2007 17:04:31 +0200 (CEST) Subject: [pypy-svn] r44146 - pypy/dist/pypy/translator/jvm Message-ID: <20070611150431.807AA8148@code0.codespeak.net> Author: pdg Date: Mon Jun 11 17:04:31 2007 New Revision: 44146 Modified: pypy/dist/pypy/translator/jvm/generator.py pypy/dist/pypy/translator/jvm/opcodes.py Log: translator/jvm - fixed tabs Modified: pypy/dist/pypy/translator/jvm/generator.py ============================================================================== --- pypy/dist/pypy/translator/jvm/generator.py (original) +++ pypy/dist/pypy/translator/jvm/generator.py Mon Jun 11 17:04:31 2007 @@ -215,7 +215,7 @@ I2L = Opcode('i2l') D2I= Opcode('d2i') L2I = Opcode('l2i') -L2D = Opcode('l2d') +L2D = Opcode('l2d') ATHROW = Opcode('athrow') DNEG = Opcode('dneg') DADD = Opcode('dadd') Modified: pypy/dist/pypy/translator/jvm/opcodes.py ============================================================================== --- pypy/dist/pypy/translator/jvm/opcodes.py (original) +++ pypy/dist/pypy/translator/jvm/opcodes.py Mon Jun 11 17:04:31 2007 @@ -233,7 +233,7 @@ 'cast_float_to_int': jvmgen.D2I, 'cast_float_to_uint': jvmgen.PYPYDOUBLETOUINT, 'truncate_longlong_to_int': jvmgen.L2I, - 'cast_longlong_to_float': jvmgen.L2D, + 'cast_longlong_to_float': jvmgen.L2D, } From cfbolz at codespeak.net Mon Jun 11 17:32:26 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 11 Jun 2007 17:32:26 +0200 (CEST) Subject: [pypy-svn] r44147 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter Message-ID: <20070611153226.41CE280A3@code0.codespeak.net> Author: cfbolz Date: Mon Jun 11 17:32:25 2007 New Revision: 44147 Added: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/ - copied from r44145, pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/ Log: revert last checkin, was too crazy From cfbolz at codespeak.net Mon Jun 11 18:08:37 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 11 Jun 2007 18:08:37 +0200 (CEST) Subject: [pypy-svn] r44152 - pypy/branch/prolog-bytecode/pypy/rpython/lltypesystem Message-ID: <20070611160837.F196B8156@code0.codespeak.net> Author: cfbolz Date: Mon Jun 11 18:08:37 2007 New Revision: 44152 Modified: pypy/branch/prolog-bytecode/pypy/rpython/lltypesystem/rstr.py Log: don't look into string equality - leads to funny inlined graphs. Modified: pypy/branch/prolog-bytecode/pypy/rpython/lltypesystem/rstr.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/rpython/lltypesystem/rstr.py (original) +++ pypy/branch/prolog-bytecode/pypy/rpython/lltypesystem/rstr.py Mon Jun 11 18:08:37 2007 @@ -333,6 +333,7 @@ j += 1 return True + ll_streq._pure_function_ = True def ll_startswith(s1, s2): len1 = len(s1.chars) From pdg at codespeak.net Mon Jun 11 20:22:49 2007 From: pdg at codespeak.net (pdg at codespeak.net) Date: Mon, 11 Jun 2007 20:22:49 +0200 (CEST) Subject: [pypy-svn] r44155 - pypy/dist/pypy/translator/jvm Message-ID: <20070611182249.20D698145@code0.codespeak.net> Author: pdg Date: Mon Jun 11 20:22:48 2007 New Revision: 44155 Modified: pypy/dist/pypy/translator/jvm/generator.py pypy/dist/pypy/translator/jvm/opcodes.py Log: translator/jvm - work towards float to longlong conversion Modified: pypy/dist/pypy/translator/jvm/generator.py ============================================================================== --- pypy/dist/pypy/translator/jvm/generator.py (original) +++ pypy/dist/pypy/translator/jvm/generator.py Mon Jun 11 20:22:48 2007 @@ -214,6 +214,7 @@ I2D = Opcode('i2d') I2L = Opcode('i2l') D2I= Opcode('d2i') +#D2L= Opcode('d2l') #PAUL L2I = Opcode('l2i') L2D = Opcode('l2d') ATHROW = Opcode('athrow') @@ -374,6 +375,7 @@ PYPYULONGCMP = Method.s(jPyPy, 'ulong_cmp', (jLong,jLong), jInt) PYPYUINTTODOUBLE = Method.s(jPyPy, 'uint_to_double', (jInt,), jDouble) PYPYDOUBLETOUINT = Method.s(jPyPy, 'double_to_uint', (jDouble,), jInt) +#PYPYDOUBLETOLONG = Method.s(jPyPy, 'double_to_long', (jDouble,), jLong) #PAUL PYPYLONGBITWISENEGATE = Method.s(jPyPy, 'long_bitwise_negate', (jLong,), jLong) PYPYSTRTOINT = Method.s(jPyPy, 'str_to_int', (jString,), jInt) PYPYSTRTOUINT = Method.s(jPyPy, 'str_to_uint', (jString,), jInt) Modified: pypy/dist/pypy/translator/jvm/opcodes.py ============================================================================== --- pypy/dist/pypy/translator/jvm/opcodes.py (original) +++ pypy/dist/pypy/translator/jvm/opcodes.py Mon Jun 11 20:22:48 2007 @@ -84,7 +84,7 @@ 'int_is_true': 'not_equals_zero', 'int_neg': jvmgen.INEG, - 'int_neg_ovf': _check_ovf(jvmgen.INEG), # How to handle overflow? + 'int_neg_ovf': None, # How to handle overflow? 'int_abs': 'iabs', 'int_abs_ovf': _check_ovf('iabs'), 'int_invert': 'bitwise_negate', @@ -216,7 +216,7 @@ # when casting from bool we want that every truth value is casted # to 1: we can't simply DoNothing, because the CLI stack could # contains a truth value not equal to 1, so we should use the !=0 - # trick. + # trick. #THIS COMMENT NEEDS TO BE VALIDATED AND UPDATED 'cast_bool_to_int': DoNothing, 'cast_bool_to_uint': DoNothing, 'cast_bool_to_float': [PushAllArgs, 'not_equals_zero', jvmgen.I2D], @@ -231,6 +231,8 @@ 'cast_uint_to_int': DoNothing, 'cast_uint_to_float': jvmgen.PYPYUINTTODOUBLE, 'cast_float_to_int': jvmgen.D2I, + #'cast_float_to_longlong': jvmgen.D2L, #PAUL + #'cast_float_to_longlong': jvmgen.PYPYDOUBLETOLONG, #PAUL 'cast_float_to_uint': jvmgen.PYPYDOUBLETOUINT, 'truncate_longlong_to_int': jvmgen.L2I, 'cast_longlong_to_float': jvmgen.L2D, From cfbolz at codespeak.net Mon Jun 11 20:49:13 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 11 Jun 2007 20:49:13 +0200 (CEST) Subject: [pypy-svn] r44156 - pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter Message-ID: <20070611184913.911FC8148@code0.codespeak.net> Author: cfbolz Date: Mon Jun 11 20:49:12 2007 New Revision: 44156 Removed: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/choice.py Log: remove long defunct experiment From cfbolz at codespeak.net Mon Jun 11 20:57:09 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 11 Jun 2007 20:57:09 +0200 (CEST) Subject: [pypy-svn] r44157 - in pypy/branch/prolog-bytecode/pypy/lang/prolog: builtin interpreter interpreter/test Message-ID: <20070611185709.4E35C8152@code0.codespeak.net> Author: cfbolz Date: Mon Jun 11 20:57:08 2007 New Revision: 44157 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/allsolution.py pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/arithmeticbuiltin.py pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/atomconstruction.py pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/database.py pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/exception.py pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/parseraccess.py pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/termconstruction.py pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/unify.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/helper.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interactive.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_arithmetic.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_jit.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_parsing.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/translatedmain.py Log: rename "heap" to "trail", which is a way better description now. Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/allsolution.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/allsolution.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/allsolution.py Mon Jun 11 20:57:08 2007 @@ -11,22 +11,22 @@ self.template = template def _call(self, engine): - clone = self.template.getvalue(engine.heap) + clone = self.template.getvalue(engine.trail) self.found.append(clone) raise error.UnificationFailed() def impl_findall(engine, template, goal, bag): - oldstate = engine.heap.branch() + oldstate = engine.trail.branch() collector = FindallContinuation(template) try: engine.call(goal, collector) except error.UnificationFailed: - engine.heap.revert(oldstate) + engine.trail.revert(oldstate) result = term.Atom.newatom("[]") for i in range(len(collector.found) - 1, -1, -1): copy = collector.found[i] d = {} - copy = copy.copy(engine.heap, d) + copy = copy.copy(engine.trail, d) result = term.Term(".", [copy, result]) - bag.unify(result, engine.heap) + bag.unify(result, engine.trail) expose_builtin(impl_findall, "findall", unwrap_spec=['raw', 'callable', 'raw']) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/arithmeticbuiltin.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/arithmeticbuiltin.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/arithmeticbuiltin.py Mon Jun 11 20:57:08 2007 @@ -9,13 +9,13 @@ def impl_between(engine, lower, upper, varorint, continuation): if isinstance(varorint, term.Var): for i in range(lower, upper): - oldstate = engine.heap.branch() + oldstate = engine.trail.branch() try: - varorint.unify(term.Number(i), engine.heap) + varorint.unify(term.Number(i), engine.trail) return continuation.call(engine, choice_point=True) except error.UnificationFailed: - engine.heap.revert(oldstate) - varorint.unify(term.Number(upper), engine.heap) + engine.trail.revert(oldstate) + varorint.unify(term.Number(upper), engine.trail) return continuation.call(engine, choice_point=False) else: integer = helper.unwrap_int(varorint) @@ -26,7 +26,7 @@ handles_continuation=True) def impl_is(engine, var, num): - var.unify(num, engine.heap) + var.unify(num, engine.trail) impl_is._look_inside_me_ = True expose_builtin(impl_is, "is", unwrap_spec=["raw", "arithmetic"]) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/atomconstruction.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/atomconstruction.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/atomconstruction.py Mon Jun 11 20:57:08 2007 @@ -11,13 +11,13 @@ # nondeterministic splitting of result r = helper.convert_to_str(result) for i in range(len(r) + 1): - oldstate = engine.heap.branch() + oldstate = engine.trail.branch() try: - a1.unify(term.Atom(r[:i]), engine.heap) - a2.unify(term.Atom(r[i:]), engine.heap) + a1.unify(term.Atom(r[:i]), engine.trail) + a2.unify(term.Atom(r[i:]), engine.trail) return continuation.call(engine, choice_point=True) except error.UnificationFailed: - engine.heap.revert(oldstate) + engine.trail.revert(oldstate) raise error.UnificationFailed() else: s2 = helper.convert_to_str(a2) @@ -25,7 +25,7 @@ if r.endswith(s2): stop = len(r) - len(s2) assert stop > 0 - a1.unify(term.Atom(r[:stop]), engine.heap) + a1.unify(term.Atom(r[:stop]), engine.trail) else: raise error.UnificationFailed() else: @@ -33,12 +33,12 @@ if isinstance(a2, term.Var): r = helper.convert_to_str(result) if r.startswith(s1): - a2.unify(term.Atom(r[len(s1):]), engine.heap) + a2.unify(term.Atom(r[len(s1):]), engine.trail) else: raise error.UnificationFailed() else: s2 = helper.convert_to_str(a2) - result.unify(term.Atom(s1 + s2), engine.heap) + result.unify(term.Atom(s1 + s2), engine.trail) return continuation.call(engine, choice_point=False) expose_builtin(impl_atom_concat, "atom_concat", unwrap_spec=["obj", "obj", "obj"], @@ -47,7 +47,7 @@ def impl_atom_length(engine, s, length): if not (isinstance(length, term.Var) or isinstance(length, term.Number)): error.throw_type_error("integer", length) - term.Number(len(s)).unify(length, engine.heap) + term.Number(len(s)).unify(length, engine.trail) expose_builtin(impl_atom_length, "atom_length", unwrap_spec = ["atom", "obj"]) def impl_sub_atom(engine, s, before, length, after, sub, continuation): @@ -70,7 +70,7 @@ if startbefore < 0: startbefore = 0 stopbefore = len(s) + 1 - oldstate = engine.heap.branch() + oldstate = engine.trail.branch() if not isinstance(sub, term.Var): s1 = helper.unwrap_atom(sub) if len(s1) >= stoplength or len(s1) < startlength: @@ -83,12 +83,12 @@ if b < 0: break start = b + 1 - before.unify(term.Number(b), engine.heap) - after.unify(term.Number(len(s) - len(s1) - b), engine.heap) - length.unify(term.Number(len(s1)), engine.heap) + before.unify(term.Number(b), engine.trail) + after.unify(term.Number(len(s) - len(s1) - b), engine.trail) + length.unify(term.Number(len(s1)), engine.trail) return continuation.call(engine, choice_point=True) except: - engine.heap.revert(oldstate) + engine.trail.revert(oldstate) raise except error.UnificationFailed: pass @@ -100,13 +100,13 @@ continue try: try: - before.unify(term.Number(b), engine.heap) - after.unify(term.Number(len(s) - l - b), engine.heap) - length.unify(term.Number(l), engine.heap) - sub.unify(term.Atom(s[b:b + l]), engine.heap) + before.unify(term.Number(b), engine.trail) + after.unify(term.Number(len(s) - l - b), engine.trail) + length.unify(term.Number(l), engine.trail) + sub.unify(term.Atom(s[b:b + l]), engine.trail) return continuation.call(engine, choice_point=True) except: - engine.heap.revert(oldstate) + engine.trail.revert(oldstate) raise except error.UnificationFailed: pass @@ -119,14 +119,14 @@ continue try: try: - before.unify(term.Number(b), engine.heap) - after.unify(term.Number(a), engine.heap) - length.unify(term.Number(l), engine.heap) - sub.unify(term.Atom(s[b:b + l]), engine.heap) + before.unify(term.Number(b), engine.trail) + after.unify(term.Number(a), engine.trail) + length.unify(term.Number(l), engine.trail) + sub.unify(term.Atom(s[b:b + l]), engine.trail) return continuation.call(engine, choice_point=True) return None except: - engine.heap.revert(oldstate) + engine.trail.revert(oldstate) raise except error.UnificationFailed: pass Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py Mon Jun 11 20:57:08 2007 @@ -33,7 +33,7 @@ self.continuation = continuation def _call(self, engine): - next_call = self.next_call.dereference(engine.heap) + next_call = self.next_call.dereference(engine.trail) next_call = helper.ensure_callable(next_call) return engine.call(next_call, self.continuation, choice_point=False) @@ -46,11 +46,11 @@ handles_continuation=True) def impl_or(engine, call1, call2, continuation): - oldstate = engine.heap.branch() + oldstate = engine.trail.branch() try: return engine.call(call1, continuation) except error.UnificationFailed: - engine.heap.revert(oldstate) + engine.trail.revert(oldstate) return engine.call(call2, continuation, choice_point=False) expose_builtin(impl_or, ";", unwrap_spec=["callable", "callable"], @@ -68,11 +68,11 @@ expose_builtin(impl_not, ["not", "\\+"], unwrap_spec=["callable"]) def impl_if(engine, if_clause, then_clause, continuation): - oldstate = engine.heap.branch() + oldstate = engine.trail.branch() try: engine.call(if_clause) except error.UnificationFailed: - engine.heap.revert(oldstate) + engine.trail.revert(oldstate) raise return engine.call(helper.ensure_callable(then_clause), continuation, choice_point=False) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/database.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/database.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/database.py Mon Jun 11 20:57:08 2007 @@ -19,11 +19,11 @@ expose_builtin(impl_abolish, "abolish", unwrap_spec=["obj"]) def impl_assert(engine, rule): - engine.add_rule(rule.getvalue(engine.heap)) + engine.add_rule(rule.getvalue(engine.trail)) expose_builtin(impl_assert, ["assert", "assertz"], unwrap_spec=["callable"]) def impl_asserta(engine, rule): - engine.add_rule(rule.getvalue(engine.heap), end=False) + engine.add_rule(rule.getvalue(engine.trail), end=False) expose_builtin(impl_asserta, "asserta", unwrap_spec=["callable"]) @@ -46,16 +46,16 @@ rulechain = function.rulechain while rulechain: rule = rulechain.rule - oldstate = engine.heap.branch() + oldstate = engine.trail.branch() try: memo = {} - rulehead = rule.head.copy(engine.heap, memo) - rulehead.unify(head, engine.heap) + rulehead = rule.head.copy(engine.trail, memo) + rulehead.unify(head, engine.trail) if body is not None: - rulebody = rule.body.copy(engine.heap, memo) - rulebody.unify(body, engine.heap) + rulebody = rule.body.copy(engine.trail, memo) + rulebody.unify(body, engine.trail) except error.UnificationFailed: - engine.heap.revert(oldstate) + engine.trail.revert(oldstate) else: if function.rulechain is rulechain: if rulechain.next is None: Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/exception.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/exception.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/exception.py Mon Jun 11 20:57:08 2007 @@ -8,23 +8,23 @@ def impl_catch(engine, goal, catcher, recover, continuation): catching_continuation = enginemod.LimitedScopeContinuation(continuation) - old_state = engine.heap.branch() + old_state = engine.trail.branch() try: return engine.call(goal, catching_continuation) except error.CatchableError, e: if not catching_continuation.scope_active: raise - exc_term = e.term.getvalue(engine.heap) - engine.heap.revert(old_state) + exc_term = e.term.getvalue(engine.trail) + engine.trail.revert(old_state) d = {} - exc_term = exc_term.copy(engine.heap, d) + exc_term = exc_term.copy(engine.trail, d) try: impl_ground(engine, exc_term) except error.UnificationFailed: raise error.UncatchableError( "not implemented: catching of non-ground terms") try: - catcher.unify(exc_term, engine.heap) + catcher.unify(exc_term, engine.trail) except error.UnificationFailed: if isinstance(e, error.UserError): raise error.UserError(exc_term) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/parseraccess.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/parseraccess.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/parseraccess.py Mon Jun 11 20:57:08 2007 @@ -9,14 +9,14 @@ for prec, allops in engine.getoperations(): for form, ops in allops: for op in ops: - oldstate = engine.heap.branch() + oldstate = engine.trail.branch() try: - precedence.unify(term.Number(prec), engine.heap) - typ.unify(term.Atom.newatom(form), engine.heap) - name.unify(term.Atom(op), engine.heap) + precedence.unify(term.Number(prec), engine.trail) + typ.unify(term.Atom.newatom(form), engine.trail) + name.unify(term.Atom(op), engine.trail) return continuation.call(engine, choice_point=True) except error.UnificationFailed: - engine.heap.revert(oldstate) + engine.trail.revert(oldstate) raise error.UnificationFailed() expose_builtin(impl_current_op, "current_op", unwrap_spec=["obj", "obj", "obj"], handles_continuation=True) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py Mon Jun 11 20:57:08 2007 @@ -44,10 +44,10 @@ varname = "var%s" % (i, ) subargs.append(varname) if spec in ("obj", "callable", "int", "atom", "arithmetic"): - code.append(" %s = %s.dereference(engine.heap)" % + code.append(" %s = %s.dereference(engine.trail)" % (varname, rawarg)) elif spec in ("concrete", "list"): - code.append(" %s = %s.getvalue(engine.heap)" % + code.append(" %s = %s.getvalue(engine.trail)" % (varname, rawarg)) if spec in ("int", "atom", "arithmetic", "list"): code.append( Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/termconstruction.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/termconstruction.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/termconstruction.py Mon Jun 11 20:57:08 2007 @@ -7,11 +7,11 @@ def impl_functor(engine, t, functor, arity): if helper.is_atomic(t): - functor.unify(t, engine.heap) - arity.unify(term.Number(0), engine.heap) + functor.unify(t, engine.trail) + arity.unify(term.Number(0), engine.trail) elif isinstance(t, term.Term): - functor.unify(term.Atom(t.name), engine.heap) - arity.unify(term.Number(len(t.args)), engine.heap) + functor.unify(term.Atom(t.name), engine.trail) + arity.unify(term.Number(len(t.args)), engine.trail) elif isinstance(t, term.Var): if isinstance(functor, term.Var): error.throw_instantiation_error() @@ -21,12 +21,12 @@ else: functor = helper.ensure_atomic(functor) if a == 0: - t.unify(helper.ensure_atomic(functor), engine.heap) + t.unify(helper.ensure_atomic(functor), engine.trail) else: name = helper.unwrap_atom(functor) t.unify( term.Term(name, [term.Var() for i in range(a)]), - engine.heap) + engine.trail) expose_builtin(impl_functor, "functor", unwrap_spec=["obj", "obj", "obj"]) def impl_arg(engine, first, second, third, continuation): @@ -39,13 +39,13 @@ if isinstance(first, term.Var): for i in range(len(second.args)): arg = second.args[i] - oldstate = engine.heap.branch() + oldstate = engine.trail.branch() try: - third.unify(arg, engine.heap) - first.unify(term.Number(i + 1), engine.heap) + third.unify(arg, engine.trail) + first.unify(term.Number(i + 1), engine.trail) return continuation.call(engine, choice_point=True) except error.UnificationFailed: - engine.heap.revert(oldstate) + engine.trail.revert(oldstate) raise error.UnificationFailed() elif isinstance(first, term.Number): num = first.num @@ -56,7 +56,7 @@ if num > len(second.args): raise error.UnificationFailed() arg = second.args[num - 1] - third.unify(arg, engine.heap) + third.unify(arg, engine.trail) else: error.throw_type_error("integer", first) return continuation.call(engine, choice_point=False) @@ -71,9 +71,9 @@ l = [first] u1 = helper.wrap_list(l) if not isinstance(second, term.Var): - u1.unify(second, engine.heap) + u1.unify(second, engine.trail) else: - u1.unify(second, engine.heap) + u1.unify(second, engine.trail) else: if isinstance(second, term.Var): error.throw_instantiation_error() @@ -82,13 +82,13 @@ head = l[0] if not isinstance(head, term.Atom): error.throw_type_error("atom", head) - term.Term(head.name, l[1:]).unify(first, engine.heap) + term.Term(head.name, l[1:]).unify(first, engine.trail) expose_builtin(impl_univ, "=..", unwrap_spec=["obj", "obj"]) def impl_copy_term(engine, interm, outterm): d = {} - copy = interm.copy(engine.heap, d) - outterm.unify(copy, engine.heap) + copy = interm.copy(engine.trail, d) + outterm.unify(copy, engine.trail) expose_builtin(impl_copy_term, "copy_term", unwrap_spec=["obj", "obj"]) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/unify.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/unify.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/unify.py Mon Jun 11 20:57:08 2007 @@ -8,21 +8,21 @@ # comparison and unification of terms def impl_unify(engine, obj1, obj2): - obj1.unify(obj2, engine.heap) + obj1.unify(obj2, engine.trail) expose_builtin(impl_unify, "=", unwrap_spec=["raw", "raw"]) def impl_unify_with_occurs_check(engine, obj1, obj2): - obj1.unify(obj2, engine.heap, occurs_check=True) + obj1.unify(obj2, engine.trail, occurs_check=True) expose_builtin(impl_unify_with_occurs_check, "unify_with_occurs_check", unwrap_spec=["raw", "raw"]) def impl_does_not_unify(engine, obj1, obj2): try: - branch = engine.heap.branch() + branch = engine.trail.branch() try: - obj1.unify(obj2, engine.heap) + obj1.unify(obj2, engine.trail) finally: - engine.heap.revert(branch) + engine.trail.revert(branch) except error.UnificationFailed: return raise error.UnificationFailed() @@ -37,7 +37,7 @@ ("ge", "@>=", "!= -1")]: exec py.code.Source(""" def impl_standard_comparison_%s(engine, obj1, obj2): - c = term.cmp_standard_order(obj1, obj2, engine.heap) + c = term.cmp_standard_order(obj1, obj2, engine.trail) if not c %s: raise error.UnificationFailed()""" % (ext, python)).compile() expose_builtin(globals()["impl_standard_comparison_%s" % (ext, )], prolog, Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py Mon Jun 11 20:57:08 2007 @@ -81,7 +81,7 @@ def compile_body(self, body): from pypy.lang.prolog.builtin import builtins_list, builtins_index - body = body.dereference(self.engine.heap) + body = body.dereference(self.engine.trail) if isinstance(body, Var): self.can_contain_cut = True self.compile_termbuilding(body) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py Mon Jun 11 20:57:08 2007 @@ -39,7 +39,7 @@ def __str__(self): return "TrailChunk(%s, %s)" % (self.last, self.trail) -class Heap(object): +class Trail(object): _virtualizable_ = True def __init__(self): self.current_chunk = TrailChunk() @@ -124,7 +124,7 @@ class Engine(object): def __init__(self): - self.heap = Heap() + self.trail = Trail() self.signature2function = {} self.parser = None self.operations = None Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/helper.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/helper.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/helper.py Mon Jun 11 20:57:08 2007 @@ -30,7 +30,7 @@ def is_ground(obj, engine): stack = [obj] while stack: - obj = stack.pop().dereference(engine.heap) + obj = stack.pop().dereference(engine.trail) if isinstance(obj, term.Var): return False if isinstance(obj, term.Term): Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interactive.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interactive.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interactive.py Mon Jun 11 20:57:08 2007 @@ -59,11 +59,11 @@ f = TermFormatter(engine, quoted=True, max_depth=10) vars = var_to_pos.items() vars.sort() - heap = engine.heap + trail = engine.trail for var, real_var in vars: if var.startswith("_"): continue - val = real_var.getvalue(heap) + val = real_var.getvalue(trail) write("%s = %s\n" % (var, f.format(val))) class PrologConsole(code.InteractiveConsole): Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Mon Jun 11 20:57:08 2007 @@ -52,11 +52,11 @@ class Frame(object): - def __init__(self, engine, code, localvarcache=None, heap=None): + def __init__(self, engine, code, localvarcache=None, trail=None): self.engine = engine - if heap is None: - heap = engine.heap - self.heap = heap + if trail is None: + trail = engine.trail + self.trail = trail self.code = code if localvarcache is None: localvarcache = [None] * code.maxlocalvar @@ -78,7 +78,7 @@ hint(i, concrete=True) arg = stack[startfrom + i] hint(arg.__class__, promote=True) - result[i].unify(arg, self.heap) + result[i].unify(arg, self.trail) i += 1 self.result = None @@ -101,12 +101,12 @@ return self._run(codeobject, head, pc, continuation) if not we_are_jitted(): assert codeobject is not None - return run_jit(self.localvarcache, self.engine, self.heap, + return run_jit(self.localvarcache, self.engine, self.trail, codeobject, head, pc, continuation) return self.opaque_run(codeobject, head, pc, continuation) def opaque_run(self, codeobject, head, pc, continuation): - return run_jit(self.localvarcache, self.engine, self.heap, + return run_jit(self.localvarcache, self.engine, self.trail, codeobject, head, pc, continuation) opaque_run._look_inside_me = False @@ -195,7 +195,7 @@ def ACTIVATE_LOCAL(self, stack, number): var = self.localvarcache[number] assert type(var) is LocalVar - self.localvarcache[number] = result = var.dereference(self.heap) + self.localvarcache[number] = result = var.dereference(self.trail) var.active = True def MAKETERM(self, stack, number): @@ -247,7 +247,7 @@ self.localvarcache[number] = None def UNIFY(self, stack): - stack.pop().unify(stack.pop(), self.heap) + stack.pop().unify(stack.pop(), self.trail) def user_call(self, function, args, continuation): rulechain = function.rulechain @@ -255,7 +255,7 @@ if rulechain is None: error.throw_existence_error( "procedure", function.prolog_signature) - oldstate = self.heap.branch() + oldstate = self.trail.branch() while rulechain is not None: rule = rulechain.rule choice_point = rulechain.next is not None @@ -267,7 +267,7 @@ result = frame.run_directly(continuation) return result except error.UnificationFailed: - self.heap.revert(oldstate) + self.trail.revert(oldstate) except error.CutException, e: if continuation.scope_active: return self.engine.continue_after_cut(e.continuation, @@ -279,12 +279,12 @@ result = frame.run_directly(continuation, choice_point) return result except error.UnificationFailed: - self.heap.revert(oldstate) + self.trail.revert(oldstate) if not choice_point: raise rulechain = rulechain.next -def run_jit(original_localvarcache, engine, heap, codeobject, +def run_jit(original_localvarcache, engine, trail, codeobject, head, pc, continuation): hint(None, global_merge_point=True) hint(codeobject, concrete=True) @@ -296,7 +296,7 @@ else: bytecode = codeobject.opcode pc = hint(pc, promote=True) - self = jit_enter_function(engine, heap, codeobject, original_localvarcache) + self = jit_enter_function(engine, trail, codeobject, original_localvarcache) original_self = self original_code = codeobject @@ -335,7 +335,7 @@ original_localvarcache) return continuation -def jit_enter_function(engine, heap, code, concrete_localvarcache): +def jit_enter_function(engine, trail, code, concrete_localvarcache): # complete funnyness localvarcache = [None] * code.maxlocalvar i = code.maxlocalvar @@ -348,7 +348,7 @@ localvarcache[i] = obj self = Frame(engine, code, localvarcache) self.localvarcache = localvarcache - self.heap = heap + self.trail = trail return self def jit_leave_function(code, localvarcache, original_localvarcache): Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py Mon Jun 11 20:57:08 2007 @@ -42,13 +42,13 @@ for cls in [term.Callable, term.Atom, term.Term]: self.seegraph(cls.get_prolog_signature) self.seegraph(PORTAL) - self.seegraph(engine.Heap.newvar) + self.seegraph(engine.Trail.newvar) self.seegraph(engine.TrailChunk.__init__) self.seegraph(interpreter.Rule.make_frame) self.seegraph(interpreter.jit_enter_function) self.seegraph(interpreter.jit_leave_function) for method in "branch revert newvar add_trail".split(): - self.seegraph(getattr(engine.Heap, method)) + self.seegraph(getattr(engine.Trail, method)) for method in ("unify_head run_directly run user_call " "dispatch_bytecode getcode " "__init__ _run").split(): Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py Mon Jun 11 20:57:08 2007 @@ -23,24 +23,24 @@ raise NotImplementedError("abstract base class") return self - def getvalue(self, heap): + def getvalue(self, trail): return self - def dereference(self, heap): + def dereference(self, trail): raise NotImplementedError("abstract base class") - def copy(self, heap, memo): + def copy(self, trail, memo): raise NotImplementedError("abstract base class") @specialize.arg(3) - def unify(self, other, heap, occurs_check=False): + def unify(self, other, trail, occurs_check=False): raise NotImplementedError("abstract base class") @specialize.arg(3) - def _unify(self, other, heap, occurs_check=False): + def _unify(self, other, trail, occurs_check=False): raise NotImplementedError("abstract base class") - def contains_var(self, var, heap): + def contains_var(self, var, trail): return False def __eq__(self, other): @@ -65,59 +65,59 @@ self.binding = None @specialize.arg(3) - def unify(self, other, heap, occurs_check=False): - return self.dereference(heap)._unify(other, heap, occurs_check) + def unify(self, other, trail, occurs_check=False): + return self.dereference(trail)._unify(other, trail, occurs_check) @specialize.arg(3) - def _unify(self, other, heap, occurs_check=False): - other = other.dereference(heap) + def _unify(self, other, trail, occurs_check=False): + other = other.dereference(trail) if isinstance(other, Var) and other is self: pass - elif occurs_check and other.contains_var(self, heap): + elif occurs_check and other.contains_var(self, trail): raise UnificationFailed() else: - self.setvalue(other, heap) + self.setvalue(other, trail) - def dereference(self, heap): + def dereference(self, trail): next = self.binding if next is None: return self if isinstance(next, Var): if _is_early_constant(next): - result = next.dereference(heap) + result = next.dereference(trail) else: - result = next.opaque_dereference(heap) - self.setvalue(result, heap) + result = next.opaque_dereference(trail) + self.setvalue(result, trail) return result return next - def opaque_dereference(self, heap): - return self.dereference(heap) + def opaque_dereference(self, trail): + return self.dereference(trail) - def getvalue(self, heap): - res = self.dereference(heap) + def getvalue(self, trail): + res = self.dereference(trail) if not isinstance(res, Var): - return res.getvalue(heap) + return res.getvalue(trail) return res - def setvalue(self, value, heap): + def setvalue(self, value, trail): if value is not self.binding: - heap.add_trail(self) + trail.add_trail(self) self.binding = value - def copy(self, heap, memo): + def copy(self, trail, memo): try: return memo[self] except KeyError: - newvar = memo[self] = heap.newvar() + newvar = memo[self] = trail.newvar() return newvar - def contains_var(self, var, heap): - self = self.dereference(heap) + def contains_var(self, var, trail): + self = self.dereference(trail) if self is var: return True if not isinstance(self, Var): - return self.contains_var(var, heap) + return self.contains_var(var, trail) return False def __repr__(self): @@ -129,7 +129,7 @@ return self is other def eval_arithmetic(self, engine): - self = self.dereference(engine.heap) + self = self.dereference(engine.trail) if isinstance(self, Var): error.throw_instantiation_error() return self.eval_arithmetic(engine) @@ -142,34 +142,34 @@ self.binding = None self.active = False - def setvalue(self, value, heap): + def setvalue(self, value, trail): if self.active: - heap.add_trail(self) + trail.add_trail(self) self.binding = value class NonVar(PrologObject): __slots__ = () - def dereference(self, heap): + def dereference(self, trail): return self @specialize.arg(3) - def unify(self, other, heap, occurs_check=False): - return self._unify(other, heap, occurs_check) + def unify(self, other, trail, occurs_check=False): + return self._unify(other, trail, occurs_check) @specialize.arg(3) - def basic_unify(self, other, heap, occurs_check=False): + def basic_unify(self, other, trail, occurs_check=False): raise NotImplementedError("abstract base class") @specialize.arg(3) - def _unify(self, other, heap, occurs_check=False): - other = other.dereference(heap) + def _unify(self, other, trail, occurs_check=False): + other = other.dereference(trail) if isinstance(other, Var): - other._unify(self, heap, occurs_check) + other._unify(self, trail, occurs_check) else: - self.basic_unify(other, heap, occurs_check) + self.basic_unify(other, trail, occurs_check) class Callable(NonVar): @@ -198,13 +198,13 @@ return "Atom(%r)" % (self.name,) @specialize.arg(3) - def basic_unify(self, other, heap, occurs_check=False): + def basic_unify(self, other, trail, occurs_check=False): if isinstance(other, Atom) and (self is other or other.name == self.name): return raise UnificationFailed - def copy(self, heap, memo): + def copy(self, trail, memo): return self def get_prolog_signature(self): @@ -235,12 +235,12 @@ self.num = num @specialize.arg(3) - def basic_unify(self, other, heap, occurs_check=False): + def basic_unify(self, other, trail, occurs_check=False): if isinstance(other, Number) and other.num == self.num: return raise UnificationFailed - def copy(self, heap, memo): + def copy(self, trail, memo): return self def __str__(self): @@ -261,13 +261,13 @@ self.floatval = floatval @specialize.arg(3) - def basic_unify(self, other, heap, occurs_check=False): + def basic_unify(self, other, trail, occurs_check=False): if isinstance(other, Float) and other.floatval == self.floatval: return raise UnificationFailed basic_unify._look_inside_me_ = False - def copy(self, heap, memo): + def copy(self, trail, memo): return self def __str__(self): @@ -291,19 +291,19 @@ pass @specialize.arg(3) - def basic_unify(self, other, heap, occurs_check=False): + def basic_unify(self, other, trail, occurs_check=False): if self is other: return raise UnificationFailed - def copy(self, heap, memo): + def copy(self, trail, memo): return self # helper functions for various Term methods -def _getvalue(obj, heap): - return obj.getvalue(heap) +def _getvalue(obj, trail): + return obj.getvalue(trail) class Term(Callable): STANDARD_ORDER = 3 @@ -323,28 +323,28 @@ return "%s(%s)" % (self.name, ", ".join([str(a) for a in self.args])) @specialize.arg(3) - def basic_unify(self, other, heap, occurs_check=False): + def basic_unify(self, other, trail, occurs_check=False): if (isinstance(other, Term) and self.name == other.name and len(self.args) == len(other.args)): i = 0 while i < len(self.args): - self.args[i].unify(other.args[i], heap, occurs_check) + self.args[i].unify(other.args[i], trail, occurs_check) i += 1 else: raise UnificationFailed - def copy(self, heap, memo): + def copy(self, trail, memo): newargs = [] i = 0 while i < len(self.args): - arg = self.args[i].copy(heap, memo) + arg = self.args[i].copy(trail, memo) newargs.append(arg) i += 1 return Term(self.name, newargs, self.signature) - def getvalue(self, heap): - return self._copy_term(_getvalue, heap) + def getvalue(self, trail): + return self._copy_term(_getvalue, trail) def _copy_term(self, copy_individual, *extraargs): args = [None] * len(self.args) @@ -363,9 +363,9 @@ def get_prolog_signature(self): return Term("/", [Atom.newatom(self.name), Number(len(self.args))]) - def contains_var(self, var, heap): + def contains_var(self, var, trail): for arg in self.args: - if arg.contains_var(var, heap): + if arg.contains_var(var, trail): return True return False @@ -393,7 +393,7 @@ return -1 return 1 -def cmp_standard_order(obj1, obj2, heap): +def cmp_standard_order(obj1, obj2, trail): c = rcmp(obj1.STANDARD_ORDER, obj2.STANDARD_ORDER) if c != 0: return c @@ -412,9 +412,9 @@ if c != 0: return c for i in range(len(obj1.args)): - a1 = obj1.args[i].dereference(heap) - a2 = obj2.args[i].dereference(heap) - c = cmp_standard_order(a1, a2, heap) + a1 = obj1.args[i].dereference(trail) + a2 = obj2.args[i].dereference(trail) + c = cmp_standard_order(a1, a2, trail) if c != 0: return c return 0 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_arithmetic.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_arithmetic.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_arithmetic.py Mon Jun 11 20:57:08 2007 @@ -2,7 +2,7 @@ from pypy.lang.prolog.interpreter.parsing import parse_file, TermBuilder from pypy.lang.prolog.interpreter.parsing import parse_query_term, get_engine from pypy.lang.prolog.interpreter.error import UnificationFailed, CutException -from pypy.lang.prolog.interpreter.engine import Heap, Engine +from pypy.lang.prolog.interpreter.engine import Trail, Engine from pypy.lang.prolog.interpreter import error from pypy.lang.prolog.interpreter.test.tool import collect_all, assert_false, assert_true Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py Mon Jun 11 20:57:08 2007 @@ -2,7 +2,7 @@ from pypy.lang.prolog.interpreter.parsing import parse_file, TermBuilder from pypy.lang.prolog.interpreter.parsing import parse_query_term, get_engine from pypy.lang.prolog.interpreter.error import UnificationFailed -from pypy.lang.prolog.interpreter.engine import Heap, Engine +from pypy.lang.prolog.interpreter.engine import Trail, Engine from pypy.lang.prolog.interpreter import error from pypy.lang.prolog.interpreter.test.tool import collect_all, assert_false, assert_true from pypy.lang.prolog.interpreter.test.tool import prolog_raises Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py Mon Jun 11 20:57:08 2007 @@ -12,7 +12,7 @@ """) t, vars = get_query_and_vars("f(X).") e.run(t) - assert vars['X'].dereference(e.heap).name == "a" + assert vars['X'].dereference(e.trail).name == "a" def test_and(): e = get_engine(""" @@ -24,7 +24,7 @@ e.run(parse_query_term("f(a, c).")) t, vars = get_query_and_vars("f(X, c).") e.run(t) - assert vars['X'].dereference(e.heap).name == "a" + assert vars['X'].dereference(e.trail).name == "a" def test_and_long(): e = get_engine(""" @@ -56,7 +56,7 @@ e.run(parse_query_term("num(succ(0)).")) t, vars = get_query_and_vars("num(X).") e.run(t) - assert vars['X'].dereference(e.heap).num == 0 + assert vars['X'].dereference(e.trail).num == 0 e.run(parse_query_term("add(0, 0, 0).")) py.test.raises(UnificationFailed, e.run, parse_query_term(""" add(0, 0, succ(0)).""")) @@ -93,7 +93,7 @@ """) t, vars = get_query_and_vars("f(a, b, Z).") e.run(t) - assert vars['Z'].dereference(e.heap).name == "a" + assert vars['Z'].dereference(e.trail).name == "a" f = collect_all(e, "X = 1; X = 2.") assert len(f) == 2 Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py Mon Jun 11 20:57:08 2007 @@ -8,7 +8,7 @@ r = Rule(head, body, e) query = get_query_and_vars("f(a).")[0] frame = r.make_frame(query.args) - assert frame.localvarcache[0].dereference(e.heap).name == "a" + assert frame.localvarcache[0].dereference(e.trail).name == "a" cont = object() c2 = frame.run(frame.code, False, 0, cont) assert cont is c2 @@ -18,7 +18,7 @@ cont = object() c2 = frame.run(frame.code, False, 0, cont) assert cont is c2 - assert vars['X'].dereference(e.heap).name == 'a' + assert vars['X'].dereference(e.trail).name == 'a' def test_build_term(): e = get_engine("") @@ -28,5 +28,5 @@ frame = Frame(e, r.code) frame.run(frame.code, True, 0, None) frame.run(frame.code, False, 0, None) - assert frame.result[0].dereference(e.heap).name == "a" - assert frame.result[1].dereference(e.heap).name == "b" + assert frame.result[0].dereference(e.trail).name == "a" + assert frame.result[1].dereference(e.trail).name == "b" Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_jit.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_jit.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_jit.py Mon Jun 11 20:57:08 2007 @@ -87,7 +87,7 @@ t, vars = get_query_and_vars("a([a, b, c], [d, f, g], X).") def main(n): - e.heap = engine.Heap() + e.heap = engine.Trail() if n == 0: e.call(t) @@ -144,7 +144,7 @@ num = term.Number(50) def main(n): - e.heap = engine.Heap() + e.heap = engine.Trail() if n == 0: e.call(term.Term("f", [num])) return True Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_parsing.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_parsing.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_parsing.py Mon Jun 11 20:57:08 2007 @@ -38,8 +38,8 @@ term, vars = get_query_and_vars( """add_numeral(succ(succ(null)), succ(succ(null)), X).""") e.run(term) - var = vars['X'].getvalue(e.heap) - var.unify(four, e.heap) + var = vars['X'].getvalue(e.trail) + var.unify(four, e.trail) term = parse_query_term( """greater_than(succ(succ(succ(null))), succ(succ(null))).""") e.run(term) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py Mon Jun 11 20:57:08 2007 @@ -1,7 +1,7 @@ import py from pypy.lang.prolog.interpreter.error import UnificationFailed from pypy.lang.prolog.interpreter.term import Atom, Var, Number, Term, BlackBox -from pypy.lang.prolog.interpreter.engine import Heap, Engine +from pypy.lang.prolog.interpreter.engine import Trail, Engine def test_atom(): a = Atom.newatom("hallo") @@ -12,45 +12,45 @@ def test_var(): b = Var() - heap = Heap() - b.unify(Atom.newatom("hallo"), heap) - assert b.getvalue(heap).name == "hallo" + trail = Trail() + b.unify(Atom.newatom("hallo"), trail) + assert b.getvalue(trail).name == "hallo" a = Var() b = Var() - a.unify(b, heap) - a.unify(Atom.newatom("hallo"), heap) - assert a.getvalue(heap).name == "hallo" - assert b.getvalue(heap).name == "hallo" + a.unify(b, trail) + a.unify(Atom.newatom("hallo"), trail) + assert a.getvalue(trail).name == "hallo" + assert b.getvalue(trail).name == "hallo" def test_unify_var(): b = Var() - heap = Heap() - b.unify(b, heap) - b.unify(Atom.newatom("hallo"), heap) - py.test.raises(UnificationFailed, b.unify, Atom.newatom("bye"), heap) + trail = Trail() + b.unify(b, trail) + b.unify(Atom.newatom("hallo"), trail) + py.test.raises(UnificationFailed, b.unify, Atom.newatom("bye"), trail) def test_recursive(): b = Var() - heap = Heap() - b.unify(Term("hallo", [b]), heap) + trail = Trail() + b.unify(Term("hallo", [b]), trail) def test_term(): X = Var() Y = Var() t1 = Term("f", [Atom.newatom("hallo"), X]) t2 = Term("f", [Y, Atom.newatom("HALLO")]) - heap = Heap() + trail = Trail() print t1, t2 - t1.unify(t2, heap) - assert X.getvalue(heap).name == "HALLO" - assert Y.getvalue(heap).name == "hallo" + t1.unify(t2, trail) + assert X.getvalue(trail).name == "HALLO" + assert Y.getvalue(trail).name == "hallo" def test_blackbox(): bl1 = BlackBox() bl2 = BlackBox() - heap = Heap() - bl1.unify(bl1, heap) - py.test.raises(UnificationFailed, bl1.unify, bl2, heap) + trail = Trail() + bl1.unify(bl1, trail) + py.test.raises(UnificationFailed, bl1.unify, bl2, trail) def test_run(): e = Engine() @@ -60,9 +60,9 @@ e.add_rule(Term("f", [X, X])) e.add_rule(Term(":-", [Term("f", [X, Y]), Term("f", [Y, X])])) - X = e.heap.newvar() + X = e.trail.newvar() e.run(Term("f", [Atom.newatom("b"), X])) - assert X.dereference(e.heap).name == "b" + assert X.dereference(e.trail).name == "b" e.run(Term("f", [Atom.newatom("b"), Atom.newatom("a")])) e.run(Term("f", [Atom.newatom("c"), Atom.newatom("c")])) Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py Mon Jun 11 20:57:08 2007 @@ -1,7 +1,7 @@ import py from pypy.lang.prolog.interpreter.error import UnificationFailed, FunctionNotFound from pypy.lang.prolog.interpreter.parsing import parse_query_term, get_engine -from pypy.lang.prolog.interpreter.engine import Continuation, Heap, Engine +from pypy.lang.prolog.interpreter.engine import Continuation, Trail, Engine def assert_true(query, e=None): if e is None: @@ -9,7 +9,7 @@ terms, vars = e.parse(query) term, = terms e.run(term) - return dict([(name, var.dereference(e.heap)) + return dict([(name, var.dereference(e.trail)) for name, var in vars.iteritems()]) def assert_false(query, e=None): if e is None: @@ -27,7 +27,7 @@ self.vars = vars def _call(self, engine): - self.heaps.append(dict([(name, var.dereference(engine.heap)) + self.heaps.append(dict([(name, var.dereference(engine.trail)) for name, var in self.vars.iteritems()])) print "restarting computation" raise UnificationFailed Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/translatedmain.py ============================================================================== --- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/translatedmain.py (original) +++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/translatedmain.py Mon Jun 11 20:57:08 2007 @@ -44,7 +44,7 @@ for var, real_var in var_to_pos.iteritems(): if var.startswith("_"): continue - val = f.format(real_var.getvalue(engine.heap)) + val = f.format(real_var.getvalue(engine.trail)) write("%s = %s\n" % (var, val)) def getch(): From santagada at codespeak.net Tue Jun 12 06:23:17 2007 From: santagada at codespeak.net (santagada at codespeak.net) Date: Tue, 12 Jun 2007 06:23:17 +0200 (CEST) Subject: [pypy-svn] r44158 - in pypy/dist/pypy/lang/js: . test Message-ID: <20070612042317.8AFA38142@code0.codespeak.net> Author: santagada Date: Tue Jun 12 06:23:16 2007 New Revision: 44158 Modified: pypy/dist/pypy/lang/js/interpreter.py pypy/dist/pypy/lang/js/jsobj.py pypy/dist/pypy/lang/js/operations.py pypy/dist/pypy/lang/js/test/test_interp.py Log: new implementation of array, and some more string methods. Modified: pypy/dist/pypy/lang/js/interpreter.py ============================================================================== --- pypy/dist/pypy/lang/js/interpreter.py (original) +++ pypy/dist/pypy/lang/js/interpreter.py Tue Jun 12 06:23:16 2007 @@ -81,6 +81,18 @@ return create_object(ctx, 'String', Value = Value) return create_object(ctx, 'String', Value = W_String('')) +class W_ArrayObject(W_NativeObject): + def Call(self, ctx, args=[], this=None): + proto = ctx.get_global().Get('Array').Get('prototype') + array = W_Array(ctx, Prototype=proto, Class = proto.Class) + for i in range(len(args)): + print "yeahh" + array.Put(str(i), args[0]) + return array + + def Construct(self, ctx, args=[]): + return self.Call(ctx, args) + TEST = False def evaljs(ctx, args, this): @@ -317,6 +329,46 @@ string += ''.join(others) return W_String(string) +class W_IndexOf(W_NewBuiltin): + def Call(self, ctx, args=[], this=None): + string = this.ToString(ctx) + if len(args) < 1: + return W_Number(-1.0) + substr = args[0].ToString(ctx) + size = len(string) + subsize = len(substr) + if len(args) < 2: + pos = 0 + else: + pos = args[1].ToInt32() + pos = min(max(pos, 0), size) + return W_Number(string.find(substr, pos)) + +class W_Substring(W_NewBuiltin): + def Call(self, ctx, args=[], this=None): + string = this.ToString(ctx) + size = len(string) + if len(args) < 1: + start = 0 + else: + start = args[0].ToInt32() + if len(args) < 2: + end = size + else: + end = args[1].ToInt32() + tmp1 = min(max(start, 0), size) + tmp2 = min(max(end, 0), size) + start = min(tmp1, tmp2) + end = max(tmp1, tmp2) + return W_String(string[start:end]) + +class W_ArrayToString(W_NewBuiltin): + def Call(self, ctx, args=[], this=None): + length = this.Get('length').ToUInt32() + sep = ',' + return W_String(sep.join([this.Get(str(index)).ToString(ctx) + for index in range(length)])) + class W_DateFake(W_NewBuiltin): # XXX This is temporary def Call(self, ctx, args=[], this=None): return create_object(ctx, 'Object') @@ -327,6 +379,10 @@ class Interpreter(object): """Creates a js interpreter""" def __init__(self): + def put_values(obj, dictvalues): + for key,value in dictvalues.iteritems(): + obj.Put(key, value) + w_Global = W_Object(Class="global") ctx = global_context(w_Global) @@ -348,31 +404,40 @@ w_Object.Put('length', W_Number(1), ro=True, dd=True) - w_ObjPrototype.Put('constructor', w_Object) - w_ObjPrototype.Put('__proto__', w_Null) toString = W_ToString(ctx) - w_ObjPrototype.Put('toString', toString) - w_ObjPrototype.Put('toLocaleString', toString) - w_ObjPrototype.Put('valueOf', W_ValueOf(ctx)) - w_ObjPrototype.Put('hasOwnProperty', W_HasOwnProperty(ctx)) - w_ObjPrototype.Put('isPrototypeOf', W_IsPrototypeOf(ctx)) - w_ObjPrototype.Put('propertyIsEnumerable', W_PropertyIsEnumerable(ctx)) + + put_values(w_ObjPrototype, { + 'constructor': w_Object, + '__proto__': w_Null, + 'toString': toString, + 'toLocaleString': toString, + 'valueOf': W_ValueOf(ctx), + 'hasOwnProperty': W_HasOwnProperty(ctx), + 'isPrototypeOf': W_IsPrototypeOf(ctx), + 'propertyIsEnumerable': W_PropertyIsEnumerable(ctx), + }) #properties of the function prototype - w_FncPrototype.Put('constructor', w_FncPrototype) - w_FncPrototype.Put('__proto__', w_ObjPrototype) - w_FncPrototype.Put('toString', W_FToString(ctx)) - w_FncPrototype.Put('apply', W_Apply(ctx)) - w_FncPrototype.Put('call', W_Call(ctx)) + put_values(w_FncPrototype, { + 'constructor': w_FncPrototype, + '__proto__': w_ObjPrototype, + 'toString': W_FToString(ctx), + 'apply': W_Apply(ctx), + 'call': W_Call(ctx), + }) w_Boolean = W_BooleanObject('Boolean', w_FncPrototype) w_Boolean.Put('constructor', w_FncPrototype) w_BoolPrototype = create_object(ctx, 'Object', Value=W_Boolean(False)) w_BoolPrototype.Class = 'Boolean' - w_BoolPrototype.Put('constructor', w_FncPrototype) - w_BoolPrototype.Put('toString', W_ValueToString(ctx)) - w_BoolPrototype.Put('valueOf', W_ValueValueOf(ctx)) + + put_values(w_BoolPrototype, { + 'constructor': w_FncPrototype, + '__proto__': w_BoolPrototype, + 'toString': W_ValueToString(ctx), + 'valueOf': W_ValueValueOf(ctx), + }) w_Boolean.Put('prototype', w_BoolPrototype) @@ -380,21 +445,61 @@ #Number w_Number = W_NumberObject('Number', w_FncPrototype) - w_Number.Put('constructor', w_FncPrototype) w_NumPrototype = create_object(ctx, 'Object', Value=W_Number(0.0)) w_NumPrototype.Class = 'Number' - w_NumPrototype.Put('constructor', w_FncPrototype) - w_NumPrototype.Put('toString', W_ValueToString(ctx)) - w_NumPrototype.Put('valueOf', W_ValueValueOf(ctx)) - - w_Number.Put('prototype', w_NumPrototype) - w_Number.Put('NaN', W_Number(NaN)) - w_Number.Put('POSITIVE_INFINITY', W_Number(Infinity)) - w_Number.Put('NEGATIVE_INFINITY', W_Number(-Infinity)) + put_values(w_NumPrototype, { + 'constructor': w_FncPrototype, + '__proto__': w_NumPrototype, + 'toString': W_ValueToString(ctx), + 'valueOf': W_ValueValueOf(ctx), + }) + + put_values(w_Number, { + 'constructor': w_FncPrototype, + 'prototype': w_NumPrototype, + 'NaN': W_Number(NaN), + 'POSITIVE_INFINITY': W_Number(Infinity), + 'NEGATIVE_INFINITY': W_Number(-Infinity), + }) w_Global.Put('Number', w_Number) + + #String + w_String = W_StringObject('String', w_FncPrototype) + + w_StrPrototype = create_object(ctx, 'Object', Value=W_String('')) + w_StrPrototype.Class = 'String' + + put_values(w_StrPrototype, { + 'constructor': w_FncPrototype, + '__proto__': w_StrPrototype, + 'toString': W_ValueToString(ctx), + 'valueOf': W_ValueValueOf(ctx), + 'charAt': W_CharAt(ctx), + 'concat': W_Concat(ctx), + 'indexOf': W_IndexOf(ctx), + 'substring': W_Substring(ctx), + }) + + w_String.Put('prototype', w_StrPrototype) + w_Global.Put('String', w_String) + + w_Array = W_ArrayObject('Array', w_FncPrototype) + + w_ArrPrototype = create_object(ctx, 'Object') + w_ArrPrototype.Class = 'Array' + + put_values(w_ArrPrototype, { + 'constructor': w_FncPrototype, + '__proto__': w_ArrPrototype, + 'toString': W_ArrayToString(ctx), + }) + + w_Array.Put('prototype', w_ArrPrototype) + w_Global.Put('Array', w_Array) + #Math w_math = W_Object(Class='Math') @@ -408,51 +513,12 @@ w_math.Put('E', W_Number(math.e)) w_math.Put('PI', W_Number(math.pi)) - w_Global.Put('String', W_Builtin(stringjs, Class='String')) - - w_Array = W_Builtin(arrayjs, Class='Array') - w_Array.Put('__proto__', w_ObjPrototype) - w_Array.Put('prototype', w_ObjPrototype, dd=True, de=True, ro=True) - - #Global Properties - w_Global.Put('Array', w_Array) w_Global.Put('version', W_Builtin(versionjs)) #Date w_Date = W_DateFake(ctx, Class='Date') w_Global.Put('Date', w_Date) - #Number - w_Number = W_NumberObject('Number', w_FncPrototype) - - w_NumPrototype = create_object(ctx, 'Object', Value=W_Number(0.0)) - w_NumPrototype.Class = 'Number' - w_NumPrototype.Put('constructor', w_FncPrototype) - w_NumPrototype.Put('toString', W_ValueToString(ctx)) - w_NumPrototype.Put('valueOf', W_ValueValueOf(ctx)) - - w_Number.Put('prototype', w_NumPrototype) - w_Number.Put('NaN', W_Number(NaN)) - w_Number.Put('POSITIVE_INFINITY', W_Number(Infinity)) - w_Number.Put('NEGATIVE_INFINITY', W_Number(-Infinity)) - - w_Global.Put('Number', w_Number) - - #String - w_String = W_StringObject('String', w_FncPrototype) - w_StrPrototype = create_object(ctx, 'Object', Value=W_String('')) - w_StrPrototype.Class = 'String' - w_StrPrototype.Put('constructor', w_FncPrototype) - w_StrPrototype.Put('toString', W_ValueToString(ctx)) - w_StrPrototype.Put('valueOf', W_ValueValueOf(ctx)) - w_StrPrototype.Put('charAt', W_CharAt(ctx)) - w_StrPrototype.Put('concat', W_Concat(ctx)) - - w_String.Put('prototype', w_StrPrototype) - - w_Global.Put('String', w_String) - - w_Global.Put('NaN', W_Number(NaN)) w_Global.Put('Infinity', W_Number(Infinity)) w_Global.Put('undefined', w_Undefined) Modified: pypy/dist/pypy/lang/js/jsobj.py ============================================================================== --- pypy/dist/pypy/lang/js/jsobj.py (original) +++ pypy/dist/pypy/lang/js/jsobj.py Tue Jun 12 06:23:16 2007 @@ -317,22 +317,14 @@ def __repr__(self): return str(self.propdict) - -def arraycallbi(ctx, args, this): - return W_Array() class W_Array(W_ListObject): def __init__(self, ctx=None, Prototype=None, Class='Array', Value=w_Undefined, callfunc=None): W_PrimitiveObject.__init__(self, ctx, Prototype, Class, Value, callfunc) - toString = W_Builtin(array_str_builtin) - self.Put('toString', toString, de=True) self.Put('length', W_Number(0)) self.length = r_uint(0) - def Construct(self, ctx, args=[]): - return self - def Put(self, P, V, dd=False, ro=False, de=False, it=False): @@ -364,14 +356,6 @@ self.length = index+1 self.propdict['length'].value = W_Number(index+1) return - - def ToString(self, ctx): - return ','.join([self.Get(str(index)).ToString(ctx) - for index in range(self.length)]) - -def array_str_builtin(ctx, args, this): - return W_String(this.ToString(ctx)) - class W_Boolean(W_Primitive): Modified: pypy/dist/pypy/lang/js/operations.py ============================================================================== --- pypy/dist/pypy/lang/js/operations.py (original) +++ pypy/dist/pypy/lang/js/operations.py Tue Jun 12 06:23:16 2007 @@ -109,7 +109,8 @@ class Array(ListOp): def eval(self, ctx): - array = W_Array() + proto = ctx.get_global().Get('Array').Get('prototype') + array = W_Array(ctx, Prototype=proto, Class = proto.Class) for i in range(len(self.nodes)): array.Put(str(i), self.nodes[i].eval(ctx).GetValue()) return array Modified: pypy/dist/pypy/lang/js/test/test_interp.py ============================================================================== --- pypy/dist/pypy/lang/js/test/test_interp.py (original) +++ pypy/dist/pypy/lang/js/test/test_interp.py Tue Jun 12 06:23:16 2007 @@ -164,7 +164,8 @@ assertp(""" x = []; print(x); - """, '') + print(x.length) + """, ['', '0']) def test_throw(): assertp("throw(3);", "uncaught exception: 3") From fijal at codespeak.net Tue Jun 12 19:07:08 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 12 Jun 2007 19:07:08 +0200 (CEST) Subject: [pypy-svn] r44184 - in pypy/dist/pypy/rpython/lltypesystem: . test Message-ID: <20070612170708.A04D38198@code0.codespeak.net> Author: fijal Date: Tue Jun 12 19:07:08 2007 New Revision: 44184 Removed: pypy/dist/pypy/rpython/lltypesystem/test/test_picklelltype.py Modified: pypy/dist/pypy/rpython/lltypesystem/lltype.py Log: Kill pickling of lltypes Modified: pypy/dist/pypy/rpython/lltypesystem/lltype.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/lltype.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/lltype.py Tue Jun 12 19:07:08 2007 @@ -5,7 +5,6 @@ from pypy.rlib.objectmodel import Symbolic from pypy.tool.uid import Hashable from pypy.tool.tls import tlsobject -from pypy.tool.picklesupport import getstate_with_slots, setstate_with_slots, pickleable_weakref from types import NoneType from sys import maxint import weakref @@ -139,9 +138,6 @@ def _is_varsize(self): return False - __getstate__ = getstate_with_slots - __setstate__ = setstate_with_slots - NFOUND = object() class ContainerType(LowLevelType): @@ -964,7 +960,7 @@ obj0 = pointing_to else: self._set_weak(True) - obj0 = pickleable_weakref(pointing_to) + obj0 = weakref.ref(pointing_to) self._set_solid(solid) self._set_obj0(obj0) @@ -1107,9 +1103,6 @@ return callb(*args) raise TypeError("%r instance is not a function" % (self._T,)) - __getstate__ = getstate_with_slots - __setstate__ = setstate_with_slots - def _cast_to(self, PTRTYPE): CURTYPE = self._TYPE down_or_up = castable(PTRTYPE, CURTYPE) @@ -1209,7 +1202,7 @@ self._dead = True def _setparentstructure(self, parent, parentindex): - self._wrparent = pickleable_weakref(parent) + self._wrparent = weakref.ref(parent) self._parent_type = typeOf(parent) self._parent_index = parentindex if (isinstance(self._parent_type, Struct) @@ -1234,9 +1227,6 @@ raise RuntimeError("accessing freed %r" % self._TYPE) self._parentstructure() - __getstate__ = getstate_with_slots - __setstate__ = setstate_with_slots - def _normalizedcontainer(self): # if we are the first inlined substructure of a structure, # return the whole (larger) structure instead @@ -1321,11 +1311,6 @@ def __str__(self): return 'struct %s { %s }' % (self._TYPE._name, self._str_fields()) - def __reduce__(self): - return _get_empty_instance_of_struct_variety, (self.__slots__, ), getstate_with_slots(self) - - __setstate__ = setstate_with_slots - def _getattr(self, field_name, uninitialized_ok=False): r = getattr(self, field_name) if isinstance(r, _uninitialized) and not uninitialized_ok: @@ -1577,19 +1562,6 @@ else: return id(self) - def __getstate__(self): - import pickle, types - __dict__ = self.__dict__.copy() - try: - pickle.dumps(self._callable) - except pickle.PicklingError: - __dict__['_callable'] = None - return __dict__ - - def __setstate__(self, __dict__): - import new - self.__dict__ = __dict__ - class _opaque(_parentable): def __init__(self, TYPE, parent=None, parentindex=None, **attrs): _parentable.__init__(self, TYPE) From fijal at codespeak.net Tue Jun 12 19:12:25 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 12 Jun 2007 19:12:25 +0200 (CEST) Subject: [pypy-svn] r44187 - pypy/dist/pypy/objspace/flow Message-ID: <20070612171225.5F49F8198@code0.codespeak.net> Author: fijal Date: Tue Jun 12 19:12:24 2007 New Revision: 44187 Modified: pypy/dist/pypy/objspace/flow/model.py Log: Kill picklesupport in flow objspace Modified: pypy/dist/pypy/objspace/flow/model.py ============================================================================== --- pypy/dist/pypy/objspace/flow/model.py (original) +++ pypy/dist/pypy/objspace/flow/model.py Tue Jun 12 19:12:24 2007 @@ -7,7 +7,6 @@ import py from pypy.tool.uid import uid, Hashable from pypy.tool.sourcetools import PY_IDENTIFIER, nice_repr_for_func -from pypy.tool.picklesupport import getstate_with_slots, setstate_with_slots """ memory size before and after introduction of __slots__ @@ -174,9 +173,6 @@ def __repr__(self): return "link from %s to %s" % (str(self.prevblock), str(self.target)) - __getstate__ = getstate_with_slots - __setstate__ = setstate_with_slots - def show(self): from pypy.translator.tool.graphpage import try_show try_show(self) @@ -254,9 +250,6 @@ exit.prevblock = self self.exits = exits - __getstate__ = getstate_with_slots - __setstate__ = setstate_with_slots - def show(self): from pypy.translator.tool.graphpage import try_show try_show(self) From fijal at codespeak.net Tue Jun 12 19:13:31 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 12 Jun 2007 19:13:31 +0200 (CEST) Subject: [pypy-svn] r44188 - in pypy/dist/pypy/tool: . test Message-ID: <20070612171331.F050E8198@code0.codespeak.net> Author: fijal Date: Tue Jun 12 19:13:31 2007 New Revision: 44188 Removed: pypy/dist/pypy/tool/picklesupport.py pypy/dist/pypy/tool/test/test_picklesupport.py Log: Kill picklesupport From arigo at codespeak.net Tue Jun 12 19:19:55 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 12 Jun 2007 19:19:55 +0200 (CEST) Subject: [pypy-svn] r44190 - in pypy/dist/pypy/module: __builtin__ _pickle_support Message-ID: <20070612171955.3779C8198@code0.codespeak.net> Author: arigo Date: Tue Jun 12 19:19:54 2007 New Revision: 44190 Modified: pypy/dist/pypy/module/__builtin__/__init__.py pypy/dist/pypy/module/__builtin__/app_functional.py pypy/dist/pypy/module/__builtin__/functional.py pypy/dist/pypy/module/_pickle_support/__init__.py pypy/dist/pypy/module/_pickle_support/maker.py Log: Move xrange to interp-level and comment out the app-level definition. Modified: pypy/dist/pypy/module/__builtin__/__init__.py ============================================================================== --- pypy/dist/pypy/module/__builtin__/__init__.py (original) +++ pypy/dist/pypy/module/__builtin__/__init__.py Tue Jun 12 19:19:54 2007 @@ -45,9 +45,6 @@ 'min' : 'app_functional.min', 'max' : 'app_functional.max', 'enumerate' : 'app_functional.enumerate', - 'xrange' : 'app_functional.xrange', - '_install_pickle_support_for_xrange_iterator': - 'app_functional._install_pickle_support_for_xrange_iterator', 'sorted' : 'app_functional.sorted', 'reversed' : 'app_functional.reversed', '_install_pickle_support_for_reversed_iterator': @@ -127,6 +124,7 @@ '__import__' : 'importing.importhook', 'range' : 'functional.range_int', + 'xrange' : 'functional.W_XRange', 'all' : 'functional.all', 'any' : 'functional.any', } Modified: pypy/dist/pypy/module/__builtin__/app_functional.py ============================================================================== --- pypy/dist/pypy/module/__builtin__/app_functional.py (original) +++ pypy/dist/pypy/module/__builtin__/app_functional.py Tue Jun 12 19:19:54 2007 @@ -276,104 +276,104 @@ # ____________________________________________________________ -def get_len_of_range(lo, hi, step): - n = 0 - if lo < hi: - diff = hi - lo - 1 - n = diff // step + 1 - return n +##def get_len_of_range(lo, hi, step): +## n = 0 +## if lo < hi: +## diff = hi - lo - 1 +## n = diff // step + 1 +## return n -class xrange(object): - """xrange([start,] stop[, step]) -> xrange object +##class xrange(object): +## """xrange([start,] stop[, step]) -> xrange object -Like range(), but instead of returning a list, returns an object that -generates the numbers in the range on demand. For looping, this is -more memory efficient.""" - - def __init__(self, start, stop=None, step=1): - if not isinstance(start, (int, long, float)): - raise TypeError('an integer is required') - start = int(start) - if stop is None: - stop = start - start = 0 - else: - if not isinstance(stop, (int, long, float)): - raise TypeError('an integer is required') - stop = int(stop) - if not isinstance(step, (int, long, float)): - raise TypeError('an integer is required') - step = int(step) - if step == 0: - raise ValueError, 'xrange() step-argument (arg 3) must not be zero' - if step > 0: - n = get_len_of_range(start, stop, step) - else: - n = get_len_of_range(stop, start, -step) - self.start = start - self.len = n - self.step = step - - def __str__(self): - stop = self.start + self.len * self.step - if self.start == 0 and self.step == 1: - s = "xrange(%d)" % (stop,) - elif self.step == 1: - s = "xrange(%d, %d)" % (self.start, stop) - else: - s = "xrange(%d, %d, %d)" %(self.start, stop, self.step) - return s - __repr__ = __str__ +##Like range(), but instead of returning a list, returns an object that +##generates the numbers in the range on demand. For looping, this is +##more memory efficient.""" + +## def __init__(self, start, stop=None, step=1): +## if not isinstance(start, (int, long, float)): +## raise TypeError('an integer is required') +## start = int(start) +## if stop is None: +## stop = start +## start = 0 +## else: +## if not isinstance(stop, (int, long, float)): +## raise TypeError('an integer is required') +## stop = int(stop) +## if not isinstance(step, (int, long, float)): +## raise TypeError('an integer is required') +## step = int(step) +## if step == 0: +## raise ValueError, 'xrange() step-argument (arg 3) must not be zero' +## if step > 0: +## n = get_len_of_range(start, stop, step) +## else: +## n = get_len_of_range(stop, start, -step) +## self.start = start +## self.len = n +## self.step = step + +## def __str__(self): +## stop = self.start + self.len * self.step +## if self.start == 0 and self.step == 1: +## s = "xrange(%d)" % (stop,) +## elif self.step == 1: +## s = "xrange(%d, %d)" % (self.start, stop) +## else: +## s = "xrange(%d, %d, %d)" %(self.start, stop, self.step) +## return s +## __repr__ = __str__ + +## def __len__(self): +## return self.len + +## def __getitem__(self, i): +## # xrange does NOT support slicing +## import operator +## i = operator.index(i) +## len = self.len +## if i < 0: +## i += len +## if 0 <= i < len: +## return self.start + i * self.step +## raise IndexError, "xrange object index out of range" + +## def __iter__(self): +## return xrange_iterator(self.start, self.len, self.step) + + +##class xrange_iterator(object): +## def __init__(self, current, remaining, step): +## self._current = current +## self._remaining = remaining +## self._step = step + +## def __iter__(self): +## return self + +## def next(self): +## if self._remaining > 0: +## item = self._current +## self._current = item + self._step +## self._remaining -= 1 +## return item +## raise StopIteration + +## def __len__(self): +## return self._remaining + +## def __reduce__(self): +## tup = (self._current, self._remaining, self._step) +## return (make_xrange_iterator, tup) - def __len__(self): - return self.len - - def __getitem__(self, i): - # xrange does NOT support slicing - import operator - i = operator.index(i) - len = self.len - if i < 0: - i += len - if 0 <= i < len: - return self.start + i * self.step - raise IndexError, "xrange object index out of range" - - def __iter__(self): - return xrange_iterator(self.start, self.len, self.step) - - -class xrange_iterator(object): - def __init__(self, current, remaining, step): - self._current = current - self._remaining = remaining - self._step = step - - def __iter__(self): - return self - - def next(self): - if self._remaining > 0: - item = self._current - self._current = item + self._step - self._remaining -= 1 - return item - raise StopIteration - - def __len__(self): - return self._remaining - - def __reduce__(self): - tup = (self._current, self._remaining, self._step) - return (make_xrange_iterator, tup) - -def make_xrange_iterator(*args): - return xrange_iterator(*args) +##def make_xrange_iterator(*args): +## return xrange_iterator(*args) -def _install_pickle_support_for_xrange_iterator(): - import _pickle_support - make_xrange_iterator.__module__ = '_pickle_support' - _pickle_support.make_xrange_iterator = make_xrange_iterator +##def _install_pickle_support_for_xrange_iterator(): +## import _pickle_support +## make_xrange_iterator.__module__ = '_pickle_support' +## _pickle_support.make_xrange_iterator = make_xrange_iterator # ____________________________________________________________ Modified: pypy/dist/pypy/module/__builtin__/functional.py ============================================================================== --- pypy/dist/pypy/module/__builtin__/functional.py (original) +++ pypy/dist/pypy/module/__builtin__/functional.py Tue Jun 12 19:19:54 2007 @@ -5,6 +5,9 @@ from pypy.interpreter.error import OperationError from pypy.interpreter.gateway import ObjSpace, W_Root, NoneNotWrapped, applevel +from pypy.interpreter.gateway import interp2app +from pypy.interpreter.typedef import TypeDef +from pypy.interpreter.baseobjspace import Wrappable from pypy.rlib.rarithmetic import r_uint, intmask from pypy.module.__builtin__.app_functional import range as app_range from inspect import getsource, getfile @@ -22,8 +25,8 @@ def get_len_of_range(lo, hi, step): """ - Return number of items in range/xrange (lo, hi, step). step > 0 - required. Return a value < 0 if & only if the true value is too + Return number of items in range/xrange (lo, hi, step). + Raise ValueError if step == 0 and OverflowError if the true value is too large to fit in a signed long. """ @@ -37,8 +40,6 @@ # for the RHS numerator is hi=M, lo=-M-1, and then # hi-lo-1 = M-(-M-1)-1 = 2*M. Therefore unsigned long has enough # precision to compute the RHS exactly. - - # slight modification: we raise on everything bad and also adjust args if step == 0: raise ValueError elif step < 0: @@ -135,3 +136,125 @@ return space.w_True return space.w_False any.unwrap_spec = [ObjSpace, W_Root] + + + +class W_XRange(Wrappable): + def __init__(self, space, start, len, step): + self.space = space + self.start = start + self.len = len + self.step = step + + def descr_new(space, w_subtype, w_start, w_stop=None, w_step=1): + start = _toint(space, w_start) + step = _toint(space, w_step) + if space.is_w(w_stop, space.w_None): # only 1 argument provided + start, stop = 0, start + else: + stop = _toint(space, w_stop) + try: + howmany = get_len_of_range(start, stop, step) + except ValueError: + raise OperationError(space.w_ValueError, + space.wrap("xrange() arg 3 must not be zero")) + except OverflowError: + raise OperationError(space.w_OverflowError, + space.wrap("xrange() result has " + "too many items")) + obj = space.allocate_instance(W_XRange, w_subtype) + W_XRange.__init__(obj, space, start, howmany, step) + return space.wrap(obj) + + def descr_repr(self): + stop = self.start + self.len * self.step + if self.start == 0 and self.step == 1: + s = "xrange(%d)" % (stop,) + elif self.step == 1: + s = "xrange(%d, %d)" % (self.start, stop) + else: + s = "xrange(%d, %d, %d)" %(self.start, stop, self.step) + return self.space.wrap(s) + + def descr_len(self): + return self.space.wrap(self.len) + + def descr_getitem(self, i): + # xrange does NOT support slicing + space = self.space + len = self.len + if i < 0: + i += len + if 0 <= i < len: + return space.wrap(self.start + i * self.step) + raise OperationError(space.w_IndexError, + space.wrap("xrange object index out of range")) + + def descr_iter(self): + return self.space.wrap(W_XRangeIterator(self.space, self.start, + self.len, self.step)) + + def descr_reversed(self): + lastitem = self.start + (self.len-1) * self.step + return self.space.wrap(W_XRangeIterator(self.space, lastitem, + self.len, -self.step)) + +def _toint(space, w_obj): + # trying to support float arguments, just because CPython still does + try: + return space.int_w(w_obj) + except OperationError, e: + if space.is_true(space.isinstance(w_obj, space.w_float)): + return space.int_w(space.int(w_obj)) + raise + +W_XRange.typedef = TypeDef("xrange", + __new__ = interp2app(W_XRange.descr_new.im_func), + __repr__ = interp2app(W_XRange.descr_repr), + __getitem__ = interp2app(W_XRange.descr_getitem, + unwrap_spec=['self', 'index']), + __iter__ = interp2app(W_XRange.descr_iter), + __len__ = interp2app(W_XRange.descr_len), + __reversed__ = interp2app(W_XRange.descr_reversed), +) + +class W_XRangeIterator(Wrappable): + def __init__(self, space, current, remaining, step): + self.space = space + self.current = current + self.remaining = remaining + self.step = step + + def descr_iter(self): + return self.space.wrap(self) + + def descr_next(self): + if self.remaining > 0: + item = self.current + self.current = item + self.step + self.remaining -= 1 + return self.space.wrap(item) + raise OperationError(self.space.w_StopIteration, self.space.w_None) + + def descr_len(self): + return self.space.wrap(self.remaining) + + def descr_reduce(self): + from pypy.interpreter.mixedmodule import MixedModule + from pypy.module._pickle_support import maker # helper fns + space = self.space + w_mod = space.getbuiltinmodule('_pickle_support') + mod = space.interp_w(MixedModule, w_mod) + new_inst = mod.get('xrangeiter_new') + w = space.wrap + nt = space.newtuple + + tup = [w(self.current), w(self.remaining), w(self.step)] + return nt([new_inst, nt(tup)]) + +W_XRangeIterator.typedef = TypeDef("rangeiterator", + __iter__ = interp2app(W_XRangeIterator.descr_iter), + __len__ = interp2app(W_XRangeIterator.descr_len), + next = interp2app(W_XRangeIterator.descr_next), + __reduce__ = interp2app(W_XRangeIterator.descr_reduce), +) Modified: pypy/dist/pypy/module/_pickle_support/__init__.py ============================================================================== --- pypy/dist/pypy/module/_pickle_support/__init__.py (original) +++ pypy/dist/pypy/module/_pickle_support/__init__.py Tue Jun 12 19:19:54 2007 @@ -19,4 +19,5 @@ 'frame_new' : 'maker.frame_new', 'traceback_new' : 'maker.traceback_new', 'generator_new' : 'maker.generator_new', + 'xrangeiter_new': 'maker.xrangeiter_new', } Modified: pypy/dist/pypy/module/_pickle_support/maker.py ============================================================================== --- pypy/dist/pypy/module/_pickle_support/maker.py (original) +++ pypy/dist/pypy/module/_pickle_support/maker.py Tue Jun 12 19:19:54 2007 @@ -80,6 +80,12 @@ return space.wrap(new_generator) generator_new.unwrap_spec = [ObjSpace, Arguments] +def xrangeiter_new(space, current, remaining, step): + from pypy.module.__builtin__.functional import W_XRangeIterator + new_iter = W_XRangeIterator(space, current, remaining, step) + return space.wrap(new_iter) +xrangeiter_new.unwrap_spec = [ObjSpace, int, int, int] + # ___________________________________________________________________ # Helper functions for internal use From arigo at codespeak.net Tue Jun 12 19:27:18 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 12 Jun 2007 19:27:18 +0200 (CEST) Subject: [pypy-svn] r44194 - pypy/dist/pypy/module/__builtin__ Message-ID: <20070612172718.624B88198@code0.codespeak.net> Author: arigo Date: Tue Jun 12 19:27:18 2007 New Revision: 44194 Modified: pypy/dist/pypy/module/__builtin__/app_functional.py Log: Kill old code instead of commenting it out. Modified: pypy/dist/pypy/module/__builtin__/app_functional.py ============================================================================== --- pypy/dist/pypy/module/__builtin__/app_functional.py (original) +++ pypy/dist/pypy/module/__builtin__/app_functional.py Tue Jun 12 19:27:18 2007 @@ -276,107 +276,6 @@ # ____________________________________________________________ -##def get_len_of_range(lo, hi, step): -## n = 0 -## if lo < hi: -## diff = hi - lo - 1 -## n = diff // step + 1 -## return n - -##class xrange(object): -## """xrange([start,] stop[, step]) -> xrange object - -##Like range(), but instead of returning a list, returns an object that -##generates the numbers in the range on demand. For looping, this is -##more memory efficient.""" - -## def __init__(self, start, stop=None, step=1): -## if not isinstance(start, (int, long, float)): -## raise TypeError('an integer is required') -## start = int(start) -## if stop is None: -## stop = start -## start = 0 -## else: -## if not isinstance(stop, (int, long, float)): -## raise TypeError('an integer is required') -## stop = int(stop) -## if not isinstance(step, (int, long, float)): -## raise TypeError('an integer is required') -## step = int(step) -## if step == 0: -## raise ValueError, 'xrange() step-argument (arg 3) must not be zero' -## if step > 0: -## n = get_len_of_range(start, stop, step) -## else: -## n = get_len_of_range(stop, start, -step) -## self.start = start -## self.len = n -## self.step = step - -## def __str__(self): -## stop = self.start + self.len * self.step -## if self.start == 0 and self.step == 1: -## s = "xrange(%d)" % (stop,) -## elif self.step == 1: -## s = "xrange(%d, %d)" % (self.start, stop) -## else: -## s = "xrange(%d, %d, %d)" %(self.start, stop, self.step) -## return s -## __repr__ = __str__ - -## def __len__(self): -## return self.len - -## def __getitem__(self, i): -## # xrange does NOT support slicing -## import operator -## i = operator.index(i) -## len = self.len -## if i < 0: -## i += len -## if 0 <= i < len: -## return self.start + i * self.step -## raise IndexError, "xrange object index out of range" - -## def __iter__(self): -## return xrange_iterator(self.start, self.len, self.step) - - -##class xrange_iterator(object): -## def __init__(self, current, remaining, step): -## self._current = current -## self._remaining = remaining -## self._step = step - -## def __iter__(self): -## return self - -## def next(self): -## if self._remaining > 0: -## item = self._current -## self._current = item + self._step -## self._remaining -= 1 -## return item -## raise StopIteration - -## def __len__(self): -## return self._remaining - -## def __reduce__(self): -## tup = (self._current, self._remaining, self._step) -## return (make_xrange_iterator, tup) - -##def make_xrange_iterator(*args): -## return xrange_iterator(*args) - -##def _install_pickle_support_for_xrange_iterator(): -## import _pickle_support -## make_xrange_iterator.__module__ = '_pickle_support' -## _pickle_support.make_xrange_iterator = make_xrange_iterator - -# ____________________________________________________________ - def sorted(lst, cmp=None, key=None, reverse=None): "sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list" sorted_lst = list(lst) From fijal at codespeak.net Tue Jun 12 21:24:53 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 12 Jun 2007 21:24:53 +0200 (CEST) Subject: [pypy-svn] r44204 - in pypy/branch/kill-ctypes/pypy/rpython/lltypesystem: . test Message-ID: <20070612192453.8960B8198@code0.codespeak.net> Author: fijal Date: Tue Jun 12 21:24:53 2007 New Revision: 44204 Modified: pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rffi.py Log: A simple test and minor fix Modified: pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py Tue Jun 12 21:24:53 2007 @@ -18,12 +18,13 @@ def lltype(self): return self.TP -def llexternal(name, args, result, sources=[], includes=[], libraries=[]): +def llexternal(name, args, result, _callable=None, sources=[], includes=[], libraries=[]): ext_type = lltype.FuncType(args, result) return lltype.functionptr(ext_type, name, external='C', sources=tuple(sources), includes=tuple(includes), - libraries=tuple(libraries)) + libraries=tuple(libraries), + _callable=_callable) def setup(): """ creates necessary c-level types Modified: pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rffi.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rffi.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rffi.py Tue Jun 12 21:24:53 2007 @@ -5,6 +5,7 @@ from pypy.rpython.lltypesystem.lltype import Signed, Ptr, Char, malloc from pypy.rpython.lltypesystem import lltype from pypy.tool.udir import udir +from pypy.rpython.test.test_llinterp import interpret def test_basic(): c_source = """ @@ -162,3 +163,13 @@ import errno assert gn() == errno.EBADF +def test_external_callable(): + """ Try to call some llexternal function with llinterp + """ + z = llexternal('z', [Signed], Signed, _callable=lambda x:x+1) + + def f(): + return z(2) + + res = interpret(f, []) + assert res == 3 From fijal at codespeak.net Tue Jun 12 23:19:41 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 12 Jun 2007 23:19:41 +0200 (CEST) Subject: [pypy-svn] r44208 - pypy/branch/kill-ctypes/pypy/rlib Message-ID: <20070612211941.5676B81AE@code0.codespeak.net> Author: fijal Date: Tue Jun 12 23:19:39 2007 New Revision: 44208 Added: pypy/branch/kill-ctypes/pypy/rlib/rtermios.py Log: Add low-level implementation of termios Added: pypy/branch/kill-ctypes/pypy/rlib/rtermios.py ============================================================================== --- (empty file) +++ pypy/branch/kill-ctypes/pypy/rlib/rtermios.py Tue Jun 12 23:19:39 2007 @@ -0,0 +1,32 @@ +# This are here only because it's always better safe than sorry. +# The issue is that from-time-to-time CPython's termios.tcgetattr +# returns list of mostly-strings of length one, but with few ints +# inside, so we make sure it works + +import termios +from termios import * + +def tcgetattr(fd): + # NOT_RPYTHON + lst = list(termios.tcgetattr(fd)) + cc = lst[-1] + next_cc = [] + for c in cc: + if isinstance(c, int): + next_cc.append(chr(c)) + else: + next_cc.append(c) + lst[-1] = next_cc + return tuple(lst) + +def tcsetattr(fd, when, mode): + # NOT_RPYTHON + # there are some bizarre requirements for that, stealing directly + # from cpython + mode_l = list(mode) + if mode_l[3] & termios.ICANON: + cc = mode_l[-1] + cc[termios.VMIN] = ord(cc[termios.VMIN]) + cc[termios.VTIME] = ord(cc[termios.VTIME]) + mode_l[-1] = cc + return termios.tcsetattr(fd, when, mode_l) From fijal at codespeak.net Tue Jun 12 23:20:28 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 12 Jun 2007 23:20:28 +0200 (CEST) Subject: [pypy-svn] r44209 - pypy/branch/kill-ctypes/pypy/rpython Message-ID: <20070612212028.80CB881B2@code0.codespeak.net> Author: fijal Date: Tue Jun 12 23:20:28 2007 New Revision: 44209 Modified: pypy/branch/kill-ctypes/pypy/rpython/llinterp.py Log: provide low-level implementation of flavored_malloc_varsize Modified: pypy/branch/kill-ctypes/pypy/rpython/llinterp.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/llinterp.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/llinterp.py Tue Jun 12 23:20:28 2007 @@ -642,10 +642,10 @@ return self.heap.malloc(obj, size, zero=True) def op_flavored_malloc_varsize(self, flavor, obj, size): - XXX # probably should be never seen, and if so, should - # be tested - assert isinstance(flavor, str) - return self.heap.malloc(obj, flavor=flavor) + # XXX should we keep info about all mallocs for later checks of + # frees? + assert flavor == 'raw' + return self.heap.malloc(obj, size, flavor=flavor) def op_flavored_malloc(self, flavor, obj): assert isinstance(flavor, str) From fijal at codespeak.net Tue Jun 12 23:21:28 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 12 Jun 2007 23:21:28 +0200 (CEST) Subject: [pypy-svn] r44210 - pypy/branch/kill-ctypes/pypy/rpython/test Message-ID: <20070612212128.09FE981B4@code0.codespeak.net> Author: fijal Date: Tue Jun 12 23:21:27 2007 New Revision: 44210 Modified: pypy/branch/kill-ctypes/pypy/rpython/test/test_rbuiltin.py Log: Fix text_rbuiltin - ootypesystem needs some improvements (skipped by now) Modified: pypy/branch/kill-ctypes/pypy/rpython/test/test_rbuiltin.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/test/test_rbuiltin.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/test/test_rbuiltin.py Tue Jun 12 23:21:27 2007 @@ -158,6 +158,7 @@ assert self.ll_to_string(res) == fn() def test_os_write(self): + self._skip_oo('os.open oo fake impl') tmpdir = str(udir.udir.join("os_write_test")) import os def wr_open(fname): @@ -172,6 +173,7 @@ assert hello == "hello world" def test_os_write_single_char(self): + self._skip_oo('os.open oo fake impl') tmpdir = str(udir.udir.join("os_write_test_char")) import os def wr_open(fname): @@ -186,6 +188,7 @@ assert hello == "x" def test_os_read(self): + self._skip_oo('os.open oo fake impl') import os tmpfile = str(udir.udir.join("os_read_test")) f = file(tmpfile, 'w') @@ -198,7 +201,8 @@ assert self.ll_to_string(res) == 'hello world' def test_os_dup(self): - py.test.skip("Cannot test it that way") + self._skip_oo('os.dup oo fake impl') + from pypy.rpython.module.ll_os import dup_lltypeimpl import os def fn(fd): return os.dup(fd) @@ -210,11 +214,13 @@ count = 0 for dir_call in enum_direct_calls(test_llinterp.typer.annotator.translator, fn): cfptr = dir_call.args[0] - assert self.get_callable(cfptr.value) == self.ll_os.Implementation.ll_os_dup.im_func + assert self.get_callable(cfptr.value) == dup_lltypeimpl count += 1 assert count == 1 def test_os_open(self): + self._skip_oo('os.open oo fake impl') + from pypy.rpython.module.ll_os import os_open_lltypeimpl tmpdir = str(udir.udir.join("os_open_test")) import os def wr_open(fname): @@ -226,7 +232,7 @@ count = 0 for dir_call in enum_direct_calls(test_llinterp.typer.annotator.translator, wr_open): cfptr = dir_call.args[0] - assert self.get_callable(cfptr.value) == self.ll_os.Implementation.ll_os_open.im_func + assert self.get_callable(cfptr.value) == os_open_lltypeimpl count += 1 assert count == 1 From fijal at codespeak.net Tue Jun 12 23:22:30 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 12 Jun 2007 23:22:30 +0200 (CEST) Subject: [pypy-svn] r44211 - in pypy/branch/kill-ctypes/pypy/rpython/module: . test Message-ID: <20070612212230.8D40B81B6@code0.codespeak.net> Author: fijal Date: Tue Jun 12 23:22:30 2007 New Revision: 44211 Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py pypy/branch/kill-ctypes/pypy/rpython/module/test/test_posix.py Log: Fix tests and provide some fake implementations. Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py Tue Jun 12 23:22:30 2007 @@ -56,7 +56,9 @@ name = '_dup' else: name = 'dup' -os_dup = rffi.llexternal(name, [lltype.Signed], lltype.Signed) + +os_dup = rffi.llexternal(name, [lltype.Signed], lltype.Signed, + _callable=os.dup) def dup_lltypeimpl(fd): newfd = os_dup(fd) @@ -110,8 +112,12 @@ register_external(ros.utime_tuple, [str, (int, int)], s_None, "ll_os.utime_tuple", llimpl=utime_tuple_lltypeimpl) +def fake_os_open(l_path, flags, mode): + path = rffi.charp2str(l_path) + return os.open(path, flags, mode) + os_open = rffi.llexternal('open', [rffi.CCHARP, lltype.Signed, rffi.MODE_T], - lltype.Signed) + lltype.Signed, _callable=fake_os_open) def os_open_lltypeimpl(path, flags, mode): l_path = rffi.str2charp(path) @@ -120,6 +126,7 @@ if result == -1: raise OSError(rffi.c_errno, "os_open failed") return result + register_external(os.open, [str, int, int], int, "ll_os.open", llimpl=os_open_lltypeimpl) Modified: pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py Tue Jun 12 23:22:30 2007 @@ -57,11 +57,12 @@ test_src = """ import os from pypy.tool.udir import udir -from pypy.rpython.lltypesystem.module.ll_os import Implementation as impl +#from pypy.rpython.module.ll_os import def test_environ(): count = 0 while 1: + l if not impl.ll_os_environ(count): break count += 1 @@ -71,6 +72,7 @@ def test_environ(): import py + py.test.skip("Test hangs, should be rewritten to new-style") gw = py.execnet.PopenGateway() chan = gw.remote_exec(py.code.Source(test_src)) res = chan.receive() Modified: pypy/branch/kill-ctypes/pypy/rpython/module/test/test_posix.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/module/test/test_posix.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/module/test/test_posix.py Tue Jun 12 23:22:30 2007 @@ -19,6 +19,7 @@ testfile.close() def test_open(self): + self._skip_oo('os.open oo fake impl') def f(): ff = posix.open(path,posix.O_RDONLY,0777) return ff From fijal at codespeak.net Tue Jun 12 23:22:40 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 12 Jun 2007 23:22:40 +0200 (CEST) Subject: [pypy-svn] r44212 - in pypy/branch/kill-ctypes/pypy/rpython/module: . test Message-ID: <20070612212240.A932B81B6@code0.codespeak.net> Author: fijal Date: Tue Jun 12 23:22:40 2007 New Revision: 44212 Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_termios.py Log: Improve rtermios Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py Tue Jun 12 23:22:40 2007 @@ -13,6 +13,7 @@ from pypy.rpython.extregistry import ExtRegistryEntry from pypy.annotation import model as annmodel from pypy.rpython import rclass +from pypy.rlib import rtermios # XXX is this portable? well.. not at all, ideally # I would like to have NCCS = CLaterConstant(NCCS) @@ -67,7 +68,7 @@ finally: lltype.free(c_struct, flavor='raw') -register_external(termios.tcgetattr, [int], (int, int, int, int, int, int, [str]), +register_external(rtermios.tcgetattr, [int], (int, int, int, int, int, int, [str]), llimpl=tcgetattr_llimpl, export_name='termios.tcgetattr') def tcsetattr_llimpl(fd, when, attributes): @@ -90,7 +91,7 @@ lltype.free(c_struct, flavor='raw') r_uint = rffi.r_uint -register_external(termios.tcsetattr, [int, int, (r_uint, r_uint, r_uint, +register_external(rtermios.tcsetattr, [int, int, (r_uint, r_uint, r_uint, r_uint, r_uint, r_uint, [str])], llimpl=tcsetattr_llimpl, export_name='termios.tcsetattr') Modified: pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_termios.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_termios.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_termios.py Tue Jun 12 23:22:40 2007 @@ -38,24 +38,25 @@ sys.path.insert(0, '%s') from pypy.translator.c.test.test_genc import compile import termios + from pypy.rlib import rtermios def runs_tcgetattr(): - tpl = list(termios.tcgetattr(2)[:-1]) + tpl = list(rtermios.tcgetattr(2)[:-1]) print tpl fn = compile(runs_tcgetattr, [], backendopt=False, ) print 'XXX' fn(expected_extra_mallocs=1) - print str(termios.tcgetattr(2)[:-1]) + print str(rtermios.tcgetattr(2)[:-1]) """ % os.path.dirname(pypydir)) f = udir.join("test_tcgetattr.py") f.write(source) child = self.spawn([str(f)]) child.expect("XXX") - child.expect('\[[^\]]*\]') - first = child.match.group(0) - child.expect('\[[^\]]*\]') - second = child.match.group(0) + child.expect('\[([^\]]*)\]') + first = child.match.group(1) + child.expect('\(([^\]]*)\)') + second = child.match.group(1) assert first == second def test_tcgetattr2(self): @@ -64,10 +65,11 @@ sys.path.insert(0, '%s') from pypy.translator.c.test.test_genc import compile from pypy.rpython.module import ll_termios + from pypy.rlib import rtermios import termios def runs_tcgetattr(): try: - termios.tcgetattr(338) + rtermios.tcgetattr(338) except termios.error, e: return 2 return 3 @@ -92,13 +94,14 @@ sys.path.insert(0, '%s') from pypy.translator.c.test.test_genc import compile from pypy.rpython.module import ll_termios + from pypy.rlib import rtermios import termios, time def runs_tcsetattr(): - tp = termios.tcgetattr(2) + tp = rtermios.tcgetattr(2) a, b, c, d, e, f, g = tp - termios.tcsetattr(2, termios.TCSANOW, (a, b, c, d, e, f, g)) + rtermios.tcsetattr(2, rtermios.TCSANOW, (a, b, c, d, e, f, g)) time.sleep(1) - tp = termios.tcgetattr(2) + tp = rtermios.tcgetattr(2) assert tp[5] == f fn = compile(runs_tcsetattr, [], backendopt=False) @@ -132,3 +135,26 @@ child = self.spawn([str(f)]) child.expect("OK!") + def test_tcsetattr_icanon(self): + source = py.code.Source(""" + import sys + sys.path.insert(0, '%s') + from pypy.rlib import rtermios + import termios + old_tcsetattr = termios.tcsetattr + def check(fd, when, attributes): + count = len([i for i in attributes[-1] if isinstance(i, int)]) + assert count == 2 + termios.tcsetattr = check + try: + attr = list(rtermios.tcgetattr(2)) + attr[3] |= termios.ICANON + rtermios.tcsetattr(2, termios.TCSANOW, attr) + finally: + termios.tcsetattr = old_tcsetattr + print 'OK!' + """ % os.path.dirname(pypydir)) + f = udir.join("test_tcsetattricanon.py") + f.write(source) + child = self.spawn([str(f)]) + child.expect("OK!") From fijal at codespeak.net Tue Jun 12 23:23:47 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 12 Jun 2007 23:23:47 +0200 (CEST) Subject: [pypy-svn] r44213 - in pypy/branch/kill-ctypes/pypy/module/termios: . test Message-ID: <20070612212347.7762281BA@code0.codespeak.net> Author: fijal Date: Tue Jun 12 23:23:47 2007 New Revision: 44213 Modified: pypy/branch/kill-ctypes/pypy/module/termios/interp_termios.py pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py Log: Fix the termios module Modified: pypy/branch/kill-ctypes/pypy/module/termios/interp_termios.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/termios/interp_termios.py (original) +++ pypy/branch/kill-ctypes/pypy/module/termios/interp_termios.py Tue Jun 12 23:23:47 2007 @@ -8,6 +8,7 @@ from pypy.rpython.module import ll_termios from pypy.rlib.objectmodel import we_are_translated import os +from pypy.rlib import rtermios import termios # proper semantics are to have termios.error, but since it's not documented @@ -33,16 +34,20 @@ space.wrap(0), space.wrap(-1), space.wrap(1))) w_iflag, w_oflag, w_cflag, w_lflag, w_ispeed, w_ospeed = \ space.unpackiterable(tup_w) - cc = [space.str_w(space.call_function(space.getattr(w_c, - space.wrap('__str__')))) for w_c in space.unpackiterable(w_cc)] + w_builtin = space.getbuiltinmodule('__builtin__') + cc = [] + for w_c in space.unpackiterable(w_cc): + if space.is_true(space.isinstance(w_c, space.w_int)): + ch = space.call_function(space.getattr(w_builtin, + space.wrap('chr')), w_c) + cc.append(space.str_w(ch)) + else: + cc.append(space.str_w(w_c)) tup = (space.int_w(w_iflag), space.int_w(w_oflag), space.int_w(w_cflag), space.int_w(w_lflag), space.int_w(w_ispeed), space.int_w(w_ospeed), cc) try: - if we_are_translated(): - termios.tcsetattr(fd, when, tup) - else: - termios.tcsetattr(fd, when, list(tup)) + rtermios.tcsetattr(fd, when, tup) except termios.error, e: e.errno = e.args[0] raise convert_error(space, e) @@ -55,14 +60,18 @@ def tcgetattr(space, fd): try: - tup = termios.tcgetattr(fd) + tup = rtermios.tcgetattr(fd) except termios.error, e: e.errno = e.args[0] raise convert_error(space, e) iflag, oflag, cflag, lflag, ispeed, ospeed, cc = tup l_w = [space.wrap(i) for i in [iflag, oflag, cflag, lflag, ispeed, ospeed]] # last one need to be chosen carefully - w_cc = space.newlist([space.wrap(i) for i in cc]) + cc_w = [space.wrap(i) for i in cc] + if lflag & termios.ICANON: + cc_w[termios.VMIN] = space.wrap(ord(cc[termios.VMIN])) + cc_w[termios.VTIME] = space.wrap(ord(cc[termios.VTIME])) + w_cc = space.newlist(cc_w) l_w.append(w_cc) return space.newlist(l_w) tcgetattr.unwrap_spec = [ObjSpace, int] Modified: pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py (original) +++ pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py Tue Jun 12 23:23:47 2007 @@ -84,6 +84,25 @@ child = self.spawn(['--withmod-termios', '--withmod-fcntl', str(f)]) child.expect('ok!') + def test_icanon(self): + source = py.code.Source(""" + import termios + import fcntl + import termios + f = termios.tcgetattr(2) + f[3] |= termios.ICANON + termios.tcsetattr(2, termios.TCSANOW, f) + f = termios.tcgetattr(2) + assert len([i for i in f[-1] if isinstance(i, int)]) == 2 + assert isinstance(f[-1][termios.VMIN], int) + assert isinstance(f[-1][termios.VTIME], int) + print 'ok!' + """) + f = udir.join("test_ioctl_termios.py") + f.write(source) + child = self.spawn(['--withmod-termios', '--withmod-fcntl', str(f)]) + child.expect('ok!') + class AppTestTermios(object): def setup_class(cls): cls.space = gettestobjspace(usemodules=['termios']) From fijal at codespeak.net Wed Jun 13 11:17:31 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Wed, 13 Jun 2007 11:17:31 +0200 (CEST) Subject: [pypy-svn] r44222 - in pypy/branch/kill-ctypes/pypy/rpython: module module/test test Message-ID: <20070613091731.9A30581D2@code0.codespeak.net> Author: fijal Date: Wed Jun 13 11:17:31 2007 New Revision: 44222 Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py pypy/branch/kill-ctypes/pypy/rpython/module/test/test_posix.py pypy/branch/kill-ctypes/pypy/rpython/test/test_rbuiltin.py Log: Fix test_rbuiltin, providing oofakeimpl Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py Wed Jun 13 11:17:31 2007 @@ -66,7 +66,7 @@ raise OSError(rffi.c_errno, "dup failed") return newfd register_external(os.dup, [int], int, llimpl=dup_lltypeimpl, - export_name="ll_os.ll_os_dup") + export_name="ll_os.ll_os_dup", oofakeimpl=os.dup) if os.name == 'nt': name = '_dup2' @@ -127,8 +127,11 @@ raise OSError(rffi.c_errno, "os_open failed") return result +def os_open_oofakeimpl(o_path, flags, mode): + return os.open(o_path._str, flags, mode) + register_external(os.open, [str, int, int], int, "ll_os.open", - llimpl=os_open_lltypeimpl) + llimpl=os_open_lltypeimpl, oofakeimpl=os_open_oofakeimpl) class BaseOS: __metaclass__ = ClassMethods Modified: pypy/branch/kill-ctypes/pypy/rpython/module/test/test_posix.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/module/test/test_posix.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/module/test/test_posix.py Wed Jun 13 11:17:31 2007 @@ -19,7 +19,6 @@ testfile.close() def test_open(self): - self._skip_oo('os.open oo fake impl') def f(): ff = posix.open(path,posix.O_RDONLY,0777) return ff Modified: pypy/branch/kill-ctypes/pypy/rpython/test/test_rbuiltin.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/test/test_rbuiltin.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/test/test_rbuiltin.py Wed Jun 13 11:17:31 2007 @@ -158,7 +158,6 @@ assert self.ll_to_string(res) == fn() def test_os_write(self): - self._skip_oo('os.open oo fake impl') tmpdir = str(udir.udir.join("os_write_test")) import os def wr_open(fname): @@ -173,7 +172,6 @@ assert hello == "hello world" def test_os_write_single_char(self): - self._skip_oo('os.open oo fake impl') tmpdir = str(udir.udir.join("os_write_test_char")) import os def wr_open(fname): @@ -188,7 +186,6 @@ assert hello == "x" def test_os_read(self): - self._skip_oo('os.open oo fake impl') import os tmpfile = str(udir.udir.join("os_read_test")) f = file(tmpfile, 'w') @@ -201,7 +198,6 @@ assert self.ll_to_string(res) == 'hello world' def test_os_dup(self): - self._skip_oo('os.dup oo fake impl') from pypy.rpython.module.ll_os import dup_lltypeimpl import os def fn(fd): @@ -214,13 +210,15 @@ count = 0 for dir_call in enum_direct_calls(test_llinterp.typer.annotator.translator, fn): cfptr = dir_call.args[0] - assert self.get_callable(cfptr.value) == dup_lltypeimpl + if self.type_system == 'lltype': + assert self.get_callable(cfptr.value) == dup_lltypeimpl + else: + assert self.get_callable(cfptr.value) == os.dup count += 1 assert count == 1 def test_os_open(self): - self._skip_oo('os.open oo fake impl') - from pypy.rpython.module.ll_os import os_open_lltypeimpl + from pypy.rpython.module.ll_os import os_open_lltypeimpl, os_open_oofakeimpl tmpdir = str(udir.udir.join("os_open_test")) import os def wr_open(fname): @@ -232,7 +230,10 @@ count = 0 for dir_call in enum_direct_calls(test_llinterp.typer.annotator.translator, wr_open): cfptr = dir_call.args[0] - assert self.get_callable(cfptr.value) == os_open_lltypeimpl + if self.type_system == 'lltype': + assert self.get_callable(cfptr.value) == os_open_lltypeimpl + else: + assert self.get_callable(cfptr.value) == os_open_oofakeimpl count += 1 assert count == 1 @@ -344,7 +345,7 @@ assert self.class_name(res) == 'B' def test_os_path_join(self): - self._skip_oo('os.path.join oofakeimpl') + self._skip_oo("os path oofakeimpl") import os.path def fn(a, b): return os.path.join(a, b) From fijal at codespeak.net Wed Jun 13 11:55:34 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Wed, 13 Jun 2007 11:55:34 +0200 (CEST) Subject: [pypy-svn] r44223 - pypy/branch/kill-ctypes/pypy/rpython Message-ID: <20070613095534.3A26D81D6@code0.codespeak.net> Author: fijal Date: Wed Jun 13 11:55:33 2007 New Revision: 44223 Modified: pypy/branch/kill-ctypes/pypy/rpython/rbuiltin.py Log: exception_cannot_occure() in free and raw_free Modified: pypy/branch/kill-ctypes/pypy/rpython/rbuiltin.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/rbuiltin.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/rbuiltin.py Wed Jun 13 11:55:33 2007 @@ -361,6 +361,7 @@ def rtype_free(hop, i_flavor): assert i_flavor == 1 + hop.exception_cannot_occur() vlist = hop.inputargs(hop.args_r[0], lltype.Void) vlist.reverse() # just for confusion hop.genop('flavored_free', vlist) @@ -566,6 +567,7 @@ def rtype_raw_free(hop): v_addr, = hop.inputargs(llmemory.Address) + hop.exception_cannot_occur() return hop.genop('raw_free', [v_addr]) def rtype_raw_memcopy(hop): From arigo at codespeak.net Wed Jun 13 11:58:58 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 13 Jun 2007 11:58:58 +0200 (CEST) Subject: [pypy-svn] r44224 - pypy/branch/graphserver-dist Message-ID: <20070613095858.2882481D8@code0.codespeak.net> Author: arigo Date: Wed Jun 13 11:58:57 2007 New Revision: 44224 Added: pypy/branch/graphserver-dist/ - copied from r44223, pypy/dist/ Log: A branch to try to integrate /svn/user/arigo/hack/pypy-hack/dotviewer/. From arigo at codespeak.net Wed Jun 13 12:04:13 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 13 Jun 2007 12:04:13 +0200 (CEST) Subject: [pypy-svn] r44225 - pypy/branch/graphserver-dist/pypy/translator/tool/pygame Message-ID: <20070613100413.B787B81DA@code0.codespeak.net> Author: arigo Date: Wed Jun 13 12:04:13 2007 New Revision: 44225 Removed: pypy/branch/graphserver-dist/pypy/translator/tool/pygame/ Log: Kill this. From arigo at codespeak.net Wed Jun 13 12:10:01 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 13 Jun 2007 12:10:01 +0200 (CEST) Subject: [pypy-svn] r44226 - pypy/branch/graphserver-dist/pypy/translator/tool Message-ID: <20070613101001.C710181DA@code0.codespeak.net> Author: arigo Date: Wed Jun 13 12:10:01 2007 New Revision: 44226 Added: pypy/branch/graphserver-dist/pypy/translator/tool/pygame.py (contents, props changed) Modified: pypy/branch/graphserver-dist/pypy/translator/tool/ (props changed) pypy/branch/graphserver-dist/pypy/translator/tool/graphpage.py Log: A quick svn:externals hack that seems to be enough for simple cases. Modified: pypy/branch/graphserver-dist/pypy/translator/tool/graphpage.py ============================================================================== --- pypy/branch/graphserver-dist/pypy/translator/tool/graphpage.py (original) +++ pypy/branch/graphserver-dist/pypy/translator/tool/graphpage.py Wed Jun 13 12:10:01 2007 @@ -7,34 +7,7 @@ from pypy.annotation.classdef import ClassDef from pypy.tool.uid import uid - -class GraphPage: - """Base class for the server-side content of one of the 'pages' - (one graph) sent over to and displayed by the client. - """ - def __init__(self, *args): - self.args = args - - def content(self): - """Compute the content of the page. - This doesn't modify the page in place; it returns a new GraphPage. - """ - if hasattr(self, 'source'): - return self - else: - new = self.__class__() - new.source = '' # '''dot source''' - new.links = {} # {'word': 'statusbar text'} - new.compute(*self.args) # defined in subclasses - return new - - def followlink(self, word): - raise KeyError - - def display(self): - "Display a graph page locally." - from pypy.translator.tool.pygame.graphclient import display_layout - display_layout(self) +from pypy.translator.tool.pygame.graphpage import GraphPage class VariableHistoryGraphPage(GraphPage): Added: pypy/branch/graphserver-dist/pypy/translator/tool/pygame.py ============================================================================== --- (empty file) +++ pypy/branch/graphserver-dist/pypy/translator/tool/pygame.py Wed Jun 13 12:10:01 2007 @@ -0,0 +1,7 @@ +"""XXX temporary integration hack""" + +import autopath, os + +# make pypy.translator.tool.pygame behave like a package whose content +# is in the dotviewer/ subdirectory +__path__ = [os.path.join(autopath.this_dir, 'dotviewer')] From fijal at codespeak.net Wed Jun 13 12:11:08 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Wed, 13 Jun 2007 12:11:08 +0200 (CEST) Subject: [pypy-svn] r44227 - in pypy/branch/kill-ctypes/pypy/module/_curses: . test Message-ID: <20070613101108.AB0AF81DA@code0.codespeak.net> Author: fijal Date: Wed Jun 13 12:11:08 2007 New Revision: 44227 Modified: pypy/branch/kill-ctypes/pypy/module/_curses/fficurses.py pypy/branch/kill-ctypes/pypy/module/_curses/test/test_curses.py Log: fix memory leakage + seems that tigetstr result is constant Modified: pypy/branch/kill-ctypes/pypy/module/_curses/fficurses.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/_curses/fficurses.py (original) +++ pypy/branch/kill-ctypes/pypy/module/_curses/fficurses.py Wed Jun 13 12:11:08 2007 @@ -73,8 +73,6 @@ if num == 0 or num == -1: raise interp_curses.TermError() res = rffi.charp2str(ll_res) - # XXX - how to avoid a problem with leaking stuff here??? - #lltype.free(ll_res, flavor='raw') return res finally: lltype.free(ll_cap, flavor='raw') @@ -92,9 +90,9 @@ ll_res = c_tparm(ll_s, l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9]) lltype.free(ll_s, flavor='raw') - # XXX - how to make this happy? - #lltype.free(ll_res, flavor.raw) - return rffi.charp2str(ll_res) + res = rffi.charp2str(ll_res) + lltype.free(ll_res, flavor='raw') + return res register_external(interp_curses._curses_tparm, [str, [int]], str, export_name='_curses.tparm', llimpl=tparm_llimpl) Modified: pypy/branch/kill-ctypes/pypy/module/_curses/test/test_curses.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/_curses/test/test_curses.py (original) +++ pypy/branch/kill-ctypes/pypy/module/_curses/test/test_curses.py Wed Jun 13 12:11:08 2007 @@ -85,5 +85,5 @@ assert res == '\033[6;4H' fn = compile(runs_tparm, []) - fn() + fn(expected_extra_mallocs=-1) From santagada at codespeak.net Wed Jun 13 12:40:56 2007 From: santagada at codespeak.net (santagada at codespeak.net) Date: Wed, 13 Jun 2007 12:40:56 +0200 (CEST) Subject: [pypy-svn] r44228 - pypy/dist/pypy/lang/js/test Message-ID: <20070613104056.8E02981E4@code0.codespeak.net> Author: santagada Date: Wed Jun 13 12:40:55 2007 New Revision: 44228 Modified: pypy/dist/pypy/lang/js/test/test_parser.py Log: remove a failing test Modified: pypy/dist/pypy/lang/js/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/js/test/test_parser.py (original) +++ pypy/dist/pypy/lang/js/test/test_parser.py Wed Jun 13 12:40:55 2007 @@ -309,8 +309,8 @@ assert w_num.ToNumber() == 6 w_num = self.eval_expr('((((6))))') assert w_num.ToNumber() == 6 - w_array = self.eval_expr('[1,2,3]') - assert w_array.ToString(self.ctx) == '1,2,3' + # w_array = self.eval_expr('[1,2,3]') + # assert w_array.ToString(self.ctx) == '1,2,3' w_identifier = self.eval_expr('x') py.test.raises(ThrowException, w_identifier.GetValue) w_object = self.eval_expr('{x:1}') From santagada at codespeak.net Wed Jun 13 12:46:26 2007 From: santagada at codespeak.net (santagada at codespeak.net) Date: Wed, 13 Jun 2007 12:46:26 +0200 (CEST) Subject: [pypy-svn] r44229 - pypy/dist/pypy/lang/js Message-ID: <20070613104626.A334681E4@code0.codespeak.net> Author: santagada Date: Wed Jun 13 12:46:26 2007 New Revision: 44229 Modified: pypy/dist/pypy/lang/js/js_interactive.py Log: a quick fix for a ToString problem... real tests comming Modified: pypy/dist/pypy/lang/js/js_interactive.py ============================================================================== --- pypy/dist/pypy/lang/js/js_interactive.py (original) +++ pypy/dist/pypy/lang/js/js_interactive.py Wed Jun 13 12:46:26 2007 @@ -162,9 +162,9 @@ self.reset() if (res is not None) and (res is not w_Undefined): try: - print res.GetValue().ToString() + print res.GetValue().ToString(self.interp.w_Global) except ThrowException, e: - print e.exception.ToString() + print e.exception.ToString(self.interp.w_Global) if __name__ == "__main__": import py From santagada at codespeak.net Wed Jun 13 17:46:24 2007 From: santagada at codespeak.net (santagada at codespeak.net) Date: Wed, 13 Jun 2007 17:46:24 +0200 (CEST) Subject: [pypy-svn] r44231 - in pypy/dist/pypy/lang/js: . test Message-ID: <20070613154624.7D52D81FE@code0.codespeak.net> Author: santagada Date: Wed Jun 13 17:46:22 2007 New Revision: 44231 Added: pypy/dist/pypy/lang/js/test/test_interactive.py Modified: pypy/dist/pypy/lang/js/js_interactive.py Log: fixed a bug when sending an empty line and made tests for printing results Modified: pypy/dist/pypy/lang/js/js_interactive.py ============================================================================== --- pypy/dist/pypy/lang/js/js_interactive.py (original) +++ pypy/dist/pypy/lang/js/js_interactive.py Wed Jun 13 17:46:22 2007 @@ -124,6 +124,9 @@ self.lines = [] self.level = 0 + def emptyline(self): + pass + def default(self, line): # let's count lines and continue till matching proper nr of { # XXX: '{' will count as well Added: pypy/dist/pypy/lang/js/test/test_interactive.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/lang/js/test/test_interactive.py Wed Jun 13 17:46:22 2007 @@ -0,0 +1,62 @@ +import py +import sys + +class TestInteraction: + """ + These tests require pexpect (UNIX-only). + http://pexpect.sourceforge.net/ + """ + + def _spawn(self, *args, **kwds): + try: + import pexpect + except ImportError, e: + py.test.skip(str(e)) + kwds.setdefault('timeout', 10) + print 'SPAWN:', args, kwds + child = pexpect.spawn(*args, **kwds) + child.logfile = sys.stdout + return child + + def spawn(self, argv): + return self._spawn('./js_interactive.py', argv) + + def prompt_send(self, message): + self.child.expect('js-pypy>') + self.child.sendline(message) + + def expect(self, message): + self.child.expect(message) + + def sendline(self, message): + self.child.sendline(message) + + def continue_send(self, message): + self.child.expect(' ... ') + self.child.sendline(message) + + def setup_method(cls, method): + cls.child = cls.spawn([]) + + def test_interactive(self): + child = self.child + #child.expect('JS ') # banner + self.prompt_send('x = "hello"') + self.expect('hello') + self.sendline('function f (x) {') + self.continue_send('return x;') + self.continue_send('') + self.continue_send('}') + self.prompt_send('f(100)') + self.expect('100') + self.prompt_send('this') + self.expect('[object Global]') + + def test_prints(self): + self.prompt_send('x=123') + self.expect('123') + self.prompt_send('x=[1,2,3]') + self.expect('1,2,3') + self.prompt_send('x={1:1}') + self.expect('[object Object]') + From gotcha at codespeak.net Thu Jun 14 00:06:05 2007 From: gotcha at codespeak.net (gotcha at codespeak.net) Date: Thu, 14 Jun 2007 00:06:05 +0200 (CEST) Subject: [pypy-svn] r44243 - in pypy/dist/pypy: bin rpython/rctypes/tool Message-ID: <20070613220605.2CB778215@code0.codespeak.net> Author: gotcha Date: Thu Jun 14 00:06:04 2007 New Revision: 44243 Modified: pypy/dist/pypy/bin/compilemodule.py pypy/dist/pypy/rpython/rctypes/tool/compilemodule.py Log: some options for extcompiler Modified: pypy/dist/pypy/bin/compilemodule.py ============================================================================== --- pypy/dist/pypy/bin/compilemodule.py (original) +++ pypy/dist/pypy/bin/compilemodule.py Thu Jun 14 00:06:04 2007 @@ -1,11 +1,4 @@ #! /usr/bin/env python -""" -Usage: compilemodule.py - -Compiles the PyPy extension module from pypy/module// -into a regular CPython extension module. -""" - import autopath, sys from pypy.rpython.rctypes.tool.compilemodule import main Modified: pypy/dist/pypy/rpython/rctypes/tool/compilemodule.py ============================================================================== --- pypy/dist/pypy/rpython/rctypes/tool/compilemodule.py (original) +++ pypy/dist/pypy/rpython/rctypes/tool/compilemodule.py Thu Jun 14 00:06:04 2007 @@ -7,6 +7,9 @@ """ import autopath import sys +import shutil +import os +from optparse import OptionParser from pypy.tool.error import debug @@ -27,6 +30,7 @@ w_moduledict = module.getdict() def __init__(mod): + print 'in' w_mod = CPyObjSpace.W_Object(mod) try: ## space.appexec([w_mod, w_moduledict], @@ -72,16 +76,42 @@ return driver.cbuilder.c_ext_module def main(argv): + usage = """usage: %prog [options] MODULENAME + +Compiles a PyPy extension module +into a regular CPython extension module. + +The module is a package with rpython interplevel code, +python applevel code, +and corresponding exports correctly declared.""" + parser = OptionParser(usage) + parser.add_option("-p", "--package", + dest="basepath", default="", + metavar="PACKAGE", + help="""package where the module to compile can be found, +default value is pypy/module""") + parser.add_option("-d", "--directory", dest="directory", default="", + help="directory where to copy the resulting module") + + (options, argv) = parser.parse_args() argvCount = len(argv) - if argvCount < 2 or argvCount > 4: - print >> sys.stderr, __doc__ - sys.exit(2) - elif len(argv) == 2: - c_ext_module = compilemodule(argv[1], interactive=True) - elif len(argv) == 3: - basepath = argv[2] - c_ext_module = compilemodule(argv[1], interactive=True, basepath=basepath) + if argvCount <> 1: + parser.error('MODULENAME is mandatory.') + if options.directory: + directory = options.directory + if not os.path.exists(directory): + parser.error('Target directory [%s] does not exist.' % directory) + elif not os.path.isdir(directory): + parser.error('Target [%s] is not a directory.' % directory) + + if not options.basepath: + c_ext_module = compilemodule(argv[0], interactive=True) + elif options.basepath: + c_ext_module = compilemodule(argv[0], interactive=True, basepath=options.basepath) print 'Created %r.' % (c_ext_module.__file__,) + if options.directory: + shutil.copy(c_ext_module.__file__, options.directory) + print 'Copied to %r.' % (directory,) if __name__ == '__main__': From arigo at codespeak.net Fri Jun 15 09:11:04 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 09:11:04 +0200 (CEST) Subject: [pypy-svn] r44260 - in pypy/branch/graphserver-dist: dotviewer dotviewer/test pypy/bin pypy/translator/tool Message-ID: <20070615071104.AC16C8240@code0.codespeak.net> Author: arigo Date: Fri Jun 15 09:11:03 2007 New Revision: 44260 Added: pypy/branch/graphserver-dist/dotviewer/ - copied from r44247, user/arigo/hack/pypy-hack/dotviewer/ pypy/branch/graphserver-dist/dotviewer/__init__.py (contents, props changed) Removed: pypy/branch/graphserver-dist/pypy/translator/tool/pygame.py Modified: pypy/branch/graphserver-dist/dotviewer/dotviewer.py pypy/branch/graphserver-dist/dotviewer/graphclient.py pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py pypy/branch/graphserver-dist/dotviewer/test/test_translator.py pypy/branch/graphserver-dist/pypy/bin/dotviewer.py pypy/branch/graphserver-dist/pypy/translator/tool/ (props changed) pypy/branch/graphserver-dist/pypy/translator/tool/graphpage.py Log: Move the dotviewer directory from my user dir to pypy/dist/. I'm putting it there for now because it's really a stand-alone tool, so people can checkout only the dotviewer/ directory. Added: pypy/branch/graphserver-dist/dotviewer/__init__.py ============================================================================== Modified: pypy/branch/graphserver-dist/dotviewer/dotviewer.py ============================================================================== --- user/arigo/hack/pypy-hack/dotviewer/dotviewer.py (original) +++ pypy/branch/graphserver-dist/dotviewer/dotviewer.py Fri Jun 15 09:11:03 2007 @@ -4,18 +4,35 @@ dotviewer.py filename.dot dotviewer.py filename.plain + dotviewer.py --server port In the first form, show the graph contained in a .dot file. In the second form, the graph was already compiled to a .plain file. +In the third form, listen for connexion on the given port and display +the graphs sent by the remote side. """ -import graphclient +import sys -if __name__ == '__main__': - import sys - args = sys.argv[1:] - if len(args) != 1: +def main(args = sys.argv[1:]): + import getopt + options, args = getopt.getopt(args, 's:h', ['server=', 'help']) + server_port = None + for option, value in options: + if option in ('-h', '--help'): + print >> sys.stderr, __doc__ + sys.exit(2) + if option in ('-s', '--server'): + server_port = int(value) + if not args and server_port is None: print >> sys.stderr, __doc__ sys.exit(2) + for filename in args: + import graphclient + graphclient.display_dot_file(filename) + if server_port is not None: + import graphserver + graphserver.listen_server(('', server_port)) - graphclient.display_dot_file(args[0]) +if __name__ == '__main__': + main() Modified: pypy/branch/graphserver-dist/dotviewer/graphclient.py ============================================================================== --- user/arigo/hack/pypy-hack/dotviewer/graphclient.py (original) +++ pypy/branch/graphserver-dist/dotviewer/graphclient.py Fri Jun 15 09:11:03 2007 @@ -8,6 +8,8 @@ def display_dot_file(dotfile, wait=True): """ Display the given dot file in a subprocess. """ + if not os.path.exists(dotfile): + raise IOError("No such file: %s" % (dotfile,)) import graphpage page = graphpage.DotFileGraphPage(str(dotfile)) display_page(page, wait=wait) Modified: pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py ============================================================================== --- user/arigo/hack/pypy-hack/dotviewer/test/test_interactive.py (original) +++ pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py Fri Jun 15 09:11:03 2007 @@ -1,6 +1,6 @@ import py import sys, os, signal, thread, time -from test.conftest import option +from dotviewer.test.conftest import option SOURCE1 = r'''digraph _generated__graph { subgraph _generated__ { @@ -40,7 +40,7 @@ udir = py.path.local.make_numbered_dir(prefix='usession-dot-', keep=3) udir.join('graph1.dot').write(SOURCE1) - import graphclient + from dotviewer import graphclient mod.pkgdir = py.path.local(graphclient.this_dir) mod.udir = udir @@ -105,7 +105,7 @@ def display1(filename, lock, errors): try: try: - from graphclient import display_dot_file + from dotviewer.graphclient import display_dot_file print "=== display_dot_file(%s) with GRAPHSERVER=%s" % ( filename, os.environ.get('GRAPHSERVER', ''),) display_dot_file(udir.join(filename)) Modified: pypy/branch/graphserver-dist/dotviewer/test/test_translator.py ============================================================================== --- user/arigo/hack/pypy-hack/dotviewer/test/test_translator.py (original) +++ pypy/branch/graphserver-dist/dotviewer/test/test_translator.py Fri Jun 15 09:11:03 2007 @@ -3,7 +3,7 @@ """ import py, sys -from test.conftest import option +from dotviewer.test.conftest import option def setup_module(mod): if not option.pygame: @@ -12,12 +12,6 @@ import pypy except ImportError: py.test.skip("cannot import pypy") - # to avoid confusion, prevent importing pypy.translator.tool.pygame - sys.modules['pypy.translator.tool.pygame'] = None - # patch GraphPage to redirect to this dotviewer - import graphclient - from pypy.translator.tool.graphpage import GraphPage - GraphPage.display = graphclient.display_page # ____________________________________________________________ Modified: pypy/branch/graphserver-dist/pypy/bin/dotviewer.py ============================================================================== --- pypy/branch/graphserver-dist/pypy/bin/dotviewer.py (original) +++ pypy/branch/graphserver-dist/pypy/bin/dotviewer.py Fri Jun 15 09:11:03 2007 @@ -1,48 +1,11 @@ #! /usr/bin/env python """ -Command-line interface for a dot file viewer -- either viewing normal .dot -files or connecting to a graph server like a browser. +Command-line interface for a dot file viewer. +Run with no arguments for help. """ import autopath -import sys, py -from pypy.translator.tool.pygame import graphclient - -from py.compat import optparse - -usage = ''' - %s filename.dot - %s filename.plain - %s hostname:port - %s :port - -In the first form, show the graph contained in a .dot file. -In the second form, the graph was already compiled to a .plain file. -In the other forms, connect to a graph server like -goal/translate.py. -''' % (sys.argv[0], sys.argv[0], sys.argv[0], sys.argv[0]) - -parser = optparse.OptionParser(usage=usage) -parser.add_option("--reload", action="store_true", dest="reload", - default=False, help="reload the dot file continously") - +from dotviewer.dotviewer import main if __name__ == '__main__': - options, args = parser.parse_args() - if len(args) != 1: - if args: - parser.error("too many arguments") - else: - parser.print_help() - sys.exit(2) - filename = args[0] - if py.path.local(filename).check(): - graphclient.display_dot_file(filename, - reload_repeatedly=options.reload) - elif filename.count(':') != 1: - print >> sys.stderr, 'No such file:', filename - sys.exit(1) - else: - hostname, port = args[0].split(':') - port = int(port) - graphclient.display_remote_layout(hostname, port) + main() Modified: pypy/branch/graphserver-dist/pypy/translator/tool/graphpage.py ============================================================================== --- pypy/branch/graphserver-dist/pypy/translator/tool/graphpage.py (original) +++ pypy/branch/graphserver-dist/pypy/translator/tool/graphpage.py Fri Jun 15 09:11:03 2007 @@ -7,7 +7,7 @@ from pypy.annotation.classdef import ClassDef from pypy.tool.uid import uid -from pypy.translator.tool.pygame.graphpage import GraphPage +from dotviewer.graphpage import GraphPage class VariableHistoryGraphPage(GraphPage): From arigo at codespeak.net Fri Jun 15 10:04:18 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 10:04:18 +0200 (CEST) Subject: [pypy-svn] r44262 - in pypy/branch/graphserver-dist/dotviewer: . test Message-ID: <20070615080418.524058246@code0.codespeak.net> Author: arigo Date: Fri Jun 15 10:04:10 2007 New Revision: 44262 Modified: pypy/branch/graphserver-dist/dotviewer/graphclient.py pypy/branch/graphserver-dist/dotviewer/graphdisplay.py pypy/branch/graphserver-dist/dotviewer/graphpage.py pypy/branch/graphserver-dist/dotviewer/graphparse.py pypy/branch/graphserver-dist/dotviewer/graphserver.py pypy/branch/graphserver-dist/dotviewer/msgstruct.py pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py Log: Safer error handling. Fix the display of colors. Modified: pypy/branch/graphserver-dist/dotviewer/graphclient.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/graphclient.py (original) +++ pypy/branch/graphserver-dist/dotviewer/graphclient.py Fri Jun 15 10:04:10 2007 @@ -63,6 +63,9 @@ reload(graph_id) except EOFError: pass + except Exception, e: + send_error(io, e) + raise io.close() def page_messages(page, graph_id): @@ -88,6 +91,17 @@ if ioerror is not None: raise ioerror +def send_error(io, e): + try: + errmsg = str(e) + if errmsg: + errmsg = '%s: %s' % (e.__class__.__name__, errmsg) + else: + errmsg = '%s' % (e.__class__.__name__,) + io.sendmsg(msgstruct.CMSG_SAY, errmsg) + except Exception: + pass + def spawn_handler(): gsvar = os.environ.get('GRAPHSERVER') if not gsvar: Modified: pypy/branch/graphserver-dist/dotviewer/graphdisplay.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/graphdisplay.py (original) +++ pypy/branch/graphserver-dist/dotviewer/graphdisplay.py Fri Jun 15 10:04:10 2007 @@ -650,10 +650,13 @@ self.quit() def process_UserEvent(self, event): # new layout request - if event.layout is None: - self.setstatusbar('cannot follow this link') - else: - self.setlayout(event.layout) + if hasattr(event, 'layout'): + if event.layout is None: + self.setstatusbar('cannot follow this link') + else: + self.setlayout(event.layout) + elif hasattr(event, 'say'): + self.setstatusbar(event.say) def quit(self): raise StopIteration Modified: pypy/branch/graphserver-dist/dotviewer/graphpage.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/graphpage.py (original) +++ pypy/branch/graphserver-dist/dotviewer/graphpage.py Fri Jun 15 10:04:10 2007 @@ -1,5 +1,5 @@ -class GraphPage: +class GraphPage(object): """Base class for the client-side content of one of the 'pages' (one graph) sent over to and displayed by the external process. """ @@ -27,6 +27,11 @@ import graphclient graphclient.display_page(self) + def display_background(self): + "Display a graph page in a background thread." + import graphclient, thread + thread.start_new_thread(graphclient.display_page, (self,)) + class DotFileGraphPage(GraphPage): def compute(self, dotfile): Modified: pypy/branch/graphserver-dist/dotviewer/graphparse.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/graphparse.py (original) +++ pypy/branch/graphserver-dist/dotviewer/graphparse.py Fri Jun 15 10:04:10 2007 @@ -101,7 +101,7 @@ color = None if color is not None: yield (msgstruct.CMSG_ADD_LINK, word, - statusbartext, color) + statusbartext, color[0], color[1], color[2]) else: yield (msgstruct.CMSG_ADD_LINK, word, statusbartext) seen[word] = True Modified: pypy/branch/graphserver-dist/dotviewer/graphserver.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/graphserver.py (original) +++ pypy/branch/graphserver-dist/dotviewer/graphserver.py Fri Jun 15 10:04:10 2007 @@ -82,6 +82,8 @@ def cmsg_add_link(self, word, *info): if len(info) == 1: info = info[0] + elif len(info) >= 4: + info = (info[0], info[1:4]) self.newlayout.links[word] = info def cmsg_stop_graph(self, *rest): @@ -92,6 +94,10 @@ def cmsg_missing_link(self, *rest): self.setlayout(None) + def cmsg_say(self, errmsg, *rest): + from drawgraph import display_async_cmd + display_async_cmd(say=errmsg) + MESSAGES = { msgstruct.CMSG_START_GRAPH: cmsg_start_graph, msgstruct.CMSG_ADD_NODE: cmsg_add_node, @@ -99,6 +105,7 @@ msgstruct.CMSG_ADD_LINK: cmsg_add_link, msgstruct.CMSG_STOP_GRAPH: cmsg_stop_graph, msgstruct.CMSG_MISSING_LINK:cmsg_missing_link, + msgstruct.CMSG_SAY: cmsg_say, } Modified: pypy/branch/graphserver-dist/dotviewer/msgstruct.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/msgstruct.py (original) +++ pypy/branch/graphserver-dist/dotviewer/msgstruct.py Fri Jun 15 10:04:10 2007 @@ -10,6 +10,7 @@ CMSG_ADD_LINK = 'l' CMSG_STOP_GRAPH = ']' CMSG_MISSING_LINK= 'm' +CMSG_SAY = 's' MSG_OK = 'O' MSG_ERROR = 'E' @@ -23,6 +24,7 @@ def message(tp, *values): + #print >> sys.stderr, tp, values typecodes = [''] for v in values: if type(v) is str: Modified: pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py (original) +++ pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py Fri Jun 15 10:04:10 2007 @@ -135,3 +135,15 @@ del os.environ['GRAPHSERVER'] finally: os.kill(pid, signal.SIGTERM) + +def test_colors(): + from dotviewer import graphpage, graphclient + class MyPage(graphpage.DotFileGraphPage): + def compute(self, dotfile): + super(MyPage, self).compute(dotfile) + self.links = {'v2721': 'Hello world', + 'v2720': ('Something green', (0, 192, 0)), + } + dotfile = udir.join('graph1.dot') + page = MyPage(str(dotfile)) + graphclient.display_page(page) From arigo at codespeak.net Fri Jun 15 10:07:18 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 10:07:18 +0200 (CEST) Subject: [pypy-svn] r44263 - in pypy/branch/graphserver-dist: dotviewer pypy/translator/goal pypy/translator/tool Message-ID: <20070615080718.AD0828246@code0.codespeak.net> Author: arigo Date: Fri Jun 15 10:07:18 2007 New Revision: 44263 Removed: pypy/branch/graphserver-dist/pypy/translator/tool/graphserver.py pypy/branch/graphserver-dist/pypy/translator/tool/port.py Modified: pypy/branch/graphserver-dist/dotviewer/graphparse.py pypy/branch/graphserver-dist/pypy/translator/goal/translate.py pypy/branch/graphserver-dist/pypy/translator/tool/pdbplus.py Log: Remove all the code that deals with running pygame in the correct thread. Modified: pypy/branch/graphserver-dist/dotviewer/graphparse.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/graphparse.py (original) +++ pypy/branch/graphserver-dist/dotviewer/graphparse.py Fri Jun 15 10:07:18 2007 @@ -19,7 +19,7 @@ cmdline = 'dot -Tplain' else: cmdline = 'neato -Tplain' - print >> sys.stderr, '* running:', cmdline + #print >> sys.stderr, '* running:', cmdline child_in, child_out = os.popen2(cmdline, 'r') thread.start_new_thread(bkgndwrite, (child_in, content)) plaincontent = child_out.read() Modified: pypy/branch/graphserver-dist/pypy/translator/goal/translate.py ============================================================================== --- pypy/branch/graphserver-dist/pypy/translator/goal/translate.py (original) +++ pypy/branch/graphserver-dist/pypy/translator/goal/translate.py Fri Jun 15 10:07:18 2007 @@ -44,9 +44,6 @@ return result translate_optiondescr = OptionDescription("translate", "XXX", [ - IntOption("graphserve", """Serve analysis graphs on port number -(see pypy/translator/tool/pygame/graphclient.py)""", - cmdline="--graphserve"), StrOption("targetspec", "XXX", default='targetpypystandalone', cmdline=None), BoolOption("profile", @@ -211,27 +208,6 @@ t = translator.TranslationContext(config=config) - class ServerSetup: - async_server = None - - def __call__(self, port=None, async_only=False): - try: - t1 = drv.hint_translator - except (NameError, AttributeError): - t1 = t - if self.async_server is not None: - return self.async_server - elif port is not None: - from pypy.translator.tool.graphserver import run_async_server - serv_start, serv_show, serv_stop = self.async_server = run_async_server(t1, translateconfig, port) - return serv_start, serv_show, serv_stop - elif not async_only: - from pypy.translator.tool.graphserver import run_server_for_inprocess_client - return run_server_for_inprocess_client(t1, translateconfig) - - server_setup = ServerSetup() - server_setup(translateconfig.graphserve, async_only=True) - pdb_plus_show = PdbPlusShow(t) # need a translator to support extended commands def debug(got_error): @@ -263,7 +239,16 @@ log.event("start debugger...") - pdb_plus_show.start(tb, server_setup, graphic=not translateconfig.text) + if not translateconfig.text: + try: + t1 = drv.hint_translator + except (NameError, AttributeError): + t1 = t + from pypy.translator.tool import graphpage + page = graphpage.TranslatorPage(t1, translateconfig.huge) + page.display_background() + + pdb_plus_show.start(tb) try: drv = driver.TranslationDriver.from_targetspec(targetspec_dic, config, args, Modified: pypy/branch/graphserver-dist/pypy/translator/tool/pdbplus.py ============================================================================== --- pypy/branch/graphserver-dist/pypy/translator/tool/pdbplus.py (original) +++ pypy/branch/graphserver-dist/pypy/translator/tool/pdbplus.py Fri Jun 15 10:07:18 2007 @@ -4,10 +4,6 @@ import sys from pypy.objspace.flow.model import FunctionGraph -class _EnableGraphic: - def __init__(self, port=None): - self.port = port - class NoTTY(Exception): pass @@ -33,16 +29,8 @@ def expose(self, d): self.exposed.update(d) - show = None - - def install_show(self, show): - self.show = show - def _show(self, page): - if not self.show: - print "*** No display" - return - self.show(page) + page.display_background() def _importobj(self, fullname): obj = None @@ -391,23 +379,6 @@ from pypy.translator.tool import graphpage self._show(graphpage.ClassHierarchyPage(self.translator)) - def do_enable_graphic(self, arg): - """enable_graphic -enable pygame graph display even from non-graphic mode""" - if self.show: - print "*** display already there" - return - raise _EnableGraphic - - def do_graphserve(self, arg): - """graphserve -start serving graphs on -""" - if self.show: - print "*** display already there" - return - raise _EnableGraphic(int(arg)) - def do_interact(self, arg): """invoke a code.py sub prompt""" ns = self.curframe.f_globals.copy() @@ -425,7 +396,7 @@ print self.TRYPREFIXES # start helpers - def _run_debugger(self, tb): + def start(self, tb): if tb is None: fn, args = self.set_trace, () else: @@ -439,37 +410,6 @@ except pdb.bdb.BdbQuit: pass - def _run_debugger_in_thread(self, tb, cleanup=None, cleanup_args=()): - def _run_in_thread(): - try: - self._run_debugger(tb) - finally: - if cleanup is not None: - cleanup(*cleanup_args) - import threading - return threading.Thread(target=_run_in_thread, args=()) - - def start(self, tb, server_setup, graphic=False): - port = None - if not graphic: - try: - self._run_debugger(tb) - except _EnableGraphic, engraph: - port = engraph.port - else: - return - try: - start, show, stop = server_setup(port) - except Exception, e: - print '%s.%s: %s' % (e.__class__.__module__, - e.__class__.__name__, e) - return self.start(tb, server_setup, graphic=False) - self.install_show(show) - debugger = self._run_debugger_in_thread(tb, stop) - debugger.start() - start() - debugger.join() - def pdbcatch(f): "A decorator that throws you in a pdbplus if the given function raises." From arigo at codespeak.net Fri Jun 15 10:18:21 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 10:18:21 +0200 (CEST) Subject: [pypy-svn] r44264 - pypy/branch/graphserver-dist/dotviewer Message-ID: <20070615081821.6CF918258@code0.codespeak.net> Author: arigo Date: Fri Jun 15 10:18:21 2007 New Revision: 44264 Modified: pypy/branch/graphserver-dist/dotviewer/dotviewer.py pypy/branch/graphserver-dist/dotviewer/graphserver.py Log: Support for specifying an interface to listen on. Useful to avoid opening an externally-visible tcp port. Modified: pypy/branch/graphserver-dist/dotviewer/dotviewer.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/dotviewer.py (original) +++ pypy/branch/graphserver-dist/dotviewer/dotviewer.py Fri Jun 15 10:18:21 2007 @@ -4,7 +4,7 @@ dotviewer.py filename.dot dotviewer.py filename.plain - dotviewer.py --server port + dotviewer.py --server [interface:]port In the first form, show the graph contained in a .dot file. In the second form, the graph was already compiled to a .plain file. @@ -17,22 +17,22 @@ def main(args = sys.argv[1:]): import getopt options, args = getopt.getopt(args, 's:h', ['server=', 'help']) - server_port = None + server_addr = None for option, value in options: if option in ('-h', '--help'): print >> sys.stderr, __doc__ sys.exit(2) if option in ('-s', '--server'): - server_port = int(value) - if not args and server_port is None: + server_addr = value + if not args and server_addr is None: print >> sys.stderr, __doc__ sys.exit(2) for filename in args: import graphclient graphclient.display_dot_file(filename) - if server_port is not None: + if server_addr is not None: import graphserver - graphserver.listen_server(('', server_port)) + graphserver.listen_server(server_addr) if __name__ == '__main__': main() Modified: pypy/branch/graphserver-dist/dotviewer/graphserver.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/graphserver.py (original) +++ pypy/branch/graphserver-dist/dotviewer/graphserver.py Fri Jun 15 10:18:21 2007 @@ -111,6 +111,12 @@ def listen_server(local_address): import socket, graphclient, thread + if isinstance(local_address, str): + if ':' in local_address: + interface, port = local_address.split(':') + else: + interface, port = '', local_address + local_address = interface, int(port) s1 = socket.socket() s1.bind(local_address) s1.listen(5) @@ -163,5 +169,4 @@ print >> f, help io.sendmsg(msgstruct.MSG_ERROR, f.getvalue()) else: - port = int(sys.argv[1]) - listen_server(('', port)) + listen_server(sys.argv[1]) From fijal at codespeak.net Fri Jun 15 10:33:53 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Fri, 15 Jun 2007 10:33:53 +0200 (CEST) Subject: [pypy-svn] r44266 - pypy/branch/graphserver-dist/dotviewer Message-ID: <20070615083353.6134A825A@code0.codespeak.net> Author: fijal Date: Fri Jun 15 10:33:53 2007 New Revision: 44266 Modified: pypy/branch/graphserver-dist/dotviewer/graphclient.py Log: Fix str(LocalPath) Modified: pypy/branch/graphserver-dist/dotviewer/graphclient.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/graphclient.py (original) +++ pypy/branch/graphserver-dist/dotviewer/graphclient.py Fri Jun 15 10:33:53 2007 @@ -8,7 +8,7 @@ def display_dot_file(dotfile, wait=True): """ Display the given dot file in a subprocess. """ - if not os.path.exists(dotfile): + if not os.path.exists(str(dotfile)): raise IOError("No such file: %s" % (dotfile,)) import graphpage page = graphpage.DotFileGraphPage(str(dotfile)) From arigo at codespeak.net Fri Jun 15 10:34:58 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 10:34:58 +0200 (CEST) Subject: [pypy-svn] r44267 - pypy/branch/graphserver-dist/pypy/objspace/std Message-ID: <20070615083458.1571A825A@code0.codespeak.net> Author: arigo Date: Fri Jun 15 10:34:57 2007 New Revision: 44267 Modified: pypy/branch/graphserver-dist/pypy/objspace/std/rope.py Log: Fix imports. Modified: pypy/branch/graphserver-dist/pypy/objspace/std/rope.py ============================================================================== --- pypy/branch/graphserver-dist/pypy/objspace/std/rope.py (original) +++ pypy/branch/graphserver-dist/pypy/objspace/std/rope.py Fri Jun 15 10:34:57 2007 @@ -90,7 +90,6 @@ return rope_from_charlist(result) def view(self): - from pypy.translator.tool.pygame import graphclient view([self]) def check_balanced(self): @@ -670,7 +669,7 @@ return restart def view(objs): - from pypy.translator.tool.pygame import graphclient + from dotviewer import graphclient content = ["digraph G{"] seen = {} for i, obj in enumerate(objs): From arigo at codespeak.net Fri Jun 15 10:49:46 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 10:49:46 +0200 (CEST) Subject: [pypy-svn] r44268 - in pypy/branch/graphserver-dist: dotviewer pypy/jit/codegen/i386 Message-ID: <20070615084946.15E94824F@code0.codespeak.net> Author: arigo Date: Fri Jun 15 10:49:46 2007 New Revision: 44268 Modified: pypy/branch/graphserver-dist/dotviewer/graphclient.py pypy/branch/graphserver-dist/dotviewer/graphparse.py pypy/branch/graphserver-dist/dotviewer/graphserver.py pypy/branch/graphserver-dist/dotviewer/msgstruct.py pypy/branch/graphserver-dist/pypy/jit/codegen/i386/viewcode.py Log: Fix more imports. Support fixedfont. Modified: pypy/branch/graphserver-dist/dotviewer/graphclient.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/graphclient.py (original) +++ pypy/branch/graphserver-dist/dotviewer/graphclient.py Fri Jun 15 10:49:46 2007 @@ -70,7 +70,8 @@ def page_messages(page, graph_id): import graphparse - return graphparse.parse_dot(graph_id, page.source, page.links) + return graphparse.parse_dot(graph_id, page.source, page.links, + getattr(page, 'fixedfont', False)) def send_graph_messages(io, messages): ioerror = None Modified: pypy/branch/graphserver-dist/dotviewer/graphparse.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/graphparse.py (original) +++ pypy/branch/graphserver-dist/dotviewer/graphparse.py Fri Jun 15 10:49:46 2007 @@ -60,7 +60,7 @@ result.append(word) return result -def parse_plain(graph_id, plaincontent, links={}): +def parse_plain(graph_id, plaincontent, links={}, fixedfont=False): lines = plaincontent.splitlines(True) for i in range(len(lines)-2, -1, -1): if lines[i].endswith('\\\n'): # line ending in '\' @@ -106,13 +106,16 @@ yield (msgstruct.CMSG_ADD_LINK, word, statusbartext) seen[word] = True + if fixedfont: + yield (msgstruct.CMSG_FIXED_FONT,) + yield (msgstruct.CMSG_STOP_GRAPH,) -def parse_dot(graph_id, content, links={}): +def parse_dot(graph_id, content, links={}, fixedfont=False): try: plaincontent = dot2plain(content, use_codespeak=False) - return list(parse_plain(graph_id, plaincontent, links)) + return list(parse_plain(graph_id, plaincontent, links, fixedfont)) except PlainParseError: # failed, retry via codespeak plaincontent = dot2plain(content, use_codespeak=True) - return list(parse_plain(graph_id, plaincontent, links)) + return list(parse_plain(graph_id, plaincontent, links, fixedfont)) Modified: pypy/branch/graphserver-dist/dotviewer/graphserver.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/graphserver.py (original) +++ pypy/branch/graphserver-dist/dotviewer/graphserver.py Fri Jun 15 10:49:46 2007 @@ -86,6 +86,9 @@ info = (info[0], info[1:4]) self.newlayout.links[word] = info + def cmsg_fixed_font(self, *rest): + self.newlayout.fixedfont = True + def cmsg_stop_graph(self, *rest): self.setlayout(self.newlayout) del self.newlayout @@ -103,6 +106,7 @@ msgstruct.CMSG_ADD_NODE: cmsg_add_node, msgstruct.CMSG_ADD_EDGE: cmsg_add_edge, msgstruct.CMSG_ADD_LINK: cmsg_add_link, + msgstruct.CMSG_FIXED_FONT: cmsg_fixed_font, msgstruct.CMSG_STOP_GRAPH: cmsg_stop_graph, msgstruct.CMSG_MISSING_LINK:cmsg_missing_link, msgstruct.CMSG_SAY: cmsg_say, Modified: pypy/branch/graphserver-dist/dotviewer/msgstruct.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/msgstruct.py (original) +++ pypy/branch/graphserver-dist/dotviewer/msgstruct.py Fri Jun 15 10:49:46 2007 @@ -8,6 +8,7 @@ CMSG_ADD_NODE = 'n' CMSG_ADD_EDGE = 'e' CMSG_ADD_LINK = 'l' +CMSG_FIXED_FONT = 'f' CMSG_STOP_GRAPH = ']' CMSG_MISSING_LINK= 'm' CMSG_SAY = 's' Modified: pypy/branch/graphserver-dist/pypy/jit/codegen/i386/viewcode.py ============================================================================== --- pypy/branch/graphserver-dist/pypy/jit/codegen/i386/viewcode.py (original) +++ pypy/branch/graphserver-dist/pypy/jit/codegen/i386/viewcode.py Fri Jun 15 10:49:46 2007 @@ -288,7 +288,7 @@ # but needs to be a bit more subtle later from pypy.translator.tool.make_dot import DotGen -from pypy.translator.tool.pygame.graphclient import display_layout +from dotviewer.graphclient import display_page class Graph(DotGen): @@ -302,7 +302,7 @@ def display(self): "Display a graph page locally." - display_layout(_Page(self)) + display_page(_Page(self)) class NoGraph(Exception): From arigo at codespeak.net Fri Jun 15 10:51:33 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 10:51:33 +0200 (CEST) Subject: [pypy-svn] r44269 - pypy/branch/graphserver-dist/pypy/rlib/parsing Message-ID: <20070615085133.20E128266@code0.codespeak.net> Author: arigo Date: Fri Jun 15 10:51:32 2007 New Revision: 44269 Modified: pypy/branch/graphserver-dist/pypy/rlib/parsing/deterministic.py pypy/branch/graphserver-dist/pypy/rlib/parsing/tree.py Log: Fix imports. Modified: pypy/branch/graphserver-dist/pypy/rlib/parsing/deterministic.py ============================================================================== --- pypy/branch/graphserver-dist/pypy/rlib/parsing/deterministic.py (original) +++ pypy/branch/graphserver-dist/pypy/rlib/parsing/deterministic.py Fri Jun 15 10:51:32 2007 @@ -370,7 +370,7 @@ return "\n".join(result) def view(self): - from pypy.translator.tool.pygame import graphclient + from dotviewer import graphclient p = py.test.ensuretemp("automaton").join("temp.dot") dot = self.dot() p.write(dot) @@ -510,7 +510,7 @@ return mapping def view(self): - from pypy.translator.tool.pygame import graphclient + from dotviewer import graphclient p = py.test.ensuretemp("automaton").join("temp.dot") dot = self.dot() p.write(dot) Modified: pypy/branch/graphserver-dist/pypy/rlib/parsing/tree.py ============================================================================== --- pypy/branch/graphserver-dist/pypy/rlib/parsing/tree.py (original) +++ pypy/branch/graphserver-dist/pypy/rlib/parsing/tree.py Fri Jun 15 10:51:32 2007 @@ -2,7 +2,7 @@ class Node(object): def view(self): - from pypy.translator.tool.pygame import graphclient + from dotviewer import graphclient content = ["digraph G{"] content.extend(self.dot()) content.append("}") From arigo at codespeak.net Fri Jun 15 11:13:01 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 11:13:01 +0200 (CEST) Subject: [pypy-svn] r44270 - pypy/branch/graphserver-dist/dotviewer Message-ID: <20070615091301.F1051827B@code0.codespeak.net> Author: arigo Date: Fri Jun 15 11:13:01 2007 New Revision: 44270 Modified: pypy/branch/graphserver-dist/dotviewer/graphparse.py Log: Typos. Modified: pypy/branch/graphserver-dist/dotviewer/graphparse.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/graphparse.py (original) +++ pypy/branch/graphserver-dist/dotviewer/graphparse.py Fri Jun 15 11:13:01 2007 @@ -68,7 +68,7 @@ del lines[i+1] header = splitline(lines.pop(0)) if header[0] != 'graph': - raise PlainParseError("%s: should start with 'graph'" % (plainfile,)) + raise PlainParseError("should start with 'graph'") yield (msgstruct.CMSG_START_GRAPH, graph_id) + tuple(header[1:]) texts = [] @@ -76,7 +76,7 @@ line = splitline(line) if line[0] == 'node': if len(line) != 11: - raise PlainParseError("%s: bad 'node'" % (plainfile,)) + raise PlainParseError("bad 'node'") yield (msgstruct.CMSG_ADD_NODE,) + tuple(line[1:]) texts.append(line[6]) if line[0] == 'edge': From arigo at codespeak.net Fri Jun 15 11:13:14 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 11:13:14 +0200 (CEST) Subject: [pypy-svn] r44271 - pypy/branch/graphserver-dist/dotviewer Message-ID: <20070615091314.10A03827E@code0.codespeak.net> Author: arigo Date: Fri Jun 15 11:13:13 2007 New Revision: 44271 Modified: pypy/branch/graphserver-dist/dotviewer/msgstruct.py Log: Test and fix for messages with many arguments. Modified: pypy/branch/graphserver-dist/dotviewer/msgstruct.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/msgstruct.py (original) +++ pypy/branch/graphserver-dist/dotviewer/msgstruct.py Fri Jun 15 11:13:13 2007 @@ -20,8 +20,8 @@ # ____________________________________________________________ -long_min = -sys.maxint-1 -long_max = sys.maxint +long_min = -2147483648 +long_max = 2147483647 def message(tp, *values): @@ -37,9 +37,12 @@ else: typecodes.append('q') typecodes = ''.join(typecodes) - assert len(typecodes) < 256 - return pack(("!B%dsc" % len(typecodes)) + typecodes, - len(typecodes), typecodes, tp, *values) + if len(typecodes) < 256: + return pack(("!B%dsc" % len(typecodes)) + typecodes, + len(typecodes), typecodes, tp, *values) + else: + # too many values - encapsulate the message in another one + return message('\x00', typecodes, pack("!c" + typecodes, tp, *values)) def decodemessage(data): if data: @@ -48,7 +51,10 @@ typecodes = "!c" + data[1:limit] end = limit + calcsize(typecodes) if len(data) >= end: - return unpack(typecodes, data[limit:end]), data[end:] + msg = unpack(typecodes, data[limit:end]) + if msg[0] == '\x00': + msg = unpack("!c" + msg[1], msg[2]) + return msg, data[end:] #elif end > 1000000: # raise OverflowError return None, data From arigo at codespeak.net Fri Jun 15 11:16:41 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 11:16:41 +0200 (CEST) Subject: [pypy-svn] r44272 - pypy/branch/graphserver-dist/dotviewer/test Message-ID: <20070615091641.7FFA8824F@code0.codespeak.net> Author: arigo Date: Fri Jun 15 11:16:41 2007 New Revision: 44272 Added: pypy/branch/graphserver-dist/dotviewer/test/test_msgstruct.py (contents, props changed) Log: And now really add the test mentioned in the previous check-in. Added: pypy/branch/graphserver-dist/dotviewer/test/test_msgstruct.py ============================================================================== --- (empty file) +++ pypy/branch/graphserver-dist/dotviewer/test/test_msgstruct.py Fri Jun 15 11:16:41 2007 @@ -0,0 +1,16 @@ +from dotviewer.msgstruct import * + + +def test_message(): + yield checkmsg, 'A' + yield checkmsg, 'B', 123, "hello", -128, -129 + yield checkmsg, 'C', "x" * 12345 + "y" + yield checkmsg, 'D', 2147483647, 2147483648, 2147483649, 2147483647000 + yield checkmsg, 'E', -2147483647, -2147483648, -2147483649, -2147483647000 + yield (checkmsg, 'F',) + tuple(range(9999)) + +def checkmsg(*args): + encoded = message(*args) + assert decodemessage(encoded[:-1]) == (None, encoded[:-1]) + assert decodemessage(encoded) == (args, '') + assert decodemessage(encoded + 'FooBar') == (args, 'FooBar') From arigo at codespeak.net Fri Jun 15 11:16:52 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 11:16:52 +0200 (CEST) Subject: [pypy-svn] r44273 - pypy/branch/graphserver-dist/pypy/rlib/parsing Message-ID: <20070615091652.2B4F68281@code0.codespeak.net> Author: arigo Date: Fri Jun 15 11:16:51 2007 New Revision: 44273 Modified: pypy/branch/graphserver-dist/pypy/rlib/parsing/tree.py Log: Fix dot file quoting. Modified: pypy/branch/graphserver-dist/pypy/rlib/parsing/tree.py ============================================================================== --- pypy/branch/graphserver-dist/pypy/rlib/parsing/tree.py (original) +++ pypy/branch/graphserver-dist/pypy/rlib/parsing/tree.py Fri Jun 15 11:16:51 2007 @@ -21,9 +21,11 @@ return "Symbol(%r, %r)" % (self.symbol, self.additional_info) def dot(self): + symbol = (self.symbol.replace("\\", "\\\\").replace('"', '\\"') + .replace('\n', '\\l')) addinfo = str(self.additional_info).replace('"', "'") or "_" yield ('"%s" [shape=box,label="%s\\n%s"];' % ( - id(self), self.symbol.replace("\\", "\\\\"), + id(self), symbol, repr(addinfo).replace('"', '').replace("\\", "\\\\"))) def visit(self, visitor): From arigo at codespeak.net Fri Jun 15 12:05:15 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 12:05:15 +0200 (CEST) Subject: [pypy-svn] r44278 - pypy/dist/pypy/annotation Message-ID: <20070615100515.4483C8290@code0.codespeak.net> Author: arigo Date: Fri Jun 15 12:05:14 2007 New Revision: 44278 Modified: pypy/dist/pypy/annotation/annrpython.py Log: Try to use signature.annotation() here, for 't.annotate([(float, float)])'. The various type-to-annotation functions we have around the code need some clean up and unification. Modified: pypy/dist/pypy/annotation/annrpython.py ============================================================================== --- pypy/dist/pypy/annotation/annrpython.py (original) +++ pypy/dist/pypy/annotation/annrpython.py Fri Jun 15 12:05:14 2007 @@ -5,6 +5,7 @@ from pypy.annotation import model as annmodel from pypy.annotation.pairtype import pair from pypy.annotation.bookkeeper import Bookkeeper, getbookkeeper +from pypy.annotation import signature from pypy.objspace.flow.model import Variable, Constant from pypy.objspace.flow.model import FunctionGraph from pypy.objspace.flow.model import c_last_exception, checkgraph @@ -293,10 +294,7 @@ raise TypeError, 'Variable or Constant expected, got %r' % (arg,) def typeannotation(self, t): - if isinstance(t, annmodel.SomeObject): - return t - else: - return self.bookkeeper.valueoftype(t) + return signature.annotation(t, self.bookkeeper) def ondegenerated(self, what, s_value, where=None, called_from_graph=None): if self.policy.allow_someobjects: From arigo at codespeak.net Fri Jun 15 13:10:36 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 13:10:36 +0200 (CEST) Subject: [pypy-svn] r44279 - pypy/branch/graphserver-dist/dotviewer/test Message-ID: <20070615111036.E24EE82AE@code0.codespeak.net> Author: arigo Date: Fri Jun 15 13:10:25 2007 New Revision: 44279 Modified: pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py Log: A test for fixedfont. Modified: pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py (original) +++ pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py Fri Jun 15 13:10:25 2007 @@ -147,3 +147,12 @@ dotfile = udir.join('graph1.dot') page = MyPage(str(dotfile)) graphclient.display_page(page) + +def test_fixedfont(): + from dotviewer import graphpage, graphclient + class MyPage(graphpage.DotFileGraphPage): + fixedfont = True + dotfile = udir.join('graph1.dot') + page = MyPage(str(dotfile)) + page.fixedfont = True + graphclient.display_page(page) From fijal at codespeak.net Fri Jun 15 13:38:06 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Fri, 15 Jun 2007 13:38:06 +0200 (CEST) Subject: [pypy-svn] r44280 - in pypy/branch/kill-ctypes/pypy/rpython/module: . test Message-ID: <20070615113806.7950182A8@code0.codespeak.net> Author: fijal Date: Fri Jun 15 13:38:00 2007 New Revision: 44280 Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py Log: Add os.WIFSIGNALED on rpython level Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py Fri Jun 15 13:38:00 2007 @@ -133,6 +133,18 @@ register_external(os.open, [str, int, int], int, "ll_os.open", llimpl=os_open_lltypeimpl, oofakeimpl=os_open_oofakeimpl) +def fake_WIFSIGNALED(status): + return int(os.WIFSIGNALED(status)) + +os_WIFSIGNALED = rffi.llexternal('WIFSIGNALED', [lltype.Signed], lltype.Signed, + _callable=fake_WIFSIGNALED) + +def WIFSIGNALED_lltypeimpl(status): + return bool(os_WIFSIGNALED(status)) + +register_external(os.WIFSIGNALED, [int], int, "ll_os.WIFSIGNALED", + llimpl=WIFSIGNALED_lltypeimpl) + class BaseOS: __metaclass__ = ClassMethods Modified: pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py (original) +++ pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py Fri Jun 15 13:38:00 2007 @@ -1,6 +1,7 @@ import os from pypy.tool.udir import udir from pypy.tool.pytest.modcheck import skipimporterror +from pypy.translator.c.test.test_genc import compile from pypy.rpython.lltypesystem.module.ll_os import Implementation as impl import sys @@ -100,3 +101,11 @@ compared_with = os.listdir(dirname) compared_with.sort() assert result == compared_with + +def test_os_wifsignaled(): + def fun(s): + return os.WIFSIGNALED(s) + + fn = compile(fun, [int]) + assert fn(0) == False + assert fn(1) == True From fijal at codespeak.net Fri Jun 15 13:41:44 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Fri, 15 Jun 2007 13:41:44 +0200 (CEST) Subject: [pypy-svn] r44281 - in pypy/branch/kill-ctypes/pypy/module/posix: . test Message-ID: <20070615114144.E64DA82B0@code0.codespeak.net> Author: fijal Date: Fri Jun 15 13:41:44 2007 New Revision: 44281 Modified: pypy/branch/kill-ctypes/pypy/module/posix/__init__.py pypy/branch/kill-ctypes/pypy/module/posix/interp_posix.py pypy/branch/kill-ctypes/pypy/module/posix/test/test_posix2.py Log: Add WIFSIGNALED in a module Modified: pypy/branch/kill-ctypes/pypy/module/posix/__init__.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/posix/__init__.py (original) +++ pypy/branch/kill-ctypes/pypy/module/posix/__init__.py Fri Jun 15 13:41:44 2007 @@ -52,6 +52,7 @@ #'getuid' : 'interp_posix.getuid', #'geteuid' : 'interp_posix.geteuid', 'utime' : 'interp_posix.utime', + 'WIFSIGNALED' : 'interp_posix.WIFSIGNALED', } if hasattr(os, 'ftruncate'): interpleveldefs['ftruncate'] = 'interp_posix.ftruncate' Modified: pypy/branch/kill-ctypes/pypy/module/posix/interp_posix.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/posix/interp_posix.py (original) +++ pypy/branch/kill-ctypes/pypy/module/posix/interp_posix.py Fri Jun 15 13:41:44 2007 @@ -497,3 +497,7 @@ raise raise OperationError(space.w_TypeError, space.wrap(msg)) utime.unwrap_spec = [ObjSpace, str, W_Root] + +def WIFSIGNALED(space, status): + return space.newbool(os.WIFSIGNALED(status)) +WIFSIGNALED.unwrap_spec = [ObjSpace, int] Modified: pypy/branch/kill-ctypes/pypy/module/posix/test/test_posix2.py ============================================================================== --- pypy/branch/kill-ctypes/pypy/module/posix/test/test_posix2.py (original) +++ pypy/branch/kill-ctypes/pypy/module/posix/test/test_posix2.py Fri Jun 15 13:41:44 2007 @@ -192,6 +192,11 @@ raises(TypeError, "os.utime('xxx', 3)") raises(OSError, "os.utime('somefilewhichihopewouldneverappearhere', None)") + def test_wifsignaled(self): + os = self.posix + assert os.WIFSIGNALED(0) == False + assert os.WIFSIGNALED(1) == True + class AppTestEnvironment(object): def setup_class(cls): cls.space = space From fijal at codespeak.net Fri Jun 15 13:50:38 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Fri, 15 Jun 2007 13:50:38 +0200 (CEST) Subject: [pypy-svn] r44282 - in pypy/branch/graphserver-dist/dotviewer: . test Message-ID: <20070615115038.39C2482B4@code0.codespeak.net> Author: fijal Date: Fri Jun 15 13:50:37 2007 New Revision: 44282 Added: pypy/branch/graphserver-dist/dotviewer/conftest.py - copied unchanged from r44265, pypy/branch/graphserver-dist/dotviewer/test/conftest.py Removed: pypy/branch/graphserver-dist/dotviewer/test/conftest.py Log: Move conftest one step up, to be able to type py.test --pygame from dotviewer dir From santagada at codespeak.net Fri Jun 15 14:24:15 2007 From: santagada at codespeak.net (santagada at codespeak.net) Date: Fri, 15 Jun 2007 14:24:15 +0200 (CEST) Subject: [pypy-svn] r44283 - pypy/dist/pypy/lang/js/test Message-ID: <20070615122415.CDB1982BC@code0.codespeak.net> Author: santagada Date: Fri Jun 15 14:24:14 2007 New Revision: 44283 Modified: pypy/dist/pypy/lang/js/test/test_interactive.py Log: fix the js_interactive location Modified: pypy/dist/pypy/lang/js/test/test_interactive.py ============================================================================== --- pypy/dist/pypy/lang/js/test/test_interactive.py (original) +++ pypy/dist/pypy/lang/js/test/test_interactive.py Fri Jun 15 14:24:14 2007 @@ -19,7 +19,7 @@ return child def spawn(self, argv): - return self._spawn('./js_interactive.py', argv) + return self._spawn(str(py.magic.autopath().dirpath().dirpath().join('js_interactive.py')), argv) def prompt_send(self, message): self.child.expect('js-pypy>') From arigo at codespeak.net Fri Jun 15 15:54:05 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 15:54:05 +0200 (CEST) Subject: [pypy-svn] r44290 - pypy/dist/pypy/rpython Message-ID: <20070615135405.3A96882B3@code0.codespeak.net> Author: arigo Date: Fri Jun 15 15:53:59 2007 New Revision: 44290 Added: pypy/dist/pypy/rpython/rbuiltin.py.merge.tmp - copied, changed from r44288, pypy/dist/pypy/rpython/rbuiltin.py Log: merging of svn+ssh://codespeak.net/svn/pypy/branch/kill-ctypes/pypy/rpython/rbuiltin.py revisions 43433 to 44288: ------------------------------------------------------------------------ r44223 | fijal | 2007-06-13 11:55:33 +0200 (Wed, 13 Jun 2007) | 2 lines exception_cannot_occure() in free and raw_free ------------------------------------------------------------------------ r43437 | fijal | 2007-05-16 21:15:04 +0200 (Wed, 16 May 2007) | 3 lines A branch which tries to create pypy without ctypes dependency, by approaching external functions via ll objects ------------------------------------------------------------------------ From arigo at codespeak.net Fri Jun 15 15:53:58 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 15:53:58 +0200 (CEST) Subject: [pypy-svn] r44289 - pypy/dist/pypy/rpython Message-ID: <20070615135358.576E082AB@code0.codespeak.net> Author: arigo Date: Fri Jun 15 15:53:57 2007 New Revision: 44289 Added: pypy/dist/pypy/rpython/llinterp.py.merge.tmp - copied, changed from r44288, pypy/dist/pypy/rpython/llinterp.py Log: merging of svn+ssh://codespeak.net/svn/pypy/branch/kill-ctypes/pypy/rpython/llinterp.py revisions 43433 to 44288: ------------------------------------------------------------------------ r44209 | fijal | 2007-06-12 23:20:28 +0200 (Tue, 12 Jun 2007) | 2 lines provide low-level implementation of flavored_malloc_varsize ------------------------------------------------------------------------ r43788 | fijal | 2007-05-28 15:06:10 +0200 (Mon, 28 May 2007) | 3 lines Add a non-working method for tests to start complain. My guess is that this kind of operation should never be seen by llinterp, but I cannot judge now. ------------------------------------------------------------------------ r43437 | fijal | 2007-05-16 21:15:04 +0200 (Wed, 16 May 2007) | 3 lines A branch which tries to create pypy without ctypes dependency, by approaching external functions via ll objects ------------------------------------------------------------------------ From arigo at codespeak.net Fri Jun 15 15:54:21 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 15:54:21 +0200 (CEST) Subject: [pypy-svn] r44292 - pypy/dist/pypy/translator/c Message-ID: <20070615135421.43C4782C6@code0.codespeak.net> Author: arigo Date: Fri Jun 15 15:54:20 2007 New Revision: 44292 Added: pypy/dist/pypy/translator/c/funcgen.py.merge.tmp - copied, changed from r44288, pypy/dist/pypy/translator/c/funcgen.py Log: merging of svn+ssh://codespeak.net/svn/pypy/branch/kill-ctypes/pypy/translator/c/funcgen.py revisions 43433 to 44288: ------------------------------------------------------------------------ r43669 | fijal | 2007-05-26 13:40:59 +0200 (Sat, 26 May 2007) | 2 lines Argh. didn't meant to do this. ------------------------------------------------------------------------ r43625 | fijal | 2007-05-25 14:39:22 +0200 (Fri, 25 May 2007) | 4 lines * add OP_FLAVORED_MALLOC_VARSIZE. I need to find tests for it, otherwise I know it's working just for a very basic case, very much XXX by now * remove unused variable ------------------------------------------------------------------------ r43570 | fijal | 2007-05-23 15:02:52 +0200 (Wed, 23 May 2007) | 3 lines Add mapping from str -> char*. Kind of works, but requires some more thinking probably. ------------------------------------------------------------------------ r43437 | fijal | 2007-05-16 21:15:04 +0200 (Wed, 16 May 2007) | 3 lines A branch which tries to create pypy without ctypes dependency, by approaching external functions via ll objects ------------------------------------------------------------------------ From arigo at codespeak.net Fri Jun 15 15:54:23 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 15:54:23 +0200 (CEST) Subject: [pypy-svn] r44291 - pypy/dist/pypy/annotation Message-ID: <20070615135423.A663F82CA@code0.codespeak.net> Author: arigo Date: Fri Jun 15 15:54:13 2007 New Revision: 44291 Added: pypy/dist/pypy/annotation/builtin.py.merge.tmp - copied, changed from r44288, pypy/dist/pypy/annotation/builtin.py Log: merging of svn+ssh://codespeak.net/svn/pypy/branch/kill-ctypes/pypy/annotation/builtin.py revisions 43433 to 44288: ------------------------------------------------------------------------ r44052 | fijal | 2007-06-06 15:37:21 +0200 (Wed, 06 Jun 2007) | 2 lines force termios.error to be of a certain shape ------------------------------------------------------------------------ r43437 | fijal | 2007-05-16 21:15:04 +0200 (Wed, 16 May 2007) | 3 lines A branch which tries to create pypy without ctypes dependency, by approaching external functions via ll objects ------------------------------------------------------------------------ From arigo at codespeak.net Fri Jun 15 15:54:24 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 15:54:24 +0200 (CEST) Subject: [pypy-svn] r44293 - pypy/dist/pypy/rpython/test Message-ID: <20070615135424.E7F9D82CD@code0.codespeak.net> Author: arigo Date: Fri Jun 15 15:54:24 2007 New Revision: 44293 Added: pypy/dist/pypy/rpython/test/test_rbuiltin.py.merge.tmp - copied, changed from r44288, pypy/dist/pypy/rpython/test/test_rbuiltin.py Log: merging of svn+ssh://codespeak.net/svn/pypy/branch/kill-ctypes/pypy/rpython/test/test_rbuiltin.py revisions 43433 to 44288: ------------------------------------------------------------------------ r44222 | fijal | 2007-06-13 11:17:31 +0200 (Wed, 13 Jun 2007) | 2 lines Fix test_rbuiltin, providing oofakeimpl ------------------------------------------------------------------------ r44210 | fijal | 2007-06-12 23:21:27 +0200 (Tue, 12 Jun 2007) | 2 lines Fix text_rbuiltin - ootypesystem needs some improvements (skipped by now) ------------------------------------------------------------------------ r43437 | fijal | 2007-05-16 21:15:04 +0200 (Wed, 16 May 2007) | 3 lines A branch which tries to create pypy without ctypes dependency, by approaching external functions via ll objects ------------------------------------------------------------------------ From arigo at codespeak.net Fri Jun 15 15:56:01 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 15:56:01 +0200 (CEST) Subject: [pypy-svn] r44294 - in pypy/dist/pypy: annotation annotation/test doc doc/config doc/discussion interpreter lang/js lib/distributed module/_curses module/fcntl module/posix module/termios rlib rpython rpython/lltypesystem rpython/lltypesystem/test rpython/module rpython/test translator/c translator/c/src translator/c/test Message-ID: <20070615135601.9360882AB@code0.codespeak.net> Author: arigo Date: Fri Jun 15 15:55:56 2007 New Revision: 44294 Added: pypy/dist/pypy/annotation/builtin.py - copied unchanged from r44293, pypy/dist/pypy/annotation/builtin.py.merge.tmp pypy/dist/pypy/annotation/classdef.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/annotation/classdef.py pypy/dist/pypy/annotation/signature.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/annotation/signature.py pypy/dist/pypy/annotation/test/test_signature.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/annotation/test/test_signature.py pypy/dist/pypy/doc/config/ - copied from r44293, pypy/branch/kill-ctypes/pypy/doc/config/ pypy/dist/pypy/doc/discussion/ - copied from r44293, pypy/branch/kill-ctypes/pypy/doc/discussion/ pypy/dist/pypy/doc/download.txt - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/doc/download.txt pypy/dist/pypy/doc/rffi.txt - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/doc/rffi.txt pypy/dist/pypy/interpreter/error.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/interpreter/error.py pypy/dist/pypy/lang/js/newparser.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/lang/js/newparser.py pypy/dist/pypy/lib/distributed/ - copied from r44293, pypy/branch/kill-ctypes/pypy/lib/distributed/ pypy/dist/pypy/module/_curses/ - copied from r44293, pypy/branch/kill-ctypes/pypy/module/_curses/ pypy/dist/pypy/module/fcntl/ - copied from r44293, pypy/branch/kill-ctypes/pypy/module/fcntl/ pypy/dist/pypy/module/posix/ - copied from r44293, pypy/branch/kill-ctypes/pypy/module/posix/ pypy/dist/pypy/module/termios/ - copied from r44293, pypy/branch/kill-ctypes/pypy/module/termios/ pypy/dist/pypy/rlib/ros.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/rlib/ros.py pypy/dist/pypy/rlib/rtermios.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/rlib/rtermios.py pypy/dist/pypy/rpython/extfunc.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/rpython/extfunc.py pypy/dist/pypy/rpython/extfuncregistry.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/rpython/extfuncregistry.py pypy/dist/pypy/rpython/extfunctable.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/rpython/extfunctable.py pypy/dist/pypy/rpython/llinterp.py - copied unchanged from r44293, pypy/dist/pypy/rpython/llinterp.py.merge.tmp pypy/dist/pypy/rpython/lltypesystem/lloperation.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/lloperation.py pypy/dist/pypy/rpython/lltypesystem/rffi.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rffi.py pypy/dist/pypy/rpython/lltypesystem/rfficache.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/rfficache.py pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rffi.py pypy/dist/pypy/rpython/lltypesystem/test/test_rfficache.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/test/test_rfficache.py pypy/dist/pypy/rpython/lltypesystem/typecache.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/rpython/lltypesystem/typecache.py pypy/dist/pypy/rpython/module/ - copied from r44293, pypy/branch/kill-ctypes/pypy/rpython/module/ pypy/dist/pypy/rpython/rbuiltin.py - copied unchanged from r44293, pypy/dist/pypy/rpython/rbuiltin.py.merge.tmp pypy/dist/pypy/rpython/test/test_extfunc.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/rpython/test/test_extfunc.py pypy/dist/pypy/rpython/test/test_rbuiltin.py - copied unchanged from r44293, pypy/dist/pypy/rpython/test/test_rbuiltin.py.merge.tmp pypy/dist/pypy/translator/c/external.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/translator/c/external.py pypy/dist/pypy/translator/c/extfunc.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/translator/c/extfunc.py pypy/dist/pypy/translator/c/funcgen.py - copied unchanged from r44293, pypy/dist/pypy/translator/c/funcgen.py.merge.tmp pypy/dist/pypy/translator/c/genc.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/translator/c/genc.py pypy/dist/pypy/translator/c/node.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/translator/c/node.py pypy/dist/pypy/translator/c/primitive.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/translator/c/primitive.py pypy/dist/pypy/translator/c/src/ll_os.h - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/translator/c/src/ll_os.h pypy/dist/pypy/translator/c/test/test_extfunc.py - copied unchanged from r44293, pypy/branch/kill-ctypes/pypy/translator/c/test/test_extfunc.py Removed: pypy/dist/pypy/annotation/builtin.py.merge.tmp pypy/dist/pypy/rpython/llinterp.py.merge.tmp pypy/dist/pypy/rpython/rbuiltin.py.merge.tmp pypy/dist/pypy/rpython/test/test_rbuiltin.py.merge.tmp pypy/dist/pypy/translator/c/funcgen.py.merge.tmp Log: (fijal, arigo) Merge the kill-ctypes branch. From arigo at codespeak.net Fri Jun 15 15:56:48 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 15:56:48 +0200 (CEST) Subject: [pypy-svn] r44295 - pypy/branch/kill-ctypes Message-ID: <20070615135648.7669182AB@code0.codespeak.net> Author: arigo Date: Fri Jun 15 15:56:48 2007 New Revision: 44295 Removed: pypy/branch/kill-ctypes/ Log: (fijal, arigo) Kill merged branch. From arigo at codespeak.net Fri Jun 15 16:01:16 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 15 Jun 2007 16:01:16 +0200 (CEST) Subject: [pypy-svn] r44296 - pypy/branch/graphserver-dist/dotviewer/test Message-ID: <20070615140116.7E758829D@code0.codespeak.net> Author: arigo Date: Fri Jun 15 16:01:15 2007 New Revision: 44296 Modified: pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py pypy/branch/graphserver-dist/dotviewer/test/test_translator.py Log: Fix imports. Modified: pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py (original) +++ pypy/branch/graphserver-dist/dotviewer/test/test_interactive.py Fri Jun 15 16:01:15 2007 @@ -1,6 +1,6 @@ import py import sys, os, signal, thread, time -from dotviewer.test.conftest import option +from dotviewer.conftest import option SOURCE1 = r'''digraph _generated__graph { subgraph _generated__ { Modified: pypy/branch/graphserver-dist/dotviewer/test/test_translator.py ============================================================================== --- pypy/branch/graphserver-dist/dotviewer/test/test_translator.py (original) +++ pypy/branch/graphserver-dist/dotviewer/test/test_translator.py Fri Jun 15 16:01:15 2007 @@ -3,7 +3,7 @@ """ import py, sys -from dotviewer.test.conftest import option +from dotviewer.conftest import option def setup_module(mod): if not option.pygame: From fijal at codespeak.net Fri Jun 15 16:11:49 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Fri, 15 Jun 2007 16:11:49 +0200 (CEST) Subject: [pypy-svn] r44297 - pypy/dist/pypy/lib Message-ID: <20070615141149.A38E082BE@code0.codespeak.net> Author: fijal Date: Fri Jun 15 16:11:49 2007 New Revision: 44297 Modified: pypy/dist/pypy/lib/ (props changed) Log: Add pyrepl into svn:externals From fijal at codespeak.net Sat Jun 16 13:31:40 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sat, 16 Jun 2007 13:31:40 +0200 (CEST) Subject: [pypy-svn] r44300 - pypy/dist/pypy/rpython/module Message-ID: <20070616113140.E0F8A80C2@code0.codespeak.net> Author: fijal Date: Sat Jun 16 13:31:39 2007 New Revision: 44300 Modified: pypy/dist/pypy/rpython/module/ll_os.py Log: Change the name to resemble old naming scheme Modified: pypy/dist/pypy/rpython/module/ll_os.py ============================================================================== --- pypy/dist/pypy/rpython/module/ll_os.py (original) +++ pypy/dist/pypy/rpython/module/ll_os.py Sat Jun 16 13:31:39 2007 @@ -130,7 +130,7 @@ def os_open_oofakeimpl(o_path, flags, mode): return os.open(o_path._str, flags, mode) -register_external(os.open, [str, int, int], int, "ll_os.open", +register_external(os.open, [str, int, int], int, "ll_os.ll_os_open", llimpl=os_open_lltypeimpl, oofakeimpl=os_open_oofakeimpl) def fake_WIFSIGNALED(status): From fijal at codespeak.net Sat Jun 16 13:42:05 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sat, 16 Jun 2007 13:42:05 +0200 (CEST) Subject: [pypy-svn] r44301 - pypy/dist/pypy/rpython/module Message-ID: <20070616114205.3F46280BF@code0.codespeak.net> Author: fijal Date: Sat Jun 16 13:42:04 2007 New Revision: 44301 Modified: pypy/dist/pypy/rpython/module/ll_os.py Log: Fix translation Modified: pypy/dist/pypy/rpython/module/ll_os.py ============================================================================== --- pypy/dist/pypy/rpython/module/ll_os.py (original) +++ pypy/dist/pypy/rpython/module/ll_os.py Sat Jun 16 13:42:04 2007 @@ -142,7 +142,7 @@ def WIFSIGNALED_lltypeimpl(status): return bool(os_WIFSIGNALED(status)) -register_external(os.WIFSIGNALED, [int], int, "ll_os.WIFSIGNALED", +register_external(os.WIFSIGNALED, [int], bool, "ll_os.WIFSIGNALED", llimpl=WIFSIGNALED_lltypeimpl) class BaseOS: From fijal at codespeak.net Sat Jun 16 14:26:41 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sat, 16 Jun 2007 14:26:41 +0200 (CEST) Subject: [pypy-svn] r44302 - in pypy/dist/pypy/rpython: . test Message-ID: <20070616122641.553A780BE@code0.codespeak.net> Author: fijal Date: Sat Jun 16 14:26:40 2007 New Revision: 44302 Modified: pypy/dist/pypy/rpython/extfunc.py pypy/dist/pypy/rpython/test/test_extfunc.py Log: rename _callable to genericcallable Modified: pypy/dist/pypy/rpython/extfunc.py ============================================================================== --- pypy/dist/pypy/rpython/extfunc.py (original) +++ pypy/dist/pypy/rpython/extfunc.py Sat Jun 16 14:26:40 2007 @@ -6,7 +6,7 @@ import py -class _callable(object): +class genericcallable(object): """ A way to specify the callable annotation, but deferred until we have bookkeeper """ @@ -15,7 +15,7 @@ self.result = result class _ext_callable(ExtRegistryEntry): - _type_ = _callable + _type_ = genericcallable # we defer a bit annotation here def compute_result_annotation(self): Modified: pypy/dist/pypy/rpython/test/test_extfunc.py ============================================================================== --- pypy/dist/pypy/rpython/test/test_extfunc.py (original) +++ pypy/dist/pypy/rpython/test/test_extfunc.py Sat Jun 16 14:26:40 2007 @@ -1,5 +1,5 @@ -from pypy.rpython.extfunc import ExtFuncEntry, _callable, register_external,\ +from pypy.rpython.extfunc import ExtFuncEntry, register_external,\ is_external from pypy.annotation import model as annmodel from pypy.annotation.annrpython import RPythonAnnotator From fijal at codespeak.net Sat Jun 16 14:27:28 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sat, 16 Jun 2007 14:27:28 +0200 (CEST) Subject: [pypy-svn] r44303 - in pypy/dist/pypy/translator/js: examples examples/bnb examples/test lib modules test Message-ID: <20070616122728.5F5AC80BF@code0.codespeak.net> Author: fijal Date: Sat Jun 16 14:27:27 2007 New Revision: 44303 Modified: pypy/dist/pypy/translator/js/examples/bnb/bnb.py pypy/dist/pypy/translator/js/examples/overmind.py pypy/dist/pypy/translator/js/examples/pythonconsole.py pypy/dist/pypy/translator/js/examples/test/test_examples.py pypy/dist/pypy/translator/js/lib/support.py pypy/dist/pypy/translator/js/modules/dom.py pypy/dist/pypy/translator/js/modules/mochikit.py pypy/dist/pypy/translator/js/test/test_bltn.py pypy/dist/pypy/translator/js/test/test_extfunc.py pypy/dist/pypy/translator/js/test/test_str.py Log: Rename extfunc._callable to extfunc.genericcallable to avoid confusion Modified: pypy/dist/pypy/translator/js/examples/bnb/bnb.py ============================================================================== --- pypy/dist/pypy/translator/js/examples/bnb/bnb.py (original) +++ pypy/dist/pypy/translator/js/examples/bnb/bnb.py Sat Jun 16 14:27:27 2007 @@ -8,7 +8,6 @@ from pypy.translator.js.examples.bnb.servermessage import log, ServerMessage,\ PMSG_INLINE_FRAME, PMSG_DEF_ICON from pypy.translator.js.examples.bnb.msgstruct import * -from pypy.rpython.extfunc import _callable from pypy.translator.js.lib.support import callback from pypy.translator.js.lib import server Modified: pypy/dist/pypy/translator/js/examples/overmind.py ============================================================================== --- pypy/dist/pypy/translator/js/examples/overmind.py (original) +++ pypy/dist/pypy/translator/js/examples/overmind.py Sat Jun 16 14:27:27 2007 @@ -7,7 +7,6 @@ from pypy.translator.js.lib import server from pypy.translator.js.lib.support import callback -from pypy.rpython.extfunc import _callable from pypy.rpython.ootypesystem.bltregistry import described from pypy.translator.js.main import rpython2javascript from pypy.translator.js.examples.console import console Modified: pypy/dist/pypy/translator/js/examples/pythonconsole.py ============================================================================== --- pypy/dist/pypy/translator/js/examples/pythonconsole.py (original) +++ pypy/dist/pypy/translator/js/examples/pythonconsole.py Sat Jun 16 14:27:27 2007 @@ -16,7 +16,7 @@ from pypy.translator.js.modules.mochikit import connect, disconnect from pypy.rpython.ootypesystem.bltregistry import MethodDesc, BasicExternal from pypy.translator.js import commproxy -from pypy.rpython.extfunc import _callable +from pypy.rpython.extfunc import genericcallable from pypy.translator.js.lib import support from pypy.translator.js.lib import server @@ -102,8 +102,8 @@ # Methods and signatures how they are rendered for JS _methods = { 'some_callback' : MethodDesc([('cmd', str), - ('callback', _callable([{str:str}]))], - {str:str}) + ('callback', genericcallable([{str:str}]))], + {str:str}) } _render_xmlhttp = True Modified: pypy/dist/pypy/translator/js/examples/test/test_examples.py ============================================================================== --- pypy/dist/pypy/translator/js/examples/test/test_examples.py (original) +++ pypy/dist/pypy/translator/js/examples/test/test_examples.py Sat Jun 16 14:27:27 2007 @@ -29,7 +29,7 @@ def test_console_2_build(): from pypy.translator.js.examples.console import console, client assert rpython2javascript(client, console.FUNCTION_LIST, - use_pdb=False) + use_pdb=True) def test_ping_play1(): from urllib import URLopener Modified: pypy/dist/pypy/translator/js/lib/support.py ============================================================================== --- pypy/dist/pypy/translator/js/lib/support.py (original) +++ pypy/dist/pypy/translator/js/lib/support.py Sat Jun 16 14:27:27 2007 @@ -5,7 +5,7 @@ from pypy.rpython.ootypesystem.bltregistry import described, load_dict_args,\ MethodDesc -from pypy.rpython.extfunc import _callable +from pypy.rpython.extfunc import genericcallable def callback(retval=None, args={}): """ Variant of described decorator, which flows @@ -21,7 +21,7 @@ arg_list = load_dict_args(vars, defs, args) else: arg_list = args - arg_list.append(("callback", _callable(args=[retval]))) + arg_list.append(("callback", genericcallable(args=[retval]))) func._method = (func.__name__, MethodDesc(arg_list, retval)) return func Modified: pypy/dist/pypy/translator/js/modules/dom.py ============================================================================== --- pypy/dist/pypy/translator/js/modules/dom.py (original) +++ pypy/dist/pypy/translator/js/modules/dom.py Sat Jun 16 14:27:27 2007 @@ -21,12 +21,11 @@ from pypy.rpython.ootypesystem.bltregistry import BasicExternal, MethodDesc from pypy.rlib.nonconst import NonConstant -from pypy.rpython.extfunc import _callable, register_external +from pypy.rpython.extfunc import genericcallable, register_external from xml.dom import minidom from pypy.annotation.signature import annotation from pypy.annotation import model as annmodel -from pypy.rpython.extfunc import _callable # EventTarget is the base class for Nodes and Window class EventTarget(BasicExternal): @@ -333,7 +332,7 @@ def setTimeout(func, delay): pass -register_external(setTimeout, args=[_callable([]), int], result=None) +register_external(setTimeout, args=[genericcallable([]), int], result=None) window = Window() document = window.document @@ -343,31 +342,31 @@ # rtyper stuff EventTarget._fields = { - 'onabort' : _callable([Event]), - 'onblur' : _callable([Event]), - 'onchange' : _callable([Event]), - 'onclick' : _callable([MouseEvent]), - 'onclose' : _callable([MouseEvent]), - 'ondblclick' : _callable([MouseEvent]), - 'ondragdrop' : _callable([MouseEvent]), - 'onerror' : _callable([MouseEvent]), - 'onfocus' : _callable([Event]), - 'onkeydown' : _callable([KeyEvent]), - 'onkeypress' : _callable([KeyEvent]), - 'onkeyup' : _callable([KeyEvent]), - 'onload' : _callable([KeyEvent]), - 'onmousedown' : _callable([MouseEvent]), - 'onmousemove' : _callable([MouseEvent]), - 'onmouseup' : _callable([MouseEvent]), - 'onmouseover' : _callable([MouseEvent]), - 'onresize' : _callable([Event]), - 'onscroll' : _callable([MouseEvent]), - 'onselect' : _callable([MouseEvent]), - 'onsubmit' : _callable([MouseEvent]), - 'onunload' : _callable([Event]), + 'onabort' : genericcallable([Event]), + 'onblur' : genericcallable([Event]), + 'onchange' : genericcallable([Event]), + 'onclick' : genericcallable([MouseEvent]), + 'onclose' : genericcallable([MouseEvent]), + 'ondblclick' : genericcallable([MouseEvent]), + 'ondragdrop' : genericcallable([MouseEvent]), + 'onerror' : genericcallable([MouseEvent]), + 'onfocus' : genericcallable([Event]), + 'onkeydown' : genericcallable([KeyEvent]), + 'onkeypress' : genericcallable([KeyEvent]), + 'onkeyup' : genericcallable([KeyEvent]), + 'onload' : genericcallable([KeyEvent]), + 'onmousedown' : genericcallable([MouseEvent]), + 'onmousemove' : genericcallable([MouseEvent]), + 'onmouseup' : genericcallable([MouseEvent]), + 'onmouseover' : genericcallable([MouseEvent]), + 'onresize' : genericcallable([Event]), + 'onscroll' : genericcallable([MouseEvent]), + 'onselect' : genericcallable([MouseEvent]), + 'onsubmit' : genericcallable([MouseEvent]), + 'onunload' : genericcallable([Event]), } -lambda_returning_true = _callable([Event]) +lambda_returning_true = genericcallable([Event]) EventTarget._methods = { 'addEventListener' : MethodDesc([str, lambda_returning_true, bool]), Modified: pypy/dist/pypy/translator/js/modules/mochikit.py ============================================================================== --- pypy/dist/pypy/translator/js/modules/mochikit.py (original) +++ pypy/dist/pypy/translator/js/modules/mochikit.py Sat Jun 16 14:27:27 2007 @@ -2,7 +2,7 @@ """ mochikit wrappers """ -from pypy.rpython.extfunc import _callable, register_external +from pypy.rpython.extfunc import genericcallable, register_external from pypy.rpython.ootypesystem.bltregistry import BasicExternal, MethodDesc from pypy.translator.js.modules import dom @@ -62,7 +62,7 @@ def connect(src, signal, dest): print 'connecting signal %s' % (signal,) -register_external(connect, args=[dom.EventTarget, str, _callable([Event])], +register_external(connect, args=[dom.EventTarget, str, genericcallable([Event])], result=int) def disconnect(id): Modified: pypy/dist/pypy/translator/js/test/test_bltn.py ============================================================================== --- pypy/dist/pypy/translator/js/test/test_bltn.py (original) +++ pypy/dist/pypy/translator/js/test/test_bltn.py Sat Jun 16 14:27:27 2007 @@ -5,7 +5,7 @@ from pypy.rpython.ootypesystem.bltregistry import BasicExternal, MethodDesc from pypy.translator.js.test.runtest import compile_function, check_source_contains -from pypy.rpython.extfunc import _callable +from pypy.rpython.extfunc import genericcallable from pypy.translator.js import commproxy # check rendering dom.document @@ -28,7 +28,7 @@ class SomeNode(BasicExternal): _fields = { - 'some_callback' : _callable([int], int), + 'some_callback' : genericcallable([int], int), } SomeProxyInstance = SomeProxy() Modified: pypy/dist/pypy/translator/js/test/test_extfunc.py ============================================================================== --- pypy/dist/pypy/translator/js/test/test_extfunc.py (original) +++ pypy/dist/pypy/translator/js/test/test_extfunc.py Sat Jun 16 14:27:27 2007 @@ -3,7 +3,6 @@ """ from pypy.translator.js.test.runtest import compile_function, check_source_contains -from pypy.rpython.extfunc import _callable def test_set_timeout(): from pypy.translator.js.modules.dom import setTimeout Modified: pypy/dist/pypy/translator/js/test/test_str.py ============================================================================== --- pypy/dist/pypy/translator/js/test/test_str.py (original) +++ pypy/dist/pypy/translator/js/test/test_str.py Sat Jun 16 14:27:27 2007 @@ -4,7 +4,7 @@ import pypy.translator.oosupport.test_template.string as oostring -# ====> ../../../rpython/test/test_str.py +# ====> ../../../rpython/test/test_rstr.py class TestJsString(JsTest, oostring.BaseTestString): def test_char_unichar_eq(self): From pedronis at codespeak.net Sat Jun 16 16:01:15 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Sat, 16 Jun 2007 16:01:15 +0200 (CEST) Subject: [pypy-svn] r44304 - in pypy/dist/pypy/rpython: . lltypesystem ootypesystem Message-ID: <20070616140115.EB98580C9@code0.codespeak.net> Author: pedronis Date: Sat Jun 16 16:01:14 2007 New Revision: 44304 Modified: pypy/dist/pypy/rpython/lltypesystem/typecache.py pypy/dist/pypy/rpython/ootypesystem/bltregistry.py pypy/dist/pypy/rpython/rexternalobj.py Log: sanity for order of definitions Modified: pypy/dist/pypy/rpython/lltypesystem/typecache.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/typecache.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/typecache.py Sat Jun 16 16:01:14 2007 @@ -1,2 +1,2 @@ # this is automatically generated cache files for c types -platforms = {('', ('32bit', 'ELF'), 'Linux'): {'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 32, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}} +platforms = {('', ('32bit', 'ELF'), 'Linux'): {'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 32, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}, ('i386', ('32bit', ''), 'Darwin'): {'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 16, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}} Modified: pypy/dist/pypy/rpython/ootypesystem/bltregistry.py ============================================================================== --- pypy/dist/pypy/rpython/ootypesystem/bltregistry.py (original) +++ pypy/dist/pypy/rpython/ootypesystem/bltregistry.py Sat Jun 16 16:01:14 2007 @@ -212,6 +212,7 @@ def compute_result_annotation(self): if self.bookkeeper is None: + # XXX diverges from the cache return annmodel.SomeExternalBuiltin(ExternalType(self.instance)) return annmodel.SomeExternalBuiltin(self.bookkeeper.getexternaldesc(self.instance)) Modified: pypy/dist/pypy/rpython/rexternalobj.py ============================================================================== --- pypy/dist/pypy/rpython/rexternalobj.py (original) +++ pypy/dist/pypy/rpython/rexternalobj.py Sat Jun 16 16:01:14 2007 @@ -10,6 +10,8 @@ from pypy.annotation.signature import annotation from pypy.annotation.pairtype import pairtype +# ExternalObjects + class __extend__(annmodel.SomeExternalObject): def rtyper_makerepr(self, rtyper): @@ -28,7 +30,55 @@ if 'const_box' in attrs: del attrs['const_box'] return self.__class__, attrs + +class ExternalObjRepr(Repr): + """Repr for the (obsolecent) extfunctable.declaretype() case. + If you use the extregistry instead you get to pick your own Repr. + """ + + def __init__(self, knowntype): + self.exttypeinfo = typetable[knowntype] + TYPE = self.exttypeinfo.get_lltype() + self.lowleveltype = lltype.Ptr(TYPE) + self.instance_cache = {} + # The set of methods supported depends on 'knowntype', so we + # cannot have rtype_method_xxx() methods directly on the + # ExternalObjRepr class. But we can store them in 'self' now. + for name, extfuncinfo in self.exttypeinfo.methods.items(): + methodname = 'rtype_method_' + name + bltintyper = rbuiltin.make_rtype_extfunc(extfuncinfo) + setattr(self, methodname, bltintyper) + def convert_const(self, value): + T = self.exttypeinfo.get_lltype() + if value is None: + return lltype.nullptr(T) + if not isinstance(value, self.exttypeinfo.typ): + raise TyperError("expected a %r: %r" % (self.exttypeinfo.typ, + value)) + key = Constant(value) + try: + p = self.instance_cache[key] + except KeyError: + p = lltype.malloc(T) + init_opaque_object(p.obj, value) + self.instance_cache[key] = p + return p + + def rtype_is_true(self, hop): + vlist = hop.inputargs(self) + return hop.genop('ptr_nonzero', vlist, resulttype=lltype.Bool) + +# ExternalBuiltins + +class __extend__(annmodel.SomeExternalBuiltin): + + def rtyper_makerepr(self, rtyper): + return ExternalBuiltinRepr(self.knowntype) + + def rtyper_makekey(self): + return self.__class__, self.knowntype + class ExternalBuiltinRepr(Repr): def __init__(self, knowntype): self.knowntype = knowntype @@ -92,51 +142,6 @@ else: raise AttributeError(attr) -class __extend__(annmodel.SomeExternalBuiltin): - - def rtyper_makerepr(self, rtyper): - return ExternalBuiltinRepr(self.knowntype) - - def rtyper_makekey(self): - return self.__class__, self.knowntype - -class ExternalObjRepr(Repr): - """Repr for the (obsolecent) extfunctable.declaretype() case. - If you use the extregistry instead you get to pick your own Repr. - """ - - def __init__(self, knowntype): - self.exttypeinfo = typetable[knowntype] - TYPE = self.exttypeinfo.get_lltype() - self.lowleveltype = lltype.Ptr(TYPE) - self.instance_cache = {} - # The set of methods supported depends on 'knowntype', so we - # cannot have rtype_method_xxx() methods directly on the - # ExternalObjRepr class. But we can store them in 'self' now. - for name, extfuncinfo in self.exttypeinfo.methods.items(): - methodname = 'rtype_method_' + name - bltintyper = rbuiltin.make_rtype_extfunc(extfuncinfo) - setattr(self, methodname, bltintyper) - - def convert_const(self, value): - T = self.exttypeinfo.get_lltype() - if value is None: - return lltype.nullptr(T) - if not isinstance(value, self.exttypeinfo.typ): - raise TyperError("expected a %r: %r" % (self.exttypeinfo.typ, - value)) - key = Constant(value) - try: - p = self.instance_cache[key] - except KeyError: - p = lltype.malloc(T) - init_opaque_object(p.obj, value) - self.instance_cache[key] = p - return p - - def rtype_is_true(self, hop): - vlist = hop.inputargs(self) - return hop.genop('ptr_nonzero', vlist, resulttype=lltype.Bool) class __extend__(pairtype(ExternalBuiltinRepr, ExternalBuiltinRepr)): def convert_from_to((from_, to), v, llops): @@ -146,5 +151,3 @@ v.concretetype=to.knowntype return v return NotImplemented - - From fijal at codespeak.net Sat Jun 16 16:09:08 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sat, 16 Jun 2007 16:09:08 +0200 (CEST) Subject: [pypy-svn] r44305 - pypy/dist/pypy/rpython Message-ID: <20070616140908.1AD778095@code0.codespeak.net> Author: fijal Date: Sat Jun 16 16:09:08 2007 New Revision: 44305 Modified: pypy/dist/pypy/rpython/rexternalobj.py Log: Add a check_update in getattr Modified: pypy/dist/pypy/rpython/rexternalobj.py ============================================================================== --- pypy/dist/pypy/rpython/rexternalobj.py (original) +++ pypy/dist/pypy/rpython/rexternalobj.py Sat Jun 16 16:09:08 2007 @@ -90,6 +90,7 @@ return _external_type(self.knowntype, value) def rtype_getattr(self, hop): + self.knowntype.check_update() attr = hop.args_s[1].const s_inst = hop.args_s[0] if self.knowntype._methods.has_key(attr): From fijal at codespeak.net Sat Jun 16 16:09:46 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sat, 16 Jun 2007 16:09:46 +0200 (CEST) Subject: [pypy-svn] r44306 - pypy/dist/pypy/rpython/ootypesystem Message-ID: <20070616140946.059D880C7@code0.codespeak.net> Author: fijal Date: Sat Jun 16 16:09:46 2007 New Revision: 44306 Modified: pypy/dist/pypy/rpython/ootypesystem/bltregistry.py Log: Add a comparison by _class_ - need to grow to sth else (keeping ExternalTypeDesc in a bookkeeper), leave it like that for now. Modified: pypy/dist/pypy/rpython/ootypesystem/bltregistry.py ============================================================================== --- pypy/dist/pypy/rpython/ootypesystem/bltregistry.py (original) +++ pypy/dist/pypy/rpython/ootypesystem/bltregistry.py Sat Jun 16 16:09:46 2007 @@ -100,6 +100,14 @@ self.s_retval = s_retval self.s_args = s_args self.value = value + + + def __ne__(self, other): + return not (self == other) + + def __eq__(self, other): + return (self.__class__ is other.__class__ and + self.__dict__ == other.__dict__) def __call__(self, *args): args = args[1:] @@ -130,6 +138,11 @@ def _is_compatible(type2): return type(type2) is ExternalType + + def __eq__(self, other): + return self.__class__ is other.__class__ and \ + self._class_ is other._class_ + _is_compatible = staticmethod(_is_compatible) def update_methods(self, _methods): From fijal at codespeak.net Sat Jun 16 16:17:28 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sat, 16 Jun 2007 16:17:28 +0200 (CEST) Subject: [pypy-svn] r44307 - pypy/dist/pypy/rpython/lltypesystem Message-ID: <20070616141728.1D90780CA@code0.codespeak.net> Author: fijal Date: Sat Jun 16 16:17:27 2007 New Revision: 44307 Modified: pypy/dist/pypy/rpython/lltypesystem/rfficache.py pypy/dist/pypy/rpython/lltypesystem/typecache.py Log: Add newlines to created file, to please svn Modified: pypy/dist/pypy/rpython/lltypesystem/rfficache.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/rfficache.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/rfficache.py Sat Jun 16 16:17:27 2007 @@ -47,6 +47,10 @@ TYPES.append(name) TYPES += ['long long', 'unsigned long long', 'size_t', 'mode_t'] +def newline_repr(d): + assert isinstance(d, dict) + return "{\n%s\n}" % ",\n".join(["%r:%r" % (k, v) for k, v in d.items()]) + def get_type_sizes(filename, platform_key=machine_key(), types=TYPES, compiler_exe=None): try: @@ -68,7 +72,7 @@ platforms[platform_key] = value comment = "# this is automatically generated cache files for c types\n" py.path.local(filename).write(comment + 'platforms = ' + - repr(platforms) + "\n") + newline_repr(platforms) + "\n") return value from pypy.tool import autopath Modified: pypy/dist/pypy/rpython/lltypesystem/typecache.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/typecache.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/typecache.py Sat Jun 16 16:17:27 2007 @@ -1,2 +1,4 @@ # this is automatically generated cache files for c types -platforms = {('', ('32bit', 'ELF'), 'Linux'): {'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 32, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}, ('i386', ('32bit', ''), 'Darwin'): {'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 16, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}} +platforms = { +('', ('32bit', 'ELF'), 'Linux'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 32, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32} +} From pedronis at codespeak.net Sat Jun 16 16:53:49 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Sat, 16 Jun 2007 16:53:49 +0200 (CEST) Subject: [pypy-svn] r44308 - in pypy/dist/pypy/rpython: lltypesystem module Message-ID: <20070616145349.D935780B5@code0.codespeak.net> Author: pedronis Date: Sat Jun 16 16:53:49 2007 New Revision: 44308 Modified: pypy/dist/pypy/rpython/lltypesystem/typecache.py pypy/dist/pypy/rpython/module/ll_os.py Log: mode_t may not be a signed Modified: pypy/dist/pypy/rpython/lltypesystem/typecache.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/typecache.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/typecache.py Sat Jun 16 16:53:49 2007 @@ -1,4 +1,5 @@ # this is automatically generated cache files for c types platforms = { -('', ('32bit', 'ELF'), 'Linux'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 32, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32} +('', ('32bit', 'ELF'), 'Linux'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 32, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}, +('i386', ('32bit', ''), 'Darwin'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 16, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32} } Modified: pypy/dist/pypy/rpython/module/ll_os.py ============================================================================== --- pypy/dist/pypy/rpython/module/ll_os.py (original) +++ pypy/dist/pypy/rpython/module/ll_os.py Sat Jun 16 16:53:49 2007 @@ -121,6 +121,7 @@ def os_open_lltypeimpl(path, flags, mode): l_path = rffi.str2charp(path) + mode = lltype.cast_primitive(rffi.MODE_T, mode) result = os_open(l_path, flags, mode) lltype.free(l_path, flavor='raw') if result == -1: From arigo at codespeak.net Sat Jun 16 19:26:34 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sat, 16 Jun 2007 19:26:34 +0200 (CEST) Subject: [pypy-svn] r44309 - in pypy/dist/pypy/lang/js: . test Message-ID: <20070616172634.97DDD80BE@code0.codespeak.net> Author: arigo Date: Sat Jun 16 19:26:33 2007 New Revision: 44309 Modified: pypy/dist/pypy/lang/js/astbuilder.py (props changed) pypy/dist/pypy/lang/js/jsparser.py (props changed) pypy/dist/pypy/lang/js/test/test_astbuilder.py (props changed) pypy/dist/pypy/lang/js/test/test_interactive.py (props changed) pypy/dist/pypy/lang/js/test/test_operations.py (props changed) Log: fixeol From pedronis at codespeak.net Sat Jun 16 19:27:42 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Sat, 16 Jun 2007 19:27:42 +0200 (CEST) Subject: [pypy-svn] r44310 - in pypy/dist/pypy: annotation annotation/test rpython rpython/ootypesystem rpython/ootypesystem/test translator/js Message-ID: <20070616172742.CCE1B80BE@code0.codespeak.net> Author: pedronis Date: Sat Jun 16 19:27:42 2007 New Revision: 44310 Added: pypy/dist/pypy/rpython/ootypesystem/rbltregistry.py - copied, changed from r44307, pypy/dist/pypy/rpython/rexternalobj.py Modified: pypy/dist/pypy/annotation/binaryop.py pypy/dist/pypy/annotation/bookkeeper.py pypy/dist/pypy/annotation/model.py pypy/dist/pypy/annotation/test/test_annrpython.py pypy/dist/pypy/annotation/unaryop.py pypy/dist/pypy/rpython/ootypesystem/bltregistry.py pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py pypy/dist/pypy/rpython/rexternalobj.py pypy/dist/pypy/translator/js/database.py Log: sanitize a bit the ExternalType mess: unify SomeExternalObject and SomeExternalBuiltin, introduce SomeExternalInstance which has just different union behavior. use getrepr and introduce rbltnregistry for rtyping logic for BasicExternal whose annotation now is a special case of SomeExternalInstance split ExternalType into a thin OOType and a desc that is cached on the bookkeeper. No more mutable ootype containing annotations ... the js test are passing, as well as the annotation and rtyping tests for BasicExternal for what is worth. Modified: pypy/dist/pypy/annotation/binaryop.py ============================================================================== --- pypy/dist/pypy/annotation/binaryop.py (original) +++ pypy/dist/pypy/annotation/binaryop.py Sat Jun 16 19:27:42 2007 @@ -20,7 +20,7 @@ from pypy.annotation.model import add_knowntypedata, merge_knowntypedata from pypy.annotation.model import lltype_to_annotation from pypy.annotation.model import SomeGenericCallable -from pypy.annotation.model import SomeExternalBuiltin +from pypy.annotation.model import SomeExternalInstance from pypy.annotation.bookkeeper import getbookkeeper from pypy.objspace.flow.model import Variable from pypy.annotation.listdef import ListDef @@ -759,7 +759,7 @@ return SomeExternalObject(ext1.knowntype) return SomeObject() -class __extend__(pairtype(SomeExternalBuiltin, SomeExternalBuiltin)): +class __extend__(pairtype(SomeExternalInstance, SomeExternalInstance)): def union((ext1, ext2)): def commonsuperclass(cls1, cls2): cls = cls2 @@ -767,11 +767,11 @@ cls = cls.__bases__[0] return cls - from pypy.rpython.ootypesystem.bltregistry import BasicExternal, ExternalType - cls = commonsuperclass(ext1.knowntype._class_, ext2.knowntype._class_) + from pypy.rpython.ootypesystem.bltregistry import BasicExternal + cls = commonsuperclass(ext1.knowntype, ext2.knowntype) if cls is BasicExternal: return SomeObject() - return SomeExternalBuiltin(ExternalType(cls)) + return SomeExternalInstance(cls) # ____________________________________________________________ # annotation of low-level types Modified: pypy/dist/pypy/annotation/bookkeeper.py ============================================================================== --- pypy/dist/pypy/annotation/bookkeeper.py (original) +++ pypy/dist/pypy/annotation/bookkeeper.py Sat Jun 16 19:27:42 2007 @@ -558,9 +558,10 @@ try: return self.external_class_cache[class_] except KeyError: - from pypy.rpython.ootypesystem.bltregistry import ExternalType - next = ExternalType(class_) + from pypy.rpython.ootypesystem import bltregistry + next = bltregistry.ExternalInstanceDesc(class_) self.external_class_cache[class_] = next + next.setup() return next def pbc_getattr(self, pbc, s_attr): Modified: pypy/dist/pypy/annotation/model.py ============================================================================== --- pypy/dist/pypy/annotation/model.py (original) +++ pypy/dist/pypy/annotation/model.py Sat Jun 16 19:27:42 2007 @@ -445,12 +445,10 @@ def can_be_none(self): return True -class SomeExternalBuiltin(SomeExternalObject): +class SomeExternalInstance(SomeExternalObject): """Stands for an object of 'external' type, but with custom access to attributes as well as methods """ - def can_be_none(self): - return True class SomeCTypesObject(SomeExternalObject): """Stands for an object of the ctypes module.""" @@ -614,7 +612,7 @@ elif T == ootype.Class: return SomeOOClass(ootype.ROOT) elif isinstance(T, ExternalType): - return SomeExternalBuiltin(T) + return SomeExternalInstance(T._class_) else: return SomePtr(T) else: Modified: pypy/dist/pypy/annotation/test/test_annrpython.py ============================================================================== --- pypy/dist/pypy/annotation/test/test_annrpython.py (original) +++ pypy/dist/pypy/annotation/test/test_annrpython.py Sat Jun 16 19:27:42 2007 @@ -2712,7 +2712,7 @@ P.allow_someobjects = False a = self.RPythonAnnotator(policy=P) s = a.build_types(f, [bool]) - assert isinstance(s, annmodel.SomeExternalBuiltin) + assert isinstance(s, annmodel.SomeExternalInstance) def test_instance_with_flags(self): from pypy.rlib.jit import hint Modified: pypy/dist/pypy/annotation/unaryop.py ============================================================================== --- pypy/dist/pypy/annotation/unaryop.py (original) +++ pypy/dist/pypy/annotation/unaryop.py Sat Jun 16 19:27:42 2007 @@ -615,6 +615,7 @@ return self.s_result class __extend__(SomeExternalObject): + # XXX kill with extfunctable.py def find_method(obj, name): "Look for a special-case implementation for the named method." type_analyser = builtin.EXTERNAL_TYPE_ANALYZERS[obj.knowntype] @@ -623,9 +624,31 @@ return SomeBuiltin(analyser, obj, name) return SomeObject.find_method(obj, name) + def getattr(p, s_attr): + if s_attr.is_constant() and isinstance(s_attr.const, str): + # XXX kill with extfunctable.py + if p.knowntype in builtin.EXTERNAL_TYPE_ANALYZERS: + return SomeObject.getattr(p, s_attr) + + attr = s_attr.const + entry = extregistry.lookup_type(p.knowntype) + s_value = entry.get_field_annotation(p.knowntype, attr) + return s_value + else: + return SomeObject() + getattr.can_only_throw = [] + + def setattr(p, s_attr, s_value): + assert s_attr.is_constant() + attr = s_attr.const + entry = extregistry.lookup_type(p.knowntype) + entry.set_field_annotation(p.knowntype, attr, s_value) + + def is_true(p): + return s_Bool # annotation of low-level types -from pypy.annotation.model import SomePtr, SomeLLADTMeth, SomeExternalBuiltin +from pypy.annotation.model import SomePtr, SomeLLADTMeth from pypy.annotation.model import SomeOOInstance, SomeOOBoundMeth, SomeOOStaticMeth from pypy.annotation.model import ll_to_annotation, lltype_to_annotation, annotation_to_lltype @@ -663,29 +686,6 @@ def is_true(p): return s_Bool -class __extend__(SomeExternalBuiltin): - def getattr(p, s_attr): - if s_attr.is_constant() and isinstance(s_attr.const, str): - attr = s_attr.const - entry = extregistry.lookup_type(p.knowntype._class_) - s_value = entry.get_field_annotation(p.knowntype, attr) - return s_value - else: - return SomeObject() - getattr.can_only_throw = [] - - def setattr(p, s_attr, s_value): - assert s_attr.is_constant() - attr = s_attr.const - entry = extregistry.lookup_type(p.knowntype._class_) - entry.set_field_annotation(p.knowntype, attr, s_value) - - def find_method(obj, name): - return obj.knowntype.get_field(name) - - def is_true(p): - return s_Bool - class __extend__(SomeLLADTMeth): def call(adtmeth, args): Modified: pypy/dist/pypy/rpython/ootypesystem/bltregistry.py ============================================================================== --- pypy/dist/pypy/rpython/ootypesystem/bltregistry.py (original) +++ pypy/dist/pypy/rpython/ootypesystem/bltregistry.py Sat Jun 16 19:27:42 2007 @@ -119,117 +119,104 @@ assert expected.contains(res) return self.s_retval -class ExternalType(ootype.OOType): - class_dict = {} - __name__ = "ExternalType" - def __init__(self, _class): - self._class_ = _class - self._name = str(_class) - self._superclass = None - self._root = True - self.updated = False - self._data = frozendict(_class._fields), frozendict(_class._methods) - - def update_fields(self, _fields): - for i, val in _fields.iteritems(): - self._fields[i] = annotation(val) - - def _is_compatible(type2): - return type(type2) is ExternalType - +class ExternalInstanceDesc(object): - def __eq__(self, other): - return self.__class__ is other.__class__ and \ - self._class_ is other._class_ + def __init__(self, class_): + self._class_ = class_ - _is_compatible = staticmethod(_is_compatible) - - def update_methods(self, _methods): - _signs = {} + def setup(self): + _signs = self._methods = {} self._fields = {} - for i, val in _methods.iteritems(): + for i, val in self._class_._methods.iteritems(): retval = annotation(val.retval._type) values = [annotation(arg._type) for arg in val.args] s_args = [j for j in values] _signs[i] = MethodDesc(tuple(s_args), retval) - next = annmodel.SomeBuiltin(Analyzer(i, val, retval, s_args), s_self = annmodel.SomeExternalBuiltin(self), methodname = i) + next = annmodel.SomeBuiltin(Analyzer(i, val, retval, s_args), + s_self = annmodel.SomeExternalInstance(self._class_), + methodname = i) next.const = True self._fields[i] = next - self._methods = frozendict(_signs) - def __hash__(self): - return hash(self._name) - + for i, val in self._class_._fields.iteritems(): + self._fields[i] = annotation(val) + def set_field(self, attr, knowntype): - self.check_update() assert attr in self._fields field_ann = self._fields[attr] res = unionof(knowntype, field_ann) assert res.contains(knowntype) - def check_update(self): - if not self.updated: - _fields, _methods = self._data - self.update_methods(_methods) - self.update_fields(_fields) - self.updated = True - self._fields = frozendict(self._fields) - del self._data - def get_field(self, attr): - self.check_update() try: return self._fields[attr] except KeyError: from pypy.tool.error import NoSuchAttrError raise NoSuchAttrError("Basic external %s has no attribute %s" % (self._class_, attr)) - - def find_method(self, meth): - raise NotImplementedError() def __repr__(self): - return "%s %s" % (self.__name__, self._name) - - def _defl(self): - return _external_type(self, None) - -class _external_type(object): - - def __init__(self, et, value): - self._TYPE = et - self.value = value + return "<%s %s>" % (self.__class__.__name__, self._name) class Entry_basicexternalmeta(ExtRegistryEntry): _metatype_ = BasicMetaExternal def compute_annotation(self): - return annmodel.SomeExternalBuiltin(self.bookkeeper.getexternaldesc\ - (self.type)) - - def get_field_annotation(self, ext_obj, attr): - return ext_obj.get_field(attr) - - #def get_arg_annotation(self, ext_obj, attr, s_pbc): - # s_field = ext_obj.get_field(attr) - # res = unionof(s_field, s_pbc) - # assert s_field.contains(res) - # return s_field.args_s + return annmodel.SomeExternalInstance(self.type) - def set_field_annotation(self, ext_obj, attr, s_val): - ext_obj.set_field(attr, s_val) + def get_field_annotation(self, _, attr): + bk = getbookkeeper() + ext_desc = bk.getexternaldesc(self.type) + return ext_desc.get_field(attr) + + def set_field_annotation(self, _, attr, s_val): + bk = getbookkeeper() + ext_desc = bk.getexternaldesc(self.type) + ext_desc.set_field(attr, s_val) + + def get_repr(self, rtyper, s_extinst): + from pypy.rpython.ootypesystem import rbltregistry + return rbltregistry.ExternalInstanceRepr(rtyper, s_extinst.knowntype) class Entry_basicexternal(ExtRegistryEntry): _type_ = BasicExternal.__metaclass__ def compute_result_annotation(self): - if self.bookkeeper is None: - # XXX diverges from the cache - return annmodel.SomeExternalBuiltin(ExternalType(self.instance)) - return annmodel.SomeExternalBuiltin(self.bookkeeper.getexternaldesc(self.instance)) + return annmodel.SomeExternalInstance(self.instance) def specialize_call(self, hop): value = hop.r_result.lowleveltype return hop.genop('new', [Constant(value, concretetype=ootype.Void)], \ resulttype = value) + +class ExternalType(ootype.OOType): + + def __init__(self, class_): + self._class_ = class_ + self._name = str(class_) # xxx fragile + self._superclass = None + self._root = True + + def _is_compatible(type2): + return type(type2) is ExternalType + _is_compatible = staticmethod(_is_compatible) + + def __eq__(self, other): + return (self.__class__ is other.__class__ and + self._class_ is other._class_) + + def __hash__(self): + return hash(self._name) + + def _defl(self): + return _external_inst(self, None) + + def __str__(self): + return "%s(%s)" % (self.__class__.__name__, self._name) + +class _external_inst(object): + + def __init__(self, et, value): + self._TYPE = et + self.value = value Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py ============================================================================== --- pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py (original) +++ pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py Sat Jun 16 19:27:42 2007 @@ -22,8 +22,7 @@ a = RPythonAnnotator() s = a.build_types(new, []) - assert isinstance(s.knowntype, ExternalType) - assert s.knowntype._class_ is C + assert s.knowntype is C class A(BasicExternal): _fields = { Modified: pypy/dist/pypy/rpython/rexternalobj.py ============================================================================== --- pypy/dist/pypy/rpython/rexternalobj.py (original) +++ pypy/dist/pypy/rpython/rexternalobj.py Sat Jun 16 19:27:42 2007 @@ -15,6 +15,7 @@ class __extend__(annmodel.SomeExternalObject): def rtyper_makerepr(self, rtyper): + # XXX kill with extfunctable.py if self.knowntype in typetable: return ExternalObjRepr(self.knowntype) else: @@ -68,87 +69,3 @@ def rtype_is_true(self, hop): vlist = hop.inputargs(self) return hop.genop('ptr_nonzero', vlist, resulttype=lltype.Bool) - -# ExternalBuiltins - -class __extend__(annmodel.SomeExternalBuiltin): - - def rtyper_makerepr(self, rtyper): - return ExternalBuiltinRepr(self.knowntype) - - def rtyper_makekey(self): - return self.__class__, self.knowntype - -class ExternalBuiltinRepr(Repr): - def __init__(self, knowntype): - self.knowntype = knowntype - self.lowleveltype = knowntype - self.name = "" % self.knowntype._class_.__name__ - - def convert_const(self, value): - from pypy.rpython.ootypesystem.bltregistry import ExternalType,_external_type - return _external_type(self.knowntype, value) - - def rtype_getattr(self, hop): - self.knowntype.check_update() - attr = hop.args_s[1].const - s_inst = hop.args_s[0] - if self.knowntype._methods.has_key(attr): - # just return instance - will be handled by simple_call - return hop.inputarg(hop.args_r[0], arg=0) - vlist = hop.inputargs(self, ootype.Void) - return hop.genop("oogetfield", vlist, - resulttype = hop.r_result.lowleveltype) - - def rtype_setattr(self, hop): - if self.lowleveltype is ootype.Void: - return - vlist = [hop.inputarg(self, arg=0), hop.inputarg(ootype.Void, arg=1)] - field_name = hop.args_s[1].const - obj = self.knowntype._class_._fields[field_name] - bookkeeper = hop.rtyper.annotator.bookkeeper - # XXX WARNING XXX - # annotation() here should not be called, but we somehow - # have overwritten _fields. This will do no harm, but may hide some - # errors - r = hop.rtyper.getrepr(annotation(obj, bookkeeper)) - r.setup() - v = hop.inputarg(r, arg=2) - vlist.append(v) - return hop.genop('oosetfield', vlist) - - def call_method(self, name, hop): - bookkeeper = hop.rtyper.annotator.bookkeeper - args_r = [] - for s_arg in self.knowntype._fields[name].analyser.s_args: - r = hop.rtyper.getrepr(s_arg) - r.setup() - args_r.append(r) - vlist = hop.inputargs(self, *args_r) - c_name = hop.inputconst(ootype.Void, name) - hop.exception_is_here() - return hop.genop('oosend', [c_name] + vlist, resulttype=hop.r_result) - - def rtype_is_true(self, hop): - vlist = hop.inputargs(self) - return hop.genop('is_true', vlist, resulttype=lltype.Bool) - - def ll_str(self, val): - return ootype.oostring(self.name, -1) - - def __getattr__(self, attr): - if attr.startswith("rtype_method_"): - name = attr[len("rtype_method_"):] - return lambda hop: self.call_method(name, hop) - else: - raise AttributeError(attr) - - -class __extend__(pairtype(ExternalBuiltinRepr, ExternalBuiltinRepr)): - def convert_from_to((from_, to), v, llops): - type_from = from_.knowntype._class_ - type_to = to.knowntype._class_ - if issubclass(type_from, type_to): - v.concretetype=to.knowntype - return v - return NotImplemented Modified: pypy/dist/pypy/translator/js/database.py ============================================================================== --- pypy/dist/pypy/translator/js/database.py (original) +++ pypy/dist/pypy/translator/js/database.py Sat Jun 16 19:27:42 2007 @@ -232,7 +232,7 @@ return StringConst(db, const) elif isinstance(const, ootype._dict): return DictConst(db, const) - elif isinstance(const, bltregistry._external_type): + elif isinstance(const, bltregistry._external_inst): return ExtObject(db, const) elif isinstance(const, ootype._class): if const._INSTANCE: From arigo at codespeak.net Sat Jun 16 19:33:06 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sat, 16 Jun 2007 19:33:06 +0200 (CEST) Subject: [pypy-svn] r44311 - in pypy: branch/graphserver-dist dist/dotviewer dist/pypy/bin dist/pypy/jit dist/pypy/objspace dist/pypy/rlib/parsing dist/pypy/translator/goal dist/pypy/translator/tool Message-ID: <20070616173306.CE6C280C6@code0.codespeak.net> Author: arigo Date: Sat Jun 16 19:33:06 2007 New Revision: 44311 Added: pypy/dist/dotviewer/ - copied from r44310, pypy/branch/graphserver-dist/dotviewer/ pypy/dist/pypy/bin/dotviewer.py - copied unchanged from r44310, pypy/branch/graphserver-dist/pypy/bin/dotviewer.py pypy/dist/pypy/jit/ - copied from r44310, pypy/branch/graphserver-dist/pypy/jit/ pypy/dist/pypy/objspace/ - copied from r44310, pypy/branch/graphserver-dist/pypy/objspace/ pypy/dist/pypy/rlib/parsing/ - copied from r44310, pypy/branch/graphserver-dist/pypy/rlib/parsing/ pypy/dist/pypy/translator/goal/ - copied from r44310, pypy/branch/graphserver-dist/pypy/translator/goal/ pypy/dist/pypy/translator/tool/ - copied from r44310, pypy/branch/graphserver-dist/pypy/translator/tool/ Removed: pypy/branch/graphserver-dist/ Log: Merge the graphserver-dist branch. For description, see my mail "Pygame viewer" on pypy-dev. From pedronis at codespeak.net Sat Jun 16 19:37:29 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Sat, 16 Jun 2007 19:37:29 +0200 (CEST) Subject: [pypy-svn] r44312 - pypy/dist/pypy/annotation/test Message-ID: <20070616173729.E953380CD@code0.codespeak.net> Author: pedronis Date: Sat Jun 16 19:37:29 2007 New Revision: 44312 Modified: pypy/dist/pypy/annotation/test/test_signature.py Log: a skipped test about the broken interaction of genericallable and annotation()! Modified: pypy/dist/pypy/annotation/test/test_signature.py ============================================================================== --- pypy/dist/pypy/annotation/test/test_signature.py (original) +++ pypy/dist/pypy/annotation/test/test_signature.py Sat Jun 16 19:37:29 2007 @@ -1,5 +1,5 @@ - -from pypy.annotation.signature import _annotation_key +import py +from pypy.annotation.signature import _annotation_key, annotation def test__annotation_key(): assert _annotation_key([[str]]) == ('list', ('list', str)) @@ -7,3 +7,9 @@ for i in ([[str]], [str], (int, int, {str: [str]})): assert hash(_annotation_key(i)) +def test_genericcallable(): + py.test.skip("this two annotations should be equal - fix!") + from pypy.rpython.extfunc import genericcallable + s1 = annotation([genericcallable([str], int)]) + s2 = annotation([genericcallable([str], int)]) + assert s1 == s2 From fijal at codespeak.net Sun Jun 17 11:17:01 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sun, 17 Jun 2007 11:17:01 +0200 (CEST) Subject: [pypy-svn] r44315 - pypy/dist/pypy/doc/config Message-ID: <20070617091701.3B1AE80E9@code0.codespeak.net> Author: fijal Date: Sun Jun 17 11:16:59 2007 New Revision: 44315 Added: pypy/dist/pypy/doc/config/objspace.usemodules.termios.txt Log: Add missing file about --withmod-termios Added: pypy/dist/pypy/doc/config/objspace.usemodules.termios.txt ============================================================================== --- (empty file) +++ pypy/dist/pypy/doc/config/objspace.usemodules.termios.txt Sun Jun 17 11:16:59 2007 @@ -0,0 +1,2 @@ +Use the 'termios' module. +This module is expected to be fully working. From fijal at codespeak.net Sun Jun 17 13:49:07 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sun, 17 Jun 2007 13:49:07 +0200 (CEST) Subject: [pypy-svn] r44316 - pypy/dist/pypy/rpython/module Message-ID: <20070617114907.112C5806D@code0.codespeak.net> Author: fijal Date: Sun Jun 17 13:49:05 2007 New Revision: 44316 Modified: pypy/dist/pypy/rpython/module/ll_os.py Log: Make arguments float. This is just a bit of sugar, because we don't use utimes anyway Modified: pypy/dist/pypy/rpython/module/ll_os.py ============================================================================== --- pypy/dist/pypy/rpython/module/ll_os.py (original) +++ pypy/dist/pypy/rpython/module/ll_os.py Sun Jun 17 13:49:05 2007 @@ -103,13 +103,14 @@ # XXX does not use utimes, even when available l_path = rffi.str2charp(path) l_utimebuf = lltype.malloc(UTIMEBUFP.TO, flavor='raw') - l_utimebuf.c_actime, l_utimebuf.c_modtime = tp + actime, modtime = tp + l_utimebuf.c_actime, l_utimebuf.c_modtime = int(actime), int(modtime) error = ros_utime(l_path, l_utimebuf) lltype.free(l_path, flavor='raw') lltype.free(l_utimebuf, flavor='raw') if error == -1: raise OSError(rffi.c_errno, "utime_tuple failed") -register_external(ros.utime_tuple, [str, (int, int)], s_None, "ll_os.utime_tuple", +register_external(ros.utime_tuple, [str, (float, float)], s_None, "ll_os.utime_tuple", llimpl=utime_tuple_lltypeimpl) def fake_os_open(l_path, flags, mode): From fijal at codespeak.net Sun Jun 17 13:50:21 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sun, 17 Jun 2007 13:50:21 +0200 (CEST) Subject: [pypy-svn] r44317 - pypy/dist/pypy/module/posix Message-ID: <20070617115021.6F5B9807C@code0.codespeak.net> Author: fijal Date: Sun Jun 17 13:50:21 2007 New Revision: 44317 Modified: pypy/dist/pypy/module/posix/interp_posix.py Log: Accept float args as well Modified: pypy/dist/pypy/module/posix/interp_posix.py ============================================================================== --- pypy/dist/pypy/module/posix/interp_posix.py (original) +++ pypy/dist/pypy/module/posix/interp_posix.py Sun Jun 17 13:50:21 2007 @@ -487,8 +487,8 @@ args_w = space.unpackiterable(w_tuple) if len(args_w) != 2: raise OperationError(space.w_TypeError, space.wrap(msg)) - actime = space.int_w(args_w[0]) - modtime = space.int_w(args_w[1]) + actime = space.float_w(args_w[0]) + modtime = space.float_w(args_w[1]) ros.utime_tuple(path, (actime, modtime)) except OSError, e: raise wrap_oserror(space, e) From fijal at codespeak.net Sun Jun 17 14:49:48 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sun, 17 Jun 2007 14:49:48 +0200 (CEST) Subject: [pypy-svn] r44319 - pypy/dist/pypy/module/_curses/test Message-ID: <20070617124948.812DE80C8@code0.codespeak.net> Author: fijal Date: Sun Jun 17 14:49:46 2007 New Revision: 44319 Modified: pypy/dist/pypy/module/_curses/test/test_curses.py Log: Move all curses tests to use pexpect Modified: pypy/dist/pypy/module/_curses/test/test_curses.py ============================================================================== --- pypy/dist/pypy/module/_curses/test/test_curses.py (original) +++ pypy/dist/pypy/module/_curses/test/test_curses.py Sun Jun 17 14:49:46 2007 @@ -8,20 +8,6 @@ import py import sys -class AppTestCurses(object): - def setup_class(cls): - cls.space = gettestobjspace(usemodules=['_curses']) - - def test_tigetstr(self): - import _curses - _curses.setupterm() - assert _curses.tigetstr('cup') == '\x1b[%i%p1%d;%p2%dH' - - def test_tparm(self): - import _curses - _curses.setupterm() - assert _curses.tparm(_curses.tigetstr('cup'), 5, 3) == '\033[6;4H' - class TestCurses(object): """ We need to fork here, to prevent the setup to be done @@ -56,6 +42,31 @@ child = self.spawn(['--withmod-_curses', str(f)]) child.expect('ok!') + def test_tigetstr(self): + source = py.code.Source(""" + import _curses + _curses.setupterm() + assert _curses.tigetstr('cup') == '\x1b[%i%p1%d;%p2%dH' + print 'ok!' + """) + f = udir.join("test_tigetstr.py") + f.write(source) + child = self.spawn(['--withmod-_curses', str(f)]) + child.expect('ok!') + + def test_tparm(self): + source = py.code.Source(""" + import _curses + _curses.setupterm() + assert _curses.tparm(_curses.tigetstr('cup'), 5, 3) == '\033[6;4H' + print 'ok!' + """) + f = udir.join("test_tparm.py") + f.write(source) + child = self.spawn(['--withmod-_curses', str(f)]) + child.expect('ok!') + + # XXX probably we need to run all the stuff here in pexpect anyway... class TestCCurses(object): @@ -86,4 +97,3 @@ fn = compile(runs_tparm, []) fn(expected_extra_mallocs=-1) - From fijal at codespeak.net Sun Jun 17 15:00:08 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sun, 17 Jun 2007 15:00:08 +0200 (CEST) Subject: [pypy-svn] r44320 - pypy/dist/pypy/doc/config Message-ID: <20070617130008.F31B480CE@code0.codespeak.net> Author: fijal Date: Sun Jun 17 15:00:08 2007 New Revision: 44320 Added: pypy/dist/pypy/doc/config/objspace.usemodules._curses.txt Log: forgotten to add this one Added: pypy/dist/pypy/doc/config/objspace.usemodules._curses.txt ============================================================================== --- (empty file) +++ pypy/dist/pypy/doc/config/objspace.usemodules._curses.txt Sun Jun 17 15:00:08 2007 @@ -0,0 +1,2 @@ +Use the '_curses' module. +This module is just a stub. From fijal at codespeak.net Sun Jun 17 16:17:08 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sun, 17 Jun 2007 16:17:08 +0200 (CEST) Subject: [pypy-svn] r44321 - pypy/dist/pypy/config Message-ID: <20070617141708.2B6E580DD@code0.codespeak.net> Author: fijal Date: Sun Jun 17 16:17:06 2007 New Revision: 44321 Modified: pypy/dist/pypy/config/pypyoption.py Log: add termios to allworkingmodules Modified: pypy/dist/pypy/config/pypyoption.py ============================================================================== --- pypy/dist/pypy/config/pypyoption.py (original) +++ pypy/dist/pypy/config/pypyoption.py Sun Jun 17 16:17:06 2007 @@ -23,7 +23,7 @@ working_modules = default_modules.copy() working_modules.update(dict.fromkeys( ["_socket", "unicodedata", "mmap", "fcntl", "rctime", "select", - "crypt", "signal", "dyngram", "readline", + "crypt", "signal", "dyngram", "readline", "termios" ] )) From fijal at codespeak.net Sun Jun 17 20:26:38 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sun, 17 Jun 2007 20:26:38 +0200 (CEST) Subject: [pypy-svn] r44324 - in pypy/dist/pypy/module/_curses: . test Message-ID: <20070617182638.6175A80C0@code0.codespeak.net> Author: fijal Date: Sun Jun 17 20:26:36 2007 New Revision: 44324 Modified: pypy/dist/pypy/module/_curses/fficurses.py pypy/dist/pypy/module/_curses/test/test_curses.py Log: Seems that this string is not meant to be freed. man says nothing... Modified: pypy/dist/pypy/module/_curses/fficurses.py ============================================================================== --- pypy/dist/pypy/module/_curses/fficurses.py (original) +++ pypy/dist/pypy/module/_curses/fficurses.py Sun Jun 17 20:26:36 2007 @@ -91,7 +91,6 @@ l[7], l[8], l[9]) lltype.free(ll_s, flavor='raw') res = rffi.charp2str(ll_res) - lltype.free(ll_res, flavor='raw') return res register_external(interp_curses._curses_tparm, [str, [int]], str, Modified: pypy/dist/pypy/module/_curses/test/test_curses.py ============================================================================== --- pypy/dist/pypy/module/_curses/test/test_curses.py (original) +++ pypy/dist/pypy/module/_curses/test/test_curses.py Sun Jun 17 20:26:36 2007 @@ -96,4 +96,4 @@ assert res == '\033[6;4H' fn = compile(runs_tparm, []) - fn(expected_extra_mallocs=-1) + fn() From fijal at codespeak.net Sun Jun 17 22:22:31 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sun, 17 Jun 2007 22:22:31 +0200 (CEST) Subject: [pypy-svn] r44326 - pypy/dist/pypy/objspace/std/test Message-ID: <20070617202231.698DA80D0@code0.codespeak.net> Author: fijal Date: Sun Jun 17 22:22:24 2007 New Revision: 44326 Modified: pypy/dist/pypy/objspace/std/test/test_stringobject.py Log: Add a failing stringobject test Modified: pypy/dist/pypy/objspace/std/test/test_stringobject.py ============================================================================== --- pypy/dist/pypy/objspace/std/test/test_stringobject.py (original) +++ pypy/dist/pypy/objspace/std/test/test_stringobject.py Sun Jun 17 22:22:24 2007 @@ -679,6 +679,9 @@ assert type(s.center(3)) is str assert type(s.splitlines()[0]) is str + def test_unicode_startswith(self): + skip("failing") + assert 'xxx'.startswith(u'x') class AppTestPrebuilt(AppTestStringObject): def setup_class(cls): From fijal at codespeak.net Mon Jun 18 11:39:25 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 18 Jun 2007 11:39:25 +0200 (CEST) Subject: [pypy-svn] r44329 - pypy/dist/pypy/objspace/std/test Message-ID: <20070618093925.0F6EA80D8@code0.codespeak.net> Author: fijal Date: Mon Jun 18 11:39:20 2007 New Revision: 44329 Modified: pypy/dist/pypy/objspace/std/test/test_stringobject.py Log: Make str/unicode interaction (failing) test a bit more elaborate Modified: pypy/dist/pypy/objspace/std/test/test_stringobject.py ============================================================================== --- pypy/dist/pypy/objspace/std/test/test_stringobject.py (original) +++ pypy/dist/pypy/objspace/std/test/test_stringobject.py Mon Jun 18 11:39:20 2007 @@ -679,9 +679,17 @@ assert type(s.center(3)) is str assert type(s.splitlines()[0]) is str - def test_unicode_startswith(self): + def test_str_unicode_interchangeable(self): skip("failing") - assert 'xxx'.startswith(u'x') + stuff = ['xxxxx', u'xxxxx'] + for x in stuff: + for y in stuff: + assert x.startswith(y) + assert x.endswith(y) + assert x.count(y) == 1 + assert x.find(y) != -1 + assert x.index(y) == 0 + # ... to be continued once this passes class AppTestPrebuilt(AppTestStringObject): def setup_class(cls): From pedronis at codespeak.net Mon Jun 18 13:40:14 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Mon, 18 Jun 2007 13:40:14 +0200 (CEST) Subject: [pypy-svn] r44337 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070618114014.B2CB980C3@code0.codespeak.net> Author: pedronis Date: Mon Jun 18 13:40:09 2007 New Revision: 44337 Added: pypy/extradoc/sprintinfo/post-ep2007/ Log: directory for the post ep 2007 sprint From afa at codespeak.net Mon Jun 18 13:42:07 2007 From: afa at codespeak.net (afa at codespeak.net) Date: Mon, 18 Jun 2007 13:42:07 +0200 (CEST) Subject: [pypy-svn] r44338 - pypy/dist/pypy/rpython/lltypesystem Message-ID: <20070618114207.BDBF98071@code0.codespeak.net> Author: afa Date: Mon Jun 18 13:42:07 2007 New Revision: 44338 Modified: pypy/dist/pypy/rpython/lltypesystem/rfficache.py Log: Quick hack for win32, where mode_t is not defined. All the tests were failing... Modified: pypy/dist/pypy/rpython/lltypesystem/rfficache.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/rfficache.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/rfficache.py Mon Jun 18 13:42:07 2007 @@ -16,6 +16,9 @@ c_source = py.code.Source(''' // includes %s + #ifdef _WIN32 + typedef int mode_t; + #endif // checking code int main(void) From afa at codespeak.net Mon Jun 18 13:45:14 2007 From: afa at codespeak.net (afa at codespeak.net) Date: Mon, 18 Jun 2007 13:45:14 +0200 (CEST) Subject: [pypy-svn] r44339 - pypy/dist/pypy/rpython/module Message-ID: <20070618114514.810DD80C3@code0.codespeak.net> Author: afa Date: Mon Jun 18 13:45:14 2007 New Revision: 44339 Modified: pypy/dist/pypy/rpython/module/ll_os.py Log: os.WIFSIGNALED does not exists on win32. Most tests now pass again. Modified: pypy/dist/pypy/rpython/module/ll_os.py ============================================================================== --- pypy/dist/pypy/rpython/module/ll_os.py (original) +++ pypy/dist/pypy/rpython/module/ll_os.py Mon Jun 18 13:45:14 2007 @@ -135,17 +135,19 @@ register_external(os.open, [str, int, int], int, "ll_os.ll_os_open", llimpl=os_open_lltypeimpl, oofakeimpl=os_open_oofakeimpl) -def fake_WIFSIGNALED(status): - return int(os.WIFSIGNALED(status)) +if hasattr(os, 'WIFSIGNALED'): + def fake_WIFSIGNALED(status): + return int(os.WIFSIGNALED(status)) + + os_WIFSIGNALED = rffi.llexternal('WIFSIGNALED', [lltype.Signed], + lltype.Signed, + _callable=fake_WIFSIGNALED) -os_WIFSIGNALED = rffi.llexternal('WIFSIGNALED', [lltype.Signed], lltype.Signed, - _callable=fake_WIFSIGNALED) + def WIFSIGNALED_lltypeimpl(status): + return bool(os_WIFSIGNALED(status)) -def WIFSIGNALED_lltypeimpl(status): - return bool(os_WIFSIGNALED(status)) - -register_external(os.WIFSIGNALED, [int], bool, "ll_os.WIFSIGNALED", - llimpl=WIFSIGNALED_lltypeimpl) + register_external(os.WIFSIGNALED, [int], bool, "ll_os.WIFSIGNALED", + llimpl=WIFSIGNALED_lltypeimpl) class BaseOS: __metaclass__ = ClassMethods From pedronis at codespeak.net Mon Jun 18 13:59:09 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Mon, 18 Jun 2007 13:59:09 +0200 (CEST) Subject: [pypy-svn] r44340 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070618115909.5321480A2@code0.codespeak.net> Author: pedronis Date: Mon Jun 18 13:59:07 2007 New Revision: 44340 Added: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt (contents, props changed) Log: checking in bea's draft with some initial tweaks and fixes Added: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt ============================================================================== --- (empty file) +++ pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Mon Jun 18 13:59:07 2007 @@ -0,0 +1,66 @@ +Vilnius/Post EuroPython PyPy Sprint 12-14th of July +======================================================== + +The PyPy team is sprinting at EuroPython again and we invite +you to participate in our 3 day long sprint at the conference hotel +- Reval Hotel Lietuva. + +If you plan to attend the sprint we recommend you to listen to the PyPy +technical talks (`ep schedule`_) during the +conference since it will give you a good overview of the status of development. + +.. _`ep schedule`: http://indico.cern.ch/conferenceTimeTable.py?confId=13919&showDate=all&showSession=all&detailLevel=contribution&viewMode=room + +On the morning if the first sprint day (12th) we will also have a +tutorial session for those new to PyPy development. + +There are many possible and interesting sprint topics to work on - here +we list some possible task areas: + +* completing the missing python 2.5 features and support +* identify slow areas of PyPy through benchmarking and work on improvements, + possibly moving app-level parts of the Python interpreter to interp-level + if useful. +* there are some parts of PyPy in need of refactoring, we may spend some time + on those, for example: + + - rctypes and the extension compiler need some rethinking + - support for LLVM 2.0 for th llvm backend + - ... + +* some JIT improvement work +* port the stackless transform to ootypesystem +* other interesting stuff that you would like to work on ...;-) + +Registration +---------------------- + +If you?d like to come, please subscribe to the `pypy-sprint mailing list`_ +and drop a note about your interests and post any questions. More +organisational information will be sent to that list. We?ll keep +a list of `people`_ which we?ll update (which you can do so yourself +if you have codespeak commit rights, let us now if you need it). + +Preparation (if you feel it is needed): +--------------------------------------- + +* read the `getting-started`_ pages on http://codespeak.net/pypy + +* for inspiration, overview and technical status you are welcome to + read `the technical reports available and other relevant documentation`_ + +* please direct any technical and/or development oriented questions to + pypy-dev at codespeak.net and any sprint organizing/logistical + questions to pypy-sprint at codespeak.net + +* if you need information about the conference, potential hotels, + directions etc we recommend to look at www.europython.org. + +We'll meet at the Vilnius Post EuroPython PyPy sprint! + +The PyPy team + +.. _getting-started: http://codespeak.net/pypy/dist/pypy/doc/getting-started.html +.. _`pypy-sprint mailing list`: http://codespeak.net/mailman/listinfo/pypy-sprint +.. _`people`: people.html +.. _`the technical reports available and other relevant documentation`: http://codespeak.net/pypy/dist/pypy/doc/index.html \ No newline at end of file From pedronis at codespeak.net Mon Jun 18 14:24:00 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Mon, 18 Jun 2007 14:24:00 +0200 (CEST) Subject: [pypy-svn] r44341 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070618122400.DCF5B80CE@code0.codespeak.net> Author: pedronis Date: Mon Jun 18 14:23:54 2007 New Revision: 44341 Added: pypy/extradoc/sprintinfo/post-ep2007/people.txt - copied, changed from r44328, pypy/extradoc/sprintinfo/trillke-2007/people.txt Log: people file to fill in From fijal at codespeak.net Mon Jun 18 18:01:30 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 18 Jun 2007 18:01:30 +0200 (CEST) Subject: [pypy-svn] r44342 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070618160130.C376780E2@code0.codespeak.net> Author: fijal Date: Mon Jun 18 18:01:29 2007 New Revision: 44342 Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt Log: Added myself Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/people.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/people.txt Mon Jun 18 18:01:29 2007 @@ -9,7 +9,7 @@ ==================== ============== ===================== Name Arrive/Depart Accomodation ==================== ============== ===================== - +Maciej Fijalkowski 5/14th Some hostel ==================== ============== ===================== People on the following list were present at previous sprints: @@ -26,7 +26,6 @@ Richard Emslie ? ? Alexander Schremmer ? ? Georg Brandl ? ? -Maciej Fijalkowski ? ? Guido Wesdorp ? ? Carl Friedrich Bolz ? ? Armin Rigo ? ? From fijal at codespeak.net Mon Jun 18 19:14:42 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 18 Jun 2007 19:14:42 +0200 (CEST) Subject: [pypy-svn] r44343 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070618171442.C061A80DF@code0.codespeak.net> Author: fijal Date: Mon Jun 18 19:14:41 2007 New Revision: 44343 Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Log: typo Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/announcement.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Mon Jun 18 19:14:41 2007 @@ -25,7 +25,7 @@ on those, for example: - rctypes and the extension compiler need some rethinking - - support for LLVM 2.0 for th llvm backend + - support for LLVM 2.0 for the llvm backend - ... * some JIT improvement work From arigo at codespeak.net Mon Jun 18 19:47:40 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 18 Jun 2007 19:47:40 +0200 (CEST) Subject: [pypy-svn] r44345 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070618174740.5BAEB80D8@code0.codespeak.net> Author: arigo Date: Mon Jun 18 19:47:40 2007 New Revision: 44345 Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Log: * mention extension modules and zlib. * typos Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/announcement.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Mon Jun 18 19:47:40 2007 @@ -11,15 +11,16 @@ .. _`ep schedule`: http://indico.cern.ch/conferenceTimeTable.py?confId=13919&showDate=all&showSession=all&detailLevel=contribution&viewMode=room -On the morning if the first sprint day (12th) we will also have a +On the morning of the first sprint day (12th) we will also have a tutorial session for those new to PyPy development. There are many possible and interesting sprint topics to work on - here we list some possible task areas: * completing the missing python 2.5 features and support +* write or port more extension modules (e.g. zlib is missing) * identify slow areas of PyPy through benchmarking and work on improvements, - possibly moving app-level parts of the Python interpreter to interp-level + possibly moving app-level parts of the Python interpreter to interp-level if useful. * there are some parts of PyPy in need of refactoring, we may spend some time on those, for example: @@ -39,7 +40,7 @@ and drop a note about your interests and post any questions. More organisational information will be sent to that list. We?ll keep a list of `people`_ which we?ll update (which you can do so yourself -if you have codespeak commit rights, let us now if you need it). +if you have codespeak commit rights; let us now if you need it). Preparation (if you feel it is needed): --------------------------------------- @@ -63,4 +64,4 @@ .. _getting-started: http://codespeak.net/pypy/dist/pypy/doc/getting-started.html .. _`pypy-sprint mailing list`: http://codespeak.net/mailman/listinfo/pypy-sprint .. _`people`: people.html -.. _`the technical reports available and other relevant documentation`: http://codespeak.net/pypy/dist/pypy/doc/index.html \ No newline at end of file +.. _`the technical reports available and other relevant documentation`: http://codespeak.net/pypy/dist/pypy/doc/index.html From fijal at codespeak.net Mon Jun 18 19:52:08 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 18 Jun 2007 19:52:08 +0200 (CEST) Subject: [pypy-svn] r44346 - pypy/dist/pypy/translator/jvm/test Message-ID: <20070618175208.C774480DB@code0.codespeak.net> Author: fijal Date: Mon Jun 18 19:52:08 2007 New Revision: 44346 Modified: pypy/dist/pypy/translator/jvm/test/test_int.py Log: A trick to allow py.test -k Modified: pypy/dist/pypy/translator/jvm/test/test_int.py ============================================================================== --- pypy/dist/pypy/translator/jvm/test/test_int.py (original) +++ pypy/dist/pypy/translator/jvm/test/test_int.py Mon Jun 18 19:52:08 2007 @@ -2,6 +2,8 @@ from pypy.translator.jvm.test.runtest import JvmTest from pypy.rpython.test.test_rint import BaseTestRint +# ====> ../../../rpython/test/test_rint.py + class TestJvmInt(JvmTest, BaseTestRint): def test_char_constant(self): def dummyfn(i): From pedronis at codespeak.net Mon Jun 18 20:02:20 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Mon, 18 Jun 2007 20:02:20 +0200 (CEST) Subject: [pypy-svn] r44347 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070618180220.5835680E2@code0.codespeak.net> Author: pedronis Date: Mon Jun 18 20:02:19 2007 New Revision: 44347 Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Log: some other typos and strange chars Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/announcement.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Mon Jun 18 20:02:19 2007 @@ -38,9 +38,9 @@ If you?d like to come, please subscribe to the `pypy-sprint mailing list`_ and drop a note about your interests and post any questions. More -organisational information will be sent to that list. We?ll keep -a list of `people`_ which we?ll update (which you can do so yourself -if you have codespeak commit rights; let us now if you need it). +organisational information will be sent to that list. We'll keep +a list of `people`_ which we'll update (which you can do so yourself +if you have codespeak commit rights; let us know if you need it). Preparation (if you feel it is needed): --------------------------------------- From arigo at codespeak.net Mon Jun 18 20:25:33 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 18 Jun 2007 20:25:33 +0200 (CEST) Subject: [pypy-svn] r44348 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070618182533.69C7E80E9@code0.codespeak.net> Author: arigo Date: Mon Jun 18 20:25:33 2007 New Revision: 44348 Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Log: Formatting. Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/announcement.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Mon Jun 18 20:25:33 2007 @@ -1,3 +1,4 @@ +======================================================== Vilnius/Post EuroPython PyPy Sprint 12-14th of July ======================================================== @@ -14,6 +15,10 @@ On the morning of the first sprint day (12th) we will also have a tutorial session for those new to PyPy development. +------------------------------ +Goals and topics of the sprint +------------------------------ + There are many possible and interesting sprint topics to work on - here we list some possible task areas: @@ -33,8 +38,9 @@ * port the stackless transform to ootypesystem * other interesting stuff that you would like to work on ...;-) +------------ Registration ----------------------- +------------ If you?d like to come, please subscribe to the `pypy-sprint mailing list`_ and drop a note about your interests and post any questions. More @@ -42,6 +48,7 @@ a list of `people`_ which we'll update (which you can do so yourself if you have codespeak commit rights; let us know if you need it). +--------------------------------------- Preparation (if you feel it is needed): --------------------------------------- @@ -57,10 +64,13 @@ * if you need information about the conference, potential hotels, directions etc we recommend to look at www.europython.org. -We'll meet at the Vilnius Post EuroPython PyPy sprint! + +We are looking forward to meet you at the Vilnius Post EuroPython +PyPy sprint! The PyPy team + .. _getting-started: http://codespeak.net/pypy/dist/pypy/doc/getting-started.html .. _`pypy-sprint mailing list`: http://codespeak.net/mailman/listinfo/pypy-sprint .. _`people`: people.html From antocuni at codespeak.net Mon Jun 18 20:55:03 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Mon, 18 Jun 2007 20:55:03 +0200 (CEST) Subject: [pypy-svn] r44349 - in pypy/dist/pypy/translator/jvm: . test Message-ID: <20070618185503.2351C80E6@code0.codespeak.net> Author: antocuni Date: Mon Jun 18 20:54:57 2007 New Revision: 44349 Modified: pypy/dist/pypy/translator/jvm/generator.py pypy/dist/pypy/translator/jvm/test/test_int.py Log: (antocuni, pdg) a typo, but it took a bit to find it Modified: pypy/dist/pypy/translator/jvm/generator.py ============================================================================== --- pypy/dist/pypy/translator/jvm/generator.py (original) +++ pypy/dist/pypy/translator/jvm/generator.py Mon Jun 18 20:54:57 2007 @@ -188,7 +188,7 @@ ACONST_NULL=Opcode('aconst_null') DCONST_0 = Opcode('dconst_0') DCONST_1 = Opcode('dconst_0') -LCONST_0 = Opcode('lconst_1') +LCONST_0 = Opcode('lconst_0') LCONST_1 = Opcode('lconst_1') GETFIELD = Opcode('getfield') PUTFIELD = Opcode('putfield') Modified: pypy/dist/pypy/translator/jvm/test/test_int.py ============================================================================== --- pypy/dist/pypy/translator/jvm/test/test_int.py (original) +++ pypy/dist/pypy/translator/jvm/test/test_int.py Mon Jun 18 20:54:57 2007 @@ -18,12 +18,9 @@ def test_rarithmetic(self): pass # does this make more sense in jvm - - def test_specializing_int_functions(self): - py.test.skip("Error with longlong precision results in 2 == 1") - + def test_float_conversion_implicit(self): - py.test.skip("Error with longlong precision results in 2 == 1") + py.test.skip("JVM backend lacks appropriate percision") def test_neg_abs_ovf(self): py.test.skip("Unaware how to handle overflow") From antocuni at codespeak.net Mon Jun 18 20:57:20 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Mon, 18 Jun 2007 20:57:20 +0200 (CEST) Subject: [pypy-svn] r44350 - pypy/dist/pypy/translator/jvm Message-ID: <20070618185720.BCDA280CE@code0.codespeak.net> Author: antocuni Date: Mon Jun 18 20:57:20 2007 New Revision: 44350 Modified: pypy/dist/pypy/translator/jvm/generator.py Log: (pdg) another typo Modified: pypy/dist/pypy/translator/jvm/generator.py ============================================================================== --- pypy/dist/pypy/translator/jvm/generator.py (original) +++ pypy/dist/pypy/translator/jvm/generator.py Mon Jun 18 20:57:20 2007 @@ -187,7 +187,7 @@ 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_0') +DCONST_1 = Opcode('dconst_1') LCONST_0 = Opcode('lconst_0') LCONST_1 = Opcode('lconst_1') GETFIELD = Opcode('getfield') From antocuni at codespeak.net Mon Jun 18 21:00:36 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Mon, 18 Jun 2007 21:00:36 +0200 (CEST) Subject: [pypy-svn] r44351 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070618190036.3028F80E5@code0.codespeak.net> Author: antocuni Date: Mon Jun 18 21:00:30 2007 New Revision: 44351 Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt Log: added myself Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/people.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/people.txt Mon Jun 18 21:00:30 2007 @@ -10,6 +10,7 @@ Name Arrive/Depart Accomodation ==================== ============== ===================== Maciej Fijalkowski 5/14th Some hostel +Antonio Cuni 8/15th Same as Maciek :-) ==================== ============== ===================== People on the following list were present at previous sprints: @@ -22,7 +23,6 @@ Anders Chrigstr?m ? ? Christian Tismer ? ? Michael Hudson ? ? -Antonio Cuni ? ? Richard Emslie ? ? Alexander Schremmer ? ? Georg Brandl ? ? From santagada at codespeak.net Mon Jun 18 22:12:45 2007 From: santagada at codespeak.net (santagada at codespeak.net) Date: Mon, 18 Jun 2007 22:12:45 +0200 (CEST) Subject: [pypy-svn] r44352 - pypy/dist/pypy/translator/jvm/test Message-ID: <20070618201245.938EB80E2@code0.codespeak.net> Author: santagada Date: Mon Jun 18 22:12:44 2007 New Revision: 44352 Modified: pypy/dist/pypy/translator/jvm/test/test_int.py Log: another typo, I saw this one in the commit logs for antonio Modified: pypy/dist/pypy/translator/jvm/test/test_int.py ============================================================================== --- pypy/dist/pypy/translator/jvm/test/test_int.py (original) +++ pypy/dist/pypy/translator/jvm/test/test_int.py Mon Jun 18 22:12:44 2007 @@ -20,7 +20,7 @@ pass # does this make more sense in jvm def test_float_conversion_implicit(self): - py.test.skip("JVM backend lacks appropriate percision") + py.test.skip("JVM backend lacks appropriate precision") def test_neg_abs_ovf(self): py.test.skip("Unaware how to handle overflow") From cfbolz at codespeak.net Mon Jun 18 23:59:01 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 18 Jun 2007 23:59:01 +0200 (CEST) Subject: [pypy-svn] r44353 - pypy/dist/pypy/rlib/parsing Message-ID: <20070618215901.2C3B78091@code0.codespeak.net> Author: cfbolz Date: Mon Jun 18 23:58:59 2007 New Revision: 44353 Modified: pypy/dist/pypy/rlib/parsing/ebnfparse.py Log: huh? Modified: pypy/dist/pypy/rlib/parsing/ebnfparse.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/ebnfparse.py (original) +++ pypy/dist/pypy/rlib/parsing/ebnfparse.py Mon Jun 18 23:58:59 2007 @@ -42,7 +42,6 @@ lexer = Lexer(regexs1 + list(regexs2), names1 + list(names2), ignore=['IGNORE']) parser = PackratParser(rules, "file") - transformer return parser, lexer, transformer def parse_ebnf(s): From cfbolz at codespeak.net Tue Jun 19 00:11:09 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Tue, 19 Jun 2007 00:11:09 +0200 (CEST) Subject: [pypy-svn] r44355 - pypy/dist/pypy/rlib/parsing Message-ID: <20070618221109.0234380DF@code0.codespeak.net> Author: cfbolz Date: Tue Jun 19 00:11:09 2007 New Revision: 44355 Modified: pypy/dist/pypy/rlib/parsing/tree.py Log: adjust the tree support a bit to allow non-tree things to appear in a tree Modified: pypy/dist/pypy/rlib/parsing/tree.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/tree.py (original) +++ pypy/dist/pypy/rlib/parsing/tree.py Tue Jun 19 00:11:09 2007 @@ -52,8 +52,13 @@ yield '"%s" [label="%s"];' % (id(self), self.symbol) for child in self.children: yield '"%s" -> "%s";' % (id(self), id(child)) - for line in child.dot(): - yield line + if isinstance(child, Node): + for line in child.dot(): + yield line + else: + yield '"%s" [label="%s"];' % ( + id(child), + repr(child).replace('"', '').replace("\\", "\\\\")) def visit(self, visitor): "NOT_RPYTHON" @@ -86,22 +91,16 @@ if node.symbol not in dispatch_table: if __general_nonterminal_visit: return __general_nonterminal_visit(self, node) - elif __general_visit: - return __general_visit(self, node) - else: - raise VisitError(node) else: return dispatch_table[node.symbol](self, node) - if isinstance(node, Symbol): + elif isinstance(node, Symbol): if node.symbol not in dispatch_table: if __general_symbol_visit: return __general_symbol_visit(self, node) - elif __general_visit: - return __general_visit(self, node) - else: - raise VisitError(node) else: return dispatch_table[node.symbol](self, node) + if __general_visit: + return __general_visit(self, node) raise VisitError(node) return dispatch From pdg at codespeak.net Tue Jun 19 02:40:34 2007 From: pdg at codespeak.net (pdg at codespeak.net) Date: Tue, 19 Jun 2007 02:40:34 +0200 (CEST) Subject: [pypy-svn] r44356 - in pypy/dist/pypy/translator/jvm: . test Message-ID: <20070619004034.2869480F1@code0.codespeak.net> Author: pdg Date: Tue Jun 19 02:40:33 2007 New Revision: 44356 Modified: pypy/dist/pypy/translator/jvm/opcodes.py pypy/dist/pypy/translator/jvm/test/test_float.py pypy/dist/pypy/translator/jvm/test/test_int.py Log: translator/jvm - updated opcodes for preliminary ovf work; updated tests from the bugs anto helped fix today (pdg) Modified: pypy/dist/pypy/translator/jvm/opcodes.py ============================================================================== --- pypy/dist/pypy/translator/jvm/opcodes.py (original) +++ pypy/dist/pypy/translator/jvm/opcodes.py Tue Jun 19 02:40:33 2007 @@ -34,6 +34,18 @@ def _check_ovf(op): # TODO return op + +def _check_unary_ovf(op): + # TODO We should just use rlib's overflow dtection + # Assume LLONG_MIN = (- LLONG_MAX-1) +# if op.operand == LLONG_MIN: +# return [TranslateException( +# jvmtype.jArithmeticException, +# 'throwOverflowError', +# _proc(op))] +# else: +# return op + return op # This table maps the opcodes to micro-ops for processing them. # It is post-processed by _proc. Modified: pypy/dist/pypy/translator/jvm/test/test_float.py ============================================================================== --- pypy/dist/pypy/translator/jvm/test/test_float.py (original) +++ pypy/dist/pypy/translator/jvm/test/test_float.py Tue Jun 19 02:40:33 2007 @@ -25,7 +25,7 @@ py.test.skip("JVM backend unknown opcode float_pow") def test_float_constant_conversions(self): - py.test.skip("JVM backend lacks appropriate percision") + py.test.skip("JVM backend lacks appropriate percision; 42.000000614400001 == 42.0") def test_from_r_uint(self): py.test.skip("JVM backend lacks appropriate percision") Modified: pypy/dist/pypy/translator/jvm/test/test_int.py ============================================================================== --- pypy/dist/pypy/translator/jvm/test/test_int.py (original) +++ pypy/dist/pypy/translator/jvm/test/test_int.py Tue Jun 19 02:40:33 2007 @@ -18,9 +18,6 @@ def test_rarithmetic(self): pass # does this make more sense in jvm - - def test_float_conversion_implicit(self): - py.test.skip("JVM backend lacks appropriate precision") def test_neg_abs_ovf(self): py.test.skip("Unaware how to handle overflow") From pedronis at codespeak.net Tue Jun 19 09:35:22 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Tue, 19 Jun 2007 09:35:22 +0200 (CEST) Subject: [pypy-svn] r44357 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070619073522.3D48380DD@code0.codespeak.net> Author: pedronis Date: Tue Jun 19 09:35:20 2007 New Revision: 44357 Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt Log: my info, add sprint dates to the title section Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/people.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/people.txt Tue Jun 19 09:35:20 2007 @@ -1,17 +1,18 @@ -People coming to the Post EuroPython Sprint (Vilnius) 2007 -============================================================= +People coming to the Post EuroPython Sprint (Vilnius) 12-14 July 2007 +====================================================================== People who have a ``?`` in their arrive/depart or accomodation column are known to be coming but there are no details available yet from them. -==================== ============== ===================== +==================== ============== ======================= Name Arrive/Depart Accomodation -==================== ============== ===================== +==================== ============== ======================= Maciej Fijalkowski 5/14th Some hostel Antonio Cuni 8/15th Same as Maciek :-) -==================== ============== ===================== +Samuele Pedroni 7/14th Ratonda Centrum Hotels +==================== ============== ======================= People on the following list were present at previous sprints: @@ -19,7 +20,6 @@ Name Arrive/Depart Accomodation ==================== ============== ===================== Beatrice Duering ? ? -Samuele Pedroni ? ? Anders Chrigstr?m ? ? Christian Tismer ? ? Michael Hudson ? ? From fijal at codespeak.net Tue Jun 19 10:30:42 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 19 Jun 2007 10:30:42 +0200 (CEST) Subject: [pypy-svn] r44359 - pypy/dist/pypy/rpython/lltypesystem Message-ID: <20070619083042.01CAA80E6@code0.codespeak.net> Author: fijal Date: Tue Jun 19 10:30:41 2007 New Revision: 44359 Modified: pypy/dist/pypy/rpython/lltypesystem/rfficache.py Log: Don't cheat anymore and solve win32 issue properly. Modified: pypy/dist/pypy/rpython/lltypesystem/rfficache.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/rfficache.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/rfficache.py Tue Jun 19 10:30:41 2007 @@ -5,6 +5,7 @@ import py import os +import sys from pypy.translator.tool.cbuild import build_executable from subprocess import PIPE, Popen from pypy.tool.udir import udir @@ -16,9 +17,6 @@ c_source = py.code.Source(''' // includes %s - #ifdef _WIN32 - typedef int mode_t; - #endif // checking code int main(void) @@ -48,7 +46,9 @@ for _name in 'char short int long'.split(): for name in (_name, 'unsigned ' + _name): TYPES.append(name) -TYPES += ['long long', 'unsigned long long', 'size_t', 'mode_t'] +TYPES += ['long long', 'unsigned long long', 'size_t'] +if os.name == 'posix': + TYPES.append('mode_t') def newline_repr(d): assert isinstance(d, dict) From fijal at codespeak.net Tue Jun 19 10:42:30 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 19 Jun 2007 10:42:30 +0200 (CEST) Subject: [pypy-svn] r44361 - in pypy/dist/pypy/rpython: lltypesystem module Message-ID: <20070619084230.9B0B180DB@code0.codespeak.net> Author: fijal Date: Tue Jun 19 10:42:30 2007 New Revision: 44361 Modified: pypy/dist/pypy/rpython/lltypesystem/rfficache.py pypy/dist/pypy/rpython/module/ll_os.py Log: A bit better fix to deal with mode_t, need windows tester. Modified: pypy/dist/pypy/rpython/lltypesystem/rfficache.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/rfficache.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/rfficache.py Tue Jun 19 10:42:30 2007 @@ -47,7 +47,7 @@ for name in (_name, 'unsigned ' + _name): TYPES.append(name) TYPES += ['long long', 'unsigned long long', 'size_t'] -if os.name == 'posix': +if sys.platform != 'nt': TYPES.append('mode_t') def newline_repr(d): Modified: pypy/dist/pypy/rpython/module/ll_os.py ============================================================================== --- pypy/dist/pypy/rpython/module/ll_os.py (original) +++ pypy/dist/pypy/rpython/module/ll_os.py Tue Jun 19 10:42:30 2007 @@ -19,6 +19,7 @@ # 'suggested_primitive' flag is set to another function, if the conversion # and buffer preparation stuff is not useful. +import sys import os from pypy.rpython.module.support import ll_strcpy, _ll_strfill from pypy.rpython.module.support import to_opaque_object, from_opaque_object @@ -117,12 +118,17 @@ path = rffi.charp2str(l_path) return os.open(path, flags, mode) -os_open = rffi.llexternal('open', [rffi.CCHARP, lltype.Signed, rffi.MODE_T], +if sys.platform == 'nt': + mode_t = lltype.Signed +else: + mode_t = rffi.MODE_T + +os_open = rffi.llexternal('open', [rffi.CCHARP, lltype.Signed, mode_t], lltype.Signed, _callable=fake_os_open) def os_open_lltypeimpl(path, flags, mode): l_path = rffi.str2charp(path) - mode = lltype.cast_primitive(rffi.MODE_T, mode) + mode = lltype.cast_primitive(mode_t, mode) result = os_open(l_path, flags, mode) lltype.free(l_path, flavor='raw') if result == -1: From afa at codespeak.net Tue Jun 19 13:37:59 2007 From: afa at codespeak.net (afa at codespeak.net) Date: Tue, 19 Jun 2007 13:37:59 +0200 (CEST) Subject: [pypy-svn] r44364 - in pypy/dist/pypy/rpython: lltypesystem module Message-ID: <20070619113759.1D42680E6@code0.codespeak.net> Author: afa Date: Tue Jun 19 13:37:58 2007 New Revision: 44364 Modified: pypy/dist/pypy/rpython/lltypesystem/rfficache.py pypy/dist/pypy/rpython/module/ll_os.py Log: Correct special casing of Windows platform Modified: pypy/dist/pypy/rpython/lltypesystem/rfficache.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/rfficache.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/rfficache.py Tue Jun 19 13:37:58 2007 @@ -5,7 +5,6 @@ import py import os -import sys from pypy.translator.tool.cbuild import build_executable from subprocess import PIPE, Popen from pypy.tool.udir import udir @@ -47,7 +46,7 @@ for name in (_name, 'unsigned ' + _name): TYPES.append(name) TYPES += ['long long', 'unsigned long long', 'size_t'] -if sys.platform != 'nt': +if os.name != 'nt': TYPES.append('mode_t') def newline_repr(d): Modified: pypy/dist/pypy/rpython/module/ll_os.py ============================================================================== --- pypy/dist/pypy/rpython/module/ll_os.py (original) +++ pypy/dist/pypy/rpython/module/ll_os.py Tue Jun 19 13:37:58 2007 @@ -19,7 +19,6 @@ # 'suggested_primitive' flag is set to another function, if the conversion # and buffer preparation stuff is not useful. -import sys import os from pypy.rpython.module.support import ll_strcpy, _ll_strfill from pypy.rpython.module.support import to_opaque_object, from_opaque_object @@ -118,7 +117,7 @@ path = rffi.charp2str(l_path) return os.open(path, flags, mode) -if sys.platform == 'nt': +if os.name == 'nt': mode_t = lltype.Signed else: mode_t = rffi.MODE_T From fijal at codespeak.net Tue Jun 19 15:09:51 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 19 Jun 2007 15:09:51 +0200 (CEST) Subject: [pypy-svn] r44371 - pypy/extradoc/talk/ep2007 Message-ID: <20070619130951.1F3D580C9@code0.codespeak.net> Author: fijal Date: Tue Jun 19 15:09:50 2007 New Revision: 44371 Added: pypy/extradoc/talk/ep2007/interpreter.txt Log: Quick skim over features I would like to talk about Added: pypy/extradoc/talk/ep2007/interpreter.txt ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2007/interpreter.txt Tue Jun 19 15:09:50 2007 @@ -0,0 +1,19 @@ +* disclaimer (not ready for production use, etc) + +* those features doesn't change syntax nor semantics of a language + +* multiple object implementations (ropes, xxx) + +* tproxy + +* distribution + +* stackless + +* security + +* taint space + +* JIT (unsure, will be on a previous talk) + +* pickling computations? From fijal at codespeak.net Tue Jun 19 15:10:22 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 19 Jun 2007 15:10:22 +0200 (CEST) Subject: [pypy-svn] r44372 - pypy/extradoc/talk/ep2007 Message-ID: <20070619131022.2E19E80C9@code0.codespeak.net> Author: fijal Date: Tue Jun 19 15:10:21 2007 New Revision: 44372 Added: pypy/extradoc/talk/ep2007/abstract_rpython.txt - copied unchanged from r44341, pypy/extradoc/talk/ep2007/rpython.txt Removed: pypy/extradoc/talk/ep2007/rpython.txt Log: move rpython.txt out of the way From fijal at codespeak.net Tue Jun 19 15:21:34 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 19 Jun 2007 15:21:34 +0200 (CEST) Subject: [pypy-svn] r44373 - pypy/extradoc/talk/ep2007 Message-ID: <20070619132134.6FE0380D8@code0.codespeak.net> Author: fijal Date: Tue Jun 19 15:21:33 2007 New Revision: 44373 Added: pypy/extradoc/talk/ep2007/rpython.txt Log: Some ideas for that talk Added: pypy/extradoc/talk/ep2007/rpython.txt ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2007/rpython.txt Tue Jun 19 15:21:33 2007 @@ -0,0 +1,20 @@ + +* RPython - why it was created? + +* RPython - translation toolchain architecture overview + +* Example of metaprogramming, graph viewer etc. + +* Few words about type annotation + +* CLI/JVM backend + +* IronPython/Jython extension modules (silverpython?) + +* JS backend - few examples, bnb etc, play1 + +* C backend - standalone programs + +* C backend - extension modules + +* ... \ No newline at end of file From cfbolz at codespeak.net Tue Jun 19 15:50:36 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Tue, 19 Jun 2007 15:50:36 +0200 (CEST) Subject: [pypy-svn] r44374 - in pypy/dist/pypy/rlib/parsing: . test Message-ID: <20070619135036.C35BC80D8@code0.codespeak.net> Author: cfbolz Date: Tue Jun 19 15:50:36 2007 New Revision: 44374 Modified: pypy/dist/pypy/rlib/parsing/regex.py pypy/dist/pypy/rlib/parsing/test/test_regex.py Log: add negation of regular expressions Modified: pypy/dist/pypy/rlib/parsing/regex.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/regex.py (original) +++ pypy/dist/pypy/rlib/parsing/regex.py Tue Jun 19 15:50:36 2007 @@ -1,3 +1,4 @@ +import string from pypy.rlib.parsing.deterministic import NFA class RegularExpression(object): @@ -16,6 +17,9 @@ def __pos__(self): return AddExpression(self, self.kleene()) + def __invert__(self): + return NotExpression(self) + def kleene(self): return KleeneClosure(self) @@ -153,6 +157,26 @@ def __repr__(self): return "OrExpression(%r, %r)" % (self.rega, self.regb) +class NotExpression(RegularExpression): + def __init__(self, reg): + self.reg = reg + + def make_automaton(self): + nfa = self.reg.make_automaton() + # add error state + error = nfa.add_state("error") + for state in range(nfa.num_states): + occurring = set(nfa.transitions.get(state, {}).keys()) + toerror = set([chr(i) for i in range(256)]) - occurring + for input in toerror: + nfa.add_transition(state, error, input) + nfa.final_states = set(range(nfa.num_states)) - nfa.final_states + return nfa + + def __invert__(self): + return self.reg + + class LexingOrExpression(RegularExpression): def __init__(self, regs, names): self.regs = regs @@ -188,3 +212,5 @@ def __repr__(self): return "LexingOrExpression(%r, %r)" % (self.regs, self.names) + + Modified: pypy/dist/pypy/rlib/parsing/test/test_regex.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_regex.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_regex.py Tue Jun 19 15:50:36 2007 @@ -137,6 +137,17 @@ assert fn("a") assert fn("aaaaaAAAAaAAzAzaslwer") +def test_not(): + r = NotExpression(StringExpression("a")) + nda = r.make_automaton() + fda = nda.make_deterministic() + fda.view() + r = fda.get_runner() + assert not r.recognize("a") + assert r.recognize("b") + assert r.recognize("bbbbbbbb") + assert r.recognize("arstiow2ie34nvarstbbbbbbbb") + def test_empty(): a = StringExpression("a") empty = StringExpression("") From cfbolz at codespeak.net Tue Jun 19 15:57:58 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Tue, 19 Jun 2007 15:57:58 +0200 (CEST) Subject: [pypy-svn] r44375 - pypy/dist/pypy/rlib/parsing/test Message-ID: <20070619135758.11A4680D8@code0.codespeak.net> Author: cfbolz Date: Tue Jun 19 15:57:57 2007 New Revision: 44375 Modified: pypy/dist/pypy/rlib/parsing/test/test_regex.py Log: remove view Modified: pypy/dist/pypy/rlib/parsing/test/test_regex.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_regex.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_regex.py Tue Jun 19 15:57:57 2007 @@ -141,7 +141,6 @@ r = NotExpression(StringExpression("a")) nda = r.make_automaton() fda = nda.make_deterministic() - fda.view() r = fda.get_runner() assert not r.recognize("a") assert r.recognize("b") From antocuni at codespeak.net Tue Jun 19 16:46:12 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Tue, 19 Jun 2007 16:46:12 +0200 (CEST) Subject: [pypy-svn] r44376 - pypy/extradoc/talk/ep2007 Message-ID: <20070619144612.0642B80E6@code0.codespeak.net> Author: antocuni Date: Tue Jun 19 16:46:12 2007 New Revision: 44376 Modified: pypy/extradoc/talk/ep2007/rpython.txt Log: (antocuni, fijal) some more points Modified: pypy/extradoc/talk/ep2007/rpython.txt ============================================================================== --- pypy/extradoc/talk/ep2007/rpython.txt (original) +++ pypy/extradoc/talk/ep2007/rpython.txt Tue Jun 19 16:46:12 2007 @@ -1,20 +1,24 @@ * RPython - why it was created? +* Big disclaimer: use at your own risk + * RPython - translation toolchain architecture overview * Example of metaprogramming, graph viewer etc. * Few words about type annotation +* C backend - extension modules + +* C backend - standalone programs + * CLI/JVM backend -* IronPython/Jython extension modules (silverpython?) +* creating .NET libraries for C#/IronPython (in the future also for Java/Jython) * JS backend - few examples, bnb etc, play1 -* C backend - standalone programs - -* C backend - extension modules +* (optional) common problems with RPython -* ... \ No newline at end of file +* ... From cfbolz at codespeak.net Tue Jun 19 17:24:32 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Tue, 19 Jun 2007 17:24:32 +0200 (CEST) Subject: [pypy-svn] r44378 - in pypy/dist/pypy/rlib/parsing: . test Message-ID: <20070619152432.8C1A480D8@code0.codespeak.net> Author: cfbolz Date: Tue Jun 19 17:24:32 2007 New Revision: 44378 Added: pypy/dist/pypy/rlib/parsing/makepackrat.py (contents, props changed) pypy/dist/pypy/rlib/parsing/pypackrat.py (contents, props changed) pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py (contents, props changed) Log: Very experimental rewrite of the packrat parsing engine. The new version is meant to be much more featureful eventually, right now it already supports over the original packrat parser: - left recursion - a limited form of sematic actions - scannerless parsing Added: pypy/dist/pypy/rlib/parsing/makepackrat.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/rlib/parsing/makepackrat.py Tue Jun 19 17:24:32 2007 @@ -0,0 +1,610 @@ +import py +import sys +from pypy.rlib.parsing.tree import Nonterminal, Symbol, RPythonVisitor +from pypy.rlib.parsing.regexparse import parse_regex + +class BacktrackException(Exception): + def __init__(self, error=None): + self.error = error + Exception.__init__(self, error) + + +class TreeOptimizer(RPythonVisitor): + def visit_or(self, t): + if len(t.children) == 1: + return self.dispatch(t.children[0]) + return self.general_nonterminal_visit(t) + + visit_commands = visit_or + visit_toplevel_or = visit_or + + def visit_negation(self, t): + child = self.dispatch(t.children[0]) + if child.symbol == "negation": + child.symbol = "lookahead" + return child + t.children[0] = child + return t + + def general_nonterminal_visit(self, t): + for i in range(len(t.children)): + t.children[i] = self.dispatch(t.children[i]) + return t + + def general_visit(self, t): + return t + + +syntax = r""" +NAME: + `[a-zA-Z_][a-zA-Z0-9_]*`; + +SPACE: + ' '; + +COMMENT: + `( *#[^\n]*\n)+`; + +IGNORE: + `(#[^\n]*\n)|\n|\t| `; + +newline: + COMMENT + | `( *\n *)*`; + + +REGEX: + r = `\`[^\\\`]*(\\.[^\\\`]*)*\`` + return {Symbol('REGEX', r, None)}; + +QUOTE: + r = `'[^\']*'` + return {Symbol('QUOTE', r, None)}; + +PYTHONCODE: + r = `\{[^\n\}]*\}` + return {Symbol('PYTHONCODE', r, None)}; + +EOF: + !__any__; + +file: + IGNORE* + list + [EOF]; + +list: + content = production+ + return {Nonterminal('list', content)}; + +production: + name = NAME + SPACE* + ':' + IGNORE* + what = or_ + IGNORE* + ';' + IGNORE* + return {Nonterminal('production', [name, what])}; + +or_: + l = (commands ['|' IGNORE*])+ + last = commands + return {Nonterminal('or', l + [last])} + | commands; + +commands: + cmd = command + newline + cmds = (command [newline])+ + return {Nonterminal('commands', [cmd] + cmds)} + | command; + +command: + simplecommand; + +simplecommand: + return_ + | named_command + | repetition + | negation + | enclosed; + +return_: + 'return' + SPACE* + code = PYTHONCODE + IGNORE* + return {Nonterminal('return', [code])}; + +commandchain: + result = simplecommand+ + return {Nonterminal('commands', result)}; + +named_command: + name = NAME + SPACE* + '=' + SPACE* + cmd = command + return {Nonterminal('named_command', [name, cmd])}; + +repetition: + what = enclosed + SPACE* '?' IGNORE* + return {Nonterminal('maybe', [what])} + | what = enclosed + SPACE* + repetition = ('*' | '+') + IGNORE* + return {Nonterminal('repetition', [repetition, what])}; + +negation: + '!' + SPACE* + what = negation + IGNORE* + return {Nonterminal('negation', [what])} + | enclosed; + +enclosed: + '<' + IGNORE* + what = primary + IGNORE* + '>' + IGNORE* + return {Nonterminal('exclusive', [what])} + | '[' + IGNORE* + what = or_ + IGNORE* + ']' + IGNORE* + return {Nonterminal('ignore', [what])} + | ['(' IGNORE*] or_ [')' IGNORE*] + | primary; + +primary: + call | REGEX [IGNORE*] | QUOTE [IGNORE*]; + +call: + x = NAME + IGNORE* + return {Nonterminal("call", [x])}; +""" + +class ErrorInformation(object): + def __init__(self, pos, expected=None): + if expected is None: + expected = [] + self.expected = expected + self.pos = pos + + def __str__(self): + return "ErrorInformation(%s, %s)" % (self.pos, self.expected) + + +class Status(object): + # status codes: + NORMAL = 0 + ERROR = 1 + INPROGRESS = 2 + LEFTRECURSION = 3 + SOMESOLUTIONS = 4 + def __repr__(self): + return "Status(%s, %s, %s, %s)" % (self.pos, self.result, self.error, + self.status) + + +class ParserBuilder(RPythonVisitor): + def __init__(self): + self.code = [] + self.blocks = [] + self.initcode = [] + self.namecount = 0 + self.names = {} + self.matchers = {} + + def get_code(self): + assert not self.blocks + return "\n".join(self.code) + + def make_parser(self): + m = {'_Status': Status, + 'Nonterminal': Nonterminal, + 'Symbol': Symbol,} + exec py.code.Source(self.get_code()).compile() in m + return m['Parser'] + + def emit(self, line): + for line in line.split("\n"): + self.code.append(" " * (4 * len(self.blocks)) + line) + + def emit_initcode(self, line): + for line in line.split("\n"): + self.initcode.append(line) + + def start_block(self, blockstarter): + assert blockstarter.endswith(":") + self.emit(blockstarter) + self.blocks.append(blockstarter) + def BlockEnder(): + yield None + self.end_block(blockstarter) + return BlockEnder() + + def end_block(self, starterpart=""): + block = self.blocks.pop() + assert starterpart in block, "ended wrong block %s with %s" % ( + block, starterpart) + + def memoize_header(self, name): + statusclassname = "self._Status_%s" % (name, ) + dictname = "_dict_%s" % (name, ) + self.emit_initcode("self.%s = {}" % (dictname, )) + self.emit("_status = self.%s.get(self._pos, None)" % (dictname, )) + for _ in self.start_block("if _status is None:"): + self.emit("_status = self.%s[self._pos] = %s()" % ( + dictname, statusclassname)) + for _ in self.start_block("elif _status.status == _status.NORMAL:"): + self.emit("self._pos = _status.pos") + self.emit("return _status") + for _ in self.start_block("elif _status.status == _status.ERROR:"): + self.emit("raise self._BacktrackException(_status.error)") + for _ in self.start_block( + "elif (_status.status == _status.INPROGRESS or\n" + " _status.status == _status.LEFTRECURSION):"): + self.emit("_status.status = _status.LEFTRECURSION") + for _ in self.start_block("if _status.result is not None:"): + self.emit("self._pos = _status.pos") + self.emit("return _status") + for _ in self.start_block("else:"): + self.emit("raise self._BacktrackException(None)") + for _ in self.start_block("elif _status.status == _status.SOMESOLUTIONS:"): + self.emit("_status.status = _status.INPROGRESS") + self.emit("_startingpos = self._pos") + self.start_block("try:") + self.emit("_result = None") + self.emit("_error = None") + + def memoize_footer(self, name): + statusclassname = "self._Status_%s" % (name, ) + dictname = "_dict_%s" % (name, ) + for _ in self.start_block("if _status.status == _status.LEFTRECURSION:"): + for _ in self.start_block("if _status.result is not None:"): + for _ in self.start_block("if _status.pos >= self._pos:"): + self.emit("_status.status = _status.NORMAL") + self.emit("self._pos = _status.pos") + self.emit("return _status") + self.emit("_status.pos = self._pos") + self.emit("_status.status = _status.SOMESOLUTIONS") + self.emit("_status.result = %s" % (self.resultname, )) + self.emit("_status.error = _error") + self.emit("self._pos = _startingpos") + self.emit("return self._%s()" % (name, )) + self.emit("_status.status = _status.NORMAL") + self.emit("_status.pos = self._pos") + self.emit("_status.result = %s" % (self.resultname, )) + self.emit("_status.error = _error") + self.emit("return _status") + self.end_block("try") + for _ in self.start_block("except self._BacktrackException, _exc:"): + self.emit("_status.pos = -1") + self.emit("_status.result = None") + self.emit("_error = self._combine_errors(_error, _exc.error)") + self.emit("_status.error = _error") + self.emit("_status.status = _status.ERROR") + self.emit("raise self._BacktrackException(_error)") + + def choice_point(self, name=None): + var = "_choice%s" % (self.namecount, ) + self.namecount += 1 + self.emit("%s = self._pos" % (var, )) + return var + + def revert(self, var): + self.emit("self._pos = %s" % (var, )) + + def make_status_class(self, name): + classname = "_Status_%s" % (name, ) + for _ in self.start_block("class %s(_Status):" % (classname, )): + for _ in self.start_block("def __init__(self):"): + self.emit("self.pos = 0") + self.emit("self.error = None") + self.emit("self.status = self.INPROGRESS") + self.emit("self.result = None") + return classname + + def visit_list(self, t): + self.start_block("class Parser(object):") + for elt in t.children: + self.dispatch(elt) + for _ in self.start_block("def __init__(self, inputstream):"): + for line in self.initcode: + self.emit(line) + self.emit("self._pos = 0") + self.emit("self._inputstream = inputstream") + if self.matchers: + self.emit_regex_code() + self.end_block("class") + + def emit_regex_code(self): + for regex, matcher in self.matchers.iteritems(): + for _ in self.start_block( + "def _regex%s(self):" % (abs(hash(regex)), )): + c = self.choice_point() + self.emit("_runner = self._Runner(self._inputstream, self._pos)") + self.emit("_i = _runner.recognize_%s(self._pos)" % ( + abs(hash(regex)), )) + self.start_block("if _runner.last_matched_state == -1:") + self.revert(c) + self.emit("raise self._BacktrackException") + self.end_block("if") + self.emit("_upto = _runner.last_matched_index + 1") + self.emit("_result = self._inputstream[self._pos: _upto]") + self.emit("self._pos = _upto") + self.emit("return _result") + + for _ in self.start_block("class _Runner(object):"): + for _ in self.start_block("def __init__(self, text, pos):"): + self.emit("self.text = text") + self.emit("self.pos = pos") + self.emit("self.last_matched_state = -1") + self.emit("self.last_matched_index = -1") + self.emit("self.state = -1") + for regex, matcher in self.matchers.iteritems(): + matcher = str(matcher).replace( + "def recognize(runner, i)", + "def recognize_%s(runner, i)" % (abs(hash(regex)), )) + self.emit(str(matcher)) + + def visit_production(self, t): + name = t.children[0] + if name in self.names: + raise Exception("name %s appears twice" % (name, )) + self.names[name] = True + self.make_status_class(name) + for _ in self.start_block("def %s(self):" % (name, )): + self.emit("return self._%s().result" % (name, )) + self.start_block("def _%s(self):" % (name, )) + self.memoize_header(name) + #self.emit("print '%s', self._pos" % (name, )) + self.resultname = "_result" + self.dispatch(t.children[1]) + self.memoize_footer(name) + self.end_block("def") + + def visit_or(self, t): + possibilities = t.children + if len(possibilities) > 1: + self.start_block("while 1:") + self.emit("_error = None") + for i, p in enumerate(possibilities): + c = self.choice_point() + for _ in self.start_block("try:"): + self.dispatch(p) + self.emit("break") + for _ in self.start_block("except self._BacktrackException, _exc:"): + self.emit("_error = self._combine_errors(_error, _exc.error)") + self.revert(c) + if i == len(possibilities) - 1: + self.emit("raise self._BacktrackException(_error)") + self.dispatch(possibilities[-1]) + if len(possibilities) > 1: + self.emit("break") + self.end_block("while") + visit_toplevel_or = visit_or + + def visit_commands(self, t): + for elt in t.children: + self.dispatch(elt) + + def visit_maybe(self, t): + c = self.choice_point() + for _ in self.start_block("try:"): + self.dispatch(t.children[0]) + for _ in self.start_block("except self._BacktrackException:"): + self.revert(c) + + def visit_repetition(self, t): + name = "_all%s" % (self.namecount, ) + self.namecount += 1 + self.emit("%s = []" % (name, )) + if t.children[0] == '+': + self.dispatch(t.children[1]) + self.emit("%s.append(_result)" % (name, )) + for _ in self.start_block("while 1:"): + c = self.choice_point() + for _ in self.start_block("try:"): + self.dispatch(t.children[1]) + self.emit("%s.append(_result)" % (name, )) + for _ in self.start_block("except self._BacktrackException, _exc:"): + self.emit("_error = self._combine_errors(_error, _exc.error)") + self.revert(c) + self.emit("break") + self.emit("_result = %s" % (name, )) + + def visit_exclusive(self, t): + self.resultname = "_enclosed" + self.dispatch(t.children[0]) + self.emit("_enclosed = _result") + + def visit_ignore(self, t): + resultname = "_before_discard%i" % (self.namecount, ) + self.namecount += 1 + self.emit("%s = _result" % (resultname, )) + self.dispatch(t.children[0]) + self.emit("_result = %s" % (resultname, )) + + def visit_negation(self, t): + c = self.choice_point() + resultname = "_stored_result%i" % (self.namecount, ) + self.namecount += 1 + child = t.children[0] + self.emit("%s = _result" % (resultname, )) + for _ in self.start_block("try:"): + self.dispatch(child) + for _ in self.start_block("except self._BacktrackException:"): + self.revert(c) + self.emit("_result = %s" % (resultname, )) + for _ in self.start_block("else:"): + # heuristic to get nice error messages sometimes + if isinstance(child, Symbol) and child.symbol == "QUOTE": + + error = "self._ErrorInformation(%s, ['NOT %s'])" % ( + c, child.additional_info[1:-1], ) + else: + error = "None" + self.emit("raise self._BacktrackException(%s)" % (error, )) + + def visit_lookahead(self, t): + resultname = "_stored_result%i" % (self.namecount, ) + self.emit("%s = _result" % (resultname, )) + c = self.choice_point() + self.dispatch(t.children[0]) + self.revert(c) + self.emit("_result = %s" % (resultname, )) + + def visit_named_command(self, t): + name = t.children[0] + self.dispatch(t.children[1]) + self.emit("%s = _result" % (name, )) + + def visit_return(self, t): + self.emit("_result = (%s)" % (t.children[0].additional_info[1:-1], )) + + def visit_call(self, t): + if t.children[0].startswith("_"): + callname = t.children[0] + self.emit("_result = self.%s()" % (callname, )) + else: + callname = "_" + t.children[0] + self.emit("_call_status = self.%s()" % (callname, )) + self.emit("_result = _call_status.result") + self.emit( + "_error = self._combine_errors(_call_status.error, _error)") + + def visit_REGEX(self, t): + r = t.additional_info[1:-1].replace('\\`', '`') + matcher = self.get_regex(r) + self.emit("_result = self._regex%s()" % (abs(hash(r)), )) + + def visit_QUOTE(self, t): + self.emit("_result = self.__chars__(%r)" % ( + str(t.additional_info[1:-1]), )) + + def get_regex(self, r): + from pypy.rlib.parsing.regexparse import parse_regex + if r in self.matchers: + return self.matchers[r] + regex = parse_regex(r) + if regex is None: + raise ValueError( + "%s is not a valid regular expression" % regextext) + automaton = regex.make_automaton().make_deterministic() + automaton.optimize() + matcher = automaton.make_lexing_code() + self.matchers[r] = py.code.Source(matcher) + return matcher + +class MetaPackratParser(type): + def __new__(cls, name_, bases, dct): + if '__doc__' not in dct or dct['__doc__'] is None: + return type.__new__(cls, name_, bases, dct) + from pypackrat import PyPackratSyntaxParser + import sys, new + frame = sys._getframe(1) + p = PyPackratSyntaxParser(dct['__doc__']) + t = p.file() + t = t.visit(TreeOptimizer()) + visitor = ParserBuilder() + t.visit(visitor) + pcls = visitor.make_parser() + forbidden = dict.fromkeys(("__weakref__ __doc__ " + "__dict__ __module__").split()) + initthere = "__init__" in dct + + for key, value in pcls.__dict__.iteritems(): + if isinstance(value, type(lambda: None)): + value = new.function(value.func_code, frame.f_globals) + if key not in dct and key not in forbidden: + dct[key] = value + dct['init_parser'] = pcls.__dict__['__init__'] + dct['_code'] = visitor.get_code() + return type.__new__(cls, name_, bases, dct) + +class PackratParser(object): + __metaclass__ = MetaPackratParser + + _Status = Status + _ErrorInformation = ErrorInformation + _BacktrackException = BacktrackException + + def __chars__(self, chars): + #print '__chars__(%s)' % (chars, ), self._pos + try: + for i in range(len(chars)): + if self._inputstream[self._pos + i] != chars[i]: + raise self._BacktrackException( + self._ErrorInformation(self._pos, [chars])) + self._pos += len(chars) + return chars + except IndexError: + raise self._BacktrackException( + self._ErrorInformation(self._pos, [chars])) + + def __any__(self): + try: + result = self._inputstream[self._pos] + self._pos += 1 + return result + except IndexError: + raise self._BacktrackException( + self._ErrorInformation(self._pos, ['anything'])) + + def _combine_errors(self, error1, error2): + if error1 is None: + return error2 + if (error2 is None or error1.pos > error2.pos or + len(error2.expected) == 0): + return error1 + elif error2.pos > error1.pos or len(error1.expected) == 0: + return error2 + expected = [] + already_there = {} + for ep in [error1.expected, error2.expected]: + for reason in ep: + if reason not in already_there: + already_there[reason] = True + expected.append(reason) + return ErrorInformation(error1.pos, expected) + + +def test_generate(): + f = py.magic.autopath().dirpath().join("pypackrat.py") + from pypackrat import PyPackratSyntaxParser + p = PyPackratSyntaxParser(syntax) + t = p.file() + t = t.visit(TreeOptimizer()) + visitor = ParserBuilder() + t.visit(visitor) + code = visitor.get_code() + content = """ +from pypy.rlib.parsing.tree import Nonterminal, Symbol +from makepackrat import PackratParser, BacktrackException, Status as _Status +%s +class PyPackratSyntaxParser(PackratParser): + def __init__(self, stream): + self.init_parser(stream) +forbidden = dict.fromkeys(("__weakref__ __doc__ " + "__dict__ __module__").split()) +initthere = "__init__" in PyPackratSyntaxParser.__dict__ +for key, value in Parser.__dict__.iteritems(): + if key not in PyPackratSyntaxParser.__dict__ and key not in forbidden: + setattr(PyPackratSyntaxParser, key, value) +PyPackratSyntaxParser.init_parser = Parser.__init__.im_func +""" % (code, ) + print content + f.write(content) Added: pypy/dist/pypy/rlib/parsing/pypackrat.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/rlib/parsing/pypackrat.py Tue Jun 19 17:24:32 2007 @@ -0,0 +1,2706 @@ + +from pypy.rlib.parsing.tree import Nonterminal, Symbol +from makepackrat import PackratParser, BacktrackException, Status as _Status +class Parser(object): + class _Status_NAME(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def NAME(self): + return self._NAME().result + def _NAME(self): + _status = self._dict_NAME.get(self._pos, None) + if _status is None: + _status = self._dict_NAME[self._pos] = self._Status_NAME() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _result = self._regex1074651696() + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._NAME() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_SPACE(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def SPACE(self): + return self._SPACE().result + def _SPACE(self): + _status = self._dict_SPACE.get(self._pos, None) + if _status is None: + _status = self._dict_SPACE[self._pos] = self._Status_SPACE() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _result = self.__chars__(' ') + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._SPACE() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_COMMENT(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def COMMENT(self): + return self._COMMENT().result + def _COMMENT(self): + _status = self._dict_COMMENT.get(self._pos, None) + if _status is None: + _status = self._dict_COMMENT[self._pos] = self._Status_COMMENT() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _result = self._regex528667127() + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._COMMENT() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_IGNORE(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def IGNORE(self): + return self._IGNORE().result + def _IGNORE(self): + _status = self._dict_IGNORE.get(self._pos, None) + if _status is None: + _status = self._dict_IGNORE[self._pos] = self._Status_IGNORE() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _result = self._regex1979538501() + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._IGNORE() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_newline(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def newline(self): + return self._newline().result + def _newline(self): + _status = self._dict_newline.get(self._pos, None) + if _status is None: + _status = self._dict_newline[self._pos] = self._Status_newline() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice0 = self._pos + try: + _call_status = self._COMMENT() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice0 + _choice1 = self._pos + try: + _result = self._regex299149370() + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice1 + raise self._BacktrackException(_error) + _result = self._regex299149370() + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._newline() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_REGEX(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def REGEX(self): + return self._REGEX().result + def _REGEX(self): + _status = self._dict_REGEX.get(self._pos, None) + if _status is None: + _status = self._dict_REGEX[self._pos] = self._Status_REGEX() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _result = self._regex1006631623() + r = _result + _result = (Symbol('REGEX', r, None)) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._REGEX() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_QUOTE(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def QUOTE(self): + return self._QUOTE().result + def _QUOTE(self): + _status = self._dict_QUOTE.get(self._pos, None) + if _status is None: + _status = self._dict_QUOTE[self._pos] = self._Status_QUOTE() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _result = self._regex1124192327() + r = _result + _result = (Symbol('QUOTE', r, None)) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._QUOTE() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_PYTHONCODE(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def PYTHONCODE(self): + return self._PYTHONCODE().result + def _PYTHONCODE(self): + _status = self._dict_PYTHONCODE.get(self._pos, None) + if _status is None: + _status = self._dict_PYTHONCODE[self._pos] = self._Status_PYTHONCODE() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _result = self._regex291086639() + r = _result + _result = (Symbol('PYTHONCODE', r, None)) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._PYTHONCODE() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_EOF(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def EOF(self): + return self._EOF().result + def _EOF(self): + _status = self._dict_EOF.get(self._pos, None) + if _status is None: + _status = self._dict_EOF[self._pos] = self._Status_EOF() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _choice2 = self._pos + _stored_result3 = _result + try: + _result = self.__any__() + except self._BacktrackException: + self._pos = _choice2 + _result = _stored_result3 + else: + raise self._BacktrackException(None) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._EOF() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_file(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def file(self): + return self._file().result + def _file(self): + _status = self._dict_file.get(self._pos, None) + if _status is None: + _status = self._dict_file[self._pos] = self._Status_file() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _all4 = [] + while 1: + _choice5 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all4.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice5 + break + _result = _all4 + _call_status = self._list() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _before_discard6 = _result + _call_status = self._EOF() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _result = _before_discard6 + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._file() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_list(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def list(self): + return self._list().result + def _list(self): + _status = self._dict_list.get(self._pos, None) + if _status is None: + _status = self._dict_list[self._pos] = self._Status_list() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _all7 = [] + _call_status = self._production() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all7.append(_result) + while 1: + _choice8 = self._pos + try: + _call_status = self._production() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all7.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice8 + break + _result = _all7 + content = _result + _result = (Nonterminal('list', content)) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._list() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_production(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def production(self): + return self._production().result + def _production(self): + _status = self._dict_production.get(self._pos, None) + if _status is None: + _status = self._dict_production[self._pos] = self._Status_production() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _call_status = self._NAME() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + name = _result + _all9 = [] + while 1: + _choice10 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all9.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice10 + break + _result = _all9 + _result = self.__chars__(':') + _all11 = [] + while 1: + _choice12 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all11.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice12 + break + _result = _all11 + _call_status = self._or_() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + what = _result + _all13 = [] + while 1: + _choice14 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all13.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice14 + break + _result = _all13 + _result = self.__chars__(';') + _all15 = [] + while 1: + _choice16 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all15.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice16 + break + _result = _all15 + _result = (Nonterminal('production', [name, what])) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._production() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_or_(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def or_(self): + return self._or_().result + def _or_(self): + _status = self._dict_or_.get(self._pos, None) + if _status is None: + _status = self._dict_or_[self._pos] = self._Status_or_() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice17 = self._pos + try: + _all18 = [] + _call_status = self._commands() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _before_discard19 = _result + _result = self.__chars__('|') + _all20 = [] + while 1: + _choice21 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all20.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice21 + break + _result = _all20 + _result = _before_discard19 + _all18.append(_result) + while 1: + _choice22 = self._pos + try: + _call_status = self._commands() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _before_discard23 = _result + _result = self.__chars__('|') + _all24 = [] + while 1: + _choice25 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all24.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice25 + break + _result = _all24 + _result = _before_discard23 + _all18.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice22 + break + _result = _all18 + l = _result + _call_status = self._commands() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + last = _result + _result = (Nonterminal('or', l + [last])) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice17 + _choice26 = self._pos + try: + _call_status = self._commands() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice26 + raise self._BacktrackException(_error) + _call_status = self._commands() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._or_() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_commands(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def commands(self): + return self._commands().result + def _commands(self): + _status = self._dict_commands.get(self._pos, None) + if _status is None: + _status = self._dict_commands[self._pos] = self._Status_commands() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice27 = self._pos + try: + _call_status = self._command() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + cmd = _result + _call_status = self._newline() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all28 = [] + _call_status = self._command() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _before_discard29 = _result + _call_status = self._newline() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _result = _before_discard29 + _all28.append(_result) + while 1: + _choice30 = self._pos + try: + _call_status = self._command() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _before_discard31 = _result + _call_status = self._newline() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _result = _before_discard31 + _all28.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice30 + break + _result = _all28 + cmds = _result + _result = (Nonterminal('commands', [cmd] + cmds)) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice27 + _choice32 = self._pos + try: + _call_status = self._command() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice32 + raise self._BacktrackException(_error) + _call_status = self._command() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._commands() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_command(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def command(self): + return self._command().result + def _command(self): + _status = self._dict_command.get(self._pos, None) + if _status is None: + _status = self._dict_command[self._pos] = self._Status_command() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _call_status = self._simplecommand() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._command() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_simplecommand(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def simplecommand(self): + return self._simplecommand().result + def _simplecommand(self): + _status = self._dict_simplecommand.get(self._pos, None) + if _status is None: + _status = self._dict_simplecommand[self._pos] = self._Status_simplecommand() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice33 = self._pos + try: + _call_status = self._return_() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice33 + _choice34 = self._pos + try: + _call_status = self._named_command() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice34 + _choice35 = self._pos + try: + _call_status = self._repetition() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice35 + _choice36 = self._pos + try: + _call_status = self._negation() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice36 + _choice37 = self._pos + try: + _call_status = self._enclosed() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice37 + raise self._BacktrackException(_error) + _call_status = self._enclosed() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._simplecommand() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_return_(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def return_(self): + return self._return_().result + def _return_(self): + _status = self._dict_return_.get(self._pos, None) + if _status is None: + _status = self._dict_return_[self._pos] = self._Status_return_() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _result = self.__chars__('return') + _all38 = [] + while 1: + _choice39 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all38.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice39 + break + _result = _all38 + _call_status = self._PYTHONCODE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + code = _result + _all40 = [] + while 1: + _choice41 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all40.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice41 + break + _result = _all40 + _result = (Nonterminal('return', [code])) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._return_() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_commandchain(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def commandchain(self): + return self._commandchain().result + def _commandchain(self): + _status = self._dict_commandchain.get(self._pos, None) + if _status is None: + _status = self._dict_commandchain[self._pos] = self._Status_commandchain() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _all42 = [] + _call_status = self._simplecommand() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all42.append(_result) + while 1: + _choice43 = self._pos + try: + _call_status = self._simplecommand() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all42.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice43 + break + _result = _all42 + result = _result + _result = (Nonterminal('commands', result)) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._commandchain() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_named_command(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def named_command(self): + return self._named_command().result + def _named_command(self): + _status = self._dict_named_command.get(self._pos, None) + if _status is None: + _status = self._dict_named_command[self._pos] = self._Status_named_command() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _call_status = self._NAME() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + name = _result + _all44 = [] + while 1: + _choice45 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all44.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice45 + break + _result = _all44 + _result = self.__chars__('=') + _all46 = [] + while 1: + _choice47 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all46.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice47 + break + _result = _all46 + _call_status = self._command() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + cmd = _result + _result = (Nonterminal('named_command', [name, cmd])) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._named_command() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_repetition(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def repetition(self): + return self._repetition().result + def _repetition(self): + _status = self._dict_repetition.get(self._pos, None) + if _status is None: + _status = self._dict_repetition[self._pos] = self._Status_repetition() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice48 = self._pos + try: + _call_status = self._enclosed() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + what = _result + _all49 = [] + while 1: + _choice50 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all49.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice50 + break + _result = _all49 + _result = self.__chars__('?') + _all51 = [] + while 1: + _choice52 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all51.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice52 + break + _result = _all51 + _result = (Nonterminal('maybe', [what])) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice48 + _choice53 = self._pos + try: + _call_status = self._enclosed() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + what = _result + _all54 = [] + while 1: + _choice55 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all54.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice55 + break + _result = _all54 + while 1: + _error = None + _choice56 = self._pos + try: + _result = self.__chars__('*') + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice56 + _choice57 = self._pos + try: + _result = self.__chars__('+') + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice57 + raise self._BacktrackException(_error) + _result = self.__chars__('+') + break + repetition = _result + _all58 = [] + while 1: + _choice59 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all58.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice59 + break + _result = _all58 + _result = (Nonterminal('repetition', [repetition, what])) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice53 + raise self._BacktrackException(_error) + _call_status = self._enclosed() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + what = _result + _all60 = [] + while 1: + _choice61 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all60.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice61 + break + _result = _all60 + while 1: + _error = None + _choice62 = self._pos + try: + _result = self.__chars__('*') + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice62 + _choice63 = self._pos + try: + _result = self.__chars__('+') + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice63 + raise self._BacktrackException(_error) + _result = self.__chars__('+') + break + repetition = _result + _all64 = [] + while 1: + _choice65 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all64.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice65 + break + _result = _all64 + _result = (Nonterminal('repetition', [repetition, what])) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._repetition() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_negation(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def negation(self): + return self._negation().result + def _negation(self): + _status = self._dict_negation.get(self._pos, None) + if _status is None: + _status = self._dict_negation[self._pos] = self._Status_negation() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice66 = self._pos + try: + _result = self.__chars__('!') + _all67 = [] + while 1: + _choice68 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all67.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice68 + break + _result = _all67 + _call_status = self._negation() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + what = _result + _all69 = [] + while 1: + _choice70 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all69.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice70 + break + _result = _all69 + _result = (Nonterminal('negation', [what])) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice66 + _choice71 = self._pos + try: + _call_status = self._enclosed() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice71 + raise self._BacktrackException(_error) + _call_status = self._enclosed() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._negation() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_enclosed(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def enclosed(self): + return self._enclosed().result + def _enclosed(self): + _status = self._dict_enclosed.get(self._pos, None) + if _status is None: + _status = self._dict_enclosed[self._pos] = self._Status_enclosed() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice72 = self._pos + try: + _result = self.__chars__('<') + _all73 = [] + while 1: + _choice74 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all73.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice74 + break + _result = _all73 + _call_status = self._primary() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + what = _result + _all75 = [] + while 1: + _choice76 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all75.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice76 + break + _result = _all75 + _result = self.__chars__('>') + _all77 = [] + while 1: + _choice78 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all77.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice78 + break + _result = _all77 + _result = (Nonterminal('exclusive', [what])) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice72 + _choice79 = self._pos + try: + _result = self.__chars__('[') + _all80 = [] + while 1: + _choice81 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all80.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice81 + break + _result = _all80 + _call_status = self._or_() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + what = _result + _all82 = [] + while 1: + _choice83 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all82.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice83 + break + _result = _all82 + _result = self.__chars__(']') + _all84 = [] + while 1: + _choice85 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all84.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice85 + break + _result = _all84 + _result = (Nonterminal('ignore', [what])) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice79 + _choice86 = self._pos + try: + _before_discard87 = _result + _result = self.__chars__('(') + _all88 = [] + while 1: + _choice89 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all88.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice89 + break + _result = _all88 + _result = _before_discard87 + _call_status = self._or_() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _before_discard90 = _result + _result = self.__chars__(')') + _all91 = [] + while 1: + _choice92 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all91.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice92 + break + _result = _all91 + _result = _before_discard90 + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice86 + _choice93 = self._pos + try: + _call_status = self._primary() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice93 + raise self._BacktrackException(_error) + _call_status = self._primary() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._enclosed() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_primary(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def primary(self): + return self._primary().result + def _primary(self): + _status = self._dict_primary.get(self._pos, None) + if _status is None: + _status = self._dict_primary[self._pos] = self._Status_primary() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice94 = self._pos + try: + _call_status = self._call() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice94 + _choice95 = self._pos + try: + _call_status = self._REGEX() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _before_discard96 = _result + _all97 = [] + while 1: + _choice98 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all97.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice98 + break + _result = _all97 + _result = _before_discard96 + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice95 + _choice99 = self._pos + try: + _call_status = self._QUOTE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _before_discard100 = _result + _all101 = [] + while 1: + _choice102 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all101.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice102 + break + _result = _all101 + _result = _before_discard100 + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice99 + raise self._BacktrackException(_error) + _call_status = self._QUOTE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _before_discard103 = _result + _all104 = [] + while 1: + _choice105 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all104.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice105 + break + _result = _all104 + _result = _before_discard103 + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._primary() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_call(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def call(self): + return self._call().result + def _call(self): + _status = self._dict_call.get(self._pos, None) + if _status is None: + _status = self._dict_call[self._pos] = self._Status_call() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _call_status = self._NAME() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + x = _result + _all106 = [] + while 1: + _choice107 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all106.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice107 + break + _result = _all106 + _result = (Nonterminal("call", [x])) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._call() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + def __init__(self, inputstream): + self._dict_NAME = {} + self._dict_SPACE = {} + self._dict_COMMENT = {} + self._dict_IGNORE = {} + self._dict_newline = {} + self._dict_REGEX = {} + self._dict_QUOTE = {} + self._dict_PYTHONCODE = {} + self._dict_EOF = {} + self._dict_file = {} + self._dict_list = {} + self._dict_production = {} + self._dict_or_ = {} + self._dict_commands = {} + self._dict_command = {} + self._dict_simplecommand = {} + self._dict_return_ = {} + self._dict_commandchain = {} + self._dict_named_command = {} + self._dict_repetition = {} + self._dict_negation = {} + self._dict_enclosed = {} + self._dict_primary = {} + self._dict_call = {} + self._pos = 0 + self._inputstream = inputstream + def _regex299149370(self): + _choice108 = self._pos + _runner = self._Runner(self._inputstream, self._pos) + _i = _runner.recognize_299149370(self._pos) + if _runner.last_matched_state == -1: + self._pos = _choice108 + raise self._BacktrackException + _upto = _runner.last_matched_index + 1 + _result = self._inputstream[self._pos: _upto] + self._pos = _upto + return _result + def _regex1006631623(self): + _choice109 = self._pos + _runner = self._Runner(self._inputstream, self._pos) + _i = _runner.recognize_1006631623(self._pos) + if _runner.last_matched_state == -1: + self._pos = _choice109 + raise self._BacktrackException + _upto = _runner.last_matched_index + 1 + _result = self._inputstream[self._pos: _upto] + self._pos = _upto + return _result + def _regex528667127(self): + _choice110 = self._pos + _runner = self._Runner(self._inputstream, self._pos) + _i = _runner.recognize_528667127(self._pos) + if _runner.last_matched_state == -1: + self._pos = _choice110 + raise self._BacktrackException + _upto = _runner.last_matched_index + 1 + _result = self._inputstream[self._pos: _upto] + self._pos = _upto + return _result + def _regex291086639(self): + _choice111 = self._pos + _runner = self._Runner(self._inputstream, self._pos) + _i = _runner.recognize_291086639(self._pos) + if _runner.last_matched_state == -1: + self._pos = _choice111 + raise self._BacktrackException + _upto = _runner.last_matched_index + 1 + _result = self._inputstream[self._pos: _upto] + self._pos = _upto + return _result + def _regex1074651696(self): + _choice112 = self._pos + _runner = self._Runner(self._inputstream, self._pos) + _i = _runner.recognize_1074651696(self._pos) + if _runner.last_matched_state == -1: + self._pos = _choice112 + raise self._BacktrackException + _upto = _runner.last_matched_index + 1 + _result = self._inputstream[self._pos: _upto] + self._pos = _upto + return _result + def _regex1124192327(self): + _choice113 = self._pos + _runner = self._Runner(self._inputstream, self._pos) + _i = _runner.recognize_1124192327(self._pos) + if _runner.last_matched_state == -1: + self._pos = _choice113 + raise self._BacktrackException + _upto = _runner.last_matched_index + 1 + _result = self._inputstream[self._pos: _upto] + self._pos = _upto + return _result + def _regex1979538501(self): + _choice114 = self._pos + _runner = self._Runner(self._inputstream, self._pos) + _i = _runner.recognize_1979538501(self._pos) + if _runner.last_matched_state == -1: + self._pos = _choice114 + raise self._BacktrackException + _upto = _runner.last_matched_index + 1 + _result = self._inputstream[self._pos: _upto] + self._pos = _upto + return _result + class _Runner(object): + def __init__(self, text, pos): + self.text = text + self.pos = pos + self.last_matched_state = -1 + self.last_matched_index = -1 + self.state = -1 + def recognize_299149370(runner, i): + assert i >= 0 + input = runner.text + state = 0 + while 1: + if state == 0: + runner.last_matched_index = i - 1 + runner.last_matched_state = state + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 0 + return i + if char == '\n': + state = 1 + elif char == ' ': + state = 2 + else: + break + if state == 1: + runner.last_matched_index = i - 1 + runner.last_matched_state = state + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 1 + return i + if char == '\n': + state = 1 + continue + elif char == ' ': + state = 1 + continue + else: + break + if state == 2: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 2 + return ~i + if char == '\n': + state = 1 + continue + elif char == ' ': + state = 2 + continue + else: + break + runner.last_matched_state = state + runner.last_matched_index = i - 1 + runner.state = state + if i == len(input): + return i + else: + return ~i + break + runner.state = state + return ~i + def recognize_1006631623(runner, i): + assert i >= 0 + input = runner.text + state = 0 + while 1: + if state == 0: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 0 + return ~i + if char == '`': + state = 3 + else: + break + if state == 2: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 2 + return ~i + if '\x00' <= char <= '\xff': + state = 3 + else: + break + if state == 3: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 3 + return ~i + if char == '`': + state = 1 + elif char == '\\': + state = 2 + continue + elif '\x00' <= char <= '[': + state = 3 + continue + elif ']' <= char <= '_': + state = 3 + continue + elif 'a' <= char <= '\xff': + state = 3 + continue + else: + break + runner.last_matched_state = state + runner.last_matched_index = i - 1 + runner.state = state + if i == len(input): + return i + else: + return ~i + break + runner.state = state + return ~i + def recognize_528667127(runner, i): + assert i >= 0 + input = runner.text + state = 0 + while 1: + if state == 0: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 0 + return ~i + if char == ' ': + state = 0 + continue + elif char == '#': + state = 2 + else: + break + if state == 1: + runner.last_matched_index = i - 1 + runner.last_matched_state = state + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 1 + return i + if char == ' ': + state = 0 + continue + elif char == '#': + state = 2 + else: + break + if state == 2: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 2 + return ~i + if char == '\n': + state = 1 + continue + elif '\x00' <= char <= '\t': + state = 2 + continue + elif '\x0b' <= char <= '\xff': + state = 2 + continue + else: + break + runner.last_matched_state = state + runner.last_matched_index = i - 1 + runner.state = state + if i == len(input): + return i + else: + return ~i + break + runner.state = state + return ~i + def recognize_291086639(runner, i): + assert i >= 0 + input = runner.text + state = 0 + while 1: + if state == 0: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 0 + return ~i + if char == '{': + state = 2 + else: + break + if state == 2: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 2 + return ~i + if char == '}': + state = 1 + elif '\x00' <= char <= '\t': + state = 2 + continue + elif '\x0b' <= char <= '|': + state = 2 + continue + elif '~' <= char <= '\xff': + state = 2 + continue + else: + break + runner.last_matched_state = state + runner.last_matched_index = i - 1 + runner.state = state + if i == len(input): + return i + else: + return ~i + break + runner.state = state + return ~i + def recognize_1074651696(runner, i): + assert i >= 0 + input = runner.text + state = 0 + while 1: + if state == 0: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 0 + return ~i + if 'A' <= char <= 'Z': + state = 1 + elif char == '_': + state = 1 + elif 'a' <= char <= 'z': + state = 1 + else: + break + if state == 1: + runner.last_matched_index = i - 1 + runner.last_matched_state = state + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 1 + return i + if '0' <= char <= '9': + state = 1 + continue + elif 'A' <= char <= 'Z': + state = 1 + continue + elif char == '_': + state = 1 + continue + elif 'a' <= char <= 'z': + state = 1 + continue + else: + break + runner.last_matched_state = state + runner.last_matched_index = i - 1 + runner.state = state + if i == len(input): + return i + else: + return ~i + break + runner.state = state + return ~i + def recognize_1124192327(runner, i): + assert i >= 0 + input = runner.text + state = 0 + while 1: + if state == 0: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 0 + return ~i + if char == "'": + state = 1 + else: + break + if state == 1: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 1 + return ~i + if '\x00' <= char <= '&': + state = 1 + continue + elif '(' <= char <= '\xff': + state = 1 + continue + elif char == "'": + state = 2 + else: + break + runner.last_matched_state = state + runner.last_matched_index = i - 1 + runner.state = state + if i == len(input): + return i + else: + return ~i + break + runner.state = state + return ~i + def recognize_1979538501(runner, i): + assert i >= 0 + input = runner.text + state = 0 + while 1: + if state == 0: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 0 + return ~i + if char == '#': + state = 1 + elif char == '\t': + state = 2 + elif char == '\n': + state = 2 + elif char == ' ': + state = 2 + else: + break + if state == 1: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 1 + return ~i + if '\x00' <= char <= '\t': + state = 1 + continue + elif '\x0b' <= char <= '\xff': + state = 1 + continue + elif char == '\n': + state = 2 + else: + break + runner.last_matched_state = state + runner.last_matched_index = i - 1 + runner.state = state + if i == len(input): + return i + else: + return ~i + break + runner.state = state + return ~i +class PyPackratSyntaxParser(PackratParser): + def __init__(self, stream): + self.init_parser(stream) +forbidden = dict.fromkeys(("__weakref__ __doc__ " + "__dict__ __module__").split()) +initthere = "__init__" in PyPackratSyntaxParser.__dict__ +for key, value in Parser.__dict__.iteritems(): + if key not in PyPackratSyntaxParser.__dict__ and key not in forbidden: + setattr(PyPackratSyntaxParser, key, value) +PyPackratSyntaxParser.init_parser = Parser.__init__.im_func Added: pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Tue Jun 19 17:24:32 2007 @@ -0,0 +1,415 @@ +import py +from pypy.rlib.parsing import regex +from pypy.rlib.parsing.pypackrat import * +import operator + +class TestPackrat(object): + def test_simple(self): + class parser(PackratParser): + """ + a: 'a'*; + b: 'a'+; + c: ('a' | 'b')+; + """ + print parser._code + p = parser("ababababa") + assert p.c() == list("ababababa") + p = parser("aaaaaaaa") + assert p.a() == list("aaaaaaaa") + p = parser("") + assert p.a() == [] + p = parser("") + py.test.raises(BacktrackException, p.b) + + def test_questionmark(self): + class parser(PackratParser): + """ + a: 'a'? 'b'; + """ + print parser._code + p = parser("ab") + assert p.a() == 'b' + p = parser("b") + assert p.a() == 'b' + + def test_call(self): + class parser(PackratParser): + """ + a: 'a'? 'b'; + b: a 'c'; + """ + print parser._code + p = parser("abc") + res = p.b() + assert res == 'c' + p = parser("bc") + res = p.b() + assert res == 'c' + + def test_memoize(self): + class parser(PackratParser): + """ + x: a 'end'; + a: b c | b; + b: 'b'; + c: 'c'; + """ + print parser._code + p = parser("bend") + res = p.x() + assert res == 'end' + + def test_enclose(self): + class parser(PackratParser): + """ + a: 'a' <'b'> 'c'+; + """ + print parser._code + p = parser("abcccccc") + p.a() == 'b' + + def test_not(self): + class parser(PackratParser): + """ + a: 'bh' !'a'; + """ + print parser._code + p = parser('bhc') + assert p.a() == 'bh' + p.__chars__('c') == 'c' + p = parser('bh') + p.a() == 'bh' + py.test.raises(BacktrackException, p.__any__) + + def test_lookahead(self): + class parser(PackratParser): + """ + a: 'b' !!'a'; + """ + print parser._code + p = parser('ba') + res = p.a() + assert res == 'b' + assert p.__any__() == 'a' + + def test_regex1(self): + class parser(PackratParser): + """ + a: 'b' `a|b`; + """ + print parser._code + p = parser('ba') + res = p.a() + assert res == 'a' + py.test.raises(BacktrackException, p.__any__) + p = parser('bb') + res = p.a() + assert res == 'b' + py.test.raises(BacktrackException, p.__any__) + + + def test_regex2(self): + class parser(PackratParser): + """ + a: 'b' `[^\n]*`; + """ + print parser._code + p = parser('ba#$@@$%\nbc') + res = p.a() + assert res == 'a#$@@$%' + assert p.__any__() == '\n' + + def test_name(self): + class parser(PackratParser): + """ + a: c = 'b' + r = `[^\n]*` + return {c + r}; + """ + print parser._code + p = parser('ba#$@@$%\nbc') + res = p.a() + assert res == 'ba#$@@$%' + assert p.__any__() == '\n' + + def test_name2(self): + class parser(PackratParser): + """ + a: c = 'b'* + r = `[^\n]*` + return {(len(c), r)}; + """ + print parser._code + p = parser('bbbbbba#$@@$%\nbc') + res = p.a() + assert res == (6, "a#$@@$%") + assert p.__any__() == '\n' + + def test_name3(self): + class parser(PackratParser): + """ + a: c = 'd'+ + r = 'f'+ + return {"".join(c) + "".join(r)} + | c = 'b'* + r = `[^\n]*` + return {(len(c), r)}; + """ + print parser._code + p = parser('bbbbbba#$@@$%\nbc') + res = p.a() + assert res == (6, "a#$@@$%") + assert p.__any__() == '\n' + p = parser('dddffffx') + res = p.a() + assert res == "dddffff" + assert p.__any__() == 'x' + + def test_nested_repetition(self): + class parser(PackratParser): + """ + a: ('a' 'b'*)+; + """ + print parser._code + p = parser('aaabbbab') + res = p.a() + assert res == [[], [], ['b', 'b', 'b'], ['b']] + + + def test_ignore(self): + class parser(PackratParser): + """ + a: ('a' ['b'])+; + """ + print parser._code + p = parser('abababababab') + res = p.a() + assert res == list('aaaaaa') + + + def test_regex(self): + class parser(PackratParser): + r""" + a: `\"`; + """ + print parser._code + p = parser('"') + res = p.a() + assert res == '"' + + + def test_memoize_exceptions(self): + class parser(PackratParser): + """ + b: 'a'; + """ + print parser._code + p = parser("c") + excinfo = py.test.raises(BacktrackException, p.b) + excinfo = py.test.raises(BacktrackException, p.b) + excinfo = py.test.raises(BacktrackException, p.b) + + def test_error_character(self): + class parser(PackratParser): + """ + b: 'a'; + """ + print parser._code + p = parser("c") + excinfo = py.test.raises(BacktrackException, p.b) + assert excinfo.value.error.pos == 0 + assert excinfo.value.error.expected == ['a'] + + def test_error_or(self): + class parser(PackratParser): + """ + b: 'a' | 'b'; + """ + print parser._code + p = parser("c") + excinfo = py.test.raises(BacktrackException, p.b) + assert excinfo.value.error.pos == 0 + assert excinfo.value.error.expected == ['a', 'b'] + + def test_error_not(self): + class parser(PackratParser): + """ + b: + 'b' !'a'; + """ + p = parser("ba") + excinfo = py.test.raises(BacktrackException, p.b) + assert excinfo.value.error.pos == 1 + assert excinfo.value.error.expected == ['NOT a'] + print parser._code + + def test_error_lookahead(self): + class parser(PackratParser): + """ + b: + 'b' !!'a'; + """ + p = parser("bc") + print parser._code + excinfo = py.test.raises(BacktrackException, p.b) + assert excinfo.value.error.pos == 1 + assert excinfo.value.error.expected == ['a'] + + def test_error_star(self): + class parser(PackratParser): + """ + b: + 'b'* !__any__; + """ + print parser._code + p = parser("bbc") + print parser._code + excinfo = py.test.raises(BacktrackException, p.b) + assert excinfo.value.error.pos == 2 + assert excinfo.value.error.expected == ['b'] + + def test_leftrecursion(self): + class parser(PackratParser): + """ + b: b 'a' | 'b'; + """ + print parser._code + p = parser("b") + res = p.b() + assert res == "b" + p = parser("bac") + res = p.b() + assert p._pos == 2 + assert res == "a" + p = parser("baaaaaaaaaaaaaac") + res = p.b() + assert p._pos == 15 + assert res == "a" + + def test_leftrecursion_arithmetic(self): + class parser(PackratParser): + """ + additive: + a = additive + '-' + b = multitive + return {a - b} + | multitive; + multitive: + a = multitive + '*' + b = simple + return {a * b} + | simple; + simple: + x = `0|([1-9][0-9]*)` + return {int(x)}; + """ + print parser._code + p = parser("5") + res = p.multitive() + assert res == 5 + p._pos = 0 + res = p.multitive() + assert res == 5 + p = parser("5-5-5") + res = p.additive() + assert res == -5 + assert p._pos == 5 + + def test_leftrecursion_more_choices(self): + class parser(PackratParser): + """ + b: + b 'a' + | b 'c' + | 'b'; + """ + print parser._code + p = parser("b") + res = p.b() + assert res == "b" + p = parser("bcx") + res = p.b() + assert p._pos == 2 + assert res == "c" + + def test_regexparse(self): + py.test.skip() + class RegexParser(PackratParser): + """ + regex: + r1 = concatenation + '|' + r2 = regex + return {r1 | r2} + | concatenation; + + concatenation: + r1 = repetition + r2 = concatenation + return {r1 + r2} + | repetition; + + repetition: + r1 = primary + '*' + return {r1.kleene()} + | r1 = primary + '+' + return {r1 + r1.kleene()} + | r1 = primary + '?' + return {regex.StringExpression("") | r1} + | r = primary + '{' + n = numrange + '}' + return {r * n[0] + reduce(operator.or_, + [r * i for i in range(n[1] - n[0])], + regex.StringExpression("")} + | primary; + + primary: + ['('] regex [')'] + | ['['] range [']'] + | char + | '.' + return {regex.RangeExpression(chr(0), chr(255))}; + + char: + c = QUOTEDCHAR + return {regex.StringExpression(unescape(c))} + | c = CHAR + return {regex.StringExpression(c)}; + + range: + '^' + r = subrange + return {~r} + | subrange; + + subrange: + l = rangeelement+ + return {reduce(operator.or_, l, regex.StringExpression(""))}; + + rangeelement: + c1 = char + '-' + c2 = char + return {regex.RangeExpression(c1, c2)} + | c = char + return {regex.StringExpression(c)}; + + numrange: + n1 = NUM + ',' + n2 = NUM + return {n1, n2} + | n1 = NUM + return {n1, n1}; + + NUM: + c = `0|([1-9][0-9]*)` + return {int(c)}; + """ From fijal at codespeak.net Tue Jun 19 17:24:46 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 19 Jun 2007 17:24:46 +0200 (CEST) Subject: [pypy-svn] r44379 - pypy/extradoc/talk/ep2007 Message-ID: <20070619152446.F057480F1@code0.codespeak.net> Author: fijal Date: Tue Jun 19 17:24:46 2007 New Revision: 44379 Modified: pypy/extradoc/talk/ep2007/rpython.txt Log: Expand few slides Modified: pypy/extradoc/talk/ep2007/rpython.txt ============================================================================== --- pypy/extradoc/talk/ep2007/rpython.txt (original) +++ pypy/extradoc/talk/ep2007/rpython.txt Tue Jun 19 17:24:46 2007 @@ -1,14 +1,73 @@ -* RPython - why it was created? +========================================== +RPython aka C and C# considered harmful +========================================== -* Big disclaimer: use at your own risk +:Authors: Antonio Cuni (xxx), Maciej Fijalkowski (merlinux GmbH) +:Place: Europython 2007 +:Date: XXX + +Why invent new language? +------------------------ + +* Grown as side effect of the pypy project + +* Python is too slow + +* Pyrex/C are ugly + +* We want to play with Python as much as possible + +What is RPython? +---------------- + +* Python (every RPython program has the same meaning + when run on top of CPython) + +* Restricted subset + +* Constructed from living objects - initialization + is fully done in Python + +* XXX more? + +Restricted, what do you mean? +----------------------------- + +* No dynamic stuff (from __ methods only + __init__ and __del__ works) + +* No frames and such stuff -* RPython - translation toolchain architecture overview +* Full type inference - you cannot mix types -* Example of metaprogramming, graph viewer etc. +XXX crappy examples expand or delete (probably would be +XXX better to just say few words + +* [1, 2, 3, 4] is ok, ['sss', 2] not + +* (1, 'xx') is ok, but cannot be mixed with ('xx', 1) + +Example of use case +------------------- + +XXX write down some simple example for that one + +* Write code + +* test it + +* compile it + +* graph viewer + + +.... * Few words about type annotation +* Big disclaimer: use at your own risk + * C backend - extension modules * C backend - standalone programs @@ -22,3 +81,4 @@ * (optional) common problems with RPython * ... + From antocuni at codespeak.net Tue Jun 19 17:35:51 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Tue, 19 Jun 2007 17:35:51 +0200 (CEST) Subject: [pypy-svn] r44380 - pypy/extradoc/talk/ep2007 Message-ID: <20070619153551.092B980C8@code0.codespeak.net> Author: antocuni Date: Tue Jun 19 17:35:51 2007 New Revision: 44380 Modified: pypy/extradoc/talk/ep2007/rpython.txt Log: some minor changes Modified: pypy/extradoc/talk/ep2007/rpython.txt ============================================================================== --- pypy/extradoc/talk/ep2007/rpython.txt (original) +++ pypy/extradoc/talk/ep2007/rpython.txt Tue Jun 19 17:35:51 2007 @@ -12,11 +12,11 @@ * Grown as side effect of the pypy project -* Python is too slow +* Python is too slow for some purposes * Pyrex/C are ugly -* We want to play with Python as much as possible +* We want to play as it were Python as much as possible What is RPython? ---------------- @@ -26,7 +26,7 @@ * Restricted subset -* Constructed from living objects - initialization +* Constructed from live objects - initialization is fully done in Python * XXX more? @@ -34,12 +34,15 @@ Restricted, what do you mean? ----------------------------- -* No dynamic stuff (from __ methods only - __init__ and __del__ works) +* Full type inference - you cannot mix incompatible types -* No frames and such stuff +* No dynamic stuff: switch class, add/remove methods, etc. + +* Java-like object model -* Full type inference - you cannot mix types +* No support for special methods (only __init__ and __del__ works) + +* No frames and such stuff XXX crappy examples expand or delete (probably would be XXX better to just say few words @@ -55,9 +58,9 @@ * Write code -* test it +* test/debug on top of CPython -* compile it +* compile * graph viewer From fijal at codespeak.net Tue Jun 19 18:06:03 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 19 Jun 2007 18:06:03 +0200 (CEST) Subject: [pypy-svn] r44382 - pypy/extradoc/talk/ep2007 Message-ID: <20070619160603.8E49C80EA@code0.codespeak.net> Author: fijal Date: Tue Jun 19 18:06:03 2007 New Revision: 44382 Modified: pypy/extradoc/talk/ep2007/rpython.txt Log: Another update Modified: pypy/extradoc/talk/ep2007/rpython.txt ============================================================================== --- pypy/extradoc/talk/ep2007/rpython.txt (original) +++ pypy/extradoc/talk/ep2007/rpython.txt Tue Jun 19 18:06:03 2007 @@ -64,18 +64,54 @@ * graph viewer +Type inference +-------------- -.... +XXXX should we really mention that? -* Few words about type annotation +RPython - why you wouldn't like to use it +----------------------------------------- -* Big disclaimer: use at your own risk +* RPython is quite new -* C backend - extension modules +* Wasn't meant to be a general purpose language from scratch -* C backend - standalone programs +* Type inference usually gives bogus erros -* CLI/JVM backend +* Compilation errors are far from perfect in general + +RPython - on the other hand... +------------------------------ + +* it's about 60x faster than CPython + +* no more pros... + +Writing standalone C programs +----------------------------- + +XXX explain + +Writing CPython extensions +--------------------------- + +XXX disclaimer +XXX using extcompiler + +The CLI backend +--------------- + +XXX anto, feel free to fill + +The JVM backend +--------------- + +XXX anto, feel free to fill + +The JS backend +-------------- + +XXX fijal, feel free to fill in * creating .NET libraries for C#/IronPython (in the future also for Java/Jython) From fijal at codespeak.net Tue Jun 19 18:46:55 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 19 Jun 2007 18:46:55 +0200 (CEST) Subject: [pypy-svn] r44383 - pypy/extradoc/talk/ep2007 Message-ID: <20070619164655.915E180F1@code0.codespeak.net> Author: fijal Date: Tue Jun 19 18:46:54 2007 New Revision: 44383 Modified: pypy/extradoc/talk/ep2007/interpreter.txt Log: Some updates - crappy though Modified: pypy/extradoc/talk/ep2007/interpreter.txt ============================================================================== --- pypy/extradoc/talk/ep2007/interpreter.txt (original) +++ pypy/extradoc/talk/ep2007/interpreter.txt Tue Jun 19 18:46:54 2007 @@ -1,19 +1,68 @@ -* disclaimer (not ready for production use, etc) +================================= +PyPy's interpreter features +================================= + +:Authors: Maciej Fijalkowski & Holger Krekel (merlinux GmbH) +:Place: Europython 2007 +:Date: XXX + +What features? +-------------- + +* We don't change python syntax nor semantics + +* avoiding religious war... + +* they give new dimensions to how you can use pypy + +* peak the feature set of your choice... + +XXX crap + +Multiple object implementations +------------------------------- + +XXX rant about python exposing impl details to use? (sets vs dicts) + +* same types - different implementations + +* example - ropes + +* example - multidicts + +Transparent proxy +----------------- + +* proxy: intercept any operation on an builtin object + +* transparent: don't change object interface + +* useful for implementing application level functionality + orthogonally to usage of objects + +* is the mechanism for distribution and persistence prototypes + +* see also .NET TransparentProxy + + + + -* those features doesn't change syntax nor semantics of a language -* multiple object implementations (ropes, xxx) -* tproxy * distribution * stackless -* security +* security (taint space) -* taint space +* thunk space -* JIT (unsure, will be on a previous talk) +* persistance + +* JIT (unsure, will be on the previous talk) * pickling computations? + +* disclaimer (not ready for production use, etc) From arigo at codespeak.net Tue Jun 19 20:13:30 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 19 Jun 2007 20:13:30 +0200 (CEST) Subject: [pypy-svn] r44384 - pypy/dist/dotviewer Message-ID: <20070619181330.5076680E6@code0.codespeak.net> Author: arigo Date: Tue Jun 19 20:13:29 2007 New Revision: 44384 Modified: pypy/dist/dotviewer/graphparse.py Log: Improve the heuristic to detect the input file type. Modified: pypy/dist/dotviewer/graphparse.py ============================================================================== --- pypy/dist/dotviewer/graphparse.py (original) +++ pypy/dist/dotviewer/graphparse.py Tue Jun 19 20:13:29 2007 @@ -6,16 +6,41 @@ import msgstruct re_nonword = re.compile(r'([^0-9a-zA-Z_.]+)') +re_plain = re.compile(r'graph [-0-9.]+ [-0-9.]+ [-0-9.]+$', re.MULTILINE) +re_digraph = re.compile(r'\b(graph|digraph)\b', re.IGNORECASE) +def guess_type(content): + # try to see whether it is a directed graph or not, + # or already a .plain file + # XXX not a perfect heursitic + if re_plain.match(content): + return 'plain' # already a .plain file + # look for the word 'graph' or 'digraph' followed by a '{'. + bracepos = None + lastfound = '' + for match in re_digraph.finditer(content): + position = match.start() + if bracepos is None: + bracepos = content.find('{', position) + if bracepos < 0: + break + elif position > bracepos: + break + lastfound = match.group() + if lastfound.lower() == 'digraph': + return 'dot' + if lastfound.lower() == 'graph': + return 'neato' + print >> sys.stderr, "Warning: could not guess file type, using 'dot'" + return 'unknown' -def dot2plain(content, use_codespeak=False): - if content.startswith('graph '): +def dot2plain(content, contenttype, use_codespeak=False): + if contenttype == 'plain': # already a .plain file return content if not use_codespeak: - # try to see whether it is a directed graph or not: - if "digraph" in content: + if contenttype != 'neato': cmdline = 'dot -Tplain' else: cmdline = 'neato -Tplain' @@ -112,10 +137,11 @@ yield (msgstruct.CMSG_STOP_GRAPH,) def parse_dot(graph_id, content, links={}, fixedfont=False): + contenttype = guess_type(content) try: - plaincontent = dot2plain(content, use_codespeak=False) + plaincontent = dot2plain(content, contenttype, use_codespeak=False) return list(parse_plain(graph_id, plaincontent, links, fixedfont)) except PlainParseError: # failed, retry via codespeak - plaincontent = dot2plain(content, use_codespeak=True) + plaincontent = dot2plain(content, contenttype, use_codespeak=True) return list(parse_plain(graph_id, plaincontent, links, fixedfont)) From arigo at codespeak.net Tue Jun 19 20:13:50 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 19 Jun 2007 20:13:50 +0200 (CEST) Subject: [pypy-svn] r44385 - pypy/dist/dotviewer Message-ID: <20070619181350.3653480F8@code0.codespeak.net> Author: arigo Date: Tue Jun 19 20:13:49 2007 New Revision: 44385 Modified: pypy/dist/dotviewer/graphpage.py Log: Avoid the unnecessary traceback from a RemoteError. Modified: pypy/dist/dotviewer/graphpage.py ============================================================================== --- pypy/dist/dotviewer/graphpage.py (original) +++ pypy/dist/dotviewer/graphpage.py Tue Jun 19 20:13:49 2007 @@ -24,13 +24,17 @@ def display(self): "Display a graph page." - import graphclient - graphclient.display_page(self) + import graphclient, msgstruct + try: + graphclient.display_page(self) + except msgstruct.RemoteError, e: + import sys + print >> sys.stderr, "Exception in the graph viewer:", str(e) def display_background(self): "Display a graph page in a background thread." - import graphclient, thread - thread.start_new_thread(graphclient.display_page, (self,)) + import thread + thread.start_new_thread(self.display, ()) class DotFileGraphPage(GraphPage): From cfbolz at codespeak.net Tue Jun 19 21:12:43 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Tue, 19 Jun 2007 21:12:43 +0200 (CEST) Subject: [pypy-svn] r44386 - in pypy/dist/pypy/rlib/parsing: . test Message-ID: <20070619191243.2479880F2@code0.codespeak.net> Author: cfbolz Date: Tue Jun 19 21:12:41 2007 New Revision: 44386 Modified: pypy/dist/pypy/rlib/parsing/regex.py pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py pypy/dist/pypy/rlib/parsing/test/test_regexparse.py Log: migrating to the new parser generator: run all the regexparse tests with the new regex parser. Modified: pypy/dist/pypy/rlib/parsing/regex.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/regex.py (original) +++ pypy/dist/pypy/rlib/parsing/regex.py Tue Jun 19 21:12:41 2007 @@ -17,6 +17,12 @@ def __pos__(self): return AddExpression(self, self.kleene()) + def __mul__(self, i): + result = StringExpression("") + for x in range(i): + result += self + return result + def __invert__(self): return NotExpression(self) Modified: pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Tue Jun 19 21:12:41 2007 @@ -334,82 +334,3 @@ assert p._pos == 2 assert res == "c" - def test_regexparse(self): - py.test.skip() - class RegexParser(PackratParser): - """ - regex: - r1 = concatenation - '|' - r2 = regex - return {r1 | r2} - | concatenation; - - concatenation: - r1 = repetition - r2 = concatenation - return {r1 + r2} - | repetition; - - repetition: - r1 = primary - '*' - return {r1.kleene()} - | r1 = primary - '+' - return {r1 + r1.kleene()} - | r1 = primary - '?' - return {regex.StringExpression("") | r1} - | r = primary - '{' - n = numrange - '}' - return {r * n[0] + reduce(operator.or_, - [r * i for i in range(n[1] - n[0])], - regex.StringExpression("")} - | primary; - - primary: - ['('] regex [')'] - | ['['] range [']'] - | char - | '.' - return {regex.RangeExpression(chr(0), chr(255))}; - - char: - c = QUOTEDCHAR - return {regex.StringExpression(unescape(c))} - | c = CHAR - return {regex.StringExpression(c)}; - - range: - '^' - r = subrange - return {~r} - | subrange; - - subrange: - l = rangeelement+ - return {reduce(operator.or_, l, regex.StringExpression(""))}; - - rangeelement: - c1 = char - '-' - c2 = char - return {regex.RangeExpression(c1, c2)} - | c = char - return {regex.StringExpression(c)}; - - numrange: - n1 = NUM - ',' - n2 = NUM - return {n1, n2} - | n1 = NUM - return {n1, n1}; - - NUM: - c = `0|([1-9][0-9]*)` - return {int(c)}; - """ Modified: pypy/dist/pypy/rlib/parsing/test/test_regexparse.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_regexparse.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_regexparse.py Tue Jun 19 21:12:41 2007 @@ -1,4 +1,119 @@ -from pypy.rlib.parsing.regexparse import make_runner +import py +from pypy.rlib.parsing.regexparse import make_runner, unescape +from pypy.rlib.parsing import regex +import operator +from pypy.rlib.parsing.makepackrat import PackratParser as _PackratParser +from pypy.rlib.parsing.deterministic import compress_char_set, DFA + +class RegexParser(_PackratParser): + r""" + EOF: + !__any__; + + parse: + regex + [EOF]; + + regex: + r1 = concatenation + '|' + r2 = regex + return {r1 | r2} + | concatenation; + + concatenation: + l = repetition+ + return {reduce(operator.add, l, regex.StringExpression(""))}; + + repetition: + r1 = primary + '*' + return {r1.kleene()} + | r1 = primary + '+' + return {r1 + r1.kleene()} + | r1 = primary + '?' + return {regex.StringExpression("") | r1} + | r = primary + '{' + n = numrange + '}' + return {r * n[0] + reduce(operator.or_, [r * i for i in range(n[1] - n[0] + 1)], regex.StringExpression(""))} + | primary; + + primary: + ['('] regex [')'] + | range + | c = char + return {regex.StringExpression(c)} + | '.' + return {regex.RangeExpression(chr(0), chr(255))}; + + char: + c = QUOTEDCHAR + return {unescape(c)} + | c = CHAR + return {c}; + + QUOTEDCHAR: + `(\\x[0-9a-fA-F]{2})|(\\.)`; + + CHAR: + `[^\*\+\(\)\[\]\{\}\|\.\-\?\,\^]`; + + range: + '[' + s = rangeinner + ']' + return {reduce(operator.or_, [regex.RangeExpression(a, chr(ord(a) + b - 1)) for a, b in compress_char_set(s)])}; + + rangeinner: + '^' + s = subrange + return {set([chr(c) for c in range(256)]) - s} + | subrange; + + subrange: + l = rangeelement+ + return {reduce(operator.or_, l)}; + + rangeelement: + c1 = char + '-' + c2 = char + return {set([chr(i) for i in range(ord(c1), ord(c2) + 1)])} + | c = char + return {set([c])}; + + numrange: + n1 = NUM + ',' + n2 = NUM + return {n1, n2} + | n1 = NUM + return {n1, n1}; + + NUM: + c = `0|([1-9][0-9]*)` + return {int(c)}; + """ + + + +def make_runner(regex, view=False): + p = RegexParser(regex) + r = p.parse() + nfa = r.make_automaton() + dfa = nfa.make_deterministic() + if view: + dfa.view() + dfa.optimize() + if view: + dfa.view() + r = dfa.get_runner() + return r + def test_simple(): r = make_runner("a*") From arigo at codespeak.net Wed Jun 20 17:10:32 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 20 Jun 2007 17:10:32 +0200 (CEST) Subject: [pypy-svn] r44392 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070620151032.0083D810F@code0.codespeak.net> Author: arigo Date: Wed Jun 20 17:10:32 2007 New Revision: 44392 Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Log: More explicit links. Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/announcement.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Wed Jun 20 17:10:32 2007 @@ -44,9 +44,15 @@ If you?d like to come, please subscribe to the `pypy-sprint mailing list`_ and drop a note about your interests and post any questions. More -organisational information will be sent to that list. We'll keep -a list of `people`_ which we'll update (which you can do so yourself -if you have codespeak commit rights; let us know if you need it). +organisational information will be sent to that list. + +Please register by adding yourself on the following list (via svn): + + http://codespeak.net/svn/pypy/extradoc/sprintinfo/post-ep2007/people.txt + +or on the pypy-sprint mailing list if you do not yet have check-in rights: + + http://codespeak.net/mailman/listinfo/pypy-sprint --------------------------------------- Preparation (if you feel it is needed): @@ -62,7 +68,7 @@ questions to pypy-sprint at codespeak.net * if you need information about the conference, potential hotels, - directions etc we recommend to look at www.europython.org. + directions etc we recommend to look at http://www.europython.org. We are looking forward to meet you at the Vilnius Post EuroPython @@ -73,5 +79,4 @@ .. _getting-started: http://codespeak.net/pypy/dist/pypy/doc/getting-started.html .. _`pypy-sprint mailing list`: http://codespeak.net/mailman/listinfo/pypy-sprint -.. _`people`: people.html .. _`the technical reports available and other relevant documentation`: http://codespeak.net/pypy/dist/pypy/doc/index.html From arigo at codespeak.net Wed Jun 20 17:11:13 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 20 Jun 2007 17:11:13 +0200 (CEST) Subject: [pypy-svn] r44393 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070620151113.9C4EC8110@code0.codespeak.net> Author: arigo Date: Wed Jun 20 17:11:13 2007 New Revision: 44393 Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Log: Squash another non-ASCII character. Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/announcement.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Wed Jun 20 17:11:13 2007 @@ -42,7 +42,7 @@ Registration ------------ -If you?d like to come, please subscribe to the `pypy-sprint mailing list`_ +If you'd like to come, please subscribe to the `pypy-sprint mailing list`_ and drop a note about your interests and post any questions. More organisational information will be sent to that list. From arigo at codespeak.net Wed Jun 20 17:34:27 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 20 Jun 2007 17:34:27 +0200 (CEST) Subject: [pypy-svn] r44395 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070620153427.409F3811C@code0.codespeak.net> Author: arigo Date: Wed Jun 20 17:34:26 2007 New Revision: 44395 Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Log: "ep" is too obscure. Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/announcement.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Wed Jun 20 17:34:26 2007 @@ -7,10 +7,10 @@ - Reval Hotel Lietuva. If you plan to attend the sprint we recommend you to listen to the PyPy -technical talks (`ep schedule`_) during the +technical talks (`EuroPython schedule`_) during the conference since it will give you a good overview of the status of development. -.. _`ep schedule`: http://indico.cern.ch/conferenceTimeTable.py?confId=13919&showDate=all&showSession=all&detailLevel=contribution&viewMode=room +.. _`EuroPython schedule`: http://indico.cern.ch/conferenceTimeTable.py?confId=13919&showDate=all&showSession=all&detailLevel=contribution&viewMode=room On the morning of the first sprint day (12th) we will also have a tutorial session for those new to PyPy development. From arigo at codespeak.net Wed Jun 20 17:36:43 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 20 Jun 2007 17:36:43 +0200 (CEST) Subject: [pypy-svn] r44396 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070620153643.B77F7811D@code0.codespeak.net> Author: arigo Date: Wed Jun 20 17:36:43 2007 New Revision: 44396 Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Log: Increase readability of the .txt file. Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/announcement.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Wed Jun 20 17:36:43 2007 @@ -10,8 +10,6 @@ technical talks (`EuroPython schedule`_) during the conference since it will give you a good overview of the status of development. -.. _`EuroPython schedule`: http://indico.cern.ch/conferenceTimeTable.py?confId=13919&showDate=all&showSession=all&detailLevel=contribution&viewMode=room - On the morning of the first sprint day (12th) we will also have a tutorial session for those new to PyPy development. @@ -77,6 +75,9 @@ The PyPy team +.. See also .. + .. _getting-started: http://codespeak.net/pypy/dist/pypy/doc/getting-started.html .. _`pypy-sprint mailing list`: http://codespeak.net/mailman/listinfo/pypy-sprint .. _`the technical reports available and other relevant documentation`: http://codespeak.net/pypy/dist/pypy/doc/index.html +.. _`EuroPython schedule`: http://indico.cern.ch/conferenceTimeTable.py?confId=13919&showDate=all&showSession=all&detailLevel=contribution&viewMode=room From arigo at codespeak.net Wed Jun 20 17:59:19 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 20 Jun 2007 17:59:19 +0200 (CEST) Subject: [pypy-svn] r44397 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070620155919.7E813811E@code0.codespeak.net> Author: arigo Date: Wed Jun 20 17:59:18 2007 New Revision: 44397 Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt pypy/extradoc/sprintinfo/post-ep2007/people.txt Log: Mention that the 14th is also a full sprint day. Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/announcement.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Wed Jun 20 17:59:18 2007 @@ -11,7 +11,9 @@ conference since it will give you a good overview of the status of development. On the morning of the first sprint day (12th) we will also have a -tutorial session for those new to PyPy development. +tutorial session for those new to PyPy development. As 3 days is relatively +short for a PyPy sprint we suggest to travel back home on the 15th if +possible (but it is ok to attend less than 3 days too). ------------------------------ Goals and topics of the sprint Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/people.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/people.txt Wed Jun 20 17:59:18 2007 @@ -2,6 +2,8 @@ People coming to the Post EuroPython Sprint (Vilnius) 12-14 July 2007 ====================================================================== +The 14th is also a full sprint day. + People who have a ``?`` in their arrive/depart or accomodation column are known to be coming but there are no details available yet from them. From arigo at codespeak.net Wed Jun 20 19:05:46 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 20 Jun 2007 19:05:46 +0200 (CEST) Subject: [pypy-svn] r44398 - in pypy/dist/pypy: module/_curses rpython/lltypesystem rpython/lltypesystem/test rpython/module Message-ID: <20070620170546.D6F898074@code0.codespeak.net> Author: arigo Date: Wed Jun 20 19:05:46 2007 New Revision: 44398 Modified: pypy/dist/pypy/module/_curses/fficurses.py pypy/dist/pypy/rpython/lltypesystem/rffi.py pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py pypy/dist/pypy/rpython/lltypesystem/typecache.py pypy/dist/pypy/rpython/module/ll_os.py Log: For symmetry, add rffi.free_charp(). This is also a long-term good idea; for example, rffi.str2charp() could in some situations return a pointer directly into the RPython string data, if we're careful enough. Modified: pypy/dist/pypy/module/_curses/fficurses.py ============================================================================== --- pypy/dist/pypy/module/_curses/fficurses.py (original) +++ pypy/dist/pypy/module/_curses/fficurses.py Wed Jun 20 19:05:46 2007 @@ -51,7 +51,7 @@ try: curses_setupterm(ll_s, fd) finally: - lltype.free(ll_s, flavor='raw') + rffi.free_charp(ll_s) register_external(interp_curses._curses_setupterm_null, [int], llimpl=curses_setupterm_null_llimpl, @@ -75,7 +75,7 @@ res = rffi.charp2str(ll_res) return res finally: - lltype.free(ll_cap, flavor='raw') + rffi.free_charp(ll_cap) register_external(interp_curses._curses_tigetstr, [str], str, export_name='_curses.tigetstr', llimpl=tigetstr_llimpl) @@ -89,7 +89,7 @@ # XXX nasty trick stolen from CPython ll_res = c_tparm(ll_s, l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9]) - lltype.free(ll_s, flavor='raw') + rffi.free_charp(ll_s) res = rffi.charp2str(ll_res) return res Modified: pypy/dist/pypy/rpython/lltypesystem/rffi.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/rffi.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/rffi.py Wed Jun 20 19:05:46 2007 @@ -74,6 +74,9 @@ array[len(s)] = '\x00' return array +def free_charp(cp): + lltype.free(cp, flavor='raw') + # char* -> str # doesn't free char* def charp2str(cp): @@ -99,9 +102,8 @@ def free_charpp(ref): """ frees list of char**, NULL terminated """ - next = ref i = 0 - while next[i]: - lltype.free(next[i], flavor='raw') + while ref[i]: + free_charp(ref[i]) i += 1 lltype.free(ref, flavor='raw') Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py Wed Jun 20 19:05:46 2007 @@ -46,7 +46,7 @@ def f(): s = str2charp("xxx") res = z(s) - lltype.free(s, flavor='raw') + free_charp(s) return res xf = compile(f, [], backendopt=False) @@ -73,7 +73,7 @@ l_res = z(s) res = charp2str(l_res) lltype.free(l_res, flavor='raw') - lltype.free(s, flavor='raw') + free_charp(s) return len(res) xf = compile(f, [], backendopt=False) Modified: pypy/dist/pypy/rpython/lltypesystem/typecache.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/typecache.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/typecache.py Wed Jun 20 19:05:46 2007 @@ -1,5 +1,6 @@ # this is automatically generated cache files for c types platforms = { ('', ('32bit', 'ELF'), 'Linux'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 32, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}, -('i386', ('32bit', ''), 'Darwin'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 16, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32} +('i386', ('32bit', ''), 'Darwin'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 16, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}, +('Intel(R) Pentium(R) M processor 1.73GHz', ('32bit', ''), 'Linux'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 32, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32} } Modified: pypy/dist/pypy/rpython/module/ll_os.py ============================================================================== --- pypy/dist/pypy/rpython/module/ll_os.py (original) +++ pypy/dist/pypy/rpython/module/ll_os.py Wed Jun 20 19:05:46 2007 @@ -46,7 +46,7 @@ l_args = rffi.liststr2charpp(args) os_execv(l_path, l_args) rffi.free_charpp(l_args) - lltype.free(l_path, flavor='raw') + rffi.free_charp(l_path) raise OSError(rffi.c_errno, "execv failed") register_external(os.execv, [str, [str]], s_ImpossibleValue, llimpl= @@ -92,7 +92,7 @@ def utime_null_lltypeimpl(path): l_path = rffi.str2charp(path) error = ros_utime(l_path, lltype.nullptr(UTIMEBUFP.TO)) - lltype.free(l_path, flavor='raw') + rffi.free_charp(l_path) if error == -1: raise OSError(rffi.c_errno, "utime_null failed") register_external(ros.utime_null, [str], s_None, "ll_os.utime_null", @@ -106,7 +106,7 @@ actime, modtime = tp l_utimebuf.c_actime, l_utimebuf.c_modtime = int(actime), int(modtime) error = ros_utime(l_path, l_utimebuf) - lltype.free(l_path, flavor='raw') + rffi.free_charp(l_path) lltype.free(l_utimebuf, flavor='raw') if error == -1: raise OSError(rffi.c_errno, "utime_tuple failed") @@ -129,7 +129,7 @@ l_path = rffi.str2charp(path) mode = lltype.cast_primitive(mode_t, mode) result = os_open(l_path, flags, mode) - lltype.free(l_path, flavor='raw') + rffi.free_charp(l_path) if result == -1: raise OSError(rffi.c_errno, "os_open failed") return result From afa at codespeak.net Thu Jun 21 10:03:57 2007 From: afa at codespeak.net (afa at codespeak.net) Date: Thu, 21 Jun 2007 10:03:57 +0200 (CEST) Subject: [pypy-svn] r44404 - pypy/dist/pypy/rpython/lltypesystem Message-ID: <20070621080357.9395C80F6@code0.codespeak.net> Author: afa Date: Thu Jun 21 10:03:56 2007 New Revision: 44404 Modified: pypy/dist/pypy/rpython/lltypesystem/rfficache.py pypy/dist/pypy/rpython/lltypesystem/typecache.py Log: Update rfficache with win32 platform information. Also add a trailing comma to reduce the risk of future conflicts. Modified: pypy/dist/pypy/rpython/lltypesystem/rfficache.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/rfficache.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/rfficache.py Thu Jun 21 10:03:56 2007 @@ -51,7 +51,7 @@ def newline_repr(d): assert isinstance(d, dict) - return "{\n%s\n}" % ",\n".join(["%r:%r" % (k, v) for k, v in d.items()]) + return "{\n%s,\n}" % ",\n".join(["%r:%r" % (k, v) for k, v in d.items()]) def get_type_sizes(filename, platform_key=machine_key(), types=TYPES, compiler_exe=None): Modified: pypy/dist/pypy/rpython/lltypesystem/typecache.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/typecache.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/typecache.py Thu Jun 21 10:03:56 2007 @@ -1,6 +1,7 @@ # this is automatically generated cache files for c types platforms = { ('', ('32bit', 'ELF'), 'Linux'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 32, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}, +('', ('32bit', 'WindowsPE'), 'Windows'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}, ('i386', ('32bit', ''), 'Darwin'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 16, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}, -('Intel(R) Pentium(R) M processor 1.73GHz', ('32bit', ''), 'Linux'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 32, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32} +('Intel(R) Pentium(R) M processor 1.73GHz', ('32bit', ''), 'Linux'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 32, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}, } From cfbolz at codespeak.net Thu Jun 21 12:09:40 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 21 Jun 2007 12:09:40 +0200 (CEST) Subject: [pypy-svn] r44406 - in pypy/dist/pypy/rlib/parsing: . test Message-ID: <20070621100940.6EB9C8102@code0.codespeak.net> Author: cfbolz Date: Thu Jun 21 12:09:39 2007 New Revision: 44406 Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py pypy/dist/pypy/rlib/parsing/regexparse.py pypy/dist/pypy/rlib/parsing/test/test_regexparse.py Log: replace the regex parser with a new one, based on the experimental new parser generator. This replaces a lot of strange auto-generated code by less (but also strange) auto-generated code. It is necessary to check the auto-generated code in for bootstrapping reasons: to parse the regular-expression grammar, we need to parse regular expressions... Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/makepackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/makepackrat.py Thu Jun 21 12:09:39 2007 @@ -1,7 +1,6 @@ import py import sys from pypy.rlib.parsing.tree import Nonterminal, Symbol, RPythonVisitor -from pypy.rlib.parsing.regexparse import parse_regex class BacktrackException(Exception): def __init__(self, error=None): Modified: pypy/dist/pypy/rlib/parsing/regexparse.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/regexparse.py (original) +++ pypy/dist/pypy/rlib/parsing/regexparse.py Thu Jun 21 12:09:39 2007 @@ -1,3 +1,7 @@ + + + + import py from pypy.rlib.parsing.parsing import PackratParser, Rule from pypy.rlib.parsing.tree import Nonterminal @@ -59,55 +63,107 @@ result.append(ESCAPES[escaped]) return "".join(result) -def make_regex_parser(): - from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function - # construct regular expressions by hand, to not go completely insane - # because of quoting - special_chars = "*+()[]{}|.-?,^" - # lexer - QUOTES = [] - for escaped in ESCAPES.iterkeys(): - QUOTES.append(StringExpression(escaped)) - REST = StringExpression("a") - for p in string.printable: - if p not in special_chars: - REST = REST | StringExpression(p) - regexs1 = QUOTES + [REST] - names1 = ['QUOTEDCHAR'] * len(QUOTES) + ['CHAR'] - # parser - rs, rules, ToAST = parse_ebnf(""" - regex: concatenation "|" regex | ; - concatenation: repetition concatenation | ; - repetition: primary "*" | - primary "+" | - primary "?" | - primary "{" numrange "}" | - ; - primary: "(" ")" | - "[" range "]" | - char | "."; - char: QUOTEDCHAR | CHAR; - range: "^" subrange | subrange; - subrange: rangeelement+; - rangeelement: char "-" char | char; - numrange: num "," num | ; - num: CHAR+; - """) - names2, regexs2 = zip(*rs) - lexer = Lexer(regexs1 + list(regexs2), names1 + list(names2)) - parser = PackratParser(rules, "regex") - return parser, lexer, ToAST +syntax = r""" +EOF: + !__any__; + +parse: + regex + [EOF]; + +regex: + r1 = concatenation + '|' + r2 = regex + return {r1 | r2} + | concatenation; + +concatenation: + l = repetition+ + return {reduce(operator.add, l, regex.StringExpression(""))}; + +repetition: + r1 = primary + '*' + return {r1.kleene()} + | r1 = primary + '+' + return {r1 + r1.kleene()} + | r1 = primary + '?' + return {regex.StringExpression("") | r1} + | r = primary + '{' + n = numrange + '}' + return {r * n[0] + reduce(operator.or_, [r * i for i in range(n[1] - n[0] + 1)], regex.StringExpression(""))} + | primary; + +primary: + ['('] regex [')'] + | range + | c = char + return {regex.StringExpression(c)} + | '.' + return {regex.RangeExpression(chr(0), chr(255))}; + +char: + c = QUOTEDCHAR + return {unescape(c)} + | c = CHAR + return {c}; + +QUOTEDCHAR: + `(\\x[0-9a-fA-F]{2})|(\\.)`; + +CHAR: + `[^\*\+\(\)\[\]\{\}\|\.\-\?\,\^]`; + +range: + '[' + s = rangeinner + ']' + return {reduce(operator.or_, [regex.RangeExpression(a, chr(ord(a) + b - 1)) for a, b in compress_char_set(s)])}; + +rangeinner: + '^' + s = subrange + return {set([chr(c) for c in range(256)]) - s} + | subrange; + +subrange: + l = rangeelement+ + return {reduce(operator.or_, l)}; + +rangeelement: + c1 = char + '-' + c2 = char + return {set([chr(i) for i in range(ord(c1), ord(c2) + 1)])} + | c = char + return {set([c])}; + +numrange: + n1 = NUM + ',' + n2 = NUM + return {n1, n2} + | n1 = NUM + return {n1, n1}; + +NUM: + c = `0|([1-9][0-9]*)` + return {int(c)}; +""" + def parse_regex(s): - tokens = lexer.tokenize(s) - s = parser.parse(tokens) - s = s.visit(RegexToAST())[0] - res = s.visit(RegexBuilder()) - assert res is not None - return res + p = RegexParser(s) + r = p.parse() + return r -def make_runner(regex, view=False): - r = parse_regex(regex) +def make_runner(st, view=False): + r = parse_regex(st) dfa = r.make_automaton().make_deterministic() if view: dfa.view() @@ -117,5076 +173,1474 @@ r = dfa.get_runner() return r -class RegexBuilder(object): - def visit_regex(self, node): - return node.children[0].visit(self) | node.children[2].visit(self) - - def visit_concatenation(self, node): - return node.children[0].visit(self) + node.children[1].visit(self) - - def visit_repetition(self, node): - if len(node.children) == 4: - subregex = node.children[0].visit(self) - r1, r2 = node.children[2].visit(self) - if r1 >= r2: - return StringExpression("") - base = StringExpression("") - for i in range(r1): - base += subregex - rest = StringExpression("") - curr = StringExpression("") - for i in range(r2 - r1): - rest = rest | curr - curr += subregex - return base + rest - if node.children[1].additional_info == "*": - return node.children[0].visit(self).kleene() - elif node.children[1].additional_info == "+": - return + node.children[0].visit(self) - elif node.children[1].additional_info == "?": - return StringExpression("") | node.children[0].visit(self) - - def visit_primary(self, node): - if len(node.children) == 1: - if node.children[0].symbol == "char": - return node.children[0].visit(self) - elif node.children[0].additional_info == ".": - return RangeExpression(chr(0), chr(255)) - raise ParserError - if node.children[0].additional_info == "(": - return node.children[1].visit(self) - else: - return node.children[1].visit(self) +def make_runner(regex, view=False): + p = RegexParser(regex) + r = p.parse() + nfa = r.make_automaton() + dfa = nfa.make_deterministic() + if view: + dfa.view() + dfa.optimize() + if view: + dfa.view() + r = dfa.get_runner() + return r + - def visit_char(self, node): - if node.children[0].symbol == "QUOTEDCHAR": - quote = node.children[0].additional_info - return StringExpression(unescape(quote)) - else: - return StringExpression(node.children[0].additional_info[-1]) - def visit_range(self, node): - ranges = node.children[-1].visit(self) - invert = len(node.children) == 2 - result = set() - for a, b in ranges: - for i in range(ord(a), ord(b) + 1): - result.add(i) - if invert: - result = set(range(256)) - result - compressed = compress_char_set([chr(i) for i in result]) - return reduce(py.std.operator.or_, - [RangeExpression(a, chr(ord(a) + b - 1)) - for a, b in compressed]) - - def visit_subrange(self, node): - return [c.visit(self) for c in node.children] - - def visit_rangeelement(self, node): - if len(node.children) == 3: - r = (node.children[0].visit(self).string, - node.children[2].visit(self).string) - else: - char = node.children[0].visit(self).string - r = (char, char) - return r - - def visit_numrange(self, node): - r1 = node.children[0].visit(self)[0] - r2 = node.children[2].visit(self)[0] + 1 - return r1, r2 - - def visit_num(self, node): - r = int("".join([c.additional_info for c in node.children])) - return r, r + 1 # generated code between this line and its other occurence -class RegexToAST(object): - def visit_regex(self, node): - length = len(node.children) - if length == 1: - return self.visit_concatenation(node.children[0]) - children = [] - children.extend(self.visit_concatenation(node.children[0])) - children.extend([node.children[1]]) - children.extend(self.visit_regex(node.children[2])) - return [Nonterminal(node.symbol, children)] - def visit_concatenation(self, node): - length = len(node.children) - if length == 1: - return self.visit_repetition(node.children[0]) - children = [] - children.extend(self.visit_repetition(node.children[0])) - children.extend(self.visit_concatenation(node.children[1])) - return [Nonterminal(node.symbol, children)] - def visit_repetition(self, node): - length = len(node.children) - if length == 1: - return self.visit_primary(node.children[0]) - if length == 2: - if node.children[1].symbol == '__1_*': - children = [] - children.extend(self.visit_primary(node.children[0])) - children.extend([node.children[1]]) - return [Nonterminal(node.symbol, children)] - if node.children[1].symbol == '__2_+': - children = [] - children.extend(self.visit_primary(node.children[0])) - children.extend([node.children[1]]) - return [Nonterminal(node.symbol, children)] - children = [] - children.extend(self.visit_primary(node.children[0])) - children.extend([node.children[1]]) - return [Nonterminal(node.symbol, children)] - children = [] - children.extend(self.visit_primary(node.children[0])) - children.extend([node.children[1]]) - children.extend(self.visit_numrange(node.children[2])) - children.extend([node.children[3]]) - return [Nonterminal(node.symbol, children)] - def visit_primary(self, node): - length = len(node.children) - if length == 1: - if node.children[0].symbol == '__10_.': - children = [] - children.extend([node.children[0]]) - return [Nonterminal(node.symbol, children)] - children = [] - children.extend(self.visit_char(node.children[0])) - return [Nonterminal(node.symbol, children)] - if node.children[0].symbol == '__6_(': - return self.visit_regex(node.children[1]) - children = [] - children.extend([node.children[0]]) - children.extend(self.visit_range(node.children[1])) - children.extend([node.children[2]]) - return [Nonterminal(node.symbol, children)] - def visit_char(self, node): - length = len(node.children) - if node.children[0].symbol == 'CHAR': - children = [] - children.extend([node.children[0]]) - return [Nonterminal(node.symbol, children)] - children = [] - children.extend([node.children[0]]) - return [Nonterminal(node.symbol, children)] - def visit_range(self, node): - length = len(node.children) - if length == 1: - children = [] - children.extend(self.visit_subrange(node.children[0])) - return [Nonterminal(node.symbol, children)] - children = [] - children.extend([node.children[0]]) - children.extend(self.visit_subrange(node.children[1])) - return [Nonterminal(node.symbol, children)] - def visit__plus_symbol0(self, node): - length = len(node.children) - if length == 1: - children = [] - children.extend(self.visit_rangeelement(node.children[0])) - return [Nonterminal(node.symbol, children)] - children = [] - children.extend(self.visit_rangeelement(node.children[0])) - expr = self.visit__plus_symbol0(node.children[1]) - assert len(expr) == 1 - children.extend(expr[0].children) - return [Nonterminal(node.symbol, children)] - def visit_subrange(self, node): - children = [] - expr = self.visit__plus_symbol0(node.children[0]) - assert len(expr) == 1 - children.extend(expr[0].children) - return [Nonterminal(node.symbol, children)] - def visit_rangeelement(self, node): - length = len(node.children) - if length == 1: - children = [] - children.extend(self.visit_char(node.children[0])) - return [Nonterminal(node.symbol, children)] - children = [] - children.extend(self.visit_char(node.children[0])) - children.extend([node.children[1]]) - children.extend(self.visit_char(node.children[2])) - return [Nonterminal(node.symbol, children)] - def visit_numrange(self, node): - length = len(node.children) - if length == 1: - return self.visit_num(node.children[0]) - children = [] - children.extend(self.visit_num(node.children[0])) - children.extend([node.children[1]]) - children.extend(self.visit_num(node.children[2])) - return [Nonterminal(node.symbol, children)] - def visit__plus_symbol1(self, node): - length = len(node.children) - if length == 1: - children = [] - children.extend([node.children[0]]) - return [Nonterminal(node.symbol, children)] - children = [] - children.extend([node.children[0]]) - expr = self.visit__plus_symbol1(node.children[1]) - assert len(expr) == 1 - children.extend(expr[0].children) - return [Nonterminal(node.symbol, children)] - def visit_num(self, node): - children = [] - expr = self.visit__plus_symbol1(node.children[0]) - assert len(expr) == 1 - children.extend(expr[0].children) - return [Nonterminal(node.symbol, children)] -parser = PackratParser([Rule('regex', [['concatenation', '__0_|', 'regex'], ['concatenation']]), - Rule('concatenation', [['repetition', 'concatenation'], ['repetition']]), - Rule('repetition', [['primary', '__1_*'], ['primary', '__2_+'], ['primary', '__3_?'], ['primary', '__4_{', 'numrange', '__5_}'], ['primary']]), - Rule('primary', [['__6_(', 'regex', '__7_)'], ['__8_[', 'range', '__9_]'], ['char'], ['__10_.']]), - Rule('char', [['QUOTEDCHAR'], ['CHAR']]), - Rule('range', [['__11_^', 'subrange'], ['subrange']]), - Rule('_plus_symbol0', [['rangeelement', '_plus_symbol0'], ['rangeelement']]), - Rule('subrange', [['_plus_symbol0']]), - Rule('rangeelement', [['char', '__12_-', 'char'], ['char']]), - Rule('numrange', [['num', '__13_,', 'num'], ['num']]), - Rule('_plus_symbol1', [['CHAR', '_plus_symbol1'], ['CHAR']]), - Rule('num', [['_plus_symbol1']])], - 'regex') -def recognize(runner, i): - assert i >= 0 - input = runner.text - state = 0 - while 1: - if state == 0: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 0 - return ~i - if '\t' <= char <= '\r': - state = 1 - elif ' ' <= char <= "'": - state = 1 - elif '/' <= char <= '>': - state = 1 - elif '@' <= char <= 'Z': - state = 1 - elif '_' <= char <= 'z': - state = 1 - elif char == '~': - state = 1 - elif char == '(': - state = 2 - elif char == ',': - state = 3 - elif char == '\\': - state = 4 - elif char == '|': - state = 5 - elif char == '+': - state = 6 - elif char == '?': - state = 7 - elif char == '[': - state = 8 - elif char == '{': - state = 9 - elif char == '*': - state = 10 - elif char == '.': - state = 11 - elif char == '^': - state = 12 - elif char == ')': - state = 13 - elif char == '-': - state = 14 - elif char == ']': - state = 15 - elif char == '}': - state = 16 - else: - break - if state == 769: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 769 - return i - if char == '1': - state = 847 - elif char == '0': - state = 848 - elif char == '3': - state = 849 - elif char == '2': - state = 850 - elif char == '5': - state = 851 - elif char == '4': - state = 852 - elif char == '7': - state = 853 - elif char == '6': - state = 854 - else: - break - if state == 770: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 770 - return i - if char == '1': - state = 839 - elif char == '0': - state = 840 - elif char == '3': - state = 841 - elif char == '2': - state = 842 - elif char == '5': - state = 843 - elif char == '4': - state = 844 - elif char == '7': - state = 845 - elif char == '6': - state = 846 - else: - break - if state == 771: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 771 - return i - if char == '0': - state = 832 - elif char == '3': - state = 833 - elif char == '2': - state = 834 - elif char == '5': - state = 835 - elif char == '4': - state = 836 - elif char == '7': - state = 837 - elif char == '6': - state = 838 - elif char == '1': - state = 831 - else: - break - if state == 4: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 4 - return i - if char == '\x00': - state = 17 - elif char == '\x83': - state = 18 - elif char == '\x04': - state = 19 - elif char == '\x87': - state = 20 - elif char == '\x08': - state = 21 - elif char == '\x8b': - state = 22 - elif char == '\x0c': - state = 23 - elif char == '\x8f': - state = 24 - elif char == '\x10': - state = 25 - elif char == '\x93': - state = 26 - elif char == '\x14': - state = 27 - elif char == '\x97': - state = 28 - elif char == '\x18': - state = 29 - elif char == '\x9b': - state = 30 - elif char == '\x1c': - state = 31 - elif char == '\x9f': - state = 32 - elif char == ' ': - state = 33 - elif char == '\xa3': - state = 34 - elif char == '$': - state = 35 - elif char == '\xa7': - state = 36 - elif char == '(': - state = 37 - elif char == '\xab': - state = 38 - elif char == ',': - state = 39 - elif char == '\xaf': - state = 40 - elif char == '\xb3': - state = 41 - elif char == '\xb7': - state = 42 - elif char == '8': - state = 43 - elif char == '\xbb': - state = 44 - elif char == '<': - state = 45 - elif char == '\xbf': - state = 46 - elif char == '@': - state = 47 - elif char == '\xc3': - state = 48 - elif char == 'D': - state = 49 - elif char == '\xc7': - state = 50 - elif char == 'H': - state = 51 - elif char == '\xcb': - state = 52 - elif char == 'L': - state = 53 - elif char == '\xcf': - state = 54 - elif char == 'P': - state = 55 - elif char == '\xd3': - state = 56 - elif char == 'T': - state = 57 - elif char == '\xd7': - state = 58 - elif char == 'X': - state = 59 - elif char == '\xdb': - state = 60 - elif char == '\\': - state = 61 - elif char == '\xdf': - state = 62 - elif char == '`': - state = 63 - elif char == '\xe3': - state = 64 - elif char == 'd': - state = 65 - elif char == '\xe7': - state = 66 - elif char == 'h': - state = 67 - elif char == '\xeb': - state = 68 - elif char == 'l': - state = 69 - elif char == '\xef': - state = 70 - elif char == 'p': - state = 71 - elif char == '\xf3': - state = 72 - elif char == 't': - state = 73 - elif char == '\xf7': - state = 74 - elif char == 'x': - state = 75 - elif char == '\xfb': - state = 76 - elif char == '|': - state = 77 - elif char == '\xff': - state = 78 - elif char == '\x80': - state = 79 - elif char == '\x03': - state = 80 - elif char == '\x84': - state = 81 - elif char == '\x07': - state = 82 - elif char == '\x88': - state = 83 - elif char == '\x0b': - state = 84 - elif char == '\x8c': - state = 85 - elif char == '\x0f': - state = 86 - elif char == '\x90': - state = 87 - elif char == '\x13': - state = 88 - elif char == '\x94': - state = 89 - elif char == '\x17': - state = 90 - elif char == '\x98': - state = 91 - elif char == '\x1b': - state = 92 - elif char == '\x9c': - state = 93 - elif char == '\x1f': - state = 94 - elif char == '\xa0': - state = 95 - elif char == '#': - state = 96 - elif char == '\xa4': - state = 97 - elif char == "'": - state = 98 - elif char == '\xa8': - state = 99 - elif char == '+': - state = 100 - elif char == '\xac': - state = 101 - elif char == '/': - state = 102 - elif char == '\xb0': - state = 103 - elif char == '\xb4': - state = 104 - elif char == '\xb8': - state = 105 - elif char == ';': - state = 106 - elif char == '\xbc': - state = 107 - elif char == '?': - state = 108 - elif char == '\xc0': - state = 109 - elif char == 'C': - state = 110 - elif char == '\xc4': - state = 111 - elif char == 'G': - state = 112 - elif char == '\xc8': - state = 113 - elif char == 'K': - state = 114 - elif char == '\xcc': - state = 115 - elif char == 'O': - state = 116 - elif char == '\xd0': - state = 117 - elif char == 'S': - state = 118 - elif char == '\xd4': - state = 119 - elif char == 'W': - state = 120 - elif char == '\xd8': - state = 121 - elif char == '[': - state = 122 - elif char == '\xdc': - state = 123 - elif char == '_': - state = 124 - elif char == '\xe0': - state = 125 - elif char == 'c': - state = 126 - elif char == '\xe4': - state = 127 - elif char == 'g': - state = 128 - elif char == '\xe8': - state = 129 - elif char == 'k': - state = 130 - elif char == '\xec': - state = 131 - elif char == 'o': - state = 132 - elif char == '\xf0': - state = 133 - elif char == 's': - state = 134 - elif char == '\xf4': - state = 135 - elif char == 'w': - state = 136 - elif char == '\xf8': - state = 137 - elif char == '{': - state = 138 - elif char == '\xfc': - state = 139 - elif char == '\x7f': - state = 140 - elif char == '\x81': - state = 141 - elif char == '\x02': - state = 142 - elif char == '\x85': - state = 143 - elif char == '\x06': - state = 144 - elif char == '\x89': - state = 145 - elif char == '\n': - state = 146 - elif char == '\x8d': - state = 147 - elif char == '\x0e': - state = 148 - elif char == '\x91': - state = 149 - elif char == '\x12': - state = 150 - elif char == '\x95': - state = 151 - elif char == '\x16': - state = 152 - elif char == '\x99': - state = 153 - elif char == '\x1a': - state = 154 - elif char == '\x9d': - state = 155 - elif char == '\x1e': - state = 156 - elif char == '\xa1': - state = 157 - elif char == '"': - state = 158 - elif char == '\xa5': - state = 159 - elif char == '&': - state = 160 - elif char == '\xa9': - state = 161 - elif char == '*': - state = 162 - elif char == '\xad': - state = 163 - elif char == '.': - state = 164 - elif char == '\xb1': - state = 165 - elif char == '\xb5': - state = 166 - elif char == '\xb9': - state = 167 - elif char == ':': - state = 168 - elif char == '\xbd': - state = 169 - elif char == '>': - state = 170 - elif char == '\xc1': - state = 171 - elif char == 'B': - state = 172 - elif char == '\xc5': - state = 173 - elif char == 'F': - state = 174 - elif char == '\xc9': - state = 175 - elif char == 'J': - state = 176 - elif char == '\xcd': - state = 177 - elif char == 'N': - state = 178 - elif char == '\xd1': - state = 179 - elif char == 'R': - state = 180 - elif char == '\xd5': - state = 181 - elif char == 'V': - state = 182 - elif char == '\xd9': - state = 183 - elif char == 'Z': - state = 184 - elif char == '\xdd': - state = 185 - elif char == '^': - state = 186 - elif char == '\xe1': - state = 187 - elif char == 'b': - state = 188 - elif char == '\xe5': - state = 189 - elif char == 'f': - state = 190 - elif char == '\xe9': - state = 191 - elif char == 'j': - state = 192 - elif char == '\xed': - state = 193 - elif char == 'n': - state = 194 - elif char == '\xf1': - state = 195 - elif char == 'r': - state = 196 - elif char == '\xf5': - state = 197 - elif char == 'v': - state = 198 - elif char == '\xf9': - state = 199 - elif char == 'z': - state = 200 - elif char == '\xfd': - state = 201 - elif char == '~': - state = 202 - elif char == '\x01': - state = 203 - elif char == '\x82': - state = 204 - elif char == '\x05': - state = 205 - elif char == '\x86': - state = 206 - elif char == '\t': - state = 207 - elif char == '\x8a': - state = 208 - elif char == '\r': - state = 209 - elif char == '\x8e': - state = 210 - elif char == '\x11': - state = 211 - elif char == '\x92': - state = 212 - elif char == '\x15': - state = 213 - elif char == '\x96': - state = 214 - elif char == '\x19': - state = 215 - elif char == '\x9a': - state = 216 - elif char == '\x1d': - state = 217 - elif char == '\x9e': - state = 218 - elif char == '!': - state = 219 - elif char == '\xa2': - state = 220 - elif char == '%': - state = 221 - elif char == '\xa6': - state = 222 - elif char == ')': - state = 223 - elif char == '\xaa': - state = 224 - elif char == '-': - state = 225 - elif char == '\xae': - state = 226 - elif char == '\xb2': - state = 227 - elif char == '\xb6': - state = 228 - elif char == '9': - state = 229 - elif char == '\xba': - state = 230 - elif char == '=': - state = 231 - elif char == '\xbe': - state = 232 - elif char == 'A': - state = 233 - elif char == '\xc2': - state = 234 - elif char == 'E': - state = 235 - elif char == '\xc6': - state = 236 - elif char == 'I': - state = 237 - elif char == '\xca': - state = 238 - elif char == 'M': - state = 239 - elif char == '\xce': - state = 240 - elif char == 'Q': - state = 241 - elif char == '\xd2': - state = 242 - elif char == 'U': - state = 243 - elif char == '\xd6': - state = 244 - elif char == 'Y': - state = 245 - elif char == '\xda': - state = 246 - elif char == ']': - state = 247 - elif char == '\xde': - state = 248 - elif char == 'a': - state = 249 - elif char == '\xe2': - state = 250 - elif char == 'e': - state = 251 - elif char == '\xe6': - state = 252 - elif char == 'i': - state = 253 - elif char == '\xea': - state = 254 - elif char == 'm': - state = 255 - elif char == '\xee': - state = 256 - elif char == 'q': - state = 257 - elif char == '\xf2': - state = 258 - elif char == 'u': - state = 259 - elif char == '\xf6': - state = 260 - elif char == 'y': - state = 261 - elif char == '\xfa': - state = 262 - elif char == '}': - state = 263 - elif char == '\xfe': - state = 264 - else: - break - if state == 773: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 773 - return i - if char == '1': - state = 815 - elif char == '0': - state = 816 - elif char == '3': - state = 817 - elif char == '2': - state = 818 - elif char == '5': - state = 819 - elif char == '4': - state = 820 - elif char == '7': - state = 821 - elif char == '6': - state = 822 - else: - break - if state == 774: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 774 - return i - if char == '1': - state = 807 - elif char == '0': - state = 808 - elif char == '3': - state = 809 - elif char == '2': - state = 810 - elif char == '5': - state = 811 - elif char == '4': - state = 812 - elif char == '7': - state = 813 - elif char == '6': - state = 814 - else: - break - if state == 942: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 942 - return i - if char == '1': - state = 1011 - elif char == '0': - state = 1012 - elif char == '3': - state = 1013 - elif char == '2': - state = 1014 - elif char == '5': - state = 1015 - elif char == '4': - state = 1016 - elif char == '7': - state = 1017 - elif char == '6': - state = 1018 - else: - break - if state == 776: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 776 - return i - if char == '1': - state = 791 - elif char == '0': - state = 792 - elif char == '3': - state = 793 - elif char == '2': - state = 794 - elif char == '5': - state = 795 - elif char == '4': - state = 796 - elif char == '7': - state = 797 - elif char == '6': - state = 798 - else: - break - if state == 265: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 265 - return ~i - if char == '1': - state = 941 - elif char == '0': - state = 942 - continue - elif char == '3': - state = 943 - elif char == '2': - state = 944 - elif char == '5': - state = 945 - elif char == '4': - state = 946 - elif char == '7': - state = 947 - elif char == '6': - state = 948 - elif char == '9': - state = 949 - elif char == '8': - state = 950 - elif char == 'A': - state = 951 - elif char == 'C': - state = 952 - elif char == 'B': - state = 953 - elif char == 'E': - state = 954 - elif char == 'D': - state = 955 - elif char == 'F': - state = 956 - elif char == 'a': - state = 957 - elif char == 'c': - state = 958 - elif char == 'b': - state = 959 - elif char == 'e': - state = 960 - elif char == 'd': - state = 961 - elif char == 'f': - state = 962 - else: - break - if state == 266: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 266 - return ~i - if char == '1': - state = 855 - elif char == '0': - state = 856 - elif char == '3': - state = 857 - elif char == '2': - state = 858 - elif char == '5': - state = 859 - elif char == '4': - state = 860 - elif char == '7': - state = 861 - elif char == '6': - state = 862 - elif char == '9': - state = 863 - elif char == '8': - state = 864 - elif char == 'A': - state = 865 - elif char == 'C': - state = 866 - elif char == 'B': - state = 867 - elif char == 'E': - state = 868 - elif char == 'D': - state = 869 - elif char == 'F': - state = 870 - elif char == 'a': - state = 871 - elif char == 'c': - state = 872 - elif char == 'b': - state = 873 - elif char == 'e': - state = 874 - elif char == 'd': - state = 875 - elif char == 'f': - state = 876 - else: - break - if state == 267: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 267 - return ~i - if char == '1': - state = 769 - continue - elif char == '0': - state = 770 - continue - elif char == '3': - state = 771 - continue - elif char == '2': - state = 772 - elif char == '5': - state = 773 - continue - elif char == '4': - state = 774 - continue - elif char == '7': - state = 775 - elif char == '6': - state = 776 - continue - elif char == '9': - state = 777 - elif char == '8': - state = 778 - elif char == 'A': - state = 779 - elif char == 'C': - state = 780 - elif char == 'B': - state = 781 - elif char == 'E': - state = 782 - elif char == 'D': - state = 783 - elif char == 'F': - state = 784 - elif char == 'a': - state = 785 - elif char == 'c': - state = 786 - elif char == 'b': - state = 787 - elif char == 'e': - state = 788 - elif char == 'd': - state = 789 - elif char == 'f': - state = 790 - else: - break - if state == 268: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 268 - return ~i - if char == '1': - state = 683 - elif char == '0': - state = 684 - elif char == '3': - state = 685 - elif char == '2': - state = 686 - elif char == '5': - state = 687 - elif char == '4': - state = 688 - elif char == '7': - state = 689 - elif char == '6': - state = 690 - elif char == '9': - state = 691 - elif char == '8': - state = 692 - elif char == 'A': - state = 693 - elif char == 'C': - state = 694 - elif char == 'B': - state = 695 - elif char == 'E': - state = 696 - elif char == 'D': - state = 697 - elif char == 'F': - state = 698 - elif char == 'a': - state = 699 - elif char == 'c': - state = 700 - elif char == 'b': - state = 701 - elif char == 'e': - state = 702 - elif char == 'd': - state = 703 - elif char == 'f': - state = 704 - else: - break - if state == 269: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 269 - return ~i - if char == '1': - state = 661 - elif char == '0': - state = 662 - elif char == '3': - state = 663 - elif char == '2': - state = 664 - elif char == '5': - state = 665 - elif char == '4': - state = 666 - elif char == '7': - state = 667 - elif char == '6': - state = 668 - elif char == '9': - state = 669 - elif char == '8': - state = 670 - elif char == 'A': - state = 671 - elif char == 'C': - state = 672 - elif char == 'B': - state = 673 - elif char == 'E': - state = 674 - elif char == 'D': - state = 675 - elif char == 'F': - state = 676 - elif char == 'a': - state = 677 - elif char == 'c': - state = 678 - elif char == 'b': - state = 679 - elif char == 'e': - state = 680 - elif char == 'd': - state = 681 - elif char == 'f': - state = 682 - else: - break - if state == 270: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 270 - return ~i - if char == '0': - state = 640 - elif char == '3': - state = 641 - elif char == '2': - state = 642 - elif char == '5': - state = 643 - elif char == '4': - state = 644 - elif char == '7': - state = 645 - elif char == '6': - state = 646 - elif char == '9': - state = 647 - elif char == '8': - state = 648 - elif char == 'A': - state = 649 - elif char == 'C': - state = 650 - elif char == 'B': - state = 651 - elif char == 'E': - state = 652 - elif char == 'D': - state = 653 - elif char == 'F': - state = 654 - elif char == 'a': - state = 655 - elif char == 'c': - state = 656 - elif char == 'b': - state = 657 - elif char == 'e': - state = 658 - elif char == 'd': - state = 659 - elif char == 'f': - state = 660 - elif char == '1': - state = 639 - else: - break - if state == 271: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 271 - return ~i - if char == '1': - state = 617 - elif char == '0': - state = 618 - elif char == '3': - state = 619 - elif char == '2': - state = 620 - elif char == '5': - state = 621 - elif char == '4': - state = 622 - elif char == '7': - state = 623 - elif char == '6': - state = 624 - elif char == '9': - state = 625 - elif char == '8': - state = 626 - elif char == 'A': - state = 627 - elif char == 'C': - state = 628 - elif char == 'B': - state = 629 - elif char == 'E': - state = 630 - elif char == 'D': - state = 631 - elif char == 'F': - state = 632 - elif char == 'a': - state = 633 - elif char == 'c': - state = 634 - elif char == 'b': - state = 635 - elif char == 'e': - state = 636 - elif char == 'd': - state = 637 - elif char == 'f': - state = 638 - else: - break - if state == 272: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 272 - return ~i - if char == '1': - state = 595 - elif char == '0': - state = 596 - elif char == '3': - state = 597 - elif char == '2': - state = 598 - elif char == '5': - state = 599 - elif char == '4': - state = 600 - elif char == '7': - state = 601 - elif char == '6': - state = 602 - elif char == '9': - state = 603 - elif char == '8': - state = 604 - elif char == 'A': - state = 605 - elif char == 'C': - state = 606 - elif char == 'B': - state = 607 - elif char == 'E': - state = 608 - elif char == 'D': - state = 609 - elif char == 'F': - state = 610 - elif char == 'a': - state = 611 - elif char == 'c': - state = 612 - elif char == 'b': - state = 613 - elif char == 'e': - state = 614 - elif char == 'd': - state = 615 - elif char == 'f': - state = 616 - else: - break - if state == 273: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 273 - return ~i - if char == '1': - state = 573 - elif char == '0': - state = 574 - elif char == '3': - state = 575 - elif char == '2': - state = 576 - elif char == '5': - state = 577 - elif char == '4': - state = 578 - elif char == '7': - state = 579 - elif char == '6': - state = 580 - elif char == '9': - state = 581 - elif char == '8': - state = 582 - elif char == 'A': - state = 583 - elif char == 'C': - state = 584 - elif char == 'B': - state = 585 - elif char == 'E': - state = 586 - elif char == 'D': - state = 587 - elif char == 'F': - state = 588 - elif char == 'a': - state = 589 - elif char == 'c': - state = 590 - elif char == 'b': - state = 591 - elif char == 'e': - state = 592 - elif char == 'd': - state = 593 - elif char == 'f': - state = 594 - else: - break - if state == 274: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 274 - return ~i - if char == '1': - state = 551 - elif char == '0': - state = 552 - elif char == '3': - state = 553 - elif char == '2': - state = 554 - elif char == '5': - state = 555 - elif char == '4': - state = 556 - elif char == '7': - state = 557 - elif char == '6': - state = 558 - elif char == '9': - state = 559 - elif char == '8': - state = 560 - elif char == 'A': - state = 561 - elif char == 'C': - state = 562 - elif char == 'B': - state = 563 - elif char == 'E': - state = 564 - elif char == 'D': - state = 565 - elif char == 'F': - state = 566 - elif char == 'a': - state = 567 - elif char == 'c': - state = 568 - elif char == 'b': - state = 569 - elif char == 'e': - state = 570 - elif char == 'd': - state = 571 - elif char == 'f': - state = 572 - else: - break - if state == 275: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 275 - return ~i - if char == '1': - state = 529 - elif char == '0': - state = 530 - elif char == '3': - state = 531 - elif char == '2': - state = 532 - elif char == '5': - state = 533 - elif char == '4': - state = 534 - elif char == '7': - state = 535 - elif char == '6': - state = 536 - elif char == '9': - state = 537 - elif char == '8': - state = 538 - elif char == 'A': - state = 539 - elif char == 'C': - state = 540 - elif char == 'B': - state = 541 - elif char == 'E': - state = 542 - elif char == 'D': - state = 543 - elif char == 'F': - state = 544 - elif char == 'a': - state = 545 - elif char == 'c': - state = 546 - elif char == 'b': - state = 547 - elif char == 'e': - state = 548 - elif char == 'd': - state = 549 - elif char == 'f': - state = 550 - else: - break - if state == 276: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 276 - return ~i - if char == '4': - state = 512 - elif char == '7': - state = 513 - elif char == '6': - state = 514 - elif char == '9': - state = 515 - elif char == '8': - state = 516 - elif char == 'A': - state = 517 - elif char == 'C': - state = 518 - elif char == 'B': - state = 519 - elif char == 'E': - state = 520 - elif char == 'D': - state = 521 - elif char == 'F': - state = 522 - elif char == 'a': - state = 523 - elif char == 'c': - state = 524 - elif char == 'b': - state = 525 - elif char == 'e': - state = 526 - elif char == 'd': - state = 527 - elif char == 'f': - state = 528 - elif char == '1': - state = 507 - elif char == '0': - state = 508 - elif char == '3': - state = 509 - elif char == '2': - state = 510 - elif char == '5': - state = 511 - else: - break - if state == 277: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 277 - return ~i - if char == '1': - state = 485 - elif char == '0': - state = 486 - elif char == '3': - state = 487 - elif char == '2': - state = 488 - elif char == '5': - state = 489 - elif char == '4': - state = 490 - elif char == '7': - state = 491 - elif char == '6': - state = 492 - elif char == '9': - state = 493 - elif char == '8': - state = 494 - elif char == 'A': - state = 495 - elif char == 'C': - state = 496 - elif char == 'B': - state = 497 - elif char == 'E': - state = 498 - elif char == 'D': - state = 499 - elif char == 'F': - state = 500 - elif char == 'a': - state = 501 - elif char == 'c': - state = 502 - elif char == 'b': - state = 503 - elif char == 'e': - state = 504 - elif char == 'd': - state = 505 - elif char == 'f': - state = 506 - else: - break - if state == 278: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 278 - return ~i - if char == '1': - state = 463 - elif char == '0': - state = 464 - elif char == '3': - state = 465 - elif char == '2': - state = 466 - elif char == '5': - state = 467 - elif char == '4': - state = 468 - elif char == '7': - state = 469 - elif char == '6': - state = 470 - elif char == '9': - state = 471 - elif char == '8': - state = 472 - elif char == 'A': - state = 473 - elif char == 'C': - state = 474 - elif char == 'B': - state = 475 - elif char == 'E': - state = 476 - elif char == 'D': - state = 477 - elif char == 'F': - state = 478 - elif char == 'a': - state = 479 - elif char == 'c': - state = 480 - elif char == 'b': - state = 481 - elif char == 'e': - state = 482 - elif char == 'd': - state = 483 - elif char == 'f': - state = 484 - else: - break - if state == 279: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 279 - return ~i - if char == '1': - state = 441 - elif char == '0': - state = 442 - elif char == '3': - state = 443 - elif char == '2': - state = 444 - elif char == '5': - state = 445 - elif char == '4': - state = 446 - elif char == '7': - state = 447 - elif char == '6': - state = 448 - elif char == '9': - state = 449 - elif char == '8': - state = 450 - elif char == 'A': - state = 451 - elif char == 'C': - state = 452 - elif char == 'B': - state = 453 - elif char == 'E': - state = 454 - elif char == 'D': - state = 455 - elif char == 'F': - state = 456 - elif char == 'a': - state = 457 - elif char == 'c': - state = 458 - elif char == 'b': - state = 459 - elif char == 'e': - state = 460 - elif char == 'd': - state = 461 - elif char == 'f': - state = 462 - else: - break - if state == 280: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 280 - return ~i - if char == '1': - state = 419 - elif char == '0': - state = 420 - elif char == '3': - state = 421 - elif char == '2': - state = 422 - elif char == '5': - state = 423 - elif char == '4': - state = 424 - elif char == '7': - state = 425 - elif char == '6': - state = 426 - elif char == '9': - state = 427 - elif char == '8': - state = 428 - elif char == 'A': - state = 429 - elif char == 'C': - state = 430 - elif char == 'B': - state = 431 - elif char == 'E': - state = 432 - elif char == 'D': - state = 433 - elif char == 'F': - state = 434 - elif char == 'a': - state = 435 - elif char == 'c': - state = 436 - elif char == 'b': - state = 437 - elif char == 'e': - state = 438 - elif char == 'd': - state = 439 - elif char == 'f': - state = 440 - else: - break - if state == 281: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 281 - return ~i - if char == '1': - state = 397 - elif char == '0': - state = 398 - elif char == '3': - state = 399 - elif char == '2': - state = 400 - elif char == '5': - state = 401 - elif char == '4': - state = 402 - elif char == '7': - state = 403 - elif char == '6': - state = 404 - elif char == '9': - state = 405 - elif char == '8': - state = 406 - elif char == 'A': - state = 407 - elif char == 'C': - state = 408 - elif char == 'B': - state = 409 - elif char == 'E': - state = 410 - elif char == 'D': - state = 411 - elif char == 'F': - state = 412 - elif char == 'a': - state = 413 - elif char == 'c': - state = 414 - elif char == 'b': - state = 415 - elif char == 'e': - state = 416 - elif char == 'd': - state = 417 - elif char == 'f': - state = 418 - else: - break - if state == 282: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 282 - return ~i - if char == '8': - state = 384 - elif char == 'A': - state = 385 - elif char == 'C': - state = 386 - elif char == 'B': - state = 387 - elif char == 'E': - state = 388 - elif char == 'D': - state = 389 - elif char == 'F': - state = 390 - elif char == 'a': - state = 391 - elif char == 'c': - state = 392 - elif char == 'b': - state = 393 - elif char == 'e': - state = 394 - elif char == 'd': - state = 395 - elif char == 'f': - state = 396 - elif char == '1': - state = 375 - elif char == '0': - state = 376 - elif char == '3': - state = 377 - elif char == '2': - state = 378 - elif char == '5': - state = 379 - elif char == '4': - state = 380 - elif char == '7': - state = 381 - elif char == '6': - state = 382 - elif char == '9': - state = 383 - else: - break - if state == 283: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 283 - return ~i - if char == '1': - state = 353 - elif char == '0': - state = 354 - elif char == '3': - state = 355 - elif char == '2': - state = 356 - elif char == '5': - state = 357 - elif char == '4': - state = 358 - elif char == '7': - state = 359 - elif char == '6': - state = 360 - elif char == '9': - state = 361 - elif char == '8': - state = 362 - elif char == 'A': - state = 363 - elif char == 'C': - state = 364 - elif char == 'B': - state = 365 - elif char == 'E': - state = 366 - elif char == 'D': - state = 367 - elif char == 'F': - state = 368 - elif char == 'a': - state = 369 - elif char == 'c': - state = 370 - elif char == 'b': - state = 371 - elif char == 'e': - state = 372 - elif char == 'd': - state = 373 - elif char == 'f': - state = 374 - else: - break - if state == 284: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 284 - return ~i - if char == '1': - state = 331 - elif char == '0': - state = 332 - elif char == '3': - state = 333 - elif char == '2': - state = 334 - elif char == '5': - state = 335 - elif char == '4': - state = 336 - elif char == '7': - state = 337 - elif char == '6': - state = 338 - elif char == '9': - state = 339 - elif char == '8': - state = 340 - elif char == 'A': - state = 341 - elif char == 'C': - state = 342 - elif char == 'B': - state = 343 - elif char == 'E': - state = 344 - elif char == 'D': - state = 345 - elif char == 'F': - state = 346 - elif char == 'a': - state = 347 - elif char == 'c': - state = 348 - elif char == 'b': - state = 349 - elif char == 'e': - state = 350 - elif char == 'd': - state = 351 - elif char == 'f': - state = 352 - else: - break - if state == 285: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 285 - return ~i - if char == '1': - state = 309 - elif char == '0': - state = 310 - elif char == '3': - state = 311 - elif char == '2': - state = 312 - elif char == '5': - state = 313 - elif char == '4': - state = 314 - elif char == '7': - state = 315 - elif char == '6': - state = 316 - elif char == '9': - state = 317 - elif char == '8': - state = 318 - elif char == 'A': - state = 319 - elif char == 'C': - state = 320 - elif char == 'B': - state = 321 - elif char == 'E': - state = 322 - elif char == 'D': - state = 323 - elif char == 'F': - state = 324 - elif char == 'a': - state = 325 - elif char == 'c': - state = 326 - elif char == 'b': - state = 327 - elif char == 'e': - state = 328 - elif char == 'd': - state = 329 - elif char == 'f': - state = 330 - else: - break - if state == 286: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 286 - return ~i - if char == '1': - state = 287 - elif char == '0': - state = 288 - elif char == '3': - state = 289 - elif char == '2': - state = 290 - elif char == '5': - state = 291 - elif char == '4': - state = 292 - elif char == '7': - state = 293 - elif char == '6': - state = 294 - elif char == '9': - state = 295 - elif char == '8': - state = 296 - elif char == 'A': - state = 297 - elif char == 'C': - state = 298 - elif char == 'B': - state = 299 - elif char == 'E': - state = 300 - elif char == 'D': - state = 301 - elif char == 'F': - state = 302 - elif char == 'a': - state = 303 - elif char == 'c': - state = 304 - elif char == 'b': - state = 305 - elif char == 'e': - state = 306 - elif char == 'd': - state = 307 - elif char == 'f': - state = 308 - else: - break - if state == 944: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 944 - return i - if char == '1': - state = 995 - elif char == '0': - state = 996 - elif char == '3': - state = 997 - elif char == '2': - state = 998 - elif char == '5': - state = 999 - elif char == '4': - state = 1000 - elif char == '7': - state = 1001 - elif char == '6': - state = 1002 - else: - break - if state == 689: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 689 - return i - if char == '1': - state = 713 - elif char == '0': - state = 714 - elif char == '3': - state = 715 - elif char == '2': - state = 716 - elif char == '5': - state = 717 - elif char == '4': - state = 718 - elif char == '7': - state = 719 - elif char == '6': - state = 720 - else: - break - if state == 683: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 683 - return i - if char == '6': - state = 768 - elif char == '1': - state = 761 - elif char == '0': - state = 762 - elif char == '3': - state = 763 - elif char == '2': - state = 764 - elif char == '5': - state = 765 - elif char == '4': - state = 766 - elif char == '7': - state = 767 - else: - break - if state == 684: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 684 - return i - if char == '1': - state = 753 - elif char == '0': - state = 754 - elif char == '3': - state = 755 - elif char == '2': - state = 756 - elif char == '5': - state = 757 - elif char == '4': - state = 758 - elif char == '7': - state = 759 - elif char == '6': - state = 760 - else: - break - if state == 941: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 941 - return i - if char == '4': - state = 1024 - elif char == '7': - state = 1025 - elif char == '6': - state = 1026 - elif char == '1': - state = 1019 - elif char == '0': - state = 1020 - elif char == '3': - state = 1021 - elif char == '2': - state = 1022 - elif char == '5': - state = 1023 - else: - break - if state == 686: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 686 - return i - if char == '1': - state = 737 - elif char == '0': - state = 738 - elif char == '3': - state = 739 - elif char == '2': - state = 740 - elif char == '5': - state = 741 - elif char == '4': - state = 742 - elif char == '7': - state = 743 - elif char == '6': - state = 744 - else: - break - if state == 943: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 943 - return i - if char == '1': - state = 1003 - elif char == '0': - state = 1004 - elif char == '3': - state = 1005 - elif char == '2': - state = 1006 - elif char == '5': - state = 1007 - elif char == '4': - state = 1008 - elif char == '7': - state = 1009 - elif char == '6': - state = 1010 - else: - break - if state == 688: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 688 - return i - if char == '1': - state = 721 - elif char == '0': - state = 722 - elif char == '3': - state = 723 - elif char == '2': - state = 724 - elif char == '5': - state = 725 - elif char == '4': - state = 726 - elif char == '7': - state = 727 - elif char == '6': - state = 728 - else: - break - if state == 945: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 945 - return i - if char == '4': - state = 992 - elif char == '7': - state = 993 - elif char == '6': - state = 994 - elif char == '1': - state = 987 - elif char == '0': - state = 988 - elif char == '3': - state = 989 - elif char == '2': - state = 990 - elif char == '5': - state = 991 - else: - break - if state == 690: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 690 - return i - if char == '1': - state = 705 - elif char == '0': - state = 706 - elif char == '3': - state = 707 - elif char == '2': - state = 708 - elif char == '5': - state = 709 - elif char == '4': - state = 710 - elif char == '7': - state = 711 - elif char == '6': - state = 712 - else: - break - if state == 947: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 947 - return i - if char == '1': - state = 971 - elif char == '0': - state = 972 - elif char == '3': - state = 973 - elif char == '2': - state = 974 - elif char == '5': - state = 975 - elif char == '4': - state = 976 - elif char == '7': - state = 977 - elif char == '6': - state = 978 - else: - break - if state == 948: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 948 - return i - if char == '1': - state = 963 - elif char == '0': - state = 964 - elif char == '3': - state = 965 - elif char == '2': - state = 966 - elif char == '5': - state = 967 - elif char == '4': - state = 968 - elif char == '7': - state = 969 - elif char == '6': - state = 970 - else: - break - if state == 687: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 687 - return i - if char == '6': - state = 736 - elif char == '1': - state = 729 - elif char == '0': - state = 730 - elif char == '3': - state = 731 - elif char == '2': - state = 732 - elif char == '5': - state = 733 - elif char == '4': - state = 734 - elif char == '7': - state = 735 - else: - break - if state == 75: - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 75 - return ~i - if char == '1': - state = 265 - continue - elif char == '0': - state = 266 - continue - elif char == '3': - state = 267 - continue - elif char == '2': - state = 268 - continue - elif char == '5': - state = 269 - continue - elif char == '4': - state = 270 - continue - elif char == '7': - state = 271 - continue - elif char == '6': - state = 272 - continue - elif char == '9': - state = 273 - continue - elif char == '8': - state = 274 - continue - elif char == 'A': - state = 275 - continue - elif char == 'C': - state = 276 - continue - elif char == 'B': - state = 277 - continue - elif char == 'E': - state = 278 - continue - elif char == 'D': - state = 279 - continue - elif char == 'F': - state = 280 - continue - elif char == 'a': - state = 281 - continue - elif char == 'c': - state = 282 - continue - elif char == 'b': - state = 283 - continue - elif char == 'e': - state = 284 - continue - elif char == 'd': - state = 285 - continue - elif char == 'f': - state = 286 - continue - else: - break - if state == 855: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 855 - return i - if char == '1': - state = 933 - elif char == '0': - state = 934 - elif char == '3': - state = 935 - elif char == '2': - state = 936 - elif char == '5': - state = 937 - elif char == '4': - state = 938 - elif char == '7': - state = 939 - elif char == '6': - state = 940 - else: - break - if state == 856: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 856 - return i - if char == '2': - state = 928 - elif char == '5': - state = 929 - elif char == '4': - state = 930 - elif char == '7': - state = 931 - elif char == '6': - state = 932 - elif char == '1': - state = 925 - elif char == '0': - state = 926 - elif char == '3': - state = 927 - else: - break - if state == 857: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 857 - return i - if char == '1': - state = 917 - elif char == '0': - state = 918 - elif char == '3': - state = 919 - elif char == '2': - state = 920 - elif char == '5': - state = 921 - elif char == '4': - state = 922 - elif char == '7': - state = 923 - elif char == '6': - state = 924 - else: - break - if state == 858: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 858 - return i - if char == '1': - state = 909 - elif char == '0': - state = 910 - elif char == '3': - state = 911 - elif char == '2': - state = 912 - elif char == '5': - state = 913 - elif char == '4': - state = 914 - elif char == '7': - state = 915 - elif char == '6': - state = 916 - else: - break - if state == 859: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 859 - return i - if char == '1': - state = 901 - elif char == '0': - state = 902 - elif char == '3': - state = 903 - elif char == '2': - state = 904 - elif char == '5': - state = 905 - elif char == '4': - state = 906 - elif char == '7': - state = 907 - elif char == '6': - state = 908 - else: - break - if state == 860: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 860 - return i - if char == '2': - state = 896 - elif char == '5': - state = 897 - elif char == '4': - state = 898 - elif char == '7': - state = 899 - elif char == '6': - state = 900 - elif char == '1': - state = 893 - elif char == '0': - state = 894 - elif char == '3': - state = 895 - else: - break - if state == 861: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 861 - return i - if char == '1': - state = 885 - elif char == '0': - state = 886 - elif char == '3': - state = 887 - elif char == '2': - state = 888 - elif char == '5': - state = 889 - elif char == '4': - state = 890 - elif char == '7': - state = 891 - elif char == '6': - state = 892 - else: - break - if state == 862: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 862 - return i - if char == '1': - state = 877 - elif char == '0': - state = 878 - elif char == '3': - state = 879 - elif char == '2': - state = 880 - elif char == '5': - state = 881 - elif char == '4': - state = 882 - elif char == '7': - state = 883 - elif char == '6': - state = 884 - else: - break - if state == 685: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 685 - return i - if char == '1': - state = 745 - elif char == '0': - state = 746 - elif char == '3': - state = 747 - elif char == '2': - state = 748 - elif char == '5': - state = 749 - elif char == '4': - state = 750 - elif char == '7': - state = 751 - elif char == '6': - state = 752 - else: - break - if state == 772: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 772 - return i - if char == '1': - state = 823 - elif char == '0': - state = 824 - elif char == '3': - state = 825 - elif char == '2': - state = 826 - elif char == '5': - state = 827 - elif char == '4': - state = 828 - elif char == '7': - state = 829 - elif char == '6': - state = 830 - else: + + +from pypy.rlib.parsing.pypackrat import PackratParser, _Status +from pypy.rlib.parsing import regex +import operator +class Parser(object): + class _Status_EOF(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def EOF(self): + return self._EOF().result + def _EOF(self): + _status = self._dict_EOF.get(self._pos, None) + if _status is None: + _status = self._dict_EOF[self._pos] = self._Status_EOF() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _choice0 = self._pos + _stored_result1 = _result + try: + _result = self.__any__() + except self._BacktrackException: + self._pos = _choice0 + _result = _stored_result1 + else: + raise self._BacktrackException(None) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._EOF() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_parse(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def parse(self): + return self._parse().result + def _parse(self): + _status = self._dict_parse.get(self._pos, None) + if _status is None: + _status = self._dict_parse[self._pos] = self._Status_parse() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _call_status = self._regex() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _before_discard2 = _result + _call_status = self._EOF() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _result = _before_discard2 + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._parse() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_regex(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def regex(self): + return self._regex().result + def _regex(self): + _status = self._dict_regex.get(self._pos, None) + if _status is None: + _status = self._dict_regex[self._pos] = self._Status_regex() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice3 = self._pos + try: + _call_status = self._concatenation() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + r1 = _result + _result = self.__chars__('|') + _call_status = self._regex() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + r2 = _result + _result = (r1 | r2) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice3 + _choice4 = self._pos + try: + _call_status = self._concatenation() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice4 + raise self._BacktrackException(_error) + _call_status = self._concatenation() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._regex() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_concatenation(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def concatenation(self): + return self._concatenation().result + def _concatenation(self): + _status = self._dict_concatenation.get(self._pos, None) + if _status is None: + _status = self._dict_concatenation[self._pos] = self._Status_concatenation() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _all5 = [] + _call_status = self._repetition() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all5.append(_result) + while 1: + _choice6 = self._pos + try: + _call_status = self._repetition() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all5.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice6 + break + _result = _all5 + l = _result + _result = (reduce(operator.add, l, regex.StringExpression(""))) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._concatenation() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_repetition(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def repetition(self): + return self._repetition().result + def _repetition(self): + _status = self._dict_repetition.get(self._pos, None) + if _status is None: + _status = self._dict_repetition[self._pos] = self._Status_repetition() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice7 = self._pos + try: + _call_status = self._primary() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + r1 = _result + _result = self.__chars__('*') + _result = (r1.kleene()) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice7 + _choice8 = self._pos + try: + _call_status = self._primary() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + r1 = _result + _result = self.__chars__('+') + _result = (r1 + r1.kleene()) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice8 + _choice9 = self._pos + try: + _call_status = self._primary() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + r1 = _result + _result = self.__chars__('?') + _result = (regex.StringExpression("") | r1) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice9 + _choice10 = self._pos + try: + _call_status = self._primary() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + r = _result + _result = self.__chars__('{') + _call_status = self._numrange() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + n = _result + _result = self.__chars__('}') + _result = (r * n[0] + reduce(operator.or_, [r * i for i in range(n[1] - n[0] + 1)], regex.StringExpression(""))) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice10 + _choice11 = self._pos + try: + _call_status = self._primary() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice11 + raise self._BacktrackException(_error) + _call_status = self._primary() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._repetition() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_primary(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def primary(self): + return self._primary().result + def _primary(self): + _status = self._dict_primary.get(self._pos, None) + if _status is None: + _status = self._dict_primary[self._pos] = self._Status_primary() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice12 = self._pos + try: + _before_discard13 = _result + _result = self.__chars__('(') + _result = _before_discard13 + _call_status = self._regex() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _before_discard14 = _result + _result = self.__chars__(')') + _result = _before_discard14 + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice12 + _choice15 = self._pos + try: + _call_status = self._range() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice15 + _choice16 = self._pos + try: + _call_status = self._char() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + c = _result + _result = (regex.StringExpression(c)) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice16 + _choice17 = self._pos + try: + _result = self.__chars__('.') + _result = (regex.RangeExpression(chr(0), chr(255))) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice17 + raise self._BacktrackException(_error) + _result = self.__chars__('.') + _result = (regex.RangeExpression(chr(0), chr(255))) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._primary() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_char(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def char(self): + return self._char().result + def _char(self): + _status = self._dict_char.get(self._pos, None) + if _status is None: + _status = self._dict_char[self._pos] = self._Status_char() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice18 = self._pos + try: + _call_status = self._QUOTEDCHAR() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + c = _result + _result = (unescape(c)) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice18 + _choice19 = self._pos + try: + _call_status = self._CHAR() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + c = _result + _result = (c) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice19 + raise self._BacktrackException(_error) + _call_status = self._CHAR() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + c = _result + _result = (c) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._char() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_QUOTEDCHAR(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def QUOTEDCHAR(self): + return self._QUOTEDCHAR().result + def _QUOTEDCHAR(self): + _status = self._dict_QUOTEDCHAR.get(self._pos, None) + if _status is None: + _status = self._dict_QUOTEDCHAR[self._pos] = self._Status_QUOTEDCHAR() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _result = self._regex1380912319() + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._QUOTEDCHAR() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_CHAR(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def CHAR(self): + return self._CHAR().result + def _CHAR(self): + _status = self._dict_CHAR.get(self._pos, None) + if _status is None: + _status = self._dict_CHAR[self._pos] = self._Status_CHAR() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _result = self._regex1323868075() + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._CHAR() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_range(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def range(self): + return self._range().result + def _range(self): + _status = self._dict_range.get(self._pos, None) + if _status is None: + _status = self._dict_range[self._pos] = self._Status_range() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _result = self.__chars__('[') + _call_status = self._rangeinner() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + s = _result + _result = self.__chars__(']') + _result = (reduce(operator.or_, [regex.RangeExpression(a, chr(ord(a) + b - 1)) for a, b in compress_char_set(s)])) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._range() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_rangeinner(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def rangeinner(self): + return self._rangeinner().result + def _rangeinner(self): + _status = self._dict_rangeinner.get(self._pos, None) + if _status is None: + _status = self._dict_rangeinner[self._pos] = self._Status_rangeinner() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice20 = self._pos + try: + _result = self.__chars__('^') + _call_status = self._subrange() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + s = _result + _result = (set([chr(c) for c in range(256)]) - s) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice20 + _choice21 = self._pos + try: + _call_status = self._subrange() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice21 + raise self._BacktrackException(_error) + _call_status = self._subrange() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._rangeinner() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_subrange(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def subrange(self): + return self._subrange().result + def _subrange(self): + _status = self._dict_subrange.get(self._pos, None) + if _status is None: + _status = self._dict_subrange[self._pos] = self._Status_subrange() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _all22 = [] + _call_status = self._rangeelement() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all22.append(_result) + while 1: + _choice23 = self._pos + try: + _call_status = self._rangeelement() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all22.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice23 + break + _result = _all22 + l = _result + _result = (reduce(operator.or_, l)) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._subrange() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_rangeelement(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def rangeelement(self): + return self._rangeelement().result + def _rangeelement(self): + _status = self._dict_rangeelement.get(self._pos, None) + if _status is None: + _status = self._dict_rangeelement[self._pos] = self._Status_rangeelement() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice24 = self._pos + try: + _call_status = self._char() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + c1 = _result + _result = self.__chars__('-') + _call_status = self._char() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + c2 = _result + _result = (set([chr(i) for i in range(ord(c1), ord(c2) + 1)])) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice24 + _choice25 = self._pos + try: + _call_status = self._char() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + c = _result + _result = (set([c])) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice25 + raise self._BacktrackException(_error) + _call_status = self._char() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + c = _result + _result = (set([c])) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._rangeelement() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_numrange(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def numrange(self): + return self._numrange().result + def _numrange(self): + _status = self._dict_numrange.get(self._pos, None) + if _status is None: + _status = self._dict_numrange[self._pos] = self._Status_numrange() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice26 = self._pos + try: + _call_status = self._NUM() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + n1 = _result + _result = self.__chars__(',') + _call_status = self._NUM() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + n2 = _result + _result = (n1, n2) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice26 + _choice27 = self._pos + try: + _call_status = self._NUM() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + n1 = _result + _result = (n1, n1) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice27 + raise self._BacktrackException(_error) + _call_status = self._NUM() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + n1 = _result + _result = (n1, n1) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._numrange() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + class _Status_NUM(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def NUM(self): + return self._NUM().result + def _NUM(self): + _status = self._dict_NUM.get(self._pos, None) + if _status is None: + _status = self._dict_NUM[self._pos] = self._Status_NUM() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _result = self._regex1166214427() + c = _result + _result = (int(c)) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._NUM() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) + def __init__(self, inputstream): + self._dict_EOF = {} + self._dict_parse = {} + self._dict_regex = {} + self._dict_concatenation = {} + self._dict_repetition = {} + self._dict_primary = {} + self._dict_char = {} + self._dict_QUOTEDCHAR = {} + self._dict_CHAR = {} + self._dict_range = {} + self._dict_rangeinner = {} + self._dict_subrange = {} + self._dict_rangeelement = {} + self._dict_numrange = {} + self._dict_NUM = {} + self._pos = 0 + self._inputstream = inputstream + def _regex1166214427(self): + _choice28 = self._pos + _runner = self._Runner(self._inputstream, self._pos) + _i = _runner.recognize_1166214427(self._pos) + if _runner.last_matched_state == -1: + self._pos = _choice28 + raise self._BacktrackException + _upto = _runner.last_matched_index + 1 + _result = self._inputstream[self._pos: _upto] + self._pos = _upto + return _result + def _regex1323868075(self): + _choice29 = self._pos + _runner = self._Runner(self._inputstream, self._pos) + _i = _runner.recognize_1323868075(self._pos) + if _runner.last_matched_state == -1: + self._pos = _choice29 + raise self._BacktrackException + _upto = _runner.last_matched_index + 1 + _result = self._inputstream[self._pos: _upto] + self._pos = _upto + return _result + def _regex1380912319(self): + _choice30 = self._pos + _runner = self._Runner(self._inputstream, self._pos) + _i = _runner.recognize_1380912319(self._pos) + if _runner.last_matched_state == -1: + self._pos = _choice30 + raise self._BacktrackException + _upto = _runner.last_matched_index + 1 + _result = self._inputstream[self._pos: _upto] + self._pos = _upto + return _result + class _Runner(object): + def __init__(self, text, pos): + self.text = text + self.pos = pos + self.last_matched_state = -1 + self.last_matched_index = -1 + self.state = -1 + def recognize_1166214427(runner, i): + assert i >= 0 + input = runner.text + state = 0 + while 1: + if state == 0: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 0 + return ~i + if char == '0': + state = 1 + elif '1' <= char <= '9': + state = 2 + else: + break + if state == 2: + runner.last_matched_index = i - 1 + runner.last_matched_state = state + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 2 + return i + if '0' <= char <= '9': + state = 2 + continue + else: + break + runner.last_matched_state = state + runner.last_matched_index = i - 1 + runner.state = state + if i == len(input): + return i + else: + return ~i break - if state == 775: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 775 - return i - if char == '0': - state = 800 - elif char == '3': - state = 801 - elif char == '2': - state = 802 - elif char == '5': - state = 803 - elif char == '4': - state = 804 - elif char == '7': - state = 805 - elif char == '6': - state = 806 - elif char == '1': - state = 799 - else: + runner.state = state + return ~i + def recognize_1323868075(runner, i): + assert i >= 0 + input = runner.text + state = 0 + while 1: + if state == 0: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 0 + return ~i + if '\x00' <= char <= "'": + state = 1 + elif '/' <= char <= '>': + state = 1 + elif '@' <= char <= 'Z': + state = 1 + elif char == '\\': + state = 1 + elif '_' <= char <= 'z': + state = 1 + elif '~' <= char <= '\xff': + state = 1 + else: + break + runner.last_matched_state = state + runner.last_matched_index = i - 1 + runner.state = state + if i == len(input): + return i + else: + return ~i break - if state == 946: - runner.last_matched_index = i - 1 - runner.last_matched_state = state - if i < len(input): - char = input[i] - i += 1 - else: - runner.state = 946 - return i - if char == '1': - state = 979 - elif char == '0': - state = 980 - elif char == '3': - state = 981 - elif char == '2': - state = 982 - elif char == '5': - state = 983 - elif char == '4': - state = 984 - elif char == '7': - state = 985 - elif char == '6': - state = 986 - else: + runner.state = state + return ~i + def recognize_1380912319(runner, i): + assert i >= 0 + input = runner.text + state = 0 + while 1: + if state == 0: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 0 + return ~i + if char == '\\': + state = 4 + else: + break + if state == 1: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 1 + return ~i + if '0' <= char <= '9': + state = 3 + elif 'A' <= char <= 'F': + state = 3 + elif 'a' <= char <= 'f': + state = 3 + else: + break + if state == 2: + runner.last_matched_index = i - 1 + runner.last_matched_state = state + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 2 + return i + if '0' <= char <= '9': + state = 1 + continue + elif 'A' <= char <= 'F': + state = 1 + continue + elif 'a' <= char <= 'f': + state = 1 + continue + else: + break + if state == 4: + if i < len(input): + char = input[i] + i += 1 + else: + runner.state = 4 + return ~i + if char == 'x': + state = 2 + continue + elif '\x00' <= char <= 'w': + state = 3 + elif 'y' <= char <= '\xff': + state = 3 + else: + break + runner.last_matched_state = state + runner.last_matched_index = i - 1 + runner.state = state + if i == len(input): + return i + else: + return ~i break - runner.last_matched_state = state - runner.last_matched_index = i - 1 - runner.state = state - if i == len(input): - return i - else: + runner.state = state return ~i - break - runner.state = state - return ~i -lexer = DummyLexer(recognize, DFA(1027, - {(0, '\t'): 1, - (0, '\n'): 1, - (0, '\x0b'): 1, - (0, '\x0c'): 1, - (0, '\r'): 1, - (0, ' '): 1, - (0, '!'): 1, - (0, '"'): 1, - (0, '#'): 1, - (0, '$'): 1, - (0, '%'): 1, - (0, '&'): 1, - (0, "'"): 1, - (0, '('): 2, - (0, ')'): 13, - (0, '*'): 10, - (0, '+'): 6, - (0, ','): 3, - (0, '-'): 14, - (0, '.'): 11, - (0, '/'): 1, - (0, '0'): 1, - (0, '1'): 1, - (0, '2'): 1, - (0, '3'): 1, - (0, '4'): 1, - (0, '5'): 1, - (0, '6'): 1, - (0, '7'): 1, - (0, '8'): 1, - (0, '9'): 1, - (0, ':'): 1, - (0, ';'): 1, - (0, '<'): 1, - (0, '='): 1, - (0, '>'): 1, - (0, '?'): 7, - (0, '@'): 1, - (0, 'A'): 1, - (0, 'B'): 1, - (0, 'C'): 1, - (0, 'D'): 1, - (0, 'E'): 1, - (0, 'F'): 1, - (0, 'G'): 1, - (0, 'H'): 1, - (0, 'I'): 1, - (0, 'J'): 1, - (0, 'K'): 1, - (0, 'L'): 1, - (0, 'M'): 1, - (0, 'N'): 1, - (0, 'O'): 1, - (0, 'P'): 1, - (0, 'Q'): 1, - (0, 'R'): 1, - (0, 'S'): 1, - (0, 'T'): 1, - (0, 'U'): 1, - (0, 'V'): 1, - (0, 'W'): 1, - (0, 'X'): 1, - (0, 'Y'): 1, - (0, 'Z'): 1, - (0, '['): 8, - (0, '\\'): 4, - (0, ']'): 15, - (0, '^'): 12, - (0, '_'): 1, - (0, '`'): 1, - (0, 'a'): 1, - (0, 'b'): 1, - (0, 'c'): 1, - (0, 'd'): 1, - (0, 'e'): 1, - (0, 'f'): 1, - (0, 'g'): 1, - (0, 'h'): 1, - (0, 'i'): 1, - (0, 'j'): 1, - (0, 'k'): 1, - (0, 'l'): 1, - (0, 'm'): 1, - (0, 'n'): 1, - (0, 'o'): 1, - (0, 'p'): 1, - (0, 'q'): 1, - (0, 'r'): 1, - (0, 's'): 1, - (0, 't'): 1, - (0, 'u'): 1, - (0, 'v'): 1, - (0, 'w'): 1, - (0, 'x'): 1, - (0, 'y'): 1, - (0, 'z'): 1, - (0, '{'): 9, - (0, '|'): 5, - (0, '}'): 16, - (0, '~'): 1, - (4, '\x00'): 17, - (4, '\x01'): 203, - (4, '\x02'): 142, - (4, '\x03'): 80, - (4, '\x04'): 19, - (4, '\x05'): 205, - (4, '\x06'): 144, - (4, '\x07'): 82, - (4, '\x08'): 21, - (4, '\t'): 207, - (4, '\n'): 146, - (4, '\x0b'): 84, - (4, '\x0c'): 23, - (4, '\r'): 209, - (4, '\x0e'): 148, - (4, '\x0f'): 86, - (4, '\x10'): 25, - (4, '\x11'): 211, - (4, '\x12'): 150, - (4, '\x13'): 88, - (4, '\x14'): 27, - (4, '\x15'): 213, - (4, '\x16'): 152, - (4, '\x17'): 90, - (4, '\x18'): 29, - (4, '\x19'): 215, - (4, '\x1a'): 154, - (4, '\x1b'): 92, - (4, '\x1c'): 31, - (4, '\x1d'): 217, - (4, '\x1e'): 156, - (4, '\x1f'): 94, - (4, ' '): 33, - (4, '!'): 219, - (4, '"'): 158, - (4, '#'): 96, - (4, '$'): 35, - (4, '%'): 221, - (4, '&'): 160, - (4, "'"): 98, - (4, '('): 37, - (4, ')'): 223, - (4, '*'): 162, - (4, '+'): 100, - (4, ','): 39, - (4, '-'): 225, - (4, '.'): 164, - (4, '/'): 102, - (4, '8'): 43, - (4, '9'): 229, - (4, ':'): 168, - (4, ';'): 106, - (4, '<'): 45, - (4, '='): 231, - (4, '>'): 170, - (4, '?'): 108, - (4, '@'): 47, - (4, 'A'): 233, - (4, 'B'): 172, - (4, 'C'): 110, - (4, 'D'): 49, - (4, 'E'): 235, - (4, 'F'): 174, - (4, 'G'): 112, - (4, 'H'): 51, - (4, 'I'): 237, - (4, 'J'): 176, - (4, 'K'): 114, - (4, 'L'): 53, - (4, 'M'): 239, - (4, 'N'): 178, - (4, 'O'): 116, - (4, 'P'): 55, - (4, 'Q'): 241, - (4, 'R'): 180, - (4, 'S'): 118, - (4, 'T'): 57, - (4, 'U'): 243, - (4, 'V'): 182, - (4, 'W'): 120, - (4, 'X'): 59, - (4, 'Y'): 245, - (4, 'Z'): 184, - (4, '['): 122, - (4, '\\'): 61, - (4, ']'): 247, - (4, '^'): 186, - (4, '_'): 124, - (4, '`'): 63, - (4, 'a'): 249, - (4, 'b'): 188, - (4, 'c'): 126, - (4, 'd'): 65, - (4, 'e'): 251, - (4, 'f'): 190, - (4, 'g'): 128, - (4, 'h'): 67, - (4, 'i'): 253, - (4, 'j'): 192, - (4, 'k'): 130, - (4, 'l'): 69, - (4, 'm'): 255, - (4, 'n'): 194, - (4, 'o'): 132, - (4, 'p'): 71, - (4, 'q'): 257, - (4, 'r'): 196, - (4, 's'): 134, - (4, 't'): 73, - (4, 'u'): 259, - (4, 'v'): 198, - (4, 'w'): 136, - (4, 'x'): 75, - (4, 'y'): 261, - (4, 'z'): 200, - (4, '{'): 138, - (4, '|'): 77, - (4, '}'): 263, - (4, '~'): 202, - (4, '\x7f'): 140, - (4, '\x80'): 79, - (4, '\x81'): 141, - (4, '\x82'): 204, - (4, '\x83'): 18, - (4, '\x84'): 81, - (4, '\x85'): 143, - (4, '\x86'): 206, - (4, '\x87'): 20, - (4, '\x88'): 83, - (4, '\x89'): 145, - (4, '\x8a'): 208, - (4, '\x8b'): 22, - (4, '\x8c'): 85, - (4, '\x8d'): 147, - (4, '\x8e'): 210, - (4, '\x8f'): 24, - (4, '\x90'): 87, - (4, '\x91'): 149, - (4, '\x92'): 212, - (4, '\x93'): 26, - (4, '\x94'): 89, - (4, '\x95'): 151, - (4, '\x96'): 214, - (4, '\x97'): 28, - (4, '\x98'): 91, - (4, '\x99'): 153, - (4, '\x9a'): 216, - (4, '\x9b'): 30, - (4, '\x9c'): 93, - (4, '\x9d'): 155, - (4, '\x9e'): 218, - (4, '\x9f'): 32, - (4, '\xa0'): 95, - (4, '\xa1'): 157, - (4, '\xa2'): 220, - (4, '\xa3'): 34, - (4, '\xa4'): 97, - (4, '\xa5'): 159, - (4, '\xa6'): 222, - (4, '\xa7'): 36, - (4, '\xa8'): 99, - (4, '\xa9'): 161, - (4, '\xaa'): 224, - (4, '\xab'): 38, - (4, '\xac'): 101, - (4, '\xad'): 163, - (4, '\xae'): 226, - (4, '\xaf'): 40, - (4, '\xb0'): 103, - (4, '\xb1'): 165, - (4, '\xb2'): 227, - (4, '\xb3'): 41, - (4, '\xb4'): 104, - (4, '\xb5'): 166, - (4, '\xb6'): 228, - (4, '\xb7'): 42, - (4, '\xb8'): 105, - (4, '\xb9'): 167, - (4, '\xba'): 230, - (4, '\xbb'): 44, - (4, '\xbc'): 107, - (4, '\xbd'): 169, - (4, '\xbe'): 232, - (4, '\xbf'): 46, - (4, '\xc0'): 109, - (4, '\xc1'): 171, - (4, '\xc2'): 234, - (4, '\xc3'): 48, - (4, '\xc4'): 111, - (4, '\xc5'): 173, - (4, '\xc6'): 236, - (4, '\xc7'): 50, - (4, '\xc8'): 113, - (4, '\xc9'): 175, - (4, '\xca'): 238, - (4, '\xcb'): 52, - (4, '\xcc'): 115, - (4, '\xcd'): 177, - (4, '\xce'): 240, - (4, '\xcf'): 54, - (4, '\xd0'): 117, - (4, '\xd1'): 179, - (4, '\xd2'): 242, - (4, '\xd3'): 56, - (4, '\xd4'): 119, - (4, '\xd5'): 181, - (4, '\xd6'): 244, - (4, '\xd7'): 58, - (4, '\xd8'): 121, - (4, '\xd9'): 183, - (4, '\xda'): 246, - (4, '\xdb'): 60, - (4, '\xdc'): 123, - (4, '\xdd'): 185, - (4, '\xde'): 248, - (4, '\xdf'): 62, - (4, '\xe0'): 125, - (4, '\xe1'): 187, - (4, '\xe2'): 250, - (4, '\xe3'): 64, - (4, '\xe4'): 127, - (4, '\xe5'): 189, - (4, '\xe6'): 252, - (4, '\xe7'): 66, - (4, '\xe8'): 129, - (4, '\xe9'): 191, - (4, '\xea'): 254, - (4, '\xeb'): 68, - (4, '\xec'): 131, - (4, '\xed'): 193, - (4, '\xee'): 256, - (4, '\xef'): 70, - (4, '\xf0'): 133, - (4, '\xf1'): 195, - (4, '\xf2'): 258, - (4, '\xf3'): 72, - (4, '\xf4'): 135, - (4, '\xf5'): 197, - (4, '\xf6'): 260, - (4, '\xf7'): 74, - (4, '\xf8'): 137, - (4, '\xf9'): 199, - (4, '\xfa'): 262, - (4, '\xfb'): 76, - (4, '\xfc'): 139, - (4, '\xfd'): 201, - (4, '\xfe'): 264, - (4, '\xff'): 78, - (75, '0'): 266, - (75, '1'): 265, - (75, '2'): 268, - (75, '3'): 267, - (75, '4'): 270, - (75, '5'): 269, - (75, '6'): 272, - (75, '7'): 271, - (75, '8'): 274, - (75, '9'): 273, - (75, 'A'): 275, - (75, 'B'): 277, - (75, 'C'): 276, - (75, 'D'): 279, - (75, 'E'): 278, - (75, 'F'): 280, - (75, 'a'): 281, - (75, 'b'): 283, - (75, 'c'): 282, - (75, 'd'): 285, - (75, 'e'): 284, - (75, 'f'): 286, - (265, '0'): 942, - (265, '1'): 941, - (265, '2'): 944, - (265, '3'): 943, - (265, '4'): 946, - (265, '5'): 945, - (265, '6'): 948, - (265, '7'): 947, - (265, '8'): 950, - (265, '9'): 949, - (265, 'A'): 951, - (265, 'B'): 953, - (265, 'C'): 952, - (265, 'D'): 955, - (265, 'E'): 954, - (265, 'F'): 956, - (265, 'a'): 957, - (265, 'b'): 959, - (265, 'c'): 958, - (265, 'd'): 961, - (265, 'e'): 960, - (265, 'f'): 962, - (266, '0'): 856, - (266, '1'): 855, - (266, '2'): 858, - (266, '3'): 857, - (266, '4'): 860, - (266, '5'): 859, - (266, '6'): 862, - (266, '7'): 861, - (266, '8'): 864, - (266, '9'): 863, - (266, 'A'): 865, - (266, 'B'): 867, - (266, 'C'): 866, - (266, 'D'): 869, - (266, 'E'): 868, - (266, 'F'): 870, - (266, 'a'): 871, - (266, 'b'): 873, - (266, 'c'): 872, - (266, 'd'): 875, - (266, 'e'): 874, - (266, 'f'): 876, - (267, '0'): 770, - (267, '1'): 769, - (267, '2'): 772, - (267, '3'): 771, - (267, '4'): 774, - (267, '5'): 773, - (267, '6'): 776, - (267, '7'): 775, - (267, '8'): 778, - (267, '9'): 777, - (267, 'A'): 779, - (267, 'B'): 781, - (267, 'C'): 780, - (267, 'D'): 783, - (267, 'E'): 782, - (267, 'F'): 784, - (267, 'a'): 785, - (267, 'b'): 787, - (267, 'c'): 786, - (267, 'd'): 789, - (267, 'e'): 788, - (267, 'f'): 790, - (268, '0'): 684, - (268, '1'): 683, - (268, '2'): 686, - (268, '3'): 685, - (268, '4'): 688, - (268, '5'): 687, - (268, '6'): 690, - (268, '7'): 689, - (268, '8'): 692, - (268, '9'): 691, - (268, 'A'): 693, - (268, 'B'): 695, - (268, 'C'): 694, - (268, 'D'): 697, - (268, 'E'): 696, - (268, 'F'): 698, - (268, 'a'): 699, - (268, 'b'): 701, - (268, 'c'): 700, - (268, 'd'): 703, - (268, 'e'): 702, - (268, 'f'): 704, - (269, '0'): 662, - (269, '1'): 661, - (269, '2'): 664, - (269, '3'): 663, - (269, '4'): 666, - (269, '5'): 665, - (269, '6'): 668, - (269, '7'): 667, - (269, '8'): 670, - (269, '9'): 669, - (269, 'A'): 671, - (269, 'B'): 673, - (269, 'C'): 672, - (269, 'D'): 675, - (269, 'E'): 674, - (269, 'F'): 676, - (269, 'a'): 677, - (269, 'b'): 679, - (269, 'c'): 678, - (269, 'd'): 681, - (269, 'e'): 680, - (269, 'f'): 682, - (270, '0'): 640, - (270, '1'): 639, - (270, '2'): 642, - (270, '3'): 641, - (270, '4'): 644, - (270, '5'): 643, - (270, '6'): 646, - (270, '7'): 645, - (270, '8'): 648, - (270, '9'): 647, - (270, 'A'): 649, - (270, 'B'): 651, - (270, 'C'): 650, - (270, 'D'): 653, - (270, 'E'): 652, - (270, 'F'): 654, - (270, 'a'): 655, - (270, 'b'): 657, - (270, 'c'): 656, - (270, 'd'): 659, - (270, 'e'): 658, - (270, 'f'): 660, - (271, '0'): 618, - (271, '1'): 617, - (271, '2'): 620, - (271, '3'): 619, - (271, '4'): 622, - (271, '5'): 621, - (271, '6'): 624, - (271, '7'): 623, - (271, '8'): 626, - (271, '9'): 625, - (271, 'A'): 627, - (271, 'B'): 629, - (271, 'C'): 628, - (271, 'D'): 631, - (271, 'E'): 630, - (271, 'F'): 632, - (271, 'a'): 633, - (271, 'b'): 635, - (271, 'c'): 634, - (271, 'd'): 637, - (271, 'e'): 636, - (271, 'f'): 638, - (272, '0'): 596, - (272, '1'): 595, - (272, '2'): 598, - (272, '3'): 597, - (272, '4'): 600, - (272, '5'): 599, - (272, '6'): 602, - (272, '7'): 601, - (272, '8'): 604, - (272, '9'): 603, - (272, 'A'): 605, - (272, 'B'): 607, - (272, 'C'): 606, - (272, 'D'): 609, - (272, 'E'): 608, - (272, 'F'): 610, - (272, 'a'): 611, - (272, 'b'): 613, - (272, 'c'): 612, - (272, 'd'): 615, - (272, 'e'): 614, - (272, 'f'): 616, - (273, '0'): 574, - (273, '1'): 573, - (273, '2'): 576, - (273, '3'): 575, - (273, '4'): 578, - (273, '5'): 577, - (273, '6'): 580, - (273, '7'): 579, - (273, '8'): 582, - (273, '9'): 581, - (273, 'A'): 583, - (273, 'B'): 585, - (273, 'C'): 584, - (273, 'D'): 587, - (273, 'E'): 586, - (273, 'F'): 588, - (273, 'a'): 589, - (273, 'b'): 591, - (273, 'c'): 590, - (273, 'd'): 593, - (273, 'e'): 592, - (273, 'f'): 594, - (274, '0'): 552, - (274, '1'): 551, - (274, '2'): 554, - (274, '3'): 553, - (274, '4'): 556, - (274, '5'): 555, - (274, '6'): 558, - (274, '7'): 557, - (274, '8'): 560, - (274, '9'): 559, - (274, 'A'): 561, - (274, 'B'): 563, - (274, 'C'): 562, - (274, 'D'): 565, - (274, 'E'): 564, - (274, 'F'): 566, - (274, 'a'): 567, - (274, 'b'): 569, - (274, 'c'): 568, - (274, 'd'): 571, - (274, 'e'): 570, - (274, 'f'): 572, - (275, '0'): 530, - (275, '1'): 529, - (275, '2'): 532, - (275, '3'): 531, - (275, '4'): 534, - (275, '5'): 533, - (275, '6'): 536, - (275, '7'): 535, - (275, '8'): 538, - (275, '9'): 537, - (275, 'A'): 539, - (275, 'B'): 541, - (275, 'C'): 540, - (275, 'D'): 543, - (275, 'E'): 542, - (275, 'F'): 544, - (275, 'a'): 545, - (275, 'b'): 547, - (275, 'c'): 546, - (275, 'd'): 549, - (275, 'e'): 548, - (275, 'f'): 550, - (276, '0'): 508, - (276, '1'): 507, - (276, '2'): 510, - (276, '3'): 509, - (276, '4'): 512, - (276, '5'): 511, - (276, '6'): 514, - (276, '7'): 513, - (276, '8'): 516, - (276, '9'): 515, - (276, 'A'): 517, - (276, 'B'): 519, - (276, 'C'): 518, - (276, 'D'): 521, - (276, 'E'): 520, - (276, 'F'): 522, - (276, 'a'): 523, - (276, 'b'): 525, - (276, 'c'): 524, - (276, 'd'): 527, - (276, 'e'): 526, - (276, 'f'): 528, - (277, '0'): 486, - (277, '1'): 485, - (277, '2'): 488, - (277, '3'): 487, - (277, '4'): 490, - (277, '5'): 489, - (277, '6'): 492, - (277, '7'): 491, - (277, '8'): 494, - (277, '9'): 493, - (277, 'A'): 495, - (277, 'B'): 497, - (277, 'C'): 496, - (277, 'D'): 499, - (277, 'E'): 498, - (277, 'F'): 500, - (277, 'a'): 501, - (277, 'b'): 503, - (277, 'c'): 502, - (277, 'd'): 505, - (277, 'e'): 504, - (277, 'f'): 506, - (278, '0'): 464, - (278, '1'): 463, - (278, '2'): 466, - (278, '3'): 465, - (278, '4'): 468, - (278, '5'): 467, - (278, '6'): 470, - (278, '7'): 469, - (278, '8'): 472, - (278, '9'): 471, - (278, 'A'): 473, - (278, 'B'): 475, - (278, 'C'): 474, - (278, 'D'): 477, - (278, 'E'): 476, - (278, 'F'): 478, - (278, 'a'): 479, - (278, 'b'): 481, - (278, 'c'): 480, - (278, 'd'): 483, - (278, 'e'): 482, - (278, 'f'): 484, - (279, '0'): 442, - (279, '1'): 441, - (279, '2'): 444, - (279, '3'): 443, - (279, '4'): 446, - (279, '5'): 445, - (279, '6'): 448, - (279, '7'): 447, - (279, '8'): 450, - (279, '9'): 449, - (279, 'A'): 451, - (279, 'B'): 453, - (279, 'C'): 452, - (279, 'D'): 455, - (279, 'E'): 454, - (279, 'F'): 456, - (279, 'a'): 457, - (279, 'b'): 459, - (279, 'c'): 458, - (279, 'd'): 461, - (279, 'e'): 460, - (279, 'f'): 462, - (280, '0'): 420, - (280, '1'): 419, - (280, '2'): 422, - (280, '3'): 421, - (280, '4'): 424, - (280, '5'): 423, - (280, '6'): 426, - (280, '7'): 425, - (280, '8'): 428, - (280, '9'): 427, - (280, 'A'): 429, - (280, 'B'): 431, - (280, 'C'): 430, - (280, 'D'): 433, - (280, 'E'): 432, - (280, 'F'): 434, - (280, 'a'): 435, - (280, 'b'): 437, - (280, 'c'): 436, - (280, 'd'): 439, - (280, 'e'): 438, - (280, 'f'): 440, - (281, '0'): 398, - (281, '1'): 397, - (281, '2'): 400, - (281, '3'): 399, - (281, '4'): 402, - (281, '5'): 401, - (281, '6'): 404, - (281, '7'): 403, - (281, '8'): 406, - (281, '9'): 405, - (281, 'A'): 407, - (281, 'B'): 409, - (281, 'C'): 408, - (281, 'D'): 411, - (281, 'E'): 410, - (281, 'F'): 412, - (281, 'a'): 413, - (281, 'b'): 415, - (281, 'c'): 414, - (281, 'd'): 417, - (281, 'e'): 416, - (281, 'f'): 418, - (282, '0'): 376, - (282, '1'): 375, - (282, '2'): 378, - (282, '3'): 377, - (282, '4'): 380, - (282, '5'): 379, - (282, '6'): 382, - (282, '7'): 381, - (282, '8'): 384, - (282, '9'): 383, - (282, 'A'): 385, - (282, 'B'): 387, - (282, 'C'): 386, - (282, 'D'): 389, - (282, 'E'): 388, - (282, 'F'): 390, - (282, 'a'): 391, - (282, 'b'): 393, - (282, 'c'): 392, - (282, 'd'): 395, - (282, 'e'): 394, - (282, 'f'): 396, - (283, '0'): 354, - (283, '1'): 353, - (283, '2'): 356, - (283, '3'): 355, - (283, '4'): 358, - (283, '5'): 357, - (283, '6'): 360, - (283, '7'): 359, - (283, '8'): 362, - (283, '9'): 361, - (283, 'A'): 363, - (283, 'B'): 365, - (283, 'C'): 364, - (283, 'D'): 367, - (283, 'E'): 366, - (283, 'F'): 368, - (283, 'a'): 369, - (283, 'b'): 371, - (283, 'c'): 370, - (283, 'd'): 373, - (283, 'e'): 372, - (283, 'f'): 374, - (284, '0'): 332, - (284, '1'): 331, - (284, '2'): 334, - (284, '3'): 333, - (284, '4'): 336, - (284, '5'): 335, - (284, '6'): 338, - (284, '7'): 337, - (284, '8'): 340, - (284, '9'): 339, - (284, 'A'): 341, - (284, 'B'): 343, - (284, 'C'): 342, - (284, 'D'): 345, - (284, 'E'): 344, - (284, 'F'): 346, - (284, 'a'): 347, - (284, 'b'): 349, - (284, 'c'): 348, - (284, 'd'): 351, - (284, 'e'): 350, - (284, 'f'): 352, - (285, '0'): 310, - (285, '1'): 309, - (285, '2'): 312, - (285, '3'): 311, - (285, '4'): 314, - (285, '5'): 313, - (285, '6'): 316, - (285, '7'): 315, - (285, '8'): 318, - (285, '9'): 317, - (285, 'A'): 319, - (285, 'B'): 321, - (285, 'C'): 320, - (285, 'D'): 323, - (285, 'E'): 322, - (285, 'F'): 324, - (285, 'a'): 325, - (285, 'b'): 327, - (285, 'c'): 326, - (285, 'd'): 329, - (285, 'e'): 328, - (285, 'f'): 330, - (286, '0'): 288, - (286, '1'): 287, - (286, '2'): 290, - (286, '3'): 289, - (286, '4'): 292, - (286, '5'): 291, - (286, '6'): 294, - (286, '7'): 293, - (286, '8'): 296, - (286, '9'): 295, - (286, 'A'): 297, - (286, 'B'): 299, - (286, 'C'): 298, - (286, 'D'): 301, - (286, 'E'): 300, - (286, 'F'): 302, - (286, 'a'): 303, - (286, 'b'): 305, - (286, 'c'): 304, - (286, 'd'): 307, - (286, 'e'): 306, - (286, 'f'): 308, - (683, '0'): 762, - (683, '1'): 761, - (683, '2'): 764, - (683, '3'): 763, - (683, '4'): 766, - (683, '5'): 765, - (683, '6'): 768, - (683, '7'): 767, - (684, '0'): 754, - (684, '1'): 753, - (684, '2'): 756, - (684, '3'): 755, - (684, '4'): 758, - (684, '5'): 757, - (684, '6'): 760, - (684, '7'): 759, - (685, '0'): 746, - (685, '1'): 745, - (685, '2'): 748, - (685, '3'): 747, - (685, '4'): 750, - (685, '5'): 749, - (685, '6'): 752, - (685, '7'): 751, - (686, '0'): 738, - (686, '1'): 737, - (686, '2'): 740, - (686, '3'): 739, - (686, '4'): 742, - (686, '5'): 741, - (686, '6'): 744, - (686, '7'): 743, - (687, '0'): 730, - (687, '1'): 729, - (687, '2'): 732, - (687, '3'): 731, - (687, '4'): 734, - (687, '5'): 733, - (687, '6'): 736, - (687, '7'): 735, - (688, '0'): 722, - (688, '1'): 721, - (688, '2'): 724, - (688, '3'): 723, - (688, '4'): 726, - (688, '5'): 725, - (688, '6'): 728, - (688, '7'): 727, - (689, '0'): 714, - (689, '1'): 713, - (689, '2'): 716, - (689, '3'): 715, - (689, '4'): 718, - (689, '5'): 717, - (689, '6'): 720, - (689, '7'): 719, - (690, '0'): 706, - (690, '1'): 705, - (690, '2'): 708, - (690, '3'): 707, - (690, '4'): 710, - (690, '5'): 709, - (690, '6'): 712, - (690, '7'): 711, - (769, '0'): 848, - (769, '1'): 847, - (769, '2'): 850, - (769, '3'): 849, - (769, '4'): 852, - (769, '5'): 851, - (769, '6'): 854, - (769, '7'): 853, - (770, '0'): 840, - (770, '1'): 839, - (770, '2'): 842, - (770, '3'): 841, - (770, '4'): 844, - (770, '5'): 843, - (770, '6'): 846, - (770, '7'): 845, - (771, '0'): 832, - (771, '1'): 831, - (771, '2'): 834, - (771, '3'): 833, - (771, '4'): 836, - (771, '5'): 835, - (771, '6'): 838, - (771, '7'): 837, - (772, '0'): 824, - (772, '1'): 823, - (772, '2'): 826, - (772, '3'): 825, - (772, '4'): 828, - (772, '5'): 827, - (772, '6'): 830, - (772, '7'): 829, - (773, '0'): 816, - (773, '1'): 815, - (773, '2'): 818, - (773, '3'): 817, - (773, '4'): 820, - (773, '5'): 819, - (773, '6'): 822, - (773, '7'): 821, - (774, '0'): 808, - (774, '1'): 807, - (774, '2'): 810, - (774, '3'): 809, - (774, '4'): 812, - (774, '5'): 811, - (774, '6'): 814, - (774, '7'): 813, - (775, '0'): 800, - (775, '1'): 799, - (775, '2'): 802, - (775, '3'): 801, - (775, '4'): 804, - (775, '5'): 803, - (775, '6'): 806, - (775, '7'): 805, - (776, '0'): 792, - (776, '1'): 791, - (776, '2'): 794, - (776, '3'): 793, - (776, '4'): 796, - (776, '5'): 795, - (776, '6'): 798, - (776, '7'): 797, - (855, '0'): 934, - (855, '1'): 933, - (855, '2'): 936, - (855, '3'): 935, - (855, '4'): 938, - (855, '5'): 937, - (855, '6'): 940, - (855, '7'): 939, - (856, '0'): 926, - (856, '1'): 925, - (856, '2'): 928, - (856, '3'): 927, - (856, '4'): 930, - (856, '5'): 929, - (856, '6'): 932, - (856, '7'): 931, - (857, '0'): 918, - (857, '1'): 917, - (857, '2'): 920, - (857, '3'): 919, - (857, '4'): 922, - (857, '5'): 921, - (857, '6'): 924, - (857, '7'): 923, - (858, '0'): 910, - (858, '1'): 909, - (858, '2'): 912, - (858, '3'): 911, - (858, '4'): 914, - (858, '5'): 913, - (858, '6'): 916, - (858, '7'): 915, - (859, '0'): 902, - (859, '1'): 901, - (859, '2'): 904, - (859, '3'): 903, - (859, '4'): 906, - (859, '5'): 905, - (859, '6'): 908, - (859, '7'): 907, - (860, '0'): 894, - (860, '1'): 893, - (860, '2'): 896, - (860, '3'): 895, - (860, '4'): 898, - (860, '5'): 897, - (860, '6'): 900, - (860, '7'): 899, - (861, '0'): 886, - (861, '1'): 885, - (861, '2'): 888, - (861, '3'): 887, - (861, '4'): 890, - (861, '5'): 889, - (861, '6'): 892, - (861, '7'): 891, - (862, '0'): 878, - (862, '1'): 877, - (862, '2'): 880, - (862, '3'): 879, - (862, '4'): 882, - (862, '5'): 881, - (862, '6'): 884, - (862, '7'): 883, - (941, '0'): 1020, - (941, '1'): 1019, - (941, '2'): 1022, - (941, '3'): 1021, - (941, '4'): 1024, - (941, '5'): 1023, - (941, '6'): 1026, - (941, '7'): 1025, - (942, '0'): 1012, - (942, '1'): 1011, - (942, '2'): 1014, - (942, '3'): 1013, - (942, '4'): 1016, - (942, '5'): 1015, - (942, '6'): 1018, - (942, '7'): 1017, - (943, '0'): 1004, - (943, '1'): 1003, - (943, '2'): 1006, - (943, '3'): 1005, - (943, '4'): 1008, - (943, '5'): 1007, - (943, '6'): 1010, - (943, '7'): 1009, - (944, '0'): 996, - (944, '1'): 995, - (944, '2'): 998, - (944, '3'): 997, - (944, '4'): 1000, - (944, '5'): 999, - (944, '6'): 1002, - (944, '7'): 1001, - (945, '0'): 988, - (945, '1'): 987, - (945, '2'): 990, - (945, '3'): 989, - (945, '4'): 992, - (945, '5'): 991, - (945, '6'): 994, - (945, '7'): 993, - (946, '0'): 980, - (946, '1'): 979, - (946, '2'): 982, - (946, '3'): 981, - (946, '4'): 984, - (946, '5'): 983, - (946, '6'): 986, - (946, '7'): 985, - (947, '0'): 972, - (947, '1'): 971, - (947, '2'): 974, - (947, '3'): 973, - (947, '4'): 976, - (947, '5'): 975, - (947, '6'): 978, - (947, '7'): 977, - (948, '0'): 964, - (948, '1'): 963, - (948, '2'): 966, - (948, '3'): 965, - (948, '4'): 968, - (948, '5'): 967, - (948, '6'): 970, - (948, '7'): 969}, - set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, 1025, 1026]), - set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, 1025, 1026]), - ['0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, start|, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0', - 'CHAR', - '__6_(', - '__13_,', - 'QUOTEDCHAR', - '__0_|', - '__2_+', - '__3_?', - '__8_[', - '__4_{', - '__1_*', - '__10_.', - '__11_^', - '__7_)', - '__12_-', - '__9_]', - '__5_}', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - '2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - '3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR', - 'QUOTEDCHAR']), {}) +class RegexParser(PackratParser): + def __init__(self, stream): + self.init_parser(stream) +forbidden = dict.fromkeys(("__weakref__ __doc__ " + "__dict__ __module__").split()) +initthere = "__init__" in RegexParser.__dict__ +for key, value in Parser.__dict__.iteritems(): + if key not in RegexParser.__dict__ and key not in forbidden: + setattr(RegexParser, key, value) +RegexParser.init_parser = Parser.__init__.im_func + # generated code between this line and its other occurence + + + + + + if __name__ == '__main__': f = py.magic.autopath() oldcontent = f.read() s = "# GENERATED CODE BETWEEN THIS LINE AND ITS OTHER OCCURENCE\n".lower() pre, gen, after = oldcontent.split(s) - parser, lexer, ToAST = make_regex_parser() - transformer = ToAST.source - newcontent = "%s%s%s\nparser = %r\n%s\n%s%s" % ( - pre, s, ToAST.source.replace("ToAST", "RegexToAST"), - parser, lexer.get_dummy_repr(), s, after) - print newcontent - f.write(newcontent) + from pypackrat import PyPackratSyntaxParser + from makepackrat import TreeOptimizer, ParserBuilder + p = PyPackratSyntaxParser(syntax) + t = p.file() + t = t.visit(TreeOptimizer()) + visitor = ParserBuilder() + t.visit(visitor) + code = visitor.get_code() + content = """ +%s +%s + +from pypy.rlib.parsing.pypackrat import PackratParser, _Status +from pypy.rlib.parsing import regex +import operator +%s +class RegexParser(PackratParser): + def __init__(self, stream): + self.init_parser(stream) +forbidden = dict.fromkeys(("__weakref__ __doc__ " + "__dict__ __module__").split()) +initthere = "__init__" in RegexParser.__dict__ +for key, value in Parser.__dict__.iteritems(): + if key not in RegexParser.__dict__ and key not in forbidden: + setattr(RegexParser, key, value) +RegexParser.init_parser = Parser.__init__.im_func + +%s +%s +""" % (pre, s, code, s, after) + print content + f.write(content) + + + + Modified: pypy/dist/pypy/rlib/parsing/test/test_regexparse.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_regexparse.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_regexparse.py Thu Jun 21 12:09:39 2007 @@ -1,118 +1,10 @@ import py -from pypy.rlib.parsing.regexparse import make_runner, unescape +from pypy.rlib.parsing.regexparse import make_runner, unescape, RegexParser from pypy.rlib.parsing import regex import operator from pypy.rlib.parsing.makepackrat import PackratParser as _PackratParser from pypy.rlib.parsing.deterministic import compress_char_set, DFA -class RegexParser(_PackratParser): - r""" - EOF: - !__any__; - - parse: - regex - [EOF]; - - regex: - r1 = concatenation - '|' - r2 = regex - return {r1 | r2} - | concatenation; - - concatenation: - l = repetition+ - return {reduce(operator.add, l, regex.StringExpression(""))}; - - repetition: - r1 = primary - '*' - return {r1.kleene()} - | r1 = primary - '+' - return {r1 + r1.kleene()} - | r1 = primary - '?' - return {regex.StringExpression("") | r1} - | r = primary - '{' - n = numrange - '}' - return {r * n[0] + reduce(operator.or_, [r * i for i in range(n[1] - n[0] + 1)], regex.StringExpression(""))} - | primary; - - primary: - ['('] regex [')'] - | range - | c = char - return {regex.StringExpression(c)} - | '.' - return {regex.RangeExpression(chr(0), chr(255))}; - - char: - c = QUOTEDCHAR - return {unescape(c)} - | c = CHAR - return {c}; - - QUOTEDCHAR: - `(\\x[0-9a-fA-F]{2})|(\\.)`; - - CHAR: - `[^\*\+\(\)\[\]\{\}\|\.\-\?\,\^]`; - - range: - '[' - s = rangeinner - ']' - return {reduce(operator.or_, [regex.RangeExpression(a, chr(ord(a) + b - 1)) for a, b in compress_char_set(s)])}; - - rangeinner: - '^' - s = subrange - return {set([chr(c) for c in range(256)]) - s} - | subrange; - - subrange: - l = rangeelement+ - return {reduce(operator.or_, l)}; - - rangeelement: - c1 = char - '-' - c2 = char - return {set([chr(i) for i in range(ord(c1), ord(c2) + 1)])} - | c = char - return {set([c])}; - - numrange: - n1 = NUM - ',' - n2 = NUM - return {n1, n2} - | n1 = NUM - return {n1, n1}; - - NUM: - c = `0|([1-9][0-9]*)` - return {int(c)}; - """ - - - -def make_runner(regex, view=False): - p = RegexParser(regex) - r = p.parse() - nfa = r.make_automaton() - dfa = nfa.make_deterministic() - if view: - dfa.view() - dfa.optimize() - if view: - dfa.view() - r = dfa.get_runner() - return r def test_simple(): From cfbolz at codespeak.net Thu Jun 21 14:32:53 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 21 Jun 2007 14:32:53 +0200 (CEST) Subject: [pypy-svn] r44408 - in pypy/dist/pypy/rlib/parsing: . test Message-ID: <20070621123253.4EC88810E@code0.codespeak.net> Author: cfbolz Date: Thu Jun 21 14:32:50 2007 New Revision: 44408 Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py pypy/dist/pypy/rlib/parsing/pypackrat.py pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Log: add a conditional to match something only if a user-given predicate is true Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/makepackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/makepackrat.py Thu Jun 21 14:32:50 2007 @@ -53,7 +53,7 @@ REGEX: - r = `\`[^\\\`]*(\\.[^\\\`]*)*\`` + r = `\`[^\\\`]*(\\.[^\\\`]*)*\`` return {Symbol('REGEX', r, None)}; QUOTE: @@ -105,10 +105,10 @@ simplecommand: return_ + | if_ | named_command | repetition - | negation - | enclosed; + | negation; return_: 'return' @@ -117,6 +117,16 @@ IGNORE* return {Nonterminal('return', [code])}; +if_: + 'do' + newline + cmd = command + SPACE* + 'if' + SPACE* + condition = PYTHONCODE + return {Nonterminal('if', [cmd, condition])}; + commandchain: result = simplecommand+ return {Nonterminal('commands', result)}; @@ -474,6 +484,14 @@ def visit_return(self, t): self.emit("_result = (%s)" % (t.children[0].additional_info[1:-1], )) + def visit_if(self, t): + self.dispatch(t.children[0]) + for _ in self.start_block("if not (%s):" % ( + t.children[1].additional_info[1:-1], )): + self.emit("raise self._BacktrackException(") + self.emit(" self._ErrorInformation(") + self.emit(" _startingpos, ['condition not met']))") + def visit_call(self, t): if t.children[0].startswith("_"): callname = t.children[0] Modified: pypy/dist/pypy/rlib/parsing/pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/pypackrat.py Thu Jun 21 14:32:50 2007 @@ -1155,7 +1155,7 @@ self._pos = _choice33 _choice34 = self._pos try: - _call_status = self._named_command() + _call_status = self._if_() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break @@ -1164,7 +1164,7 @@ self._pos = _choice34 _choice35 = self._pos try: - _call_status = self._repetition() + _call_status = self._named_command() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break @@ -1173,7 +1173,7 @@ self._pos = _choice35 _choice36 = self._pos try: - _call_status = self._negation() + _call_status = self._repetition() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break @@ -1182,7 +1182,7 @@ self._pos = _choice36 _choice37 = self._pos try: - _call_status = self._enclosed() + _call_status = self._negation() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break @@ -1190,7 +1190,7 @@ _error = self._combine_errors(_error, _exc.error) self._pos = _choice37 raise self._BacktrackException(_error) - _call_status = self._enclosed() + _call_status = self._negation() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break @@ -1305,6 +1305,101 @@ _status.error = _error _status.status = _status.ERROR raise self._BacktrackException(_error) + class _Status_if_(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def if_(self): + return self._if_().result + def _if_(self): + _status = self._dict_if_.get(self._pos, None) + if _status is None: + _status = self._dict_if_[self._pos] = self._Status_if_() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _result = self.__chars__('do') + _call_status = self._newline() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _call_status = self._command() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + cmd = _result + _all42 = [] + while 1: + _choice43 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all42.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice43 + break + _result = _all42 + _result = self.__chars__('if') + _all44 = [] + while 1: + _choice45 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all44.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice45 + break + _result = _all44 + _call_status = self._PYTHONCODE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + condition = _result + _result = (Nonterminal('if', [cmd, condition])) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._if_() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) class _Status_commandchain(_Status): def __init__(self): self.pos = 0 @@ -1336,23 +1431,23 @@ try: _result = None _error = None - _all42 = [] + _all46 = [] _call_status = self._simplecommand() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all42.append(_result) + _all46.append(_result) while 1: - _choice43 = self._pos + _choice47 = self._pos try: _call_status = self._simplecommand() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all42.append(_result) + _all46.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice43 + self._pos = _choice47 break - _result = _all42 + _result = _all46 result = _result _result = (Nonterminal('commands', result)) if _status.status == _status.LEFTRECURSION: @@ -1414,33 +1509,33 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) name = _result - _all44 = [] + _all48 = [] while 1: - _choice45 = self._pos + _choice49 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all44.append(_result) + _all48.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice45 + self._pos = _choice49 break - _result = _all44 + _result = _all48 _result = self.__chars__('=') - _all46 = [] + _all50 = [] while 1: - _choice47 = self._pos + _choice51 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all46.append(_result) + _all50.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice47 + self._pos = _choice51 break - _result = _all46 + _result = _all50 _call_status = self._command() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -1503,152 +1598,152 @@ _error = None while 1: _error = None - _choice48 = self._pos + _choice52 = self._pos try: _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all49 = [] + _all53 = [] while 1: - _choice50 = self._pos + _choice54 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all49.append(_result) + _all53.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice50 + self._pos = _choice54 break - _result = _all49 + _result = _all53 _result = self.__chars__('?') - _all51 = [] + _all55 = [] while 1: - _choice52 = self._pos + _choice56 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all51.append(_result) + _all55.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice52 + self._pos = _choice56 break - _result = _all51 + _result = _all55 _result = (Nonterminal('maybe', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice48 - _choice53 = self._pos + self._pos = _choice52 + _choice57 = self._pos try: _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all54 = [] + _all58 = [] while 1: - _choice55 = self._pos + _choice59 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all54.append(_result) + _all58.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice55 + self._pos = _choice59 break - _result = _all54 + _result = _all58 while 1: _error = None - _choice56 = self._pos + _choice60 = self._pos try: _result = self.__chars__('*') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice56 - _choice57 = self._pos + self._pos = _choice60 + _choice61 = self._pos try: _result = self.__chars__('+') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice57 + self._pos = _choice61 raise self._BacktrackException(_error) _result = self.__chars__('+') break repetition = _result - _all58 = [] + _all62 = [] while 1: - _choice59 = self._pos + _choice63 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all58.append(_result) + _all62.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice59 + self._pos = _choice63 break - _result = _all58 + _result = _all62 _result = (Nonterminal('repetition', [repetition, what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice53 + self._pos = _choice57 raise self._BacktrackException(_error) _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all60 = [] + _all64 = [] while 1: - _choice61 = self._pos + _choice65 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all60.append(_result) + _all64.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice61 + self._pos = _choice65 break - _result = _all60 + _result = _all64 while 1: _error = None - _choice62 = self._pos + _choice66 = self._pos try: _result = self.__chars__('*') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice62 - _choice63 = self._pos + self._pos = _choice66 + _choice67 = self._pos try: _result = self.__chars__('+') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice63 + self._pos = _choice67 raise self._BacktrackException(_error) _result = self.__chars__('+') break repetition = _result - _all64 = [] + _all68 = [] while 1: - _choice65 = self._pos + _choice69 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all64.append(_result) + _all68.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice65 + self._pos = _choice69 break - _result = _all64 + _result = _all68 _result = (Nonterminal('repetition', [repetition, what])) break if _status.status == _status.LEFTRECURSION: @@ -1708,45 +1803,45 @@ _error = None while 1: _error = None - _choice66 = self._pos + _choice70 = self._pos try: _result = self.__chars__('!') - _all67 = [] + _all71 = [] while 1: - _choice68 = self._pos + _choice72 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all67.append(_result) + _all71.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice68 + self._pos = _choice72 break - _result = _all67 + _result = _all71 _call_status = self._negation() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all69 = [] + _all73 = [] while 1: - _choice70 = self._pos + _choice74 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all69.append(_result) + _all73.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice70 + self._pos = _choice74 break - _result = _all69 + _result = _all73 _result = (Nonterminal('negation', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice66 - _choice71 = self._pos + self._pos = _choice70 + _choice75 = self._pos try: _call_status = self._enclosed() _result = _call_status.result @@ -1754,7 +1849,7 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice71 + self._pos = _choice75 raise self._BacktrackException(_error) _call_status = self._enclosed() _result = _call_status.result @@ -1817,152 +1912,152 @@ _error = None while 1: _error = None - _choice72 = self._pos + _choice76 = self._pos try: _result = self.__chars__('<') - _all73 = [] + _all77 = [] while 1: - _choice74 = self._pos + _choice78 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all73.append(_result) + _all77.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice74 + self._pos = _choice78 break - _result = _all73 + _result = _all77 _call_status = self._primary() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all75 = [] + _all79 = [] while 1: - _choice76 = self._pos + _choice80 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all75.append(_result) + _all79.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice76 + self._pos = _choice80 break - _result = _all75 + _result = _all79 _result = self.__chars__('>') - _all77 = [] + _all81 = [] while 1: - _choice78 = self._pos + _choice82 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all77.append(_result) + _all81.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice78 + self._pos = _choice82 break - _result = _all77 + _result = _all81 _result = (Nonterminal('exclusive', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice72 - _choice79 = self._pos + self._pos = _choice76 + _choice83 = self._pos try: _result = self.__chars__('[') - _all80 = [] + _all84 = [] while 1: - _choice81 = self._pos + _choice85 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all80.append(_result) + _all84.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice81 + self._pos = _choice85 break - _result = _all80 + _result = _all84 _call_status = self._or_() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all82 = [] + _all86 = [] while 1: - _choice83 = self._pos + _choice87 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all82.append(_result) + _all86.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice83 + self._pos = _choice87 break - _result = _all82 + _result = _all86 _result = self.__chars__(']') - _all84 = [] + _all88 = [] while 1: - _choice85 = self._pos + _choice89 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all84.append(_result) + _all88.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice85 + self._pos = _choice89 break - _result = _all84 + _result = _all88 _result = (Nonterminal('ignore', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice79 - _choice86 = self._pos + self._pos = _choice83 + _choice90 = self._pos try: - _before_discard87 = _result + _before_discard91 = _result _result = self.__chars__('(') - _all88 = [] + _all92 = [] while 1: - _choice89 = self._pos + _choice93 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all88.append(_result) + _all92.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice89 + self._pos = _choice93 break - _result = _all88 - _result = _before_discard87 + _result = _all92 + _result = _before_discard91 _call_status = self._or_() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard90 = _result + _before_discard94 = _result _result = self.__chars__(')') - _all91 = [] + _all95 = [] while 1: - _choice92 = self._pos + _choice96 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all91.append(_result) + _all95.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice92 + self._pos = _choice96 break - _result = _all91 - _result = _before_discard90 + _result = _all95 + _result = _before_discard94 break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice86 - _choice93 = self._pos + self._pos = _choice90 + _choice97 = self._pos try: _call_status = self._primary() _result = _call_status.result @@ -1970,7 +2065,7 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice93 + self._pos = _choice97 raise self._BacktrackException(_error) _call_status = self._primary() _result = _call_status.result @@ -2033,7 +2128,7 @@ _error = None while 1: _error = None - _choice94 = self._pos + _choice98 = self._pos try: _call_status = self._call() _result = _call_status.result @@ -2041,74 +2136,74 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice94 - _choice95 = self._pos + self._pos = _choice98 + _choice99 = self._pos try: _call_status = self._REGEX() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard96 = _result - _all97 = [] + _before_discard100 = _result + _all101 = [] while 1: - _choice98 = self._pos + _choice102 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all97.append(_result) + _all101.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice98 + self._pos = _choice102 break - _result = _all97 - _result = _before_discard96 + _result = _all101 + _result = _before_discard100 break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice95 - _choice99 = self._pos + self._pos = _choice99 + _choice103 = self._pos try: _call_status = self._QUOTE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard100 = _result - _all101 = [] + _before_discard104 = _result + _all105 = [] while 1: - _choice102 = self._pos + _choice106 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all101.append(_result) + _all105.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice102 + self._pos = _choice106 break - _result = _all101 - _result = _before_discard100 + _result = _all105 + _result = _before_discard104 break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice99 + self._pos = _choice103 raise self._BacktrackException(_error) _call_status = self._QUOTE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard103 = _result - _all104 = [] + _before_discard107 = _result + _all108 = [] while 1: - _choice105 = self._pos + _choice109 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all104.append(_result) + _all108.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice105 + self._pos = _choice109 break - _result = _all104 - _result = _before_discard103 + _result = _all108 + _result = _before_discard107 break if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -2169,19 +2264,19 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) x = _result - _all106 = [] + _all110 = [] while 1: - _choice107 = self._pos + _choice111 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all106.append(_result) + _all110.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice107 + self._pos = _choice111 break - _result = _all106 + _result = _all110 _result = (Nonterminal("call", [x])) if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -2225,6 +2320,7 @@ self._dict_command = {} self._dict_simplecommand = {} self._dict_return_ = {} + self._dict_if_ = {} self._dict_commandchain = {} self._dict_named_command = {} self._dict_repetition = {} @@ -2235,77 +2331,77 @@ self._pos = 0 self._inputstream = inputstream def _regex299149370(self): - _choice108 = self._pos + _choice112 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_299149370(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice108 + self._pos = _choice112 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1006631623(self): - _choice109 = self._pos + _choice113 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1006631623(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice109 + self._pos = _choice113 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex528667127(self): - _choice110 = self._pos + _choice114 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_528667127(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice110 + self._pos = _choice114 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex291086639(self): - _choice111 = self._pos + _choice115 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_291086639(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice111 + self._pos = _choice115 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1074651696(self): - _choice112 = self._pos + _choice116 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1074651696(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice112 + self._pos = _choice116 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1124192327(self): - _choice113 = self._pos + _choice117 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1124192327(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice113 + self._pos = _choice117 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1979538501(self): - _choice114 = self._pos + _choice118 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1979538501(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice114 + self._pos = _choice118 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] Modified: pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Thu Jun 21 14:32:50 2007 @@ -334,3 +334,23 @@ assert p._pos == 2 assert res == "c" + def test_if(self): + class parser(PackratParser): + """ + INT: + c = `[1-9][0-9]*` + return {int(c)}; + b: + do + c = INT + if {c > 42}; + """ + print parser._code + p = parser("54") + res = p.b() + assert res == 54 + p = parser("12") + excinfo = py.test.raises(BacktrackException, p.b) + assert excinfo.value.error.pos == 0 + assert excinfo.value.error.expected == ['condition not met'] + From mwh at codespeak.net Fri Jun 22 11:06:28 2007 From: mwh at codespeak.net (mwh at codespeak.net) Date: Fri, 22 Jun 2007 11:06:28 +0200 (CEST) Subject: [pypy-svn] r44416 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070622090628.9B34580EC@code0.codespeak.net> Author: mwh Date: Fri Jun 22 11:06:27 2007 New Revision: 44416 Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Log: use the shorter redirect url for the timetable Modified: pypy/extradoc/sprintinfo/post-ep2007/announcement.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/announcement.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/announcement.txt Fri Jun 22 11:06:27 2007 @@ -82,4 +82,4 @@ .. _getting-started: http://codespeak.net/pypy/dist/pypy/doc/getting-started.html .. _`pypy-sprint mailing list`: http://codespeak.net/mailman/listinfo/pypy-sprint .. _`the technical reports available and other relevant documentation`: http://codespeak.net/pypy/dist/pypy/doc/index.html -.. _`EuroPython schedule`: http://indico.cern.ch/conferenceTimeTable.py?confId=13919&showDate=all&showSession=all&detailLevel=contribution&viewMode=room +.. _`EuroPython schedule`: http://europython.org/timetable From lac at codespeak.net Fri Jun 22 11:12:43 2007 From: lac at codespeak.net (lac at codespeak.net) Date: Fri, 22 Jun 2007 11:12:43 +0200 (CEST) Subject: [pypy-svn] r44417 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070622091243.1C0CF80E3@code0.codespeak.net> Author: lac Date: Fri Jun 22 11:12:42 2007 New Revision: 44417 Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt Log: register Jacob and me. Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/people.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/people.txt Fri Jun 22 11:12:42 2007 @@ -14,6 +14,8 @@ Maciej Fijalkowski 5/14th Some hostel Antonio Cuni 8/15th Same as Maciek :-) Samuele Pedroni 7/14th Ratonda Centrum Hotels +Laura Creighton 7/14th Ratonda Centrum Hotels +Jacob Hallen 7/14th Ratonda Centrum Hotels ==================== ============== ======================= People on the following list were present at previous sprints: From mwh at codespeak.net Fri Jun 22 11:14:14 2007 From: mwh at codespeak.net (mwh at codespeak.net) Date: Fri, 22 Jun 2007 11:14:14 +0200 (CEST) Subject: [pypy-svn] r44418 - pypy/dist/pypy/translator/llvm Message-ID: <20070622091414.4411E80E3@code0.codespeak.net> Author: mwh Date: Fri Jun 22 11:14:13 2007 New Revision: 44418 Modified: pypy/dist/pypy/translator/llvm/gc.py Log: surely everyone who builds pypy-llvm has this in their wcs already? it's been in the pypytester tree on tuatara for ages anyway. Modified: pypy/dist/pypy/translator/llvm/gc.py ============================================================================== --- pypy/dist/pypy/translator/llvm/gc.py (original) +++ pypy/dist/pypy/translator/llvm/gc.py Fri Jun 22 11:14:13 2007 @@ -116,7 +116,7 @@ # """ factory """ if gcpolicy == 'boehm': # XXX would be nice to localise this sort of thing? - assert have_boehm(), 'warning: Boehm GC libary not found in /usr/lib' + #assert have_boehm(), 'warning: Boehm GC libary not found in /usr/lib' gcpolicy = BoehmGcPolicy(db) elif gcpolicy == 'ref': gcpolicy = RefcountingGcPolicy(db) From mwh at codespeak.net Fri Jun 22 11:14:40 2007 From: mwh at codespeak.net (mwh at codespeak.net) Date: Fri, 22 Jun 2007 11:14:40 +0200 (CEST) Subject: [pypy-svn] r44419 - pypy/dist/pypy/translator/goal Message-ID: <20070622091440.2A6EF80E3@code0.codespeak.net> Author: mwh Date: Fri Jun 22 11:14:39 2007 New Revision: 44419 Modified: pypy/dist/pypy/translator/goal/bench-unix.py Log: more tuatara-fixes Modified: pypy/dist/pypy/translator/goal/bench-unix.py ============================================================================== --- pypy/dist/pypy/translator/goal/bench-unix.py (original) +++ pypy/dist/pypy/translator/goal/bench-unix.py Fri Jun 22 11:14:39 2007 @@ -101,7 +101,8 @@ ref_rich, ref_stone = None, None - for exe in '/usr/local/bin/python2.5 python2.4 python2.3'.split(): +# for exe in '/usr/local/bin/python2.5 python2.4 python2.3'.split(): + for exe in 'python2.4 python2.3'.split(): v = os.popen(exe + ' -c "import sys;print sys.version.split()[0]"').read().strip() if not v: continue @@ -131,7 +132,7 @@ f = '../microbench/archive/%s.txt' % exe if not os.path.exists(f) or os.stat(f).st_size < 100: os.chdir('../microbench') - run_cmd('./microbench.py python "../goal/%s" > "archive/%s.txt"' % (exe, exe)) + run_cmd('python2.4 ./microbench.py python2.4 "../goal/%s" > "archive/%s.txt"' % (exe, exe)) os.chdir('../goal') r = exe + '_richards' From jlg at codespeak.net Fri Jun 22 11:26:19 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Fri, 22 Jun 2007 11:26:19 +0200 (CEST) Subject: [pypy-svn] r44420 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070622092619.21346810B@code0.codespeak.net> Author: jlg Date: Fri Jun 22 11:26:18 2007 New Revision: 44420 Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt Log: jlg at ep2007 Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/people.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/people.txt Fri Jun 22 11:26:18 2007 @@ -16,6 +16,7 @@ Samuele Pedroni 7/14th Ratonda Centrum Hotels Laura Creighton 7/14th Ratonda Centrum Hotels Jacob Hallen 7/14th Ratonda Centrum Hotels +Jakub Gustak 7/15th Hospitality Club :) ==================== ============== ======================= People on the following list were present at previous sprints: From antocuni at codespeak.net Fri Jun 22 11:35:35 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Fri, 22 Jun 2007 11:35:35 +0200 (CEST) Subject: [pypy-svn] r44421 - in pypy/dist/pypy: objspace/flow translator/backendopt/test Message-ID: <20070622093535.74FF680B0@code0.codespeak.net> Author: antocuni Date: Fri Jun 22 11:35:34 2007 New Revision: 44421 Modified: pypy/dist/pypy/objspace/flow/model.py pypy/dist/pypy/translator/backendopt/test/test_inline.py Log: add another check to checkgraph and the corresponding failing test Modified: pypy/dist/pypy/objspace/flow/model.py ============================================================================== --- pypy/dist/pypy/objspace/flow/model.py (original) +++ pypy/dist/pypy/objspace/flow/model.py Fri Jun 22 11:35:34 2007 @@ -663,6 +663,9 @@ for link in block.exits: assert len(link.args) == len(link.target.inputargs) assert link.prevblock is block + for linkv, inputv in zip(link.args, link.target.inputargs): + if hasattr(linkv, 'concretetype') and hasattr(inputv, 'concretetype'): + assert linkv.concretetype == inputv.concretetype exc_link = link in exc_links if exc_link: for v in [link.last_exception, link.last_exc_value]: Modified: pypy/dist/pypy/translator/backendopt/test/test_inline.py ============================================================================== --- pypy/dist/pypy/translator/backendopt/test/test_inline.py (original) +++ pypy/dist/pypy/translator/backendopt/test/test_inline.py Fri Jun 22 11:35:34 2007 @@ -638,6 +638,28 @@ res = eval_func([True, 42]) assert res == expected + def test_oosend_inherited(self): + py.test.skip('fixme, this prevents pypy-cli from being built') + class A: + def bar(self, x): + return x + class B(A): + def foo(self, x): + return self.bar(x) + class C(A): + pass + def fn(x): + if x: + b_obj = B() + return b_obj.foo(x) + else: + c_obj = C() + return c_obj.bar(x) + eval_func, t = self.check_auto_inlining(fn, [int], checkvirtual=True) + expected = fn(42) + res = eval_func([42]) + assert res == expected + def test_classattr(self): class A: attr = 666 From antocuni at codespeak.net Fri Jun 22 15:04:43 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Fri, 22 Jun 2007 15:04:43 +0200 (CEST) Subject: [pypy-svn] r44432 - pypy/dist/pypy/objspace/fake Message-ID: <20070622130443.0F55E80E9@code0.codespeak.net> Author: antocuni Date: Fri Jun 22 15:04:43 2007 New Revision: 44432 Modified: pypy/dist/pypy/objspace/fake/objspace.py Log: more operations for the fake objspace Modified: pypy/dist/pypy/objspace/fake/objspace.py ============================================================================== --- pypy/dist/pypy/objspace/fake/objspace.py (original) +++ pypy/dist/pypy/objspace/fake/objspace.py Fri Jun 22 15:04:43 2007 @@ -1,6 +1,7 @@ from pypy.interpreter.baseobjspace import ObjSpace, Wrappable, W_Root from pypy.rlib.nonconst import NonConstant from pypy.rlib.rarithmetic import r_uint +from pypy.rlib.rbigint import rbigint class W_Type(W_Root): pass @@ -22,6 +23,8 @@ uint_dummy = make_dummy(r_uint(42), r_uint(43)) str_dummy = make_dummy('foo', 'bar') bool_dummy = make_dummy(True, False) +unichars_dummy = make_dummy([u'a', u'b'], [u'c', u'd']) +bigint_dummy = make_dummy(rbigint([0]), rbigint([1])) class FakeObjSpace(ObjSpace): w_None = W_Object() @@ -35,6 +38,7 @@ w_long = W_Object() w_tuple = W_Object() w_str = W_Object() + w_basestring = W_Object() w_unicode = W_Object() w_type = W_Object() w_instance = W_Object() @@ -71,9 +75,13 @@ int_w = int_dummy uint_w = uint_dummy float_w = float_dummy + unichars_w = unichars_dummy + bigint_w = bigint_dummy iter = make_dummy() type = make_dummy() str = make_dummy() + int = make_dummy() + float = make_dummy() repr = make_dummy() id = make_dummy() len = make_dummy() From pypy-svn at codespeak.net Fri Jun 22 15:55:37 2007 From: pypy-svn at codespeak.net (pypy-svn at codespeak.net) Date: Fri, 22 Jun 2007 15:55:37 +0200 (CEST) Subject: [pypy-svn] Men's sale ending soon! Don't miss out!! Message-ID: <20070622065615.5677.qmail@jubilant-relay.volia.net> An HTML attachment was scrubbed... URL: From jlg at codespeak.net Fri Jun 22 20:35:04 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Fri, 22 Jun 2007 20:35:04 +0200 (CEST) Subject: [pypy-svn] r44438 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070622183504.9B1AA8125@code0.codespeak.net> Author: jlg Date: Fri Jun 22 20:35:04 2007 New Revision: 44438 Added: pypy/dist/pypy/lang/scheme/TODO.txt (contents, props changed) pypy/dist/pypy/lang/scheme/astbuilder.py (contents, props changed) Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/ssparser.py pypy/dist/pypy/lang/scheme/test/test_parser.py Log: Added TODO.txt and astbuilder in separate file Added: pypy/dist/pypy/lang/scheme/TODO.txt ============================================================================== --- (empty file) +++ pypy/dist/pypy/lang/scheme/TODO.txt Fri Jun 22 20:35:04 2007 @@ -0,0 +1,27 @@ +Do now +------ + +- evaluate simple expressions like + (* 6 7) or even (+ 1 2 3 4) + - convert nodes from AST tree into W_xxx - tree.dispatch() + - evaluate the tree + W_xxx object like W_Fixnum should eval to itself despite context + - implement basic operations like * / and so on + +Do next +------- + +- symbols, variables and execution context +- control structures +- functions + +Do in some future +----------------- + +Here starts the real fun! + +- delayed evaluation +- macros +- proper tail-recursion +- continuations + Added: pypy/dist/pypy/lang/scheme/astbuilder.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/lang/scheme/astbuilder.py Fri Jun 22 20:35:04 2007 @@ -0,0 +1,16 @@ +import autopath +from pypy.rlib.parsing.tree import RPythonVisitor + +class ASTBuilder(RPythonVisitor): + + def visit_STRING(self, node): + print node.symbol + ":" + node.additional_info + + def visit_IDENTIFIER(self, node): + print node.symbol + ":" + node.additional_info + + def visit_sexpr(self, node): + print node.symbol + ":(" + nodes = [self.dispatch(child) for child in node.children] + print ")" + Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Fri Jun 22 20:35:04 2007 @@ -1,5 +1,21 @@ import autopath +class ExecutionContext(object): + """Execution context implemented as a dict. + + { "IDENTIFIER": W_Root } + """ + def __init__(self, scope): + assert scope is not None + self.scope = scope + + def __get__(self, name): + # shouldn't neme be instance of sth like W_Identifier + return self.scope.get(name, None) + + def __put__(self, name, obj): + self.scope[name] = obj + class W_Root(object): def to_string(self): return '' @@ -13,6 +29,16 @@ def __repr__(self): return "" +class W_Symbol(W_Root): + def __init__(self, val): + self.name = val + + def to_string(self): + return self.name + + def __repr__(self): + return "" + class W_Boolean(W_Root): def __init__(self, val): self.boolval = bool(val) Modified: pypy/dist/pypy/lang/scheme/ssparser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/ssparser.py (original) +++ pypy/dist/pypy/lang/scheme/ssparser.py Fri Jun 22 20:35:04 2007 @@ -1,7 +1,6 @@ import autopath from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function from pypy.rlib.parsing.parsing import ParseError -from pypy.rlib.parsing.tree import RPythonVisitor DEBUG = False @@ -21,22 +20,10 @@ parsef = make_parse_function(regexs, rules, eof=True) def parse(code): - t = parsef(code) - tree = t.visit(ToAST())[0] + t = parsef(code) + #tree = t.visit(ToAST())[0] + tree = ToAST().transform(t) if DEBUG: - ToAST().transform(t).view() + tree.view() return tree -class ASTBuilder(RPythonVisitor): - - def visit_STRING(self, node): - print node.symbol + ":" + node.additional_info - - def visit_IDENTIFIER(self, node): - print node.symbol + ":" + node.additional_info - - def visit_sexpr(self, node): - print node.symbol + ":(" - nodes = [self.dispatch(child) for child in node.children] - print ")" - Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Fri Jun 22 20:35:04 2007 @@ -4,7 +4,7 @@ def test_simple_sexpr(): #parse simple sexpr t = parse(r'''(+ 1 2)''') - assert isinstance(t, Nonterminal) + assert isinstance(t, Nonterminal) assert len(t.children) == 3 def test_string(): From jlg at codespeak.net Fri Jun 22 20:37:57 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Fri, 22 Jun 2007 20:37:57 +0200 (CEST) Subject: [pypy-svn] r44439 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070622183757.41C668125@code0.codespeak.net> Author: jlg Date: Fri Jun 22 20:37:55 2007 New Revision: 44439 Modified: pypy/dist/pypy/lang/scheme/TODO.txt pypy/dist/pypy/lang/scheme/test/test_parser.py Log: update test_parser to work with astbuilder new location Modified: pypy/dist/pypy/lang/scheme/TODO.txt ============================================================================== --- pypy/dist/pypy/lang/scheme/TODO.txt (original) +++ pypy/dist/pypy/lang/scheme/TODO.txt Fri Jun 22 20:37:55 2007 @@ -12,6 +12,7 @@ ------- - symbols, variables and execution context + global dict for symbols _obarray_ - control structures - functions Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Fri Jun 22 20:37:55 2007 @@ -1,4 +1,5 @@ -from pypy.lang.scheme.ssparser import * +from pypy.lang.scheme.ssparser import parse +from pypy.lang.scheme.astbuilder import ASTBuilder from pypy.rlib.parsing.parsing import Symbol, Nonterminal def test_simple_sexpr(): From cfbolz at codespeak.net Fri Jun 22 22:17:08 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Fri, 22 Jun 2007 22:17:08 +0200 (CEST) Subject: [pypy-svn] r44445 - pypy/dist/pypy/rpython/lltypesystem Message-ID: <20070622201708.1A23F812E@code0.codespeak.net> Author: cfbolz Date: Fri Jun 22 22:17:07 2007 New Revision: 44445 Modified: pypy/dist/pypy/rpython/lltypesystem/rfficache.py Log: python 2.3 compat Modified: pypy/dist/pypy/rpython/lltypesystem/rfficache.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/rfficache.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/rfficache.py Fri Jun 22 22:17:07 2007 @@ -6,7 +6,7 @@ import py import os from pypy.translator.tool.cbuild import build_executable -from subprocess import PIPE, Popen +from py.compat.subprocess import PIPE, Popen from pypy.tool.udir import udir def sizeof_c_type(c_typename, includes={}, compiler_exe=None): @@ -63,7 +63,7 @@ platforms = {} try: result = platforms[platform_key] - if sorted(result.keys()) != sorted(TYPES): + if py.builtin.sorted(result.keys()) != py.builtin.sorted(TYPES): # invalidate file platforms = {} raise KeyError From cfbolz at codespeak.net Fri Jun 22 22:46:17 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Fri, 22 Jun 2007 22:46:17 +0200 (CEST) Subject: [pypy-svn] r44446 - in pypy/dist/pypy/rlib/parsing: . test Message-ID: <20070622204617.6FBAE8132@code0.codespeak.net> Author: cfbolz Date: Fri Jun 22 22:46:16 2007 New Revision: 44446 Modified: pypy/dist/pypy/rlib/parsing/deterministic.py pypy/dist/pypy/rlib/parsing/ebnfparse.py pypy/dist/pypy/rlib/parsing/parsing.py pypy/dist/pypy/rlib/parsing/regex.py pypy/dist/pypy/rlib/parsing/regexparse.py pypy/dist/pypy/rlib/parsing/test/test_deterministic.py pypy/dist/pypy/rlib/parsing/test/test_ebnfparse.py Log: more 2.3 compat Modified: pypy/dist/pypy/rlib/parsing/deterministic.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/deterministic.py (original) +++ pypy/dist/pypy/rlib/parsing/deterministic.py Fri Jun 22 22:46:16 2007 @@ -3,7 +3,7 @@ try: set except NameError: - from sets import Set as set, FrozenSet as frozenset + from sets import Set as set, ImmutableSet as frozenset def compress_char_set(chars): chars = list(chars) Modified: pypy/dist/pypy/rlib/parsing/ebnfparse.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/ebnfparse.py (original) +++ pypy/dist/pypy/rlib/parsing/ebnfparse.py Fri Jun 22 22:46:16 2007 @@ -8,6 +8,8 @@ from pypy.rlib.parsing.lexer import Lexer, DummyLexer from pypy.rlib.objectmodel import we_are_translated +set = py.builtin.set + def make_ebnf_parser(): NONTERMINALNAME = parse_regex("([a-z]|_)[a-z0-9_]*") SYMBOLNAME = parse_regex("_*[A-Z]([A-Z]|_)*") Modified: pypy/dist/pypy/rlib/parsing/parsing.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/parsing.py (original) +++ pypy/dist/pypy/rlib/parsing/parsing.py Fri Jun 22 22:46:16 2007 @@ -187,7 +187,7 @@ """NOT_RPYTHON""" follows = {} for rule in self.rules: - follow = set() + follow = py.builtin.set() follows[rule.nonterminal] = follow for expansion in rule.expansions: if expansion and self.is_nonterminal(expansion[0]): Modified: pypy/dist/pypy/rlib/parsing/regex.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/regex.py (original) +++ pypy/dist/pypy/rlib/parsing/regex.py Fri Jun 22 22:46:16 2007 @@ -1,6 +1,9 @@ +import py import string from pypy.rlib.parsing.deterministic import NFA +set = py.builtin.set + class RegularExpression(object): def __init__(self): raise NotImplementedError("abstract base class") Modified: pypy/dist/pypy/rlib/parsing/regexparse.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/regexparse.py (original) +++ pypy/dist/pypy/rlib/parsing/regexparse.py Fri Jun 22 22:46:16 2007 @@ -1,7 +1,3 @@ - - - - import py from pypy.rlib.parsing.parsing import PackratParser, Rule from pypy.rlib.parsing.tree import Nonterminal @@ -10,6 +6,8 @@ from pypy.rlib.parsing.deterministic import compress_char_set, DFA import string +set = py.builtin.set + ESCAPES = { "\\a": "\a", "\\b": "\b", Modified: pypy/dist/pypy/rlib/parsing/test/test_deterministic.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_deterministic.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_deterministic.py Fri Jun 22 22:46:16 2007 @@ -1,5 +1,7 @@ from pypy.rlib.parsing.deterministic import * +from sets import Set + def test_DFA_simple(): a = DFA() s0 = a.add_state("start") Modified: pypy/dist/pypy/rlib/parsing/test/test_ebnfparse.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_ebnfparse.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_ebnfparse.py Fri Jun 22 22:46:16 2007 @@ -4,6 +4,7 @@ from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function from pypy.rlib.parsing.test.test_parse import EvaluateVisitor +from sets import Set def test_simple(): regexs, rules, transformer = parse_ebnf(""" From jlg at codespeak.net Fri Jun 22 23:18:08 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Fri, 22 Jun 2007 23:18:08 +0200 (CEST) Subject: [pypy-svn] r44447 - pypy/dist/pypy/lang/scheme/test Message-ID: <20070622211808.356528136@code0.codespeak.net> Author: jlg Date: Fri Jun 22 23:18:07 2007 New Revision: 44447 Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py Log: simple avaluation tests Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Fri Jun 22 23:18:07 2007 @@ -36,8 +36,13 @@ assert isinstance(t, Nonterminal) assert isinstance(t.children[0], Symbol) -def test_ast(): - t = parse(r'''(define var "(+ 1 2 (sqrt 4))")''') +def eval_expr(expr): + t = parse(expr) astb = ASTBuilder() - astb.dispatch(t) - #assert False + ast = astb.dispatch(t) + # evaluate with no context + return ast.eval(None) + +def test_eval_obj(): + w_num = eval_expr(r'''1''') + assert w_num.to_number() == 1 From cfbolz at codespeak.net Fri Jun 22 23:28:02 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Fri, 22 Jun 2007 23:28:02 +0200 (CEST) Subject: [pypy-svn] r44448 - pypy/dist/pypy/lang/scheme/test Message-ID: <20070622212802.70EBD8136@code0.codespeak.net> Author: cfbolz Date: Fri Jun 22 23:28:01 2007 New Revision: 44448 Modified: pypy/dist/pypy/lang/scheme/test/test_object.py Log: test for jakub Modified: pypy/dist/pypy/lang/scheme/test/test_object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_object.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_object.py Fri Jun 22 23:28:01 2007 @@ -37,3 +37,9 @@ assert p.cdr.car == c2 assert p.cdr.cdr.car == c3 assert p.cdr.cdr.cdr == c4 + +def test_eval_obj(): + py.test.skip("in progress") + w_num = W_Pair(W_Symbol("+"), + W_Pair(W_Fixnum(4), W_Pair(W_Fixnum(5), W_Nil()))) + assert w_num.to_number() == 20 From cfbolz at codespeak.net Fri Jun 22 23:28:26 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Fri, 22 Jun 2007 23:28:26 +0200 (CEST) Subject: [pypy-svn] r44449 - pypy/dist/pypy/lang/scheme/test Message-ID: <20070622212826.DCD958136@code0.codespeak.net> Author: cfbolz Date: Fri Jun 22 23:28:26 2007 New Revision: 44449 Modified: pypy/dist/pypy/lang/scheme/test/test_object.py Log: fix the test Modified: pypy/dist/pypy/lang/scheme/test/test_object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_object.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_object.py Fri Jun 22 23:28:26 2007 @@ -42,4 +42,4 @@ py.test.skip("in progress") w_num = W_Pair(W_Symbol("+"), W_Pair(W_Fixnum(4), W_Pair(W_Fixnum(5), W_Nil()))) - assert w_num.to_number() == 20 + assert w_num.eval(None).to_number() == 20 From jlg at codespeak.net Sat Jun 23 00:12:10 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Sat, 23 Jun 2007 00:12:10 +0200 (CEST) Subject: [pypy-svn] r44451 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070622221210.676868139@code0.codespeak.net> Author: jlg Date: Sat Jun 23 00:12:09 2007 New Revision: 44451 Added: pypy/dist/pypy/lang/scheme/operation.py (contents, props changed) Modified: pypy/dist/pypy/lang/scheme/test/test_object.py pypy/dist/pypy/lang/scheme/test/test_parser.py Log: added operation.py + new tests in test_object.py Added: pypy/dist/pypy/lang/scheme/operation.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/lang/scheme/operation.py Sat Jun 23 00:12:09 2007 @@ -0,0 +1,18 @@ +import autopath +from pypy.lang.scheme.object import * + +def mul(ctx, args_lst): + acc = 1 + for arg in args_lst: + acc *= arg.to_number() + + return W_Fixnum(acc) + +def add(ctx, args_lst): + acc = 0 + for arg in args_lst: + acc += arg.to_number() + + return W_Fixnum(acc) + + Modified: pypy/dist/pypy/lang/scheme/test/test_object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_object.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_object.py Sat Jun 23 00:12:09 2007 @@ -1,4 +1,6 @@ +import py from pypy.lang.scheme.object import * +from pypy.lang.scheme.operation import * def test_false(): w_false = W_Boolean(False) @@ -43,3 +45,26 @@ w_num = W_Pair(W_Symbol("+"), W_Pair(W_Fixnum(4), W_Pair(W_Fixnum(5), W_Nil()))) assert w_num.eval(None).to_number() == 20 + +def test_operations_simple(): + py.test.skip("in progress") + w_num1 = W_Fixnum(4) + w_num2 = W_Fixnum(5) + w_num3 = W_Float(6.1) + + w_num = mul(None, [w_num1]) + assert w_num.to_number() == w_num1.to_number() + w_num = mul(None, [w_num1, w_num2]) + assert w_num.to_number() == w_num1.to_number() * w_num2.to_number() + w_num = mul(None, [w_num1, w_num2, w_num3]) + assert w_num.to_number() == (w_num2.to_number() * w_num2.to_number() + * w_num3.to_number()) + + w_num = add(None, [w_num1]) + assert w_num.to_number() == w_num1.to_number() + w_num = add(None, [w_num1, w_num2]) + assert w_num.to_number() == w_num1.to_number() + w_num2.to_number() + w_num = add(None, [w_num1, w_num2, w_num3]) + assert w_num.to_number() == (w_num2.to_number() + w_num2.to_number() + + w_num3.to_number()) + Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Sat Jun 23 00:12:09 2007 @@ -1,3 +1,4 @@ +import py from pypy.lang.scheme.ssparser import parse from pypy.lang.scheme.astbuilder import ASTBuilder from pypy.rlib.parsing.parsing import Symbol, Nonterminal @@ -43,6 +44,8 @@ # evaluate with no context return ast.eval(None) -def test_eval_obj(): +def test_eval_simple(): + py.test.skip("in progress") w_num = eval_expr(r'''1''') assert w_num.to_number() == 1 + From cfbolz at codespeak.net Sat Jun 23 00:42:20 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sat, 23 Jun 2007 00:42:20 +0200 (CEST) Subject: [pypy-svn] r44452 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070622224220.6331F813B@code0.codespeak.net> Author: cfbolz Date: Sat Jun 23 00:42:18 2007 New Revision: 44452 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/ssparser.py pypy/dist/pypy/lang/scheme/test/test_parser.py Log: use the experimental parsing thingy to write the scheme parser. seems to work somewhat. Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Sat Jun 23 00:42:18 2007 @@ -27,7 +27,7 @@ return self.to_string() + "W" def __repr__(self): - return "" + return "" class W_Symbol(W_Root): def __init__(self, val): Modified: pypy/dist/pypy/lang/scheme/ssparser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/ssparser.py (original) +++ pypy/dist/pypy/lang/scheme/ssparser.py Sat Jun 23 00:42:18 2007 @@ -1,29 +1,60 @@ import autopath -from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function -from pypy.rlib.parsing.parsing import ParseError +from pypy.rlib.parsing.pypackrat import PackratParser +from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Symbol +from pypy.lang.scheme.object import W_Nil DEBUG = False -grammar = r''' -STRING: "\"([^\\\"]|\\\"|\\\\)*\""; -IDENTIFIER: "[\+\-\*\^\?a-zA-Z0-9!<=>_~/$%&:]+"; -IGNORE: " |\n|\t|;[^\n]*"; -sexpr: ["("] sexpr* [")"] | | ; -''' - -try: - regexs, rules, ToAST = parse_ebnf(grammar) -except ParseError, e: - #print e.nice_error_message() - raise - -parsef = make_parse_function(regexs, rules, eof=True) +class SchemeParser(PackratParser): + r''' + STRING: + c = `\"([^\\\"]|\\\"|\\\\)*\"` + IGNORE* + return {W_String(c)}; + + IDENTIFIER: + c = `[\+\-\*\^\?a-zA-Z!<=>_~/$%&:][\+\-\*\^\?a-zA-Z0-9!<=>_~/$%&:]*` + IGNORE* + return {W_Symbol(c)}; + + FIXNUM: + c = `0|([1-9][0-9]*)` + IGNORE* + return {W_Fixnum(int(c))}; + + IGNORE: + ` |\n|\t|;[^\n]*`; + + EOF: + !__any__; + + file: + IGNORE* + s = sexpr + EOF + return {s}; + + sexpr: + list + | FIXNUM + | IDENTIFIER + | STRING; + + list: + '(' + IGNORE* + p = pair + ')' + IGNORE* + return {p}; + + pair: + car = sexpr + cdr = pair + return {W_Pair(car, cdr)} + | return {W_Nil()}; + ''' def parse(code): - t = parsef(code) - #tree = t.visit(ToAST())[0] - tree = ToAST().transform(t) - if DEBUG: - tree.view() - return tree - + p = SchemeParser(code) + return p.file() Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Sat Jun 23 00:42:18 2007 @@ -1,18 +1,43 @@ -import py from pypy.lang.scheme.ssparser import parse -from pypy.lang.scheme.astbuilder import ASTBuilder -from pypy.rlib.parsing.parsing import Symbol, Nonterminal +from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Symbol +from pypy.lang.scheme.object import W_Nil -def test_simple_sexpr(): - #parse simple sexpr - t = parse(r'''(+ 1 2)''') - assert isinstance(t, Nonterminal) - assert len(t.children) == 3 - -def test_string(): - #parse string +def unwrap(w_obj): + """for testing purposes: unwrap a scheme object into a python object""" + if isinstance(w_obj, W_Fixnum): + return w_obj.to_number() + elif isinstance(w_obj, W_String): + return w_obj.strval + elif isinstance(w_obj, W_Symbol): + return w_obj.name + elif isinstance(w_obj, W_Pair): + result = [] + while not isinstance(w_obj, W_Nil): + result.append(unwrap(w_obj.car)) + w_obj = w_obj.cdr + return result + raise NotImplementedError("don't know what to do with: %s" % (w_obj, )) + +def test_simple(): + w_fixnum = parse(r'''1''') + assert isinstance(w_fixnum, W_Fixnum) + w_fixnum = parse(r'''0''') + assert isinstance(w_fixnum, W_Fixnum) + w_fixnum = parse(r'''1123''') + assert isinstance(w_fixnum, W_Fixnum) + w_fixnum = parse(r'''abfa__''') + assert isinstance(w_fixnum, W_Symbol) + w_fixnum = parse(r'''+''') + assert isinstance(w_fixnum, W_Symbol) t = parse(r'''"don't beleive \"them\""''') - assert isinstance(t, Symbol) + assert isinstance(t, W_String) + w_list = parse(r'''(+ 1 2)''') + assert isinstance(w_list, W_Pair) + assert isinstance(w_list.car, W_Symbol) + assert isinstance(w_list.cdr, W_Pair) + assert isinstance(w_list.cdr.car, W_Fixnum) + assert isinstance(w_list.cdr.cdr.car, W_Fixnum) + assert isinstance(w_list.cdr.cdr.cdr, W_Nil) def test_complex_sexpr(): #parse more complex sexpr @@ -21,31 +46,20 @@ (if (< n 2) n (* (fac (- n 1)) n))) ''') - assert isinstance(t, Nonterminal) - assert len(t.children) == 3 - assert isinstance(t.children[0], Symbol) - assert isinstance(t.children[1], Nonterminal) - assert isinstance(t.children[2], Nonterminal) + assert isinstance(t, W_Pair) + assert unwrap(t) == ['define', ['fac', 'n'], + ['if', ['<', 'n', 2], 'n', + ['*', ['fac', ['-', 'n', 1]], 'n']]] def test_ident_gen(): - ch_list = "+-*/azAZ09<=>-_~!$%&:?^" + ch_list = "+-*/azAZ<=>-_~!$%&:?^" for char in ch_list: yield check_ident_ch, char def check_ident_ch(char): t = parse("(" + char + ")") - assert isinstance(t, Nonterminal) - assert isinstance(t.children[0], Symbol) + assert isinstance(t, W_Pair) + assert isinstance(t.car, W_Symbol) + assert isinstance(t.cdr, W_Nil) -def eval_expr(expr): - t = parse(expr) - astb = ASTBuilder() - ast = astb.dispatch(t) - # evaluate with no context - return ast.eval(None) - -def test_eval_simple(): - py.test.skip("in progress") - w_num = eval_expr(r'''1''') - assert w_num.to_number() == 1 From cfbolz at codespeak.net Sat Jun 23 00:45:50 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sat, 23 Jun 2007 00:45:50 +0200 (CEST) Subject: [pypy-svn] r44453 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070622224550.DBF90813B@code0.codespeak.net> Author: cfbolz Date: Sat Jun 23 00:45:50 2007 New Revision: 44453 Modified: pypy/dist/pypy/lang/scheme/ssparser.py pypy/dist/pypy/lang/scheme/test/test_parser.py Log: unquoting of strings Modified: pypy/dist/pypy/lang/scheme/ssparser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/ssparser.py (original) +++ pypy/dist/pypy/lang/scheme/ssparser.py Sat Jun 23 00:45:50 2007 @@ -5,12 +5,15 @@ DEBUG = False +def unquote(s): + return s.replace('\\"', '"') + class SchemeParser(PackratParser): r''' STRING: c = `\"([^\\\"]|\\\"|\\\\)*\"` IGNORE* - return {W_String(c)}; + return {W_String(unquote(c[1:-1]))}; IDENTIFIER: c = `[\+\-\*\^\?a-zA-Z!<=>_~/$%&:][\+\-\*\^\?a-zA-Z0-9!<=>_~/$%&:]*` Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Sat Jun 23 00:45:50 2007 @@ -29,8 +29,9 @@ assert isinstance(w_fixnum, W_Symbol) w_fixnum = parse(r'''+''') assert isinstance(w_fixnum, W_Symbol) - t = parse(r'''"don't beleive \"them\""''') + t = parse(r'''"don't believe \"them\""''') assert isinstance(t, W_String) + assert unwrap(t) == 'don\'t believe "them"' w_list = parse(r'''(+ 1 2)''') assert isinstance(w_list, W_Pair) assert isinstance(w_list.car, W_Symbol) @@ -62,4 +63,3 @@ assert isinstance(t.car, W_Symbol) assert isinstance(t.cdr, W_Nil) - From jlg at codespeak.net Sat Jun 23 00:48:13 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Sat, 23 Jun 2007 00:48:13 +0200 (CEST) Subject: [pypy-svn] r44454 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070622224813.50DE3813B@code0.codespeak.net> Author: jlg Date: Sat Jun 23 00:48:12 2007 New Revision: 44454 Modified: pypy/dist/pypy/lang/scheme/operation.py pypy/dist/pypy/lang/scheme/test/test_object.py Log: simple mul and add works Modified: pypy/dist/pypy/lang/scheme/operation.py ============================================================================== --- pypy/dist/pypy/lang/scheme/operation.py (original) +++ pypy/dist/pypy/lang/scheme/operation.py Sat Jun 23 00:48:12 2007 @@ -6,13 +6,19 @@ for arg in args_lst: acc *= arg.to_number() - return W_Fixnum(acc) + if isinstance(acc, int): + return W_Fixnum(acc) + else: + return W_Float(acc) def add(ctx, args_lst): acc = 0 for arg in args_lst: acc += arg.to_number() - return W_Fixnum(acc) + if isinstance(acc, int): + return W_Fixnum(acc) + else: + return W_Float(acc) Modified: pypy/dist/pypy/lang/scheme/test/test_object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_object.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_object.py Sat Jun 23 00:48:12 2007 @@ -47,7 +47,6 @@ assert w_num.eval(None).to_number() == 20 def test_operations_simple(): - py.test.skip("in progress") w_num1 = W_Fixnum(4) w_num2 = W_Fixnum(5) w_num3 = W_Float(6.1) @@ -57,14 +56,13 @@ w_num = mul(None, [w_num1, w_num2]) assert w_num.to_number() == w_num1.to_number() * w_num2.to_number() w_num = mul(None, [w_num1, w_num2, w_num3]) - assert w_num.to_number() == (w_num2.to_number() * w_num2.to_number() - * w_num3.to_number()) + assert w_num.to_number() == (w_num1.to_number() * w_num2.to_number() * w_num3.to_number()) w_num = add(None, [w_num1]) assert w_num.to_number() == w_num1.to_number() w_num = add(None, [w_num1, w_num2]) assert w_num.to_number() == w_num1.to_number() + w_num2.to_number() w_num = add(None, [w_num1, w_num2, w_num3]) - assert w_num.to_number() == (w_num2.to_number() + w_num2.to_number() + assert w_num.to_number() == (w_num1.to_number() + w_num2.to_number() + w_num3.to_number()) From cfbolz at codespeak.net Sat Jun 23 00:49:01 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sat, 23 Jun 2007 00:49:01 +0200 (CEST) Subject: [pypy-svn] r44455 - pypy/dist/pypy/lang/scheme/test Message-ID: <20070622224901.E2010813B@code0.codespeak.net> Author: cfbolz Date: Sat Jun 23 00:49:01 2007 New Revision: 44455 Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py Log: improve int test Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Sat Jun 23 00:49:01 2007 @@ -21,9 +21,12 @@ def test_simple(): w_fixnum = parse(r'''1''') assert isinstance(w_fixnum, W_Fixnum) + assert unwrap(w_fixnum) == 1 w_fixnum = parse(r'''0''') + assert unwrap(w_fixnum) == 0 assert isinstance(w_fixnum, W_Fixnum) w_fixnum = parse(r'''1123''') + assert unwrap(w_fixnum) == 1123 assert isinstance(w_fixnum, W_Fixnum) w_fixnum = parse(r'''abfa__''') assert isinstance(w_fixnum, W_Symbol) From cfbolz at codespeak.net Sat Jun 23 00:53:44 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sat, 23 Jun 2007 00:53:44 +0200 (CEST) Subject: [pypy-svn] r44456 - pypy/dist/pypy/lang/scheme/test Message-ID: <20070622225344.B8D5C813B@code0.codespeak.net> Author: cfbolz Date: Sat Jun 23 00:53:44 2007 New Revision: 44456 Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py Log: improve the symbol tests Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Sat Jun 23 00:53:44 2007 @@ -64,5 +64,6 @@ t = parse("(" + char + ")") assert isinstance(t, W_Pair) assert isinstance(t.car, W_Symbol) + assert unwrap(t.car) == char assert isinstance(t.cdr, W_Nil) From cfbolz at codespeak.net Sat Jun 23 00:58:37 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sat, 23 Jun 2007 00:58:37 +0200 (CEST) Subject: [pypy-svn] r44457 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070622225837.1DB4F813B@code0.codespeak.net> Author: cfbolz Date: Sat Jun 23 00:58:36 2007 New Revision: 44457 Modified: pypy/dist/pypy/lang/scheme/ssparser.py pypy/dist/pypy/lang/scheme/test/test_parser.py Log: add boolean support to the parser Modified: pypy/dist/pypy/lang/scheme/ssparser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/ssparser.py (original) +++ pypy/dist/pypy/lang/scheme/ssparser.py Sat Jun 23 00:58:36 2007 @@ -1,7 +1,7 @@ import autopath from pypy.rlib.parsing.pypackrat import PackratParser from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Symbol -from pypy.lang.scheme.object import W_Nil +from pypy.lang.scheme.object import W_Nil, W_Boolean DEBUG = False @@ -25,6 +25,11 @@ IGNORE* return {W_Fixnum(int(c))}; + BOOLEAN: + c = `#(t|f)` + IGNORE* + return {W_Boolean(c[-1] == 't')}; + IGNORE: ` |\n|\t|;[^\n]*`; @@ -40,6 +45,7 @@ sexpr: list | FIXNUM + | BOOLEAN | IDENTIFIER | STRING; Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Sat Jun 23 00:58:36 2007 @@ -1,6 +1,6 @@ from pypy.lang.scheme.ssparser import parse from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Symbol -from pypy.lang.scheme.object import W_Nil +from pypy.lang.scheme.object import W_Nil, W_Boolean def unwrap(w_obj): """for testing purposes: unwrap a scheme object into a python object""" @@ -10,6 +10,8 @@ return w_obj.strval elif isinstance(w_obj, W_Symbol): return w_obj.name + elif isinstance(w_obj, W_Boolean): + return w_obj.boolval elif isinstance(w_obj, W_Pair): result = [] while not isinstance(w_obj, W_Nil): @@ -67,3 +69,8 @@ assert unwrap(t.car) == char assert isinstance(t.cdr, W_Nil) +def test_truth_values(): + t = parse("#f") + assert unwrap(t) == False + t = parse("#t") + assert unwrap(t) == True From cfbolz at codespeak.net Sat Jun 23 01:09:02 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sat, 23 Jun 2007 01:09:02 +0200 (CEST) Subject: [pypy-svn] r44458 - pypy/dist/pypy/lang/scheme Message-ID: <20070622230902.85C22813B@code0.codespeak.net> Author: cfbolz Date: Sat Jun 23 01:09:02 2007 New Revision: 44458 Removed: pypy/dist/pypy/lang/scheme/astbuilder.py Log: this file is not needed any more From jlg at codespeak.net Sat Jun 23 01:57:23 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Sat, 23 Jun 2007 01:57:23 +0200 (CEST) Subject: [pypy-svn] r44459 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070622235723.57556814A@code0.codespeak.net> Author: jlg Date: Sat Jun 23 01:57:22 2007 New Revision: 44459 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/operation.py pypy/dist/pypy/lang/scheme/test/test_object.py Log: ugly code to pass cfboltz's test Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Sat Jun 23 01:57:22 2007 @@ -27,7 +27,10 @@ return self.to_string() + "W" def __repr__(self): - return "" + return "" + + def eval(self, ctx): + return self class W_Symbol(W_Root): def __init__(self, val): @@ -39,6 +42,28 @@ def __repr__(self): return "" + def eval(self, ctx): + if self.name == '+': + return add_lst + + raise NotImplementedError + +#not sure though any operations should exist here +#it its very similar to operation.add +def add_lst(ctx, lst): + acc = 0 + if not isinstance(lst, W_Pair): + #raise argument error + raise + + arg = lst + while not isinstance(arg, W_Nil): + acc += arg.car.eval(ctx).to_number() + arg = arg.cdr + + return W_Fixnum(acc) + + class W_Boolean(W_Root): def __init__(self, val): self.boolval = bool(val) @@ -104,6 +129,10 @@ def to_string(self): return "(" + self.car.to_string() + " . " + self.cdr.to_string() + ")" + def eval(self, ctx): + oper = self.car.eval(ctx) + return oper(ctx, self.cdr) + class W_Nil(W_Root): def to_string(self): return "()" Modified: pypy/dist/pypy/lang/scheme/operation.py ============================================================================== --- pypy/dist/pypy/lang/scheme/operation.py (original) +++ pypy/dist/pypy/lang/scheme/operation.py Sat Jun 23 01:57:22 2007 @@ -21,4 +21,3 @@ else: return W_Float(acc) - Modified: pypy/dist/pypy/lang/scheme/test/test_object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_object.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_object.py Sat Jun 23 01:57:22 2007 @@ -41,10 +41,9 @@ assert p.cdr.cdr.cdr == c4 def test_eval_obj(): - py.test.skip("in progress") w_num = W_Pair(W_Symbol("+"), W_Pair(W_Fixnum(4), W_Pair(W_Fixnum(5), W_Nil()))) - assert w_num.eval(None).to_number() == 20 + assert w_num.eval(None).to_number() == 9 def test_operations_simple(): w_num1 = W_Fixnum(4) From jlg at codespeak.net Sat Jun 23 11:23:09 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Sat, 23 Jun 2007 11:23:09 +0200 (CEST) Subject: [pypy-svn] r44466 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070623092309.9597E813E@code0.codespeak.net> Author: jlg Date: Sat Jun 23 11:23:07 2007 New Revision: 44466 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_object.py pypy/dist/pypy/lang/scheme/test/test_parser.py Log: added test_eval, simple operations works Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Sat Jun 23 11:23:07 2007 @@ -43,25 +43,11 @@ return "" def eval(self, ctx): - if self.name == '+': - return add_lst - - raise NotImplementedError - -#not sure though any operations should exist here -#it its very similar to operation.add -def add_lst(ctx, lst): - acc = 0 - if not isinstance(lst, W_Pair): - #raise argument error - raise - - arg = lst - while not isinstance(arg, W_Nil): - acc += arg.car.eval(ctx).to_number() - arg = arg.cdr - - return W_Fixnum(acc) + # should be -> get form ctx dict the right method + try: + return OPERATION_MAP[self.name] + except KeyError: + raise NotImplementedError class W_Boolean(W_Root): @@ -137,3 +123,40 @@ def to_string(self): return "()" +############################ +# operations +#not sure though any operations should exist here +#it its very similar to operation.add +############################# + +def add_lst(ctx, lst): + return apply_lst(ctx, lambda x, y: x + y, lst) + +def mul_lst(ctx, lst): + return apply_lst(ctx, lambda x, y: x * y, lst) + +def apply_lst(ctx, fun, lst): + acc = None + + if not isinstance(lst, W_Pair): + #raise argument error + raise + + arg = lst + while not isinstance(arg, W_Nil): + if acc is None: + acc = arg.car.eval(ctx).to_number() + else: + acc = fun(acc, arg.car.eval(ctx).to_number()) + arg = arg.cdr + + if isinstance(acc, int): + return W_Fixnum(acc) + else: + return W_Float(acc) + +OPERATION_MAP = \ + { + '+': add_lst, + '*': mul_lst, + } Modified: pypy/dist/pypy/lang/scheme/test/test_object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_object.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_object.py Sat Jun 23 11:23:07 2007 @@ -39,29 +39,3 @@ assert p.cdr.car == c2 assert p.cdr.cdr.car == c3 assert p.cdr.cdr.cdr == c4 - -def test_eval_obj(): - w_num = W_Pair(W_Symbol("+"), - W_Pair(W_Fixnum(4), W_Pair(W_Fixnum(5), W_Nil()))) - assert w_num.eval(None).to_number() == 9 - -def test_operations_simple(): - w_num1 = W_Fixnum(4) - w_num2 = W_Fixnum(5) - w_num3 = W_Float(6.1) - - w_num = mul(None, [w_num1]) - assert w_num.to_number() == w_num1.to_number() - w_num = mul(None, [w_num1, w_num2]) - assert w_num.to_number() == w_num1.to_number() * w_num2.to_number() - w_num = mul(None, [w_num1, w_num2, w_num3]) - assert w_num.to_number() == (w_num1.to_number() * w_num2.to_number() * w_num3.to_number()) - - w_num = add(None, [w_num1]) - assert w_num.to_number() == w_num1.to_number() - w_num = add(None, [w_num1, w_num2]) - assert w_num.to_number() == w_num1.to_number() + w_num2.to_number() - w_num = add(None, [w_num1, w_num2, w_num3]) - assert w_num.to_number() == (w_num1.to_number() + w_num2.to_number() - + w_num3.to_number()) - Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Sat Jun 23 11:23:07 2007 @@ -19,7 +19,7 @@ w_obj = w_obj.cdr return result raise NotImplementedError("don't know what to do with: %s" % (w_obj, )) - + def test_simple(): w_fixnum = parse(r'''1''') assert isinstance(w_fixnum, W_Fixnum) @@ -55,7 +55,7 @@ assert isinstance(t, W_Pair) assert unwrap(t) == ['define', ['fac', 'n'], ['if', ['<', 'n', 2], 'n', - ['*', ['fac', ['-', 'n', 1]], 'n']]] + ['*', ['fac', ['-', 'n', 1]], 'n']]] def test_ident_gen(): ch_list = "+-*/azAZ<=>-_~!$%&:?^" From jlg at codespeak.net Sat Jun 23 11:24:25 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Sat, 23 Jun 2007 11:24:25 +0200 (CEST) Subject: [pypy-svn] r44467 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070623092425.947B4813E@code0.codespeak.net> Author: jlg Date: Sat Jun 23 11:24:25 2007 New Revision: 44467 Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt Log: changed my arrival date Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/people.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/people.txt Sat Jun 23 11:24:25 2007 @@ -16,7 +16,7 @@ Samuele Pedroni 7/14th Ratonda Centrum Hotels Laura Creighton 7/14th Ratonda Centrum Hotels Jacob Hallen 7/14th Ratonda Centrum Hotels -Jakub Gustak 7/15th Hospitality Club :) +Jakub Gustak 8/15th Hospitality Club :) ==================== ============== ======================= People on the following list were present at previous sprints: From cfbolz at codespeak.net Sat Jun 23 12:10:27 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sat, 23 Jun 2007 12:10:27 +0200 (CEST) Subject: [pypy-svn] r44468 - in pypy/dist/pypy/rlib/parsing: . test Message-ID: <20070623101027.CDBE68152@code0.codespeak.net> Author: cfbolz Date: Sat Jun 23 12:10:27 2007 New Revision: 44468 Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py pypy/dist/pypy/rlib/parsing/pypackrat.py pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Log: add support for productions with arguments Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/makepackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/makepackrat.py Sat Jun 23 12:10:27 2007 @@ -79,14 +79,34 @@ production: name = NAME SPACE* + args = productionargs ':' IGNORE* what = or_ IGNORE* ';' IGNORE* - return {Nonterminal('production', [name, what])}; + return {Nonterminal('production', [name, args, what])}; +productionargs: + '(' + IGNORE* + args = ( + NAME + [ + IGNORE* + ',' + IGNORE* + ] + )* + arg = NAME + IGNORE* + ')' + IGNORE* + return {Nonterminal('productionargs', args + [arg])} + | return {Nonterminal('productionargs', [])}; + + or_: l = (commands ['|' IGNORE*])+ last = commands @@ -179,9 +199,23 @@ call | REGEX [IGNORE*] | QUOTE [IGNORE*]; call: - x = NAME + x = NAME + args = arguments + IGNORE* + return {Nonterminal("call", [x, args])}; + +arguments: + '(' IGNORE* - return {Nonterminal("call", [x])}; + args = ( + PYTHONCODE + [IGNORE* ',' IGNORE*] + )* + last = PYTHONCODE + ')' + IGNORE* + return {Nonterminal("args", args + [last])} + | return {Nonterminal("args", [])}; """ class ErrorInformation(object): @@ -249,13 +283,17 @@ assert starterpart in block, "ended wrong block %s with %s" % ( block, starterpart) - def memoize_header(self, name): + def memoize_header(self, name, args): statusclassname = "self._Status_%s" % (name, ) dictname = "_dict_%s" % (name, ) self.emit_initcode("self.%s = {}" % (dictname, )) - self.emit("_status = self.%s.get(self._pos, None)" % (dictname, )) + if args: + self.emit("_key = (self._pos, %s)" % (", ".join(args))) + else: + self.emit("_key = self._pos") + self.emit("_status = self.%s.get(_key, None)" % (dictname, )) for _ in self.start_block("if _status is None:"): - self.emit("_status = self.%s[self._pos] = %s()" % ( + self.emit("_status = self.%s[_key] = %s()" % ( dictname, statusclassname)) for _ in self.start_block("elif _status.status == _status.NORMAL:"): self.emit("self._pos = _status.pos") @@ -271,7 +309,8 @@ self.emit("return _status") for _ in self.start_block("else:"): self.emit("raise self._BacktrackException(None)") - for _ in self.start_block("elif _status.status == _status.SOMESOLUTIONS:"): + for _ in self.start_block( + "elif _status.status == _status.SOMESOLUTIONS:"): self.emit("_status.status = _status.INPROGRESS") self.emit("_startingpos = self._pos") self.start_block("try:") @@ -375,13 +414,17 @@ raise Exception("name %s appears twice" % (name, )) self.names[name] = True self.make_status_class(name) - for _ in self.start_block("def %s(self):" % (name, )): - self.emit("return self._%s().result" % (name, )) - self.start_block("def _%s(self):" % (name, )) - self.memoize_header(name) + otherargs = t.children[1].children + argswithself = ", ".join(["self"] + otherargs) + argswithoutself = ", ".join(otherargs) + for _ in self.start_block("def %s(%s):" % (name, argswithself)): + self.emit("return self._%s(%s).result" % (name, argswithoutself)) + self.start_block("def _%s(%s):" % (name, argswithself, )) + + self.memoize_header(name, otherargs) #self.emit("print '%s', self._pos" % (name, )) self.resultname = "_result" - self.dispatch(t.children[1]) + self.dispatch(t.children[-1]) self.memoize_footer(name) self.end_block("def") @@ -493,12 +536,14 @@ self.emit(" _startingpos, ['condition not met']))") def visit_call(self, t): + args = ", ".join(['(%s)' % (arg.additional_info[1:-1], ) + for arg in t.children[1].children]) if t.children[0].startswith("_"): callname = t.children[0] - self.emit("_result = self.%s()" % (callname, )) + self.emit("_result = self.%s(%s)" % (callname, args)) else: callname = "_" + t.children[0] - self.emit("_call_status = self.%s()" % (callname, )) + self.emit("_call_status = self.%s(%s)" % (callname, args)) self.emit("_result = _call_status.result") self.emit( "_error = self._combine_errors(_call_status.error, _error)") Modified: pypy/dist/pypy/rlib/parsing/pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/pypackrat.py Sat Jun 23 12:10:27 2007 @@ -11,9 +11,10 @@ def NAME(self): return self._NAME().result def _NAME(self): - _status = self._dict_NAME.get(self._pos, None) + _key = self._pos + _status = self._dict_NAME.get(_key, None) if _status is None: - _status = self._dict_NAME[self._pos] = self._Status_NAME() + _status = self._dict_NAME[_key] = self._Status_NAME() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -67,9 +68,10 @@ def SPACE(self): return self._SPACE().result def _SPACE(self): - _status = self._dict_SPACE.get(self._pos, None) + _key = self._pos + _status = self._dict_SPACE.get(_key, None) if _status is None: - _status = self._dict_SPACE[self._pos] = self._Status_SPACE() + _status = self._dict_SPACE[_key] = self._Status_SPACE() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -123,9 +125,10 @@ def COMMENT(self): return self._COMMENT().result def _COMMENT(self): - _status = self._dict_COMMENT.get(self._pos, None) + _key = self._pos + _status = self._dict_COMMENT.get(_key, None) if _status is None: - _status = self._dict_COMMENT[self._pos] = self._Status_COMMENT() + _status = self._dict_COMMENT[_key] = self._Status_COMMENT() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -179,9 +182,10 @@ def IGNORE(self): return self._IGNORE().result def _IGNORE(self): - _status = self._dict_IGNORE.get(self._pos, None) + _key = self._pos + _status = self._dict_IGNORE.get(_key, None) if _status is None: - _status = self._dict_IGNORE[self._pos] = self._Status_IGNORE() + _status = self._dict_IGNORE[_key] = self._Status_IGNORE() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -235,9 +239,10 @@ def newline(self): return self._newline().result def _newline(self): - _status = self._dict_newline.get(self._pos, None) + _key = self._pos + _status = self._dict_newline.get(_key, None) if _status is None: - _status = self._dict_newline[self._pos] = self._Status_newline() + _status = self._dict_newline[_key] = self._Status_newline() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -311,9 +316,10 @@ def REGEX(self): return self._REGEX().result def _REGEX(self): - _status = self._dict_REGEX.get(self._pos, None) + _key = self._pos + _status = self._dict_REGEX.get(_key, None) if _status is None: - _status = self._dict_REGEX[self._pos] = self._Status_REGEX() + _status = self._dict_REGEX[_key] = self._Status_REGEX() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -369,9 +375,10 @@ def QUOTE(self): return self._QUOTE().result def _QUOTE(self): - _status = self._dict_QUOTE.get(self._pos, None) + _key = self._pos + _status = self._dict_QUOTE.get(_key, None) if _status is None: - _status = self._dict_QUOTE[self._pos] = self._Status_QUOTE() + _status = self._dict_QUOTE[_key] = self._Status_QUOTE() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -427,9 +434,10 @@ def PYTHONCODE(self): return self._PYTHONCODE().result def _PYTHONCODE(self): - _status = self._dict_PYTHONCODE.get(self._pos, None) + _key = self._pos + _status = self._dict_PYTHONCODE.get(_key, None) if _status is None: - _status = self._dict_PYTHONCODE[self._pos] = self._Status_PYTHONCODE() + _status = self._dict_PYTHONCODE[_key] = self._Status_PYTHONCODE() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -485,9 +493,10 @@ def EOF(self): return self._EOF().result def _EOF(self): - _status = self._dict_EOF.get(self._pos, None) + _key = self._pos + _status = self._dict_EOF.get(_key, None) if _status is None: - _status = self._dict_EOF[self._pos] = self._Status_EOF() + _status = self._dict_EOF[_key] = self._Status_EOF() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -549,9 +558,10 @@ def file(self): return self._file().result def _file(self): - _status = self._dict_file.get(self._pos, None) + _key = self._pos + _status = self._dict_file.get(_key, None) if _status is None: - _status = self._dict_file[self._pos] = self._Status_file() + _status = self._dict_file[_key] = self._Status_file() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -625,9 +635,10 @@ def list(self): return self._list().result def _list(self): - _status = self._dict_list.get(self._pos, None) + _key = self._pos + _status = self._dict_list.get(_key, None) if _status is None: - _status = self._dict_list[self._pos] = self._Status_list() + _status = self._dict_list[_key] = self._Status_list() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -699,9 +710,10 @@ def production(self): return self._production().result def _production(self): - _status = self._dict_production.get(self._pos, None) + _key = self._pos + _status = self._dict_production.get(_key, None) if _status is None: - _status = self._dict_production[self._pos] = self._Status_production() + _status = self._dict_production[_key] = self._Status_production() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -738,6 +750,10 @@ self._pos = _choice10 break _result = _all9 + _call_status = self._productionargs() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + args = _result _result = self.__chars__(':') _all11 = [] while 1: @@ -783,7 +799,7 @@ self._pos = _choice16 break _result = _all15 - _result = (Nonterminal('production', [name, what])) + _result = (Nonterminal('production', [name, args, what])) if _status.status == _status.LEFTRECURSION: if _status.result is not None: if _status.pos >= self._pos: @@ -808,6 +824,169 @@ _status.error = _error _status.status = _status.ERROR raise self._BacktrackException(_error) + class _Status_productionargs(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def productionargs(self): + return self._productionargs().result + def _productionargs(self): + _key = self._pos + _status = self._dict_productionargs.get(_key, None) + if _status is None: + _status = self._dict_productionargs[_key] = self._Status_productionargs() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice17 = self._pos + try: + _result = self.__chars__('(') + _all18 = [] + while 1: + _choice19 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all18.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice19 + break + _result = _all18 + _all20 = [] + while 1: + _choice21 = self._pos + try: + _call_status = self._NAME() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _before_discard22 = _result + _all23 = [] + while 1: + _choice24 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all23.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice24 + break + _result = _all23 + _result = self.__chars__(',') + _all25 = [] + while 1: + _choice26 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all25.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice26 + break + _result = _all25 + _result = _before_discard22 + _all20.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice21 + break + _result = _all20 + args = _result + _call_status = self._NAME() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + arg = _result + _all27 = [] + while 1: + _choice28 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all27.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice28 + break + _result = _all27 + _result = self.__chars__(')') + _all29 = [] + while 1: + _choice30 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all29.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice30 + break + _result = _all29 + _result = (Nonterminal('productionargs', args + [arg])) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice17 + _choice31 = self._pos + try: + _result = (Nonterminal('productionargs', [])) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice31 + raise self._BacktrackException(_error) + _result = (Nonterminal('productionargs', [])) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._productionargs() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) class _Status_or_(_Status): def __init__(self): self.pos = 0 @@ -817,9 +996,10 @@ def or_(self): return self._or_().result def _or_(self): - _status = self._dict_or_.get(self._pos, None) + _key = self._pos + _status = self._dict_or_.get(_key, None) if _status is None: - _status = self._dict_or_[self._pos] = self._Status_or_() + _status = self._dict_or_[_key] = self._Status_or_() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -841,57 +1021,57 @@ _error = None while 1: _error = None - _choice17 = self._pos + _choice32 = self._pos try: - _all18 = [] + _all33 = [] _call_status = self._commands() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard19 = _result + _before_discard34 = _result _result = self.__chars__('|') - _all20 = [] + _all35 = [] while 1: - _choice21 = self._pos + _choice36 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all20.append(_result) + _all35.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice21 + self._pos = _choice36 break - _result = _all20 - _result = _before_discard19 - _all18.append(_result) + _result = _all35 + _result = _before_discard34 + _all33.append(_result) while 1: - _choice22 = self._pos + _choice37 = self._pos try: _call_status = self._commands() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard23 = _result + _before_discard38 = _result _result = self.__chars__('|') - _all24 = [] + _all39 = [] while 1: - _choice25 = self._pos + _choice40 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all24.append(_result) + _all39.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice25 + self._pos = _choice40 break - _result = _all24 - _result = _before_discard23 - _all18.append(_result) + _result = _all39 + _result = _before_discard38 + _all33.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice22 + self._pos = _choice37 break - _result = _all18 + _result = _all33 l = _result _call_status = self._commands() _result = _call_status.result @@ -901,8 +1081,8 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice17 - _choice26 = self._pos + self._pos = _choice32 + _choice41 = self._pos try: _call_status = self._commands() _result = _call_status.result @@ -910,7 +1090,7 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice26 + self._pos = _choice41 raise self._BacktrackException(_error) _call_status = self._commands() _result = _call_status.result @@ -949,9 +1129,10 @@ def commands(self): return self._commands().result def _commands(self): - _status = self._dict_commands.get(self._pos, None) + _key = self._pos + _status = self._dict_commands.get(_key, None) if _status is None: - _status = self._dict_commands[self._pos] = self._Status_commands() + _status = self._dict_commands[_key] = self._Status_commands() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -973,7 +1154,7 @@ _error = None while 1: _error = None - _choice27 = self._pos + _choice42 = self._pos try: _call_status = self._command() _result = _call_status.result @@ -982,40 +1163,40 @@ _call_status = self._newline() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all28 = [] + _all43 = [] _call_status = self._command() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard29 = _result + _before_discard44 = _result _call_status = self._newline() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _result = _before_discard29 - _all28.append(_result) + _result = _before_discard44 + _all43.append(_result) while 1: - _choice30 = self._pos + _choice45 = self._pos try: _call_status = self._command() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard31 = _result + _before_discard46 = _result _call_status = self._newline() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _result = _before_discard31 - _all28.append(_result) + _result = _before_discard46 + _all43.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice30 + self._pos = _choice45 break - _result = _all28 + _result = _all43 cmds = _result _result = (Nonterminal('commands', [cmd] + cmds)) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice27 - _choice32 = self._pos + self._pos = _choice42 + _choice47 = self._pos try: _call_status = self._command() _result = _call_status.result @@ -1023,7 +1204,7 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice32 + self._pos = _choice47 raise self._BacktrackException(_error) _call_status = self._command() _result = _call_status.result @@ -1062,9 +1243,10 @@ def command(self): return self._command().result def _command(self): - _status = self._dict_command.get(self._pos, None) + _key = self._pos + _status = self._dict_command.get(_key, None) if _status is None: - _status = self._dict_command[self._pos] = self._Status_command() + _status = self._dict_command[_key] = self._Status_command() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -1120,9 +1302,10 @@ def simplecommand(self): return self._simplecommand().result def _simplecommand(self): - _status = self._dict_simplecommand.get(self._pos, None) + _key = self._pos + _status = self._dict_simplecommand.get(_key, None) if _status is None: - _status = self._dict_simplecommand[self._pos] = self._Status_simplecommand() + _status = self._dict_simplecommand[_key] = self._Status_simplecommand() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -1144,7 +1327,7 @@ _error = None while 1: _error = None - _choice33 = self._pos + _choice48 = self._pos try: _call_status = self._return_() _result = _call_status.result @@ -1152,8 +1335,8 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice33 - _choice34 = self._pos + self._pos = _choice48 + _choice49 = self._pos try: _call_status = self._if_() _result = _call_status.result @@ -1161,8 +1344,8 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice34 - _choice35 = self._pos + self._pos = _choice49 + _choice50 = self._pos try: _call_status = self._named_command() _result = _call_status.result @@ -1170,8 +1353,8 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice35 - _choice36 = self._pos + self._pos = _choice50 + _choice51 = self._pos try: _call_status = self._repetition() _result = _call_status.result @@ -1179,8 +1362,8 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice36 - _choice37 = self._pos + self._pos = _choice51 + _choice52 = self._pos try: _call_status = self._negation() _result = _call_status.result @@ -1188,7 +1371,7 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice37 + self._pos = _choice52 raise self._BacktrackException(_error) _call_status = self._negation() _result = _call_status.result @@ -1227,9 +1410,10 @@ def return_(self): return self._return_().result def _return_(self): - _status = self._dict_return_.get(self._pos, None) + _key = self._pos + _status = self._dict_return_.get(_key, None) if _status is None: - _status = self._dict_return_[self._pos] = self._Status_return_() + _status = self._dict_return_[_key] = self._Status_return_() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -1250,36 +1434,36 @@ _result = None _error = None _result = self.__chars__('return') - _all38 = [] + _all53 = [] while 1: - _choice39 = self._pos + _choice54 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all38.append(_result) + _all53.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice39 + self._pos = _choice54 break - _result = _all38 + _result = _all53 _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) code = _result - _all40 = [] + _all55 = [] while 1: - _choice41 = self._pos + _choice56 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all40.append(_result) + _all55.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice41 + self._pos = _choice56 break - _result = _all40 + _result = _all55 _result = (Nonterminal('return', [code])) if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -1314,9 +1498,10 @@ def if_(self): return self._if_().result def _if_(self): - _status = self._dict_if_.get(self._pos, None) + _key = self._pos + _status = self._dict_if_.get(_key, None) if _status is None: - _status = self._dict_if_[self._pos] = self._Status_if_() + _status = self._dict_if_[_key] = self._Status_if_() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -1344,33 +1529,33 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) cmd = _result - _all42 = [] + _all57 = [] while 1: - _choice43 = self._pos + _choice58 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all42.append(_result) + _all57.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice43 + self._pos = _choice58 break - _result = _all42 + _result = _all57 _result = self.__chars__('if') - _all44 = [] + _all59 = [] while 1: - _choice45 = self._pos + _choice60 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all44.append(_result) + _all59.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice45 + self._pos = _choice60 break - _result = _all44 + _result = _all59 _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -1409,9 +1594,10 @@ def commandchain(self): return self._commandchain().result def _commandchain(self): - _status = self._dict_commandchain.get(self._pos, None) + _key = self._pos + _status = self._dict_commandchain.get(_key, None) if _status is None: - _status = self._dict_commandchain[self._pos] = self._Status_commandchain() + _status = self._dict_commandchain[_key] = self._Status_commandchain() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -1431,23 +1617,23 @@ try: _result = None _error = None - _all46 = [] + _all61 = [] _call_status = self._simplecommand() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all46.append(_result) + _all61.append(_result) while 1: - _choice47 = self._pos + _choice62 = self._pos try: _call_status = self._simplecommand() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all46.append(_result) + _all61.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice47 + self._pos = _choice62 break - _result = _all46 + _result = _all61 result = _result _result = (Nonterminal('commands', result)) if _status.status == _status.LEFTRECURSION: @@ -1483,9 +1669,10 @@ def named_command(self): return self._named_command().result def _named_command(self): - _status = self._dict_named_command.get(self._pos, None) + _key = self._pos + _status = self._dict_named_command.get(_key, None) if _status is None: - _status = self._dict_named_command[self._pos] = self._Status_named_command() + _status = self._dict_named_command[_key] = self._Status_named_command() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -1509,33 +1696,33 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) name = _result - _all48 = [] + _all63 = [] while 1: - _choice49 = self._pos + _choice64 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all48.append(_result) + _all63.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice49 + self._pos = _choice64 break - _result = _all48 + _result = _all63 _result = self.__chars__('=') - _all50 = [] + _all65 = [] while 1: - _choice51 = self._pos + _choice66 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all50.append(_result) + _all65.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice51 + self._pos = _choice66 break - _result = _all50 + _result = _all65 _call_status = self._command() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -1574,9 +1761,10 @@ def repetition(self): return self._repetition().result def _repetition(self): - _status = self._dict_repetition.get(self._pos, None) + _key = self._pos + _status = self._dict_repetition.get(_key, None) if _status is None: - _status = self._dict_repetition[self._pos] = self._Status_repetition() + _status = self._dict_repetition[_key] = self._Status_repetition() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -1598,152 +1786,152 @@ _error = None while 1: _error = None - _choice52 = self._pos + _choice67 = self._pos try: _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all53 = [] + _all68 = [] while 1: - _choice54 = self._pos + _choice69 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all53.append(_result) + _all68.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice54 + self._pos = _choice69 break - _result = _all53 + _result = _all68 _result = self.__chars__('?') - _all55 = [] + _all70 = [] while 1: - _choice56 = self._pos + _choice71 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all55.append(_result) + _all70.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice56 + self._pos = _choice71 break - _result = _all55 + _result = _all70 _result = (Nonterminal('maybe', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice52 - _choice57 = self._pos + self._pos = _choice67 + _choice72 = self._pos try: _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all58 = [] + _all73 = [] while 1: - _choice59 = self._pos + _choice74 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all58.append(_result) + _all73.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice59 + self._pos = _choice74 break - _result = _all58 + _result = _all73 while 1: _error = None - _choice60 = self._pos + _choice75 = self._pos try: _result = self.__chars__('*') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice60 - _choice61 = self._pos + self._pos = _choice75 + _choice76 = self._pos try: _result = self.__chars__('+') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice61 + self._pos = _choice76 raise self._BacktrackException(_error) _result = self.__chars__('+') break repetition = _result - _all62 = [] + _all77 = [] while 1: - _choice63 = self._pos + _choice78 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all62.append(_result) + _all77.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice63 + self._pos = _choice78 break - _result = _all62 + _result = _all77 _result = (Nonterminal('repetition', [repetition, what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice57 + self._pos = _choice72 raise self._BacktrackException(_error) _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all64 = [] + _all79 = [] while 1: - _choice65 = self._pos + _choice80 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all64.append(_result) + _all79.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice65 + self._pos = _choice80 break - _result = _all64 + _result = _all79 while 1: _error = None - _choice66 = self._pos + _choice81 = self._pos try: _result = self.__chars__('*') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice66 - _choice67 = self._pos + self._pos = _choice81 + _choice82 = self._pos try: _result = self.__chars__('+') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice67 + self._pos = _choice82 raise self._BacktrackException(_error) _result = self.__chars__('+') break repetition = _result - _all68 = [] + _all83 = [] while 1: - _choice69 = self._pos + _choice84 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all68.append(_result) + _all83.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice69 + self._pos = _choice84 break - _result = _all68 + _result = _all83 _result = (Nonterminal('repetition', [repetition, what])) break if _status.status == _status.LEFTRECURSION: @@ -1779,9 +1967,10 @@ def negation(self): return self._negation().result def _negation(self): - _status = self._dict_negation.get(self._pos, None) + _key = self._pos + _status = self._dict_negation.get(_key, None) if _status is None: - _status = self._dict_negation[self._pos] = self._Status_negation() + _status = self._dict_negation[_key] = self._Status_negation() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -1803,45 +1992,45 @@ _error = None while 1: _error = None - _choice70 = self._pos + _choice85 = self._pos try: _result = self.__chars__('!') - _all71 = [] + _all86 = [] while 1: - _choice72 = self._pos + _choice87 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all71.append(_result) + _all86.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice72 + self._pos = _choice87 break - _result = _all71 + _result = _all86 _call_status = self._negation() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all73 = [] + _all88 = [] while 1: - _choice74 = self._pos + _choice89 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all73.append(_result) + _all88.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice74 + self._pos = _choice89 break - _result = _all73 + _result = _all88 _result = (Nonterminal('negation', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice70 - _choice75 = self._pos + self._pos = _choice85 + _choice90 = self._pos try: _call_status = self._enclosed() _result = _call_status.result @@ -1849,7 +2038,7 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice75 + self._pos = _choice90 raise self._BacktrackException(_error) _call_status = self._enclosed() _result = _call_status.result @@ -1888,9 +2077,10 @@ def enclosed(self): return self._enclosed().result def _enclosed(self): - _status = self._dict_enclosed.get(self._pos, None) + _key = self._pos + _status = self._dict_enclosed.get(_key, None) if _status is None: - _status = self._dict_enclosed[self._pos] = self._Status_enclosed() + _status = self._dict_enclosed[_key] = self._Status_enclosed() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -1912,152 +2102,152 @@ _error = None while 1: _error = None - _choice76 = self._pos + _choice91 = self._pos try: _result = self.__chars__('<') - _all77 = [] + _all92 = [] while 1: - _choice78 = self._pos + _choice93 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all77.append(_result) + _all92.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice78 + self._pos = _choice93 break - _result = _all77 + _result = _all92 _call_status = self._primary() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all79 = [] + _all94 = [] while 1: - _choice80 = self._pos + _choice95 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all79.append(_result) + _all94.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice80 + self._pos = _choice95 break - _result = _all79 + _result = _all94 _result = self.__chars__('>') - _all81 = [] + _all96 = [] while 1: - _choice82 = self._pos + _choice97 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all81.append(_result) + _all96.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice82 + self._pos = _choice97 break - _result = _all81 + _result = _all96 _result = (Nonterminal('exclusive', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice76 - _choice83 = self._pos + self._pos = _choice91 + _choice98 = self._pos try: _result = self.__chars__('[') - _all84 = [] + _all99 = [] while 1: - _choice85 = self._pos + _choice100 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all84.append(_result) + _all99.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice85 + self._pos = _choice100 break - _result = _all84 + _result = _all99 _call_status = self._or_() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all86 = [] + _all101 = [] while 1: - _choice87 = self._pos + _choice102 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all86.append(_result) + _all101.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice87 + self._pos = _choice102 break - _result = _all86 + _result = _all101 _result = self.__chars__(']') - _all88 = [] + _all103 = [] while 1: - _choice89 = self._pos + _choice104 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all88.append(_result) + _all103.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice89 + self._pos = _choice104 break - _result = _all88 + _result = _all103 _result = (Nonterminal('ignore', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice83 - _choice90 = self._pos + self._pos = _choice98 + _choice105 = self._pos try: - _before_discard91 = _result + _before_discard106 = _result _result = self.__chars__('(') - _all92 = [] + _all107 = [] while 1: - _choice93 = self._pos + _choice108 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all92.append(_result) + _all107.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice93 + self._pos = _choice108 break - _result = _all92 - _result = _before_discard91 + _result = _all107 + _result = _before_discard106 _call_status = self._or_() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard94 = _result + _before_discard109 = _result _result = self.__chars__(')') - _all95 = [] + _all110 = [] while 1: - _choice96 = self._pos + _choice111 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all95.append(_result) + _all110.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice96 + self._pos = _choice111 break - _result = _all95 - _result = _before_discard94 + _result = _all110 + _result = _before_discard109 break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice90 - _choice97 = self._pos + self._pos = _choice105 + _choice112 = self._pos try: _call_status = self._primary() _result = _call_status.result @@ -2065,7 +2255,7 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice97 + self._pos = _choice112 raise self._BacktrackException(_error) _call_status = self._primary() _result = _call_status.result @@ -2104,9 +2294,10 @@ def primary(self): return self._primary().result def _primary(self): - _status = self._dict_primary.get(self._pos, None) + _key = self._pos + _status = self._dict_primary.get(_key, None) if _status is None: - _status = self._dict_primary[self._pos] = self._Status_primary() + _status = self._dict_primary[_key] = self._Status_primary() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -2128,7 +2319,7 @@ _error = None while 1: _error = None - _choice98 = self._pos + _choice113 = self._pos try: _call_status = self._call() _result = _call_status.result @@ -2136,74 +2327,74 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice98 - _choice99 = self._pos + self._pos = _choice113 + _choice114 = self._pos try: _call_status = self._REGEX() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard100 = _result - _all101 = [] + _before_discard115 = _result + _all116 = [] while 1: - _choice102 = self._pos + _choice117 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all101.append(_result) + _all116.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice102 + self._pos = _choice117 break - _result = _all101 - _result = _before_discard100 + _result = _all116 + _result = _before_discard115 break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice99 - _choice103 = self._pos + self._pos = _choice114 + _choice118 = self._pos try: _call_status = self._QUOTE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard104 = _result - _all105 = [] + _before_discard119 = _result + _all120 = [] while 1: - _choice106 = self._pos + _choice121 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all105.append(_result) + _all120.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice106 + self._pos = _choice121 break - _result = _all105 - _result = _before_discard104 + _result = _all120 + _result = _before_discard119 break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice103 + self._pos = _choice118 raise self._BacktrackException(_error) _call_status = self._QUOTE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard107 = _result - _all108 = [] + _before_discard122 = _result + _all123 = [] while 1: - _choice109 = self._pos + _choice124 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all108.append(_result) + _all123.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice109 + self._pos = _choice124 break - _result = _all108 - _result = _before_discard107 + _result = _all123 + _result = _before_discard122 break if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -2238,9 +2429,10 @@ def call(self): return self._call().result def _call(self): - _status = self._dict_call.get(self._pos, None) + _key = self._pos + _status = self._dict_call.get(_key, None) if _status is None: - _status = self._dict_call[self._pos] = self._Status_call() + _status = self._dict_call[_key] = self._Status_call() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status @@ -2264,20 +2456,24 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) x = _result - _all110 = [] + _call_status = self._arguments() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + args = _result + _all125 = [] while 1: - _choice111 = self._pos + _choice126 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all110.append(_result) + _all125.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice111 + self._pos = _choice126 break - _result = _all110 - _result = (Nonterminal("call", [x])) + _result = _all125 + _result = (Nonterminal("call", [x, args])) if _status.status == _status.LEFTRECURSION: if _status.result is not None: if _status.pos >= self._pos: @@ -2302,6 +2498,156 @@ _status.error = _error _status.status = _status.ERROR raise self._BacktrackException(_error) + class _Status_arguments(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def arguments(self): + return self._arguments().result + def _arguments(self): + _key = self._pos + _status = self._dict_arguments.get(_key, None) + if _status is None: + _status = self._dict_arguments[_key] = self._Status_arguments() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + while 1: + _error = None + _choice127 = self._pos + try: + _result = self.__chars__('(') + _all128 = [] + while 1: + _choice129 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all128.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice129 + break + _result = _all128 + _all130 = [] + while 1: + _choice131 = self._pos + try: + _call_status = self._PYTHONCODE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _before_discard132 = _result + _all133 = [] + while 1: + _choice134 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all133.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice134 + break + _result = _all133 + _result = self.__chars__(',') + _all135 = [] + while 1: + _choice136 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all135.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice136 + break + _result = _all135 + _result = _before_discard132 + _all130.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice131 + break + _result = _all130 + args = _result + _call_status = self._PYTHONCODE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + last = _result + _result = self.__chars__(')') + _all137 = [] + while 1: + _choice138 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all137.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice138 + break + _result = _all137 + _result = (Nonterminal("args", args + [last])) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice127 + _choice139 = self._pos + try: + _result = (Nonterminal("args", [])) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice139 + raise self._BacktrackException(_error) + _result = (Nonterminal("args", [])) + break + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._arguments() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) def __init__(self, inputstream): self._dict_NAME = {} self._dict_SPACE = {} @@ -2315,6 +2661,7 @@ self._dict_file = {} self._dict_list = {} self._dict_production = {} + self._dict_productionargs = {} self._dict_or_ = {} self._dict_commands = {} self._dict_command = {} @@ -2328,80 +2675,81 @@ self._dict_enclosed = {} self._dict_primary = {} self._dict_call = {} + self._dict_arguments = {} self._pos = 0 self._inputstream = inputstream def _regex299149370(self): - _choice112 = self._pos + _choice140 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_299149370(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice112 + self._pos = _choice140 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1006631623(self): - _choice113 = self._pos + _choice141 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1006631623(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice113 + self._pos = _choice141 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex528667127(self): - _choice114 = self._pos + _choice142 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_528667127(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice114 + self._pos = _choice142 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex291086639(self): - _choice115 = self._pos + _choice143 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_291086639(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice115 + self._pos = _choice143 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1074651696(self): - _choice116 = self._pos + _choice144 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1074651696(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice116 + self._pos = _choice144 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1124192327(self): - _choice117 = self._pos + _choice145 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1124192327(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice117 + self._pos = _choice145 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1979538501(self): - _choice118 = self._pos + _choice146 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1979538501(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice118 + self._pos = _choice146 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] @@ -2428,38 +2776,37 @@ else: runner.state = 0 return i - if char == '\n': + if char == ' ': state = 1 - elif char == ' ': + elif char == '\n': state = 2 else: break if state == 1: - runner.last_matched_index = i - 1 - runner.last_matched_state = state if i < len(input): char = input[i] i += 1 else: runner.state = 1 - return i - if char == '\n': - state = 1 - continue - elif char == ' ': + return ~i + if char == ' ': state = 1 continue + elif char == '\n': + state = 2 else: break if state == 2: + runner.last_matched_index = i - 1 + runner.last_matched_state = state if i < len(input): char = input[i] i += 1 else: runner.state = 2 - return ~i + return i if char == '\n': - state = 1 + state = 2 continue elif char == ' ': state = 2 @@ -2489,40 +2836,40 @@ runner.state = 0 return ~i if char == '`': - state = 3 + state = 1 else: break - if state == 2: + if state == 1: if i < len(input): char = input[i] i += 1 else: - runner.state = 2 + runner.state = 1 return ~i - if '\x00' <= char <= '\xff': + if '\x00' <= char <= '[': + state = 1 + continue + elif ']' <= char <= '_': + state = 1 + continue + elif 'a' <= char <= '\xff': + state = 1 + continue + elif char == '\\': + state = 2 + elif char == '`': state = 3 else: break - if state == 3: + if state == 2: if i < len(input): char = input[i] i += 1 else: - runner.state = 3 + runner.state = 2 return ~i - if char == '`': + if '\x00' <= char <= '\xff': state = 1 - elif char == '\\': - state = 2 - continue - elif '\x00' <= char <= '[': - state = 3 - continue - elif ']' <= char <= '_': - state = 3 - continue - elif 'a' <= char <= '\xff': - state = 3 continue else: break @@ -2552,40 +2899,40 @@ state = 0 continue elif char == '#': - state = 2 + state = 1 else: break if state == 1: - runner.last_matched_index = i - 1 - runner.last_matched_state = state if i < len(input): char = input[i] i += 1 else: runner.state = 1 - return i - if char == ' ': - state = 0 + return ~i + if '\x00' <= char <= '\t': + state = 1 continue - elif char == '#': + elif '\x0b' <= char <= '\xff': + state = 1 + continue + elif char == '\n': state = 2 else: break if state == 2: + runner.last_matched_index = i - 1 + runner.last_matched_state = state if i < len(input): char = input[i] i += 1 else: runner.state = 2 - return ~i - if char == '\n': - state = 1 - continue - elif '\x00' <= char <= '\t': - state = 2 + return i + if char == ' ': + state = 0 continue - elif '\x0b' <= char <= '\xff': - state = 2 + elif char == '#': + state = 1 continue else: break @@ -2612,27 +2959,27 @@ runner.state = 0 return ~i if char == '{': - state = 2 + state = 1 else: break - if state == 2: + if state == 1: if i < len(input): char = input[i] i += 1 else: - runner.state = 2 + runner.state = 1 return ~i - if char == '}': + if '\x00' <= char <= '\t': state = 1 - elif '\x00' <= char <= '\t': - state = 2 continue elif '\x0b' <= char <= '|': - state = 2 + state = 1 continue elif '~' <= char <= '\xff': - state = 2 + state = 1 continue + elif char == '}': + state = 2 else: break runner.last_matched_state = state Modified: pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Sat Jun 23 12:10:27 2007 @@ -354,3 +354,34 @@ assert excinfo.value.error.pos == 0 assert excinfo.value.error.expected == ['condition not met'] + def test_parse_arguments(self): + class parser(PackratParser): + """ + between(a, b): + do + c = __any__ + if {ord(a) <= ord(c) <= ord(b)} + return {c}; + + small_big_small: + x = between({'a'}, {'z'})+ + y = between({'A'}, {'Z'})+ + z = between({'a'}, {'z'})+ + return {"".join(x) + "".join(y) + "".join(z)}; + """ + p = parser('abc') + c = p.between('a', 'z') + assert c == 'a' + p._pos = 0 + c = p.between('a', 'z') + assert c == 'a' + excinfo = py.test.raises(BacktrackException, p.between, 'A', 'Z') + assert excinfo.value.error.pos == 1 + assert excinfo.value.error.expected == ['condition not met'] + p = parser('aBc') + res = p.small_big_small() + assert res == 'aBc' + p = parser('aaaaarstawfpacawBAAAFPAcccfafp') + res = p.small_big_small() + assert res == 'aaaaarstawfpacawBAAAFPAcccfafp' + From cfbolz at codespeak.net Sat Jun 23 12:21:30 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sat, 23 Jun 2007 12:21:30 +0200 (CEST) Subject: [pypy-svn] r44469 - pypy/dist/pypy/rlib/parsing Message-ID: <20070623102130.29C2C8152@code0.codespeak.net> Author: cfbolz Date: Sat Jun 23 12:21:29 2007 New Revision: 44469 Modified: pypy/dist/pypy/rlib/parsing/deterministic.py Log: make the code generation for regular expressions deterministic to prevent superfluous diffs to autogenerated (but checked in) code. Modified: pypy/dist/pypy/rlib/parsing/deterministic.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/deterministic.py (original) +++ pypy/dist/pypy/rlib/parsing/deterministic.py Sat Jun 23 12:21:29 2007 @@ -267,8 +267,10 @@ state_to_chars = {} for (state, char), nextstate in self.transitions.iteritems(): state_to_chars.setdefault(state, {}).setdefault(nextstate, set()).add(char) + state_to_chars_sorted = state_to_chars.items() + state_to_chars_sorted.sort() above = set() - for state, nextstates in state_to_chars.iteritems(): + for state, nextstates in state_to_chars: above.add(state) result.append(" if state == %s:" % (state, )) if state in self.final_states: From cfbolz at codespeak.net Sat Jun 23 12:24:00 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sat, 23 Jun 2007 12:24:00 +0200 (CEST) Subject: [pypy-svn] r44470 - pypy/dist/pypy/rlib/parsing Message-ID: <20070623102400.20C968152@code0.codespeak.net> Author: cfbolz Date: Sat Jun 23 12:23:59 2007 New Revision: 44470 Modified: pypy/dist/pypy/rlib/parsing/deterministic.py Log: ehem Modified: pypy/dist/pypy/rlib/parsing/deterministic.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/deterministic.py (original) +++ pypy/dist/pypy/rlib/parsing/deterministic.py Sat Jun 23 12:23:59 2007 @@ -270,7 +270,7 @@ state_to_chars_sorted = state_to_chars.items() state_to_chars_sorted.sort() above = set() - for state, nextstates in state_to_chars: + for state, nextstates in state_to_chars_sorted: above.add(state) result.append(" if state == %s:" % (state, )) if state in self.final_states: From jlg at codespeak.net Sat Jun 23 14:08:32 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Sat, 23 Jun 2007 14:08:32 +0200 (CEST) Subject: [pypy-svn] r44471 - pypy/dist/pypy/lang/scheme Message-ID: <20070623120832.748DA8158@code0.codespeak.net> Author: jlg Date: Sat Jun 23 14:08:30 2007 New Revision: 44471 Modified: pypy/dist/pypy/lang/scheme/TODO.txt pypy/dist/pypy/lang/scheme/object.py Log: nested s-expr evalutaion test added Modified: pypy/dist/pypy/lang/scheme/TODO.txt ============================================================================== --- pypy/dist/pypy/lang/scheme/TODO.txt (original) +++ pypy/dist/pypy/lang/scheme/TODO.txt Sat Jun 23 14:08:30 2007 @@ -3,10 +3,9 @@ - evaluate simple expressions like (* 6 7) or even (+ 1 2 3 4) - - convert nodes from AST tree into W_xxx - tree.dispatch() - - evaluate the tree + - parsing is done by some shiny new Carl's thingy W_xxx object like W_Fixnum should eval to itself despite context - - implement basic operations like * / and so on + - implement basic operations like + * / and so on Do next ------- Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Sat Jun 23 14:08:30 2007 @@ -128,7 +128,6 @@ #not sure though any operations should exist here #it its very similar to operation.add ############################# - def add_lst(ctx, lst): return apply_lst(ctx, lambda x, y: x + y, lst) @@ -155,8 +154,15 @@ else: return W_Float(acc) +###################################### +# dict mapping operations to callables +# callables must have 2 arguments +# - ctx = execution context +# - lst = list of arguments +####################################### OPERATION_MAP = \ { '+': add_lst, '*': mul_lst, } + From jlg at codespeak.net Sat Jun 23 14:09:40 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Sat, 23 Jun 2007 14:09:40 +0200 (CEST) Subject: [pypy-svn] r44472 - pypy/dist/pypy/lang/scheme/test Message-ID: <20070623120940.BAFE48158@code0.codespeak.net> Author: jlg Date: Sat Jun 23 14:09:40 2007 New Revision: 44472 Added: pypy/dist/pypy/lang/scheme/test/test_eval.py (contents, props changed) Log: test_eval added Added: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Sat Jun 23 14:09:40 2007 @@ -0,0 +1,55 @@ +from pypy.lang.scheme.ssparser import parse +from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_Float, W_String +from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Symbol +from pypy.lang.scheme.operation import mul, add + +def test_operations_simple(): + w_num1 = W_Fixnum(4) + w_num2 = W_Fixnum(5) + w_num3 = W_Float(6.1) + + w_num = mul(None, [w_num1]) + assert w_num.to_number() == w_num1.to_number() + w_num = mul(None, [w_num1, w_num2]) + assert w_num.to_number() == w_num1.to_number() * w_num2.to_number() + w_num = mul(None, [w_num1, w_num2, w_num3]) + assert w_num.to_number() == (w_num1.to_number() * w_num2.to_number() + * w_num3.to_number()) + + w_num = add(None, [w_num1]) + assert w_num.to_number() == w_num1.to_number() + w_num = add(None, [w_num1, w_num2]) + assert w_num.to_number() == w_num1.to_number() + w_num2.to_number() + w_num = add(None, [w_num1, w_num2, w_num3]) + assert w_num.to_number() == (w_num1.to_number() + w_num2.to_number() + + w_num3.to_number()) + +def test_eval_obj(): + w_num = W_Pair(W_Symbol("+"), + W_Pair(W_Fixnum(4), W_Pair(W_Fixnum(5), W_Nil()))) + assert w_num.eval(None).to_number() == 9 + +def eval_expr(ctx, expr): + return parse(expr).eval(ctx) + +def eval_noctx(expr): + return parse(expr).eval(None) + +def test_eval_simple(): + w_num = eval_noctx('(+ 4)') + assert w_num.to_number() == 4 + w_num = eval_noctx('(+ 4 5)') + assert w_num.to_number() == 9 + w_num = eval_noctx('(+ 4 5 6)') + assert w_num.to_number() == 15 + + w_num = eval_noctx('(* 4)') + assert w_num.to_number() == 4 + w_num = eval_noctx('(* 4 5)') + assert w_num.to_number() == 20 + w_num = eval_noctx('(* 4 5 6)') + assert w_num.to_number() == (4 * 5 * 6) + +def test_eval_nested(): + w_num = eval_noctx('(+ 4 (* (+ 5) 6) (+ 1 2))') + assert w_num.to_number() == 37 From antocuni at codespeak.net Sat Jun 23 16:41:44 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 23 Jun 2007 16:41:44 +0200 (CEST) Subject: [pypy-svn] r44474 - in pypy/dist/pypy: objspace/flow translator/backendopt translator/backendopt/test Message-ID: <20070623144144.D8D308131@code0.codespeak.net> Author: antocuni Date: Sat Jun 23 16:41:43 2007 New Revision: 44474 Modified: pypy/dist/pypy/objspace/flow/model.py pypy/dist/pypy/translator/backendopt/inline.py pypy/dist/pypy/translator/backendopt/test/test_inline.py Log: - add a comment for the new check in checkgraph - add a new test that really showed the problem - fix it by inserting an ooupcast when needed Modified: pypy/dist/pypy/objspace/flow/model.py ============================================================================== --- pypy/dist/pypy/objspace/flow/model.py (original) +++ pypy/dist/pypy/objspace/flow/model.py Sat Jun 23 16:41:43 2007 @@ -663,9 +663,15 @@ for link in block.exits: assert len(link.args) == len(link.target.inputargs) assert link.prevblock is block + + # checking for exact types is not strictly necessary + # for ootype, because upcasting could be implicit, but + # forcing them to be explicit makes the life of other + # parts of the toolchain much easier for linkv, inputv in zip(link.args, link.target.inputargs): if hasattr(linkv, 'concretetype') and hasattr(inputv, 'concretetype'): assert linkv.concretetype == inputv.concretetype + exc_link = link in exc_links if exc_link: for v in [link.last_exception, link.last_exc_value]: Modified: pypy/dist/pypy/translator/backendopt/inline.py ============================================================================== --- pypy/dist/pypy/translator/backendopt/inline.py (original) +++ pypy/dist/pypy/translator/backendopt/inline.py Sat Jun 23 16:41:43 2007 @@ -431,7 +431,6 @@ copiedexceptblock.recloseblock(Link(linkargs, blocks[0])) copiedexceptblock.operations += self.generate_keepalive(linkargs) - def do_inline(self, block, index_operation): splitlink = split_block_with_keepalive(block, index_operation) afterblock = splitlink.target @@ -460,6 +459,23 @@ index = afterblock.inputargs.index(arg) passon_args.append(linktoinlined.args[index]) passon_args += self.original_passon_vars + + if self.op.opname == 'oosend' and not isinstance(self.op.args[1], Constant): + # if we try to inline a graph defined in a superclass, the + # type of 'self' on the graph differs from the current + linkv = passon_args[0] + inputv = copiedstartblock.inputargs[0] + LINK_SELF = linkv.concretetype + INPUT_SELF = inputv.concretetype + if LINK_SELF != INPUT_SELF: + # need to insert an upcast + assert ootype.isSubclass(LINK_SELF, INPUT_SELF) + v = Variable() + v.concretetype = INPUT_SELF + upcast = SpaceOperation('ooupcast', [linkv], v) + block.operations.append(upcast) + passon_args[0] = v + #rewire blocks linktoinlined.target = copiedstartblock linktoinlined.args = passon_args Modified: pypy/dist/pypy/translator/backendopt/test/test_inline.py ============================================================================== --- pypy/dist/pypy/translator/backendopt/test/test_inline.py (original) +++ pypy/dist/pypy/translator/backendopt/test/test_inline.py Sat Jun 23 16:41:43 2007 @@ -17,7 +17,7 @@ from pypy.translator.test.snippet import is_perfect_number from pypy.translator.backendopt.all import INLINE_THRESHOLD_FOR_TEST from pypy.conftest import option - +from pypy.translator.backendopt import removenoops def no_missing_concretetype(node): if isinstance(node, Block): @@ -87,7 +87,7 @@ return eval_func def check_auto_inlining(self, func, sig, multiplier=None, call_count_check=False, - checkvirtual=False): + checkvirtual=False, remove_same_as=False): t = self.translate(func, sig) if checkvirtual: check_virtual_methods() @@ -105,6 +105,10 @@ call_count_pred = lambda lbl: True instrument_inline_candidates(t.graphs, threshold) + if remove_same_as: + for graph in t.graphs: + removenoops.remove_same_as(graph) + auto_inlining(t, threshold, call_count_pred=call_count_pred) sanity_check(t) @@ -639,25 +643,41 @@ assert res == expected def test_oosend_inherited(self): - py.test.skip('fixme, this prevents pypy-cli from being built') - class A: - def bar(self, x): - return x - class B(A): - def foo(self, x): - return self.bar(x) - class C(A): + class BaseStringFormatter: + def __init__(self): + self.fmtpos = 0 + def forward(self): + self.fmtpos += 1 + + class StringFormatter(BaseStringFormatter): + def __init__(self, fmt): + BaseStringFormatter.__init__(self) + self.fmt = fmt + def peekchr(self): + return self.fmt[self.fmtpos] + def peel_num(self): + while True: + self.forward() + c = self.peekchr() + if self.fmtpos == 2: break + return 0 + + class UnicodeStringFormatter(BaseStringFormatter): pass + def fn(x): if x: - b_obj = B() - return b_obj.foo(x) + fmt = StringFormatter('foo') + return fmt.peel_num() else: - c_obj = C() - return c_obj.bar(x) - eval_func, t = self.check_auto_inlining(fn, [int], checkvirtual=True) - expected = fn(42) - res = eval_func([42]) + dummy = UnicodeStringFormatter() + dummy.forward() + return 0 + + eval_func, t = self.check_auto_inlining(fn, [int], checkvirtual=True, + remove_same_as=True) + expected = fn(1) + res = eval_func([1]) assert res == expected def test_classattr(self): From tismer at codespeak.net Sat Jun 23 18:05:57 2007 From: tismer at codespeak.net (tismer at codespeak.net) Date: Sat, 23 Jun 2007 18:05:57 +0200 (CEST) Subject: [pypy-svn] r44475 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070623160557.90FBC8095@code0.codespeak.net> Author: tismer Date: Sat Jun 23 18:05:56 2007 New Revision: 44475 Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt Log: added my itinerary Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/people.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/people.txt Sat Jun 23 18:05:56 2007 @@ -17,6 +17,7 @@ Laura Creighton 7/14th Ratonda Centrum Hotels Jacob Hallen 7/14th Ratonda Centrum Hotels Jakub Gustak 8/15th Hospitality Club :) +Christian Tismer 8/16th Ratonda Centrum Hotels ==================== ============== ======================= People on the following list were present at previous sprints: From antocuni at codespeak.net Sun Jun 24 15:45:55 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sun, 24 Jun 2007 15:45:55 +0200 (CEST) Subject: [pypy-svn] r44481 - pypy/dist/pypy/objspace/flow Message-ID: <20070624134555.498C68124@code0.codespeak.net> Author: antocuni Date: Sun Jun 24 15:45:54 2007 New Revision: 44481 Modified: pypy/dist/pypy/objspace/flow/model.py Log: this condition is too strict to be easly enforced. The comment says the false, It's easier to fix the rest of the toolchain. Modified: pypy/dist/pypy/objspace/flow/model.py ============================================================================== --- pypy/dist/pypy/objspace/flow/model.py (original) +++ pypy/dist/pypy/objspace/flow/model.py Sun Jun 24 15:45:54 2007 @@ -663,15 +663,6 @@ for link in block.exits: assert len(link.args) == len(link.target.inputargs) assert link.prevblock is block - - # checking for exact types is not strictly necessary - # for ootype, because upcasting could be implicit, but - # forcing them to be explicit makes the life of other - # parts of the toolchain much easier - for linkv, inputv in zip(link.args, link.target.inputargs): - if hasattr(linkv, 'concretetype') and hasattr(inputv, 'concretetype'): - assert linkv.concretetype == inputv.concretetype - exc_link = link in exc_links if exc_link: for v in [link.last_exception, link.last_exc_value]: From antocuni at codespeak.net Sun Jun 24 16:35:59 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sun, 24 Jun 2007 16:35:59 +0200 (CEST) Subject: [pypy-svn] r44482 - in pypy/dist/pypy: config rpython/ootypesystem rpython/ootypesystem/test Message-ID: <20070624143559.16D4C8122@code0.codespeak.net> Author: antocuni Date: Sun Jun 24 16:35:58 2007 New Revision: 44482 Modified: pypy/dist/pypy/config/translationoption.py pypy/dist/pypy/rpython/ootypesystem/rclass.py pypy/dist/pypy/rpython/ootypesystem/rpbc.py pypy/dist/pypy/rpython/ootypesystem/test/test_oortype.py Log: new translation option that makes ootype not to mangle the names of the attributes. Might be useful for a general purpose rpython-compiler. Modified: pypy/dist/pypy/config/translationoption.py ============================================================================== --- pypy/dist/pypy/config/translationoption.py (original) +++ pypy/dist/pypy/config/translationoption.py Sun Jun 24 16:35:58 2007 @@ -104,6 +104,11 @@ "hintannotate", "timeshift"], default=None, cmdline="--fork-before"), + # options for ootype + OptionDescription("ootype", "Object Oriented Typesystem options", [ + BoolOption("mangle", "Mangle names of class members", default=True), + ]), + OptionDescription("backendopt", "Backend Optimization Options", [ # control inlining BoolOption("inline", "Do basic inlining and malloc removal", Modified: pypy/dist/pypy/rpython/ootypesystem/rclass.py ============================================================================== --- pypy/dist/pypy/rpython/ootypesystem/rclass.py (original) +++ pypy/dist/pypy/rpython/ootypesystem/rclass.py Sun Jun 24 16:35:58 2007 @@ -137,15 +137,23 @@ # ____________________________________________________________ -def mangle(name): +def mangle(name, config): # XXX temporary: for now it looks like a good idea to mangle names # systematically to trap bugs related to a confusion between mangled # and non-mangled names - return 'o' + name - -def unmangle(mangled): - assert mangled.startswith('o') - return mangled[1:] + if config.translation.ootype.mangle: + return 'o' + name + else: + not_allowed = ('_hash_cache_', 'meta', 'class_') + assert name not in not_allowed, "%s is a reserved name" % name + return name + +def unmangle(mangled, config): + if config.translation.ootype.mangle: + assert mangled.startswith('o') + return mangled[1:] + else: + return mangled class InstanceRepr(AbstractInstanceRepr): def __init__(self, rtyper, classdef, gcflavor='ignored'): @@ -194,7 +202,7 @@ selfattrs = self.classdef.attrs for name, attrdef in selfattrs.iteritems(): - mangled = mangle(name) + mangled = mangle(name, self.rtyper.getconfig()) if not attrdef.readonly: repr = self.rtyper.getrepr(attrdef.s_value) allfields[mangled] = repr @@ -226,7 +234,7 @@ s_meth = self.classdef.classdesc.s_get_value(self.classdef, meth_name) if isinstance(s_meth, annmodel.SomePBC): - mangled = mangle(meth_name) + mangled = mangle(meth_name, self.rtyper.getconfig()) allmethods[mangled] = meth_name, s_meth # else: it's the __init__ of a builtin exception @@ -279,7 +287,7 @@ for name, attrdef in classdef.attrs.iteritems(): if not attrdef.readonly: continue - mangled = mangle(name) + mangled = mangle(name, self.rtyper.getconfig()) if mangled in allclassattributes: selfdesc = self.classdef.classdesc if name not in selfattrs: @@ -297,7 +305,7 @@ # a non-method class attribute if not attrdef.s_value.is_constant(): classattributes[mangled] = attrdef.s_value, value - + ootype.addMethods(self.lowleveltype, methods) self.allfields = allfields @@ -344,7 +352,7 @@ # about it repr = self.rtyper.getrepr(attrdef.s_value) oot = repr.lowleveltype - mangled = mangle(name) + mangled = mangle(name, self.rtyper.getconfig()) value = self.classdef.classdesc.read_attribute(name) default = repr.convert_desc_or_const(value) overridden_defaults[mangled] = oot, default @@ -375,7 +383,7 @@ v_inst, _ = hop.inputargs(self, ootype.Void) s_inst = hop.args_s[0] attr = hop.args_s[1].const - mangled = mangle(attr) + mangled = mangle(attr, self.rtyper.getconfig()) v_attr = hop.inputconst(ootype.Void, mangled) if mangled in self.allfields: # regular instance attributes @@ -409,7 +417,7 @@ def rtype_setattr(self, hop): attr = hop.args_s[1].const - mangled = mangle(attr) + mangled = mangle(attr, self.rtyper.getconfig()) self.lowleveltype._check_field(mangled) r_value = self.allfields[mangled] v_inst, _, v_newval = hop.inputargs(self, ootype.Void, r_value) @@ -420,7 +428,7 @@ # this method emulates behaviour from the corresponding # lltypesystem one. It is referenced in some obscure corners # like rtyping of OSError. - mangled_name = mangle(attr) + mangled_name = mangle(attr, self.rtyper.getconfig()) cname = inputconst(ootype.Void, mangled_name) llops.genop('oosetfield', [vinst, cname, vvalue]) @@ -476,7 +484,7 @@ elif mangled == '_hash_cache_': # hash() support llattrvalue = hash(value) else: - name = unmangle(mangled) + name = unmangle(mangled, self.rtyper.getconfig()) try: attrvalue = getattr(value, name) except AttributeError: Modified: pypy/dist/pypy/rpython/ootypesystem/rpbc.py ============================================================================== --- pypy/dist/pypy/rpython/ootypesystem/rpbc.py (original) +++ pypy/dist/pypy/rpython/ootypesystem/rpbc.py Sun Jun 24 16:35:58 2007 @@ -149,7 +149,7 @@ def _get_method_name(self, opname, s_pbc, args_s): shape, index, callfamily = self._get_shape_index_callfamily(opname, s_pbc, args_s) - mangled = mangle(self.methodname) + mangled = mangle(self.methodname, self.rtyper.getconfig()) row = self.concretetable[shape, index] derived_mangled = row_method_name(mangled, row.attrname) return derived_mangled Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_oortype.py ============================================================================== --- pypy/dist/pypy/rpython/ootypesystem/test/test_oortype.py (original) +++ pypy/dist/pypy/rpython/ootypesystem/test/test_oortype.py Sun Jun 24 16:35:58 2007 @@ -1,3 +1,4 @@ +import py from pypy import conftest from pypy.rpython.ootypesystem.ootype import * from pypy.rpython.ootypesystem import ootype @@ -10,8 +11,9 @@ from pypy.rlib.objectmodel import r_dict from pypy.rpython.ootypesystem import ooregistry # side effects -def gengraph(f, args=[], viewBefore=False, viewAfter=False): +def gengraph(f, args=[], viewBefore=False, viewAfter=False, mangle=True): t = TranslationContext() + t.config.translation.ootype.mangle = mangle t.buildannotator().build_types(f, args) if viewBefore or conftest.option.view: t.view() @@ -268,3 +270,21 @@ d['x'] = 42 return d['x'] assert interpret(oof, [], type_system='ootype') == 42 + +def test_not_mangle_attrs(): + class Foo: + def __init__(self): + self.x = 42 + def fn(): + return Foo() + + graph = gengraph(fn, mangle=False) + FOO = graph.getreturnvar().concretetype + assert FOO._fields.keys() == ['x'] + + class Bar: + def __init__(self): + self.meta = 42 + def fn(): + return Bar() + py.test.raises(AssertionError, gengraph, fn, mangle=False) From jlg at codespeak.net Mon Jun 25 12:43:52 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Mon, 25 Jun 2007 12:43:52 +0200 (CEST) Subject: [pypy-svn] r44503 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070625104352.B883E80CF@code0.codespeak.net> Author: jlg Date: Mon Jun 25 12:43:51 2007 New Revision: 44503 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/ssparser.py pypy/dist/pypy/lang/scheme/test/test_parser.py Log: parsing of negative numbers and floats Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Mon Jun 25 12:43:51 2007 @@ -43,13 +43,11 @@ return "" def eval(self, ctx): - # should be -> get form ctx dict the right method try: return OPERATION_MAP[self.name] except KeyError: raise NotImplementedError - class W_Boolean(W_Root): def __init__(self, val): self.boolval = bool(val) Modified: pypy/dist/pypy/lang/scheme/ssparser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/ssparser.py (original) +++ pypy/dist/pypy/lang/scheme/ssparser.py Mon Jun 25 12:43:51 2007 @@ -1,9 +1,7 @@ import autopath from pypy.rlib.parsing.pypackrat import PackratParser from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Symbol -from pypy.lang.scheme.object import W_Nil, W_Boolean - -DEBUG = False +from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Float def unquote(s): return s.replace('\\"', '"') @@ -21,9 +19,14 @@ return {W_Symbol(c)}; FIXNUM: - c = `0|([1-9][0-9]*)` + c = `\-?(0|([1-9][0-9]*))` + IGNORE* + return {W_Fixnum(c)}; + + FLOAT: + c = `\-?[0-9]*\.[0-9]*` IGNORE* - return {W_Fixnum(int(c))}; + return {W_Float(c)}; BOOLEAN: c = `#(t|f)` @@ -44,6 +47,7 @@ sexpr: list + | FLOAT | FIXNUM | BOOLEAN | IDENTIFIER Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Mon Jun 25 12:43:51 2007 @@ -1,10 +1,13 @@ +import py from pypy.lang.scheme.ssparser import parse from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Symbol -from pypy.lang.scheme.object import W_Nil, W_Boolean +from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Float def unwrap(w_obj): """for testing purposes: unwrap a scheme object into a python object""" - if isinstance(w_obj, W_Fixnum): + if isinstance(w_obj, W_Float): + return w_obj.to_number() + elif isinstance(w_obj, W_Fixnum): return w_obj.to_number() elif isinstance(w_obj, W_String): return w_obj.strval @@ -21,23 +24,37 @@ raise NotImplementedError("don't know what to do with: %s" % (w_obj, )) def test_simple(): - w_fixnum = parse(r'''1''') + w_fixnum = parse('1') assert isinstance(w_fixnum, W_Fixnum) assert unwrap(w_fixnum) == 1 - w_fixnum = parse(r'''0''') + w_fixnum = parse('0') assert unwrap(w_fixnum) == 0 assert isinstance(w_fixnum, W_Fixnum) - w_fixnum = parse(r'''1123''') + w_fixnum = parse('1123') assert unwrap(w_fixnum) == 1123 assert isinstance(w_fixnum, W_Fixnum) - w_fixnum = parse(r'''abfa__''') - assert isinstance(w_fixnum, W_Symbol) - w_fixnum = parse(r'''+''') + w_fixnum = parse('abfa__') assert isinstance(w_fixnum, W_Symbol) t = parse(r'''"don't believe \"them\""''') assert isinstance(t, W_String) assert unwrap(t) == 'don\'t believe "them"' - w_list = parse(r'''(+ 1 2)''') + +def test_objects(): + #py.test.skip("in progress") + + w_fixnum = parse('-12345') + assert isinstance(w_fixnum, W_Fixnum) + assert unwrap(w_fixnum) == -12345 + + w_float = parse('123456.1234') + assert isinstance(w_float, W_Float) + assert unwrap(w_float) == 123456.1234 + w_float = parse('-123456.1234') + assert isinstance(w_float, W_Float) + assert unwrap(w_float) == -123456.1234 + +def test_sexpr(): + w_list = parse('(+ 1 2)') assert isinstance(w_list, W_Pair) assert isinstance(w_list.car, W_Symbol) assert isinstance(w_list.cdr, W_Pair) From jlg at codespeak.net Mon Jun 25 13:57:25 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Mon, 25 Jun 2007 13:57:25 +0200 (CEST) Subject: [pypy-svn] r44504 - pypy/dist/pypy/lang/scheme/test Message-ID: <20070625115725.2F69B80DA@code0.codespeak.net> Author: jlg Date: Mon Jun 25 13:57:23 2007 New Revision: 44504 Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py Log: test_eval tuned Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Mon Jun 25 13:57:23 2007 @@ -35,21 +35,22 @@ def eval_noctx(expr): return parse(expr).eval(None) -def test_eval_simple(): +def test_eval_numerical(): w_num = eval_noctx('(+ 4)') assert w_num.to_number() == 4 - w_num = eval_noctx('(+ 4 5)') - assert w_num.to_number() == 9 - w_num = eval_noctx('(+ 4 5 6)') - assert w_num.to_number() == 15 + w_num = eval_noctx('(+ 4 -5)') + assert w_num.to_number() == -1 + w_num = eval_noctx('(+ 4 -5 6.1)') + assert w_num.to_number() == 5.1 w_num = eval_noctx('(* 4)') assert w_num.to_number() == 4 - w_num = eval_noctx('(* 4 5)') - assert w_num.to_number() == 20 - w_num = eval_noctx('(* 4 5 6)') - assert w_num.to_number() == (4 * 5 * 6) + w_num = eval_noctx('(* 4 -5)') + assert w_num.to_number() == -20 + w_num = eval_noctx('(* 4 -5 6.1)') + assert w_num.to_number() == (4 * -5 * 6.1) -def test_eval_nested(): +def test_eval_numerical_nested(): w_num = eval_noctx('(+ 4 (* (+ 5) 6) (+ 1 2))') assert w_num.to_number() == 37 + From cfbolz at codespeak.net Mon Jun 25 14:21:42 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 25 Jun 2007 14:21:42 +0200 (CEST) Subject: [pypy-svn] r44506 - in pypy/dist/pypy/rlib/parsing: . test Message-ID: <20070625122142.F04CD80D7@code0.codespeak.net> Author: cfbolz Date: Mon Jun 25 14:21:42 2007 New Revision: 44506 Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py pypy/dist/pypy/rlib/parsing/pypackrat.py pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Log: add an if without a body Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/makepackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/makepackrat.py Mon Jun 25 14:21:42 2007 @@ -145,7 +145,13 @@ 'if' SPACE* condition = PYTHONCODE - return {Nonterminal('if', [cmd, condition])}; + IGNORE* + return {Nonterminal('if', [cmd, condition])} + | 'if' + SPACE* + condition = PYTHONCODE + IGNORE* + return {Nonterminal('if', [condition])}; commandchain: result = simplecommand+ @@ -528,9 +534,10 @@ self.emit("_result = (%s)" % (t.children[0].additional_info[1:-1], )) def visit_if(self, t): - self.dispatch(t.children[0]) + if len(t.children) == 2: + self.dispatch(t.children[0]) for _ in self.start_block("if not (%s):" % ( - t.children[1].additional_info[1:-1], )): + t.children[-1].additional_info[1:-1], )): self.emit("raise self._BacktrackException(") self.emit(" self._ErrorInformation(") self.emit(" _startingpos, ['condition not met']))") Modified: pypy/dist/pypy/rlib/parsing/pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/pypackrat.py Mon Jun 25 14:21:42 2007 @@ -1521,46 +1521,139 @@ try: _result = None _error = None - _result = self.__chars__('do') - _call_status = self._newline() - _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) - _call_status = self._command() - _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) - cmd = _result - _all57 = [] while 1: - _choice58 = self._pos + _error = None + _choice57 = self._pos try: - _call_status = self._SPACE() + _result = self.__chars__('do') + _call_status = self._newline() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _call_status = self._command() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + cmd = _result + _all58 = [] + while 1: + _choice59 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all58.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice59 + break + _result = _all58 + _result = self.__chars__('if') + _all60 = [] + while 1: + _choice61 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all60.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice61 + break + _result = _all60 + _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all57.append(_result) + condition = _result + _all62 = [] + while 1: + _choice63 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all62.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice63 + break + _result = _all62 + _result = (Nonterminal('if', [cmd, condition])) + break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice58 - break - _result = _all57 - _result = self.__chars__('if') - _all59 = [] - while 1: - _choice60 = self._pos + self._pos = _choice57 + _choice64 = self._pos try: - _call_status = self._SPACE() + _result = self.__chars__('if') + _all65 = [] + while 1: + _choice66 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all65.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice66 + break + _result = _all65 + _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all59.append(_result) + condition = _result + _all67 = [] + while 1: + _choice68 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all67.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice68 + break + _result = _all67 + _result = (Nonterminal('if', [condition])) + break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice60 - break - _result = _all59 - _call_status = self._PYTHONCODE() - _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) - condition = _result - _result = (Nonterminal('if', [cmd, condition])) + self._pos = _choice64 + raise self._BacktrackException(_error) + _result = self.__chars__('if') + _all69 = [] + while 1: + _choice70 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all69.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice70 + break + _result = _all69 + _call_status = self._PYTHONCODE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + condition = _result + _all71 = [] + while 1: + _choice72 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all71.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice72 + break + _result = _all71 + _result = (Nonterminal('if', [condition])) + break if _status.status == _status.LEFTRECURSION: if _status.result is not None: if _status.pos >= self._pos: @@ -1617,23 +1710,23 @@ try: _result = None _error = None - _all61 = [] + _all73 = [] _call_status = self._simplecommand() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all61.append(_result) + _all73.append(_result) while 1: - _choice62 = self._pos + _choice74 = self._pos try: _call_status = self._simplecommand() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all61.append(_result) + _all73.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice62 + self._pos = _choice74 break - _result = _all61 + _result = _all73 result = _result _result = (Nonterminal('commands', result)) if _status.status == _status.LEFTRECURSION: @@ -1696,33 +1789,33 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) name = _result - _all63 = [] + _all75 = [] while 1: - _choice64 = self._pos + _choice76 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all63.append(_result) + _all75.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice64 + self._pos = _choice76 break - _result = _all63 + _result = _all75 _result = self.__chars__('=') - _all65 = [] + _all77 = [] while 1: - _choice66 = self._pos + _choice78 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all65.append(_result) + _all77.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice66 + self._pos = _choice78 break - _result = _all65 + _result = _all77 _call_status = self._command() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -1786,152 +1879,152 @@ _error = None while 1: _error = None - _choice67 = self._pos + _choice79 = self._pos try: _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all68 = [] + _all80 = [] while 1: - _choice69 = self._pos + _choice81 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all68.append(_result) + _all80.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice69 + self._pos = _choice81 break - _result = _all68 + _result = _all80 _result = self.__chars__('?') - _all70 = [] + _all82 = [] while 1: - _choice71 = self._pos + _choice83 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all70.append(_result) + _all82.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice71 + self._pos = _choice83 break - _result = _all70 + _result = _all82 _result = (Nonterminal('maybe', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice67 - _choice72 = self._pos + self._pos = _choice79 + _choice84 = self._pos try: _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all73 = [] + _all85 = [] while 1: - _choice74 = self._pos + _choice86 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all73.append(_result) + _all85.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice74 + self._pos = _choice86 break - _result = _all73 + _result = _all85 while 1: _error = None - _choice75 = self._pos + _choice87 = self._pos try: _result = self.__chars__('*') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice75 - _choice76 = self._pos + self._pos = _choice87 + _choice88 = self._pos try: _result = self.__chars__('+') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice76 + self._pos = _choice88 raise self._BacktrackException(_error) _result = self.__chars__('+') break repetition = _result - _all77 = [] + _all89 = [] while 1: - _choice78 = self._pos + _choice90 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all77.append(_result) + _all89.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice78 + self._pos = _choice90 break - _result = _all77 + _result = _all89 _result = (Nonterminal('repetition', [repetition, what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice72 + self._pos = _choice84 raise self._BacktrackException(_error) _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all79 = [] + _all91 = [] while 1: - _choice80 = self._pos + _choice92 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all79.append(_result) + _all91.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice80 + self._pos = _choice92 break - _result = _all79 + _result = _all91 while 1: _error = None - _choice81 = self._pos + _choice93 = self._pos try: _result = self.__chars__('*') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice81 - _choice82 = self._pos + self._pos = _choice93 + _choice94 = self._pos try: _result = self.__chars__('+') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice82 + self._pos = _choice94 raise self._BacktrackException(_error) _result = self.__chars__('+') break repetition = _result - _all83 = [] + _all95 = [] while 1: - _choice84 = self._pos + _choice96 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all83.append(_result) + _all95.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice84 + self._pos = _choice96 break - _result = _all83 + _result = _all95 _result = (Nonterminal('repetition', [repetition, what])) break if _status.status == _status.LEFTRECURSION: @@ -1992,45 +2085,45 @@ _error = None while 1: _error = None - _choice85 = self._pos + _choice97 = self._pos try: _result = self.__chars__('!') - _all86 = [] + _all98 = [] while 1: - _choice87 = self._pos + _choice99 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all86.append(_result) + _all98.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice87 + self._pos = _choice99 break - _result = _all86 + _result = _all98 _call_status = self._negation() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all88 = [] + _all100 = [] while 1: - _choice89 = self._pos + _choice101 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all88.append(_result) + _all100.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice89 + self._pos = _choice101 break - _result = _all88 + _result = _all100 _result = (Nonterminal('negation', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice85 - _choice90 = self._pos + self._pos = _choice97 + _choice102 = self._pos try: _call_status = self._enclosed() _result = _call_status.result @@ -2038,7 +2131,7 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice90 + self._pos = _choice102 raise self._BacktrackException(_error) _call_status = self._enclosed() _result = _call_status.result @@ -2102,152 +2195,152 @@ _error = None while 1: _error = None - _choice91 = self._pos + _choice103 = self._pos try: _result = self.__chars__('<') - _all92 = [] + _all104 = [] while 1: - _choice93 = self._pos + _choice105 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all92.append(_result) + _all104.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice93 + self._pos = _choice105 break - _result = _all92 + _result = _all104 _call_status = self._primary() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all94 = [] + _all106 = [] while 1: - _choice95 = self._pos + _choice107 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all94.append(_result) + _all106.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice95 + self._pos = _choice107 break - _result = _all94 + _result = _all106 _result = self.__chars__('>') - _all96 = [] + _all108 = [] while 1: - _choice97 = self._pos + _choice109 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all96.append(_result) + _all108.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice97 + self._pos = _choice109 break - _result = _all96 + _result = _all108 _result = (Nonterminal('exclusive', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice91 - _choice98 = self._pos + self._pos = _choice103 + _choice110 = self._pos try: _result = self.__chars__('[') - _all99 = [] + _all111 = [] while 1: - _choice100 = self._pos + _choice112 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all99.append(_result) + _all111.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice100 + self._pos = _choice112 break - _result = _all99 + _result = _all111 _call_status = self._or_() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all101 = [] + _all113 = [] while 1: - _choice102 = self._pos + _choice114 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all101.append(_result) + _all113.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice102 + self._pos = _choice114 break - _result = _all101 + _result = _all113 _result = self.__chars__(']') - _all103 = [] + _all115 = [] while 1: - _choice104 = self._pos + _choice116 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all103.append(_result) + _all115.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice104 + self._pos = _choice116 break - _result = _all103 + _result = _all115 _result = (Nonterminal('ignore', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice98 - _choice105 = self._pos + self._pos = _choice110 + _choice117 = self._pos try: - _before_discard106 = _result + _before_discard118 = _result _result = self.__chars__('(') - _all107 = [] + _all119 = [] while 1: - _choice108 = self._pos + _choice120 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all107.append(_result) + _all119.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice108 + self._pos = _choice120 break - _result = _all107 - _result = _before_discard106 + _result = _all119 + _result = _before_discard118 _call_status = self._or_() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard109 = _result + _before_discard121 = _result _result = self.__chars__(')') - _all110 = [] + _all122 = [] while 1: - _choice111 = self._pos + _choice123 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all110.append(_result) + _all122.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice111 + self._pos = _choice123 break - _result = _all110 - _result = _before_discard109 + _result = _all122 + _result = _before_discard121 break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice105 - _choice112 = self._pos + self._pos = _choice117 + _choice124 = self._pos try: _call_status = self._primary() _result = _call_status.result @@ -2255,7 +2348,7 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice112 + self._pos = _choice124 raise self._BacktrackException(_error) _call_status = self._primary() _result = _call_status.result @@ -2319,7 +2412,7 @@ _error = None while 1: _error = None - _choice113 = self._pos + _choice125 = self._pos try: _call_status = self._call() _result = _call_status.result @@ -2327,74 +2420,74 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice113 - _choice114 = self._pos + self._pos = _choice125 + _choice126 = self._pos try: _call_status = self._REGEX() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard115 = _result - _all116 = [] + _before_discard127 = _result + _all128 = [] while 1: - _choice117 = self._pos + _choice129 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all116.append(_result) + _all128.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice117 + self._pos = _choice129 break - _result = _all116 - _result = _before_discard115 + _result = _all128 + _result = _before_discard127 break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice114 - _choice118 = self._pos + self._pos = _choice126 + _choice130 = self._pos try: _call_status = self._QUOTE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard119 = _result - _all120 = [] + _before_discard131 = _result + _all132 = [] while 1: - _choice121 = self._pos + _choice133 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all120.append(_result) + _all132.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice121 + self._pos = _choice133 break - _result = _all120 - _result = _before_discard119 + _result = _all132 + _result = _before_discard131 break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice118 + self._pos = _choice130 raise self._BacktrackException(_error) _call_status = self._QUOTE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard122 = _result - _all123 = [] + _before_discard134 = _result + _all135 = [] while 1: - _choice124 = self._pos + _choice136 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all123.append(_result) + _all135.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice124 + self._pos = _choice136 break - _result = _all123 - _result = _before_discard122 + _result = _all135 + _result = _before_discard134 break if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -2460,19 +2553,19 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) args = _result - _all125 = [] + _all137 = [] while 1: - _choice126 = self._pos + _choice138 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all125.append(_result) + _all137.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice126 + self._pos = _choice138 break - _result = _all125 + _result = _all137 _result = (Nonterminal("call", [x, args])) if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -2532,95 +2625,95 @@ _error = None while 1: _error = None - _choice127 = self._pos + _choice139 = self._pos try: _result = self.__chars__('(') - _all128 = [] + _all140 = [] while 1: - _choice129 = self._pos + _choice141 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all128.append(_result) + _all140.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice129 + self._pos = _choice141 break - _result = _all128 - _all130 = [] + _result = _all140 + _all142 = [] while 1: - _choice131 = self._pos + _choice143 = self._pos try: _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard132 = _result - _all133 = [] + _before_discard144 = _result + _all145 = [] while 1: - _choice134 = self._pos + _choice146 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all133.append(_result) + _all145.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice134 + self._pos = _choice146 break - _result = _all133 + _result = _all145 _result = self.__chars__(',') - _all135 = [] + _all147 = [] while 1: - _choice136 = self._pos + _choice148 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all135.append(_result) + _all147.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice136 + self._pos = _choice148 break - _result = _all135 - _result = _before_discard132 - _all130.append(_result) + _result = _all147 + _result = _before_discard144 + _all142.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice131 + self._pos = _choice143 break - _result = _all130 + _result = _all142 args = _result _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) last = _result _result = self.__chars__(')') - _all137 = [] + _all149 = [] while 1: - _choice138 = self._pos + _choice150 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all137.append(_result) + _all149.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice138 + self._pos = _choice150 break - _result = _all137 + _result = _all149 _result = (Nonterminal("args", args + [last])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice127 - _choice139 = self._pos + self._pos = _choice139 + _choice151 = self._pos try: _result = (Nonterminal("args", [])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice139 + self._pos = _choice151 raise self._BacktrackException(_error) _result = (Nonterminal("args", [])) break @@ -2679,77 +2772,77 @@ self._pos = 0 self._inputstream = inputstream def _regex299149370(self): - _choice140 = self._pos + _choice152 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_299149370(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice140 + self._pos = _choice152 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1006631623(self): - _choice141 = self._pos + _choice153 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1006631623(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice141 + self._pos = _choice153 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex528667127(self): - _choice142 = self._pos + _choice154 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_528667127(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice142 + self._pos = _choice154 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex291086639(self): - _choice143 = self._pos + _choice155 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_291086639(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice143 + self._pos = _choice155 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1074651696(self): - _choice144 = self._pos + _choice156 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1074651696(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice144 + self._pos = _choice156 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1124192327(self): - _choice145 = self._pos + _choice157 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1124192327(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice145 + self._pos = _choice157 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1979538501(self): - _choice146 = self._pos + _choice158 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1979538501(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice146 + self._pos = _choice158 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] Modified: pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Mon Jun 25 14:21:42 2007 @@ -334,7 +334,7 @@ assert p._pos == 2 assert res == "c" - def test_if(self): + def test_doif(self): class parser(PackratParser): """ INT: @@ -354,6 +354,23 @@ assert excinfo.value.error.pos == 0 assert excinfo.value.error.expected == ['condition not met'] + def test_doif(self): + class parser(PackratParser): + """ + b(c): + if {c > 42} + c = __chars__({str(c)}) + return {int(c)} + | 'xyz'; + """ + print parser._code + p = parser("54") + res = p.b(54) + assert res == 54 + p = parser("xyz") + res = p.b(21) + assert res == 'xyz' + def test_parse_arguments(self): class parser(PackratParser): """ @@ -385,3 +402,4 @@ res = p.small_big_small() assert res == 'aaaaarstawfpacawBAAAFPAcccfafp' + From cfbolz at codespeak.net Mon Jun 25 14:23:01 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 25 Jun 2007 14:23:01 +0200 (CEST) Subject: [pypy-svn] r44507 - pypy/dist/pypy/rlib/parsing/test Message-ID: <20070625122301.9858680F3@code0.codespeak.net> Author: cfbolz Date: Mon Jun 25 14:23:01 2007 New Revision: 44507 Modified: pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Log: oops, give the tests different names Modified: pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Mon Jun 25 14:23:01 2007 @@ -354,7 +354,7 @@ assert excinfo.value.error.pos == 0 assert excinfo.value.error.expected == ['condition not met'] - def test_doif(self): + def test_if(self): class parser(PackratParser): """ b(c): From cfbolz at codespeak.net Mon Jun 25 16:26:15 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 25 Jun 2007 16:26:15 +0200 (CEST) Subject: [pypy-svn] r44513 - in pypy/dist/pypy/rlib/parsing: . test Message-ID: <20070625142615.E332180E4@code0.codespeak.net> Author: cfbolz Date: Mon Jun 25 16:26:15 2007 New Revision: 44513 Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py pypy/dist/pypy/rlib/parsing/pypackrat.py pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Log: add a choice. the parser language is becoming quite like Prolog, not sure it is a good thing. Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/makepackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/makepackrat.py Mon Jun 25 16:26:15 2007 @@ -128,6 +128,7 @@ | if_ | named_command | repetition + | choose | negation; return_: @@ -153,6 +154,18 @@ IGNORE* return {Nonterminal('if', [condition])}; +choose: + 'choose' + SPACE* + name = NAME + SPACE* + 'in' + SPACE* + expr = PYTHONCODE + IGNORE* + cmds = commands + return {Nonterminal('choose', [name, expr, cmds])}; + commandchain: result = simplecommand+ return {Nonterminal('commands', result)}; @@ -541,6 +554,17 @@ self.emit("raise self._BacktrackException(") self.emit(" self._ErrorInformation(") self.emit(" _startingpos, ['condition not met']))") + + def visit_choose(self, t): + for _ in self.start_block("for %s in (%s):" % ( + t.children[0], t.children[1].additional_info[1:-1], )): + for _ in self.start_block("try:"): + self.dispatch(t.children[2]) + self.emit("break") + for _ in self.start_block("except BacktrackException, _exc:"): + self.emit("_error = self._combine_errors(_exc.error, _error)") + for _ in self.start_block("else:"): + self.emit("raise BacktrackException(_error)") def visit_call(self, t): args = ", ".join(['(%s)' % (arg.additional_info[1:-1], ) Modified: pypy/dist/pypy/rlib/parsing/pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/pypackrat.py Mon Jun 25 16:26:15 2007 @@ -1365,13 +1365,22 @@ self._pos = _choice51 _choice52 = self._pos try: - _call_status = self._negation() + _call_status = self._choose() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice52 + _choice53 = self._pos + try: + _call_status = self._negation() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + break + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice53 raise self._BacktrackException(_error) _call_status = self._negation() _result = _call_status.result @@ -1434,36 +1443,36 @@ _result = None _error = None _result = self.__chars__('return') - _all53 = [] + _all54 = [] while 1: - _choice54 = self._pos + _choice55 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all53.append(_result) + _all54.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice54 + self._pos = _choice55 break - _result = _all53 + _result = _all54 _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) code = _result - _all55 = [] + _all56 = [] while 1: - _choice56 = self._pos + _choice57 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all55.append(_result) + _all56.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice56 + self._pos = _choice57 break - _result = _all55 + _result = _all56 _result = (Nonterminal('return', [code])) if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -1523,7 +1532,7 @@ _error = None while 1: _error = None - _choice57 = self._pos + _choice58 = self._pos try: _result = self.__chars__('do') _call_status = self._newline() @@ -1533,125 +1542,125 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) cmd = _result - _all58 = [] + _all59 = [] while 1: - _choice59 = self._pos + _choice60 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all58.append(_result) + _all59.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice59 + self._pos = _choice60 break - _result = _all58 + _result = _all59 _result = self.__chars__('if') - _all60 = [] + _all61 = [] while 1: - _choice61 = self._pos + _choice62 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all60.append(_result) + _all61.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice61 + self._pos = _choice62 break - _result = _all60 + _result = _all61 _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) condition = _result - _all62 = [] + _all63 = [] while 1: - _choice63 = self._pos + _choice64 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all62.append(_result) + _all63.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice63 + self._pos = _choice64 break - _result = _all62 + _result = _all63 _result = (Nonterminal('if', [cmd, condition])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice57 - _choice64 = self._pos + self._pos = _choice58 + _choice65 = self._pos try: _result = self.__chars__('if') - _all65 = [] + _all66 = [] while 1: - _choice66 = self._pos + _choice67 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all65.append(_result) + _all66.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice66 + self._pos = _choice67 break - _result = _all65 + _result = _all66 _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) condition = _result - _all67 = [] + _all68 = [] while 1: - _choice68 = self._pos + _choice69 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all67.append(_result) + _all68.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice68 + self._pos = _choice69 break - _result = _all67 + _result = _all68 _result = (Nonterminal('if', [condition])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice64 + self._pos = _choice65 raise self._BacktrackException(_error) _result = self.__chars__('if') - _all69 = [] + _all70 = [] while 1: - _choice70 = self._pos + _choice71 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all69.append(_result) + _all70.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice70 + self._pos = _choice71 break - _result = _all69 + _result = _all70 _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) condition = _result - _all71 = [] + _all72 = [] while 1: - _choice72 = self._pos + _choice73 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all71.append(_result) + _all72.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice72 + self._pos = _choice73 break - _result = _all71 + _result = _all72 _result = (Nonterminal('if', [condition])) break if _status.status == _status.LEFTRECURSION: @@ -1678,6 +1687,129 @@ _status.error = _error _status.status = _status.ERROR raise self._BacktrackException(_error) + class _Status_choose(_Status): + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None + def choose(self): + return self._choose().result + def _choose(self): + _key = self._pos + _status = self._dict_choose.get(_key, None) + if _status is None: + _status = self._dict_choose[_key] = self._Status_choose() + elif _status.status == _status.NORMAL: + self._pos = _status.pos + return _status + elif _status.status == _status.ERROR: + raise self._BacktrackException(_status.error) + elif (_status.status == _status.INPROGRESS or + _status.status == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise self._BacktrackException(None) + elif _status.status == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS + _startingpos = self._pos + try: + _result = None + _error = None + _result = self.__chars__('choose') + _all74 = [] + while 1: + _choice75 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all74.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice75 + break + _result = _all74 + _call_status = self._NAME() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + name = _result + _all76 = [] + while 1: + _choice77 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all76.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice77 + break + _result = _all76 + _result = self.__chars__('in') + _all78 = [] + while 1: + _choice79 = self._pos + try: + _call_status = self._SPACE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all78.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice79 + break + _result = _all78 + _call_status = self._PYTHONCODE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + expr = _result + _all80 = [] + while 1: + _choice81 = self._pos + try: + _call_status = self._IGNORE() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + _all80.append(_result) + except self._BacktrackException, _exc: + _error = self._combine_errors(_error, _exc.error) + self._pos = _choice81 + break + _result = _all80 + _call_status = self._commands() + _result = _call_status.result + _error = self._combine_errors(_call_status.error, _error) + cmds = _result + _result = (Nonterminal('choose', [name, expr, cmds])) + if _status.status == _status.LEFTRECURSION: + if _status.result is not None: + if _status.pos >= self._pos: + _status.status = _status.NORMAL + self._pos = _status.pos + return _status + _status.pos = self._pos + _status.status = _status.SOMESOLUTIONS + _status.result = _result + _status.error = _error + self._pos = _startingpos + return self._choose() + _status.status = _status.NORMAL + _status.pos = self._pos + _status.result = _result + _status.error = _error + return _status + except self._BacktrackException, _exc: + _status.pos = -1 + _status.result = None + _error = self._combine_errors(_error, _exc.error) + _status.error = _error + _status.status = _status.ERROR + raise self._BacktrackException(_error) class _Status_commandchain(_Status): def __init__(self): self.pos = 0 @@ -1710,23 +1842,23 @@ try: _result = None _error = None - _all73 = [] + _all82 = [] _call_status = self._simplecommand() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all73.append(_result) + _all82.append(_result) while 1: - _choice74 = self._pos + _choice83 = self._pos try: _call_status = self._simplecommand() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all73.append(_result) + _all82.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice74 + self._pos = _choice83 break - _result = _all73 + _result = _all82 result = _result _result = (Nonterminal('commands', result)) if _status.status == _status.LEFTRECURSION: @@ -1789,33 +1921,33 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) name = _result - _all75 = [] + _all84 = [] while 1: - _choice76 = self._pos + _choice85 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all75.append(_result) + _all84.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice76 + self._pos = _choice85 break - _result = _all75 + _result = _all84 _result = self.__chars__('=') - _all77 = [] + _all86 = [] while 1: - _choice78 = self._pos + _choice87 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all77.append(_result) + _all86.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice78 + self._pos = _choice87 break - _result = _all77 + _result = _all86 _call_status = self._command() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -1879,152 +2011,152 @@ _error = None while 1: _error = None - _choice79 = self._pos + _choice88 = self._pos try: _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all80 = [] + _all89 = [] while 1: - _choice81 = self._pos + _choice90 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all80.append(_result) + _all89.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice81 + self._pos = _choice90 break - _result = _all80 + _result = _all89 _result = self.__chars__('?') - _all82 = [] + _all91 = [] while 1: - _choice83 = self._pos + _choice92 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all82.append(_result) + _all91.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice83 + self._pos = _choice92 break - _result = _all82 + _result = _all91 _result = (Nonterminal('maybe', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice79 - _choice84 = self._pos + self._pos = _choice88 + _choice93 = self._pos try: _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all85 = [] + _all94 = [] while 1: - _choice86 = self._pos + _choice95 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all85.append(_result) + _all94.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice86 + self._pos = _choice95 break - _result = _all85 + _result = _all94 while 1: _error = None - _choice87 = self._pos + _choice96 = self._pos try: _result = self.__chars__('*') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice87 - _choice88 = self._pos + self._pos = _choice96 + _choice97 = self._pos try: _result = self.__chars__('+') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice88 + self._pos = _choice97 raise self._BacktrackException(_error) _result = self.__chars__('+') break repetition = _result - _all89 = [] + _all98 = [] while 1: - _choice90 = self._pos + _choice99 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all89.append(_result) + _all98.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice90 + self._pos = _choice99 break - _result = _all89 + _result = _all98 _result = (Nonterminal('repetition', [repetition, what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice84 + self._pos = _choice93 raise self._BacktrackException(_error) _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all91 = [] + _all100 = [] while 1: - _choice92 = self._pos + _choice101 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all91.append(_result) + _all100.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice92 + self._pos = _choice101 break - _result = _all91 + _result = _all100 while 1: _error = None - _choice93 = self._pos + _choice102 = self._pos try: _result = self.__chars__('*') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice93 - _choice94 = self._pos + self._pos = _choice102 + _choice103 = self._pos try: _result = self.__chars__('+') break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice94 + self._pos = _choice103 raise self._BacktrackException(_error) _result = self.__chars__('+') break repetition = _result - _all95 = [] + _all104 = [] while 1: - _choice96 = self._pos + _choice105 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all95.append(_result) + _all104.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice96 + self._pos = _choice105 break - _result = _all95 + _result = _all104 _result = (Nonterminal('repetition', [repetition, what])) break if _status.status == _status.LEFTRECURSION: @@ -2085,45 +2217,45 @@ _error = None while 1: _error = None - _choice97 = self._pos + _choice106 = self._pos try: _result = self.__chars__('!') - _all98 = [] + _all107 = [] while 1: - _choice99 = self._pos + _choice108 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all98.append(_result) + _all107.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice99 + self._pos = _choice108 break - _result = _all98 + _result = _all107 _call_status = self._negation() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all100 = [] + _all109 = [] while 1: - _choice101 = self._pos + _choice110 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all100.append(_result) + _all109.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice101 + self._pos = _choice110 break - _result = _all100 + _result = _all109 _result = (Nonterminal('negation', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice97 - _choice102 = self._pos + self._pos = _choice106 + _choice111 = self._pos try: _call_status = self._enclosed() _result = _call_status.result @@ -2131,7 +2263,7 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice102 + self._pos = _choice111 raise self._BacktrackException(_error) _call_status = self._enclosed() _result = _call_status.result @@ -2195,152 +2327,152 @@ _error = None while 1: _error = None - _choice103 = self._pos + _choice112 = self._pos try: _result = self.__chars__('<') - _all104 = [] + _all113 = [] while 1: - _choice105 = self._pos + _choice114 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all104.append(_result) + _all113.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice105 + self._pos = _choice114 break - _result = _all104 + _result = _all113 _call_status = self._primary() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all106 = [] + _all115 = [] while 1: - _choice107 = self._pos + _choice116 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all106.append(_result) + _all115.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice107 + self._pos = _choice116 break - _result = _all106 + _result = _all115 _result = self.__chars__('>') - _all108 = [] + _all117 = [] while 1: - _choice109 = self._pos + _choice118 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all108.append(_result) + _all117.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice109 + self._pos = _choice118 break - _result = _all108 + _result = _all117 _result = (Nonterminal('exclusive', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice103 - _choice110 = self._pos + self._pos = _choice112 + _choice119 = self._pos try: _result = self.__chars__('[') - _all111 = [] + _all120 = [] while 1: - _choice112 = self._pos + _choice121 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all111.append(_result) + _all120.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice112 + self._pos = _choice121 break - _result = _all111 + _result = _all120 _call_status = self._or_() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) what = _result - _all113 = [] + _all122 = [] while 1: - _choice114 = self._pos + _choice123 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all113.append(_result) + _all122.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice114 + self._pos = _choice123 break - _result = _all113 + _result = _all122 _result = self.__chars__(']') - _all115 = [] + _all124 = [] while 1: - _choice116 = self._pos + _choice125 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all115.append(_result) + _all124.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice116 + self._pos = _choice125 break - _result = _all115 + _result = _all124 _result = (Nonterminal('ignore', [what])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice110 - _choice117 = self._pos + self._pos = _choice119 + _choice126 = self._pos try: - _before_discard118 = _result + _before_discard127 = _result _result = self.__chars__('(') - _all119 = [] + _all128 = [] while 1: - _choice120 = self._pos + _choice129 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all119.append(_result) + _all128.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice120 + self._pos = _choice129 break - _result = _all119 - _result = _before_discard118 + _result = _all128 + _result = _before_discard127 _call_status = self._or_() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard121 = _result + _before_discard130 = _result _result = self.__chars__(')') - _all122 = [] + _all131 = [] while 1: - _choice123 = self._pos + _choice132 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all122.append(_result) + _all131.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice123 + self._pos = _choice132 break - _result = _all122 - _result = _before_discard121 + _result = _all131 + _result = _before_discard130 break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice117 - _choice124 = self._pos + self._pos = _choice126 + _choice133 = self._pos try: _call_status = self._primary() _result = _call_status.result @@ -2348,7 +2480,7 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice124 + self._pos = _choice133 raise self._BacktrackException(_error) _call_status = self._primary() _result = _call_status.result @@ -2412,7 +2544,7 @@ _error = None while 1: _error = None - _choice125 = self._pos + _choice134 = self._pos try: _call_status = self._call() _result = _call_status.result @@ -2420,74 +2552,74 @@ break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice125 - _choice126 = self._pos + self._pos = _choice134 + _choice135 = self._pos try: _call_status = self._REGEX() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard127 = _result - _all128 = [] + _before_discard136 = _result + _all137 = [] while 1: - _choice129 = self._pos + _choice138 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all128.append(_result) + _all137.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice129 + self._pos = _choice138 break - _result = _all128 - _result = _before_discard127 + _result = _all137 + _result = _before_discard136 break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice126 - _choice130 = self._pos + self._pos = _choice135 + _choice139 = self._pos try: _call_status = self._QUOTE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard131 = _result - _all132 = [] + _before_discard140 = _result + _all141 = [] while 1: - _choice133 = self._pos + _choice142 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all132.append(_result) + _all141.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice133 + self._pos = _choice142 break - _result = _all132 - _result = _before_discard131 + _result = _all141 + _result = _before_discard140 break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice130 + self._pos = _choice139 raise self._BacktrackException(_error) _call_status = self._QUOTE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard134 = _result - _all135 = [] + _before_discard143 = _result + _all144 = [] while 1: - _choice136 = self._pos + _choice145 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all135.append(_result) + _all144.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice136 + self._pos = _choice145 break - _result = _all135 - _result = _before_discard134 + _result = _all144 + _result = _before_discard143 break if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -2553,19 +2685,19 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) args = _result - _all137 = [] + _all146 = [] while 1: - _choice138 = self._pos + _choice147 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all137.append(_result) + _all146.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice138 + self._pos = _choice147 break - _result = _all137 + _result = _all146 _result = (Nonterminal("call", [x, args])) if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -2625,95 +2757,95 @@ _error = None while 1: _error = None - _choice139 = self._pos + _choice148 = self._pos try: _result = self.__chars__('(') - _all140 = [] + _all149 = [] while 1: - _choice141 = self._pos + _choice150 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all140.append(_result) + _all149.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice141 + self._pos = _choice150 break - _result = _all140 - _all142 = [] + _result = _all149 + _all151 = [] while 1: - _choice143 = self._pos + _choice152 = self._pos try: _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _before_discard144 = _result - _all145 = [] + _before_discard153 = _result + _all154 = [] while 1: - _choice146 = self._pos + _choice155 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all145.append(_result) + _all154.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice146 + self._pos = _choice155 break - _result = _all145 + _result = _all154 _result = self.__chars__(',') - _all147 = [] + _all156 = [] while 1: - _choice148 = self._pos + _choice157 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all147.append(_result) + _all156.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice148 + self._pos = _choice157 break - _result = _all147 - _result = _before_discard144 - _all142.append(_result) + _result = _all156 + _result = _before_discard153 + _all151.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice143 + self._pos = _choice152 break - _result = _all142 + _result = _all151 args = _result _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) last = _result _result = self.__chars__(')') - _all149 = [] + _all158 = [] while 1: - _choice150 = self._pos + _choice159 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) - _all149.append(_result) + _all158.append(_result) except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice150 + self._pos = _choice159 break - _result = _all149 + _result = _all158 _result = (Nonterminal("args", args + [last])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice139 - _choice151 = self._pos + self._pos = _choice148 + _choice160 = self._pos try: _result = (Nonterminal("args", [])) break except self._BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice151 + self._pos = _choice160 raise self._BacktrackException(_error) _result = (Nonterminal("args", [])) break @@ -2761,6 +2893,7 @@ self._dict_simplecommand = {} self._dict_return_ = {} self._dict_if_ = {} + self._dict_choose = {} self._dict_commandchain = {} self._dict_named_command = {} self._dict_repetition = {} @@ -2772,77 +2905,77 @@ self._pos = 0 self._inputstream = inputstream def _regex299149370(self): - _choice152 = self._pos + _choice161 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_299149370(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice152 + self._pos = _choice161 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1006631623(self): - _choice153 = self._pos + _choice162 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1006631623(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice153 + self._pos = _choice162 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex528667127(self): - _choice154 = self._pos + _choice163 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_528667127(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice154 + self._pos = _choice163 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex291086639(self): - _choice155 = self._pos + _choice164 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_291086639(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice155 + self._pos = _choice164 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1074651696(self): - _choice156 = self._pos + _choice165 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1074651696(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice156 + self._pos = _choice165 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1124192327(self): - _choice157 = self._pos + _choice166 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1124192327(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice157 + self._pos = _choice166 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1979538501(self): - _choice158 = self._pos + _choice167 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1979538501(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice158 + self._pos = _choice167 raise self._BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] Modified: pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Mon Jun 25 16:26:15 2007 @@ -402,4 +402,33 @@ res = p.small_big_small() assert res == 'aaaaarstawfpacawBAAAFPAcccfafp' + def test_choose(self): + # getting more and more like Prolog, not sure that's good + class parser(PackratParser): + """ + choice: + choose a in {self.possibilities} + __chars__({a})+ + return {a}; + """ + possibilities = ['a', 'x', 'y'] + + p = parser('aaaaaaa') + c = p.choice() + assert c == 'a' + p = parser('xxxxxxxxxxxx') + c = p.choice() + assert c == 'x' + p = parser('y') + c = p.choice() + assert c == 'y' + p = parser('y') + c = p.choice() + assert c == 'y' + p = parser('vvvvvv') + excinfo = py.test.raises(BacktrackException, p.choice) + assert excinfo.value.error.pos == 0 + expected = excinfo.value.error.expected + expected.sort() + assert expected == ['a', 'x', 'y'] From cfbolz at codespeak.net Mon Jun 25 18:32:43 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 25 Jun 2007 18:32:43 +0200 (CEST) Subject: [pypy-svn] r44517 - pypy/dist/pypy/annotation/test Message-ID: <20070625163243.870A280EA@code0.codespeak.net> Author: cfbolz Date: Mon Jun 25 18:32:42 2007 New Revision: 44517 Modified: pypy/dist/pypy/annotation/test/test_annrpython.py Log: a passing test for specialize:ctr_location in the attempt to make sense of my current problems. Modified: pypy/dist/pypy/annotation/test/test_annrpython.py ============================================================================== --- pypy/dist/pypy/annotation/test/test_annrpython.py (original) +++ pypy/dist/pypy/annotation/test/test_annrpython.py Mon Jun 25 18:32:42 2007 @@ -2754,6 +2754,25 @@ assert isinstance(s.items[2], annmodel.SomeInstance) assert s.items[2].flags == {} + def test_ctr_location(self): + from pypy.rlib.jit import hint + + class A: + _annspecialcase_ = 'specialize:ctr_location' + def __init__(self, x): + self.x = x + + def f(n): + a = A(2 * n) + a.x = n + b = A("") + b.x = str(n) + return len(b.x) + a.x + a = self.RPythonAnnotator() + s = a.build_types(f, [int]) + assert isinstance(s, annmodel.SomeInteger) + + def g(n): return [0,1,2,n] From jlg at codespeak.net Mon Jun 25 18:36:32 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Mon, 25 Jun 2007 18:36:32 +0200 (CEST) Subject: [pypy-svn] r44518 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070625163632.66BC280EA@code0.codespeak.net> Author: jlg Date: Mon Jun 25 18:36:30 2007 New Revision: 44518 Modified: pypy/dist/pypy/lang/scheme/TODO.txt pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py pypy/dist/pypy/lang/scheme/test/test_object.py Log: execution context begins Modified: pypy/dist/pypy/lang/scheme/TODO.txt ============================================================================== --- pypy/dist/pypy/lang/scheme/TODO.txt (original) +++ pypy/dist/pypy/lang/scheme/TODO.txt Mon Jun 25 18:36:30 2007 @@ -1,17 +1,22 @@ Do now ------ -- evaluate simple expressions like ++ evaluate simple expressions like (* 6 7) or even (+ 1 2 3 4) - - parsing is done by some shiny new Carl's thingy + + parsing is done by some shiny new Carl's thingy W_xxx object like W_Fixnum should eval to itself despite context - implement basic operations like + * / and so on +- symbols, variables and execution context + global dict for symbols _obarray_ + Do next ------- -- symbols, variables and execution context - global dict for symbols _obarray_ +- there is need to distinct identifier from symbol + (define var 11) + (symbol? var) -> #f + (symbol? 'var) -> #t - control structures - functions Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Mon Jun 25 18:36:30 2007 @@ -9,11 +9,11 @@ assert scope is not None self.scope = scope - def __get__(self, name): + def get(self, name): # shouldn't neme be instance of sth like W_Identifier return self.scope.get(name, None) - def __put__(self, name, obj): + def put(self, name, obj): self.scope[name] = obj class W_Root(object): @@ -43,6 +43,12 @@ return "" def eval(self, ctx): + + if ctx is not None: + w_obj = ctx.get(self.name) + if w_obj is not None: + return w_obj.eval(ctx) + try: return OPERATION_MAP[self.name] except KeyError: Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Mon Jun 25 18:36:30 2007 @@ -1,6 +1,6 @@ from pypy.lang.scheme.ssparser import parse from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_Float, W_String -from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Symbol +from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Symbol, ExecutionContext from pypy.lang.scheme.operation import mul, add def test_operations_simple(): @@ -35,7 +35,7 @@ def eval_noctx(expr): return parse(expr).eval(None) -def test_eval_numerical(): +def test_numerical(): w_num = eval_noctx('(+ 4)') assert w_num.to_number() == 4 w_num = eval_noctx('(+ 4 -5)') @@ -50,7 +50,19 @@ w_num = eval_noctx('(* 4 -5 6.1)') assert w_num.to_number() == (4 * -5 * 6.1) -def test_eval_numerical_nested(): +def test_numerical_nested(): w_num = eval_noctx('(+ 4 (* (+ 5) 6) (+ 1 2))') assert w_num.to_number() == 37 +def test_ctx_simple(): + ctx = ExecutionContext({}) + ctx.put("v1", W_Fixnum(4)) + ctx.put("v2", W_Fixnum(5)) + + w_num = eval_expr(ctx, "(+ 1 v1 v2)") + assert w_num.to_number() == 10 + + ctx.put("v2", W_Float(3.2)) + w_num = eval_expr(ctx, "(+ 1 v1 v2)") + assert w_num.to_number() == 8.2 + Modified: pypy/dist/pypy/lang/scheme/test/test_object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_object.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_object.py Mon Jun 25 18:36:30 2007 @@ -39,3 +39,20 @@ assert p.cdr.car == c2 assert p.cdr.cdr.car == c3 assert p.cdr.cdr.cdr == c4 + +def test_symbol(): + w_sym = W_Symbol("symb") + assert w_sym.to_string() == "symb" + +def test_ctx(): + w_fnum = W_Fixnum(12) + w_symb = W_Symbol("symb") + + ctx = ExecutionContext({}) + ctx.put("v1", w_fnum) + ctx.put("symb", w_symb) + + assert w_symb is ctx.get("symb") + assert w_fnum is ctx.get("v1") + assert ctx.get("no_such_key") is None + From jlg at codespeak.net Mon Jun 25 19:41:06 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Mon, 25 Jun 2007 19:41:06 +0200 (CEST) Subject: [pypy-svn] r44519 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070625174106.4B15880E6@code0.codespeak.net> Author: jlg Date: Mon Jun 25 19:41:04 2007 New Revision: 44519 Modified: pypy/dist/pypy/lang/scheme/TODO.txt pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: objects - W_Procedure added, evaluation refactoring Modified: pypy/dist/pypy/lang/scheme/TODO.txt ============================================================================== --- pypy/dist/pypy/lang/scheme/TODO.txt (original) +++ pypy/dist/pypy/lang/scheme/TODO.txt Mon Jun 25 19:41:04 2007 @@ -10,15 +10,18 @@ - symbols, variables and execution context global dict for symbols _obarray_ -Do next -------- - - there is need to distinct identifier from symbol (define var 11) (symbol? var) -> #f (symbol? 'var) -> #t + +Do next +------- + - control structures - functions +- implement key funcions + (apply, reduce, mapcar and so on) Do in some future ----------------- Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Mon Jun 25 19:41:04 2007 @@ -1,21 +1,5 @@ import autopath -class ExecutionContext(object): - """Execution context implemented as a dict. - - { "IDENTIFIER": W_Root } - """ - def __init__(self, scope): - assert scope is not None - self.scope = scope - - def get(self, name): - # shouldn't neme be instance of sth like W_Identifier - return self.scope.get(name, None) - - def put(self, name, obj): - self.scope[name] = obj - class W_Root(object): def to_string(self): return '' @@ -44,14 +28,14 @@ def eval(self, ctx): - if ctx is not None: - w_obj = ctx.get(self.name) - if w_obj is not None: - return w_obj.eval(ctx) - - try: - return OPERATION_MAP[self.name] - except KeyError: + if ctx is None: + ctx = ExecutionContext() + + w_obj = ctx.get(self.name) + if w_obj is not None: + return w_obj.eval(ctx) + else: + #reference to undefined identifier raise NotImplementedError class W_Boolean(W_Root): @@ -117,7 +101,8 @@ self.cdr = cdr def to_string(self): - return "(" + self.car.to_string() + " . " + self.cdr.to_string() + ")" + return "(" + self.car.to_string() + " . " \ + + self.cdr.to_string() + ")" def eval(self, ctx): oper = self.car.eval(ctx) @@ -132,6 +117,17 @@ #not sure though any operations should exist here #it its very similar to operation.add ############################# +class W_Procedure(W_Root): + + def __init__(self, pname=""): + self.pname = pname + + def to_string(self): + return "#" % (self.pname,) + + def eval(self, ctx, lst=None): + raise NotImplementedError + def add_lst(ctx, lst): return apply_lst(ctx, lambda x, y: x + y, lst) @@ -158,6 +154,14 @@ else: return W_Float(acc) +class Add(W_Procedure): + def eval(self, ctx): + return add_lst + +class Mul(W_Procedure): + def eval(self, ctx): + return mul_lst + ###################################### # dict mapping operations to callables # callables must have 2 arguments @@ -166,7 +170,22 @@ ####################################### OPERATION_MAP = \ { - '+': add_lst, - '*': mul_lst, + '+': Add("+"), + '*': Mul("*"), } +class ExecutionContext(object): + """Execution context implemented as a dict. + + { "IDENTIFIER": W_Root } + """ + def __init__(self, scope=OPERATION_MAP): + assert scope is not None + self.scope = scope + + def get(self, name): + return self.scope.get(name, None) + + def put(self, name, obj): + self.scope[name] = obj + Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Mon Jun 25 19:41:04 2007 @@ -36,26 +36,26 @@ return parse(expr).eval(None) def test_numerical(): - w_num = eval_noctx('(+ 4)') + w_num = eval_noctx("(+ 4)") assert w_num.to_number() == 4 - w_num = eval_noctx('(+ 4 -5)') + w_num = eval_noctx("(+ 4 -5)") assert w_num.to_number() == -1 - w_num = eval_noctx('(+ 4 -5 6.1)') + w_num = eval_noctx("(+ 4 -5 6.1)") assert w_num.to_number() == 5.1 - w_num = eval_noctx('(* 4)') + w_num = eval_noctx("(* 4)") assert w_num.to_number() == 4 - w_num = eval_noctx('(* 4 -5)') + w_num = eval_noctx("(* 4 -5)") assert w_num.to_number() == -20 - w_num = eval_noctx('(* 4 -5 6.1)') + w_num = eval_noctx("(* 4 -5 6.1)") assert w_num.to_number() == (4 * -5 * 6.1) def test_numerical_nested(): - w_num = eval_noctx('(+ 4 (* (+ 5) 6) (+ 1 2))') + w_num = eval_noctx("(+ 4 (* (+ 5) 6) (+ 1 2))") assert w_num.to_number() == 37 def test_ctx_simple(): - ctx = ExecutionContext({}) + ctx = ExecutionContext() ctx.put("v1", W_Fixnum(4)) ctx.put("v2", W_Fixnum(5)) From cfbolz at codespeak.net Mon Jun 25 19:43:44 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 25 Jun 2007 19:43:44 +0200 (CEST) Subject: [pypy-svn] r44520 - in pypy/dist/pypy/rlib/parsing: . test Message-ID: <20070625174344.C268380E9@code0.codespeak.net> Author: cfbolz Date: Mon Jun 25 19:43:44 2007 New Revision: 44520 Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py pypy/dist/pypy/rlib/parsing/pypackrat.py pypy/dist/pypy/rlib/parsing/regexparse.py pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py pypy/dist/pypy/rlib/parsing/test/test_translate.py Log: get the first translation test to run Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/makepackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/makepackrat.py Mon Jun 25 19:43:44 2007 @@ -1,11 +1,13 @@ import py import sys from pypy.rlib.parsing.tree import Nonterminal, Symbol, RPythonVisitor +from pypy.rlib.objectmodel import we_are_translated class BacktrackException(Exception): def __init__(self, error=None): self.error = error - Exception.__init__(self, error) + if not we_are_translated(): + Exception.__init__(self, error) class TreeOptimizer(RPythonVisitor): @@ -255,10 +257,17 @@ INPROGRESS = 2 LEFTRECURSION = 3 SOMESOLUTIONS = 4 + + _annspecialcase_ = 'specialize:ctr_location' # polymorphic def __repr__(self): return "Status(%s, %s, %s, %s)" % (self.pos, self.result, self.error, self.status) + def __init__(self): + self.pos = 0 + self.error = None + self.status = self.INPROGRESS + self.result = None class ParserBuilder(RPythonVisitor): def __init__(self): @@ -274,7 +283,7 @@ return "\n".join(self.code) def make_parser(self): - m = {'_Status': Status, + m = {'Status': Status, 'Nonterminal': Nonterminal, 'Symbol': Symbol,} exec py.code.Source(self.get_code()).compile() in m @@ -303,7 +312,6 @@ block, starterpart) def memoize_header(self, name, args): - statusclassname = "self._Status_%s" % (name, ) dictname = "_dict_%s" % (name, ) self.emit_initcode("self.%s = {}" % (dictname, )) if args: @@ -312,32 +320,33 @@ self.emit("_key = self._pos") self.emit("_status = self.%s.get(_key, None)" % (dictname, )) for _ in self.start_block("if _status is None:"): - self.emit("_status = self.%s[_key] = %s()" % ( - dictname, statusclassname)) - for _ in self.start_block("elif _status.status == _status.NORMAL:"): - self.emit("self._pos = _status.pos") - self.emit("return _status") - for _ in self.start_block("elif _status.status == _status.ERROR:"): - self.emit("raise self._BacktrackException(_status.error)") - for _ in self.start_block( - "elif (_status.status == _status.INPROGRESS or\n" - " _status.status == _status.LEFTRECURSION):"): - self.emit("_status.status = _status.LEFTRECURSION") - for _ in self.start_block("if _status.result is not None:"): + self.emit("_status = self.%s[_key] = Status()" % ( + dictname, )) + for _ in self.start_block("else:"): + self.emit("_statusstatus = _status.status") + for _ in self.start_block("if _statusstatus == _status.NORMAL:"): self.emit("self._pos = _status.pos") self.emit("return _status") - for _ in self.start_block("else:"): - self.emit("raise self._BacktrackException(None)") - for _ in self.start_block( - "elif _status.status == _status.SOMESOLUTIONS:"): - self.emit("_status.status = _status.INPROGRESS") + for _ in self.start_block("elif _statusstatus == _status.ERROR:"): + self.emit("raise BacktrackException(_status.error)") + for _ in self.start_block( + "elif (_statusstatus == _status.INPROGRESS or\n" + " _statusstatus == _status.LEFTRECURSION):"): + self.emit("_status.status = _status.LEFTRECURSION") + for _ in self.start_block("if _status.result is not None:"): + self.emit("self._pos = _status.pos") + self.emit("return _status") + for _ in self.start_block("else:"): + self.emit("raise BacktrackException(None)") + for _ in self.start_block( + "elif _statusstatus == _status.SOMESOLUTIONS:"): + self.emit("_status.status = _status.INPROGRESS") self.emit("_startingpos = self._pos") self.start_block("try:") self.emit("_result = None") self.emit("_error = None") def memoize_footer(self, name): - statusclassname = "self._Status_%s" % (name, ) dictname = "_dict_%s" % (name, ) for _ in self.start_block("if _status.status == _status.LEFTRECURSION:"): for _ in self.start_block("if _status.result is not None:"): @@ -357,13 +366,13 @@ self.emit("_status.error = _error") self.emit("return _status") self.end_block("try") - for _ in self.start_block("except self._BacktrackException, _exc:"): + for _ in self.start_block("except BacktrackException, _exc:"): self.emit("_status.pos = -1") self.emit("_status.result = None") self.emit("_error = self._combine_errors(_error, _exc.error)") self.emit("_status.error = _error") self.emit("_status.status = _status.ERROR") - self.emit("raise self._BacktrackException(_error)") + self.emit("raise BacktrackException(_error)") def choice_point(self, name=None): var = "_choice%s" % (self.namecount, ) @@ -374,16 +383,6 @@ def revert(self, var): self.emit("self._pos = %s" % (var, )) - def make_status_class(self, name): - classname = "_Status_%s" % (name, ) - for _ in self.start_block("class %s(_Status):" % (classname, )): - for _ in self.start_block("def __init__(self):"): - self.emit("self.pos = 0") - self.emit("self.error = None") - self.emit("self.status = self.INPROGRESS") - self.emit("self.result = None") - return classname - def visit_list(self, t): self.start_block("class Parser(object):") for elt in t.children: @@ -407,7 +406,7 @@ abs(hash(regex)), )) self.start_block("if _runner.last_matched_state == -1:") self.revert(c) - self.emit("raise self._BacktrackException") + self.emit("raise BacktrackException") self.end_block("if") self.emit("_upto = _runner.last_matched_index + 1") self.emit("_result = self._inputstream[self._pos: _upto]") @@ -432,7 +431,6 @@ if name in self.names: raise Exception("name %s appears twice" % (name, )) self.names[name] = True - self.make_status_class(name) otherargs = t.children[1].children argswithself = ", ".join(["self"] + otherargs) argswithoutself = ", ".join(otherargs) @@ -457,11 +455,11 @@ for _ in self.start_block("try:"): self.dispatch(p) self.emit("break") - for _ in self.start_block("except self._BacktrackException, _exc:"): + for _ in self.start_block("except BacktrackException, _exc:"): self.emit("_error = self._combine_errors(_error, _exc.error)") self.revert(c) if i == len(possibilities) - 1: - self.emit("raise self._BacktrackException(_error)") + self.emit("raise BacktrackException(_error)") self.dispatch(possibilities[-1]) if len(possibilities) > 1: self.emit("break") @@ -476,7 +474,7 @@ c = self.choice_point() for _ in self.start_block("try:"): self.dispatch(t.children[0]) - for _ in self.start_block("except self._BacktrackException:"): + for _ in self.start_block("except BacktrackException:"): self.revert(c) def visit_repetition(self, t): @@ -491,7 +489,7 @@ for _ in self.start_block("try:"): self.dispatch(t.children[1]) self.emit("%s.append(_result)" % (name, )) - for _ in self.start_block("except self._BacktrackException, _exc:"): + for _ in self.start_block("except BacktrackException, _exc:"): self.emit("_error = self._combine_errors(_error, _exc.error)") self.revert(c) self.emit("break") @@ -517,7 +515,7 @@ self.emit("%s = _result" % (resultname, )) for _ in self.start_block("try:"): self.dispatch(child) - for _ in self.start_block("except self._BacktrackException:"): + for _ in self.start_block("except BacktrackException:"): self.revert(c) self.emit("_result = %s" % (resultname, )) for _ in self.start_block("else:"): @@ -528,7 +526,7 @@ c, child.additional_info[1:-1], ) else: error = "None" - self.emit("raise self._BacktrackException(%s)" % (error, )) + self.emit("raise BacktrackException(%s)" % (error, )) def visit_lookahead(self, t): resultname = "_stored_result%i" % (self.namecount, ) @@ -551,7 +549,7 @@ self.dispatch(t.children[0]) for _ in self.start_block("if not (%s):" % ( t.children[-1].additional_info[1:-1], )): - self.emit("raise self._BacktrackException(") + self.emit("raise BacktrackException(") self.emit(" self._ErrorInformation(") self.emit(" _startingpos, ['condition not met']))") @@ -619,6 +617,9 @@ "__dict__ __module__").split()) initthere = "__init__" in dct + #XXX XXX XXX + if 'BacktrackException' not in frame.f_globals: + raise Exception("must import BacktrackException") for key, value in pcls.__dict__.iteritems(): if isinstance(value, type(lambda: None)): value = new.function(value.func_code, frame.f_globals) @@ -631,7 +632,6 @@ class PackratParser(object): __metaclass__ = MetaPackratParser - _Status = Status _ErrorInformation = ErrorInformation _BacktrackException = BacktrackException @@ -640,12 +640,12 @@ try: for i in range(len(chars)): if self._inputstream[self._pos + i] != chars[i]: - raise self._BacktrackException( + raise BacktrackException( self._ErrorInformation(self._pos, [chars])) self._pos += len(chars) return chars except IndexError: - raise self._BacktrackException( + raise BacktrackException( self._ErrorInformation(self._pos, [chars])) def __any__(self): @@ -654,7 +654,7 @@ self._pos += 1 return result except IndexError: - raise self._BacktrackException( + raise BacktrackException( self._ErrorInformation(self._pos, ['anything'])) def _combine_errors(self, error1, error2): @@ -686,7 +686,7 @@ code = visitor.get_code() content = """ from pypy.rlib.parsing.tree import Nonterminal, Symbol -from makepackrat import PackratParser, BacktrackException, Status as _Status +from makepackrat import PackratParser, BacktrackException, Status %s class PyPackratSyntaxParser(PackratParser): def __init__(self, stream): Modified: pypy/dist/pypy/rlib/parsing/pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/pypackrat.py Mon Jun 25 19:43:44 2007 @@ -1,25 +1,19 @@ from pypy.rlib.parsing.tree import Nonterminal, Symbol -from makepackrat import PackratParser, BacktrackException, Status as _Status +from makepackrat import PackratParser, BacktrackException, Status class Parser(object): - class _Status_NAME(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None def NAME(self): return self._NAME().result def _NAME(self): _key = self._pos _status = self._dict_NAME.get(_key, None) if _status is None: - _status = self._dict_NAME[_key] = self._Status_NAME() + _status = self._dict_NAME[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -27,7 +21,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -52,31 +46,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_SPACE(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def SPACE(self): return self._SPACE().result def _SPACE(self): _key = self._pos _status = self._dict_SPACE.get(_key, None) if _status is None: - _status = self._dict_SPACE[_key] = self._Status_SPACE() + _status = self._dict_SPACE[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -84,7 +72,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -109,31 +97,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_COMMENT(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def COMMENT(self): return self._COMMENT().result def _COMMENT(self): _key = self._pos _status = self._dict_COMMENT.get(_key, None) if _status is None: - _status = self._dict_COMMENT[_key] = self._Status_COMMENT() + _status = self._dict_COMMENT[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -141,7 +123,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -166,31 +148,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_IGNORE(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def IGNORE(self): return self._IGNORE().result def _IGNORE(self): _key = self._pos _status = self._dict_IGNORE.get(_key, None) if _status is None: - _status = self._dict_IGNORE[_key] = self._Status_IGNORE() + _status = self._dict_IGNORE[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -198,7 +174,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -223,31 +199,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_newline(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def newline(self): return self._newline().result def _newline(self): _key = self._pos _status = self._dict_newline.get(_key, None) if _status is None: - _status = self._dict_newline[_key] = self._Status_newline() + _status = self._dict_newline[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -255,7 +225,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -270,17 +240,17 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice0 _choice1 = self._pos try: _result = self._regex299149370() break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice1 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _result = self._regex299149370() break if _status.status == _status.LEFTRECURSION: @@ -300,31 +270,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_REGEX(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def REGEX(self): return self._REGEX().result def _REGEX(self): _key = self._pos _status = self._dict_REGEX.get(_key, None) if _status is None: - _status = self._dict_REGEX[_key] = self._Status_REGEX() + _status = self._dict_REGEX[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -332,7 +296,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -359,31 +323,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_QUOTE(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def QUOTE(self): return self._QUOTE().result def _QUOTE(self): _key = self._pos _status = self._dict_QUOTE.get(_key, None) if _status is None: - _status = self._dict_QUOTE[_key] = self._Status_QUOTE() + _status = self._dict_QUOTE[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -391,7 +349,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -418,31 +376,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_PYTHONCODE(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def PYTHONCODE(self): return self._PYTHONCODE().result def _PYTHONCODE(self): _key = self._pos _status = self._dict_PYTHONCODE.get(_key, None) if _status is None: - _status = self._dict_PYTHONCODE[_key] = self._Status_PYTHONCODE() + _status = self._dict_PYTHONCODE[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -450,7 +402,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -477,31 +429,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_EOF(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def EOF(self): return self._EOF().result def _EOF(self): _key = self._pos _status = self._dict_EOF.get(_key, None) if _status is None: - _status = self._dict_EOF[_key] = self._Status_EOF() + _status = self._dict_EOF[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -509,7 +455,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -520,11 +466,11 @@ _stored_result3 = _result try: _result = self.__any__() - except self._BacktrackException: + except BacktrackException: self._pos = _choice2 _result = _stored_result3 else: - raise self._BacktrackException(None) + raise BacktrackException(None) if _status.status == _status.LEFTRECURSION: if _status.result is not None: if _status.pos >= self._pos: @@ -542,31 +488,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_file(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def file(self): return self._file().result def _file(self): _key = self._pos _status = self._dict_file.get(_key, None) if _status is None: - _status = self._dict_file[_key] = self._Status_file() + _status = self._dict_file[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -574,7 +514,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -589,7 +529,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all4.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice5 break @@ -619,31 +559,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_list(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def list(self): return self._list().result def _list(self): _key = self._pos _status = self._dict_list.get(_key, None) if _status is None: - _status = self._dict_list[_key] = self._Status_list() + _status = self._dict_list[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -651,7 +585,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -670,7 +604,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all7.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice8 break @@ -694,31 +628,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_production(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def production(self): return self._production().result def _production(self): _key = self._pos _status = self._dict_production.get(_key, None) if _status is None: - _status = self._dict_production[_key] = self._Status_production() + _status = self._dict_production[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -726,7 +654,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -745,7 +673,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all9.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice10 break @@ -763,7 +691,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all11.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice12 break @@ -780,7 +708,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all13.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice14 break @@ -794,7 +722,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all15.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice16 break @@ -817,31 +745,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_productionargs(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def productionargs(self): return self._productionargs().result def _productionargs(self): _key = self._pos _status = self._dict_productionargs.get(_key, None) if _status is None: - _status = self._dict_productionargs[_key] = self._Status_productionargs() + _status = self._dict_productionargs[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -849,7 +771,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -869,7 +791,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all18.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice19 break @@ -890,7 +812,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all23.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice24 break @@ -904,14 +826,14 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all25.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice26 break _result = _all25 _result = _before_discard22 _all20.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice21 break @@ -929,7 +851,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all27.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice28 break @@ -943,24 +865,24 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all29.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice30 break _result = _all29 _result = (Nonterminal('productionargs', args + [arg])) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice17 _choice31 = self._pos try: _result = (Nonterminal('productionargs', [])) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice31 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _result = (Nonterminal('productionargs', [])) break if _status.status == _status.LEFTRECURSION: @@ -980,31 +902,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_or_(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def or_(self): return self._or_().result def _or_(self): _key = self._pos _status = self._dict_or_.get(_key, None) if _status is None: - _status = self._dict_or_[_key] = self._Status_or_() + _status = self._dict_or_[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -1012,7 +928,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -1037,7 +953,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all35.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice36 break @@ -1060,14 +976,14 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all39.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice40 break _result = _all39 _result = _before_discard38 _all33.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice37 break @@ -1079,7 +995,7 @@ last = _result _result = (Nonterminal('or', l + [last])) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice32 _choice41 = self._pos @@ -1088,10 +1004,10 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice41 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _call_status = self._commands() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -1113,31 +1029,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_commands(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def commands(self): return self._commands().result def _commands(self): _key = self._pos _status = self._dict_commands.get(_key, None) if _status is None: - _status = self._dict_commands[_key] = self._Status_commands() + _status = self._dict_commands[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -1145,7 +1055,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -1185,7 +1095,7 @@ _error = self._combine_errors(_call_status.error, _error) _result = _before_discard46 _all43.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice45 break @@ -1193,7 +1103,7 @@ cmds = _result _result = (Nonterminal('commands', [cmd] + cmds)) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice42 _choice47 = self._pos @@ -1202,10 +1112,10 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice47 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _call_status = self._command() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -1227,31 +1137,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_command(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def command(self): return self._command().result def _command(self): _key = self._pos _status = self._dict_command.get(_key, None) if _status is None: - _status = self._dict_command[_key] = self._Status_command() + _status = self._dict_command[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -1259,7 +1163,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -1286,31 +1190,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_simplecommand(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def simplecommand(self): return self._simplecommand().result def _simplecommand(self): _key = self._pos _status = self._dict_simplecommand.get(_key, None) if _status is None: - _status = self._dict_simplecommand[_key] = self._Status_simplecommand() + _status = self._dict_simplecommand[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -1318,7 +1216,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -1333,7 +1231,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice48 _choice49 = self._pos @@ -1342,7 +1240,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice49 _choice50 = self._pos @@ -1351,7 +1249,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice50 _choice51 = self._pos @@ -1360,7 +1258,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice51 _choice52 = self._pos @@ -1369,7 +1267,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice52 _choice53 = self._pos @@ -1378,10 +1276,10 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice53 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _call_status = self._negation() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -1403,31 +1301,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_return_(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def return_(self): return self._return_().result def _return_(self): _key = self._pos _status = self._dict_return_.get(_key, None) if _status is None: - _status = self._dict_return_[_key] = self._Status_return_() + _status = self._dict_return_[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -1435,7 +1327,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -1451,7 +1343,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all54.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice55 break @@ -1468,7 +1360,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all56.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice57 break @@ -1491,31 +1383,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_if_(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def if_(self): return self._if_().result def _if_(self): _key = self._pos _status = self._dict_if_.get(_key, None) if _status is None: - _status = self._dict_if_[_key] = self._Status_if_() + _status = self._dict_if_[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -1523,7 +1409,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -1550,7 +1436,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all59.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice60 break @@ -1564,7 +1450,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all61.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice62 break @@ -1581,14 +1467,14 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all63.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice64 break _result = _all63 _result = (Nonterminal('if', [cmd, condition])) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice58 _choice65 = self._pos @@ -1602,7 +1488,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all66.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice67 break @@ -1619,17 +1505,17 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all68.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice69 break _result = _all68 _result = (Nonterminal('if', [condition])) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice65 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _result = self.__chars__('if') _all70 = [] while 1: @@ -1639,7 +1525,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all70.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice71 break @@ -1656,7 +1542,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all72.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice73 break @@ -1680,31 +1566,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_choose(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def choose(self): return self._choose().result def _choose(self): _key = self._pos _status = self._dict_choose.get(_key, None) if _status is None: - _status = self._dict_choose[_key] = self._Status_choose() + _status = self._dict_choose[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -1712,7 +1592,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -1728,7 +1608,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all74.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice75 break @@ -1745,7 +1625,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all76.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice77 break @@ -1759,7 +1639,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all78.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice79 break @@ -1776,7 +1656,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all80.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice81 break @@ -1803,31 +1683,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_commandchain(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def commandchain(self): return self._commandchain().result def _commandchain(self): _key = self._pos _status = self._dict_commandchain.get(_key, None) if _status is None: - _status = self._dict_commandchain[_key] = self._Status_commandchain() + _status = self._dict_commandchain[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -1835,7 +1709,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -1854,7 +1728,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all82.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice83 break @@ -1878,31 +1752,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_named_command(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def named_command(self): return self._named_command().result def _named_command(self): _key = self._pos _status = self._dict_named_command.get(_key, None) if _status is None: - _status = self._dict_named_command[_key] = self._Status_named_command() + _status = self._dict_named_command[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -1910,7 +1778,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -1929,7 +1797,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all84.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice85 break @@ -1943,7 +1811,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all86.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice87 break @@ -1970,31 +1838,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_repetition(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def repetition(self): return self._repetition().result def _repetition(self): _key = self._pos _status = self._dict_repetition.get(_key, None) if _status is None: - _status = self._dict_repetition[_key] = self._Status_repetition() + _status = self._dict_repetition[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -2002,7 +1864,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -2025,7 +1887,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all89.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice90 break @@ -2039,14 +1901,14 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all91.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice92 break _result = _all91 _result = (Nonterminal('maybe', [what])) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice88 _choice93 = self._pos @@ -2063,7 +1925,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all94.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice95 break @@ -2074,17 +1936,17 @@ try: _result = self.__chars__('*') break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice96 _choice97 = self._pos try: _result = self.__chars__('+') break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice97 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _result = self.__chars__('+') break repetition = _result @@ -2096,17 +1958,17 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all98.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice99 break _result = _all98 _result = (Nonterminal('repetition', [repetition, what])) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice93 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -2119,7 +1981,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all100.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice101 break @@ -2130,17 +1992,17 @@ try: _result = self.__chars__('*') break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice102 _choice103 = self._pos try: _result = self.__chars__('+') break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice103 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _result = self.__chars__('+') break repetition = _result @@ -2152,7 +2014,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all104.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice105 break @@ -2176,31 +2038,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_negation(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def negation(self): return self._negation().result def _negation(self): _key = self._pos _status = self._dict_negation.get(_key, None) if _status is None: - _status = self._dict_negation[_key] = self._Status_negation() + _status = self._dict_negation[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -2208,7 +2064,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -2228,7 +2084,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all107.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice108 break @@ -2245,14 +2101,14 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all109.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice110 break _result = _all109 _result = (Nonterminal('negation', [what])) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice106 _choice111 = self._pos @@ -2261,10 +2117,10 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice111 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -2286,31 +2142,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_enclosed(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def enclosed(self): return self._enclosed().result def _enclosed(self): _key = self._pos _status = self._dict_enclosed.get(_key, None) if _status is None: - _status = self._dict_enclosed[_key] = self._Status_enclosed() + _status = self._dict_enclosed[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -2318,7 +2168,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -2338,7 +2188,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all113.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice114 break @@ -2355,7 +2205,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all115.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice116 break @@ -2369,14 +2219,14 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all117.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice118 break _result = _all117 _result = (Nonterminal('exclusive', [what])) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice112 _choice119 = self._pos @@ -2390,7 +2240,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all120.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice121 break @@ -2407,7 +2257,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all122.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice123 break @@ -2421,14 +2271,14 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all124.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice125 break _result = _all124 _result = (Nonterminal('ignore', [what])) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice119 _choice126 = self._pos @@ -2443,7 +2293,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all128.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice129 break @@ -2462,14 +2312,14 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all131.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice132 break _result = _all131 _result = _before_discard130 break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice126 _choice133 = self._pos @@ -2478,10 +2328,10 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice133 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _call_status = self._primary() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -2503,31 +2353,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_primary(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def primary(self): return self._primary().result def _primary(self): _key = self._pos _status = self._dict_primary.get(_key, None) if _status is None: - _status = self._dict_primary[_key] = self._Status_primary() + _status = self._dict_primary[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -2535,7 +2379,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -2550,7 +2394,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice134 _choice135 = self._pos @@ -2567,14 +2411,14 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all137.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice138 break _result = _all137 _result = _before_discard136 break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice135 _choice139 = self._pos @@ -2591,17 +2435,17 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all141.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice142 break _result = _all141 _result = _before_discard140 break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice139 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _call_status = self._QUOTE() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -2614,7 +2458,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all144.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice145 break @@ -2638,31 +2482,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_call(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def call(self): return self._call().result def _call(self): _key = self._pos _status = self._dict_call.get(_key, None) if _status is None: - _status = self._dict_call[_key] = self._Status_call() + _status = self._dict_call[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -2670,7 +2508,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -2693,7 +2531,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all146.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice147 break @@ -2716,31 +2554,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_arguments(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def arguments(self): return self._arguments().result def _arguments(self): _key = self._pos _status = self._dict_arguments.get(_key, None) if _status is None: - _status = self._dict_arguments[_key] = self._Status_arguments() + _status = self._dict_arguments[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -2748,7 +2580,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -2768,7 +2600,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all149.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice150 break @@ -2789,7 +2621,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all154.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice155 break @@ -2803,14 +2635,14 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all156.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice157 break _result = _all156 _result = _before_discard153 _all151.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice152 break @@ -2829,24 +2661,24 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all158.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice159 break _result = _all158 _result = (Nonterminal("args", args + [last])) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice148 _choice160 = self._pos try: _result = (Nonterminal("args", [])) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice160 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _result = (Nonterminal("args", [])) break if _status.status == _status.LEFTRECURSION: @@ -2866,13 +2698,13 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) + raise BacktrackException(_error) def __init__(self, inputstream): self._dict_NAME = {} self._dict_SPACE = {} @@ -2910,7 +2742,7 @@ _i = _runner.recognize_299149370(self._pos) if _runner.last_matched_state == -1: self._pos = _choice161 - raise self._BacktrackException + raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto @@ -2921,7 +2753,7 @@ _i = _runner.recognize_1006631623(self._pos) if _runner.last_matched_state == -1: self._pos = _choice162 - raise self._BacktrackException + raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto @@ -2932,7 +2764,7 @@ _i = _runner.recognize_528667127(self._pos) if _runner.last_matched_state == -1: self._pos = _choice163 - raise self._BacktrackException + raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto @@ -2943,7 +2775,7 @@ _i = _runner.recognize_291086639(self._pos) if _runner.last_matched_state == -1: self._pos = _choice164 - raise self._BacktrackException + raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto @@ -2954,7 +2786,7 @@ _i = _runner.recognize_1074651696(self._pos) if _runner.last_matched_state == -1: self._pos = _choice165 - raise self._BacktrackException + raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto @@ -2965,7 +2797,7 @@ _i = _runner.recognize_1124192327(self._pos) if _runner.last_matched_state == -1: self._pos = _choice166 - raise self._BacktrackException + raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto @@ -2976,7 +2808,7 @@ _i = _runner.recognize_1979538501(self._pos) if _runner.last_matched_state == -1: self._pos = _choice167 - raise self._BacktrackException + raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto Modified: pypy/dist/pypy/rlib/parsing/regexparse.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/regexparse.py (original) +++ pypy/dist/pypy/rlib/parsing/regexparse.py Mon Jun 25 19:43:44 2007 @@ -1,3 +1,8 @@ + + + + + import py from pypy.rlib.parsing.parsing import PackratParser, Rule from pypy.rlib.parsing.tree import Nonterminal @@ -188,30 +193,31 @@ + + + + + # generated code between this line and its other occurence -from pypy.rlib.parsing.pypackrat import PackratParser, _Status +from pypy.rlib.parsing.pypackrat import PackratParser, Status +from pypy.rlib.parsing.pypackrat import BacktrackException from pypy.rlib.parsing import regex import operator class Parser(object): - class _Status_EOF(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None def EOF(self): return self._EOF().result def _EOF(self): - _status = self._dict_EOF.get(self._pos, None) + _key = self._pos + _status = self._dict_EOF.get(_key, None) if _status is None: - _status = self._dict_EOF[self._pos] = self._Status_EOF() + _status = self._dict_EOF[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -219,7 +225,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -230,11 +236,11 @@ _stored_result1 = _result try: _result = self.__any__() - except self._BacktrackException: + except BacktrackException: self._pos = _choice0 _result = _stored_result1 else: - raise self._BacktrackException(None) + raise BacktrackException(None) if _status.status == _status.LEFTRECURSION: if _status.result is not None: if _status.pos >= self._pos: @@ -252,30 +258,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_parse(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def parse(self): return self._parse().result def _parse(self): - _status = self._dict_parse.get(self._pos, None) + _key = self._pos + _status = self._dict_parse.get(_key, None) if _status is None: - _status = self._dict_parse[self._pos] = self._Status_parse() + _status = self._dict_parse[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -283,7 +284,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -315,30 +316,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_regex(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def regex(self): return self._regex().result def _regex(self): - _status = self._dict_regex.get(self._pos, None) + _key = self._pos + _status = self._dict_regex.get(_key, None) if _status is None: - _status = self._dict_regex[self._pos] = self._Status_regex() + _status = self._dict_regex[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -346,7 +342,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -368,7 +364,7 @@ r2 = _result _result = (r1 | r2) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice3 _choice4 = self._pos @@ -377,10 +373,10 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice4 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _call_status = self._concatenation() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -402,30 +398,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_concatenation(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def concatenation(self): return self._concatenation().result def _concatenation(self): - _status = self._dict_concatenation.get(self._pos, None) + _key = self._pos + _status = self._dict_concatenation.get(_key, None) if _status is None: - _status = self._dict_concatenation[self._pos] = self._Status_concatenation() + _status = self._dict_concatenation[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -433,7 +424,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -452,7 +443,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all5.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice6 break @@ -476,30 +467,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_repetition(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def repetition(self): return self._repetition().result def _repetition(self): - _status = self._dict_repetition.get(self._pos, None) + _key = self._pos + _status = self._dict_repetition.get(_key, None) if _status is None: - _status = self._dict_repetition[self._pos] = self._Status_repetition() + _status = self._dict_repetition[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -507,7 +493,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -525,7 +511,7 @@ _result = self.__chars__('*') _result = (r1.kleene()) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice7 _choice8 = self._pos @@ -537,7 +523,7 @@ _result = self.__chars__('+') _result = (r1 + r1.kleene()) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice8 _choice9 = self._pos @@ -549,7 +535,7 @@ _result = self.__chars__('?') _result = (regex.StringExpression("") | r1) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice9 _choice10 = self._pos @@ -566,7 +552,7 @@ _result = self.__chars__('}') _result = (r * n[0] + reduce(operator.or_, [r * i for i in range(n[1] - n[0] + 1)], regex.StringExpression(""))) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice10 _choice11 = self._pos @@ -575,10 +561,10 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice11 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _call_status = self._primary() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -600,30 +586,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_primary(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def primary(self): return self._primary().result def _primary(self): - _status = self._dict_primary.get(self._pos, None) + _key = self._pos + _status = self._dict_primary.get(_key, None) if _status is None: - _status = self._dict_primary[self._pos] = self._Status_primary() + _status = self._dict_primary[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -631,7 +612,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -652,7 +633,7 @@ _result = self.__chars__(')') _result = _before_discard14 break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice12 _choice15 = self._pos @@ -661,7 +642,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice15 _choice16 = self._pos @@ -672,7 +653,7 @@ c = _result _result = (regex.StringExpression(c)) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice16 _choice17 = self._pos @@ -680,10 +661,10 @@ _result = self.__chars__('.') _result = (regex.RangeExpression(chr(0), chr(255))) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice17 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _result = self.__chars__('.') _result = (regex.RangeExpression(chr(0), chr(255))) break @@ -704,30 +685,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_char(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def char(self): return self._char().result def _char(self): - _status = self._dict_char.get(self._pos, None) + _key = self._pos + _status = self._dict_char.get(_key, None) if _status is None: - _status = self._dict_char[self._pos] = self._Status_char() + _status = self._dict_char[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -735,7 +711,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -752,7 +728,7 @@ c = _result _result = (unescape(c)) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice18 _choice19 = self._pos @@ -763,10 +739,10 @@ c = _result _result = (c) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice19 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _call_status = self._CHAR() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -790,30 +766,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_QUOTEDCHAR(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def QUOTEDCHAR(self): return self._QUOTEDCHAR().result def _QUOTEDCHAR(self): - _status = self._dict_QUOTEDCHAR.get(self._pos, None) + _key = self._pos + _status = self._dict_QUOTEDCHAR.get(_key, None) if _status is None: - _status = self._dict_QUOTEDCHAR[self._pos] = self._Status_QUOTEDCHAR() + _status = self._dict_QUOTEDCHAR[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -821,7 +792,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -846,30 +817,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_CHAR(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def CHAR(self): return self._CHAR().result def _CHAR(self): - _status = self._dict_CHAR.get(self._pos, None) + _key = self._pos + _status = self._dict_CHAR.get(_key, None) if _status is None: - _status = self._dict_CHAR[self._pos] = self._Status_CHAR() + _status = self._dict_CHAR[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -877,7 +843,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -902,30 +868,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_range(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def range(self): return self._range().result def _range(self): - _status = self._dict_range.get(self._pos, None) + _key = self._pos + _status = self._dict_range.get(_key, None) if _status is None: - _status = self._dict_range[self._pos] = self._Status_range() + _status = self._dict_range[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -933,7 +894,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -964,30 +925,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_rangeinner(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def rangeinner(self): return self._rangeinner().result def _rangeinner(self): - _status = self._dict_rangeinner.get(self._pos, None) + _key = self._pos + _status = self._dict_rangeinner.get(_key, None) if _status is None: - _status = self._dict_rangeinner[self._pos] = self._Status_rangeinner() + _status = self._dict_rangeinner[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -995,7 +951,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -1013,7 +969,7 @@ s = _result _result = (set([chr(c) for c in range(256)]) - s) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice20 _choice21 = self._pos @@ -1022,10 +978,10 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice21 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _call_status = self._subrange() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -1047,30 +1003,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_subrange(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def subrange(self): return self._subrange().result def _subrange(self): - _status = self._dict_subrange.get(self._pos, None) + _key = self._pos + _status = self._dict_subrange.get(_key, None) if _status is None: - _status = self._dict_subrange[self._pos] = self._Status_subrange() + _status = self._dict_subrange[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -1078,7 +1029,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -1097,7 +1048,7 @@ _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) _all22.append(_result) - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice23 break @@ -1121,30 +1072,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_rangeelement(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def rangeelement(self): return self._rangeelement().result def _rangeelement(self): - _status = self._dict_rangeelement.get(self._pos, None) + _key = self._pos + _status = self._dict_rangeelement.get(_key, None) if _status is None: - _status = self._dict_rangeelement[self._pos] = self._Status_rangeelement() + _status = self._dict_rangeelement[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -1152,7 +1098,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -1174,7 +1120,7 @@ c2 = _result _result = (set([chr(i) for i in range(ord(c1), ord(c2) + 1)])) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice24 _choice25 = self._pos @@ -1185,10 +1131,10 @@ c = _result _result = (set([c])) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice25 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _call_status = self._char() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -1212,30 +1158,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_numrange(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def numrange(self): return self._numrange().result def _numrange(self): - _status = self._dict_numrange.get(self._pos, None) + _key = self._pos + _status = self._dict_numrange.get(_key, None) if _status is None: - _status = self._dict_numrange[self._pos] = self._Status_numrange() + _status = self._dict_numrange[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -1243,7 +1184,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -1265,7 +1206,7 @@ n2 = _result _result = (n1, n2) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice26 _choice27 = self._pos @@ -1276,10 +1217,10 @@ n1 = _result _result = (n1, n1) break - except self._BacktrackException, _exc: + except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) self._pos = _choice27 - raise self._BacktrackException(_error) + raise BacktrackException(_error) _call_status = self._NUM() _result = _call_status.result _error = self._combine_errors(_call_status.error, _error) @@ -1303,30 +1244,25 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) - class _Status_NUM(_Status): - def __init__(self): - self.pos = 0 - self.error = None - self.status = self.INPROGRESS - self.result = None + raise BacktrackException(_error) def NUM(self): return self._NUM().result def _NUM(self): - _status = self._dict_NUM.get(self._pos, None) + _key = self._pos + _status = self._dict_NUM.get(_key, None) if _status is None: - _status = self._dict_NUM[self._pos] = self._Status_NUM() + _status = self._dict_NUM[_key] = Status() elif _status.status == _status.NORMAL: self._pos = _status.pos return _status elif _status.status == _status.ERROR: - raise self._BacktrackException(_status.error) + raise BacktrackException(_status.error) elif (_status.status == _status.INPROGRESS or _status.status == _status.LEFTRECURSION): _status.status = _status.LEFTRECURSION @@ -1334,7 +1270,7 @@ self._pos = _status.pos return _status else: - raise self._BacktrackException(None) + raise BacktrackException(None) elif _status.status == _status.SOMESOLUTIONS: _status.status = _status.INPROGRESS _startingpos = self._pos @@ -1361,13 +1297,13 @@ _status.result = _result _status.error = _error return _status - except self._BacktrackException, _exc: + except BacktrackException, _exc: _status.pos = -1 _status.result = None _error = self._combine_errors(_error, _exc.error) _status.error = _error _status.status = _status.ERROR - raise self._BacktrackException(_error) + raise BacktrackException(_error) def __init__(self, inputstream): self._dict_EOF = {} self._dict_parse = {} @@ -1392,7 +1328,7 @@ _i = _runner.recognize_1166214427(self._pos) if _runner.last_matched_state == -1: self._pos = _choice28 - raise self._BacktrackException + raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto @@ -1403,7 +1339,7 @@ _i = _runner.recognize_1323868075(self._pos) if _runner.last_matched_state == -1: self._pos = _choice29 - raise self._BacktrackException + raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto @@ -1414,7 +1350,7 @@ _i = _runner.recognize_1380912319(self._pos) if _runner.last_matched_state == -1: self._pos = _choice30 - raise self._BacktrackException + raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto @@ -1438,23 +1374,23 @@ else: runner.state = 0 return ~i - if char == '0': + if '1' <= char <= '9': state = 1 - elif '1' <= char <= '9': + elif char == '0': state = 2 else: break - if state == 2: + if state == 1: runner.last_matched_index = i - 1 runner.last_matched_state = state if i < len(input): char = input[i] i += 1 else: - runner.state = 2 + runner.state = 1 return i if '0' <= char <= '9': - state = 2 + state = 1 continue else: break @@ -1517,7 +1453,7 @@ runner.state = 0 return ~i if char == '\\': - state = 4 + state = 1 else: break if state == 1: @@ -1527,11 +1463,11 @@ else: runner.state = 1 return ~i - if '0' <= char <= '9': - state = 3 - elif 'A' <= char <= 'F': + if char == 'x': + state = 2 + elif '\x00' <= char <= 'w': state = 3 - elif 'a' <= char <= 'f': + elif 'y' <= char <= '\xff': state = 3 else: break @@ -1545,14 +1481,11 @@ runner.state = 2 return i if '0' <= char <= '9': - state = 1 - continue + state = 4 elif 'A' <= char <= 'F': - state = 1 - continue + state = 4 elif 'a' <= char <= 'f': - state = 1 - continue + state = 4 else: break if state == 4: @@ -1562,12 +1495,11 @@ else: runner.state = 4 return ~i - if char == 'x': - state = 2 - continue - elif '\x00' <= char <= 'w': + if '0' <= char <= '9': state = 3 - elif 'y' <= char <= '\xff': + elif 'A' <= char <= 'F': + state = 3 + elif 'a' <= char <= 'f': state = 3 else: break @@ -1600,7 +1532,12 @@ -if __name__ == '__main__': + + + + + +def test_generate(): f = py.magic.autopath() oldcontent = f.read() s = "# GENERATED CODE BETWEEN THIS LINE AND ITS OTHER OCCURENCE\n".lower() @@ -1618,7 +1555,8 @@ %s %s -from pypy.rlib.parsing.pypackrat import PackratParser, _Status +from pypy.rlib.parsing.pypackrat import PackratParser, Status +from pypy.rlib.parsing.pypackrat import BacktrackException from pypy.rlib.parsing import regex import operator %s @@ -1641,4 +1579,3 @@ - Modified: pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Mon Jun 25 19:43:44 2007 @@ -432,3 +432,168 @@ expected.sort() assert expected == ['a', 'x', 'y'] + def test_prolog(self): + py.test.skip() + class PrologParser(PackratParser): + r""" + VAR: + `[A-Z_]([a-zA-Z0-9]|_)*|_`; + + NUMBER: + `(0|[1-9][0-9]*)(\.[0-9]+)?`; + + IGNORE: + `[ \\n\\t]|(/\\*[^\\*]*(\\*[^/][^\\*]*)*\\*/)|(%[^\\n]*)`; + + ATOM: + `([a-z]([a-zA-Z0-9]|_)*)|('[^']*')|\[\]|!|\+|\-`; + + EOF: + !__any__; + + fact: + toplevel_op_expr ['.']; + + simple: + VAR + [IGNORE*] + | sign = ('+' | '-') + IGNORE* + num = NUMBER + IGNORE* + return {XXX} + | ATOM + [IGNORE*] + | '(' + IGNORE* + expr = toplevel_op_expr + ')' + IGNORE* + return {expr}; + | listexpr; + + listexpr: + '[' + IGNORE* + body = listbody + ']' + return {body}; + + listbody: + head = toplevel_op_expr + '|' + tail = toplevel_op_expr + return {XXX} + | list = toplevel_op_expr + return {XXX}; + + toplevel_op_expr: + choose priority in {range(len(self.ops))} + expr(priority); + + expr(priority): + if {priority < len(self.ops)} + choose patternindex in {range(len(self.ops[priority]))} + expr_pattern({priority}, {patternindex}) + | simple; + + expr_pattern(priority, patternindex): + choose operator in {self.ops[priority][patternindex]} + args = pattern({priority}, {self.pattern[patternindex]}, + {operator}) + return {Term(operator, args)}; + + pattern(priority, pattern, operator): + loop({priority}, {pattern}, {operator}, {0}); + + loop(priority, pattern, operator, index): + ( + if {pattern[index] == 'f'} + args1 = op({operator}) + | if {pattern[index] == 'x'} + args1 = lower({priority}) + | if {pattern[index] == 'y'} + args1 = same({priority}) + ) + args2 = loop( + + op(operator): + __chars__({self.ops[priority].xfx[pos]}) + return {[]} + + xfx(priority, pos): + expr1 = expr({priority + 1}) + IGNORE* + op = __chars__({self.ops[priority].xfx[pos]}) + IGNORE* + expr2 = expr({priority + 1}) + return {Term(op, [expr1, expr2])} + | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} + xfx({priority}, {pos + 1}); + + xfy(priority, pos): + expr1 = expr({priority + 1}) + IGNORE* + op = __chars__({self.ops[priority].xfx[pos]}) + IGNORE* + expr2 = expr({priority}) + return {Term(op, [expr1, expr2])} + | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} + xfx({priority}, {pos + 1}); + + yfx(priority, pos): + expr1 = expr({priority + 1}) + IGNORE* + op = __chars__({self.ops[priority].xfx[pos]}) + IGNORE* + expr2 = expr({priority}) + return {Term(op, [expr1, expr2])} + | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} + xfx({priority}, {pos + 1}); + + yfy(priority, pos): + expr1 = expr({priority}) + IGNORE* + op = __chars__({self.ops[priority].xfx[pos]}) + IGNORE* + expr2 = expr({priority}) + return {Term(op, [expr1, expr2])} + | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} + xfx({priority}, {pos + 1}); + + fx(priority, pos): + op = __chars__({self.ops[priority].fx[pos]}) + IGNORE* + ex = expr({priority + 1}) + return {Term(op, [ex])} + | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} + xfx({priority}, {pos + 1}); + + fy(priority, pos): + op = __chars__({self.ops[priority].xfx[pos]}) + IGNORE* + ex = expr({priority}) + return {Term(op, [ex])} + | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} + xfx({priority}, {pos + 1}); + + xf(priority, pos): + op = __chars__({self.ops[priority].xfx[pos]}) + IGNORE* + expr2 = expr({priority + 1}) + return {Term(op, [expr1, expr2])} + | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} + xfx({priority}, {pos + 1}); + + yf(priority, pos): + ex = expr({priority + 1}) + IGNORE* + op = __chars__({self.ops[priority].xfx[pos]}) + IGNORE* + expr2 = expr({priority + 1}) + return {Term(op, [expr1, expr2])} + | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} + xfx({priority}, {pos + 1}); + + + """ Modified: pypy/dist/pypy/rlib/parsing/test/test_translate.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_translate.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_translate.py Mon Jun 25 19:43:44 2007 @@ -4,6 +4,7 @@ from pypy.rlib.parsing.regex import * from pypy.rlib.parsing.parsing import * from pypy.rlib.parsing import deterministic +from pypy.rlib.parsing.pypackrat import BacktrackException, Status class TestTranslateLexer(object): @@ -120,3 +121,39 @@ func = t.compile_c() res2 = func() assert res1 == res2 + +def test_translate_pypackrat(): + from pypy.rlib.parsing.pypackrat import PackratParser + class parser(PackratParser): + """ + expr: + additive; + additive: + a = additive + '-' + b = multitive + return {'(%s - %s)' % (a, b)} + | multitive; + multitive: + a = multitive + '*' + b = simple + return {'(%s * %s)' % (a, b)} + | simple; + simple: + ('0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'); + """ + print parser._code + def parse(s): + p = parser(s) + return p.expr() + res = parse("5-5-5") + assert res == '((5 - 5) - 5)' + t = Translation(parse) + t.annotate([str]) + t.rtype() + t.backendopt() + func = t.compile_c() + res = func("5-5-5") + assert res == '((5 - 5) - 5)' + From jlg at codespeak.net Mon Jun 25 20:02:03 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Mon, 25 Jun 2007 20:02:03 +0200 (CEST) Subject: [pypy-svn] r44521 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070625180203.ECCED80E9@code0.codespeak.net> Author: jlg Date: Mon Jun 25 20:02:03 2007 New Revision: 44521 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: procedure define added Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Mon Jun 25 20:02:03 2007 @@ -162,6 +162,18 @@ def eval(self, ctx): return mul_lst +def define(ctx, lst): + w_identifier = lst.car + assert isinstance(w_identifier, W_Symbol) + + w_val = lst.cdr.car.eval(ctx) + ctx.put(w_identifier.name, w_val) + return w_val + +class Define(W_Procedure): + def eval(self, ctx): + return define + ###################################### # dict mapping operations to callables # callables must have 2 arguments @@ -172,6 +184,7 @@ { '+': Add("+"), '*': Mul("*"), + 'define': Define("define"), } class ExecutionContext(object): Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Mon Jun 25 20:02:03 2007 @@ -66,3 +66,16 @@ w_num = eval_expr(ctx, "(+ 1 v1 v2)") assert w_num.to_number() == 8.2 +def test_ctx_define(): + ctx = ExecutionContext() + eval_expr(ctx, "(define v1 42)") + assert ctx.get("v1").to_number() == 42 + eval_expr(ctx, "(define v2 2.1)") + assert ctx.get("v2").to_number() == 2.1 + + w_num = eval_expr(ctx, "(+ 1 v1 v2)") + assert w_num.to_number() == 45.1 + + eval_expr(ctx, "(define v2 3.1)") + w_num = eval_expr(ctx, "(+ 1 v1 v2)") + assert w_num.to_number() == 46.1 From jlg at codespeak.net Mon Jun 25 20:12:58 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Mon, 25 Jun 2007 20:12:58 +0200 (CEST) Subject: [pypy-svn] r44522 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070625181258.9C72E80E9@code0.codespeak.net> Author: jlg Date: Mon Jun 25 20:12:58 2007 New Revision: 44522 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/ssparser.py pypy/dist/pypy/lang/scheme/test/test_eval.py pypy/dist/pypy/lang/scheme/test/test_object.py pypy/dist/pypy/lang/scheme/test/test_parser.py Log: W_Identifier added, W_Identifier != W_Symbol Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Mon Jun 25 20:12:58 2007 @@ -16,7 +16,7 @@ def eval(self, ctx): return self -class W_Symbol(W_Root): +class W_Identifier(W_Root): def __init__(self, val): self.name = val @@ -24,7 +24,7 @@ return self.name def __repr__(self): - return "" + return "" def eval(self, ctx): @@ -38,6 +38,16 @@ #reference to undefined identifier raise NotImplementedError +class W_Symbol(W_Root): + def __init__(self, val): + self.name = val + + def to_string(self): + return self.name + + def __repr__(self): + return "" + class W_Boolean(W_Root): def __init__(self, val): self.boolval = bool(val) @@ -164,7 +174,7 @@ def define(ctx, lst): w_identifier = lst.car - assert isinstance(w_identifier, W_Symbol) + assert isinstance(w_identifier, W_Identifier) w_val = lst.cdr.car.eval(ctx) ctx.put(w_identifier.name, w_val) Modified: pypy/dist/pypy/lang/scheme/ssparser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/ssparser.py (original) +++ pypy/dist/pypy/lang/scheme/ssparser.py Mon Jun 25 20:12:58 2007 @@ -1,6 +1,6 @@ import autopath from pypy.rlib.parsing.pypackrat import PackratParser -from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Symbol +from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Identifier from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Float def unquote(s): @@ -16,7 +16,7 @@ IDENTIFIER: c = `[\+\-\*\^\?a-zA-Z!<=>_~/$%&:][\+\-\*\^\?a-zA-Z0-9!<=>_~/$%&:]*` IGNORE* - return {W_Symbol(c)}; + return {W_Identifier(c)}; FIXNUM: c = `\-?(0|([1-9][0-9]*))` Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Mon Jun 25 20:12:58 2007 @@ -1,6 +1,7 @@ from pypy.lang.scheme.ssparser import parse -from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_Float, W_String -from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Symbol, ExecutionContext +from pypy.lang.scheme.object import W_Boolean, W_Fixnum, W_Float, W_String +from pypy.lang.scheme.object import W_Nil, W_Pair, W_Symbol, W_Identifier +from pypy.lang.scheme.object import ExecutionContext from pypy.lang.scheme.operation import mul, add def test_operations_simple(): @@ -25,7 +26,7 @@ + w_num3.to_number()) def test_eval_obj(): - w_num = W_Pair(W_Symbol("+"), + w_num = W_Pair(W_Identifier("+"), W_Pair(W_Fixnum(4), W_Pair(W_Fixnum(5), W_Nil()))) assert w_num.eval(None).to_number() == 9 Modified: pypy/dist/pypy/lang/scheme/test/test_object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_object.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_object.py Mon Jun 25 20:12:58 2007 @@ -44,6 +44,10 @@ w_sym = W_Symbol("symb") assert w_sym.to_string() == "symb" +def test_symbol(): + w_id = W_Identifier("ident") + assert w_id.to_string() == "ident" + def test_ctx(): w_fnum = W_Fixnum(12) w_symb = W_Symbol("symb") Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Mon Jun 25 20:12:58 2007 @@ -1,7 +1,7 @@ import py from pypy.lang.scheme.ssparser import parse -from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Symbol -from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Float +from pypy.lang.scheme.object import W_Boolean, W_Float, W_Fixnum, W_String +from pypy.lang.scheme.object import W_Pair, W_Nil, W_Symbol, W_Identifier def unwrap(w_obj): """for testing purposes: unwrap a scheme object into a python object""" @@ -11,6 +11,8 @@ return w_obj.to_number() elif isinstance(w_obj, W_String): return w_obj.strval + elif isinstance(w_obj, W_Identifier): + return w_obj.name elif isinstance(w_obj, W_Symbol): return w_obj.name elif isinstance(w_obj, W_Boolean): @@ -34,7 +36,7 @@ assert unwrap(w_fixnum) == 1123 assert isinstance(w_fixnum, W_Fixnum) w_fixnum = parse('abfa__') - assert isinstance(w_fixnum, W_Symbol) + assert isinstance(w_fixnum, W_Identifier) t = parse(r'''"don't believe \"them\""''') assert isinstance(t, W_String) assert unwrap(t) == 'don\'t believe "them"' @@ -56,7 +58,7 @@ def test_sexpr(): w_list = parse('(+ 1 2)') assert isinstance(w_list, W_Pair) - assert isinstance(w_list.car, W_Symbol) + assert isinstance(w_list.car, W_Identifier) assert isinstance(w_list.cdr, W_Pair) assert isinstance(w_list.cdr.car, W_Fixnum) assert isinstance(w_list.cdr.cdr.car, W_Fixnum) @@ -82,7 +84,7 @@ def check_ident_ch(char): t = parse("(" + char + ")") assert isinstance(t, W_Pair) - assert isinstance(t.car, W_Symbol) + assert isinstance(t.car, W_Identifier) assert unwrap(t.car) == char assert isinstance(t.cdr, W_Nil) @@ -91,3 +93,4 @@ assert unwrap(t) == False t = parse("#t") assert unwrap(t) == True + From rxe at codespeak.net Mon Jun 25 20:47:07 2007 From: rxe at codespeak.net (rxe at codespeak.net) Date: Mon, 25 Jun 2007 20:47:07 +0200 (CEST) Subject: [pypy-svn] r44523 - pypy/dist/pypy/translator/llvm/test Message-ID: <20070625184707.4759080A9@code0.codespeak.net> Author: rxe Date: Mon Jun 25 20:47:05 2007 New Revision: 44523 Modified: pypy/dist/pypy/translator/llvm/test/test_lltype.py Log: rctypes disappearing already? Modified: pypy/dist/pypy/translator/llvm/test/test_lltype.py ============================================================================== --- pypy/dist/pypy/translator/llvm/test/test_lltype.py (original) +++ pypy/dist/pypy/translator/llvm/test/test_lltype.py Mon Jun 25 20:47:05 2007 @@ -450,6 +450,7 @@ assert res == 42 def test_rctypes_array_access(): + py.test.skip("this breaks during annotation - ?") from ctypes import ARRAY, c_int c_int_1 = ARRAY(c_int, 1) @@ -464,6 +465,7 @@ assert res == 42 def test_rctypes_char_array_value(): + py.test.skip("this breaks during annotation - ?") from ctypes import c_char A = c_char * 3 From rxe at codespeak.net Mon Jun 25 20:53:57 2007 From: rxe at codespeak.net (rxe at codespeak.net) Date: Mon, 25 Jun 2007 20:53:57 +0200 (CEST) Subject: [pypy-svn] r44524 - pypy/dist/pypy/translator/llvm Message-ID: <20070625185357.465F080A9@code0.codespeak.net> Author: rxe Date: Mon Jun 25 20:53:56 2007 New Revision: 44524 Modified: pypy/dist/pypy/translator/llvm/opwriter.py Log: add flavored_malloc_varsize, not really tested yet Modified: pypy/dist/pypy/translator/llvm/opwriter.py ============================================================================== --- pypy/dist/pypy/translator/llvm/opwriter.py (original) +++ pypy/dist/pypy/translator/llvm/opwriter.py Mon Jun 25 20:53:56 2007 @@ -320,6 +320,17 @@ else: raise NotImplementedError + def flavored_malloc_varsize(self, opr): + flavor = opr.op.args[0].value + if flavor == "raw": + arg_type = opr.op.args[1].value + node = self.db.obj2node[arg_type] + self.db.gcpolicy.var_zeromalloc(self.codewriter, opr.retref, + opr.rettype, node, opr.argrefs[2], + atomic=arg_type._is_atomic()) + else: + raise NotImplementedError + def flavored_free(self, opr): flavor = opr.op.args[0].value if flavor == "raw": From cfbolz at codespeak.net Mon Jun 25 22:44:16 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 25 Jun 2007 22:44:16 +0200 (CEST) Subject: [pypy-svn] r44530 - pypy/dist/pypy/rlib/parsing Message-ID: <20070625204416.1175F80D5@code0.codespeak.net> Author: cfbolz Date: Mon Jun 25 22:44:15 2007 New Revision: 44530 Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py Log: safe one of the initializations of _error Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/makepackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/makepackrat.py Mon Jun 25 22:44:15 2007 @@ -449,7 +449,6 @@ possibilities = t.children if len(possibilities) > 1: self.start_block("while 1:") - self.emit("_error = None") for i, p in enumerate(possibilities): c = self.choice_point() for _ in self.start_block("try:"): From cfbolz at codespeak.net Mon Jun 25 23:30:48 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 25 Jun 2007 23:30:48 +0200 (CEST) Subject: [pypy-svn] r44531 - in pypy/dist/pypy/rlib/parsing: . test Message-ID: <20070625213048.2DBB580DD@code0.codespeak.net> Author: cfbolz Date: Mon Jun 25 23:30:47 2007 New Revision: 44531 Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py pypy/dist/pypy/rlib/parsing/pypackrat.py pypy/dist/pypy/rlib/parsing/test/test_translate.py Log: try to make the generated code more compact Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/makepackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/makepackrat.py Mon Jun 25 23:30:47 2007 @@ -17,7 +17,6 @@ return self.general_nonterminal_visit(t) visit_commands = visit_or - visit_toplevel_or = visit_or def visit_negation(self, t): child = self.dispatch(t.children[0]) @@ -348,18 +347,22 @@ def memoize_footer(self, name): dictname = "_dict_%s" % (name, ) - for _ in self.start_block("if _status.status == _status.LEFTRECURSION:"): - for _ in self.start_block("if _status.result is not None:"): - for _ in self.start_block("if _status.pos >= self._pos:"): - self.emit("_status.status = _status.NORMAL") - self.emit("self._pos = _status.pos") - self.emit("return _status") - self.emit("_status.pos = self._pos") - self.emit("_status.status = _status.SOMESOLUTIONS") - self.emit("_status.result = %s" % (self.resultname, )) - self.emit("_status.error = _error") - self.emit("self._pos = _startingpos") - self.emit("return self._%s()" % (name, )) + if self.have_call: + for _ in self.start_block( + "if _status.status == _status.LEFTRECURSION:"): + for _ in self.start_block("if _status.result is not None:"): + for _ in self.start_block("if _status.pos >= self._pos:"): + self.emit("_status.status = _status.NORMAL") + self.emit("self._pos = _status.pos") + self.emit("return _status") + self.emit("_status.pos = self._pos") + self.emit("_status.status = _status.SOMESOLUTIONS") + self.emit("_status.result = %s" % (self.resultname, )) + self.emit("_status.error = _error") + self.emit("self._pos = _startingpos") + self.emit("return self._%s()" % (name, )) + else: + self.emit("assert _status.status != _status.LEFTRECURSION") self.emit("_status.status = _status.NORMAL") self.emit("_status.pos = self._pos") self.emit("_status.result = %s" % (self.resultname, )) @@ -369,7 +372,7 @@ for _ in self.start_block("except BacktrackException, _exc:"): self.emit("_status.pos = -1") self.emit("_status.result = None") - self.emit("_error = self._combine_errors(_error, _exc.error)") + self.combine_error('_exc.error') self.emit("_status.error = _error") self.emit("_status.status = _status.ERROR") self.emit("raise BacktrackException(_error)") @@ -441,11 +444,13 @@ self.memoize_header(name, otherargs) #self.emit("print '%s', self._pos" % (name, )) self.resultname = "_result" + self.have_call = False + self.created_error = False self.dispatch(t.children[-1]) self.memoize_footer(name) self.end_block("def") - def visit_or(self, t): + def visit_or(self, t, first=False): possibilities = t.children if len(possibilities) > 1: self.start_block("while 1:") @@ -455,7 +460,7 @@ self.dispatch(p) self.emit("break") for _ in self.start_block("except BacktrackException, _exc:"): - self.emit("_error = self._combine_errors(_error, _exc.error)") + self.combine_error('_exc.error') self.revert(c) if i == len(possibilities) - 1: self.emit("raise BacktrackException(_error)") @@ -463,7 +468,6 @@ if len(possibilities) > 1: self.emit("break") self.end_block("while") - visit_toplevel_or = visit_or def visit_commands(self, t): for elt in t.children: @@ -489,7 +493,7 @@ self.dispatch(t.children[1]) self.emit("%s.append(_result)" % (name, )) for _ in self.start_block("except BacktrackException, _exc:"): - self.emit("_error = self._combine_errors(_error, _exc.error)") + self.combine_error('_exc.error') self.revert(c) self.emit("break") self.emit("_result = %s" % (name, )) @@ -559,11 +563,12 @@ self.dispatch(t.children[2]) self.emit("break") for _ in self.start_block("except BacktrackException, _exc:"): - self.emit("_error = self._combine_errors(_exc.error, _error)") + self.combine_error('_exc.error') for _ in self.start_block("else:"): self.emit("raise BacktrackException(_error)") def visit_call(self, t): + self.have_call = True args = ", ".join(['(%s)' % (arg.additional_info[1:-1], ) for arg in t.children[1].children]) if t.children[0].startswith("_"): @@ -573,8 +578,7 @@ callname = "_" + t.children[0] self.emit("_call_status = self.%s(%s)" % (callname, args)) self.emit("_result = _call_status.result") - self.emit( - "_error = self._combine_errors(_call_status.error, _error)") + self.combine_error('_call_status.error') def visit_REGEX(self, t): r = t.additional_info[1:-1].replace('\\`', '`') @@ -599,6 +603,14 @@ self.matchers[r] = py.code.Source(matcher) return matcher + def combine_error(self, newerror): + if self.created_error: + self.emit( + "_error = self._combine_errors(_error, %s)" % (newerror, )) + else: + self.emit("_error = %s" % (newerror, )) + self.created_error = True + class MetaPackratParser(type): def __new__(cls, name_, bases, dct): if '__doc__' not in dct or dct['__doc__'] is None: Modified: pypy/dist/pypy/rlib/parsing/pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/pypackrat.py Mon Jun 25 23:30:47 2007 @@ -9,38 +9,29 @@ _status = self._dict_NAME.get(_key, None) if _status is None: _status = self._dict_NAME[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None _result = self._regex1074651696() - if _status.status == _status.LEFTRECURSION: - if _status.result is not None: - if _status.pos >= self._pos: - _status.status = _status.NORMAL - self._pos = _status.pos - return _status - _status.pos = self._pos - _status.status = _status.SOMESOLUTIONS - _status.result = _result - _status.error = _error - self._pos = _startingpos - return self._NAME() + assert _status.status != _status.LEFTRECURSION _status.status = _status.NORMAL _status.pos = self._pos _status.result = _result @@ -49,7 +40,7 @@ except BacktrackException, _exc: _status.pos = -1 _status.result = None - _error = self._combine_errors(_error, _exc.error) + _error = _exc.error _status.error = _error _status.status = _status.ERROR raise BacktrackException(_error) @@ -60,38 +51,29 @@ _status = self._dict_SPACE.get(_key, None) if _status is None: _status = self._dict_SPACE[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None _result = self.__chars__(' ') - if _status.status == _status.LEFTRECURSION: - if _status.result is not None: - if _status.pos >= self._pos: - _status.status = _status.NORMAL - self._pos = _status.pos - return _status - _status.pos = self._pos - _status.status = _status.SOMESOLUTIONS - _status.result = _result - _status.error = _error - self._pos = _startingpos - return self._SPACE() + assert _status.status != _status.LEFTRECURSION _status.status = _status.NORMAL _status.pos = self._pos _status.result = _result @@ -100,7 +82,7 @@ except BacktrackException, _exc: _status.pos = -1 _status.result = None - _error = self._combine_errors(_error, _exc.error) + _error = _exc.error _status.error = _error _status.status = _status.ERROR raise BacktrackException(_error) @@ -111,38 +93,29 @@ _status = self._dict_COMMENT.get(_key, None) if _status is None: _status = self._dict_COMMENT[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None _result = self._regex528667127() - if _status.status == _status.LEFTRECURSION: - if _status.result is not None: - if _status.pos >= self._pos: - _status.status = _status.NORMAL - self._pos = _status.pos - return _status - _status.pos = self._pos - _status.status = _status.SOMESOLUTIONS - _status.result = _result - _status.error = _error - self._pos = _startingpos - return self._COMMENT() + assert _status.status != _status.LEFTRECURSION _status.status = _status.NORMAL _status.pos = self._pos _status.result = _result @@ -151,7 +124,7 @@ except BacktrackException, _exc: _status.pos = -1 _status.result = None - _error = self._combine_errors(_error, _exc.error) + _error = _exc.error _status.error = _error _status.status = _status.ERROR raise BacktrackException(_error) @@ -162,38 +135,29 @@ _status = self._dict_IGNORE.get(_key, None) if _status is None: _status = self._dict_IGNORE[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None _result = self._regex1979538501() - if _status.status == _status.LEFTRECURSION: - if _status.result is not None: - if _status.pos >= self._pos: - _status.status = _status.NORMAL - self._pos = _status.pos - return _status - _status.pos = self._pos - _status.status = _status.SOMESOLUTIONS - _status.result = _result - _status.error = _error - self._pos = _startingpos - return self._IGNORE() + assert _status.status != _status.LEFTRECURSION _status.status = _status.NORMAL _status.pos = self._pos _status.result = _result @@ -202,7 +166,7 @@ except BacktrackException, _exc: _status.pos = -1 _status.result = None - _error = self._combine_errors(_error, _exc.error) + _error = _exc.error _status.error = _error _status.status = _status.ERROR raise BacktrackException(_error) @@ -213,32 +177,33 @@ _status = self._dict_newline.get(_key, None) if _status is None: _status = self._dict_newline[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None _choice0 = self._pos try: _call_status = self._COMMENT() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -284,21 +249,23 @@ _status = self._dict_REGEX.get(_key, None) if _status is None: _status = self._dict_REGEX[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -306,18 +273,7 @@ _result = self._regex1006631623() r = _result _result = (Symbol('REGEX', r, None)) - if _status.status == _status.LEFTRECURSION: - if _status.result is not None: - if _status.pos >= self._pos: - _status.status = _status.NORMAL - self._pos = _status.pos - return _status - _status.pos = self._pos - _status.status = _status.SOMESOLUTIONS - _status.result = _result - _status.error = _error - self._pos = _startingpos - return self._REGEX() + assert _status.status != _status.LEFTRECURSION _status.status = _status.NORMAL _status.pos = self._pos _status.result = _result @@ -326,7 +282,7 @@ except BacktrackException, _exc: _status.pos = -1 _status.result = None - _error = self._combine_errors(_error, _exc.error) + _error = _exc.error _status.error = _error _status.status = _status.ERROR raise BacktrackException(_error) @@ -337,21 +293,23 @@ _status = self._dict_QUOTE.get(_key, None) if _status is None: _status = self._dict_QUOTE[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -359,18 +317,7 @@ _result = self._regex1124192327() r = _result _result = (Symbol('QUOTE', r, None)) - if _status.status == _status.LEFTRECURSION: - if _status.result is not None: - if _status.pos >= self._pos: - _status.status = _status.NORMAL - self._pos = _status.pos - return _status - _status.pos = self._pos - _status.status = _status.SOMESOLUTIONS - _status.result = _result - _status.error = _error - self._pos = _startingpos - return self._QUOTE() + assert _status.status != _status.LEFTRECURSION _status.status = _status.NORMAL _status.pos = self._pos _status.result = _result @@ -379,7 +326,7 @@ except BacktrackException, _exc: _status.pos = -1 _status.result = None - _error = self._combine_errors(_error, _exc.error) + _error = _exc.error _status.error = _error _status.status = _status.ERROR raise BacktrackException(_error) @@ -390,21 +337,23 @@ _status = self._dict_PYTHONCODE.get(_key, None) if _status is None: _status = self._dict_PYTHONCODE[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -412,18 +361,7 @@ _result = self._regex291086639() r = _result _result = (Symbol('PYTHONCODE', r, None)) - if _status.status == _status.LEFTRECURSION: - if _status.result is not None: - if _status.pos >= self._pos: - _status.status = _status.NORMAL - self._pos = _status.pos - return _status - _status.pos = self._pos - _status.status = _status.SOMESOLUTIONS - _status.result = _result - _status.error = _error - self._pos = _startingpos - return self._PYTHONCODE() + assert _status.status != _status.LEFTRECURSION _status.status = _status.NORMAL _status.pos = self._pos _status.result = _result @@ -432,7 +370,7 @@ except BacktrackException, _exc: _status.pos = -1 _status.result = None - _error = self._combine_errors(_error, _exc.error) + _error = _exc.error _status.error = _error _status.status = _status.ERROR raise BacktrackException(_error) @@ -443,21 +381,23 @@ _status = self._dict_EOF.get(_key, None) if _status is None: _status = self._dict_EOF[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -491,7 +431,7 @@ except BacktrackException, _exc: _status.pos = -1 _status.result = None - _error = self._combine_errors(_error, _exc.error) + _error = _exc.error _status.error = _error _status.status = _status.ERROR raise BacktrackException(_error) @@ -502,21 +442,23 @@ _status = self._dict_file.get(_key, None) if _status is None: _status = self._dict_file[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -527,7 +469,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error _all4.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -536,11 +478,11 @@ _result = _all4 _call_status = self._list() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _before_discard6 = _result _call_status = self._EOF() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _result = _before_discard6 if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -573,21 +515,23 @@ _status = self._dict_list.get(_key, None) if _status is None: _status = self._dict_list[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -595,14 +539,14 @@ _all7 = [] _call_status = self._production() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error _all7.append(_result) while 1: _choice8 = self._pos try: _call_status = self._production() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all7.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -642,28 +586,30 @@ _status = self._dict_production.get(_key, None) if _status is None: _status = self._dict_production[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None _call_status = self._NAME() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error name = _result _all9 = [] while 1: @@ -671,7 +617,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all9.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -680,7 +626,7 @@ _result = _all9 _call_status = self._productionargs() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) args = _result _result = self.__chars__(':') _all11 = [] @@ -689,7 +635,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all11.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -698,7 +644,7 @@ _result = _all11 _call_status = self._or_() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) what = _result _all13 = [] while 1: @@ -706,7 +652,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all13.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -720,7 +666,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all15.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -759,27 +705,28 @@ _status = self._dict_productionargs.get(_key, None) if _status is None: _status = self._dict_productionargs[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None _choice17 = self._pos try: _result = self.__chars__('(') @@ -789,7 +736,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error _all18.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -802,7 +749,7 @@ try: _call_status = self._NAME() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _before_discard22 = _result _all23 = [] while 1: @@ -810,7 +757,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all23.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -824,7 +771,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all25.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -841,7 +788,7 @@ args = _result _call_status = self._NAME() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) arg = _result _all27 = [] while 1: @@ -849,7 +796,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all27.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -863,7 +810,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all29.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -916,33 +863,34 @@ _status = self._dict_or_.get(_key, None) if _status is None: _status = self._dict_or_[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None _choice32 = self._pos try: _all33 = [] _call_status = self._commands() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error _before_discard34 = _result _result = self.__chars__('|') _all35 = [] @@ -951,7 +899,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all35.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -965,7 +913,7 @@ try: _call_status = self._commands() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _before_discard38 = _result _result = self.__chars__('|') _all39 = [] @@ -974,7 +922,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all39.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -991,7 +939,7 @@ l = _result _call_status = self._commands() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) last = _result _result = (Nonterminal('or', l + [last])) break @@ -1002,7 +950,7 @@ try: _call_status = self._commands() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1010,7 +958,7 @@ raise BacktrackException(_error) _call_status = self._commands() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -1043,44 +991,45 @@ _status = self._dict_commands.get(_key, None) if _status is None: _status = self._dict_commands[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None _choice42 = self._pos try: _call_status = self._command() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error cmd = _result _call_status = self._newline() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all43 = [] _call_status = self._command() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _before_discard44 = _result _call_status = self._newline() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _result = _before_discard44 _all43.append(_result) while 1: @@ -1088,11 +1037,11 @@ try: _call_status = self._command() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _before_discard46 = _result _call_status = self._newline() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _result = _before_discard46 _all43.append(_result) except BacktrackException, _exc: @@ -1110,7 +1059,7 @@ try: _call_status = self._command() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1118,7 +1067,7 @@ raise BacktrackException(_error) _call_status = self._command() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -1151,28 +1100,30 @@ _status = self._dict_command.get(_key, None) if _status is None: _status = self._dict_command[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None _call_status = self._simplecommand() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error if _status.status == _status.LEFTRECURSION: if _status.result is not None: if _status.pos >= self._pos: @@ -1204,32 +1155,33 @@ _status = self._dict_simplecommand.get(_key, None) if _status is None: _status = self._dict_simplecommand[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None _choice48 = self._pos try: _call_status = self._return_() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1238,7 +1190,7 @@ try: _call_status = self._if_() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1247,7 +1199,7 @@ try: _call_status = self._named_command() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1256,7 +1208,7 @@ try: _call_status = self._repetition() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1265,7 +1217,7 @@ try: _call_status = self._choose() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1274,7 +1226,7 @@ try: _call_status = self._negation() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1282,7 +1234,7 @@ raise BacktrackException(_error) _call_status = self._negation() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -1315,21 +1267,23 @@ _status = self._dict_return_.get(_key, None) if _status is None: _status = self._dict_return_[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -1341,7 +1295,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error _all54.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1350,7 +1304,7 @@ _result = _all54 _call_status = self._PYTHONCODE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) code = _result _all56 = [] while 1: @@ -1358,7 +1312,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all56.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1397,36 +1351,37 @@ _status = self._dict_if_.get(_key, None) if _status is None: _status = self._dict_if_[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None _choice58 = self._pos try: _result = self.__chars__('do') _call_status = self._newline() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error _call_status = self._command() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) cmd = _result _all59 = [] while 1: @@ -1434,7 +1389,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all59.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1448,7 +1403,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all61.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1457,7 +1412,7 @@ _result = _all61 _call_status = self._PYTHONCODE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) condition = _result _all63 = [] while 1: @@ -1465,7 +1420,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all63.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1486,7 +1441,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all66.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1495,7 +1450,7 @@ _result = _all66 _call_status = self._PYTHONCODE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) condition = _result _all68 = [] while 1: @@ -1503,7 +1458,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all68.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1523,7 +1478,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all70.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1532,7 +1487,7 @@ _result = _all70 _call_status = self._PYTHONCODE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) condition = _result _all72 = [] while 1: @@ -1540,7 +1495,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all72.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1580,21 +1535,23 @@ _status = self._dict_choose.get(_key, None) if _status is None: _status = self._dict_choose[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -1606,7 +1563,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error _all74.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1615,7 +1572,7 @@ _result = _all74 _call_status = self._NAME() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) name = _result _all76 = [] while 1: @@ -1623,7 +1580,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all76.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1637,7 +1594,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all78.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1646,7 +1603,7 @@ _result = _all78 _call_status = self._PYTHONCODE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) expr = _result _all80 = [] while 1: @@ -1654,7 +1611,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all80.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1663,7 +1620,7 @@ _result = _all80 _call_status = self._commands() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) cmds = _result _result = (Nonterminal('choose', [name, expr, cmds])) if _status.status == _status.LEFTRECURSION: @@ -1697,21 +1654,23 @@ _status = self._dict_commandchain.get(_key, None) if _status is None: _status = self._dict_commandchain[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -1719,14 +1678,14 @@ _all82 = [] _call_status = self._simplecommand() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error _all82.append(_result) while 1: _choice83 = self._pos try: _call_status = self._simplecommand() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all82.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1766,28 +1725,30 @@ _status = self._dict_named_command.get(_key, None) if _status is None: _status = self._dict_named_command[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None _call_status = self._NAME() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error name = _result _all84 = [] while 1: @@ -1795,7 +1756,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all84.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1809,7 +1770,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all86.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1818,7 +1779,7 @@ _result = _all86 _call_status = self._command() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) cmd = _result _result = (Nonterminal('named_command', [name, cmd])) if _status.status == _status.LEFTRECURSION: @@ -1852,32 +1813,33 @@ _status = self._dict_repetition.get(_key, None) if _status is None: _status = self._dict_repetition[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None _choice88 = self._pos try: _call_status = self._enclosed() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error what = _result _all89 = [] while 1: @@ -1885,7 +1847,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all89.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1899,7 +1861,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all91.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1915,7 +1877,7 @@ try: _call_status = self._enclosed() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) what = _result _all94 = [] while 1: @@ -1923,7 +1885,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all94.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1931,7 +1893,6 @@ break _result = _all94 while 1: - _error = None _choice96 = self._pos try: _result = self.__chars__('*') @@ -1956,7 +1917,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all98.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1971,7 +1932,7 @@ raise BacktrackException(_error) _call_status = self._enclosed() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) what = _result _all100 = [] while 1: @@ -1979,7 +1940,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all100.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -1987,7 +1948,6 @@ break _result = _all100 while 1: - _error = None _choice102 = self._pos try: _result = self.__chars__('*') @@ -2012,7 +1972,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all104.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2052,27 +2012,28 @@ _status = self._dict_negation.get(_key, None) if _status is None: _status = self._dict_negation[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None _choice106 = self._pos try: _result = self.__chars__('!') @@ -2082,7 +2043,7 @@ try: _call_status = self._SPACE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error _all107.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2091,7 +2052,7 @@ _result = _all107 _call_status = self._negation() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) what = _result _all109 = [] while 1: @@ -2099,7 +2060,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all109.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2115,7 +2076,7 @@ try: _call_status = self._enclosed() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2123,7 +2084,7 @@ raise BacktrackException(_error) _call_status = self._enclosed() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -2156,27 +2117,28 @@ _status = self._dict_enclosed.get(_key, None) if _status is None: _status = self._dict_enclosed[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None _choice112 = self._pos try: _result = self.__chars__('<') @@ -2186,7 +2148,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error _all113.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2195,7 +2157,7 @@ _result = _all113 _call_status = self._primary() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) what = _result _all115 = [] while 1: @@ -2203,7 +2165,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all115.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2217,7 +2179,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all117.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2238,7 +2200,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all120.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2247,7 +2209,7 @@ _result = _all120 _call_status = self._or_() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) what = _result _all122 = [] while 1: @@ -2255,7 +2217,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all122.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2269,7 +2231,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all124.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2291,7 +2253,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all128.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2301,7 +2263,7 @@ _result = _before_discard127 _call_status = self._or_() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _before_discard130 = _result _result = self.__chars__(')') _all131 = [] @@ -2310,7 +2272,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all131.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2326,7 +2288,7 @@ try: _call_status = self._primary() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2334,7 +2296,7 @@ raise BacktrackException(_error) _call_status = self._primary() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -2367,32 +2329,33 @@ _status = self._dict_primary.get(_key, None) if _status is None: _status = self._dict_primary[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None _choice134 = self._pos try: _call_status = self._call() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2401,7 +2364,7 @@ try: _call_status = self._REGEX() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _before_discard136 = _result _all137 = [] while 1: @@ -2409,7 +2372,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all137.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2425,7 +2388,7 @@ try: _call_status = self._QUOTE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _before_discard140 = _result _all141 = [] while 1: @@ -2433,7 +2396,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all141.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2448,7 +2411,7 @@ raise BacktrackException(_error) _call_status = self._QUOTE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _before_discard143 = _result _all144 = [] while 1: @@ -2456,7 +2419,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all144.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2496,32 +2459,34 @@ _status = self._dict_call.get(_key, None) if _status is None: _status = self._dict_call[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None _call_status = self._NAME() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error x = _result _call_status = self._arguments() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) args = _result _all146 = [] while 1: @@ -2529,7 +2494,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all146.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2568,27 +2533,28 @@ _status = self._dict_arguments.get(_key, None) if _status is None: _status = self._dict_arguments[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None _choice148 = self._pos try: _result = self.__chars__('(') @@ -2598,7 +2564,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error _all149.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2611,7 +2577,7 @@ try: _call_status = self._PYTHONCODE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _before_discard153 = _result _all154 = [] while 1: @@ -2619,7 +2585,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all154.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2633,7 +2599,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all156.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) @@ -2650,7 +2616,7 @@ args = _result _call_status = self._PYTHONCODE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) last = _result _result = self.__chars__(')') _all158 = [] @@ -2659,7 +2625,7 @@ try: _call_status = self._IGNORE() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) _all158.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) Modified: pypy/dist/pypy/rlib/parsing/test/test_translate.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_translate.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_translate.py Mon Jun 25 23:30:47 2007 @@ -153,6 +153,7 @@ t.annotate([str]) t.rtype() t.backendopt() + t.view() func = t.compile_c() res = func("5-5-5") assert res == '((5 - 5) - 5)' From cfbolz at codespeak.net Tue Jun 26 00:07:46 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Tue, 26 Jun 2007 00:07:46 +0200 (CEST) Subject: [pypy-svn] r44533 - pypy/dist/pypy/rlib/parsing Message-ID: <20070625220746.05D6F80BA@code0.codespeak.net> Author: cfbolz Date: Tue Jun 26 00:07:46 2007 New Revision: 44533 Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py Log: slightly hackish: save the left-recursion detection code in the header when it is not necessary (because no call that could have led to recursion was done) Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/makepackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/makepackrat.py Tue Jun 26 00:07:46 2007 @@ -273,13 +273,12 @@ self.code = [] self.blocks = [] self.initcode = [] - self.namecount = 0 self.names = {} self.matchers = {} def get_code(self): assert not self.blocks - return "\n".join(self.code) + return "\n".join([" " * depth + line for depth, line in self.code]) def make_parser(self): m = {'Status': Status, @@ -290,7 +289,7 @@ def emit(self, line): for line in line.split("\n"): - self.code.append(" " * (4 * len(self.blocks)) + line) + self.code.append((len(self.blocks), line)) def emit_initcode(self, line): for line in line.split("\n"): @@ -310,6 +309,22 @@ assert starterpart in block, "ended wrong block %s with %s" % ( block, starterpart) + def store_code_away(self): + result = self.blocks, self.code + self.code = [] + self.blocks = [] + return result + + def restore_code(self, (blocks, code)): + result = self.blocks, self.code + self.code = code + self.blocks = blocks + return result + + def add_code(self, (blocks, code)): + self.code += [(depth + len(self.blocks), line) for depth, line in code] + self.blocks += blocks + def memoize_header(self, name, args): dictname = "_dict_%s" % (name, ) self.emit_initcode("self.%s = {}" % (dictname, )) @@ -328,18 +343,19 @@ self.emit("return _status") for _ in self.start_block("elif _statusstatus == _status.ERROR:"): self.emit("raise BacktrackException(_status.error)") - for _ in self.start_block( - "elif (_statusstatus == _status.INPROGRESS or\n" - " _statusstatus == _status.LEFTRECURSION):"): - self.emit("_status.status = _status.LEFTRECURSION") - for _ in self.start_block("if _status.result is not None:"): - self.emit("self._pos = _status.pos") - self.emit("return _status") - for _ in self.start_block("else:"): - self.emit("raise BacktrackException(None)") - for _ in self.start_block( - "elif _statusstatus == _status.SOMESOLUTIONS:"): - self.emit("_status.status = _status.INPROGRESS") + if self.have_call: + for _ in self.start_block( + "elif (_statusstatus == _status.INPROGRESS or\n" + " _statusstatus == _status.LEFTRECURSION):"): + self.emit("_status.status = _status.LEFTRECURSION") + for _ in self.start_block("if _status.result is not None:"): + self.emit("self._pos = _status.pos") + self.emit("return _status") + for _ in self.start_block("else:"): + self.emit("raise BacktrackException(None)") + for _ in self.start_block( + "elif _statusstatus == _status.SOMESOLUTIONS:"): + self.emit("_status.status = _status.INPROGRESS") self.emit("_startingpos = self._pos") self.start_block("try:") self.emit("_result = None") @@ -440,13 +456,15 @@ for _ in self.start_block("def %s(%s):" % (name, argswithself)): self.emit("return self._%s(%s).result" % (name, argswithoutself)) self.start_block("def _%s(%s):" % (name, argswithself, )) - - self.memoize_header(name, otherargs) - #self.emit("print '%s', self._pos" % (name, )) + self.namecount = 0 self.resultname = "_result" self.have_call = False self.created_error = False + allother = self.store_code_away() self.dispatch(t.children[-1]) + subsequent = self.restore_code(allother) + self.memoize_header(name, otherargs) + self.add_code(subsequent) self.memoize_footer(name) self.end_block("def") From cfbolz at codespeak.net Tue Jun 26 00:13:29 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Tue, 26 Jun 2007 00:13:29 +0200 (CEST) Subject: [pypy-svn] r44534 - pypy/dist/pypy/rlib/parsing Message-ID: <20070625221329.77EF980BB@code0.codespeak.net> Author: cfbolz Date: Tue Jun 26 00:13:29 2007 New Revision: 44534 Modified: pypy/dist/pypy/rlib/parsing/pypackrat.py pypy/dist/pypy/rlib/parsing/regexparse.py Log: check in the current version of the auto-generated files Modified: pypy/dist/pypy/rlib/parsing/pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/pypackrat.py Tue Jun 26 00:13:29 2007 @@ -16,16 +16,6 @@ return _status elif _statusstatus == _status.ERROR: raise BacktrackException(_status.error) - elif (_statusstatus == _status.INPROGRESS or - _statusstatus == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: - self._pos = _status.pos - return _status - else: - raise BacktrackException(None) - elif _statusstatus == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -58,16 +48,6 @@ return _status elif _statusstatus == _status.ERROR: raise BacktrackException(_status.error) - elif (_statusstatus == _status.INPROGRESS or - _statusstatus == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: - self._pos = _status.pos - return _status - else: - raise BacktrackException(None) - elif _statusstatus == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -100,16 +80,6 @@ return _status elif _statusstatus == _status.ERROR: raise BacktrackException(_status.error) - elif (_statusstatus == _status.INPROGRESS or - _statusstatus == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: - self._pos = _status.pos - return _status - else: - raise BacktrackException(None) - elif _statusstatus == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -142,16 +112,6 @@ return _status elif _statusstatus == _status.ERROR: raise BacktrackException(_status.error) - elif (_statusstatus == _status.INPROGRESS or - _statusstatus == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: - self._pos = _status.pos - return _status - else: - raise BacktrackException(None) - elif _statusstatus == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -256,16 +216,6 @@ return _status elif _statusstatus == _status.ERROR: raise BacktrackException(_status.error) - elif (_statusstatus == _status.INPROGRESS or - _statusstatus == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: - self._pos = _status.pos - return _status - else: - raise BacktrackException(None) - elif _statusstatus == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -300,16 +250,6 @@ return _status elif _statusstatus == _status.ERROR: raise BacktrackException(_status.error) - elif (_statusstatus == _status.INPROGRESS or - _statusstatus == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: - self._pos = _status.pos - return _status - else: - raise BacktrackException(None) - elif _statusstatus == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -344,16 +284,6 @@ return _status elif _statusstatus == _status.ERROR: raise BacktrackException(_status.error) - elif (_statusstatus == _status.INPROGRESS or - _statusstatus == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: - self._pos = _status.pos - return _status - else: - raise BacktrackException(None) - elif _statusstatus == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -402,13 +332,13 @@ try: _result = None _error = None - _choice2 = self._pos - _stored_result3 = _result + _choice0 = self._pos + _stored_result1 = _result try: _result = self.__any__() except BacktrackException: - self._pos = _choice2 - _result = _stored_result3 + self._pos = _choice0 + _result = _stored_result1 else: raise BacktrackException(None) if _status.status == _status.LEFTRECURSION: @@ -463,27 +393,27 @@ try: _result = None _error = None - _all4 = [] + _all0 = [] while 1: - _choice5 = self._pos + _choice1 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = _call_status.error - _all4.append(_result) + _all0.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice5 + self._pos = _choice1 break - _result = _all4 + _result = _all0 _call_status = self._list() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _before_discard6 = _result + _before_discard2 = _result _call_status = self._EOF() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _result = _before_discard6 + _result = _before_discard2 if _status.status == _status.LEFTRECURSION: if _status.result is not None: if _status.pos >= self._pos: @@ -536,23 +466,23 @@ try: _result = None _error = None - _all7 = [] + _all0 = [] _call_status = self._production() _result = _call_status.result _error = _call_status.error - _all7.append(_result) + _all0.append(_result) while 1: - _choice8 = self._pos + _choice1 = self._pos try: _call_status = self._production() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all7.append(_result) + _all0.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice8 + self._pos = _choice1 break - _result = _all7 + _result = _all0 content = _result _result = (Nonterminal('list', content)) if _status.status == _status.LEFTRECURSION: @@ -611,68 +541,68 @@ _result = _call_status.result _error = _call_status.error name = _result - _all9 = [] + _all0 = [] while 1: - _choice10 = self._pos + _choice1 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all9.append(_result) + _all0.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice10 + self._pos = _choice1 break - _result = _all9 + _result = _all0 _call_status = self._productionargs() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) args = _result _result = self.__chars__(':') - _all11 = [] + _all2 = [] while 1: - _choice12 = self._pos + _choice3 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all11.append(_result) + _all2.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice12 + self._pos = _choice3 break - _result = _all11 + _result = _all2 _call_status = self._or_() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) what = _result - _all13 = [] + _all4 = [] while 1: - _choice14 = self._pos + _choice5 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all13.append(_result) + _all4.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice14 + self._pos = _choice5 break - _result = _all13 + _result = _all4 _result = self.__chars__(';') - _all15 = [] + _all6 = [] while 1: - _choice16 = self._pos + _choice7 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all15.append(_result) + _all6.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice16 + self._pos = _choice7 break - _result = _all15 + _result = _all6 _result = (Nonterminal('production', [name, args, what])) if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -727,108 +657,108 @@ _result = None _error = None while 1: - _choice17 = self._pos + _choice0 = self._pos try: _result = self.__chars__('(') - _all18 = [] + _all1 = [] while 1: - _choice19 = self._pos + _choice2 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = _call_status.error - _all18.append(_result) + _all1.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice19 + self._pos = _choice2 break - _result = _all18 - _all20 = [] + _result = _all1 + _all3 = [] while 1: - _choice21 = self._pos + _choice4 = self._pos try: _call_status = self._NAME() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _before_discard22 = _result - _all23 = [] + _before_discard5 = _result + _all6 = [] while 1: - _choice24 = self._pos + _choice7 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all23.append(_result) + _all6.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice24 + self._pos = _choice7 break - _result = _all23 + _result = _all6 _result = self.__chars__(',') - _all25 = [] + _all8 = [] while 1: - _choice26 = self._pos + _choice9 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all25.append(_result) + _all8.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice26 + self._pos = _choice9 break - _result = _all25 - _result = _before_discard22 - _all20.append(_result) + _result = _all8 + _result = _before_discard5 + _all3.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice21 + self._pos = _choice4 break - _result = _all20 + _result = _all3 args = _result _call_status = self._NAME() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) arg = _result - _all27 = [] + _all10 = [] while 1: - _choice28 = self._pos + _choice11 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all27.append(_result) + _all10.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice28 + self._pos = _choice11 break - _result = _all27 + _result = _all10 _result = self.__chars__(')') - _all29 = [] + _all12 = [] while 1: - _choice30 = self._pos + _choice13 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all29.append(_result) + _all12.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice30 + self._pos = _choice13 break - _result = _all29 + _result = _all12 _result = (Nonterminal('productionargs', args + [arg])) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice17 - _choice31 = self._pos + self._pos = _choice0 + _choice14 = self._pos try: _result = (Nonterminal('productionargs', [])) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice31 + self._pos = _choice14 raise BacktrackException(_error) _result = (Nonterminal('productionargs', [])) break @@ -885,57 +815,57 @@ _result = None _error = None while 1: - _choice32 = self._pos + _choice0 = self._pos try: - _all33 = [] + _all1 = [] _call_status = self._commands() _result = _call_status.result _error = _call_status.error - _before_discard34 = _result + _before_discard2 = _result _result = self.__chars__('|') - _all35 = [] + _all3 = [] while 1: - _choice36 = self._pos + _choice4 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all35.append(_result) + _all3.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice36 + self._pos = _choice4 break - _result = _all35 - _result = _before_discard34 - _all33.append(_result) + _result = _all3 + _result = _before_discard2 + _all1.append(_result) while 1: - _choice37 = self._pos + _choice5 = self._pos try: _call_status = self._commands() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _before_discard38 = _result + _before_discard6 = _result _result = self.__chars__('|') - _all39 = [] + _all7 = [] while 1: - _choice40 = self._pos + _choice8 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all39.append(_result) + _all7.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice40 + self._pos = _choice8 break - _result = _all39 - _result = _before_discard38 - _all33.append(_result) + _result = _all7 + _result = _before_discard6 + _all1.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice37 + self._pos = _choice5 break - _result = _all33 + _result = _all1 l = _result _call_status = self._commands() _result = _call_status.result @@ -945,8 +875,8 @@ break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice32 - _choice41 = self._pos + self._pos = _choice0 + _choice9 = self._pos try: _call_status = self._commands() _result = _call_status.result @@ -954,7 +884,7 @@ break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice41 + self._pos = _choice9 raise BacktrackException(_error) _call_status = self._commands() _result = _call_status.result @@ -1013,7 +943,7 @@ _result = None _error = None while 1: - _choice42 = self._pos + _choice0 = self._pos try: _call_status = self._command() _result = _call_status.result @@ -1022,40 +952,40 @@ _call_status = self._newline() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all43 = [] + _all1 = [] _call_status = self._command() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _before_discard44 = _result + _before_discard2 = _result _call_status = self._newline() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _result = _before_discard44 - _all43.append(_result) + _result = _before_discard2 + _all1.append(_result) while 1: - _choice45 = self._pos + _choice3 = self._pos try: _call_status = self._command() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _before_discard46 = _result + _before_discard4 = _result _call_status = self._newline() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _result = _before_discard46 - _all43.append(_result) + _result = _before_discard4 + _all1.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice45 + self._pos = _choice3 break - _result = _all43 + _result = _all1 cmds = _result _result = (Nonterminal('commands', [cmd] + cmds)) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice42 - _choice47 = self._pos + self._pos = _choice0 + _choice5 = self._pos try: _call_status = self._command() _result = _call_status.result @@ -1063,7 +993,7 @@ break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice47 + self._pos = _choice5 raise BacktrackException(_error) _call_status = self._command() _result = _call_status.result @@ -1177,7 +1107,7 @@ _result = None _error = None while 1: - _choice48 = self._pos + _choice0 = self._pos try: _call_status = self._return_() _result = _call_status.result @@ -1185,8 +1115,8 @@ break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice48 - _choice49 = self._pos + self._pos = _choice0 + _choice1 = self._pos try: _call_status = self._if_() _result = _call_status.result @@ -1194,8 +1124,8 @@ break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice49 - _choice50 = self._pos + self._pos = _choice1 + _choice2 = self._pos try: _call_status = self._named_command() _result = _call_status.result @@ -1203,8 +1133,8 @@ break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice50 - _choice51 = self._pos + self._pos = _choice2 + _choice3 = self._pos try: _call_status = self._repetition() _result = _call_status.result @@ -1212,8 +1142,8 @@ break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice51 - _choice52 = self._pos + self._pos = _choice3 + _choice4 = self._pos try: _call_status = self._choose() _result = _call_status.result @@ -1221,8 +1151,8 @@ break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice52 - _choice53 = self._pos + self._pos = _choice4 + _choice5 = self._pos try: _call_status = self._negation() _result = _call_status.result @@ -1230,7 +1160,7 @@ break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice53 + self._pos = _choice5 raise BacktrackException(_error) _call_status = self._negation() _result = _call_status.result @@ -1289,36 +1219,36 @@ _result = None _error = None _result = self.__chars__('return') - _all54 = [] + _all0 = [] while 1: - _choice55 = self._pos + _choice1 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = _call_status.error - _all54.append(_result) + _all0.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice55 + self._pos = _choice1 break - _result = _all54 + _result = _all0 _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) code = _result - _all56 = [] + _all2 = [] while 1: - _choice57 = self._pos + _choice3 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all56.append(_result) + _all2.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice57 + self._pos = _choice3 break - _result = _all56 + _result = _all2 _result = (Nonterminal('return', [code])) if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -1373,7 +1303,7 @@ _result = None _error = None while 1: - _choice58 = self._pos + _choice0 = self._pos try: _result = self.__chars__('do') _call_status = self._newline() @@ -1383,125 +1313,125 @@ _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) cmd = _result - _all59 = [] + _all1 = [] while 1: - _choice60 = self._pos + _choice2 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all59.append(_result) + _all1.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice60 + self._pos = _choice2 break - _result = _all59 + _result = _all1 _result = self.__chars__('if') - _all61 = [] + _all3 = [] while 1: - _choice62 = self._pos + _choice4 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all61.append(_result) + _all3.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice62 + self._pos = _choice4 break - _result = _all61 + _result = _all3 _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) condition = _result - _all63 = [] + _all5 = [] while 1: - _choice64 = self._pos + _choice6 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all63.append(_result) + _all5.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice64 + self._pos = _choice6 break - _result = _all63 + _result = _all5 _result = (Nonterminal('if', [cmd, condition])) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice58 - _choice65 = self._pos + self._pos = _choice0 + _choice7 = self._pos try: _result = self.__chars__('if') - _all66 = [] + _all8 = [] while 1: - _choice67 = self._pos + _choice9 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all66.append(_result) + _all8.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice67 + self._pos = _choice9 break - _result = _all66 + _result = _all8 _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) condition = _result - _all68 = [] + _all10 = [] while 1: - _choice69 = self._pos + _choice11 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all68.append(_result) + _all10.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice69 + self._pos = _choice11 break - _result = _all68 + _result = _all10 _result = (Nonterminal('if', [condition])) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice65 + self._pos = _choice7 raise BacktrackException(_error) _result = self.__chars__('if') - _all70 = [] + _all12 = [] while 1: - _choice71 = self._pos + _choice13 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all70.append(_result) + _all12.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice71 + self._pos = _choice13 break - _result = _all70 + _result = _all12 _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) condition = _result - _all72 = [] + _all14 = [] while 1: - _choice73 = self._pos + _choice15 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all72.append(_result) + _all14.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice73 + self._pos = _choice15 break - _result = _all72 + _result = _all14 _result = (Nonterminal('if', [condition])) break if _status.status == _status.LEFTRECURSION: @@ -1557,67 +1487,67 @@ _result = None _error = None _result = self.__chars__('choose') - _all74 = [] + _all0 = [] while 1: - _choice75 = self._pos + _choice1 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = _call_status.error - _all74.append(_result) + _all0.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice75 + self._pos = _choice1 break - _result = _all74 + _result = _all0 _call_status = self._NAME() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) name = _result - _all76 = [] + _all2 = [] while 1: - _choice77 = self._pos + _choice3 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all76.append(_result) + _all2.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice77 + self._pos = _choice3 break - _result = _all76 + _result = _all2 _result = self.__chars__('in') - _all78 = [] + _all4 = [] while 1: - _choice79 = self._pos + _choice5 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all78.append(_result) + _all4.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice79 + self._pos = _choice5 break - _result = _all78 + _result = _all4 _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) expr = _result - _all80 = [] + _all6 = [] while 1: - _choice81 = self._pos + _choice7 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all80.append(_result) + _all6.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice81 + self._pos = _choice7 break - _result = _all80 + _result = _all6 _call_status = self._commands() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) @@ -1675,23 +1605,23 @@ try: _result = None _error = None - _all82 = [] + _all0 = [] _call_status = self._simplecommand() _result = _call_status.result _error = _call_status.error - _all82.append(_result) + _all0.append(_result) while 1: - _choice83 = self._pos + _choice1 = self._pos try: _call_status = self._simplecommand() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all82.append(_result) + _all0.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice83 + self._pos = _choice1 break - _result = _all82 + _result = _all0 result = _result _result = (Nonterminal('commands', result)) if _status.status == _status.LEFTRECURSION: @@ -1750,33 +1680,33 @@ _result = _call_status.result _error = _call_status.error name = _result - _all84 = [] + _all0 = [] while 1: - _choice85 = self._pos + _choice1 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all84.append(_result) + _all0.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice85 + self._pos = _choice1 break - _result = _all84 + _result = _all0 _result = self.__chars__('=') - _all86 = [] + _all2 = [] while 1: - _choice87 = self._pos + _choice3 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all86.append(_result) + _all2.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice87 + self._pos = _choice3 break - _result = _all86 + _result = _all2 _call_status = self._command() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) @@ -1835,150 +1765,150 @@ _result = None _error = None while 1: - _choice88 = self._pos + _choice0 = self._pos try: _call_status = self._enclosed() _result = _call_status.result _error = _call_status.error what = _result - _all89 = [] + _all1 = [] while 1: - _choice90 = self._pos + _choice2 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all89.append(_result) + _all1.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice90 + self._pos = _choice2 break - _result = _all89 + _result = _all1 _result = self.__chars__('?') - _all91 = [] + _all3 = [] while 1: - _choice92 = self._pos + _choice4 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all91.append(_result) + _all3.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice92 + self._pos = _choice4 break - _result = _all91 + _result = _all3 _result = (Nonterminal('maybe', [what])) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice88 - _choice93 = self._pos + self._pos = _choice0 + _choice5 = self._pos try: _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) what = _result - _all94 = [] + _all6 = [] while 1: - _choice95 = self._pos + _choice7 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all94.append(_result) + _all6.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice95 + self._pos = _choice7 break - _result = _all94 + _result = _all6 while 1: - _choice96 = self._pos + _choice8 = self._pos try: _result = self.__chars__('*') break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice96 - _choice97 = self._pos + self._pos = _choice8 + _choice9 = self._pos try: _result = self.__chars__('+') break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice97 + self._pos = _choice9 raise BacktrackException(_error) _result = self.__chars__('+') break repetition = _result - _all98 = [] + _all10 = [] while 1: - _choice99 = self._pos + _choice11 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all98.append(_result) + _all10.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice99 + self._pos = _choice11 break - _result = _all98 + _result = _all10 _result = (Nonterminal('repetition', [repetition, what])) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice93 + self._pos = _choice5 raise BacktrackException(_error) _call_status = self._enclosed() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) what = _result - _all100 = [] + _all12 = [] while 1: - _choice101 = self._pos + _choice13 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all100.append(_result) + _all12.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice101 + self._pos = _choice13 break - _result = _all100 + _result = _all12 while 1: - _choice102 = self._pos + _choice14 = self._pos try: _result = self.__chars__('*') break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice102 - _choice103 = self._pos + self._pos = _choice14 + _choice15 = self._pos try: _result = self.__chars__('+') break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice103 + self._pos = _choice15 raise BacktrackException(_error) _result = self.__chars__('+') break repetition = _result - _all104 = [] + _all16 = [] while 1: - _choice105 = self._pos + _choice17 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all104.append(_result) + _all16.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice105 + self._pos = _choice17 break - _result = _all104 + _result = _all16 _result = (Nonterminal('repetition', [repetition, what])) break if _status.status == _status.LEFTRECURSION: @@ -2034,45 +1964,45 @@ _result = None _error = None while 1: - _choice106 = self._pos + _choice0 = self._pos try: _result = self.__chars__('!') - _all107 = [] + _all1 = [] while 1: - _choice108 = self._pos + _choice2 = self._pos try: _call_status = self._SPACE() _result = _call_status.result _error = _call_status.error - _all107.append(_result) + _all1.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice108 + self._pos = _choice2 break - _result = _all107 + _result = _all1 _call_status = self._negation() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) what = _result - _all109 = [] + _all3 = [] while 1: - _choice110 = self._pos + _choice4 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all109.append(_result) + _all3.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice110 + self._pos = _choice4 break - _result = _all109 + _result = _all3 _result = (Nonterminal('negation', [what])) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice106 - _choice111 = self._pos + self._pos = _choice0 + _choice5 = self._pos try: _call_status = self._enclosed() _result = _call_status.result @@ -2080,7 +2010,7 @@ break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice111 + self._pos = _choice5 raise BacktrackException(_error) _call_status = self._enclosed() _result = _call_status.result @@ -2139,152 +2069,152 @@ _result = None _error = None while 1: - _choice112 = self._pos + _choice0 = self._pos try: _result = self.__chars__('<') - _all113 = [] + _all1 = [] while 1: - _choice114 = self._pos + _choice2 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = _call_status.error - _all113.append(_result) + _all1.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice114 + self._pos = _choice2 break - _result = _all113 + _result = _all1 _call_status = self._primary() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) what = _result - _all115 = [] + _all3 = [] while 1: - _choice116 = self._pos + _choice4 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all115.append(_result) + _all3.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice116 + self._pos = _choice4 break - _result = _all115 + _result = _all3 _result = self.__chars__('>') - _all117 = [] + _all5 = [] while 1: - _choice118 = self._pos + _choice6 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all117.append(_result) + _all5.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice118 + self._pos = _choice6 break - _result = _all117 + _result = _all5 _result = (Nonterminal('exclusive', [what])) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice112 - _choice119 = self._pos + self._pos = _choice0 + _choice7 = self._pos try: _result = self.__chars__('[') - _all120 = [] + _all8 = [] while 1: - _choice121 = self._pos + _choice9 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all120.append(_result) + _all8.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice121 + self._pos = _choice9 break - _result = _all120 + _result = _all8 _call_status = self._or_() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) what = _result - _all122 = [] + _all10 = [] while 1: - _choice123 = self._pos + _choice11 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all122.append(_result) + _all10.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice123 + self._pos = _choice11 break - _result = _all122 + _result = _all10 _result = self.__chars__(']') - _all124 = [] + _all12 = [] while 1: - _choice125 = self._pos + _choice13 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all124.append(_result) + _all12.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice125 + self._pos = _choice13 break - _result = _all124 + _result = _all12 _result = (Nonterminal('ignore', [what])) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice119 - _choice126 = self._pos + self._pos = _choice7 + _choice14 = self._pos try: - _before_discard127 = _result + _before_discard15 = _result _result = self.__chars__('(') - _all128 = [] + _all16 = [] while 1: - _choice129 = self._pos + _choice17 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all128.append(_result) + _all16.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice129 + self._pos = _choice17 break - _result = _all128 - _result = _before_discard127 + _result = _all16 + _result = _before_discard15 _call_status = self._or_() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _before_discard130 = _result + _before_discard18 = _result _result = self.__chars__(')') - _all131 = [] + _all19 = [] while 1: - _choice132 = self._pos + _choice20 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all131.append(_result) + _all19.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice132 + self._pos = _choice20 break - _result = _all131 - _result = _before_discard130 + _result = _all19 + _result = _before_discard18 break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice126 - _choice133 = self._pos + self._pos = _choice14 + _choice21 = self._pos try: _call_status = self._primary() _result = _call_status.result @@ -2292,7 +2222,7 @@ break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice133 + self._pos = _choice21 raise BacktrackException(_error) _call_status = self._primary() _result = _call_status.result @@ -2351,7 +2281,7 @@ _result = None _error = None while 1: - _choice134 = self._pos + _choice0 = self._pos try: _call_status = self._call() _result = _call_status.result @@ -2359,74 +2289,74 @@ break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice134 - _choice135 = self._pos + self._pos = _choice0 + _choice1 = self._pos try: _call_status = self._REGEX() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _before_discard136 = _result - _all137 = [] + _before_discard2 = _result + _all3 = [] while 1: - _choice138 = self._pos + _choice4 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all137.append(_result) + _all3.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice138 + self._pos = _choice4 break - _result = _all137 - _result = _before_discard136 + _result = _all3 + _result = _before_discard2 break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice135 - _choice139 = self._pos + self._pos = _choice1 + _choice5 = self._pos try: _call_status = self._QUOTE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _before_discard140 = _result - _all141 = [] + _before_discard6 = _result + _all7 = [] while 1: - _choice142 = self._pos + _choice8 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all141.append(_result) + _all7.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice142 + self._pos = _choice8 break - _result = _all141 - _result = _before_discard140 + _result = _all7 + _result = _before_discard6 break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice139 + self._pos = _choice5 raise BacktrackException(_error) _call_status = self._QUOTE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _before_discard143 = _result - _all144 = [] + _before_discard9 = _result + _all10 = [] while 1: - _choice145 = self._pos + _choice11 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all144.append(_result) + _all10.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice145 + self._pos = _choice11 break - _result = _all144 - _result = _before_discard143 + _result = _all10 + _result = _before_discard9 break if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -2488,19 +2418,19 @@ _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) args = _result - _all146 = [] + _all0 = [] while 1: - _choice147 = self._pos + _choice1 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all146.append(_result) + _all0.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice147 + self._pos = _choice1 break - _result = _all146 + _result = _all0 _result = (Nonterminal("call", [x, args])) if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -2555,95 +2485,95 @@ _result = None _error = None while 1: - _choice148 = self._pos + _choice0 = self._pos try: _result = self.__chars__('(') - _all149 = [] + _all1 = [] while 1: - _choice150 = self._pos + _choice2 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = _call_status.error - _all149.append(_result) + _all1.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice150 + self._pos = _choice2 break - _result = _all149 - _all151 = [] + _result = _all1 + _all3 = [] while 1: - _choice152 = self._pos + _choice4 = self._pos try: _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _before_discard153 = _result - _all154 = [] + _before_discard5 = _result + _all6 = [] while 1: - _choice155 = self._pos + _choice7 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all154.append(_result) + _all6.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice155 + self._pos = _choice7 break - _result = _all154 + _result = _all6 _result = self.__chars__(',') - _all156 = [] + _all8 = [] while 1: - _choice157 = self._pos + _choice9 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all156.append(_result) + _all8.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice157 + self._pos = _choice9 break - _result = _all156 - _result = _before_discard153 - _all151.append(_result) + _result = _all8 + _result = _before_discard5 + _all3.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice152 + self._pos = _choice4 break - _result = _all151 + _result = _all3 args = _result _call_status = self._PYTHONCODE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) last = _result _result = self.__chars__(')') - _all158 = [] + _all10 = [] while 1: - _choice159 = self._pos + _choice11 = self._pos try: _call_status = self._IGNORE() _result = _call_status.result _error = self._combine_errors(_error, _call_status.error) - _all158.append(_result) + _all10.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice159 + self._pos = _choice11 break - _result = _all158 + _result = _all10 _result = (Nonterminal("args", args + [last])) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice148 - _choice160 = self._pos + self._pos = _choice0 + _choice12 = self._pos try: _result = (Nonterminal("args", [])) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice160 + self._pos = _choice12 raise BacktrackException(_error) _result = (Nonterminal("args", [])) break @@ -2703,77 +2633,77 @@ self._pos = 0 self._inputstream = inputstream def _regex299149370(self): - _choice161 = self._pos + _choice13 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_299149370(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice161 + self._pos = _choice13 raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1006631623(self): - _choice162 = self._pos + _choice14 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1006631623(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice162 + self._pos = _choice14 raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex528667127(self): - _choice163 = self._pos + _choice15 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_528667127(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice163 + self._pos = _choice15 raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex291086639(self): - _choice164 = self._pos + _choice16 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_291086639(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice164 + self._pos = _choice16 raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1074651696(self): - _choice165 = self._pos + _choice17 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1074651696(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice165 + self._pos = _choice17 raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1124192327(self): - _choice166 = self._pos + _choice18 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1124192327(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice166 + self._pos = _choice18 raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1979538501(self): - _choice167 = self._pos + _choice19 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1979538501(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice167 + self._pos = _choice19 raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] Modified: pypy/dist/pypy/rlib/parsing/regexparse.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/regexparse.py (original) +++ pypy/dist/pypy/rlib/parsing/regexparse.py Tue Jun 26 00:13:29 2007 @@ -1,8 +1,3 @@ - - - - - import py from pypy.rlib.parsing.parsing import PackratParser, Rule from pypy.rlib.parsing.tree import Nonterminal @@ -198,9 +193,12 @@ -# generated code between this line and its other occurence + + +# generated code between this line and its other occurence + from pypy.rlib.parsing.pypackrat import PackratParser, Status from pypy.rlib.parsing.pypackrat import BacktrackException from pypy.rlib.parsing import regex @@ -213,21 +211,23 @@ _status = self._dict_EOF.get(_key, None) if _status is None: _status = self._dict_EOF[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -261,7 +261,7 @@ except BacktrackException, _exc: _status.pos = -1 _status.result = None - _error = self._combine_errors(_error, _exc.error) + _error = _exc.error _status.error = _error _status.status = _status.ERROR raise BacktrackException(_error) @@ -272,33 +272,35 @@ _status = self._dict_parse.get(_key, None) if _status is None: _status = self._dict_parse[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None _call_status = self._regex() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) - _before_discard2 = _result + _error = _call_status.error + _before_discard0 = _result _call_status = self._EOF() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) - _result = _before_discard2 + _error = self._combine_errors(_error, _call_status.error) + _result = _before_discard0 if _status.status == _status.LEFTRECURSION: if _status.result is not None: if _status.pos >= self._pos: @@ -330,56 +332,57 @@ _status = self._dict_regex.get(_key, None) if _status is None: _status = self._dict_regex[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None - _choice3 = self._pos + _choice0 = self._pos try: _call_status = self._concatenation() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error r1 = _result _result = self.__chars__('|') _call_status = self._regex() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) r2 = _result _result = (r1 | r2) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice3 - _choice4 = self._pos + self._pos = _choice0 + _choice1 = self._pos try: _call_status = self._concatenation() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice4 + self._pos = _choice1 raise BacktrackException(_error) _call_status = self._concatenation() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -412,42 +415,44 @@ _status = self._dict_concatenation.get(_key, None) if _status is None: _status = self._dict_concatenation[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None - _all5 = [] + _all0 = [] _call_status = self._repetition() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) - _all5.append(_result) + _error = _call_status.error + _all0.append(_result) while 1: - _choice6 = self._pos + _choice1 = self._pos try: _call_status = self._repetition() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) - _all5.append(_result) + _error = self._combine_errors(_error, _call_status.error) + _all0.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice6 + self._pos = _choice1 break - _result = _all5 + _result = _all0 l = _result _result = (reduce(operator.add, l, regex.StringExpression(""))) if _status.status == _status.LEFTRECURSION: @@ -481,93 +486,94 @@ _status = self._dict_repetition.get(_key, None) if _status is None: _status = self._dict_repetition[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None - _choice7 = self._pos + _choice0 = self._pos try: _call_status = self._primary() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error r1 = _result _result = self.__chars__('*') _result = (r1.kleene()) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice7 - _choice8 = self._pos + self._pos = _choice0 + _choice1 = self._pos try: _call_status = self._primary() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) r1 = _result _result = self.__chars__('+') _result = (r1 + r1.kleene()) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice8 - _choice9 = self._pos + self._pos = _choice1 + _choice2 = self._pos try: _call_status = self._primary() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) r1 = _result _result = self.__chars__('?') _result = (regex.StringExpression("") | r1) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice9 - _choice10 = self._pos + self._pos = _choice2 + _choice3 = self._pos try: _call_status = self._primary() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) r = _result _result = self.__chars__('{') _call_status = self._numrange() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) n = _result _result = self.__chars__('}') _result = (r * n[0] + reduce(operator.or_, [r * i for i in range(n[1] - n[0] + 1)], regex.StringExpression(""))) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice10 - _choice11 = self._pos + self._pos = _choice3 + _choice4 = self._pos try: _call_status = self._primary() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice11 + self._pos = _choice4 raise BacktrackException(_error) _call_status = self._primary() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -600,70 +606,71 @@ _status = self._dict_primary.get(_key, None) if _status is None: _status = self._dict_primary[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None - _choice12 = self._pos + _choice0 = self._pos try: - _before_discard13 = _result + _before_discard1 = _result _result = self.__chars__('(') - _result = _before_discard13 + _result = _before_discard1 _call_status = self._regex() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) - _before_discard14 = _result + _error = _call_status.error + _before_discard2 = _result _result = self.__chars__(')') - _result = _before_discard14 + _result = _before_discard2 break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice12 - _choice15 = self._pos + self._pos = _choice0 + _choice3 = self._pos try: _call_status = self._range() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice15 - _choice16 = self._pos + self._pos = _choice3 + _choice4 = self._pos try: _call_status = self._char() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) c = _result _result = (regex.StringExpression(c)) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice16 - _choice17 = self._pos + self._pos = _choice4 + _choice5 = self._pos try: _result = self.__chars__('.') _result = (regex.RangeExpression(chr(0), chr(255))) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice17 + self._pos = _choice5 raise BacktrackException(_error) _result = self.__chars__('.') _result = (regex.RangeExpression(chr(0), chr(255))) @@ -699,53 +706,54 @@ _status = self._dict_char.get(_key, None) if _status is None: _status = self._dict_char[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None - _choice18 = self._pos + _choice0 = self._pos try: _call_status = self._QUOTEDCHAR() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error c = _result _result = (unescape(c)) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice18 - _choice19 = self._pos + self._pos = _choice0 + _choice1 = self._pos try: _call_status = self._CHAR() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) c = _result _result = (c) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice19 + self._pos = _choice1 raise BacktrackException(_error) _call_status = self._CHAR() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) c = _result _result = (c) break @@ -780,38 +788,19 @@ _status = self._dict_QUOTEDCHAR.get(_key, None) if _status is None: _status = self._dict_QUOTEDCHAR[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) _startingpos = self._pos try: _result = None _error = None _result = self._regex1380912319() - if _status.status == _status.LEFTRECURSION: - if _status.result is not None: - if _status.pos >= self._pos: - _status.status = _status.NORMAL - self._pos = _status.pos - return _status - _status.pos = self._pos - _status.status = _status.SOMESOLUTIONS - _status.result = _result - _status.error = _error - self._pos = _startingpos - return self._QUOTEDCHAR() + assert _status.status != _status.LEFTRECURSION _status.status = _status.NORMAL _status.pos = self._pos _status.result = _result @@ -820,7 +809,7 @@ except BacktrackException, _exc: _status.pos = -1 _status.result = None - _error = self._combine_errors(_error, _exc.error) + _error = _exc.error _status.error = _error _status.status = _status.ERROR raise BacktrackException(_error) @@ -831,38 +820,19 @@ _status = self._dict_CHAR.get(_key, None) if _status is None: _status = self._dict_CHAR[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) _startingpos = self._pos try: _result = None _error = None _result = self._regex1323868075() - if _status.status == _status.LEFTRECURSION: - if _status.result is not None: - if _status.pos >= self._pos: - _status.status = _status.NORMAL - self._pos = _status.pos - return _status - _status.pos = self._pos - _status.status = _status.SOMESOLUTIONS - _status.result = _result - _status.error = _error - self._pos = _startingpos - return self._CHAR() + assert _status.status != _status.LEFTRECURSION _status.status = _status.NORMAL _status.pos = self._pos _status.result = _result @@ -871,7 +841,7 @@ except BacktrackException, _exc: _status.pos = -1 _status.result = None - _error = self._combine_errors(_error, _exc.error) + _error = _exc.error _status.error = _error _status.status = _status.ERROR raise BacktrackException(_error) @@ -882,21 +852,23 @@ _status = self._dict_range.get(_key, None) if _status is None: _status = self._dict_range[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None @@ -904,7 +876,7 @@ _result = self.__chars__('[') _call_status = self._rangeinner() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error s = _result _result = self.__chars__(']') _result = (reduce(operator.or_, [regex.RangeExpression(a, chr(ord(a) + b - 1)) for a, b in compress_char_set(s)])) @@ -939,52 +911,53 @@ _status = self._dict_rangeinner.get(_key, None) if _status is None: _status = self._dict_rangeinner[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None - _choice20 = self._pos + _choice0 = self._pos try: _result = self.__chars__('^') _call_status = self._subrange() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error s = _result _result = (set([chr(c) for c in range(256)]) - s) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice20 - _choice21 = self._pos + self._pos = _choice0 + _choice1 = self._pos try: _call_status = self._subrange() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice21 + self._pos = _choice1 raise BacktrackException(_error) _call_status = self._subrange() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) break if _status.status == _status.LEFTRECURSION: if _status.result is not None: @@ -1017,42 +990,44 @@ _status = self._dict_subrange.get(_key, None) if _status is None: _status = self._dict_subrange[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None - _all22 = [] + _all0 = [] _call_status = self._rangeelement() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) - _all22.append(_result) + _error = _call_status.error + _all0.append(_result) while 1: - _choice23 = self._pos + _choice1 = self._pos try: _call_status = self._rangeelement() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) - _all22.append(_result) + _error = self._combine_errors(_error, _call_status.error) + _all0.append(_result) except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice23 + self._pos = _choice1 break - _result = _all22 + _result = _all0 l = _result _result = (reduce(operator.or_, l)) if _status.status == _status.LEFTRECURSION: @@ -1086,58 +1061,59 @@ _status = self._dict_rangeelement.get(_key, None) if _status is None: _status = self._dict_rangeelement[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None - _choice24 = self._pos + _choice0 = self._pos try: _call_status = self._char() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error c1 = _result _result = self.__chars__('-') _call_status = self._char() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) c2 = _result _result = (set([chr(i) for i in range(ord(c1), ord(c2) + 1)])) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice24 - _choice25 = self._pos + self._pos = _choice0 + _choice1 = self._pos try: _call_status = self._char() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) c = _result _result = (set([c])) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice25 + self._pos = _choice1 raise BacktrackException(_error) _call_status = self._char() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) c = _result _result = (set([c])) break @@ -1172,58 +1148,59 @@ _status = self._dict_numrange.get(_key, None) if _status is None: _status = self._dict_numrange[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) + elif (_statusstatus == _status.INPROGRESS or + _statusstatus == _status.LEFTRECURSION): + _status.status = _status.LEFTRECURSION + if _status.result is not None: + self._pos = _status.pos + return _status + else: + raise BacktrackException(None) + elif _statusstatus == _status.SOMESOLUTIONS: + _status.status = _status.INPROGRESS _startingpos = self._pos try: _result = None _error = None while 1: - _error = None - _choice26 = self._pos + _choice0 = self._pos try: _call_status = self._NUM() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = _call_status.error n1 = _result _result = self.__chars__(',') _call_status = self._NUM() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) n2 = _result _result = (n1, n2) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice26 - _choice27 = self._pos + self._pos = _choice0 + _choice1 = self._pos try: _call_status = self._NUM() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) n1 = _result _result = (n1, n1) break except BacktrackException, _exc: _error = self._combine_errors(_error, _exc.error) - self._pos = _choice27 + self._pos = _choice1 raise BacktrackException(_error) _call_status = self._NUM() _result = _call_status.result - _error = self._combine_errors(_call_status.error, _error) + _error = self._combine_errors(_error, _call_status.error) n1 = _result _result = (n1, n1) break @@ -1258,21 +1235,13 @@ _status = self._dict_NUM.get(_key, None) if _status is None: _status = self._dict_NUM[_key] = Status() - elif _status.status == _status.NORMAL: - self._pos = _status.pos - return _status - elif _status.status == _status.ERROR: - raise BacktrackException(_status.error) - elif (_status.status == _status.INPROGRESS or - _status.status == _status.LEFTRECURSION): - _status.status = _status.LEFTRECURSION - if _status.result is not None: + else: + _statusstatus = _status.status + if _statusstatus == _status.NORMAL: self._pos = _status.pos return _status - else: - raise BacktrackException(None) - elif _status.status == _status.SOMESOLUTIONS: - _status.status = _status.INPROGRESS + elif _statusstatus == _status.ERROR: + raise BacktrackException(_status.error) _startingpos = self._pos try: _result = None @@ -1280,18 +1249,7 @@ _result = self._regex1166214427() c = _result _result = (int(c)) - if _status.status == _status.LEFTRECURSION: - if _status.result is not None: - if _status.pos >= self._pos: - _status.status = _status.NORMAL - self._pos = _status.pos - return _status - _status.pos = self._pos - _status.status = _status.SOMESOLUTIONS - _status.result = _result - _status.error = _error - self._pos = _startingpos - return self._NUM() + assert _status.status != _status.LEFTRECURSION _status.status = _status.NORMAL _status.pos = self._pos _status.result = _result @@ -1300,7 +1258,7 @@ except BacktrackException, _exc: _status.pos = -1 _status.result = None - _error = self._combine_errors(_error, _exc.error) + _error = _exc.error _status.error = _error _status.status = _status.ERROR raise BacktrackException(_error) @@ -1323,33 +1281,33 @@ self._pos = 0 self._inputstream = inputstream def _regex1166214427(self): - _choice28 = self._pos + _choice0 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1166214427(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice28 + self._pos = _choice0 raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1323868075(self): - _choice29 = self._pos + _choice1 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1323868075(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice29 + self._pos = _choice1 raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] self._pos = _upto return _result def _regex1380912319(self): - _choice30 = self._pos + _choice2 = self._pos _runner = self._Runner(self._inputstream, self._pos) _i = _runner.recognize_1380912319(self._pos) if _runner.last_matched_state == -1: - self._pos = _choice30 + self._pos = _choice2 raise BacktrackException _upto = _runner.last_matched_index + 1 _result = self._inputstream[self._pos: _upto] @@ -1523,7 +1481,6 @@ if key not in RegexParser.__dict__ and key not in forbidden: setattr(RegexParser, key, value) RegexParser.init_parser = Parser.__init__.im_func - # generated code between this line and its other occurence @@ -1537,6 +1494,13 @@ + + + + + + + def test_generate(): f = py.magic.autopath() oldcontent = f.read() @@ -1551,10 +1515,9 @@ visitor = ParserBuilder() t.visit(visitor) code = visitor.get_code() - content = """ -%s + content = """\ +%s\ %s - from pypy.rlib.parsing.pypackrat import PackratParser, Status from pypy.rlib.parsing.pypackrat import BacktrackException from pypy.rlib.parsing import regex @@ -1570,12 +1533,8 @@ if key not in RegexParser.__dict__ and key not in forbidden: setattr(RegexParser, key, value) RegexParser.init_parser = Parser.__init__.im_func - -%s %s +%s\ """ % (pre, s, code, s, after) print content f.write(content) - - - From cfbolz at codespeak.net Tue Jun 26 00:41:40 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Tue, 26 Jun 2007 00:41:40 +0200 (CEST) Subject: [pypy-svn] r44535 - pypy/dist/pypy/rlib/parsing/test Message-ID: <20070625224140.09FE580C4@code0.codespeak.net> Author: cfbolz Date: Tue Jun 26 00:41:40 2007 New Revision: 44535 Modified: pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Log: another test for good errors Modified: pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Tue Jun 26 00:41:40 2007 @@ -268,6 +268,21 @@ assert excinfo.value.error.pos == 2 assert excinfo.value.error.expected == ['b'] + def test_error_success(self): + class parser(PackratParser): + """ + b: + bstar !__any__; + bstar: + 'b'*; + """ + print parser._code + p = parser("bbc") + print parser._code + excinfo = py.test.raises(BacktrackException, p.b) + assert excinfo.value.error.pos == 2 + assert excinfo.value.error.expected == ['b'] + def test_leftrecursion(self): class parser(PackratParser): """ From cfbolz at codespeak.net Tue Jun 26 00:55:38 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Tue, 26 Jun 2007 00:55:38 +0200 (CEST) Subject: [pypy-svn] r44536 - pypy/dist/pypy/rlib/parsing Message-ID: <20070625225538.6A81180C5@code0.codespeak.net> Author: cfbolz Date: Tue Jun 26 00:55:38 2007 New Revision: 44536 Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py Log: try to generate nice error messages Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/makepackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/makepackrat.py Tue Jun 26 00:55:38 2007 @@ -10,6 +10,7 @@ Exception.__init__(self, error) + class TreeOptimizer(RPythonVisitor): def visit_or(self, t): if len(t.children) == 1: @@ -248,6 +249,33 @@ def __str__(self): return "ErrorInformation(%s, %s)" % (self.pos, self.expected) + def get_line_column(self, source): + uptoerror = source[:self.pos] + lineno = uptoerror.count("\n") + columnno = self.pos - uptoerror.rfind("\n") + return lineno, columnno + + def nice_error_message(self, filename='', source=""): + if source: + lineno, columnno = self.get_line_column(source) + result = [" File %s, line %s" % (filename, lineno + 1)] + result.append(source.split("\n")[lineno]) + result.append(" " * columnno + "^") + else: + result.append("") + if self.expected: + failure_reasons = self.expected + if len(failure_reasons) > 1: + all_but_one = failure_reasons[:-1] + last = failure_reasons[-1] + expected = "%s or '%s'" % ( + ", ".join(["'%s'" % e for e in all_but_one]), last) + else: + expected = failure_reasons[0] + result.append("ParseError: expected %s" % (expected, )) + else: + result.append("ParseError") + return "\n".join(result) class Status(object): # status codes: @@ -634,10 +662,27 @@ if '__doc__' not in dct or dct['__doc__'] is None: return type.__new__(cls, name_, bases, dct) from pypackrat import PyPackratSyntaxParser - import sys, new + import sys, new, inspect frame = sys._getframe(1) - p = PyPackratSyntaxParser(dct['__doc__']) - t = p.file() + source = dct['__doc__'] + p = PyPackratSyntaxParser(source) + try: + t = p.file() + except BacktrackException, exc: + print exc.error.nice_error_message("", source) + lineno, _ = exc.error.get_line_column(source) + errorline = source.split("\n")[lineno] + try: + code = frame.f_code + source = inspect.getsource(code) + lineno_in_orig = source.split("\n").index(errorline) + if lineno_in_orig >= 0: + print "probable error position:" + print "file:", code.co_filename + print "line:", lineno_in_orig + code.co_firstlineno + 1 + except (IOError, ValueError): + pass + raise exc t = t.visit(TreeOptimizer()) visitor = ParserBuilder() t.visit(visitor) @@ -649,6 +694,8 @@ #XXX XXX XXX if 'BacktrackException' not in frame.f_globals: raise Exception("must import BacktrackException") + if 'Status' not in frame.f_globals: + raise Exception("must import Status") for key, value in pcls.__dict__.iteritems(): if isinstance(value, type(lambda: None)): value = new.function(value.func_code, frame.f_globals) From antocuni at codespeak.net Tue Jun 26 14:00:35 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Tue, 26 Jun 2007 14:00:35 +0200 (CEST) Subject: [pypy-svn] r44540 - in pypy/dist/pypy/translator/cli: . test Message-ID: <20070626120035.3414280CF@code0.codespeak.net> Author: antocuni Date: Tue Jun 26 14:00:33 2007 New Revision: 44540 Modified: pypy/dist/pypy/translator/cli/silverpython.py pypy/dist/pypy/translator/cli/test/test_silverpython.py Log: - @export decorator, to let the user to specify the annotation of the enty-points of the DLL - a procedure to scan a file and collect all the export()ed names Modified: pypy/dist/pypy/translator/cli/silverpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/silverpython.py (original) +++ pypy/dist/pypy/translator/cli/silverpython.py Tue Jun 26 14:00:33 2007 @@ -1,8 +1,20 @@ +#! /usr/bin/env python +""" +Usage: silverpython.py .py + +Compiles an RPython module into a .NET dll. +""" + +import sys +import new +import types +import os.path + from pypy.translator.driver import TranslationDriver from pypy.translator.cli.entrypoint import DllEntryPoint class DllDef: - def __init__(self, name, namespace, functions=[], classes=[]): + def __init__(self, name, namespace, functions=[]): self.name = name self.namespace = namespace self.functions = functions # [(function, annotation), ...] @@ -20,25 +32,61 @@ if not hasattr(func, '_namespace_'): func._namespace_ = self.namespace driver = TranslationDriver() + driver.config.translation.ootype.mangle = False driver.setup_library(self) driver.proceed(['compile_cli']) return driver - -class MyClass: - def __init__(self, x): - self.x = x - - def foo(self): - return self.x - -def main(): - dll = DllDef('mylibrary', 'foo', [], [ - (MyClass, [int]), - ]) +class export(object): + def __new__(self, *args, **kwds): + if len(args) == 1 and isinstance(args[0], types.FunctionType): + func = args[0] + func._inputtypes_ = () + return func + return object.__new__(self, *args, **kwds) + + def __init__(self, *args, **kwds): + self.inputtypes = args + self.namespace = kwds.pop('namespace', None) + if len(kwds) > 0: + raise TypeError, "unexpected keyword argument: '%s'" % kwds.keys()[0] + + def __call__(self, func): + func._inputtypes_ = self.inputtypes + if self.namespace is not None: + func._namespace_ = self.namespace + return func + +def collect_entrypoints(dic): + entrypoints = [] + for item in dic.itervalues(): + if isinstance(item, types.FunctionType) and hasattr(item, '_inputtypes_'): + entrypoints.append((item, item._inputtypes_)) + return entrypoints + +def compile_dll(filename): + _, name = os.path.split(filename) + dllname, _ = os.path.splitext(name) + + module = new.module(dllname) + execfile(filename, module.__dict__) + entrypoints = collect_entrypoints(module.__dict__) + namespace = module.__dict__.get('_namespace_', dllname) + + dll = DllDef(dllname, namespace, entrypoints) driver = dll.compile() driver.copy_cli_dll() - + +def main(argv): + if len(argv) != 2: + print >> sys.stderr, __doc__ + sys.exit(2) + filename = argv[1] + if not os.path.exists(filename): + print >> sys.stderr, "Cannot find file %s" % filename + sys.exit(1) + compile_dll(filename) if __name__ == '__main__': - main() + main(sys.argv) + Modified: pypy/dist/pypy/translator/cli/test/test_silverpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/test/test_silverpython.py (original) +++ pypy/dist/pypy/translator/cli/test/test_silverpython.py Tue Jun 26 14:00:33 2007 @@ -1,6 +1,6 @@ from pypy.tool import udir from pypy.translator.cli.rte import Target -from pypy.translator.cli.silverpython import DllDef +from pypy.translator.cli.silverpython import DllDef, export, collect_entrypoints from pypy.translator.cli.test.runtest import CliFunctionWrapper, CliTest TEMPLATE = """ @@ -31,7 +31,6 @@ func = CliFunctionWrapper(MyTarget.get()) return func() - def test_compilation(self): res = self._csharp(None, 'Console.WriteLine(42);') assert res == 42 @@ -56,3 +55,30 @@ dll.compile() res = self._csharp('test', 'Console.WriteLine("{0}, {1}", Test.foo(42), Test.bar(42));') assert res == (43, 84) + + def test_export(self): + @export(int, float) + def foo(x, y): + pass + @export(int, float, namespace='test') + def bar(x, y): + pass + @export + def baz(): + pass + + assert foo._inputtypes_ == (int, float) + assert not hasattr(foo, '_namespace_') + assert bar._inputtypes_ == (int, float) + assert bar._namespace_ == 'test' + assert baz._inputtypes_ == () + + def test_collect_entrypoints(self): + @export(int, float) + def foo(x, y): + pass + def bar(x, y): + pass + mydict = dict(foo=foo, bar=bar, x=42) + entrypoints = collect_entrypoints(mydict) + assert entrypoints == [(foo, (int, float))] From antocuni at codespeak.net Tue Jun 26 14:53:04 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Tue, 26 Jun 2007 14:53:04 +0200 (CEST) Subject: [pypy-svn] r44542 - pypy/dist/pypy/doc/config Message-ID: <20070626125304.807BC80DA@code0.codespeak.net> Author: antocuni Date: Tue Jun 26 14:53:04 2007 New Revision: 44542 Added: pypy/dist/pypy/doc/config/translation.ootype.mangle.txt (contents, props changed) pypy/dist/pypy/doc/config/translation.ootype.txt (contents, props changed) Log: documentation for the new options Added: pypy/dist/pypy/doc/config/translation.ootype.mangle.txt ============================================================================== --- (empty file) +++ pypy/dist/pypy/doc/config/translation.ootype.mangle.txt Tue Jun 26 14:53:04 2007 @@ -0,0 +1,3 @@ +Mangle the names of user defined attributes of the classes, in order +to ensure that every name is unique. Default is true, and it should +not be turned off unless you know what you are doing. Added: pypy/dist/pypy/doc/config/translation.ootype.txt ============================================================================== --- (empty file) +++ pypy/dist/pypy/doc/config/translation.ootype.txt Tue Jun 26 14:53:04 2007 @@ -0,0 +1 @@ +This group contains options specific for ootypesystem. From simonb at codespeak.net Tue Jun 26 20:41:45 2007 From: simonb at codespeak.net (simonb at codespeak.net) Date: Tue, 26 Jun 2007 20:41:45 +0200 (CEST) Subject: [pypy-svn] r44550 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070626184145.6EA5680F9@code0.codespeak.net> Author: simonb Date: Tue Jun 26 20:41:44 2007 New Revision: 44550 Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt Log: simon is coming to the sprint Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/people.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/people.txt Tue Jun 26 20:41:44 2007 @@ -18,6 +18,7 @@ Jacob Hallen 7/14th Ratonda Centrum Hotels Jakub Gustak 8/15th Hospitality Club :) Christian Tismer 8/16th Ratonda Centrum Hotels +Simon Burton 8/15th ==================== ============== ======================= People on the following list were present at previous sprints: From arigo at codespeak.net Tue Jun 26 21:03:19 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 26 Jun 2007 21:03:19 +0200 (CEST) Subject: [pypy-svn] r44551 - pypy/dist/pypy/doc Message-ID: <20070626190319.0402180D3@code0.codespeak.net> Author: arigo Date: Tue Jun 26 21:03:19 2007 New Revision: 44551 Modified: pypy/dist/pypy/doc/news.txt Log: Link to the Vilnius sprint announcement. Modified: pypy/dist/pypy/doc/news.txt ============================================================================== --- pypy/dist/pypy/doc/news.txt (original) +++ pypy/dist/pypy/doc/news.txt Tue Jun 26 21:03:19 2007 @@ -14,6 +14,18 @@ .. _`iCalendar format`: webcal://pypycal.sabi.net///calendars/PyPy.ics .. _eventhistory: eventhistory.html +PyPy Sprint at EuroPython, Vilnius: 12-14th July 2007 +================================================================== + +The next EuroPython_ conference will be held in Vilnius from the 9th to +the 11th of July, 2007. It now became a tradition to have several PyPy +talks during the conference, followed by a sprint. For more information +on the latter, see the `Vilnius sprint announcement`_. + +.. _EuroPython: http://europython.org +.. _`Vilnius sprint announcement`: http://codespeak.net/pypy/extradoc/sprintinfo/post-ep2007/announcement.html + + Review passed with flying colours ================================= From cfbolz at codespeak.net Wed Jun 27 13:21:12 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Wed, 27 Jun 2007 13:21:12 +0200 (CEST) Subject: [pypy-svn] r44556 - pypy/dist/pypy/rlib/parsing Message-ID: <20070627112112.422A080CE@code0.codespeak.net> Author: cfbolz Date: Wed Jun 27 13:21:10 2007 New Revision: 44556 Added: pypy/dist/pypy/rlib/parsing/codebuilder.py Modified: pypy/dist/pypy/rlib/parsing/ebnfparse.py pypy/dist/pypy/rlib/parsing/makepackrat.py Log: factor out common code Added: pypy/dist/pypy/rlib/parsing/codebuilder.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/rlib/parsing/codebuilder.py Wed Jun 27 13:21:10 2007 @@ -0,0 +1,54 @@ +class Codebuilder(object): + def __init__(self): + self.blocks = [] + self.code = [] + + def get_code(self): + assert not self.blocks + return "\n".join([" " * depth + line for depth, line in self.code]) + + def make_parser(self): + m = {'Status': Status, + 'Nonterminal': Nonterminal, + 'Symbol': Symbol,} + exec py.code.Source(self.get_code()).compile() in m + return m['Parser'] + + def emit(self, line): + for line in line.split("\n"): + self.code.append((len(self.blocks), line)) + + def emit_initcode(self, line): + for line in line.split("\n"): + self.initcode.append(line) + + def start_block(self, blockstarter): + assert blockstarter.endswith(":") + self.emit(blockstarter) + self.blocks.append(blockstarter) + def BlockEnder(): + yield None + self.end_block(blockstarter) + return BlockEnder() + + def end_block(self, starterpart=""): + block = self.blocks.pop() + assert starterpart in block, "ended wrong block %s with %s" % ( + block, starterpart) + + def store_code_away(self): + result = self.blocks, self.code + self.code = [] + self.blocks = [] + return result + + def restore_code(self, (blocks, code)): + result = self.blocks, self.code + self.code = code + self.blocks = blocks + return result + + def add_code(self, (blocks, code)): + self.code += [(depth + len(self.blocks), line) for depth, line in code] + self.blocks += blocks + Modified: pypy/dist/pypy/rlib/parsing/ebnfparse.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/ebnfparse.py (original) +++ pypy/dist/pypy/rlib/parsing/ebnfparse.py Wed Jun 27 13:21:10 2007 @@ -1,6 +1,7 @@ import py from pypy.rlib.parsing.parsing import PackratParser, Rule from pypy.rlib.parsing.tree import Nonterminal, Symbol, RPythonVisitor +from pypy.rlib.parsing.codebuilder import Codebuilder from pypy.rlib.parsing.regexparse import parse_regex import string from pypy.rlib.parsing.regex import * @@ -277,14 +278,12 @@ all_changes.append(real_changes) return all_rules + other_rules, all_changes + other_changes -class TransformerMaker(object): +class TransformerMaker(Codebuilder): def __init__(self, rules, changes): + Codebuilder.__init__(self) self.rules = rules self.changes = changes self.nonterminals = dict.fromkeys([rule.nonterminal for rule in rules]) - self.code = [] - self.depth = 0 - self.blocks = [] def make_transformer(self, print_code=False): self.start_block("class ToAST(object):") @@ -309,8 +308,7 @@ self.emit("return r[0]") self.end_block("transform") self.end_block("ToAST") - assert not self.blocks - code = "\n".join(self.code) + code = self.get_code() if print_code: print code ns = {"RPythonVisitor": RPythonVisitor, "Nonterminal": Nonterminal, @@ -324,20 +322,6 @@ ToAST.changes = self.changes return ToAST - def emit(self, line): - for line in line.split("\n"): - self.code.append(" " * (4 * len(self.blocks)) + line) - - def start_block(self, blockstarter): - assert blockstarter.endswith(":") - self.emit(blockstarter) - self.blocks.append(blockstarter) - - def end_block(self, starterpart=""): - block = self.blocks.pop() - assert starterpart in block, "ended wrong block %s with %s" % ( - block, starterpart) - def dispatch(self, symbol, expr): if symbol in self.nonterminals: return "self.visit_%s(%s)" % (symbol, expr) Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/makepackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/makepackrat.py Wed Jun 27 13:21:10 2007 @@ -1,6 +1,7 @@ import py import sys from pypy.rlib.parsing.tree import Nonterminal, Symbol, RPythonVisitor +from pypy.rlib.parsing.codebuilder import Codebuilder from pypy.rlib.objectmodel import we_are_translated class BacktrackException(Exception): @@ -296,18 +297,13 @@ self.status = self.INPROGRESS self.result = None -class ParserBuilder(RPythonVisitor): +class ParserBuilder(RPythonVisitor, Codebuilder): def __init__(self): - self.code = [] - self.blocks = [] + Codebuilder.__init__(self) self.initcode = [] self.names = {} self.matchers = {} - def get_code(self): - assert not self.blocks - return "\n".join([" " * depth + line for depth, line in self.code]) - def make_parser(self): m = {'Status': Status, 'Nonterminal': Nonterminal, @@ -315,44 +311,6 @@ exec py.code.Source(self.get_code()).compile() in m return m['Parser'] - def emit(self, line): - for line in line.split("\n"): - self.code.append((len(self.blocks), line)) - - def emit_initcode(self, line): - for line in line.split("\n"): - self.initcode.append(line) - - def start_block(self, blockstarter): - assert blockstarter.endswith(":") - self.emit(blockstarter) - self.blocks.append(blockstarter) - def BlockEnder(): - yield None - self.end_block(blockstarter) - return BlockEnder() - - def end_block(self, starterpart=""): - block = self.blocks.pop() - assert starterpart in block, "ended wrong block %s with %s" % ( - block, starterpart) - - def store_code_away(self): - result = self.blocks, self.code - self.code = [] - self.blocks = [] - return result - - def restore_code(self, (blocks, code)): - result = self.blocks, self.code - self.code = code - self.blocks = blocks - return result - - def add_code(self, (blocks, code)): - self.code += [(depth + len(self.blocks), line) for depth, line in code] - self.blocks += blocks - def memoize_header(self, name, args): dictname = "_dict_%s" % (name, ) self.emit_initcode("self.%s = {}" % (dictname, )) From antocuni at codespeak.net Wed Jun 27 14:48:42 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Wed, 27 Jun 2007 14:48:42 +0200 (CEST) Subject: [pypy-svn] r44557 - in pypy/dist/pypy/translator/cli: . test Message-ID: <20070627124842.DCDFD8110@code0.codespeak.net> Author: antocuni Date: Wed Jun 27 14:48:41 2007 New Revision: 44557 Modified: pypy/dist/pypy/translator/cli/silverpython.py pypy/dist/pypy/translator/cli/test/test_silverpython.py Log: add the possibility to export classes. A class is exported is its __init__ is marked with @export. Individual methods can also be @exported, useful for methods that can't be reached by one of the entrypoints. To force the annotator to analyze a given method, we generates a dummy function which call that method. Better approached are welcome. Modified: pypy/dist/pypy/translator/cli/silverpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/silverpython.py (original) +++ pypy/dist/pypy/translator/cli/silverpython.py Wed Jun 27 14:48:41 2007 @@ -9,6 +9,7 @@ import new import types import os.path +import inspect from pypy.translator.driver import TranslationDriver from pypy.translator.cli.entrypoint import DllEntryPoint @@ -18,6 +19,9 @@ self.name = name self.namespace = namespace self.functions = functions # [(function, annotation), ...] + self.driver = TranslationDriver() + self.driver.config.translation.ootype.mangle = False + self.driver.setup_library(self) def add_function(self, func, inputtypes): self.functions.append((func, inputtypes)) @@ -31,11 +35,7 @@ for func, _ in self.functions: if not hasattr(func, '_namespace_'): func._namespace_ = self.namespace - driver = TranslationDriver() - driver.config.translation.ootype.mangle = False - driver.setup_library(self) - driver.proceed(['compile_cli']) - return driver + self.driver.proceed(['compile_cli']) class export(object): def __new__(self, *args, **kwds): @@ -57,25 +57,76 @@ func._namespace_ = self.namespace return func +def is_exported(obj): + return isinstance(obj, (types.FunctionType, types.UnboundMethodType)) \ + and hasattr(obj, '_inputtypes_') + def collect_entrypoints(dic): entrypoints = [] for item in dic.itervalues(): - if isinstance(item, types.FunctionType) and hasattr(item, '_inputtypes_'): + if is_exported(item): entrypoints.append((item, item._inputtypes_)) + elif isinstance(item, types.ClassType) or isinstance(item, type): + entrypoints += collect_class_entrypoints(item) + return entrypoints + +def collect_class_entrypoints(cls): + try: + __init__ = cls.__init__ + if not is_exported(__init__): + return [] + except AttributeError: + return [] + + entrypoints = [(wrap_init(cls, __init__), __init__._inputtypes_)] + for item in cls.__dict__.itervalues(): + if item is not __init__.im_func and is_exported(item): + inputtypes = (cls,) + item._inputtypes_ + entrypoints.append((wrap_method(item), inputtypes)) return entrypoints +def getarglist(meth): + arglist, starargs, kwargs, defaults = inspect.getargspec(meth) + assert starargs is None, '*args not supported yet' + assert kwargs is None, '**kwds not supported yet' + assert defaults is None, 'default values not supported yet' + return arglist + +def wrap_init(cls, meth): + arglist = getarglist(meth)[1:] # discard self + args = ', '.join(arglist) + source = 'def __internal__ctor(%s): return %s(%s)' % ( + args, cls.__name__, args) + mydict = {cls.__name__: cls} + print source + exec source in mydict + return mydict['__internal__ctor'] + +def wrap_method(meth, is_init=False): + arglist = getarglist(meth) + name = '__internal__%s' % meth.func_name + selfvar = arglist[0] + args = ', '.join(arglist) + params = ', '.join(arglist[1:]) + source = 'def %s(%s): return %s.%s(%s)' % ( + name, args, selfvar, meth.func_name, params) + mydict = {} + print source + exec source in mydict + return mydict[name] + + def compile_dll(filename): _, name = os.path.split(filename) dllname, _ = os.path.splitext(name) - module = new.module(dllname) - execfile(filename, module.__dict__) - entrypoints = collect_entrypoints(module.__dict__) namespace = module.__dict__.get('_namespace_', dllname) - - dll = DllDef(dllname, namespace, entrypoints) - driver = dll.compile() - driver.copy_cli_dll() + execfile(filename, module.__dict__) + + dll = DllDef(dllname, namespace) + dll.functions = collect_entrypoints(module.__dict__) + dll.compile() + dll.driver.copy_cli_dll() def main(argv): if len(argv) != 2: Modified: pypy/dist/pypy/translator/cli/test/test_silverpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/test/test_silverpython.py (original) +++ pypy/dist/pypy/translator/cli/test/test_silverpython.py Wed Jun 27 14:48:41 2007 @@ -1,6 +1,7 @@ from pypy.tool import udir from pypy.translator.cli.rte import Target -from pypy.translator.cli.silverpython import DllDef, export, collect_entrypoints +from pypy.translator.cli.silverpython import DllDef, export, collect_entrypoints,\ + collect_class_entrypoints from pypy.translator.cli.test.runtest import CliFunctionWrapper, CliTest TEMPLATE = """ @@ -82,3 +83,42 @@ mydict = dict(foo=foo, bar=bar, x=42) entrypoints = collect_entrypoints(mydict) assert entrypoints == [(foo, (int, float))] + + def test_collect_class_entrypoints(self): + class NotExported: + def __init__(self): + pass + + class MyClass: + @export + def __init__(self): + pass + @export(int) + def foo(self, x): + return x + + assert collect_class_entrypoints(NotExported) == [] + entrypoints = collect_class_entrypoints(MyClass) + assert len(entrypoints) == 2 + assert entrypoints[0][1] == () # __init__ inputtypes + assert entrypoints[1][1] == (MyClass, int) # foo inputtypes + + def test_compile_class(self): + class MyClass: + @export(int) + def __init__(self, x): + self.x = x + @export(int, int) + def add(self, y, z): + return self.x + y + z + MyClass.__module__ = 'Test' # put the class in the Test namespace + + entrypoints = collect_entrypoints({'MyClass': MyClass}) + dll = DllDef('test', 'Test', entrypoints) + dll.compile() + res = self._csharp('test', """ + Test.MyClass obj = new Test.MyClass(); + obj.__init___variant0(39); + Console.WriteLine(obj.add_variant0(1, 2)); + """) + assert res == 42 From cfbolz at codespeak.net Wed Jun 27 15:42:27 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Wed, 27 Jun 2007 15:42:27 +0200 (CEST) Subject: [pypy-svn] r44558 - pypy/dist/pypy/rlib/parsing Message-ID: <20070627134227.E501780D2@code0.codespeak.net> Author: cfbolz Date: Wed Jun 27 15:42:27 2007 New Revision: 44558 Modified: pypy/dist/pypy/rlib/parsing/codebuilder.py pypy/dist/pypy/rlib/parsing/deterministic.py Log: refactor the first half of the regex building code to use the new codebuilder Modified: pypy/dist/pypy/rlib/parsing/codebuilder.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/codebuilder.py (original) +++ pypy/dist/pypy/rlib/parsing/codebuilder.py Wed Jun 27 15:42:27 2007 @@ -16,7 +16,8 @@ def emit(self, line): for line in line.split("\n"): - self.code.append((len(self.blocks), line)) + if line: + self.code.append((len(self.blocks), line)) def emit_initcode(self, line): for line in line.split("\n"): Modified: pypy/dist/pypy/rlib/parsing/deterministic.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/deterministic.py (original) +++ pypy/dist/pypy/rlib/parsing/deterministic.py Wed Jun 27 15:42:27 2007 @@ -190,71 +190,75 @@ return True def make_code(self): - result = [""" -def recognize(input): - i = 0 - state = 0 - while 1: -"""] + from pypy.rlib.parsing.codebuilder import Codebuilder + result = Codebuilder() + result.start_block("def recognize(input):") + result.emit("i = 0") + result.emit("state = 0") + result.start_block("while 1:") state_to_chars = {} for (state, char), nextstate in self.transitions.iteritems(): state_to_chars.setdefault(state, {}).setdefault(nextstate, set()).add(char) above = set() for state, nextstates in state_to_chars.iteritems(): above.add(state) - result.append("""\ - if state == %s: - if i < len(input): - char = input[i] - i += 1 - else:""" % (state, )) - if state in self.final_states: - result.append(" return True") - else: - result.append(" break") - elif_prefix = "" - for nextstate, chars in nextstates.iteritems(): - final = nextstate in self.final_states - compressed = compress_char_set(chars) - if nextstate in above: - continue_prefix = "\n" + " " * 16 + "continue" - else: - continue_prefix = "" - for i, (a, num) in enumerate(compressed): - if num < 5: - for charord in range(ord(a), ord(a) + num): - result.append(""" - %sif char == %r: - state = %s%s""" % (elif_prefix, chr(charord), nextstate, continue_prefix)) + for _ in result.start_block("if state == %s:" % (state, )): + for _ in result.start_block("if i < len(input):"): + result.emit("char = input[i]") + result.emit("i += 1") + for _ in result.start_block("else:"): + if state in self.final_states: + result.emit("return True") + else: + result.emit("break") + elif_prefix = "" + for nextstate, chars in nextstates.iteritems(): + final = nextstate in self.final_states + compressed = compress_char_set(chars) + if nextstate in above: + continue_prefix = "continue" + else: + continue_prefix = "" + for i, (a, num) in enumerate(compressed): + if num < 5: + for charord in range(ord(a), ord(a) + num): + for _ in result.start_block( + "%sif char == %r:" % ( + elif_prefix, chr(charord))): + result.emit("state = %s" % (nextstate, )) + result.emit(continue_prefix) + if not elif_prefix: + elif_prefix = "el" + else: + for _ in result.start_block( + "%sif %r <= char <= %r:" % ( + elif_prefix, a, chr(ord(a) + num - 1))): + result.emit("state = %s""" % (nextstate, )) + result.emit(continue_prefix) if not elif_prefix: elif_prefix = "el" - else: - result.append(""" - %sif %r <= char <= %r: - state = %s%s""" % (elif_prefix, a, chr(ord(a) + num - 1), nextstate, continue_prefix)) - if not elif_prefix: - elif_prefix = "el" - - result.append(" " * 12 + "else:") - result.append(" " * 16 + "break") + for _ in result.start_block("else:"): + result.emit("break") #print state_to_chars.keys() for state in range(self.num_states): if state in state_to_chars: continue - result.append("""\ - if state == %s: - if i == len(input): - return True - else: - break""" % (state, )) - result.append(" break") - result.append(" raise LexerError(input, state, i)") - result = "\n".join(result) + for _ in result.start_block("if state == %s:" % (state, )): + for _ in result.start_block("if i == len(input):"): + result.emit("return True") + for _ in result.start_block("else:"): + result.emit("break") + result.emit("break") + result.end_block("while") + result.emit("raise LexerError(input, state, i)") + result.end_block("def") + result = result.get_code() while "\n\n" in result: result = result.replace("\n\n", "\n") - #print result - exec py.code.Source(result).compile() - return recognize + print result + d = {'LexerError': LexerError} + exec py.code.Source(result).compile() in d + return d['recognize'] def make_lexing_code(self): result = [""" @@ -277,10 +281,10 @@ result.append(" runner.last_matched_index = i - 1") result.append(" runner.last_matched_state = state") result.append("""\ - if i < len(input): + try: char = input[i] i += 1 - else: + except IndexError: runner.state = %s""" % (state, )) if state in self.final_states: result.append(" return i") From cfbolz at codespeak.net Wed Jun 27 16:09:17 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Wed, 27 Jun 2007 16:09:17 +0200 (CEST) Subject: [pypy-svn] r44559 - pypy/dist/pypy/rlib/parsing Message-ID: <20070627140917.9141E80D2@code0.codespeak.net> Author: cfbolz Date: Wed Jun 27 16:09:15 2007 New Revision: 44559 Modified: pypy/dist/pypy/rlib/parsing/deterministic.py Log: more refactoring to use the code builder Modified: pypy/dist/pypy/rlib/parsing/deterministic.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/deterministic.py (original) +++ pypy/dist/pypy/rlib/parsing/deterministic.py Wed Jun 27 16:09:15 2007 @@ -255,19 +255,19 @@ result = result.get_code() while "\n\n" in result: result = result.replace("\n\n", "\n") - print result + #print result d = {'LexerError': LexerError} exec py.code.Source(result).compile() in d return d['recognize'] def make_lexing_code(self): - result = [""" -def recognize(runner, i): - assert i >= 0 - input = runner.text - state = 0 - while 1: -"""] + from pypy.rlib.parsing.codebuilder import Codebuilder + result = Codebuilder() + result.start_block("def recognize(runner, i):") + result.emit("assert i >= 0") + result.emit("input = runner.text") + result.emit("state = 0") + result.start_block("while 1:") state_to_chars = {} for (state, char), nextstate in self.transitions.iteritems(): state_to_chars.setdefault(state, {}).setdefault(nextstate, set()).add(char) @@ -276,62 +276,66 @@ above = set() for state, nextstates in state_to_chars_sorted: above.add(state) - result.append(" if state == %s:" % (state, )) - if state in self.final_states: - result.append(" runner.last_matched_index = i - 1") - result.append(" runner.last_matched_state = state") - result.append("""\ - try: - char = input[i] - i += 1 - except IndexError: - runner.state = %s""" % (state, )) - if state in self.final_states: - result.append(" return i") - else: - result.append(" return ~i") - elif_prefix = "" - for nextstate, chars in nextstates.iteritems(): - final = nextstate in self.final_states - compressed = compress_char_set(chars) - if nextstate in above: - continue_prefix = "\n" + " " * 16 + "continue" - else: - continue_prefix = "" - for i, (a, num) in enumerate(compressed): - if num < 3: - for charord in range(ord(a), ord(a) + num): - result.append(""" - %sif char == %r: - state = %s%s""" % (elif_prefix, chr(charord), nextstate, continue_prefix)) + for _ in result.start_block("if state == %s:" % (state, )): + if state in self.final_states: + result.emit("runner.last_matched_index = i - 1") + result.emit("runner.last_matched_state = state") + for _ in result.start_block("try:"): + result.emit("char = input[i]") + result.emit("i += 1") + for _ in result.start_block("except IndexError:"): + result.emit("runner.state = %s" % (state, )) + if state in self.final_states: + result.emit("return i") + else: + result.emit("return ~i") + elif_prefix = "" + for nextstate, chars in nextstates.iteritems(): + final = nextstate in self.final_states + compressed = compress_char_set(chars) + if nextstate in above: + continue_prefix = "continue" + else: + continue_prefix = "" + for i, (a, num) in enumerate(compressed): + if num < 3: + for charord in range(ord(a), ord(a) + num): + for _ in result.start_block("%sif char == %r:" + % (elif_prefix, chr(charord))): + result.emit("state = %s" % (nextstate, )) + result.emit(continue_prefix) + if not elif_prefix: + elif_prefix = "el" + else: + for _ in result.start_block( + "%sif %r <= char <= %r:" % ( + elif_prefix, a, chr(ord(a) + num - 1))): + result.emit("state = %s" % (nextstate, )) + result.emit(continue_prefix) if not elif_prefix: elif_prefix = "el" - else: - result.append(""" - %sif %r <= char <= %r: - state = %s%s""" % (elif_prefix, a, chr(ord(a) + num - 1), nextstate, continue_prefix)) - if not elif_prefix: - elif_prefix = "el" - - result.append(" " * 12 + "else:") - result.append(" " * 16 + "break") + for _ in result.start_block("else:"): + result.emit("break") #print state_to_chars.keys() for state in range(self.num_states): if state in state_to_chars: continue assert state in self.final_states - result.append("""\ - runner.last_matched_state = state - runner.last_matched_index = i - 1 - runner.state = state - if i == len(input): - return i - else: - return ~i - break - runner.state = state - return ~i""") - result = "\n".join(result) + result.emit(""" +runner.last_matched_state = state +runner.last_matched_index = i - 1 +runner.state = state +if i == len(input): + return i +else: + return ~i +break""") + result.end_block("while") + result.emit(""" +runner.state = state +return ~i""") + result.end_block("def") + result = result.get_code() while "\n\n" in result: result = result.replace("\n\n", "\n") #print result From cfbolz at codespeak.net Wed Jun 27 16:20:41 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Wed, 27 Jun 2007 16:20:41 +0200 (CEST) Subject: [pypy-svn] r44560 - pypy/dist/pypy/rlib/parsing/test Message-ID: <20070627142041.DB97E80D4@code0.codespeak.net> Author: cfbolz Date: Wed Jun 27 16:20:39 2007 New Revision: 44560 Modified: pypy/dist/pypy/rlib/parsing/test/test_regexparse.py Log: remove unneeded import Modified: pypy/dist/pypy/rlib/parsing/test/test_regexparse.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_regexparse.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_regexparse.py Wed Jun 27 16:20:39 2007 @@ -3,7 +3,6 @@ from pypy.rlib.parsing import regex import operator from pypy.rlib.parsing.makepackrat import PackratParser as _PackratParser -from pypy.rlib.parsing.deterministic import compress_char_set, DFA From cfbolz at codespeak.net Wed Jun 27 16:21:29 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Wed, 27 Jun 2007 16:21:29 +0200 (CEST) Subject: [pypy-svn] r44561 - pypy/dist/pypy/rlib/parsing Message-ID: <20070627142129.AA26880D4@code0.codespeak.net> Author: cfbolz Date: Wed Jun 27 16:21:28 2007 New Revision: 44561 Modified: pypy/dist/pypy/rlib/parsing/regexparse.py Log: remove dead code Modified: pypy/dist/pypy/rlib/parsing/regexparse.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/regexparse.py (original) +++ pypy/dist/pypy/rlib/parsing/regexparse.py Wed Jun 27 16:21:28 2007 @@ -160,17 +160,6 @@ r = p.parse() return r -def make_runner(st, view=False): - r = parse_regex(st) - dfa = r.make_automaton().make_deterministic() - if view: - dfa.view() - dfa.optimize() - if view: - dfa.view() - r = dfa.get_runner() - return r - def make_runner(regex, view=False): p = RegexParser(regex) r = p.parse() From cfbolz at codespeak.net Wed Jun 27 16:24:57 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Wed, 27 Jun 2007 16:24:57 +0200 (CEST) Subject: [pypy-svn] r44562 - pypy/dist/pypy/rlib/parsing Message-ID: <20070627142457.6DA3280D4@code0.codespeak.net> Author: cfbolz Date: Wed Jun 27 16:24:56 2007 New Revision: 44562 Modified: pypy/dist/pypy/rlib/parsing/deterministic.py Log: reorder the if conditions in the code that is generated for state transitions to give the if-to-switch optimization more opportunities. Modified: pypy/dist/pypy/rlib/parsing/deterministic.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/deterministic.py (original) +++ pypy/dist/pypy/rlib/parsing/deterministic.py Wed Jun 27 16:24:56 2007 @@ -17,7 +17,9 @@ result.append(1) real_result = [] for i in range(len(result) // 2): - real_result.append((result[i * 2], result[i * 2 + 1])) + real_result.append((result[i * 2 + 1], result[i * 2])) + real_result.sort() + real_result = zip(*zip(*real_result)[::-1]) return real_result class LexerError(Exception): From antocuni at codespeak.net Wed Jun 27 16:30:44 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Wed, 27 Jun 2007 16:30:44 +0200 (CEST) Subject: [pypy-svn] r44563 - in pypy/dist/pypy: rpython rpython/lltypesystem rpython/ootypesystem rpython/test translator/cli/test Message-ID: <20070627143044.1262380D4@code0.codespeak.net> Author: antocuni Date: Wed Jun 27 16:30:43 2007 New Revision: 44563 Modified: pypy/dist/pypy/rpython/lltypesystem/typecache.py pypy/dist/pypy/rpython/ootypesystem/rpbc.py pypy/dist/pypy/rpython/rpbc.py pypy/dist/pypy/rpython/test/test_rclass.py pypy/dist/pypy/translator/cli/test/test_silverpython.py Log: append _variant0 to method names only when necessary Modified: pypy/dist/pypy/rpython/lltypesystem/typecache.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/typecache.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/typecache.py Wed Jun 27 16:30:43 2007 @@ -4,4 +4,5 @@ ('', ('32bit', 'WindowsPE'), 'Windows'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}, ('i386', ('32bit', ''), 'Darwin'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 16, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}, ('Intel(R) Pentium(R) M processor 1.73GHz', ('32bit', ''), 'Linux'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 32, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}, +('Intel(R) Core(TM)2 CPU T7200 @ 2.00GHz', ('32bit', ''), 'Linux'):{'short': 16, 'int': 32, 'unsigned char': 8, 'long': 32, 'char': 8, 'unsigned short': 16, 'unsigned long': 32, 'long long': 64, 'mode_t': 32, 'unsigned long long': 64, 'size_t': 32, 'unsigned int': 32}, } Modified: pypy/dist/pypy/rpython/ootypesystem/rpbc.py ============================================================================== --- pypy/dist/pypy/rpython/ootypesystem/rpbc.py (original) +++ pypy/dist/pypy/rpython/ootypesystem/rpbc.py Wed Jun 27 16:30:43 2007 @@ -56,7 +56,10 @@ def row_method_name(methodname, rowname): - return "%s_%s" % (methodname, rowname) + if rowname is None: + return methodname + else: + return "%s_%s" % (methodname, rowname) class MethodImplementations(object): Modified: pypy/dist/pypy/rpython/rpbc.py ============================================================================== --- pypy/dist/pypy/rpython/rpbc.py (original) +++ pypy/dist/pypy/rpython/rpbc.py Wed Jun 27 16:30:43 2007 @@ -147,8 +147,11 @@ assert biggerrow == row # otherwise, addrow() is broken concretetable[shape, index] = row - for finalindex, row in enumerate(uniquerows): - row.attrname = 'variant%d' % finalindex + if len(uniquerows) == 1: + uniquerows[0].attrname = None + else: + for finalindex, row in enumerate(uniquerows): + row.attrname = 'variant%d' % finalindex return concretetable, uniquerows Modified: pypy/dist/pypy/rpython/test/test_rclass.py ============================================================================== --- pypy/dist/pypy/rpython/test/test_rclass.py (original) +++ pypy/dist/pypy/rpython/test/test_rclass.py Wed Jun 27 16:30:43 2007 @@ -700,7 +700,7 @@ t.buildrtyper(type_system=self.type_system).specialize() graph = graphof(t, f) TYPE = graph.startblock.operations[0].args[0].value - _, meth = TYPE._lookup("o__del___variant0") + _, meth = TYPE._lookup("o__del__") assert meth.finalizer def test_del_inheritance(self): @@ -734,9 +734,9 @@ TYPEA = graph.startblock.operations[0].args[0].value TYPEB = graph.startblock.operations[2].args[0].value TYPEC = graph.startblock.operations[4].args[0].value - _, destra = TYPEA._lookup("o__del___variant0") - _, destrb = TYPEB._lookup("o__del___variant0") - _, destrc = TYPEC._lookup("o__del___variant0") + _, destra = TYPEA._lookup("o__del__") + _, destrb = TYPEB._lookup("o__del__") + _, destrc = TYPEC._lookup("o__del__") assert destra == destrc assert destrb is not None assert destra is not None Modified: pypy/dist/pypy/translator/cli/test/test_silverpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/test/test_silverpython.py (original) +++ pypy/dist/pypy/translator/cli/test/test_silverpython.py Wed Jun 27 16:30:43 2007 @@ -118,7 +118,7 @@ dll.compile() res = self._csharp('test', """ Test.MyClass obj = new Test.MyClass(); - obj.__init___variant0(39); - Console.WriteLine(obj.add_variant0(1, 2)); + obj.__init__(39); + Console.WriteLine(obj.add(1, 2)); """) assert res == 42 From antocuni at codespeak.net Wed Jun 27 17:09:46 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Wed, 27 Jun 2007 17:09:46 +0200 (CEST) Subject: [pypy-svn] r44564 - in pypy/dist/pypy/translator/cli: . test Message-ID: <20070627150946.A655B80AE@code0.codespeak.net> Author: antocuni Date: Wed Jun 27 17:09:45 2007 New Revision: 44564 Added: pypy/dist/pypy/translator/cli/carbonpython.py - copied unchanged from r44559, pypy/dist/pypy/translator/cli/silverpython.py pypy/dist/pypy/translator/cli/test/test_carbonpython.py - copied unchanged from r44563, pypy/dist/pypy/translator/cli/test/test_silverpython.py Removed: pypy/dist/pypy/translator/cli/silverpython.py pypy/dist/pypy/translator/cli/test/test_silverpython.py Log: rename silverpython to carbonpython, not to confuse it with MS silverlight. Of course carbonpython can be used togheter with ironpython, leading to a stronger steelpython :-) From antocuni at codespeak.net Wed Jun 27 17:11:16 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Wed, 27 Jun 2007 17:11:16 +0200 (CEST) Subject: [pypy-svn] r44565 - in pypy/dist/pypy/translator/cli: . test Message-ID: <20070627151116.A8D6F80CC@code0.codespeak.net> Author: antocuni Date: Wed Jun 27 17:11:16 2007 New Revision: 44565 Modified: pypy/dist/pypy/translator/cli/carbonpython.py pypy/dist/pypy/translator/cli/test/test_carbonpython.py Log: s/silver/carbon step #2 Modified: pypy/dist/pypy/translator/cli/carbonpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/carbonpython.py (original) +++ pypy/dist/pypy/translator/cli/carbonpython.py Wed Jun 27 17:11:16 2007 @@ -1,6 +1,6 @@ #! /usr/bin/env python """ -Usage: silverpython.py .py +Usage: carbonpython.py .py Compiles an RPython module into a .NET dll. """ Modified: pypy/dist/pypy/translator/cli/test/test_carbonpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/test/test_carbonpython.py (original) +++ pypy/dist/pypy/translator/cli/test/test_carbonpython.py Wed Jun 27 17:11:16 2007 @@ -1,19 +1,19 @@ from pypy.tool import udir from pypy.translator.cli.rte import Target -from pypy.translator.cli.silverpython import DllDef, export, collect_entrypoints,\ +from pypy.translator.cli.carbonpython import DllDef, export, collect_entrypoints,\ collect_class_entrypoints from pypy.translator.cli.test.runtest import CliFunctionWrapper, CliTest TEMPLATE = """ using System; -class SilveRPytonTest { +class CarbonPytonTest { public static void Main() { %s } } """ -class TestSilveRPython(CliTest): +class TestCarbonPython(CliTest): def _csharp(self, reference, source): tmpfile = udir.udir.join('tmp.cs') From fijal at codespeak.net Thu Jun 28 10:37:39 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Thu, 28 Jun 2007 10:37:39 +0200 (CEST) Subject: [pypy-svn] r44576 - pypy/dist/pypy/objspace/std/test Message-ID: <20070628083739.BF40D810A@code0.codespeak.net> Author: fijal Date: Thu Jun 28 10:37:39 2007 New Revision: 44576 Modified: pypy/dist/pypy/objspace/std/test/test_strjoinobject.py Log: Make it run on top of cpy 2.5 Modified: pypy/dist/pypy/objspace/std/test/test_strjoinobject.py ============================================================================== --- pypy/dist/pypy/objspace/std/test/test_strjoinobject.py (original) +++ pypy/dist/pypy/objspace/std/test/test_strjoinobject.py Thu Jun 28 10:37:39 2007 @@ -10,7 +10,9 @@ def test_basic(self): import __pypy__ - s = "Hello, " + "World!" + # cannot do "Hello, " + "World!" because cpy2.5 optimises this + # away on AST level (no idea why it doesn't this one) + s = "Hello, ".__add__("World!") assert type(s) is str assert 'W_StringJoinObject' in __pypy__.internal_repr(s) From fijal at codespeak.net Thu Jun 28 10:38:17 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Thu, 28 Jun 2007 10:38:17 +0200 (CEST) Subject: [pypy-svn] r44577 - in pypy/dist/pypy/objspace/std: . test Message-ID: <20070628083817.B3C85810A@code0.codespeak.net> Author: fijal Date: Thu Jun 28 10:38:17 2007 New Revision: 44577 Modified: pypy/dist/pypy/objspace/std/dictmultiobject.py pypy/dist/pypy/objspace/std/test/test_dictmultiobject.py Log: Fix a funny bug in empty dict impl (!!!!) Modified: pypy/dist/pypy/objspace/std/dictmultiobject.py ============================================================================== --- pypy/dist/pypy/objspace/std/dictmultiobject.py (original) +++ pypy/dist/pypy/objspace/std/dictmultiobject.py Thu Jun 28 10:38:17 2007 @@ -148,6 +148,10 @@ self.space = space def get(self, w_lookup): + space = self.space + if not _is_str(space, w_lookup) and not _is_sane_hash(space, w_lookup): + # count hash + space.hash(w_lookup) return None def setitem(self, w_key, w_value): @@ -165,7 +169,12 @@ def setitem_str(self, w_key, w_value, shadows_type=True): return StrDictImplementation(self.space).setitem_str(w_key, w_value) #return SmallStrDictImplementation(self.space, w_key, w_value) + def delitem(self, w_key): + space = self.space + if not _is_str(space, w_key) and not _is_sane_hash(space, w_key): + # count hash + space.hash(w_key) raise KeyError def length(self): Modified: pypy/dist/pypy/objspace/std/test/test_dictmultiobject.py ============================================================================== --- pypy/dist/pypy/objspace/std/test/test_dictmultiobject.py (original) +++ pypy/dist/pypy/objspace/std/test/test_dictmultiobject.py Thu Jun 28 10:38:17 2007 @@ -28,6 +28,10 @@ raises(StopIteration, i.next) raises(StopIteration, i.next) + def test_emptydict_unhashable(self): + raises(TypeError, "{}[['x']]") + + class TestW_DictSharing(test_dictobject.TestW_DictObject): def setup_class(cls): cls.space = gettestobjspace(**{"objspace.std.withsharingdict": True}) From fijal at codespeak.net Thu Jun 28 10:43:32 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Thu, 28 Jun 2007 10:43:32 +0200 (CEST) Subject: [pypy-svn] r44578 - in pypy/dist/pypy/objspace/std: . test Message-ID: <20070628084332.2C6F3810A@code0.codespeak.net> Author: fijal Date: Thu Jun 28 10:43:31 2007 New Revision: 44578 Modified: pypy/dist/pypy/objspace/std/test/test_stringobject.py pypy/dist/pypy/objspace/std/unicodetype.py Log: Controversial checkin - make unicode and str interchangeable. __doc__ are not the same as in CPy, but the difference is lack of word "string" or so. Modified: pypy/dist/pypy/objspace/std/test/test_stringobject.py ============================================================================== --- pypy/dist/pypy/objspace/std/test/test_stringobject.py (original) +++ pypy/dist/pypy/objspace/std/test/test_stringobject.py Thu Jun 28 10:43:31 2007 @@ -680,7 +680,6 @@ assert type(s.splitlines()[0]) is str def test_str_unicode_interchangeable(self): - skip("failing") stuff = ['xxxxx', u'xxxxx'] for x in stuff: for y in stuff: @@ -689,7 +688,17 @@ assert x.count(y) == 1 assert x.find(y) != -1 assert x.index(y) == 0 - # ... to be continued once this passes + d = ["x", u"x"] + for a in d: + for b in d: + assert x.replace(a, b) == y + assert x.rfind(y) != -1 + assert x.rindex(y) == 0 + assert x.split(y) == ['', ''] + assert x.rsplit(y) == ['', ''] + assert x.strip(y) == '' + assert x.rstrip(y) == '' + assert x.lstrip(y) == '' class AppTestPrebuilt(AppTestStringObject): def setup_class(cls): Modified: pypy/dist/pypy/objspace/std/unicodetype.py ============================================================================== --- pypy/dist/pypy/objspace/std/unicodetype.py (original) +++ pypy/dist/pypy/objspace/std/unicodetype.py Thu Jun 28 10:43:31 2007 @@ -32,29 +32,11 @@ ' well as any other name registered' ' with\ncodecs.register_error that can handle' ' UnicodeEncodeErrors.') -unicode_endswith = SMM('endswith', 4, defaults=(0,maxint), - doc='S.endswith(suffix[, start[, end]]) ->' - ' bool\n\nReturn True if S ends with the' - ' specified suffix, False otherwise.\nWith' - ' optional start, test S beginning at that' - ' position.\nWith optional end, stop comparing S' - ' at that position.') unicode_expandtabs = SMM('expandtabs', 2, defaults=(8,), doc='S.expandtabs([tabsize]) -> unicode\n\nReturn a' ' copy of S where all tab characters are expanded' ' using spaces.\nIf tabsize is not given, a tab' ' size of 8 characters is assumed.') -unicode_find = SMM('find', 4, defaults=(0, maxint), - doc='S.find(sub [,start [,end]]) -> int\n\nReturn the' - ' lowest index in S where substring sub is' - ' found,\nsuch that sub is contained within' - ' s[start,end]. Optional\narguments start and' - ' end are interpreted as in slice' - ' notation.\n\nReturn -1 on failure.') -unicode_index = SMM('index', 4, defaults=(0, maxint), - doc='S.index(sub [,start [,end]]) -> int\n\nLike' - ' S.find() but raise ValueError when the' - ' substring is not found.') unicode_isalnum = SMM('isalnum', 1, doc='S.isalnum() -> bool\n\nReturn True if all' ' characters in S are alphanumeric\nand there is' @@ -109,79 +91,11 @@ unicode_lower = SMM('lower', 1, doc='S.lower() -> unicode\n\nReturn a copy of the' ' string S converted to lowercase.') -unicode_lstrip = SMM('lstrip', 2, defaults=(None,), - doc='S.lstrip([chars]) -> unicode\n\nReturn a copy of' - ' the string S with leading whitespace' - ' removed.\nIf chars is given and not None,' - ' remove characters in chars instead.\nIf chars' - ' is a str, it will be converted to unicode' - ' before stripping') -unicode_replace = SMM('replace', 4, defaults=(-1,), - doc='S.replace (old, new[, maxsplit]) ->' - ' unicode\n\nReturn a copy of S with all' - ' occurrences of substring\nold replaced by new. ' - ' If the optional argument maxsplit is\ngiven,' - ' only the first maxsplit occurrences are' - ' replaced.') -unicode_rfind = SMM('rfind', 4, defaults=(0, maxint), - doc='S.rfind(sub [,start [,end]]) -> int\n\nReturn' - ' the highest index in S where substring sub is' - ' found,\nsuch that sub is contained within' - ' s[start,end]. Optional\narguments start and' - ' end are interpreted as in slice' - ' notation.\n\nReturn -1 on failure.') -unicode_rindex = SMM('rindex', 4, defaults=(0, maxint), - doc='S.rindex(sub [,start [,end]]) -> int\n\nLike' - ' S.rfind() but raise ValueError when the' - ' substring is not found.') unicode_rjust = SMM('rjust', 3, defaults=(' ',), doc='S.rjust(width[, fillchar]) -> unicode\n\nReturn' ' S right justified in a Unicode string of length' ' width. Padding is\ndone using the specified' ' fill character (default is a space).') -unicode_rstrip = SMM('rstrip', 2, defaults=(None,), - doc='S.rstrip([chars]) -> unicode\n\nReturn a copy of' - ' the string S with trailing whitespace' - ' removed.\nIf chars is given and not None,' - ' remove characters in chars instead.\nIf chars' - ' is a str, it will be converted to unicode' - ' before stripping') -unicode_rsplit = SMM('rsplit', 3, defaults=(None,-1), - doc='S.rsplit([sep [,maxsplit]]) -> list of' - ' strings\n\nReturn a list of the words in S,' - ' using sep as the\ndelimiter string, starting at' - ' the end of the string and\nworking to the' - ' front. If maxsplit is given, at most' - ' maxsplit\nsplits are done. If sep is not' - ' specified, any whitespace string\nis a' - ' separator.') -unicode_split = SMM('split', 3, defaults=(None,-1), - doc='S.split([sep [,maxsplit]]) -> list of' - ' strings\n\nReturn a list of the words in S,' - ' using sep as the\ndelimiter string. If' - ' maxsplit is given, at most maxsplit\nsplits are' - ' done. If sep is not specified or is None,\nany' - ' whitespace string is a separator.') -unicode_splitlines = SMM('splitlines', 2, defaults=(0,), - doc='S.splitlines([keepends]]) -> list of' - ' strings\n\nReturn a list of the lines in S,' - ' breaking at line boundaries.\nLine breaks are' - ' not included in the resulting list unless' - ' keepends\nis given and true.') -unicode_startswith = SMM('startswith', 4, defaults=(0,maxint), - doc='S.startswith(prefix[, start[, end]]) ->' - ' bool\n\nReturn True if S starts with the' - ' specified prefix, False otherwise.\nWith' - ' optional start, test S beginning at that' - ' position.\nWith optional end, stop comparing S' - ' at that position.') -unicode_strip = SMM('strip', 2, defaults=(None,), - doc='S.strip([chars]) -> unicode\n\nReturn a copy of' - ' the string S with leading and' - ' trailing\nwhitespace removed.\nIf chars is' - ' given and not None, remove characters in chars' - ' instead.\nIf chars is a str, it will be' - ' converted to unicode before stripping') unicode_swapcase = SMM('swapcase', 1, doc='S.swapcase() -> unicode\n\nReturn a copy of S' ' with uppercase characters converted to' @@ -207,19 +121,24 @@ ' string x with zeros on the left, to fill a' ' field\nof the specified width. The string x is' ' never truncated.') -unicode_partition = SMM('partition', 2, - doc='S.partition(sep) -> (head, sep, tail)\n\nSearches' - ' for the separator sep in S, and returns the part before' - ' it,\nthe separator itself, and the part after it. If' - ' the separator is not\nfound, returns S and two empty' - ' strings.') -unicode_rpartition = SMM('rpartition', 2, - doc='S.rpartition(sep) -> (tail, sep, head)\n\nSearches' - ' for the separator sep in S, starting at the end of S,' - ' and returns\nthe part before it, the separator itself,' - ' and the part after it. If the\nseparator is not found,' - ' returns two empty strings and S.') +# stuff imported from stringtype for interoperability + +from pypy.objspace.std.stringtype import str_endswith as unicode_endswith +from pypy.objspace.std.stringtype import str_startswith as unicode_startswith +from pypy.objspace.std.stringtype import str_find as unicode_find +from pypy.objspace.std.stringtype import str_index as unicode_index +from pypy.objspace.std.stringtype import str_replace as unicode_replace +from pypy.objspace.std.stringtype import str_rfind as unicode_rfind +from pypy.objspace.std.stringtype import str_rindex as unicode_rindex +from pypy.objspace.std.stringtype import str_split as unicode_split +from pypy.objspace.std.stringtype import str_rsplit as unicode_rsplit +from pypy.objspace.std.stringtype import str_partition as unicode_partition +from pypy.objspace.std.stringtype import str_rpartition as unicode_rpartition +from pypy.objspace.std.stringtype import str_splitlines as unicode_splitlines +from pypy.objspace.std.stringtype import str_strip as unicode_strip +from pypy.objspace.std.stringtype import str_rstrip as unicode_rstrip +from pypy.objspace.std.stringtype import str_lstrip as unicode_lstrip # ____________________________________________________________ From fijal at codespeak.net Thu Jun 28 10:44:11 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Thu, 28 Jun 2007 10:44:11 +0200 (CEST) Subject: [pypy-svn] r44579 - pypy/dist/pypy/objspace/test Message-ID: <20070628084411.06D37810A@code0.codespeak.net> Author: fijal Date: Thu Jun 28 10:44:11 2007 New Revision: 44579 Modified: pypy/dist/pypy/objspace/test/test_descriptor.py Log: Comment out stuff that was failing for cpy 2.5 (hash() can return long in 2.5 and it gets moded sys.maxint) Modified: pypy/dist/pypy/objspace/test/test_descriptor.py ============================================================================== --- pypy/dist/pypy/objspace/test/test_descriptor.py (original) +++ pypy/dist/pypy/objspace/test/test_descriptor.py Thu Jun 28 10:44:11 2007 @@ -62,10 +62,10 @@ def __cmp__(self, other): pass raises(TypeError, "hash(C())") - class D: - def __hash__(self): - return 23L - raises(TypeError, hash, D()) + #class D: + # def __hash__(self): + # return 23L + #raises(TypeError, hash, D()) class E: def __hash__(self): From fijal at codespeak.net Thu Jun 28 10:45:03 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Thu, 28 Jun 2007 10:45:03 +0200 (CEST) Subject: [pypy-svn] r44580 - in pypy/dist/pypy: . tool/test Message-ID: <20070628084503.D0A67810A@code0.codespeak.net> Author: fijal Date: Thu Jun 28 10:45:03 2007 New Revision: 44580 Modified: pypy/dist/pypy/conftest.py pypy/dist/pypy/tool/test/test_pytestsupport.py Log: The thing I always want to do - add a ExpectTest test case for running inside pexpect. usefull for testing terminal stuff. Modified: pypy/dist/pypy/conftest.py ============================================================================== --- pypy/dist/pypy/conftest.py (original) +++ pypy/dist/pypy/conftest.py Thu Jun 28 10:45:03 2007 @@ -1,10 +1,12 @@ -import py, sys +import py, sys, os from py.__.test.outcome import Failed from pypy.interpreter.gateway import app2interp_temp from pypy.interpreter.error import OperationError from pypy.tool.pytest import appsupport from pypy.tool.option import make_config, make_objspace from inspect import isclass, getmro +from pypy.tool.udir import udir +from pypy.tool.autopath import pypydir rootdir = py.magic.autopath().dirpath() @@ -25,6 +27,9 @@ Option('-A', '--runappdirect', action="store_true", default=False, dest="runappdirect", help="run applevel tests directly on python interpreter (not through PyPy)"), + Option('--direct', action="store_true", + default=False, dest="rundirect", + help="run pexpect tests directly") ) _SPACECACHE={} @@ -183,6 +188,11 @@ return self.accept_regular_test() if name.startswith('AppTest'): return True + if name.startswith('ExpectTest'): + return True + #XXX todo + #if name.startswith('AppExpectTest'): + # return True return False def setup(self): @@ -196,9 +206,19 @@ obj = getattr(self.obj, name) if isclass(obj): if name.startswith('AppTest'): - return AppClassCollector(name, parent=self) - else: - return IntClassCollector(name, parent=self) + return AppClassCollector(name, parent=self) + elif name.startswith('ExpectTest'): + if option.rundirect: + return py.test.collect.Class(name, parent=self) + return ExpectClassCollector(name, parent=self) + # XXX todo + #elif name.startswith('AppExpectTest'): + # if option.rundirect: + # return AppClassCollector(name, parent=self) + # return AppExpectClassCollector(name, parent=self) + else: + return IntClassCollector(name, parent=self) + elif hasattr(obj, 'func_code'): if name.startswith('app_test_'): assert not obj.func_code.co_flags & 32, \ @@ -335,7 +355,7 @@ self.execute_appex(space, func, space, w_instance) class PyPyClassCollector(py.test.collect.Class): - def setup(self): + def setup(self): cls = self.obj cls.space = LazyObjSpaceGetter() super(PyPyClassCollector, self).setup() @@ -380,3 +400,59 @@ space.newtuple([]), space.newdict()) self.w_class = w_class + +class ExpectTestMethod(py.test.collect.Function): + def safe_name(target): + s = "_".join(target) + s = s.replace("()", "paren") + s = s.replace(".py", "") + s = s.replace(".", "_") + return s + + safe_name = staticmethod(safe_name) + + def safe_filename(self): + name = self.safe_name(self.listnames()) + num = 0 + while udir.join(name + '.py').check(): + num += 1 + name = self.safe_name(self.listnames()) + "_" + str(num) + return name + '.py' + + def _spawn(self, *args, **kwds): + import pexpect + child = pexpect.spawn(*args, **kwds) + child.logfile = sys.stdout + return child + + def spawn(self, argv): + return self._spawn(sys.executable, argv) + + def execute(self, target, *args): + assert not args + import pexpect + source = py.code.Source(target)[1:].deindent() + filename = self.safe_filename() + source.lines = ['import sys', + 'sys.path.insert(0, %s)' % repr(os.path.dirname(pypydir)) + ] + source.lines + source.lines.append('print "%s ok!"' % filename) + f = udir.join(filename) + f.write(source) + # run target in the guarded environment + child = self.spawn([str(f)]) + import re + child.expect(re.escape(filename + " ok!")) + +class ExpectClassInstance(py.test.collect.Instance): + Function = ExpectTestMethod + +class ExpectClassCollector(py.test.collect.Class): + Instance = ExpectClassInstance + + def setup(self): + super(ExpectClassCollector, self).setup() + try: + import pexpect + except ImportError: + py.test.skip("pexpect not found") Modified: pypy/dist/pypy/tool/test/test_pytestsupport.py ============================================================================== --- pypy/dist/pypy/tool/test/test_pytestsupport.py (original) +++ pypy/dist/pypy/tool/test/test_pytestsupport.py Thu Jun 28 10:45:03 2007 @@ -6,7 +6,10 @@ from pypy.interpreter.pycode import PyCode from pypy.interpreter.pyframe import PyFrame from pypy.tool.pytest.appsupport import AppFrame, build_pytest_assertion, AppExceptionInfo - +import py +from pypy.tool.udir import udir +import os +import sys def somefunc(x): print x @@ -99,3 +102,54 @@ def test_values_arrive2(self): assert self.some1 == 42 + +def test_expectcollect(): + try: + import pexpect + except ImportError: + py.test.skip("pexpect not found") + source = py.code.Source(""" + class ExpectTestOne: + def test_one(self): + pass + """) + from pypy import conftest + tdir = udir.ensure("t", dir=True) + dest = tdir.join("test_expect.py") + dest.write(source) + col = conftest.Module(dest) + result = col.run() + assert len(result) == 1 + +def test_safename(): + from pypy.conftest import ExpectTestMethod + + safe_name = ExpectTestMethod.safe_name + assert safe_name(['pypy', 'tool', 'test', 'test_pytestsupport.py', + 'ExpectTest', '()', 'test_one']) == \ + 'pypy_tool_test_test_pytestsupport_ExpectTest_paren_test_one' + +def test_safe_filename(): + source = py.code.Source(""" + class ExpectTestOne: + def test_one(self): + pass + """) + dest = udir.join("test_expect_safefilename.py") + dest.write(source) + from pypy import conftest + col = conftest.Module(dest) + methcol = col.join('ExpectTestOne').join('()').join('test_one') + name = 'test_expect_safefilename_ExpectTestOne_paren_test_one.py' + assert methcol.safe_filename() == name + udir.ensure(name) + assert methcol.safe_filename() == name[:-3] + '_1.py' + +class ExpectTest: + def test_one(self): + import os + import sys + assert os.ttyname(sys.stdin.fileno()) + + def test_two(self): + import pypy From fijal at codespeak.net Thu Jun 28 10:45:53 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Thu, 28 Jun 2007 10:45:53 +0200 (CEST) Subject: [pypy-svn] r44581 - pypy/dist/pypy/rpython/module/test Message-ID: <20070628084553.AAD46810A@code0.codespeak.net> Author: fijal Date: Thu Jun 28 10:45:53 2007 New Revision: 44581 Modified: pypy/dist/pypy/rpython/module/test/test_ll_termios.py Log: Move to new interface Modified: pypy/dist/pypy/rpython/module/test/test_ll_termios.py ============================================================================== --- pypy/dist/pypy/rpython/module/test/test_ll_termios.py (original) +++ pypy/dist/pypy/rpython/module/test/test_ll_termios.py Thu Jun 28 10:45:53 2007 @@ -9,60 +9,27 @@ def setup_module(mod): try: - import pexpect - mod.pexpect = pexpect - except ImportError: - py.test.skip("Pexpect not found") - try: import termios mod.termios = termios except ImportError: py.test.skip("termios not found") - py_py = py.path.local(pypydir).join('bin', 'py.py') - assert py_py.check() - mod.py_py = py_py - -class TestTermios(object): - def _spawn(self, *args, **kwds): - print 'SPAWN:', args, kwds - child = pexpect.spawn(*args, **kwds) - child.logfile = sys.stdout - return child - - def spawn(self, argv): - return self._spawn(sys.executable, argv) +class ExpectTestLLTermios(object): def test_tcgetattr(self): - source = py.code.Source(""" - import sys - sys.path.insert(0, '%s') + from pypy.translator.c.test.test_genc import compile import termios from pypy.rlib import rtermios def runs_tcgetattr(): tpl = list(rtermios.tcgetattr(2)[:-1]) - print tpl + return str(tpl) - fn = compile(runs_tcgetattr, [], backendopt=False, -) - print 'XXX' - fn(expected_extra_mallocs=1) - print str(rtermios.tcgetattr(2)[:-1]) - """ % os.path.dirname(pypydir)) - f = udir.join("test_tcgetattr.py") - f.write(source) - child = self.spawn([str(f)]) - child.expect("XXX") - child.expect('\[([^\]]*)\]') - first = child.match.group(1) - child.expect('\(([^\]]*)\)') - second = child.match.group(1) - assert first == second + fn = compile(runs_tcgetattr, [], backendopt=False) + res = fn() + res2 = str(rtermios.tcgetattr(2)[:-1]) + assert res[1:-1] == res2[1:-1] def test_tcgetattr2(self): - source = py.code.Source(""" - import sys - sys.path.insert(0, '%s') from pypy.translator.c.test.test_genc import compile from pypy.rpython.module import ll_termios from pypy.rlib import rtermios @@ -76,22 +43,11 @@ fn = compile(runs_tcgetattr, [], backendopt=False) res = fn() - if res == 2: - print 'OK!' - else: - print 'fail!' - """ % os.path.dirname(pypydir)) - f = udir.join("test_tcgetattr.py") - f.write(source) - child = self.spawn([str(f)]) - child.expect("OK!") + assert res == 2 def test_tcsetattr(self): # a test, which doesn't even check anything. # I've got no idea how to test it to be honest :-( - source = py.code.Source(""" - import sys - sys.path.insert(0, '%s') from pypy.translator.c.test.test_genc import compile from pypy.rpython.module import ll_termios from pypy.rlib import rtermios @@ -106,17 +62,8 @@ fn = compile(runs_tcsetattr, [], backendopt=False) fn() - print 'OK!' - """ % os.path.dirname(pypydir)) - f = udir.join("test_tcsetattr.py") - f.write(source) - child = self.spawn([str(f)]) - child.expect("OK!") - + def test_tcrest(self): - source = py.code.Source(""" - import sys - sys.path.insert(0, '%s') from pypy.translator.c.test.test_genc import compile from pypy.rpython.module import ll_termios import termios, time @@ -128,33 +75,15 @@ fn = compile(runs_tcall, [], backendopt=False) fn() - print 'OK!' - """ % os.path.dirname(pypydir)) - f = udir.join("test_tcall.py") - f.write(source) - child = self.spawn([str(f)]) - child.expect("OK!") def test_tcsetattr_icanon(self): - source = py.code.Source(""" - import sys - sys.path.insert(0, '%s') from pypy.rlib import rtermios import termios - old_tcsetattr = termios.tcsetattr def check(fd, when, attributes): count = len([i for i in attributes[-1] if isinstance(i, int)]) assert count == 2 termios.tcsetattr = check - try: - attr = list(rtermios.tcgetattr(2)) - attr[3] |= termios.ICANON - rtermios.tcsetattr(2, termios.TCSANOW, attr) - finally: - termios.tcsetattr = old_tcsetattr - print 'OK!' - """ % os.path.dirname(pypydir)) - f = udir.join("test_tcsetattricanon.py") - f.write(source) - child = self.spawn([str(f)]) - child.expect("OK!") + attr = list(rtermios.tcgetattr(2)) + attr[3] |= termios.ICANON + rtermios.tcsetattr(2, termios.TCSANOW, attr) + From fijal at codespeak.net Thu Jun 28 10:46:53 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Thu, 28 Jun 2007 10:46:53 +0200 (CEST) Subject: [pypy-svn] r44582 - in pypy/dist/pypy/rpython/module: . test Message-ID: <20070628084653.93EA1810A@code0.codespeak.net> Author: fijal Date: Thu Jun 28 10:46:52 2007 New Revision: 44582 Modified: pypy/dist/pypy/rpython/module/ll_os.py pypy/dist/pypy/rpython/module/test/test_ll_os.py Log: * separators * add os.ttyname * few clarifications Modified: pypy/dist/pypy/rpython/module/ll_os.py ============================================================================== --- pypy/dist/pypy/rpython/module/ll_os.py (original) +++ pypy/dist/pypy/rpython/module/ll_os.py Thu Jun 28 10:46:52 2007 @@ -32,13 +32,11 @@ from pypy.rpython.lltypesystem import rffi from pypy.rpython.lltypesystem import lltype +# ------------------------------- os.execv ------------------------------ + if hasattr(os, 'execv'): - if os.name == 'nt': - name = '_execv' - else: - name = 'execv' - os_execv = rffi.llexternal(name, [rffi.CCHARP, rffi.CCHARPP], + os_execv = rffi.llexternal('execv', [rffi.CCHARP, rffi.CCHARPP], lltype.Signed) def execv_lltypeimpl(path, args): @@ -52,12 +50,9 @@ register_external(os.execv, [str, [str]], s_ImpossibleValue, llimpl= execv_lltypeimpl, export_name="ll_os.ll_os_execv") -if os.name == 'nt': - name = '_dup' -else: - name = 'dup' +# ------------------------------- os.dup -------------------------------- -os_dup = rffi.llexternal(name, [lltype.Signed], lltype.Signed, +os_dup = rffi.llexternal('dup', [lltype.Signed], lltype.Signed, _callable=os.dup) def dup_lltypeimpl(fd): @@ -68,11 +63,9 @@ register_external(os.dup, [int], int, llimpl=dup_lltypeimpl, export_name="ll_os.ll_os_dup", oofakeimpl=os.dup) -if os.name == 'nt': - name = '_dup2' -else: - name = 'dup2' -os_dup2 = rffi.llexternal(name, [lltype.Signed, lltype.Signed], lltype.Signed) +# ------------------------------- os.dup2 ------------------------------- + +os_dup2 = rffi.llexternal('dup2', [lltype.Signed, lltype.Signed], lltype.Signed) def dup2_lltypeimpl(fd, newfd): error = os_dup2(fd, newfd) @@ -81,6 +74,7 @@ register_external(os.dup2, [int, int], s_None, llimpl=dup2_lltypeimpl, export_name="ll_os.ll_os_dup2") +# ------------------------------- os.utime ------------------------------ UTIMEBUFP = rffi.CStruct('utimbuf', ('actime', rffi.SIZE_T), ('modtime', rffi.SIZE_T)) @@ -111,7 +105,9 @@ if error == -1: raise OSError(rffi.c_errno, "utime_tuple failed") register_external(ros.utime_tuple, [str, (float, float)], s_None, "ll_os.utime_tuple", - llimpl=utime_tuple_lltypeimpl) + llimpl=utime_tuple_lltypeimpl) + +# ------------------------------- os.open ------------------------------- def fake_os_open(l_path, flags, mode): path = rffi.charp2str(l_path) @@ -140,6 +136,9 @@ register_external(os.open, [str, int, int], int, "ll_os.ll_os_open", llimpl=os_open_lltypeimpl, oofakeimpl=os_open_oofakeimpl) +# ------------------------------- os.WIFSIGNALED ------------------------ +# XXX this needs to be generated automatically for all os.W* + if hasattr(os, 'WIFSIGNALED'): def fake_WIFSIGNALED(status): return int(os.WIFSIGNALED(status)) @@ -154,6 +153,24 @@ register_external(os.WIFSIGNALED, [int], bool, "ll_os.WIFSIGNALED", llimpl=WIFSIGNALED_lltypeimpl) +# ------------------------------- os.ttyname ---------------------------- + +if hasattr(os, 'ttyname'): + def fake_ttyname(fd): + return rffi.str2charp(os.ttyname(fd)) + + os_ttyname = rffi.llexternal('ttyname', [lltype.Signed], rffi.CCHARP, + _callable=fake_ttyname) + + def ttyname_lltypeimpl(fd): + l_name = os_ttyname(fd) + if not l_name: + raise OSError(rffi.c_errno, "ttyname raised") + return rffi.charp2str(l_name) + + register_external(os.ttyname, [int], str, "ll_os.ttyname", + llimpl=ttyname_lltypeimpl) + class BaseOS: __metaclass__ = ClassMethods @@ -221,14 +238,6 @@ return os.system(cls.from_rstr(cmd)) ll_os_system.suggested_primitive = True - #def ll_os_execv(cls, cmd, args): - # os.execv(cmd, args) - #ll_os_execv.suggested_primitive = True - - #def ll_os_execve(cls, cmd, args, env): - # env_list = from_rdict(env) - # ll_execve(cmd, args, env_list) - def ll_os_unlink(cls, path): os.unlink(cls.from_rstr(path)) ll_os_unlink.suggested_primitive = True Modified: pypy/dist/pypy/rpython/module/test/test_ll_os.py ============================================================================== --- pypy/dist/pypy/rpython/module/test/test_ll_os.py (original) +++ pypy/dist/pypy/rpython/module/test/test_ll_os.py Thu Jun 28 10:46:52 2007 @@ -109,3 +109,24 @@ fn = compile(fun, [int]) assert fn(0) == False assert fn(1) == True + +class ExpectTestOs: + def setup_class(cls): + if not hasattr(os, 'ttyname'): + py.test.skip("no ttyname") + + def test_ttyname(self): + import os + import py + from pypy.translator.c.test.test_genc import compile + def f(num): + try: + return os.ttyname(num) + except OSError: + return '' + + fn = compile(f, [int]) + assert f(0) == fn(0) + assert fn(338) == '' + + From mwh at codespeak.net Thu Jun 28 10:47:21 2007 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 28 Jun 2007 10:47:21 +0200 (CEST) Subject: [pypy-svn] r44583 - pypy/dist/pypy/objspace/std Message-ID: <20070628084721.74662810A@code0.codespeak.net> Author: mwh Date: Thu Jun 28 10:47:20 2007 New Revision: 44583 Modified: pypy/dist/pypy/objspace/std/dictmultiobject.py Log: improve two comments Modified: pypy/dist/pypy/objspace/std/dictmultiobject.py ============================================================================== --- pypy/dist/pypy/objspace/std/dictmultiobject.py (original) +++ pypy/dist/pypy/objspace/std/dictmultiobject.py Thu Jun 28 10:47:20 2007 @@ -14,7 +14,7 @@ directly to signal that the key is not in the dict in any case. XXX The types should provide such a flag. """ - # XXX there are much more types + # XXX there are many more types return (space.is_w(w_lookup_type, space.w_NoneType) or space.is_w(w_lookup_type, space.w_int) or space.is_w(w_lookup_type, space.w_bool) or @@ -150,7 +150,7 @@ def get(self, w_lookup): space = self.space if not _is_str(space, w_lookup) and not _is_sane_hash(space, w_lookup): - # count hash + # give hash a chance to raise an exception space.hash(w_lookup) return None From fijal at codespeak.net Thu Jun 28 10:49:33 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Thu, 28 Jun 2007 10:49:33 +0200 (CEST) Subject: [pypy-svn] r44584 - in pypy/dist/pypy/translator: . test Message-ID: <20070628084933.D1325810A@code0.codespeak.net> Author: fijal Date: Thu Jun 28 10:49:33 2007 New Revision: 44584 Modified: pypy/dist/pypy/translator/driver.py pypy/dist/pypy/translator/test/test_driver.py Log: Make entry_point default target if target function is not specified Modified: pypy/dist/pypy/translator/driver.py ============================================================================== --- pypy/dist/pypy/translator/driver.py (original) +++ pypy/dist/pypy/translator/driver.py Thu Jun 28 10:49:33 2007 @@ -753,9 +753,16 @@ if backend == 'cli': from pypy.translator.cli.support import patch driver.old_cli_defs = patch() - - target = targetspec_dic['target'] - spec = target(driver, args) + + if 'target' in targetspec_dic: + target = targetspec_dic['target'] + spec = target(driver, args) + else: + try: + entry_point = targetspec_dic['entry_point'] + except KeyError: + raise ValueError("Target spec doesn't seem to have target nor entry_point") + spec = entry_point, None try: entry_point, inputtypes, policy = spec Modified: pypy/dist/pypy/translator/test/test_driver.py ============================================================================== --- pypy/dist/pypy/translator/test/test_driver.py (original) +++ pypy/dist/pypy/translator/test/test_driver.py Thu Jun 28 10:49:33 2007 @@ -63,3 +63,15 @@ 'run_c', 'prehannotatebackendopt', 'hintannotate', 'timeshift'] assert cmpl(td.exposed, expected) + +def test_from_targetspecdic(): + py.test.raises(ValueError, TranslationDriver.from_targetspec, {}) + def f(argv): + return 0 + driver = TranslationDriver.from_targetspec({'entry_point':f}) + assert driver.entry_point is f + def target(driver, args): + return f, None + driver = TranslationDriver.from_targetspec({'target':target}) + assert driver.entry_point is f + From fijal at codespeak.net Thu Jun 28 10:50:01 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Thu, 28 Jun 2007 10:50:01 +0200 (CEST) Subject: [pypy-svn] r44585 - pypy/dist/pypy/translator/goal Message-ID: <20070628085001.55120810A@code0.codespeak.net> Author: fijal Date: Thu Jun 28 10:50:01 2007 New Revision: 44585 Modified: pypy/dist/pypy/translator/goal/targetnopstandalone.py Log: Simplify targetnopstandalone Modified: pypy/dist/pypy/translator/goal/targetnopstandalone.py ============================================================================== --- pypy/dist/pypy/translator/goal/targetnopstandalone.py (original) +++ pypy/dist/pypy/translator/goal/targetnopstandalone.py Thu Jun 28 10:50:01 2007 @@ -17,8 +17,3 @@ def entry_point(argv): debug("hello world") return 0 - -# _____ Define and setup target ___ - -def target(*args): - return entry_point, None From fijal at codespeak.net Thu Jun 28 10:51:27 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Thu, 28 Jun 2007 10:51:27 +0200 (CEST) Subject: [pypy-svn] r44586 - pypy/dist/pypy/translator/goal Message-ID: <20070628085127.8022B810F@code0.codespeak.net> Author: fijal Date: Thu Jun 28 10:51:24 2007 New Revision: 44586 Modified: pypy/dist/pypy/translator/goal/app_main.py Log: Make pyrepl default frontend if available Modified: pypy/dist/pypy/translator/goal/app_main.py ============================================================================== --- pypy/dist/pypy/translator/goal/app_main.py (original) +++ pypy/dist/pypy/translator/goal/app_main.py Thu Jun 28 10:51:24 2007 @@ -299,7 +299,18 @@ success = run_toplevel(execfile, sys.argv[0], mainmodule.__dict__) if is_interactive(): - success = run_toplevel(interactive_console, mainmodule) + try: + import _curses + import termios + from pyrepl.python_reader import main + from pyrepl import cmdrepl + #import pdb + #pdb.Pdb = cmdrepl.replize(pdb.Pdb, 1) + except ImportError: + success = run_toplevel(interactive_console, mainmodule) + else: + main(print_banner=False) + success = True except SystemExit, e: return e.code else: From fijal at codespeak.net Thu Jun 28 10:52:26 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Thu, 28 Jun 2007 10:52:26 +0200 (CEST) Subject: [pypy-svn] r44587 - pypy/dist/pypy/module/_curses/test Message-ID: <20070628085226.93FDE810F@code0.codespeak.net> Author: fijal Date: Thu Jun 28 10:52:25 2007 New Revision: 44587 Modified: pypy/dist/pypy/module/_curses/test/test_curses.py Log: Move tests to new interface Modified: pypy/dist/pypy/module/_curses/test/test_curses.py ============================================================================== --- pypy/dist/pypy/module/_curses/test/test_curses.py (original) +++ pypy/dist/pypy/module/_curses/test/test_curses.py Thu Jun 28 10:52:25 2007 @@ -67,12 +67,12 @@ child.expect('ok!') -# XXX probably we need to run all the stuff here in pexpect anyway... - -class TestCCurses(object): +class ExpectTestCCurses(object): """ Test compiled version """ def test_csetupterm(self): + from pypy.translator.c.test.test_genc import compile + from pypy.module._curses import interp_curses def runs_setupterm(): interp_curses._curses_setupterm_null(1) @@ -80,20 +80,25 @@ fn() def test_ctgetstr(self): + from pypy.translator.c.test.test_genc import compile + from pypy.module._curses import interp_curses def runs_ctgetstr(): interp_curses._curses_setupterm("xterm", 1) - res = interp_curses._curses_tigetstr('cup') - assert res == '\x1b[%i%p1%d;%p2%dH' + return interp_curses._curses_tigetstr('cup') fn = compile(runs_ctgetstr, []) - fn() + res = fn() + assert res == '\x1b[%i%p1%d;%p2%dH' def test_ctparm(self): + from pypy.translator.c.test.test_genc import compile + from pypy.module._curses import interp_curses def runs_tparm(): interp_curses._curses_setupterm("xterm", 1) cup = interp_curses._curses_tigetstr('cup') - res = interp_curses._curses_tparm(cup, [5, 3]) - assert res == '\033[6;4H' + return interp_curses._curses_tparm(cup, [5, 3]) fn = compile(runs_tparm, []) - fn() + res = fn() + assert res == '\033[6;4H' + From fijal at codespeak.net Thu Jun 28 10:53:13 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Thu, 28 Jun 2007 10:53:13 +0200 (CEST) Subject: [pypy-svn] r44588 - in pypy/dist/pypy/module/posix: . test Message-ID: <20070628085313.1ACD8810A@code0.codespeak.net> Author: fijal Date: Thu Jun 28 10:53:12 2007 New Revision: 44588 Modified: pypy/dist/pypy/module/posix/__init__.py pypy/dist/pypy/module/posix/interp_posix.py pypy/dist/pypy/module/posix/test/test_posix2.py Log: add os.ttyname Modified: pypy/dist/pypy/module/posix/__init__.py ============================================================================== --- pypy/dist/pypy/module/posix/__init__.py (original) +++ pypy/dist/pypy/module/posix/__init__.py Thu Jun 28 10:53:12 2007 @@ -81,6 +81,8 @@ interpleveldefs['execve'] = 'interp_posix.execve' #if hasattr(ctypes_posix, 'uname'): # interpleveldefs['uname'] = 'interp_posix.uname' + if hasattr(os, 'ttyname'): + interpleveldefs['ttyname'] = 'interp_posix.ttyname' def setup_after_space_initialization(self): """NOT_RPYTHON""" Modified: pypy/dist/pypy/module/posix/interp_posix.py ============================================================================== --- pypy/dist/pypy/module/posix/interp_posix.py (original) +++ pypy/dist/pypy/module/posix/interp_posix.py Thu Jun 28 10:53:12 2007 @@ -501,3 +501,10 @@ def WIFSIGNALED(space, status): return space.newbool(os.WIFSIGNALED(status)) WIFSIGNALED.unwrap_spec = [ObjSpace, int] + +def ttyname(space, fd): + try: + return space.wrap(os.ttyname(fd)) + except OSError, e: + raise wrap_oserror(space, e) +ttyname.unwrap_spec = [ObjSpace, int] Modified: pypy/dist/pypy/module/posix/test/test_posix2.py ============================================================================== --- pypy/dist/pypy/module/posix/test/test_posix2.py (original) +++ pypy/dist/pypy/module/posix/test/test_posix2.py Thu Jun 28 10:53:12 2007 @@ -1,7 +1,10 @@ from pypy.objspace.std import StdObjSpace from pypy.tool.udir import udir from pypy.conftest import gettestobjspace +from pypy.tool.autopath import pypydir import os +import py +import sys def setup_module(mod): mod.space = gettestobjspace(usemodules=['posix']) @@ -228,3 +231,33 @@ cmd = '''python -c "import os, sys; sys.exit(int('ABCABC' in os.environ))" ''' res = os.system(cmd) assert res == 0 + +class TestPexpect(object): + # XXX replace with AppExpectTest class as soon as possible + def setup_class(cls): + try: + import pexpect + except ImportError: + py.test.skip("pexpect not found") + + def _spawn(self, *args, **kwds): + import pexpect + print 'SPAWN:', args, kwds + child = pexpect.spawn(*args, **kwds) + child.logfile = sys.stdout + return child + + def spawn(self, argv): + py_py = py.path.local(pypydir).join('bin', 'py.py') + return self._spawn(sys.executable, [str(py_py)] + argv) + + def test_ttyname(self): + source = py.code.Source(""" + import os, sys + assert os.ttyname(sys.stdin.fileno()) + print 'ok!' + """) + f = udir.join("test_ttyname.py") + f.write(source) + child = self.spawn([str(f)]) + child.expect('ok!') From pedronis at codespeak.net Thu Jun 28 11:17:01 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Thu, 28 Jun 2007 11:17:01 +0200 (CEST) Subject: [pypy-svn] r44589 - in pypy/dist/pypy/translator: . goal test Message-ID: <20070628091701.D3A1280EC@code0.codespeak.net> Author: pedronis Date: Thu Jun 28 11:17:01 2007 New Revision: 44589 Modified: pypy/dist/pypy/translator/driver.py pypy/dist/pypy/translator/goal/targetnopstandalone.py pypy/dist/pypy/translator/test/test_driver.py Log: revert new implicit way of doing things Modified: pypy/dist/pypy/translator/driver.py ============================================================================== --- pypy/dist/pypy/translator/driver.py (original) +++ pypy/dist/pypy/translator/driver.py Thu Jun 28 11:17:01 2007 @@ -753,16 +753,9 @@ if backend == 'cli': from pypy.translator.cli.support import patch driver.old_cli_defs = patch() - - if 'target' in targetspec_dic: - target = targetspec_dic['target'] - spec = target(driver, args) - else: - try: - entry_point = targetspec_dic['entry_point'] - except KeyError: - raise ValueError("Target spec doesn't seem to have target nor entry_point") - spec = entry_point, None + + target = targetspec_dic['target'] + spec = target(driver, args) try: entry_point, inputtypes, policy = spec Modified: pypy/dist/pypy/translator/goal/targetnopstandalone.py ============================================================================== --- pypy/dist/pypy/translator/goal/targetnopstandalone.py (original) +++ pypy/dist/pypy/translator/goal/targetnopstandalone.py Thu Jun 28 11:17:01 2007 @@ -17,3 +17,8 @@ def entry_point(argv): debug("hello world") return 0 + +# _____ Define and setup target ___ + +def target(*args): + return entry_point, None Modified: pypy/dist/pypy/translator/test/test_driver.py ============================================================================== --- pypy/dist/pypy/translator/test/test_driver.py (original) +++ pypy/dist/pypy/translator/test/test_driver.py Thu Jun 28 11:17:01 2007 @@ -63,15 +63,3 @@ 'run_c', 'prehannotatebackendopt', 'hintannotate', 'timeshift'] assert cmpl(td.exposed, expected) - -def test_from_targetspecdic(): - py.test.raises(ValueError, TranslationDriver.from_targetspec, {}) - def f(argv): - return 0 - driver = TranslationDriver.from_targetspec({'entry_point':f}) - assert driver.entry_point is f - def target(driver, args): - return f, None - driver = TranslationDriver.from_targetspec({'target':target}) - assert driver.entry_point is f - From antocuni at codespeak.net Thu Jun 28 14:49:43 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Thu, 28 Jun 2007 14:49:43 +0200 (CEST) Subject: [pypy-svn] r44595 - in pypy/dist/pypy/translator/cli: . test Message-ID: <20070628124943.3EBCF80B4@code0.codespeak.net> Author: antocuni Date: Thu Jun 28 14:49:42 2007 New Revision: 44595 Modified: pypy/dist/pypy/translator/cli/dotnet.py pypy/dist/pypy/translator/cli/test/test_carbonpython.py Log: let CliClass to be used in @export Modified: pypy/dist/pypy/translator/cli/dotnet.py ============================================================================== --- pypy/dist/pypy/translator/cli/dotnet.py (original) +++ pypy/dist/pypy/translator/cli/dotnet.py Thu Jun 28 14:49:42 2007 @@ -256,6 +256,8 @@ def compute_annotation(self): return SomeCliClass() + def compute_result_annotation(self): + return SomeOOInstance(self.instance._INSTANCE) class CliNamespace(object): def __init__(self, name): Modified: pypy/dist/pypy/translator/cli/test/test_carbonpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/test/test_carbonpython.py (original) +++ pypy/dist/pypy/translator/cli/test/test_carbonpython.py Thu Jun 28 14:49:42 2007 @@ -6,6 +6,7 @@ TEMPLATE = """ using System; +using System.Collections; class CarbonPytonTest { public static void Main() { %s @@ -122,3 +123,20 @@ Console.WriteLine(obj.add(1, 2)); """) assert res == 42 + + def test_export_cliclass(self): + from pypy.translator.cli.dotnet import CLR + + @export(CLR.System.Collections.ArrayList, int) + def getitem(obj, i): + return obj.get_Item(i) + + entrypoints = collect_entrypoints({'getitem': getitem}) + dll = DllDef('test', 'Test', entrypoints) + dll.compile() + res = self._csharp('test', """ + ArrayList obj = new ArrayList(); + obj.Add(42); + Console.WriteLine(Test.getitem(obj, 0)); + """) + assert res == 42 From cfbolz at codespeak.net Thu Jun 28 15:17:41 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Thu, 28 Jun 2007 15:17:41 +0200 (CEST) Subject: [pypy-svn] r44598 - in pypy/dist/pypy/rlib/parsing: . test Message-ID: <20070628131741.100448103@code0.codespeak.net> Author: cfbolz Date: Thu Jun 28 15:17:41 2007 New Revision: 44598 Modified: pypy/dist/pypy/rlib/parsing/deterministic.py pypy/dist/pypy/rlib/parsing/makepackrat.py pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Log: fix a bug in the handling of left recursion in the presence of arguments. also remove accidentally checked in code for a new prolog parser. Modified: pypy/dist/pypy/rlib/parsing/deterministic.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/deterministic.py (original) +++ pypy/dist/pypy/rlib/parsing/deterministic.py Thu Jun 28 15:17:41 2007 @@ -340,7 +340,7 @@ result = result.get_code() while "\n\n" in result: result = result.replace("\n\n", "\n") - #print result + print result exec py.code.Source(result).compile() return recognize Modified: pypy/dist/pypy/rlib/parsing/makepackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/makepackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/makepackrat.py Thu Jun 28 15:17:41 2007 @@ -347,7 +347,7 @@ self.emit("_result = None") self.emit("_error = None") - def memoize_footer(self, name): + def memoize_footer(self, name, args): dictname = "_dict_%s" % (name, ) if self.have_call: for _ in self.start_block( @@ -362,7 +362,7 @@ self.emit("_status.result = %s" % (self.resultname, )) self.emit("_status.error = _error") self.emit("self._pos = _startingpos") - self.emit("return self._%s()" % (name, )) + self.emit("return self._%s(%s)" % (name, ', '.join(args))) else: self.emit("assert _status.status != _status.LEFTRECURSION") self.emit("_status.status = _status.NORMAL") @@ -451,7 +451,7 @@ subsequent = self.restore_code(allother) self.memoize_header(name, otherargs) self.add_code(subsequent) - self.memoize_footer(name) + self.memoize_footer(name, otherargs) self.end_block("def") def visit_or(self, t, first=False): Modified: pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py ============================================================================== --- pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py (original) +++ pypy/dist/pypy/rlib/parsing/test/test_pypackrat.py Thu Jun 28 15:17:41 2007 @@ -349,6 +349,30 @@ assert p._pos == 2 assert res == "c" + def test_leftrecursion_argument(self): + class parser(PackratParser): + """ + additive(op): + a = additive({op}) + __chars__({op}) + b = multitive + return {eval('a %s b' % (op, ))} + | multitive; + multitive: + a = multitive + '*' + b = simple + return {a * b} + | simple; + simple: + x = `0|([1-9][0-9]*)` + return {int(x)}; + """ + p = parser('4-4-4-4') + res = p.additive('-') + assert res == -8 + + def test_doif(self): class parser(PackratParser): """ @@ -447,168 +471,4 @@ expected.sort() assert expected == ['a', 'x', 'y'] - def test_prolog(self): - py.test.skip() - class PrologParser(PackratParser): - r""" - VAR: - `[A-Z_]([a-zA-Z0-9]|_)*|_`; - - NUMBER: - `(0|[1-9][0-9]*)(\.[0-9]+)?`; - - IGNORE: - `[ \\n\\t]|(/\\*[^\\*]*(\\*[^/][^\\*]*)*\\*/)|(%[^\\n]*)`; - - ATOM: - `([a-z]([a-zA-Z0-9]|_)*)|('[^']*')|\[\]|!|\+|\-`; - - EOF: - !__any__; - - fact: - toplevel_op_expr ['.']; - - simple: - VAR - [IGNORE*] - | sign = ('+' | '-') - IGNORE* - num = NUMBER - IGNORE* - return {XXX} - | ATOM - [IGNORE*] - | '(' - IGNORE* - expr = toplevel_op_expr - ')' - IGNORE* - return {expr}; - | listexpr; - - listexpr: - '[' - IGNORE* - body = listbody - ']' - return {body}; - - listbody: - head = toplevel_op_expr - '|' - tail = toplevel_op_expr - return {XXX} - | list = toplevel_op_expr - return {XXX}; - - toplevel_op_expr: - choose priority in {range(len(self.ops))} - expr(priority); - - expr(priority): - if {priority < len(self.ops)} - choose patternindex in {range(len(self.ops[priority]))} - expr_pattern({priority}, {patternindex}) - | simple; - - expr_pattern(priority, patternindex): - choose operator in {self.ops[priority][patternindex]} - args = pattern({priority}, {self.pattern[patternindex]}, - {operator}) - return {Term(operator, args)}; - - pattern(priority, pattern, operator): - loop({priority}, {pattern}, {operator}, {0}); - - loop(priority, pattern, operator, index): - ( - if {pattern[index] == 'f'} - args1 = op({operator}) - | if {pattern[index] == 'x'} - args1 = lower({priority}) - | if {pattern[index] == 'y'} - args1 = same({priority}) - ) - args2 = loop( - - op(operator): - __chars__({self.ops[priority].xfx[pos]}) - return {[]} - - xfx(priority, pos): - expr1 = expr({priority + 1}) - IGNORE* - op = __chars__({self.ops[priority].xfx[pos]}) - IGNORE* - expr2 = expr({priority + 1}) - return {Term(op, [expr1, expr2])} - | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} - xfx({priority}, {pos + 1}); - - xfy(priority, pos): - expr1 = expr({priority + 1}) - IGNORE* - op = __chars__({self.ops[priority].xfx[pos]}) - IGNORE* - expr2 = expr({priority}) - return {Term(op, [expr1, expr2])} - | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} - xfx({priority}, {pos + 1}); - - yfx(priority, pos): - expr1 = expr({priority + 1}) - IGNORE* - op = __chars__({self.ops[priority].xfx[pos]}) - IGNORE* - expr2 = expr({priority}) - return {Term(op, [expr1, expr2])} - | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} - xfx({priority}, {pos + 1}); - - yfy(priority, pos): - expr1 = expr({priority}) - IGNORE* - op = __chars__({self.ops[priority].xfx[pos]}) - IGNORE* - expr2 = expr({priority}) - return {Term(op, [expr1, expr2])} - | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} - xfx({priority}, {pos + 1}); - - fx(priority, pos): - op = __chars__({self.ops[priority].fx[pos]}) - IGNORE* - ex = expr({priority + 1}) - return {Term(op, [ex])} - | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} - xfx({priority}, {pos + 1}); - - fy(priority, pos): - op = __chars__({self.ops[priority].xfx[pos]}) - IGNORE* - ex = expr({priority}) - return {Term(op, [ex])} - | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} - xfx({priority}, {pos + 1}); - - xf(priority, pos): - op = __chars__({self.ops[priority].xfx[pos]}) - IGNORE* - expr2 = expr({priority + 1}) - return {Term(op, [expr1, expr2])} - | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} - xfx({priority}, {pos + 1}); - - yf(priority, pos): - ex = expr({priority + 1}) - IGNORE* - op = __chars__({self.ops[priority].xfx[pos]}) - IGNORE* - expr2 = expr({priority + 1}) - return {Term(op, [expr1, expr2])} - | do !!__any__ if {len(self.ops[priority].xfx) < pos - 1} - xfx({priority}, {pos + 1}); - - """ From jlg at codespeak.net Thu Jun 28 15:49:30 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 28 Jun 2007 15:49:30 +0200 (CEST) Subject: [pypy-svn] r44599 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070628134930.7F1688101@code0.codespeak.net> Author: jlg Date: Thu Jun 28 15:49:30 2007 New Revision: 44599 Modified: pypy/dist/pypy/lang/scheme/TODO.txt pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_parser.py Log: RPython direction for object.py Modified: pypy/dist/pypy/lang/scheme/TODO.txt ============================================================================== --- pypy/dist/pypy/lang/scheme/TODO.txt (original) +++ pypy/dist/pypy/lang/scheme/TODO.txt Thu Jun 28 15:49:30 2007 @@ -5,12 +5,14 @@ (* 6 7) or even (+ 1 2 3 4) + parsing is done by some shiny new Carl's thingy W_xxx object like W_Fixnum should eval to itself despite context - - implement basic operations like + * / and so on + = implement basic operations like + * / and so on -- symbols, variables and execution context - global dict for symbols _obarray_ +-+variables and execution context -- there is need to distinct identifier from symbol +- symbols + - global dict for symbols _obarray_ + ++ there is need to distinct identifier from symbol (define var 11) (symbol? var) -> #f (symbol? 'var) -> #t @@ -28,8 +30,8 @@ Here starts the real fun! -- delayed evaluation - macros - proper tail-recursion +- delayed evaluation - continuations Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Thu Jun 28 15:49:30 2007 @@ -139,10 +139,16 @@ raise NotImplementedError def add_lst(ctx, lst): - return apply_lst(ctx, lambda x, y: x + y, lst) + def adder(x, y): + return x + y + + return apply_lst(ctx, adder, lst) def mul_lst(ctx, lst): - return apply_lst(ctx, lambda x, y: x * y, lst) + def multiplier(x, y): + return x * y + + return apply_lst(ctx, multiplier, lst) def apply_lst(ctx, fun, lst): acc = None Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Thu Jun 28 15:49:30 2007 @@ -42,8 +42,6 @@ assert unwrap(t) == 'don\'t believe "them"' def test_objects(): - #py.test.skip("in progress") - w_fixnum = parse('-12345') assert isinstance(w_fixnum, W_Fixnum) assert unwrap(w_fixnum) == -12345 From jlg at codespeak.net Thu Jun 28 16:02:28 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 28 Jun 2007 16:02:28 +0200 (CEST) Subject: [pypy-svn] r44600 - pypy/dist/pypy/lang/scheme Message-ID: <20070628140228.C5AF38101@code0.codespeak.net> Author: jlg Date: Thu Jun 28 16:02:27 2007 New Revision: 44600 Modified: pypy/dist/pypy/lang/scheme/ssparser.py Log: some imports needed Modified: pypy/dist/pypy/lang/scheme/ssparser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/ssparser.py (original) +++ pypy/dist/pypy/lang/scheme/ssparser.py Thu Jun 28 16:02:27 2007 @@ -1,5 +1,6 @@ import autopath from pypy.rlib.parsing.pypackrat import PackratParser +from pypy.rlib.parsing.makepackrat import BacktrackException, Status from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Identifier from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Float From jlg at codespeak.net Thu Jun 28 16:18:20 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 28 Jun 2007 16:18:20 +0200 (CEST) Subject: [pypy-svn] r44601 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070628141820.2B69B8101@code0.codespeak.net> Author: jlg Date: Thu Jun 28 16:18:19 2007 New Revision: 44601 Modified: pypy/dist/pypy/lang/scheme/TODO.txt pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_object.py Log: all scheme objects .to_boolean() is True but #f Modified: pypy/dist/pypy/lang/scheme/TODO.txt ============================================================================== --- pypy/dist/pypy/lang/scheme/TODO.txt (original) +++ pypy/dist/pypy/lang/scheme/TODO.txt Thu Jun 28 16:18:19 2007 @@ -17,10 +17,12 @@ (symbol? var) -> #f (symbol? 'var) -> #t +- control structures + - boolean + Do next ------- -- control structures - functions - implement key funcions (apply, reduce, mapcar and so on) Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Thu Jun 28 16:18:19 2007 @@ -5,7 +5,7 @@ return '' def to_boolean(self): - return False + return True def __str__(self): return self.to_string() + "W" Modified: pypy/dist/pypy/lang/scheme/test/test_object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_object.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_object.py Thu Jun 28 16:18:19 2007 @@ -14,18 +14,21 @@ str = "Hello World!" w_str = W_String(str) assert str == w_str.to_string() + assert w_str.to_boolean() is True def test_fixnum(): num = 12345 w_num = W_Fixnum(num) assert num == w_num.to_fixnum() assert float(num) == w_num.to_float() + assert w_num.to_boolean() is True def test_float(): num = 12345.567 w_num = W_Float(num) assert num == w_num.to_float() assert int(num) == w_num.to_fixnum() + assert w_num.to_boolean() is True def test_pair(): c1 = W_Fixnum(1) @@ -39,14 +42,18 @@ assert p.cdr.car == c2 assert p.cdr.cdr.car == c3 assert p.cdr.cdr.cdr == c4 + assert p.to_boolean() is True + assert c4.to_boolean() is True def test_symbol(): w_sym = W_Symbol("symb") assert w_sym.to_string() == "symb" + assert w_sym.to_boolean() is True def test_symbol(): w_id = W_Identifier("ident") assert w_id.to_string() == "ident" + assert w_id.to_boolean() is True def test_ctx(): w_fnum = W_Fixnum(12) From jlg at codespeak.net Thu Jun 28 16:29:14 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 28 Jun 2007 16:29:14 +0200 (CEST) Subject: [pypy-svn] r44602 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070628142914.6A2F9809E@code0.codespeak.net> Author: jlg Date: Thu Jun 28 16:29:14 2007 New Revision: 44602 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: (if ) macro implemented Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Thu Jun 28 16:29:14 2007 @@ -190,6 +190,21 @@ def eval(self, ctx): return define +def macro_if(ctx, lst): + w_condition = lst.car + w_then = lst.cdr.car + w_else = lst.cdr.cdr.car + + w_cond_val = w_condition.eval(ctx) + if w_cond_val.to_boolean() is True: + return w_then.eval(ctx) + else: + return w_else.eval(ctx) + +class MacroIf(W_Procedure): + def eval(self, ctx): + return macro_if + ###################################### # dict mapping operations to callables # callables must have 2 arguments @@ -201,6 +216,7 @@ '+': Add("+"), '*': Mul("*"), 'define': Define("define"), + 'if': MacroIf("if"), } class ExecutionContext(object): Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Thu Jun 28 16:29:14 2007 @@ -80,3 +80,12 @@ eval_expr(ctx, "(define v2 3.1)") w_num = eval_expr(ctx, "(+ 1 v1 v2)") assert w_num.to_number() == 46.1 + +def test_if_simple(): + ctx = ExecutionContext() + w_t = eval_expr(ctx, "(if #t #t #f)") + assert w_t.to_boolean() is True + w_f = eval_expr(ctx, "(if #f #t #f)") + assert w_f.to_boolean() is False + + From jlg at codespeak.net Thu Jun 28 16:42:37 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 28 Jun 2007 16:42:37 +0200 (CEST) Subject: [pypy-svn] r44603 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070628144237.26E458101@code0.codespeak.net> Author: jlg Date: Thu Jun 28 16:42:36 2007 New Revision: 44603 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: if evaluation tests Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Thu Jun 28 16:42:36 2007 @@ -36,6 +36,7 @@ return w_obj.eval(ctx) else: #reference to undefined identifier + #unbound raise NotImplementedError class W_Symbol(W_Root): Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Thu Jun 28 16:42:36 2007 @@ -1,3 +1,4 @@ +import py from pypy.lang.scheme.ssparser import parse from pypy.lang.scheme.object import W_Boolean, W_Fixnum, W_Float, W_String from pypy.lang.scheme.object import W_Nil, W_Pair, W_Symbol, W_Identifier @@ -71,6 +72,9 @@ ctx = ExecutionContext() eval_expr(ctx, "(define v1 42)") assert ctx.get("v1").to_number() == 42 + w_num = eval_expr(ctx, "v1") + assert w_num.to_number() == 42 + eval_expr(ctx, "(define v2 2.1)") assert ctx.get("v2").to_number() == 2.1 @@ -87,5 +91,20 @@ assert w_t.to_boolean() is True w_f = eval_expr(ctx, "(if #f #t #f)") assert w_f.to_boolean() is False + w_f = eval_expr(ctx, "(if 1 #f #t)") + assert w_f.to_boolean() is False +def test_if_evaluation(): + ctx = ExecutionContext() + eval_expr(ctx, "(define then #f)") + eval_expr(ctx, "(define else #f)") + eval_expr(ctx, "(if #t (define then #t) (define else #t))") + assert ctx.get("then").to_boolean() is True + assert ctx.get("else").to_boolean() is False + + eval_expr(ctx, "(define then #f)") + eval_expr(ctx, "(define else #f)") + eval_expr(ctx, "(if #f (define then #t) (define else #t))") + assert ctx.get("then").to_boolean() is False + assert ctx.get("else").to_boolean() is True From antocuni at codespeak.net Thu Jun 28 17:10:18 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Thu, 28 Jun 2007 17:10:18 +0200 (CEST) Subject: [pypy-svn] r44604 - pypy/dist/pypy/doc Message-ID: <20070628151018.D0CE78115@code0.codespeak.net> Author: antocuni Date: Thu Jun 28 17:10:17 2007 New Revision: 44604 Added: pypy/dist/pypy/doc/carbonpython.txt (contents, props changed) Log: some docs about carbonpython Added: pypy/dist/pypy/doc/carbonpython.txt ============================================================================== --- (empty file) +++ pypy/dist/pypy/doc/carbonpython.txt Thu Jun 28 17:10:17 2007 @@ -0,0 +1,230 @@ +================================================== +CarbonPython, aka C# considered harmful +================================================== + +CarbonPython overview +===================== + +CarbonPython is an experimental RPython to .NET compiler. Its main +focus is to produce DLLs to be used by other .NET programs, not +standalone executables; if you want to compile an RPython standalone +program, have a look to `translate.py`_. + +Compiled RPython programs are much faster (up to 250x) than +interpreted IronPython programs, hence it might be a convenient +replacement for C# when more speed is needed. RPython programs can be +as fast as C# programs. + +RPython is a restrict subset of Python, static enough to be analyzed +and compiled efficiently to lower level languages. To read more about +the RPython limitations read the `RPython description`_. + +**Disclaimer**: RPython is a much less convenient language than Python +to program with. If you do not need speed, there is no reason to look +at RPython. + +**Big disclaimer**: CarbonPython is still in a pre-alpha stage: it's +not meant to be used for production code, and the API might change in +the future. Despite this, it might be useful in some situations and +you are encouraged to try it by yourself. Suggestions, bug-reports and +even better patches are welcome. + +.. _`RPython description`: coding-guide.html#restricted-python +.. _`translate.py`: faq.html#how-do-i-compile-my-own-interpreters + + +Quick start +=========== + +Suppose you want to write a little DLL in RPython and call its +function from C#. + +Here is the file mylibrary.py:: + + from pypy.translator.cli.carbonpython import export + + @export(int, int) + def add(x, y): + return x+y + + @export(int, int) + def sub(x, y): + return x-y + + +And here the C# program main.cs:: + + using System; + public class CarbonPythonTest + { + public static void Main() + { + Console.WriteLine(mylibrary.add(40, 2)); + Console.WriteLine(mylibrary.sub(44, 2)); + } + } + +Once the files have been created, you can compile ``mylibrary.py`` +with CarbonPython to get the corresponding DLL:: + + $ python carbonpython.py mylibrary.py + ... lot of stuff + +Then, we compile main.cs into an executable, being sure to add a +reference to the newly created ``mylibrary.dll``:: + + # with mono on linux + $ gmcs /r:mylibrary.dll main.cs + + # with Microsoft CLR on windows + c:\> csc /r:mylibrary main.cs + +Now we can run the executable to see whether the answers are right:: + + $ mono main.exe + 42 + 42 + + +Multiple entry-points +===================== + +In RPython, the type of each variable is inferred by the `Annotator`_: +the annotator analyzed the whole program top-down starting from an +entry-point, i.e. a function whose we specified the types of the +parameters. + +This approach works for a standalone executables, but not for a +library that by definition is composed by more than one +entry-point. Thus, you need to explicitly specify which functions you +want to include in your DLL, together with the expected input types. + +To mark a function as an entry-point, you use the ``@export`` +decorator, which is defined in ``pypy.translator.cli.carbonpython``, +as shown by the previous example. Note that you do not need to +specify the return type, because it is automatically inferenced by the +annotator. + +.. _`Annotator`: dynamic-language-translation.html#annotator + + +Namespaces +========== + +Since `CLS`_ (Common Language Specification) does not support module +level static methods, RPython functions marked as entry-points are +compiled to static methods of a class, in order to be accessible by +every CLS-compliant language such as C# or VB.NET. + +The class which each function is placed in depends on its +**namespace**; for example, if the namespace of a function ``foo`` is +``A.B.C``, the function will be rendered as a static method of the +``C`` class inside the ``A.B`` namespace. This allows C# and +IronPython code to call the function using the intuitive ``A.B.C.foo`` +syntax. + +By default, the default namespace for exported function is the same as +the name of the module. Thus in the previous example the default +namespace is ``mylibrary`` and the functions are placed inside the +corresponding class in the global namespace. + +You can change the default namespace by setting the ``_namespace_`` +variable in the module you are compiling:: + + _namespace_ = 'Foo.Bar' + + @export(int, int) + def f(x, y): + pass + +Finally, you can also set a specific namespace on a per-function +basis, using the appropriate keyword argument of the ``@export`` +decorator:: + + @export(int, int, namespace='Foo.Bar') + def f(x, y): + pass + + +.. _`CLS`: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-335.pdf + + +Exporting classes +================= + +RPython libraries can also export classes: to export a class, add the +``@export`` decorator to its ``__init__`` method; similarly, you can +also export any methods of the class:: + + class MyClass: + + @export(int) + def __init__(self, x): + self.x = x + + @export + def getx(self): + return self.x + + +Note that the type of ``self`` must not be speficied: it will +automatically assumed to be ``MyClass``. + +The ``__init__`` method is not automatically mapped to the .NET +constructor; to properly initialize an RPython object from C# or +IronPython code you need to explicitly call ``__init__``; for example, +in C#:: + + MyClass obj = new MyClass(); + obj.__init__(x); + +Note that this is needed only when calling RPython code from the +outside; the RPython compiler automatically calls ``__init__`` +whenever an RPython class is instantiated. + +In the future this discrepacy will be fixed and the ``__init__`` +method will be automatically mapped to the constructor. + + +Accessing .NET libraries +======================== + +**Warning**: the API for accessing .NET classes from RPython is highly +experimental and will probably change in the future. + +In RPython you can access native .NET classes through the ``CLR`` +object defined in ``translator.cli.dotnet``: from there, you can +navigate through namespaces using the usual dot notation; for example, +``CLR.System.Collections.ArrayList`` refers to the ``ArrayList`` class +in the ``System.Collections`` namespace. + +To instantiate a .NET class, simply call it:: + + ArrayList = CLR.System.Collections.ArrayList + def foo(): + obj = ArrayList() + obj.Add(42) + return obj + +At the moment there is no special syntax support for indexers and +properties: for example, you can't access ArrayList's elements using +the square bracked notation, but you have to call the call the +``get_Item`` and ``set_Item`` methods; similarly, to access a property +``XXX`` you need to call ``get_XXX`` and ``set_XXX``:: + + def foo(): + obj = ArrayList() + obj.Add(42) + print obj.get_Item(0) + print obj.get_Count() + +Static methods and are also supported, as well as overloadings:: + + Math = CLR.System.Math + def foo(): + print Math.Abs(-42) + print Math.Abs(-42.0) + + +At the moment, it is not possible to reference assemblies other than +mscorlib. This will be fixed soon. From antocuni at codespeak.net Thu Jun 28 17:25:46 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Thu, 28 Jun 2007 17:25:46 +0200 (CEST) Subject: [pypy-svn] r44605 - pypy/dist/pypy/bin Message-ID: <20070628152546.002D4812E@code0.codespeak.net> Author: antocuni Date: Thu Jun 28 17:25:46 2007 New Revision: 44605 Added: pypy/dist/pypy/bin/carbonpython.py (contents, props changed) Log: add a script for carbonpython to the bin directory Added: pypy/dist/pypy/bin/carbonpython.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/bin/carbonpython.py Thu Jun 28 17:25:46 2007 @@ -0,0 +1,5 @@ +#! /usr/bin/env python +import autopath, sys +from pypy.translator.cli.carbonpython import main + +main(sys.argv) From jlg at codespeak.net Thu Jun 28 18:21:49 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 28 Jun 2007 18:21:49 +0200 (CEST) Subject: [pypy-svn] r44606 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070628162149.D1DE78118@code0.codespeak.net> Author: jlg Date: Thu Jun 28 18:21:49 2007 New Revision: 44606 Modified: pypy/dist/pypy/lang/scheme/TODO.txt pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: no arbitrary else statement for (if ...) Modified: pypy/dist/pypy/lang/scheme/TODO.txt ============================================================================== --- pypy/dist/pypy/lang/scheme/TODO.txt (original) +++ pypy/dist/pypy/lang/scheme/TODO.txt Thu Jun 28 18:21:49 2007 @@ -9,9 +9,6 @@ -+variables and execution context -- symbols - - global dict for symbols _obarray_ - + there is need to distinct identifier from symbol (define var 11) (symbol? var) -> #f @@ -23,6 +20,10 @@ Do next ------- +- symbols (should be done with next point) + - global dict for symbols _obarray_ +- (quote ) and ', not only symbols + - functions - implement key funcions (apply, reduce, mapcar and so on) Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Thu Jun 28 18:21:49 2007 @@ -194,7 +194,10 @@ def macro_if(ctx, lst): w_condition = lst.car w_then = lst.cdr.car - w_else = lst.cdr.cdr.car + if isinstance(lst.cdr.cdr, W_Nil): + w_else = W_Boolean(False) + else: + w_else = lst.cdr.cdr.car w_cond_val = w_condition.eval(ctx) if w_cond_val.to_boolean() is True: Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Thu Jun 28 18:21:49 2007 @@ -93,6 +93,10 @@ assert w_f.to_boolean() is False w_f = eval_expr(ctx, "(if 1 #f #t)") assert w_f.to_boolean() is False + w_f = eval_expr(ctx, "(if #t #t)") + assert w_f.to_boolean() is True + w_f = eval_expr(ctx, "(if #f #t)") + assert w_f.to_boolean() is False def test_if_evaluation(): ctx = ExecutionContext() From xoraxax at codespeak.net Thu Jun 28 23:12:24 2007 From: xoraxax at codespeak.net (xoraxax at codespeak.net) Date: Thu, 28 Jun 2007 23:12:24 +0200 (CEST) Subject: [pypy-svn] r44609 - pypy/dist/pypy/doc Message-ID: <20070628211224.6414A80D7@code0.codespeak.net> Author: xoraxax Date: Thu Jun 28 23:12:23 2007 New Revision: 44609 Modified: pypy/dist/pypy/doc/carbonpython.txt Log: Remove a "the" in carbonpython.txt Modified: pypy/dist/pypy/doc/carbonpython.txt ============================================================================== --- pypy/dist/pypy/doc/carbonpython.txt (original) +++ pypy/dist/pypy/doc/carbonpython.txt Thu Jun 28 23:12:23 2007 @@ -178,7 +178,7 @@ MyClass obj = new MyClass(); obj.__init__(x); -Note that this is needed only when calling RPython code from the +Note that this is needed only when calling RPython code from outside; the RPython compiler automatically calls ``__init__`` whenever an RPython class is instantiated. From jlg at codespeak.net Fri Jun 29 01:38:00 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Fri, 29 Jun 2007 01:38:00 +0200 (CEST) Subject: [pypy-svn] r44611 - pypy/dist/pypy/lang/scheme Message-ID: <20070628233800.86B9880D4@code0.codespeak.net> Author: jlg Date: Fri Jun 29 01:37:59 2007 New Revision: 44611 Modified: pypy/dist/pypy/lang/scheme/TODO.txt Log: very maeningful commit Modified: pypy/dist/pypy/lang/scheme/TODO.txt ============================================================================== --- pypy/dist/pypy/lang/scheme/TODO.txt (original) +++ pypy/dist/pypy/lang/scheme/TODO.txt Fri Jun 29 01:37:59 2007 @@ -1,21 +1,10 @@ Do now ------ -+ evaluate simple expressions like - (* 6 7) or even (+ 1 2 3 4) - + parsing is done by some shiny new Carl's thingy - W_xxx object like W_Fixnum should eval to itself despite context - = implement basic operations like + * / and so on - --+variables and execution context - -+ there is need to distinct identifier from symbol - (define var 11) - (symbol? var) -> #f - (symbol? 'var) -> #t - -- control structures - - boolean +- variables and execution context +- list operations: cons car cdr list +- comparison: = < > eq? eqv? +- lambdas! Do next ------- @@ -24,7 +13,6 @@ - global dict for symbols _obarray_ - (quote ) and ', not only symbols -- functions - implement key funcions (apply, reduce, mapcar and so on) From arigo at codespeak.net Fri Jun 29 11:20:21 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 29 Jun 2007 11:20:21 +0200 (CEST) Subject: [pypy-svn] r44617 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070629092021.8F384810B@code0.codespeak.net> Author: arigo Date: Fri Jun 29 11:20:21 2007 New Revision: 44617 Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt Log: Added myself. Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/people.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/people.txt Fri Jun 29 11:20:21 2007 @@ -19,6 +19,7 @@ Jakub Gustak 8/15th Hospitality Club :) Christian Tismer 8/16th Ratonda Centrum Hotels Simon Burton 8/15th +Armin Rigo 8/16th Comfort Vilnius ==================== ============== ======================= People on the following list were present at previous sprints: @@ -35,7 +36,6 @@ Georg Brandl ? ? Guido Wesdorp ? ? Carl Friedrich Bolz ? ? -Armin Rigo ? ? Holger Krekel ? ? Anders Lehmann ? ? Niklaus Haldimann ? ? From jlg at codespeak.net Fri Jun 29 23:11:45 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Fri, 29 Jun 2007 23:11:45 +0200 (CEST) Subject: [pypy-svn] r44633 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070629211145.EE238810E@code0.codespeak.net> Author: jlg Date: Fri Jun 29 23:11:45 2007 New Revision: 44633 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: cons car cdr works in simple cases Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Fri Jun 29 23:11:45 2007 @@ -209,18 +209,46 @@ def eval(self, ctx): return macro_if +def cons(ctx, lst): + w_car = lst.car.eval(ctx) + w_cdr = lst.cdr.car.eval(ctx) + return W_Pair(w_car, w_cdr) + +class Cons(W_Procedure): + def eval(self, ctx): + return cons + +def car(ctx, lst): + w_pair = lst.car.eval(ctx) + return w_pair.car + +class Car(W_Procedure): + def eval(self, ctx): + return car + +def cdr(ctx, lst): + w_pair = lst.car.eval(ctx) + return w_pair.cdr + +class Cdr(W_Procedure): + def eval(self, ctx): + return cdr + ###################################### # dict mapping operations to callables # callables must have 2 arguments # - ctx = execution context # - lst = list of arguments -####################################### +###################################### OPERATION_MAP = \ { '+': Add("+"), '*': Mul("*"), 'define': Define("define"), 'if': MacroIf("if"), + 'cons': Cons("cons"), + 'car': Car("car"), + 'cdr': Cdr("cdr"), } class ExecutionContext(object): Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Fri Jun 29 23:11:45 2007 @@ -112,3 +112,29 @@ assert ctx.get("then").to_boolean() is False assert ctx.get("else").to_boolean() is True +def test_cons_simple(): + w_pair = eval_noctx("(cons 1 2)") + assert isinstance(w_pair, W_Pair) + assert w_pair.car.to_number() == 1 + assert w_pair.cdr.to_number() == 2 + + w_pair = eval_noctx("(cons 1 (cons 2 3))") + assert isinstance(w_pair, W_Pair) + assert isinstance(w_pair.cdr, W_Pair) + assert w_pair.car.to_number() == 1 + assert w_pair.cdr.car.to_number() == 2 + assert w_pair.cdr.cdr.to_number() == 3 + +def test_car_simple(): + w_car = eval_noctx("(car (cons 1 2))") + assert w_car.to_number() == 1 + + w_cdr = eval_noctx("(cdr (cons 1 2))") + assert w_cdr.to_number() == 2 + + w_cadr = eval_noctx("(car (cdr (cons 1 (cons 2 3))))") + assert w_cadr.to_number() == 2 + + w_cddr = eval_noctx("(cdr (cdr (cons 1 (cons 2 3))))") + assert w_cddr.to_number() == 3 + From fijal at codespeak.net Sat Jun 30 13:14:20 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sat, 30 Jun 2007 13:14:20 +0200 (CEST) Subject: [pypy-svn] r44641 - pypy/extradoc/talk/ep2007 Message-ID: <20070630111420.3CF468095@code0.codespeak.net> Author: fijal Date: Sat Jun 30 13:14:18 2007 New Revision: 44641 Modified: pypy/extradoc/talk/ep2007/interpreter.txt pypy/extradoc/talk/ep2007/rpython.txt Log: A bit of update for talks. Modified: pypy/extradoc/talk/ep2007/interpreter.txt ============================================================================== --- pypy/extradoc/talk/ep2007/interpreter.txt (original) +++ pypy/extradoc/talk/ep2007/interpreter.txt Sat Jun 30 13:14:18 2007 @@ -13,9 +13,9 @@ * avoiding religious war... -* they give new dimensions to how you can use pypy +* they give new dimensions to how one can use python -* peak the feature set of your choice... +* pick the feature set of your choice... XXX crap @@ -44,25 +44,82 @@ * see also .NET TransparentProxy +XXX list-over-http demo +Lazy ad-hoc distribution +------------------------ +- transparent lazy access to remote objects +- internally uses RPC-like protocol +- remote objects are presented through transparent proxies +- access to remote tracebacks, frames, etc. work as if local! +XXX show +Orthogonal Persistence +-------------------------- +* persist Python objects "invisibly" +* interpose interception of changes to objects -* distribution +* implement your own custom persistence scheme (e.g. using ZODB) -* stackless +XXX some demo -* security (taint space) +Micro threading in PyPy +----------------------- -* thunk space +* stackless *transform* / micro-threads: -* persistance +* suspending/resuming computations -* JIT (unsure, will be on the previous talk) +* pickling/migration of computations -* pickling computations? +XXX show -* disclaimer (not ready for production use, etc) +* unlimited recursion + +* *composable* greenlets, tasklets, co-routines + +Taint Space +-------------------- + +* control of information data flow: + + - label sensitive data + - avoid sensitive information leaks + - explicit primitive to declassify + +* easily implemented as an object space around + the standard one securing all operations + on objects + +Taint Space diagram +--------------------- + +.. raw:: html + +
+ +.. image:: interpreterarch.png + +* interactive prompt demo + +Thunk object space +------------------ + +* lazy computations + +* easy hack (200 loc, including demo) + +Disclaimer +---------- + +* pypy features are not ready for production use + +* although not because they're buggy + +* lack of modules + +XXX more? Modified: pypy/extradoc/talk/ep2007/rpython.txt ============================================================================== --- pypy/extradoc/talk/ep2007/rpython.txt (original) +++ pypy/extradoc/talk/ep2007/rpython.txt Sat Jun 30 13:14:18 2007 @@ -1,7 +1,7 @@ -========================================== -RPython aka C and C# considered harmful -========================================== +======================================================= +RPython: need for speed aka C and C# considered harmful +======================================================= :Authors: Antonio Cuni (xxx), Maciej Fijalkowski (merlinux GmbH) :Place: Europython 2007 @@ -10,7 +10,7 @@ Why invent new language? ------------------------ -* Grown as side effect of the pypy project +* Grown as a side effect of the pypy project * Python is too slow for some purposes @@ -27,7 +27,7 @@ * Restricted subset * Constructed from live objects - initialization - is fully done in Python + is done in Python * XXX more? @@ -36,6 +36,8 @@ * Full type inference - you cannot mix incompatible types +* Polymorphic collections (ie list of ints) + * No dynamic stuff: switch class, add/remove methods, etc. * Java-like object model @@ -44,18 +46,9 @@ * No frames and such stuff -XXX crappy examples expand or delete (probably would be -XXX better to just say few words - -* [1, 2, 3, 4] is ok, ['sss', 2] not - -* (1, 'xx') is ok, but cannot be mixed with ('xx', 1) - Example of use case ------------------- -XXX write down some simple example for that one - * Write code * test/debug on top of CPython @@ -69,6 +62,20 @@ XXXX should we really mention that? +Modules restrictions +-------------------- + +* few modules work + +* they have different, more static API (ie open()) + +* all modules might be used when initializing + +Few more words about file API +----------------------------- + +XXX really? + RPython - why you wouldn't like to use it ----------------------------------------- @@ -90,7 +97,7 @@ Writing standalone C programs ----------------------------- -XXX explain +XXX explain writing targets Writing CPython extensions --------------------------- @@ -113,11 +120,3 @@ XXX fijal, feel free to fill in -* creating .NET libraries for C#/IronPython (in the future also for Java/Jython) - -* JS backend - few examples, bnb etc, play1 - -* (optional) common problems with RPython - -* ... - From fijal at codespeak.net Sat Jun 30 13:15:01 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sat, 30 Jun 2007 13:15:01 +0200 (CEST) Subject: [pypy-svn] r44642 - pypy/dist/pypy/translator/goal Message-ID: <20070630111501.7D7958095@code0.codespeak.net> Author: fijal Date: Sat Jun 30 13:15:01 2007 New Revision: 44642 Modified: pypy/dist/pypy/translator/goal/targetpypystandalone.py Log: seems to have never worked. Modified: pypy/dist/pypy/translator/goal/targetpypystandalone.py ============================================================================== --- pypy/dist/pypy/translator/goal/targetpypystandalone.py (original) +++ pypy/dist/pypy/translator/goal/targetpypystandalone.py Sat Jun 30 13:15:01 2007 @@ -135,8 +135,9 @@ if config.translation.backend == "cli": config.objspace.usemodules.clr = True - elif config.objspace.usemodules.clr: - config.translation.backend == "clr" + # XXX did it ever work? + #elif config.objspace.usemodules.clr: + # config.translation.backend == "cli" config.objspace.nofaking = True config.objspace.compiler = "ast" From fijal at codespeak.net Sat Jun 30 13:15:48 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sat, 30 Jun 2007 13:15:48 +0200 (CEST) Subject: [pypy-svn] r44643 - pypy/dist/pypy/tool Message-ID: <20070630111548.CFADE8095@code0.codespeak.net> Author: fijal Date: Sat Jun 30 13:15:48 2007 New Revision: 44643 Modified: pypy/dist/pypy/tool/udir.py Log: kill long-time dead code Modified: pypy/dist/pypy/tool/udir.py ============================================================================== --- pypy/dist/pypy/tool/udir.py (original) +++ pypy/dist/pypy/tool/udir.py Sat Jun 30 13:15:48 2007 @@ -10,23 +10,3 @@ from py.path import local udir = local.make_numbered_dir(prefix='usession-', keep=3) - -# try: -# username = os.environ['USER'] #linux, et al -# except: -# try: -# username = os.environ['USERNAME'] #windows -# except: -# username = 'current' - -# import os -# src = str(udir) -# dest = src[:src.rfind('-')] + '-' + username -# try: -# os.unlink(dest) -# except: -# pass -# try: -# os.symlink(src, dest) -# except: -# pass From fijal at codespeak.net Sat Jun 30 13:16:49 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sat, 30 Jun 2007 13:16:49 +0200 (CEST) Subject: [pypy-svn] r44644 - in pypy/dist/pypy/rpython/module: . test Message-ID: <20070630111649.8E9E480EF@code0.codespeak.net> Author: fijal Date: Sat Jun 30 13:16:49 2007 New Revision: 44644 Modified: pypy/dist/pypy/rpython/module/ll_os.py pypy/dist/pypy/rpython/module/test/test_ll_os.py Log: add os.w_*, rpython level. Modified: pypy/dist/pypy/rpython/module/ll_os.py ============================================================================== --- pypy/dist/pypy/rpython/module/ll_os.py (original) +++ pypy/dist/pypy/rpython/module/ll_os.py Sat Jun 30 13:16:49 2007 @@ -136,22 +136,43 @@ register_external(os.open, [str, int, int], int, "ll_os.ll_os_open", llimpl=os_open_lltypeimpl, oofakeimpl=os_open_oofakeimpl) -# ------------------------------- os.WIFSIGNALED ------------------------ -# XXX this needs to be generated automatically for all os.W* +# ------------------------------- os.* ---------------------------------- -if hasattr(os, 'WIFSIGNALED'): - def fake_WIFSIGNALED(status): - return int(os.WIFSIGNALED(status)) - - os_WIFSIGNALED = rffi.llexternal('WIFSIGNALED', [lltype.Signed], - lltype.Signed, - _callable=fake_WIFSIGNALED) - - def WIFSIGNALED_lltypeimpl(status): - return bool(os_WIFSIGNALED(status)) - - register_external(os.WIFSIGNALED, [int], bool, "ll_os.WIFSIGNALED", - llimpl=WIFSIGNALED_lltypeimpl) +w_star = ['WCOREDUMP', 'WIFCONTINUED', 'WIFSTOPPED', + 'WIFSIGNALED', 'WIFEXITED', 'WEXITSTATUS', + 'WSTOPSIG', 'WTERMSIG'] +# last 3 are returning int +w_star_returning_int = dict.fromkeys(w_star[-3:]) + +def declare_new_w_star(name): + """ stupid workaround for the python late-binding + 'feature' + """ + def fake(status): + return int(getattr(os, name)(status)) + fake.func_name = 'fake_' + name + + os_c_func = rffi.llexternal(name, [lltype.Signed], + lltype.Signed, + _callable=fake, + includes=["sys/wait.h", "sys/types.h"]) + + if name in w_star_returning_int: + def lltypeimpl(status): + return os_c_func(status) + resulttype = int + else: + def lltypeimpl(status): + return bool(os_c_func(status)) + resulttype = bool + lltypeimpl.func_name = name + '_lltypeimpl' + register_external(getattr(os, name), [int], resulttype, "ll_os."+name, + llimpl=lltypeimpl) + + +for name in w_star: + if hasattr(os, name): + declare_new_w_star(name) # ------------------------------- os.ttyname ---------------------------- Modified: pypy/dist/pypy/rpython/module/test/test_ll_os.py ============================================================================== --- pypy/dist/pypy/rpython/module/test/test_ll_os.py (original) +++ pypy/dist/pypy/rpython/module/test/test_ll_os.py Sat Jun 30 13:16:49 2007 @@ -102,13 +102,15 @@ compared_with.sort() assert result == compared_with -def test_os_wifsignaled(): - def fun(s): - return os.WIFSIGNALED(s) +def test_os_wstar(): + from pypy.rpython.module.ll_os import w_star + for name in w_star: + def fun(s): + return getattr(os, name)(s) - fn = compile(fun, [int]) - assert fn(0) == False - assert fn(1) == True + fn = compile(fun, [int]) + for value in [0, 1, 127, 128, 255]: + assert fn(value) == fun(value) class ExpectTestOs: def setup_class(cls): From fijal at codespeak.net Sat Jun 30 13:17:09 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Sat, 30 Jun 2007 13:17:09 +0200 (CEST) Subject: [pypy-svn] r44645 - in pypy/dist/pypy/module/posix: . test Message-ID: <20070630111709.C7BAE80EF@code0.codespeak.net> Author: fijal Date: Sat Jun 30 13:17:07 2007 New Revision: 44645 Modified: pypy/dist/pypy/module/posix/__init__.py pypy/dist/pypy/module/posix/interp_posix.py pypy/dist/pypy/module/posix/test/test_posix2.py Log: Add os.w_*, app level Modified: pypy/dist/pypy/module/posix/__init__.py ============================================================================== --- pypy/dist/pypy/module/posix/__init__.py (original) +++ pypy/dist/pypy/module/posix/__init__.py Sat Jun 30 13:17:07 2007 @@ -1,5 +1,6 @@ # Package initialisation from pypy.interpreter.mixedmodule import MixedModule +from pypy.rpython.module.ll_os import w_star #Turned off for now. posix must support targets without ctypes. #from pypy.module.posix import ctypes_posix @@ -52,7 +53,6 @@ #'getuid' : 'interp_posix.getuid', #'geteuid' : 'interp_posix.geteuid', 'utime' : 'interp_posix.utime', - 'WIFSIGNALED' : 'interp_posix.WIFSIGNALED', } if hasattr(os, 'ftruncate'): interpleveldefs['ftruncate'] = 'interp_posix.ftruncate' @@ -83,6 +83,9 @@ # interpleveldefs['uname'] = 'interp_posix.uname' if hasattr(os, 'ttyname'): interpleveldefs['ttyname'] = 'interp_posix.ttyname' + for name in w_star: + if hasattr(os, name): + interpleveldefs[name] = 'interp_posix.' + name def setup_after_space_initialization(self): """NOT_RPYTHON""" Modified: pypy/dist/pypy/module/posix/interp_posix.py ============================================================================== --- pypy/dist/pypy/module/posix/interp_posix.py (original) +++ pypy/dist/pypy/module/posix/interp_posix.py Sat Jun 30 13:17:07 2007 @@ -2,6 +2,7 @@ from pypy.rlib.rarithmetic import intmask from pypy.rlib import ros from pypy.interpreter.error import OperationError, wrap_oserror +from pypy.rpython.module.ll_os import w_star, w_star_returning_int import os @@ -498,9 +499,20 @@ raise OperationError(space.w_TypeError, space.wrap(msg)) utime.unwrap_spec = [ObjSpace, str, W_Root] -def WIFSIGNALED(space, status): - return space.newbool(os.WIFSIGNALED(status)) -WIFSIGNALED.unwrap_spec = [ObjSpace, int] +def declare_new_w_star(name): + if name in w_star_returning_int: + def WSTAR(space, status): + return space.wrap(getattr(os, name)(status)) + else: + def WSTAR(space, status): + return space.newbool(getattr(os, name)(status)) + WSTAR.unwrap_spec = [ObjSpace, int] + WSTAR.func_name = name + return WSTAR + +for name in w_star: + func = declare_new_w_star(name) + globals()[name] = func def ttyname(space, fd): try: Modified: pypy/dist/pypy/module/posix/test/test_posix2.py ============================================================================== --- pypy/dist/pypy/module/posix/test/test_posix2.py (original) +++ pypy/dist/pypy/module/posix/test/test_posix2.py Sat Jun 30 13:17:07 2007 @@ -2,6 +2,7 @@ from pypy.tool.udir import udir from pypy.conftest import gettestobjspace from pypy.tool.autopath import pypydir +from pypy.rpython.module.ll_os import w_star import os import py import sys @@ -195,6 +196,19 @@ raises(TypeError, "os.utime('xxx', 3)") raises(OSError, "os.utime('somefilewhichihopewouldneverappearhere', None)") + for name in w_star: + if hasattr(os, name): + values = [0, 1, 127, 128, 255] + code = py.code.Source(""" + def test_wstar(self): + os = self.posix + %s + """ % "\n ".join(["assert os.%s(%d) == %d" % (name, value, + getattr(os, name)(value)) for value in values])) + d = {} + exec code.compile() in d + locals()['test_' + name] = d['test_wstar'] + def test_wifsignaled(self): os = self.posix assert os.WIFSIGNALED(0) == False