[pypy-svn] r33983 - in pypy/dist/pypy/lang/js: . test
fijal at codespeak.net
fijal at codespeak.net
Tue Oct 31 19:39:42 CET 2006
Author: fijal
Date: Tue Oct 31 19:39:40 2006
New Revision: 33983
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/test/test_interp.py
Log:
(santagada, fijal, guido) - Nested scopes.
Modified: pypy/dist/pypy/lang/js/astgen.py
==============================================================================
--- pypy/dist/pypy/lang/js/astgen.py (original)
+++ pypy/dist/pypy/lang/js/astgen.py Tue Oct 31 19:39:40 2006
@@ -36,7 +36,7 @@
self.params = params
self.body = body
self.scope = scope
- w_obj = W_Object({}, body=self)
+ #w_obj = W_Object({}, function=self)
#self.scope = Scope(copy(scope.dict))
class Identifier(Node):
Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py (original)
+++ pypy/dist/pypy/lang/js/interpreter.py Tue Oct 31 19:39:40 2006
@@ -31,13 +31,14 @@
name = self.right.get_literal()
return w_obj.Get(name)
-class __extend__(Function):
- def call(self, context=None):
- backup_scope = scope_manager.current_scope
- scope_manager.current_scope = self.scope
- retval = self.body.call()
- scope_manager.current_scope = backup_scope
- return retval
+#class __extend__(Function):
+# def call(self, context=None):
+# #import pdb;pdb.set_trace()
+# #backup_scope = scope_manager.current_scope
+# #scope_manager.current_scope = self.scope
+# retval = self.body.call()
+# #scope_manager.current_scope = backup_scope
+# return retval
class __extend__(Plus):
def call(self, context=None):
@@ -86,8 +87,18 @@
if name == 'print':
writer(",".join([i.ToString() for i in self.arglist.call(context)]))
else:
+ # #import pdb;pdb.set_trace()
+
+# #
+# retval = self.body.call()
+# #scope_manager.current_scope = backup_scope
+# return retval
+ backup_scope = scope_manager.current_scope
w_obj = scope_manager.get_variable(name)
- return w_obj.Call()
+ scope_manager.current_scope = w_obj.function.scope
+ retval = w_obj.Call()
+ scope_manager.current_scope = backup_scope
+ return retval
class __extend__(List):
def call(self, context=None):
@@ -122,9 +133,8 @@
class __extend__(Function):
def call(self, context=None):
- w_obj = W_Object({})
- w_obj.body = self.body
- return w_obj
+ w_obj = W_Object({}, function=self)
+ return w_obj
class __extend__(Return):
def call(self, context=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 Oct 31 19:39:40 2006
@@ -80,17 +80,19 @@
raise NotImplementedError("W_Reference.GetValue")
class W_Object(W_Root):
- def __init__(self, dict_w, body=None):
+ def __init__(self, dict_w, function=None):
# string --> W_Root
self.dict_w = dict_w
# XXX: more stuff
self.dict_w['toString'] = W_Builtin({}, self.w_string)
- self.body = body
+ # XXX A bit hairy here, we store here a Function, and Script
+ # is a self.function.body
+ self.function = function
#self.class_ = None
def Call(self, this=None):
- if self.body:
- return self.body.call()
+ if self.function:
+ return self.function.body.call()
else:
raise SeePage(33)
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 Oct 31 19:39:40 2006
@@ -62,3 +62,17 @@
def test_var_declartion(self):
self.assert_prints(parse_d('var x = 3; print(x+x);'), ["6"])
+
+ def test_var_scoping(self):
+ self.assert_prints(parse_d("""
+ var y;
+ var p;
+ p = 0;
+ x = function() {
+ var p;
+ p = 1;
+ y = 3; return y + z;
+ };
+ var z = 2;
+ print(x(), y, p);
+ """), ["5,3,0"])
More information about the Pypy-commit
mailing list