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

fijal at codespeak.net fijal at codespeak.net
Wed Sep 13 16:31:25 CEST 2006


Author: fijal
Date: Wed Sep 13 16:31:22 2006
New Revision: 32264

Modified:
   pypy/dist/pypy/translator/js/helper.py
   pypy/dist/pypy/translator/js/jsbuiltin.py
   pypy/dist/pypy/translator/js/jssrc/misc.js
   pypy/dist/pypy/translator/js/test/test_seq.py
   pypy/dist/pypy/translator/js/test/test_transformer.py
Log:
Fixed substring, added test for that.


Modified: pypy/dist/pypy/translator/js/helper.py
==============================================================================
--- pypy/dist/pypy/translator/js/helper.py	(original)
+++ pypy/dist/pypy/translator/js/helper.py	Wed Sep 13 16:31:22 2006
@@ -11,6 +11,7 @@
 
 def create_debug_div():
     debug_div = get_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)

Modified: pypy/dist/pypy/translator/js/jsbuiltin.py
==============================================================================
--- pypy/dist/pypy/translator/js/jsbuiltin.py	(original)
+++ pypy/dist/pypy/translator/js/jsbuiltin.py	Wed Sep 13 16:31:22 2006
@@ -43,7 +43,8 @@
                 'll_startswith' : CallBuiltin('startswith'),
                 'll_endswith' : CallBuiltin('endswith'),
                 'll_split_chr' : CallBuiltin('splitchr'),
-                'll_substring' : lambda g,op: Call._render_builtin_method(g, 'substring', [op.args[1], op.args[2], op.args[3]]),
+                #'ll_substring' : lambda g,op: Call._render_builtin_method(g, 'substring', [op.args[1], op.args[2], op.args[3]]),
+                'll_substring' : CallBuiltin('substring'),
                 'll_lower' : lambda g, op: Call._render_builtin_method(g, 'toLowerCase', [op.args[1]]),
                 'll_upper' : lambda g, op: Call._render_builtin_method(g, 'toUpperCase', [op.args[1]]),
             },

Modified: pypy/dist/pypy/translator/js/jssrc/misc.js
==============================================================================
--- pypy/dist/pypy/translator/js/jssrc/misc.js	(original)
+++ pypy/dist/pypy/translator/js/jssrc/misc.js	Wed Sep 13 16:31:22 2006
@@ -158,4 +158,8 @@
         return 0;
     }
 }
+
+function substring(s, l, c) {
+    return (s.substring(l, l+c));
+}
 // ends hand written code

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	Wed Sep 13 16:31:22 2006
@@ -112,6 +112,18 @@
         
         fn = compile_function(upperlower, [])
         assert fn() == "ABAFabaf"
+    
+    def test_slice(self):
+        def one_slice(s):
+            return s[1:]
+            
+        def two_slice(s):
+            return s[2:]
+        
+        fn = compile_function(one_slice, [str])
+        assert fn("dupa") == "upa"
+        fn = compile_function(two_slice, [str])
+        assert fn("kupa") == "pa"
 
 def test_simple_seq():
     def fun(i):

Modified: pypy/dist/pypy/translator/js/test/test_transformer.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_transformer.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_transformer.py	Wed Sep 13 16:31:22 2006
@@ -158,3 +158,4 @@
     lst = retval.split("|")
     assert len(lst) == 1
     assert lst[0] == ''
+



More information about the Pypy-commit mailing list