blob: f6c999c8648985c93c30b86f760b911fd5c38a82 [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"
swissChili9d428a82022-08-01 20:47:40 -07005#include "lib/std.h"
6#include <stdlib.h>
swissChili7a6f5eb2021-04-13 16:46:02 -07007
swissChili53472e82021-05-08 16:06:32 -07008int main(int argc, char **argv)
swissChili7a6f5eb2021-04-13 16:46:02 -07009{
swissChili80560312022-07-31 21:05:47 -070010 gc_push_segment(NULL, 0);
11
swissChili6d02af42021-08-05 19:49:01 -070012 struct environment *env = NULL;
13 struct error compile_error;
swissChili9d428a82022-08-01 20:47:40 -070014
15 if (argc < 2)
swissChili923b5362021-05-09 20:31:43 -070016 {
swissChili9d428a82022-08-01 20:47:40 -070017 env = malloc(sizeof(struct environment));
18 env->first = NULL;
19 env->first_loaded = NULL;
20
21 if (!IS_OKAY((compile_error = load_std(env))))
22 {
23 ereport(compile_error);
24 goto done;
25 }
26
27 if (!load_library(env, "repl"))
28 goto done;
swissChilic0acce42022-07-31 13:38:17 -070029 }
swissChili9d428a82022-08-01 20:47:40 -070030 else
31 {
32 if (!IS_OKAY((compile_error = compile_file(argv[1], &env))))
33 {
34 ereport(compile_error);
35 goto done;
36 }
37 }
38
swissChili36f2c692021-08-08 14:31:44 -070039 struct function *lisp_main_f = find_function(env, "main");
swissChilie9fec8b2021-06-22 13:59:33 -070040
swissChili36f2c692021-08-08 14:31:44 -070041 if (lisp_main_f)
swissChili53e7cd12021-08-02 21:55:53 -070042 {
swissChili36f2c692021-08-08 14:31:44 -070043 value_t (*lisp_main)() = lisp_main_f->def0;
swissChili80560312022-07-31 21:05:47 -070044 gc_prepare_call(0);
swissChili53e7cd12021-08-02 21:55:53 -070045 lisp_main();
46 }
47 else
48 {
49 fprintf(stderr, "No MAIN function defined! nothing to do\n");
50 }
swissChilib8fd4712021-06-23 15:32:04 -070051
swissChili6d02af42021-08-05 19:49:01 -070052done:
swissChilib8fd4712021-06-23 15:32:04 -070053 free_all();
swissChili6d02af42021-08-05 19:49:01 -070054 if (env)
55 del_env(env);
swissChili16156be2022-07-31 21:14:02 -070056 gc_pop_segment();
swissChili7a6f5eb2021-04-13 16:46:02 -070057}