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

jandem at codespeak.net jandem at codespeak.net
Wed May 6 17:37:25 CEST 2009


Author: jandem
Date: Wed May  6 17:37:24 2009
New Revision: 65107

Modified:
   pypy/branch/js-refactoring/pypy/lang/js/interpreter.py
   pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
Log:
fix translation of JS-interpreter


Modified: pypy/branch/js-refactoring/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/interpreter.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/interpreter.py	Wed May  6 17:37:24 2009
@@ -232,7 +232,7 @@
             elif (i + 5 < lgt and strval[i + 1] == 'u' and
                   _ishex(strval[i + 2]) and _ishex(strval[i + 3]) and
                   _ishex(strval[i + 4]) and _ishex(strval[i + 5])):
-                ch = unichr(int(strval[i+2:i+6], 16))
+                ch = chr(int(strval[i+2:i+6], 16))
                 i += 5
         i += 1
         res.append(ch)
@@ -375,7 +375,7 @@
         temp = []
         for arg in args:
             i = arg.ToInt32(ctx) % 65536 # XXX should be uint16
-            temp.append(unichr(i))
+            temp.append(chr(i))
         return W_String(''.join(temp))
 
 class W_CharAt(W_NewBuiltin):
@@ -422,7 +422,8 @@
             pos = 0
         else:
             pos = args[1].ToInteger(ctx)
-        pos = min(max(pos, 0), size)
+        pos = int(min(max(pos, 0), size))
+        assert pos >= 0
         return W_IntNumber(string.find(substr, pos))
 
 class W_LastIndexOf(W_NewBuiltin):
@@ -441,9 +442,11 @@
             else:
                 pos = args[1].ToInteger(ctx)
         size = len(string)
-        pos = min(max(pos, 0), size)
+        pos = int(min(max(pos, 0), size))
         subsize = len(substr)
-        return W_IntNumber(string.rfind(substr, 0, pos+subsize))
+        endpos = pos+subsize
+        assert endpos >= 0
+        return W_IntNumber(string.rfind(substr, 0, endpos))
 
 class W_Substring(W_NewBuiltin):
     length = 2
@@ -722,8 +725,8 @@
         w_math.Put(ctx, 'E', W_FloatNumber(math.e), flags=allon)
         w_math.Put(ctx, 'LN2', W_FloatNumber(math.log(2)), flags=allon)
         w_math.Put(ctx, 'LN10', W_FloatNumber(math.log(10)), flags=allon)
-        w_math.Put(ctx, 'LOG2E', W_FloatNumber(math.log(math.e, 2)), flags=allon)
-        w_math.Put(ctx, 'LOG10E', W_FloatNumber(math.log(math.e, 10)), flags=allon)
+        #w_math.Put(ctx, 'LOG2E', W_FloatNumber(math.log(math.e, 2)), flags=allon)
+        #w_math.Put(ctx, 'LOG10E', W_FloatNumber(math.log(math.e, 10)), flags=allon)
         w_math.Put(ctx, 'PI', W_FloatNumber(math.pi), flags=allon)
         w_math.Put(ctx, 'SQRT1_2', W_FloatNumber(math.sqrt(0.5)), flags=allon)
         w_math.Put(ctx, 'SQRT2', W_FloatNumber(math.sqrt(2)), flags=allon)

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	Wed May  6 17:37:24 2009
@@ -111,7 +111,6 @@
 
 
 class W_PrimitiveObject(W_Root):
-    length = -1
     def __init__(self, ctx=None, Prototype=None, Class='Object',
                  Value=w_Undefined, callfunc=None):
         self.propdict = {}
@@ -126,9 +125,6 @@
         else:
             self.Scope = None
         self.Value = Value
-        
-        if self.length != -1:
-            self.Put(ctx, 'length', W_IntNumber(self.length), flags = DE|DD|RO)
 
     def Call(self, ctx, args=[], this=None):
         if self.callfunc is None: # XXX Not sure if I should raise it here
@@ -260,6 +256,7 @@
         return self.Get(ctx, 'valueOf').Call(ctx, args=[], this=self).ToNumber(ctx)
 
 class W_NewBuiltin(W_PrimitiveObject):
+    length = -1
     def __init__(self, ctx, Prototype=None, Class='function',
                  Value=w_Undefined, callfunc=None):
         if Prototype is None:
@@ -267,6 +264,10 @@
             Prototype = proto
 
         W_PrimitiveObject.__init__(self, ctx, Prototype, Class, Value, callfunc)
+        
+        if self.length != -1:
+            self.Put(ctx, 'length', W_IntNumber(self.length), flags = DE|DD|RO)
+
 
     def Call(self, ctx, args=[], this = None):
         raise NotImplementedError



More information about the Pypy-commit mailing list