[pypy-svn] r65523 - in pypy/branch/js-refactoring/pypy/lang/js: . test test/ecma

santagada at codespeak.net santagada at codespeak.net
Mon Jun 1 03:08:41 CEST 2009


Author: santagada
Date: Mon Jun  1 03:08:39 2009
New Revision: 65523

Removed:
   pypy/branch/js-refactoring/pypy/lang/js/conftest.py
Modified:
   pypy/branch/js-refactoring/pypy/lang/js/astbuilder.py
   pypy/branch/js-refactoring/pypy/lang/js/interpreter.py
   pypy/branch/js-refactoring/pypy/lang/js/js_interactive.py
   pypy/branch/js-refactoring/pypy/lang/js/jscode.py
   pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
   pypy/branch/js-refactoring/pypy/lang/js/operations.py
   pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py
   pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py
Log:
Applied hpk patches to conftest, unskipped test_interpreter tests and fixed pypy_repr, fixed propertyvalue pairs, fixed with statement, improved js_interactive error messages.

Modified: pypy/branch/js-refactoring/pypy/lang/js/astbuilder.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/astbuilder.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/astbuilder.py	Mon Jun  1 03:08:39 2009
@@ -223,7 +223,12 @@
     
     def visit_propertynameandvalue(self, node):
         pos = self.get_pos(node)
-        left = self.dispatch(node.children[0])
+        l = node.children[0]
+        if l.symbol == "IDENTIFIERNAME":
+            lpos = self.get_pos(l)
+            left = operations.Identifier(lpos, l.additional_info)
+        else:
+            left = self.dispatch(l)
         right = self.dispatch(node.children[1])
         return operations.PropertyInit(pos,left,right)
 

Modified: pypy/branch/js-refactoring/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/interpreter.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/interpreter.py	Mon Jun  1 03:08:39 2009
@@ -627,8 +627,8 @@
     def Construct(self, ctx, args=[]):
         return create_object(ctx, 'Date', Value = W_FloatNumber(0.0))
 
-def pypy_repr(ctx, repr, w_arg):
-    return W_String(w_arg.__class__.__name__)
+def pypy_repr(ctx, args, this):
+    return W_String(args[0].__class__.__name__)
 
 def put_values(ctx, obj, dictvalues):
     for key,value in dictvalues.iteritems():
@@ -829,8 +829,8 @@
 
         w_Global.Put(ctx, 'this', w_Global)
 
-        # DEBUGGING
-        if 0:
+        # debugging
+        if not we_are_translated():
             w_Global.Put(ctx, 'pypy_repr', W_Builtin(pypy_repr))
         
         self.global_context = ctx

Modified: pypy/branch/js-refactoring/pypy/lang/js/js_interactive.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/js_interactive.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/js_interactive.py	Mon Jun  1 03:08:39 2009
@@ -11,6 +11,7 @@
 from pypy.lang.js.jsparser import parse, ParseError
 from pypy.lang.js.jsobj import W_Builtin, W_String, ThrowException, w_Undefined
 from pypy.rlib.streamio import open_file_as_stream
+from pypy.lang.js.jscode import JsCode
 
 import code
 sys.ps1 = 'js> '
@@ -31,6 +32,11 @@
 except ImportError:
     pass
 
+DEBUG = False
+
+def debugjs(ctx, args, this):
+    global DEBUG
+    DEBUG = True
 
 def loadjs(ctx, args, this):
     filename = args[0].ToString()
@@ -53,7 +59,7 @@
         self.interpreter.w_Global.Put(ctx, 'quit', W_Builtin(quitjs))
         self.interpreter.w_Global.Put(ctx, 'load', W_Builtin(loadjs))
         self.interpreter.w_Global.Put(ctx, 'trace', W_Builtin(tracejs))
-
+        self.interpreter.w_Global.Put(ctx, 'debug', W_Builtin(debugjs))
 
     def runcodefromfile(self, filename):
         f = open_file_as_stream(filename)
@@ -67,6 +73,10 @@
         traceback.
         """
         try:
+            if DEBUG:
+                bytecode = JsCode()
+                ast.emit(bytecode)
+                print bytecode
             res = self.interpreter.run(ast, interactive=True)
             if res not in (None, w_Undefined):
                 try:
@@ -113,7 +123,7 @@
         print ' '*4 + \
               ' '*exc.source_pos.columnno + \
               '^'
-        print 'Syntax Error'
+        print 'Syntax Error:', exc.errorinformation.failure_reasons
 
     def interact(self, banner=None):
         if banner is None:

Modified: pypy/branch/js-refactoring/pypy/lang/js/jscode.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/jscode.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/jscode.py	Mon Jun  1 03:08:39 2009
@@ -923,11 +923,9 @@
 # ---------------- with support ---------------------
 
 class WITH_START(Opcode):
-    def __init__(self, name):
-        self.name = name
-
     def eval(self, ctx, stack):
-        ctx.push_object(ctx.resolve_identifier(ctx, self.name).ToObject(ctx))
+        obj = stack.pop().ToObject(ctx)
+        ctx.push_object(obj)
 
 class WITH_END(Opcode):
     def eval(self, ctx, stack):

Modified: pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/jsobj.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/jsobj.py	Mon Jun  1 03:08:39 2009
@@ -292,7 +292,7 @@
         return self.callfuncbi(ctx, args, None)
         
     def type(self):
-        return 'builtin'
+        return self.Class
 
 class W_ListObject(W_PrimitiveObject):
     def tolist(self):
@@ -427,7 +427,14 @@
         try:
             return float(self.strval)
         except ValueError:
-            return NAN
+            try:
+                return float(int(self.strval, 16))
+            except ValueError:
+                try:
+                    return float(int(self.strval, 8))
+                except ValueError:
+                    return NAN
+
 
 class W_BaseNumber(W_Primitive):
     """ Base class for numbers, both known to be floats

Modified: pypy/branch/js-refactoring/pypy/lang/js/operations.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/operations.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/operations.py	Mon Jun  1 03:08:39 2009
@@ -721,14 +721,14 @@
         bytecode.emit('LOAD_UNDEFINED')
 
 class With(Statement):
-    def __init__(self, pos, identifier, body):
+    def __init__(self, pos, expr, body):
         self.pos = pos
-        assert isinstance(identifier, VariableIdentifier)
-        self.identifier = identifier.identifier
+        self.expr = expr
         self.body = body
 
     def emit(self, bytecode):
-        bytecode.emit('WITH_START', self.identifier)
+        self.expr.emit(bytecode)
+        bytecode.emit('WITH_START')
         self.body.emit(bytecode)
         bytecode.emit('WITH_END')
 

Modified: pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py	Mon Jun  1 03:08:39 2009
@@ -14,32 +14,31 @@
 
 def overriden_evaljs(ctx, args, this):
     try:
-        return evaljs(ctx, args, this)
+        w_eval = W_Eval(ctx)
+        return w_eval.Call(ctx, args, this)
     except JsBaseExcept:
         return W_String("error")
 
-passing_tests = ['Number', 'Boolean']
+passing_tests = ['Number', 'Boolean', 'Array']
 
-class JSDirectory(py.test.collect.Directory):
+class EcmatestPlugin:
+    def pytest_addoption(self, parser):
+        parser.addoption('--ecma',
+               action="store_true", dest="ecma", default=False,
+               help="run js interpreter ecma tests"
+        )
 
-    def filefilter(self, path):
-        if not py.test.config.option.ecma:
-            for i in passing_tests:
-                if i in str(path):
-                    break
-            else:
-                return False
-        if path.check(file=1):
-            return (path.basename not in exclusionlist)  and (path.ext == '.js')
-
-    def join(self, name):
-        if not name.endswith('.js'):
-            return super(Directory, self).join(name)
-        p = self.fspath.join(name)
-        if p.check(file=1):
-            return JSTestFile(p, parent=self)
+    def pytest_collect_file(self, path, parent):
+        if parent.name not in passing_tests:
+            return
+        if path.ext == ".js" and path.basename not in exclusionlist:
+            if not parent.config.option.ecma:
+                py.test.skip("ECMA tests disabled, run with --ecma")
+            return JSTestFile(path, parent=parent)
+
+ConftestPlugin = EcmatestPlugin
 
-class JSTestFile(py.test.collect.Module):
+class JSTestFile(py.test.collect.File):
     def init_interp(cls):
         if hasattr(cls, 'interp'):
             cls.testcases.PutValue(W_Array(), cls.interp.global_context)
@@ -62,13 +61,7 @@
         self.name = fspath.purebasename
         self.fspath = fspath
           
-    def run(self):
-        if not py.test.config.option.ecma:
-            for i in passing_tests:
-                if i in self.listnames():
-                    break
-            else:
-                py.test.skip("ECMA tests disabled, run with --ecma")
+    def collect(self):
         if py.test.config.option.collectonly:
             return
         self.init_interp()
@@ -81,23 +74,20 @@
         except JsBaseExcept:
             raise Failed(msg="Javascript Error", excinfo=py.code.ExceptionInfo())
         except:
-            raise Failed(excinfo=py.code.ExceptionInfo())
+            raise
         ctx = self.interp.global_context
         testcases = ctx.resolve_identifier(ctx, 'testcases')
         self.tc = ctx.resolve_identifier(ctx, 'tc')
         testcount = testcases.Get(ctx, 'length').ToInt32(ctx)
         self.testcases = testcases
-        return range(testcount)
-
-    def join(self, number):
-        return JSTestItem(number, parent = self)
+        return [JSTestItem(number, parent=self) for number in range(testcount)]
 
 class JSTestItem(py.test.collect.Item):
     def __init__(self, number, parent=None):
         super(JSTestItem, self).__init__(str(number), parent)
         self.number = number
         
-    def run(self):
+    def runtest(self):
         ctx = JSTestFile.interp.global_context
         r3 = ctx.resolve_identifier(ctx, 'run_test')
         w_test_number = W_IntNumber(self.number)
@@ -110,4 +100,3 @@
     def _getpathlineno(self):
         return self.parent.parent.fspath, 0 
 
-Directory = JSDirectory

Modified: pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py	Mon Jun  1 03:08:39 2009
@@ -519,6 +519,14 @@
     print(x);
     """, ['4', '2', '3', '4'])
 
+def test_with_expr():
+    assertp("""
+    var x = 4;
+    with({x:2}) {
+        print(x);
+    }
+    """, ['2'])
+
 def test_bitops():
     yield assertv, "2 ^ 2;", 0
     yield assertv, "2 & 3;", 2
@@ -563,7 +571,6 @@
     yield assertv, "x=2; x^=2; x;", 0
 
 def test_not():
-    py.test.skip("not supported")
     assertv("~1", -2)
 
 def test_delete_member():
@@ -625,9 +632,11 @@
     assertv("var x = new Boolean; x.toString();", 'false')
 
 def test_pypy_repr():
-    py.test.skip("I don't understand, but it does not work")
-    assertv("pypy_repr(3);", 'W_IntNumber')
-    assertv("pypy_repr(3.0);", 'W_FloatNumber')
+    yield assertv, "pypy_repr(3);", 'W_IntNumber'
+    # See optimization on astbuilder.py for a reason to the test below
+    yield assertv, "pypy_repr(3.0);", 'W_IntNumber'
+    yield assertv, "pypy_repr(3.5);", 'W_FloatNumber'
+    yield assertv, "x=9999; pypy_repr(x*x*x);", 'W_FloatNumber'
 
 def test_number():
     assertp("print(Number(void 0))", "NaN")



More information about the Pypy-commit mailing list