[pypy-svn] r19964 - in pypy/dist/pypy/translator/js: . src

ericvrp at codespeak.net ericvrp at codespeak.net
Thu Nov 17 10:14:40 CET 2005


Author: ericvrp
Date: Thu Nov 17 10:14:39 2005
New Revision: 19964

Modified:
   pypy/dist/pypy/translator/js/codewriter.py
   pypy/dist/pypy/translator/js/src/ll_stackless.js
Log:
intermediatte checkin


Modified: pypy/dist/pypy/translator/js/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/codewriter.py	(original)
+++ pypy/dist/pypy/translator/js/codewriter.py	Thu Nov 17 10:14:39 2005
@@ -145,17 +145,22 @@
         if self.js.stackless:   #save&restore all local variable for now
             self.openblock(self._savehandler_blocknum)
             self.comment('save block for stackless feature')
-            self.append('slp_frame_stack_top = new Array(slp_resume_block, %s)' % ', '.join(self._usedvars.keys()))
-            self.append('return undefined')
+            usedvars = ', '.join(self._usedvars.keys())
+            self.append('slp_frame_stack_bottom.f_back = slp_new_frame(0, new Array(slp_function, slp_resume_block, slp_targetvar, %s))' % usedvars)    #XXX what should state (here 0) really be?
+            self.append('slp_frame_stack_bottom        = slp_frame_stack_bottom.f_back')
+            self.comment('and unwind')
+            self.append('return')
             self.skip_closeblock()
             self.closeblock()
 
             self.openblock(self._resumehandler_blocknum)
             self.comment('resume block for stackless feature')
-            self.append('%-19s = slp_frame_stack_top[0]' % 'block')
+            self.append('%-19s = slp_frame_stack_top.resume_data[1]' % 'block')
+            self.append('%-19s = slp_frame_stack_top.resume_data[2]' % 'slp_targetvar')
             for i, k in enumerate(self._usedvars.keys()):
-                self.append('%-19s = slp_frame_stack_top[%d]' % (k, i+1))
+                self.append('%-19s = slp_frame_stack_top.resume_data[%d]' % (k, i+3))
             self.append('slp_frame_stack_top = null')
+            self.append('eval(slp_targetvar + " = slp_return_value")')
             self.closeblock()
 
         self.append("}")    #end of switch
@@ -180,18 +185,23 @@
 
         if not exceptions:
             assert no_exception is None
-            self.append('%s = %s(%s)' % (targetvar, functionref, args))
             if self.js.stackless:
-                self.append('if (slp_frame_stack_bottom) { slp_resume_block = %d; block = %d; break; }' % (self._resume_blocknum, self._savehandler_blocknum))
+                self.append('%s = %s(%s)' % (targetvar, functionref, args))
+                self.append('if (slp_frame_stack_bottom) { slp_function = %s; slp_targetvar = "%s"; block = %d; slp_resume_block = %d; break; }' %
+                    (functionref, targetvar, self._savehandler_blocknum, self._resume_blocknum))
                 self.indent_less()
                 self.append('case %d:' % self._resume_blocknum)
                 self.indent_more()
                 self._resume_blocknum += 1
+            else:
+                self.append('%s = %s(%s)' % (targetvar, functionref, args))
         else:
             assert no_exception is not None
             no_exception_label, no_exception_exit = no_exception
             self.append('try {')
             self.indent_more()
+            if self.js.stackless:
+                self.comment('TODO: stackless andf exceptions handling')
             self.append('%s = %s(%s)' % (targetvar, functionref, args))
             self._phi(no_exception_exit)
             self._goto_block(no_exception_label)

Modified: pypy/dist/pypy/translator/js/src/ll_stackless.js
==============================================================================
--- pypy/dist/pypy/translator/js/src/ll_stackless.js	(original)
+++ pypy/dist/pypy/translator/js/src/ll_stackless.js	Thu Nov 17 10:14:39 2005
@@ -1,46 +1,23 @@
 // Stackless helper data and code
 
-slp_frame_stack_top    = null
-slp_frame_stack_bottom = null
-slp_resume_block       = 0
+slp_frame_stack_top    = null;
+slp_frame_stack_bottom = null;
+slp_resume_block       = 0;
+
+// slp_restart_substate   = undefined; // XXX do we really need this?
+slp_return_value       = undefined;
+slp_targetvar          = undefined;
+slp_function           = undefined;
 
 function ll_stack_too_big() {
     return false; // XXX TODO use call depth here!
 }
 
-/*
-#define STANDALONE_ENTRY_POINT   slp_standalone_entry_point
-
-
-typedef struct slp_frame_s {
-  struct slp_frame_s *f_back;
-  int state;
-} slp_frame_t;
-
-typedef struct {
-  slp_frame_t header;
-  void* p0;
-} slp_frame_1ptr_t;
-
-struct slp_state_decoding_entry_s {
-  void *function;
-  int signature;
-};
-
-#include "slp_defs.h"
-
-// implementations
-
-// int slp_restart_substate;
-// long slp_retval_long;
-// double slp_retval_double;
-// void *slp_retval_voidptr;
-*/
-
-function slp_new_frame(state) {
+function slp_new_frame(state, resume_data) {
   f        = new Object();
   f.f_back = null;
   f.state  = state;
+  f.resume_data = resume_data;
   return f;
 }
 
@@ -51,7 +28,7 @@
         slp_frame_stack_top = slp_frame_stack_bottom = slp_new_frame(0);
     }
 }
-ll_stack_unwind = ll_stackless_stack_unwind
+ll_stack_unwind = ll_stackless_stack_unwind;    // alias (XXX really need both?)
 
 function    slp_return_current_frame_to_caller() {
   var   result = slp_frame_stack_top;
@@ -61,7 +38,7 @@
 }
 
 function slp_end_of_yielding_function() {
-  slp_frame_stack_top = slp_retval_voidptr;
+  slp_frame_stack_top = slp_return_value;
   return null;
 }
 
@@ -86,7 +63,7 @@
 	slp_frame_stack_top = slp_frame_stack_bottom = f;
 	return null;
 }
-ll_stackless_switch__frame_stack_topPtr = ll_stackless_switch
+ll_stackless_switch__frame_stack_topPtr = ll_stackless_switch;  // alias (XXX really need both?)
 
 // example function for testing
 
@@ -104,72 +81,54 @@
     }
 }
 
-/*
-#include "slp_state_decoding.h"
-
-void slp_main_loop(void)
-{
-  int state, signature;
-  slp_frame_t* pending;
-  slp_frame_t* back;
-  void* fn;
-
-  while (1)
-    {
-      slp_frame_stack_bottom = null;
-      pending = slp_frame_stack_top;
-
-      while (1)
-        {
-          back = pending.f_back;
-          state = pending.state;
-          fn = slp_state_decoding_table[state].function;
-          signature = slp_state_decoding_table[state].signature;
-          if (fn != null)
-            slp_restart_substate = 0;
-          else
-            {
-              slp_restart_substate = signature;
-              state -= signature;
-              fn = slp_state_decoding_table[state].function;
-              signature = slp_state_decoding_table[state].signature;
-            }
-
-          switch (signature) {
-
-#include "slp_signatures.h"
-
-	  }
-
-          free(pending);  // consumed by the previous call
-          if (slp_frame_stack_top)
-            break;
-          if (!back)
-            return;
-          pending = back;
-          slp_frame_stack_top = pending;
-        }
-      // slp_frame_stack_bottom is usually non-null here, apart from
-      // when returning from switch()
-      if (slp_frame_stack_bottom)
-        {
-          assert(slp_frame_stack_bottom.f_back == null);
-          slp_frame_stack_bottom.f_back = back;
+function slp_main_loop() {
+    while (true) {
+        slp_frame_stack_bottom = null;
+        pending = slp_frame_stack_top;
+
+        while (true) {
+            f_back      = pending.f_back;
+
+            // state     = pending.state;
+            // fn        = slp_state_decoding_table[state].function;
+            // signature = slp_state_decoding_table[state].signature;
+            // if (fn) {
+            //     slp_restart_substate = 0;
+            // } else {
+            //     slp_restart_substate = signature;
+            //     state    -= signature;
+            //     fn        = slp_state_decoding_table[state].function;
+            //     signature = slp_state_decoding_table[state].signature;
+            // }
+
+            // Call back into the function...
+            // Ignoring parameters because they get initialized in the function anyway!
+            slp_return_value = pending.slp_function();
+
+            if (slp_frame_stack_top)
+                break;
+            if (!f_back)
+                return;
+            pending = f_back;
+            slp_frame_stack_top = pending;
         }
+        
+        // slp_frame_stack_bottom is usually non-null here, apart from
+        // when returning from switch()
+        if (slp_frame_stack_bottom)
+            slp_frame_stack_bottom.f_back = f_back;
     }
 }
 
-int slp_standalone_entry_point(RPyListOfString *argv)
-{
-	int result;
-	result = PYPY_STANDALONE(argv);
-	if (slp_frame_stack_bottom) {
-		slp_main_loop();
-		result = (int) slp_retval_long;
-	}
-	return result;
+function slp_standalone_entry_point() {
+    var result = fn();  //XXX hardcoded for now
+    if (slp_frame_stack_bottom) {
+        // if the stack unwound we need to run the dispatch loop
+        // to retrieve the actual result
+        slp_main_loop();
+        result = slp_return_value;
+    }
+    return result;
 }
-*/
 
 // End of Stackless helper data and code
-



More information about the Pypy-commit mailing list