blob: 2a37b4c819ac2460786d594e04902f66aa6e41dc [file] [log] [blame]
swissChilif3e7f182021-04-20 13:57:22 -07001#include "compiler.h"
swissChilie9fec8b2021-06-22 13:59:33 -07002#include "gc.h"
swissChilic0acce42022-07-31 13:38:17 -07003#include "lisp.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{
swissChili80560312022-07-31 21:05:47 -07008 gc_push_segment(NULL, 0);
9
swissChili53472e82021-05-08 16:06:32 -070010 if (argc < 2)
swissChilibed80922021-04-13 21:58:05 -070011 {
swissChilie9fec8b2021-06-22 13:59:33 -070012 puts("pass the program you want to run as the first argument please");
swissChilibed80922021-04-13 21:58:05 -070013 return 1;
14 }
15
swissChilif68671f2021-07-05 14:14:44 -070016 bool ok;
swissChili6d02af42021-08-05 19:49:01 -070017 struct environment *env = NULL;
18 struct error compile_error;
19 if (!IS_OKAY((compile_error = compile_file(argv[1], &env))))
swissChili923b5362021-05-09 20:31:43 -070020 {
swissChili6d02af42021-08-05 19:49:01 -070021 ereport(compile_error);
22 goto done;
swissChilic0acce42022-07-31 13:38:17 -070023 }
swissChili7a6f5eb2021-04-13 16:46:02 -070024
swissChili36f2c692021-08-08 14:31:44 -070025 struct function *lisp_main_f = find_function(env, "main");
swissChilie9fec8b2021-06-22 13:59:33 -070026
swissChili36f2c692021-08-08 14:31:44 -070027 if (lisp_main_f)
swissChili53e7cd12021-08-02 21:55:53 -070028 {
swissChili36f2c692021-08-08 14:31:44 -070029 value_t (*lisp_main)() = lisp_main_f->def0;
swissChili80560312022-07-31 21:05:47 -070030 gc_prepare_call(0);
swissChili53e7cd12021-08-02 21:55:53 -070031 lisp_main();
32 }
33 else
34 {
35 fprintf(stderr, "No MAIN function defined! nothing to do\n");
36 }
swissChilib8fd4712021-06-23 15:32:04 -070037
swissChili6d02af42021-08-05 19:49:01 -070038done:
swissChilib8fd4712021-06-23 15:32:04 -070039 free_all();
swissChili6d02af42021-08-05 19:49:01 -070040 if (env)
41 del_env(env);
swissChili7a6f5eb2021-04-13 16:46:02 -070042}