Worked on code execution
This commit is contained in:
parent
521bd9907a
commit
0bbb43d5a3
|
|
@ -57,7 +57,7 @@ typedef struct {
|
|||
HashTable *functions;
|
||||
} InterpreterState;
|
||||
|
||||
void execute(InterpreterState *interpreter_state, LexerTokenResult *token);
|
||||
Boolean execute(InterpreterState *interpreter_state, LexerTokenResult *token);
|
||||
InterpreterState *interpreter_create();
|
||||
void interpreter_delete(InterpreterState *interpreter_state);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
// Interpreter
|
||||
// November 2025
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "sls/string.h"
|
||||
#include "sls/interpreter.h"
|
||||
#include "sls/lexer.h"
|
||||
|
|
@ -37,10 +39,21 @@ static TokenString *hash_table_get_funcs(const HashTable *ht, SlsStr key, TokenS
|
|||
return (TokenString*)hash_table_get(ht, key, (void *)default_item);
|
||||
}
|
||||
|
||||
void execute(InterpreterState *interpreter_state, LexerTokenResult *token) {
|
||||
static Boolean push_token(InterpreterState *interpreter_state, Token token) {
|
||||
|
||||
}
|
||||
|
||||
static Boolean execute_func(InterpreterState *interpreter_state, SlsStr key) {
|
||||
|
||||
}
|
||||
|
||||
Boolean execute(InterpreterState *interpreter_state, LexerTokenResult *token) {
|
||||
if (token->result.type == TOKEN_IDENTIFIER && !token->result.identifier.is_literal)
|
||||
return execute_func(interpreter_state, token->result.identifier.name);
|
||||
else
|
||||
return push_token(interpreter_state, token->result);
|
||||
}
|
||||
|
||||
InterpreterState *interpreter_create() {
|
||||
InterpreterState *interpreter_state = (InterpreterState *)malloc(sizeof(InterpreterState));
|
||||
interpreter_state->stack = NULL;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,10 @@ int repl(int argc, char *argv[]) {
|
|||
printf("%s\n", head->error.message.str);
|
||||
break;
|
||||
} else
|
||||
execute(interpreter_state, head);
|
||||
if (!execute(interpreter_state, head)) {
|
||||
printf("A runtime error occurred!");
|
||||
break;
|
||||
}
|
||||
head = head->next;
|
||||
}
|
||||
clean_token_result(result.result);
|
||||
|
|
|
|||
Loading…
Reference in New Issue