scripting: Added stubs fro scripting vm
authorLukas Krickl <lukas@krickl.dev>
Sun, 8 Mar 2026 11:44:19 +0000 (12:44 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sun, 8 Mar 2026 11:44:19 +0000 (12:44 +0100)
src/l_lsl.h

index d2a3a30c48b9dbb42fa8e2ba22b774fd57ec11e6..4e21daf671320d00b7f1fdc67746e6795ab6ce29 100644 (file)
@@ -81,12 +81,97 @@ enum l_lsl_flags {
        L_LSL_F_NONE = 0
 };
 
+enum l_lsl_data_type {
+       L_LSL_TYPE_INT,
+       L_LSL_TYPE_STRING,
+       L_LSL_TYPE_TABLE,
+       L_LSL_FUNCTION
+};
+
+enum l_lsl_error {
+       L_LSL_ERR_OK = 0
+};
+
+/* all string constants are stored in this string table.
+ * strings should be unique and deduplicated */
+struct l_lsl_strings {
+       const char **strings;
+       u32 index;
+       u32 max_len;
+};
+
+/* a table entry is a single value
+ * of a specific data type */
+struct l_lsl_tableent {
+       /* string table entry */
+       u32 name;
+       enum l_lsl_data_type type;
+       
+};
+
+/* 
+ * a table is a mapping of 
+ * names to values
+ * table entries can contain more tables
+ */
+struct l_lsl_table {
+       u32 index;
+       u32 max_len;
+       struct l_lsl_tableent *entries;
+       struct l_lsl_table *parent;
+};
+
+/* list of all valid opcodes */
+enum l_lsl_op {
+       L_LSL_OP_NOP,
+       L_LSL_OP_ADD,
+       L_LSL_OP_SUB,
+       L_LSL_OP_MUL,
+       L_LSL_OP_DIV,
+
+       L_LSL_OP_RET,
+       L_LSL_OP_CALL
+};
+
+/* some opcodes might need data
+ * to perform their action 
+ * opcode data should not exceed 
+ * 32 bits
+ */
+union l_lsl_op_data {
+       /* string table index of function name to call */
+       u32 call;
+};
+
+struct l_lsl_instruction {
+       enum l_lsl_op opcode;
+       union l_lsl_op_data data;
+};
+
 struct l_lsl_vm {
+       enum l_lsl_error error;
        enum l_lsl_flags flags;
+
+       struct l_lsl_table global_table;
 };
 
+
 struct l_lsl_vm l_lsl_vm_init();
 
 void l_lsl_vm_free(struct l_lsl_vm *vm);
 
+/* 
+ * gets the next token returns tone's length in token_len
+ * the result token is placed into an interla string buffer and should not be modified 
+ * or saved.
+ */
+const char* l_lsl_next_token(const char *code, u32 len, u32 *token_len);
+
+/* compiles a program and places its byte code into the vm memory */
+enum l_lsl_error l_lsl_compile(struct l_lsl_vm *v, const char *code, u32 len);
+
+/* runs a program from a given entry point function
+ * if the entry point is NULL the global scope is executed */
+enum l_lsl_error l_lsl_run(struct l_lsl_vm *v, const char *entry);
+
 #endif