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

fijal at codespeak.net fijal at codespeak.net
Tue Apr 1 04:39:44 CEST 2008


Author: fijal
Date: Tue Apr  1 04:39:42 2008
New Revision: 53223

Modified:
   pypy/branch/js-refactoring/pypy/lang/js/baseop.py
   pypy/branch/js-refactoring/pypy/lang/js/jscode.py
   pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
Log:
* Fix reprs
* First assignments work


Modified: pypy/branch/js-refactoring/pypy/lang/js/baseop.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/baseop.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/baseop.py	Tue Apr  1 04:39:42 2008
@@ -24,6 +24,12 @@
         fright = nright.ToNumber()
         return W_FloatNumber(fleft + fright)
 
+def increment(ctx, nleft, constval=1):
+    if isinstance(nleft, W_IntNumber):
+        return W_IntNumber(nleft.intval + constval)
+    else:
+        return plus(ctx, nleft, W_IntNumber(constval))
+
 def sub(ctx, nleft, nright):
     if isinstance(nleft, W_IntNumber) and isinstance(nright, W_IntNumber):
         ileft = nleft.ToInt32()

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:39:42 2008
@@ -6,7 +6,7 @@
 from pypy.lang.js.execution import JsTypeError, ReturnException, ThrowException
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.lang.js.baseop import plus, sub, compare, AbstractEC, StrictEC,\
-     compare_e
+     compare_e, increment
 from pypy.rlib.jit import hint
 
 class AlreadyRun(Exception):
@@ -28,6 +28,10 @@
     if check_stack:
         assert not stack
 
+class T(list):
+    def append(self, element):
+        assert element is not None
+        super(T, self).append(element)
 
 class JsCode(object):
     """ That object stands for code of a single javascript function
@@ -36,7 +40,7 @@
         self.opcodes = []
         self.label_count = 0
         self.has_labels = True
-        self.stack = []
+        self.stack = T()
 
     def emit_label(self):
         num = self.prealocate_label()
@@ -121,8 +125,8 @@
 
 class BaseBinaryComparison(Opcode):
     def eval(self, ctx, stack):
-        s4 = stack.pop()#.GetValue()
-        s2 = stack.pop()#.GetValue()
+        s4 = stack.pop()
+        s2 = stack.pop()
         stack.append(self.decision(ctx, s2, s4))
 
     def decision(self, ctx, op1, op2):
@@ -130,8 +134,8 @@
 
 class BaseBinaryBitwiseOp(Opcode):
     def eval(self, ctx, stack):
-        s5 = stack.pop().ToInt32()#.GetValue().ToInt32()
-        s6 = stack.pop().ToInt32()#.GetValue().ToInt32()
+        s5 = stack.pop().ToInt32()
+        s6 = stack.pop().ToInt32()
         stack.append(self.operation(ctx, s5, s6))
     
     def operation(self, ctx, op1, op2):
@@ -139,8 +143,8 @@
 
 class BaseBinaryOperation(Opcode):
     def eval(self, ctx, stack):
-        right = stack.pop()#.GetValue()
-        left = stack.pop()#.GetValue()
+        right = stack.pop()
+        left = stack.pop()
         stack.append(self.operation(ctx, left, right))
 
 class BaseUnaryOperation(Opcode):
@@ -218,7 +222,7 @@
         proto = ctx.get_global().Get('Array').Get('prototype')
         array = W_Array(ctx, Prototype=proto, Class = proto.Class)
         for i in range(self.counter):
-            array.Put(str(self.counter - i - 1), stack.pop())#.GetValue())
+            array.Put(str(self.counter - i - 1), stack.pop())
         stack.append(array)
 
     def __repr__(self):
@@ -263,24 +267,26 @@
         self.name = name
     
     def eval(self, ctx, stack):
-        value = stack[-1]
-        value = self.process(ctx, self.name, value)
+        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, value):
-        return value
+    def process(self, ctx, name, stack):
+        return stack[-1]
 
 class STORE_ADD(BaseStore):
-    def process(self, ctx, name, value):
+    def process(self, ctx, name, stack):
         xxx
 
 class STORE_POSTINCR(BaseStore):
-    def process(self, ctx, name, value):
-        xxx
+    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):
@@ -301,8 +307,8 @@
     def eval(self, ctx, stack):
         w_obj = create_object(ctx, 'Object')
         for _ in range(self.counter):
-            name = stack.pop().ToString(ctx)#.GetValue().ToString(ctx)
-            w_elem = stack.pop()#.GetValue()
+            name = stack.pop().ToString(ctx)
+            w_elem = stack.pop()
             w_obj.Put(name, w_elem)
         stack.append(w_obj)
 
@@ -314,7 +320,7 @@
         self.name = name
 
     def eval(self, ctx, stack):
-        w_obj = stack.pop().ToObject(ctx)#GetValue().ToObject(ctx)
+        w_obj = stack.pop().ToObject(ctx)
         stack.append(w_obj.Get(self.name))
         #stack.append(W_Reference(self.name, w_obj))
 
@@ -323,8 +329,8 @@
 
 class LOAD_ELEMENT(Opcode):
     def eval(self, ctx, stack):
-        name = stack.pop().ToString(ctx)#GetValue().ToString(ctx)
-        w_obj = stack.pop().ToObject(ctx)#GetValue().ToObject(ctx)
+        name = stack.pop().ToString(ctx)
+        w_obj = stack.pop().ToObject(ctx)
         stack.append(w_obj.Get(name))
         #stack.append(W_Reference(name, w_obj))
 
@@ -508,8 +514,7 @@
     def eval(self, ctx, stack):
         r1 = stack.pop()
         args = stack.pop()
-        r3 = r1#.GetValue()
-        if not isinstance(r3, W_PrimitiveObject):
+        if not isinstance(r1, W_PrimitiveObject):
             raise ThrowException(W_String("it is not a callable"))
             
         if isinstance(r1, W_Reference):
@@ -521,7 +526,7 @@
         else:
             r7 = r6
         try:
-            res = r3.Call(ctx=ctx, args=args.tolist(), this=r7)
+            res = r1.Call(ctx=ctx, args=args.tolist(), this=r7)
         except JsTypeError:
             raise ThrowException(W_String('it is not a function'))
         stack.append(res)

Modified: pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/jsobj.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/jsobj.py	Tue Apr  1 04:39:42 2008
@@ -413,9 +413,6 @@
     def __init__(self, intval):
         self.intval = intmask(intval)
 
-    def __str__(self):
-        return str(self.intval)+"W"
-
     def ToString(self, ctx=None):
         return str(self.intval)
 
@@ -435,14 +432,14 @@
     def GetPropertyName(self):
         return self.ToString()
 
+    def __repr__(self):
+        return 'W_IntNumber(%s)' % (self.intval,)
+
 class W_FloatNumber(W_BaseNumber):
     """ Number known to be a float
     """
     def __init__(self, floatval):
         self.floatval = floatval
-
-    def __str__(self):
-        return str(self.floatval)+"W"
     
     def ToString(self, ctx = None):
         if isnan(self.floatval):
@@ -474,6 +471,9 @@
         if isnan(self.floatval) or isinf(self.floatval):
             return r_uint(0)
         return r_uint(self.floatval)
+
+    def __repr__(self):
+        return 'W_FloatNumber(%s)' % (self.floatval,)
             
 class W_List(W_Root):
     def __init__(self, list_w):
@@ -487,10 +487,10 @@
     
     def get_args(self):
         return self.list_w
-    
-    def __str__(self):
-        return str(self.list_w)
 
+    def __repr__(self):
+        return 'W_List(%s)' % (self.list_w,)
+    
 class ExecutionContext(object):
     def __init__(self, scope, this=None, variable=None, 
                     debug=False, jsproperty=None):



More information about the Pypy-commit mailing list