fix compilation format.

This commit is contained in:
trans_soup 2023-11-06 15:35:21 +01:00
parent 64a01d4abf
commit abdea0828f
1 changed files with 10 additions and 2 deletions

View File

@ -98,16 +98,24 @@ function evaluate (env, expr, locals = []) {
const args = [ ...expr.args ].reverse();
const body = evaluate(env, expr.body, args);
return body;
return compile_function(args, body);
}
throw new Error();
}
function compile_function (args, body) {
if (args.length > 1) {
return [0, compile_function(args.slice(1), body)];
} else {
return [0, body];
}
}
function has_local (locals, name) {
return locals.includes(name);
}
function get_local (locals, name) {
return locals.indexOf(name);
return locals.indexOf(name) + 1;
}