[pypy-svn] r53306 - pypy/branch/js-refactoring/pypy/lang/js

fijal at codespeak.net fijal at codespeak.net
Fri Apr 4 03:05:32 CEST 2008


Author: fijal
Date: Fri Apr  4 03:05:32 2008
New Revision: 53306

Modified:
   pypy/branch/js-refactoring/pypy/lang/js/jscode.py
   pypy/branch/js-refactoring/pypy/lang/js/operations.py
Log:
With support. I think we can do better and not have a finally: related
slowdown when not using with (not sure how bad this is honestly)


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 03:05:32 2008
@@ -14,18 +14,28 @@
 
 def run_bytecode(opcodes, ctx, stack, check_stack=True):
     i = 0
-    while i < len(opcodes):
-        for name, op in opcode_unrolling:
-            opcode = opcodes[i]
-            opcode = hint(opcode, deepfreeze=True)
-            if isinstance(opcode, op):
-                result = opcode.eval(ctx, stack)
-                assert result is None
-                break
-        if isinstance(opcode, BaseJump):
-            i = opcode.do_jump(stack, i)
-        else:
-            i += 1
+    to_pop = 0
+    try:
+        while i < len(opcodes):
+            for name, op in opcode_unrolling:
+                opcode = opcodes[i]
+                opcode = hint(opcode, deepfreeze=True)
+                if isinstance(opcode, op):
+                    result = opcode.eval(ctx, stack)
+                    assert result is None
+                    break
+            if isinstance(opcode, BaseJump):
+                i = opcode.do_jump(stack, i)
+            else:
+                i += 1
+            if isinstance(opcode, WITH_START):
+                to_pop += 1
+            elif isinstance(opcode, WITH_END):
+                to_pop -= 1
+    finally:
+        for i in range(to_pop):
+            ctx.pop_object()
+                
     if check_stack:
         assert not stack
 
@@ -714,6 +724,19 @@
         assert isinstance(iterator, W_Iterator)
         ctx.assign(self.name, iterator.next())
 
+# ---------------- with support ---------------------
+
+class WITH_START(Opcode):
+    def __init__(self, name):
+        self.name = name
+
+    def eval(self, ctx, stack):
+        ctx.push_object(ctx.resolve_identifier(self.name).ToObject(ctx))
+
+class WITH_END(Opcode):
+    def eval(self, ctx, stack):
+        ctx.pop_object()
+
 OpcodeMap = {}
 
 for name, value in locals().items():

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	Fri Apr  4 03:05:32 2008
@@ -788,9 +788,15 @@
 class With(Statement):
     def __init__(self, pos, identifier, body):
         self.pos = pos
-        self.identifier = identifier
+        assert isinstance(identifier, VariableIdentifier)
+        self.identifier = identifier.identifier
         self.body = body
 
+    def emit(self, bytecode):
+        bytecode.emit('WITH_START', self.identifier)
+        self.body.emit(bytecode)
+        bytecode.emit('WITH_END')
+
     def execute(self, ctx):
         obj = self.identifier.eval(ctx).GetValue().ToObject(ctx)
         ctx.push_object(obj)
@@ -860,24 +866,7 @@
         self.body.emit(bytecode)
         bytecode.emit('JUMP', precond)
         bytecode.emit_endloop_label(finish)
-        bytecode.emit('POP')
-
-    def execute(self, ctx):
-        self.vardecl.eval(ctx)
-        obj = self.object.eval(ctx).GetValue().ToObject(ctx)
-        for prop in obj.propdict.values():
-            if prop.de:
-                continue
-            iterator = self.vardecl.eval(ctx)
-            iterator.PutValue(prop.value, ctx)
-            try:
-                result = self.body.execute(ctx)
-            except ExecutionReturned, e:
-                if e.type == 'break':
-                    break
-                elif e.type == 'continue':
-                    continue
-    
+        bytecode.emit('POP')    
 
 class ForIn(Statement):
     def __init__(self, pos, name, lobject, body):



More information about the Pypy-commit mailing list