[pypy-svn] r20416 - in pypy/dist/pypy/translator/js: . src test
ericvrp at codespeak.net
ericvrp at codespeak.net
Wed Nov 30 11:04:31 CET 2005
Author: ericvrp
Date: Wed Nov 30 11:04:28 2005
New Revision: 20416
Modified:
pypy/dist/pypy/translator/js/codewriter.py
pypy/dist/pypy/translator/js/conftest.py
pypy/dist/pypy/translator/js/js.py
pypy/dist/pypy/translator/js/src/ll_stackless.js
pypy/dist/pypy/translator/js/test/runtest.py
pypy/dist/pypy/translator/js/test/test_stackless.py
Log:
WIP, fixes for running stackless stuff in browsers.
Genjs will break shortly. After the somepbc refactor it will be fixed.
Modified: pypy/dist/pypy/translator/js/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/codewriter.py (original)
+++ pypy/dist/pypy/translator/js/codewriter.py Wed Nov 30 11:04:28 2005
@@ -4,8 +4,6 @@
log = log.codewriter
-debug = False
-
class CodeWriter(object):
tabstring = ' '
@@ -43,24 +41,31 @@
else:
eol = ';\n'
- do_log = debug and line and not line.endswith('}')
- for x in ['var', '//', 'for (;;) {', 'switch (block) {', 'slp_new_frame']:
+ do_log = self.js.logging and line and not line.endswith('}')
+ for x in ['var', '//', 'for (;;) {', 'switch (block) {', 'slp_new_frame', 'case ', 'if ', 'elif ', 'else ', '} else ']:
if line.startswith(x):
do_log = False
break
log_before = True
- for x in ['function ', 'case ', '} else {', 'else if', 'else {']:
+ for x in ['function ',]:
if line.startswith(x):
log_before = False
break
+ try:
+ func_name = self.decl.split('(')[0]
+ except AttributeError:
+ func_name = 'UNKNOWN'
if do_log and log_before:
- self.f.write("%slogme('%-40s %s')\n" % (s, line, self.decl))
+ self.f.write("%slog('%-40s IN %s')\n" % (s, line, func_name))
self.f.write(s + line + eol)
if do_log and not log_before:
- self.f.write("%slogme('%-40s %s')\n" % (s, line, self.decl))
+ if line.startswith('function '):
+ self.f.write("%slog('FUNCTION %s')\n" % (s, func_name))
+ else:
+ self.f.write("%slog('%-40s IN %s')\n" % (s, line, func_name))
def comment(self, line):
self.append("// " + line)
Modified: pypy/dist/pypy/translator/js/conftest.py
==============================================================================
--- pypy/dist/pypy/translator/js/conftest.py (original)
+++ pypy/dist/pypy/translator/js/conftest.py Wed Nov 30 11:04:28 2005
@@ -7,4 +7,6 @@
default=False, help="run Javascript tests in your default browser"),
Option('--stackless', action="store_true",dest="jsstackless",
default=False, help="enable stackless feature"),
+ Option('--log', action="store_true",dest="jslog",
+ default=False, help="log debugging info"),
)
Modified: pypy/dist/pypy/translator/js/js.py
==============================================================================
--- pypy/dist/pypy/translator/js/js.py (original)
+++ pypy/dist/pypy/translator/js/js.py Wed Nov 30 11:04:28 2005
@@ -26,10 +26,11 @@
return path
class JS(object): # JS = Javascript
- def __init__(self, translator, entrypoint=None, stackless=False):
+ def __init__(self, translator, entrypoint=None, stackless=False, logging=False):
self.db = Database(translator)
self.entrypoint = entrypoint or translator.entrypoint
- self.stackless = stackless or conftest.option.jsstackless
+ self.stackless = stackless or conftest.option.jsstackless
+ self.logging = logging or conftest.option.jslog
def write_source(self):
func = self.entrypoint
@@ -78,18 +79,17 @@
else:
s = 'stack.js'
src_filename = _path_join(os.path.dirname(__file__), 'src', s)
- f.write(open(src_filename).read())
+ s = open(src_filename).read()
+ if self.logging:
+ s = s.replace('LOG', 'log')
+ else:
+ s = s.replace('LOG', '// log')
+ f.write(s)
f.close()
entry_point= c.value._obj
self.graph = self.db.obj2node[entry_point].graph
- startblock = self.graph.startblock
- args = ','.join(['arguments[%d]' % i for i,v in enumerate(startblock.inputargs)])
- if self.stackless:
- self.wrappertemplate = "load('%s'); print(slp_entry_point('%s(%%s)'))" % (self.filename, self.graph.name)
- else:
- self.wrappertemplate = "load('%s'); print(%s(%%s))" % (self.filename, self.graph.name)
log('Written:', self.filename)
return self.filename
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 Wed Nov 30 11:04:28 2005
@@ -3,14 +3,27 @@
var slp_frame_stack_top = null;
var slp_frame_stack_bottom = null;
var slp_return_value = undefined;
-var slp_debug = false;
-function logme(s) {
- if (slp_debug) {
- print("logme: " + s);
+// This gets called with --log
+
+function log(s) {
+ try {
+ alert(s); // in browser
+ } catch (e) {
+ print('log:' + s); // commandline
}
}
+function function_name(func) {
+ var s = func.toString().split("\n");
+ s = s[0].length == 0 ? s[1] : s[0];
+ s = s.split(' ')[1];
+ s = s.split('(')[0];
+ return s
+}
+
+//
+
function ll_stack_too_big_helper(depth) {
if (depth > 0) {
ll_stack_too_big_helper(depth-1)
@@ -19,15 +32,17 @@
function ll_stack_too_big() {
try {
- ll_stack_too_big_helper(5); //XXX
+ ll_stack_too_big_helper(5); // some magic number that seems to work
} catch (e) { //stack overflow when recursing some more
+ LOG("stack is too big")
return true;
}
+ LOG("stack is not too big yet")
return false;
}
function slp_new_frame(targetvar, func, resume_blocknum, vars) {
- if (slp_debug) logme("starting slp_new_frame("+targetvar+","+func.toString().split("\n")[1]+","+resume_blocknum+","+vars.toSource()+")");
+ LOG("starting slp_new_frame("+targetvar+","+function_name(func)+","+resume_blocknum+","+vars.toSource()+")");
var f = new Object();
f.func = func;
f.targetvar = targetvar;
@@ -38,60 +53,61 @@
// the slp_frame_stack will be correctly sorted
slp_frame_stack_bottom.f_back = f;
slp_frame_stack_bottom = f;
- if (slp_debug) logme("finished slp_new_frame");
+ LOG("finished slp_new_frame");
}
function slp_new_frame_simple(func) {
- if (slp_debug) logme("starting slp_new_frame_simple("+func.toString().split("\n")[1]+")");
+ LOG("starting slp_new_frame_simple("+function_name(func)+")");
var f = new Object();
f.func = func;
f.targetvar = undefined;
f.resume_blocknum = undefined;
f.vars = undefined;
f.f_back = null;
- if (slp_debug) logme("finished slp_new_frame_simple");
+ LOG("finished slp_new_frame_simple");
return f; // note: the non-simple version returns nothing
}
// <UNTESTED>
-function ll_stackless_stack_unwind() {
- if (slp_debug) logme("starting ll_stackless_stack_unwind");
+function ll_stack_unwind() {
+ LOG("starting ll_stackless_stack_unwind");
if (slp_frame_stack_top) {
slp_frame_stack_top = null; // no need to resume
} else {
- slp_frame_stack_top = slp_frame_stack_bottom = slp_new_frame_simple(ll_stackless_stack_unwind);
+ slp_frame_stack_top = slp_frame_stack_bottom = slp_new_frame_simple(ll_stack_unwind);
}
- if (slp_debug) logme("finished ll_stackless_stack_unwind");
+ LOG("finished ll_stackless_stack_unwind");
}
-ll_stack_unwind = ll_stackless_stack_unwind; // alias (XXX really need both?)
+// // ll_stack_unwind = ll_stackless_stack_unwind; // alias (XXX really need both?)
+// ll_stackless_stack_unwind = ll_stack_unwind; // alias (XXX really need both?)
function slp_return_current_frame_to_caller() {
- if (slp_debug) logme("starting slp_return_current_frame_to_caller");
+ LOG("starting slp_return_current_frame_to_caller");
if (!slp_frame_stack_top) alert('!slp_frame_stack_top');
if (!slp_frame_stack_bottom) alert('!slp_frame_stack_bottom');
var result = slp_frame_stack_top;
slp_frame_stack_bottom.f_back = slp_new_frame_simple(slp_return_current_frame_to_caller);
slp_frame_stack_top = slp_frame_stack_bottom = null; // stop unwinding
- if (slp_debug) logme("finished slp_return_current_frame_to_caller");
+ LOG("finished slp_return_current_frame_to_caller");
return result;
}
function slp_end_of_yielding_function() {
- if (slp_debug) logme("starting slp_end_of_yielding_function");
+ LOG("starting slp_end_of_yielding_function");
if (!slp_frame_stack_top) alert('!slp_frame_stack_top'); // can only resume from slp_return_current_frame_to_caller()
if (!slp_return_value) alert('!slp_return_value');
slp_frame_stack_top = slp_return_value;
- if (slp_debug) logme("finished slp_end_of_yielding_function");
+ LOG("finished slp_end_of_yielding_function");
return null; // XXX or just return?
}
function ll_stackless_switch(c) {
- if (slp_debug) logme("starting ll_stackless_switch");
+ LOG("starting ll_stackless_switch");
var f;
var result;
if (slp_frame_stack_top) { //resume
- if (slp_debug) logme("slp_frame_stack_top != null");
+ LOG("slp_frame_stack_top != null");
// ready to do the switch. The current (old) frame_stack_top is
// f.f_back, which we store where it will be found immediately
// after the switch
@@ -100,16 +116,16 @@
// grab the saved value of 'c' and do the switch
slp_frame_stack_top = f.p0;
- if (slp_debug) logme("finished ll_stackless_switch");
+ LOG("finished ll_stackless_switch");
return result;
}
- if (slp_debug) logme("slp_frame_stack_top == null");
+ LOG("slp_frame_stack_top == null");
// first, unwind the current stack
f = slp_new_frame_simple(ll_stackless_switch);
f.p0 = c;
slp_frame_stack_top = slp_frame_stack_bottom = f;
- if (slp_debug) logme("finished ll_stackless_switch");
+ LOG("finished ll_stackless_switch");
return null;
}
ll_stackless_switch__frame_stack_topPtr = ll_stackless_switch; // alias (XXX really need both?)
@@ -120,36 +136,38 @@
function ll_stackless_stack_frames_depth() {
if (!slp_frame_stack_top) {
- if (slp_debug) logme("starting ll_stackless_stack_frames_depth init");
+ LOG("starting ll_stackless_stack_frames_depth init");
slp_frame_stack_top = slp_frame_stack_bottom = slp_new_frame_simple(ll_stackless_stack_frames_depth);
- if (slp_debug) logme("finished ll_stackless_stack_frames_depth init");
+ LOG("finished ll_stackless_stack_frames_depth init");
return;
}
- if (slp_debug) logme("starting ll_stackless_stack_frames_depth resume");
+ LOG("starting ll_stackless_stack_frames_depth resume");
var f = slp_frame_stack_top;
slp_frame_stack_top = null;
for (var result = 0;f;result++) {
f = f.f_back;
}
- if (slp_debug) logme("stack_frames_depth = " + result);
- if (slp_debug) logme("finished ll_stackless_stack_frames_depth resume");
+ LOG("stack_frames_depth = " + result);
+ LOG("finished ll_stackless_stack_frames_depth resume");
return result;
}
+// main dispatcher loop
+
function slp_main_loop() {
var f_back;
- if (slp_debug) logme("starting slp_main_loop");
+ LOG("starting slp_main_loop");
while (true) {
- if (slp_debug) logme("slp_main_loop (outer loop)");
+ LOG("slp_main_loop (outer loop)");
slp_frame_stack_bottom = null;
pending = slp_frame_stack_top;
while (true) {
- if (slp_debug) logme("slp_main_loop (inner loop)");
+ LOG("slp_main_loop (inner loop)");
f_back = pending.f_back;
- logme('calling: ' + pending.func.toString().split('\n')[1]);
+ LOG('calling: ' + function_name(pending.func));
slp_return_value = pending.func(); // params get initialized in the function because it's a resume!
if (slp_frame_stack_top) {
break;
@@ -166,19 +184,22 @@
slp_frame_stack_bottom.f_back = f_back;
}
}
- if (slp_debug) logme("finished slp_main_loop");
+ LOG("finished slp_main_loop");
}
function slp_entry_point(funcstring) {
- if (slp_debug) logme("starting slp_standalone_entry_point");
+ LOG("starting slp_standalone_entry_point");
var result = eval(funcstring);
+ LOG("RESULT = " + result);
+ LOG("slp_frame_stack_bottom = " + slp_frame_stack_bottom);
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;
}
- if (slp_debug) logme("finished slp_standalone_entry_point");
+ LOG("FINAL RESULT = " + result);
+ LOG("finished slp_standalone_entry_point");
return result;
}
Modified: pypy/dist/pypy/translator/js/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/runtest.py (original)
+++ pypy/dist/pypy/translator/js/test/runtest.py Wed Nov 30 11:04:28 2005
@@ -34,12 +34,14 @@
def __call__(self, *kwds):
args = ', '.join([str(kw).lower() for kw in kwds]) #lowerstr for (py)False->(js)false, etc.
+ function_call = "%s(%s)" % (self.js.graph.name, args)
+ if self.js.stackless:
+ function_call = "slp_entry_point(%s)" % function_call
+
if use_browsertest:
- jstestcase = '%s(%s)' % (self.js.graph.name, args)
- output = jstest(self.js.filename, jstestcase)
+ output = jstest(self.js.filename, function_call)
else:
- wrappercode = self.js.wrappertemplate % args
- cmd = 'echo "%s" | js 2>&1' % wrappercode
+ cmd = 'echo "load(\'%s\'); print(%s)" | js 2>&1' % (self.js.filename, function_call)
log(cmd)
output = os.popen(cmd).read().strip()
for s in output.split('\n'):
Modified: pypy/dist/pypy/translator/js/test/test_stackless.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_stackless.py (original)
+++ pypy/dist/pypy/translator/js/test/test_stackless.py Wed Nov 30 11:04:28 2005
@@ -99,7 +99,7 @@
def test_stack_too_big():
if not conftest.option.jsstackless:
py.test.skip("stackless disabled (enable with py.test --stackless)")
- py.test.skip("stackless feature not incomplete")
+ #py.test.skip("stackless feature not incomplete")
def f1():
return stack_too_big()
More information about the Pypy-commit
mailing list