diff --git a/SLS_C/src/repl.c b/SLS_C/src/repl.c index 8c39e4c..18f13c6 100644 --- a/SLS_C/src/repl.c +++ b/SLS_C/src/repl.c @@ -12,6 +12,7 @@ #include "sls/errors.h" #include "sls/lexer.h" #include "sls/string.h" +#include "sls/interpreter.h" static const size_t BUFFER_SIZE = 256; static const SlsStr REPL_FILE_NAME = SLS_STR_CONST(""); @@ -25,11 +26,16 @@ int repl(int argc, char *argv[]) { printf("Type `#exit` to exit.\n"); LexerInfo lexer_info; + InterpreterState *interpreter_state = interpreter_create(); char buf[BUFFER_SIZE]; while (fgets(buf, sizeof buf, stdin)) { size_t len = strlen(buf); if (len && buf[len - 1] == '\n') buf[len - 1] = '\0'; - if (strncmp("#exit", buf, BUFFER_SIZE) == 0) return 0; + if (strncmp("#exit", buf, BUFFER_SIZE) == 0) { + interpreter_delete(interpreter_state); + return 0; + } + SlsStr code = sls_str_malloc(buf, BUFFER_SIZE); init_lexer(&lexer_info, REPL_FILE_NAME, code); LexerResult result = lexical_analysis(&lexer_info); @@ -38,15 +44,17 @@ int repl(int argc, char *argv[]) { } else { LexerTokenResult *head = result.result; while (head) { - if (head->type == SLS_ERROR) + if (head->type == SLS_ERROR) { printf("%s\n", head->error.message.str); - else - printf("%s\n", TOKEN_TYPES_NAMES[head->result.type]); + break; + } else + execute(interpreter_state, head); head = head->next; } } sls_str_free(&code); } + interpreter_delete(interpreter_state); return 1; }