2019-08-09 12:00:17 -04:00
|
|
|
#include <assert.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <stdarg.h>
|
2019-08-09 16:25:20 -04:00
|
|
|
#include <stdint.h>
|
2019-08-09 13:14:42 -04:00
|
|
|
#include <stdio.h>
|
2010-05-02 14:17:47 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2019-08-09 12:00:17 -04:00
|
|
|
|
|
|
|
#include "dtypes.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "utf8.h"
|
|
|
|
#include "ios.h"
|
|
|
|
#include "socket.h"
|
|
|
|
#include "timefuncs.h"
|
|
|
|
#include "hashing.h"
|
|
|
|
#include "htable.h"
|
|
|
|
#include "htableh_inc.h"
|
|
|
|
#include "bitvector.h"
|
2019-08-09 16:12:19 -04:00
|
|
|
#include "fs.h"
|
2019-08-09 12:00:17 -04:00
|
|
|
#include "random.h"
|
2010-05-02 14:17:47 -04:00
|
|
|
#include "llt.h"
|
2019-08-09 12:00:17 -04:00
|
|
|
|
2010-05-02 14:17:47 -04:00
|
|
|
#include "flisp.h"
|
|
|
|
|
|
|
|
static value_t argv_list(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int i;
|
2019-08-09 07:02:02 -04:00
|
|
|
value_t lst = FL_NIL, temp;
|
2010-05-02 14:17:47 -04:00
|
|
|
fl_gc_handle(&lst);
|
|
|
|
fl_gc_handle(&temp);
|
2019-08-09 07:02:02 -04:00
|
|
|
for (i = argc - 1; i >= 0; i--) {
|
2010-05-02 14:17:47 -04:00
|
|
|
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];
|
2019-08-09 13:14:42 -04:00
|
|
|
const char *bootfile = "flisp.boot";
|
2010-05-02 14:17:47 -04:00
|
|
|
|
2019-08-09 07:02:02 -04:00
|
|
|
fl_init(512 * 1024);
|
2010-05-02 14:17:47 -04:00
|
|
|
|
|
|
|
fname_buf[0] = '\0';
|
|
|
|
value_t str = symbol_value(symbol("*install-dir*"));
|
|
|
|
char *exedir = (str == UNBOUND ? NULL : cvalue_data(str));
|
2019-08-09 13:14:42 -04:00
|
|
|
if (exedir == NULL) {
|
|
|
|
snprintf(fname_buf, sizeof(fname_buf), "%s", bootfile);
|
|
|
|
} else {
|
2019-08-09 16:12:19 -04:00
|
|
|
snprintf(fname_buf, sizeof(fname_buf), "%s/%s", exedir, bootfile);
|
2010-05-02 14:17:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
value_t args[2];
|
|
|
|
fl_gc_handle(&args[0]);
|
|
|
|
fl_gc_handle(&args[1]);
|
2019-08-09 07:02:02 -04:00
|
|
|
FL_TRY_EXTERN
|
|
|
|
{
|
2010-05-02 14:17:47 -04:00
|
|
|
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));
|
|
|
|
}
|
2019-08-09 07:02:02 -04:00
|
|
|
FL_CATCH_EXTERN
|
|
|
|
{
|
2010-05-02 14:17:47 -04:00
|
|
|
ios_puts("fatal error:\n", ios_stderr);
|
|
|
|
fl_print(ios_stderr, fl_lasterror);
|
|
|
|
ios_putc('\n', ios_stderr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|