[pypy-svn] r53254 - pypy/branch/js-refactoring/pypy/lang/js
fijal at codespeak.net
fijal at codespeak.net
Wed Apr 2 18:00:10 CEST 2008
Author: fijal
Date: Wed Apr 2 18:00:08 2008
New Revision: 53254
Modified:
pypy/branch/js-refactoring/pypy/lang/js/astbuilder.py
pypy/branch/js-refactoring/pypy/lang/js/jscode.py
pypy/branch/js-refactoring/pypy/lang/js/operations.py
Log:
In and For
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 Wed Apr 2 18:00:08 2008
@@ -33,7 +33,7 @@
'.': operations.MemberDot,
'[': operations.Member,
',': operations.Comma,
- #'in': operations.In,
+ 'in': operations.In,
}
UNOP_TO_CLS = {
#'~': operations.BitwiseNot,
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 Wed Apr 2 18:00:08 2008
@@ -319,6 +319,14 @@
def operation(ctx, left, right):
return sub(ctx, left, right)
+class IN(BaseBinaryOperation):
+ @staticmethod
+ def operation(ctx, left, right):
+ if not isinstance(right, W_Object):
+ raise ThrowException(W_String("TypeError"))
+ name = left.ToString(ctx)
+ return W_Boolean(right.HasProperty(name))
+
class ADD(BaseBinaryOperation):
@staticmethod
def operation(ctx, left, right):
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 Wed Apr 2 18:00:08 2008
@@ -501,15 +501,8 @@
StrictEq = create_binary_op('IS')
StrictNe = create_binary_op('ISNOT')
-# class In(BinaryOp):
-# """
-# The in operator, eg: "property in object"
-# """
-# def decision(self, ctx, op1, op2):
-# if not isinstance(op2, W_Object):
-# raise ThrowException(W_String("TypeError"))
-# name = op1.ToString(ctx)
-# return W_Boolean(op2.HasProperty(name))
+In = create_binary_op('IN')
+
# class Delete(UnaryOp):
# """
@@ -921,6 +914,19 @@
self.condition = condition
self.update = update
self.body = body
+
+ def emit(self, bytecode):
+ self.setup.emit(bytecode)
+ bytecode.emit('POP')
+ precond = bytecode.emit_label()
+ finish = bytecode.prealocate_label()
+ self.condition.emit(bytecode)
+ bytecode.emit('JUMP_IF_FALSE', finish)
+ self.body.emit(bytecode)
+ self.update.emit(bytecode)
+ bytecode.emit('POP')
+ bytecode.emit('JUMP', precond)
+ bytecode.emit('LABEL', finish)
def execute(self, ctx):
self.setup.eval(ctx).GetValue()
More information about the Pypy-commit
mailing list