#ifndef TSL_BYTECODE_H #define TSL_BYTECODE_H #include "std/buffer.h" #include "std/string_view.h" #include "value.h" #include typedef uint8_t TslOpcodeType; typedef enum { TSL_OPCODE_LOADN, /* load number */ TSL_OPCODE_LOADB, /* load bool */ TSL_OPCODE_LOADS, /* load string */ TSL_OPCODE_LOADF, /* load function */ TSL_OPCODE_LOADV, /* load variable */ TSL_OPCODE_LOADNULL, /* load null */ TSL_OPCODE_SETV, /* set variable to the value at the top of the stack */ TSL_OPCODE_LIST, /* create a list using values from the stack */ TSL_OPCODE_MAP, /* create a map using values from the stack */ TSL_OPCODE_MINDEX, /* map index. pop two values from stack, where the first value will be a map and the second a key */ TSL_OPCODE_CALLF, /* call the function at the top of the stack using the next N values at the top of the stack as arguments */ TSL_OPCODE_ADD, TSL_OPCODE_SUB, TSL_OPCODE_MUL, TSL_OPCODE_DIV, TSL_OPCODE_LOADCA, /* add command argument to stack */ TSL_OPCODE_CALLC /* run a program using N arguments from the stack, where the bottom value is the name of the program */ } TslOpcode; typedef struct { TslBuffer buffer; } TslBytecodeWriter; typedef struct { TslOpcodeType opcode; int value; } TslInstructionType1; typedef struct { TslOpcodeType opcode; double value; } TslInstructionType2; typedef struct { TslOpcodeType opcode; TslBool value; } TslInstructionType3; typedef struct { TslOpcodeType opcode; TslStringView value; } TslInstructionType4; typedef struct { TslOpcodeType opcode; } TslInstructionType5; void tsl_bytecode_writer_init(TslBytecodeWriter *self); void tsl_bytecode_writer_deinit(TslBytecodeWriter *self); int tsl_bytecode_writer_add_ins1(TslBytecodeWriter *self, TslOpcode opcode, int value); int tsl_bytecode_writer_add_ins2(TslBytecodeWriter *self, TslOpcode opcode, double value); int tsl_bytecode_writer_add_ins3(TslBytecodeWriter *self, TslOpcode opcode, TslBool value); int tsl_bytecode_writer_add_ins4(TslBytecodeWriter *self, TslOpcode opcode, TslStringView *value); int tsl_bytecode_writer_add_ins5(TslBytecodeWriter *self, TslOpcode opcode); #endif /* TSL_BYTECODE_H */