eval("function self_test() {"+source+"}");
eresult = self_test(isource);
if (typeof(eresult) != "string") eresult = ""+JSON.stringify(eresult);
fill('expected-result', 'Expected result', eresult);
}
if (SHOW_SOURCE) {
sl = source.split(/\n/);
ci = 0;
o = "<pre>";
for (j=0; j < sl.length; j++) {
o += ci+": "+html_escape(sl[j])+"\n";
ci += sl[j].length + 1;
}
o += "</pre>";
fill('source', 'Interpreted source', o, 1);
}
tree = parse(source, top_level);
if (tree) {
if (PRINT_TREE) {
fill('parse-tree', 'Parse tree',
JSON.stringify(tree, ['key', 'name', 'message',
'value', 'arity', 'first', 'second', 'third', 'fourth'], 4));
}
if (PRINT_JCOMPILE) {
fill('jcompile', 'Recompiled to JavaScript', jcompile(tree));
}
bc = bcompile(tree);
if (PRINT_RAW_BYTECODE) {
fill('raw-bytecode', 'Raw Bytecode File Contents',
JSON.stringify(bc, ['functions', 'literals', 'id', 'nargs',
'bytecode', 'label'], 4));
}
if (PRINT_ENCODED_BYTECODE) {
var out_file = bc.encode();
fill('encoded-bytecode', 'Encoded Bytecode', out_file.length+" "+
JSON.stringify(out_file));
}
b = "<p>Index: ";
for (i=0; i<bc.functions.length; i++) {
var f = bc.functions[i];
b+= "<a href='#bc-"+i+"'>";
b+= html_escape((f.name) ? f.name : ("<#"+i+">"));
b+= "</a> ";
}
b += "</p>";
for (i=0; i<bc.functions.length; i++) {
var f = bc.functions[i];
b += "<h2><a id='bc-"+i+"'>Function #"+f.id;
if (f.name) b += " "+html_escape(f.name);
b += "</a>";
b += " ("+f.nargs+" args; max stack depth="+f.max_stack+")</h2>\n";
b += "<pre>"+html_escape(bc.decompile(f.id))+"</pre>";
}
fill('bytecode', 'Compiled Bytecode', b, 1);
frame = binterp.make_top_level_frame.call({} ,
isource);
result = binterp.binterp(bc, 0, frame);
fill('isource', 'Input to interpreted compiler', isource);
if (typeof(result) != "string") result = ""+JSON.stringify(result);
fill('result', 'Result from interpreter', result);
}
}
if (!CATCH_ERRORS) {
do_it();
} else {
try {
do_it();
} catch (e) {
fill('errors', 'Error!',
JSON.stringify(e, ['name', 'message', 'from', 'to',
'key', 'value', 'arity', 'first',
'second', 'third', 'fourth'], 4));
}
}
});