-
Notifications
You must be signed in to change notification settings - Fork 119
/
flmain.c
64 lines (56 loc) · 1.49 KB
/
flmain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "llt.h"
#include "flisp.h"
static value_t argv_list(int argc, char *argv[])
{
int i;
value_t lst=FL_NIL, temp;
fl_gc_handle(&lst);
fl_gc_handle(&temp);
for(i=argc-1; i >= 0; i--) {
temp = cvalue_static_cstring(argv[i]);
lst = fl_cons(temp, lst);
}
fl_free_gc_handles(2);
return lst;
}
extern value_t fl_file(value_t *args, uint32_t nargs);
int main(int argc, char *argv[])
{
char fname_buf[1024];
fl_init(512*1024);
fname_buf[0] = '\0';
#ifdef INITFILE
strcat(fname_buf, INITFILE);
#else
value_t str = symbol_value(symbol("*install-dir*"));
char *exedir = (str == UNBOUND ? NULL : cvalue_data(str));
if (exedir != NULL) {
strcat(fname_buf, exedir);
strcat(fname_buf, PATHSEPSTRING);
}
strcat(fname_buf, "flisp.boot");
#endif
value_t args[2];
fl_gc_handle(&args[0]);
fl_gc_handle(&args[1]);
FL_TRY_EXTERN {
args[0] = cvalue_static_cstring(fname_buf);
args[1] = symbol(":read");
value_t f = fl_file(&args[0], 2);
fl_free_gc_handles(2);
if (fl_load_system_image(f))
return 1;
(void)fl_applyn(1, symbol_value(symbol("__start")),
argv_list(argc, argv));
}
FL_CATCH_EXTERN {
ios_puts("fatal error:\n", ios_stderr);
fl_print(ios_stderr, fl_lasterror);
ios_putc('\n', ios_stderr);
return 1;
}
return 0;
}