aboutsummaryrefslogtreecommitdiff
path: root/include/bytecode.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/bytecode.h')
-rw-r--r--include/bytecode.h35
1 files changed, 19 insertions, 16 deletions
diff --git a/include/bytecode.h b/include/bytecode.h
index 4a14b8d..4a9d49c 100644
--- a/include/bytecode.h
+++ b/include/bytecode.h
@@ -4,37 +4,40 @@
#include "std/buffer.h"
#include <stdint.h>
-/*
- All instructions are 4 bytes in size.
-*/
-
typedef uint8_t TslOpcodeType;
-typedef uint8_t TslRegister;
+/* Registers are positive if they refer to local variables and negative when they refer to parameters */
+typedef int16_t TslRegister;
typedef uint16_t TslValueIndex;
typedef enum {
- TSL_OPCODE_ASSIGN
+ TSL_OPCODE_LOAD_NUMBER,
+ TSL_OPCODE_MOV_REG
} TslOpcode;
typedef struct {
TslBuffer buffer;
+ TslRegister register_counter;
} TslBytecodeWriter;
typedef struct {
+ TslRegister dst_reg;
+ double number;
+ TslOpcodeType opcode;
+} TslInstructionType1;
+
+typedef struct {
+ TslRegister dst_reg;
+ TslRegister src_reg;
TslOpcodeType opcode;
- union {
- TslRegister dst_reg;
- TslRegister src_reg;
- } type1;
- union {
- TslRegister dst_reg;
- TslValueIndex value_index;
- } type2;
-} TslInstruction;
+} TslInstructionType2;
void tsl_bytecode_writer_init(TslBytecodeWriter *self);
void tsl_bytecode_writer_deinit(TslBytecodeWriter *self);
+void tsl_bytecode_writer_reset_register_counter(TslBytecodeWriter *self);
+/* Returns -1 on error (too many registers used (more than 2^15)) */
+TslRegister tsl_bytecode_writer_get_unique_register(TslBytecodeWriter *self);
-int tsl_bytecode_writer_assign(TslBytecodeWriter *self, TslRegister reg, double value);
+int tsl_bytecode_writer_load_number(TslBytecodeWriter *self, TslRegister dst, double number);
+int tsl_bytecode_writer_mov_reg(TslBytecodeWriter *self, TslRegister dst, TslRegister src);
#endif /* TSL_BYTECODE_H */