diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-01-22 06:14:42 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-01-22 06:14:42 +0100 |
commit | 840a3c6c5aa2400ce80d8ec7bb8b1a8d6e25770b (patch) | |
tree | 3b58d296814b54ee20f050e21a9cd8f2c1f2bf5a /src/bytecode.c | |
parent | a724ddbe1c8c53acd8b2836e437237cf17c57043 (diff) |
Simplify bytecode
Diffstat (limited to 'src/bytecode.c')
-rw-r--r-- | src/bytecode.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index 9406852..d15df9e 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -4,36 +4,32 @@ void tsl_bytecode_writer_init(TslBytecodeWriter *self) { tsl_buffer_init(&self->buffer); - self->register_counter = 0; } void tsl_bytecode_writer_deinit(TslBytecodeWriter *self) { tsl_buffer_deinit(&self->buffer); } -void tsl_bytecode_writer_reset_register_counter(TslBytecodeWriter *self) { - self->register_counter = 0; -} - -TslRegister tsl_bytecode_writer_get_unique_register(TslBytecodeWriter *self) { - if(self->register_counter < INT16_MAX) - return self->register_counter++; - fprintf(stderr, "Error: Too many variables in the same scope\n"); - return -1; -} - -int tsl_bytecode_writer_load_number(TslBytecodeWriter *self, TslRegister dst, double number) { +int tsl_bytecode_writer_loadn(TslBytecodeWriter *self, double number) { TslInstructionType1 instruction; instruction.opcode = TSL_OPCODE_LOAD_NUMBER; - instruction.dst_reg = dst; instruction.number = number; + fprintf(stderr, "loadn %f\n", number); return tsl_buffer_append(&self->buffer, &instruction, sizeof(instruction)); } -int tsl_bytecode_writer_mov_reg(TslBytecodeWriter *self, TslRegister dst, TslRegister src) { +int tsl_bytecode_writer_loadb(TslBytecodeWriter *self, TslBool value) { TslInstructionType2 instruction; - instruction.opcode = TSL_OPCODE_MOV_REG; - instruction.dst_reg = dst; - instruction.src_reg = src; + instruction.opcode = TSL_OPCODE_LOAD_BOOL; + instruction.value = value; + fprintf(stderr, "loadb %s\n", value ? "true" : "false"); + return tsl_buffer_append(&self->buffer, &instruction, sizeof(instruction)); +} + +int tsl_bytecode_writer_setv(TslBytecodeWriter *self, TslStringView *key) { + TslInstructionType3 instruction; + instruction.opcode = TSL_OPCODE_SETV; + instruction.key = *key; + fprintf(stderr, "setv \"%.*s\"\n", (int)key->size, key->data); return tsl_buffer_append(&self->buffer, &instruction, sizeof(instruction)); } |