[pypy-commit] lang-js default: static sisze of slots in declarative environment record

stepahn noreply at buildbot.pypy.org
Fri Dec 28 11:35:16 CET 2012


Author: Stephan <stephan at stzal.com>
Branch: 
Changeset: r295:3c974365c7f1
Date: 2012-09-04 15:44 +0200
http://bitbucket.org/pypy/lang-js/changeset/3c974365c7f1/

Log:	static sisze of slots in declarative environment record

diff --git a/js/astbuilder.py b/js/astbuilder.py
--- a/js/astbuilder.py
+++ b/js/astbuilder.py
@@ -53,6 +53,9 @@
             if idx == index:
                 return symbol
 
+    def len(self):
+        return self.next_index
+
 empty_symbols = SymbolMap()
 
 
diff --git a/js/environment_record.py b/js/environment_record.py
--- a/js/environment_record.py
+++ b/js/environment_record.py
@@ -30,10 +30,11 @@
 
 
 class DeclarativeEnvironmentRecord(EnvironmentRecord):
-    def __init__(self):
+    def __init__(self, size=0, resize=True):
         EnvironmentRecord.__init__(self)
         self._binding_map_ = _new_map()
-        self._binding_slots_ = []
+        self._binding_slots_ = [None] * size
+        self._binding_resize_ = resize
         self._mutable_bindings_map_ = _new_map()
         self._deletable_bindings_map_ = _new_map()
 
@@ -55,27 +56,26 @@
 
     def _get_binding(self, name):
         idx = self._binding_map_.lookup(name)
-
-        if self._binding_map_.not_found(idx):
-            return
-        if idx >= len(self._binding_slots_):
-            return
-
         binding = self._binding_slots_[idx]
         return binding
 
-    def _set_binding(self, name, value):
+    def _add_binding(self, name, value):
         idx = self._binding_map_.lookup(name)
 
         if self._binding_map_.not_found(idx):
             self._binding_map_ = self._binding_map_.add(name)
             idx = self._binding_map_.index
 
-        if idx >= len(self._binding_slots_):
-            self._binding_slots_ += ([None] * (1 + idx - len(self._binding_slots_)))
+        if self._binding_resize_ is True:
+            if idx >= len(self._binding_slots_):
+                self._binding_slots_ += ([None] * (1 + idx - len(self._binding_slots_)))
 
         self._binding_slots_[idx] = value
 
+    def _set_binding(self, name, value):
+        idx = self._binding_map_.lookup(name)
+        self._binding_slots_[idx] = value
+
     def _del_binding(self, name):
         idx = self._binding_map_.lookup(name)
 
@@ -88,7 +88,7 @@
     # 10.2.1.1.2
     def create_mutuable_binding(self, identifier, deletable):
         assert not self.has_binding(identifier)
-        self._set_binding(identifier, w_Undefined)
+        self._add_binding(identifier, w_Undefined)
         self._set_mutable_binding(identifier)
         if deletable:
             self._set_deletable_binding(identifier)
diff --git a/js/execution_context.py b/js/execution_context.py
--- a/js/execution_context.py
+++ b/js/execution_context.py
@@ -164,6 +164,7 @@
         from js.object_space import object_space
 
         stack_size = code.estimated_stack_size()
+        env_size = code.env_size()
 
         ExecutionContext.__init__(self, stack_size)
 
@@ -177,7 +178,7 @@
         self._calling_context_ = None
 
         from js.lexical_environment import DeclarativeEnvironment
-        localEnv = DeclarativeEnvironment(scope)
+        localEnv = DeclarativeEnvironment(scope, env_size, False)
         self._lexical_environment_ = localEnv
         self._variable_environment_ = localEnv
 
diff --git a/js/functions.py b/js/functions.py
--- a/js/functions.py
+++ b/js/functions.py
@@ -43,6 +43,9 @@
     def is_function_code(self):
         return False
 
+    def env_size(self):
+        return 0
+
 
 class JsNativeFunction(JsBaseFunction):
     def __init__(self, function, name=u''):
@@ -88,10 +91,14 @@
         assert isinstance(js_code, JsCode)
         self._js_code_ = js_code
         self._stack_size_ = js_code.estimated_stack_size()
+        self._symbol_size_ = js_code.symbol_size()
 
     def estimated_stack_size(self):
         return self._stack_size_
 
+    def env_size(self):
+        return self._symbol_size_
+
     def get_js_code(self):
         from js.jscode import JsCode
         assert isinstance(self._js_code_, JsCode)
diff --git a/js/jscode.py b/js/jscode.py
--- a/js/jscode.py
+++ b/js/jscode.py
@@ -76,6 +76,9 @@
 
         return self._estimated_stack_size
 
+    def symbol_size(self):
+        return self._symbols.len()
+
     def emit_label(self, num=-1):
         if num == -1:
             num = self.prealocate_label()
diff --git a/js/lexical_environment.py b/js/lexical_environment.py
--- a/js/lexical_environment.py
+++ b/js/lexical_environment.py
@@ -26,10 +26,10 @@
 
 
 class DeclarativeEnvironment(LexicalEnvironment):
-    def __init__(self, outer_environment=None):
+    def __init__(self, outer_environment=None, env_size=0, env_resize=True):
         LexicalEnvironment.__init__(self, outer_environment)
         from js.environment_record import DeclarativeEnvironmentRecord
-        self.environment_record = DeclarativeEnvironmentRecord()
+        self.environment_record = DeclarativeEnvironmentRecord(env_size, env_resize)
 
 
 class ObjectEnvironment(LexicalEnvironment):


More information about the pypy-commit mailing list