diff options
author | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2025-05-25 15:54:50 +0200 |
---|---|---|
committer | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2025-05-25 15:54:50 +0200 |
commit | 330e46236b421ffb8fe263caf91196f4cd1114c5 (patch) | |
tree | 09b3df77fca2d23dacef64f6962e9a1afd5b4d29 /src/main.c | |
parent | de59dbd1773dff06051b7b604977bcb2803ada4f (diff) | |
download | imp-330e46236b421ffb8fe263caf91196f4cd1114c5.tar.gz imp-330e46236b421ffb8fe263caf91196f4cd1114c5.zip |
[cleanup] codebase cleanup
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..5ef854d --- /dev/null +++ b/src/main.c @@ -0,0 +1,45 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "interpreter_context.h" +#include "driver.h" +#include "repl.h" + + +static int interpret_file(const char *path) { + IMP_InterpreterContext *context = imp_interpreter_context_create(); + if (imp_driver_interpret_file(context, path)) { + fprintf(stderr, "Error interpreting file: %s\n", path); + imp_interpreter_context_destroy(context); + return -1; + } + imp_driver_print_var_table(context); + imp_interpreter_context_destroy(context); + return 0; +} + +int main(int argc, char **argv) { + int opt; + while ((opt = getopt(argc, argv, "i:a:h")) != -1) { + switch (opt) { + case 'i': + return interpret_file(optarg) ? EXIT_FAILURE : EXIT_SUCCESS; + case 'a': + return imp_driver_print_ast_file(optarg) ? EXIT_FAILURE : EXIT_SUCCESS; + case 'h': + default: + fprintf(stderr, + "Usage: %s [ARGS]\n" + " (no args) start REPL\n" + " -i <program.imp> interpret program\n" + " -a <program.imp> print ast\n" + " -h print this message\n", + argv[0]); + return (opt == 'h') ? EXIT_SUCCESS : EXIT_FAILURE; + } + } + imp_repl(); + return EXIT_SUCCESS; +}
\ No newline at end of file |