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

fijal at codespeak.net fijal at codespeak.net
Fri Apr 4 06:17:33 CEST 2008


Author: fijal
Date: Fri Apr  4 06:17:30 2008
New Revision: 53316

Modified:
   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/test/test_interp.py
Log:
Oops. Fix interactive interpreter


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	Fri Apr  4 06:17:30 2008
@@ -114,12 +114,7 @@
 
     bytecode = JsCode()
     node.emit(bytecode)
-    # XXX awful hack, we shall have a general way of doing that
-    from pypy.lang.js.jscode import POP
-    assert isinstance(bytecode.opcodes[-1], POP)
-    bytecode.opcodes.pop()
-    bytecode.run(ctx, check_stack=False)
-    return bytecode.stack[-1]
+    return bytecode.run(ctx, retlast=True)
 
 def parseIntjs(ctx, args, this):
     if len(args) < 1:
@@ -263,12 +258,7 @@
         ast = ASTBUILDER.dispatch(funcnode)
         bytecode = JsCode()
         ast.emit(bytecode)
-        # XXX awful hack
-        from pypy.lang.js.jscode import POP
-        assert isinstance(bytecode.opcodes[-1], POP)
-        bytecode.opcodes.pop()
-        bytecode.run(ctx, check_stack=False)
-        return bytecode.stack[-1]
+        return bytecode.run(ctx, retlast=True)
     
     def Construct(self, ctx, args=[]):
         return self.Call(ctx, args, this=None)
@@ -559,12 +549,14 @@
         self.w_Global = w_Global
         self.w_Object = w_Object
 
-    def run(self, script):
+    def run(self, script, interactive=False):
         """run the interpreter"""
         bytecode = JsCode()
         script.emit(bytecode)
-        bytecode.run(self.global_context)
-        # XXX not sure what this should return
+        if interactive:
+            return bytecode.run(self.global_context, retlast=True)
+        else:
+            bytecode.run(self.global_context)
 
 def wrap_arguments(pyargs):
     "receives a list of arguments and wrap then in their js equivalents"

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	Fri Apr  4 06:17:30 2008
@@ -69,7 +69,7 @@
             res = self.interpreter.run(ast)
             if res not in (None, w_Undefined):
                 try:
-                    print res.GetValue().ToString(self.interpreter.w_Global)
+                    print res.ToString(self.interpreter.w_Global)
                 except ThrowException, exc:
                     print exc.exception.ToString(self.interpreter.w_Global)
         except SystemExit:

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	Fri Apr  4 06:17:30 2008
@@ -13,7 +13,10 @@
 class AlreadyRun(Exception):
     pass
 
-def run_bytecode(opcodes, ctx, stack, check_stack=True):
+def run_bytecode(opcodes, ctx, stack, check_stack=True, retlast=False):
+    if retlast:
+        assert opcodes[-1] == 'POP'
+        opcodes.pop()
     i = 0
     to_pop = 0
     try:
@@ -36,7 +39,10 @@
     finally:
         for i in range(to_pop):
             ctx.pop_object()
-                
+
+    if retlast:
+        assert len(stack) == 1
+        return stack[0]
     if check_stack:
         assert not stack
 
@@ -102,10 +108,10 @@
         raise ValueError("Unknown opcode %s" % (operation,))
     emit._annspecialcase_ = 'specialize:arg(1)'
 
-    def run(self, ctx, check_stack=True):
+    def run(self, ctx, check_stack=True, retlast=False):
         if self.has_labels:
             self.remove_labels()
-        run_bytecode(self.opcodes, ctx, self.stack, check_stack)
+        return run_bytecode(self.opcodes, ctx, self.stack, check_stack, retlast)
 
     def remove_labels(self):
         """ Basic optimization to remove all labels and change

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	Fri Apr  4 06:17:30 2008
@@ -36,11 +36,7 @@
     try:
         bytecode = JsCode()
         interpreter.load_source(code, '').emit(bytecode)
-        # XXX terrible hack
-        assert isinstance(bytecode.opcodes[-1], POP)
-        bytecode.opcodes.pop()
-        bytecode.run(ExecutionContext([ctx]), check_stack=False)
-        code_val = bytecode.stack[0]
+        code_val = bytecode.run(ExecutionContext([ctx]), retlast=True)
     except ThrowException, excpt:
         code_val = excpt.exception
     print code_val, value



More information about the Pypy-commit mailing list