From b7f056a73ad4053eb2284c54873dfb3888dcb430 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 22 Jan 2020 19:14:06 +0100 Subject: Correctly parse and produce bytecode for example --- include/bytecode.h | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'include/bytecode.h') diff --git a/include/bytecode.h b/include/bytecode.h index 6ce1dc9..a194517 100644 --- a/include/bytecode.h +++ b/include/bytecode.h @@ -9,9 +9,23 @@ typedef uint8_t TslOpcodeType; typedef enum { - TSL_OPCODE_LOAD_NUMBER, - TSL_OPCODE_LOAD_BOOL, - TSL_OPCODE_SETV + 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 { @@ -19,25 +33,36 @@ typedef struct { } TslBytecodeWriter; typedef struct { - double number; TslOpcodeType opcode; + int value; } TslInstructionType1; typedef struct { - TslBool value; TslOpcodeType opcode; + double value; } TslInstructionType2; typedef struct { - TslStringView key; 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_loadn(TslBytecodeWriter *self, double number); -int tsl_bytecode_writer_loadb(TslBytecodeWriter *self, TslBool value); -int tsl_bytecode_writer_setv(TslBytecodeWriter *self, TslStringView *key); +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 */ -- cgit v1.2.3