21#include "YapStreams.h"
65X_API
bool YAP_initialized =
false;
66static int n_mdelays = 0;
70 GLOBAL_FAST_BOOT_FLAG = yap_init->FastBoot;
71#if defined(YAPOR) || defined(TABLING)
73 Yap_init_root_frames();
77 Yap_init_yapor_workers();
80 Yap_thread_self() != 0
85#if defined(YAPOR_COPY) || defined(YAPOR_SBA)
90 Yap_InitYaamRegs(worker_id,
false);
93 Yap_InitPreAllocCodeSpace(0);
96 CurrentModule = USER_MODULE;
97 P = GETWORK_FIRST_TIME;
98 Yap_exec_absmi(FALSE, YAP_EXEC_ABSMI);
99 Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
100 "abstract machine unexpected exit (YAP_Init)");
103 RECOVER_MACHINE_REGS();
105 if (yap_init->MaxStackSize) {
106 GLOBAL_AllowLocalExpansion = FALSE;
108 GLOBAL_AllowLocalExpansion = TRUE;
110 if (yap_init->MaxGlobalSize) {
111 GLOBAL_AllowGlobalExpansion = FALSE;
113 GLOBAL_AllowGlobalExpansion = TRUE;
115 if (yap_init->MaxTrailSize) {
116 GLOBAL_AllowTrailExpansion = FALSE;
118 GLOBAL_AllowTrailExpansion = TRUE;
120 if (yap_init->PrologRCFile) {
121 Yap_PutValue(AtomConsultOnBoot,
122 MkAtomTerm(Yap_LookupAtom(yap_init->PrologRCFile)));
127 setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG,
128 yap_init->HaltAfterBoot);
130 if (yap_init->PrologTopLevelGoal) {
131 Yap_PutValue(AtomTopLevelGoal,
132 MkAtomTerm(Yap_LookupAtom(yap_init->PrologTopLevelGoal)));
134 if (yap_init->PrologGoal) {
135 Yap_PutValue(AtomInitGoal,
136 MkAtomTerm(Yap_LookupAtom(yap_init->PrologGoal)));
138 if (yap_init->PrologAddPath) {
139 Yap_PutValue(AtomExtendFileSearchPath,
140 MkAtomTerm(Yap_LookupAtom(yap_init->PrologAddPath)));
143 if (yap_init->QuietMode) {
144 setBooleanLocalPrologFlag(VERBOSE_LOAD_FLAG,
false);
149const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR,
150 *Yap_PLDIR, *Yap_BOOTSTRAP, *Yap_COMMONSDIR, *Yap_INPUT_STARTUP,
151 *Yap_OUTPUT_STARTUP, *Yap_SOURCEBOOT, *Yap_INCLUDEDIR, *Yap_PLBOOTDIR;
158static bool load_file(
const char *b_file USES_REGS) {
160 int c_stream, osno, oactive;
162 Functor functor_query = Yap_MkFunctor(Yap_LookupAtom(
"?-"), 1);
163 Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(
":-"), 1);
164 Functor functor_compile2 = Yap_MkFunctor(Yap_LookupAtom(
"c_compile"), 1);
167 int lvl = push_text_stack();
169 char *full =
Malloc(MAX_PATH);
171 osno = Yap_CheckAlias(AtomLoopStream);
172 c_stream = YAP_InitConsult(YAP_BOOT_MODE, b_file, full, &oactive);
174 ANDROID_LOG_INFO,
"YAPDroid",
"done init_consult %s ",b_file);
176 fprintf(stderr,
"[ FATAL ERROR: could not open file %s\n", b_file);
180 if (!Yap_AddAlias(AtomLoopStream, c_stream)) {
185 ANDROID_LOG_INFO,
"YAPDroid",
"do reset %s ",b_file);
187 while (t != TermEof) {
189 LOCAL_RestartEnv = &e;
191 if (sigsetjmp(e,0) == 0) {
193 YAP_Reset(YAP_FULL_RESET,
false);
197 RESET_VARIABLE(vs+1);
201 if (t == TermEof || t == TermNil) {
204 fprintf(stderr,
"%s:" Int_FORMAT
" :0: error: SYNTAX ERROR\n",
205 b_file, GLOBAL_Stream[c_stream].linecount);
214 }
else if (IsVarTerm(t)) {
215 fprintf(stderr,
"%s:" Int_FORMAT
":0: error: unbound or NULL parser output\n\n",
217 GLOBAL_Stream[c_stream].linecount);
219 }
else if (IsApplTerm(t) &&
220 (FunctorOfTerm(t) == functor_query ||
221 FunctorOfTerm(t) == functor_command1)) {
223 if (IsApplTerm(t) && FunctorOfTerm(t) == functor_compile2) {
224 load_file(RepAtom(AtomOfTerm(ArgOfTerm(1, t)))->StrOfAE);
231 YAP_CompileClause(t);
237 (errd->
errorNo != YAP_NO_ERROR)) {
241 BACKUP_MACHINE_REGS();
242 YAP_EndConsult(c_stream, &osno, full);
247static const char * EOLIST =
"EOLINE";
248static bool is_install;
250static bool is_dir(
const char *path,
const void *info) {
254 if (Yap_isDirectory( path ))
256 char s[MAX_PATH + 1];
257 Int i = strlen(path);
258 strncpy(s, path, MAX_PATH);
260 if (Yap_dir_separator((
int)path[i]))
271 strcmp(info,s) == 0 ||
272 Yap_isDirectory( s );
275static bool is_file(
const char *path,
const void *info) {
278 return Yap_Exists( path );
281static bool is_wfile(
const char *path,
const void *info) {
286typedef bool testf(
const char *s,
const void *info);
291static const char *sel(
292 testf test,
const void *info,
const char *s1, ...) {
293 const char *fmt = s1;
295 char *buf = malloc(FILENAME_MAX + 1);
298 while (fmt != EOLIST) {
299 if (fmt == NULL || fmt[0]==
'\0') {
300 fmt = va_arg(ap,
const char *);
303 strncpy(buf, fmt, FILENAME_MAX);
304 if (test(buf,info)) {
305 buf = realloc(buf, strlen(buf) + 1);
309 fmt = va_arg(ap,
const char *);
318static const char *join(
const char *s0,
const char *s1) {
321 if (!s0 || s0[0] ==
'\0') {
327 if (!s1 || s1[0] ==
'\0')
330 char *buf = malloc(strlen(s0)+strlen(s1) + 2);
332 if (Yap_dir_separator(s0[strlen(s0)-1])) {
333 if (Yap_dir_separator(s1[0])) {
337 if (!Yap_dir_separator(s1[0]-1)) {
346 is_install= iap->install;
355 Yap_ROOTDIR = sel( is_dir, NULL,
357 getenv(
"YAPROOTDIR"),
358 join(getenv(
"DESTDIR"), YAP_ROOTDIR),
363 join(getenv(
"DESTDIR"), YAP_ROOTDIR),
364 join(getenv(
"DESTDIR"), join(getenv(
"ḦOME"),
".local")),
365 join(getenv(
"DESTDIR"),
"/usr/local"),
366 join(getenv(
"DESTDIR"),
"/usr"),
367 join(getenv(
"DESTDIR"),
"/opt"),
372 ANDROID_LOG_INFO,
"YAPDroid",
"Yap_ROOTDIR %s", Yap_ROOTDIR);
375 Yap_BINDIR = sel( is_dir, Yap_ROOTDIR, iap->BINDIR,
377#
if !defined(__ANDROID__)
378 join(getenv(
"DESTDIR"), YAP_BINDIR),
380 join(Yap_ROOTDIR,
"bin"),
384 Yap_LIBDIR = sel( is_dir, Yap_ROOTDIR, iap->LIBDIR,
385#
if !defined(__ANDROID__)
386 join(getenv(
"DESTDIR"), YAP_LIBDIR),
388 join(Yap_ROOTDIR,
"lib"),
392 Yap_DLLDIR = sel(is_dir, Yap_LIBDIR, iap->DLLDIR,
394 join(getenv(
"DESTDIR"), YAP_DLLDIR),
395 join(Yap_DLLDIR,
"Yap"),
399 Yap_INCLUDEDIR = sel(is_dir, Yap_ROOTDIR, iap->INCLUDEDIR,
400#
if !defined(__ANDROID__)
401 join(getenv(
"DESTDIR"), YAP_INCLUDEDIR),
403 join(Yap_ROOTDIR,
"include"),
408 Yap_SHAREDIR = sel( is_dir, Yap_ROOTDIR, iap->SHAREDIR,
409 getenv(
"YAPSHAREDIR"),
411 "/data/data/pt.up.yap/files",
414 join(getenv(
"DESTDIR"), YAP_SHAREDIR),
415 join(Yap_ROOTDIR,
"share"),
416 join(Yap_ROOTDIR,
"files"),
419 ANDROID_LOG_INFO,
"YAPDroid",
"Yap_SHAREDIR %s", Yap_SHAREDIR);
424 Yap_PLDIR = sel( is_dir, Yap_SHAREDIR, iap->PLDIR,
425 join(getenv(
"DESTDIR"), join(Yap_SHAREDIR,
"Yap")),
429 ANDROID_LOG_INFO,
"YAPDroid",
"Yap_PLDIR %s", Yap_PLDIR);
432 Yap_COMMONSDIR = sel(is_dir, Yap_SHAREDIR, iap->COMMONSDIR,
433 join(getenv(
"DESTDIR"), join(Yap_SHAREDIR,
"PrologCommons")),
436 Yap_SOURCEBOOT = sel( is_file,
Yap_AbsoluteFile(
"pl",
false), iap->SOURCEBOOT,
442 ANDROID_LOG_INFO,
"YAPDroid",
"Yap_SOURCEBOOT %s", Yap_SOURCEBOOT);
444 Yap_PLBOOTDIR = sel( is_dir, Yap_PLDIR, iap->BOOTDIR,
445 join(getenv(
"DESTDIR"),join(Yap_PLDIR,
"pl")),
448 ANDROID_LOG_INFO,
"YAPDroid",
"Yap_BOOTSTRAP %s", Yap_BOOTSTRAP);
450 Yap_BOOTSTRAP = sel( is_file, Yap_PLBOOTDIR, iap->BOOTSTRAP,
451 join(getenv(
"DESTDIR"),YAP_BOOTSTRAP),
452 join(getenv(
"DESTDIR"),join(Yap_PLBOOTDIR,
"boot.yap")),
455 ANDROID_LOG_INFO,
"YAPDroid",
"Yap_BOOTSTRAP %s", Yap_PLBOOTDIR);
458 sel( is_wfile,
".", iap->OUTPUT_STARTUP,
460 join(getenv(
"DESTDIR"), join(Yap_DLLDIR,
"startup.yss")),
461 join(getenv(
"DESTDIR"), join(Yap_DLLDIR,iap->OUTPUT_STARTUP)),
466 sel( is_file, Yap_DLLDIR, iap->INPUT_STARTUP,
468 join(getenv(
"DESTDIR"), join(Yap_DLLDIR,
"startup.yss")),
469#
if !defined(__ANDROID__)
470 join(getenv(
"DESTDIR"), YAP_INPUT_STARTUP),
472 "/usr/local/lib/Yap/startup.yss",
473 "/usr/lib/Yap/startup.yss",
477 setAtomicGlobalPrologFlag(HOME_FLAG,
478 MkAtomTerm(Yap_LookupAtom(Yap_ROOTDIR)));
480 setAtomicGlobalPrologFlag(PROLOG_LIBRARY_DIRECTORY_FLAG,
481 MkAtomTerm(Yap_LookupAtom(Yap_PLDIR)));
483 setAtomicGlobalPrologFlag(PROLOG_FOREIGN_DIRECTORY_FLAG,
484 MkAtomTerm(Yap_LookupAtom(Yap_DLLDIR)));
487static void print_usage(
void) {
488 fprintf(stderr,
"\n[ Valid switches for command line arguments: ]\n");
489 fprintf(stderr,
" -? Shows this screen\n");
490 fprintf(stderr,
" -B Used during compilation: boot from ../pl/boot.yap and generate a saved state. \n");
491 fprintf(stderr,
" -b Boot file \n");
492 fprintf(stderr,
" -dump-runtime-variables\n");
493 fprintf(stderr,
" -f initialization file or \"none\"\n");
494 fprintf(stderr,
" -g Run Goal Before Top-Level \n");
495 fprintf(stderr,
" -z Run Goal Before Top-Level \n");
496 fprintf(stderr,
" -q start with informational messages off\n");
497 fprintf(stderr,
" -l load Prolog file\n");
498 fprintf(stderr,
" -L run Prolog file and exit\n");
499 fprintf(stderr,
" -p extra path for file-search-path\n");
500 fprintf(stderr,
" -hSize Heap area in Kbytes (default: %d, minimum: %d)\n",
501 DefHeapSpace, MinHeapSpace);
503 " -sSize Stack area in Kbytes (default: %d, minimum: %d)\n",
504 DefStackSpace, MinStackSpace);
506 " -tSize Trail area in Kbytes (default: %d, minimum: %d)\n",
507 DefTrailSpace, MinTrailSpace);
508 fprintf(stderr,
" -GSize Max Area for Global Stack\n");
510 " -LSize Max Area for Local Stack (number must follow L)\n");
511 fprintf(stderr,
" -TSize Max Area for Trail (number must follow T)\n");
512 fprintf(stderr,
" -nosignals disable signal handling from Prolog\n");
513 fprintf(stderr,
"\n[Execution Modes]\n");
514 fprintf(stderr,
" -J0 Interpreted mode (default)\n");
515 fprintf(stderr,
" -J1 Mixed mode only for user predicates\n");
516 fprintf(stderr,
" -J2 Mixed mode for all predicates\n");
517 fprintf(stderr,
" -J3 Compile all user predicates\n");
518 fprintf(stderr,
" -J4 Compile all predicates\n");
522 " -ts Maximum table space area in Mbytes (default: unlimited)\n");
524#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \
525 defined(YAPOR_THREADS)
526 fprintf(stderr,
" -w Number of workers (default: %d)\n",
527 DEFAULT_NUMBERWORKERS);
529 " -sl Loop scheduler executions before look for hiden "
530 "shared work (default: %d)\n",
531 DEFAULT_SCHEDULERLOOP);
532 fprintf(stderr,
" -d Value of delayed release of load (default: %d)\n",
533 DEFAULT_DELAYEDRELEASELOAD);
537 fprintf(stderr,
"\n");
540static int myisblank(
int c) {
552static char *add_end_dot(
char arg[]) {
553 int sz = strlen(arg), i;
555 while (i && myisblank(arg[--i]))
557 if (i && arg[i] !=
',') {
558 char *p = (
char *)malloc(sz + 2);
569static int dump_runtime_variables(
void) {
570 fprintf(stdout,
"CC=\"%s\"\n", C_CC);
571 fprintf(stdout,
"YAP_ROOTDIR=\"%s\"\n", YAP_ROOTDIR);
572 fprintf(stdout,
"YAP_LIBS=\"%s\"\n", C_LIBS);
573 fprintf(stdout,
"YAP_SHLIB_SUFFIX=\"%s\"\n", SO_EXT);
574 fprintf(stdout,
"YAP_VERSION=%s\n", YAP_NUMERIC_VERSION);
579X_API YAP_file_type_t Yap_InitDefaults(
void *x,
char *saved_state,
int argc,
582 if (!LOCAL_TextBuffer)
583 LOCAL_TextBuffer = Yap_InitTextAllocator();
589 iap->boot_file_type = YAP_PL;
590 iap->INPUT_STARTUP = NULL;
591 iap->assetManager = NULL;
594 iap->boot_file_type = YAP_QLY;
595 iap->INPUT_STARTUP = saved_state;
611 Yap_InitDefaults(iap, NULL, argc,
argv);
617 iap->boot_file_type = YAP_PL;
619 iap->BOOTSTRAP = p + 1;
620 else if (
argv[1] && *
argv[1] !=
'-') {
621 iap->BOOTSTRAP = *++
argv;
626 iap->boot_file_type = YAP_SOURCE_PL;
628 iap->SOURCEBOOT = p + 1;
629 else if (
argv[1] && *
argv[1] !=
'-') {
630 iap->SOURCEBOOT = *++
argv;
639 iap->QuietMode = TRUE;
641#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \
642 defined(YAPOR_THREADS)
644 ssize = &(iap->NumberWorkers);
647 if (!strcmp(
"dump-runtime-variables", p))
648 return dump_runtime_variables();
649 ssize = &(iap->DelayedReleaseLoad);
653 if (!strcmp(
"dump-runtime-variables", p))
654 return dump_runtime_variables();
662 iap->FastBoot = TRUE;
663 if (argc > 1 &&
argv[1][0] !=
'-') {
666 if (strcmp(*
argv,
"none")) {
667 iap->PrologRCFile = *
argv;
676 iap->ExecutionMode = YAPC_INTERPRETED;
679 iap->ExecutionMode = YAPC_MIXED_MODE_USER;
682 iap->ExecutionMode = YAPC_MIXED_MODE_ALL;
685 iap->ExecutionMode = YAPC_COMPILE_USER;
688 iap->ExecutionMode = YAPC_COMPILE_ALL;
691 fprintf(stderr,
"[ YAP unrecoverable error: unknown switch -%c%c ]\n",
698 ssize = &(iap->MaxGlobalSize);
703 ssize = &(iap->StackSize);
704#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \
705 defined(YAPOR_THREADS)
708 ssize = &(iap->SchedulerLoop);
714 ssize = &(iap->AttsSize);
717 ssize = &(iap->MaxTrailSize);
720 ssize = &(iap->TrailSize);
724 ssize = &(iap->MaxTableSpaceSize);
733 "[ YAP unrecoverable error: missing size in flag %s ]",
740 unsigned long int i = 0, ch;
741 while ((ch = *p++) >=
'0' && ch <=
'9')
742 i = i * 10 + ch -
'0';
759 iap->PrologTopLevelGoal = add_end_dot(*
argv);
767 ssize = &(iap->HeapSize);
774 "[ YAP unrecoverable error: missing size in flag %s ]",
781 unsigned long int i = 0, ch;
782 while ((ch = *p++) >=
'0' && ch <=
'9')
783 i = i * 10 + ch -
'0';
803 "[ YAP unrecoverable error: illegal size specification %s ]",
813 while (p[1] !=
'\0') {
815 if (ch >=
'A' && ch <=
'Z')
817 if (ch >=
'a' && ch <=
'z')
818 GLOBAL_Option[ch - 96] = 1;
822 YAP_SetOutputMessage();
827 if (p[1] && p[1] >=
'0' &&
830 ssize = &(iap->MaxStackSize);
833 iap->QuietMode = TRUE;
834 iap->HaltAfterBoot =
true;
837 iap->QuietMode = TRUE;
840 "%% YAP unrecoverable error: missing load file name\n");
842 }
else if (!strcmp(
"--", *
argv)) {
844 iap->PrologRCFile =
argv[1];
848 iap->PrologRCFile = *
argv;
858 while (*p && (*p ==
' ' || *p ==
'\t'))
860 if (p[0] ==
'-' && p[1] ==
'-') {
868 if ((*
argv)[0] ==
'\0')
869 iap->PrologGoal = *
argv;
873 fprintf(stderr,
" [ YAP unrecoverable error: missing "
874 "initialization goal for option 'g' ]\n");
878 iap->PrologGoal = *
argv;
883 if ((*
argv)[0] ==
'\0')
884 iap->PrologTopLevelGoal = *
argv;
888 fprintf(stderr,
" [ YAP unrecoverable error: missing goal for "
893 iap->PrologTopLevelGoal = add_end_dot(*
argv);
895 iap->HaltAfterBoot =
true;
898 if (!strcmp(
"nosignals", p)) {
899 iap->PrologCannotHandleInterrupts =
true;
904 if (!strcmp(
"-nosignals", p)) {
905 iap->PrologCannotHandleInterrupts =
true;
907 }
else if (!strncmp(
"-output-saved-state=", p,
908 strlen(
"-output-saved-state="))) {
909 iap->OUTPUT_STARTUP = p + strlen(
"-output-saved-state=");
910 }
else if (!strncmp(
"-home=", p, strlen(
"-home="))) {
911 iap->ROOTDIR = p + strlen(
"-home=");
912 }
else if (!strncmp(
"-system-library-directory=", p,
913 strlen(
"-system-library-directory="))) {
914 iap->LIBDIR = p + strlen(
"-system-library-directory=");
915 }
else if (!strncmp(
"-system-shared-directory=", p,
916 strlen(
"-system-shared-directory="))) {
917 iap->SHAREDIR = p + strlen(
"-system-shared-directory=");
918 }
else if (!strncmp(
"-prolog-library-directory=", p,
919 strlen(
"-prolog-library-directory="))) {
920 iap->PLDIR = p + strlen(
"-prolog-library-directory=");
921 }
else if (!strncmp(
"-dll-library-directory=", p,
922 strlen(
"-dll-library-directory="))) {
923 iap->DLLDIR = p + strlen(
"-dll-library-directory=");
924 }
else if (!strncmp(
"-home=", p, strlen(
"-home="))) {
925 iap->ROOTDIR = p + strlen(
"-home=");
926 }
else if (!strncmp(
"-cwd=", p, strlen(
"-cwd="))) {
927 if (!Yap_ChDir(p + strlen(
"-cwd="))) {
928 fprintf(stderr,
" [ YAP unrecoverable error in setting cwd: %s ]\n",
931 }
else if (!strncmp(
"-stack=", p, strlen(
"-stack="))) {
932 ssize = &(iap->StackSize);
933 p += strlen(
"-stack=");
935 }
else if (!strncmp(
"-trail=", p, strlen(
"-trail="))) {
936 ssize = &(iap->TrailSize);
937 p += strlen(
"-trail=");
939 }
else if (!strncmp(
"-heap=", p, strlen(
"-heap="))) {
940 ssize = &(iap->HeapSize);
941 p += strlen(
"-heap=");
943 }
else if (!strncmp(
"-max-stack=", p, strlen(
"-max-stack="))) {
944 ssize = &(iap->MaxStackSize);
945 p += strlen(
"-max-stack=");
947 }
else if (!strncmp(
"-max-trail=", p, strlen(
"-max-trail="))) {
948 ssize = &(iap->MaxTrailSize);
949 p += strlen(
"-max-trail=");
951 }
else if (!strncmp(
"-max-heap=", p, strlen(
"-max-heap="))) {
952 ssize = &(iap->MaxHeapSize);
953 p += strlen(
"-max-heap=");
955 }
else if (!strncmp(
"-goal=", p, strlen(
"-goal="))) {
956 iap->PrologGoal = p + strlen(
"-goal=");
957 }
else if (!strncmp(
"-top-level=", p, strlen(
"-top-level="))) {
958 iap->PrologTopLevelGoal = p + strlen(
"-top-level=");
959 }
else if (!strncmp(
"-table=", p, strlen(
"-table="))) {
960 ssize = &(iap->MaxTableSpaceSize);
961 p += strlen(
"-table=");
963 }
else if (!strncmp(
"-", p, strlen(
"-="))) {
964 ssize = &(iap->MaxTableSpaceSize);
965 p += strlen(
"-table=");
971 if ((*
argv)[0] ==
'\0')
972 iap->PrologAddPath = *
argv;
976 fprintf(stderr,
" [ YAP unrecoverable error: missing paths for "
981 iap->PrologAddPath = *
argv;
989 if (var == NULL || *var ==
'\0')
991 while (*p !=
'=' && *p !=
'\0')
1000 if (iap->def_c == YAP_MAX_YPP_DEFS)
1002 iap->def_var[iap->def_c] = var;
1003 iap->def_value[iap->def_c] = value;
1009 fprintf(stderr,
"[ YAP unrecoverable error: unknown switch -%c ]\n",
1016 iap->INPUT_STARTUP = p;
1019 return iap->boot_file_type;
1036 m_delays[n_mdelays].f = f;
1037 m_delays[n_mdelays].s = s;
1042bool Yap_LateInit(
const char s[]) {
1044 for (i = 0; i < n_mdelays; i++) {
1045 if (!strcmp(m_delays[i].s, s)) {
1054 size_t Heap, Stack, Trail;
1057extern bool Yap_Embedded;
1060 Yap_page_size = Yap_InitPageSize();
1062#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
1063 Yap_init_yapor_global_local_memory();
1065 if (yap_init->Embedded) {
1066 yap_init->install =
false;
1067 GLOBAL_PrologShouldHandleInterrupts =
1068 yap_init->PrologCannotHandleInterrupts =
true;
1069 Yap_Embedded =
true;
1071 GLOBAL_PrologShouldHandleInterrupts =
1072 !yap_init->PrologCannotHandleInterrupts;
1074 GLOBAL_PL_Argv = yap_init->Argv;
1079 GLOBAL_argv = yap_init->Argv;
1080 GLOBAL_argc = yap_init->Argc;
1083 if (yap_init->TrailSize == 0) {
1084 if (spt->Trail == 0)
1085 spt->Trail = DefTrailSpace;
1087 spt->Trail = yap_init->TrailSize;
1090 if (yap_init->StackSize == 0) {
1091 spt->Stack = DefStackSpace;
1093 spt->Stack = yap_init->StackSize;
1095#ifndef USE_SYSTEM_MALLOC
1096 if (yap_init->HeapSize == 0) {
1098 spt->Heap = DefHeapSpace;
1100 spt->Heap = yap_init->HeapSize;
1106 YAP_initialized =
true;
1107 if (iap->HaltAfterBoot)
1109 LOCAL_PrologMode &= ~BootMode;
1110 CurrentModule = USER_MODULE;
1111 LOCAL_SourceModule = USER_MODULE;
1114static void start_modules(
void) {
1115 Term cm = CurrentModule;
1117 for (i = 0; i < n_mdelays; i++) {
1118 CurrentModule = MkAtomTerm(YAP_LookupAtom(m_delays[i].s));
1135 bool try_restore = yap_init->boot_file_type == YAP_QLY;
1136 bool do_bootstrap = yap_init->boot_file_type == YAP_PL ||
1137 yap_init->boot_file_type == YAP_SOURCE_PL;
1139 __android_log_print(
1140 ANDROID_LOG_INFO,
"YAPDroid",
"start init ");
1141 if (YAP_initialized)
1144 if (!LOCAL_TextBuffer)
1145 LOCAL_TextBuffer = Yap_InitTextAllocator();
1147 Yap_Embedded = yap_init->Embedded;
1149 minfo.Trail = 0, minfo.Stack = 0, minfo.Trail = 0;
1150 init_hw(yap_init, &minfo);
1151 Yap_InitWorkspace(yap_init, minfo.Heap, minfo.Stack, minfo.Trail, 0,
1152 yap_init->MaxTableSpaceSize, yap_init->NumberWorkers,
1153 yap_init->SchedulerLoop, yap_init->DelayedReleaseLoad);
1157 CurrentModule = PROLOG_MODULE;
1159 if (yap_init->QuietMode) {
1160 setBooleanLocalPrologFlag(VERBOSE_LOAD_FLAG,
1163 if (yap_init->PrologRCFile != NULL) {
1168 setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG,
1169 yap_init->HaltAfterBoot);
1172 Yap_ExecutionMode = yap_init->ExecutionMode;
1173 Yap_set_locations(yap_init);
1175 if (Yap_INPUT_STARTUP==NULL)
1176 try_restore =
false;
1177 if (do_bootstrap || !try_restore ||
1178 !Yap_SavedInfo(Yap_INPUT_STARTUP, &minfo.Trail, &minfo.Stack,
1180 init_globals(yap_init);
1183 TermEof = MkAtomTerm(Yap_LookupAtom(
"end_of_file"));
1184 LOCAL_consult_level = -1;
1185 __android_log_print(
1186 ANDROID_LOG_INFO,
"YAPDroid",
"init %s ", Yap_BOOTSTRAP);
1187 if (yap_init->install) {
1188 load_file(Yap_SOURCEBOOT PASS_REGS);
1189 setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
1190 MkAtomTerm(Yap_LookupAtom(Yap_SOURCEBOOT)));
1193 load_file(Yap_BOOTSTRAP PASS_REGS);
1194 setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
1195 MkAtomTerm(Yap_LookupAtom(Yap_BOOTSTRAP)));
1198 CurrentModule = LOCAL_SourceModule = TermUser;
1199 setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG,
false);
1201 if (yap_init->QuietMode) {
1202 setBooleanLocalPrologFlag(VERBOSE_LOAD_FLAG,
false);
1203 setBooleanLocalPrologFlag(COMPILING_FLAG,
true);
1205 __android_log_print(
1206 ANDROID_LOG_INFO,
"YAPDroid",
"restore %s ",Yap_INPUT_STARTUP );
1207 Yap_Restore(Yap_INPUT_STARTUP);
1208 CurrentModule = LOCAL_SourceModule = TermUser;
1209 init_globals(yap_init);
1212 if (yap_init->install && Yap_OUTPUT_STARTUP) {
1213 setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
1214 MkAtomTerm(Yap_LookupAtom(Yap_INPUT_STARTUP)));
1215 setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG,
true);
1217 LOCAL_consult_level = 0;
1219 YAP_RunGoalOnce(TermInitProlog);
1220 setBooleanLocalPrologFlag(COMPILING_FLAG,
false);
1221 setBooleanLocalPrologFlag(VERBOSE_LOAD_FLAG,
true);
1222 if (yap_init->install && Yap_OUTPUT_STARTUP) {
1223 Term t = MkAtomTerm(Yap_LookupAtom(Yap_OUTPUT_STARTUP));
1224 Term g = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom(
"qsave_program"), 1),
1232#if (DefTrailSpace < MinTrailSpace)
1234#define DefTrailSpace MinTrailSpace
1237#if (DefStackSpace < MinStackSpace)
1239#define DefStackSpace MinStackSpace
1242#if (DefHeapSpace < MinHeapSpace)
1244#define DefHeapSpace MinHeapSpace
1247#define DEFAULT_NUMBERWORKERS 1
1248#define DEFAULT_SCHEDULERLOOP 10
1249#define DEFAULT_DELAYEDRELEASELOAD 3
1251X_API
void YAP_FastInit(
char *saved_state,
int argc,
char *
argv[]) {
1253 YAP_file_type_t out;
1255 if ((out = Yap_InitDefaults(&init_args, saved_state, argc,
argv)) !=
1256 YAP_FOUND_BOOT_ERROR)
1257 YAP_Init(&init_args);
1258 if (out == YAP_FOUND_BOOT_ERROR) {
1259 Yap_Error(init_args.ErrorNo, TermNil, init_args.ErrorCause);
const char * Yap_AbsoluteFile(const char *spec, bool ok)
generate absolute path, if ok first expand SICStus Prolog style
X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
Parse command line.
X_API YAP_Term YAP_ReadClauseFromStream(int s, YAP_Term varNames, YAP_Term)
read a Prolog clause from a Prolog opened stream $s$
X_API bool YAP_DelayInit(YAP_ModInit_t f, const char s[])
YAP_DelayInit()
yap_error_descriptor_t * Yap_GetException(void)
clone Active Error
void * Malloc(size_t sz USES_REGS)
allocate a temporary text block
@ argv
read-only atom, it describes the list with all arguments received by YAP at boot
all we need to know about an error/throw
yap_error_number errorNo
error identifier
char * classAsText
errorClass as text
char * errorAsText
errorNo as text
intptr_t errorLine
c-code that generated the error C-line