Fixes, mostly to the biting o
This commit is contained in:
parent
645b2c7d93
commit
3061844c95
724
C/c_interface.c
724
C/c_interface.c
File diff suppressed because it is too large
Load Diff
25
C/load_dl.c
25
C/load_dl.c
@ -167,18 +167,10 @@ static Int LoadForeign(StringList
|
|||||||
|
|
||||||
while (libs) {
|
while (libs) {
|
||||||
const char *file = AtomName(libs->name);
|
const char *file = AtomName(libs->name);
|
||||||
if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true,
|
|
||||||
true)) {
|
|
||||||
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);
|
|
||||||
/* use LD_LIBRARY_PATH */
|
|
||||||
strncpy(LOCAL_ErrorMessage, (char *)AtomName(libs->name),
|
|
||||||
YAP_FILENAME_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __osf__
|
#ifdef __osf__
|
||||||
if ((libs->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY)) == NULL)
|
if ((libs->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY)) == NULL)
|
||||||
#else
|
#else
|
||||||
if ((libs->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY | RTLD_GLOBAL)) ==
|
if ((libs->handle = dlopen(file, RTLD_LAZY | RTLD_GLOBAL)) ==
|
||||||
NULL)
|
NULL)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@ -195,20 +187,9 @@ static Int LoadForeign(StringList
|
|||||||
/* load libraries first so that their symbols are available to
|
/* load libraries first so that their symbols are available to
|
||||||
other routines */
|
other routines */
|
||||||
const char *file = AtomName(ofiles->name);
|
const char *file = AtomName(ofiles->name);
|
||||||
if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true,
|
|
||||||
true)) {
|
if ((ofiles->handle = dlopen(file, RTLD_LAZY | RTLD_GLOBAL)) ==
|
||||||
if (LOCAL_ErrorMessage == NULL) {
|
|
||||||
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);
|
|
||||||
strcpy(LOCAL_ErrorMessage,
|
|
||||||
"%% Trying to open non-existing file in LoadForeign");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#ifdef __osf__
|
|
||||||
if ((ofiles->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY)) == NULL)
|
|
||||||
#else
|
|
||||||
if ((ofiles->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY | RTLD_GLOBAL)) ==
|
|
||||||
NULL)
|
NULL)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
if (LOCAL_ErrorMessage == NULL) {
|
if (LOCAL_ErrorMessage == NULL) {
|
||||||
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);
|
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);
|
||||||
|
4
C/qlyr.c
4
C/qlyr.c
@ -1097,10 +1097,10 @@ static Int qload_program(USES_REGS1) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
YAP_file_type_t Yap_Restore(const char *s, const char *lib_dir) {
|
YAP_file_type_t Yap_Restore(const char *s) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
FILE *stream = Yap_OpenRestore(s, lib_dir);
|
FILE *stream = Yap_OpenRestore(s);
|
||||||
if (!stream)
|
if (!stream)
|
||||||
return -1;
|
return -1;
|
||||||
GLOBAL_RestoreFile = s;
|
GLOBAL_RestoreFile = s;
|
||||||
|
48
C/save.c
48
C/save.c
@ -87,7 +87,7 @@ void initIO(void);
|
|||||||
|
|
||||||
static int myread(FILE *, char *, Int);
|
static int myread(FILE *, char *, Int);
|
||||||
static Int mywrite(FILE *, char *, Int);
|
static Int mywrite(FILE *, char *, Int);
|
||||||
static FILE *open_file(char *, int);
|
static FILE *open_file(const char *, int);
|
||||||
static int close_file(void);
|
static int close_file(void);
|
||||||
static Int putout(CELL);
|
static Int putout(CELL);
|
||||||
static Int putcellptr(CELL *);
|
static Int putcellptr(CELL *);
|
||||||
@ -123,7 +123,7 @@ static void restore_heap(void);
|
|||||||
static void ShowAtoms(void);
|
static void ShowAtoms(void);
|
||||||
static void ShowEntries(PropEntry *);
|
static void ShowEntries(PropEntry *);
|
||||||
#endif
|
#endif
|
||||||
static int OpenRestore(const char *, const char *, CELL *, CELL *, CELL *,
|
static int OpenRestore(const char *, CELL *, CELL *, CELL *,
|
||||||
CELL *, FILE **);
|
CELL *, FILE **);
|
||||||
static void CloseRestore(void);
|
static void CloseRestore(void);
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@ -233,7 +233,7 @@ static Int OldHeapUsed;
|
|||||||
static CELL which_save;
|
static CELL which_save;
|
||||||
|
|
||||||
/* Open a file to read or to write */
|
/* Open a file to read or to write */
|
||||||
static FILE *open_file(char *my_file, int flag) {
|
static FILE *open_file(const char *my_file, int flag) {
|
||||||
FILE *splfild;
|
FILE *splfild;
|
||||||
char flags[6];
|
char flags[6];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -1307,10 +1307,11 @@ static void ShowAtoms() {
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static int commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail,
|
static int commit_to_saved_state(const char *s, CELL *Astate, CELL *ATrail,
|
||||||
CELL *AStack, CELL *AHeap) {
|
CELL *AStack, CELL *AHeap) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int mode;
|
int mode;
|
||||||
|
char tmp[YAP_FILENAME_MAX+1];
|
||||||
|
|
||||||
if ((mode = check_header(Astate, ATrail, AStack, AHeap PASS_REGS)) ==
|
if ((mode = check_header(Astate, ATrail, AStack, AHeap PASS_REGS)) ==
|
||||||
FAIL_RESTORE)
|
FAIL_RESTORE)
|
||||||
@ -1318,9 +1319,8 @@ static int commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail,
|
|||||||
LOCAL_PrologMode = BootMode;
|
LOCAL_PrologMode = BootMode;
|
||||||
if (Yap_HeapBase) {
|
if (Yap_HeapBase) {
|
||||||
if (falseGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG) && !silentMode()) {
|
if (falseGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG) && !silentMode()) {
|
||||||
Yap_findFile(s, NULL, NULL, LOCAL_FileNameBuf2, true, YAP_QLY, true,
|
Yap_AbsoluteFile(s, tmp, true);
|
||||||
true);
|
fprintf(stderr, "%% Restoring file %s\n", tmp);
|
||||||
fprintf(stderr, "%% Restoring file %s\n", LOCAL_FileNameBuf2);
|
|
||||||
}
|
}
|
||||||
Yap_CloseStreams(TRUE);
|
Yap_CloseStreams(TRUE);
|
||||||
}
|
}
|
||||||
@ -1333,7 +1333,7 @@ static int commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail,
|
|||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack,
|
static int try_open(const char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack,
|
||||||
CELL *AHeap, FILE **streamp) {
|
CELL *AHeap, FILE **streamp) {
|
||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
@ -1355,18 +1355,13 @@ static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack,
|
|||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int OpenRestore(const char *inpf, const char *YapLibDir, CELL *Astate,
|
static int OpenRestore(const char *fname, CELL *Astate,
|
||||||
CELL *ATrail, CELL *AStack, CELL *AHeap,
|
CELL *ATrail, CELL *AStack, CELL *AHeap,
|
||||||
FILE **streamp) {
|
FILE **streamp) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
int mode;
|
int mode;
|
||||||
char fname[YAP_FILENAME_MAX + 1];
|
if (fname && fname[0] && (mode = try_open(fname, Astate, ATrail, AStack, AHeap,
|
||||||
|
|
||||||
if (!Yap_findFile(inpf, YAP_STARTUP, YapLibDir, fname, true, YAP_QLY,
|
|
||||||
true, true))
|
|
||||||
return FAIL_RESTORE;
|
|
||||||
if (fname[0] && (mode = try_open(fname, Astate, ATrail, AStack, AHeap,
|
|
||||||
streamp)) != FAIL_RESTORE) {
|
streamp)) != FAIL_RESTORE) {
|
||||||
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
|
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
|
||||||
MkAtomTerm(Yap_LookupAtom(fname)));
|
MkAtomTerm(Yap_LookupAtom(fname)));
|
||||||
@ -1378,22 +1373,19 @@ static int OpenRestore(const char *inpf, const char *YapLibDir, CELL *Astate,
|
|||||||
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,
|
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,
|
||||||
"incorrect saved state ");
|
"incorrect saved state ");
|
||||||
} else {
|
} else {
|
||||||
strncpy(LOCAL_FileNameBuf, inpf, YAP_FILENAME_MAX - 1);
|
strncpy(LOCAL_FileNameBuf, fname, YAP_FILENAME_MAX - 1);
|
||||||
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,
|
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,
|
||||||
"could not open saved state");
|
"could not open saved state");
|
||||||
}
|
}
|
||||||
return FAIL_RESTORE;
|
return FAIL_RESTORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *Yap_OpenRestore(const char *inpf, const char *YapLibDir) {
|
FILE *Yap_OpenRestore(const char *inpf) {
|
||||||
FILE *stream = NULL;
|
FILE *stream = NULL;
|
||||||
|
|
||||||
if (!inpf)
|
if (!inpf)
|
||||||
inpf = "startup.yss";
|
inpf = "startup.yss";
|
||||||
if (!YapLibDir) {
|
OpenRestore(inpf, NULL, NULL, NULL, NULL, &stream);
|
||||||
YapLibDir = YAP_LIBDIR;
|
|
||||||
}
|
|
||||||
OpenRestore(inpf, YapLibDir, NULL, NULL, NULL, NULL, &stream);
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1467,14 +1459,14 @@ static void RestoreHeap(OPCODE old_ops[] USES_REGS) {
|
|||||||
* This function is called to know about the parameters of the last saved
|
* This function is called to know about the parameters of the last saved
|
||||||
* state
|
* state
|
||||||
*/
|
*/
|
||||||
int Yap_SavedInfo(const char *FileName, const char *YapLibDir, CELL *ATrail,
|
int Yap_SavedInfo(const char *FileName, CELL *ATrail,
|
||||||
CELL *AStack, CELL *AHeap) {
|
CELL *AStack, CELL *AHeap) {
|
||||||
return DO_ONLY_CODE;
|
return DO_ONLY_CODE;
|
||||||
|
|
||||||
CELL MyTrail, MyStack, MyHeap, MyState;
|
CELL MyTrail, MyStack, MyHeap, MyState;
|
||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
mode = OpenRestore(FileName, YapLibDir, &MyState, &MyTrail, &MyStack, &MyHeap,
|
mode = OpenRestore(FileName, &MyState, &MyTrail, &MyStack, &MyHeap,
|
||||||
NULL);
|
NULL);
|
||||||
if (mode == FAIL_RESTORE) {
|
if (mode == FAIL_RESTORE) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -1554,13 +1546,13 @@ static void FreeRecords(void) {
|
|||||||
* This function is called when wanting only to restore the heap and
|
* This function is called when wanting only to restore the heap and
|
||||||
* associated registers
|
* associated registers
|
||||||
*/
|
*/
|
||||||
static int Restore(char *s, char *lib_dir USES_REGS) {
|
static int Restore(char *s_dir USES_REGS) {
|
||||||
int restore_mode;
|
int restore_mode;
|
||||||
|
|
||||||
OPCODE old_ops[_std_top + 1];
|
OPCODE old_ops[_std_top + 1];
|
||||||
CELL MyTrail, MyStack, MyHeap, MyState;
|
CELL MyTrail, MyStack, MyHeap, MyState;
|
||||||
|
|
||||||
if ((restore_mode = OpenRestore(s, lib_dir, &MyState, &MyTrail, &MyStack,
|
if ((restore_mode = OpenRestore(s_dir, &MyState, &MyTrail, &MyStack,
|
||||||
&MyHeap, NULL)) == FAIL_RESTORE)
|
&MyHeap, NULL)) == FAIL_RESTORE)
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
Yap_ShutdownLoadForeign();
|
Yap_ShutdownLoadForeign();
|
||||||
@ -1612,9 +1604,9 @@ static int Restore(char *s, char *lib_dir USES_REGS) {
|
|||||||
return restore_mode;
|
return restore_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Yap_SavedStateRestore(char *s, char *lib_dir) {
|
int Yap_SavedStateRestore(char *s) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
return Restore(s, lib_dir PASS_REGS);
|
return Restore(s PASS_REGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int p_restore(USES_REGS1) {
|
static Int p_restore(USES_REGS1) {
|
||||||
@ -1640,7 +1632,7 @@ static Int p_restore(USES_REGS1) {
|
|||||||
Yap_Error(TYPE_ERROR_LIST, t1, "restore/1");
|
Yap_Error(TYPE_ERROR_LIST, t1, "restore/1");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
if ((mode = Restore(s, NULL PASS_REGS)) == DO_ONLY_CODE) {
|
if ((mode = Restore(s PASS_REGS)) == DO_ONLY_CODE) {
|
||||||
Yap_RestartYap(3);
|
Yap_RestartYap(3);
|
||||||
}
|
}
|
||||||
return (mode != FAIL_RESTORE);
|
return (mode != FAIL_RESTORE);
|
||||||
|
@ -1349,13 +1349,13 @@ static Int p_statistics_lu_db_size(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int p_executable(USES_REGS1) {
|
static Int p_executable(USES_REGS1) {
|
||||||
|
char tmp[YAP_FILENAME_MAX+1];
|
||||||
if (GLOBAL_argv && GLOBAL_argv[0])
|
if (GLOBAL_argv && GLOBAL_argv[0])
|
||||||
Yap_findFile(GLOBAL_argv[0], NULL, NULL, LOCAL_FileNameBuf, true, YAP_EXE,
|
Yap_AbsoluteFile(GLOBAL_argv[0], tmp, true);
|
||||||
true, true);
|
|
||||||
else
|
else
|
||||||
strncpy(LOCAL_FileNameBuf, Yap_FindExecutable(), YAP_FILENAME_MAX - 1);
|
strncpy(tmp, Yap_FindExecutable(), YAP_FILENAME_MAX);
|
||||||
|
|
||||||
return Yap_unify(MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)), ARG1);
|
return Yap_unify(MkAtomTerm(Yap_LookupAtom(tmp)), ARG1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int p_system_mode(USES_REGS1) {
|
static Int p_system_mode(USES_REGS1) {
|
||||||
|
2
C/text.c
2
C/text.c
@ -31,7 +31,7 @@ inline static size_t min_size(size_t i, size_t j) { return (i < j ? i : j); }
|
|||||||
#define wcsnlen(S, N) min_size(N, wcslen(S))
|
#define wcsnlen(S, N) min_size(N, wcslen(S))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_STPCPY
|
#if !defined(HAVE_STPCPY) && !defined(__APPLE__)
|
||||||
inline static void* __stpcpy(void * i, const void * j) { return strcpy(i,j)+strlen(j);}
|
inline static void* __stpcpy(void * i, const void * j) { return strcpy(i,j)+strlen(j);}
|
||||||
#define stpcpy __stpcpy
|
#define stpcpy __stpcpy
|
||||||
#endif
|
#endif
|
||||||
|
678
C/yap-args.c
678
C/yap-args.c
@ -9,7 +9,8 @@
|
|||||||
**************************************************************************
|
**************************************************************************
|
||||||
* *
|
* *
|
||||||
* File: Yap.C * Last
|
* File: Yap.C * Last
|
||||||
*Rev: * Mods:
|
*Rev:
|
||||||
|
* Mods:
|
||||||
** Comments: Yap's Main File: parse arguments *
|
** Comments: Yap's Main File: parse arguments *
|
||||||
* *
|
* *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
@ -18,6 +19,7 @@
|
|||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
#include "YapHeap.h"
|
#include "YapHeap.h"
|
||||||
#include "YapInterface.h"
|
#include "YapInterface.h"
|
||||||
|
#include "YapStreams.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#if HAVE_UNISTD_H
|
#if HAVE_UNISTD_H
|
||||||
@ -61,111 +63,329 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR, *Yap_PLDIR;
|
const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR,
|
||||||
|
*Yap_PLDIR, *Yap_BOOTPLDIR, *Yap_BOOTSTRAPPLDIR, *Yap_COMMONSDIR,
|
||||||
|
*Yap_STARTUP, *Yap_BOOTFILE;
|
||||||
|
|
||||||
const char *rootdirs[] = {
|
|
||||||
YAP_ROOTDIR,
|
static int yap_lineno = 0;
|
||||||
"(EXECUTABLE)..",
|
|
||||||
"/usr/local",
|
/* do initial boot by consulting the file boot.yap */
|
||||||
"~",
|
static void do_bootfile(const char *b_file USES_REGS) {
|
||||||
NULL
|
Term t;
|
||||||
};
|
int boot_stream, osno;
|
||||||
|
Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1);
|
||||||
|
Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1);
|
||||||
|
|
||||||
|
/* consult boot.pl */
|
||||||
|
char *full = malloc(YAP_FILENAME_MAX + 1);
|
||||||
|
full[0] = '\0';
|
||||||
|
/* the consult mode does not matter here, really */
|
||||||
|
boot_stream = YAP_InitConsult(YAP_BOOT_MODE, b_file, full, &osno);
|
||||||
|
if (boot_stream < 0) {
|
||||||
|
fprintf(stderr, "[ FATAL ERROR: could not open boot_stream %s ]\n",
|
||||||
|
b_file);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
free(full);
|
||||||
|
setAtomicGlobalPrologFlag(
|
||||||
|
RESOURCE_DATABASE_FLAG,
|
||||||
|
MkAtomTerm(GLOBAL_Stream[boot_stream].name));
|
||||||
|
do {
|
||||||
|
CACHE_REGS
|
||||||
|
YAP_Reset(YAP_FULL_RESET);
|
||||||
|
Yap_StartSlots();
|
||||||
|
t = YAP_ReadClauseFromStream(boot_stream);
|
||||||
|
|
||||||
|
// Yap_DebugPlWriteln(t);
|
||||||
|
if (t == 0) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"[ SYNTAX ERROR: while parsing boot_stream %s at line %d ]\n",
|
||||||
|
b_file, yap_lineno);
|
||||||
|
} else if (YAP_IsVarTerm(t) || t == TermNil) {
|
||||||
|
fprintf(stderr, "[ line %d: term cannot be compiled ]", yap_lineno);
|
||||||
|
} else if (YAP_IsPairTerm(t)) {
|
||||||
|
fprintf(stderr, "[ SYSTEM ERROR: consult not allowed in boot file ]\n");
|
||||||
|
fprintf(stderr, "error found at line %d and pos %d", yap_lineno,
|
||||||
|
fseek(GLOBAL_Stream[boot_stream].file, 0L, SEEK_CUR));
|
||||||
|
} else if (IsApplTerm(t) && (FunctorOfTerm(t) == functor_query ||
|
||||||
|
FunctorOfTerm(t) == functor_command1)) {
|
||||||
|
YAP_RunGoalOnce(ArgOfTerm(1, t));
|
||||||
|
} else {
|
||||||
|
Term ts[2];
|
||||||
|
char *ErrorMessage;
|
||||||
|
Functor fun = Yap_MkFunctor(Yap_LookupAtom("$prepare_clause"), 2);
|
||||||
|
PredEntry *pe = RepPredProp(PredPropByFunc(fun, PROLOG_MODULE));
|
||||||
|
|
||||||
|
if (pe->OpcodeOfPred != UNDEF_OPCODE && pe->OpcodeOfPred != FAIL_OPCODE) {
|
||||||
|
ts[0] = t;
|
||||||
|
RESET_VARIABLE(ts + 1);
|
||||||
|
if (YAP_RunGoal(Yap_MkApplTerm(fun, 2, ts)))
|
||||||
|
t = ts[1];
|
||||||
|
}
|
||||||
|
ErrorMessage = YAP_CompileClause(t);
|
||||||
|
if (ErrorMessage) {
|
||||||
|
fprintf(stderr, "%s", ErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (t != TermEof);
|
||||||
|
BACKUP_MACHINE_REGS();
|
||||||
|
|
||||||
|
YAP_EndConsult(boot_stream, &osno);
|
||||||
|
#if DEBUG
|
||||||
|
if (Yap_output_msg)
|
||||||
|
fprintf(stderr, "Boot loaded\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief A simple language for detecting where YAP stuff cn be found
|
||||||
|
*
|
||||||
|
* @long The options are
|
||||||
|
* `[V]` use a configuration variable YAP_XXXDIR, prefixed by "DESTDIR"
|
||||||
|
* `(V)PATH` compute V and add /PATH,
|
||||||
|
* `$V` search the envurinment
|
||||||
|
* `?V` search the WINDOWS registry
|
||||||
|
* ~` search HOME
|
||||||
|
* `@` query user option.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
const char *rootdirs[] = {"[root]", "(execdir)..", "/usr/local", "~", NULL};
|
||||||
|
|
||||||
|
const char *bindirs[] = {"[bin]", "(root)bin", NULL};
|
||||||
|
|
||||||
const char *libdirs[] = {
|
const char *libdirs[] = {
|
||||||
"$YAPLIBDIR",
|
|
||||||
"[lib]",
|
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
"/assets/lib",
|
"/assets/lib",
|
||||||
#endif
|
#endif
|
||||||
YAP_LIBDIR,
|
"[lib]", "(root)lib", NULL};
|
||||||
"(root)lib",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *sharedirs[] = {
|
const char *sharedirs[] = {
|
||||||
"$YAPSHAREDIR",
|
|
||||||
"[share]",
|
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
"/assets/share",
|
"/assets/share",
|
||||||
#endif
|
#endif
|
||||||
YAP_SHAREDIR,
|
"[share]", "(root)share", NULL};
|
||||||
"(root)share",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *dlldirs[] = {
|
const char *dlldirs[] = {"$YAPLIBDIR", "(lib)Yap", ".", NULL};
|
||||||
"(lib)Yap",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *pldirs[] = {
|
const char *ssdirs[] = {".", "$YAPLIBDIR", "(lib)Yap", NULL};
|
||||||
"(share)Yap",
|
|
||||||
NULL
|
const char *pldirs[] = {"$YAPSHAREDIR", "?library", "(share)Yap", ".", NULL};
|
||||||
};
|
|
||||||
|
const char *bootpldirs[] = {"(pl)pl", ".", NULL};
|
||||||
|
|
||||||
|
const char *bootstrappldirs[] = {YAP_PL_SRCDIR, NULL};
|
||||||
|
|
||||||
|
const char *commonsdirs[] = {"(share)PrologCommons", ".", NULL};
|
||||||
|
|
||||||
|
const char *ssnames[] = {"@SavedState", YAP_STARTUP, "startup.yss", NULL};
|
||||||
|
|
||||||
|
const char *plnames[] = {"@YapPrologBootFile", YAP_BOOTFILE, "boot.yap", NULL};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search
|
||||||
|
*/
|
||||||
|
char *location(YAP_init_args *iap, const char *inp, char *out) {
|
||||||
|
if (inp == NULL || inp[0] == '\0') {
|
||||||
|
return NULL;
|
||||||
|
} else if (inp[0] == '(') {
|
||||||
|
if (strstr(inp + 1, "root") == inp + 1) {
|
||||||
|
if (!Yap_ROOTDIR || Yap_ROOTDIR[0] == '\0') {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
strcpy(out, Yap_ROOTDIR);
|
||||||
|
strcat(out, "/");
|
||||||
|
strcat(out, inp + strlen("(root)"));
|
||||||
|
} else if (strstr(inp + 1, "bin") == inp + 1) {
|
||||||
|
if (!Yap_BINDIR || Yap_BINDIR[0] == '\0') {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
strcpy(out, Yap_BINDIR);
|
||||||
|
strcat(out, "/");
|
||||||
|
strcat(out, inp + strlen("(bin)"));
|
||||||
|
} else if (strstr(inp + 1, "lib") == inp + 1) {
|
||||||
|
if (!Yap_LIBDIR || Yap_LIBDIR[0] == '\0') {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
strcpy(out, Yap_LIBDIR);
|
||||||
|
strcat(out, "/");
|
||||||
|
strcat(out, inp + strlen("(lib)"));
|
||||||
|
} else if (strstr(inp + 1, "share") == inp + 1) {
|
||||||
|
if (!Yap_SHAREDIR || Yap_SHAREDIR[0] == '\0') {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
strcpy(out, Yap_SHAREDIR);
|
||||||
|
strcat(out, "/");
|
||||||
|
strcat(out, inp + strlen("(share)"));
|
||||||
|
} else if (strstr(inp + 1, "pl") == inp + 1) {
|
||||||
|
if (!Yap_PLDIR || Yap_PLDIR[0] == '\0') {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
strcpy(out, Yap_PLDIR);
|
||||||
|
strcat(out, "/");
|
||||||
|
strcat(out, inp + strlen("(pl)"));
|
||||||
|
}else if (strstr(inp + 1, "execdir") == inp + 1) {
|
||||||
|
const char *ex = Yap_FindExecutable();
|
||||||
|
if (ex == NULL)
|
||||||
|
return NULL;
|
||||||
|
strcpy(out, dirname(ex));
|
||||||
|
strcat(out, "/");
|
||||||
|
strcat(out, inp + strlen("(execdir)"));
|
||||||
|
} else
|
||||||
|
return NULL;
|
||||||
|
} else if (inp[0] == '@') {
|
||||||
|
|
||||||
|
if (strstr(inp + 1, "YapPrologBootFile") == inp + 1) {
|
||||||
|
const char *tmp;
|
||||||
|
tmp = iap->YapPrologBootFile;
|
||||||
|
if (tmp && tmp[0])
|
||||||
|
strcpy(out, tmp);
|
||||||
|
} else if (strstr(inp + 1, "SavedState") == inp + 1) {
|
||||||
|
const char *tmp = iap->SavedState;
|
||||||
|
if (tmp && tmp[0])
|
||||||
|
strcpy(out, tmp);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
} else if (inp[0] == '$') {
|
||||||
|
char *e;
|
||||||
|
if ((e = getenv(inp + 1)) != NULL) {
|
||||||
|
strcpy(out, e);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
} else if (inp[0] == '?') {
|
||||||
|
#if _WINDOWS_
|
||||||
|
char *e;
|
||||||
|
if ((e = Yap_RegistryGetString(inp + 1)) != NULL) {
|
||||||
|
strcpy(out, e);
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
|
} else if (inp[0] == '~') {
|
||||||
|
char *e;
|
||||||
|
if ((e = getenv("HOME")) != NULL) {
|
||||||
|
strcpy(out, e);
|
||||||
|
}
|
||||||
|
if (inp[1] != '\0')
|
||||||
|
strcat(out, inp + 1);
|
||||||
|
} else if (inp[0] == '[') {
|
||||||
|
char *o = out;
|
||||||
|
const char *e;
|
||||||
|
if ((e = getenv("DESTDIR"))) {
|
||||||
|
strcpy(out, e);
|
||||||
|
o += strlen(e);
|
||||||
|
}
|
||||||
|
if (strstr(inp + 1, "root") == inp + 1) {
|
||||||
|
#ifdef YAP_ROOTDIR
|
||||||
|
strcpy(o, YAP_ROOTDIR);
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
} else if (strstr(inp + 1, "lib") == inp + 1) {
|
||||||
|
#ifdef YAP_LIBDIR
|
||||||
|
strcpy(o, YAP_LIBDIR);
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
} else if (strstr(inp + 1, "share") == inp + 1) {
|
||||||
|
#ifdef YAP_SHAREDIR
|
||||||
|
strcpy(o, YAP_SHAREDIR);
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
} else if (strstr(inp + 1, "dll") == inp + 1) {
|
||||||
|
#ifdef YAP_DLLDIR
|
||||||
|
strcpy(o, YAP_DLLDIR);
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
} else if (strstr(inp + 1, "pl") == inp + 1) {
|
||||||
|
#ifdef YAP_PLDIR
|
||||||
|
strcpy(o, YAP_PLDIR);
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
} else if (strstr(inp + 1, "commons") == inp + 1) {
|
||||||
|
#ifdef YAP_COMMONSDIR
|
||||||
|
strcpy(o, YAP_COMMONSDIR);
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
strcpy(out, inp);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief find default paths for main YAP variables
|
* @brief find default paths for main YAP variables
|
||||||
*
|
*
|
||||||
* This function is called once at boot time to set the main paths; it searches a list of paths to instantiate a number of variables.
|
* This function is called once at boot time to set the main paths; it searches
|
||||||
* Paths must be directories.
|
* a list of paths to instantiate a number of variables. Paths must be
|
||||||
|
* directories.
|
||||||
*
|
*
|
||||||
* It treats the following variables as :
|
* It treats the following variables as :
|
||||||
* ROOTDIR, SHAREDIR, LIBDIR, EXECUTABLE
|
* ROOTDIR, SHAREDIR, LIBDIR, EXECUTABLE
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static const char *find_directory(const char *paths[]) {
|
static const char *find_directory(YAP_init_args *iap, const char *paths[],
|
||||||
int i = 0;
|
const char *names[]) {
|
||||||
|
int lvl = push_text_stack();
|
||||||
|
char *out = Malloc(YAP_FILENAME_MAX + 1);
|
||||||
const char *inp;
|
const char *inp;
|
||||||
char *out = malloc(YAP_FILENAME_MAX + 1);
|
char *full;
|
||||||
out[0] = '\0';
|
if (names) {
|
||||||
|
full = Malloc(YAP_FILENAME_MAX + 1);
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
while ((inp = paths[i++]) != NULL) {
|
while ((inp = paths[i++]) != NULL) {
|
||||||
if (inp[0] == '(') {
|
|
||||||
if (strstr(inp + 1, "root") == inp + 1) {
|
|
||||||
strcpy(out, Yap_ROOTDIR);
|
|
||||||
strcat(out, "/");
|
|
||||||
strcat(out, inp+(strlen("(root)")+1));
|
|
||||||
} else if (strstr(inp + 1, "lib") == inp + 1) {
|
|
||||||
strcpy(out, Yap_LIBDIR);
|
|
||||||
strcat(out, "/");
|
|
||||||
strcat(out, inp+(strlen("(lib)")+1));
|
|
||||||
} else if (strstr(inp + 1, "share") == inp + 1) {
|
|
||||||
strcpy(out, Yap_LIBDIR);
|
|
||||||
strcat(out, "/");
|
|
||||||
strcat(out, inp+(strlen("(share)")+1));
|
|
||||||
} else if (strstr(inp + 1, "executable") == inp + 1) {
|
|
||||||
strcpy(out, Yap_LIBDIR);
|
|
||||||
strcat(out, "/");
|
|
||||||
strcat(out, inp+(strlen("(executable)")+1));
|
|
||||||
}
|
|
||||||
} else if (inp[0] == '$') {
|
|
||||||
char *e;
|
|
||||||
if ((e = getenv(inp + 1)) != NULL) {
|
|
||||||
strcpy(out, e);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
} else if (inp[0] == '[') {
|
|
||||||
if (Yap_ROOTDIR && Yap_ROOTDIR[0] && strstr(inp + 1, "root") == inp + 1) {
|
|
||||||
strcpy(out, Yap_ROOTDIR);
|
|
||||||
} else if (Yap_LIBDIR && Yap_LIBDIR[0] && strstr(inp + 1, "lib") == inp + 1) {
|
|
||||||
strcpy(out, Yap_LIBDIR);
|
|
||||||
} else if (Yap_SHAREDIR && Yap_SHAREDIR[0] && strstr(inp + 1, "share") == inp + 1) {
|
|
||||||
strcpy(out, Yap_SHAREDIR);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
char *e;
|
|
||||||
if ((e = getenv(inp + 1)) != NULL) {
|
|
||||||
strcpy(out, e);
|
|
||||||
} else {
|
|
||||||
out[0] = '\0';
|
out[0] = '\0';
|
||||||
|
char *o = location(iap, inp, out), *no;
|
||||||
|
if (o && o[0] && Yap_isDirectory(o)) {
|
||||||
|
if (names) {
|
||||||
|
size_t s = strlen(o);
|
||||||
|
o[s++] = '/';
|
||||||
|
const char *p;
|
||||||
|
int j = 0;
|
||||||
|
while ((p = names[j++])) {
|
||||||
|
char *io = o + s;
|
||||||
|
if ((no = location(iap, p, io)) && io[0] != '\0' && Yap_Exists(o))
|
||||||
|
return pop_output_text_stack(lvl, realpath(o, full));
|
||||||
}
|
}
|
||||||
strcat(out, inp);
|
} else
|
||||||
}
|
return pop_output_text_stack(lvl, o);
|
||||||
if (out[0]) {
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pop_text_stack(lvl);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Yap_set_locations(YAP_init_args *iap) {
|
||||||
|
#if CONDA_BUILD
|
||||||
|
if (!getenv("DESTDIR")) {
|
||||||
|
char buf[YAP_FILENAME_MAX + 1];
|
||||||
|
const char *o = Yap_FindExecutable();
|
||||||
|
if (!o)
|
||||||
|
return;
|
||||||
|
strcpy(buf, dirname(dirname(o)));
|
||||||
|
putenv("DESTDIR", buf)k
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
Yap_ROOTDIR = find_directory(iap, rootdirs, NULL);
|
||||||
|
Yap_LIBDIR = find_directory(iap, libdirs, NULL);
|
||||||
|
Yap_BINDIR = find_directory(iap, bindirs, NULL);
|
||||||
|
Yap_SHAREDIR = find_directory(iap, sharedirs, NULL);
|
||||||
|
Yap_DLLDIR = find_directory(iap, dlldirs, NULL);
|
||||||
|
Yap_PLDIR = find_directory(iap, pldirs, NULL);
|
||||||
|
Yap_COMMONSDIR = find_directory(iap, commonsdirs, NULL);
|
||||||
|
Yap_STARTUP = find_directory(iap, ssdirs, ssnames);
|
||||||
|
if (iap->bootstrapping)
|
||||||
|
Yap_BOOTFILE = find_directory(iap, bootstrappldirs, plnames);
|
||||||
|
else
|
||||||
|
Yap_BOOTFILE = find_directory(iap, bootpldirs, plnames);
|
||||||
|
setAtomicGlobalPrologFlag( HOME_FLAG, MkAtomTerm(Yap_LookupAtom(Yap_ROOTDIR)));
|
||||||
|
setAtomicGlobalPrologFlag( PROLOG_LIBRARY_DIRECTORY_FLAG,MkAtomTerm(Yap_LookupAtom(Yap_PLDIR)));
|
||||||
|
setAtomicGlobalPrologFlag( PROLOG_FOREIGN_DIRECTORY_FLAG, MkAtomTerm(Yap_LookupAtom(Yap_DLLDIR)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,9 +456,10 @@ static int myisblank(int c) {
|
|||||||
static char *add_end_dot(char arg[]) {
|
static char *add_end_dot(char arg[]) {
|
||||||
int sz = strlen(arg), i;
|
int sz = strlen(arg), i;
|
||||||
i = sz;
|
i = sz;
|
||||||
while (i && myisblank(arg[--i]));
|
while (i && myisblank(arg[--i]))
|
||||||
|
;
|
||||||
if (i && arg[i] != ',') {
|
if (i && arg[i] != ',') {
|
||||||
char *p = (char *) malloc(sz + 2);
|
char *p = (char *)malloc(sz + 2);
|
||||||
if (!p)
|
if (!p)
|
||||||
return NULL;
|
return NULL;
|
||||||
strncpy(p, arg, sz);
|
strncpy(p, arg, sz);
|
||||||
@ -261,6 +482,9 @@ static int dump_runtime_variables(void) {
|
|||||||
|
|
||||||
X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state, int argc,
|
X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state, int argc,
|
||||||
char *argv[]) {
|
char *argv[]) {
|
||||||
|
|
||||||
|
if (!LOCAL_TextBuffer)
|
||||||
|
LOCAL_TextBuffer = Yap_InitTextAllocator();
|
||||||
YAP_init_args *iap = x;
|
YAP_init_args *iap = x;
|
||||||
memset(iap, 0, sizeof(YAP_init_args));
|
memset(iap, 0, sizeof(YAP_init_args));
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
@ -273,11 +497,6 @@ X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state, int argc,
|
|||||||
#endif
|
#endif
|
||||||
iap->Argc = argc;
|
iap->Argc = argc;
|
||||||
iap->Argv = argv;
|
iap->Argv = argv;
|
||||||
Yap_ROOTDIR = find_directory(rootdirs);
|
|
||||||
Yap_LIBDIR = find_directory(libdirs);
|
|
||||||
Yap_SHAREDIR = find_directory(sharedirs);
|
|
||||||
Yap_DLLDIR = find_directory(dlldirs);
|
|
||||||
Yap_PLDIR = find_directory(pldirs);
|
|
||||||
return YAP_QLY;
|
return YAP_QLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,34 +507,10 @@ X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state, int argc,
|
|||||||
* @param iap options, see YAP_init_args
|
* @param iap options, see YAP_init_args
|
||||||
* @return boot from saved state or restore; error
|
* @return boot from saved state or restore; error
|
||||||
*/
|
*/
|
||||||
X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
|
X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
|
||||||
YAP_init_args *iap) {
|
YAP_init_args *iap) {
|
||||||
char *p;
|
char *p;
|
||||||
size_t *ssize;
|
size_t *ssize;
|
||||||
#ifndef YAP_ROOTDIR
|
|
||||||
{
|
|
||||||
char *b0 = Yap_FindExecutable(), *b1, *b2;
|
|
||||||
char b[YAP_FILENAME_MAX + 1];
|
|
||||||
|
|
||||||
strncpy(b, b0, YAP_FILENAME_MAX);
|
|
||||||
b1 = dirname(b);
|
|
||||||
YAP_BINDIR = malloc(strlen(b1) + 1);
|
|
||||||
strcpy(YAP_BINDIR, b1);
|
|
||||||
b2 = dirname(b1);
|
|
||||||
YAP_ROOTDIR = malloc(strlen(b2) + 1);
|
|
||||||
strcpy(YAP_ROOTDIR, b2);
|
|
||||||
strncpy(b, YAP_ROOTDIR, YAP_FILENAME_MAX);
|
|
||||||
strncat(b, "/share", YAP_FILENAME_MAX);
|
|
||||||
YAP_SHAREDIR = malloc(strlen(b) + 1);
|
|
||||||
strcpy(YAP_SHAREDIR, b);
|
|
||||||
strncpy(b, YAP_ROOTDIR, YAP_FILENAME_MAX);
|
|
||||||
strncat(b, "/lib", YAP_FILENAME_MAX);
|
|
||||||
YAP_LIBDIR = malloc(strlen(b) + 1);
|
|
||||||
strcpy(YAP_LIBDIR, b);
|
|
||||||
strncpy(b, YAP_ROOTDIR, YAP_FILENAME_MAX);
|
|
||||||
strncat(b, "/lib/Yap", YAP_FILENAME_MAX);
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Yap_InitDefaults(iap, NULL, argc, argv);
|
Yap_InitDefaults(iap, NULL, argc, argv);
|
||||||
while (--argc > 0) {
|
while (--argc > 0) {
|
||||||
@ -701,4 +896,271 @@ X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state, int argc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return iap->boot_file_type;
|
return iap->boot_file_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
YAP_DelayInit()
|
||||||
|
|
||||||
|
ensures initialization is done after engine creation.
|
||||||
|
It receives a pointer to function and a string describing
|
||||||
|
the module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
X_API bool YAP_initialized = false;
|
||||||
|
static int n_mdelays = 0;
|
||||||
|
static YAP_delaymodule_t *m_delays;
|
||||||
|
|
||||||
|
X_API bool YAP_DelayInit(YAP_ModInit_t f, const char s[]) {
|
||||||
|
if (m_delays) {
|
||||||
|
m_delays = realloc(m_delays, (n_mdelays + 1) * sizeof(YAP_delaymodule_t));
|
||||||
|
} else {
|
||||||
|
m_delays = malloc(sizeof(YAP_delaymodule_t));
|
||||||
}
|
}
|
||||||
|
m_delays[n_mdelays].f = f;
|
||||||
|
m_delays[n_mdelays].s = s;
|
||||||
|
n_mdelays++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Yap_LateInit(const char s[]) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < n_mdelays; i++) {
|
||||||
|
if (!strcmp(m_delays[i].s, s)) {
|
||||||
|
m_delays[i].f();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void start_modules(void) {
|
||||||
|
Term cm = CurrentModule;
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < n_mdelays; i++) {
|
||||||
|
CurrentModule = MkAtomTerm(YAP_LookupAtom(m_delays[i].s));
|
||||||
|
m_delays[i].f();
|
||||||
|
}
|
||||||
|
CurrentModule = cm;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// whether Yap is under control of some other system
|
||||||
|
bool Yap_embedded = true;
|
||||||
|
|
||||||
|
struct ssz_t {
|
||||||
|
size_t Heap, Stack, Trail;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void init_hw(YAP_init_args *yap_init, struct ssz_t *spt) {
|
||||||
|
Yap_page_size = Yap_InitPageSize(); /* init memory page size, required by
|
||||||
|
later functions */
|
||||||
|
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
|
||||||
|
Yap_init_yapor_global_local_memory();
|
||||||
|
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
|
||||||
|
if (!yap_init->Embedded) {
|
||||||
|
GLOBAL_PrologShouldHandleInterrupts =
|
||||||
|
!yap_init->PrologCannotHandleInterrupts;
|
||||||
|
Yap_InitSysbits(0); /* init signal handling and time, required by later
|
||||||
|
functions */
|
||||||
|
GLOBAL_argv = yap_init->Argv;
|
||||||
|
GLOBAL_argc = yap_init->Argc;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __ANDROID__
|
||||||
|
|
||||||
|
// if (yap_init->assetManager)
|
||||||
|
Yap_InitAssetManager();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (yap_init->TrailSize == 0) {
|
||||||
|
if (spt->Trail == 0)
|
||||||
|
spt->Trail = DefTrailSpace;
|
||||||
|
} else {
|
||||||
|
spt->Trail = yap_init->TrailSize;
|
||||||
|
}
|
||||||
|
// Atts = yap_init->AttsSize;
|
||||||
|
if (yap_init->StackSize == 0) {
|
||||||
|
spt->Stack = DefStackSpace;
|
||||||
|
} else {
|
||||||
|
spt->Stack = yap_init->StackSize;
|
||||||
|
}
|
||||||
|
#ifndef USE_SYSTEM_MALLOC
|
||||||
|
if (yap_init->HeapSize == 0) {
|
||||||
|
if (spt->Heap == 0)
|
||||||
|
spt->Heap = DefHeapSpace;
|
||||||
|
} else {
|
||||||
|
spt->Heap = yap_init->HeapSize;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void init_globals(YAP_init_args *yap_init) {
|
||||||
|
GLOBAL_FAST_BOOT_FLAG = yap_init->FastBoot;
|
||||||
|
#if defined(YAPOR) || defined(TABLING)
|
||||||
|
|
||||||
|
Yap_init_root_frames();
|
||||||
|
|
||||||
|
#endif /* YAPOR || TABLING */
|
||||||
|
#ifdef YAPOR
|
||||||
|
Yap_init_yapor_workers();
|
||||||
|
#if YAPOR_THREADS
|
||||||
|
if (Yap_thread_self() != 0) {
|
||||||
|
#else
|
||||||
|
if (worker_id != 0) {
|
||||||
|
#endif
|
||||||
|
#if defined(YAPOR_COPY) || defined(YAPOR_SBA)
|
||||||
|
/*
|
||||||
|
In the SBA we cannot just happily inherit registers
|
||||||
|
from the other workers
|
||||||
|
*/
|
||||||
|
Yap_InitYaamRegs(worker_id);
|
||||||
|
#endif /* YAPOR_COPY || YAPOR_SBA */
|
||||||
|
#ifndef YAPOR_THREADS
|
||||||
|
Yap_InitPreAllocCodeSpace(0);
|
||||||
|
#endif /* YAPOR_THREADS */
|
||||||
|
/* slaves, waiting for work */
|
||||||
|
CurrentModule = USER_MODULE;
|
||||||
|
P = GETWORK_FIRST_TIME;
|
||||||
|
Yap_exec_absmi(FALSE, YAP_EXEC_ABSMI);
|
||||||
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
|
"abstract machine unexpected exit (YAP_Init)");
|
||||||
|
}
|
||||||
|
#endif /* YAPOR */
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
|
/* make sure we do this after restore */
|
||||||
|
if (yap_init->MaxStackSize) {
|
||||||
|
GLOBAL_AllowLocalExpansion = FALSE;
|
||||||
|
} else {
|
||||||
|
GLOBAL_AllowLocalExpansion = TRUE;
|
||||||
|
}
|
||||||
|
if (yap_init->MaxGlobalSize) {
|
||||||
|
GLOBAL_AllowGlobalExpansion = FALSE;
|
||||||
|
} else {
|
||||||
|
GLOBAL_AllowGlobalExpansion = TRUE;
|
||||||
|
}
|
||||||
|
if (yap_init->MaxTrailSize) {
|
||||||
|
GLOBAL_AllowTrailExpansion = FALSE;
|
||||||
|
} else {
|
||||||
|
GLOBAL_AllowTrailExpansion = TRUE;
|
||||||
|
}
|
||||||
|
if (yap_init->YapPrologRCFile) {
|
||||||
|
Yap_PutValue(AtomConsultOnBoot,
|
||||||
|
MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologRCFile)));
|
||||||
|
/*
|
||||||
|
This must be done again after restore, as yap_flags
|
||||||
|
has been overwritten ....
|
||||||
|
*/
|
||||||
|
setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG,
|
||||||
|
yap_init->HaltAfterConsult);
|
||||||
|
}
|
||||||
|
if (yap_init->YapPrologTopLevelGoal) {
|
||||||
|
Yap_PutValue(AtomTopLevelGoal,
|
||||||
|
MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologTopLevelGoal)));
|
||||||
|
}
|
||||||
|
if (yap_init->YapPrologGoal) {
|
||||||
|
Yap_PutValue(AtomInitGoal,
|
||||||
|
MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologGoal)));
|
||||||
|
}
|
||||||
|
if (yap_init->YapPrologAddPath) {
|
||||||
|
Yap_PutValue(AtomExtendFileSearchPath,
|
||||||
|
MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologAddPath)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (yap_init->QuietMode) {
|
||||||
|
setVerbosity(TermSilent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static YAP_file_type_t end_init(YAP_init_args *yap_init, YAP_file_type_t rc) {
|
||||||
|
init_globals(yap_init);
|
||||||
|
LOCAL_PrologMode &= ~BootMode;
|
||||||
|
|
||||||
|
start_modules();
|
||||||
|
|
||||||
|
YAP_initialized = true;
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* this routine is supposed to be called from an external program
|
||||||
|
that wants to control Yap */
|
||||||
|
|
||||||
|
X_API YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
|
||||||
|
YAP_file_type_t restore_result = yap_init->boot_file_type;
|
||||||
|
bool do_bootstrap = (restore_result & YAP_CONSULT_MODE);
|
||||||
|
struct ssz_t minfo;
|
||||||
|
|
||||||
|
if (YAP_initialized)
|
||||||
|
return YAP_FOUND_BOOT_ERROR;
|
||||||
|
if (!LOCAL_TextBuffer)
|
||||||
|
LOCAL_TextBuffer = Yap_InitTextAllocator();
|
||||||
|
|
||||||
|
/* ignore repeated calls to YAP_Init */
|
||||||
|
Yap_embedded = yap_init->Embedded;
|
||||||
|
|
||||||
|
minfo.Trail = 0, minfo.Stack = 0, minfo.Trail = 0;
|
||||||
|
init_hw(yap_init, &minfo);
|
||||||
|
Yap_InitWorkspace(yap_init, minfo.Heap, minfo.Stack, minfo.Trail, 0,
|
||||||
|
yap_init->MaxTableSpaceSize, yap_init->NumberWorkers,
|
||||||
|
yap_init->SchedulerLoop, yap_init->DelayedReleaseLoad);
|
||||||
|
//
|
||||||
|
|
||||||
|
CACHE_REGS
|
||||||
|
if (Yap_embedded)
|
||||||
|
if (yap_init->QuietMode) {
|
||||||
|
setVerbosity(TermSilent);
|
||||||
|
}
|
||||||
|
if (yap_init->YapPrologRCFile != NULL) {
|
||||||
|
/*
|
||||||
|
This must be done before restore, otherwise
|
||||||
|
restore will print out messages ....
|
||||||
|
*/
|
||||||
|
setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG,
|
||||||
|
yap_init->HaltAfterConsult);
|
||||||
|
}
|
||||||
|
/* tell the system who should cope with interrupts */
|
||||||
|
Yap_ExecutionMode = yap_init->ExecutionMode;
|
||||||
|
Yap_set_locations(yap_init);
|
||||||
|
if (!do_bootstrap && Yap_STARTUP && yap_init->boot_file_type != YAP_BOOT_PL &&
|
||||||
|
Yap_SavedInfo(Yap_STARTUP, &minfo.Trail, &minfo.Stack, &minfo.Heap) &&
|
||||||
|
Yap_Restore(Yap_STARTUP)) {
|
||||||
|
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true);
|
||||||
|
CurrentModule = LOCAL_SourceModule = USER_MODULE;
|
||||||
|
return end_init(yap_init, YAP_QLY);
|
||||||
|
} else {
|
||||||
|
do_bootfile(Yap_BOOTFILE PASS_REGS);
|
||||||
|
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
|
||||||
|
return end_init(yap_init, YAP_BOOT_PL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (DefTrailSpace < MinTrailSpace)
|
||||||
|
#undef DefTrailSpace
|
||||||
|
#define DefTrailSpace MinTrailSpace
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (DefStackSpace < MinStackSpace)
|
||||||
|
#undef DefStackSpace
|
||||||
|
#define DefStackSpace MinStackSpace
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (DefHeapSpace < MinHeapSpace)
|
||||||
|
#undef DefHeapSpace
|
||||||
|
#define DefHeapSpace MinHeapSpace
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DEFAULT_NUMBERWORKERS 1
|
||||||
|
#define DEFAULT_SCHEDULERLOOP 10
|
||||||
|
#define DEFAULT_DELAYEDRELEASELOAD 3
|
||||||
|
|
||||||
|
X_API YAP_file_type_t YAP_FastInit(char *saved_state, int argc, char *argv[]) {
|
||||||
|
YAP_init_args init_args;
|
||||||
|
YAP_file_type_t out;
|
||||||
|
|
||||||
|
if ((out = Yap_InitDefaults(&init_args, saved_state, argc, argv)) !=
|
||||||
|
YAP_FOUND_BOOT_ERROR)
|
||||||
|
out = YAP_Init(&init_args);
|
||||||
|
if (out == YAP_FOUND_BOOT_ERROR) {
|
||||||
|
Yap_Error(init_args.ErrorNo, TermNil, init_args.ErrorCause);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
@ -17,8 +17,8 @@ cmake_policy(VERSION 3.4)
|
|||||||
|
|
||||||
set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/cmake")
|
set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
set(ANACONDA $ENV{CONDA_BUILD} CACHE BOOL "Anaconda Environment")
|
set(ANACONDA $ENV{CONDA_BUILD} CACHE BOOL "Anaconda Environment")
|
||||||
message(STATUS "ANACONDA found: ${ANACONDA}")
|
message(STATUS "ANACONDA found: ${ANACONDA}")
|
||||||
|
|
||||||
include(CheckIncludeFiles)
|
include(CheckIncludeFiles)
|
||||||
include(CheckLibraryExists)
|
include(CheckLibraryExists)
|
||||||
@ -222,6 +222,7 @@ if (ANACONDA)
|
|||||||
#set( CMAKE_INSTALL_FULL_PREFIX $ENV{PREFIX} )
|
#set( CMAKE_INSTALL_FULL_PREFIX $ENV{PREFIX} )
|
||||||
set( PYTHON_LIBRARY $ENV{PREFIX}/lib/libpython$ENV{PY_VER}m$ENV{SHLIB_EXT})
|
set( PYTHON_LIBRARY $ENV{PREFIX}/lib/libpython$ENV{PY_VER}m$ENV{SHLIB_EXT})
|
||||||
set( PYTHON_INCLUDE_DIR $ENV{PREFIX}/include/python$ENV{PY_VER}m)
|
set( PYTHON_INCLUDE_DIR $ENV{PREFIX}/include/python$ENV{PY_VER}m)
|
||||||
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CONDA_BUILD=1)
|
||||||
set(YAP_IS_MOVABLE 1)
|
set(YAP_IS_MOVABLE 1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -814,7 +815,7 @@ endif(NOT ANDROID)
|
|||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
install(FILES ${INCLUDE_HEADERS} ${CONFIGURATION_HEADERS} DESTINATION ${YAP_INCLUDEDIR} )
|
install(FILES ${INCLUDE_HEADERS} ${CONFIGURATION_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Yap )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
3
H/Yap.h
3
H/Yap.h
@ -151,7 +151,8 @@ typedef void *(*fptr_t)(void);
|
|||||||
main exports in YapInterface.h
|
main exports in YapInterface.h
|
||||||
*************************************************************************************************/
|
*************************************************************************************************/
|
||||||
|
|
||||||
extern const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR, *Yap_PLDIR;
|
extern const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR, *Yap_PLDIR, *Yap_COMMONSDIR, *Yap_STARTUP, *Yap_BOOTFILE;
|
||||||
|
|
||||||
|
|
||||||
/* Basic exports */
|
/* Basic exports */
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ process, namely, on choice-points.
|
|||||||
YAP_FLAG(GMP_VERSION_FLAG, "gmp_version", false, isatom, "4.8.12", NULL),
|
YAP_FLAG(GMP_VERSION_FLAG, "gmp_version", false, isatom, "4.8.12", NULL),
|
||||||
YAP_FLAG(HALT_AFTER_CONSULT_FLAG, "halt_after_consult", false, booleanFlag,
|
YAP_FLAG(HALT_AFTER_CONSULT_FLAG, "halt_after_consult", false, booleanFlag,
|
||||||
"false", NULL),
|
"false", NULL),
|
||||||
/* YAP_FLAG(HOME_FLAG, "home", false, isatom, rootdir, NULL),*/ /**< home `
|
YAP_FLAG(HOME_FLAG, "home", false, isatom, rootdir, NULL), /**< home `
|
||||||
|
|
||||||
the root of the YAP installation, by default `/usr/local` in Unix or
|
the root of the YAP installation, by default `/usr/local` in Unix or
|
||||||
`c:\Yap` in Windows system. Can only be set at configure time
|
`c:\Yap` in Windows system. Can only be set at configure time
|
||||||
|
169
H/YapTerm.h
169
H/YapTerm.h
@ -1,169 +0,0 @@
|
|||||||
/*************************************************************************
|
|
||||||
* *
|
|
||||||
* YAP Prolog %W% %G% *
|
|
||||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
||||||
* *
|
|
||||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
||||||
* *
|
|
||||||
**************************************************************************
|
|
||||||
* *
|
|
||||||
* File: Yap.h *
|
|
||||||
* mods: *
|
|
||||||
* comments: abstract type definitions for YAP *
|
|
||||||
* version: $Id: Yap.h,v 1.38 2008-06-18 10:02:27 vsc Exp $ *
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
#ifndef YAP_H
|
|
||||||
#include "YapTermConfig.h"
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAVE_STDINT_H
|
|
||||||
#include <stdint.h>
|
|
||||||
#endif
|
|
||||||
#if HAVE_INTTYPES_H
|
|
||||||
#include <inttypes.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* truth-values */
|
|
||||||
/* stdbool defines the booleam type, bool,
|
|
||||||
and the constants false and true */
|
|
||||||
#if HAVE_STDBOOL_H
|
|
||||||
#include <stdbool.h>
|
|
||||||
#else
|
|
||||||
#ifndef true
|
|
||||||
typedef int _Bool;
|
|
||||||
#define bool _Bool;
|
|
||||||
|
|
||||||
#define false 0
|
|
||||||
#define true 1
|
|
||||||
#endif
|
|
||||||
#endif /* HAVE_STDBOOL_H */
|
|
||||||
|
|
||||||
|
|
||||||
#define ALIGN_BY_TYPE(X, TYPE) \
|
|
||||||
(((CELL)(X) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1))
|
|
||||||
|
|
||||||
#ifndef EXTERN
|
|
||||||
#ifdef MSC_VER
|
|
||||||
#define EXTERN
|
|
||||||
#else
|
|
||||||
#define EXTERN extern
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* defines integer types Int and UInt (unsigned) with the same size as a ptr
|
|
||||||
** and integer types Short and UShort with half the size of a ptr */
|
|
||||||
|
|
||||||
#if defined(PRIdPTR)
|
|
||||||
|
|
||||||
typedef intptr_t YAP_Int;
|
|
||||||
typedef uintptr_t YAP_UInt;
|
|
||||||
|
|
||||||
#elif defined(_WIN64)
|
|
||||||
|
|
||||||
|
|
||||||
typedef int64_t YAP_Int;
|
|
||||||
typedef uint64_t YAP_UInt;
|
|
||||||
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
|
|
||||||
typedef int32_t YAP_Int;
|
|
||||||
typedef uint32_t YAP_UInt;
|
|
||||||
|
|
||||||
#elif SIZEOF_LONG_INT == SIZEOF_INT_P
|
|
||||||
|
|
||||||
typedef long int YAP_Int;
|
|
||||||
typedef unsigned long int YAP_UInt;
|
|
||||||
|
|
||||||
#elif SIZEOF_INT == SIZEOF_INT_P
|
|
||||||
|
|
||||||
typedef int YAP_Int;
|
|
||||||
typedef unsigned int YAP_UInt;
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error Yap require integer types of the same size as a pointer
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* */ typedef short int YAP_Short;
|
|
||||||
/* */ typedef unsigned short int YAP_UShort;
|
|
||||||
|
|
||||||
typedef YAP_UInt YAP_CELL;
|
|
||||||
typedef YAP_UInt YAP_Term;
|
|
||||||
|
|
||||||
/* Type definitions */
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef TRUE
|
|
||||||
#define TRUE true
|
|
||||||
#endif
|
|
||||||
#ifndef FALSE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef bool YAP_Bool;
|
|
||||||
#define FALSE false
|
|
||||||
|
|
||||||
typedef YAP_Int YAP_handle_t;
|
|
||||||
|
|
||||||
|
|
||||||
typedef double YAP_Float;
|
|
||||||
|
|
||||||
typedef void *YAP_Atom;
|
|
||||||
|
|
||||||
typedef void *YAP_Functor;
|
|
||||||
|
|
||||||
#ifdef YAP_H
|
|
||||||
|
|
||||||
typedef YAP_Int Int;
|
|
||||||
typedef YAP_UInt UInt;
|
|
||||||
typedef YAP_Short Short;
|
|
||||||
typedef YAP_UShort UShort;
|
|
||||||
|
|
||||||
typedef uint16_t BITS16;
|
|
||||||
typedef int16_t SBITS16;
|
|
||||||
typedef uint32_t BITS32;
|
|
||||||
|
|
||||||
typedef YAP_CELL CELL;
|
|
||||||
|
|
||||||
typedef YAP_Term Term;
|
|
||||||
|
|
||||||
#define WordSize sizeof(BITS16)
|
|
||||||
#define CellSize sizeof(CELL)
|
|
||||||
#define SmallSize sizeof(SMALLUNSGN)
|
|
||||||
|
|
||||||
typedef YAP_Int Int;
|
|
||||||
typedef YAP_Float Float;
|
|
||||||
typedef YAP_handle_t yhandle_t;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "YapError.h"
|
|
||||||
|
|
||||||
#include "../os/encoding.h"
|
|
||||||
|
|
||||||
typedef encoding_t YAP_encoding_t;
|
|
||||||
|
|
||||||
#include "YapFormat.h"
|
|
||||||
|
|
||||||
/*************************************************************************************************
|
|
||||||
type casting macros
|
|
||||||
*************************************************************************************************/
|
|
||||||
|
|
||||||
#if SIZEOF_INT < SIZEOF_INT_P
|
|
||||||
#define SHORT_INTS 1
|
|
||||||
#else
|
|
||||||
#define SHORT_INTS 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
typedef long long int YAP_LONG_LONG;
|
|
||||||
typedef unsigned long long int YAP_ULONG_LONG;
|
|
||||||
#else
|
|
||||||
typedef long int YAP_LONG_LONG;
|
|
||||||
typedef unsigned long int YAP_ULONG_LONG;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define Unsigned(V) ((CELL)(V))
|
|
||||||
#define Signed(V) ((Int)(V))
|
|
||||||
|
|
14
H/Yapproto.h
14
H/Yapproto.h
@ -354,16 +354,16 @@ extern void Yap_InitReadUtil(void);
|
|||||||
|
|
||||||
/* qly.c */
|
/* qly.c */
|
||||||
extern void Yap_InitQLY(void);
|
extern void Yap_InitQLY(void);
|
||||||
extern YAP_file_type_t Yap_Restore(const char *, const char *);
|
extern YAP_file_type_t Yap_Restore(const char *);
|
||||||
extern void Yap_InitQLYR(void);
|
extern void Yap_InitQLYR(void);
|
||||||
|
|
||||||
/* range.c */
|
/* range.c */
|
||||||
extern void Yap_InitRange(void);
|
extern void Yap_InitRange(void);
|
||||||
|
|
||||||
/* save.c */
|
/* save.c */
|
||||||
extern int Yap_SavedInfo(const char *, const char *, CELL *, CELL *, CELL *);
|
extern int Yap_SavedInfo(const char *, CELL *, CELL *, CELL *);
|
||||||
extern int Yap_SavedStateRestore(char *, char *);
|
extern int Yap_SavedStateRestore(char *);
|
||||||
extern FILE *Yap_OpenRestore(const char *, const char *);
|
extern FILE *Yap_OpenRestore(const char *);
|
||||||
extern void Yap_InitSavePreds(void);
|
extern void Yap_InitSavePreds(void);
|
||||||
|
|
||||||
/* scanner.c */
|
/* scanner.c */
|
||||||
@ -432,10 +432,10 @@ extern void Yap_WinError(char *);
|
|||||||
extern const char *Yap_AbsoluteFile(const char *spec, char *obuf, bool ok);
|
extern const char *Yap_AbsoluteFile(const char *spec, char *obuf, bool ok);
|
||||||
extern const char *Yap_AbsoluteFileInBuffer(const char *spec, char *outp, size_t sz,
|
extern const char *Yap_AbsoluteFileInBuffer(const char *spec, char *outp, size_t sz,
|
||||||
bool ok);
|
bool ok);
|
||||||
extern const char *Yap_findFile(const char *isource, const char *idef,
|
|
||||||
const char *root, char *result, bool access,
|
|
||||||
YAP_file_type_t ftype, bool expand_root, bool in_lib);
|
|
||||||
extern bool Yap_ChDir(const char *path);
|
extern bool Yap_ChDir(const char *path);
|
||||||
|
bool Yap_isDirectory(const char *FileName);
|
||||||
|
extern bool Yap_Exists(const char *f);
|
||||||
|
|
||||||
|
|
||||||
/* threads.c */
|
/* threads.c */
|
||||||
extern void Yap_InitThreadPreds(void);
|
extern void Yap_InitThreadPreds(void);
|
||||||
|
@ -1971,7 +1971,6 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef YAP_IS_MOVABLE
|
|
||||||
/* name of YAP instaii */
|
/* name of YAP instaii */
|
||||||
#ifndef YAP_ROOTDIR
|
#ifndef YAP_ROOTDIR
|
||||||
#define YAP_ROOTDIR "${YAP_ROOTDIR}"
|
#define YAP_ROOTDIR "${YAP_ROOTDIR}"
|
||||||
@ -2001,13 +2000,14 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
|
|||||||
#define YAP_SHAREDIR "${YAP_ROOTDIR}/share"
|
#define YAP_SHAREDIR "${YAP_ROOTDIR}/share"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
/* name of YAP PL library */
|
||||||
extern char
|
#ifndef YAP_PLDIR
|
||||||
*YAP_BINDIR,
|
#define YAP_PLDIR "${YAP_SHAREDIR}/Yap"
|
||||||
*YAP_ROOTDIR,
|
#endif
|
||||||
*YAP_SHAREDIR,
|
|
||||||
*YAP_LIBDIR,
|
/* name of Commons library */
|
||||||
*YAP_YAPLIB;
|
#ifndef YAP_COMMONSDIR
|
||||||
|
#define YAP COMMONSDIR "${YAP_SHAREDIR}/PrologCommmons"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -1370,7 +1370,7 @@ writable.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static Int open3(USES_REGS1) {
|
static Int open3(USES_RfEGS1) {
|
||||||
/* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
/* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
||||||
return do_open(Deref(ARG1), Deref(ARG2), TermNil PASS_REGS);
|
return do_open(Deref(ARG1), Deref(ARG2), TermNil PASS_REGS);
|
||||||
}
|
}
|
||||||
@ -1465,11 +1465,11 @@ static Int p_file_expansion(USES_REGS1) { /* '$file_expansion'(+File,-Name) */
|
|||||||
PlIOError(INSTANTIATION_ERROR, file_name, "absolute_file_name/3");
|
PlIOError(INSTANTIATION_ERROR, file_name, "absolute_file_name/3");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
if (!Yap_findFile(RepAtom(AtomOfTerm(file_name))->StrOfAE, NULL, NULL,
|
char tmp[YAP_FILENAME_MAX+1];
|
||||||
LOCAL_FileNameBuf, true, YAP_ANY_FILE, true, false))
|
if (!Yap_AbsoluteFile(RepAtom(AtomOfTerm(file_name))->StrOfAE,tmp, false))
|
||||||
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name,
|
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name,
|
||||||
"absolute_file_name/3"));
|
"absolute_file_name/3"));
|
||||||
return (Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))));
|
return (Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(tmp))));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int p_open_null_stream(USES_REGS1) {
|
static Int p_open_null_stream(USES_REGS1) {
|
||||||
|
@ -273,7 +273,6 @@ extern FILE *Yap_stderr;
|
|||||||
|
|
||||||
char *Yap_MemExportStreamPtr(int sno);
|
char *Yap_MemExportStreamPtr(int sno);
|
||||||
|
|
||||||
extern bool Yap_Exists(const char *f);
|
|
||||||
|
|
||||||
static inline void freeBuffer(const void *ptr) {
|
static inline void freeBuffer(const void *ptr) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
293
os/sysbits.c
293
os/sysbits.c
@ -34,7 +34,6 @@ static void FileError(yap_error_number type, Term where, const char *format,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Int p_sh(USES_REGS1);
|
static Int p_sh(USES_REGS1);
|
||||||
static Int p_shell(USES_REGS1);
|
static Int p_shell(USES_REGS1);
|
||||||
static Int p_system(USES_REGS1);
|
static Int p_system(USES_REGS1);
|
||||||
@ -67,11 +66,11 @@ void Yap_WinError(char *yap_error) {
|
|||||||
|
|
||||||
/// is_directory: verifies whether an expanded file name
|
/// is_directory: verifies whether an expanded file name
|
||||||
/// points at a readable directory
|
/// points at a readable directory
|
||||||
static bool is_directory(const char *FileName) {
|
bool Yap_isDirectory(const char *FileName) {
|
||||||
|
|
||||||
VFS_t *vfs;
|
VFS_t *vfs;
|
||||||
if ((vfs = vfs_owner(FileName))) {
|
if ((vfs = vfs_owner(FileName))) {
|
||||||
return vfs->isdir(vfs,FileName);
|
return vfs->isdir(vfs, FileName);
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
DWORD dwAtts = GetFileAttributes(FileName);
|
DWORD dwAtts = GetFileAttributes(FileName);
|
||||||
@ -97,7 +96,7 @@ bool Yap_Exists(const char *f) {
|
|||||||
VFS_t *vfs;
|
VFS_t *vfs;
|
||||||
f = Yap_VFAlloc(f);
|
f = Yap_VFAlloc(f);
|
||||||
if ((vfs = vfs_owner(f))) {
|
if ((vfs = vfs_owner(f))) {
|
||||||
return vfs->exists(vfs,f);
|
return vfs->exists(vfs, f);
|
||||||
}
|
}
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
if (_access(f, 0) == 0)
|
if (_access(f, 0) == 0)
|
||||||
@ -345,7 +344,7 @@ static char *PrologPath(const char *Y, char *X) { return (char *)Y; }
|
|||||||
|
|
||||||
char virtual_cwd[YAP_FILENAME_MAX + 1];
|
char virtual_cwd[YAP_FILENAME_MAX + 1];
|
||||||
|
|
||||||
bool Yap_ChDir(const char *path) {
|
bool Yap_ChDir(const char *path) {
|
||||||
bool rc = false;
|
bool rc = false;
|
||||||
char qp[FILENAME_MAX + 1];
|
char qp[FILENAME_MAX + 1];
|
||||||
const char *qpath = Yap_AbsoluteFile(path, qp, true);
|
const char *qpath = Yap_AbsoluteFile(path, qp, true);
|
||||||
@ -369,10 +368,9 @@ char virtual_cwd[YAP_FILENAME_MAX + 1];
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char *myrealpath(const char *path, char *out) {
|
static const char *myrealpath(const char *path, char *out) {
|
||||||
int lvl = push_text_stack();
|
int lvl = push_text_stack();
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
DWORD retval = 0;
|
DWORD retval = 0;
|
||||||
|
|
||||||
// notice that the file does not need to exist
|
// notice that the file does not need to exist
|
||||||
@ -393,8 +391,8 @@ static const char *myrealpath(const char *path, char *out) {
|
|||||||
}
|
}
|
||||||
// rc = NULL;
|
// rc = NULL;
|
||||||
if (errno == ENOENT || errno == EACCES) {
|
if (errno == ENOENT || errno == EACCES) {
|
||||||
char *base= Malloc(YAP_FILENAME_MAX + 1);
|
char *base = Malloc(YAP_FILENAME_MAX + 1);
|
||||||
strncpy(base, path, YAP_FILENAME_MAX );
|
strncpy(base, path, YAP_FILENAME_MAX);
|
||||||
rc = realpath(dirname(base), out);
|
rc = realpath(dirname(base), out);
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
@ -959,95 +957,10 @@ static bool initSysPath(Term tlib, Term tcommons, bool dir_done,
|
|||||||
int len;
|
int len;
|
||||||
char *dir;
|
char *dir;
|
||||||
|
|
||||||
#if __WINDOWS__
|
|
||||||
{
|
|
||||||
if ((dir = Yap_RegistryGetString("library")) && is_directory(dir)) {
|
|
||||||
dir_done = true;
|
|
||||||
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(dir))))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ((dir = Yap_RegistryGetString("prolog_commons")) && is_directory(dir)) {
|
|
||||||
if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(dir))))
|
|
||||||
return false;
|
|
||||||
commons_done = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (dir_done && commons_done)
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(Yap_PLDIR))))
|
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(Yap_PLDIR))))
|
||||||
return false;
|
return false;
|
||||||
if (!commons_done) {
|
|
||||||
LOCAL_FileNameBuf[len] = '\0';
|
|
||||||
strncat(LOCAL_FileNameBuf, "PrologCommons", YAP_FILENAME_MAX);
|
|
||||||
if (is_directory(LOCAL_FileNameBuf)) {
|
|
||||||
if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
commons_done = true;
|
|
||||||
}
|
|
||||||
if (dir_done && commons_done)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
#if __WINDOWS__
|
return Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(Yap_COMMONSDIR)));
|
||||||
{
|
|
||||||
size_t buflen;
|
|
||||||
char *pt;
|
|
||||||
/* couldn't find it where it was supposed to be,
|
|
||||||
let's try using the executable */
|
|
||||||
if (!GetModuleFileName(NULL, LOCAL_FileNameBuf, YAP_FILENAME_MAX)) {
|
|
||||||
Yap_WinError("could not find executable name");
|
|
||||||
/* do nothing */
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
buflen = strlen(LOCAL_FileNameBuf);
|
|
||||||
pt = LOCAL_FileNameBuf + buflen;
|
|
||||||
while (*--pt != '\\') {
|
|
||||||
/* skip executable */
|
|
||||||
if (pt == LOCAL_FileNameBuf) {
|
|
||||||
FileError(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil,
|
|
||||||
"could not find executable name");
|
|
||||||
/* do nothing */
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (*--pt != '\\') {
|
|
||||||
/* skip parent directory "bin\\" */
|
|
||||||
if (pt == LOCAL_FileNameBuf) {
|
|
||||||
FileError(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil,
|
|
||||||
"could not find executable name");
|
|
||||||
/* do nothing */
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* now, this is a possible location for the ROOT_DIR, let's look for a share
|
|
||||||
* directory here */
|
|
||||||
pt[1] = '\0';
|
|
||||||
/* grosse */
|
|
||||||
strncat(LOCAL_FileNameBuf, "lib\\Yap", YAP_FILENAME_MAX);
|
|
||||||
libdir = Yap_AllocCodeSpace(strlen(LOCAL_FileNameBuf) + 1);
|
|
||||||
strncpy(libdir, LOCAL_FileNameBuf, strlen(LOCAL_FileNameBuf) + 1);
|
|
||||||
pt[1] = '\0';
|
|
||||||
strncat(LOCAL_FileNameBuf, "share", YAP_FILENAME_MAX);
|
|
||||||
}
|
|
||||||
strncat(LOCAL_FileNameBuf, "\\", YAP_FILENAME_MAX);
|
|
||||||
len = strlen(LOCAL_FileNameBuf);
|
|
||||||
strncat(LOCAL_FileNameBuf, "Yap", YAP_FILENAME_MAX);
|
|
||||||
if (!dir_done && is_directory(LOCAL_FileNameBuf)) {
|
|
||||||
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
|
|
||||||
return FALSE;
|
|
||||||
dir_done = true;
|
|
||||||
}
|
|
||||||
LOCAL_FileNameBuf[len] = '\0';
|
|
||||||
strncat(LOCAL_FileNameBuf, "PrologCommons", YAP_FILENAME_MAX);
|
|
||||||
if (!commons_done && is_directory(LOCAL_FileNameBuf)) {
|
|
||||||
if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
|
|
||||||
return FALSE;
|
|
||||||
commons_done = true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return dir_done && commons_done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int libraries_directories(USES_REGS1) {
|
static Int libraries_directories(USES_REGS1) {
|
||||||
@ -1134,9 +1047,9 @@ int Yap_volume_header(char *file) { return volume_header(file); }
|
|||||||
const char *Yap_getcwd(char *cwd, size_t cwdlen) {
|
const char *Yap_getcwd(char *cwd, size_t cwdlen) {
|
||||||
if (virtual_cwd[0]) {
|
if (virtual_cwd[0]) {
|
||||||
if (!cwd) {
|
if (!cwd) {
|
||||||
cwd = malloc(cwdlen+1);
|
cwd = malloc(cwdlen + 1);
|
||||||
}
|
}
|
||||||
strcpy( cwd, virtual_cwd);
|
strcpy(cwd, virtual_cwd);
|
||||||
return cwd;
|
return cwd;
|
||||||
}
|
}
|
||||||
#if _WIN32 || defined(__MINGW32__)
|
#if _WIN32 || defined(__MINGW32__)
|
||||||
@ -1171,184 +1084,6 @@ static Int working_directory(USES_REGS1) {
|
|||||||
return Yap_ChDir(RepAtom(AtomOfTerm(t2))->StrOfAE);
|
return Yap_ChDir(RepAtom(AtomOfTerm(t2))->StrOfAE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Yap_findFile(): tries to locate a file, no expansion should be performed/
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param isource the proper file
|
|
||||||
* @param idef the default name fothe file, ie, startup.yss
|
|
||||||
* @param root the prefix
|
|
||||||
* @param result the output
|
|
||||||
* @param access verify whether the file has access permission
|
|
||||||
* @param ftype saved state, object, saved file, prolog file
|
|
||||||
* @param expand_root expand $ ~, etc
|
|
||||||
* @param in_lib library file
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
const char *Yap_findFile(const char *isource, const char *idef,
|
|
||||||
const char *iroot, char *result, bool access,
|
|
||||||
YAP_file_type_t ftype, bool expand_root, bool in_lib) {
|
|
||||||
|
|
||||||
char *save_buffer = NULL;
|
|
||||||
char *root, *source;
|
|
||||||
int rc = FAIL_RESTORE;
|
|
||||||
int try = 0;
|
|
||||||
bool abspath = false;
|
|
||||||
|
|
||||||
int lvl = push_text_stack();
|
|
||||||
root = Malloc(YAP_FILENAME_MAX+1);
|
|
||||||
source= Malloc(YAP_FILENAME_MAX+1);
|
|
||||||
if (iroot && iroot[0])
|
|
||||||
strcpy(root, iroot);
|
|
||||||
else
|
|
||||||
root[0] = 0;
|
|
||||||
if (isource && isource[0])
|
|
||||||
strcpy(source, isource);
|
|
||||||
else
|
|
||||||
source[0] = 0;
|
|
||||||
//__android_log_print(ANDROID_LOG_ERROR, "YAPDroid " __FUNCTION__,
|
|
||||||
// "try=%d %s %s", try, isource, iroot) ; }
|
|
||||||
while (rc == FAIL_RESTORE) {
|
|
||||||
// means we failed this iteration
|
|
||||||
bool done = false;
|
|
||||||
// { CACHE_REGS
|
|
||||||
switch (try ++) {
|
|
||||||
case 0: // path or file name is given;
|
|
||||||
if (!source[0] && idef && idef[0]) {
|
|
||||||
strcpy(source, idef);
|
|
||||||
}
|
|
||||||
if (source[0]) {
|
|
||||||
abspath = Yap_IsAbsolutePath(source, expand_root);
|
|
||||||
}
|
|
||||||
if (!abspath && !root[0] && ftype == YAP_BOOT_PL) {
|
|
||||||
strcpy(root, YAP_PL_SRCDIR);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1: // library directory is given in command line
|
|
||||||
if (in_lib && ftype == YAP_SAVED_STATE) {
|
|
||||||
if (iroot && iroot[0])
|
|
||||||
strcpy(root, iroot);
|
|
||||||
else
|
|
||||||
root[0] = 0;
|
|
||||||
if (isource && isource[0])
|
|
||||||
strcpy(source, isource);
|
|
||||||
else if (idef && idef[0])
|
|
||||||
strcpy(source, idef);
|
|
||||||
else
|
|
||||||
source[0] = 0;
|
|
||||||
} else {
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 3: // use compilation variable YAPLIBDIR
|
|
||||||
if (in_lib) {
|
|
||||||
if (isource && isource[0])
|
|
||||||
strcpy(source, isource);
|
|
||||||
else if (idef && idef[0])
|
|
||||||
strcpy(source, idef);
|
|
||||||
else
|
|
||||||
source[0] = 0;
|
|
||||||
if (ftype == YAP_PL) {
|
|
||||||
strcpy(root,YAP_SHAREDIR);
|
|
||||||
} else if (ftype == YAP_BOOT_PL) {
|
|
||||||
strcpy(root, YAP_SHAREDIR);
|
|
||||||
strcat(root,"/pl");
|
|
||||||
} else {
|
|
||||||
strcpy(root,YAP_LIBDIR);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
done = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4: // WIN stuff: registry
|
|
||||||
#if __WINDOWS
|
|
||||||
if (in_lib) {
|
|
||||||
const char *key = (ftype == YAP_PL || ftype == YAP_QLY ? "library" : "startup");
|
|
||||||
strcpy( source, Yap_RegistryGetString(source) );
|
|
||||||
root[0] = 0;
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
done = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 5: // search from the binary
|
|
||||||
#ifndef __ANDROID__
|
|
||||||
{
|
|
||||||
done = true;
|
|
||||||
} break;
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
const char *pt = Yap_FindExecutable();
|
|
||||||
|
|
||||||
if (pt) {
|
|
||||||
if (ftype == YAP_BOOT_PL) {
|
|
||||||
#if __ANDROID__
|
|
||||||
strcpy(root, "../../../files/Yap/pl");
|
|
||||||
#else
|
|
||||||
root = "../../share/Yap/pl";
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
strcpy(root, (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ
|
|
||||||
? "../../lib/Yap"
|
|
||||||
: "../../share/Yap"));
|
|
||||||
}
|
|
||||||
if (strcmp(root, iroot) == 0) {
|
|
||||||
done = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!save_buffer) {
|
|
||||||
save_buffer = Malloc(YAP_FILENAME_MAX + 1);
|
|
||||||
|
|
||||||
save_buffer[0] = 0;
|
|
||||||
}
|
|
||||||
if (Yap_findFile(source, NULL, root, save_buffer, access, ftype,
|
|
||||||
expand_root, in_lib))
|
|
||||||
strcpy(root, save_buffer);
|
|
||||||
else
|
|
||||||
done = true;
|
|
||||||
} else {
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
if (isource && isource[0])
|
|
||||||
strcpy(source, isource);
|
|
||||||
else if (idef && idef[0])
|
|
||||||
strcpy(source, idef);
|
|
||||||
else
|
|
||||||
source[0] = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 6: // default, try current directory
|
|
||||||
if (!isource && ftype == YAP_SAVED_STATE)
|
|
||||||
strcpy(source, idef);
|
|
||||||
root[0] = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
pop_text_stack(lvl);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (done)
|
|
||||||
continue;
|
|
||||||
// { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__,
|
|
||||||
// "root= %s %s ", root, source) ; }
|
|
||||||
const char *work = PlExpandVars(source, root, result);
|
|
||||||
|
|
||||||
|
|
||||||
// expand names in case you have
|
|
||||||
// to add a prefix
|
|
||||||
if (!access || Yap_Exists(work)) {
|
|
||||||
work = pop_output_text_stack(lvl,work);
|
|
||||||
return work; // done
|
|
||||||
} else if (abspath) {
|
|
||||||
pop_text_stack(lvl);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pop_text_stack(lvl);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Int true_file_name(USES_REGS1) {
|
static Int true_file_name(USES_REGS1) {
|
||||||
Term t = Deref(ARG1);
|
Term t = Deref(ARG1);
|
||||||
const char *s;
|
const char *s;
|
||||||
@ -1414,10 +1149,10 @@ static Int true_file_name3(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
root = RepAtom(AtomOfTerm(t2))->StrOfAE;
|
root = RepAtom(AtomOfTerm(t2))->StrOfAE;
|
||||||
}
|
}
|
||||||
if (!Yap_findFile(RepAtom(AtomOfTerm(t))->StrOfAE, NULL, root,
|
char tmp[YAP_FILENAME_MAX + 1];
|
||||||
LOCAL_FileNameBuf, false, YAP_PL, false, false))
|
if (!Yap_AbsoluteFile(RepAtom(AtomOfTerm(t))->StrOfAE, tmp, true))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
return Yap_unify(ARG3, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)));
|
return Yap_unify(ARG3, MkAtomTerm(Yap_LookupAtom(tmp)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Executes $SHELL under Prolog */
|
/* Executes $SHELL under Prolog */
|
||||||
@ -1864,7 +1599,7 @@ static Int p_win32(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int p_ld_path(USES_REGS1) {
|
static Int p_ld_path(USES_REGS1) {
|
||||||
return Yap_unify(ARG1, MkAtomTerm(Yap_LookupAtom(YAP_DLLDIR)));
|
return Yap_unify(ARG1, MkAtomTerm(Yap_LookupAtom(Yap_DLLDIR)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int p_address_bits(USES_REGS1) {
|
static Int p_address_bits(USES_REGS1) {
|
||||||
|
@ -7,6 +7,7 @@ set(PL_BOOT_SOURCES
|
|||||||
attributes.yap
|
attributes.yap
|
||||||
boot.yap
|
boot.yap
|
||||||
bootlists.yap
|
bootlists.yap
|
||||||
|
bootutils.yap
|
||||||
callcount.yap
|
callcount.yap
|
||||||
checker.yap
|
checker.yap
|
||||||
consult.yap
|
consult.yap
|
||||||
@ -84,6 +85,9 @@ install(FILES ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP}
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
install(FILES ${PL_SOURCES}
|
install(FILES ${PL_BOOT_SOURCES}
|
||||||
DESTINATION ${libpl}/pl
|
DESTINATION ${libpl}/pl
|
||||||
)
|
)
|
||||||
|
install(FILES ../library/ypp.yap
|
||||||
|
DESTINATION ${libpl}/library
|
||||||
|
)
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
:- system_module( '$_arith', [compile_expressions/0,
|
:- system_module( '$_arith', [compile_expressions/0,
|
||||||
expand_exprs/2,
|
expand_exprs/2,
|
||||||
plus/3,
|
plus/3,
|
||||||
succ/2], ['$c_built_in'/3]).
|
succ/2], ['$c_built_in'/4]).
|
||||||
|
|
||||||
:- private( [do_c_built_in/3,
|
:- private( [do_c_built_in/3,
|
||||||
do_c_built_metacall/3,
|
do_c_built_metacall/3,
|
||||||
@ -86,7 +86,6 @@ expand_exprs(Old,New) :-
|
|||||||
After a call to this predicate, arithmetical expressions will be compiled.
|
After a call to this predicate, arithmetical expressions will be compiled.
|
||||||
(see example below). This is the default behavior.
|
(see example below). This is the default behavior.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
compile_expressions :- set_value('$c_arith',true).
|
compile_expressions :- set_value('$c_arith',true).
|
||||||
|
|
||||||
/** @pred do_not_compile_expressions
|
/** @pred do_not_compile_expressions
|
||||||
|
@ -118,6 +118,7 @@ otherwise.
|
|||||||
|
|
||||||
:- compile_expressions.
|
:- compile_expressions.
|
||||||
|
|
||||||
|
|
||||||
:- bootstrap('bootutils.yap').
|
:- bootstrap('bootutils.yap').
|
||||||
:- bootstrap('bootlists.yap').
|
:- bootstrap('bootlists.yap').
|
||||||
:- bootstrap('consult.yap').
|
:- bootstrap('consult.yap').
|
||||||
|
@ -57,7 +57,7 @@ variable:
|
|||||||
+ YAPLIBDIR
|
+ YAPLIBDIR
|
||||||
|
|
||||||
if defined, or in the default library.
|
if defined, or in the default library.
|
||||||
|
available as
|
||||||
YAP supports the SWI-Prolog interface to loading foreign code, the shlib package.
|
YAP supports the SWI-Prolog interface to loading foreign code, the shlib package.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
@ -30,6 +30,9 @@ meta_predicate declaration
|
|||||||
|
|
||||||
% directive now meta_predicate Ps :- $meta_predicate(Ps).
|
% directive now meta_predicate Ps :- $meta_predicate(Ps).
|
||||||
|
|
||||||
|
:- use_system_module( '$_arith', ['$c_built_in'/4]).
|
||||||
|
|
||||||
|
|
||||||
:- dynamic prolog:'$meta_predicate'/4.
|
:- dynamic prolog:'$meta_predicate'/4.
|
||||||
|
|
||||||
:- multifile prolog:'$meta_predicate'/4,
|
:- multifile prolog:'$meta_predicate'/4,
|
||||||
|
Reference in New Issue
Block a user