Permalink
Browse files

Minimize stack trace by using array runner. Enough to run examples in…

… safari
  • Loading branch information...
amasad committed Jan 17, 2013
1 parent d50ca41 commit 83411011a08448bf7f1b07490a58e330a1fd433a
Showing with 18 additions and 7 deletions.
  1. +18 −7 public/qlb/qlb.js
@@ -39,7 +39,7 @@ Qlb.eval = function(exp, env) {
return rest
} else if(first == "إفعل") {
rest = rest.map(function(e) { return Qlb.eval(e, env) });
rest = run(rest, env);
return rest[rest.length - 1];
} else if(first == "إذا") {
@@ -75,7 +75,8 @@ Qlb.eval = function(exp, env) {
}
} else {
var exps = exp.map(function(p) { return Qlb.eval(p, env) })
var exps = run(exp, env);
if(typeof exps[0] == "function")
// first element evaluates to a function
return exps.shift().apply(this, exps)
@@ -86,23 +87,33 @@ Qlb.eval = function(exp, env) {
} else
// return last element
return exps[exps.length - 1];
}
}
};
Qlb.execute = function(code) {
function run(ast, env) {
try {
var ast = Qlb.parser.parse(code);
var val;
var ret = [];
for (var i = 0; i < ast.length; i++) {
val = Qlb.eval(ast[i], Qlb.globalEnvironment);
val = Qlb.eval(ast[i], env);
ret.push(val);
};
return val;
return ret;
} catch(e) {
Qlb.handleUncaughtException(e);
}
}
Qlb.execute = function(code) {
try {
var ast = Qlb.parser.parse(code);
return run(ast, Qlb.globalEnvironment).pop();
} catch (e) {
Qlb.handleUncaughtException(e);
}
};

0 comments on commit 8341101

Please sign in to comment.