From fijal at codespeak.net Mon Jan 1 11:51:11 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 11:51:11 +0100 (CET) Subject: [pypy-svn] r36084 - pypy/dist/pypy/doc/js Message-ID: <20070101105111.6C6351007E@code0.codespeak.net> Author: fijal Date: Mon Jan 1 11:51:09 2007 New Revision: 36084 Modified: pypy/dist/pypy/doc/js/webapps_with_pypy.txt Log: * Added important sentence (what is rpython) * Reworded CPython/Python Modified: pypy/dist/pypy/doc/js/webapps_with_pypy.txt ============================================================================== --- pypy/dist/pypy/doc/js/webapps_with_pypy.txt (original) +++ pypy/dist/pypy/doc/js/webapps_with_pypy.txt Mon Jan 1 11:51:09 2007 @@ -26,7 +26,9 @@ JavaScript code. Unlike other libraries that perform similar functionality, PyPy really interprets the code, and produces 'lower level' JavaScript code, so it implements Python core language features like list comprehensions, and -really behaves like Python (it's not Python syntax with JS semantics). +really behaves like Python (it's not Python syntax with JS semantics). +This particulary means that when a program is in RPython, you can run it +on top of Python interpreter with the same results as translated to JS version. However, mostly for demonstration purposes, some other interesting code is available in the PyPy code package that may help developing web apps. The most @@ -52,7 +54,7 @@ A quick overview of the (main) layers of code in the application we're going to write: - * HTTP server implementation - 'normal' (C-)Python code + * HTTP server implementation - 'normal' Python code the web server code, the code that handles dealing with the HTTP API and dispatching to application code is written in 'normal' Python code, and is From fijal at codespeak.net Mon Jan 1 11:55:42 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 11:55:42 +0100 (CET) Subject: [pypy-svn] r36085 - pypy/dist/pypy/doc/js Message-ID: <20070101105542.73B061007E@code0.codespeak.net> Author: fijal Date: Mon Jan 1 11:55:40 2007 New Revision: 36085 Modified: pypy/dist/pypy/doc/js/webapps_with_pypy.txt Log: Added link. Modified: pypy/dist/pypy/doc/js/webapps_with_pypy.txt ============================================================================== --- pypy/dist/pypy/doc/js/webapps_with_pypy.txt (original) +++ pypy/dist/pypy/doc/js/webapps_with_pypy.txt Mon Jan 1 11:55:40 2007 @@ -7,7 +7,7 @@ PyPy is a platform that is very versatile, and provides almost endless possibilities. One of the features that is currently already available is -that of translating RPython (the 'restricted Python' subset) to JavaScript. +that of translating `RPython`_ (the 'restricted Python' subset) to JavaScript. This specific feature can make the life of a developer of web applications that use client-side logic a lot easier, although there are certain hurdles to take. @@ -89,3 +89,4 @@ XXX hands-on guide to writing guestbook or something +.. _`RPython`: ../coding-guide.html#restricted-python \ No newline at end of file From fijal at codespeak.net Mon Jan 1 11:58:26 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 11:58:26 +0100 (CET) Subject: [pypy-svn] r36086 - pypy/dist/pypy/lib/distributed/test Message-ID: <20070101105826.190B21007E@code0.codespeak.net> Author: fijal Date: Mon Jan 1 11:58:24 2007 New Revision: 36086 Added: pypy/dist/pypy/lib/distributed/test/ Log: Added test directory From fijal at codespeak.net Mon Jan 1 11:59:04 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 11:59:04 +0100 (CET) Subject: [pypy-svn] r36087 - in pypy/dist/pypy/lib: distributed/test test2 Message-ID: <20070101105904.D5C7A1007E@code0.codespeak.net> Author: fijal Date: Mon Jan 1 11:59:03 2007 New Revision: 36087 Added: pypy/dist/pypy/lib/distributed/test/test_distributed.py - copied unchanged from r36076, pypy/dist/pypy/lib/test2/test_distributed.py Removed: pypy/dist/pypy/lib/test2/test_distributed.py Log: Moved tests from deprecated directory From fijal at codespeak.net Mon Jan 1 12:51:53 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 12:51:53 +0100 (CET) Subject: [pypy-svn] r36088 - in pypy/dist/pypy/translator/js/modules: . test Message-ID: <20070101115153.825511007F@code0.codespeak.net> Author: fijal Date: Mon Jan 1 12:51:51 2007 New Revision: 36088 Removed: pypy/dist/pypy/translator/js/modules/bltns.py pypy/dist/pypy/translator/js/modules/test/test_xmlhttp.py pypy/dist/pypy/translator/js/modules/xmlhttp.py Log: Removed deprecated files. From fijal at codespeak.net Mon Jan 1 14:52:58 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 14:52:58 +0100 (CET) Subject: [pypy-svn] r36091 - pypy/dist/pypy/translator/js/doc Message-ID: <20070101135258.E2ECA1007F@code0.codespeak.net> Author: fijal Date: Mon Jan 1 14:52:57 2007 New Revision: 36091 Removed: pypy/dist/pypy/translator/js/doc/ Log: Removed unused dir. From fijal at codespeak.net Mon Jan 1 15:27:58 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 15:27:58 +0100 (CET) Subject: [pypy-svn] r36092 - in pypy/dist/pypy/translator/js/examples: . test Message-ID: <20070101142758.AF94A1007F@code0.codespeak.net> Author: fijal Date: Mon Jan 1 15:27:57 2007 New Revision: 36092 Modified: pypy/dist/pypy/translator/js/examples/server.py pypy/dist/pypy/translator/js/examples/test/test_server.py Log: Add a test and not fork by default. Modified: pypy/dist/pypy/translator/js/examples/server.py ============================================================================== --- pypy/dist/pypy/translator/js/examples/server.py (original) +++ pypy/dist/pypy/translator/js/examples/server.py Mon Jan 1 15:27:57 2007 @@ -98,10 +98,10 @@ self.end_headers() self.wfile.write(data) -def start_server(server_address = ('', 8000), handler=TestHandler, start_new=True): +def start_server(server_address = ('', 8000), handler=TestHandler, fork=False): httpd = HTTPServer(server_address, handler) - if start_new: + if fork: import thread thread.start_new_thread(httpd.serve_forever, ()) print "Server started, listening on %s" % (server_address,) Modified: pypy/dist/pypy/translator/js/examples/test/test_server.py ============================================================================== --- pypy/dist/pypy/translator/js/examples/test/test_server.py (original) +++ pypy/dist/pypy/translator/js/examples/test/test_server.py Mon Jan 1 15:27:57 2007 @@ -17,3 +17,7 @@ thread.start_new_thread(httpd.serve_forever, ()) assert URLopener().open("http://127.0.0.1:21210/index").read() == "xxx" +def test_own_startup(): + server.start_server(server_address=('127.0.0.1', 21211), + handler=Handler, fork=True) + assert URLopener().open("http://127.0.0.1:21210/index").read() == "xxx" From fijal at codespeak.net Mon Jan 1 15:44:33 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 15:44:33 +0100 (CET) Subject: [pypy-svn] r36094 - in pypy/dist/pypy/translator/js: . test Message-ID: <20070101144433.0D5501007F@code0.codespeak.net> Author: fijal Date: Mon Jan 1 15:44:31 2007 New Revision: 36094 Modified: pypy/dist/pypy/translator/js/main.py pypy/dist/pypy/translator/js/test/test_main.py Log: Added possibility not to specify module (caller module) and a test. Modified: pypy/dist/pypy/translator/js/main.py ============================================================================== --- pypy/dist/pypy/translator/js/main.py (original) +++ pypy/dist/pypy/translator/js/main.py Mon Jan 1 15:44:31 2007 @@ -113,6 +113,15 @@ return retval def rpython2javascript(mod, function_names, jsconfig=None, use_pdb=True): + if isinstance(function_names, str): + function_names = [function_names] + # avoid confusion + if mod is None: + # this means actual module, which is quite hairy to get in python, + # so we cheat + import sys + mod = sys.modules[sys._getframe(1).f_globals['__name__']] + if jsconfig is None: jsconfig = Config(js_optiondescr) if use_pdb: Modified: pypy/dist/pypy/translator/js/test/test_main.py ============================================================================== --- pypy/dist/pypy/translator/js/test/test_main.py (original) +++ pypy/dist/pypy/translator/js/test/test_main.py Mon Jan 1 15:44:31 2007 @@ -21,6 +21,12 @@ def fun(x='3'): return a.method({'a':x})['a'] +def fff(): + pass + def test_bookkeeper_cleanup(): - rpython2javascript(sys.modules[__name__], ["fun"]) - rpython2javascript(sys.modules[__name__], ["fun"]) + assert rpython2javascript(sys.modules[__name__], ["fun"]) + assert rpython2javascript(sys.modules[__name__], ["fun"]) + +def test_module_none(): + assert rpython2javascript(None, "fff") From fijal at codespeak.net Mon Jan 1 15:50:34 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 15:50:34 +0100 (CET) Subject: [pypy-svn] r36095 - pypy/dist/pypy/translator/js/modules Message-ID: <20070101145034.E9BAA1007F@code0.codespeak.net> Author: fijal Date: Mon Jan 1 15:50:33 2007 New Revision: 36095 Added: pypy/dist/pypy/translator/js/modules/browser.py (contents, props changed) Modified: pypy/dist/pypy/translator/js/modules/dom.py Log: Moved some stuff (one function for now) from dom to browser. Added: pypy/dist/pypy/translator/js/modules/browser.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/translator/js/modules/browser.py Mon Jan 1 15:50:33 2007 @@ -0,0 +1,9 @@ + +""" +Here are some functions which does not belong to dom, but rather +to browser itself +""" + +def alert(msg): + pass +alert.suggested_primitive = True Modified: pypy/dist/pypy/translator/js/modules/dom.py ============================================================================== --- pypy/dist/pypy/translator/js/modules/dom.py (original) +++ pypy/dist/pypy/translator/js/modules/dom.py Mon Jan 1 15:50:33 2007 @@ -303,9 +303,6 @@ func() #pass -def alert(msg): - pass - # some helper functions (XXX imo these can go, but the code seems to use them # a lot... isn't it possible to just use dom.window and dom.document instead?) From fijal at codespeak.net Mon Jan 1 15:55:51 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 15:55:51 +0100 (CET) Subject: [pypy-svn] r36096 - pypy/dist/pypy/translator/js/modules Message-ID: <20070101145551.57DC01007F@code0.codespeak.net> Author: fijal Date: Mon Jan 1 15:55:50 2007 New Revision: 36096 Modified: pypy/dist/pypy/translator/js/modules/dom.py Log: oops. Modified: pypy/dist/pypy/translator/js/modules/dom.py ============================================================================== --- pypy/dist/pypy/translator/js/modules/dom.py (original) +++ pypy/dist/pypy/translator/js/modules/dom.py Mon Jan 1 15:55:50 2007 @@ -694,7 +694,6 @@ get_window.suggested_primitive = True get_document.suggested_primitive = True setTimeout.suggested_primitive = True -alert.suggested_primitive = True # the following code wraps minidom nodes with Node classes, and makes # sure all methods on the nodes return wrapped nodes From fijal at codespeak.net Mon Jan 1 16:06:35 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 16:06:35 +0100 (CET) Subject: [pypy-svn] r36097 - pypy/dist/pypy/translator/js/tutorial Message-ID: <20070101150635.DF72E1007A@code0.codespeak.net> Author: fijal Date: Mon Jan 1 16:06:34 2007 New Revision: 36097 Added: pypy/dist/pypy/translator/js/tutorial/ pypy/dist/pypy/translator/js/tutorial/__init__.py (contents, props changed) pypy/dist/pypy/translator/js/tutorial/step1.py (contents, props changed) pypy/dist/pypy/translator/js/tutorial/step2.py (contents, props changed) Log: Added two simple steps how to start, this is intermediate checkin. Added: pypy/dist/pypy/translator/js/tutorial/__init__.py ============================================================================== Added: pypy/dist/pypy/translator/js/tutorial/step1.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/translator/js/tutorial/step1.py Mon Jan 1 16:06:34 2007 @@ -0,0 +1,27 @@ +#!/usr/bin/env python +""" + +This is simple all-in-one self-containing server, +which just shows almost-empty HTML page + +""" + +# here we import server, which is derivative of +# BaseHTTPServer from python standard library +from pypy.translator.js.examples import server + +# We create handler, which will handle all our requests +class Handler(server.TestHandler): + + def index(self): + # provide some html contents + return "
Something
" + # this line is necessary to make server show something, + # otherwise method is considered private-only + index.exposed = True + +if __name__ == '__main__': + # let's start our server, + # this will create running server instance on port 8000 by default, + # which will run until we press Control-C + server.start_server(handler=Handler) Added: pypy/dist/pypy/translator/js/tutorial/step2.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/translator/js/tutorial/step2.py Mon Jan 1 16:06:34 2007 @@ -0,0 +1,52 @@ +#!/usr/bin/env python +""" +In this example, we'll show how to add javascript to our simple +server from previous example +""" + +from pypy.translator.js.examples import server +import sys + +# here we have virtual script "source.js" which we generate +# on-the-fly when requested +HTML = """ + + + +| A row |
" + data["response"] + "
" @@ -39,7 +39,7 @@ def ping_init(): mochikit.createLoggingPane(True) - button = dom.get_document().getElementById("doping") + button = dom.document.getElementById("doping") button.onclick = doping_onclick mochikit.logDebug("Ping button setup") Modified: pypy/dist/pypy/translator/js/demo/jsdemo/example.py ============================================================================== --- pypy/dist/pypy/translator/js/demo/jsdemo/example.py (original) +++ pypy/dist/pypy/translator/js/demo/jsdemo/example.py Tue Jan 2 16:18:14 2007 @@ -6,7 +6,7 @@ from pypy.translator.js.demo.jsdemo import support -from pypy.translator.js.modules.dom import setTimeout, get_document +from pypy.translator.js.modules.dom import setTimeout, document from pypy.rpython.ootypesystem.bltregistry import MethodDesc, BasicExternal from pypy.translator.js import commproxy @@ -31,7 +31,7 @@ httpd = None def callback(data): - get_document().getElementById("counter").innerHTML = data['counter'] + document.getElementById("counter").innerHTML = data['counter'] runjs() def runjs(): Modified: pypy/dist/pypy/translator/js/demo/jsdemo/pythonconsole.py ============================================================================== --- pypy/dist/pypy/translator/js/demo/jsdemo/pythonconsole.py (original) +++ pypy/dist/pypy/translator/js/demo/jsdemo/pythonconsole.py Tue Jan 2 16:18:14 2007 @@ -12,7 +12,7 @@ import sys, os, cStringIO from cgi import parse_qs -from pypy.translator.js.modules.dom import setTimeout, get_document +from pypy.translator.js.modules.dom import setTimeout, document from pypy.rpython.ootypesystem.bltregistry import MethodDesc, BasicExternal from pypy.translator.js import commproxy from pypy.translator.js.modules.mochikit import escapeHTML @@ -46,14 +46,14 @@ httpd = None def callback(data): - inp_elem = get_document().getElementById("inp") + inp_elem = document.getElementById("inp") inp_elem.disabled = False answer = data.get('answer', '') add_text(answer) inp_elem.focus() def add_text(text): - data_elem = get_document().getElementById("data") + data_elem = document.getElementById("data") data_elem.innerHTML += escapeHTML(text) class Storage(object): @@ -66,7 +66,7 @@ def keypressed(key): kc = key.keyCode if kc == ord("\r"): - inp_elem = get_document().getElementById("inp") + inp_elem = document.getElementById("inp") cmd = inp_elem.value if storage.level == 0: add_text(">>> %s\n" % (cmd,)) @@ -85,8 +85,8 @@ storage.level = 0 def setup_page(): - get_document().onkeypress = keypressed - get_document().getElementById("inp").focus() + document.onkeypress = keypressed + document.getElementById("inp").focus() class Server(HTTPServer, BasicExternal): # Methods and signatures how they are rendered for JS Modified: pypy/dist/pypy/translator/js/examples/console.py ============================================================================== --- pypy/dist/pypy/translator/js/examples/console.py (original) +++ pypy/dist/pypy/translator/js/examples/console.py Tue Jan 2 16:18:14 2007 @@ -12,7 +12,7 @@ conftest.option.browser = "default" from pypy.translator.js.test.runtest import compile_function -from pypy.translator.js.modules.dom import Node, get_document, setTimeout, \ +from pypy.translator.js.modules.dom import Node, document, setTimeout, \ alert #from pypy.translator.js.modules.xmlhttp import XMLHttpRequest from pypy.translator.js.modules.mochikit import logDebug, createLoggingPane, log @@ -27,7 +27,7 @@ self.indent_level = 0 def initialise(self): - self.elem = get_document().getElementById("data") + self.elem = document.getElementById("data") def add_data(self, data): if self.indent_level == 0 and data == "": @@ -51,18 +51,17 @@ def onchange(key): kc = key.keyCode if kc == ord("\r"): - inp_elem = get_document().getElementById("inp") + inp_elem = document.getElementById("inp") inp_elem.value = console.add_data(inp_elem.value) def test_run_console(): def some_fun(): - #cons = get_document().getElementById("data") #write_start(cons) createLoggingPane(True) console.initialise() #data_field = get_document().getElementById("data") #console.onload(data_field) - get_document().onkeypress = onchange + document.onkeypress = onchange #get_document().onkeyup = onchangedown print "It's not working" Modified: pypy/dist/pypy/translator/js/examples/start_bnb.py ============================================================================== --- pypy/dist/pypy/translator/js/examples/start_bnb.py (original) +++ pypy/dist/pypy/translator/js/examples/start_bnb.py Tue Jan 2 16:18:14 2007 @@ -12,7 +12,7 @@ conftest.option.browser = "default" from pypy.translator.js.test.runtest import compile_function -from pypy.translator.js.modules.dom import get_document +from pypy.translator.js.modules.dom import document from pypy.translator.js.modules.xmlhttp import XMLHttpRequest from pypy.translator.js.modules.mochikit import log, logWarning, createLoggingPane, logDebug from pypy.translator.js.modules.bltns import date @@ -74,10 +74,10 @@ # img = self.sprite_queues[icon_code].pop() #except IndexError: stats.n_sprites += 1 - img = get_document().createElement("img") + img = document.createElement("img") 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) + document.getElementById("playfield").appendChild(img) try: self.sprites[s].style.visibility = "hidden" # FIXME: We should delete it @@ -144,23 +144,23 @@ def appendPlayfield(msg): bgcolor = '#000000' - get_document().body.setAttribute('bgcolor', bgcolor) - div = get_document().createElement("div") + document.body.setAttribute('bgcolor', bgcolor) + div = document.createElement("div") div.setAttribute("id", "playfield") div.setAttribute('width', msg['width']) div.setAttribute('height', msg['height']) div.setAttribute('style', 'position:absolute; top:0px; left:0px') - get_document().body.appendChild(div) + document.body.appendChild(div) def appendPlayfieldXXX(): bgcolor = '#000000' - get_document().body.setAttribute('bgcolor', bgcolor) - div = get_document().createElement("div") + document.body.setAttribute('bgcolor', bgcolor) + div = document.createElement("div") div.setAttribute("id", "playfield") div.setAttribute('width', 500) div.setAttribute('height', 250) div.setAttribute('style', 'position:absolute; top:0px; left:0px') - get_document().body.appendChild(div) + document.body.appendChild(div) def process_message(msg): if msg['type'] == 'def_playfield': @@ -247,8 +247,8 @@ # stats.__init__() # sm.__init__() # sm.begin_clean_sprites() - # playfield = get_document().getElementById("playfield") - # get_document().body.removeChild(playfield) + # playfield = document.getElementById("playfield") + # document.body.removeChild(playfield) # appendPlayfieldXXX() ## count = int(msgs['add_data'][0]['n']) @@ -266,20 +266,20 @@ for msg in msgs['messages']: process_message(msg) stats.register_frame() - get_document().title = str(stats.n_sprites) + " sprites " + str(stats.fps) + document.title = str(stats.n_sprites) + " sprites " + str(stats.fps) def session_dispatcher(msgs): BnbRootInstance.get_message(player.id, "", bnb_dispatcher) def run_bnb(): def bnb(): - genjsinfo = get_document().getElementById("genjsinfo") - get_document().body.removeChild(genjsinfo) + genjsinfo = document.getElementById("genjsinfo") + document.body.removeChild(genjsinfo) createLoggingPane(True) log("keys: [0-9] to select player, [wsad] to walk around") BnbRootInstance.initialize_session(session_dispatcher) - get_document().onkeydown = keydown - get_document().onkeyup = keyup + document.onkeydown = keydown + document.onkeyup = keyup from pypy.translator.js.demo.jsdemo.bnb import BnbRoot fn = compile_function(bnb, [], root = BnbRoot, run_browser = False) Modified: pypy/dist/pypy/translator/js/helper.py ============================================================================== --- pypy/dist/pypy/translator/js/helper.py (original) +++ pypy/dist/pypy/translator/js/helper.py Tue Jan 2 16:18:14 2007 @@ -2,7 +2,7 @@ """ Some helpers """ -from pypy.translator.js.modules.dom import get_document +from pypy.translator.js.modules.dom import document def escape(s): #return s.replace("&", "&").replace("<", "<").replace(">", ">"). \ @@ -10,23 +10,23 @@ return s def create_debug_div(): - debug_div = get_document().createElement("div") + debug_div = document.createElement("div") debug_div.setAttribute("id", "debug_div") # XXX attach it somewhere... - #body = get_document().getElementsByTagName('body')[0] - get_document().childNodes[0].childNodes[1].appendChild(debug_div) + #body = document.getElementsByTagName('body')[0] + document.childNodes[0].childNodes[1].appendChild(debug_div) return debug_div def __show_traceback(tb, exc): - debug_div = get_document().getElementById("debug_div") + debug_div = document.getElementById("debug_div") if not debug_div: # create div here debug_div = create_debug_div() - pre_div = get_document().createElement("pre") + pre_div = document.createElement("pre") pre_div.style.color = "#FF0000" debug_div.appendChild(pre_div) - txt = get_document().createTextNode("") + txt = document.createTextNode("") pre_div.appendChild(txt) for tb_entry in tb[1:]: # list of tuples... Modified: pypy/dist/pypy/translator/js/jsbuiltin.py ============================================================================== --- pypy/dist/pypy/translator/js/jsbuiltin.py (original) +++ pypy/dist/pypy/translator/js/jsbuiltin.py Tue Jan 2 16:18:14 2007 @@ -14,17 +14,12 @@ self.builtin_map = { 'll_js_jseval' : CallBuiltin('eval'), - #'ll_newlist' : CallBuiltin('newlist'), - #'ll_alloc_and_set' : CallBuiltin('alloc_and_set'), - 'get_document' : lambda g,op: g.ilasm.load_const('document'), 'set_on_keydown' : SetOnEvent('onkeydown'), 'set_on_keyup' : SetOnEvent('onkeyup'), 'setTimeout' : SetTimeout, - #'xmlSetCallback' : XmlSetCallback, 'll_int_str' : lambda g,op: Call._render_builtin_method(g, 'toString' , [op.args[2]]), 'll_strconcat' : InstructionList([PushAllArgs, '+']), 'll_int' : CallBuiltin('parseInt'), - #'ll_int' : lambda g,op: Call._render_builtin(g, 'parseInt', [op.args[0], op.args[0]]), 'alert' : CallBuiltin('alert'), 'seval' : CallBuiltin('seval'), 'date': NewBuiltin('Date'), Modified: pypy/dist/pypy/translator/js/modules/dom.py ============================================================================== --- pypy/dist/pypy/translator/js/modules/dom.py (original) +++ pypy/dist/pypy/translator/js/modules/dom.py Tue Jan 2 16:18:14 2007 @@ -87,7 +87,7 @@ def __setattr__(self, name, value): """set an attribute on the wrapped node""" - if name in dir(self): + if name in dir(self) or name.startswith('_'): return super(Node, self).__setattr__(name, value) if name not in self._fields: raise NameError, name @@ -303,18 +303,10 @@ func() #pass -# some helper functions (XXX imo these can go, but the code seems to use them -# a lot... isn't it possible to just use dom.window and dom.document instead?) - window = Window() - -def get_document(): - return window.document -get_document.suggested_primitive = True - -def get_window(): - return window -get_window.suggested_primitive = True +document = window.document +window._render_name = 'window' +document._render_name = 'document' # rtyper stuff @@ -691,8 +683,6 @@ 'charCode' : 12, }) -get_window.suggested_primitive = True -get_document.suggested_primitive = True setTimeout.suggested_primitive = True # the following code wraps minidom nodes with Node classes, and makes Modified: pypy/dist/pypy/translator/js/modules/test/test_dom.py ============================================================================== --- pypy/dist/pypy/translator/js/modules/test/test_dom.py (original) +++ pypy/dist/pypy/translator/js/modules/test/test_dom.py Tue Jan 2 16:18:14 2007 @@ -19,7 +19,7 @@ def get_window(): if TRANSLATING: - return dom.get_window() + return dom.window else: return dom.Window() Modified: pypy/dist/pypy/translator/js/test/test_basicexternal.py ============================================================================== --- pypy/dist/pypy/translator/js/test/test_basicexternal.py (original) +++ pypy/dist/pypy/translator/js/test/test_basicexternal.py Tue Jan 2 16:18:14 2007 @@ -14,6 +14,7 @@ pass a = A() +a._render_name = 'a' class B(object): pass @@ -23,7 +24,7 @@ a.some_code("aa") fun = compile_function(dec_fun, []) - check_source_contains(fun, "\.some_code") + assert check_source_contains(fun, "\.some_code") def test_basicexternal_element(): def be_fun(): @@ -32,7 +33,7 @@ b.a.some_code("aa") fun = compile_function(be_fun, []) - check_source_contains(fun, "\.some_code") + assert check_source_contains(fun, "\.some_code") ##def test_basicexternal_raise(): ## #py.test.skip("Constant BasicExternals not implemented") @@ -53,13 +54,14 @@ pass ee = EE() +ee._render_name = 'ee' def test_prebuild_basicexternal(): def tt_fun(): ee.bb() fun = compile_function(tt_fun, []) - check_source_contains(fun, "ee.bb\(") + assert check_source_contains(fun, "EE = ee") class C(BasicExternal): @described(retval=3) @@ -67,6 +69,7 @@ pass c = C() +c._render_name = 'c' def test_basicexternal_raise_method_call(): def raising_method_call(): @@ -88,6 +91,7 @@ D._fields['c'] = [D(),D()] d = D() +d._render_name = 'd' def test_basicexternal_list(): def getaa(item): Modified: pypy/dist/pypy/translator/js/test/test_bltn.py ============================================================================== --- pypy/dist/pypy/translator/js/test/test_bltn.py (original) +++ pypy/dist/pypy/translator/js/test/test_bltn.py Tue Jan 2 16:18:14 2007 @@ -6,14 +6,11 @@ from pypy.rpython.ootypesystem.bltregistry import BasicExternal, MethodDesc from pypy.translator.js.test.runtest import compile_function, check_source_contains -#def setup_function(fun): -# rebuild_basic_external() - -# check rendering dom.get_document() +# check rendering dom.document def test_simple_builtin(): - from pypy.translator.js.modules.dom import get_document + from pypy.translator.js.modules.dom import document def test_document_call(): - return get_document().getElementById("some_id") + return document.getElementById("some_id") fn = compile_function(test_document_call, []) assert check_source_contains(fn, "= document") @@ -42,6 +39,7 @@ assert check_source_contains(fn, "loadJSONDoc\('some_method'") SomeNodeInstance = SomeNode() +SomeNodeInstance._render_name = 's' # next will try out the callback def test_callback(): @@ -58,7 +56,7 @@ from pypy.translator.js.modules import dom def getaa(tname): - return dom.get_document().getElementsByTagName(tname)[0].nodeValue + return dom.document.getElementsByTagName(tname)[0].nodeValue def some_stuff(): one = getaa("some") Modified: pypy/dist/pypy/translator/js/test/test_main.py ============================================================================== --- pypy/dist/pypy/translator/js/test/test_main.py (original) +++ pypy/dist/pypy/translator/js/test/test_main.py Tue Jan 2 16:18:14 2007 @@ -17,6 +17,7 @@ method = described(retval={'a':'a'})(method) a = A() +a._render_name = 'a' def fun(x='3'): return a.method({'a':x})['a'] Modified: pypy/dist/pypy/translator/js/tutorial/step3.py ============================================================================== --- pypy/dist/pypy/translator/js/tutorial/step3.py (original) +++ pypy/dist/pypy/translator/js/tutorial/step3.py Tue Jan 2 16:18:14 2007 @@ -12,7 +12,7 @@ from pypy.translator.js.examples import server from pypy.translator.js.main import rpython2javascript -from pypy.translator.js.modules import dom +from pypy.translator.js.modules.dom import document # dom manipulating module HTML = """ @@ -33,17 +33,15 @@ # these are exposed functions def addrow(): - doc = dom.get_document() - # we need to call a helper, similiar to document in JS - tr = doc.createElement("tr") - td = doc.createElement("td") - td.appendChild(doc.createTextNode("A row")) + tr = document.createElement("tr") + td = document.createElement("td") + td.appendChild(document.createTextNode("A row")) tr.appendChild(td) - dom.get_document().getElementById("atable").appendChild(tr) + document.getElementById("atable").appendChild(tr) def delrow(): - table = dom.get_document().getElementById("atable") + table = document.getElementById("atable") # note -1 working here like in python, this is last element in list table.removeChild(table.childNodes[-1]) From fijal at codespeak.net Tue Jan 2 16:32:45 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Tue, 2 Jan 2007 16:32:45 +0100 (CET) Subject: [pypy-svn] r36109 - in pypy/dist/pypy/translator/js: . modules tutorial Message-ID: <20070102153245.9BD1F1007F@code0.codespeak.net> Author: fijal Date: Tue Jan 2 16:32:43 2007 New Revision: 36109 Removed: pypy/dist/pypy/translator/js/modules/browser.py Modified: pypy/dist/pypy/translator/js/asmgen.py pypy/dist/pypy/translator/js/jsbuiltin.py pypy/dist/pypy/translator/js/modules/dom.py pypy/dist/pypy/translator/js/support.py pypy/dist/pypy/translator/js/tutorial/step2.py Log: Kill another suggested_primitive and move back alert to dom, because alert is window.alert Modified: pypy/dist/pypy/translator/js/asmgen.py ============================================================================== --- pypy/dist/pypy/translator/js/asmgen.py (original) +++ pypy/dist/pypy/translator/js/asmgen.py Tue Jan 2 16:32:43 2007 @@ -44,7 +44,6 @@ self.subst_table = subst_table def pop(self): - #if len(self.l) == 0: el = self.l.pop() return self.subst_table.get(el, el) @@ -193,11 +192,6 @@ def set_static_field(self, _type, namespace, _class, varname): self.codegenerator.writeline("%s.prototype.%s = %s;"%(_class, varname, self.right_hand.pop())) - #def load_set_field(self, _type, name): - # #self.right_hand.append("") - # #self.codegenerator.writeline("set field %r %r"%(_type, name)) - # pass - def set_field(self, useless_parameter, name): v = self.right_hand.pop() self.codegenerator.writeline("%s.%s = %s;"%(self.right_hand.pop(), name, v)) @@ -226,10 +220,8 @@ if len(self.right_hand) == 0: return v = self.right_hand.pop() - # if v is not calling anything, drop it if v is not None and v.find('('): self.codegenerator.writeline(v+";") - #self.right_hand.pop() def begin_consts(self, name): # load consts, maybe more try to use stack-based features? @@ -293,6 +285,3 @@ def throw_real(self, s): self.codegenerator.writeline("throw(%s);"%s) - - #def finish ( self ): - # self . outfile . write ( "%r" % self . right_hand ) Modified: pypy/dist/pypy/translator/js/jsbuiltin.py ============================================================================== --- pypy/dist/pypy/translator/js/jsbuiltin.py (original) +++ pypy/dist/pypy/translator/js/jsbuiltin.py Tue Jan 2 16:32:43 2007 @@ -20,7 +20,7 @@ 'll_int_str' : lambda g,op: Call._render_builtin_method(g, 'toString' , [op.args[2]]), 'll_strconcat' : InstructionList([PushAllArgs, '+']), 'll_int' : CallBuiltin('parseInt'), - 'alert' : CallBuiltin('alert'), + #'alert' : CallBuiltin('alert'), 'seval' : CallBuiltin('seval'), 'date': NewBuiltin('Date'), 'll_math_fmod' : InstructionList([PushAllArgs, '%']), Modified: pypy/dist/pypy/translator/js/modules/dom.py ============================================================================== --- pypy/dist/pypy/translator/js/modules/dom.py (original) +++ pypy/dist/pypy/translator/js/modules/dom.py Tue Jan 2 16:32:43 2007 @@ -6,7 +6,7 @@ note that the API is not and will not be complete: more exotic features will most probably not behave as expected, or are not implemented at all - + http://www.w3.org/DOM/ - main standard http://www.w3schools.com/dhtml/dhtml_dom.asp - more informal stuff http://developer.mozilla.org/en/docs/Gecko_DOM_Reference - Gecko reference @@ -764,6 +764,9 @@ raise ValueError('unsupported node type %s' % (node.nodeType,)) return ''.join(ret) +def alert(msg): + window.alert(msg) + # initialization # set the global 'window' instance to an empty HTML document, override using Modified: pypy/dist/pypy/translator/js/support.py ============================================================================== --- pypy/dist/pypy/translator/js/support.py (original) +++ pypy/dist/pypy/translator/js/support.py Tue Jan 2 16:32:43 2007 @@ -17,7 +17,7 @@ namespace native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof - use var void volatile while with + use var void volatile while with alert ''' for name in reserved_words.split(): self.reserved[name] = True Modified: pypy/dist/pypy/translator/js/tutorial/step2.py ============================================================================== --- pypy/dist/pypy/translator/js/tutorial/step2.py (original) +++ pypy/dist/pypy/translator/js/tutorial/step2.py Tue Jan 2 16:32:43 2007 @@ -23,13 +23,13 @@ from pypy.translator.js.main import rpython2javascript # here we import rpython -> javascript conversion utility -from pypy.translator.js.modules import browser +from pypy.translator.js.modules import dom # and here we import functions from modules that we want to use # this is function which will be translated into javascript, # we can put it in a different module if we like so def show(): - browser.alert("Alert") + dom.alert("Alert") class Handler(server.TestHandler): From arigo at codespeak.net Tue Jan 2 17:57:30 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 2 Jan 2007 17:57:30 +0100 (CET) Subject: [pypy-svn] r36110 - in pypy/extradoc/planning/secprototype: . ui Message-ID: <20070102165730.F028210071@code0.codespeak.net> Author: arigo Date: Tue Jan 2 17:57:29 2007 New Revision: 36110 Added: pypy/extradoc/planning/secprototype/arch-pypy-basic.png - copied unchanged from r36104, pypy/extradoc/talk/vancouver/arch-pypy-basic.png pypy/extradoc/planning/secprototype/arch-translation.png - copied unchanged from r36104, pypy/extradoc/talk/vancouver/arch-translation.png pypy/extradoc/planning/secprototype/talk.txt - copied, changed from r36104, pypy/extradoc/talk/vancouver/talk.txt pypy/extradoc/planning/secprototype/ui/ - copied from r36104, pypy/extradoc/talk/vancouver/ui/ Log: (pedronis, cfbolz looking, arigo) The Zuerich workshop talk (still to be checked). From antocuni at codespeak.net Tue Jan 2 20:33:21 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Tue, 2 Jan 2007 20:33:21 +0100 (CET) Subject: [pypy-svn] r36111 - pypy/dist/pypy/translator/cli/test Message-ID: <20070102193321.03B2D10063@code0.codespeak.net> Author: antocuni Date: Tue Jan 2 20:33:20 2007 New Revision: 36111 Modified: pypy/dist/pypy/translator/cli/test/test_list.py pypy/dist/pypy/translator/cli/test/test_string.py Log: skip these tests for now. Modified: pypy/dist/pypy/translator/cli/test/test_list.py ============================================================================== --- pypy/dist/pypy/translator/cli/test/test_list.py (original) +++ pypy/dist/pypy/translator/cli/test/test_list.py Tue Jan 2 20:33:20 2007 @@ -5,3 +5,6 @@ class TestCliList(CliTest, BaseTestRlist): def test_recursive(self): py.test.skip("CLI doesn't support recursive lists") + + def test_getitem_exc(self): + py.test.skip('fixme!') Modified: pypy/dist/pypy/translator/cli/test/test_string.py ============================================================================== --- pypy/dist/pypy/translator/cli/test/test_string.py (original) +++ pypy/dist/pypy/translator/cli/test/test_string.py Tue Jan 2 20:33:20 2007 @@ -48,3 +48,7 @@ def fn(answer): return 'the answer is %s' % answer assert self.ll_to_string(self.interpret(fn, [42])) == 'the answer is 42' + + def test_getitem_exc(self): + py.test.skip('fixme!') + From santagada at codespeak.net Tue Jan 2 22:03:35 2007 From: santagada at codespeak.net (santagada at codespeak.net) Date: Tue, 2 Jan 2007 22:03:35 +0100 (CET) Subject: [pypy-svn] r36112 - in pypy/dist/pypy/lang/js: . test Message-ID: <20070102210335.87C131006F@code0.codespeak.net> Author: santagada Date: Tue Jan 2 22:03:29 2007 New Revision: 36112 Modified: pypy/dist/pypy/lang/js/astgen.py pypy/dist/pypy/lang/js/interpreter.py pypy/dist/pypy/lang/js/test/test_interp.py Log: binary and comparison operations ready Modified: pypy/dist/pypy/lang/js/astgen.py ============================================================================== --- pypy/dist/pypy/lang/js/astgen.py (original) +++ pypy/dist/pypy/lang/js/astgen.py Tue Jan 2 22:03:29 2007 @@ -14,6 +14,16 @@ self.left = left self.right = right +class BinaryLogicOperator(Node): + """super class for binary operators""" + def __init__(self, left, right): + self.left = left + self.right = right + +class Or(BinaryLogicOperator): pass + +class And(BinaryLogicOperator): pass + class Array(Node): def __init__(self, items=()): @@ -44,6 +54,8 @@ self.left = left self.right = right +class Eq(BinaryOperator): pass + class Function(Node): def __init__(self, name, params, body): self.name = name @@ -54,6 +66,8 @@ def __init__(self, expr): self.expr = expr +class Ge(BinaryOperator): pass + class Gt(BinaryOperator): pass class Identifier(Node): @@ -69,6 +83,8 @@ self.thenPart = thenPart self.elsePart = elsePart +class In(BinaryOperator): pass + class Index(Node): def __init__(self, left, expr): self.left = left @@ -78,8 +94,14 @@ def __init__(self, nodes): self.nodes = nodes +class Le(BinaryOperator): pass + class Lt(BinaryOperator): pass +class Minus(BinaryOperator):pass + +class Ne(BinaryOperator):pass + class New(Node): def __init__(self, identifier): self.identifier = identifier @@ -187,6 +209,12 @@ return Comma(from_dict(d['0']),from_dict(d['1'])) elif tp == 'DOT': return Dot(from_dict(d['0']), from_dict(d['1'])) + elif tp == 'EQ': + return Eq(from_dict(d['0']), from_dict(d['1'])) + elif tp == 'OR': + return Or(from_dict(d['0']), from_dict(d['1'])) + elif tp == 'AND': + return And(from_dict(d['0']), from_dict(d['1'])) elif tp == 'FUNCTION': name = d.get('name', '') body = from_dict(d['body']) @@ -198,6 +226,8 @@ return f elif tp == 'GROUP': return Group(from_dict(d['0'])) + elif tp == 'GE': + return Ge(from_dict(d['0']), from_dict(d['1'])) elif tp == 'GT': return Gt(from_dict(d['0']), from_dict(d['1'])) elif tp == 'IDENTIFIER': @@ -213,12 +243,20 @@ else: elsePart = from_dict(d['elsePart']) return If(condition,thenPart,elsePart) + elif tp == 'IN': + return In(from_dict(d['0']), from_dict(d['1'])) elif tp == 'INDEX': return Index(from_dict(d['0']), from_dict(d['1'])) elif tp == 'LIST': return List(getlist(d)) + elif tp == 'LE': + return Le(from_dict(d['0']), from_dict(d['1'])) elif tp == 'LT': return Lt(from_dict(d['0']), from_dict(d['1'])) + elif tp == 'MINUS': + return Minus(from_dict(d['0']), from_dict(d['1'])) + elif tp == 'NE': + return Ne(from_dict(d['0']), from_dict(d['1'])) elif tp == 'NEW': return New(d['0']['value']) elif tp == 'NUMBER': Modified: pypy/dist/pypy/lang/js/interpreter.py ============================================================================== --- pypy/dist/pypy/lang/js/interpreter.py (original) +++ pypy/dist/pypy/lang/js/interpreter.py Tue Jan 2 22:03:29 2007 @@ -124,29 +124,88 @@ else: pass -class __extend__(Gt): - def call(self, ctx = None): +class __extend__(Or): + def call(self, ctx): + s2 = self.left.call(ctx).GetValue() + if s2.ToBoolean(): + return s2 + s4 = self.right.call(ctx).GetValue() + return s4 + +class __extend__(And): + def call(self, ctx): s2 = self.left.call(ctx).GetValue() + if not s2.ToBoolean(): + return s2 s4 = self.right.call(ctx).GetValue() - s5 = ARC(s4, s2) + return s4 + + +class __extend__(BinaryOperator): + def call(self, ctx): + s2 = self.left.call(ctx).GetValue() + s4 = self.right.call(ctx).GetValue() + return self.decision(s2, s4) + +class __extend__(Ge): + def decision(self, op1, op2): + s5 = ARC(op1, op2) + if s5 is None or s5: + return W_Boolean(False) + else: + return W_Boolean(True) + +class __extend__(Gt): + def decision(self, op1, op2): + s5 = ARC(op2, op1) if s5 is None: return W_Boolean(False) else: return W_Boolean(s5) +class __extend__(Le): + def decision(self, op1, op2): + s5 = ARC(op2, op1) + if s5 is None or s5: + return W_Boolean(False) + else: + return W_Boolean(True) + class __extend__(Lt): - def call(self, ctx = None): - s2 = self.left.call(ctx).GetValue() - s4 = self.right.call(ctx).GetValue() - s5 = ARC(s2, s4) - print "< ARC result = ", s5 + def decision(self, op1, op2): + s5 = ARC(op1, op2) if s5 is None: return W_Boolean(False) else: return W_Boolean(s5) +def AEC(x, y): + """ + Implements the Abstract Equality Comparison x == y + not following the specs yet + """ + r = x.ToNumber() == y.ToNumber() + return r + +class __extend__(Eq): + def decision(self, op1, op2): + return W_Boolean(AEC(op1, op2)) + +class __extend__(Ne): + def decision(self, op1, op2): + return W_Boolean(not AEC(op1, op2)) + + +class __extend__(In): + def decision(self, op1, op2): + if not isinstance(op2, W_Object): + raise ThrowException("TypeError") + name = op1.ToString() + return W_Boolean(op2.HasProperty(name)) + + class __extend__(Index): - def call(self, ctx=None): + def call(self, ctx): w_obj = self.left.call(ctx).GetValue() w_member = self.expr.call(ctx).GetValue() w_obj = w_obj.ToObject() @@ -158,6 +217,12 @@ print "nodes = ", self.nodes return [node.call(ctx) for node in self.nodes] +class __extend__(Minus): + def decision(self, op1, op2): + x = op1.ToNumber() + y = op2.ToNumber() + return W_Number(x - y) + class __extend__(New): def call(self, ctx=None): obj = W_Object() @@ -165,10 +230,8 @@ constructor = ctx.resolve_identifier(self.identifier).GetValue() obj.Put('prototype', constructor.Get('prototype')) constructor.Call(ctx, this = obj) - return obj - class __extend__(Number): def call(self, ctx): return W_Number(self.num) @@ -188,13 +251,9 @@ return w_obj class __extend__(Plus): - def call(self, ctx): - print "left", self.left.call(ctx) - left = self.left.call(ctx).GetValue() - right = self.right.call(ctx).GetValue() - prim_left = left.ToPrimitive('Number') - prim_right = right.ToPrimitive('Number') - # INSANE + def decision(self, op1, op2): + prim_left = op1.ToPrimitive('Number') + prim_right = op2.ToPrimitive('Number') if isinstance(prim_left, W_String) or isinstance(prim_right, W_String): str_left = prim_left.ToString() str_right = prim_right.ToString() @@ -202,7 +261,6 @@ else: num_left = prim_left.ToNumber() num_right = prim_right.ToNumber() - # XXX: obey all the rules return W_Number(num_left + num_right) class __extend__(Script): Modified: pypy/dist/pypy/lang/js/test/test_interp.py ============================================================================== --- pypy/dist/pypy/lang/js/test/test_interp.py (original) +++ pypy/dist/pypy/lang/js/test/test_interp.py Tue Jan 2 22:03:29 2007 @@ -52,6 +52,9 @@ self.assert_prints("x=3;print(x);", ["3"]) self.assert_prints("x=3;y=4;print(x+y);", ["7"]) + def test_minus(self): + self.assert_prints("print(2-1)", ["1"]) + def test_string_var(self): self.assert_prints('print(\"sss\");', ["sss"]) @@ -82,7 +85,6 @@ self.assert_prints('var x = 3; print(x);', ["3"]) self.assert_prints('var x = 3; print(x+x);', ["6"]) - def test_var_scoping(self): self.assert_prints(""" var y; @@ -213,8 +215,22 @@ self.assert_prints("print(1<0)",["false"]) self.assert_prints("print(0<1)",["true"]) self.assert_prints("print(0<0)",["false"]) - - + self.assert_prints("print(1>=0)",["true"]) + self.assert_prints("print(1>=1)",["true"]) + self.assert_prints("print(1>=2)",["false"]) + self.assert_prints("print(0<=1)",["true"]) + self.assert_prints("print(1<=1)",["true"]) + self.assert_prints("print(1<=0)",["false"]) + self.assert_prints("print(0==0)",["true"]) + self.assert_prints("print(1==1)",["true"]) + self.assert_prints("print(0==1)",["false"]) + self.assert_prints("print(0!=1)",["true"]) + self.assert_prints("print(1!=1)",["false"]) + + def test_binary_op(self): + self.assert_prints("print(0||0); print(1||0)",["0", "1"]) + self.assert_prints("print(0&&1); print(1&&1)",["0", "1"]) + def test_while(self): self.assert_prints(""" i = 0; @@ -262,13 +278,13 @@ def test_vars(self): self.assert_prints(""" var x;x=3; print(x)""", ["3"]) - - def test_fun_decl(self): - py.test.skip("still not ready") + + def test_minus(self): self.assert_prints(""" - function x () { print('i work')} - x() - """, ["i work"]) + x = {y:3}; + print("y" in x); + print("z" in x); + """, ["true", "false"]) - + From arigo at codespeak.net Wed Jan 3 10:20:47 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 3 Jan 2007 10:20:47 +0100 (CET) Subject: [pypy-svn] r36115 - pypy/dist/pypy/rpython Message-ID: <20070103092047.76A8010064@code0.codespeak.net> Author: arigo Date: Wed Jan 3 10:20:44 2007 New Revision: 36115 Modified: pypy/dist/pypy/rpython/llinterp.py Log: Python 2.3 compatibility. Modified: pypy/dist/pypy/rpython/llinterp.py ============================================================================== --- pypy/dist/pypy/rpython/llinterp.py (original) +++ pypy/dist/pypy/rpython/llinterp.py Wed Jan 3 10:20:44 2007 @@ -1,5 +1,6 @@ from pypy.objspace.flow.model import FunctionGraph, Constant, Variable, c_last_exception -from pypy.rlib.rarithmetic import intmask, r_uint, ovfcheck, r_longlong, r_ulonglong +from pypy.rlib.rarithmetic import intmask, r_uint, ovfcheck, r_longlong +from pypy.rlib.rarithmetic import r_ulonglong, ovfcheck_lshift from pypy.rpython.lltypesystem import lltype, llmemory, lloperation, llheap from pypy.rpython.lltypesystem import rclass from pypy.rpython.ootypesystem import ootype @@ -786,6 +787,22 @@ except OverflowError: self.make_llexception() + def op_int_lshift_ovf(self, x, y): + assert isinstance(x, int) + assert isinstance(y, int) + try: + return ovfcheck_lshift(x, y) + except OverflowError: + self.make_llexception() + + def op_int_lshift_ovf_val(self, x, y): + assert isinstance(x, int) + assert isinstance(y, int) + try: + return ovfcheck_lshift(x, y) + except (OverflowError, ValueError): + self.make_llexception() + def _makefunc2(fn, operator, xtype, ytype=None): import sys d = sys._getframe(1).f_locals @@ -816,9 +833,7 @@ _makefunc2('op_int_mod_ovf', '%', 'int') _makefunc2('op_int_mod_zer', '%', 'int') _makefunc2('op_int_mod_ovf_zer', '%', 'int') - _makefunc2('op_int_lshift_ovf', '<<', 'int') _makefunc2('op_int_lshift_val', '<<', 'int') - _makefunc2('op_int_lshift_ovf_val', '<<', 'int') _makefunc2('op_int_rshift_val', '>>', 'int') _makefunc2('op_uint_floordiv_zer', '//', 'r_uint') From mwh at codespeak.net Wed Jan 3 12:53:03 2007 From: mwh at codespeak.net (mwh at codespeak.net) Date: Wed, 3 Jan 2007 12:53:03 +0100 (CET) Subject: [pypy-svn] r36117 - in pypy/dist/pypy: config objspace/std objspace/std/test Message-ID: <20070103115303.E6F901006F@code0.codespeak.net> Author: mwh Date: Wed Jan 3 12:52:58 2007 New Revision: 36117 Modified: pypy/dist/pypy/config/pypyoption.py pypy/dist/pypy/objspace/std/objspace.py pypy/dist/pypy/objspace/std/test/test_intobject.py Log: add a hopefully short-lived config option to specialize the addition of two integers in BINARY_ADD like CPython does. hopefully short-lived because it would be much nicer to specialize multimethod implementations automagically... Modified: pypy/dist/pypy/config/pypyoption.py ============================================================================== --- pypy/dist/pypy/config/pypyoption.py (original) +++ pypy/dist/pypy/config/pypyoption.py Wed Jan 3 12:52:58 2007 @@ -118,6 +118,10 @@ "list is mutaged", default=False), + BoolOption("optimized_int_add", + "special case the addition of two integers in BINARY_ADD", + default=False), + BoolOption("oldstyle", "specify whether the default metaclass should be classobj", default=False, cmdline="--oldstyle"), @@ -133,6 +137,7 @@ ("objspace.std.withstrslice", True), ("objspace.std.withsmallint", True), ("objspace.std.withrangelist", True), + ("objspace.std.optimized_int_add", True), ], cmdline="--faassen"), Modified: pypy/dist/pypy/objspace/std/objspace.py ============================================================================== --- pypy/dist/pypy/objspace/std/objspace.py (original) +++ pypy/dist/pypy/objspace/std/objspace.py Wed Jan 3 12:52:58 2007 @@ -2,6 +2,7 @@ from pypy.interpreter.baseobjspace import ObjSpace, Wrappable from pypy.interpreter.error import OperationError, debug_print from pypy.interpreter.typedef import get_unique_interplevel_subclass +from pypy.interpreter import pyframe from pypy.rlib.objectmodel import instantiate from pypy.interpreter.gateway import PyPyCacheDir from pypy.tool.cache import Cache @@ -36,39 +37,6 @@ assert issubclass(implcls, W_Object) _registered_implementations[implcls] = True -from pypy.interpreter import pyframe - -class StdObjSpaceFrame(pyframe.PyFrame): - def CALL_LIKELY_BUILTIN(f, oparg, *ignored): - from pypy.module.__builtin__ import OPTIMIZED_BUILTINS, Module - from pypy.objspace.std.dictmultiobject import W_DictMultiObject - w_globals = f.w_globals - num = oparg >> 8 - assert isinstance(w_globals, W_DictMultiObject) - w_value = w_globals.implementation.get_builtin_indexed(num) - if w_value is None: - w_builtins = f.builtin - assert isinstance(w_builtins, Module) - w_builtin_dict = w_builtins.w_dict - assert isinstance(w_builtin_dict, W_DictMultiObject) - w_value = w_builtin_dict.implementation.get_builtin_indexed(num) -## if w_value is not None: -## print "CALL_LIKELY_BUILTIN fast" - if w_value is None: - varname = OPTIMIZED_BUILTINS[num] - message = "global name '%s' is not defined" % varname - raise OperationError(f.space.w_NameError, - f.space.wrap(message)) - nargs = oparg & 0xff - w_function = w_value - try: - w_result = f.space.call_valuestack(w_function, nargs, f.valuestack) - # XXX XXX fix the problem of resume points! - #rstack.resume_point("CALL_FUNCTION", f, nargs, returns=w_result) - finally: - f.valuestack.drop(nargs) - f.valuestack.push(w_result) - ################################################################## class StdObjSpace(ObjSpace, DescrOperation): @@ -88,6 +56,55 @@ # Import all the object types and implementations self.model = StdTypeModel(self.config) + class StdObjSpaceFrame(pyframe.PyFrame): + if self.config.objspace.std.optimized_int_add: + def BINARY_ADD(f, oparg, *ignored): + from pypy.objspace.std.intobject import \ + W_IntObject, add__Int_Int + w_2 = f.valuestack.pop() + w_1 = f.valuestack.pop() + if isinstance(w_1, W_IntObject) and \ + isinstance(w_2, W_IntObject): + try: + w_result = add__Int_Int(f.space, w_1, w_2) + except FailedToImplement: + w_result = f.space.add(w_1, w_2) + else: + w_result = f.space.add(w_1, w_2) + f.valuestack.push(w_result) + + def CALL_LIKELY_BUILTIN(f, oparg, *ignored): + from pypy.module.__builtin__ import OPTIMIZED_BUILTINS, Module + from pypy.objspace.std.dictmultiobject import W_DictMultiObject + w_globals = f.w_globals + num = oparg >> 8 + assert isinstance(w_globals, W_DictMultiObject) + w_value = w_globals.implementation.get_builtin_indexed(num) + if w_value is None: + w_builtins = f.builtin + assert isinstance(w_builtins, Module) + w_builtin_dict = w_builtins.w_dict + assert isinstance(w_builtin_dict, W_DictMultiObject) + w_value = w_builtin_dict.implementation.get_builtin_indexed(num) + ## if w_value is not None: + ## print "CALL_LIKELY_BUILTIN fast" + if w_value is None: + varname = OPTIMIZED_BUILTINS[num] + message = "global name '%s' is not defined" % varname + raise OperationError(f.space.w_NameError, + f.space.wrap(message)) + nargs = oparg & 0xff + w_function = w_value + try: + w_result = f.space.call_valuestack(w_function, nargs, f.valuestack) + # XXX XXX fix the problem of resume points! + #rstack.resume_point("CALL_FUNCTION", f, nargs, returns=w_result) + finally: + f.valuestack.drop(nargs) + f.valuestack.push(w_result) + + self.FrameClass = StdObjSpaceFrame + # XXX store the dict class on the space to access it in various places if self.config.objspace.std.withstrdict: from pypy.objspace.std import dictstrobject @@ -265,7 +282,7 @@ if not we_are_translated() and isinstance(code, CPythonFakeCode): return CPythonFakeFrame(self, code, w_globals) else: - return StdObjSpaceFrame(self, code, w_globals, closure) + return self.FrameClass(self, code, w_globals, closure) def gettypefor(self, cls): return self.gettypeobject(cls.typedef) Modified: pypy/dist/pypy/objspace/std/test/test_intobject.py ============================================================================== --- pypy/dist/pypy/objspace/std/test/test_intobject.py (original) +++ pypy/dist/pypy/objspace/std/test/test_intobject.py Wed Jan 3 12:52:58 2007 @@ -375,3 +375,8 @@ def test_getnewargs(self): assert 0 .__getnewargs__() == (0,) + +class AppTestIntOptimizedAdd(AppTestInt): + def setup_class(cls): + from pypy.conftest import gettestobjspace + cls.space = gettestobjspace(**{"objspace.std.optimized_int_add": True}) From afayolle at codespeak.net Wed Jan 3 14:04:57 2007 From: afayolle at codespeak.net (afayolle at codespeak.net) Date: Wed, 3 Jan 2007 14:04:57 +0100 (CET) Subject: [pypy-svn] r36118 - pypy/extradoc/sprintinfo/leysin-winter-2007 Message-ID: <20070103130457.3AF5010069@code0.codespeak.net> Author: afayolle Date: Wed Jan 3 14:04:55 2007 New Revision: 36118 Modified: pypy/extradoc/sprintinfo/leysin-winter-2007/people.txt Log: Woops, I had forgotten to check this in Modified: pypy/extradoc/sprintinfo/leysin-winter-2007/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/leysin-winter-2007/people.txt (original) +++ pypy/extradoc/sprintinfo/leysin-winter-2007/people.txt Wed Jan 3 14:04:55 2007 @@ -27,6 +27,8 @@ Carl Friedrich Bolz 5th-14th Ermina Guido Wesdorp 6th-14th Ermina Leonardo Santagada 6th-14th Ermina +Alexandre Fayolle 8th-12th Ermina +Sylvain Th?nault 8th-12th Ermina ==================== ============== ===================== People on the following list were present at previous sprints: @@ -38,8 +40,6 @@ Michael Hudson ? ? Anders Lehmann ? ? Niklaus Haldimann ? ? -Aurelien Campeas ? ? -Alexandre Fayolle ? ? Lene Wagner ? ? Amaury Forgeot d'Arc ? ? Valentino Volonghi ? ? From arigo at codespeak.net Wed Jan 3 16:16:45 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 3 Jan 2007 16:16:45 +0100 (CET) Subject: [pypy-svn] r36119 - pypy/dist/pypy/rpython/memory Message-ID: <20070103151645.25AB110068@code0.codespeak.net> Author: arigo Date: Wed Jan 3 16:16:43 2007 New Revision: 36119 Modified: pypy/dist/pypy/rpython/memory/gc.py Log: Fix a complete bug in x_become(): replace the old object with the new one *before* we follow a pointer... otherwise the new object can be freed! Modified: pypy/dist/pypy/rpython/memory/gc.py ============================================================================== --- pypy/dist/pypy/rpython/memory/gc.py (original) +++ pypy/dist/pypy/rpython/memory/gc.py Wed Jan 3 16:16:43 2007 @@ -530,7 +530,8 @@ item = obj + itemlength * i j = 0 while j < len(offsets): - objects.append((item + offsets[j]).address[0]) + pointer = item + offsets[j] + objects.append(pointer.address[0]) j += 1 i += 1 @@ -733,13 +734,13 @@ i = 0 while i < len(offsets): pointer = obj + offsets[i] - objects.append(pointer.address[0]) # ------------------------------------------------- # begin difference from collect if pointer.address[0] == target_addr: pointer.address[0] = source_addr # end difference from collect # ------------------------------------------------- + objects.append(pointer.address[0]) i += 1 if self.is_varsize(typeid): offset = self.varsize_offset_to_variable_part( @@ -753,14 +754,14 @@ item = obj + itemlength * i j = 0 while j < len(offsets): - objects.append((item + offsets[j]).address[0]) + pointer = item + offsets[j] # ------------------------------------------------- # begin difference from collect - pointer = item + offsets[j] if pointer.address[0] == target_addr: pointer.address[0] = source_addr ## end difference from collect # ------------------------------------------------- + objects.append(pointer.address[0]) j += 1 i += 1 From arigo at codespeak.net Wed Jan 3 16:26:44 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Wed, 3 Jan 2007 16:26:44 +0100 (CET) Subject: [pypy-svn] r36120 - in pypy/dist/pypy: rlib/rctypes rlib/rctypes/test rpython rpython/lltypesystem rpython/lltypesystem/test rpython/memory rpython/memory/gctransform rpython/memory/gctransform/test translator/c translator/llvm Message-ID: <20070103152644.0DAA610068@code0.codespeak.net> Author: arigo Date: Wed Jan 3 16:26:37 2007 New Revision: 36120 Modified: pypy/dist/pypy/rlib/rctypes/rctypesobject.py pypy/dist/pypy/rlib/rctypes/test/test_rctypesobject.py pypy/dist/pypy/rpython/llinterp.py pypy/dist/pypy/rpython/lltypesystem/llmemory.py pypy/dist/pypy/rpython/lltypesystem/lltype.py pypy/dist/pypy/rpython/lltypesystem/test/test_llmemory.py pypy/dist/pypy/rpython/memory/gcheader.py pypy/dist/pypy/rpython/memory/gctransform/framework.py pypy/dist/pypy/rpython/memory/gctransform/test/test_framework.py pypy/dist/pypy/translator/c/database.py pypy/dist/pypy/translator/c/primitive.py pypy/dist/pypy/translator/llvm/database.py Log: Simplification of llmemory, triggered by the fact that two addresses would compare as different if they were obtained in different ways, even if they pointed to the same final object. The 'offset' field of fakeaddress is gone, and 'ob' is renamed to 'ptr'. It's always just a pointer. With the new stuff in lltype like direct_fieldptr() we can take pointers to fields, or array items, so no need for anything more. Hack a bit for arenas and address-of-length-of-array. A new test in rctypesobject that triggered this whole thing, and implementation of recursive data structures. llvm/database.py updated but not tested (will do so on another machine). gctransform/test/test_framework took ages because of the llinterpretation of a raw_memclear() of the root stack, with 160'000 items! Trying to do something cleaner about raw_memcopy() in llmemory.py. Modified: pypy/dist/pypy/rlib/rctypes/rctypesobject.py ============================================================================== --- pypy/dist/pypy/rlib/rctypes/rctypesobject.py (original) +++ pypy/dist/pypy/rlib/rctypes/rctypesobject.py Wed Jan 3 16:26:37 2007 @@ -242,35 +242,29 @@ try: return contentscls._ptrcls except AttributeError: - assert issubclass(contentscls, RCTypesObject) - if contentscls in _abstract_classes: - raise Exception("cannot call RPointer(%s) or " - "pointer(x) if x degenerated to the base " - "%s class" % (contentscls.__name__, - contentscls.__name__,)) class RCTypesPtr(RCTypesObject): - CONTENTS = contentscls.CDATATYPE - LLTYPE = lltype.Ptr(CONTENTS) + LLTYPE = lltype.Ptr(lltype.ForwardReference()) num_keepalives = 1 + setpointertype = classmethod(_rpointer_set_pointer_type) def get_contents(self): ptr = self.ll_ref(RCTypesPtr.CDATATYPE) targetaddr = llmemory.cast_ptr_to_adr(ptr[0]) keepalive_until_here(self) - targetkeepalives = contentscls.num_keepalives + targetkeepalives = RCTypesPtr.CONTENTSCLS.num_keepalives targetmemblock = self._getmemblock(0, targetkeepalives) - return contentscls(targetaddr, targetmemblock) + return RCTypesPtr.CONTENTSCLS(targetaddr, targetmemblock) def ref(self, index): ptr = self.ll_ref(RCTypesPtr.CDATATYPE) targetaddr = llmemory.cast_ptr_to_adr(ptr[0]) if index: - targetaddr += ofs_item * index + targetaddr += self._OFS_ITEM * index keepalive_until_here(self) - targetkeepalives = contentscls.num_keepalives + targetkeepalives = RCTypesPtr.CONTENTSCLS.num_keepalives targetmemblock = self._getmemblock(0, targetkeepalives) - return contentscls(targetaddr, targetmemblock) + return RCTypesPtr.CONTENTSCLS(targetaddr, targetmemblock) def set_contents(self, newcontentsbox): targetaddr = newcontentsbox.addr @@ -293,11 +287,30 @@ keepalive_until_here(self) self._keepalivememblock(0, None) - ofs_item = llmemory.sizeof(contentscls.LLTYPE) - contentscls._ptrcls = RCTypesPtr + if contentscls is None: + pass # forward pointer + else: + RCTypesPtr.setpointertype(contentscls) return RCTypesPtr RPointer._annspecialcase_ = 'specialize:memo' +def _rpointer_set_pointer_type(RCTypesPtr, contentscls): + assert issubclass(contentscls, RCTypesObject) + if contentscls in _abstract_classes: + raise Exception("cannot call RPointer(%s) or " + "pointer(x) if x degenerated to the base " + "%s class" % (contentscls.__name__, + contentscls.__name__,)) + RCTypesPtr.CONTENTSCLS = contentscls + RCTypesPtr.CONTENTS = contentscls.CDATATYPE + RCTypesPtr.LLTYPE.TO.become(RCTypesPtr.CONTENTS) + RCTypesPtr._OFS_ITEM = llmemory.sizeof(contentscls.LLTYPE) + RCTypesPtr.__name__ = 'RCTypes_%s' % (RCTypesPtr.LLTYPE,) + assert not hasattr(contentscls, '_ptrcls'), ( + "the RPointer class corresponding to %r exists already" % + (contentscls,)) + contentscls._ptrcls = RCTypesPtr + def pointer(x): PTR = RPointer(x.__class__) p = PTR.allocate() Modified: pypy/dist/pypy/rlib/rctypes/test/test_rctypesobject.py ============================================================================== --- pypy/dist/pypy/rlib/rctypes/test/test_rctypesobject.py (original) +++ pypy/dist/pypy/rlib/rctypes/test/test_rctypesobject.py Wed Jan 3 16:26:37 2007 @@ -266,6 +266,18 @@ res = self.do(func) assert res == 101 + def test_recursive_structure(self): + P1 = RPointer(None) + S1 = RStruct('S1', [('next', P1)]) + P1.setpointertype(S1) + def func(): + s1 = S1.allocate() + s2 = S1.allocate() + s2.ref_next().set_contents(s1) + return s2.ref_next().get_contents().sameaddr(s1) + res = self.do(func) + assert res == True + POLICY = AnnotatorPolicy() POLICY.allow_someobjects = False Modified: pypy/dist/pypy/rpython/llinterp.py ============================================================================== --- pypy/dist/pypy/rpython/llinterp.py (original) +++ pypy/dist/pypy/rpython/llinterp.py Wed Jan 3 16:26:37 2007 @@ -571,8 +571,7 @@ def op_unsafe_call(self, TGT, f): checkadr(f) - assert f.offset is None - obj = self.llinterpreter.typer.type_system.deref(f.ob) + obj = self.llinterpreter.typer.type_system.deref(f.ref()) assert hasattr(obj, 'graph') # don't want to think about that graph = obj.graph args = [] @@ -670,8 +669,8 @@ def op_gc_call_rtti_destructor(self, rtti, addr): if hasattr(rtti._obj, 'destructor_funcptr'): d = rtti._obj.destructor_funcptr - ob = addr.get() - return self.op_direct_call(d, ob) + obptr = addr.ref() + return self.op_direct_call(d, obptr) def op_gc_deallocate(self, TYPE, addr): raise NotImplementedError("gc_deallocate") Modified: pypy/dist/pypy/rpython/lltypesystem/llmemory.py ============================================================================== --- pypy/dist/pypy/rpython/lltypesystem/llmemory.py (original) +++ pypy/dist/pypy/rpython/lltypesystem/llmemory.py Wed Jan 3 16:26:37 2007 @@ -4,6 +4,7 @@ # sizeof, offsetof +import weakref from pypy.rlib.objectmodel import Symbolic from pypy.rpython.lltypesystem import lltype @@ -21,11 +22,12 @@ return NotImplemented return CompositeOffset(self, other) - def raw_malloc(self, rest): + def raw_malloc(self, rest, zero): raise NotImplementedError("raw_malloc(%r, %r)" % (self, rest)) - def raw_memclear(self, adr): - raise NotImplementedError("raw_memclear(%r, %r)" % (self, adr)) + def raw_memcopy(self, srcadr, dstsrc): + raise NotImplementedError("raw_memcopy(%r)" % (self,)) + class ItemOffset(AddressOffset): @@ -46,56 +48,57 @@ def __neg__(self): return ItemOffset(self.TYPE, -self.repeat) - def ref(self, firstitemref): - if isinstance(firstitemref, _obref): - parent, index = lltype.parentlink(firstitemref.ob._obj) - if parent is None: - raise TypeError("address + itemoffset: not the address" - " of an array") - A = lltype.typeOf(parent) - assert isinstance(A, (lltype.Array, lltype.FixedSizeArray)) + def ref(self, firstitemptr): + A = lltype.typeOf(firstitemptr).TO + if A == self.TYPE: + # for array of containers + parent, index = lltype.parentlink(firstitemptr._obj) + assert parent, "%r is not within a container" % (firstitemptr,) + assert isinstance(lltype.typeOf(parent), + (lltype.Array, lltype.FixedSizeArray)), ( + "%r is not within an array" % (firstitemptr,)) if isinstance(index, str): - assert index.startswith("item") - index = int(index[4:]) # "itemN" => N - firstitemref = _arrayitemref(parent._as_ptr(), index) - assert isinstance(firstitemref, _arrayitemref) - array = firstitemref.array - assert lltype.typeOf(array).TO.OF == self.TYPE - index = firstitemref.index + self.repeat - return _arrayitemref(array, index) + assert index.startswith('item') # itemN => N + index = int(index[4:]) + return parent.getitem(index + self.repeat)._as_ptr() + elif isinstance(A, lltype.FixedSizeArray) and A.OF == self.TYPE: + # for array of primitives or pointers + return lltype.direct_ptradd(firstitemptr, self.repeat) + else: + raise TypeError('got %r, expected %r' % (A, self.TYPE)) - def raw_malloc(self, rest): + def raw_malloc(self, rest, zero): assert not rest if (isinstance(self.TYPE, lltype.ContainerType) and self.TYPE._gckind == 'gc'): assert self.repeat == 1 - p = lltype.malloc(self.TYPE, flavor='raw') + p = lltype.malloc(self.TYPE, flavor='raw', zero=zero) return cast_ptr_to_adr(p) else: T = lltype.FixedSizeArray(self.TYPE, self.repeat) - p = lltype.malloc(T, flavor='raw') + p = lltype.malloc(T, flavor='raw', zero=zero) array_adr = cast_ptr_to_adr(p) return array_adr + ArrayItemsOffset(T) - def raw_memclear(self, adr): - if (isinstance(self.TYPE, lltype.ContainerType) and self.repeat == 1): - from pypy.rpython.rctypes.rmodel import reccopy - fresh = lltype.malloc(self.TYPE, flavor='raw', zero=True) - reccopy(fresh, adr.get()) - else: - assert adr.offset is not None - if isinstance(adr.offset, ArrayItemsOffset): - array = adr.ob - elif isinstance(adr.offset, CompositeOffset): - array = (adr + -adr.offset.offsets[-1]).get() - if isinstance(self.TYPE, lltype.ContainerType): - fresh = lltype.malloc(self.TYPE, flavor='raw', zero=True) - for i in range(self.repeat): - reccopy(fresh, array[i]) - else: - for i in range(self.repeat): - array[i] = self.TYPE._defl() - + def raw_memcopy(self, srcadr, dstadr): + repeat = self.repeat + if repeat == 0: + return + from pypy.rpython.rctypes.rmodel import reccopy + if isinstance(self.TYPE, lltype.ContainerType): + PTR = lltype.Ptr(self.TYPE) + else: + PTR = lltype.Ptr(lltype.FixedSizeArray(self.TYPE, 1)) + while True: + src = cast_adr_to_ptr(srcadr, PTR) + dst = cast_adr_to_ptr(dstadr, PTR) + reccopy(src, dst) + repeat -= 1 + if repeat <= 0: + break + srcadr += ItemOffset(self.TYPE) + dstadr += ItemOffset(self.TYPE) + class FieldOffset(AddressOffset): @@ -106,33 +109,31 @@ def __repr__(self): return "