From a0881e3c22421c23c6fc6bd376c1d8970d128dd5 Mon Sep 17 00:00:00 2001 From: Andre Wagner Date: Fri, 15 May 2026 08:04:30 -0500 Subject: [PATCH] . --- TODO.md | 4 ++-- lib/compiler/compiler.lua | 4 ++++ test/tests.c | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index 380044f..0b153c3 100644 --- a/TODO.md +++ b/TODO.md @@ -15,8 +15,8 @@ Decisions: - [x] Arrays - [x] Tables - [ ] VM - - [ ] (Lua interface) call assembler - - [ ] (Lua) generate bytecode + - [x] (Lua interface) call assembler + - [x] (Lua) generate bytecode - [ ] Labels - [ ] Code - [ ] Interpret bytecode (fast) diff --git a/lib/compiler/compiler.lua b/lib/compiler/compiler.lua index 42a16ac..4d6b577 100644 --- a/lib/compiler/compiler.lua +++ b/lib/compiler/compiler.lua @@ -227,6 +227,10 @@ local function assemble(proto) if opcode == nil then error("Unknown instruction " .. inst[1]) end if operand == nil then push8(opcode) + elseif type(operand) == 'string' then + -- TODO + push8(opcode) + push16(0) else if opcode >= 0xc0 and opcode < 0xe0 then push8(opcode) diff --git a/test/tests.c b/test/tests.c index 4bf2fda..1837686 100644 --- a/test/tests.c +++ b/test/tests.c @@ -269,4 +269,23 @@ int main() code_destroy(code); free(bytecode); } + + { + printf("### Bytecode - labels\n"); + const char* assembly_code = + ".func 0\n" + " jmp @my_label\n" + " pushi \n" + "@my_label:\n" + " ret"; + + uint8_t* bytecode; size_t bytecode_sz; + assert(code_assemble(assembly_code, &bytecode, &bytecode_sz) == T_OK); + + Code* code = code_new(); + assert(code_load_bytecode(code, bytecode, bytecode_sz) == T_OK); + + code_destroy(code); + free(bytecode); + } } \ No newline at end of file