[pypy-commit] lang-js default: * initialize stack with required size for functions

stepahn noreply at buildbot.pypy.org
Fri Dec 28 11:32:54 CET 2012


Author: Stephan <stephan at stzal.com>
Branch: 
Changeset: r156:72c1633b1238
Date: 2011-11-09 14:02 +0100
http://bitbucket.org/pypy/lang-js/changeset/72c1633b1238/

Log:	* initialize stack with required size for functions
	* mark local_variables map as immutable

diff --git a/js/astbuilder.py b/js/astbuilder.py
--- a/js/astbuilder.py
+++ b/js/astbuilder.py
@@ -9,6 +9,7 @@
     return ROOT_MAP
 
 class Scope(object):
+    _immutable_fields_ = ['local_variables']
     def __init__(self):
         self.local_variables = ROOT_MAP
         self.declared_variables = []
diff --git a/js/jscode.py b/js/jscode.py
--- a/js/jscode.py
+++ b/js/jscode.py
@@ -167,7 +167,7 @@
     ctx.stack = old_stack
 
 class JsFunction(object):
-    _immutable_fields_ = ["opcodes[*]"]
+    _immutable_fields_ = ["opcodes[*]", 'name', 'params', 'code', 'scope']
 
     def __init__(self, name, params, code):
         from pypy.rlib.debug import make_sure_not_resized
@@ -180,6 +180,10 @@
     def estimated_stack_size(self):
         return self.code.estimated_stack_size()
 
+    def local_variables(self):
+        if self.scope:
+            return self.scope.local_variables
+
     def run(self, ctx, check_stack=True, save_stack=True):
         state = ([], 0)
         if save_stack:
diff --git a/js/jsexecution_context.py b/js/jsexecution_context.py
--- a/js/jsexecution_context.py
+++ b/js/jsexecution_context.py
@@ -143,19 +143,20 @@
         self._map_dict_delete(name)
         return True
 
-    def _init_execution_context(self, parent):
+    def _init_execution_context(self, parent, stack_size=1):
         self = jit.hint(self, access_directly=True, fresh_virtualizable=True)
         self._init_map_dict(0)
         self.parent = parent
         self.ctx_obj = None
-        self._init_stack()
+        self._init_stack(stack_size)
         self._variables_map = root_map()
 
     def _init_function_context(self, parent, func):
         self = jit.hint(self, access_directly=True, fresh_virtualizable=True)
-        self._init_execution_context(parent)
-        if func.scope:
-            self._init_map_dict_with_map(func.scope.local_variables)
+        self._init_execution_context(parent, func.estimated_stack_size())
+        local_variables = func.local_variables()
+        if local_variables is not None:
+            self._init_map_dict_with_map(local_variables)
 
     def _init_acitvation_context(self, parent, this, args):
         self = jit.hint(self, access_directly=True, fresh_virtualizable=True)


More information about the pypy-commit mailing list