[pypy-svn] r34202 - in pypy/dist/pypy/lang/js: . js test
santagada at codespeak.net
santagada at codespeak.net
Sat Nov 4 18:19:07 CET 2006
Author: santagada
Date: Sat Nov 4 18:19:02 2006
New Revision: 34202
Modified:
pypy/dist/pypy/lang/js/astgen.py
pypy/dist/pypy/lang/js/context.py
pypy/dist/pypy/lang/js/interpreter.py
pypy/dist/pypy/lang/js/js/jsparse.js
pypy/dist/pypy/lang/js/test/test_interp.py
Log:
(santagada) almost everything is working... except prototypes
Modified: pypy/dist/pypy/lang/js/astgen.py
==============================================================================
--- pypy/dist/pypy/lang/js/astgen.py (original)
+++ pypy/dist/pypy/lang/js/astgen.py Sat Nov 4 18:19:02 2006
@@ -107,6 +107,7 @@
class Script(Node):
def __init__(self, nodes, var_decl, func_decl):
self.nodes = nodes
+ [scope_manager.add_variable(id.name, w_Undefined) for id in var_decl]
self.var_decl = var_decl
self.func_decl = func_decl
@@ -139,7 +140,7 @@
class Vars(Node):
def __init__(self, nodes):
self.nodes = nodes
- [scope_manager.add_variable(id.name, w_Undefined) for id in nodes]
+ #[scope_manager.add_variable(id.name, w_Undefined) for id in nodes]
class While(Node):
def __init__(self, condition, body):
@@ -218,8 +219,12 @@
elif tp == 'RETURN':
return Return(from_dict(d['value']))
elif tp == 'SCRIPT':
- # XXX: Cannot parse it right now
- return Script(getlist(d), [], [])
+ # TODO: get function names
+ if isinstance(d['varDecls'], dict):
+ var_decl = [from_dict(d['varDecls']),]
+ else:
+ var_decl = [from_dict(x) for x in d['varDecls']]
+ return Script(getlist(d), var_decl, [])
elif tp == 'SEMICOLON':
return Semicolon(from_dict(d['expression']))
elif tp == 'STRING':
Modified: pypy/dist/pypy/lang/js/context.py
==============================================================================
--- pypy/dist/pypy/lang/js/context.py (original)
+++ pypy/dist/pypy/lang/js/context.py Sat Nov 4 18:19:02 2006
@@ -8,11 +8,12 @@
self.globals = {}
else:
self.globals = parent.globals
- #self.locals = {}
def assign(self, name, value):
- self.locals[name] = value
- #self.globals[name] = value
+ if (name not in self.locals) and (name in self.globals):
+ self.globals[name] = value
+ else:
+ self.locals[name] = value
def access(self, name):
if name in self.locals:
Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py (original)
+++ pypy/dist/pypy/lang/js/interpreter.py Sat Nov 4 18:19:02 2006
@@ -25,7 +25,10 @@
class __extend__(Assign):
def call(self, context):
+ #print context.locals.keys(), "|||||", context.globals
+ #print context.globals['z']
val = self.expr.call(context)
+ print val
self.identifier.put(context,val)
class __extend__(Block):
@@ -79,14 +82,14 @@
class __extend__(Function):
- def call(self, context=None):
+ def call(self, context):
w_obj = W_Object({}, function=self)
return w_obj
class __extend__(Identifier):
- def call(self, context=None):
+ def call(self, context):
if self.initialiser is not None:
- scope_manager.set_variable(self.name, self.initialiser.call(context))
+ context.assign(self.name, self.initialiser.call(context))
try:
return context.access(self.name)
except NameError:
@@ -197,7 +200,7 @@
return W_Number(num_left + num_right)
class __extend__(Script):
- def call(self, context=None, args=(), params=[]):
+ def call(self, context=None, args=(), params=[], first = False):
ncontext = ExecutionContext(context)
for i, item in enumerate(params):
try:
@@ -205,6 +208,12 @@
except IndexError:
temp = w_Undefined
ncontext.assign(item, temp)
+
+ for var in self.var_decl:
+ if first:
+ ncontext.globals[var.name] = w_Undefined
+ else:
+ ncontext.locals[var.name] = w_Undefined
w_Arguments = W_Arguments(dict([(str(x),y) for x,y in enumerate(args)]))
ncontext.assign('arguments', w_Arguments)
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 Sat Nov 4 18:19:02 2006
@@ -284,9 +284,9 @@
var s = "{\n" + INDENTATION.repeat(n) + "'type': '" + tokenstr(this.type) + "'";
for (i = 0; i < a.length; i++) {
val = a[i].value + "";
- if (val.search("\\},\\{") != -1) {
+ if ((val.search("\\},\\{") != -1 )) {
s += ",\n" + INDENTATION.repeat(n) + "'" + a[i].id + "': [" + val + "]";
- } else {
+ } else {
if (val.search("\n") != -1) {
s += ",\n" + INDENTATION.repeat(n) + "'" + a[i].id + "': " + val + " ";
} else {
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 Sat Nov 4 18:19:02 2006
@@ -30,7 +30,7 @@
ctx = ExecutionContext()
ctx.globals['Object'] = W_Object({})
try:
- code.call(ctx)
+ code.call(ctx, first = True)
except ThrowException, excpt:
l.append("uncaught exception: "+str(excpt.exception))
assert l == assval
@@ -227,4 +227,8 @@
print(o.info);
"""), ["hello"])
+ def test_vars(self):
+ self.assert_prints(parse_d("""
+ var x;x=3; print(x)"""), ["3"])
+
More information about the Pypy-commit
mailing list