aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-01-22 19:14:06 +0100
committerdec05eba <dec05eba@protonmail.com>2020-01-22 19:14:06 +0100
commitb7f056a73ad4053eb2284c54873dfb3888dcb430 (patch)
tree6d036345c5214390781d0019b46bf446e2190478 /include
parent840a3c6c5aa2400ce80d8ec7bb8b1a8d6e25770b (diff)
Correctly parse and produce bytecode for example
Diffstat (limited to 'include')
-rw-r--r--include/bytecode.h43
-rw-r--r--include/std/buffer.h2
2 files changed, 36 insertions, 9 deletions
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 */
diff --git a/include/std/buffer.h b/include/std/buffer.h
index db6474e..b7224e9 100644
--- a/include/std/buffer.h
+++ b/include/std/buffer.h
@@ -17,6 +17,8 @@ void tsl_buffer_init(TslBuffer *self);
void tsl_buffer_deinit(TslBuffer *self);
int tsl_buffer_append(TslBuffer *self, const void *data, size_t size);
+/* The buffer has to >= @size */
+void tsl_buffer_pop(TslBuffer *self, size_t size);
void* tsl_buffer_begin(TslBuffer *self);
void* tsl_buffer_end(TslBuffer *self);