From rxe at codespeak.net Sat Jul 1 00:01:50 2006 From: rxe at codespeak.net (rxe at codespeak.net) Date: Sat, 1 Jul 2006 00:01:50 +0200 (CEST) Subject: [pypy-svn] r29541 - in pypy/dist/pypy/translator/llvm: . test Message-ID: <20060630220150.A1AE910075@code0.codespeak.net> Author: rxe Date: Sat Jul 1 00:01:47 2006 New Revision: 29541 Modified: pypy/dist/pypy/translator/llvm/arraynode.py pypy/dist/pypy/translator/llvm/structnode.py pypy/dist/pypy/translator/llvm/test/test_lltype.py Log: y Modified: pypy/dist/pypy/translator/llvm/arraynode.py ============================================================================== --- pypy/dist/pypy/translator/llvm/arraynode.py (original) +++ pypy/dist/pypy/translator/llvm/arraynode.py Sat Jul 1 00:01:47 2006 @@ -86,7 +86,6 @@ self.db.prepare_constant(self.arraytype, item) p, c = lltype.parentlink(self.value) - p, c = lltype.parentlink(self.value) if p is not None: self.db.prepare_constant(lltype.typeOf(p), p) @@ -109,18 +108,21 @@ def get_ref(self): typeval = self.db.repr_type(lltype.typeOf(self.value)) + p, c = lltype.parentlink(self.value) + if p is None: + ref = self.ref + else: + ref = self.db.get_childref(p, c) + ref = "cast(%s* %s to %s*)" % (self.get_typerepr(), - self.ref, + ref, typeval) - - p, c = lltype.parentlink(self.value) - assert p is None, "child arrays are NOT needed by rtyper" return ref def get_pbcref(self, toptr): ref = self.ref p, c = lltype.parentlink(self.value) - assert p is None, "child arrays are NOT needed by rtyper" + assert p is None, "child PBC arrays are NOT needed by rtyper" fromptr = "%s*" % self.get_typerepr() ref = "cast(%s %s to %s)" % (fromptr, ref, toptr) Modified: pypy/dist/pypy/translator/llvm/structnode.py ============================================================================== --- pypy/dist/pypy/translator/llvm/structnode.py (original) +++ pypy/dist/pypy/translator/llvm/structnode.py Sat Jul 1 00:01:47 2006 @@ -209,24 +209,37 @@ types_repr.append(self._get_lastnode().get_typerepr()) result = "{%s}" % ", ".join(types_repr) self._get_typerepr_cache = result - return result - + return result + + def get_childref(self, index): + pos = 0 + found = False + for name in self.structtype._names_without_voids(): + if name == index: + found = True + break + pos += 1 + + ref = "getelementptr(%s* %s, int 0, uint %s)" %( + self.get_typerepr(), + super(StructVarsizeNode, self).get_ref(), + pos) + + return ref + def get_ref(self): - if self._get_ref_cache: - return self._get_ref_cache ref = super(StructVarsizeNode, self).get_ref() typeval = self.db.repr_type(lltype.typeOf(self.value)) ref = "cast(%s* %s to %s*)" % (self.get_typerepr(), ref, typeval) - self._get_ref_cache = ref return ref def get_pbcref(self, toptr): """ Returns a reference as used per pbc. """ ref = self.ref p, c = lltype.parentlink(self.value) - assert p is None, "child arrays are NOT needed by rtyper" + assert p is None, "child varsize struct are NOT needed by rtyper" fromptr = "%s*" % self.get_typerepr() refptr = "getelementptr(%s %s, int 0)" % (fromptr, ref) ref = "cast(%s %s to %s)" % (fromptr, refptr, toptr) 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 Sat Jul 1 00:01:47 2006 @@ -172,7 +172,7 @@ return s.aptr[1] - a[0] f = compile_function(array_constant, []) assert f() == array_constant() - + def test_struct_array2(): A = lltype.Array(lltype.Signed) STEST = lltype.GcStruct('test', ('a', lltype.Signed), ('b', A)) @@ -180,6 +180,7 @@ s.a = 41 s.b[0] = 100 s.b[1] = 101 + def array_constant(): return s.b[1] - s.b[0] + s.a f = compile_function(array_constant, []) From pedronis at codespeak.net Sat Jul 1 10:04:00 2006 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Sat, 1 Jul 2006 10:04:00 +0200 (CEST) Subject: [pypy-svn] r29544 - pypy/dist/pypy/objspace/std/test Message-ID: <20060701080400.B293B10077@code0.codespeak.net> Author: pedronis Date: Sat Jul 1 10:03:57 2006 New Revision: 29544 Modified: pypy/dist/pypy/objspace/std/test/test_userobject.py Log: add a test to make sure that overriding of methods in instances works in PyPy as expected. Modified: pypy/dist/pypy/objspace/std/test/test_userobject.py ============================================================================== --- pypy/dist/pypy/objspace/std/test/test_userobject.py (original) +++ pypy/dist/pypy/objspace/std/test/test_userobject.py Sat Jul 1 10:03:57 2006 @@ -175,3 +175,13 @@ assert 'NameError' in line2 assert 'yaddadlaouti' in line2 assert 'ignored' in line2 + + def test_instance_overrides_meth(self): + class C(object): + def m(self): + return "class" + assert C().m() == 'class' + c = C() + c.m = lambda: "instance" + res = c.m() + assert res == "instance" From antocuni at codespeak.net Sat Jul 1 11:00:48 2006 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 1 Jul 2006 11:00:48 +0200 (CEST) Subject: [pypy-svn] r29545 - pypy/dist/pypy/rpython/ootypesystem/test Message-ID: <20060701090048.03FCC1007F@code0.codespeak.net> Author: antocuni Date: Sat Jul 1 11:00:44 2006 New Revision: 29545 Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_oorecord.py Log: Remove this test, because _add_fields is not supposed to be part of the public interface. Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_oorecord.py ============================================================================== --- pypy/dist/pypy/rpython/ootypesystem/test/test_oorecord.py (original) +++ pypy/dist/pypy/rpython/ootypesystem/test/test_oorecord.py Sat Jul 1 11:00:44 2006 @@ -38,14 +38,3 @@ t.a = 1 t.b = 2 assert ooidentityhash(t) != ooidentityhash(t2) - -import py -def test_hash(): - py.test.skip("LowLevelType.__hash__ bug waiting to be fixed") - T1 = Record({"item0": Signed, "item1": Signed}) - T2 = Record({"item0": Signed}) - - hash(T2) # compute the hash, it will stored in __cached_hash - T2._add_fields({"item1": Signed}) # modify the object - assert T1 == T2 - assert hash(T1) == hash(T2) From arigo at codespeak.net Sat Jul 1 11:04:59 2006 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sat, 1 Jul 2006 11:04:59 +0200 (CEST) Subject: [pypy-svn] r29546 - pypy/dist/pypy/rpython/ootypesystem Message-ID: <20060701090459.7D6701007F@code0.codespeak.net> Author: arigo Date: Sat Jul 1 11:04:58 2006 New Revision: 29546 Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py Log: ...and remove the _add_fields() methods from class Record, to avoid temptation. Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py ============================================================================== --- pypy/dist/pypy/rpython/ootypesystem/ootype.py (original) +++ pypy/dist/pypy/rpython/ootypesystem/ootype.py Sat Jul 1 11:04:58 2006 @@ -222,14 +222,9 @@ def __init__(self, fields): self._fields = frozendict() - self._add_fields(fields) - self._null = _null_record(self) - - def _add_fields(self, fields): - fields.copy() for name, ITEMTYPE in fields.items(): - fields[name] = ITEMTYPE, ITEMTYPE._defl() - self._fields.update(fields) + self._fields[name] = ITEMTYPE, ITEMTYPE._defl() + self._null = _null_record(self) def _defl(self): return self._null From antocuni at codespeak.net Sat Jul 1 11:05:37 2006 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 1 Jul 2006 11:05:37 +0200 (CEST) Subject: [pypy-svn] r29547 - pypy/dist/pypy/translator/cli/test Message-ID: <20060701090537.ADBE71007F@code0.codespeak.net> Author: antocuni Date: Sat Jul 1 11:05:33 2006 New Revision: 29547 Modified: pypy/dist/pypy/translator/cli/test/test_rpython.py Log: These tests don't longer fail. Modified: pypy/dist/pypy/translator/cli/test/test_rpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/test/test_rpython.py (original) +++ pypy/dist/pypy/translator/cli/test/test_rpython.py Sat Jul 1 11:05:33 2006 @@ -38,18 +38,10 @@ class TestCliList(CliTest, BaseTestRlist): def test_recursive(self): py.test.skip("CLI doesn't support recursive lists") - - def test_list_comparestr(self): - py.test.skip("CLI doesn't support string, yet") - - def test_not_a_char_list_after_all(self): - py.test.skip("CLI doesn't support string, yet") def test_list_str(self): - py.test.skip("CLI doesn't support string, yet") + py.test.skip("CLI doesn't support ll_int_str, yet") - def test_inst_list(self): - py.test.skip("CLI doesn't support string, yet") class TestCliTuple(CliTest, BaseTestRtuple): From antocuni at codespeak.net Sat Jul 1 11:13:47 2006 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 1 Jul 2006 11:13:47 +0200 (CEST) Subject: [pypy-svn] r29548 - pypy/dist/pypy/rpython/ootypesystem Message-ID: <20060701091347.9C3C610074@code0.codespeak.net> Author: antocuni Date: Sat Jul 1 11:13:38 2006 New Revision: 29548 Modified: pypy/dist/pypy/rpython/ootypesystem/ll_str.py Log: ll_int_str is not a suggested_primitive in ootypesystem. Modified: pypy/dist/pypy/rpython/ootypesystem/ll_str.py ============================================================================== --- pypy/dist/pypy/rpython/ootypesystem/ll_str.py (original) +++ pypy/dist/pypy/rpython/ootypesystem/ll_str.py Sat Jul 1 11:13:38 2006 @@ -5,7 +5,6 @@ def ll_int_str(repr, i): return ll_int2dec(i) -ll_int_str.suggested_primitive = True def ll_int2dec(i): return oostring(i, const(10)) From antocuni at codespeak.net Sat Jul 1 11:17:01 2006 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 1 Jul 2006 11:17:01 +0200 (CEST) Subject: [pypy-svn] r29549 - pypy/dist/pypy/translator/cli/test Message-ID: <20060701091701.A52D810074@code0.codespeak.net> Author: antocuni Date: Sat Jul 1 11:16:53 2006 New Revision: 29549 Modified: pypy/dist/pypy/translator/cli/test/test_rpython.py Log: This test no longer fails. Alternative message: "more ootypesystem tests" (cit.) Modified: pypy/dist/pypy/translator/cli/test/test_rpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/test/test_rpython.py (original) +++ pypy/dist/pypy/translator/cli/test/test_rpython.py Sat Jul 1 11:16:53 2006 @@ -39,10 +39,6 @@ def test_recursive(self): py.test.skip("CLI doesn't support recursive lists") - def test_list_str(self): - py.test.skip("CLI doesn't support ll_int_str, yet") - - class TestCliTuple(CliTest, BaseTestRtuple): def test_constant_tuple_contains(self): From antocuni at codespeak.net Sat Jul 1 11:45:28 2006 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 1 Jul 2006 11:45:28 +0200 (CEST) Subject: [pypy-svn] r29550 - in pypy/dist/pypy/translator/cli: src test Message-ID: <20060701094528.C644F10077@code0.codespeak.net> Author: antocuni Date: Sat Jul 1 11:45:16 2006 New Revision: 29550 Modified: pypy/dist/pypy/translator/cli/src/pypylib.cs pypy/dist/pypy/translator/cli/test/test_rpython.py Log: Fix the implementation of string.ll_rfind and string.ll_rfind_char. Don't skip the relevant tests. Modified: pypy/dist/pypy/translator/cli/src/pypylib.cs ============================================================================== --- pypy/dist/pypy/translator/cli/src/pypylib.cs (original) +++ pypy/dist/pypy/translator/cli/src/pypylib.cs Sat Jul 1 11:45:16 2006 @@ -174,13 +174,12 @@ public static int ll_rfind(string s1, string s2, int start, int stop) { - // XXX: it doesn't work properly if (stop > s1.Length) stop = s1.Length; int count = stop-start; if (start > s1.Length) return -1; - return s1.LastIndexOf(s2, start, count); + return s1.LastIndexOf(s2, stop-1, count); } public static int ll_find_char(string s, char ch, int start, int stop) @@ -196,7 +195,9 @@ if (stop > s.Length) stop = s.Length; int count=stop-start; - return s.IndexOf(ch, start, count); + if (start > s.Length) + return -1; + return s.LastIndexOf(ch, stop-1, count); } public static string ll_strip(string s, char ch, bool left, bool right) Modified: pypy/dist/pypy/translator/cli/test/test_rpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/test/test_rpython.py (original) +++ pypy/dist/pypy/translator/cli/test/test_rpython.py Sat Jul 1 11:45:16 2006 @@ -69,11 +69,6 @@ test_unichar_ord = test_unichar_const test_unichar_hash = test_unichar_const - def test_rfind(self): - py.test.skip("CLI doens't support rfind(), yey") - test_rfind_empty_string = test_rfind - test_find_char = test_rfind - def test_upper(self): py.test.skip("CLI doens't support backquotes inside string literals") test_lower = test_upper From pedronis at codespeak.net Sat Jul 1 13:06:55 2006 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Sat, 1 Jul 2006 13:06:55 +0200 (CEST) Subject: [pypy-svn] r29556 - pypy/dist/pypy/jit/hintannotator Message-ID: <20060701110655.5B68F10078@code0.codespeak.net> Author: pedronis Date: Sat Jul 1 13:06:53 2006 New Revision: 29556 Modified: pypy/dist/pypy/jit/hintannotator/bookkeeper.py pypy/dist/pypy/jit/hintannotator/model.py Log: (arre, arigo, pedronis) move the logic to pick a specialized version of a function depending on the color of the arguments as an helper get_graph_for_call on the hint-bookkeeper, to be used by the timeshifter to deal with calls. Modified: pypy/dist/pypy/jit/hintannotator/bookkeeper.py ============================================================================== --- pypy/dist/pypy/jit/hintannotator/bookkeeper.py (original) +++ pypy/dist/pypy/jit/hintannotator/bookkeeper.py Sat Jul 1 13:06:53 2006 @@ -115,6 +115,33 @@ def warning(self, msg): return self.annotator.warning(msg) + def get_graph_for_call(self, graph, fixed, args_hs): + # this can modify args_hs in-place! + from pypy.jit.hintannotator.model import SomeLLAbstractConstant + desc = self.getdesc(graph) + key = None + alt_name = None + if fixed: + key = 'fixed' + alt_name = graph.name + '_HFixed' + else: + key = [] + specialize = False + for i, arg_hs in enumerate(args_hs): + if isinstance(arg_hs, SomeLLAbstractConstant) and arg_hs.eager_concrete: + key.append('E') + specialize = True + else: + key.append('x') + if specialize: + key = ''.join(key) + alt_name = graph.name + '_H'+key + else: + key = None + + graph = desc.specialize(args_hs, key=key, alt_name=alt_name) + return graph + # get current bookkeeper def getbookkeeper(): Modified: pypy/dist/pypy/jit/hintannotator/model.py ============================================================================== --- pypy/dist/pypy/jit/hintannotator/model.py (original) +++ pypy/dist/pypy/jit/hintannotator/model.py Sat Jul 1 13:06:53 2006 @@ -228,29 +228,10 @@ # normal call if not hasattr(fnobj, 'graph'): raise NotImplementedError("XXX call to externals or primitives") - desc = bookkeeper.getdesc(fnobj.graph) - key = None - alt_name = None - if bookkeeper.myorigin().read_fixed(): - key = 'fixed' - alt_name = fnobj.graph.name + '_HFixed' - else: - key = [] - specialize = False - for i, arg_hs in enumerate(args_hs): - if isinstance(arg_hs, SomeLLAbstractConstant) and arg_hs.eager_concrete: - key.append('E') - specialize = True - else: - key.append('x') - if specialize: - key = ''.join(key) - alt_name = fnobj.graph.name + '_H'+key - else: - key = None - + input_args_hs = list(args_hs) - graph = desc.specialize(input_args_hs, key=key, alt_name=alt_name) + fixed = bookkeeper.myorigin().read_fixed() + graph = bookkeeper.get_graph_for_call(fnobj.graph, fixed, input_args_hs) # propagate fixing of arguments in the function to the caller for inp_arg_hs, arg_hs in zip(input_args_hs, args_hs): @@ -273,7 +254,7 @@ [o] = hs_inputarg.origins.keys() if o in hs_res.origins: deps_hs.append(hs_arg) - if key == 'fixed': + if fixed: deps_hs.append(hs_res) hs_res = reorigin(hs_res, *deps_hs) From arigo at codespeak.net Sat Jul 1 13:15:00 2006 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sat, 1 Jul 2006 13:15:00 +0200 (CEST) Subject: [pypy-svn] r29557 - pypy/dist/pypy/translator/backendopt Message-ID: <20060701111500.07D7710078@code0.codespeak.net> Author: arigo Date: Sat Jul 1 13:14:59 2006 New Revision: 29557 Modified: pypy/dist/pypy/translator/backendopt/constfold.py Log: Fix for lltypesystem/test/test_rtagged. Someone please kill keepalives. Modified: pypy/dist/pypy/translator/backendopt/constfold.py ============================================================================== --- pypy/dist/pypy/translator/backendopt/constfold.py (original) +++ pypy/dist/pypy/translator/backendopt/constfold.py Sat Jul 1 13:14:59 2006 @@ -115,23 +115,34 @@ n = len(block.operations) if block.exitswitch == c_last_exception: n -= 1 - if folded_count < n: - nextop = block.operations[folded_count] + # is the next, non-folded operation an indirect_call? + m = folded_count + while m < n and block.operations[m].opname == 'keepalive': + m += 1 + if m < n: + nextop = block.operations[m] if nextop.opname == 'indirect_call' and nextop.args[0] in constants: # indirect_call -> direct_call callargs = [constants[nextop.args[0]]] constants1 = constants.copy() complete_constants(link, constants1) + newkeepalives = [] + for i in range(folded_count, m): + [v] = block.operations[i].args + v = constants1.get(v, v) + v_void = Variable() + v_void.concretetype = lltype.Void + newkeepalives.append(SpaceOperation('keepalive', [v], v_void)) for v in nextop.args[1:-1]: callargs.append(constants1.get(v, v)) v_result = Variable(nextop.result) v_result.concretetype = nextop.result.concretetype constants[nextop.result] = v_result callop = SpaceOperation('direct_call', callargs, v_result) - newblock = insert_empty_block(None, link, [callop]) + newblock = insert_empty_block(None, link, newkeepalives + [callop]) [link] = newblock.exits assert link.target is block - folded_count += 1 + folded_count = m+1 if folded_count > 0: splits = splitblocks.setdefault(block, []) From arigo at codespeak.net Sat Jul 1 13:16:01 2006 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sat, 1 Jul 2006 13:16:01 +0200 (CEST) Subject: [pypy-svn] r29558 - pypy/dist/pypy/objspace/flow/test Message-ID: <20060701111601.3769110078@code0.codespeak.net> Author: arigo Date: Sat Jul 1 13:16:00 2006 New Revision: 29558 Modified: pypy/dist/pypy/objspace/flow/test/test_picklegraph.py Log: Skip this. Modified: pypy/dist/pypy/objspace/flow/test/test_picklegraph.py ============================================================================== --- pypy/dist/pypy/objspace/flow/test/test_picklegraph.py (original) +++ pypy/dist/pypy/objspace/flow/test/test_picklegraph.py Sat Jul 1 13:16:00 2006 @@ -4,6 +4,9 @@ import pickle +import py; py.test.skip("pickling graphs not really used") + + def test_pickle_block(): # does not raise s = pickle.dumps(test_model.graph.startblock) From antocuni at codespeak.net Sat Jul 1 14:47:44 2006 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 1 Jul 2006 14:47:44 +0200 (CEST) Subject: [pypy-svn] r29559 - in pypy/dist/pypy/translator/cli: . src test Message-ID: <20060701124744.3554E10079@code0.codespeak.net> Author: antocuni Date: Sat Jul 1 14:47:36 2006 New Revision: 29559 Modified: pypy/dist/pypy/translator/cli/cts.py pypy/dist/pypy/translator/cli/database.py pypy/dist/pypy/translator/cli/src/pypylib.cs pypy/dist/pypy/translator/cli/test/test_rpython.py Log: - Added support for dict constants. - Added support for dict whose VALUETYPE is Void - Don't skip two tests that no longer fail. Modified: pypy/dist/pypy/translator/cli/cts.py ============================================================================== --- pypy/dist/pypy/translator/cli/cts.py (original) +++ pypy/dist/pypy/translator/cli/cts.py Sat Jul 1 14:47:36 2006 @@ -17,6 +17,7 @@ PYPY_LIST = '[pypylib]pypy.runtime.List`1<%s>' PYPY_LIST_OF_VOID = '[pypylib]pypy.runtime.ListOfVoid' PYPY_DICT = '[pypylib]pypy.runtime.Dict`2<%s, %s>' +PYPY_DICT_OF_VOID = '[pypylib]pypy.runtime.DictOfVoid`1<%s>' PYPY_DICT_ITEMS_ITERATOR = '[pypylib]pypy.runtime.DictItemsIterator`2<%s, %s>' PYPY_STRING_BUILDER = '[pypylib]pypy.runtime.StringBuilder' @@ -98,6 +99,8 @@ elif isinstance(t, ootype.Dict): key_type = self.lltype_to_cts(t._KEYTYPE) value_type = self.lltype_to_cts(t._VALUETYPE) + if value_type == 'void': # special case: Dict of Void + return self.__class(PYPY_DICT_OF_VOID % key_type, include_class) return self.__class(PYPY_DICT % (key_type, value_type), include_class) elif isinstance(t, ootype.DictItemsIterator): key_type = self.lltype_to_cts(t._KEYTYPE) Modified: pypy/dist/pypy/translator/cli/database.py ============================================================================== --- pypy/dist/pypy/translator/cli/database.py (original) +++ pypy/dist/pypy/translator/cli/database.py Sat Jul 1 14:47:36 2006 @@ -1,4 +1,4 @@ -from pypy.translator.cli.cts import CTS, PYPY_LIST_OF_VOID +from pypy.translator.cli.cts import CTS, PYPY_LIST_OF_VOID, PYPY_DICT_OF_VOID from pypy.translator.cli.function import Function from pypy.translator.cli.class_ import Class from pypy.translator.cli.record import Record @@ -180,6 +180,8 @@ return StaticMethodConst(db, value, count) elif isinstance(value, ootype._class): return ClassConst(db, value, count) + elif isinstance(value, ootype._dict): + return DictConst(db, value, count) else: assert False, 'Unknown constant: %s' % value make = staticmethod(make) @@ -366,6 +368,60 @@ ilasm.call_method(meth, False) +class DictConst(AbstractConst): + def __init__(self, db, dict_, count): + self.db = db + self.cts = CTS(db) + self.dict = dict_ + self.name = 'DICT__%d' % count + + def __hash__(self): + return hash(self.dict) + + def __eq__(self, other): + return self.dict == other.dict + + def get_type(self, include_class=True): + return self.cts.lltype_to_cts(self.dict._TYPE, include_class) + + def init(self, ilasm): + if not self.dict: # it is a null dict + ilasm.opcode('ldnull') + return + + class_name = self.get_type(False) + KEYTYPE = self.dict._TYPE._KEYTYPE + keytype = self.cts.lltype_to_cts(KEYTYPE) + keytype_T = self.cts.lltype_to_cts(self.dict._TYPE.KEYTYPE_T) + + VALUETYPE = self.dict._TYPE._VALUETYPE + valuetype = self.cts.lltype_to_cts(VALUETYPE) + valuetype_T = self.cts.lltype_to_cts(self.dict._TYPE.VALUETYPE_T) + + ilasm.new('instance void class %s::.ctor()' % class_name) + + if KEYTYPE is ootype.Void: + assert False, "gencli doesn't support dict with void keys" + + # special case: dict of void, ignore the values + if VALUETYPE is ootype.Void: + class_name = PYPY_DICT_OF_VOID % keytype + for key in self.dict._dict: + ilasm.opcode('dup') + AbstractConst.load(self.db, KEYTYPE, key, ilasm) + meth = 'void class %s::ll_set(%s)' % (class_name, keytype_T) + ilasm.call_method(meth, False) + return + + for key, value in self.dict._dict.iteritems(): + ilasm.opcode('dup') + AbstractConst.load(self.db, KEYTYPE, key, ilasm) + AbstractConst.load(self.db, VALUETYPE, value, ilasm) + meth = 'void class [pypylib]pypy.runtime.Dict`2<%s, %s>::ll_set(%s, %s)' %\ + (keytype, valuetype, keytype_T, valuetype_T) + ilasm.call_method(meth, False) + + class InstanceConst(AbstractConst): def __init__(self, db, obj, static_type, count): self.db = db Modified: pypy/dist/pypy/translator/cli/src/pypylib.cs ============================================================================== --- pypy/dist/pypy/translator/cli/src/pypylib.cs (original) +++ pypy/dist/pypy/translator/cli/src/pypylib.cs Sat Jul 1 14:47:36 2006 @@ -365,6 +365,25 @@ } } + public class DictOfVoid: System.Collections.Generic.Dictionary // int is a placeholder + { + public int ll_length() { return this.Count; } + public void ll_get(TKey key) { } + public void ll_set(TKey key) { this[key] = 0; } + public bool ll_remove(TKey key) { return this.Remove(key); } + public bool ll_contains(TKey key) { return this.ContainsKey(key); } + public void ll_clear() { this.Clear(); } + + //XXX ll_get_items_iterator is not supported, yet + /* + public DictItemsIterator ll_get_items_iterator() + { + return new DictItemsIterator(this.GetEnumerator()); + } + */ + } + + public class DictItemsIterator { IEnumerator> it; Modified: pypy/dist/pypy/translator/cli/test/test_rpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/test/test_rpython.py (original) +++ pypy/dist/pypy/translator/cli/test/test_rpython.py Sat Jul 1 14:47:36 2006 @@ -41,11 +41,8 @@ class TestCliTuple(CliTest, BaseTestRtuple): - def test_constant_tuple_contains(self): - py.test.skip("CLI doesn't support dict, yet") - - test_constant_tuple_contains2 = test_constant_tuple_contains - test_constant_unichar_tuple_contains = test_constant_tuple_contains + def test_constant_unichar_tuple_contains(self): + py.test.skip("CLI doesn't support cast_int_to_unichar, yet") class TestCliString(CliTest, BaseTestRstr): From arigo at codespeak.net Sat Jul 1 14:48:42 2006 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sat, 1 Jul 2006 14:48:42 +0200 (CEST) Subject: [pypy-svn] r29560 - pypy/dist/pypy/rpython Message-ID: <20060701124842.5364410079@code0.codespeak.net> Author: arigo Date: Sat Jul 1 14:48:41 2006 New Revision: 29560 Modified: pypy/dist/pypy/rpython/llinterp.py Log: Oups, big performance bug in the llinterpreter. Modified: pypy/dist/pypy/rpython/llinterp.py ============================================================================== --- pypy/dist/pypy/rpython/llinterp.py (original) +++ pypy/dist/pypy/rpython/llinterp.py Sat Jul 1 14:48:41 2006 @@ -222,7 +222,7 @@ # try to import the operation from opimpl.py from pypy.rpython.lltypesystem.opimpl import get_op_impl ophandler = get_op_impl(opname) - LLFrame.ophandler = staticmethod(ophandler) + setattr(self.__class__, 'op_' + opname, staticmethod(ophandler)) return ophandler # _______________________________________________________ # evaling functions From arigo at codespeak.net Sat Jul 1 14:50:05 2006 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sat, 1 Jul 2006 14:50:05 +0200 (CEST) Subject: [pypy-svn] r29561 - pypy/dist/pypy/translator/asm Message-ID: <20060701125005.5FBE810079@code0.codespeak.net> Author: arigo Date: Sat Jul 1 14:50:04 2006 New Revision: 29561 Modified: pypy/dist/pypy/translator/asm/model.py Log: Fix for translator/asm failures. Modified: pypy/dist/pypy/translator/asm/model.py ============================================================================== --- pypy/dist/pypy/translator/asm/model.py (original) +++ pypy/dist/pypy/translator/asm/model.py Sat Jul 1 14:50:04 2006 @@ -53,7 +53,8 @@ def execute(self, machine): sources = map(machine.get_register, self.sources) - result = getattr(self._frame(), 'op_' + self.opname)(*sources) + ophandler = self._frame().getoperationhandler(self.opname) + result = ophandler(*sources) machine.store_register(self.dest, result) From antocuni at codespeak.net Sat Jul 1 14:50:43 2006 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 1 Jul 2006 14:50:43 +0200 (CEST) Subject: [pypy-svn] r29562 - pypy/dist/pypy/translator/cli/src Message-ID: <20060701125043.544E310079@code0.codespeak.net> Author: antocuni Date: Sat Jul 1 14:50:39 2006 New Revision: 29562 Modified: pypy/dist/pypy/translator/cli/src/pypylib.cs Log: Make the source code a bit more compact. Modified: pypy/dist/pypy/translator/cli/src/pypylib.cs ============================================================================== --- pypy/dist/pypy/translator/cli/src/pypylib.cs (original) +++ pypy/dist/pypy/translator/cli/src/pypylib.cs Sat Jul 1 14:50:39 2006 @@ -104,25 +104,10 @@ { System.Text.StringBuilder builder = new System.Text.StringBuilder(); - public void ll_allocate(int size) - { - builder.Capacity = size; - } - - public void ll_append_char(char ch) - { - builder.Append(ch); - } - - public void ll_append(string s) - { - builder.Append(s); - } - - public string ll_build() - { - return builder.ToString(); - } + public void ll_allocate(int size) { builder.Capacity = size; } + public void ll_append_char(char ch) { builder.Append(ch); } + public void ll_append(string s) { builder.Append(s); } + public string ll_build() { return builder.ToString(); } } public class String @@ -329,35 +314,12 @@ public class Dict: System.Collections.Generic.Dictionary { - public int ll_length() - { - return this.Count; - } - - public TValue ll_get(TKey key) - { - return this[key]; - } - - public void ll_set(TKey key, TValue value) - { - this[key] = value; - } - - public bool ll_remove(TKey key) - { - return this.Remove(key); - } - - public bool ll_contains(TKey key) - { - return this.ContainsKey(key); - } - - public void ll_clear() - { - this.Clear(); - } + public int ll_length() { return this.Count; } + public TValue ll_get(TKey key) { return this[key]; } + public void ll_set(TKey key, TValue value) { this[key] = value; } + public bool ll_remove(TKey key) { return this.Remove(key); } + public bool ll_contains(TKey key) { return this.ContainsKey(key); } + public void ll_clear() { this.Clear(); } public DictItemsIterator ll_get_items_iterator() { @@ -393,19 +355,8 @@ this.it = it; } - public bool ll_go_next() - { - return it.MoveNext(); - } - - public TKey ll_current_key() - { - return it.Current.Key; - } - - public TValue ll_current_value() - { - return it.Current.Value; - } + public bool ll_go_next() { return it.MoveNext(); } + public TKey ll_current_key() { return it.Current.Key; } + public TValue ll_current_value() { return it.Current.Value; } } } From antocuni at codespeak.net Sat Jul 1 14:54:22 2006 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 1 Jul 2006 14:54:22 +0200 (CEST) Subject: [pypy-svn] r29563 - in pypy/dist/pypy/translator/cli: . test Message-ID: <20060701125422.552E410082@code0.codespeak.net> Author: antocuni Date: Sat Jul 1 14:54:16 2006 New Revision: 29563 Modified: pypy/dist/pypy/translator/cli/opcodes.py pypy/dist/pypy/translator/cli/test/test_rpython.py Log: Added support for converting int to unichar and vice-versa. Don't skip a test that rely on them.. Modified: pypy/dist/pypy/translator/cli/opcodes.py ============================================================================== --- pypy/dist/pypy/translator/cli/opcodes.py (original) +++ pypy/dist/pypy/translator/cli/opcodes.py Sat Jul 1 14:54:16 2006 @@ -206,9 +206,9 @@ 'cast_bool_to_uint': [PushAllArgs, 'ldc.i4.0', 'ceq']+Not, 'cast_bool_to_float': [PushAllArgs, 'ldc.i4 0', 'ceq']+Not+['conv.r8'], 'cast_char_to_int': DoNothing, - 'cast_unichar_to_int': None, + 'cast_unichar_to_int': DoNothing, 'cast_int_to_char': DoNothing, - 'cast_int_to_unichar': None, + 'cast_int_to_unichar': DoNothing, 'cast_int_to_uint': DoNothing, 'cast_int_to_float': 'conv.r8', 'cast_int_to_longlong': 'conv.i8', Modified: pypy/dist/pypy/translator/cli/test/test_rpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/test/test_rpython.py (original) +++ pypy/dist/pypy/translator/cli/test/test_rpython.py Sat Jul 1 14:54:16 2006 @@ -41,9 +41,7 @@ class TestCliTuple(CliTest, BaseTestRtuple): - def test_constant_unichar_tuple_contains(self): - py.test.skip("CLI doesn't support cast_int_to_unichar, yet") - + pass class TestCliString(CliTest, BaseTestRstr): def test_char_isxxx(self): From antocuni at codespeak.net Sat Jul 1 15:01:05 2006 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 1 Jul 2006 15:01:05 +0200 (CEST) Subject: [pypy-svn] r29564 - pypy/dist/pypy/rpython/ootypesystem Message-ID: <20060701130105.8551D10079@code0.codespeak.net> Author: antocuni Date: Sat Jul 1 15:01:01 2006 New Revision: 29564 Modified: pypy/dist/pypy/rpython/ootypesystem/rstr.py Log: Don't mark ll_int as a suggested_primitive in ootypesystem. Modified: pypy/dist/pypy/rpython/ootypesystem/rstr.py ============================================================================== --- pypy/dist/pypy/rpython/ootypesystem/rstr.py (original) +++ pypy/dist/pypy/rpython/ootypesystem/rstr.py Sat Jul 1 15:01:01 2006 @@ -152,7 +152,6 @@ def ll_int(s, base): return ootype.ooparse_int(s, base) - ll_int.suggested_primitive = True def do_stringformat(cls, hop, sourcevarsrepr): InstanceRepr = hop.rtyper.type_system.rclass.InstanceRepr From pedronis at codespeak.net Sat Jul 1 17:29:15 2006 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Sat, 1 Jul 2006 17:29:15 +0200 (CEST) Subject: [pypy-svn] r29566 - in pypy/dist/pypy: jit/timeshifter jit/timeshifter/test rpython Message-ID: <20060701152915.F29E410077@code0.codespeak.net> Author: pedronis Date: Sat Jul 1 17:29:12 2006 New Revision: 29566 Modified: pypy/dist/pypy/jit/timeshifter/oop.py pypy/dist/pypy/jit/timeshifter/rcontainer.py pypy/dist/pypy/jit/timeshifter/rtimeshift.py pypy/dist/pypy/jit/timeshifter/rtyper.py pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py pypy/dist/pypy/jit/timeshifter/timeshift.py pypy/dist/pypy/jit/timeshifter/vlist.py pypy/dist/pypy/rpython/annlowlevel.py pypy/dist/pypy/rpython/rgenop.py Log: intermediate check-in of a refactoring in preperation of handling Modified: pypy/dist/pypy/jit/timeshifter/oop.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/oop.py (original) +++ pypy/dist/pypy/jit/timeshifter/oop.py Sat Jul 1 17:29:12 2006 @@ -61,7 +61,7 @@ if pos > 0: gv_arg = argboxes[i].getgenvar(jitstate) args_gv[pos] = gv_arg - gv_result = rgenop.genop(jitstate.curblock, + gv_result = jitstate.curbuilder.genop( 'direct_call', args_gv, self.gv_result_type) Modified: pypy/dist/pypy/jit/timeshifter/rcontainer.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/rcontainer.py (original) +++ pypy/dist/pypy/jit/timeshifter/rcontainer.py Sat Jul 1 17:29:12 2006 @@ -141,18 +141,17 @@ def generate_set(self, jitstate, genvar, box): gv_sub = genvar + genop = jitstate.curbuilder.genop for i in range(len(self.accessptrtype_gv)-1): op_args = lltype.malloc(rgenop.VARLIST.TO, 2) op_args[0] = gv_sub op_args[1] = self.fieldname_gv[i] - gv_sub = rgenop.genop(jitstate.curblock, 'getsubstruct', - op_args, self.accessptrtype_gv[i+1]) + gv_sub = genop('getsubstruct', op_args, self.accessptrtype_gv[i+1]) op_args = lltype.malloc(rgenop.VARLIST.TO, 3) op_args[0] = gv_sub op_args[1] = self.fieldname_gv[-1] op_args[2] = box.getgenvar(jitstate) - rgenop.genop(jitstate.curblock, 'setfield', op_args, - rgenop.gv_Void) + genop('setfield', op_args, rgenop.gv_Void) # ____________________________________________________________ @@ -207,20 +206,19 @@ box.enter_block(newblock, incoming, memo) def force_runtime_container(self, jitstate): + genop = jitstate.curbuilder.genop typedesc = self.typedesc boxes = self.content_boxes self.content_boxes = None op_args = lltype.malloc(rgenop.VARLIST.TO, 1) op_args[0] = typedesc.gv_type - genvar = rgenop.genop(jitstate.curblock, 'malloc', op_args, - typedesc.gv_ptrtype) + genvar = genop('malloc', op_args, typedesc.gv_ptrtype) # force all the boxes pointing to this VirtualStruct for box in self.substruct_boxes: # XXX using getsubstruct would be nicer op_args = lltype.malloc(rgenop.VARLIST.TO, 1) op_args[0] = genvar - box.genvar = rgenop.genop(jitstate.curblock, 'cast_pointer', - op_args, box.gv_type) + box.genvar = genop('cast_pointer', op_args, box.gv_type) box.content = None self.substruct_boxes = None fielddescs = typedesc.fielddescs Modified: pypy/dist/pypy/jit/timeshifter/rtimeshift.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/rtimeshift.py (original) +++ pypy/dist/pypy/jit/timeshifter/rtimeshift.py Sat Jul 1 17:29:12 2006 @@ -5,422 +5,6 @@ FOLDABLE_OPS = dict.fromkeys(lloperation.enum_foldable_ops()) - -##def make_types_const(TYPES): -## n = len(TYPES) -## l = lltype.malloc(rgenop.VARLIST.TO, n) -## for i in range(n): -## l[i] = rgenop.constTYPE(TYPES[i]) -## return l - - -##class RedBox(object): - -## def same_constant(self, other): -## return False - -## def getallvariables(self, jitstate, result_gv, memo): -## pass - -## def copybox(self, newblock, gv_type, memo): -## try: -## return memo[self] -## except KeyError: -## return self._copybox(newblock, gv_type, memo) - -## def match(self, jitstate, newbox, incoming, memo): -## if self in memo: -## return memo[self] is newbox -## if newbox in memo: -## return memo[newbox] is self -## memo[self] = newbox -## memo[newbox] = self -## return self._match(jitstate, newbox, incoming, memo) - -## def union_for_new_block(self, jitstate, newbox, newblock, -## gv_type, incoming, memo): -## try: -## return memo[newbox] -## except KeyError: -## return self._union_for_new_block(jitstate, newbox, newblock, -## gv_type, incoming, memo) - -## # generic implementation of some operations -## def op_getfield(self, jitstate, fielddesc): -## op_args = lltype.malloc(rgenop.VARLIST.TO, 2) -## op_args[0] = self.getgenvar(jitstate) -## op_args[1] = fielddesc.gv_fieldname -## genvar = rgenop.genop(jitstate.curblock, 'getfield', op_args, -## fielddesc.gv_resulttype) -## return VarRedBox(genvar) - -## def op_setfield(self, jitstate, fielddesc, valuebox): -## op_args = lltype.malloc(rgenop.VARLIST.TO, 3) -## op_args[0] = self.getgenvar(jitstate) -## op_args[1] = fielddesc.gv_fieldname -## op_args[2] = valuebox.getgenvar(jitstate) -## rgenop.genop(jitstate.curblock, 'setfield', op_args, -## rgenop.gv_Void) - -## def op_getsubstruct(self, jitstate, fielddesc): -## op_args = lltype.malloc(rgenop.VARLIST.TO, 2) -## op_args[0] = self.getgenvar(jitstate) -## op_args[1] = fielddesc.gv_fieldname -## genvar = rgenop.genop(jitstate.curblock, 'getsubstruct', op_args, -## fielddesc.gv_resulttype) -## return VarRedBox(genvar) - - -##class VarRedBox(RedBox): -## "A red box that contains a run-time variable." - -## def __init__(self, genvar): -## self.genvar = genvar - -## def getgenvar(self, jitstate): -## return self.genvar - -## def getallvariables(self, jitstate, result_gv, memo): -## if self not in memo: -## result_gv.append(self.genvar) -## memo[self] = None - -## def _copybox(self, newblock, gv_type, memo): -## newgenvar = rgenop.geninputarg(newblock, gv_type) -## memo[self] = newbox = VarRedBox(newgenvar) -## return newbox - -## incoming.append(newbox.getgenvar(jitstate)) -## return True - -## def _match(self, jitstate, newbox, incoming, memo): -## incoming.append(newbox.getgenvar(jitstate)) -## return True - -## def _union_for_new_block(self, jitstate, newbox, newblock, -## gv_type, incoming, memo): -## incoming.append(newbox.getgenvar(jitstate)) -## newgenvar = rgenop.geninputarg(newblock, gv_type) -## memo[newbox] = newnewbox = VarRedBox(newgenvar) -## return newnewbox - - -##VCONTAINER = lltype.GcStruct("vcontainer") - -##class ContainerRedBox(RedBox): -## def __init__(self, envelope, content_addr): -## self.envelope = envelope -## self.content_addr = content_addr - -## def getgenvar(self, jitstate): # no support at the moment -## raise RuntimeError("cannot force virtual containers") - -## def ll_make_container_box(envelope, content_addr): -## return ContainerRedBox(envelope, content_addr) -## ll_make_container_box = staticmethod(ll_make_container_box) - -## def ll_make_subcontainer_box(box, content_addr): -## return ContainerRedBox(box.envelope, content_addr) -## ll_make_subcontainer_box = staticmethod(ll_make_subcontainer_box) - - -##def ll_getenvelope(box): -## assert isinstance(box, ContainerRedBox) -## return box.envelope - -##def ll_getcontent(box): -## assert isinstance(box, ContainerRedBox) -## return box.content_addr - - -##class BigRedBox(RedBox): -## "A (big) red box that contains (small) red boxes inside." - -## #def __init__(self, content_boxes): -## # self.content_boxes = content_boxes - -## def op_getfield(self, jitstate, fielddesc): -## if self.content_boxes is None: -## return RedBox.op_getfield(self, jitstate, fielddesc) -## else: -## return self.content_boxes[fielddesc.fieldindex] - -## def op_setfield(self, jitstate, fielddesc, valuebox): -## if self.content_boxes is None: -## RedBox.op_setfield(self, jitstate, fielddesc, valuebox) -## else: -## self.content_boxes[fielddesc.fieldindex] = valuebox - -## def op_getsubstruct(self, jitstate, fielddesc): -## if self.content_boxes is None: -## return RedBox.op_getsubstruct(self, jitstate, fielddesc) -## else: -## return self.content_boxes[fielddesc.fieldindex] - - -##class VirtualRedBox(BigRedBox): -## "A red box that contains (for now) a virtual Struct." - -## def __init__(self, typedesc): -## self.content_boxes = typedesc.build_content_boxes(self) -## self.typedesc = typedesc -## self.genvar = rgenop.nullvar - -## def getgenvar(self, jitstate): -## if not self.genvar: -## typedesc = self.typedesc -## boxes = self.content_boxes -## self.content_boxes = None -## op_args = lltype.malloc(rgenop.VARLIST.TO, 1) -## op_args[0] = typedesc.gv_type -## self.genvar = rgenop.genop(jitstate.curblock, 'malloc', op_args, -## typedesc.gv_ptrtype) -## typedesc.materialize_content(jitstate, self.genvar, boxes) -## return self.genvar - -## def is_forced(self): -## return bool(self.genvar) - -## def getallvariables(self, jitstate, result_gv, memo): -## if self.genvar: -## if self not in memo: -## result_gv.append(self.genvar) -## memo[self] = None -## else: -## for smallbox in self.content_boxes: -## smallbox.getallvariables(jitstate, result_gv, memo) - -## def _copybox(self, newblock, gv_type, memo): -## if self.genvar: -## newgenvar = rgenop.geninputarg(newblock, gv_type) -## memo[self] = newbox = VarRedBox(newgenvar) -## return newbox -## bigbox = VirtualRedBox(self.typedesc) -## memo[self] = bigbox -## for i in range(len(bigbox.content_boxes)): -## gv_fldtype = self.typedesc.fielddescs[i].gv_resulttype -## bigbox.content_boxes[i] = self.content_boxes[i].copybox(newblock, -## gv_fldtype, -## memo) -## return bigbox - -## def _match(self, jitstate, newbox, incoming, memo): -## if self.genvar: -## incoming.append(newbox.getgenvar(jitstate)) -## return True -## if not isinstance(newbox, VirtualRedBox): -## return False -## for i in range(len(self.content_boxes)): -## mysmallbox = self.content_boxes[i] -## newsmallbox = newbox.content_boxes[i] -## if not mysmallbox.match(jitstate, newsmallbox, incoming, memo): -## return False -## else: -## return True - -## def inlined_structs_are_compatible(self, newbox): -## return (isinstance(newbox, VirtualRedBox) and not newbox.genvar and -## self.typedesc.compare_content_boxes(self.content_boxes, -## newbox.content_boxes)) - -## def _union_for_new_block(self, jitstate, newbox, newblock, -## gv_type, incoming, memo): -## if self.genvar or not self.inlined_structs_are_compatible(newbox): -## incoming.append(newbox.getgenvar(jitstate)) -## newgenvar = rgenop.geninputarg(newblock, gv_type) -## memo[newbox] = newnewbox = VarRedBox(newgenvar) -## return newnewbox -## bigbox = VirtualRedBox(self.typedesc) -## memo[newbox] = bigbox -## for i in range(len(bigbox.content_boxes)): -## gv_fldtype = self.typedesc.fielddescs[i].gv_resulttype -## box = self.content_boxes[i] -## bigbox.content_boxes[i] = box.union_for_new_block( -## jitstate, -## newbox.content_boxes[i], -## newblock, -## gv_fldtype, -## incoming, -## memo) -## return bigbox - - -##class SubVirtualRedBox(BigRedBox): - -## def __init__(self, parentbox, fielddesc): -## self.parentbox = parentbox -## self.fielddesc = fielddesc -## typedesc = fielddesc.inlined_typedesc -## self.content_boxes = typedesc.build_content_boxes(self) - -## def getgenvar(self, jitstate): -## gv = self.parentbox.getgenvar(jitstate) -## op_args = lltype.malloc(rgenop.VARLIST.TO, 2) -## op_args[0] = gv -## op_args[1] = self.fielddesc.gv_fieldname -## genvar = rgenop.genop(jitstate.curblock, 'getsubstruct', op_args, -## self.fielddesc.gv_resulttype) -## return genvar - -## def is_forced(self): -## return self.parentbox.is_forced() - -## def getallvariables(self, jitstate, result_gv, memo): -## if self.is_forced(): -## if self not in memo: -## result_gv.append(self.getgenvar(jitstate)) -## memo[self] = None -## else: -## for smallbox in self.content_boxes: -## smallbox.getallvariables(jitstate, result_gv, memo) - -## def _copybox(self, newblock, gv_type, memo): -## if self.is_forced(): -## newgenvar = rgenop.geninputarg(newblock, gv_type) -## memo[self] = newbox = VarRedBox(newgenvar) -## return newbox -## bigbox = SubVirtualRedBox(None, self.fielddesc) -## memo[self] = bigbox -## gv_parenttype = self.fielddesc.parenttypedesc.gv_ptrtype -## parentcopybox = self.parentbox.copybox(newblock, gv_parenttype, memo) -## bigbox.parentbox = parentcopybox -## typedesc = self.fielddesc.inlined_typedesc -## for i in range(len(bigbox.content_boxes)): -## gv_fldtype = typedesc.fielddescs[i].gv_resulttype -## bigbox.content_boxes[i] = self.content_boxes[i].copybox(newblock, -## gv_fldtype, -## memo) -## return bigbox - -## def _match(self, jitstate, newbox, incoming, memo): -## if self.is_forced(): -## incoming.append(newbox.getgenvar(jitstate)) -## return True -## if not (isinstance(newbox, SubVirtualRedBox) and -## self.fielddesc is newbox.fielddesc and -## self.parentbox.match(jitstate, newbox.parentbox, -## incoming, memo)): -## return False -## for i in range(len(self.content_boxes)): -## mysmallbox = self.content_boxes[i] -## newsmallbox = newbox.content_boxes[i] -## if not mysmallbox.match(jitstate, newsmallbox, incoming, memo): -## return False -## else: -## return True - -## def inlined_structs_are_compatible(self, newbox): -## if (isinstance(newbox, SubVirtualRedBox) and not newbox.is_forced() and -## self.fielddesc is newbox.fielddesc): -## return self.parentbox.inlined_structs_are_compatible( -## newbox.parentbox) -## else: -## return False - -## def _union_for_new_block(self, jitstate, newbox, newblock, -## gv_type, incoming, memo): -## if self.is_forced() or not self.inlined_structs_are_compatible(newbox): -## incoming.append(newbox.getgenvar(jitstate)) -## newgenvar = rgenop.geninputarg(newblock, gv_type) -## memo[newbox] = newnewbox = VarRedBox(newgenvar) -## return newnewbox -## assert isinstance(newbox, SubVirtualRedBox) -## bigbox = SubVirtualRedBox(None, self.fielddesc) -## memo[newbox] = bigbox -## gv_parenttype = self.fielddesc.parenttypedesc.gv_ptrtype -## parentcopybox = self.parentbox.union_for_new_block(jitstate, -## newbox.parentbox, -## newblock, -## gv_parenttype, -## incoming, -## memo) -## bigbox.parentbox = parentcopybox -## typedesc = self.fielddesc.inlined_typedesc -## for i in range(len(bigbox.content_boxes)): -## gv_fldtype = typedesc.fielddescs[i].gv_resulttype -## box = self.content_boxes[i] -## bigbox.content_boxes[i] = box.union_for_new_block( -## jitstate, -## newbox.content_boxes[i], -## newblock, -## gv_fldtype, -## incoming, -## memo) -## return bigbox - - -##class ConstRedBox(RedBox): -## "A red box that contains a run-time constant." - -## def __init__(self, genvar): -## self.genvar = genvar - -## def getgenvar(self, jitstate): -## return self.genvar - -## def copybox(self, newblock, gv_type, memo): -## return self - -## def match(self, jitstate, newbox, incoming, memo): -## return self.same_constant(newbox) - -## def _union_for_new_block(self, jitstate, newbox, newblock, -## gv_type, incoming, memo): -## if self.same_constant(newbox): -## newnewbox = newbox -## else: -## incoming.append(newbox.getgenvar(jitstate)) -## newgenvar = rgenop.geninputarg(newblock, gv_type) -## newnewbox = VarRedBox(newgenvar) -## memo[newbox] = newnewbox -## return newnewbox - -## def ll_fromvalue(value): -## T = lltype.typeOf(value) -## gv = rgenop.genconst(value) -## if isinstance(T, lltype.Ptr): -## return AddrRedBox(gv) -## elif T is lltype.Float: -## return DoubleRedBox(gv) -## else: -## assert isinstance(T, lltype.Primitive) -## assert T is not lltype.Void, "cannot make red boxes of voids" -## # XXX what about long longs? -## return IntRedBox(gv) -## ll_fromvalue = staticmethod(ll_fromvalue) - -## def ll_getvalue(self, T): -## # note: this is specialized by low-level type T, as a low-level helper -## return rgenop.revealconst(T, self.genvar) - -##def ll_getvalue(box, T): -## return box.ll_getvalue(T) - - -##class IntRedBox(ConstRedBox): -## "A red box that contains a constant integer-like value." - -## def same_constant(self, other): -## return (isinstance(other, IntRedBox) and -## self.ll_getvalue(lltype.Signed) == other.ll_getvalue(lltype.Signed)) - - -##class DoubleRedBox(ConstRedBox): -## "A red box that contains a constant double-precision floating point value." - -## def same_constant(self, other): -## return (isinstance(other, DoubleRedBox) and -## self.ll_getvalue(lltype.Float) == other.ll_getvalue(lltype.Float)) - - -##class AddrRedBox(ConstRedBox): -## "A red box that contains a constant address." - -## def same_constant(self, other): -## return (isinstance(other, AddrRedBox) and -## self.ll_getvalue(llmemory.Address) == other.ll_getvalue(llmemory.Address)) - - # ____________________________________________________________ # emit ops @@ -479,8 +63,8 @@ return rvalue.ll_fromvalue(res) op_args = lltype.malloc(rgenop.VARLIST.TO, 1) op_args[0] = argbox.getgenvar(jitstate) - genvar = rgenop.genop(jitstate.curblock, opdesc.opname, op_args, - opdesc.gv_RESULT) + genvar = jitstate.curbuilder.genop(opdesc.opname, op_args, + opdesc.gv_RESULT) return opdesc.redboxcls(opdesc.gv_RESULT, genvar) def ll_generate_operation2(opdesc, jitstate, argbox0, argbox1): @@ -497,157 +81,10 @@ op_args = lltype.malloc(rgenop.VARLIST.TO, 2) op_args[0] = argbox0.getgenvar(jitstate) op_args[1] = argbox1.getgenvar(jitstate) - genvar = rgenop.genop(jitstate.curblock, opdesc.opname, op_args, - opdesc.gv_RESULT) + genvar = jitstate.curbuilder.genop(opdesc.opname, op_args, + opdesc.gv_RESULT) return opdesc.redboxcls(opdesc.gv_RESULT, genvar) -## class StructTypeDesc(object): -## _type_cache = weakref.WeakKeyDictionary() - -## def __init__(self, TYPE): -## self.TYPE = TYPE -## self.PTRTYPE = lltype.Ptr(TYPE) -## self.gv_type = rgenop.constTYPE(self.TYPE) -## self.gv_ptrtype = rgenop.constTYPE(self.PTRTYPE) - -## def setup(self): -## self.fielddescs = [StructFieldDesc.make(self.PTRTYPE, name) -## for name in self.TYPE._names] -## defls = [] -## for desc in self.fielddescs: -## if desc.inlined_typedesc is not None: -## defaultbox = None -## else: -## defaultvalue = desc.RESTYPE._defl() -## defaultbox = rvalue.ll_fromvalue(defaultvalue) -## defls.append(defaultbox) -## self.default_boxes = defls - -## def build_content_boxes(self, parentbox): -## # make a'content_boxes' list based on the typedesc's default_boxes, -## # building nested SubVirtualRedBoxes for inlined substructs -## clist = [] -## for i in range(len(self.fielddescs)): -## fielddesc = self.fielddescs[i] -## if fielddesc.inlined_typedesc: -## box = SubVirtualRedBox(parentbox, fielddesc) -## else: -## box = self.default_boxes[i] -## clist.append(box) -## return clist - -## def compare_content_boxes(self, content_boxes_1, content_boxes_2): -## for i in range(len(self.fielddescs)): -## fielddesc = self.fielddescs[i] -## if fielddesc.inlined_typedesc: -## box1 = content_boxes_1[i] -## box2 = content_boxes_2[i] -## assert isinstance(box1, BigRedBox) -## assert isinstance(box2, BigRedBox) -## if not fielddesc.inlined_typedesc.compare_content_boxes( -## box1.content_boxes, box2.content_boxes): -## return False -## else: -## return True - -## def materialize_content(self, jitstate, gv, boxes): -## for i in range(len(boxes)): -## smallbox = boxes[i] -## fielddesc = self.fielddescs[i] -## if fielddesc.inlined_typedesc: -## op_args = lltype.malloc(rgenop.VARLIST.TO, 2) -## op_args[0] = gv -## op_args[1] = fielddesc.gv_fieldname -## gv_sub = rgenop.genop(jitstate.curblock, 'getsubstruct', -## op_args, fielddesc.gv_resulttype) -## assert isinstance(smallbox, SubVirtualRedBox) -## subboxes = smallbox.content_boxes -## smallbox.content_boxes = None -## fielddesc.inlined_typedesc.materialize_content(jitstate, -## gv_sub, -## subboxes) -## else: -## op_args = lltype.malloc(rgenop.VARLIST.TO, 3) -## op_args[0] = gv -## op_args[1] = fielddesc.gv_fieldname -## op_args[2] = smallbox.getgenvar(jitstate) -## rgenop.genop(jitstate.curblock, 'setfield', op_args, -## rgenop.gv_Void) - -## def make(T): -## try: -## return StructTypeDesc._type_cache[T] -## except KeyError: -## desc = StructTypeDesc._type_cache[T] = StructTypeDesc(T) -## desc.setup() -## return desc -## make = staticmethod(make) - -## def ll_factory(self): -## return VirtualRedBox(self) - -## def _freeze_(self): -## return True - -## def compact_repr(self): # goes in ll helper names -## return "Desc_%s" % (self.TYPE._short_name(),) - -## class FieldDesc(object): -## _fielddesc_cache = weakref.WeakKeyDictionary() - -## def __init__(self, PTRTYPE, RESTYPE): -## self.PTRTYPE = PTRTYPE -## if isinstance(RESTYPE, lltype.ContainerType): -## RESTYPE = lltype.Ptr(RESTYPE) -## self.RESTYPE = RESTYPE -## self.gv_resulttype = rgenop.constTYPE(RESTYPE) -## self.redboxcls = rvalue.ll_redboxcls(RESTYPE) -## self.immutable = PTRTYPE.TO._hints.get('immutable', False) - -## def _freeze_(self): -## return True - -## def make(cls, PTRTYPE, *args): -## T = PTRTYPE.TO -## cache = FieldDesc._fielddesc_cache.setdefault(T, {}) -## try: -## return cache[args] -## except KeyError: -## fdesc = cache[args] = cls(PTRTYPE, *args) -## fdesc.setup() -## return fdesc -## make = classmethod(make) - -## class StructFieldDesc(FieldDesc): -## def __init__(self, PTRTYPE, fieldname): -## assert isinstance(PTRTYPE.TO, lltype.Struct) -## RES1 = getattr(PTRTYPE.TO, fieldname) -## FieldDesc.__init__(self, PTRTYPE, RES1) -## self.fieldname = fieldname -## self.gv_fieldname = rgenop.constFieldName(fieldname) -## self.fieldindex = operator.indexOf(PTRTYPE.TO._names, fieldname) -## if isinstance(RES1, lltype.Struct): -## # inlined substructure -## self.inlined_typedesc = StructTypeDesc.make(RES1) -## ## elif isinstance(RES1, lltype.Array): -## ## # inlined array XXX in-progress -## ## self.inlined_typedesc = ArrayTypeDesc.make(RES1) -## else: -## self.inlined_typedesc = None - -## def setup(self): -## self.parenttypedesc = StructTypeDesc.make(self.PTRTYPE.TO) - -## def compact_repr(self): # goes in ll helper names -## return "Fld_%s_in_%s" % (self.fieldname, self.PTRTYPE._short_name()) - -## class ArrayFieldDesc(FieldDesc): -## def __init__(self, PTRTYPE): -## assert isinstance(PTRTYPE.TO, lltype.Array) -## FieldDesc.__init__(self, PTRTYPE, PTRTYPE.TO.OF) -## def setup(self): -## pass - def ll_generate_getfield(jitstate, fielddesc, argbox): if fielddesc.immutable and argbox.is_constant(): res = getattr(rvalue.ll_getvalue(argbox, fielddesc.PTRTYPE), @@ -658,8 +95,8 @@ op_args = lltype.malloc(rgenop.VARLIST.TO, 2) op_args[0] = argbox.getgenvar(jitstate) op_args[1] = fielddesc.fieldname_gv[-1] - genvar = rgenop.genop(jitstate.curblock, 'getfield', op_args, - fielddesc.gv_resulttype) + genvar = jitstate.curbuilder.genop('getfield', op_args, + fielddesc.gv_resulttype) return fielddesc.redboxcls(fielddesc.gv_resulttype, genvar) else: return argbox.content.op_getfield(jitstate, fielddesc) @@ -671,8 +108,8 @@ op_args[0] = destbox.getgenvar(jitstate) op_args[1] = fielddesc.fieldname_gv[-1] op_args[2] = valuebox.getgenvar(jitstate) - rgenop.genop(jitstate.curblock, 'setfield', op_args, - rgenop.gv_Void) + jitstate.curbuilder.genop('setfield', op_args, + rgenop.gv_Void) else: destbox.content.op_setfield(jitstate, fielddesc, valuebox) @@ -686,8 +123,8 @@ op_args = lltype.malloc(rgenop.VARLIST.TO, 2) op_args[0] = argbox.getgenvar(jitstate) op_args[1] = fielddesc.gv_fieldname - genvar = rgenop.genop(jitstate.curblock, 'getsubstruct', op_args, - fielddesc.gv_resulttype) + genvar = jitstate.curbuilder.genop('getsubstruct', op_args, + fielddesc.gv_resulttype) return fielddesc.redboxcls(fielddesc.gv_resulttype, genvar) else: return argbox.content.op_getsubstruct(jitstate, fielddesc) @@ -701,20 +138,15 @@ op_args = lltype.malloc(rgenop.VARLIST.TO, 2) op_args[0] = argbox.getgenvar(jitstate) op_args[1] = indexbox.getgenvar(jitstate) - genvar = rgenop.genop(jitstate.curblock, 'getarrayitem', op_args, - fielddesc.gv_resulttype) + genvar = jitstate.curbuilder.genop('getarrayitem', op_args, + fielddesc.gv_resulttype) return fielddesc.redboxcls(fielddesc.gv_resulttype, genvar) -##def ll_generate_malloc(jitstate, gv_type, gv_resulttype): -## op_args = lltype.malloc(rgenop.VARLIST.TO, 1) -## op_args[0] = gv_type -## genvar = rgenop.genop(jitstate.curblock, 'malloc', op_args, -## gv_resulttype) -## return VarRedBox(genvar) - # ____________________________________________________________ # other jitstate/graph level operations +def enter_graph(builder): + return builder.build_jitstate() def retrieve_jitstate_for_merge(states_dic, jitstate, key, redboxes): if key not in states_dic: @@ -730,9 +162,7 @@ for box in outgoingvarboxes: linkargs.append(box.getgenvar(None)) box.genvar = rgenop.geninputarg(newblock, box.gv_type) - rgenop.closelink(jitstate.curoutgoinglink, linkargs, newblock) - jitstate.curblock = newblock - jitstate.curoutgoinglink = lltype.nullptr(rgenop.LINK.TO) + jitstate.curbuilder.enter_block(linkargs, newblock) states_dic[key] = frozens, newblock return jitstate @@ -750,8 +180,8 @@ linkargs = [] for box in outgoingvarboxes: linkargs.append(box.getgenvar(jitstate)) - link = rgenop.closeblock1(jitstate.curblock) - rgenop.closelink(link, linkargs, oldblock) + jitstate.curbuilder.leave_block() + jitstate.curbuilder.finish_and_goto(linkargs, oldblock) return None # Make a more general block @@ -768,33 +198,12 @@ if replace_memo.boxes: for i in range(len(redboxes)): redboxes[i] = redboxes[i].replace(replace_memo) - link = rgenop.closeblock1(jitstate.curblock) - rgenop.closelink(link, linkargs, newblock) - jitstate.curblock = newblock - #jitstate.curoutgoinglink = lltype.nullptr(rgenop.LINK.TO) + jitstate.curbuilder.leave_block() + jitstate.curbuilder.enter_block(linkargs, newblock) memo = rvalue.freeze_memo() frozens = [redbox.freeze(memo) for redbox in redboxes] states_dic[key] = frozens, newblock return jitstate - -## newblock = rgenop.newblock() -## incoming = [] -## memo = {} -## for i in range(len(redboxes)): -## oldbox = oldboxes[i] -## newbox = redboxes[i] -## redboxes[i] = oldbox.union_for_new_block(jitstate, newbox, newblock, -## types_gv[i], incoming, memo) -## ## if not oldbox.same_constant(newbox): -## ## incoming.append(newbox.getgenvar(jitstate)) -## ## newgenvar = rgenop.geninputarg(newblock, TYPES[i]) -## ## redboxes[i] = VarRedBox(newgenvar) -## link = rgenop.closeblock1(jitstate.curblock) -## rgenop.closelink(link, incoming, newblock) -## jitstate.curblock = newblock -## #jitstate.curoutgoinglink = lltype.nullptr(rgenop.LINK.TO) -## states_dic[key] = redboxes, newblock -## return jitstate retrieve_jitstate_for_merge._annspecialcase_ = "specialize:arglltype(2)" def enter_block(jitstate, redboxes): @@ -803,9 +212,7 @@ memo = rvalue.enter_block_memo() for i in range(len(redboxes)): redboxes[i].enter_block(newblock, incoming, memo) - rgenop.closelink(jitstate.curoutgoinglink, incoming, newblock) - jitstate.curblock = newblock - jitstate.curoutgoinglink = lltype.nullptr(rgenop.LINK.TO) + jitstate.curbuilder.enter_block(incoming, newblock) return jitstate def dyn_enter_block(jitstate, redboxes): @@ -814,49 +221,42 @@ memo = rvalue.enter_block_memo() for redbox in redboxes: redbox.enter_block(newblock, incoming, memo) - rgenop.closelink(jitstate.curoutgoinglink, incoming, newblock) - jitstate.curblock = newblock - jitstate.curoutgoinglink = lltype.nullptr(rgenop.LINK.TO) + jitstate.curbuilder.enter_block(incoming, newblock) return jitstate def leave_block(jitstate): - jitstate.curoutgoinglink = rgenop.closeblock1(jitstate.curblock) + jitstate.curbuilder.leave_block() return jitstate def leave_block_split(jitstate, switchredbox, exitindex, redboxes): if switchredbox.is_constant(): - jitstate.curoutgoinglink = rgenop.closeblock1(jitstate.curblock) + jitstate.curbuilder.leave_block() return rvalue.ll_getvalue(switchredbox, lltype.Bool) else: exitgvar = switchredbox.getgenvar(jitstate) - linkpair = rgenop.closeblock2(jitstate.curblock, exitgvar) - false_link, true_link = linkpair.item0, linkpair.item1 - later_jitstate = jitstate.copystate() - jitstate.curoutgoinglink = true_link - later_jitstate.curoutgoinglink = false_link + later_builder = jitstate.curbuilder.leave_block_split(exitgvar) memo = rvalue.copy_memo() redboxcopies = [redbox.copy(memo) for redbox in redboxes] - jitstate.split_queue.append((exitindex, later_jitstate, redboxcopies)) + jitstate.split_queue.append((exitindex, later_builder, redboxcopies)) return True def schedule_return(jitstate, redbox): - jitstate.return_queue.append((jitstate.curoutgoinglink, redbox)) + jitstate.return_queue.append((jitstate.curbuilder, redbox)) novars = lltype.malloc(rgenop.VARLIST.TO, 0) def dispatch_next(jitstate, outredboxes, gv_return_type): split_queue = jitstate.split_queue if split_queue: - exitindex, later_jitstate, redboxes = split_queue.pop() - jitstate.curblock = later_jitstate.curblock - jitstate.curoutgoinglink = later_jitstate.curoutgoinglink - jitstate.curvalue = later_jitstate.curvalue + exitindex, later_builder, redboxes = split_queue.pop() + jitstate.curbuilder = later_builder for box in redboxes: outredboxes.append(box) return exitindex return_queue = jitstate.return_queue first_redbox = return_queue[0][1] - finalblock = rgenop.newblock() + finalbuilder = ResidualGraphBuilder(rgenop.newblock()) + finalblock = finalbuilder.block ## jitstate.curblock = finalblock ## if isinstance(first_redbox, ConstRedBox): ## for link, redbox in return_queue: @@ -871,19 +271,19 @@ ## return -1 finalvar = rgenop.geninputarg(finalblock, gv_return_type) - for link, redbox in return_queue: + for builder, redbox in return_queue: newblock = rgenop.newblock() incoming = [] memo = rvalue.enter_block_memo() redbox.enter_block(newblock, incoming, memo) - jitstate.curblock = newblock + jitstate.curbuilder = builder + builder.enter_block(incoming, newblock) gv_retval = redbox.getgenvar(jitstate) - rgenop.closelink(link, incoming, newblock) - newlink = rgenop.closeblock1(newblock) - rgenop.closelink(newlink, [gv_retval], finalblock) - finallink = rgenop.closeblock1(finalblock) - jitstate.curoutgoinglink = finallink - jitstate.curvalue = finalvar + builder.leave_block() + builder.finish_and_goto([gv_retval], finalblock) + finalbuilder.leave_block() + finalbuilder.value = finalvar + jitstate.curbuilder = finalbuilder return -1 def ll_gvar_from_redbox(jitstate, redbox): @@ -894,34 +294,42 @@ # ____________________________________________________________ -class JITState(object): - # XXX obscure interface - - def setup(self): - self.return_queue = [] - self.split_queue = [] - self.curblock = rgenop.newblock() - self.curvalue = rgenop.nullvar - - def end_setup(self): - self.curoutgoinglink = rgenop.closeblock1(self.curblock) +class ResidualGraphBuilder(rgenop.LowLevelOpBuilder): + def __init__(self, block=rgenop.nullblock, link=rgenop.nulllink): + rgenop.LowLevelOpBuilder.__init__(self, block) + self.outgoinglink = link + self.value = rgenop.nullvar + + def build_jitstate(self): + return JITState(self) + + def enter_block(self, linkargs, newblock): + rgenop.closelink(self.outgoinglink, linkargs, newblock) + self.block = newblock + self.outgoinglink = rgenop.nulllink + + def leave_block(self): + self.outgoinglink = rgenop.closeblock1(self.block) - def close(self, return_gvar): - rgenop.closereturnlink(self.curoutgoinglink, return_gvar) + def leave_block_split(self, exitgvar): + linkpair = rgenop.closeblock2(self.block, exitgvar) + false_link, true_link = linkpair.item0, linkpair.item1 + later_builder = ResidualGraphBuilder(link=false_link) + self.outgoinglink = true_link + return later_builder + + def finish_and_goto(self, linkargs, targetblock): + rgenop.closelink(self.outgoinglink, linkargs, targetblock) + self.outgoinglink = rgenop.nulllink + + def finish_and_return(self): + rgenop.closereturnlink(self.outgoinglink, self.value) + + def clone(self): + XXX - def copystate(self): - other = JITState() - other.return_queue = self.return_queue - other.split_queue = self.split_queue - other.curblock = self.curblock - other.curoutgoinglink = self.curoutgoinglink - other.curvalue = self.curvalue - return other - -def ll_build_jitstate(): - jitstate = JITState() - jitstate.setup() - return jitstate +def ll_make_builder(): + return ResidualGraphBuilder(rgenop.newblock()) def ll_int_box(gv_type, gv): return rvalue.IntRedBox(gv_type, gv) @@ -932,13 +340,22 @@ def ll_addr_box(gv_type, gv): return rvalue.PtrRedBox(gv_type, gv) -def ll_geninputarg(jitstate, gv_TYPE): - return rgenop.geninputarg(jitstate.curblock, gv_TYPE) - -def ll_end_setup_jitstate(jitstate): - jitstate.end_setup() - return jitstate.curblock +def ll_geninputarg(builder, gv_TYPE): + return rgenop.geninputarg(builder.block, gv_TYPE) +def ll_end_setup_builder(builder): + builder.leave_block() + return builder.block + def ll_close_jitstate(jitstate): - result_genvar = jitstate.curvalue - jitstate.close(result_genvar) + jitstate.curbuilder.finish_and_return() + +class JITState(object): + # XXX obscure interface + + def __init__(self, builder): + self.return_queue = [] + self.split_queue = [] + self.curbuilder = builder + + Modified: pypy/dist/pypy/jit/timeshifter/rtyper.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/rtyper.py (original) +++ pypy/dist/pypy/jit/timeshifter/rtyper.py Sat Jul 1 17:29:12 2006 @@ -6,14 +6,14 @@ from pypy.rpython.rtyper import RPythonTyper, LowLevelOpList, TyperError from pypy.rpython.rmodel import Repr, inputconst from pypy.rpython.lltypesystem.rstr import string_repr -from pypy.rpython.typesystem import TypeSystem +from pypy.rpython.typesystem import LowLevelTypeSystem from pypy.rpython.lltypesystem import lltype, llmemory from pypy.rpython import rgenop from pypy.jit.hintannotator import model as hintmodel from pypy.jit.hintannotator import container as hintcontainer from pypy.jit.timeshifter import rtimeshift, rvalue, rcontainer -class HintTypeSystem(TypeSystem): +class HintTypeSystem(LowLevelTypeSystem): name = "hinttypesystem" offers_exceptiondata = False @@ -218,7 +218,20 @@ v = hop.genop('direct_call', hop.args_v, hop.r_result.lowleveltype) return v else: - raise NotImplementedError("direct_call") + bk = self.annotator.bookkeeper + hop.r_s_popfirstarg() + args_hs = hop.args_s[:] + # fixed is always false here + graph = bk.get_graph_for_call(fnobj.graph, False, args_hs) + args_r = [self.getrepr(hs) for hs in args_hs] + args_v = hop.inputargs(*args_r) + fnptr = self.getcallable(graph) + self.timeshifter.schedule_graph(graph) + v_jitstate = hop.llops.getjitstate() + args_v.insert(0, v_jitstate) + args_v.insert(0, hop.llops.genconst(fnptr)) + v = hop.genop('direct_call', args_v, hop.r_result.lowleveltype) + return v def handle_highlevel_operation(self, fnobj, hop): from pypy.jit.timeshifter.oop import OopSpecDesc, Index Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py (original) +++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py Sat Jul 1 17:29:12 2006 @@ -79,9 +79,8 @@ # run the time-shifted graph-producing graphs graph1 = ha.translator.graphs[0] llinterp = LLInterpreter(rtyper) - llinterp.eval_graph(htshift.ll_clearcaches, []) - jitstate = llinterp.eval_graph(htshift.ll_build_jitstate_graph, []) - graph1args = [jitstate] + builder = llinterp.eval_graph(htshift.ll_make_builder_graph, []) + graph1args = [builder] residual_graph_args = [] assert len(graph1.getargs()) == 1 + len(values) for i, (v, llvalue) in enumerate(zip(graph1.getargs()[1:], values)): @@ -95,7 +94,7 @@ assert residual_v == [llvalue], "XXX for now" TYPE = htshift.originalconcretetype(v) gv_type = rgenop.constTYPE(TYPE) - gvar = llinterp.eval_graph(htshift.ll_geninputarg_graph, [jitstate, + gvar = llinterp.eval_graph(htshift.ll_geninputarg_graph, [builder, gv_type]) if i in opt_consts: # XXX what should happen here interface wise is unclear gvar = rgenop.genconst(llvalue) @@ -108,13 +107,13 @@ box = llinterp.eval_graph(ll_box_graph, [gv_type, gvar]) graph1args.append(box) residual_graph_args.append(llvalue) - startblock = llinterp.eval_graph(htshift.ll_end_setup_jitstate_graph, [jitstate]) + startblock = llinterp.eval_graph(htshift.ll_end_setup_builder_graph, [builder]) - newjitstate = llinterp.eval_graph(graph1, graph1args) - # now try to run the blocks produced by the jitstate + jitstate = llinterp.eval_graph(graph1, graph1args) r = htshift.hrtyper.getrepr(hs) llinterp.eval_graph(htshift.ll_close_jitstate_graph, [jitstate]) + # now try to run the blocks produced by the builder residual_graph = rgenop.buildgraph(startblock) insns = summary(residual_graph) res = rgenop.testgengraph(residual_graph, residual_graph_args, @@ -559,3 +558,12 @@ insns, res = timeshift(ll_function, [1], [], policy=P_NOVIRTUAL) assert res == 1 + 2 assert insns == {'int_is_true': 1, 'int_add': 1} + +def test_call_simple(): + def ll_add_one(x): + return x + 1 + def ll_function(y): + return ll_add_one(y) + insns, res = timeshift(ll_function, [5], [], policy=P_NOVIRTUAL) + assert res == 6 + assert insns == {'int_add': 1} Modified: pypy/dist/pypy/jit/timeshifter/timeshift.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/timeshift.py (original) +++ pypy/dist/pypy/jit/timeshifter/timeshift.py Sat Jul 1 17:29:12 2006 @@ -4,7 +4,7 @@ from pypy.annotation import model as annmodel from pypy.annotation import listdef, dictdef from pypy.jit.timeshifter import rvalue, oop -from pypy.jit.timeshifter.rtimeshift import JITState +from pypy.jit.timeshifter.rtimeshift import JITState, ResidualGraphBuilder from pypy.rpython import rmodel, rgenop, annlowlevel from pypy.rpython.lltypesystem import rtuple, rlist, rdict from pypy.jit.timeshifter import rtimeshift @@ -24,6 +24,7 @@ self.annhelper = annlowlevel.MixLevelHelperAnnotator(rtyper) + self.s_ResidualGraphBuilder, self.r_ResidualGraphBuilder = self.s_r_instanceof(ResidualGraphBuilder) self.s_JITState, self.r_JITState = self.s_r_instanceof(JITState) self.s_RedBox, self.r_RedBox = self.s_r_instanceof(rvalue.RedBox) self.s_OopSpecDesc, self.r_OopSpecDesc = self.s_r_instanceof( @@ -45,9 +46,9 @@ self.r_box_accum = getrepr(self.s_box_accum) self.r_box_accum.setup() - self.ll_build_jitstate_graph = self.annhelper.getgraph( - rtimeshift.ll_build_jitstate, - [], self.s_JITState) + self.ll_make_builder_graph = self.annhelper.getgraph( + rtimeshift.ll_make_builder, + [], self.s_ResidualGraphBuilder) self.ll_int_box_graph = self.annhelper.getgraph( rtimeshift.ll_int_box, [rgenop.s_ConstOrVar, rgenop.s_ConstOrVar], @@ -62,12 +63,13 @@ self.s_RedBox) self.ll_geninputarg_graph = self.annhelper.getgraph( rtimeshift.ll_geninputarg, - [self.s_JITState, annmodel.SomePtr(rgenop.CONSTORVAR)], + [self.s_ResidualGraphBuilder, annmodel.SomePtr(rgenop.CONSTORVAR)], rgenop.s_ConstOrVar) - self.ll_end_setup_jitstate_graph = self.annhelper.getgraph( - rtimeshift.ll_end_setup_jitstate, - [self.s_JITState], + self.ll_end_setup_builder_graph = self.annhelper.getgraph( + rtimeshift.ll_end_setup_builder, + [self.s_ResidualGraphBuilder], annmodel.SomePtr(rgenop.BLOCK)) + self.ll_close_jitstate_graph = self.annhelper.getgraph( rtimeshift.ll_close_jitstate, [self.s_JITState], @@ -124,16 +126,22 @@ self.dispatch_to.append((self.latestexitindex, from_dispatch)) return self.latestexitindex + def schedule_graph(self, graph): + if graph not in self.already_scheduled_graphs: + self.already_scheduled_graphs[graph] = True + self.graphs_to_timeshift.append(graph) + def timeshift(self): - # XXX in-progress: - ##for graph in self.hannotator.translator.graphs: - ## self.timeshift_graph(graph) - - # instead: - graph = self.hannotator.translator.graphs[0] - self.timeshift_graph(graph) + self.already_scheduled_graphs = {} + self.graphs_to_timeshift = [] + + self.schedule_graph(self.hannotator.translator.graphs[0]) + + while self.graphs_to_timeshift: + graph = self.graphs_to_timeshift.pop() + self.timeshift_graph(graph) - # Annotate and rType the helpers found during timeshifting + # Annotate and rtype the helpers found during timeshifting self.annhelper.finish() def timeshift_graph(self, graph): @@ -186,9 +194,27 @@ source.append(" pass") exec py.code.Source('\n'.join(source)).compile() in miniglobals clearcaches = miniglobals['clearcaches'] - self.ll_clearcaches = self.annhelper.getgraph(clearcaches, [], - annmodel.s_None) + self.c_ll_clearcaches_ptr = self.annhelper.constfunc(clearcaches, [], + annmodel.s_None) + self.insert_start_setup() + + def insert_start_setup(self): + newstartblock = self.insert_before_block(self.graph.startblock, None, closeblock=True) + v_builder = flowmodel.Variable('builder') + v_builder.concretetype = self.r_ResidualGraphBuilder.lowleveltype + v_jitstate = newstartblock.inputargs[0] + newstartblock.inputargs[0] = v_builder + llops = HintLowLevelOpList(self, None) + + llops.genop('direct_call', [self.c_ll_clearcaches_ptr]) + v_jitstate1 = llops.genmixlevelhelpercall(rtimeshift.enter_graph, + [self.s_ResidualGraphBuilder], + [v_builder], + self.s_JITState) + llops.append(flowmodel.SpaceOperation('same_as', [v_jitstate1], v_jitstate)) + newstartblock.operations = list(llops) + def insert_jitstate_arg(self, block): # pass 'jitstate' as an extra argument around the whole graph if block.operations != (): Modified: pypy/dist/pypy/jit/timeshifter/vlist.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/vlist.py (original) +++ pypy/dist/pypy/jit/timeshifter/vlist.py Sat Jul 1 17:29:12 2006 @@ -75,7 +75,7 @@ typedesc = self.typedesc boxes = self.item_boxes self.item_boxes = None - llops = rgenop.LowLevelOpBuilder(jitstate.curblock) + llops = jitstate.curbuilder gv_list = typedesc.build_newlist(llops, len(boxes)) self.ownbox.genvar = gv_list self.ownbox.content = None Modified: pypy/dist/pypy/rpython/annlowlevel.py ============================================================================== --- pypy/dist/pypy/rpython/annlowlevel.py (original) +++ pypy/dist/pypy/rpython/annlowlevel.py Sat Jul 1 17:29:12 2006 @@ -99,6 +99,8 @@ funcdesc2 = bk.getdesc(x) return pol.default_specialize(funcdesc2, args_s) + specialize__ll = default_specialize + def annotate_lowlevel_helper(annotator, ll_function, args_s, policy=None): if policy is None: policy= LowLevelAnnotatorPolicy() Modified: pypy/dist/pypy/rpython/rgenop.py ============================================================================== --- pypy/dist/pypy/rpython/rgenop.py (original) +++ pypy/dist/pypy/rpython/rgenop.py Sat Jul 1 17:29:12 2006 @@ -52,12 +52,15 @@ return res # is opname a runtime value? -def genop(blockcontainer, opname, vars, gv_RESULT_TYPE): +def genop(blockcontainer, opname, vars, resulttype): if not isinstance(opname, str): opname = LLSupport.from_rstr(opname) block = from_opaque_object(blockcontainer.obj) assert block.exits == [], "block already closed" - RESULT_TYPE = from_opaque_object(gv_RESULT_TYPE).value + if isinstance(resulttype, lltype.LowLevelType): + RESULT_TYPE = resultype + else: + RESULT_TYPE = from_opaque_object(resulttype).value opvars = _inputvars(vars) v = flowmodel.Variable() v.concretetype = RESULT_TYPE @@ -242,6 +245,8 @@ # support constants and types nullvar = lltype.nullptr(CONSTORVAR.TO) +nullblock = lltype.nullptr(BLOCK.TO) +nulllink = lltype.nullptr(LINK.TO) gv_Void = constTYPE(lltype.Void) # VARLIST @@ -322,7 +327,7 @@ genconst = staticmethod(genconst) genvoidconst = staticmethod(placeholder) - def genop(self, opname, args_gv, RESULTTYPE=lltype.Void): - gv_result_type = constTYPE(RESULTTYPE) - return genop(self.block, opname, args_gv, gv_result_type) - genop._annspecialcase_ = 'specialize:arg(3)' + def genop(self, opname, args_gv, resulttype=lltype.Void): + #gv_result_type = constTYPE(RESULTTYPE) + return genop(self.block, opname, args_gv, resulttype) + genop._annspecialcase_ = "specialize:ll" From pedronis at codespeak.net Sat Jul 1 17:32:52 2006 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Sat, 1 Jul 2006 17:32:52 +0200 (CEST) Subject: [pypy-svn] r29567 - pypy/dist/pypy/jit/timeshifter/test Message-ID: <20060701153252.4100710077@code0.codespeak.net> Author: pedronis Date: Sat Jul 1 17:32:51 2006 New Revision: 29567 Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py Log: (arre, arigo, pedronis) the refactoring is about preparation for supporting calls in the timeshifter. this skip should have been in the last checkin Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py (original) +++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py Sat Jul 1 17:32:51 2006 @@ -560,6 +560,7 @@ assert insns == {'int_is_true': 1, 'int_add': 1} def test_call_simple(): + py.test.skip("in-progress") def ll_add_one(x): return x + 1 def ll_function(y): From pedronis at codespeak.net Sat Jul 1 17:40:05 2006 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Sat, 1 Jul 2006 17:40:05 +0200 (CEST) Subject: [pypy-svn] r29568 - pypy/dist/pypy/rpython Message-ID: <20060701154005.2A21510077@code0.codespeak.net> Author: pedronis Date: Sat Jul 1 17:40:04 2006 New Revision: 29568 Modified: pypy/dist/pypy/rpython/rgenop.py Log: typo Modified: pypy/dist/pypy/rpython/rgenop.py ============================================================================== --- pypy/dist/pypy/rpython/rgenop.py (original) +++ pypy/dist/pypy/rpython/rgenop.py Sat Jul 1 17:40:04 2006 @@ -58,7 +58,7 @@ block = from_opaque_object(blockcontainer.obj) assert block.exits == [], "block already closed" if isinstance(resulttype, lltype.LowLevelType): - RESULT_TYPE = resultype + RESULT_TYPE = resulttype else: RESULT_TYPE = from_opaque_object(resulttype).value opvars = _inputvars(vars) From pedronis at codespeak.net Sat Jul 1 19:17:28 2006 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Sat, 1 Jul 2006 19:17:28 +0200 (CEST) Subject: [pypy-svn] r29571 - pypy/dist/pypy/jit/timeshifter Message-ID: <20060701171728.53FD910077@code0.codespeak.net> Author: pedronis Date: Sat Jul 1 19:17:26 2006 New Revision: 29571 Modified: pypy/dist/pypy/jit/timeshifter/timeshift.py Log: (arre, pedronis) started working on code to put the graphs in the right shape to support direct_calls Modified: pypy/dist/pypy/jit/timeshifter/timeshift.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/timeshift.py (original) +++ pypy/dist/pypy/jit/timeshifter/timeshift.py Sat Jul 1 19:17:26 2006 @@ -10,6 +10,7 @@ from pypy.jit.timeshifter import rtimeshift from pypy.jit.timeshifter.rtyper import HintRTyper, originalconcretetype from pypy.jit.timeshifter.rtyper import GreenRepr, RedRepr, HintLowLevelOpList +from pypy.translator.backendopt import support # ___________________________________________________________ @@ -151,8 +152,10 @@ entering_links = flowmodel.mkentrymap(graph) originalblocks = list(graph.iterblocks()) + timeshifted_blocks = [] for block in originalblocks: - self.timeshift_block(block) + self.timeshift_block(timeshifted_blocks, entering_links, block) + originalblocks = timeshifted_blocks returnblock = graph.returnblock # we need to get the jitstate to the before block of the return block @@ -595,9 +598,23 @@ self.block2jitstate[block] = v_jitstate return self.block2jitstate[block] - def timeshift_block(self, block): - self.getjitstate(block) # force this to be precomputed - self.hrtyper.specialize_block(block) + def timeshift_block(self, timeshifted_blocks, entering_links, block): + blocks = [block] + #i = 0 + #while i < len(block.operations): + # op = block.operations[i] + # if op.opname == 'direct_call': + # link = support.split_block_with_keepalive(block, i+1) + # block = link.target + # entering_links[block] = [link] + # blocks.append(block) + # i = 0 + # continue + # i += 1 + for block in blocks: + self.getjitstate(block) # force this to be precomputed + self.hrtyper.specialize_block(block) + timeshifted_blocks.extend(blocks) def originalconcretetype(self, var): return originalconcretetype(self.hannotator.binding(var)) From cfbolz at codespeak.net Sat Jul 1 20:58:57 2006 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sat, 1 Jul 2006 20:58:57 +0200 (CEST) Subject: [pypy-svn] r29572 - pypy/dist/pypy/module/_sre/test Message-ID: <20060701185857.0B96610077@code0.codespeak.net> Author: cfbolz Date: Sat Jul 1 20:58:54 2006 New Revision: 29572 Modified: pypy/dist/pypy/module/_sre/test/test_app_sre.py Log: it's no longer necessary so skip these tests, since the _sre implementation is now used by default Modified: pypy/dist/pypy/module/_sre/test/test_app_sre.py ============================================================================== --- pypy/dist/pypy/module/_sre/test/test_app_sre.py (original) +++ pypy/dist/pypy/module/_sre/test/test_app_sre.py Sat Jul 1 20:58:54 2006 @@ -13,15 +13,9 @@ b.s = support_test_app_sre sys.path.pop(0) -def skip_if_faked(cls): - if "_sre" not in cls.space.options.usemodules: - skip("--usemodules=_sre option not provided") - class AppTestSrePy: - setup_class = skip_if_faked - def test_magic(self): import _sre, sre_constants assert sre_constants.MAGIC == _sre.MAGIC @@ -33,8 +27,6 @@ class AppTestSrePattern: - setup_class = skip_if_faked - def test_copy(self): # copy support is disabled by default in _sre.c import re @@ -94,8 +86,6 @@ class AppTestSreMatch: - setup_class = skip_if_faked - def test_copy(self): import re # copy support is disabled by default in _sre.c @@ -201,8 +191,6 @@ class AppTestSreScanner: - setup_class = skip_if_faked - def test_scanner_attributes(self): import re p = re.compile("bla") @@ -235,7 +223,6 @@ class AppTestGetlower: def setup_class(cls): - skip_if_faked(cls) # This imports support_test_sre as the global "s" app2interp_temp(app_init_globals_hack)(cls.space) @@ -279,8 +266,6 @@ class AppTestSimpleSearches: - setup_class = skip_if_faked - def test_search_simple_literal(self): import re assert re.search("bla", "bla") @@ -461,8 +446,6 @@ class AppTestMarksStack: - setup_class = skip_if_faked - def test_mark_stack_branch(self): import re m = re.match("b(.)a|b.b", "bob") @@ -497,7 +480,6 @@ class AppTestOpcodes: def setup_class(cls): - skip_if_faked(cls) # This imports support_test_sre as the global "s" app2interp_temp(app_init_globals_hack)(cls.space) @@ -875,8 +857,6 @@ class AppTestOptimizations: """These tests try to trigger optmized edge cases.""" - setup_class = skip_if_faked - def test_match_length_optimization(self): import re assert None == re.match("bla", "blub") From cfbolz at codespeak.net Sat Jul 1 23:09:32 2006 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sat, 1 Jul 2006 23:09:32 +0200 (CEST) Subject: [pypy-svn] r29573 - pypy/extradoc/talk/ep2006 Message-ID: <20060701210932.9DB821007D@code0.codespeak.net> Author: cfbolz Date: Sat Jul 1 23:09:31 2006 New Revision: 29573 Added: pypy/extradoc/talk/ep2006/fibonacci.py pypy/extradoc/talk/ep2006/fibonacci2.py pypy/extradoc/talk/ep2006/fibonacci3.py pypy/extradoc/talk/ep2006/fibonacci4.py pypy/extradoc/talk/ep2006/fork_demo.py pypy/extradoc/talk/ep2006/usecases-planning.txt Log: (arigo, cfbolz): plans for the ep talk. seems way to much material for half an hour :-( Added: pypy/extradoc/talk/ep2006/fibonacci.py ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2006/fibonacci.py Sat Jul 1 23:09:31 2006 @@ -0,0 +1,32 @@ +""" +This is a typical Functional Programming Languages demo, computing the +Fibonacci sequence by using an infinite lazy linked list. +""" + +try: + newvar # only available in 'py.py -o logic' +except NameError: + print __doc__ + raise SystemExit(2) + +# ____________________________________________________________ + +Fibonacci = (1, (1, newvar())) + +def generate(): + lst = Fibonacci + while 1: + (a, (b, tail)) = lst + wait_needed(tail) + newtail = newvar() + unify(tail, (a+b, newtail)) + lst = lst[1] + +def display(limit): + cur = Fibonacci + for i in range(limit): + print cur[0] + cur = cur[1] + +uthread(generate) +uthread(display, 15) Added: pypy/extradoc/talk/ep2006/fibonacci2.py ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2006/fibonacci2.py Sat Jul 1 23:09:31 2006 @@ -0,0 +1,40 @@ +""" +This is a typical Functional Programming Languages demo, computing the +Fibonacci sequence by using an infinite lazy linked list. +""" + +try: + newvar # only available in 'py.py -o logic' +except NameError: + print __doc__ + raise SystemExit(2) + +# ____________________________________________________________ + +class Node: + def __init__(self, head, tail): + self.head = head + self.tail = tail + +Fibonacci = Node(1, Node(1, newvar())) + +def generate(): + lst = Fibonacci + while 1: + a = newvar() + b = newvar() + tail = newvar() + unify(lst, Node(a, Node(b, tail))) + wait_needed(tail) + newtail = newvar() + bind(tail, Node(a+b, newtail)) + lst = lst.tail + +def display(limit): + cur = Fibonacci + for i in range(limit): + print cur.head + cur = cur.tail + +uthread(generate) +uthread(display, 15) Added: pypy/extradoc/talk/ep2006/fibonacci3.py ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2006/fibonacci3.py Sat Jul 1 23:09:31 2006 @@ -0,0 +1,39 @@ +""" +This is a typical Functional Programming Languages demo, computing the +Fibonacci sequence by using an infinite lazy linked list. +""" + +try: + newvar # only available in 'py.py -o logic' +except NameError: + print __doc__ + raise SystemExit(2) + +# ____________________________________________________________ + +class Node: + def __init__(self, head, tail): + self.head = head + self.tail = tail + +Fibonacci = Node(1, Node(1, newvar())) + +def generate(): + lst = Fibonacci + while 1: + a = newvar() + b = newvar() + tail = newvar() + unify(lst, Node(a, Node(b, tail))) + wait_needed(tail) + unify(lst, Node(a, Node(b, Node(a+b, newvar())))) + lst = lst.tail + +def display(limit): + cur = Fibonacci + for i in range(limit): + print cur.head + cur = cur.tail + +uthread(generate) +uthread(display, 15) Added: pypy/extradoc/talk/ep2006/fibonacci4.py ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2006/fibonacci4.py Sat Jul 1 23:09:31 2006 @@ -0,0 +1,37 @@ +""" +This is a typical Functional Programming Languages demo, computing the +Fibonacci sequence by using an infinite lazy linked list. +""" + +try: + newvar # only available in 'py.py -o logic' +except NameError: + print __doc__ + raise SystemExit(2) + +# ____________________________________________________________ + +class Node: + def __init__(self, head, tail): + self.head = head + self.tail = tail + +Fibonacci = Node(1, Node(1, newvar())) + +def generate(): + lst = Fibonacci + while 1: + a = lst.head + b = lst.tail.head + wait_needed(lst.tail.tail) + unify(lst, Node(a, Node(b, Node(a+b, newvar())))) + lst = lst.tail + +def display(limit): + cur = Fibonacci + for i in range(limit): + print cur.head + cur = cur.tail + +uthread(generate) +uthread(display, 15) Added: pypy/extradoc/talk/ep2006/fork_demo.py ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2006/fork_demo.py Sat Jul 1 23:09:31 2006 @@ -0,0 +1,70 @@ +choicepoints = [] + +def choice(): + child = fork() + if child is not None: + choicepoints.append(child) + return 0 + else: + return 1 + +class Fail(Exception): + pass + + + +invalid_branches = dict.fromkeys([ + (0, 0, 0), + (0, 0, 1), + (0, 1), + (1, 0, 0, 0), + (1, 0, 0, 0, 0), + (1, 0, 0, 0, 1), + (1, 0, 1), + (1, 1, 0, 0), + ]) + +def search(): + path = [] + for i in range(10): + path.append(choice()) + if tuple(path) in invalid_branches: + raise Fail + return path + +# ^ ^ ^ that's quite cool code I think :-) +# yes, I agree :-) +# much easier than doing it by hand + + + +# hum, not really RPython, the dict with var-sized tuples +# hum +# we could use lists +# and use a list of lists insteaed of a dict +# good enough +# I can prepare that +# ok, great +# note that fork is a class method or something +# ah, I see +# will just try +# also, I was about to write something like: + +search_coro = ... +choicepoints.append(search_coro) + +while choicepoints: + try: + res = choicepoints.pop().switch() + except Fail: + pass + else: + print "found it!", res + +# is this searching for only one? then we will get (0, ) +# no, answers must be 10 numbers long +# ah, I see +# also if we don't add a break after the print, it will +# find all solutions +# oh, right + Added: pypy/extradoc/talk/ep2006/usecases-planning.txt ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2006/usecases-planning.txt Sat Jul 1 23:09:31 2006 @@ -0,0 +1,39 @@ +What can PyPy do for you? +========================= + +Peek under the hood +------------------- + + - sys.pypy_repr() with small ints + +Stackless stuff +--------------- + + - lightweight threadlets similar to what stackless python provides + + - tasklet cloning + + - gc: performance/memory/feature tradeoffs: e.g. (check if and) show an + example where a refcounting pypy uses less Unix process memory than a Boehm + one (but of course the latter is faster). Mention that tasklet cloning + requires a gc which is (ATM) a bit slower. + +Lazy stuff +---------- + + - lazy evaluation with the thunk object space + try running demo/sharedref on pypy-c-thunk. + + - Oz-like dataflow variables with the logic object space + py.py -o logic --usemodules=_stackless fibonacci{,2,3,4}.py + +Compiling +--------- + + - algo example, e.g. sieve of eratosthenes + - ctypes example + - Writing compatible extension modules for PyPy and CPython with the PyPy + extension compiler + + - The Javascript backend and its uses + From hpk at codespeak.net Sun Jul 2 08:08:28 2006 From: hpk at codespeak.net (hpk at codespeak.net) Date: Sun, 2 Jul 2006 08:08:28 +0200 (CEST) Subject: [pypy-svn] r29574 - pypy/dist/pypy/doc Message-ID: <20060702060828.DC01F1007F@code0.codespeak.net> Author: hpk Date: Sun Jul 2 08:08:26 2006 New Revision: 29574 Modified: pypy/dist/pypy/doc/news.txt Log: fixed typo (IMO) Modified: pypy/dist/pypy/doc/news.txt ============================================================================== --- pypy/dist/pypy/doc/news.txt (original) +++ pypy/dist/pypy/doc/news.txt Sun Jul 2 08:08:26 2006 @@ -15,7 +15,7 @@ .. _`iCalendar format`: webcal://pypycal.sabi.net///calendars/PyPy.ics .. _eventhistory: eventhistory.html -Release of PyPy video documentations +Release of PyPy video documentation ================================================================== The PyPy team is happy to announce that the first bunch of PyPy videos From cfbolz at codespeak.net Sun Jul 2 09:44:25 2006 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sun, 2 Jul 2006 09:44:25 +0200 (CEST) Subject: [pypy-svn] r29575 - pypy/extradoc/talk/ep2006 Message-ID: <20060702074425.61C5210081@code0.codespeak.net> Author: cfbolz Date: Sun Jul 2 09:44:24 2006 New Revision: 29575 Added: pypy/extradoc/talk/ep2006/fork_demo_translate.py Log: attempt at making the fork_demo translatable. becomes obscure and produces strange results Added: pypy/extradoc/talk/ep2006/fork_demo_translate.py ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2006/fork_demo_translate.py Sun Jul 2 09:44:24 2006 @@ -0,0 +1,77 @@ +from pypy.module._stackless import interp_coroutine +from pypy.module._stackless.interp_clonable import ClonableCoroutine, fork +import os + +class ChoicePointHolder(object): + def __init__(self): + self.choicepoints = [] + + def next_choice(self): + return self.choicepoints.pop() + + def choice(self): + os.write(1, "choice\n") + child = fork() + if child is not None: + self.choicepoints.append(child) + return 0 + else: + return 1 + + def add(self, choice): + self.choicepoints.append(choice) + + def more_choices(self): + return bool(self.choicepoints) + +choicepoints = ChoicePointHolder() + +invalid_branches = [ + [0, 0, 0], + [0, 0, 1], + [0, 1], + [1, 0, 0, 0], + [1, 0, 0, 0, 0], + [1, 0, 0, 0, 1], + [1, 0, 1], + [1, 1, 0, 0], + ] + +class SearchTask(interp_coroutine.AbstractThunk): + def call(self): + try: + path = [] + for i in range(10): + path = path[:] + path = path + [choicepoints.choice()] + for invalid_branch in invalid_branches: + if len(path) < len(invalid_branches): + continue + for i in range(len(invalid_branch)): + if path[i] != invalid_branch[i]: + break + else: + return + os.write(1, "found a solution!: ") + os.write(1, "[" + ", ".join([str(i) for i in path]) + "]\n") + except Exception, e: + os.write(1, "exception raised :-(") + +# ^ ^ ^ that's quite cool code I think :-) +# yes, I agree :-) +# much easier than doing it by hand + + +def search_all(argv): + search_coro = ClonableCoroutine() + search_coro.bind(SearchTask()) + choicepoints.add(search_coro) + + os.write(1, "starting\n") + while choicepoints.more_choices(): + searcher = choicepoints.next_choice() + searcher.switch() + return 0 + +def target(*args): + return search_all, None From cfbolz at codespeak.net Sun Jul 2 09:47:26 2006 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sun, 2 Jul 2006 09:47:26 +0200 (CEST) Subject: [pypy-svn] r29576 - pypy/extradoc/talk/ep2006 Message-ID: <20060702074726.2BAE010082@code0.codespeak.net> Author: cfbolz Date: Sun Jul 2 09:47:25 2006 New Revision: 29576 Modified: pypy/extradoc/talk/ep2006/usecases-planning.txt Log: example session with small ints Modified: pypy/extradoc/talk/ep2006/usecases-planning.txt ============================================================================== --- pypy/extradoc/talk/ep2006/usecases-planning.txt (original) +++ pypy/extradoc/talk/ep2006/usecases-planning.txt Sun Jul 2 09:47:25 2006 @@ -4,7 +4,19 @@ Peek under the hood ------------------- - - sys.pypy_repr() with small ints + - sys.pypy_repr() with small ints:: + + >>>> import sys + >>>> sys.pypy_repr(1) + '' + >>>> sys.pypy_repr(42) + '' + >>>> sys.pypy_repr(sys.maxint) + '' + >>>> sys.pypy_repr(sys.maxint / 2) + '' + >>>> sys.pypy_repr(sys.maxint / 2 + 1) + '' Stackless stuff --------------- From cfbolz at codespeak.net Sun Jul 2 10:05:56 2006 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sun, 2 Jul 2006 10:05:56 +0200 (CEST) Subject: [pypy-svn] r29577 - pypy/dist/pypy/module/_demo Message-ID: <20060702080556.35CEF1007F@code0.codespeak.net> Author: cfbolz Date: Sun Jul 2 10:05:53 2006 New Revision: 29577 Modified: pypy/dist/pypy/module/_demo/__init__.py pypy/dist/pypy/module/_demo/demo.py Log: add a sieve of eratosthenes implementation to the _demo module Modified: pypy/dist/pypy/module/_demo/__init__.py ============================================================================== --- pypy/dist/pypy/module/_demo/__init__.py (original) +++ pypy/dist/pypy/module/_demo/__init__.py Sun Jul 2 10:05:53 2006 @@ -5,6 +5,7 @@ interpleveldefs = { 'measuretime' : 'demo.measuretime', + 'sieve' : 'demo.sieve', } appleveldefs = { Modified: pypy/dist/pypy/module/_demo/demo.py ============================================================================== --- pypy/dist/pypy/module/_demo/demo.py (original) +++ pypy/dist/pypy/module/_demo/demo.py Sun Jul 2 10:05:53 2006 @@ -2,7 +2,7 @@ from pypy.interpreter.baseobjspace import ObjSpace, W_Root from pypy.rpython.rctypes.tool import ctypes_platform from pypy.rpython.rctypes.tool.libc import libc -import sys +import sys, math from ctypes import * time_t = ctypes_platform.getsimpletype('time_t', '#include ', c_long) @@ -27,3 +27,22 @@ endtime = time(None) return space.wrap(endtime - starttime) measuretime.unwrap_spec = [ObjSpace, int, W_Root] + +def sieve(space, n): + lst = range(2, n + 1) + head = 0 + while 1: + first = lst[head] + if first > math.sqrt(n) + 1: + lst_w = [space.newint(i) for i in range(n)] + return space.newlist(lst_w) + newlst = [] + for element in lst: + if element <= first: + newlst.append(element) + elif element % first != 0: + newlst.append(element) + lst = newlst + head += 1 +sieve.unwrap_spec = [ObjSpace, int] + From arigo at codespeak.net Sun Jul 2 10:40:28 2006 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sun, 2 Jul 2006 10:40:28 +0200 (CEST) Subject: [pypy-svn] r29578 - in pypy/dist/pypy/rpython: . test Message-ID: <20060702084028.316531007F@code0.codespeak.net> Author: arigo Date: Sun Jul 2 10:40:26 2006 New Revision: 29578 Modified: pypy/dist/pypy/rpython/rlist.py pypy/dist/pypy/rpython/test/test_rlist.py Log: get_ll_eq_function() for lists. This is to support things like 'list1 in list2'. Modified: pypy/dist/pypy/rpython/rlist.py ============================================================================== --- pypy/dist/pypy/rpython/rlist.py (original) +++ pypy/dist/pypy/rpython/rlist.py Sun Jul 2 10:40:26 2006 @@ -35,6 +35,7 @@ class AbstractBaseListRepr(Repr): + eq_func_cache = None def recast(self, llops, v): return llops.convertvar(v, self.item_repr, self.external_item_repr) @@ -91,6 +92,17 @@ hop.exception_is_here() return hop.gendirectcall(ll_listindex, v_lst, v_value, self.get_eqfunc()) + def get_ll_eq_function(self): + result = self.eq_func_cache + if result is not None: + return result + def list_eq(l1, l2): + return ll_listeq(l1, l2, item_eq_func) + self.eq_func_cache = list_eq + # ^^^ do this first, before item_repr.get_ll_eq_function() + item_eq_func = self.item_repr.get_ll_eq_function() + return list_eq + class AbstractListRepr(AbstractBaseListRepr): Modified: pypy/dist/pypy/rpython/test/test_rlist.py ============================================================================== --- pypy/dist/pypy/rpython/test/test_rlist.py (original) +++ pypy/dist/pypy/rpython/test/test_rlist.py Sun Jul 2 10:40:26 2006 @@ -1015,6 +1015,14 @@ res = self.interpret(g, [3]) assert res == 77 + def test_list_equality(self): + def dummyfn(n): + lst = [12] * n + assert lst == [12, 12, 12] + lst2 = [[12, 34], [5], [], [12, 12, 12], [5]] + assert lst in lst2 + self.interpret(dummyfn, [3]) + class TestLLtype(BaseTestRlist, LLRtypeMixin): rlist = ll_rlist From arigo at codespeak.net Sun Jul 2 11:21:07 2006 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sun, 2 Jul 2006 11:21:07 +0200 (CEST) Subject: [pypy-svn] r29579 - pypy/extradoc/talk/ep2006 Message-ID: <20060702092107.8C3401007D@code0.codespeak.net> Author: arigo Date: Sun Jul 2 11:21:06 2006 New Revision: 29579 Modified: pypy/extradoc/talk/ep2006/fork_demo_translate.py Log: A version with a simpler "user" code part. This "should work" but doesn't. Modified: pypy/extradoc/talk/ep2006/fork_demo_translate.py ============================================================================== --- pypy/extradoc/talk/ep2006/fork_demo_translate.py (original) +++ pypy/extradoc/talk/ep2006/fork_demo_translate.py Sun Jul 2 11:21:06 2006 @@ -1,30 +1,35 @@ -from pypy.module._stackless import interp_coroutine -from pypy.module._stackless.interp_clonable import ClonableCoroutine, fork +from pypy.module._stackless.interp_coroutine import AbstractThunk +from pypy.module._stackless.interp_clonable import ClonableCoroutine import os class ChoicePointHolder(object): def __init__(self): self.choicepoints = [] + self.clone_me = False + self.answer = 0 def next_choice(self): return self.choicepoints.pop() - def choice(self): - os.write(1, "choice\n") - child = fork() - if child is not None: - self.choicepoints.append(child) - return 0 - else: - return 1 - - def add(self, choice): - self.choicepoints.append(choice) + def add(self, choice, answer=0): + self.choicepoints.append((choice, answer)) def more_choices(self): return bool(self.choicepoints) + def choice(self): + os.write(1, "choice\n") + self.clone_me = True + g_main.switch() + return self.answer + choicepoints = ChoicePointHolder() +g_main = ClonableCoroutine.getmain() + +class Fail(Exception): + pass + +# ____________________________________________________________ invalid_branches = [ [0, 0, 0], @@ -37,29 +42,17 @@ [1, 1, 0, 0], ] -class SearchTask(interp_coroutine.AbstractThunk): +class SearchTask(AbstractThunk): def call(self): - try: - path = [] - for i in range(10): - path = path[:] - path = path + [choicepoints.choice()] - for invalid_branch in invalid_branches: - if len(path) < len(invalid_branches): - continue - for i in range(len(invalid_branch)): - if path[i] != invalid_branch[i]: - break - else: - return - os.write(1, "found a solution!: ") - os.write(1, "[" + ", ".join([str(i) for i in path]) + "]\n") - except Exception, e: - os.write(1, "exception raised :-(") - -# ^ ^ ^ that's quite cool code I think :-) -# yes, I agree :-) -# much easier than doing it by hand + path = [] + for i in range(10): + path.append(choicepoints.choice()) + os.write(1, "trying: %s" % path) + if path in invalid_branches: + os.write(1, " NO\n") + raise Fail + os.write(1, " yes\n") + os.write(1, "found a solution: %s\n" % path) def search_all(argv): @@ -69,8 +62,18 @@ os.write(1, "starting\n") while choicepoints.more_choices(): - searcher = choicepoints.next_choice() - searcher.switch() + searcher, nextvalue = choicepoints.next_choice() + choicepoints.clone_me = False + choicepoints.answer = nextvalue + try: + searcher.switch() + except Fail: + assert not choicepoints.clone_me + else: + if choicepoints.clone_me: + searcher2 = searcher.clone() + choicepoints.add(searcher, 1) + choicepoints.add(searcher2, 0) return 0 def target(*args): From ac at codespeak.net Sun Jul 2 11:27:35 2006 From: ac at codespeak.net (ac at codespeak.net) Date: Sun, 2 Jul 2006 11:27:35 +0200 (CEST) Subject: [pypy-svn] r29580 - in pypy/dist/pypy: jit/codegen/llvm rpython rpython/memory translator translator/backendopt translator/c translator/llvm translator/llvm/backendopt translator/stackless translator/test Message-ID: <20060702092735.036EF1007E@code0.codespeak.net> Author: ac Date: Sun Jul 2 11:27:34 2006 New Revision: 29580 Modified: pypy/dist/pypy/jit/codegen/llvm/jitcode.py pypy/dist/pypy/rpython/memory/gctransform.py pypy/dist/pypy/rpython/rtyper.py pypy/dist/pypy/translator/backendopt/propagate.py pypy/dist/pypy/translator/c/exceptiontransform.py pypy/dist/pypy/translator/llvm/backendopt/exception.py pypy/dist/pypy/translator/llvm/funcnode.py pypy/dist/pypy/translator/stackless/transform.py pypy/dist/pypy/translator/test/test_unsimplify.py pypy/dist/pypy/translator/unsimplify.py Log: (pedrnis, arre) Refactor copyvar to take an annotator instead of a translator adjusting callers as needed. Modified: pypy/dist/pypy/jit/codegen/llvm/jitcode.py ============================================================================== --- pypy/dist/pypy/jit/codegen/llvm/jitcode.py (original) +++ pypy/dist/pypy/jit/codegen/llvm/jitcode.py Sun Jul 2 11:27:34 2006 @@ -52,7 +52,7 @@ remove_same_as(graph) simplify.eliminate_empty_blocks(graph) simplify.transform_dead_op_vars(graph, translator) - remove_double_links(translator, graph) + remove_double_links(None, graph) #translator.checkgraph(graph) def codegen(self, graph): Modified: pypy/dist/pypy/rpython/memory/gctransform.py ============================================================================== --- pypy/dist/pypy/rpython/memory/gctransform.py (original) +++ pypy/dist/pypy/rpython/memory/gctransform.py Sun Jul 2 11:27:34 2006 @@ -81,7 +81,7 @@ # for sanity, we need an empty block at the start of the graph if not starts_with_empty_block(graph): - insert_empty_startblock(self.translator, graph) + insert_empty_startblock(self.translator.annotator, graph) is_borrowed = self.compute_borrowed_vars(graph) for block in graph.iterblocks(): @@ -97,7 +97,7 @@ if link.prevblock.exitswitch is None: link.prevblock.operations.extend(newops) else: - insert_empty_block(self.translator, link, newops) + insert_empty_block(self.translator.annotator, link, newops) # remove the empty block at the start of the graph, which should # still be empty (but let's check) Modified: pypy/dist/pypy/rpython/rtyper.py ============================================================================== --- pypy/dist/pypy/rpython/rtyper.py (original) +++ pypy/dist/pypy/rpython/rtyper.py Sun Jul 2 11:27:34 2006 @@ -363,7 +363,7 @@ assert 0 <= pos < len(newops) - 1 extraops = block.operations[pos+1:] del block.operations[pos+1:] - extrablock = insert_empty_block(self.annotator.translator, + extrablock = insert_empty_block(self.annotator, noexclink, newops = extraops) @@ -439,7 +439,7 @@ # cannot insert conversion operations around a single # link, unless it is the only exit of this block. # create a new block along the link... - newblock = insert_empty_block(self.annotator.translator, + newblock = insert_empty_block(self.annotator, link, # ...and store the conversions there. newops=newops) Modified: pypy/dist/pypy/translator/backendopt/propagate.py ============================================================================== --- pypy/dist/pypy/translator/backendopt/propagate.py (original) +++ pypy/dist/pypy/translator/backendopt/propagate.py Sun Jul 2 11:27:34 2006 @@ -296,7 +296,7 @@ return None if isinstance(var, Constant): return var - result = copyvar(translator, var) + result = copyvar(None, var) vars_to_newvars[var] = result return result newops = [] Modified: pypy/dist/pypy/translator/c/exceptiontransform.py ============================================================================== --- pypy/dist/pypy/translator/c/exceptiontransform.py (original) +++ pypy/dist/pypy/translator/c/exceptiontransform.py Sun Jul 2 11:27:34 2006 @@ -1,5 +1,5 @@ from pypy.translator.simplify import join_blocks, cleanup_graph -from pypy.translator.unsimplify import copyvar, split_block +from pypy.translator.unsimplify import copyvar from pypy.translator.backendopt import canraise, inline, support, removenoops from pypy.objspace.flow.model import Block, Constant, Variable, Link, \ c_last_exception, SpaceOperation, checkgraph, FunctionGraph @@ -233,7 +233,7 @@ inlined, the correct exception matching blocks are produced.""" # XXX slightly annoying: construct a graph by hand # but better than the alternative - result = copyvar(self.translator, op.result) + result = copyvar(None, op.result) opargs = [] inputargs = [] callargs = [] Modified: pypy/dist/pypy/translator/llvm/backendopt/exception.py ============================================================================== --- pypy/dist/pypy/translator/llvm/backendopt/exception.py (original) +++ pypy/dist/pypy/translator/llvm/backendopt/exception.py Sun Jul 2 11:27:34 2006 @@ -32,7 +32,7 @@ continue n_calls_patched += 1 - split_block(translator, block, i+1) + split_block(translator.annotator, block, i+1) res = Variable() res.concretetype = Bool Modified: pypy/dist/pypy/translator/llvm/funcnode.py ============================================================================== --- pypy/dist/pypy/translator/llvm/funcnode.py (original) +++ pypy/dist/pypy/translator/llvm/funcnode.py Sun Jul 2 11:27:34 2006 @@ -73,7 +73,7 @@ def post_setup_transform(self): #self.db.exceptionpolicy.transform(self.db.translator, self.graph) - remove_double_links(self.db.translator, self.graph) + remove_double_links(self.db.translator.annotator, self.graph) def writedecl(self, codewriter): codewriter.declare(self.getdecl()) Modified: pypy/dist/pypy/translator/stackless/transform.py ============================================================================== --- pypy/dist/pypy/translator/stackless/transform.py (original) +++ pypy/dist/pypy/translator/stackless/transform.py Sun Jul 2 11:27:34 2006 @@ -399,7 +399,7 @@ def insert_resume_handling(self, graph): old_start_block = graph.startblock - newinputargs = [unsimplify.copyvar(self.translator, v) + newinputargs = [unsimplify.copyvar(self.translator.annotator, v) for v in old_start_block.inputargs] new_start_block = model.Block(newinputargs) var_resume_state = varoftype(lltype.Signed) Modified: pypy/dist/pypy/translator/test/test_unsimplify.py ============================================================================== --- pypy/dist/pypy/translator/test/test_unsimplify.py (original) +++ pypy/dist/pypy/translator/test/test_unsimplify.py Sun Jul 2 11:27:34 2006 @@ -16,7 +16,7 @@ w = x * y return z + w graph, t = translate(f, [int, int]) - split_block(t, graph.startblock, i) + split_block(t.annotator, graph.startblock, i) checkgraph(graph) interp = LLInterpreter(t.rtyper) result = interp.eval_graph(graph, [1, 2]) @@ -30,7 +30,7 @@ else: return y + 2 graph, t = translate(f, [int, int]) - split_block(t, graph.startblock, i) + split_block(t.annotator, graph.startblock, i) checkgraph(graph) interp = LLInterpreter(t.rtyper) result = interp.eval_graph(graph, [-12, 2]) @@ -56,7 +56,7 @@ return 1 return x graph, t = translate(catches, [int]) - split_block(t, graph.startblock, i) + split_block(t.annotator, graph.startblock, i) checkgraph(graph) interp = LLInterpreter(t.rtyper) result = interp.eval_graph(graph, [0]) Modified: pypy/dist/pypy/translator/unsimplify.py ============================================================================== --- pypy/dist/pypy/translator/unsimplify.py (original) +++ pypy/dist/pypy/translator/unsimplify.py Sun Jul 2 11:27:34 2006 @@ -1,18 +1,16 @@ from pypy.objspace.flow.model import * -def copyvar(translator, v): +def copyvar(annotator, v): """Make a copy of the Variable v, preserving annotations and concretetype.""" assert isinstance(v, Variable) newvar = Variable(v) - if translator is not None: - annotator = translator.annotator - if annotator is not None and v in annotator.bindings: - annotator.transfer_binding(newvar, v) + if annotator is not None and v in annotator.bindings: + annotator.transfer_binding(newvar, v) if hasattr(v, 'concretetype'): newvar.concretetype = v.concretetype return newvar -def insert_empty_block(translator, link, newops=[]): +def insert_empty_block(annotator, link, newops=[]): """Insert and return a new block along the given link.""" vars = {} for v in link.args: @@ -26,7 +24,7 @@ vars = [v for v, keep in vars.items() if keep] mapping = {} for v in vars: - mapping[v] = copyvar(translator, v) + mapping[v] = copyvar(annotator, v) newblock = Block(vars) newblock.operations.extend(newops) newblock.closeblock(Link(link.args, link.target)) @@ -35,8 +33,8 @@ link.target = newblock return newblock -def insert_empty_startblock(translator, graph): - vars = [copyvar(translator, v) for v in graph.startblock.inputargs] +def insert_empty_startblock(annotator, graph): + vars = [copyvar(annotator, v) for v in graph.startblock.inputargs] newblock = Block(vars) newblock.closeblock(Link(vars, graph.startblock)) graph.startblock.isstartblock = False @@ -53,7 +51,7 @@ graph.startblock = graph.startblock.exits[0].target graph.startblock.isstartblock = True -def split_block(translator, block, index): +def split_block(annotator, block, index): """return a link where prevblock is the block leading up but excluding the index'th operation and target is a new block with the neccessary variables passed on. NOTE: if you call this after rtyping, you WILL need to worry @@ -74,7 +72,7 @@ if var in vars_produced_in_new_block: return var if var not in varmap: - varmap[var] = copyvar(translator, var) + varmap[var] = copyvar(annotator, var) return varmap[var] moved_operations = block.operations[index:] new_moved_ops = [] @@ -111,7 +109,7 @@ block.exc_handler = False return link -def remove_direct_loops(translator, graph): +def remove_direct_loops(annotator, graph): """This is useful for code generators: it ensures that no link has common input and output variables, which could occur if a block's exit points back directly to the same block. It allows code generators to be @@ -119,10 +117,10 @@ variables when generating a sequence of assignments.""" def visit(link): if isinstance(link, Link) and link.prevblock is link.target: - insert_empty_block(translator, link) + insert_empty_block(annotator, link) traverse(visit, graph) -def remove_double_links(translator, graph): +def remove_double_links(annotator, graph): """This can be useful for code generators: it ensures that no block has more than one incoming links from one and the same other block. It allows argument passing along links to be implemented with phi nodes since the @@ -137,5 +135,5 @@ double_links.append(link) seen[link.target] = True for link in double_links: - insert_empty_block(translator, link) + insert_empty_block(annotator, link) traverse(visit, graph) From mwh at codespeak.net Sun Jul 2 11:41:51 2006 From: mwh at codespeak.net (mwh at codespeak.net) Date: Sun, 2 Jul 2006 11:41:51 +0200 (CEST) Subject: [pypy-svn] r29581 - in pypy/extradoc/talk/ep2006: . intro.key intro.key/Contents intro.key/thumbs Message-ID: <20060702094151.E4C671007E@code0.codespeak.net> Author: mwh Date: Sun Jul 2 11:41:16 2006 New Revision: 29581 Added: pypy/extradoc/talk/ep2006/intro.key/ pypy/extradoc/talk/ep2006/intro.key/.typeAttributes.dict pypy/extradoc/talk/ep2006/intro.key/Contents/ pypy/extradoc/talk/ep2006/intro.key/Contents/PkgInfo pypy/extradoc/talk/ep2006/intro.key/White_photo-bullets.pdf (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/White_photo-h.pdf pypy/extradoc/talk/ep2006/intro.key/White_photo-v.pdf (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/index.apxl.gz (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/py-web1.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/ pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-0.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-10.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-11.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-12.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-13.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-14.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-15.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-16.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-17.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-28.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-33.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-4.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-7.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-9.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st0-1.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st1-1.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st12-1.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st12-2.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st2.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st21.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st22.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st23.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st25.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st26.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st28.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st3-1.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st3-2.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st3-3.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st3-4.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st3-5.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st3.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st30.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st31.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st32-1.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st32-3.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st32-4.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st32-5.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st32.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st4.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st5.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st6.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st7-1.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st7-3.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st7-5.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st7-6.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st7-7.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st7-8.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/thumbs/st7.tiff (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/tile_paper_blue.jpg (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/tile_paper_gray.jpg (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/tile_paper_green.jpg (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/tile_paper_purple.jpg (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/tile_paper_red.jpg (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/tile_paper_yellow.jpg (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/zban.png (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/zor.png (contents, props changed) pypy/extradoc/talk/ep2006/intro.key/zpeach.png (contents, props changed) pypy/extradoc/talk/ep2006/intro.pdf Log: first cut at my ep talk, this is just my accu talk chopped down by a few slides and with the status updated somewhat Added: pypy/extradoc/talk/ep2006/intro.key/.typeAttributes.dict ============================================================================== Added: pypy/extradoc/talk/ep2006/intro.key/Contents/PkgInfo ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2006/intro.key/Contents/PkgInfo Sun Jul 2 11:41:16 2006 @@ -0,0 +1 @@ +???????? \ No newline at end of file Added: pypy/extradoc/talk/ep2006/intro.key/White_photo-bullets.pdf ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/White_photo-h.pdf ============================================================================== Files (empty file) and pypy/extradoc/talk/ep2006/intro.key/White_photo-h.pdf Sun Jul 2 11:41:16 2006 differ Added: pypy/extradoc/talk/ep2006/intro.key/White_photo-v.pdf ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/index.apxl.gz ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/py-web1.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-0.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-10.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-11.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-12.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-13.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-14.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-15.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-16.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-17.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-28.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-33.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-4.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-7.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/mt0-9.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st0-1.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st1-1.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st12-1.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st12-2.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st2.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st21.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st22.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st23.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st25.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st26.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st28.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st3-1.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st3-2.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st3-3.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st3-4.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st3-5.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st3.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st30.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st31.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st32-1.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st32-3.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st32-4.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st32-5.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st32.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st4.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st5.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st6.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st7-1.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st7-3.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st7-5.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st7-6.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st7-7.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st7-8.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/thumbs/st7.tiff ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/tile_paper_blue.jpg ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/tile_paper_gray.jpg ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/tile_paper_green.jpg ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/tile_paper_purple.jpg ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/tile_paper_red.jpg ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/tile_paper_yellow.jpg ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/zban.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/zor.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.key/zpeach.png ============================================================================== Binary file. No diff available. Added: pypy/extradoc/talk/ep2006/intro.pdf ============================================================================== Files (empty file) and pypy/extradoc/talk/ep2006/intro.pdf Sun Jul 2 11:41:16 2006 differ From arigo at codespeak.net Sun Jul 2 16:13:18 2006 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sun, 2 Jul 2006 16:13:18 +0200 (CEST) Subject: [pypy-svn] r29588 - in pypy/dist/pypy/rpython: . lltypesystem test Message-ID: <20060702141318.C67AA1007E@code0.codespeak.net> Author: arigo Date: Sun Jul 2 16:13:17 2006 New Revision: 29588 Modified: pypy/dist/pypy/rpython/lltypesystem/rtuple.py pypy/dist/pypy/rpython/rstr.py pypy/dist/pypy/rpython/test/test_rtuple.py Log: * Support ("%s" % whatever) in RPython, in addition to ("%s" % (whatever,)) * Mark tuple GcStructs as immutable. Modified: pypy/dist/pypy/rpython/lltypesystem/rtuple.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/rtuple.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/rtuple.py Sun Jul 2 16:13:17 2006 @@ -21,7 +21,10 @@ def __init__(self, rtyper, items_r): AbstractTupleRepr.__init__(self, rtyper, items_r) fields = zip(self.fieldnames, self.lltypes) - self.lowleveltype = Ptr(GcStruct('tuple%d' % len(self.items_r), *fields)) + kwds = {'hints': {'immutable': True}} + self.lowleveltype = Ptr(GcStruct('tuple%d' % len(self.items_r), + *fields, + **kwds)) def newtuple(cls, llops, r_tuple, items_v): # items_v should have the lowleveltype of the internal reprs Modified: pypy/dist/pypy/rpython/rstr.py ============================================================================== --- pypy/dist/pypy/rpython/rstr.py (original) +++ pypy/dist/pypy/rpython/rstr.py Sun Jul 2 16:13:17 2006 @@ -203,6 +203,14 @@ def ll_str(self, s): return s + +class __extend__(pairtype(AbstractStringRepr, Repr)): + def rtype_mod((r_str, _), hop): + # for the case where the 2nd argument is a tuple, see the + # overriding rtype_mod() below + return r_str.ll.do_stringformat(hop, [(hop.args_v[1], hop.args_r[1])]) + + class __extend__(pairtype(AbstractStringRepr, IntegerRepr)): def rtype_getitem((r_str, r_int), hop): string_repr = hop.rtyper.type_system.rstr.string_repr @@ -220,9 +228,6 @@ hop.exception_is_here() return hop.gendirectcall(llfn, v_str, v_index) - def rtype_mod((r_str, r_int), hop): - return r_str.ll.do_stringformat(hop, [(hop.args_v[1], hop.args_r[1])]) - class __extend__(pairtype(AbstractStringRepr, AbstractSliceRepr)): @@ -288,9 +293,6 @@ return hop.genop('int_gt', [vres, hop.inputconst(Signed, 0)], resulttype=Bool) - def rtype_mod((r_str1, r_str2), hop): - return r_str1.ll.do_stringformat(hop, [(hop.args_v[1], hop.args_r[1])]) - class __extend__(pairtype(AbstractStringRepr, AbstractCharRepr)): def rtype_contains((r_str, r_chr), hop): rstr = hop.rtyper.type_system.rstr Modified: pypy/dist/pypy/rpython/test/test_rtuple.py ============================================================================== --- pypy/dist/pypy/rpython/test/test_rtuple.py (original) +++ pypy/dist/pypy/rpython/test/test_rtuple.py Sun Jul 2 16:13:17 2006 @@ -12,7 +12,7 @@ assert rtuple.lowleveltype == Ptr(GcStruct('tuple2', ('item0', Signed), ('item1', Bool), - )) + hints={'immutable': True})) # ____________________________________________________________ From arigo at codespeak.net Sun Jul 2 16:33:19 2006 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sun, 2 Jul 2006 16:33:19 +0200 (CEST) Subject: [pypy-svn] r29591 - in pypy/dist/pypy/rpython: lltypesystem test Message-ID: <20060702143319.7F8AE1007E@code0.codespeak.net> Author: arigo Date: Sun Jul 2 16:33:17 2006 New Revision: 29591 Modified: pypy/dist/pypy/rpython/lltypesystem/rtuple.py pypy/dist/pypy/rpython/test/test_rtuple.py Log: Represent empty tuples as a Void. Modified: pypy/dist/pypy/rpython/lltypesystem/rtuple.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/rtuple.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/rtuple.py Sun Jul 2 16:33:17 2006 @@ -20,16 +20,19 @@ def __init__(self, rtyper, items_r): AbstractTupleRepr.__init__(self, rtyper, items_r) - fields = zip(self.fieldnames, self.lltypes) - kwds = {'hints': {'immutable': True}} - self.lowleveltype = Ptr(GcStruct('tuple%d' % len(self.items_r), - *fields, - **kwds)) + if len(items_r) == 0: + self.lowleveltype = Void # empty tuple + else: + fields = zip(self.fieldnames, self.lltypes) + kwds = {'hints': {'immutable': True}} + self.lowleveltype = Ptr(GcStruct('tuple%d' % len(self.items_r), + *fields, + **kwds)) def newtuple(cls, llops, r_tuple, items_v): # items_v should have the lowleveltype of the internal reprs if len(r_tuple.items_r) == 0: - return inputconst(r_tuple, ()) # always the same empty tuple + return inputconst(Void, ()) # a Void empty tuple c1 = inputconst(Void, r_tuple.lowleveltype.TO) v_result = llops.genop('malloc', [c1], resulttype = r_tuple.lowleveltype) for i in range(len(r_tuple.items_r)): @@ -39,7 +42,10 @@ newtuple = classmethod(newtuple) def instantiate(self): - return malloc(self.lowleveltype.TO) + if len(self.items_r) == 0: + return dum_empty_tuple # PBC placeholder for an empty tuple + else: + return malloc(self.lowleveltype.TO) def rtype_bltn_list(self, hop): from pypy.rpython.lltypesystem import rlist @@ -72,6 +78,8 @@ newtuple = TupleRepr.newtuple +def dum_empty_tuple(): pass + # # _________________________ Conversions _________________________ Modified: pypy/dist/pypy/rpython/test/test_rtuple.py ============================================================================== --- pypy/dist/pypy/rpython/test/test_rtuple.py (original) +++ pypy/dist/pypy/rpython/test/test_rtuple.py Sun Jul 2 16:33:17 2006 @@ -242,6 +242,15 @@ res = self.interpret(example, []) assert res == 6 + def test_empty_tuple(self): + def f(): + lst = [(), (), ()] + res = [] + for x in lst: + res.append(list(x)) + assert res[0] == res[1] == res[2] == [] + self.interpret(f, []) + class TestLLtype(BaseTestRtuple, LLRtypeMixin): pass From ac at codespeak.net Sun Jul 2 17:00:01 2006 From: ac at codespeak.net (ac at codespeak.net) Date: Sun, 2 Jul 2006 17:00:01 +0200 (CEST) Subject: [pypy-svn] r29592 - in pypy/dist/pypy/jit/timeshifter: . test Message-ID: <20060702150001.921931007E@code0.codespeak.net> Author: ac Date: Sun Jul 2 17:00:00 2006 New Revision: 29592 Modified: pypy/dist/pypy/jit/timeshifter/oop.py pypy/dist/pypy/jit/timeshifter/rcontainer.py pypy/dist/pypy/jit/timeshifter/rtimeshift.py pypy/dist/pypy/jit/timeshifter/rvalue.py pypy/dist/pypy/jit/timeshifter/test/__init__.py pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py pypy/dist/pypy/jit/timeshifter/timeshift.py pypy/dist/pypy/jit/timeshifter/vlist.py Log: (pedronis, arigo, arre) Refactoring inprogress. Modified: pypy/dist/pypy/jit/timeshifter/oop.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/oop.py (original) +++ pypy/dist/pypy/jit/timeshifter/oop.py Sun Jul 2 17:00:00 2006 @@ -53,16 +53,15 @@ None, None, [method]) self.ll_handler = getattr(vmodule, method) - def residual_call(self, jitstate, argboxes): + def residual_call(self, builder, argboxes): args_gv = self.args_gv[:] argpositions = self.argpositions for i in range(len(argpositions)): pos = argpositions[i] if pos > 0: - gv_arg = argboxes[i].getgenvar(jitstate) + gv_arg = argboxes[i].getgenvar(builder) args_gv[pos] = gv_arg - gv_result = jitstate.curbuilder.genop( - 'direct_call', - args_gv, - self.gv_result_type) + gv_result = builder.genop('direct_call', + args_gv, + self.gv_result_type) return self.redboxbuilder(self.gv_result_type, gv_result) Modified: pypy/dist/pypy/jit/timeshifter/rcontainer.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/rcontainer.py (original) +++ pypy/dist/pypy/jit/timeshifter/rcontainer.py Sun Jul 2 17:00:00 2006 @@ -139,9 +139,9 @@ return "Fld_%s_in_%s" % (self.fieldname.replace('.','_'), self.PTRTYPE._short_name()) - def generate_set(self, jitstate, genvar, box): + def generate_set(self, builder, genvar, box): gv_sub = genvar - genop = jitstate.curbuilder.genop + genop = builder.genop for i in range(len(self.accessptrtype_gv)-1): op_args = lltype.malloc(rgenop.VARLIST.TO, 2) op_args[0] = gv_sub @@ -150,7 +150,7 @@ op_args = lltype.malloc(rgenop.VARLIST.TO, 3) op_args[0] = gv_sub op_args[1] = self.fieldname_gv[-1] - op_args[2] = box.getgenvar(jitstate) + op_args[2] = box.getgenvar(builder) genop('setfield', op_args, rgenop.gv_Void) # ____________________________________________________________ @@ -205,8 +205,8 @@ for box in self.content_boxes: box.enter_block(newblock, incoming, memo) - def force_runtime_container(self, jitstate): - genop = jitstate.curbuilder.genop + def force_runtime_container(self, builder): + genop = builder.genop typedesc = self.typedesc boxes = self.content_boxes self.content_boxes = None @@ -226,7 +226,7 @@ fielddesc = fielddescs[i] box = boxes[i] # xxx a bit inefficient - fielddesc.generate_set(jitstate, genvar, box) + fielddesc.generate_set(builder, genvar, box) def freeze(self, memo): contmemo = memo.containers Modified: pypy/dist/pypy/jit/timeshifter/rtimeshift.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/rtimeshift.py (original) +++ pypy/dist/pypy/jit/timeshifter/rtimeshift.py Sun Jul 2 17:00:00 2006 @@ -62,7 +62,7 @@ res = opdesc.llop(RESULT, arg) return rvalue.ll_fromvalue(res) op_args = lltype.malloc(rgenop.VARLIST.TO, 1) - op_args[0] = argbox.getgenvar(jitstate) + op_args[0] = argbox.getgenvar(jitstate.curbuilder) genvar = jitstate.curbuilder.genop(opdesc.opname, op_args, opdesc.gv_RESULT) return opdesc.redboxcls(opdesc.gv_RESULT, genvar) @@ -79,8 +79,8 @@ res = opdesc.llop(RESULT, arg0, arg1) return rvalue.ll_fromvalue(res) op_args = lltype.malloc(rgenop.VARLIST.TO, 2) - op_args[0] = argbox0.getgenvar(jitstate) - op_args[1] = argbox1.getgenvar(jitstate) + op_args[0] = argbox0.getgenvar(jitstate.curbuilder) + op_args[1] = argbox1.getgenvar(jitstate.curbuilder) genvar = jitstate.curbuilder.genop(opdesc.opname, op_args, opdesc.gv_RESULT) return opdesc.redboxcls(opdesc.gv_RESULT, genvar) @@ -93,7 +93,7 @@ assert isinstance(argbox, rvalue.PtrRedBox) if argbox.content is None: op_args = lltype.malloc(rgenop.VARLIST.TO, 2) - op_args[0] = argbox.getgenvar(jitstate) + op_args[0] = argbox.getgenvar(jitstate.curbuilder) op_args[1] = fielddesc.fieldname_gv[-1] genvar = jitstate.curbuilder.genop('getfield', op_args, fielddesc.gv_resulttype) @@ -105,9 +105,9 @@ assert isinstance(destbox, rvalue.PtrRedBox) if destbox.content is None: op_args = lltype.malloc(rgenop.VARLIST.TO, 3) - op_args[0] = destbox.getgenvar(jitstate) + op_args[0] = destbox.getgenvar(jitstate.curbuilder) op_args[1] = fielddesc.fieldname_gv[-1] - op_args[2] = valuebox.getgenvar(jitstate) + op_args[2] = valuebox.getgenvar(jitstate.curbuilder) jitstate.curbuilder.genop('setfield', op_args, rgenop.gv_Void) else: @@ -121,7 +121,7 @@ assert isinstance(argbox, rvalue.PtrRedBox) if argbox.content is None: op_args = lltype.malloc(rgenop.VARLIST.TO, 2) - op_args[0] = argbox.getgenvar(jitstate) + op_args[0] = argbox.getgenvar(jitstate.curbuilder) op_args[1] = fielddesc.gv_fieldname genvar = jitstate.curbuilder.genop('getsubstruct', op_args, fielddesc.gv_resulttype) @@ -136,8 +136,8 @@ res = array[rvalue.ll_getvalue(indexbox, lltype.Signed)] return rvalue.ll_fromvalue(res) op_args = lltype.malloc(rgenop.VARLIST.TO, 2) - op_args[0] = argbox.getgenvar(jitstate) - op_args[1] = indexbox.getgenvar(jitstate) + op_args[0] = argbox.getgenvar(jitstate.curbuilder) + op_args[1] = indexbox.getgenvar(jitstate.curbuilder) genvar = jitstate.curbuilder.genop('getarrayitem', op_args, fielddesc.gv_resulttype) return fielddesc.redboxcls(fielddesc.gv_resulttype, genvar) @@ -179,7 +179,7 @@ jitstate = dyn_enter_block(jitstate, outgoingvarboxes) linkargs = [] for box in outgoingvarboxes: - linkargs.append(box.getgenvar(jitstate)) + linkargs.append(box.getgenvar(jitstate.curbuilder)) jitstate.curbuilder.leave_block() jitstate.curbuilder.finish_and_goto(linkargs, oldblock) return None @@ -190,7 +190,7 @@ linkargs = [] replace_memo = rvalue.copy_memo() for box in outgoingvarboxes: - linkargs.append(box.getgenvar(jitstate)) + linkargs.append(box.getgenvar(jitstate.curbuilder)) for box in outgoingvarboxes: if box.is_constant(): # constant boxes considered immutable: box = box.copy(replace_memo) # copy to avoid patching the original @@ -233,19 +233,16 @@ jitstate.curbuilder.leave_block() return rvalue.ll_getvalue(switchredbox, lltype.Bool) else: - exitgvar = switchredbox.getgenvar(jitstate) + exitgvar = switchredbox.getgenvar(jitstate.curbuilder) later_builder = jitstate.curbuilder.leave_block_split(exitgvar) memo = rvalue.copy_memo() redboxcopies = [redbox.copy(memo) for redbox in redboxes] jitstate.split_queue.append((exitindex, later_builder, redboxcopies)) return True -def schedule_return(jitstate, redbox): - jitstate.return_queue.append((jitstate.curbuilder, redbox)) - novars = lltype.malloc(rgenop.VARLIST.TO, 0) -def dispatch_next(jitstate, outredboxes, gv_return_type): +def dispatch_next(jitstate, outredboxes): split_queue = jitstate.split_queue if split_queue: exitindex, later_builder, redboxes = split_queue.pop() @@ -253,41 +250,17 @@ for box in redboxes: outredboxes.append(box) return exitindex - return_queue = jitstate.return_queue - first_redbox = return_queue[0][1] - finalbuilder = ResidualGraphBuilder(rgenop.newblock()) - finalblock = finalbuilder.block -## jitstate.curblock = finalblock -## if isinstance(first_redbox, ConstRedBox): -## for link, redbox in return_queue: -## if not redbox.match(first_redbox): -## break -## else: -## for link, _ in return_queue: -## rgenop.closelink(link, novars, finalblock) -## finallink = rgenop.closeblock1(finalblock) -## jitstate.curoutgoinglink = finallink -## jitstate.curvalue = first_redbox -## return -1 - - finalvar = rgenop.geninputarg(finalblock, gv_return_type) - for builder, redbox in return_queue: - newblock = rgenop.newblock() - incoming = [] - memo = rvalue.enter_block_memo() - redbox.enter_block(newblock, incoming, memo) - jitstate.curbuilder = builder - builder.enter_block(incoming, newblock) - gv_retval = redbox.getgenvar(jitstate) - builder.leave_block() - builder.finish_and_goto([gv_retval], finalblock) - finalbuilder.leave_block() - finalbuilder.value = finalvar - jitstate.curbuilder = finalbuilder return -1 +def prepare_return(cache, gv_return_type): + frozens, block = cache[()] + builder = ResidualGraphBuilder(block) + memo = rvalue.unfreeze_memo() + builder.valuebox = frozens[0].unfreeze(memo, block, gv_return_type) + return builder + def ll_gvar_from_redbox(jitstate, redbox): - return redbox.getgenvar(jitstate) + return redbox.getgenvar(jitstate.curbuilder) def ll_gvar_from_constant(ll_value): return rgenop.genconst(ll_value) @@ -298,7 +271,7 @@ def __init__(self, block=rgenop.nullblock, link=rgenop.nulllink): rgenop.LowLevelOpBuilder.__init__(self, block) self.outgoinglink = link - self.value = rgenop.nullvar + self.valuebox = None def build_jitstate(self): return JITState(self) @@ -323,7 +296,9 @@ self.outgoinglink = rgenop.nulllink def finish_and_return(self): - rgenop.closereturnlink(self.outgoinglink, self.value) + gv_retval = self.valuebox.getgenvar(self) + returnlink = rgenop.closeblock1(self.block) + rgenop.closereturnlink(returnlink, gv_retval) def clone(self): XXX @@ -347,14 +322,13 @@ builder.leave_block() return builder.block -def ll_close_jitstate(jitstate): - jitstate.curbuilder.finish_and_return() +def ll_close_builder(builder): + builder.finish_and_return() class JITState(object): # XXX obscure interface def __init__(self, builder): - self.return_queue = [] self.split_queue = [] self.curbuilder = builder Modified: pypy/dist/pypy/jit/timeshifter/rvalue.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/rvalue.py (original) +++ pypy/dist/pypy/jit/timeshifter/rvalue.py Sun Jul 2 17:00:00 2006 @@ -14,6 +14,9 @@ def freeze_memo(): return Memo() +def unfreeze_memo(): + return {} # Memo() + def exactmatch_memo(): return Memo() @@ -37,7 +40,7 @@ def is_constant(self): return bool(self.genvar) and rgenop.isconst(self.genvar) - def getgenvar(self, jitstate): + def getgenvar(self, builder): return self.genvar def enter_block(self, newblock, incoming, memo): @@ -188,10 +191,10 @@ boxmemo[self] = result return result - def getgenvar(self, jitstate): + def getgenvar(self, builder): if not self.genvar: assert self.content - self.content.force_runtime_container(jitstate) + self.content.force_runtime_container(builder) assert self.genvar return self.genvar Modified: pypy/dist/pypy/jit/timeshifter/test/__init__.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/test/__init__.py (original) +++ pypy/dist/pypy/jit/timeshifter/test/__init__.py Sun Jul 2 17:00:00 2006 @@ -0,0 +1,2 @@ +import py +py.test.skip('Refactoring in progress') Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py (original) +++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py Sun Jul 2 17:00:00 2006 @@ -109,9 +109,9 @@ residual_graph_args.append(llvalue) startblock = llinterp.eval_graph(htshift.ll_end_setup_builder_graph, [builder]) - jitstate = llinterp.eval_graph(graph1, graph1args) + builder = llinterp.eval_graph(graph1, graph1args) r = htshift.hrtyper.getrepr(hs) - llinterp.eval_graph(htshift.ll_close_jitstate_graph, [jitstate]) + llinterp.eval_graph(htshift.ll_close_builder_graph, [builder]) # now try to run the blocks produced by the builder residual_graph = rgenop.buildgraph(startblock) @@ -156,7 +156,7 @@ assert res == 12 assert insns == {} -def test_simple(): +def test_very_simple(): def ll_function(x, y): return x + y insns, res = timeshift(ll_function, [5, 7]) @@ -560,7 +560,7 @@ assert insns == {'int_is_true': 1, 'int_add': 1} def test_call_simple(): - py.test.skip("in-progress") + #py.test.skip("in-progress") def ll_add_one(x): return x + 1 def ll_function(y): Modified: pypy/dist/pypy/jit/timeshifter/timeshift.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/timeshift.py (original) +++ pypy/dist/pypy/jit/timeshifter/timeshift.py Sun Jul 2 17:00:00 2006 @@ -22,7 +22,7 @@ self.hrtyper = HintRTyper(hannotator, self) self.latestexitindex = -1 self.block2jitstate = {} - + self.return_cache = None self.annhelper = annlowlevel.MixLevelHelperAnnotator(rtyper) self.s_ResidualGraphBuilder, self.r_ResidualGraphBuilder = self.s_r_instanceof(ResidualGraphBuilder) @@ -71,9 +71,14 @@ [self.s_ResidualGraphBuilder], annmodel.SomePtr(rgenop.BLOCK)) - self.ll_close_jitstate_graph = self.annhelper.getgraph( - rtimeshift.ll_close_jitstate, - [self.s_JITState], +## self.ll_close_jitstate_graph = self.annhelper.getgraph( +## rtimeshift.ll_close_jitstate, +## [self.s_JITState], +## annmodel.s_None) + + self.ll_close_builder_graph = self.annhelper.getgraph( + rtimeshift.ll_close_builder, + [self.s_ResidualGraphBuilder], annmodel.s_None) def s_r_instanceof(self, cls, can_be_None=True): @@ -158,32 +163,35 @@ originalblocks = timeshifted_blocks returnblock = graph.returnblock + self.r_returnvalue = self.hrtyper.bindingrepr(returnblock.inputargs[0]) + returnblock.operations = [] + graph.returnblock = None # we need to get the jitstate to the before block of the return block self.dispatchblock = flowmodel.Block([]) self.insert_jitstate_arg(self.dispatchblock) - before_returnblock = self.insert_before_block(returnblock, - entering_links[returnblock], - closeblock=False) +# before_returnblock = self.insert_before_block(returnblock, +# entering_links[returnblock], +# closeblock=False) # fix its concretetypes - self.hrtyper.setup_block_entry(before_returnblock) - self.insert_jitstate_arg(before_returnblock) + #self.hrtyper.setup_block_entry(before_returnblock) + #self.insert_jitstate_arg(before_returnblock) for block in originalblocks: self.insert_jitstate_arg(block) for block in originalblocks: - if block.operations != (): - block_entering_links = entering_links.pop(block) - before_block = self.insert_before_block(block, block_entering_links) - self.insert_bookkeeping_enter(block, before_block, len(block_entering_links)) - - self.insert_bookkeeping_leave_block(block, entering_links) + block_entering_links = entering_links.pop(block) + before_block = self.insert_before_block(block, + block_entering_links) + self.insert_bookkeeping_enter(block, before_block, + len(block_entering_links)) + self.insert_bookkeeping_leave_block(block, entering_links) - self.hrtyper.insert_link_conversions(before_returnblock) + #self.hrtyper.insert_link_conversions(before_returnblock) # add booking logic - self.insert_return_bookkeeping(before_returnblock) + #self.insert_return_bookkeeping(before_returnblock) # fix its concretetypes - self.insert_dispatch_logic(returnblock) + self.insert_dispatch_logic() # hack to allow the state caches to be cleared # XXX! doesn't work if there are several graphs @@ -220,14 +228,14 @@ def insert_jitstate_arg(self, block): # pass 'jitstate' as an extra argument around the whole graph - if block.operations != (): + #if block.operations != (): v_jitstate = self.getjitstate(block) block.inputargs.insert(0, v_jitstate) for link in block.exits: - if link.target.operations != (): - link.args.insert(0, v_jitstate) - elif len(link.args) == 1: - assert False, "the return block should not be seen" + #if link.target.operations != (): + link.args.insert(0, v_jitstate) + #elif len(link.args) == 1: + # assert False, "the return block should not be seen" def insert_before_block(self, block, entering_links, closeblock=True): newinputargs = [] @@ -303,17 +311,21 @@ v_boxes = self.build_box_list(llops, boxes_v) - if nentrylinks > 1: + is_returnblock = len(block.exits) == 0 + if nentrylinks > 1 or is_returnblock: enter_block_logic = self.bookkeeping_enter_for_join else: enter_block_logic = self.bookkeeping_enter_simple # fill the block with logic - enter_block_logic(args_r, newinputargs, - before_block, - llops, - v_boxes) + cache = enter_block_logic(args_r, newinputargs, + before_block, + llops, + v_boxes) + if is_returnblock: + assert self.return_cache is None + self.return_cache = cache def build_box_list(self, llops, boxes_v): type_erased_v = [llops.convertvar(v_box, self.r_RedBox, @@ -333,7 +345,8 @@ # not used any more: v_boxes is not modified by enter_block() nowadays #self.insert_read_out_boxes(bridge, llops, v_newjitstate, v_boxes, args_r, newinputargs) before_block.operations[:] = llops - + + return None # insert before join blocks a block with: # key = () # boxes = [] @@ -426,6 +439,7 @@ read_boxes_block.closeblock(to_target) + return cache def insert_bookkeeping_leave_block(self, block, entering_links): # XXX wrong with exceptions as much else @@ -484,7 +498,13 @@ block.recloseblock(inlink) llops = HintLowLevelOpList(self, None) - if len(newblock.exits) == 1 or isinstance(self.hrtyper.bindingrepr(oldexitswitch), GreenRepr): + if len(newblock.exits) == 0: # this is the original returnblock + llops.genmixlevelhelpercall(rtimeshift.save_return, + [...], + [...], + ...) + newblock.recloseblock(flowmodel.Link(newblock.inputargs, self.dispatchblock)) + elif len(newblock.exits) == 1 or isinstance(self.hrtyper.bindingrepr(oldexitswitch), GreenRepr): newblock.exitswitch = rename(oldexitswitch) v_res = llops.genmixlevelhelpercall(rtimeshift.leave_block, [self.s_JITState], @@ -529,51 +549,34 @@ newblock.exitswitch = v_res newblock.operations[:] = llops - def insert_return_bookkeeping(self, before_returnblock): - v_jitstate, v_value = before_returnblock.inputargs - - r_value = self.hrtyper.bindingrepr(v_value) - llops = HintLowLevelOpList(self, None) - if isinstance(r_value, GreenRepr): - v_value = self.make_const_box(llops, r_value, v_value) - - llops.genmixlevelhelpercall(rtimeshift.schedule_return, - [self.s_JITState, - self.s_RedBox], - [v_jitstate, v_value], - self.s_JITState) - - before_returnblock.operations[:] = llops - bridge = flowmodel.Link([v_jitstate], self.dispatchblock) - before_returnblock.closeblock(bridge) - - def insert_dispatch_logic(self, returnblock): + def insert_dispatch_logic(self): dispatchblock = self.dispatchblock [v_jitstate] = dispatchblock.inputargs llops = HintLowLevelOpList(self, None) + v_returnbuilder = flowmodel.Variable('builder') + v_returnbuilder.concretetype = self.r_ResidualGraphBuilder.lowleveltype + returnblock = flowmodel.Block([v_returnbuilder]) + returnblock.operations = () + self.graph.returnblock = returnblock + v_boxes = rlist.newlist(llops, self.r_box_accum, []) - - - r_returnvalue = self.hrtyper.bindingrepr(returnblock.inputargs[0]) - RETURN_TYPE = r_returnvalue.original_concretetype - c_TYPE = rmodel.inputconst(rgenop.CONSTORVAR, rgenop.constTYPE(RETURN_TYPE)) v_next = llops.genmixlevelhelpercall(rtimeshift.dispatch_next, [self.s_JITState, - self.s_box_accum, - annmodel.SomePtr(rgenop.CONSTORVAR)], - [v_jitstate, v_boxes, c_TYPE], + self.s_box_accum], + [v_jitstate, v_boxes], annmodel.SomeInteger()) - dispatchblock.operations[:] = llops + dispatchblock.operations = list(llops) dispatch_to = self.dispatch_to - finishedlink = flowmodel.Link([v_jitstate], returnblock) - dispatch_to.append(('default', finishedlink)) + prepare_return_block = flowmodel.Block([]) + prepare_return_link = flowmodel.Link([], prepare_return_block) + dispatch_to.append(('default', prepare_return_link)) if len(dispatch_to) == 1: - dispatchblock.closeblock(finishedlink) + dispatchblock.closeblock(prepare_return_link) else: dispatchblock.exitswitch = v_next exitlinks = [] @@ -587,9 +590,19 @@ exitlinks.append(link) dispatchblock.closeblock(*exitlinks) - v_returnjitstate = flowmodel.Variable('jitstate') - returnblock.inputargs = [v_returnjitstate] - v_returnjitstate.concretetype = self.r_JITState.lowleveltype + return_cache = self.return_cache + assert return_cache is not None + RETURN_TYPE = self.r_returnvalue.original_concretetype + def prepare_return(): + return rtimeshift.prepare_return(return_cache, + rgenop.constTYPE(RETURN_TYPE)) + llops = HintLowLevelOpList(self, None) + v_return_builder = llops.genmixlevelhelpercall(prepare_return, + [], [], self.s_ResidualGraphBuilder) + + prepare_return_block.operations = list(llops) + finishedlink = flowmodel.Link([v_return_builder], returnblock) + prepare_return_block.closeblock(finishedlink) def getjitstate(self, block): if block not in self.block2jitstate: @@ -600,17 +613,19 @@ def timeshift_block(self, timeshifted_blocks, entering_links, block): blocks = [block] - #i = 0 - #while i < len(block.operations): - # op = block.operations[i] - # if op.opname == 'direct_call': - # link = support.split_block_with_keepalive(block, i+1) - # block = link.target - # entering_links[block] = [link] - # blocks.append(block) - # i = 0 - # continue - # i += 1 + i = 0 + while i < len(block.operations): + op = block.operations[i] + if op.opname == 'direct_call': + link = support.split_block_with_keepalive(block, i+1, + annotator=self.hannotator) + block = link.target + entering_links[block] = [link] + blocks.append(block) + self.hannotator.annotated[block] = self.graph + i = 0 + continue + i += 1 for block in blocks: self.getjitstate(block) # force this to be precomputed self.hrtyper.specialize_block(block) Modified: pypy/dist/pypy/jit/timeshifter/vlist.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/vlist.py (original) +++ pypy/dist/pypy/jit/timeshifter/vlist.py Sun Jul 2 17:00:00 2006 @@ -71,17 +71,16 @@ for box in self.item_boxes: box.enter_block(newblock, incoming, memo) - def force_runtime_container(self, jitstate): + def force_runtime_container(self, builder): typedesc = self.typedesc boxes = self.item_boxes self.item_boxes = None - llops = jitstate.curbuilder - gv_list = typedesc.build_newlist(llops, len(boxes)) + gv_list = typedesc.build_newlist(builder, len(boxes)) self.ownbox.genvar = gv_list self.ownbox.content = None for i in range(len(boxes)): - gv_item = boxes[i].getgenvar(jitstate) - typedesc.build_setitem(llops, gv_list, i, gv_item) + gv_item = boxes[i].getgenvar(builder) + typedesc.build_setitem(builder, gv_list, i, gv_item) def freeze(self, memo): contmemo = memo.containers @@ -118,24 +117,24 @@ length = rvalue.ll_getvalue(lengthbox, lltype.Signed) if length == 0 or itembox is not None: return oopspecdesc.typedesc.factory(length, itembox) - return oopspecdesc.residual_call(jitstate, [lengthbox, itembox]) + return oopspecdesc.residual_call(jitstate.curbuilder, [lengthbox, itembox]) def oop_list_append(jitstate, oopspecdesc, selfbox, itembox): if isinstance(selfbox.content, VirtualList): selfbox.content.item_boxes.append(itembox) else: - oopspecdesc.residual_call(jitstate, [selfbox, itembox]) + oopspecdesc.residual_call(jitstate.curbuilder, [selfbox, itembox]) def oop_list_getitem(jitstate, oopspecdesc, selfbox, indexbox): if isinstance(selfbox.content, VirtualList) and indexbox.is_constant(): index = rvalue.ll_getvalue(indexbox, lltype.Signed) return selfbox.content.item_boxes[index] else: - return oopspecdesc.residual_call(jitstate, [selfbox, indexbox]) + return oopspecdesc.residual_call(jitstate.curbuilder, [selfbox, indexbox]) def oop_list_setitem(jitstate, oopspecdesc, selfbox, indexbox, itembox): if isinstance(selfbox.content, VirtualList) and indexbox.is_constant(): index = rvalue.ll_getvalue(indexbox, lltype.Signed) selfbox.content.item_boxes[index] = itembox else: - oopspecdesc.residual_call(jitstate, [selfbox, indexbox, itembox]) + oopspecdesc.residual_call(jitstate.curbuilder, [selfbox, indexbox, itembox]) From arigo at codespeak.net Sun Jul 2 17:06:04 2006 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sun, 2 Jul 2006 17:06:04 +0200 (CEST) Subject: [pypy-svn] r29593 - in pypy/dist/pypy/rpython/lltypesystem: . module Message-ID: <20060702150604.596CA1007D@code0.codespeak.net> Author: arigo Date: Sun Jul 2 17:06:03 2006 New Revision: 29593 Modified: pypy/dist/pypy/rpython/lltypesystem/module/ll_os.py pypy/dist/pypy/rpython/lltypesystem/rtuple.py Log: Fix breakage from previous check-in. Modified: pypy/dist/pypy/rpython/lltypesystem/module/ll_os.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/module/ll_os.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/module/ll_os.py Sun Jul 2 17:06:03 2006 @@ -1,13 +1,10 @@ from pypy.rpython.module.support import LLSupport from pypy.rpython.module.ll_os import BaseOS -from pypy.rpython.lltypesystem import lltype +from pypy.rpython.lltypesystem import lltype, rtuple from pypy.rpython.rarithmetic import intmask n = 10 -fieldnames = ['item%d' % i for i in range(n)] -lltypes = [lltype.Signed]*n -fields = tuple(zip(fieldnames, lltypes)) -STAT_RESULT = lltype.GcStruct('tuple%d' % n, *fields) +STAT_RESULT = rtuple.TUPLE_TYPE([lltype.Signed]*n).TO class Implementation(BaseOS, LLSupport): Modified: pypy/dist/pypy/rpython/lltypesystem/rtuple.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/rtuple.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/rtuple.py Sun Jul 2 17:06:03 2006 @@ -16,18 +16,19 @@ # ... # } +def TUPLE_TYPE(field_lltypes): + if len(field_lltypes) == 0: + return Void # empty tuple + else: + fields = [('item%d' % i, TYPE) for i, TYPE in enumerate(field_lltypes)] + kwds = {'hints': {'immutable': True}} + return Ptr(GcStruct('tuple%d' % len(field_lltypes), *fields, **kwds)) + class TupleRepr(AbstractTupleRepr): def __init__(self, rtyper, items_r): AbstractTupleRepr.__init__(self, rtyper, items_r) - if len(items_r) == 0: - self.lowleveltype = Void # empty tuple - else: - fields = zip(self.fieldnames, self.lltypes) - kwds = {'hints': {'immutable': True}} - self.lowleveltype = Ptr(GcStruct('tuple%d' % len(self.items_r), - *fields, - **kwds)) + self.lowleveltype = TUPLE_TYPE(self.lltypes) def newtuple(cls, llops, r_tuple, items_v): # items_v should have the lowleveltype of the internal reprs From ericvrp at codespeak.net Sun Jul 2 20:04:03 2006 From: ericvrp at codespeak.net (ericvrp at codespeak.net) Date: Sun, 2 Jul 2006 20:04:03 +0200 (CEST) Subject: [pypy-svn] r29596 - in pypy/extradoc/talk/ep2006: . ui Message-ID: <20060702180403.547101007E@code0.codespeak.net> Author: ericvrp Date: Sun Jul 2 20:03:56 2006 New Revision: 29596 Added: pypy/extradoc/talk/ep2006/ui/ - copied from r29573, pypy/extradoc/talk/mallorca-talk-2006/ui/ pypy/extradoc/talk/ep2006/usecases-slides.txt (contents, props changed) Log: (cfbolz) first draft of the use cases Added: pypy/extradoc/talk/ep2006/usecases-slides.txt ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2006/usecases-slides.txt Sun Jul 2 20:03:56 2006 @@ -0,0 +1,103 @@ +====================================== +What can PyPy do for you? +====================================== + +:Authors: Armin Rigo (HHU), Carl Friedrich Bolz (merlinux), Eric van Riet Paap +:Date: 4th July 2006 + + +Peek under the hood +==================== + + * PyPy feature: ``sys.pypy_repr`` function + + * allows you to get the interpreter-level representation of an object + + * in the compiled PyPy version you get the name of the RPython class + + * ... demo + +Stackless Features (1/2) +======================== + + * PyPy can be translated with stackless features + + * allows arbitrarily deep recursion + + * enables usage of coroutines + + * tasklets and channels (as in Stackless Python) + + * greenlets without evil platform hacks + + +Stackless Features (2/2) +======================== + + * experimentally: (un-)pickling of coroutines + + * working on: making coroutines clonable + + * made possible by our mark-n-sweep GC + + +Lazy Computations +================= + + * two object spaces with lazy features + + * thunk object space: lazy computed objects + + * logic object space: logic variables, unification, microthreads + + +The Thunk Object Space +====================== + + * new builtin: ``thunk`` + + * takes a function and arguments + + * returns something that behaves like the result of the call + + * the call is made as late as possible + + * only when the value is actually needed + +The Logic Object Space +====================== + + * ``newvar``: makes a new unbound logic variable (prolog and Oz-like) + + * ``unify``: unifies two expressions + + * trying to access an unbound var blocks the current thread + + * ``wait_needed(X)`` waits until somebody needs the var ``X`` + + * ``uthread(callable, *args)`` starts a new thread + + +The Extension-Compiler +====================== + + * pypy extension modules are written in RPython + + * extensions translated to efficient low level code + + * the extension compiler makes these useable with CPython + + * write fast extensions for PyPy `and` CPython + +RCTypes +======= + + * Makes it possible to use RCTypes in RPython + + * usual type restrictions apply + + * dynamic libary calls are translated to real ones + + * makes wrapping of libaries easy and testable + + * again useable with PyPy and CPython From fijal at codespeak.net Mon Jul 3 01:36:45 2006 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 3 Jul 2006 01:36:45 +0200 (CEST) Subject: [pypy-svn] r29597 - pypy/dist/pypy/annotation Message-ID: <20060702233645.38CCD1007C@code0.codespeak.net> Author: fijal Date: Mon Jul 3 01:36:42 2006 New Revision: 29597 Modified: pypy/dist/pypy/annotation/model.py pypy/dist/pypy/annotation/unaryop.py Log: ExternalBuiltin callback field support Modified: pypy/dist/pypy/annotation/model.py ============================================================================== --- pypy/dist/pypy/annotation/model.py (original) +++ pypy/dist/pypy/annotation/model.py Mon Jul 3 01:36:42 2006 @@ -573,6 +573,7 @@ ll_to_annotation_map = dict([(ll, ann) for ann, ll in annotation_to_ll_map if ll is not NUMBER]) def lltype_to_annotation(T): + from pypy.rpython.ootypesystem.bltregistry import ExternalType try: s = ll_to_annotation_map.get(T) except TypeError: @@ -586,6 +587,8 @@ return SomeOOStaticMeth(T) elif T == ootype.Class: return SomeOOClass(ootype.ROOT) + elif isinstance(T, ExternalType): + return SomeExternalBuiltin(T) else: return SomePtr(T) else: Modified: pypy/dist/pypy/annotation/unaryop.py ============================================================================== --- pypy/dist/pypy/annotation/unaryop.py (original) +++ pypy/dist/pypy/annotation/unaryop.py Mon Jul 3 01:36:42 2006 @@ -632,9 +632,13 @@ entry = extregistry.lookup_type(p.knowntype._class_) # we need to flow it, if it's something which can be called if isinstance(s_value, SomePBC): + # we have to have such a declaration to know what we're flowing it with bookkeeper = getbookkeeper() - bookkeeper.pbc_call(s_value, bookkeeper.build_args("simple_call", ())) - entry.set_field_annotation(p.knowntype, attr, s_value) + args_ann = entry.get_arg_annotation(p.knowntype, attr) + bookkeeper.pbc_call(s_value, bookkeeper.build_args("simple_call", args_ann)) + p.knowntype.check_update() + if not p.knowntype._fields.has_key(attr): + entry.set_field_annotation(p.knowntype, attr, s_value) def find_method(obj, name): return obj.knowntype.get_field(name) From fijal at codespeak.net Mon Jul 3 01:37:23 2006 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 3 Jul 2006 01:37:23 +0200 (CEST) Subject: [pypy-svn] r29598 - in pypy/dist/pypy/rpython/ootypesystem: . test Message-ID: <20060702233723.623681007C@code0.codespeak.net> Author: fijal Date: Mon Jul 3 01:37:20 2006 New Revision: 29598 Modified: pypy/dist/pypy/rpython/ootypesystem/bltregistry.py pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py Log: ExternalBuiltin callback field support Modified: pypy/dist/pypy/rpython/ootypesystem/bltregistry.py ============================================================================== --- pypy/dist/pypy/rpython/ootypesystem/bltregistry.py (original) +++ pypy/dist/pypy/rpython/ootypesystem/bltregistry.py Mon Jul 3 01:37:20 2006 @@ -10,6 +10,8 @@ from pypy.annotation.bookkeeper import getbookkeeper from pypy.rpython.lltypesystem.lltype import frozendict, isCompatibleType from types import MethodType +from pypy.rpython.extregistry import ExtRegistryEntry +from pypy.rpython.rmodel import Repr class ArgDesc(object): def __init__(self, name, ex_value): @@ -21,9 +23,10 @@ self.num = 0 self.args = [self.convert_val(arg) for arg in args] self.retval = self.convert_val(retval) + self.example = self def convert_val(self, val): - if isinstance(val, ArgDesc): + if isinstance(val, ArgDesc) or isinstance(val, MethodDesc): return val elif isinstance(val, tuple): return ArgDesc(*val) @@ -31,6 +34,20 @@ self.num += 1 return ArgDesc('v%d' % (self.num-1), val) +class CallableEntry(ExtRegistryEntry): + _type_ = MethodDesc + + def compute_annotation(self): + # because we have no good annotation + # let's cheat a little bit for a while... + bookkeeper = getbookkeeper() + # hack, hack, hack, hack, hack, hack, hack, hack, hack, hack, hack, hack, hack, hack, hack + values = ["v%d"%i for i in xrange(len(self.instance.args))] + lb = eval("lambda %s: None" % ",".join(values)) + s = annmodel.SomePBC([bookkeeper.getdesc(lb)]) + #bookkeeper.pbc_call(s, bookkeeper.build_args("simple_call", [bookkeeper.annotation_from_example(arg.example) for arg in self.instance.args])) + return s + class BasicMetaExternal(type): def _is_compatible(type2): return type(type2) is BasicMetaExternal @@ -44,13 +61,17 @@ _fields = {} _methods = {} -from pypy.rpython.extregistry import ExtRegistryEntry -from pypy.rpython.rmodel import Repr - class Analyzer(object): def __init__(self, name, value): self.name = name + # dirty hack + # FIXME: to replace in future + #if value.args[-1].name == 'callback': + # itervalues = value.args[:-1] + #else: + # itervalues = value.args self.args, self.retval = [i.example for i in value.args], value.retval.example + self.value = value def __call__(self, *args): #for i in xrange(len(args)): @@ -62,6 +83,9 @@ for i in args: if isinstance(i, annmodel.SomePBC): bookkeeper = getbookkeeper() + #import pdb;pdb.set_trace() + #bookkeeper.pbc_call(i, bookkeeper.build_args("simple_call", [bookkeeper.annotation_from_example(arg) for arg in self.args])) + bookkeeper.pbc_call(i, bookkeeper.build_args("simple_call", (ann_retval,))) return ann_retval @@ -75,9 +99,8 @@ self._name = str(_class) self._superclass = None self._root = True - self._fields = {} self.updated = False - self._data = _class._fields, _class._methods + self._data = frozendict(_class._fields), frozendict(_class._methods) #self._methods = _class._methods #_methods = dict([(i,ootype._meth(ootype.Meth(*val))) for i,val in _class._methods.iteritems()]) #ootype.Instance.__init__(self, str(_class), None, _class._fields, _methods, True) @@ -94,6 +117,7 @@ def update_methods(self, _methods): _signs = {} + self._fields = {} for i, val in _methods.iteritems(): retval = getbookkeeper().annotation_from_example(val.retval.example) values = [arg.example for arg in val.args] @@ -133,6 +157,9 @@ def __repr__(self): return "%s %s" % (self.__name__, self._name) + + def _defl(self): + return _external_type(self) ## def _defl(self): ## raise AttributeError() @@ -157,6 +184,11 @@ def get_field_annotation(self, ext_obj, attr): return ext_obj.get_field(attr) + def get_arg_annotation(self, ext_obj, attr): + field = ext_obj._class_._fields[attr] + assert isinstance(field, MethodDesc) + return [getbookkeeper().annotation_from_example(arg.example) for arg in field.args] + def set_field_annotation(self, ext_obj, attr, s_val): ext_obj.set_field(attr, s_val) 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 Mon Jul 3 01:37:20 2006 @@ -94,3 +94,37 @@ s = a.build_types(set_callback, []) assert s.knowntype is int +class CC(BasicExternal): + _methods = { + 'some_method' : MethodDesc(['some_callback', MethodDesc([('some_int', 3)], 3.0)], 3) + } + +def test_callback_flowin(): + def some_f(i): + return 3.2 + + def set_defined_callback(): + a = CC() + return a.some_method(some_f) + + a = RPythonAnnotator() + s = a.build_types(set_defined_callback, []) + assert s.knowntype is int + +class CD(BasicExternal): + _fields = { + 'callback_field' : MethodDesc([('some_int', 3)], 3.0) + } + +def test_callback_field(): + def callback(x): + return 8.3 + + def callback_field(): + a = CD() + a.callback_field = callback + return a.callback_field + + a = RPythonAnnotator() + s = a.build_types(callback_field, []) + assert isinstance(s, annmodel.SomePBC) From fijal at codespeak.net Mon Jul 3 01:40:13 2006 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 3 Jul 2006 01:40:13 +0200 (CEST) Subject: [pypy-svn] r29599 - in pypy/dist/pypy/translator/js: . demo/jsdemo jssrc modules test tools Message-ID: <20060702234013.002BA1007E@code0.codespeak.net> Author: fijal Date: Mon Jul 3 01:40:03 2006 New Revision: 29599 Added: pypy/dist/pypy/translator/js/demo/jsdemo/consserv.py pypy/dist/pypy/translator/js/modules/_dom.py pypy/dist/pypy/translator/js/tools/console.py (contents, props changed) Modified: pypy/dist/pypy/translator/js/commproxy.py pypy/dist/pypy/translator/js/database.py pypy/dist/pypy/translator/js/demo/jsdemo/bnb.py pypy/dist/pypy/translator/js/function.py pypy/dist/pypy/translator/js/jsbuiltin.py pypy/dist/pypy/translator/js/jssrc/misc.js pypy/dist/pypy/translator/js/jts.py pypy/dist/pypy/translator/js/metavm.py pypy/dist/pypy/translator/js/opcodes.py pypy/dist/pypy/translator/js/test/test_genllvm.py pypy/dist/pypy/translator/js/test/test_seq.py pypy/dist/pypy/translator/js/tools/start_bnb.py Log: Added simple console. Added some passing tests. Fixed chr support. Fixed "\n" issues. Added support for BasicExternal _dom module. Added support for callback (we can write document.onkeypress = function) Modified: pypy/dist/pypy/translator/js/commproxy.py ============================================================================== --- pypy/dist/pypy/translator/js/commproxy.py (original) +++ pypy/dist/pypy/translator/js/commproxy.py Mon Jul 3 01:40:03 2006 @@ -51,14 +51,14 @@ data = %(data)s; str = "" for(i in data) { - //if (data[i]) { + if (!(data[i] == undefined)) { if (str.length == 0) { str += "?"; } else { str += "&"; } str += i + "=" + data[i].toString(); - //} + } } //logDebug('%(call)s'+str); loadJSONDoc('%(call)s' + str).addCallback(callback); Modified: pypy/dist/pypy/translator/js/database.py ============================================================================== --- pypy/dist/pypy/translator/js/database.py (original) +++ pypy/dist/pypy/translator/js/database.py Mon Jul 3 01:40:03 2006 @@ -351,7 +351,10 @@ return self.const._str == other.const._str def init(self, ilasm): - ilasm.load_str("'%s'"%self.const._str) + s = self.const._str + # do some escaping + s = s.replace("\n", "\\n") + ilasm.load_str('"%s"'%s) def init_fields(self, ilasm, const_var, name): pass Modified: pypy/dist/pypy/translator/js/demo/jsdemo/bnb.py ============================================================================== --- pypy/dist/pypy/translator/js/demo/jsdemo/bnb.py (original) +++ pypy/dist/pypy/translator/js/demo/jsdemo/bnb.py Mon Jul 3 01:40:03 2006 @@ -23,8 +23,6 @@ class SpriteManager(object): - FULL_FRAME = 100 - def __init__(self): self.sprite_sets = {} self.positions = {} @@ -39,10 +37,6 @@ def get_frame_number(self): self.num_frame += 1 - if self.num_frame >= self.FULL_FRAME: - self.num_frame = 0 - return True - return False def get_sprite(self, icon_code, x, y): try: @@ -244,7 +238,7 @@ #log('RECEIVED HEADER LINE: %s' % header_line) #log('RECEIVED DATA CONTAINS %d BYTES' % len(data)) - messages = [ {'type':'count', 'n':sm.count()} ] + messages = [] while data: values, data = decodemessage(data) if not values: @@ -270,9 +264,9 @@ to_append = [] sprite_manager = self.get_sprite_manager() - def get_full_frame(next): - new_sprite, s_num = sprite_manager.get_sprite(*next) - to_append.append({'type':'show_sprite', 's':s_num, 'icon_code':str(next[0]), 'x':str(next[1]), 'y':str(next[2])}) +## def get_full_frame(next): +## new_sprite, s_num = sprite_manager.get_sprite(*next) +## to_append.append({'type':'show_sprite', 's':s_num, 'icon_code':str(next[0]), 'x':str(next[1]), 'y':str(next[2])}) def get_partial_frame(next): new_sprite, s_num = sprite_manager.get_sprite(*next) @@ -281,35 +275,24 @@ elif new_sprite == 'move': to_append.append({'type':'sm', 's':str(s_num), 'x':str(next[1]), 'y':str(next[2])}) - if sprite_manager.get_frame_number(): - full_frame = True - get_frame = get_full_frame - to_append.append({'type':'begin_clean_sprites'}) - else: - full_frame = False - get_frame = get_partial_frame - for i, msg in enumerate(messages): if msg['type'] == PMSG_INLINE_FRAME: for next in msg['sprites']: #to_append.append({'type':'ns', 's':self.num, 'icon_code':str(next[0]), 'x':str(next[1]), 'y':str(next[2])}) #self.num += 1 - get_frame(next) + get_partial_frame(next) del messages[i] empty_frame = False if sprite_manager.seen == set([]): empty_frame = True - if not empty_frame and not full_frame: + if not empty_frame: for i in sprite_manager.end_frame(): to_append.append({'type':'ds', 's':str(i)}) - if full_frame: - to_append.append({'type':'clean_sprites'}) - sprite_manager.end_frame() messages += to_append #messages.append(to_append[0]) #log(len(messages)) - return dict(messages=messages) + return dict(messages=messages, add_data=[{'n':sm.count()}]) BnbRootInstance = BnbRoot() Added: pypy/dist/pypy/translator/js/demo/jsdemo/consserv.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/translator/js/demo/jsdemo/consserv.py Mon Jul 3 01:40:03 2006 @@ -0,0 +1,53 @@ + +""" nb-server - server side of multiuser notebook +""" + +import turbogears +import cherrypy +from pypy.rpython.ootypesystem.bltregistry import BasicExternal, MethodDesc +from pypy.translator.js.demo.jsdemo.controllers import Root +from cherrypy import session + +import re, time, sys, os, urllib, socket, copy + +from pypy.translator.js.test.runtest import compile_function + + +from pypy.translator.js.modules._dom import Node, get_document, setTimeout, alert +#from pypy.translator.js.modules.xmlhttp import XMLHttpRequest +from pypy.translator.js.modules.mochikit import logDebug, createLoggingPane, log +from pypy.translator.js.modules.bltns import date + +class ConsoleRoot(BasicExternal, Root): + _methods = { + 'run_command' : MethodDesc([('str_to_eval', 'ss'), ('callback', lambda : None)], {'aa':'aa'}) + } + + @turbogears.expose(html='jsdemo.templates.console') + def index(self): + return dict(now=time.ctime(), onload=self.jsname, code=self.jssource) + + @turbogears.expose(format="json") + def run_command(self, str_to_eval): + # we need what has changed + # we try to run it... + + lines = str_to_eval.split("
") + for num, line in enumerate(lines): + if not line.startswith(" "): + lines[num] = " " + line + all_text = "\n".join(["def f():"] + lines[:-1]) + print all_text + try: + exec(all_text) + fn = compile_function(f, []) + retval = "compilation ok" + source = fn.js.tmpfile.open().read() + except Exception, e: + print str(e) + retval = str(e) + source = "" + + return dict(data=all_text, retval=retval, source=source) + +ConsoleRootInstance = ConsoleRoot() Modified: pypy/dist/pypy/translator/js/function.py ============================================================================== --- pypy/dist/pypy/translator/js/function.py (original) +++ pypy/dist/pypy/translator/js/function.py Mon Jul 3 01:40:03 2006 @@ -15,6 +15,7 @@ from pypy.translator.cli.class_ import Class from pypy.translator.js.log import log +from types import FunctionType import re @@ -414,6 +415,18 @@ self.db.load_const(v.concretetype, v.value, self.ilasm) else: assert False + + def load_special(self, v): + # special case for loading value + # when setting builtin field we need to load function instead of None + # FIXME: we cheat here + if isinstance(v, flowmodel.Constant) and v.concretetype is ootype.Void and isinstance(v.value, FunctionType): + graph = self.db.translator.annotator.bookkeeper.getdesc(v.value).cachedgraph(None) + self.db.pending_function(graph) + name = graph.name + self.ilasm.load_str(name) + else: + self.load(v) def store(self, v): if isinstance(v, flowmodel.Variable): Modified: pypy/dist/pypy/translator/js/jsbuiltin.py ============================================================================== --- pypy/dist/pypy/translator/js/jsbuiltin.py (original) +++ pypy/dist/pypy/translator/js/jsbuiltin.py Mon Jul 3 01:40:03 2006 @@ -37,6 +37,8 @@ 'll_strcmp' : CallBuiltin('strcmp'), 'll_startswith' : CallBuiltin('startswith'), 'll_endswith' : CallBuiltin('endswith'), + 'll_split_chr' : CallBuiltin('splitchr'), + 'll_substring' : lambda g,op: Call._render_builtin_method(g, 'substring', [op.args[1], op.args[2], op.args[3]]) }, ootype.List: { 'll_setitem_fast' : ListSetitem, Modified: pypy/dist/pypy/translator/js/jssrc/misc.js ============================================================================== --- pypy/dist/pypy/translator/js/jssrc/misc.js (original) +++ pypy/dist/pypy/translator/js/jssrc/misc.js Mon Jul 3 01:40:03 2006 @@ -1,3 +1,4 @@ +// starts hand written code Function.prototype.method = function (name, func) { this.prototype[name] = func; return this; @@ -76,3 +77,22 @@ } return(true); } + +function splitchr(s, ch) { + var i, lst; + lst = []; + next = ""; + for (i = 0; i")) + console.go = False + console.add_line(">>> ") + +class Console(object): + def __init__(self): + self.to_run = "" + self.shift = False + self.go = False + + def add_line(self, text): + self.data_field.innerHTML += "
" + text + + def onload(self, df): + self.data_field = df + df.innerHTML = "" + self.add_line("This is some console") + self.add_line(">>> ") + + def history_up(self): + pass + + def history_down(self): + pass + + def backspace(self): + # FIXME: terribly inneficient + #if self.data_field.innerHTML.endswith(" "): + # self.data_field.innerHTML = self.data_field.innerHTML[:-5] + # seems to be pypy bug, so you cannot delete spaces + #else: + self.data_field.innerHTML = self.data_field.innerHTML[:-1] + self.to_run = self.to_run[:-1] + + def run(self): + if self.go: + self.add_line(">>> ") + ConsoleRootInstance.run_command(self.to_run, command_run) + self.to_run = "" + else: + self.add_line("... ") + self.to_run += "
" + self.go = True + + def add_space(self): + self.data_field.innerHTML += " " + self.to_run += " " + self.go = False + + def add_key(self, char): + #if self.shift: + # char = chr(kc) + #else: + # char = chr(kc + 32) + self.data_field.innerHTML += char + self.to_run += char + self.go = False + + def shift_up(self): + self.shift = False + + def shift_down(self): + self.shift = True + +console = Console() + +def onchange(key): + kc = key.keyCode + if kc == 38: # up key + console.history_up() + elif kc == 40: # down key + console.history_down() + elif kc == 13: # return + console.run() + elif kc == 8: # backspace + console.backspace() + elif chr(key.charCode) == " ": + console.add_space() + else: + console.add_key(chr(key.charCode)) + logDebug(chr(key.charCode)) + log(str(key.keyCode)) + #data_field = get_document().getElementById("data") + #data_field.innerHTML = chr(key.keyCode) + #logDebug(str(conn.childNodes[1].value)) + #ConsoleRootInstance.run_command(data_field.innerHTML, comeback) + +def test_run_console(): + def some_fun(): + #cons = get_document().getElementById("data") + #write_start(cons) + createLoggingPane(True) + data_field = get_document().getElementById("data") + console.onload(data_field) + get_document().onkeypress = onchange + #get_document().onkeyup = onchangedown + + fn = compile_function(some_fun, [], root = ConsoleRoot, run_browser = True) + fn() + +if __name__ == '__main__': + test_run_console() Modified: pypy/dist/pypy/translator/js/tools/start_bnb.py ============================================================================== --- pypy/dist/pypy/translator/js/tools/start_bnb.py (original) +++ pypy/dist/pypy/translator/js/tools/start_bnb.py Mon Jul 3 01:40:03 2006 @@ -62,6 +62,7 @@ self.sprites = {} self.filenames = {} self.all_sprites = {} + self.frames = [] def add_icon(self, icon_code, filename): self.filenames[icon_code] = filename @@ -79,7 +80,11 @@ img.setAttribute("src", self.filenames[icon_code]) img.setAttribute("style", 'position:absolute; left:'+x+'px; top:'+y+'px; visibility:visible') get_document().getElementById("playfield").appendChild(img) - self.sprites[s] = img + try: + self.sprites[s].style.visibility = "hidden" + # FIXME: We should delete it + except KeyError: + self.sprites[s] = img return img def move_sprite(self, s, x, y): @@ -145,11 +150,6 @@ elif msg['type'] == 'player_icon' or msg['type'] == 'def_key' or \ msg['type'] == 'player_join' or msg['type'] == 'player_kill': pass #ignore - elif msg['type'] == 'count': - count = int(msg['n']) - if count != player.prev_count + 1: - logWarning("incorrect response order, expected " + str(player.prev_count+1) + ' got ' + str(count)) - player.prev_count = count else: logWarning('unknown message type: ' + msg['type']) @@ -237,6 +237,18 @@ def bnb_dispatcher(msgs): BnbRootInstance.get_message(bnb_dispatcher) + + count = int(msgs['add_data'][0]['n']) + if count != player.prev_count + 1: + logWarning("incorrect response order, expected " + str(player.prev_count+1) + ' got ' + str(count)) + sm.frames.append(msgs) + #else: + # player.prev_count = count + # for i in sm.frames: + # render_frame(i) + render_frame(msgs) + +def render_frame(msgs): for msg in msgs['messages']: process_message(msg) stats.register_frame() From hpk at codespeak.net Mon Jul 3 08:00:31 2006 From: hpk at codespeak.net (hpk at codespeak.net) Date: Mon, 3 Jul 2006 08:00:31 +0200 (CEST) Subject: [pypy-svn] r29601 - pypy/extradoc/sprintinfo/post-ep2006 Message-ID: <20060703060031.44AE310082@code0.codespeak.net> Author: hpk Date: Mon Jul 3 08:00:23 2006 New Revision: 29601 Modified: pypy/extradoc/sprintinfo/post-ep2006/people.txt Log: i don't think christian is coming Modified: pypy/extradoc/sprintinfo/post-ep2006/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2006/people.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2006/people.txt Mon Jul 3 08:00:23 2006 @@ -16,7 +16,6 @@ Maciej Fijalkowski 6-9th ? Anders Chrigstroem 2/7 - 10/7 NH Geneva Airport Samuele Pedroni 2/7 - 10/7 NH Geneva Airport -Christian Tismer 6-9th ? Antonio Cuni 6-9th CERN Hostel Anders Lehmann 6-9th ? Eric van Riet Paap 2-9th CERN Hostel From pedronis at codespeak.net Mon Jul 3 08:02:07 2006 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Mon, 3 Jul 2006 08:02:07 +0200 (CEST) Subject: [pypy-svn] r29602 - pypy/dist/pypy/jit/timeshifter Message-ID: <20060703060207.5937410081@code0.codespeak.net> Author: pedronis Date: Mon Jul 3 08:02:04 2006 New Revision: 29602 Modified: pypy/dist/pypy/jit/timeshifter/rtimeshift.py pypy/dist/pypy/jit/timeshifter/timeshift.py Log: (arre, pedronis) fix some of the refactoring breakage TODO: we need to be more careful with the return block there are possibly multiple less general blocks that need to be closed into a real return block. See degenerated_before_return for an example of this! Modified: pypy/dist/pypy/jit/timeshifter/rtimeshift.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/rtimeshift.py (original) +++ pypy/dist/pypy/jit/timeshifter/rtimeshift.py Mon Jul 3 08:02:04 2006 @@ -252,11 +252,13 @@ return exitindex return -1 -def prepare_return(cache, gv_return_type): +def save_return(jitstate, redboxes): + jitstate.returnbox = redboxes[0] + +def prepare_return(jitstate, cache, gv_return_type): frozens, block = cache[()] builder = ResidualGraphBuilder(block) - memo = rvalue.unfreeze_memo() - builder.valuebox = frozens[0].unfreeze(memo, block, gv_return_type) + builder.valuebox = jitstate.returnbox return builder def ll_gvar_from_redbox(jitstate, redbox): Modified: pypy/dist/pypy/jit/timeshifter/timeshift.py ============================================================================== --- pypy/dist/pypy/jit/timeshifter/timeshift.py (original) +++ pypy/dist/pypy/jit/timeshifter/timeshift.py Mon Jul 3 08:02:04 2006 @@ -322,7 +322,8 @@ cache = enter_block_logic(args_r, newinputargs, before_block, llops, - v_boxes) + v_boxes, + is_returnblock) if is_returnblock: assert self.return_cache is None self.return_cache = cache @@ -335,7 +336,7 @@ return v_boxes def bookkeeping_enter_simple(self, args_r, newinputargs, before_block, - llops, v_boxes): + llops, v_boxes, is_returnblock=False): v_newjitstate = llops.genmixlevelhelpercall(rtimeshift.enter_block, [self.s_JITState, self.s_box_list], [newinputargs[0], v_boxes], @@ -358,7 +359,7 @@ # mapping green values combinations to frozen states for red boxes values # and generated blocks def bookkeeping_enter_for_join(self, args_r, newinputargs, before_block, - llops, v_boxes): + llops, v_boxes, is_returnblock): getrepr = self.rtyper.getrepr items_s = [] key_v = [] @@ -401,7 +402,7 @@ v_boxes2 = flowmodel.Variable(v_boxes) v_boxes2.concretetype = self.r_box_list.lowleveltype - + read_boxes_block_vars = [v_newjitstate2, v_boxes2] for greenvar in orig_key_v: @@ -412,6 +413,8 @@ read_boxes_block = flowmodel.Block(read_boxes_block_vars) to_read_boxes_block = flowmodel.Link([v_newjitstate, v_boxes] + orig_key_v, read_boxes_block) to_read_boxes_block.exitcase = to_read_boxes_block.llexitcase = True + + to_dispatch_block = flowmodel.Link([v_oldjitstate], self.dispatchblock) to_dispatch_block.exitcase = to_dispatch_block.llexitcase = False @@ -423,16 +426,24 @@ llops = HintLowLevelOpList(self, None) newinputargs2 = [v_newjitstate2] - i = 0 - j = 0 - for r in args_r[1:]: - if isinstance(r, RedRepr): - newinputargs2.append(self.read_out_box(llops, v_boxes2, i)) - i += 1 - else: - newinputargs2.append(read_boxes_block_vars[j+2]) - j += 1 - + if not is_returnblock: + i = 0 + j = 0 + for r in args_r[1:]: + if isinstance(r, RedRepr): + newinputargs2.append(self.read_out_box(llops, v_boxes2, i)) + i += 1 + else: + newinputargs2.append(read_boxes_block_vars[j+2]) + j += 1 + else: + # xxx reorganize + llops.genmixlevelhelpercall(rtimeshift.save_return, + [self.s_JITState, self.s_box_list], + [v_newjitstate2, v_boxes2], + annmodel.s_None) + target = self.dispatchblock + read_boxes_block.operations[:] = llops to_target = flowmodel.Link(newinputargs2, target) @@ -499,10 +510,6 @@ llops = HintLowLevelOpList(self, None) if len(newblock.exits) == 0: # this is the original returnblock - llops.genmixlevelhelpercall(rtimeshift.save_return, - [...], - [...], - ...) newblock.recloseblock(flowmodel.Link(newblock.inputargs, self.dispatchblock)) elif len(newblock.exits) == 1 or isinstance(self.hrtyper.bindingrepr(oldexitswitch), GreenRepr): newblock.exitswitch = rename(oldexitswitch) @@ -571,8 +578,10 @@ dispatchblock.operations = list(llops) dispatch_to = self.dispatch_to - prepare_return_block = flowmodel.Block([]) - prepare_return_link = flowmodel.Link([], prepare_return_block) + v_jitstate2 = flowmodel.Variable('jitstate') + v_jitstate2.concretetype = self.r_JITState.lowleveltype + prepare_return_block = flowmodel.Block([v_jitstate2]) + prepare_return_link = flowmodel.Link([v_jitstate], prepare_return_block) dispatch_to.append(('default', prepare_return_link)) if len(dispatch_to) == 1: @@ -593,12 +602,13 @@ return_cache = self.return_cache assert return_cache is not None RETURN_TYPE = self.r_returnvalue.original_concretetype - def prepare_return(): - return rtimeshift.prepare_return(return_cache, + def prepare_return(jitstate): + return rtimeshift.prepare_return(jitstate, return_cache, rgenop.constTYPE(RETURN_TYPE)) llops = HintLowLevelOpList(self, None) v_return_builder = llops.genmixlevelhelpercall(prepare_return, - [], [], self.s_ResidualGraphBuilder) + [self.s_JITState], [v_jitstate2], + self.s_ResidualGraphBuilder) prepare_return_block.operations = list(llops) finishedlink = flowmodel.Link([v_return_builder], returnblock) From rhymes at codespeak.net Mon Jul 3 08:58:07 2006 From: rhymes at codespeak.net (rhymes at codespeak.net) Date: Mon, 3 Jul 2006 08:58:07 +0200 (CEST) Subject: [pypy-svn] r29604 - pypy/extradoc/sprintinfo/post-ep2006 Message-ID: <20060703065807.DBE8E10080@code0.codespeak.net> Author: rhymes Date: Mon Jul 3 08:58:05 2006 New Revision: 29604 Modified: pypy/extradoc/sprintinfo/post-ep2006/people.txt Log: add Fabrizio Milo to the sprinters Modified: pypy/extradoc/sprintinfo/post-ep2006/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2006/people.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2006/people.txt Mon Jul 3 08:58:05 2006 @@ -20,6 +20,7 @@ Anders Lehmann 6-9th ? Eric van Riet Paap 2-9th CERN Hostel Lawrence Oluyede 6-9th CERN Hostel +Fabrizio Milo 6-9th Geneva City Hostel Alexander Schremmer 6-9th CERN Hostel Aurelien Campeas 6-8th ? Alexandre Fayolle 6-8th ? From fijal at codespeak.net Mon Jul 3 10:32:39 2006 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 3 Jul 2006 10:32:39 +0200 (CEST) Subject: [pypy-svn] r29607 - in pypy/dist/pypy/translator/js: . demo/jsdemo/templates Message-ID: <20060703083239.59CBA10080@code0.codespeak.net> Author: fijal Date: Mon Jul 3 10:32:36 2006 New Revision: 29607 Added: pypy/dist/pypy/translator/js/demo/jsdemo/templates/console.kid Modified: pypy/dist/pypy/translator/js/jsbuiltin.py pypy/dist/pypy/translator/js/opcodes.py Log: Fixed int() isssue. Added console kid. Added: pypy/dist/pypy/translator/js/demo/jsdemo/templates/console.kid ============================================================================== --- (empty file) +++ pypy/dist/pypy/translator/js/demo/jsdemo/templates/console.kid Mon Jul 3 10:32:36 2006 @@ -0,0 +1,18 @@ + + + + + Python console + +