[pypy-svn] r36981 - in pypy/dist/pypy/lang/js: . test
santagada at codespeak.net
santagada at codespeak.net
Fri Jan 19 11:41:25 CET 2007
Author: santagada
Date: Fri Jan 19 11:41:23 2007
New Revision: 36981
Modified:
pypy/dist/pypy/lang/js/interpreter.py
pypy/dist/pypy/lang/js/jsobj.py
pypy/dist/pypy/lang/js/test/test_interp.py
Log:
working
Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py (original)
+++ pypy/dist/pypy/lang/js/interpreter.py Fri Jan 19 11:41:23 2007
@@ -1,4 +1,5 @@
+import math
from pypy.lang.js.jsparser import parse, parse_bytecode
from pypy.lang.js.jsobj import *
from pypy.rlib.parsing.ebnfparse import Symbol, Nonterminal
@@ -86,6 +87,8 @@
return W_Boolean(args[0].ToBoolean())
return W_Boolean(False)
+def absjs(ctx, args, this):
+ return W_Number(abs(args[0].ToNumber()))
class Interpreter(object):
"""Creates a js interpreter"""
@@ -110,8 +113,9 @@
#And some other stuff
#Math
- # w_math = W_Object(Class='Math')
- # w_math.Put('abs')
+ w_math = W_Object(Class='Math')
+ w_Global.Put('Math', w_math)
+ w_math.Put('abs', W_Builtin(absjs, Class='function'))
#Global Properties
w_Global.Put('Object', w_Object)
@@ -217,9 +221,6 @@
r7 = None
else:
r7 = r6
- if r1.property_name == "getTestCaseResult":
- import pdb
- pdb.set_trace()
retval = r3.Call(ctx=ctx, args=r2.get_args(), this=r7)
return retval
@@ -247,7 +248,7 @@
class Dot(BinaryOp):
def eval(self, ctx):
w_obj = self.left.eval(ctx).GetValue().ToObject()
- name = self.right.get_literal()
+ name = self.right.eval(ctx).GetPropertyName()
return W_Reference(name, w_obj)
class Function(Expression):
@@ -411,18 +412,16 @@
self.expr = expr
def eval(self, ctx):
- w_obj = self.left.eval(ctx).GetValue()
- w_member = self.expr.eval(ctx).GetValue()
- w_obj = w_obj.ToObject()
- name = w_member.ToString()
- return w_obj.Get(name)
+ w_obj = self.left.eval(ctx).GetValue().ToObject()
+ name= self.expr.eval(ctx).GetValue().ToString()
+ return W_Reference(name, w_obj)
class List(Node):
def __init__(self, nodes):
self.nodes = nodes
def eval(self, ctx):
- return W_List([node.eval(ctx) for node in self.nodes])
+ return W_List([node.eval(ctx).GetValue() for node in self.nodes])
class Minus(BinaryComparisonOp):
def decision(self, ctx, op1, op2):
@@ -483,6 +482,7 @@
def decision(self, ctx, op1, op2):
prim_left = op1.ToPrimitive(ctx, 'Number')
prim_right = op2.ToPrimitive(ctx, 'Number')
+ print "plus", self.left, op1, prim_left, "+", self.right, op2, prim_right
if isinstance(prim_left, W_String) or isinstance(prim_right, W_String):
str_left = prim_left.ToString()
str_right = prim_right.ToString()
@@ -615,14 +615,10 @@
def eval(self, ctx):
val = self.op.eval(ctx)
- print val, val.GetBase()
if val.GetBase() is None:
return W_String("undefined")
- if isinstance(val.GetValue(), W_Reference):
- import pdb
- pdb.set_trace()
return W_String(val.GetValue().type())
-
+
class Undefined(Statement):
def execute(self, ctx):
return None
Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py (original)
+++ pypy/dist/pypy/lang/js/jsobj.py Fri Jan 19 11:41:23 2007
@@ -67,6 +67,7 @@
raise NotImplementedError
def PutValue(self, w, ctx):
+ print self, w.ToString(), w.__class__, ctx
raise NotImplementedError
def Call(self, ctx, args=[], this=None):
@@ -116,7 +117,7 @@
class W_Primitive(W_Root):
"""unifying parent for primitives"""
- def ToPrimitive(self, ctx, PreferredType):
+ def ToPrimitive(self, ctx, hint=""):
return self
class W_PrimitiveObject(W_Root):
@@ -140,7 +141,6 @@
arg = self.callfunc.params[i]
try:
value = args[i]
- print "value is", value
except IndexError:
value = w_Undefined
act.Put(self.callfunc.params[i], value)
@@ -212,7 +212,7 @@
return val
raise JsTypeError
- def DefaultValue(self, ctx, hint):
+ def DefaultValue(self, ctx, hint=""):
if hint == "String":
return self.internal_def_value(ctx, "toString", "valueOf")
else: #suppose hint is "Number" dunno what to do otherwise
@@ -294,11 +294,13 @@
def Put(self, P, V):
try:
x = int(P)
- if x > self.Get('length').ToNumber():
+ print "puting", V, 'in', x
+ if x > self.Get('length').ToNumber() - 1:
self.propdict['length'].value = W_Number(x)
currsize = len(self.array)
for i in range(x-(currsize-1)):
self.array.append(w_Undefined)
+ self.array[x]=V
except ValueError:
if not self.CanPut(P): return
@@ -311,8 +313,9 @@
try:
x = int(P)
if x > (len(self.array)-1):
- return W_Undefined
+ return w_Undefined
else:
+ print "returning", self.array[x], 'in', x
return self.array[x]
except ValueError:
return W_PrimitiveObject.Get(self, P)
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 Fri Jan 19 11:41:23 2007
@@ -378,7 +378,6 @@
print(y)""", ["5"])
def test_math_stuff(self):
- py.test.skip('not ready yet')
self.assert_prints("""
var x = 5;
var z = 2;
@@ -390,8 +389,9 @@
print(Number.POSITIVE_INFINITY)
print(Number.NEGATIVE_INFINITY)
print(Math.floor(3.2))
+ print(null)
print(-z)
- """, ['10', '2', 'false', '3', '-2'])
+ """, ['10', '2', 'false', '3', '', '-2'])
def test_globalproperties(self):
self.assert_prints( """
@@ -413,8 +413,26 @@
def test_activationprob(self):
self.assert_prints( """
- function x (actual){
- print(typeof actual)
+ function intern (int1){
+ print(int1);
+ return int1;
}
- x(true)
- """, ['boolean'])
+ function x (v1){
+ this.p1 = v1
+ this.p2 = intern(this.p1)
+ }
+ var ins = new x(1)
+ print(ins.p1)
+ print(ins.p2)
+ """, ['1','1', '1'])
+
+ def test_array_acess(self):
+ self.assert_prints("""
+ var x = new Array()
+ x[0] = 1;
+ x[x[0]] = 2;
+ x[2] = x[0]+x[1];
+ for(i=0; i<3; i++){
+ print(x[i]);
+ }
+ """, ['1', '2', '3'])
\ No newline at end of file
More information about the Pypy-commit
mailing list