[pypy-svn] r31965 - in pypy/dist/pypy/translator/js: . demo/jsdemo modules/test test tools

fijal at codespeak.net fijal at codespeak.net
Sun Sep 3 14:16:43 CEST 2006


Author: fijal
Date: Sun Sep  3 14:16:09 2006
New Revision: 31965

Added:
   pypy/dist/pypy/translator/js/modules/test/__init__.py   (contents, props changed)
   pypy/dist/pypy/translator/js/test/test_transformer.py   (contents, props changed)
Modified:
   pypy/dist/pypy/translator/js/demo/jsdemo/consserv.py
   pypy/dist/pypy/translator/js/js.py
   pypy/dist/pypy/translator/js/main.py
   pypy/dist/pypy/translator/js/modules/test/test_dom.py
   pypy/dist/pypy/translator/js/test/runtest.py
   pypy/dist/pypy/translator/js/test/test_seq.py
   pypy/dist/pypy/translator/js/tools/console.py
Log:
Added basic support for debug transform, some minor fixes as well. Need to write wrapper around it next.


Modified: pypy/dist/pypy/translator/js/demo/jsdemo/consserv.py
==============================================================================
--- pypy/dist/pypy/translator/js/demo/jsdemo/consserv.py	(original)
+++ pypy/dist/pypy/translator/js/demo/jsdemo/consserv.py	Sun Sep  3 14:16:09 2006
@@ -36,12 +36,11 @@
     def run_command(self, str_to_eval = "aa"):
         # we need what has changed
         # we try to run it...
-        
         lines = str_to_eval.split("<br>")
         for num, line in enumerate(lines):
             if not line.startswith(" "):
                 lines[num] = "    " + line
-        all_text = "\n".join(["def f():"] + lines[:-1])
+        all_text = "\n".join(["def f():"] + lines)
         print all_text
         try:
             exec(all_text)

Modified: pypy/dist/pypy/translator/js/js.py
==============================================================================
--- pypy/dist/pypy/translator/js/js.py	(original)
+++ pypy/dist/pypy/translator/js/js.py	Sun Sep  3 14:16:09 2006
@@ -34,7 +34,8 @@
     return path
 
 class JS(GenOO):
-    def __init__(self, translator, functions=[], stackless=False, compress=False, logging=False):
+    def __init__(self, translator, functions=[], stackless=False, compress=False, \
+            logging=False, use_debug=False):
         backend_mapping = {
             'type_system_class' : JTS,
             'opcode_dict' : opcodes,
@@ -49,6 +50,7 @@
             translator.annotator.bookkeeper.getdesc(f).cachedgraph(None) for f in functions ])
         self.translator = translator
         self.db.translator = translator
+        self.use_debug = use_debug
     
     def gen_pendings(self):
         while self.db._pending_nodes:

Modified: pypy/dist/pypy/translator/js/main.py
==============================================================================
--- pypy/dist/pypy/translator/js/main.py	(original)
+++ pypy/dist/pypy/translator/js/main.py	Sun Sep  3 14:16:09 2006
@@ -5,7 +5,7 @@
 
 #from pypy.translator.js.test.runtest import compile_function
 #from pypy.translator.translator import TranslationContext
-from pypy.translator.driver import TranslationDriver
+from pypy.translator.driver import TranslationDriver, _default_options
 from pypy.translator.js.js import JS
 from pypy.tool.error import AnnotatorError, FlowingError, debug
 from pypy.rpython.nonconst import NonConstant
@@ -38,7 +38,7 @@
     mod = __import__(module_name, None, None, ["Module"])
     return rpython2javascript(mod, function_names)
 
-def rpython2javascript(mod, function_names):
+def rpython2javascript(mod, function_names, use_debug=True):
     module_name = mod.__name__
     if not function_names and 'main' in mod.__dict__:
         function_names.append('main')
@@ -50,11 +50,12 @@
             raise BadSignature("Function %s does not have default arguments" % func_name)
     source_ssf = "\n".join(["import %s" % module_name, "def some_strange_function_which_will_never_be_called():"] + ["  "+\
         module_name+"."+fun_name+get_args(mod.__dict__[fun_name]) for fun_name in function_names])
-    print source_ssf
     exec(source_ssf) in globals()
     #fn = compile_function([mod.__dict__[f_name] for f_name in function_names], [[] for i in function_names])
     # now we gonna just cut off not needed function
-    driver = TranslationDriver()
+    options = _default_options.copy()
+    options.debug_transform = use_debug
+    driver = TranslationDriver(options=options)
     try:
         driver.setup(some_strange_function_which_will_never_be_called, [], policy = JsPolicy())
         driver.proceed(["compile_js"])

Added: pypy/dist/pypy/translator/js/modules/test/__init__.py
==============================================================================

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	Sun Sep  3 14:16:09 2006
@@ -9,20 +9,6 @@
 from pypy.translator.js import conftest
 #from pypy.rpython.rjs import jseval
 
-import time
-
-if not conftest.option.browser:
-    py.test.skip("Works only in browser (right now?)")
-
-def test_document_base():
-    def f():
-        return get_document().getElementById("dupa")
-        #document.getElementById("dupa").setInnerHTML("<h1>Fire!</h1>")
-        #return document.getElementById("dupa")
-    
-    fn = compile_function(f, [], html = 'html/test.html')
-    assert fn() == '[object HTMLHeadingElement]'
-
 class Mover(object):
     def __init__(self, elem):
         self.x = 0
@@ -54,37 +40,51 @@
 def move_it():
     movers[0].move_it()
     #movers[1].move_it()
-
-def test_anim_f():  
-    def anim_fun():
-        obj = get_document().createElement('img')
-        obj.id = 'anim_img'
-        obj.setAttribute('style', 'position:absolute; top:0; left:0;')
-        obj.src = '/static/gfx/BubBob.gif'
-        get_document().body.appendChild(obj)
-        #obj2 = get_document().getElementById("anim_img2")
-        #obj2.setAttribute('style', 'position: absolute; top: 50; left: 0;')
-        move_it()
-        setTimeout(move_it, 10)
-        return get_document().getElementById("anim_img").style.left
     
-    fn = compile_function(anim_fun, [], html = 'html/anim.html')
-    assert fn() == '3px'
-
-xml = XMLHttpRequest()
-
-def t_xml_fun():
-    if xml.readyState == 4:
-        alert('Wow!')
+class TestReal(object):
+    def setup_class(self):
+        if not conftest.option.browser:
+            py.test.skip("Works only in browser (right now?)")
+    
+    def test_document_base(self):
+        def f():
+            return get_document().getElementById("dupa")
+            #document.getElementById("dupa").setInnerHTML("<h1>Fire!</h1>")
+            #return document.getElementById("dupa")
+        
+        fn = compile_function(f, [], html = 'html/test.html')
+        assert fn() == '[object HTMLHeadingElement]'
+    
+    def test_anim_f(self):  
+        def anim_fun():
+            obj = get_document().createElement('img')
+            obj.id = 'anim_img'
+            obj.setAttribute('style', 'position:absolute; top:0; left:0;')
+            obj.src = '/static/gfx/BubBob.gif'
+            get_document().body.appendChild(obj)
+            #obj2 = get_document().getElementById("anim_img2")
+            #obj2.setAttribute('style', 'position: absolute; top: 50; left: 0;')
+            move_it()
+            setTimeout(move_it, 10)
+            return get_document().getElementById("anim_img").style.left
         
-def test_xmlhttp():
-    """ Low level XMLHttpRequest test
-    """
-    def xml_fun():
-        xml.open('GET', '/get_some_info?info=dupa', True)
-        xml.onreadystatechange = t_xml_fun
-        #return xml.readyState
-        xml.send(None)
+        fn = compile_function(anim_fun, [], html = 'html/anim.html')
+        assert fn() == '3px'
+    
+    xml = XMLHttpRequest()
     
-    fn = compile_function(xml_fun, [])
-    fn()
+    def t_xml_fun(self):
+        if xml.readyState == 4:
+            alert('Wow!')
+            
+    def test_xmlhttp(self):
+        """ Low level XMLHttpRequest test
+        """
+        def xml_fun():
+            xml.open('GET', '/get_some_info?info=dupa', True)
+            xml.onreadystatechange = t_xml_fun
+            #return xml.readyState
+            xml.send(None)
+        
+        fn = compile_function(xml_fun, [])
+        fn()

Modified: pypy/dist/pypy/translator/js/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/runtest.py	(original)
+++ pypy/dist/pypy/translator/js/test/runtest.py	Sun Sep  3 14:16:09 2006
@@ -12,6 +12,7 @@
 from pypy.translator.js.log import log
 from pypy.conftest import option
 from pypy.rpython.test.tool import BaseRtypingTest, OORtypeMixin
+from pypy.translator.transformer.debug import DebugTransformer
 
 log = log.runtest
 use_browsertest = conftest.option.browser
@@ -27,16 +28,18 @@
     return True
 
 class compile_function(object):
-    def __init__(self, functions, annotations, stackless=False, view=False, html=None, is_interactive=False, root = None, run_browser = True):
+    def __init__(self, functions, annotations, stackless=False, view=False, html=None, is_interactive=False, root = None, run_browser = True, debug_transform = False):
         if not use_browsertest and not _CLI_is_on_path():
             py.test.skip('Javascript CLI (js) not found')
 
         self.html = html
         self.is_interactive = is_interactive
         t = TranslationContext()
-        t.buildannotator().build_types(functions, annotations)
+        ann = t.buildannotator()
+        ann.build_types(functions, annotations)
+        if debug_transform:
+            DebugTransformer(t).transform_all()
         t.buildrtyper(type_system="ootype").specialize()
-        #print t.rtyper
 
         #backend_optimizations(t, raisingop2direct_call_all=True, inline_threshold=0, mallocs=False)
         #backend_optimizations(t)

Modified: pypy/dist/pypy/translator/js/test/test_seq.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_seq.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_seq.py	Sun Sep  3 14:16:09 2006
@@ -76,6 +76,17 @@
             for y in c2.keys():
                 assert fn(x, y) == soph_const(x, y)
 
+    def test_dict_iterator(self):
+        c = {'aa':1, 'bb':2, 'cc':3, 'dd':4}
+        def dict_iter():
+            sum = 0
+            for i in c:
+                sum += c[i]
+            return sum
+
+        fn = compile_function(dict_iter, [])
+        assert fn() == dict_iter()
+
 class TestTuple(object):
     def test_f1(self):
         f = compile_function(llvmsnippet.tuple_f1, [int])

Added: pypy/dist/pypy/translator/js/test/test_transformer.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js/test/test_transformer.py	Sun Sep  3 14:16:09 2006
@@ -0,0 +1,42 @@
+
+""" some javascript transform test examples
+"""
+
+from pypy.translator.js.main import rpython2javascript
+from pypy.translator.js.test.runtest import compile_function
+from pypy.translator.transformer.debug import traceback_handler
+
+def test_simple_tansform():
+    def g():
+        raise ValueError()
+    
+    def f():
+        g()
+    
+    def wrapper():
+        try:
+            # XXX: this is needed to make annotator happy
+            traceback_handler.enter("entrypoint", "data")
+            f()
+        except:
+            return "|".join([i + ": " + j for i, j in traceback_handler.tb])
+        return ""
+    
+    fn = compile_function(wrapper, [], debug_transform = True)
+    retval = fn()
+    lst = retval.split('|')
+    assert len(lst) == 3
+    assert lst[1] == 'f: ()'
+    assert lst[2] == 'g: ()'
+
+def test_simple_seq():
+    def fun(i):
+        if i:
+            a = [("ab", "cd"), ("ef", "xy")]
+        else:
+            a = [("xz", "pr"), ("as", "fg")]
+        return ",".join(["%s : %s" % (i, j) for i,j in a])
+    
+    fn = compile_function(fun, [int])
+    assert fn(0) == fun(0)
+    assert fn(1) == fun(1)

Modified: pypy/dist/pypy/translator/js/tools/console.py
==============================================================================
--- pypy/dist/pypy/translator/js/tools/console.py	(original)
+++ pypy/dist/pypy/translator/js/tools/console.py	Sun Sep  3 14:16:09 2006
@@ -45,7 +45,7 @@
 console = Console()
 
 def comeback(msg):
-    pass
+    jseval(msg['source'] + "\nf()")
 
 def onchange(key):
     kc = key.keyCode



More information about the Pypy-commit mailing list