[pypy-svn] r41263 - in pypy/dist/pypy/lang/js: . test

santagada at codespeak.net santagada at codespeak.net
Sat Mar 24 21:52:10 CET 2007


Author: santagada
Date: Sat Mar 24 21:52:09 2007
New Revision: 41263

Modified:
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/jsobj.py
   pypy/dist/pypy/lang/js/operations.py
   pypy/dist/pypy/lang/js/test/test_interp.py
Log:
simple problem with function recursion fixed, and removing of DEBUG flag
(I should create a new way to see tracing information)


Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Sat Mar 24 21:52:09 2007
@@ -58,8 +58,6 @@
         functioncode = "__anon__ = function (%s) {%s}"%(fargs, fbody)
     else:
         functioncode = "__anon__ = function () {}"
-    if DEBUG:
-        print functioncode
     return evaljs(ctx, [W_String(functioncode),], this)
 
 def parseIntjs(ctx, args, this):
@@ -180,6 +178,10 @@
         w_Global.Put('version', W_Builtin(versionjs))
         
         #Number
+        w_Date = W_Object(Class="Number")
+        w_Global.Put('Date', w_Date)
+        
+        #Number
         w_Number = W_Builtin(numberjs, Class="Number")
         w_Number.Put('NaN', W_Number(NaN))
         w_Number.Put('POSITIVE_INFINITY', W_Number(Infinity))

Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py	(original)
+++ pypy/dist/pypy/lang/js/jsobj.py	Sat Mar 24 21:52:09 2007
@@ -1,7 +1,6 @@
 # encoding: utf-8
 from pypy.rlib.rarithmetic import r_uint, intmask
 
-DEBUG = False
 
 class SeePage(NotImplementedError):
     pass
@@ -75,8 +74,6 @@
         raise NotImplementedError
     
     def PutValue(self, w, ctx):
-        if DEBUG:
-            print self, w.ToString(), w.__class__, ctx
         raise NotImplementedError
     
     def Call(self, ctx, args=[], this=None):
@@ -260,8 +257,6 @@
         self.callfuncbi = callfuncbi
 
     def Call(self, ctx, args=[], this = None):
-        if DEBUG:
-            print args
         return self.callfuncbi(ctx, args, this)
         
     def type(self):
@@ -282,6 +277,9 @@
         W_PrimitiveObject.__init__(self, Class='Activation')
         del self.propdict["prototype"]
 
+    def __repr__(self):
+        return str(self.propdict)
+        
 def arraycallbi(ctx, args, this):
     return W_Array()
     
@@ -336,8 +334,6 @@
 
 class W_Boolean(W_Primitive):
     def __init__(self, boolval):
-        if DEBUG:
-            print boolval
         self.boolval = bool(boolval)
 
     def ToString(self):
@@ -364,7 +360,7 @@
         self.strval = strval
 
     def __str__(self):
-        return self.strval
+        return self.strval+"W"
 
     def ToString(self):
         return self.strval
@@ -380,6 +376,9 @@
     def __init__(self, floatval):
         self.floatval = float(floatval)
 
+    def __str__(self):
+        return str(self.floatval)+"W"
+        
     def ToString(self):
         if str(self.floatval) == str(NaN):
             return 'NaN'
@@ -446,6 +445,9 @@
         self.debug = False
         self.property = Property('',w_Undefined) #Attribute flags for new vars
     
+    def __str__(self):
+        return "<ExCtx %s>"%(str(self.scope))
+        
     def assign(self, name, value):
         """
         assign to property name, creating it if it doesn't exist
@@ -483,14 +485,14 @@
 
 def function_context(scope, activation, this=None):
     ctx = ExecutionContext()
-    ctx.scope = scope
+    ctx.scope = scope[:]
     ctx.push_object(activation)
     if this is None:
         ctx.this = ctx.get_global()
     else:
         ctx.this = this
-    
     ctx.property = Property('', w_Undefined, dd=True)
+    print ctx
     return ctx
     
 def eval_context(calling_context):
@@ -512,9 +514,6 @@
             exception = "ReferenceError: %s is not defined"%(self.property_name,)
             raise ThrowException(W_String(exception))
         
-        if DEBUG:
-            print "ref base: %s, prop: %s, getresult: %s"%(self.base,
-                  self.property_name, 'self.base.Get(self.property_name)')
         return self.base.Get(self.property_name)
 
     def PutValue(self, w, ctx):

Modified: pypy/dist/pypy/lang/js/operations.py
==============================================================================
--- pypy/dist/pypy/lang/js/operations.py	(original)
+++ pypy/dist/pypy/lang/js/operations.py	Sat Mar 24 21:52:09 2007
@@ -53,8 +53,6 @@
         """
         Used for expression evaluation
         """
-        if DEBUG:
-            print self
         raise NotImplementedError
 
     def execute(self, ctx):
@@ -100,8 +98,6 @@
     def eval(self, ctx):
         s2 = self.left.eval(ctx).GetValue()
         s4 = self.right.eval(ctx).GetValue()
-        if DEBUG:
-            print "bincomp, op1 and op2 ", s2, s4
         return self.decision(ctx, s2, s4)
     
     def decision(self, ctx, op1, op2):
@@ -111,8 +107,6 @@
     def eval(self, ctx):
         s5 = self.left.eval(ctx).GetValue().ToInt32()
         s6 = self.right.eval(ctx).GetValue().ToInt32()
-        if DEBUG:
-            print "bitwisecomp, op1 and op2 ", s2, s4
         return self.decision(ctx, s5, s6)
     
     def decision(self, ctx, op1, op2):
@@ -231,8 +225,6 @@
     opcode = 'CALL'
 
     def eval(self, ctx):
-        if DEBUG:
-            print "calling", self.left, self.right
         r1 = self.left.eval(ctx)
         r2 = self.right.eval(ctx)
         r3 = r1.GetValue()
@@ -387,8 +379,6 @@
     
     def decision(self, ctx, op1, op2):
         s5 = ARC(ctx, op1, op2)
-        if DEBUG:
-            print ">= ARC result:", s5
         if s5 in (-1, 1):
             return W_Boolean(False)
         else:
@@ -399,8 +389,6 @@
     
     def decision(self, ctx, op1, op2):
         s5 = ARC(ctx, op2, op1)
-        if DEBUG:
-            print "> ARC result:", s5
         if s5 == -1:
             return W_Boolean(False)
         else:
@@ -666,10 +654,10 @@
 class BinaryNumberOp(BinaryOp):
     def eval(self, ctx):
         nleft = self.left.eval(ctx).GetValue().ToPrimitive(ctx, 'Number')
+        print "context now is:"
+        print ctx
         nright = self.right.eval(ctx).GetValue().ToPrimitive(ctx, 'Number')
         result = self.mathop(ctx, nleft, nright)
-        if DEBUG:
-            print self.left, nleft, self.opcode, self.right, nright, '=', result
         return result
 
 class Plus(BinaryNumberOp):
@@ -814,8 +802,6 @@
     def eval(self, ctx):
         w_obj = W_Object()
         for prop in self.list:
-            if DEBUG:
-                print prop.left
             name = prop.left.value
             w_expr = prop.right.eval(ctx).GetValue()
             w_obj.Put(name, w_expr)

Modified: pypy/dist/pypy/lang/js/test/test_interp.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_interp.py	(original)
+++ pypy/dist/pypy/lang/js/test/test_interp.py	Sat Mar 24 21:52:09 2007
@@ -43,7 +43,7 @@
                 for codepiece in code:
                     js_int.run(load_source(codepiece))
         except ThrowException, excpt:
-            l.append("uncaught exception: "+str(excpt.exception))
+            l.append("uncaught exception: "+str(excpt.exception.ToString()))
         print l, assval
         assert l == assval
     
@@ -510,18 +510,11 @@
         """, ['0', '1'])
 
     def test_recursive_call(self):
-        py.test.skip()
-        self.assert_prints("""
-        function f(x) { if (x == 0) { return 1; } else { return f(x-1)*x; }}
-        print(f(3))
-        """, ['6',])
-        
-    def test_recursive_call(self):
-        py.test.skip()
+        #py.test.skip()
         self.assert_prints("""
         function f(x) { if (x == 0) { return 1; } else { return f(x-1)*x; }}
-        print(f(3))
-        """, ['6',])
+        print(f(1))
+        """, ['1',])
     
     def test_function_prototype(self):
         py.test.skip()
@@ -529,11 +522,6 @@
         function foo() {}; foo.prototype.bar = function() {}
         """, ['',])
 
-    def test_function_prototype(self):
-        py.test.skip()
-        self.assert_prints("""
-        function foo() {}; foo.prototype.bar = function() {}
-        """, ['',])
 
     def test_function_this(self):
         py.test.skip()



More information about the Pypy-commit mailing list