Author: Stephan <[email protected]>
Branch:
Changeset: r119:63a82deba87a
Date: 2011-09-05 13:58 +0200
http://bitbucket.org/pypy/lang-js/changeset/63a82deba87a/
Log: use Map when building AST scopes
diff --git a/js/astbuilder.py b/js/astbuilder.py
--- a/js/astbuilder.py
+++ b/js/astbuilder.py
@@ -3,30 +3,34 @@
from pypy.rlib.parsing.parsing import ParseError
from js import operations
+from js.utils import Map
class Scope(object):
def __init__(self):
- self.local_variables = []
+ self.local_variables = Map()
self.declared_variables = []
def __repr__(self):
return 'Scope ' + repr(self.local_variables)
def add_local(self, identifier):
- if not self.is_local(identifier) == True:
- self.local_variables.append(identifier)
+ if not self.is_local(identifier):
+ self.local_variables.addname(identifier)
def declare_local(self, identifier):
- if not self.is_local(identifier) == True:
+ if not self.is_local(identifier):
self.add_local(identifier)
if not identifier in self.declared_variables:
self.declared_variables.append(identifier)
def is_local(self, identifier):
- return identifier in self.local_variables
+ return self.local_variables.indexof(identifier) !=
self.local_variables.NOT_FOUND
def get_local(self, identifier):
- return self.local_variables.index(identifier)
+ idx = self.local_variables.indexof(identifier)
+ if idx == self.local_variables.NOT_FOUND:
+ raise ValueError
+ return idx
class Scopes(object):
def __init__(self):
diff --git a/js/jscode.py b/js/jscode.py
--- a/js/jscode.py
+++ b/js/jscode.py
@@ -29,6 +29,8 @@
self.startlooplabel = []
self.endlooplabel = []
self.updatelooplabel = []
+ from js.astbuilder import Scope
+ self.scope = Scope()
def emit_label(self, num = -1):
if num == -1:
@@ -110,7 +112,9 @@
if self.has_labels:
self.remove_labels()
- return JsFunction(name, params, self.opcodes[:])
+ #import pdb; pdb.set_trace()
+ return JsFunction(name, params, self)
+ #return JsFunction(name, params, self.opcodes[:])
def remove_labels(self):
""" Basic optimization to remove all labels and change
@@ -157,7 +161,9 @@
from pypy.rlib.debug import make_sure_not_resized
self.name = name
self.params = params
- self.opcodes = make_sure_not_resized(code)
+ self.code = code
+ self.opcodes = make_sure_not_resized(code.opcodes[:])
+ self.scope = code.scope
def run(self, ctx, check_stack=True):
state = _save_stack(ctx, len(self.opcodes) * 2)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit