[pypy-commit] lang-js default: 12.6.3-3

stepahn noreply at buildbot.pypy.org
Fri Dec 28 11:34:01 CET 2012


Author: Stephan <stephan at stzal.com>
Branch: 
Changeset: r221:5f3f2a98ade1
Date: 2012-05-23 13:59 +0200
http://bitbucket.org/pypy/lang-js/changeset/5f3f2a98ade1/

Log:	12.6.3-3

diff --git a/js/astbuilder.py b/js/astbuilder.py
--- a/js/astbuilder.py
+++ b/js/astbuilder.py
@@ -585,18 +585,14 @@
         left = self.dispatch(node.children[1])
         right = self.dispatch(node.children[2])
         body= self.dispatch(node.children[3])
-        assert isinstance(left, Identifier)
-        name = left.name
-        return operations.ForIn(pos, name, right, body)
+        return operations.ForIn(pos, left, right, body)
 
     def visit_invarfor(self, node):
         pos = self.get_pos(node)
         left = self.dispatch(node.children[1])
         right = self.dispatch(node.children[2])
         body= self.dispatch(node.children[3])
-        assert isinstance(left, operations.VariableDeclaration)# or isinstance(left, operations.LocalVariableDeclaration)
-        name = left.identifier
-        return operations.ForIn(pos, name, right, body)
+        return operations.ForIn(pos, left, right, body)
 
     def get_next_expr(self, node, i):
         if isinstance(node.children[i], Symbol) and \
diff --git a/js/jsobj.py b/js/jsobj.py
--- a/js/jsobj.py
+++ b/js/jsobj.py
@@ -1140,7 +1140,7 @@
         return self.to_string() == other_string
 
     def __str__(self):
-        return 'W_String("%s")' % (repr(self._strval_),)
+        return 'W_String("%s")' % (str(self._strval_),)
 
     def ToObject(self):
         return W_StringObject(self)
diff --git a/js/opcodes.py b/js/opcodes.py
--- a/js/opcodes.py
+++ b/js/opcodes.py
@@ -140,19 +140,16 @@
     def eval(self, ctx):
         from js.jsobj import W__Array
         array = W__Array()
-        for i in range(self.counter):
-            el = ctx.stack_pop()
-            index = str(self.counter - i - 1)
-            array.put(index, el)
-        length = self.counter
-        array.put('length', _w(length))
+        list_w = ctx.stack_pop_n(self.counter) # [:] # pop_n returns a non-resizable list
+        for index, el in enumerate(list_w):
+            array.put(str(index), el)
         ctx.stack_append(array)
 
     def stack_change(self):
         return -1 * self.counter + 1
 
-    #def __repr__(self):
-        #return 'LOAD_ARRAY %d' % (self.counter,)
+    def __str__(self):
+        return 'LOAD_ARRAY %d' % (self.counter,)
 
 class LOAD_LIST(Opcode):
     _immutable_fields_ = ['counter']
@@ -167,8 +164,8 @@
     def stack_change(self):
         return -1 * self.counter + 1
 
-    #def __repr__(self):
-        #return 'LOAD_LIST %d' % (self.counter,)
+    def __str__(self):
+        return 'LOAD_LIST %d' % (self.counter,)
 
 class LOAD_FUNCTION(Opcode):
     def __init__(self, funcobj):
@@ -212,6 +209,9 @@
         value = w_obj.get(name)
         ctx.stack_append(value)
 
+    def __str__(self):
+        return 'LOAD_MEMBER'
+
 class COMMA(BaseUnaryOperation):
     def eval(self, ctx):
         one = ctx.stack_pop()
@@ -662,10 +662,13 @@
         from js.jsobj import W_BasicObject
         assert isinstance(obj, W_BasicObject)
 
-        for key, prop in obj._properties_.items():
+        properties = obj._properties_.items()
+        properties.sort()
+        for key, prop in properties:
             if prop.enumerable is True:
                 props.append(_w(key))
 
+        props.reverse()
         from js.jsobj import W_Iterator
         iterator = W_Iterator(props)
 
@@ -688,8 +691,6 @@
 
 class NEXT_ITERATOR(Opcode):
     _stack_change = 0
-    def __init__(self, name):
-        self.name = name
 
     def eval(self, ctx):
         from js.jsobj import W_Iterator
@@ -697,8 +698,10 @@
         iterator = ctx.stack_top()
         assert isinstance(iterator, W_Iterator)
         next_el = iterator.next()
-        ref = ctx.get_ref(self.name)
-        ref.put_value(next_el)
+        ctx.stack_append(next_el)
+
+        #ref = ctx.get_ref(self.name)
+        #ref.put_value(next_el)
 
 # ---------------- with support ---------------------
 
diff --git a/js/operations.py b/js/operations.py
--- a/js/operations.py
+++ b/js/operations.py
@@ -915,20 +915,44 @@
         bytecode.done_continue()
 
 class ForIn(Statement):
-    def __init__(self, pos, name, lobject, body):
+    def __init__(self, pos, left_expr, lobject, body):
         self.pos = pos
-        self.iteratorname = name
+        self.left_expr = left_expr
         self.w_object = lobject
         self.body = body
 
     def emit(self, bytecode):
-        self.w_object.emit(bytecode)
+        w_object = self.w_object
+        left_expr = self.left_expr
+        body = self.body
+
+        w_object.emit(bytecode)
         bytecode.emit('LOAD_ITERATOR')
         precond = bytecode.emit_startloop_label()
         finish = bytecode.prealocate_endloop_label()
         bytecode.emit('JUMP_IF_ITERATOR_EMPTY', finish)
-        bytecode.emit('NEXT_ITERATOR', self.iteratorname)
-        self.body.emit(bytecode)
+
+        # put next iterator value on stack
+        bytecode.emit('NEXT_ITERATOR')
+
+        # store iterrator value into approperiate place
+        if isinstance(left_expr, Identifier):
+            name = left_expr.name
+            index = left_expr.index
+            bytecode.emit('STORE', index, name)
+            bytecode.emit('POP')
+        elif isinstance(left_expr, VariableDeclaration):
+            name = left_expr.identifier
+            index = left_expr.index
+            bytecode.emit('STORE', index, name)
+            bytecode.emit('POP')
+        elif isinstance(left_expr, MemberDot):
+            bytecode.emit('LOAD_STRINGCONSTANT', left_expr.name)
+            left_expr.left.emit(bytecode)
+            bytecode.emit('STORE_MEMBER')
+            bytecode.emit('POP')
+
+        body.emit(bytecode)
         # remove last body statement from stack
         bytecode.emit('POP')
         bytecode.emit('JUMP', precond)


More information about the pypy-commit mailing list