aboutsummaryrefslogtreecommitdiff
path: root/src/repl.c
diff options
context:
space:
mode:
authorFlavian Kaufmann <flavian@flaviankaufmann.ch>2025-05-25 15:54:50 +0200
committerFlavian Kaufmann <flavian@flaviankaufmann.ch>2025-05-25 15:54:50 +0200
commit330e46236b421ffb8fe263caf91196f4cd1114c5 (patch)
tree09b3df77fca2d23dacef64f6962e9a1afd5b4d29 /src/repl.c
parentde59dbd1773dff06051b7b604977bcb2803ada4f (diff)
downloadimp-330e46236b421ffb8fe263caf91196f4cd1114c5.tar.gz
imp-330e46236b421ffb8fe263caf91196f4cd1114c5.zip
[cleanup] codebase cleanup
Diffstat (limited to 'src/repl.c')
-rw-r--r--src/repl.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/repl.c b/src/repl.c
index 199c110..b553aec 100644
--- a/src/repl.c
+++ b/src/repl.c
@@ -8,7 +8,8 @@
#include <readline/readline.h>
#include <readline/history.h>
-#include "interpreter.h"
+#include "interpreter_context.h"
+#include "driver.h"
static void print_help(void) {
@@ -31,7 +32,7 @@ static int is_valid_identifier(const char *var) {
return 1;
}
-static void repl_exec_command(context_t context, char *command) {
+static void repl_exec_command(IMP_InterpreterContext *context, char *command) {
char *cmd = strtok(command, " \t");
if (strcmp(cmd, "%quit") == 0) {
exit(EXIT_SUCCESS);
@@ -40,7 +41,8 @@ static void repl_exec_command(context_t context, char *command) {
} else if (strcmp(cmd, "%run") == 0) {
char *file = strtok(NULL, " \t");
if (file) {
- if (!interp_file(context, file)) context_print_var_table(context);
+ if (!imp_driver_interpret_file(context, file)) imp_driver_print_var_table(context);
+ else fprintf(stderr, "Error interpreting file: %s\n", file);
} else {
fprintf(stderr, "Usage: %%run <path/to/file.imp>\n");
}
@@ -49,7 +51,7 @@ static void repl_exec_command(context_t context, char *command) {
char *val = strtok(NULL, " \t");
if (var && val) {
if (is_valid_identifier(var)) {
- context_set_var(context, var, atoi(val));
+ imp_interpreter_context_var_set(context, var, atoi(val));
} else {
fprintf(stderr, "Invalid variable name: %s\n", var);
}
@@ -58,28 +60,28 @@ static void repl_exec_command(context_t context, char *command) {
char *var = strtok(NULL, " \t");
if (var) {
if (is_valid_identifier(var)) {
- printf("%s = %d\n", var, context_get_var(context, var));
+ printf("%s = %d\n", var, imp_interpreter_context_var_get(context, var));
} else {
fprintf(stderr, "Invalid variable name: %s\n", var);
}
- } else context_print_var_table(context);
+ } else imp_driver_print_var_table(context);
} else if (strcmp(cmd, "%procedures") == 0) {
- context_print_proc_table(context);
+ imp_driver_print_proc_table(context);
} else {
fprintf(stderr, "Unknown command: %s\n", cmd);
}
}
-static void repl_exec_statement(context_t context, const char *statement) {
- if (interp_str(context, statement)) {
+static void repl_exec_statement(IMP_InterpreterContext *context, const char *statement) {
+ if (imp_driver_interpret_str(context, statement)) {
fprintf(stderr, "Error interpreting statement: %s\n", statement);
return;
}
- context_print_var_table(context);
+ imp_driver_print_var_table(context);
}
-void repl(void) {
- context_t context = context_create();
+void imp_repl(void) {
+ IMP_InterpreterContext *context = imp_interpreter_context_create();
char *line;
print_help();
@@ -91,5 +93,5 @@ void repl(void) {
}
printf("\n");
- context_free(context);
+ imp_interpreter_context_destroy(context);
} \ No newline at end of file