Lua stack frame refactor

This commit is contained in:
Zef Hemel
2024-10-20 15:06:23 +02:00
parent 64c98678bc
commit 8acb112e4e
14 changed files with 300 additions and 201 deletions
+8 -3
View File
@@ -2,6 +2,7 @@ import { assertEquals } from "@std/assert/equals";
import {
LuaEnv,
LuaNativeJSFunction,
LuaStackFrame,
luaValueToJS,
singleResult,
} from "./runtime.ts";
@@ -11,15 +12,19 @@ import { evalExpression, evalStatement } from "./eval.ts";
import { luaBuildStandardEnv } from "$common/space_lua/stdlib.ts";
function evalExpr(s: string, e = new LuaEnv()): any {
const node = parse(`e(${s})`).statements[0] as LuaFunctionCallStatement;
const sf = new LuaStackFrame(e, node.ctx);
return evalExpression(
(parse(`e(${s})`).statements[0] as LuaFunctionCallStatement).call
.args[0],
node.call.args[0],
e,
sf,
);
}
function evalBlock(s: string, e = new LuaEnv()): Promise<void> {
return evalStatement(parse(s) as LuaBlock, e);
const node = parse(s) as LuaBlock;
const sf = new LuaStackFrame(e, node.ctx);
return evalStatement(node, e, sf);
}
Deno.test("Evaluator test", async () => {