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

santagada at codespeak.net santagada at codespeak.net
Fri Mar 2 15:52:09 CET 2007


Author: santagada
Date: Fri Mar  2 15:52:07 2007
New Revision: 39692

Modified:
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/jsobj.py
   pypy/dist/pypy/lang/js/test/ecma/conftest.py
Log:
now the math should be working, but the tests are still failling

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 15:52:07 2007
@@ -3,7 +3,6 @@
 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
@@ -492,25 +491,25 @@
     opcode = 'URSH'
     
     def decision(self, ctx, op1, op2):
-        a = op1.ToInt32()
-        b = op2.ToInt32()
-        return W_Number(int(r_uint(a) >> (r_uint(b) & 0x1F)))
+        a = op1.ToUInt32()
+        b = op2.ToUInt32()
+        return W_Number(a >> (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))
+        b = op2.ToUInt32()
+        return W_Number(a >> int(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))
+        b = op2.ToUInt32()
+        return W_Number(a << int(b & 0x1F))
 
 class Ge(BinaryComparisonOp):
     opcode = 'GE'

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 15:52:07 2007
@@ -1,4 +1,5 @@
 # encoding: utf-8
+from pypy.rlib.rarithmetic import r_uint
 
 DEBUG = False
 
@@ -63,6 +64,9 @@
     def ToInt32(self):
         return 0
     
+    def ToUInt32(self):
+        return r_uint(0)
+    
     def Get(self, P):
         raise NotImplementedError
     
@@ -368,7 +372,7 @@
 
 class W_Number(W_Primitive):
     def __init__(self, floatval):
-        self.floatval = floatval
+        self.floatval = float(floatval)
 
     def ToString(self):
         if str(self.floatval) == str(NaN):
@@ -402,6 +406,15 @@
             return 0
            
         return int(self.floatval)
+    
+    def ToUInt32(self):
+        strval = str(self.floatval)
+        if strval == str(NaN) or \
+           strval == str(Infinity) or \
+           strval == str(-Infinity):
+            return r_uint(0)
+           
+        return r_uint(self.floatval)
 
 class W_List(W_Root):
     def __init__(self, list_w):

Modified: pypy/dist/pypy/lang/js/test/ecma/conftest.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/conftest.py	(original)
+++ pypy/dist/pypy/lang/js/test/ecma/conftest.py	Fri Mar  2 15:52:07 2007
@@ -63,7 +63,7 @@
             raise Failed(msg="Javascript Error", excinfo=py.code.ExceptionInfo())
         testcases = self.interp.global_context.resolve_identifier('testcases')
         self.tc = self.interp.global_context.resolve_identifier('tc')
-        testcount = testcases.GetValue().Get('length').GetValue().ToNumber()
+        testcount = testcases.GetValue().Get('length').GetValue().ToInt32()
         self.testcases = testcases
         return range(testcount)
 



More information about the Pypy-commit mailing list