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

santagada at codespeak.net santagada at codespeak.net
Mon Jan 15 13:21:41 CET 2007


Author: santagada
Date: Mon Jan 15 13:21:39 2007
New Revision: 36775

Modified:
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/js/jsparse.js
   pypy/dist/pypy/lang/js/jsobj.py
   pypy/dist/pypy/lang/js/jsparser.py
   pypy/dist/pypy/lang/js/test/autotestbase.py
   pypy/dist/pypy/lang/js/test/test_interp.py
Log:
more tests passing

Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Mon Jan 15 13:21:39 2007
@@ -18,7 +18,6 @@
         raise NotImplementedError
     
     def get_literal(self):
-        print self
         raise NotImplementedError
     
     def get_args(self, ctx):
@@ -441,8 +440,8 @@
         x = self.newexpr.eval(ctx).GetValue()
         if not isinstance(x, W_PrimitiveObject):
             raise TypeError()
-        
-        return x.Construct(ctx=ctx, args=[i for i in self.arglist.get_args(ctx)])
+        args = self.arglist.eval(ctx).get_args()
+        return x.Construct(ctx=ctx, args=args)
             
 
 class Number(Expression):
@@ -552,7 +551,11 @@
         self.expr = expr
 
     def execute(self, ctx):
-        raise ExecutionReturned('return', self.expr.eval(ctx), None)
+        if self.expr is None:
+            raise ExecutionReturned('return', None, None)
+        else:
+            raise ExecutionReturned('return', self.expr.eval(ctx), None)
+                    
 
 class Throw(Statement):
     def __init__(self, exception):
@@ -659,6 +662,13 @@
     def eval(self, ctx):
         return W_Boolean(not self.op.eval(ctx).GetValue().ToBoolean())
 
+class UMinus(Expression):
+    def __init__(self, op):
+        self.op = op
+    
+    def eval(self, ctx):
+        return W_Number(-self.op.eval(ctx).GetValue().ToNumber())
+
 def getlist(t):
     item = gettreeitem(t, 'length')
     if item is None:
@@ -669,8 +679,9 @@
     
 def gettreeitem(t, name):
     for x in t.children:
-        if x.children[0].additional_info == name:
-            return x.children[1]
+        if isinstance(x.children[0], Symbol):
+            if x.children[0].additional_info == name:
+                return x.children[1]
     return None
 
 
@@ -781,7 +792,11 @@
     elif tp == 'PROPERTY_INIT':
         node = PropertyInit(from_tree(gettreeitem(t, '0')), from_tree(gettreeitem(t, '1')))
     elif tp == 'RETURN':
-        node = Return(from_tree(gettreeitem(t, 'value')))
+        valit = gettreeitem(t, 'value')
+        if not isinstance(valit, Symbol):
+            node = Return(from_tree(valit))
+        else:
+            node = Return(None)
     elif tp == 'SCRIPT':
         f = gettreeitem(t, 'funDecls')
         if f.symbol == "dict":
@@ -839,6 +854,8 @@
         node = Boolean(False)
     elif tp == 'NOT':
         node = Not(from_tree(gettreeitem(t, '0')))
+    elif tp == 'UNARY_MINUS':
+        node = UMinus(from_tree(gettreeitem(t, '0')))
     else:
         raise NotImplementedError("Dont know how to handler %s" % tp)
     
@@ -854,7 +871,6 @@
     else:
         value = gettreeitem(t, 'value').additional_info
     
-    
     node.init_common(gettreeitem(t, 'type').additional_info, value,
     int(gettreeitem(t, 'lineno').additional_info), start, end)
     return node

Modified: pypy/dist/pypy/lang/js/js/jsparse.js
==============================================================================
--- pypy/dist/pypy/lang/js/js/jsparse.js	(original)
+++ pypy/dist/pypy/lang/js/js/jsparse.js	Mon Jan 15 13:21:39 2007
@@ -296,7 +296,7 @@
             }
         }
         val = a[i].value + "";
-        if ((val.search("\\},\\{") != -1 )) {
+        if ((val.search("\n"+INDENTATION.repeat(n)+"\\},\\{") != -1 )) {
             s += ",\n" + INDENTATION.repeat(n) + "'" + a[i].id + "': [" + val + "]";
         } else { 
             if (val.search("\n") != -1) {

Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py	(original)
+++ pypy/dist/pypy/lang/js/jsobj.py	Mon Jan 15 13:21:39 2007
@@ -477,8 +477,8 @@
             exception = "ReferenceError: %s is not defined"%(self.property_name,)
             raise ThrowException(W_String(exception))
         
-        print "ref base: %s, prop: %s, getresult: %s"%(self.base,
-                        self.property_name, self.base.Get(self.property_name))
+        # print "ref base: %s, prop: %s, getresult: %s"%(self.base,
+        #                         self.property_name, self.base.Get(self.property_name))
         return self.base.Get(self.property_name)
 
     def PutValue(self, w, ctx):

Modified: pypy/dist/pypy/lang/js/jsparser.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsparser.py	(original)
+++ pypy/dist/pypy/lang/js/jsparser.py	Mon Jan 15 13:21:39 2007
@@ -46,6 +46,7 @@
     return t
 
 def parse_bytecode(bytecode):
+    # print bytecode
     t = parse_tree(bytecode)
     tree = ToAST().transform(t)
     unquote(tree)

Modified: pypy/dist/pypy/lang/js/test/autotestbase.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/autotestbase.py	(original)
+++ pypy/dist/pypy/lang/js/test/autotestbase.py	Mon Jan 15 13:21:39 2007
@@ -4,14 +4,24 @@
 """
 
 from pypy.lang.js import interpreter
+from pypy.lang.js.interpreter import *
+from pypy.lang.js.test.conftest import option
+import py
 
+if not option.ecma:
+    py.test.skip('skipping ecma tests, use --ecma to run then')
+    print hello
+    
 class TestCase(object):
-    code = None
     def setup_class(self):
-        self.inter = interpreter.Interpreter(self.code or ";")
+        self.inter = interpreter.Interpreter()
+        if base() is not None:
+            self.inter.run(load_source(base()))
+            
+    def base(self):
+        return None
 
     def auto(self, expect, typeof, code):
-        self.inter.append_source(code)
-        r = self.inter.run()
+        r = self.inter.run(load_source(code))
         assert r.GetValue().ToString() == expect
         # TODO: assert typeof

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 Jan 15 13:21:39 2007
@@ -81,6 +81,7 @@
     
     def test_function_returns(self):
         self.assert_prints('x=function(){return 1;}; print(x()+x());', ["2"])
+        self.assert_prints('function x() { return }', [])
     
     def test_var_declaration(self):
         self.assert_prints('var x = 3; print(x);', ["3"])
@@ -388,7 +389,8 @@
         print(Number.POSITIVE_INFINITY)
         print(Number.NEGATIVE_INFINITY)
         print(Math.floor(3.2))
-        """, ['10', '2', 'false', '3'])
+        print(-z)
+        """, ['10', '2', 'false', '3', '-2'])
         
     def test_globalproperties(self):
         self.assert_prints( """
@@ -396,3 +398,6 @@
         print(Infinity)
         print(undefined)
         """, ['NaN', 'inf', 'undefined'])
+
+    def test_strangefunc(self):
+        self.assert_prints("""function f1() { var z; var t;}""", [])
\ No newline at end of file



More information about the Pypy-commit mailing list