aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-01-23 03:09:54 +0100
committerdec05eba <dec05eba@protonmail.com>2020-01-23 03:09:54 +0100
commitcc30a97ab90a8fa40707936d3d089d81c49559b6 (patch)
treec6544b785395cf12b8c9f4c65c3f8ebb9699232d /include
parentb7f056a73ad4053eb2284c54873dfb3888dcb430 (diff)
Add bytecode decoding.. starting on program execution now
Diffstat (limited to 'include')
-rw-r--r--include/bytecode.h30
-rw-r--r--include/parser.h7
-rw-r--r--include/program.h22
-rw-r--r--include/std/buffer.h1
4 files changed, 45 insertions, 15 deletions
diff --git a/include/bytecode.h b/include/bytecode.h
index a194517..06ebf19 100644
--- a/include/bytecode.h
+++ b/include/bytecode.h
@@ -29,40 +29,42 @@ typedef enum {
} TslOpcode;
typedef struct {
- TslBuffer buffer;
-} TslBytecodeWriter;
+ TslBuffer /*TslInstruction*/ buffer;
+} TslBytecode;
typedef struct {
- TslOpcodeType opcode;
+ TslOpcode opcode;
int value;
} TslInstructionType1;
typedef struct {
- TslOpcodeType opcode;
+ TslOpcode opcode;
double value;
} TslInstructionType2;
typedef struct {
- TslOpcodeType opcode;
+ TslOpcode opcode;
TslBool value;
} TslInstructionType3;
typedef struct {
- TslOpcodeType opcode;
+ TslOpcode opcode;
TslStringView value;
} TslInstructionType4;
typedef struct {
- TslOpcodeType opcode;
+ TslOpcode opcode;
} TslInstructionType5;
-void tsl_bytecode_writer_init(TslBytecodeWriter *self);
-void tsl_bytecode_writer_deinit(TslBytecodeWriter *self);
+const char* tsl_opcode_to_string(TslOpcode opcode);
-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);
+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 */
diff --git a/include/parser.h b/include/parser.h
index b915dfd..440fbac 100644
--- a/include/parser.h
+++ b/include/parser.h
@@ -2,12 +2,17 @@
#define TSL_PARSER_H
#include "tokenizer.h"
+#include "program.h"
typedef enum {
TSL_PARSE_RESULT_ERR,
TSL_PARSE_RESULT_OK
} TslParseResult;
-TslParseResult tsl_parse(const char *code, size_t code_size);
+/*
+ TODO: Make this function load a file instead of parsing memory.
+ This is needed because when using @import function instead tsl, it will load a file anyways.
+*/
+TslParseResult tsl_parse(const char *code, size_t code_size, TslProgram *program_output);
#endif /* TSL_PARSER_H */
diff --git a/include/program.h b/include/program.h
new file mode 100644
index 0000000..6135726
--- /dev/null
+++ b/include/program.h
@@ -0,0 +1,22 @@
+#ifndef TSL_PROGRAM_H
+#define TSL_PROGRAM_H
+
+#include "std/buffer.h"
+#include "std/hash_map.h"
+
+typedef struct {
+ TslBuffer /*TslBytecode*/ function_bytecode_list;
+ TslHashMap variables;
+} TslProgram;
+
+typedef enum {
+ TSL_PROGRAM_RESULT_ERR,
+ TSL_PROGRAM_RESULT_OK
+} TslProgramResult;
+
+void tsl_program_init(TslProgram *self);
+void tsl_program_deinit(TslProgram *self);
+
+TslProgramResult tsl_program_run(TslProgram *self);
+
+#endif /* TSL_PROGRAM_H */
diff --git a/include/std/buffer.h b/include/std/buffer.h
index b7224e9..3aad48b 100644
--- a/include/std/buffer.h
+++ b/include/std/buffer.h
@@ -21,5 +21,6 @@ int tsl_buffer_append(TslBuffer *self, const void *data, size_t size);
void tsl_buffer_pop(TslBuffer *self, size_t size);
void* tsl_buffer_begin(TslBuffer *self);
void* tsl_buffer_end(TslBuffer *self);
+void tsl_buffer_move(TslBuffer *dst, TslBuffer *src);
#endif /* TSL_BUFFER_H */