#include "../include/bytecode.h" #include 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++; 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)); }