#ifndef TSL_BYTECODE_H #define TSL_BYTECODE_H #include "std/buffer.h" #include "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_INDEX, /* list/map/string index. pop two values from stack, where the first value will be a list/map/string and the second a key/index */ 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_CALLC /* run a program using N arguments from the stack, where the bottom value is the name of the program */ } TslOpcode; typedef struct { TslBuffer /*TslInstruction*/ buffer; } TslBytecode; typedef struct { TslOpcode opcode; int value; } TslInstructionType1; typedef struct { TslOpcode opcode; double value; } TslInstructionType2; typedef struct { TslOpcode opcode; TslBool value; } TslInstructionType3; typedef struct { TslOpcode opcode; TslStringView value; } TslInstructionType4; typedef struct { TslOpcode opcode; } TslInstructionType5; const char* tsl_opcode_to_string(TslOpcode opcode); void tsl_bytecode_init(TslBytecode *self); void tsl_bytecode_deinit(TslBytecode *self); int tsl_bytecode_add_ins1(TslBytecode *self, TslOpcode opcode, int value); int tsl_bytecode_add_ins2(TslBytecode *self, TslOpcode opcode, double value); int tsl_bytecode_add_ins3(TslBytecode *self, TslOpcode opcode, TslBool value); int tsl_bytecode_add_ins4(TslBytecode *self, TslOpcode opcode, TslStringView *value); int tsl_bytecode_add_ins5(TslBytecode *self, TslOpcode opcode); #endif /* TSL_BYTECODE_H */