[pypy-svn] r19599 - in pypy/dist/pypy/translator/js: . test

ericvrp at codespeak.net ericvrp at codespeak.net
Mon Nov 7 13:51:54 CET 2005


Author: ericvrp
Date: Mon Nov  7 13:51:53 2005
New Revision: 19599

Modified:
   pypy/dist/pypy/translator/js/codewriter.py
   pypy/dist/pypy/translator/js/js.py
   pypy/dist/pypy/translator/js/opwriter.py
   pypy/dist/pypy/translator/js/test/browsertest.py
   pypy/dist/pypy/translator/js/test/test_exception.py
Log:
* Added phi node to try/catch blocks making three exception tests pass.

* being more verbose in the browser window. (showing the js code)


Modified: pypy/dist/pypy/translator/js/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/codewriter.py	(original)
+++ pypy/dist/pypy/translator/js/codewriter.py	Mon Nov  7 13:51:53 2005
@@ -78,7 +78,7 @@
             self.append('block = ' + str(block))
             self.append('break')
 
-    def _phi(self, targetblock, exit):
+    def _phi(self, exit):
         for i, exitarg in enumerate(exit.args):
             dest = str(exit.target.inputargs[i])
             src = str(self.js.db.repr_arg(exitarg))
@@ -92,19 +92,19 @@
                 self.append('%s = %s' % (dest, src))
 
     def br_uncond(self, block, exit): 
-        self._phi(block, exit)
+        self._phi(exit)
         self._goto_block(block)
         self.skip_closeblock()
 
     def br(self, cond, block_false, exit_false, block_true, exit_true):
         self.append('if (%s) {' % cond)
         self.indent_more()
-        self._phi(block_true, exit_true)
+        self._phi(exit_true)
         self._goto_block(block_true)
         self.indent_less()
         self.append('} else {')
         self.indent_more()
-        self._phi(block_false, exit_false)
+        self._phi(exit_false)
         self._goto_block(block_false)
         self.indent_less()
         self.append('}')
@@ -156,24 +156,27 @@
     def neg(self, targetvar, source):
         self.append('%(targetvar)s = -%(source)s' % locals())
         
-    def call(self, targetvar, functionref, argrefs, label=None, exceptions=[]):
+    def call(self, targetvar, functionref, argrefs, no_exception=None, exceptions=[]):
         args = ", ".join(argrefs)
 
         if not exceptions:
-            assert label is None
+            assert no_exception is None
             self.append('%s = %s(%s)' % (targetvar, functionref, args))
         else:
-            assert label is not None
+            assert no_exception is not None
+            no_exception_label, no_exception_exit = no_exception
             self.append('try {')
             self.indent_more()
-            self._goto_block(label)
+            self.append('%s = %s(%s)' % (targetvar, functionref, args))
+            self._phi(no_exception_exit)
+            self._goto_block(no_exception_label)
             self.indent_less()
             
             self.append('} catch (e) {')
             self.indent_more()
             catch_all = False
             for i, exception in enumerate(exceptions):
-                exception_match, exception_ref, exception_target = exception
+                exception_match, exception_ref, exception_target, exit = exception
                 if i:
                     else_ = 'else '
                 else:
@@ -185,6 +188,7 @@
                     matcher   = 'if (%s(e.typeptr, %s) == true) ' % (exception_match, exception_ref)
                 self.append('%s%s{' % (else_, matcher))
                 self.indent_more()
+                self._phi(exit)
                 self._goto_block(exception_target)
                 self.indent_less()
                 self.append('}')

Modified: pypy/dist/pypy/translator/js/js.py
==============================================================================
--- pypy/dist/pypy/translator/js/js.py	(original)
+++ pypy/dist/pypy/translator/js/js.py	Mon Nov  7 13:51:53 2005
@@ -140,8 +140,8 @@
         #codewriter.comment("Wrapper code for the Javascript CLI", 0)
         #codewriter.newline()
         #codewriter.append(self.wrappercode, 0)
-        codewriter.newline()
-        codewriter.comment("EOF")
+        #codewriter.newline()
+        #codewriter.comment("EOF")
         f.close()
 
         log('Written:', self.filename)

Modified: pypy/dist/pypy/translator/js/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/opwriter.py	(original)
+++ pypy/dist/pypy/translator/js/opwriter.py	Mon Nov  7 13:51:53 2005
@@ -271,6 +271,7 @@
         targetvar  = self.db.repr_arg(op.result)
         argrefs    = self.db.repr_arg_multi(op_args[1:])
         none_label = self.node.blockindex[link.target]
+        no_exception = (none_label, link)
 
         exceptions = []
         for exit in self.block.exits[1:]:
@@ -278,10 +279,10 @@
             exception_match  = self.db.translator.rtyper.getexceptiondata().ll_exception_match.__name__
             exception_ref    = self.db.obj2node[exit.llexitcase._obj].get_ref()
             exception_target = self.node.blockindex[exit.target]
-            exception        = (exception_match, exception_ref, exception_target)
+            exception        = (exception_match, exception_ref, exception_target, exit)
             exceptions.append(exception)
 
-        self.codewriter.call(targetvar, functionref, argrefs, none_label, exceptions)
+        self.codewriter.call(targetvar, functionref, argrefs, no_exception, exceptions)
 
     def malloc(self, op): 
         arg_type = op.args[0].value

Modified: pypy/dist/pypy/translator/js/test/browsertest.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/browsertest.py	(original)
+++ pypy/dist/pypy/translator/js/test/browsertest.py	Mon Nov  7 13:51:53 2005
@@ -14,23 +14,20 @@
 
     html_page = """<html>
 <head>
-<title>%(jsfilename)s</title>
 <script type="text/javascript">
 %(jscode)s
-</script>
-<script type="text/javascript">
-    function runTest() {
-        var result = undefined;
-        try {
-            result = %(jstestcase)s;
-        } catch (e) {
-            //result = 'Exception("' + e.toString() + '")'
-            result = 'undefined'
-        }
-        var resultform = document.forms['resultform'];
-        resultform.result.value = result;
-        resultform.submit();
-    };
+
+function runTest() {
+    var result = undefined;
+    try {
+        result = %(jstestcase)s;
+    } catch (e) {
+        result = 'Exception("' + e + '")'
+    }
+    var resultform = document.forms['resultform'];
+    resultform.result.value = result;
+    resultform.submit();
+};
 </script>
 </head>
 <body onload="runTest()">
@@ -46,7 +43,11 @@
 <meta http-equiv="refresh" content="0">
 </head>
 <body>
-refresh after %(jsfilename)s
+<pre>
+// %(jsfilename)s
+
+%(jscode)s
+</pre>
 </body>
 </html>"""
 
@@ -54,6 +55,7 @@
 class TestCase(object):
     def __init__(self, jsfilename, jstestcase):
         self.jsfilename = jsfilename
+        self.jscode     = open(jsfilename).read()
         self.jstestcase = jstestcase
         self.result     = None
 
@@ -63,35 +65,31 @@
 
     def do_GET(self):
         global do_status
-        log('do_GET path', self.path)
         if self.path != "/test.html":
             self.send_error(404, "File not found")
             return
+        jsfilename = jstest.jsfilename
         jstestcase = jstest.jstestcase
-        jsfilename = str(jstest.jsfilename)
-        jscode     = open(jsfilename).read()
+        jscode     = jstest.jscode
         html_page  = config.html_page % locals()
-        log('do_GET sends', jsfilename)
         self.serve_data('text/html', html_page)
         do_status = 'do_GET'
 
     def do_POST(self):
         global do_status
-        log('do_POST path', self.path)
         if self.path != "/test.html":
             self.send_error(404, "File not found")
             return
         form = parse_qs(self.rfile.read(int(self.headers['content-length'])))
         jstest.result = form['result'][0]
-        log('do_POST received result', jstest.result)
 
         #we force a page refresh here because of two reason:
         # 1. we don't have the next testcase ready yet
         # 2. browser should ask again when we do have a test
         jsfilename = jstest.jsfilename
+        jscode     = jstest.jscode
         refresh_page = config.refresh_page % locals()
         self.serve_data('text/html', refresh_page)
-        log('do_POST sends refresh page')
         do_status = 'do_POST'
 
     def serve_data(self, content_type, data):
@@ -106,7 +104,6 @@
     """The browser driver"""
 
     def start_server(self, port):
-        log('BrowserTest.start_server')
         server_address = ('', port)
         self.httpd = HTTPServer(server_address, TestHandler)
 
@@ -114,20 +111,15 @@
         global do_status
         do_status = None
         while do_status != 'do_GET':
-            log('waiting for do_GET')
             self.httpd.handle_request()
         while do_status != 'do_POST':
-            log('waiting for do_POST')
             self.httpd.handle_request()
-        while not jstest.result:
-            log('waiting for result')
-            sleep(1.0)
         return jstest.result
 
 
 def jstest(jsfilename, jstestcase):
     global driver, jstest
-    jstest = TestCase(jsfilename, jstestcase)
+    jstest = TestCase(str(jsfilename), str(jstestcase))
 
     try:
         driver

Modified: pypy/dist/pypy/translator/js/test/test_exception.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_exception.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_exception.py	Mon Nov  7 13:51:53 2005
@@ -42,7 +42,7 @@
     assert f(0) == fn(0)
     assert f(1) == fn(1)
 
-def DONTtest_simple2():
+def test_simple2():
     def fn(n):
         lst = range(10)
         try:
@@ -81,7 +81,7 @@
     assert f(1) == fn(1)
     assert f(2) == fn(2)
 
-def DONTtest_pass_exc():
+def test_pass_exc():
     def fn(n):
         lst = range(10)
         try:
@@ -194,7 +194,7 @@
     for i in [-1, 0, 1, 2]:
         assert f(i) == i
 
-def DONTtest_two_exceptionsB():
+def test_two_exceptionsB():
     def fn1():
         raise Exception
     def fn2():



More information about the Pypy-commit mailing list