blob: f78b3b129f57e5769fba3afcbc4acbee842e5236 [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
swissChili36f2c692021-08-08 14:31:44 -070023 struct function *lisp_main_f = find_function(env, "main");
swissChilie9fec8b2021-06-22 13:59:33 -070024
swissChili36f2c692021-08-08 14:31:44 -070025 if (lisp_main_f)
swissChili53e7cd12021-08-02 21:55:53 -070026 {
swissChili36f2c692021-08-08 14:31:44 -070027 value_t (*lisp_main)() = lisp_main_f->def0;
swissChili53e7cd12021-08-02 21:55:53 -070028 gc_set_base_here();
29 lisp_main();
30 }
31 else
32 {
33 fprintf(stderr, "No MAIN function defined! nothing to do\n");
34 }
swissChilib8fd4712021-06-23 15:32:04 -070035
swissChili6d02af42021-08-05 19:49:01 -070036done:
swissChilib8fd4712021-06-23 15:32:04 -070037 free_all();
swissChili6d02af42021-08-05 19:49:01 -070038 if (env)
39 del_env(env);
swissChili7a6f5eb2021-04-13 16:46:02 -070040}