| 1 |
#include <stdlib.h> |
| 2 |
#include <ecl/ecl.h> |
| 3 |
#if ANDROID |
| 4 |
#include <android/log.h> |
| 5 |
#endif |
| 6 |
|
| 7 |
#if ANDROID |
| 8 |
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__)) |
| 9 |
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "native-activity", __VA_ARGS__)) |
| 10 |
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "native-activity", __VA_ARGS__)) |
| 11 |
#define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, "native-activity", __VA_ARGS__)) |
| 12 |
#else |
| 13 |
#define LOGI(...) |
| 14 |
#define LOGW(...) |
| 15 |
#define LOGE(...) |
| 16 |
#endif |
| 17 |
|
| 18 |
#include "ecl_boot.h" |
| 19 |
|
| 20 |
#ifdef __cplusplus |
| 21 |
#define ECL_CPP_TAG "C" |
| 22 |
#else |
| 23 |
#define ECL_CPP_TAG |
| 24 |
#endif |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
; |
| 32 |
|
| 33 |
extern void loadLispFromAssets(char* fn); |
| 34 |
|
| 35 |
int ecl_boot(const char *root_dir) |
| 36 |
{ |
| 37 |
char *ecl = "ecl"; |
| 38 |
char tmp[2048]; |
| 39 |
|
| 40 |
LOGI("ECL boot beginning\n"); |
| 41 |
|
| 42 |
LOGI("Setting directories\n"); |
| 43 |
setenv("HOME", root_dir, 1); |
| 44 |
|
| 45 |
sprintf(tmp, "%s/lib/", root_dir); |
| 46 |
setenv("ECLDIR", tmp, 1); |
| 47 |
|
| 48 |
sprintf(tmp, "%s/etc/", root_dir); |
| 49 |
setenv("ETC", tmp, 1); |
| 50 |
|
| 51 |
sprintf(tmp, "%s/home/", root_dir); |
| 52 |
setenv("HOME", tmp, 1); |
| 53 |
|
| 54 |
LOGI("Directories set\n"); |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
cl_boot(1, &ecl); |
| 66 |
|
| 67 |
LOGI("installing bytecodes compiler\n"); |
| 68 |
si_safe_eval(3, c_string_to_object("(si:install-bytecodes-compiler)"), ECL_NIL, OBJNULL); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
LOGI("writing some info to stdout\n"); |
| 77 |
si_safe_eval |
| 78 |
(3, c_string_to_object |
| 79 |
("(format t \"ECL_BOOT, features = ~A ~%\" *features*)"), |
| 80 |
Cnil, OBJNULL); |
| 81 |
si_safe_eval |
| 82 |
(3, c_string_to_object |
| 83 |
("(format t \"(truename SYS:): ~A)\" (truename \"SYS:\"))"), |
| 84 |
Cnil, OBJNULL); |
| 85 |
|
| 86 |
ecl_toplevel(root_dir); |
| 87 |
return 0; |
| 88 |
} |
| 89 |
|
| 90 |
void ecl_toplevel(const char *home) |
| 91 |
{ |
| 92 |
char tmp[2048]; |
| 93 |
|
| 94 |
LOGI("Executing the init scripts\n"); |
| 95 |
|
| 96 |
CL_CATCH_ALL_BEGIN(ecl_process_env()) |
| 97 |
{ |
| 98 |
sprintf(tmp, "(setq *default-pathname-defaults* #p\"%s/\")", home); |
| 99 |
si_safe_eval(3, c_string_to_object(tmp), Cnil, OBJNULL); |
| 100 |
si_select_package(ecl_make_simple_base_string("CL-USER", 7)); |
| 101 |
si_safe_eval(3, c_string_to_object("(load \"etc/init\")"), Cnil, OBJNULL); |
| 102 |
} CL_CATCH_ALL_END; |
| 103 |
|
| 104 |
LOGI("Toplevel initialization done\n"); |
| 105 |
} |