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

ericvrp at codespeak.net ericvrp at codespeak.net
Fri Jan 27 19:45:48 CET 2006


Author: ericvrp
Date: Fri Jan 27 19:45:44 2006
New Revision: 22757

Modified:
   pypy/dist/pypy/translator/js/database.py
   pypy/dist/pypy/translator/js/optimize.py
   pypy/dist/pypy/translator/js/opwriter.py
   pypy/dist/pypy/translator/js/support.py
   pypy/dist/pypy/translator/js/test/runtest.py
   pypy/dist/pypy/translator/js/test/test_exc_operation.py
   pypy/dist/pypy/translator/js/test/test_jseval.py
   pypy/dist/pypy/translator/js/test/test_stackless.py
Log:
* Added longlong support

* Added first of exception raising operations through transformation
  that can be shared between genc/genllvm and genjs in due time.

* Added native javascript code for string concat.


Modified: pypy/dist/pypy/translator/js/database.py
==============================================================================
--- pypy/dist/pypy/translator/js/database.py	(original)
+++ pypy/dist/pypy/translator/js/database.py	Fri Jan 27 19:45:44 2006
@@ -20,6 +20,8 @@
             lltype.Float: "double",
             lltype.Signed: "int",
             lltype.Unsigned: "uint",
+            lltype.SignedLongLong: "int",
+            lltype.UnsignedLongLong: "uint",
             lltype.UniChar: "uint",
             lltype.Void: "void"}
 

Modified: pypy/dist/pypy/translator/js/optimize.py
==============================================================================
--- pypy/dist/pypy/translator/js/optimize.py	(original)
+++ pypy/dist/pypy/translator/js/optimize.py	Fri Jan 27 19:45:44 2006
@@ -8,6 +8,7 @@
     'll_str__IntegerR_SignedConst_Signed',
     'll_str__FloatR_FloatConst_Float',
     'll_int__rpy_stringPtr_Signed',
+    'll_join_strs__Signed_arrayPtr',
 
     #'ll_issubclass__object_vtablePtr_object_vtablePtr',
 
@@ -52,6 +53,9 @@
     elif funcname == 'll_int__rpy_stringPtr_Signed' and params[1] == '10':
         return True, '%s = parseInt(%s)' % (targetvar, params[0])
 
+    elif funcname == 'll_join_strs__Signed_arrayPtr' and params[0] == '2':
+        return True, '%s = {hash:0, chars:%s + %s}' % (targetvar, params[0], params[1])
+
     #externals...
     elif funcname == 'll_js_jseval__rpy_stringPtr':
         return True, '%s = eval(%s.chars)' % (targetvar, params[0])

Modified: pypy/dist/pypy/translator/js/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/opwriter.py	(original)
+++ pypy/dist/pypy/translator/js/opwriter.py	Fri Jan 27 19:45:44 2006
@@ -79,6 +79,11 @@
         #log(str(op))
         #self.codewriter.comment(str(op))
 
+        if op.opname.startswith('llong_'):
+            op.opname = 'int_' + op.opname[6:]
+        elif op.opname.startswith('ullong_'):
+            op.opname = 'uint_' + op.opname[7:]
+
         invoke = op.opname.startswith('invoke:')
         if invoke:
             self.invoke(op)
@@ -97,7 +102,7 @@
                 if not meth:
                     raise Exception, "operation %s not found" % op.opname
                     return
-                meth(op)    
+                meth(op)
 
     def _generic_pow(self, op, onestr): 
         targetvar = self.db.repr_arg(op.result)

Modified: pypy/dist/pypy/translator/js/support.py
==============================================================================
--- pypy/dist/pypy/translator/js/support.py	(original)
+++ pypy/dist/pypy/translator/js/support.py	Fri Jan 27 19:45:44 2006
@@ -10,7 +10,7 @@
         reserved_names_string = '''
                    if    then   else   function  
                    for   while  witch  continue
-                   break super  var
+                   break super  var    do
                    bool  char   int    float
                    Array String Struct Number
                    '''

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	Fri Jan 27 19:45:44 2006
@@ -1,13 +1,12 @@
 import py, os
 from pypy.translator.translator import TranslationContext
-from pypy.translator.backendopt.all import backend_optimizations                                 
+from pypy.translator.backendopt.all import backend_optimizations
 from pypy.translator.js.js import JS
 from pypy.translator.js.test.browsertest import jstest
 from pypy.translator.js import conftest
 from pypy.translator.js.log import log
 log = log.runtest
 use_browsertest = conftest.option.jsbrowser
-#from pypy.translator.js.test.test_jseval import add_callback_function
 
 def _CLI_is_on_path():
     try:
@@ -26,9 +25,7 @@
 
         t.buildrtyper().specialize() 
 
-        #add_callback_function(t.translator)
-
-        backend_optimizations(t, inline_threshold=0, mallocs=False)
+        backend_optimizations(t, raisingop2direct_call_all=True, inline_threshold=0, mallocs=False)
         #backend_optimizations(t)
         if view:
             t.view()

Modified: pypy/dist/pypy/translator/js/test/test_exc_operation.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_exc_operation.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_exc_operation.py	Fri Jan 27 19:45:44 2006
@@ -4,7 +4,7 @@
 from pypy.rpython.rarithmetic import r_uint, ovfcheck, ovfcheck_lshift
 from pypy.translator.test import snippet 
 
-def DONTtest_zerodiv_int(): #issue no exception raising operations yet
+def test_zerodiv_int(): #issue no exception raising operations yet
     def zerodiv_int(n):
         try:
             r=100/n

Modified: pypy/dist/pypy/translator/js/test/test_jseval.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_jseval.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_jseval.py	Fri Jan 27 19:45:44 2006
@@ -6,12 +6,10 @@
 from pypy.rpython.rjs import jseval
 from pypy.translator.js import conftest
 
-class jsnative(object):
-    def __init__(self, cmd):
-        self._cmd = cmd
-
-    def __call__(self):
-        return jseval(self._cmd)
+def jsnative(cmd):
+    def do():
+        return jseval(cmd)
+    return do
 
 getDate = jsnative("new Date().getDate()")
 getTime = jsnative("Math.floor(new Date().getTime())")
@@ -29,8 +27,8 @@
     from time import localtime
 
     def jsnative1():
-        return jseval("new Date().getDate()")
-        #return getDate()
+        getTime()
+        return getDate()
 
     jsnative1_fn = compile_function(jsnative1, [])
     assert jsnative1_fn() == localtime()[2]
@@ -40,30 +38,20 @@
 
 def callback_function():
     n_times_called[0] += 1
-    jseval("setTimeout('callback_function()', 10)")
+    jseval("document.title=" + str(n_times_called[0]))
+    jseval("setTimeout('callback_function()', 100)")
 
-#def add_callback_function(translator):
-#    a  = translator.annotator
-#    bk = a.bookkeeper
-#    s_cb = bk.immutablevalue(callback_function)
-#    bk.emulate_pbc_call('callback_function', s_cb, [])
-#    a.complete()
-#    translator.rtyper.specialize_more_blocks()  
-    
 def test_register_callback():
     if not conftest.option.jsbrowser:
         py.test.skip("works only in a browser (use py.test --browser)")
 
     def register_callback():
-        callback_function()
-        #callbacks.append(callback_function)
-        #jseval("setTimeout('callback_function()', 10)")
-        start_time = current_time = int(jseval("Math.floor(new Date().getTime())"))
+        callback_function() #..start timer
+        start_time = current_time = int(getTime())
         while current_time - start_time < 1000:
-            current_time = int(jseval("Math.floor(new Date().getTime())"))
-        return n_times_called
+            current_time = int(getTime())
+        return n_times_called[0]
 
     register_callback_fn = compile_function(register_callback, [])
     result = register_callback_fn()
-    print 'result=%d' % result
-    assert result > 1
+    assert result == 1

Modified: pypy/dist/pypy/translator/js/test/test_stackless.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_stackless.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_stackless.py	Fri Jan 27 19:45:44 2006
@@ -194,16 +194,18 @@
     def getTime():
         return int(jseval("Math.floor(new Date().getTime())"))
 
-    def g():
-        for i in range(100):
+    def g(n):
+        for i in range(10):
             pass
         if getTime() - start_time[0] < 10*1000:
-            g()
-        return 123
+            x = g(n-1)
+            if x != n-1:
+                jseval("log('x != n-1')")
+        return n
 
     def lp():
         start_time[0] = getTime()
-        return g()
+        return g(100000)
 
     data = wrap_stackless_function(lp)
 



More information about the Pypy-commit mailing list