blob: 07e6d4a3eac5f708e0fbee8cbf346767876f68d0 [file] [log] [blame]
swissChilif3e7f182021-04-20 13:57:22 -07001#include "compiler.h"
swissChili53472e82021-05-08 16:06:32 -07002#include "lisp.h"
swissChilie9fec8b2021-06-22 13:59:33 -07003#include "gc.h"
swissChilif68671f2021-07-05 14:14:44 -07004#include "plat/plat.h"
swissChili7a6f5eb2021-04-13 16:46:02 -07005
swissChili53472e82021-05-08 16:06:32 -07006int main(int argc, char **argv)
swissChili7a6f5eb2021-04-13 16:46:02 -07007{
swissChili53472e82021-05-08 16:06:32 -07008 if (argc < 2)
swissChilibed80922021-04-13 21:58:05 -07009 {
swissChilie9fec8b2021-06-22 13:59:33 -070010 puts("pass the program you want to run as the first argument please");
swissChilibed80922021-04-13 21:58:05 -070011 return 1;
12 }
13
swissChilif68671f2021-07-05 14:14:44 -070014 bool ok;
swissChili6d02af42021-08-05 19:49:01 -070015 struct environment *env = NULL;
16 struct error compile_error;
17 if (!IS_OKAY((compile_error = compile_file(argv[1], &env))))
swissChili923b5362021-05-09 20:31:43 -070018 {
swissChili6d02af42021-08-05 19:49:01 -070019 ereport(compile_error);
20 goto done;
21 }
swissChili7a6f5eb2021-04-13 16:46:02 -070022
swissChili7e1393c2021-07-07 12:59:12 -070023 value_t (*lisp_main)() = find_function(env, "main")->def0;
swissChilie9fec8b2021-06-22 13:59:33 -070024
swissChili53e7cd12021-08-02 21:55:53 -070025 if (lisp_main)
26 {
27 gc_set_base_here();
28 lisp_main();
29 }
30 else
31 {
32 fprintf(stderr, "No MAIN function defined! nothing to do\n");
33 }
swissChilib8fd4712021-06-23 15:32:04 -070034
swissChili6d02af42021-08-05 19:49:01 -070035done:
swissChilib8fd4712021-06-23 15:32:04 -070036 free_all();
swissChili6d02af42021-08-05 19:49:01 -070037 if (env)
38 del_env(env);
swissChili7a6f5eb2021-04-13 16:46:02 -070039}