.
This commit is contained in:
22
lib/code.c
22
lib/code.c
@@ -9,9 +9,16 @@
|
||||
|
||||
#define MAGIC 0xa7d6e9b1
|
||||
|
||||
#define VERSION_ADDR 0x04
|
||||
#define CODE_START_ADDR 0x08
|
||||
#define N_CONST_ADDR 0x0c
|
||||
#define CONST_START 0x10
|
||||
|
||||
struct Code {
|
||||
uint8_t* bytecode;
|
||||
size_t bytecode_sz;
|
||||
uint8_t* bytecode;
|
||||
size_t bytecode_sz;
|
||||
uint32_t* const_addr;
|
||||
uint32_t* fn_addr;
|
||||
};
|
||||
|
||||
Code* code_new()
|
||||
@@ -39,12 +46,21 @@ TYC_RESULT code_load_bytecode(Code* code, uint8_t* bytecode, size_t bytecode_sz)
|
||||
code->bytecode = bytecode;
|
||||
code->bytecode_sz = bytecode_sz;
|
||||
|
||||
for (size_t i = 0; i < bytecode_sz; ++i) {
|
||||
if (i % 16 == 0)
|
||||
printf("%04X: ", i);
|
||||
printf("%02x ", bytecode[i]);
|
||||
if (i % 16 == 15)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return T_OK;
|
||||
}
|
||||
|
||||
size_t code_n_consts(Code const* code)
|
||||
{
|
||||
return 0; // TODO
|
||||
uint32_t n_consts = *(uint32_t*) &code->bytecode[N_CONST_ADDR];
|
||||
return n_consts;
|
||||
}
|
||||
|
||||
TYC_CONST_TYPE code_const_type(Code const* code, size_t n)
|
||||
|
||||
Reference in New Issue
Block a user