Author: Stephan <step...@stzal.com>
Branch: 
Changeset: r294:eed924e44c28
Date: 2012-09-04 15:40 +0200
http://bitbucket.org/pypy/lang-js/changeset/eed924e44c28/

Log:    static stack size

diff --git a/js/execution_context.py b/js/execution_context.py
--- a/js/execution_context.py
+++ b/js/execution_context.py
@@ -3,11 +3,12 @@
 
 
 class ExecutionContext(StackMixin):
-    def __init__(self):
+    _immutable_fields_ = ['_stack_', '_stack_resize_', '_this_binding_', 
'_lexical_environment_', '_variable_environment_']
+    def __init__(self, stack_size=1):
         self._lexical_environment_ = None
         self._variable_environment_ = None
         self._this_binding_ = None
-        self._init_stack_()
+        self._init_stack_(size=stack_size, resize=False)
 
     def stack_append(self, value):
         self._stack_append(value)
@@ -117,8 +118,11 @@
         return ref
 
 class GlobalExecutionContext(ExecutionContext):
-        ExecutionContext.__init__(self)
     def __init__(self, code, global_object, strict=False):
+        stack_size = code.estimated_stack_size()
+
+        ExecutionContext.__init__(self, stack_size)
+
         self._code_ = code
         self._strict_ = strict
 
@@ -132,8 +136,10 @@
 
 
 class EvalExecutionContext(ExecutionContext):
-        ExecutionContext.__init__(self)
     def __init__(self, code, calling_context=None):
+        stack_size = code.estimated_stack_size()
+
+        ExecutionContext.__init__(self, stack_size)
         self._code_ = code
         self._strict_ = code.strict
 
@@ -153,8 +159,14 @@
 
 
 class FunctionExecutionContext(ExecutionContext):
-        ExecutionContext.__init__(self)
     def __init__(self, code, formal_parameters=[], argv=[], this=w_Undefined, 
strict=False, scope=None, w_func=None):
+        from js.jsobj import isnull_or_undefined, W_BasicObject
+        from js.object_space import object_space
+
+        stack_size = code.estimated_stack_size()
+
+        ExecutionContext.__init__(self, stack_size)
+
         self._code_ = code
         self._formal_parameters_ = formal_parameters
         self._argument_values_ = argv
diff --git a/js/functions.py b/js/functions.py
--- a/js/functions.py
+++ b/js/functions.py
@@ -87,10 +87,10 @@
         from js.jscode import JsCode
         assert isinstance(js_code, JsCode)
         self._js_code_ = js_code
-        #self.stack_size = js_code.estimated_stack_size()
+        self._stack_size_ = js_code.estimated_stack_size()
 
-    #def estimated_stack_size(self):
-        #return self.stack_size
+    def estimated_stack_size(self):
+        return self._stack_size_
 
     def get_js_code(self):
         from js.jscode import JsCode
diff --git a/js/utils.py b/js/utils.py
--- a/js/utils.py
+++ b/js/utils.py
@@ -1,6 +1,6 @@
 # encoding: utf-8
 #from pypy.rlib.jit import hint
-#from pypy.rlib import jit, debug
+from pypy.rlib import jit  # , debug
 
 
 class StackMixin(object):
@@ -14,22 +14,25 @@
         self._stack_pointer_ = 0
         self._stack_resize_ = resize
 
+    def _stack_pointer(self):
+        return jit.promote(self._stack_pointer_)
+
     def _stack_pop(self):
         e = self._stack_top()
-        i = self._stack_pointer_ - 1
+        i = self._stack_pointer() - 1
         assert i >= 0
         self._stack_[i] = None
         self._stack_pointer_ = i
         return e
 
     def _stack_top(self):
-        i = self._stack_pointer_ - 1
+        i = self._stack_pointer() - 1
         if i < 0:
             raise IndexError
         return self._stack_[i]
 
     def _stack_append(self, element):
-        i = self._stack_pointer_
+        i = self._stack_pointer()
         assert i >= 0
         if len(self._stack_) <= i and self._stack_resize_ is True:
             self._stack_ += [None]
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to