From 32af8eae4a50390d1a01bd2f80c8edd67190efdb Mon Sep 17 00:00:00 2001 From: Andre Wagner Date: Sat, 16 May 2026 08:49:58 -0500 Subject: [PATCH] . --- test/code-tests.lua | 13 +++++++++++++ test/tests.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/test/code-tests.lua b/test/code-tests.lua index b083784..4ba2c0d 100644 --- a/test/code-tests.lua +++ b/test/code-tests.lua @@ -11,4 +11,17 @@ return { expected_stack_size = 1, expected_stack_top = 5, }, + { + name = "VM: integer expressions", + template = [[ + .func 0 + pushi %d + pushi %d + %s + ret + ]], + replacements = { + { 2, 3, 'sum', expected_stack_top = 5 }, + }, + } } \ No newline at end of file diff --git a/test/tests.c b/test/tests.c index cdf1040..79cda1b 100644 --- a/test/tests.c +++ b/test/tests.c @@ -14,6 +14,8 @@ static void run_assembly_tests(void); static void run_assembly_test(lua_State* L); +static void run_assembly_test_code(lua_State* L); +static void run_assembly_test_template(lua_State* L); int main(void) { @@ -343,13 +345,35 @@ static void run_assembly_tests(void) static void run_assembly_test(lua_State* L) { - TycheVM* T = tyc_new(); - // print test name lua_getfield(L, -1, "name"); printf(" - %s\n", lua_tostring(L, -1)); lua_pop(L, 1); + // has code? + lua_getfield(L, -1, "code"); + if (!lua_isnil(L, -1)) { + lua_pop(L, 1); + run_assembly_test_code(L); + return; + } else { + lua_pop(L, 1); + } + + // has template + lua_getfield(L, -1, "template"); + if (!lua_isnil(L, -1)) { + lua_pop(L, 1); + run_assembly_test_template(L); + } else { + lua_pop(L, 1); + } +} + +static void run_assembly_test_code(lua_State* L) +{ + TycheVM* T = tyc_new(); + // load code uint8_t* bytecode; size_t bytecode_sz; lua_getfield(L, -1, "code"); @@ -379,4 +403,8 @@ static void run_assembly_test(lua_State* L) // cleanup free(bytecode); tyc_destroy(T); +} + +static void run_assembly_test_template(lua_State* L) +{ } \ No newline at end of file