[pypy-svn] r36812 - in pypy/dist/pypy/lang/js: . js test
santagada at codespeak.net
santagada at codespeak.net
Tue Jan 16 16:16:59 CET 2007
Author: santagada
Date: Tue Jan 16 16:16:56 2007
New Revision: 36812
Modified:
pypy/dist/pypy/lang/js/interpreter.py
pypy/dist/pypy/lang/js/js/jsparse.js
pypy/dist/pypy/lang/js/js_interactive.py
pypy/dist/pypy/lang/js/jsobj.py
pypy/dist/pypy/lang/js/jsparser.py
pypy/dist/pypy/lang/js/test/test_interp.py
Log:
(santagada, antonio)some corrections with antonio on the train and on the plane
Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py (original)
+++ pypy/dist/pypy/lang/js/interpreter.py Tue Jan 16 16:16:56 2007
@@ -80,7 +80,13 @@
def isnanjs(ctx, args, this):
return W_Boolean(args[0].ToNumber() == NaN)
+
+def booleanjs(ctx, args, this):
+ if len(args) > 0:
+ return W_Boolean(args[0].ToBoolean())
+ return W_Boolean(False)
+
class Interpreter(object):
"""Creates a js interpreter"""
def __init__(self):
@@ -116,6 +122,7 @@
w_Global.Put('eval', W_Builtin(evaljs))
w_Global.Put('print', W_Builtin(printjs))
w_Global.Put('isNaN', W_Builtin(isnanjs))
+ w_Global.Put('Boolean', W_Builtin(booleanjs, Class="Boolean"))
w_Global.Put('NaN', W_Number(NaN))
w_Global.Put('Infinity', W_Number(Infinity))
@@ -210,6 +217,9 @@
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
@@ -442,7 +452,10 @@
raise TypeError()
args = self.arglist.eval(ctx).get_args()
return x.Construct(ctx=ctx, args=args)
-
+
+class Null(Expression):
+ def eval(self, ctx):
+ return w_Null
class Number(Expression):
def __init__(self, num):
@@ -526,7 +539,7 @@
return e.value
else:
print "exeception in line: %s, %s - %s"%(node.lineno, node.value, self)
- raise e
+ raise
class Semicolon(Statement):
def __init__(self, expr = None):
@@ -601,7 +614,14 @@
self.op = op
def eval(self, ctx):
- return W_String(self.op.eval(ctx).GetValue().type())
+ 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):
@@ -615,6 +635,14 @@
for var in self.nodes:
var.execute(ctx)
+class Void(Expression):
+ def __init__(self, expr):
+ self.expr = expr
+
+ def eval(self, ctx):
+ self.expr.eval(ctx)
+ return w_Undefined
+
class While(Statement):
def __init__(self, condition, body):
self.condition = condition
@@ -778,6 +806,8 @@
node = New(from_tree(gettreeitem(t, '0')))
elif tp == 'NEW_WITH_ARGS':
node = NewWithArgs(from_tree(gettreeitem(t, '0')), from_tree(gettreeitem(t, '1')))
+ elif tp == 'NULL':
+ node = Null()
elif tp == 'NUMBER':
node = Number(float(gettreeitem(t, 'value').additional_info))
elif tp == 'OBJECT_INIT':
@@ -845,6 +875,8 @@
node = Typeof(from_tree(gettreeitem(t, '0')))
elif tp == 'VAR':
node = Vars(getlist(t))
+ elif tp == 'VOID':
+ node = Void(from_tree(gettreeitem(t, '0')))
elif tp == 'WHILE':
body = from_tree(gettreeitem(t, 'body'))
condition = from_tree(gettreeitem(t, 'condition'))
@@ -858,7 +890,7 @@
elif tp == 'UNARY_MINUS':
node = UMinus(from_tree(gettreeitem(t, '0')))
else:
- raise NotImplementedError("Dont know how to handler %s" % tp)
+ raise NotImplementedError("Dont know how to handle %s" % tp)
if tp == 'SCRIPT':
start = 0
Modified: pypy/dist/pypy/lang/js/js/jsparse.js
==============================================================================
--- pypy/dist/pypy/lang/js/js/jsparse.js (original)
+++ pypy/dist/pypy/lang/js/js/jsparse.js Tue Jan 16 16:16:56 2007
@@ -295,7 +295,12 @@
continue
}
}
- val = a[i].value + "";
+
+ if(typeof a[i].value == 'string'){
+ val = a[i].value.replace(/'/g, "\\'")
+ } else {
+ val = a[i].value+ "";
+ }
if ((val.search("\n"+INDENTATION.repeat(n)+"\\},\\{") != -1 )) {
s += ",\n" + INDENTATION.repeat(n) + "'" + a[i].id + "': [" + val + "]";
} else {
Modified: pypy/dist/pypy/lang/js/js_interactive.py
==============================================================================
--- pypy/dist/pypy/lang/js/js_interactive.py (original)
+++ pypy/dist/pypy/lang/js/js_interactive.py Tue Jan 16 16:16:56 2007
@@ -55,15 +55,11 @@
sys.exit(0)
return "this should not be printed"
- quitbi = W_Builtin()
- quitbi.set_builtin_call(quiter)
- loadbi = W_Builtin()
- loadbi.set_builtin_call(loadjs)
- interp.w_Global.Put('quit', quitbi)
- interp.w_Global.Put('load', loadbi)
+ interp.w_Global.Put('quit', W_Builtin(quiter))
+ interp.w_Global.Put('load', W_Builtin(loadjs))
for filename in filenames:
loadjs(interp.global_context, [W_String(filename)], None)
-
+
while 1:
res = interp.run(load_source(raw_input("pypy-js> ")))
if res is not None:
Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py (original)
+++ pypy/dist/pypy/lang/js/jsobj.py Tue Jan 16 16:16:56 2007
@@ -140,6 +140,7 @@
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)
Modified: pypy/dist/pypy/lang/js/jsparser.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsparser.py (original)
+++ pypy/dist/pypy/lang/js/jsparser.py Tue Jan 16 16:16:56 2007
@@ -52,8 +52,8 @@
unquote(tree)
return tree
-regexs, rules, ToAST = parse_ebnf("""
- QUOTED_STRING: "'[^\\']*'";
+regexs, rules, ToAST = parse_ebnf(r"""
+ QUOTED_STRING: "'([^\']|\\\')*'";"""+"""
IGNORE: " |\n";
data: <dict> | <QUOTED_STRING> | <list>;
dict: ["{"] (dictentry [","])* dictentry ["}"];
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 Tue Jan 16 16:16:56 2007
@@ -378,6 +378,7 @@
print(y)""", ["5"])
def test_math_stuff(self):
+ py.test.skip('not ready yet')
self.assert_prints("""
var x = 5;
var z = 2;
@@ -400,4 +401,20 @@
""", ['NaN', 'inf', 'undefined'])
def test_strangefunc(self):
- self.assert_prints("""function f1() { var z; var t;}""", [])
\ No newline at end of file
+ self.assert_prints("""function f1() { var z; var t;}""", [])
+ self.assert_prints(""" "'t'" """, [])
+
+ def test_null(self):
+ self.assert_result("null", w_Null)
+
+ def test_void(self):
+ self.assert_prints("print(void print('hello'))",
+ ["hello", "undefined"])
+
+ def test_activationprob(self):
+ self.assert_prints( """
+ function x (actual){
+ print(typeof actual)
+ }
+ x(true)
+ """, ['boolean'])
More information about the Pypy-commit
mailing list