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 | 7a6f5eb | 2021-04-13 16:46:02 -0700 | [diff] [blame] | 4 | |
swissChili | 53472e8 | 2021-05-08 16:06:32 -0700 | [diff] [blame] | 5 | int main(int argc, char **argv) |
swissChili | 7a6f5eb | 2021-04-13 16:46:02 -0700 | [diff] [blame] | 6 | { |
swissChili | 53472e8 | 2021-05-08 16:06:32 -0700 | [diff] [blame] | 7 | if (argc < 2) |
swissChili | bed8092 | 2021-04-13 21:58:05 -0700 | [diff] [blame] | 8 | { |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 9 | puts("pass the program you want to run as the first argument please"); |
swissChili | bed8092 | 2021-04-13 21:58:05 -0700 | [diff] [blame] | 10 | return 1; |
11 | } | ||||
12 | |||||
swissChili | 923b536 | 2021-05-09 20:31:43 -0700 | [diff] [blame] | 13 | struct istream *is = new_fistream(argv[1], false); |
14 | |||||
15 | if (is == NULL) | ||||
16 | { | ||||
17 | fprintf(stderr, "Could not open %s\n", argv[1]); | ||||
18 | return 1; | ||||
19 | } | ||||
swissChili | 7a6f5eb | 2021-04-13 16:46:02 -0700 | [diff] [blame] | 20 | |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 21 | struct environment env = compile_all(is); |
22 | value_t (*lisp_main)() = find_function(&env, "main")->def0; | ||||
23 | |||||
24 | gc_set_base_here(); | ||||
25 | lisp_main(); | ||||
swissChili | b8fd471 | 2021-06-23 15:32:04 -0700 | [diff] [blame] | 26 | |
27 | free_all(); | ||||
swissChili | 708d4c4 | 2021-07-04 17:40:07 -0700 | [diff] [blame^] | 28 | del_env(&env); |
29 | del_fistream(is); | ||||
swissChili | 7a6f5eb | 2021-04-13 16:46:02 -0700 | [diff] [blame] | 30 | } |