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

santagada at codespeak.net santagada at codespeak.net
Fri Mar 2 14:58:26 CET 2007


Author: santagada
Date: Fri Mar  2 14:58:24 2007
New Revision: 39678

Modified:
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/jsobj.py
   pypy/dist/pypy/lang/js/test/ecma/shell.js
Log:
new shift operators and math.pow

Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Fri Mar  2 14:58:24 2007
@@ -3,6 +3,7 @@
 from pypy.lang.js.jsparser import parse, parse_bytecode
 from pypy.lang.js.jsobj import *
 from pypy.rlib.parsing.ebnfparse import Symbol, Nonterminal
+from pypy.rlib.rarithmetic import r_uint
 
 class Node(object):
     opcode = None
@@ -156,6 +157,9 @@
 def floorjs(ctx, args, this):
     return W_Number(math.floor(args[0].ToNumber()))
 
+def powjs(ctx, args, this):
+    return W_Number(math.pow(args[0].ToNumber(), args[1].ToNumber()))
+    
 def versionjs(ctx, args, this):
     return w_Undefined
 
@@ -187,6 +191,7 @@
         w_math.Put('__proto__',  w_ObjPrototype)
         w_math.Put('abs', W_Builtin(absjs, Class='function'))
         w_math.Put('floor', W_Builtin(floorjs, Class='function'))
+        w_math.Put('pow', W_Builtin(powjs, Class='function'))
         w_math.Put('E', W_Number(math.e))
         w_math.Put('PI', W_Number(math.pi))
         
@@ -351,6 +356,7 @@
             r7 = None
         else:
             r7 = r6
+        
         retval = r3.Call(ctx=ctx, args=r2.get_args(), this=r7)
         return retval
 
@@ -482,6 +488,30 @@
         s4 = self.right.eval(ctx).GetValue()
         return s4
 
+class Ursh(BinaryComparisonOp):
+    opcode = 'URSH'
+    
+    def decision(self, ctx, op1, op2):
+        a = op1.ToInt32()
+        b = op2.ToInt32()
+        return W_Number(r_uint(a) >> (r_uint(b) & 0x1F))
+
+class Rsh(BinaryComparisonOp):
+    opcode = 'RSH'
+    
+    def decision(self, ctx, op1, op2):
+        a = op1.ToInt32()
+        b = op2.ToInt32()
+        return W_Number(a >> int(r_uint(b) & 0x1F))
+
+class Lsh(BinaryComparisonOp):
+    opcode = 'LSH'
+    
+    def decision(self, ctx, op1, op2):
+        a = op1.ToInt32()
+        b = op2.ToInt32()
+        return W_Number(a << int(r_uint(b) & 0x1F))
+
 class Ge(BinaryComparisonOp):
     opcode = 'GE'
     
@@ -842,6 +872,7 @@
             ctx.variable.Put(var.name, w_Undefined)
         for fun in self.func_decl:
             ctx.variable.Put(fun.name, fun.eval(ctx))
+            
         
         node = self
 

Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py	(original)
+++ pypy/dist/pypy/lang/js/jsobj.py	Fri Mar  2 14:58:24 2007
@@ -395,6 +395,12 @@
         return 'number'
     
     def ToInt32(self):
+        strval = str(self.floatval)
+        if strval == str(NaN) or \
+           strval == str(Infinity) or \
+           strval == str(-Infinity):
+            return 0
+           
         return int(self.floatval)
 
 class W_List(W_Root):

Modified: pypy/dist/pypy/lang/js/test/ecma/shell.js
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/shell.js	(original)
+++ pypy/dist/pypy/lang/js/test/ecma/shell.js	Fri Mar  2 14:58:24 2007
@@ -50,7 +50,7 @@
 var PASSED = " PASSED!"
 var FAILED = " FAILED! expected: ";
 
-var DEBUG = true;
+var DEBUG = false;
 
 var DESCRIPTION;
 var EXPECTED;
@@ -218,7 +218,7 @@
 }
 
 function writeHeaderToLog( string ) {
-  print( string );
+  // print( string );
 }
 /* end of print functions */
 



More information about the Pypy-commit mailing list