This commit is contained in:
2026-05-15 08:04:30 -05:00
parent 06e5be5c89
commit a0881e3c22
3 changed files with 25 additions and 2 deletions

View File

@@ -15,8 +15,8 @@ Decisions:
- [x] Arrays - [x] Arrays
- [x] Tables - [x] Tables
- [ ] VM - [ ] VM
- [ ] (Lua interface) call assembler - [x] (Lua interface) call assembler
- [ ] (Lua) generate bytecode - [x] (Lua) generate bytecode
- [ ] Labels - [ ] Labels
- [ ] Code - [ ] Code
- [ ] Interpret bytecode (fast) - [ ] Interpret bytecode (fast)

View File

@@ -227,6 +227,10 @@ local function assemble(proto)
if opcode == nil then error("Unknown instruction " .. inst[1]) end if opcode == nil then error("Unknown instruction " .. inst[1]) end
if operand == nil then if operand == nil then
push8(opcode) push8(opcode)
elseif type(operand) == 'string' then
-- TODO
push8(opcode)
push16(0)
else else
if opcode >= 0xc0 and opcode < 0xe0 then if opcode >= 0xc0 and opcode < 0xe0 then
push8(opcode) push8(opcode)

View File

@@ -269,4 +269,23 @@ int main()
code_destroy(code); code_destroy(code);
free(bytecode); 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);
}
} }