[pypy-svn] r43546 - in pypy/dist/pypy/lang/js: . test

santagada at codespeak.net santagada at codespeak.net
Mon May 21 18:53:29 CEST 2007


Author: santagada
Date: Mon May 21 18:53:27 2007
New Revision: 43546

Modified:
   pypy/dist/pypy/lang/js/astbuilder.py
   pypy/dist/pypy/lang/js/operations.py
   pypy/dist/pypy/lang/js/test/test_interp.py
Log:
more tests passing

Modified: pypy/dist/pypy/lang/js/astbuilder.py
==============================================================================
--- pypy/dist/pypy/lang/js/astbuilder.py	(original)
+++ pypy/dist/pypy/lang/js/astbuilder.py	Mon May 21 18:53:27 2007
@@ -42,10 +42,14 @@
         '||': operations.Or,
         '==': operations.Eq,
         '!=': operations.Ne,
+        '!==': operations.StrictNe,
+        '===': operations.StrictEq,
         '.': operations.Member,
         '[': operations.Member,
     }
     UNOP_TO_CLS = {
+        '~': operations.BitwiseNot,
+        '!': operations.Not,
         '+': operations.UPlus,
         '-': operations.UMinus,
         '++': operations.Increment,
@@ -74,6 +78,8 @@
                 source_pos = curr.token.source_pos
 
         # XXX some of the source positions are not perfect
+        if source_pos is None:
+            return operations.Position()
         return operations.Position(
                    source_pos.lineno,
                    source_pos.columnno,
@@ -112,12 +118,10 @@
     def visit_memberexpression(self, node):
         if isinstance(node.children[0], Symbol) and \
            node.children[0].additional_info == 'new': # XXX could be a identifier?
-            # "new case"
             pos = self.get_pos(node)
             left = self.dispatch(node.children[1])
             right = self.dispatch(node.children[2])
-            exp = operations.Call(pos, left, right)
-            return operations.New(pos, exp)            
+            return operations.NewWithArgs(pos, left, right)
         else:
             return self.binaryop(node)
 
@@ -139,6 +143,13 @@
         pos = self.get_pos(op)
         child = self.dispatch(node.children[1])
         return self.UNOP_TO_CLS[op.additional_info](pos, child)
+
+    def visit_postfixexpression(self, node):
+        op = node.children[1]
+        pos = self.get_pos(op)
+        child = self.dispatch(node.children[0])
+        return self.UNOP_TO_CLS[op.additional_info](pos, child, postfix=True)
+
     
     def listop(self, node):
         op = node.children[0]

Modified: pypy/dist/pypy/lang/js/operations.py
==============================================================================
--- pypy/dist/pypy/lang/js/operations.py	(original)
+++ pypy/dist/pypy/lang/js/operations.py	Mon May 21 18:53:27 2007
@@ -154,28 +154,25 @@
     
 
 class BitwiseAnd(BinaryBitwiseOp):
-    opcode = 'BITWISE_AND'
-    
     def decision(self, ctx, op1, op2):
         return W_Number(op1&op2)
+    
 
 class BitwiseNot(UnaryOp):
-    opcode = 'BITWISE_NOT'
-
     def eval(self, ctx):
         op1 = self.expr.eval(ctx).GetValue().ToInt32()
         return W_Number(~op1)
-
+    
 
 class BitwiseOr(BinaryBitwiseOp):
-    opcode = 'BITWISE_OR'
-    
     def decision(self, ctx, op1, op2):
         return W_Number(op1|op2)
+    
 
 class BitwiseXor(BinaryBitwiseOp):    
     def decision(self, ctx, op1, op2):
         return W_Number(op1^op2)
+    
 
 class Unconditional(Statement):
     def __init__(self, pos, t):
@@ -702,14 +699,13 @@
     
 
 class NewWithArgs(BinaryOp):
-    opcode = 'NEW_WITH_ARGS'
-    
     def eval(self, ctx):
         x = self.left.eval(ctx).GetValue()
         if not isinstance(x, W_PrimitiveObject):
             raise TypeError()
         args = self.right.eval(ctx).get_args()
         return x.Construct(ctx=ctx, args=args)
+    
 
 class Number(Expression):    
     def __init__(self, pos, num):
@@ -1024,6 +1020,7 @@
 class Not(UnaryOp):
     def eval(self, ctx):
         return W_Boolean(not self.expr.eval(ctx).GetValue().ToBoolean())
+    
 
 class UMinus(UnaryOp):
     def eval(self, ctx):

Modified: pypy/dist/pypy/lang/js/test/test_interp.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_interp.py	(original)
+++ pypy/dist/pypy/lang/js/test/test_interp.py	Mon May 21 18:53:27 2007
@@ -53,7 +53,9 @@
     except ThrowException, excpt:
         code_val = excpt
     print code_val, value
-    if isinstance(value, int):
+    if isinstance(value, bool):
+        assert code_val.ToBoolean() == value
+    elif isinstance(value, int):
         assert code_val.ToInt32() == value
     elif isinstance(value, float):
         assert code_val.ToNumber() == value
@@ -75,10 +77,10 @@
     yield assertv, "x=3;y=4;x+y;", 7
 
 def test_minus():
-    assert_prints("print(2-1);", ["1"])
+    assertv("2-1;", 1)
 
 def test_string_var():
-    assert_prints('print(\"sss\");', ["sss"])
+    assertv('\"sss\";', 'sss')
 
 def test_string_concat():
     assert_prints('x="xxx"; y="yyy"; print(x+y);', ["xxxyyy"])
@@ -280,11 +282,10 @@
     """, ["0","1","2","3"])
 
 def test_object_creation():
-    py.test.skip("not ready yet")
-    assert_prints("""
+    yield assertv, """
     o = new Object();
-    print(o);
-    """, ["[object Object]"])
+    o;
+    """, "[object Object]"
 
 def test_var_decl():
     py.test.skip("not ready yet")
@@ -321,7 +322,7 @@
     assert_prints("""
     var x;x=3; print(x);""", ["3"])
 
-def test_minus():
+def test_in():
     py.test.skip("not ready yet")
     assert_prints("""
     x = {y:3};
@@ -350,17 +351,15 @@
     """, ["0","1","2","3"])
 
 def test_eval():
-    py.test.skip("not ready yet")
-    assert_prints("""
+    assertp("""
     var x = 2;
-    eval('x=x+1; print(x); z=2');
+    eval('x=x+1; print(x); z=2;');
     print(z);
     """, ["3","2"])
 
 def test_arrayobject():
-    py.test.skip("not ready yet")
-    assert_prints("""var x = new Array();
-    print(x.length == 0);""", ['true'])
+    assertv("""var x = new Array();
+    x.length == 0;""", 'true')
      
 def test_break():
     py.test.skip("not ready yet")
@@ -381,23 +380,20 @@
     """, W_Boolean(True))
     
 def test_semicolon():
-    py.test.skip("not ready yet")
-    assert_prints(';', [])
+    assertp(';', [])
 
 def test_newwithargs():
-    py.test.skip("not ready yet")
-    assert_prints("""
+    assertp("""
     var x = new Object(1,2,3,4);
     print(x);
-    """, ["[object Object]"])
+    """, "[object Object]")
 
 def test_increment():
-    py.test.skip("not ready yet")
-    assert_prints("""
+    assertv("""
     var x;
     x = 1;
     x++;
-    print(x);""", ["2"])
+    x;""", 2)
     
 def test_ternaryop():
     py.test.skip("not ready yet")
@@ -407,27 +403,26 @@
     ["yep","nope"])
 
 def test_booleanliterals():
-    assert_prints("""
+    assertp("""
     var x = false;
     var y = true;
     print(y);
     print(x);""", ["true", "false"])
     
 def test_unarynot():
-    py.test.skip("not ready yet")
-    assert_prints("""
+    assertp("""
     var x = false;
     print(!x);
     print(!!x);""", ["true", "false"])
 
 def test_equals():
-    assert_prints("""
+    assertv("""
     var x = 5;
     y = z = x;
-    print(y);""", ["5"])
+    y;""", 5)
 
 def test_math_stuff():
-    assert_prints("""
+    assertp("""
     var x = 5;
     var z = 2;
     print(x*z);
@@ -443,7 +438,7 @@
     """, ['10', '2', 'false', '3', 'NaN', 'inf', '-inf', '3', '', '-2'])
     
 def test_globalproperties():
-    assert_prints( """
+    assertp( """
     print(NaN);
     print(Infinity);
     print(undefined);
@@ -491,18 +486,17 @@
     """, ['1', '2', '3'])
 
 def test_array_length():
-    py.test.skip("not ready yet")
-    assert_prints("""
+    assertp("""
     var testcases = new Array();
     var tc = testcases.length;
     print('tc'+tc);
-    """, ['tc0'])
+    """, 'tc0')
 
 def test_mod_op():
-    assert_prints("print(2%2);", ['0'])
+    assertp("print(2%2);", '0')
 
 def test_unary_plus():
-    assert_prints("print(+1);", ['1'])
+    assertp("print(+1);", '1')
 
 def test_delete():
     py.test.skip("not ready yet")
@@ -523,13 +517,10 @@
     """, ['5',])
 
 def test_stricteq():
-    py.test.skip("not ready yet")
-    assert_prints("""
-    print(2 === 2);
-    print(2 === 3);
-    print(2 !== 3);
-    print(2 !== 2);   
-    """, ['true', 'false', 'true', 'false'])
+    yield assertv, "2 === 2;", True
+    yield assertv, "2 === 3;", False
+    yield assertv, "2 !== 3;", True
+    yield assertv, "2 !== 2;", False
 
 def test_with():
     py.test.skip("not ready yet")
@@ -551,11 +542,9 @@
     """, ['4', '2', '3', '4'])
 
 def test_bitops():
-    assert_prints("""
-    print(2 ^ 2);
-    print(2 & 3);
-    print(2 | 3);
-    """, ['0', '2', '3'])
+    yield assertv, "2 ^ 2;", 0
+    yield assertv, "2 & 3;", 2
+    yield assertv, "2 | 3;", 3
 
 def test_for_strange():
     py.test.skip("not ready yet")



More information about the Pypy-commit mailing list