aboutsummaryrefslogtreecommitdiff
path: root/src/bytecode.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bytecode.c')
-rw-r--r--src/bytecode.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 3e9a6e8..a0b5406 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -2,18 +2,36 @@
#include <assert.h>
void tsl_bytecode_writer_init(TslBytecodeWriter *self) {
- assert(sizeof(TslInstruction) == 4);
tsl_buffer_init(&self->buffer);
+ self->register_counter = 0;
}
void tsl_bytecode_writer_deinit(TslBytecodeWriter *self) {
tsl_buffer_deinit(&self->buffer);
}
-int tsl_bytecode_writer_assign(TslBytecodeWriter *self, TslRegister reg, double value) {
- TslInstruction instruction;
- instruction.opcode = TSL_OPCODE_ASSIGN;
- instruction.type2.dst_reg = reg;
- instruction.type2.value_index = value;
+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++;
+ return -1;
+}
+
+int tsl_bytecode_writer_load_number(TslBytecodeWriter *self, TslRegister dst, double number) {
+ TslInstructionType1 instruction;
+ instruction.opcode = TSL_OPCODE_LOAD_NUMBER;
+ instruction.dst_reg = dst;
+ instruction.number = number;
+ return tsl_buffer_append(&self->buffer, &instruction, sizeof(instruction));
+}
+
+tsl_bytecode_writer_mov_reg(TslBytecodeWriter *self, TslRegister dst, TslRegister src) {
+ TslInstructionType2 instruction;
+ instruction.opcode = TSL_OPCODE_MOV_REG;
+ instruction.dst_reg = dst;
+ instruction.src_reg = src;
return tsl_buffer_append(&self->buffer, &instruction, sizeof(instruction));
}