swissChili | f3e7f18 | 2021-04-20 13:57:22 -0700 | [diff] [blame] | 1 | #include "compiler.h" |
swissChili | 53472e8 | 2021-05-08 16:06:32 -0700 | [diff] [blame] | 2 | #include "lisp.h" |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 3 | #include "gc.h" |
swissChili | f68671f | 2021-07-05 14:14:44 -0700 | [diff] [blame] | 4 | #include "plat/plat.h" |
swissChili | 7a6f5eb | 2021-04-13 16:46:02 -0700 | [diff] [blame] | 5 | |
swissChili | 53472e8 | 2021-05-08 16:06:32 -0700 | [diff] [blame] | 6 | int main(int argc, char **argv) |
swissChili | 7a6f5eb | 2021-04-13 16:46:02 -0700 | [diff] [blame] | 7 | { |
swissChili | 53472e8 | 2021-05-08 16:06:32 -0700 | [diff] [blame] | 8 | if (argc < 2) |
swissChili | bed8092 | 2021-04-13 21:58:05 -0700 | [diff] [blame] | 9 | { |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 10 | puts("pass the program you want to run as the first argument please"); |
swissChili | bed8092 | 2021-04-13 21:58:05 -0700 | [diff] [blame] | 11 | return 1; |
12 | } | ||||
13 | |||||
swissChili | f68671f | 2021-07-05 14:14:44 -0700 | [diff] [blame] | 14 | bool ok; |
swissChili | 6d02af4 | 2021-08-05 19:49:01 -0700 | [diff] [blame] | 15 | struct environment *env = NULL; |
16 | struct error compile_error; | ||||
17 | if (!IS_OKAY((compile_error = compile_file(argv[1], &env)))) | ||||
swissChili | 923b536 | 2021-05-09 20:31:43 -0700 | [diff] [blame] | 18 | { |
swissChili | 6d02af4 | 2021-08-05 19:49:01 -0700 | [diff] [blame] | 19 | ereport(compile_error); |
20 | goto done; | ||||
21 | } | ||||
swissChili | 7a6f5eb | 2021-04-13 16:46:02 -0700 | [diff] [blame] | 22 | |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 23 | struct function *lisp_main_f = find_function(env, "main"); |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 24 | |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 25 | if (lisp_main_f) |
swissChili | 53e7cd1 | 2021-08-02 21:55:53 -0700 | [diff] [blame] | 26 | { |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 27 | value_t (*lisp_main)() = lisp_main_f->def0; |
swissChili | 53e7cd1 | 2021-08-02 21:55:53 -0700 | [diff] [blame] | 28 | gc_set_base_here(); |
29 | lisp_main(); | ||||
30 | } | ||||
31 | else | ||||
32 | { | ||||
33 | fprintf(stderr, "No MAIN function defined! nothing to do\n"); | ||||
34 | } | ||||
swissChili | b8fd471 | 2021-06-23 15:32:04 -0700 | [diff] [blame] | 35 | |
swissChili | 6d02af4 | 2021-08-05 19:49:01 -0700 | [diff] [blame] | 36 | done: |
swissChili | b8fd471 | 2021-06-23 15:32:04 -0700 | [diff] [blame] | 37 | free_all(); |
swissChili | 6d02af4 | 2021-08-05 19:49:01 -0700 | [diff] [blame] | 38 | if (env) |
39 | del_env(env); | ||||
swissChili | 7a6f5eb | 2021-04-13 16:46:02 -0700 | [diff] [blame] | 40 | } |