[pypy-svn] r35920 - in pypy/dist/pypy/lang/js: . test
santagada at codespeak.net
santagada at codespeak.net
Wed Dec 20 15:19:21 CET 2006
Author: santagada
Date: Wed Dec 20 15:19:05 2006
New Revision: 35920
Modified:
pypy/dist/pypy/lang/js/astgen.py
pypy/dist/pypy/lang/js/interpreter.py
pypy/dist/pypy/lang/js/jsobj.py
pypy/dist/pypy/lang/js/reference.py
pypy/dist/pypy/lang/js/test/test_interp.py
Log:
only 3 tests failling now.
Modified: pypy/dist/pypy/lang/js/astgen.py
==============================================================================
--- pypy/dist/pypy/lang/js/astgen.py (original)
+++ pypy/dist/pypy/lang/js/astgen.py Wed Dec 20 15:19:05 2006
@@ -60,6 +60,8 @@
def __init__(self, name, initialiser=None):
self.name = name
self.initialiser = initialiser
+ def __str__(self):
+ return "<id %s init: %s>"%(str(self.name), str(self.initialiser))
class If(Node):
def __init__(self, condition, thenPart=None, elsePart=None):
@@ -96,6 +98,9 @@
def __init__(self, name, value):
self.name = name
self.value = value
+
+ def __repr__(self):
+ return "<%s : %s>"%(str(self.name), str(self.value))
class Return(Node):
def __init__(self, expr):
Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py (original)
+++ pypy/dist/pypy/lang/js/interpreter.py Wed Dec 20 15:19:05 2006
@@ -34,7 +34,7 @@
def run(self):
"""run the interpreter"""
- self.script.call(self.global_context)
+ return self.script.call(self.global_context)
@@ -67,6 +67,7 @@
writer(",".join([i.GetValue().ToString() for i in self.arglist.call(ctx)]))
else:
w_obj = ctx.resolve_identifier(name).GetValue()
+ print "arglist = ", self.arglist
retval = w_obj.Call(ctx=ctx, args=[i for i in self.arglist.call(ctx)])
return retval
@@ -176,6 +177,7 @@
class __extend__(List):
def call(self, ctx):
+ print "nodes = ", self.nodes
return [node.call(ctx) for node in self.nodes]
class __extend__(New):
@@ -194,14 +196,15 @@
return W_Number(self.num)
def get_literal(self):
- # XXX Think about a shortcut later
- return str(W_Number(self.num))
+ return W_Number(self.num).ToString()
class __extend__(ObjectInit):
def call(self, ctx):
w_obj = W_Object()
+ print "properties = ", self.properties
for property in self.properties:
name = property.name.get_literal()
+ print "prop name = ", name
w_expr = property.value.call(ctx).GetValue()
w_obj.Put(name, w_expr)
return w_obj
@@ -246,7 +249,7 @@
return W_String(self.strval)
def get_literal(self):
- return self.strval
+ return W_String(self.strval).ToString()
class __extend__(Return):
def call(self, ctx):
@@ -263,10 +266,12 @@
tryresult = self.tryblock.call(ctx)
except ThrowException, excpt:
e = excpt
- nctx = ExecutionContext(ctx)
- nctx.assign(self.catchparam, e.exception)
if self.catchblock is not None:
- tryresult = self.catchblock.call(nctx)
+ obj = W_Object()
+ obj.Put(self.catchparam, e.exception)
+ ctx.push_object(obj)
+ tryresult = self.catchblock.call(ctx)
+ ctx.pop_object()
if self.finallyblock is not None:
tryresult = self.finallyblock.call(ctx)
Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py (original)
+++ pypy/dist/pypy/lang/js/jsobj.py Wed Dec 20 15:19:05 2006
@@ -41,6 +41,11 @@
def ToNumber(self):
return NaN
+ def get_literal(self):
+ return self.ToString()
+
+ __str__ = get_literal
+
def __repr__(self):
return "<%s(%s)>" % (self.__class__.__name__, self.ToString())
@@ -64,6 +69,8 @@
return W_Object()
def Get(self, P):
+ if not isinstance(P, str):
+ P = P.ToString()
if P in self.propdict: return self.propdict[P].value
if self.Prototype is None: return w_Undefined
return self.Prototype.Get(P) # go down the prototype chain
@@ -76,6 +83,8 @@
return self.Prototype.CanPut(P)
def Put(self, P, V):
+ if not isinstance(P, str):
+ P = P.ToString()
if not self.CanPut(P): return
if P in self.propdict:
self.propdict[P].value = V
@@ -118,9 +127,16 @@
def ToString(self):
return "[object %s]"%(self.Class,)
+ def __str__(self):
+ return "<Object class: %s\nproperties: %s\nPrototype: %s>"%(self.Class,
+ self.propdict, self.Prototype)
+
class W_Arguments(W_Object):
def __init__(self, callee, args):
W_Object.__init__(self)
+ self.Class = "arguments"
+ self.propdict.pop("toString")
+ self.propdict.pop("prototype")
self.Put('callee', callee)
self.Put('length', len(args))
for i, arg in enumerate(args):
@@ -130,6 +146,7 @@
"""The object used on function calls to hold arguments and this"""
def __init__(self):
W_Object.__init__(self)
+ self.Class = "Activation"
self.propdict.pop("toString")
self.propdict.pop("prototype")
@@ -143,20 +160,22 @@
self.scope = ctx.scope[:]
def Call(self, ctx, args=[], this=None):
- print args
+ print "* start of function call"
+ print " args = ", args
act = ActivationObject()
- for i, arg in enumerate(args):
+ for i, arg in enumerate(self.function.params):
try:
value = args[i]
except IndexError:
value = w_Undefined
act.Put(self.function.params[i], value)
act.Put('this', this)
- print act.propdict
+ print " act.propdict = ", act.propdict
w_Arguments = W_Arguments(self, args)
act.Put('arguments', w_Arguments)
newctx = function_context(self.scope, act, this)
val = self.function.body.call(ctx=newctx)
+ print "* end of function call return = ", val
return val
class W_Undefined(W_Root):
@@ -207,7 +226,7 @@
class W_Number(W_Primitive):
def __init__(self, floatval):
- print "novo numero"
+ print "w_number = ", floatval
self.floatval = floatval
def ToString(self):
@@ -248,6 +267,9 @@
def ToBoolean(self):
return bool(self.list_w)
+
+ def __str__(self):
+ return str(self.list_w)
w_Undefined = W_Undefined()
w_Null = W_Null()
Modified: pypy/dist/pypy/lang/js/reference.py
==============================================================================
--- pypy/dist/pypy/lang/js/reference.py (original)
+++ pypy/dist/pypy/lang/js/reference.py Wed Dec 20 15:19:05 2006
@@ -2,20 +2,26 @@
class Reference(object):
"""Reference Type"""
- def __init__(self, propertyname, baseobject=None):
- self.baseobject = baseobject
- self.propertyname = propertyname
+ def __init__(self, property_name, base=None):
+ self.base = base
+ self.property_name = property_name
def GetValue(self):
- if self.baseobject is None:
+ if self.base is None:
raise ReferenceError
- return self.baseobject.Get(self.propertyname)
+ return self.base.Get(self.property_name)
def PutValue(self, w, ctx):
- base = self.baseobject
- if self.baseobject is None:
+ base = self.base
+ if self.base is None:
base = ctx.scope[-1]
- base.Put(self.propertyname, w)
+ base.Put(self.property_name, w)
+
+ def GetBase(self):
+ return self.base
+
+ def GetPropertyName(self):
+ return self.property_name
def __str__(self):
- return str(self.baseobject) + " : " + str(self.propertyname)
\ No newline at end of file
+ return "< " + str(self.base) + " -> " + str(self.property_name) + " >"
\ No newline at end of file
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 Wed Dec 20 15:19:05 2006
@@ -41,7 +41,8 @@
assert l == assval
def assert_result(self, code, result):
- r = code.call(ExecutionContext())
+ inter = interpreter.Interpreter(code)
+ r = inter.run()
assert r.ToString() == result.ToString()
def test_interp_parse(self):
More information about the Pypy-commit
mailing list