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

santagada at codespeak.net santagada at codespeak.net
Sat May 19 19:01:57 CEST 2007


Author: santagada
Date: Sat May 19 19:01:56 2007
New Revision: 43506

Modified:
   pypy/dist/pypy/lang/js/astbuilder.py
   pypy/dist/pypy/lang/js/jsgrammar.txt
   pypy/dist/pypy/lang/js/jsparser.py
   pypy/dist/pypy/lang/js/operations.py
   pypy/dist/pypy/lang/js/test/test_interp.py
   pypy/dist/pypy/lang/js/test/test_parser.py
Log:
lots of changes, new operations, new way to call mathops, some grammar changes
and some new tests.


Modified: pypy/dist/pypy/lang/js/astbuilder.py
==============================================================================
--- pypy/dist/pypy/lang/js/astbuilder.py	(original)
+++ pypy/dist/pypy/lang/js/astbuilder.py	Sat May 19 19:01:56 2007
@@ -1,13 +1,42 @@
 from pypy.rlib.parsing.tree import RPythonVisitor, Symbol
 from pypy.lang.js import operations
 
+#this is a noop for now
+def varfinder(opnode):
+    return [] 
+    if isinstance(opnode, operations.Vars):
+        return [opnode,]
+    elif hasattr(opnode, "nodes"):
+        temp = []
+        for op in opnode.nodes:
+            temp.extend(varfinder(op))
+        return temp
+    elif hasattr(opnode, "body"):
+        return varfinder(opnode.body)
+    else:
+        return []
+
+#this is a noop for now
+def funcfinder(opnode):
+    return []
+    if isinstance(opnode, operations.Function):
+        return [opnode,]
+    elif hasattr(opnode, "nodes"):
+        return [funcfinder(op) for op in opnode.nodes]
+    elif hasattr(opnode, "body"):
+        return funcfinder(opnode.body)
+    else:
+        return []
+
+
 class ASTBuilder(RPythonVisitor):
     BINOP_TO_CLS = {
         '+': operations.Plus,
         '-': operations.Minus,
         '*': operations.Mult,
-        '/': operations.Div,
+        '/': operations.Division,
         '%': operations.Mod,
+        '.': operations.Member,
     }
     UNOP_TO_CLS = {
         '+': operations.UPlus,
@@ -90,8 +119,7 @@
     def visit_IDENTIFIERNAME(self, node):
         pos = self.get_pos(node)
         name = node.additional_info
-        initializer = operations.astundef #XXX this is uneded now
-        return operations.Identifier(pos, name, initializer)
+        return operations.Identifier(pos, name)
 
     def visit_program(self, node):
         pos = self.get_pos(node)
@@ -100,11 +128,41 @@
         
     def visit_sourceelements(self, node):
         pos = self.get_pos(node)
-        var_decl = None #XXX TODO
-        func_decl = None #XXX TODO
         nodes = [self.dispatch(child) for child in node.children]
-        return operations.Script(pos, var_decl, func_decl, nodes)
+        var_decl = []
+        func_decl = []
+        for node in nodes:
+            var_decl.extend(varfinder(node))
+            func_decl.extend(funcfinder(node))
+        
+        return operations.SourceElements(pos, var_decl, func_decl, nodes)
     
     def visit_expressionstatement(self, node):
         return self.dispatch(node.children[0])
-        
\ No newline at end of file
+    
+    def visit_variablestatement(self, node):
+        pos = self.get_pos(node)
+        body = self.dispatch(node.children[0])
+        return operations.Variable(pos, body)
+    
+    def visit_variabledeclarationlist(self, node):
+        pos = self.get_pos(node)
+    
+    def visit_callexpression(self, node):
+        pos = self.get_pos(node)
+        left = self.dispatch(node.children[0])
+        right = self.dispatch(node.children[1])
+        return operations.Call(pos, left, right)
+    
+    def visit_argumentlist(self, node):
+        pos = self.get_pos(node)
+        nodes = [self.dispatch(child) for child in node.children]
+        return operations.ArgumentList(pos, nodes)
+    
+    def visit_assignmentexpression(self, node):
+        pos = self.get_pos(node)
+        left = self.dispatch(node.children[0])
+        atype = node.children[1].additional_info
+        right = self.dispatch(node.children[2])
+        return operations.Assignment(pos, left, right, atype)
+    
\ No newline at end of file

Modified: pypy/dist/pypy/lang/js/jsgrammar.txt
==============================================================================
--- pypy/dist/pypy/lang/js/jsgrammar.txt	(original)
+++ pypy/dist/pypy/lang/js/jsgrammar.txt	Sat May 19 19:01:56 2007
@@ -188,10 +188,10 @@
                 | <numericliteral>
                 ; 
 
-functiondeclaration : ["function"] identifier ["("] formalparameterlist? [")"] ["{"] >functionbody< ["}"]
+functiondeclaration : ["function"] identifier ["("] formalparameterlist? [")"] ["{"] >functionbody<? ["}"]
                     ;
 
-functionexpression  : ["function"] identifier? ["("] formalparameterlist? [")"] ["{"] >functionbody< ["}"]
+functionexpression  : ["function"] identifier? ["("] formalparameterlist? [")"] ["{"] >functionbody<? ["}"]
                     ;
 
 formalparameterlist : identifier [","] >formalparameterlist<
@@ -201,15 +201,13 @@
 functionbody    : sourceelements
                 ;
 
-begmemberexpression : <primaryexpression>
-                    | <functionexpression>
-                    ;
-
-memberexpression    : begmemberexpression "[" expression "]" memberexpression* 
-                    | begmemberexpression "." identifier memberexpression*
-                    | "new" memberexpression arguments
-                    | <begmemberexpression>
-                    ;
+memberexpression	: "." identifier >memberexpression<*
+					| "[" expression "]" >memberexpression<*
+					| "new" memberexpression arguments
+					| <primaryexpression> >memberexpression<*
+					| <functionexpression> >memberexpression<*
+					;
+					
 
 newexpression   : "new" newexpression
                 | <memberexpression>
@@ -362,6 +360,6 @@
 initialisernoin : "=" assignmentexpressionnoin
             ;
 
-variabledeclarationlistnoin : variabledeclarationnoin "," variabledeclarationlistnoin 
+variabledeclarationlistnoin : variabledeclarationnoin [","] >variabledeclarationlistnoin< 
                         | variabledeclarationnoin
                         ;

Modified: pypy/dist/pypy/lang/js/jsparser.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsparser.py	(original)
+++ pypy/dist/pypy/lang/js/jsparser.py	Sat May 19 19:01:56 2007
@@ -14,4 +14,4 @@
 parsef = make_parse_function(regexs, rules, eof=True)
 
 def parse(code):
-    parsef(code).visit(ToAST())
+    return parsef(code).visit(ToAST())[0]

Modified: pypy/dist/pypy/lang/js/operations.py
==============================================================================
--- pypy/dist/pypy/lang/js/operations.py	(original)
+++ pypy/dist/pypy/lang/js/operations.py	Sat May 19 19:01:56 2007
@@ -46,7 +46,7 @@
         raise NotImplementedError
     
     def __str__(self):
-        return "<ASTop %s %s >"%(self.opcode, self.value)
+        return "%s()"%(self.__class__)
 
 class Statement(Node):
     def __init__(self, pos):
@@ -60,9 +60,9 @@
         return self.eval(ctx)
 
 class ListOp(Expression):
-    def __init__(self, pos, nodelist):
+    def __init__(self, pos, nodes):
         self.pos = pos
-        self.nodelist = nodelist
+        self.nodes = nodes
         
 class UnaryOp(Expression):
     def __init__(self, pos, expr, postfix=False):
@@ -100,30 +100,36 @@
 class Array(ListOp):    
     def eval(self, ctx):
         array = W_Array()
-        for i in range(len(self.nodelist)):
-            array.Put(str(i), self.nodelist[i].eval(ctx).GetValue())
+        for i in range(len(self.nodes)):
+            array.Put(str(i), self.nodes[i].eval(ctx).GetValue())
         return array
 
-class Assign(BinaryOp):    
+class Assignment(Expression):
+    def __init__(self, pos, left, right, atype):
+        self.pos = pos
+        self.left = left
+        self.right = right
+        self.type = atype    
+
     def eval(self, ctx):
         v1 = self.left.eval(ctx)
         v3 = self.right.eval(ctx).GetValue()
-        op = self.value
+        op = self.type
         if op == "=":
             val = v3
-        elif op == "*":
+        elif op == "*=":
             val = Mult().mathop(ctx, v1.GetValue(), v3)
-        elif op == "+":
+        elif op == "+=":
             val = Plus().mathop(ctx, v1.GetValue(), v3)
-        elif op == "/":
+        elif op == "/=":
             val = Div().mathop(ctx, v1.GetValue(), v3)
-        elif op == "%":
+        elif op == "%=":
             val = Mod().mathop(ctx, v1.GetValue(), v3)
-        elif op == "&":
+        elif op == "&=":
             val = BitwiseAnd().decision(ctx, v1.GetValue().ToInt32(), v3.ToInt32())
-        elif op == "|":
+        elif op == "|=":
             val = BitwiseOR().decision(ctx, v1.GetValue().ToInt32(), v3.ToInt32())
-        elif op == "^":
+        elif op == "^=":
             val = BitwiseXOR().decision(ctx, v1.GetValue().ToInt32(), v3.ToInt32())
         else:
             print op
@@ -131,11 +137,12 @@
         
         v1.PutValue(val, ctx)
         return val
+    
 
 class Block(Statement):
-    def __init__(self, pos, t):
-        self.nodes = get_objects(t)        
-
+    def __init__(self, pos, nodes):
+        self.nodes = nodes
+    
     def execute(self, ctx):
         try:
             last = w_Undefined
@@ -147,6 +154,7 @@
                 return e.value
             else:
                 raise e
+    
 
 class BitwiseAnd(BinaryBitwiseOp):
     opcode = 'BITWISE_AND'
@@ -193,9 +201,7 @@
     def execute(self, ctx):
         raise ExecutionReturned('continue', None, None)
 
-class Call(BinaryOp):
-    opcode = 'CALL'
-
+class Call(BinaryOp):    
     def eval(self, ctx):
         r1 = self.left.eval(ctx)
         r2 = self.right.eval(ctx)
@@ -217,6 +223,7 @@
             return retval
         except ExecutionReturned, e:
             return e.value
+    
 
 class Comma(BinaryOp):
     opcode = 'COMMA'
@@ -239,50 +246,38 @@
         else:
             return self.falseop.eval(ctx).GetValue()
 
-class Dot(BinaryOp):
-    opcode = 'DOT'
-
+class Member(BinaryOp):
     def eval(self, ctx):
         w_obj = self.left.eval(ctx).GetValue().ToObject()
         name = self.right.eval(ctx).GetPropertyName()
         return W_Reference(name, w_obj)
+    
 
 class Function(Expression):
     opcode = 'FUNCTION'
 
-    def __init__(self, pos, t):
-        self.name = get_string(t, 'name')
-        self.body = get_obj(t, 'body')
-        params = get_string(t, 'params')
-        if params == '':
-            self.params = []
-        else:
-            self.params = params.split(',')
+    def __init__(self, pos, name, body, params):
+        self.name = name
+        self.body = body
+        self.params = params
 
     def eval(self, ctx):
-        # TODO: this is wrong, should clone the function prototype
+        #XXX this is wrong, should clone the function prototype
         w_obj = W_Object(ctx=ctx, callfunc = self)
         w_obj.Put('prototype', W_Object(ctx=ctx))
         return w_obj
 
 class Identifier(Expression):
-    opcode = 'IDENTIFIER'
-
-    def __init__(self, pos, name, initializer):
+    def __init__(self, pos, name):
+        self.pos = pos
         self.name = name
-        self.initializer = initializer
         
-    def __str__(self):
-        return "<id %s init: %s>"%(str(self.name), str(self.initializer))
-    
     def eval(self, ctx):
-        if not isinstance(self.initializer, Undefined):
-            ref = ctx.resolve_identifier(self.name)
-            ref.PutValue(self.initializer.eval(ctx).GetValue(), ctx)
         return ctx.resolve_identifier(self.name)
     
     def get_literal(self):
         return self.name
+    
 
 class This(Identifier):
     opcode = "THIS"
@@ -335,64 +330,58 @@
         return -1
 
 class Or(BinaryOp):
-    
     def eval(self, ctx):
         s2 = self.left.eval(ctx).GetValue()
         if s2.ToBoolean():
             return s2
         s4 = self.right.eval(ctx).GetValue()
         return s4
+    
 
 class And(BinaryOp):
-    opcode = 'AND'
-    
     def eval(self, ctx):
         s2 = self.left.eval(ctx).GetValue()
         if not s2.ToBoolean():
             return s2
         s4 = self.right.eval(ctx).GetValue()
         return s4
+    
 
 class Ge(BinaryComparisonOp):
-    opcode = 'GE'
-    
     def decision(self, ctx, op1, op2):
         s5 = ARC(ctx, op1, op2)
         if s5 in (-1, 1):
             return W_Boolean(False)
         else:
             return W_Boolean(True)
+    
 
 class Gt(BinaryComparisonOp):
-    opcode = 'GT'
-    
     def decision(self, ctx, op1, op2):
         s5 = ARC(ctx, op2, op1)
         if s5 == -1:
             return W_Boolean(False)
         else:
             return W_Boolean(s5)
+    
 
 class Le(BinaryComparisonOp):
-    opcode = 'LE'
-    
     def decision(self, ctx, op1, op2):
         s5 = ARC(ctx, op2, op1)
         if s5 in (-1, 1):
             return W_Boolean(False)
         else:
             return W_Boolean(True)
+    
 
 class Lt(BinaryComparisonOp):
-    opcode = 'LT'
-    
     def decision(self, ctx, op1, op2):
         s5 = ARC(ctx, op1, op2)
         if s5 == -1:
             return W_Boolean(False)
         else:
             return W_Boolean(s5)
-
+    
 
 ##############################################################################
 #
@@ -617,11 +606,9 @@
         name= self.right.eval(ctx).GetValue().ToString()
         return W_Reference(name, w_obj)
 
-class List(ListOp):
-    opcode = 'LIST'
-        
+class ArgumentList(ListOp):
     def eval(self, ctx):
-        return W_List([node.eval(ctx).GetValue() for node in self.list])
+        return W_List([node.eval(ctx).GetValue() for node in self.nodes])
 
 
 ##############################################################################
@@ -637,47 +624,56 @@
         result = self.mathop(ctx, nleft, nright)
         return result
 
+def plus(ctx, nleft, nright):
+    if isinstance(nleft, W_String) or isinstance(nright, W_String):
+        sleft = nleft.ToString()
+        sright = nright.ToString()
+        return W_String(sleft + sright)
+    else:
+        fleft = nleft.ToNumber()
+        fright = nright.ToNumber()
+        return W_Number(fleft + fright)
+
+def mult(ctx, nleft, nright):
+    fleft = nleft.ToNumber()
+    fright = nright.ToNumber()
+    return W_Number(fleft * fright)
+
+def mod(ctx, nleft, nright): # XXX this one is really not following spec
+    ileft = nleft.ToInt32()
+    iright = nright.ToInt32()
+    return W_Number(ileft % iright)
+
+def division(ctx, nleft, nright):
+    fleft = nleft.ToNumber()
+    fright = nright.ToNumber()
+    return W_Number(fleft / fright)
+
+def minus(ctx, nleft, nright):
+    fleft = nleft.ToNumber()
+    fright = nright.ToNumber()
+    return W_Number(fleft - fright)
+
+
 class Plus(BinaryNumberOp):
-    @staticmethod
-    def mathop(ctx, nleft, nright):
-        if isinstance(nleft, W_String) or isinstance(nright, W_String):
-            sleft = nleft.ToString()
-            sright = nright.ToString()
-            return W_String(sleft + sright)
-        else:
-            fleft = nleft.ToNumber()
-            fright = nright.ToNumber()
-            return W_Number(fleft + fright)
+    mathop = staticmethod(plus)
+    
 
 class Mult(BinaryNumberOp):
-    def mathop(self, ctx, nleft, nright):
-        fleft = nleft.ToNumber()
-        fright = nright.ToNumber()
-        return W_Number(fleft * fright)
+    mathop = staticmethod(mult)
+    
 
 class Mod(BinaryNumberOp):
-    def mathop(self, ctx, nleft, nright):
-        fleft = nleft.ToInt32()
-        fright = nright.ToInt32()
-        return W_Number(fleft % fright)
-
-class Div(BinaryNumberOp):
-    opcode = 'DIV'
-    
-    def mathop(self, ctx, nleft, nright):
-        fleft = nleft.ToInt32()
-        fright = nright.ToInt32()
-        return W_Number(fleft / fright)
-
-class Minus(BinaryNumberOp):
-    opcode = 'MINUS'
+    mathop = staticmethod(mod)
     
-    def mathop(self, ctx, nleft, nright):
-        fleft = nleft.ToNumber()
-        fright = nright.ToNumber()
-        return W_Number(fleft - fright)
 
+class Division(BinaryNumberOp):
+    mathop = staticmethod(division)
+    
 
+class Minus(BinaryNumberOp):
+    mathop = staticmethod(minus)
+    
 
 class Null(Expression):
     opcode = 'NULL'
@@ -768,7 +764,7 @@
 
     def eval(self, ctx):
         w_obj = W_Object()
-        for prop in self.nodelist:
+        for prop in self.nodes:
             name = prop.left.name
             w_expr = prop.right.eval(ctx).GetValue()
             w_obj.Put(name, w_expr)
@@ -780,9 +776,9 @@
 #
 ##############################################################################
 
-class Script(Statement):
+class SourceElements(Statement):
     """
-    Script nodes are found on each function declaration and in global code
+    SourceElements nodes are found on each function declaration and in global code
     """
     def __init__(self, pos, var_decl, func_decl, nodes):        
         self.var_decl = var_decl
@@ -794,8 +790,6 @@
             ctx.variable.Put(var.name, w_Undefined)
         for fun in self.func_decl:
             ctx.variable.Put(fun.name, fun.eval(ctx))
-            
-        
         node = self
 
         try:
@@ -808,7 +802,7 @@
                 raise
             else:
                 # TODO: proper exception handling
-                print "exception in line: %s, on: %s"%(node.lineno, node.value)
+                print "exception in line: %s, on: %s"%(node.pos.lineno, node)
                 raise
 
 class Program(Statement):
@@ -817,7 +811,7 @@
         self.body = body
 
     def execute(self, ctx):
-        return self.body.execute(self, ctx)
+        return self.body.execute(ctx)
 
 class Semicolon(Statement):
     opcode = 'SEMICOLON'
@@ -830,6 +824,13 @@
             return w_Undefined
         return self.expr.execute(ctx)
 
+# class ExpressionStatement(Statement):
+#     def __init__(self, pos, exp):
+#         self.expr = expr
+#     
+#     def execute(self, ctx):
+#         return self.expr.eval(ctx)
+
 class Return(Statement):
     opcode = 'RETURN'
 
@@ -902,19 +903,36 @@
     def execute(self, ctx):
         return None
 
-class Vars(Statement):
-    opcode = 'VAR'
-
-    def __init__(self, pos, t):
-        self.nodes = get_objects(t)
+class VariableDeclaration(Node):
+    def __init__(self, pos, identifier, initializerexp):
+        self.pos = pos
+        self.identifier = identifier
+        self.initializerexp = initializerexp
+    
+    def eval(self, ctx):
+        if not isinstance(self.initializerexp, Undefined):
+            ref = self.identifier.eval()
+            ref.PutValue(self.initializerexp.eval(ctx).GetValue(), ctx)
+        return w_Undefined
+    
 
-    def execute(self, ctx):
+class VariableDeclList(Expression):
+    def __init__(self, pos, nodes):
+        self.pos = pos
+        self.nodes = nodes
+    
+    def eval(self, ctx):
         for var in self.nodes:
-            var.execute(ctx)
-        return W_String(self.nodes[-1].get_literal())
+            var.eval(ctx)
+        return w_Undefined
+    
 
-    def eval(self, ctx):
-        return self.execute(ctx)
+class Variable(Statement):
+    def __init__(self, pos, body):
+        self.body = body
+    
+    def execute(self, ctx):
+        return self.body.eval()
 
 class Void(UnaryOp):
     opcode = 'VOID'
@@ -1021,20 +1039,12 @@
                     continue
     
 class Boolean(Expression):
-    def __init__(self, pos, t):
-        if self.opcode == 'TRUE':
-            self.bool = True
-        else:
-            self.bool = False
+    def __init__(self, pos, boolval):
+        self.bool = boolval
     
     def eval(self, ctx):
         return W_Boolean(self.bool)
-
-class BTrue(Boolean):
-    pass
-
-class BFalse(Boolean):
-    pass
+    
 
 class Not(UnaryOp):
     def eval(self, ctx):
@@ -1047,6 +1057,6 @@
 class UPlus(UnaryOp):    
     def eval(self, ctx):
         return W_Number(+self.expr.eval(ctx).GetValue().ToNumber())
-
+    
 
 astundef = Undefined(Position())

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	Sat May 19 19:01:56 2007
@@ -15,18 +15,14 @@
         py.test.skip("js binary not found")
 
 js_is_on_path()
-py.test.skip("making the transition to the new parser")
+py.test.skip("not ready yet")
 
 class TestInterp(object):
     def test_simple(self):
-        p = Plus()
-        n1 = Number()
-        n2 = Number()
-        n1.num = 2
-        n2.num = 4
-        p.left = n1
-        p.right = n2
-        assert p.eval(ExecutionContext()).GetValue().ToNumber() == 6
+        n1 = Number(Position(), 2.0)
+        n2 = Number(Position(), 4.0)
+        p = Plus(Position(), n1, n2)
+        assert p.eval(ExecutionContext()).GetValue().ToNumber() == 6.0
         l = []
         interpreter.writer = l.append
         # Script([Semicolon(Call(Identifier('print', None), 
@@ -54,8 +50,8 @@
         assert r.ToString() == result.ToString()
         
     def test_interp_parse(self):
-        self.assert_prints("print(1+1)", ["2"])
-        self.assert_prints("print(1+2+3); print(1)", ["6", "1"])
+        self.assert_prints("print(1+1);", ["2"])
+        self.assert_prints("print(1+2+3); print(1);", ["6", "1"])
         self.assert_prints("print(1,2,3);\n", ["1,2,3"])
 
     def test_var_assign(self):
@@ -63,7 +59,7 @@
         self.assert_prints("x=3;y=4;print(x+y);", ["7"])
 
     def test_minus(self):
-        self.assert_prints("print(2-1)", ["1"])
+        self.assert_prints("print(2-1);", ["1"])
     
     def test_string_var(self):
         self.assert_prints('print(\"sss\");', ["sss"])
@@ -90,7 +86,7 @@
     
     def test_function_returns(self):
         self.assert_prints('x=function(){return 1;}; print(x()+x());', ["2"])
-        self.assert_prints('function x() { return }', [])
+        self.assert_prints('function x() { return; };', [])
     
     def test_var_declaration(self):
         self.assert_prints('var x = 3; print(x);', ["3"])
@@ -167,13 +163,13 @@
         """, [""])
 
     def test_throw(self):
-        self.assert_prints("throw(3)", ["uncaught exception: 3"])
+        self.assert_prints("throw(3);", ["uncaught exception: 3"])
         
     def test_group(self):
-        self.assert_prints("print((2+1))", ["3"])
+        self.assert_prints("print((2+1));", ["3"])
 
     def test_comma(self):
-        self.assert_prints("print((500,3))", ["3"])
+        self.assert_prints("print((500,3));", ["3"])
     
     def test_try_catch(self):
         self.assert_prints("""
@@ -186,8 +182,8 @@
         """, ["3"])
     
     def test_block(self):
-        self.assert_result("{ 5}", W_Number(5))
-        self.assert_result("{3; 5}", W_Number(5))
+        self.assert_result("{ 5};", W_Number(5))
+        self.assert_result("{3; 5};", W_Number(5))
     
     def test_try_catch_finally(self):
         self.assert_prints("""
@@ -198,7 +194,7 @@
             print(x);
         }
         finally {
-            print(5)
+            print(5);
         }
         """, ["3", "5"])
         
@@ -219,27 +215,27 @@
         """, ["2"])
 
     def test_compare(self):
-        self.assert_prints("print(1>0)",["true"])
-        self.assert_prints("print(0>1)",["false"])
-        self.assert_prints("print(0>0)",["false"])
-        self.assert_prints("print(1<0)",["false"])
-        self.assert_prints("print(0<1)",["true"])
-        self.assert_prints("print(0<0)",["false"])
-        self.assert_prints("print(1>=0)",["true"])
-        self.assert_prints("print(1>=1)",["true"])
-        self.assert_prints("print(1>=2)",["false"])
-        self.assert_prints("print(0<=1)",["true"])
-        self.assert_prints("print(1<=1)",["true"])
-        self.assert_prints("print(1<=0)",["false"])
-        self.assert_prints("print(0==0)",["true"])
-        self.assert_prints("print(1==1)",["true"])
-        self.assert_prints("print(0==1)",["false"])
-        self.assert_prints("print(0!=1)",["true"])
-        self.assert_prints("print(1!=1)",["false"])
+        self.assert_prints("print(1>0);",["true"])
+        self.assert_prints("print(0>1);",["false"])
+        self.assert_prints("print(0>0);",["false"])
+        self.assert_prints("print(1<0);",["false"])
+        self.assert_prints("print(0<1);",["true"])
+        self.assert_prints("print(0<0);",["false"])
+        self.assert_prints("print(1>=0);",["true"])
+        self.assert_prints("print(1>=1);",["true"])
+        self.assert_prints("print(1>=2);",["false"])
+        self.assert_prints("print(0<=1);",["true"])
+        self.assert_prints("print(1<=1);",["true"])
+        self.assert_prints("print(1<=0);",["false"])
+        self.assert_prints("print(0==0);",["true"])
+        self.assert_prints("print(1==1);",["true"])
+        self.assert_prints("print(0==1);",["false"])
+        self.assert_prints("print(0!=1);",["true"])
+        self.assert_prints("print(1!=1);",["false"])
 
     def test_binary_op(self):
-        self.assert_prints("print(0||0); print(1||0)",["0", "1"])
-        self.assert_prints("print(0&&1); print(1&&1)",["0", "1"])
+        self.assert_prints("print(0||0); print(1||0);",["0", "1"])
+        self.assert_prints("print(0&&1); print(1&&1);",["0", "1"])
     
     def test_while(self):
         self.assert_prints("""
@@ -264,7 +260,7 @@
             print(z);
         }
         catch (e) {
-            print(e)
+            print(e);
         }
         """, ["ReferenceError: z is not defined"])
 
@@ -287,7 +283,7 @@
 
     def test_vars(self):
         self.assert_prints("""
-        var x;x=3; print(x)""", ["3"])
+        var x;x=3; print(x);""", ["3"])
 
     def test_minus(self):
         self.assert_prints("""
@@ -303,7 +299,7 @@
         print(x);
         z = 2;
         ""","""
-        print(z)
+        print(z);
         """]
         ,["3", "2"])
     
@@ -324,7 +320,7 @@
 
     def test_arrayobject(self):
         self.assert_prints("""var x = new Array();
-        print(x.length == 0)""", ['true'])
+        print(x.length == 0);""", ['true'])
          
     def test_break(self):
         self.assert_prints("""
@@ -334,12 +330,12 @@
         for(x=0;1==1;x++) {
             break;
         }
-        print('out')""", ["out"])
+        print('out');""", ["out"])
 
     def test_typeof(self):
         self.assert_result("""
         var x = 3;
-        typeof x == 'number'
+        typeof x == 'number';
         """, W_Boolean(True))
         
     def test_semicolon(self):
@@ -348,15 +344,15 @@
     def test_newwithargs(self):
         self.assert_prints("""
         var x = new Object(1,2,3,4);
-        print(x)
+        print(x);
         """, ["[object Object]"])
 
     def test_increment(self):
         self.assert_prints("""
         var x;
-        x = 1
-        x++
-        print(x)""", ["2"])
+        x = 1;
+        x++;
+        print(x);""", ["2"])
         
     def test_ternaryop(self):
         self.assert_prints([
@@ -368,53 +364,53 @@
         self.assert_prints("""
         var x = false;
         var y = true;
-        print(y)
-        print(x)""", ["true", "false"])
+        print(y);
+        print(x);""", ["true", "false"])
         
     def test_unarynot(self):
         self.assert_prints("""
         var x = false;
-        print(!x)
-        print(!!x)""", ["true", "false"])
+        print(!x);
+        print(!!x);""", ["true", "false"])
 
     def test_equals(self):
         self.assert_prints("""
         var x = 5;
-        y = z = x
-        print(y)""", ["5"])
+        y = z = x;
+        print(y);""", ["5"])
     
     def test_math_stuff(self):
         self.assert_prints("""
         var x = 5;
         var z = 2;
-        print(x*z)
-        print(4/z)
-        print(isNaN(z))
-        print(Math.abs(z-x))
-        print(Number.NaN)
-        print(Number.POSITIVE_INFINITY)
-        print(Number.NEGATIVE_INFINITY)
-        print(Math.floor(3.2))
-        print(null)
-        print(-z)
+        print(x*z);
+        print(4/z);
+        print(isNaN(z));
+        print(Math.abs(z-x));
+        print(Number.NaN);
+        print(Number.POSITIVE_INFINITY);
+        print(Number.NEGATIVE_INFINITY);
+        print(Math.floor(3.2));
+        print(null);
+        print(-z);
         """, ['10', '2', 'false', '3', 'NaN', 'inf', '-inf', '3', '', '-2'])
         
     def test_globalproperties(self):
         self.assert_prints( """
-        print(NaN)
-        print(Infinity)
-        print(undefined)
+        print(NaN);
+        print(Infinity);
+        print(undefined);
         """, ['NaN', 'inf', 'undefined'])
 
     def test_strangefunc(self):
         self.assert_prints("""function f1() { var z; var t;}""", [])
-        self.assert_prints(""" "'t'" """, [])
+        self.assert_prints(""" "'t'"; """, [])
         
     def test_null(self):
-        self.assert_result("null", w_Null)
+        self.assert_result("null;", w_Null)
 
     def test_void(self):
-        self.assert_prints("print(void print('hello'))",
+        self.assert_prints("print(void print('hello'));",
                             ["hello", "undefined"])
 
     def test_activationprob(self):
@@ -424,17 +420,17 @@
             return int1;
         }
         function x (v1){
-            this.p1 = v1
-            this.p2 = intern(this.p1)
+            this.p1 = v1;
+            this.p2 = intern(this.p1);
         }
-        var ins = new x(1)
-        print(ins.p1)
-        print(ins.p2)
+        var ins = new x(1);
+        print(ins.p1);
+        print(ins.p2);
         """, ['1','1', '1'])
 
     def test_array_acess(self):
         self.assert_prints("""
-        var x = new Array()
+        var x = new Array();
         x[0] = 1;
         x[x[0]] = 2;
         x[2] = x[0]+x[1];
@@ -447,73 +443,73 @@
         self.assert_prints("""
         var testcases = new Array();
         var tc = testcases.length;
-        print('tc'+tc) 
+        print('tc'+tc);
         """, ['tc0'])
     
     def test_mod_op(self):
-        self.assert_prints("print(2%2)", ['0'])
+        self.assert_prints("print(2%2);", ['0'])
     
     def test_unary_plus(self):
-        self.assert_prints("print(+1)", ['1'])
+        self.assert_prints("print(+1);", ['1'])
 
     def test_delete(self):
         self.assert_prints("""
-        var x = {}
+        var x = {};
         x.y = 1;
-        delete x.y
-        print(x.y)
+        delete x.y;
+        print(x.y);
         """, ['undefined'])
 
     def test_forin(self):
         self.assert_prints("""
-        var x = {a:5}
+        var x = {a:5};
         for(y in x){
-            print(y)
+            print(y);
         }
         """, ['5',])
 
     def test_stricteq(self):
         self.assert_prints("""
-        print(2 === 2)
-        print(2 === 3)
-        print(2 !== 3)
-        print(2 !== 2)    
+        print(2 === 2);
+        print(2 === 3);
+        print(2 !== 3);
+        print(2 !== 2);   
         """, ['true', 'false', 'true', 'false'])
     
     def test_with(self):
         self.assert_prints("""
-        var mock = {x:2}
-        var x=4
-        print(x)
+        var mock = {x:2};
+        var x=4;
+        print(x);
         try {
             with(mock) {
-                print(x)
-                throw 3
-                print("not reacheable")
+                print(x);
+                throw 3;
+                print("not reacheable");
             }
         }
         catch(y){
-            print(y)
+            print(y);
         }
-        print(x)
+        print(x);
         """, ['4', '2', '3', '4'])
     
     def test_bitops(self):
         self.assert_prints("""
-        print(2 ^ 2)
-        print(2 & 3)
-        print(2 | 3)
+        print(2 ^ 2);
+        print(2 & 3);
+        print(2 | 3);
         """, ['0', '2', '3'])
 
     def test_for_strange(self):
         self.assert_prints("""
-        for (var arg = "", i = 0; i < 2; i++) { print(i)}
+        for (var arg = "", i = 0; i < 2; i++) { print(i);}
         """, ['0', '1'])
 
     def test_recursive_call(self):
         self.assert_prints("""
         function fact(x) { if (x == 0) { return 1; } else { return fact(x-1)*x; }}
-        print(fact(3))
+        print(fact(3));
         """, ['6',])
     
     def test_function_prototype(self):
@@ -524,7 +520,8 @@
 
     def test_function_this(self):
         self.assert_prints("""
-        function foo() {print("debug");this.bar = function() {}};
+        function foo() {print("debug");this.bar = function() {};};
         var f = new foo();
         f.bar();
         """, ['debug',])
+    

Modified: pypy/dist/pypy/lang/js/test/test_parser.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_parser.py	(original)
+++ pypy/dist/pypy/lang/js/test/test_parser.py	Sat May 19 19:01:56 2007
@@ -308,8 +308,8 @@
         assert w_num.ToNumber() == 6
         w_num =  self.eval_expr('((((6))))')
         assert w_num.ToNumber() == 6
-        w_array = self.eval_expr('[1,2,3]')
-        assert w_array.ToString() == '1,2,3'
+        #w_array = self.eval_expr('[1,2,3]')
+        #assert w_array.ToString() == '1,2,3'
         w_identifier = self.eval_expr('x')
         py.test.raises(ThrowException, w_identifier.GetValue)
         w_object = self.eval_expr('{x:1}')
@@ -328,16 +328,3 @@
         w_str = self.eval_expr('"hello "+\'world\'')
         assert w_str.ToString() == 'hello world'
     
-
-class TestToASTProgram(BaseGrammarTest):
-    def setup_class(cls):
-        cls.parse = parse_func()
-
-    def to_ast(self, s):
-        ASTBuilder().dispatch(self.parse(s))
-    
-    def test_simple(self):
-        self.to_ast("1;")
-        #self.to_ast("var x=1;")
-        #self.to_ast("print(1+1);")
-    



More information about the Pypy-commit mailing list