blob: b0c014eb85815e7216190accad3ba389588a6c83 [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;
swissChili7e1393c2021-07-07 12:59:12 -070015 struct environment *env = compile_file(argv[1], &ok);
swissChili923b5362021-05-09 20:31:43 -070016
swissChilif68671f2021-07-05 14:14:44 -070017 if (!ok)
swissChili923b5362021-05-09 20:31:43 -070018 {
19 fprintf(stderr, "Could not open %s\n", argv[1]);
20 return 1;
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
35 free_all();
swissChili7e1393c2021-07-07 12:59:12 -070036 del_env(env);
swissChili7a6f5eb2021-04-13 16:46:02 -070037}