[pypy-svn] r53224 - in pypy/branch/js-refactoring/pypy/lang/js: . test
fijal at codespeak.net
fijal at codespeak.net
Tue Apr 1 04:53:14 CEST 2008
Author: fijal
Date: Tue Apr 1 04:53:13 2008
New Revision: 53224
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
pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py
Log:
* disable variable assignment, it's not working anyway
* make more operations pass
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 Tue Apr 1 04:53:13 2008
@@ -167,7 +167,8 @@
if isinstance(left, Identifier):
return operations.SimpleAssignment(pos, left, None, atype, prepost)
elif isinstance(left, VariableIdentifier):
- return operations.VariableAssignment(pos, left, None, atype,
+ # XXX exchange to VariableAssignment
+ return operations.SimpleAssignment(pos, left, None, atype,
prepost)
elif isinstance(left, Member):
return operations.MemberAssignment(pos, left.left, left.expr,
@@ -326,7 +327,8 @@
if isinstance(left, Identifier):
return operations.SimpleAssignment(pos, left, right, atype)
elif isinstance(left, VariableIdentifier):
- return operations.VariableAssignment(pos, left, right, atype)
+ # XXX exchange to VariableAssignment
+ return operations.SimpleAssignment(pos, left, right, atype)
elif isinstance(left, Member):
return operations.MemberAssignment(pos, left.left, left.expr,
right, atype)
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 Tue Apr 1 04:53:13 2008
@@ -245,60 +245,17 @@
def __repr__(self):
return 'LOAD_FUNCTION' # XXX
-class BaseStoreMember(Opcode):
- pass
- #def eval(self, ctx, ):
- # XXX
-
-class STORE_MEMBER(Opcode):
- pass
-
-class STORE_MEMBER_POSTINCR(Opcode):
- pass
-
-class STORE_MEMBER_PREINCR(Opcode):
- pass
-
-class STORE_MEMBER_SUB(Opcode):
- pass
-
-class BaseStore(Opcode):
- def __init__(self, name):
- self.name = name
-
- def eval(self, ctx, stack):
- value = self.process(ctx, self.name, stack)
- ctx.assign(self.name, value)
-
- def __repr__(self):
- return '%s "%s"' % (self.__class__.__name__, self.name)
-
-class STORE(BaseStore):
- def process(self, ctx, name, stack):
- return stack[-1]
-
-class STORE_ADD(BaseStore):
- def process(self, ctx, name, stack):
- xxx
-
-class STORE_POSTINCR(BaseStore):
- def process(self, ctx, name, stack):
- value = ctx.resolve_identifier(name)
- newval = increment(ctx, value)
- stack.append(newval)
- return newval
-
-class STORE_VAR(Opcode):
- def __init__(self, depth, name):
- self.name = name
- self.depth = depth
-
- def eval(self, ctx, stack):
- value = stack[-1]
- ctx.scope[self.depth].Put(self.name, value)
+# class STORE_VAR(Opcode):
+# def __init__(self, depth, name):
+# self.name = name
+# self.depth = depth
+
+# def eval(self, ctx, stack):
+# value = stack[-1]
+# ctx.scope[self.depth].Put(self.name, value)
- def __repr__(self):
- return 'STORE "%s"' % self.name
+# def __repr__(self):
+# return 'STORE_VAR "%s"' % self.name
class LOAD_OBJECT(Opcode):
def __init__(self, counter):
@@ -342,15 +299,18 @@
# XXX
class SUB(BaseBinaryOperation):
- def operation(self, ctx, left, right):
+ @staticmethod
+ def operation(ctx, left, right):
return sub(ctx, left, right)
class ADD(BaseBinaryOperation):
- def operation(self, ctx, left, right):
+ @staticmethod
+ def operation(ctx, left, right):
return plus(ctx, left, right)
class BITAND(BaseBinaryBitwiseOp):
- def operation(self, ctx, op1, op2):
+ @staticmethod
+ def operation(ctx, op1, op2):
return W_IntNumber(op1&op2)
@@ -407,6 +367,60 @@
def decision(self, ctx, op1, op2):
return newbool(not StrictEC(ctx, op1, op2))
+
+class BaseStoreMember(Opcode):
+ pass
+ #def eval(self, ctx, ):
+ # XXX
+
+class STORE_MEMBER(Opcode):
+ pass
+
+class STORE_MEMBER_POSTINCR(Opcode):
+ pass
+
+class STORE_MEMBER_PREINCR(Opcode):
+ pass
+
+class STORE_MEMBER_SUB(Opcode):
+ pass
+
+class BaseStore(Opcode):
+ def __init__(self, name):
+ self.name = name
+
+ def eval(self, ctx, stack):
+ value = self.process(ctx, self.name, stack)
+ ctx.assign(self.name, value)
+
+ def __repr__(self):
+ return '%s "%s"' % (self.__class__.__name__, self.name)
+
+class STORE(BaseStore):
+ def process(self, ctx, name, stack):
+ return stack[-1]
+
+class BaseAssignOper(BaseStore):
+ def process(self, ctx, name, stack):
+ right = stack.pop()
+ left = ctx.resolve_identifier(name)
+ result = self.operation(ctx, left, right)
+ stack.append(result)
+ return result
+
+class STORE_ADD(BaseAssignOper):
+ operation = staticmethod(ADD.operation)
+
+class STORE_SUB(BaseAssignOper):
+ operation = staticmethod(SUB.operation)
+
+class STORE_POSTINCR(BaseStore):
+ def process(self, ctx, name, stack):
+ value = ctx.resolve_identifier(name)
+ newval = increment(ctx, value)
+ stack.append(newval)
+ return newval
+
class LABEL(Opcode):
def __init__(self, num):
self.num = num
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 Tue Apr 1 04:53:13 2008
@@ -166,6 +166,7 @@
class VariableAssignment(Assignment):
def __init__(self, pos, left, right, operand):
+ xxx # shall never land here for now
self.identifier = left.identifier
self.right = right
self.pos = pos
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 Tue Apr 1 04:53:13 2008
@@ -266,6 +266,10 @@
print(i);
""", ["0","1","2","3"])
+def test_assignments():
+ yield assertv, "var x = 3; x += 4; x;", 7
+ yield assertv, "x = 8; x -= 3; x;", 5
+
def test_object_creation():
yield assertv, """
o = new Object();
More information about the Pypy-commit
mailing list