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

ericvrp at codespeak.net ericvrp at codespeak.net
Fri Jan 20 11:14:06 CET 2006


Author: ericvrp
Date: Fri Jan 20 11:14:04 2006
New Revision: 22466

Modified:
   pypy/dist/pypy/translator/js/codewriter.py
   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/test/test_genllvm.py
   pypy/dist/pypy/translator/js/test/test_typed.py
Log:
Fixed genjs casts, 6 more tests pass.
Added optimization for char to string and int to string.


Modified: pypy/dist/pypy/translator/js/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/codewriter.py	(original)
+++ pypy/dist/pypy/translator/js/codewriter.py	Fri Jan 20 11:14:04 2006
@@ -280,6 +280,10 @@
             self.append("%(targetvar)s = 0.0 + %(fromvar)s" % locals())
         elif targettype in ('bool',):
             self.append("%(targetvar)s = %(fromvar)s == 0" % locals())
+        elif targettype in ('ubyte',):
+            self.append("%(targetvar)s = %(fromvar)s.charCodeAt(0)" % locals())
+        elif targettype in ('sbyte',):
+            self.append("%(targetvar)s = String.fromCharCode(%(fromvar)s)" % locals())
         else:
             self.comment("next line should be: %(targetvar)s = cast %(fromtype)s %(fromvar)s to %(targettype)s" % locals())
             self.append("%(targetvar)s = %(fromvar)s" % locals())

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 20 11:14:04 2006
@@ -231,12 +231,7 @@
         return repr
 
     def char_to_str(self, value):
-        x = ord(value)
-        if x >= 128:
-            r = "cast (ubyte %s to sbyte)" % x
-        else:
-            r = str(x)
-        return r
+        return "String.fromCharCode(%s)" % ord(value)
     
     def primitive_to_str(self, type_, value):
         if type_ is lltype.Bool:

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 20 11:14:04 2006
@@ -4,6 +4,8 @@
     'll_stritem_nonneg__rpy_stringPtr_Signed',
     'll_stritem__rpy_stringPtr_Signed',
     'll_streq__rpy_stringPtr_rpy_stringPtr',
+    'll_str__IntegerR_SignedConst_Signed',
+    'll_chr2str__Char',
     'll_issubclass__object_vtablePtr_object_vtablePtr'  #TODO
 ]
 
@@ -34,6 +36,12 @@
         return '%s = (%s == %s) || (%s && %s && %s.chars == %s.chars)' %\
                 (targetvar, s0,s1, s0,s1, s0,s1)
 
+    elif funcname == 'll_str__IntegerR_SignedConst_Signed':
+        return '%s = new Object({hash:0, chars:%s + ""})' % (targetvar, params[0])
+
+    elif funcname == 'll_chr2str__Char':
+        return '%s = new Object({hash:0, chars:%s})' % (targetvar, params[0])
+
     return '%s = %s(%s)' % (targetvar, funcname, ', '.join(params))
 
 def optimize_filesize(filename):

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 20 11:14:04 2006
@@ -76,6 +76,9 @@
         self.block = block
 
     def write_operation(self, op):
+        #log(str(op))
+        #self.codewriter.comment(str(op))
+
         invoke = op.opname.startswith('invoke:')
         if invoke:
             self.invoke(op)
@@ -158,14 +161,8 @@
         name = self.char_operations[op.opname]
         assert len(op.args) == 2
         res = self.db.repr_arg(op.result)
-        if True:
-            c1 = self.db.repr_arg(op.args[0])
-            c2 = self.db.repr_arg(op.args[1])
-        else:
-            c1 = self.db.repr_tmpvar()
-            c2 = self.db.repr_tmpvar()
-            self.codewriter.cast(c1, "sbyte", self.db.repr_arg(op.args[0]), "ubyte")
-            self.codewriter.cast(c2, "sbyte", self.db.repr_arg(op.args[1]), "ubyte")
+        c1 = self.db.repr_arg(op.args[0])
+        c2 = self.db.repr_arg(op.args[1])
         self.codewriter.binaryop(name, res, c1, c2)
 
     def cast_char_to_int(self, op):

Modified: pypy/dist/pypy/translator/js/test/test_genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_genllvm.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_genllvm.py	Fri Jan 20 11:14:04 2006
@@ -288,7 +288,7 @@
     f = compile_function(string_simple, [int])
     assert f(0) 
     
-def DONTtest_string_simple_ops():   #issue with casts
+def test_string_simple_ops():
     def string_simple_ops(i): 
         res = 0
         s = str(i)
@@ -301,21 +301,21 @@
     f = compile_function(string_simple_ops, [int])
     assert f(5) == ord('5') + 2
         
-def DONTtest_string_getitem1(): #issue with cast sbyte to ubyte
+def test_string_getitem1():
     l = "Hello, World"
     def string_getitem1(i): 
         return ord(l[i])
     f = compile_function(string_getitem1, [int])
     assert f(0) == ord("H")
 
-def DONTtest_string_getitem2(): #issue with cast sbyte to ubyte
+def test_string_getitem2():
     def string_test(i): 
         l = "Hello, World"
         return ord(l[i])
     f = compile_function(string_test, [int])
     assert f(0) == ord("H")
 
-def DONTtest_list_of_string():  #issue with casts
+def test_list_of_string():
     a = ["hello", "world"]
     def string_simple(i, j, k, l):
         s = a[i][j] + a[k][l]

Modified: pypy/dist/pypy/translator/js/test/test_typed.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_typed.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_typed.py	Fri Jan 20 11:14:04 2006
@@ -75,7 +75,7 @@
     result = fn()
     assert result == 4
 
-def DONTtest_str_compare(): #issue with skipped/incorrect cast sbyte -> ubyte
+def test_str_compare():
     def testfn_eq(i, j):
         s1 = ['one', 'two']
         s2 = ['one', 'two', 'o', 'on', 'twos', 'foobar']
@@ -305,7 +305,7 @@
     for ii in range(255):
         assert f(ii) == ii
 
-def DONTtest_char_comparisons():    #issue with illegal cast syntax
+def test_char_comparisons():
     def comps(v):
         x = chr(v)
         res = 0



More information about the Pypy-commit mailing list