This commit is contained in:
Vitor Santoss Costa 2017-02-22 11:32:28 +00:00
commit 477772e703
374 changed files with 33890 additions and 39248 deletions

203
#.gitignore# Normal file
View File

@ -0,0 +1,203 @@
*~
*.itf
*.po
*.qlf
*.xwam
*.wam
*.ma
*.s
*.o
*.so
*.dylib
*.dll
docs/yap.info*
.build
tags
TGSautom4te.cache
cscope.*
GPATH
m32
GRTAGS
GTAGS
tmtags*
.autotools
.Rhistory
.zedstate
config.h
Yap.h
YapConfig.h
YapTermConfig.h
.graffiti
.#*#
*/#*#
*bak
*rej
*.db
groups
*.ede
.??*
*ggtags*
.atom-build.josn
.autotools
.cproject
.dir-locals.el
.DS_store
.kateproject
.project
.pydevproject
.Rhistory
.zedstate
.graffiti
.kateproject
autom4te.cache
*rej
#*
#*#
config.h
*.html
packages/gecode/dev
JIT/HPP/bkp
cmake_install.cmake
cmake_clean.cmake
*.build
C/myabsmi.c
*.ctags#
*.hs
CMakeFiles
*.make
C/new_iop.c
*.pdf
*.log
*.orig
JIT/HPP/#JIT_In#
*.text
yap
*startup.yss
*cmake_files
C/pl-yap.c
GitSHA1.c
.vscode
CMakeLists.txt.*
FindPackageLog.txt
GitSHA1.c
clang
cmake-build-debug
os/YapIOConfig.h
CodeBlocks
os/readterm.c.cpp
os/readterm.c.cpp
packages/ProbLog/problog_examples/output/,_query_1_cluster_1.dot
packages/ProbLog/#problog_lbdd.yap#
packages/ProbLog/problog_examples/output/,_query_1_cluster_1.dot
packages/ProbLog/problog_examples/output/out.dat
packages/ProbLog/problog_examples/outputvalues.pl
packages/ProbLog/problogbdd
packages/raptor/raptor_config.h
packages/real/rconfig.h
packages/ProbLog/problog/#completion.yap#
packages/ProbLog/problog_examples/output
packages/ProbLog/problog_examples/queries
packages/swig/java/*.java
packages/swig/java/*.class
packages/swig/java/*.jar
packages/swig/java/*wrap*
*jnilib
*.jar
*LOG
packages/cplint/approx/simplecuddLPADs/LPADBDD
packages/swi-minisat2/˜:ilp
packages/swig/android/app
packages/cplint/L
packages/CLPBN/horus/hcli
tmp
Eclipse
packages/bdd/simplecudd/problogbdd
trace
packages/bdd/cudd_config.h
Makefile
build
Debug
debug
Release
Build
xcode
Threads
droid
mxe
mxe32
msys2
caret
codelite
configure
Qt
cmake/cmake-android
sublime
yap-6.3.workspace
yap-6.3.geany
YAP.project
CBlocks
yPQ
*.tmp
YAP.sublime*
yap32
Eclipse
codeblocks
yap-6.3.tags
android
yap.prj
yap.VITORs-MBP.vsc.pui
vc
packages/myddas/pl/myddas_odbc.yap
packages/myddas/pl/myddas_postgres.yap
packages/myddas/pl/myddas_sqlite3.ypp
packages/myddas/pl/#myddas_postgres.ypp#
packages/myddas/hh
packages/myddas/DaysInHospital_Y3.csv
packages/myddas/agile.csv
*.pyc
*.cmake#
*.tex
*.c#
packages/swig/yap_wrap.cxx
packages/swig/yap_wrap.h
packages/swig/yap_wrap.cpp
packages/swig/yap.py
*.ipynb
yap
packages/python/yap_kernel/x/__init__.py
x
packages/python/yap_kernel/x/__main__.py
*.gch
mxe
build

2
#GitSHA1.c.in# Normal file
View File

@ -0,0 +1,2 @@
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee#define GIT_SHA1 "@GIT_SHA1@"
const char g_GIT_SHA1[] = GIT_SHA1;

View File

@ -1,2 +1,20 @@
ENABLE_VARS="jit|no|WITH_JIT clpbn|yes|WITH_CLPBN cplint|yes|WITH_CPLINT horus|yes|WITH_HORUS docs|no|WITH_DOCS problog|yes|WITH_PROBLOG" ENABLE_VARS="clpbn|yes|WITH_CLPBN \
WITH_VARS="swig|yes|WITH_SWIG gecode|yes|WITH_GECODE R|yes|WITH_REAL cudd|yes|WITH_BDD python|yes|WITH_PYTHON " cplint|yes|WITH_CPLINT \
horus|yes|WITH_HORUS \
clpr|yes|WITH_CLPR \
problog|yes|WITH_PROBLOG \
jit|no|WITH_JIT \
chr|no|WITH_CHR \
threads|no|WITH_THREADS"
WITH_VARS="swig|yes|WITH_SWIG \
mpi|yes|WITH_MPI \
gecode|yes|WITH_GECODE \
docs|yes|WITH_DOCS \
r|yes|WITH_REAL \
cudd|yes|WITH_CUDD \
xml2|yes|WITH_XML2 \
raptor|yes|WITH_RAPTOR \
python|yes|WITH_PYTHON \
openssl|yes|WITH_OPENSSL\
readline|yes|WITH_READLINE \
gmp|yes|WITH_GMP "

6
.ctags
View File

@ -6,6 +6,7 @@
--regex-Prolog=/^([a-z][A-Za-z0-9_]*:)?\'(.*)\'\(.*\)\.[ \t]*.*/\2/p,predicate,predicate definition/ --regex-Prolog=/^([a-z][A-Za-z0-9_]*:)?\'(.*)\'\(.*\)\.[ \t]*.*/\2/p,predicate,predicate definition/
--regex-Prolog=/^:-[ \t]+(discontiguous|dynamic|multifile|table|thread_local)[ \t]+([a-z][_a-zA-Z0-9]*:)?([a-z0-9_][_a-zA-Z0-9]*)/\1/p,predicate,predicate metadata/ --regex-Prolog=/^:-[ \t]+(discontiguous|dynamic|multifile|table|thread_local)[ \t]+([a-z][_a-zA-Z0-9]*:)?([a-z0-9_][_a-zA-Z0-9]*)/\1/p,predicate,predicate metadata/
--regex-Prolog=/^[ \t]*Yap_InitCPred[ \t]*\"(\$?[A-Za-z0-9_]*)\"([ \t]*).*/\1/p,predicate,predicate definition/ --regex-Prolog=/^[ \t]*Yap_InitCPred[ \t]*\"(\$?[A-Za-z0-9_]*)\"([ \t]*).*/\1/p,predicate,predicate definition/
--langmap=C:+.(h.cmake).(h.config)
--exclude=\._* --exclude=\._*
--exclude=*\.bak --exclude=*\.bak
--exclude=\.svn --exclude=\.svn
@ -22,3 +23,8 @@
--exclude=\#.* --exclude=\#.*
--exclude=(.)\#* --exclude=(.)\#*
--exclude=*.dylib --exclude=*.dylib
--exclude=docs
--exclude=build
--exclude=cmake-build-debug
--exclude=clang

14
.gitignore vendored
View File

@ -80,15 +80,11 @@ GitSHA1.c
CMakeLists.txt.* CMakeLists.txt.*
FindPackageLog.txt FindPackageLog.txt
GitSHA1.c GitSHA1.c
clang
GitSHA1.c cmake-build-debug
os/YapIOConfig.h os/YapIOConfig.h
CodeBlocks
os/YapIOConfig.h x
os/YapIOConfig.h
os/readterm.c.cpp os/readterm.c.cpp
os/readterm.c.cpp os/readterm.c.cpp
@ -203,3 +199,5 @@ packages/python/yap_kernel/x/__init__.py
packages/python/yap_kernel/x/__main__.py packages/python/yap_kernel/x/__main__.py
*.gch *.gch
mxe
build

View File

@ -12,7 +12,7 @@
#ifdef BEAM #ifdef BEAM
#include "Yap.h" #include "Yap.h"
#include "compile.h" #include "YapCompile.h"
#include "clause.h" #include "clause.h"
#include "eam.h" #include "eam.h"
#include "eamamasm.h" #include "eamamasm.h"

View File

@ -12,7 +12,7 @@
#ifdef BEAM #ifdef BEAM
#include "Yap.h" #include "Yap.h"
#include "compile.h" #include "YapCompile.h"
#include "clause.h" #include "clause.h"
#include "eam.h" #include "eam.h"
#include <stdio.h> #include <stdio.h>

View File

@ -1,4 +1,4 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog * * YAP Prolog *
* * * *
@ -78,7 +78,7 @@ void *my_malloc(size_t sz) {
p = malloc(sz); p = malloc(sz);
// Yap_DebugPuts(stderr,"gof\n"); // Yap_DebugPuts(stderr,"gof\n");
if (Yap_do_low_level_trace) if (Yap_do_low_level_trace)
fprintf(stderr, "+ %p : %lu\n", p, sz); fprintf(stderr, "+ %p: %" Sizet_F "\n", p, sz);
if (sz > 500 && write_malloc++ > 0) if (sz > 500 && write_malloc++ > 0)
__android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "+ %d %p", write_malloc, __android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "+ %d %p", write_malloc,
p); p);
@ -90,7 +90,7 @@ void *my_realloc(void *ptr, size_t sz) {
p = realloc(ptr, sz); p = realloc(ptr, sz);
if (Yap_do_low_level_trace) if (Yap_do_low_level_trace)
// fprintf(stderr, "+ %p -> %p : %lu\n", ptr, p, sz); // fprintf(stderr, "+ %p -> %p : " Sizet_F "\n", ptr, p, sz);
// Yap_DebugPuts(stderr,"gof\n"); // Yap_DebugPuts(stderr,"gof\n");
if (sz > 500 && write_malloc++ > 0) if (sz > 500 && write_malloc++ > 0)
__android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "* %d %p", write_malloc, __android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "* %d %p", write_malloc,

View File

@ -188,7 +188,7 @@ static char SccsId[] = "@(#)amasm.c 1.3 3/15/90";
#include "Yap.h" #include "Yap.h"
#include "clause.h" #include "clause.h"
#include "compile.h" #include "YapCompile.h"
#include "yapio.h" #include "yapio.h"
#ifdef BEAM #ifdef BEAM

View File

@ -111,7 +111,7 @@ static char SccsId[] = "%W% %G%";
#include "Yap.h" #include "Yap.h"
#include "Yatom.h" #include "Yatom.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "eval.h" #include "YapEval.h"

View File

@ -228,7 +228,7 @@ X is Y*10+C-48.
#include "Yap.h" #include "Yap.h"
#include "Yatom.h" #include "Yatom.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "eval.h" #include "YapEval.h"
static Term static Term
float_to_int(Float v USES_REGS) float_to_int(Float v USES_REGS)
@ -1075,4 +1075,3 @@ Yap_ReInitUnaryExps(void)
{ {
return TRUE; return TRUE;
} }

View File

@ -127,7 +127,7 @@ These are the binary numeric operators currently supported by YAP.
#include "Yap.h" #include "Yap.h"
#include "Yatom.h" #include "Yatom.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "eval.h" #include "YapEval.h"
#include "arith2.h" #include "arith2.h"

View File

@ -102,7 +102,7 @@ The following predicates manipulate arrays:
#include "Yap.h" #include "Yap.h"
#include "Yatom.h" #include "Yatom.h"
#include "clause.h" #include "clause.h"
#include "eval.h" #include "YapEval.h"
#include "heapgc.h" #include "heapgc.h"
#if HAVE_ERRNO_H #if HAVE_ERRNO_H
#include <errno.h> #include <errno.h>

1152
C/atomic.c Normal file → Executable file

File diff suppressed because it is too large Load Diff

View File

@ -28,10 +28,11 @@ static char SccsId[] = "%W% %G%";
#define NULL (void *)0 #define NULL (void *)0
#endif #endif
/** @{ */ /** @file attvars.c
@{ */
/** @defgroup AttributeVariables_Builtins Implementation of Attribute /**
Declarations * @defgroup AttributeVariables_Builtins Implementation of Attribute Declarations
@ingroup AttributeVariables @ingroup AttributeVariables
*/ */

View File

@ -30,7 +30,7 @@ static char SccsId[] = "%W% %G%";
#ifdef USE_GMP #ifdef USE_GMP
#include "eval.h" #include "YapEval.h"
#include "alloc.h" #include "alloc.h"
Term Term

View File

@ -127,8 +127,7 @@ X_API yhandle_t YAP_CurrentSlot(void);
/// @brief allocate n empty new slots /// @brief allocate n empty new slots
/// ///
/// Return a handle to the system's default slot. /// Return a handle to the system's default slo t. iX_API yhandle_t YAP_NewSlots(int NumberOfSlots);
X_API yhandle_t YAP_NewSlots(int NumberOfSlots);
/// @brief allocate n empty new slots /// @brief allocate n empty new slots
/// ///
@ -246,6 +245,8 @@ X_API YAP_Bool YAP_IsRationalTerm(YAP_Term t) {
#endif #endif
} }
X_API YAP_Bool YAP_IsStringTerm(YAP_Term t) { return (IsStringTerm(t)); }
X_API YAP_Bool YAP_IsVarTerm(YAP_Term t) { return (IsVarTerm(t)); } X_API YAP_Bool YAP_IsVarTerm(YAP_Term t) { return (IsVarTerm(t)); }
X_API YAP_Bool YAP_IsNonVarTerm(YAP_Term t) { return (IsNonVarTerm(t)); } X_API YAP_Bool YAP_IsNonVarTerm(YAP_Term t) { return (IsNonVarTerm(t)); }
@ -277,6 +278,32 @@ X_API Term YAP_MkIntTerm(Int n) {
return I; return I;
} }
X_API Term YAP_MkStringTerm(const char *n) {
CACHE_REGS
Term I;
BACKUP_H();
I = MkStringTerm(n);
RECOVER_H();
return I;
}
X_API Term YAP_MkUnsignedStringTerm(const unsigned char *n) {
CACHE_REGS
Term I;
BACKUP_H();
I = MkUStringTerm(n);
RECOVER_H();
return I;
}
X_API const char *YAP_StringOfTerm(Term t) { return StringOfTerm(t); }
X_API const unsigned char *YAP_UnsignedStringOfTerm(Term t) {
return UStringOfTerm(t);
}
X_API Int YAP_IntOfTerm(Term t) { X_API Int YAP_IntOfTerm(Term t) {
if (!IsApplTerm(t)) if (!IsApplTerm(t))
return IntOfTerm(t); return IntOfTerm(t);
@ -399,11 +426,11 @@ X_API Term YAP_MkAtomTerm(Atom n) {
X_API Atom YAP_AtomOfTerm(Term t) { return (AtomOfTerm(t)); } X_API Atom YAP_AtomOfTerm(Term t) { return (AtomOfTerm(t)); }
X_API bool YAP_IsWideAtom(Atom a) { X_API bool YAP_IsWideAtom(Atom a) {
const unsigned char *s = RepAtom(a)->UStrOfAE; const unsigned char *s = RepAtom(a)->UStrOfAE;
int32_t v; int32_t v;
while (*s) { while (*s) {
size_t n = get_utf8(s,1,&v); size_t n = get_utf8(s, 1, &v);
if (n>1) if (n > 1)
return true; return true;
} }
return false; return false;
@ -419,15 +446,15 @@ X_API const char *YAP_AtomName(Atom a) {
X_API const wchar_t *YAP_WideAtomName(Atom a) { X_API const wchar_t *YAP_WideAtomName(Atom a) {
int32_t v; int32_t v;
const unsigned char *s = RepAtom(a)->UStrOfAE; const unsigned char *s = RepAtom(a)->UStrOfAE;
size_t n = strlen_utf8( s ); size_t n = strlen_utf8(s);
wchar_t *dest = Malloc( (n+1)* sizeof(wchar_t)), *o = dest; wchar_t *dest = Malloc((n + 1) * sizeof(wchar_t)), *o = dest;
while (*s) { while (*s) {
size_t n = get_utf8(s,1,&v); size_t n = get_utf8(s, 1, &v);
if (n==0) if (n == 0)
return NULL; return NULL;
*o++ = v; *o++ = v;
} }
o[0] = '\0'; o[0] = '\0';
return dest; return dest;
} }
@ -453,9 +480,8 @@ X_API Atom YAP_LookupWideAtom(const wchar_t *c) {
CACHE_REGS CACHE_REGS
Atom a; Atom a;
while (TRUE) { while (TRUE) {
a = Yap_NWCharsToAtom(c, -1 USES_REGS); a = Yap_NWCharsToAtom(c, -1 USES_REGS);
if (a == NIL || Yap_get_signal(YAP_CDOVF_SIGNAL)) { if (a == NIL || Yap_get_signal(YAP_CDOVF_SIGNAL)) {
if (!Yap_locked_growheap(FALSE, 0, NULL)) { if (!Yap_locked_growheap(FALSE, 0, NULL)) {
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "YAP failed to grow heap: %s", Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "YAP failed to grow heap: %s",
@ -490,10 +516,9 @@ X_API size_t YAP_AtomNameLength(Atom at) {
if (IsBlob(at)) { if (IsBlob(at)) {
return RepAtom(at)->rep.blob->length; return RepAtom(at)->rep.blob->length;
} }
unsigned char *c = RepAtom(at)->UStrOfAE; unsigned char *c = RepAtom(at)->UStrOfAE;
return strlen_utf8(c);
return strlen_utf8(c);
} }
X_API Term YAP_MkVarTerm(void) { X_API Term YAP_MkVarTerm(void) {
@ -1376,10 +1401,14 @@ X_API Term YAP_ReadBuffer(const char *s, Term *tp) {
Term tv, t; Term tv, t;
BACKUP_H(); BACKUP_H();
if (*tp) tv = *tp; else tv = 0; if (*tp)
tv = *tp;
else
tv = 0;
LOCAL_ErrorMessage = NULL; LOCAL_ErrorMessage = NULL;
while (!(t = Yap_StringToTerm(s, strlen(s) + 1, &LOCAL_encoding, const unsigned char *us = (const unsigned char *)s;
GLOBAL_MaxPriority,tv))) { while (!(t = Yap_BufferToTermWithPrioBindings(us, strlen(s) + 1, TermNil,
GLOBAL_MaxPriority, tv))) {
if (LOCAL_ErrorMessage) { if (LOCAL_ErrorMessage) {
if (!strcmp(LOCAL_ErrorMessage, "Stack Overflow")) { if (!strcmp(LOCAL_ErrorMessage, "Stack Overflow")) {
if (!Yap_dogc(0, NULL PASS_REGS)) { if (!Yap_dogc(0, NULL PASS_REGS)) {
@ -1636,7 +1665,6 @@ X_API PredEntry *YAP_AtomToPredInModule(Atom at, Term mod) {
static int run_emulator(USES_REGS1) { static int run_emulator(USES_REGS1) {
int out; int out;
LOCAL_PrologMode &= ~(UserCCallMode | CCallMode);
out = Yap_absmi(0); out = Yap_absmi(0);
LOCAL_PrologMode |= UserCCallMode; LOCAL_PrologMode |= UserCCallMode;
return out; return out;
@ -1659,7 +1687,7 @@ X_API bool YAP_EnterGoal(PredEntry *pe, CELL *ptr, YAP_dogoalinfo *dgi) {
// slot=%d", pe, pe->CodeOfPred->opc, FAILCODE, Deref(ARG1), Deref(ARG2), // slot=%d", pe, pe->CodeOfPred->opc, FAILCODE, Deref(ARG1), Deref(ARG2),
// LOCAL_CurSlot); // LOCAL_CurSlot);
dgi->b = LCL0 - (CELL *)B; dgi->b = LCL0 - (CELL *)B;
out = run_emulator(PASS_REGS1); out = Yap_exec_absmi(true, false);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
if (out) { if (out) {
dgi->EndSlot = LOCAL_CurSlot; dgi->EndSlot = LOCAL_CurSlot;
@ -2107,7 +2135,7 @@ X_API void YAP_Write(Term t, FILE *f, int flags) {
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
} }
X_API Term YAP_CopyTerm(Term t) { X_API YAP_Term YAP_CopyTerm(Term t) {
Term tn; Term tn;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
@ -2115,21 +2143,25 @@ X_API Term YAP_CopyTerm(Term t) {
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return tn; return (tn);
} }
X_API char *YAP_WriteBuffer(Term t, char *buf, size_t sze, int flags) { X_API char *YAP_WriteBuffer(Term t, char *buf, size_t sze, int flags) {
CACHE_REGS CACHE_REGS
size_t length; seq_tv_t inp, out;
size_t length = sze;
char *b; char *b;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
if ((b = Yap_TermToString(t, &length, LOCAL_encoding, flags)) != buf) { inp.val.t = t;
RECOVER_MACHINE_REGS(); inp.type = YAP_STRING_TERM;
return b; out.type = YAP_STRING_CHARS;
} out.val.c = buf;
out.enc = LOCAL_encoding;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return NULL;
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return buf; return out.val.c;
} }
/// write a a term to n user-provided buffer: make sure not tp /// write a a term to n user-provided buffer: make sure not tp
@ -2251,13 +2283,11 @@ static void do_bootfile(const char *bootfilename USES_REGS) {
the module. the module.
*/ */
static bool initialized = false; X_API bool YAP_initialized = false;
static int n_mdelays = 0; static int n_mdelays = 0;
static YAP_delaymodule_t *m_delays; static YAP_delaymodule_t *m_delays;
X_API bool YAP_DelayInit(YAP_ModInit_t f, const char s[]) { X_API bool YAP_DelayInit(YAP_ModInit_t f, const char s[]) {
if (initialized)
return false;
if (m_delays) { if (m_delays) {
m_delays = realloc(m_delays, (n_mdelays + 1) * sizeof(YAP_delaymodule_t)); m_delays = realloc(m_delays, (n_mdelays + 1) * sizeof(YAP_delaymodule_t));
} else { } else {
@ -2269,6 +2299,17 @@ X_API bool YAP_DelayInit(YAP_ModInit_t f, const char s[]) {
return true; 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) { static void start_modules(void) {
Term cm = CurrentModule; Term cm = CurrentModule;
size_t i; size_t i;
@ -2280,7 +2321,7 @@ static void start_modules(void) {
} }
/// whether Yap is under control of some other system /// whether Yap is under control of some other system
bool Yap_embedded; bool Yap_embedded = true;
/* this routine is supposed to be called from an external program /* this routine is supposed to be called from an external program
that wants to control Yap */ that wants to control Yap */
@ -2294,9 +2335,8 @@ YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
const char *yroot; const char *yroot;
/* ignore repeated calls to YAP_Init */ /* ignore repeated calls to YAP_Init */
if (initialized) if (YAP_initialized)
return YAP_FOUND_BOOT_ERROR; return YAP_FOUND_BOOT_ERROR;
initialized = true;
Yap_embedded = yap_init->Embedded; Yap_embedded = yap_init->Embedded;
Yap_page_size = Yap_InitPageSize(); /* init memory page size, required by Yap_page_size = Yap_InitPageSize(); /* init memory page size, required by
@ -2304,10 +2344,12 @@ YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) #if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
Yap_init_yapor_global_local_memory(); Yap_init_yapor_global_local_memory();
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */ #endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
GLOBAL_PrologShouldHandleInterrupts = yap_init->PrologShouldHandleInterrupts; // GLOBAL_PrologShouldHandleInterrupts =
Yap_InitSysbits(0); /* init signal handling and time, required by later // yap_init->PrologShouldHandleInterrupts &&
if (!yap_init->Embedded)
Yap_InitSysbits(0); /* init signal handling and time, required by later
functions */ functions */
GLOBAL_argv = yap_init->Argv; GLOBAL_argv = yap_init->Argv;
GLOBAL_argc = yap_init->Argc; GLOBAL_argc = yap_init->Argc;
if (0 && ((YAP_QLY && yap_init->SavedState) || if (0 && ((YAP_QLY && yap_init->SavedState) ||
(YAP_BOOT_PL && (yap_init->YapPrologBootFile)))) { (YAP_BOOT_PL && (yap_init->YapPrologBootFile)))) {
@ -2368,10 +2410,10 @@ YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
// //
CACHE_REGS CACHE_REGS
if (Yap_embedded) if (Yap_embedded)
if (yap_init->QuietMode) { if (yap_init->QuietMode) {
setVerbosity(TermSilent); setVerbosity(TermSilent);
} }
{ {
if (yap_init->YapPrologRCFile != NULL) { if (yap_init->YapPrologRCFile != NULL) {
/* /*
@ -2489,6 +2531,7 @@ YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false); setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
} }
start_modules(); start_modules();
YAP_initialized = true;
return rc; return rc;
} }
@ -3209,10 +3252,10 @@ size_t YAP_UTF8_TextLength(Term t) {
Term hd = HeadOfTerm(t); Term hd = HeadOfTerm(t);
if (IsAtomTerm(hd)) { if (IsAtomTerm(hd)) {
Atom at = AtomOfTerm(hd); Atom at = AtomOfTerm(hd);
unsigned char *s = RepAtom(at)->UStrOfAE; unsigned char *s = RepAtom(at)->UStrOfAE;
int32_t ch; int32_t ch;
get_utf8(s, 1, &ch); get_utf8(s, 1, &ch);
c = ch; c = ch;
} else if (IsIntegerTerm(hd)) { } else if (IsIntegerTerm(hd)) {
c = IntegerOfTerm(hd); c = IntegerOfTerm(hd);
} else { } else {
@ -3223,8 +3266,8 @@ size_t YAP_UTF8_TextLength(Term t) {
} }
} else if (IsAtomTerm(t)) { } else if (IsAtomTerm(t)) {
Atom at = AtomOfTerm(t); Atom at = AtomOfTerm(t);
sz = strlen(RepAtom(at)->StrOfAE); sz = strlen(RepAtom(at)->StrOfAE);
} else if (IsStringTerm(t)) { } else if (IsStringTerm(t)) {
sz = strlen(StringOfTerm(t)); sz = strlen(StringOfTerm(t));
} }
return sz; return sz;

View File

@ -20,7 +20,7 @@ static char SccsId[] = "@(#)cdmgr.c 1.1 05/02/98";
#include "Yap.h" #include "Yap.h"
#include "clause.h" #include "clause.h"
#include "eval.h" #include "YapEval.h"
#include "tracer.h" #include "tracer.h"
#include "yapio.h" #include "yapio.h"
#ifdef YAPOR #ifdef YAPOR

View File

@ -57,7 +57,7 @@ static char SccsId[] = "%W% %G%";
#include "Yap.h" #include "Yap.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "Yatom.h" #include "Yatom.h"
#include "eval.h" #include "YapEval.h"
#if HAVE_STRING_H #if HAVE_STRING_H
#include <string.h> #include <string.h>
#endif #endif
@ -83,7 +83,7 @@ static Int a_gen_ge(Term, Term);
#define rfloat(X) (X > 0.0 ? 1 : (X == 0.0 ? 0 : -1)) #define rfloat(X) (X > 0.0 ? 1 : (X == 0.0 ? 0 : -1))
static int cmp_atoms(Atom a1, Atom a2) { static int cmp_atoms(Atom a1, Atom a2) {
return strcmp(RepAtom(a1)->StrOfAE, RepAtom(a2)->StrOfAE); return strcmp(RepAtom(a1)->StrOfAE, RepAtom(a2)->StrOfAE);
} }
static Int compare_complex(register CELL *pt0, register CELL *pt0_end, static Int compare_complex(register CELL *pt0, register CELL *pt0_end,
@ -382,7 +382,7 @@ inline static Int compare(Term t1, Term t2) /* compare terms t1 and t2 */
if (f != FunctorDot) if (f != FunctorDot)
return strcmp(".", RepAtom(NameOfFunctor(f))->StrOfAE); return strcmp(".", RepAtom(NameOfFunctor(f))->StrOfAE);
else { else {
return compare_complex(RepPair(t1) - 1, RepPair(t1) + 1, RepAppl(t2) ); return compare_complex(RepPair(t1) - 1, RepPair(t1) + 1, RepAppl(t2));
} }
} }
} }
@ -595,10 +595,12 @@ inline static Int flt_cmp(Float dif) {
static Int a_cmp(Term t1, Term t2 USES_REGS) { static Int a_cmp(Term t1, Term t2 USES_REGS) {
if (IsVarTerm(t1)) { if (IsVarTerm(t1)) {
Yap_ThrowError( INSTANTIATION_ERROR, t1, 4, "while doing arithmetic comparison" ); Yap_ArithError(INSTANTIATION_ERROR, t1,
"while doing arithmetic comparison");
} }
if (IsVarTerm(t2)) { if (IsVarTerm(t2)) {
Yap_ThrowError( INSTANTIATION_ERROR, t1, 4, "while doing arithmetic comparison" ); Yap_ArithError(INSTANTIATION_ERROR, t2,
"while doing arithmetic comparison");
} }
if (IsFloatTerm(t1) && IsFloatTerm(t2)) { if (IsFloatTerm(t1) && IsFloatTerm(t2)) {
return flt_cmp(FloatOfTerm(t1) - FloatOfTerm(t2)); return flt_cmp(FloatOfTerm(t1) - FloatOfTerm(t2));
@ -621,7 +623,8 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) {
Float f2 = FloatOfTerm(t2); Float f2 = FloatOfTerm(t2);
#if HAVE_ISNAN #if HAVE_ISNAN
if (isnan(f2)) { if (isnan(f2)) {
Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, 4, "trying to evaluate nan" ); Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t2,
"trying to evaluate nan");
} }
#endif #endif
return flt_cmp(i1 - f2); return flt_cmp(i1 - f2);
@ -636,7 +639,8 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) {
Float f1 = FloatOfTerm(t1); Float f1 = FloatOfTerm(t1);
#if HAVE_ISNAN #if HAVE_ISNAN
if (isnan(f1)) { if (isnan(f1)) {
Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t1, 4, "trying to evaluate nan" ); Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t1,
"trying to evaluate nan");
} }
#endif #endif
t2 = Yap_Eval(t2); t2 = Yap_Eval(t2);
@ -652,8 +656,9 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) {
Float f2 = FloatOfTerm(t2); Float f2 = FloatOfTerm(t2);
#if HAVE_ISNAN #if HAVE_ISNAN
if (isnan(f2)) { if (isnan(f2)) {
Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, 4, "trying to evaluate nan" ); Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t2,
} "trying to evaluate nan");
}
#endif #endif
return flt_cmp(f1 - f2); return flt_cmp(f1 - f2);
#ifdef USE_GMP #ifdef USE_GMP
@ -674,7 +679,8 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) {
Float f2 = FloatOfTerm(t2); Float f2 = FloatOfTerm(t2);
#if HAVE_ISNAN #if HAVE_ISNAN
if (isnan(f2)) { if (isnan(f2)) {
Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, 4, "trying to evaluate nan" ); Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t2,
"trying to evaluate nan");
} }
#endif #endif
return Yap_gmp_cmp_big_float(t1, f2); return Yap_gmp_cmp_big_float(t1, f2);

View File

@ -174,7 +174,7 @@ static char SccsId[] = "%W% %G%";
#include "Yap.h" #include "Yap.h"
#include "alloc.h" #include "alloc.h"
#include "clause.h" #include "clause.h"
#include "compile.h" #include "YapCompile.h"
#include "yapio.h" #include "yapio.h"
#if HAVE_STRING_H #if HAVE_STRING_H
#include <string.h> #include <string.h>
@ -1081,7 +1081,8 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal,
char s[32]; char s[32];
Yap_bip_name(Op, s); Yap_bip_name(Op, s);
Yap_ThrowError( TYPE_ERROR_NUMBER, t2, "compiling %s/2 with output bound", s); Yap_ThrowError(TYPE_ERROR_NUMBER, t2, 1,
"compiling %s/2 with output bound", s);
save_machine_regs(); save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, 1); siglongjmp(cglobs->cint.CompilerBotch, 1);
} }
@ -1093,7 +1094,7 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal,
char s[32]; char s[32];
Yap_bip_name(Op, s); Yap_bip_name(Op, s);
Yap_ThrowError(INSTANTIATION_ERROR , t2, "compiling %s/3", s); Yap_ThrowError(INSTANTIATION_ERROR, t2, 1, "compiling %s/3", s);
save_machine_regs(); save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, 1); siglongjmp(cglobs->cint.CompilerBotch, 1);
} }
@ -1103,17 +1104,17 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal,
Int i2; Int i2;
if (!IsIntegerTerm(t2)) { if (!IsIntegerTerm(t2)) {
Yap_Error( TYPE_ERROR_INTEGER, t2, "compiling functor/3"); Yap_ThrowError(TYPE_ERROR_INTEGER, t2, 1, "compiling functor/3");
save_machine_regs(); save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, 1); siglongjmp(cglobs->cint.CompilerBotch, 1);
} }
i2 = IntegerOfTerm(t2); i2 = IntegerOfTerm(t2);
if (i2 < 0) { if (i2 < 0) {
Yap_ThrowError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO , t2, "compiling functor/3"); Yap_ThrowError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2,
"compiling functor/3");
save_machine_regs(); save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, 1); siglongjmp(cglobs->cint.CompilerBotch, 1);
} }
if (IsNumTerm(t1)) { if (IsNumTerm(t1)) {
/* we will always fail */ /* we will always fail */
@ -1122,9 +1123,8 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal,
} else if (!IsAtomTerm(t1)) { } else if (!IsAtomTerm(t1)) {
char s[32]; char s[32];
LOCAL_Error_TYPE = TYPE_ERROR_ATOM;
Yap_bip_name(Op, s); Yap_bip_name(Op, s);
sprintf(LOCAL_ErrorMessage, "compiling functor/3"); Yap_ThrowError(TYPE_ERROR_ATOM, t2, 4, "compiling functor/3");
save_machine_regs(); save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, 1); siglongjmp(cglobs->cint.CompilerBotch, 1);
} }
@ -1178,9 +1178,8 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal,
else { else {
char s[32]; char s[32];
LOCAL_Error_TYPE = TYPE_ERROR_INTEGER;
Yap_bip_name(Op, s); Yap_bip_name(Op, s);
sprintf(LOCAL_ErrorMessage, "compiling %s/2", s); Yap_ThrowError(TYPE_ERROR_INTEGER, t1, 1, "compiling %s/2", s);
save_machine_regs(); save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, 1); siglongjmp(cglobs->cint.CompilerBotch, 1);
} }
@ -1190,6 +1189,8 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal,
LOCAL_Error_TYPE = TYPE_ERROR_COMPOUND; LOCAL_Error_TYPE = TYPE_ERROR_COMPOUND;
Yap_bip_name(Op, s); Yap_bip_name(Op, s);
Yap_ThrowError(TYPE_ERROR_COMPOUND, t2, 1, "compiling %s/2", 1, s);
save_machine_regs(); save_machine_regs();
siglongjmp(cglobs->cint.CompilerBotch, 1); siglongjmp(cglobs->cint.CompilerBotch, 1);
} else if (IsApplTerm(t2)) { } else if (IsApplTerm(t2)) {
@ -1476,7 +1477,7 @@ static void c_goal(Term Goal, Term mod, compiler_struct *cglobs) {
PredEntry *p; PredEntry *p;
Prop p0; Prop p0;
Goal = Yap_YapStripModule( Goal, &mod); Goal = Yap_YapStripModule(Goal, &mod);
if (IsVarTerm(Goal)) { if (IsVarTerm(Goal)) {
Goal = Yap_MkApplTerm(FunctorCall, 1, &Goal); Goal = Yap_MkApplTerm(FunctorCall, 1, &Goal);
} else if (IsNumTerm(Goal)) { } else if (IsNumTerm(Goal)) {

View File

@ -60,7 +60,7 @@ static char SccsId[] = "%W% %G%";
#include "Yap.h" #include "Yap.h"
#include "Yatom.h" #include "Yatom.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "compile.h" #include "YapCompile.h"
#include "yapio.h" #include "yapio.h"
#if HAVE_STRING_H #if HAVE_STRING_H
#include <string.h> #include <string.h>
@ -795,4 +795,3 @@ Yap_ShowCode (struct intermediates *cint)
} }
#endif /* DEBUG */ #endif /* DEBUG */

View File

@ -22,7 +22,7 @@ static char SccsId[] = "%W% %G%";
#include "Yap.h" #include "Yap.h"
#include "Yatom.h" #include "Yatom.h"
#include "eval.h" #include "YapEval.h"
#ifdef DEPTH_LIMIT #ifdef DEPTH_LIMIT

View File

@ -207,7 +207,7 @@ void Yap_RestartYap(int flag) {
#if PUSH_REGS #if PUSH_REGS
restore_absmi_regs(&Yap_standard_regs); restore_absmi_regs(&Yap_standard_regs);
#endif #endif
siglongjmp(LOCAL_RestartEnv, 1); siglongjmp(*LOCAL_RestartEnv, 1);
} }
static void error_exit_yap(int value) { static void error_exit_yap(int value) {
@ -311,24 +311,24 @@ yap_error_descriptor_t *Yap_popErrorContext(void) {
} }
void Yap_ThrowError__(const char *file, const char *function, int lineno, void Yap_ThrowError__(const char *file, const char *function, int lineno,
yap_error_number type, Term where, ...) { yap_error_number type, Term where, ...) {
va_list ap; va_list ap;
char tmpbuf[MAXPATHLEN]; char tmpbuf[MAXPATHLEN];
va_start(ap, where); va_start(ap, where);
char *format = va_arg(ap, char *); char *format = va_arg(ap, char *);
if (format != NULL) { if (format != NULL) {
#if HAVE_VSNPRINTF #if HAVE_VSNPRINTF
(void)vsnprintf(tmpbuf, MAXPATHLEN - 1, format, ap); (void)vsnprintf(tmpbuf, MAXPATHLEN - 1, format, ap);
#else #else
(void)vsprintf(tnpbuf, format, ap); (void)vsprintf(tnpbuf, format, ap);
#endif #endif
// fprintf(stderr, "warning: "); // fprintf(stderr, "warning: ");
Yap_Error__(file, function, lineno, type, where, tmpbuf); Yap_Error__(file, function, lineno, type, where, tmpbuf);
} else { } else {
Yap_Error__(file, function, lineno, type, where); Yap_Error__(file, function, lineno, type, where);
} }
siglongjmp(LOCAL_RestartEnv, 4); siglongjmp(*LOCAL_RestartEnv, 4);
} }
/** /**

View File

@ -31,7 +31,7 @@ static char SccsId[] = "%W% %G%";
#include "YapHeap.h" #include "YapHeap.h"
#include "Yatom.h" #include "Yatom.h"
#include "eval.h" #include "YapEval.h"
#if HAVE_STDARG_H #if HAVE_STDARG_H
#include <stdarg.h> #include <stdarg.h>
#endif #endif

180
C/exec.c
View File

@ -48,7 +48,7 @@ static choiceptr cp_from_integer(Term cpt USES_REGS) {
*/ */
Term Yap_cp_as_integer(choiceptr cp) { Term Yap_cp_as_integer(choiceptr cp) {
CACHE_REGS CACHE_REGS
return cp_as_integer(cp PASS_REGS); return cp_as_integer(cp PASS_REGS);
} }
/** /**
@ -128,7 +128,7 @@ inline static bool CallMetaCall(Term t, Term mod USES_REGS) {
*/ */
Term Yap_ExecuteCallMetaCall(Term mod) { Term Yap_ExecuteCallMetaCall(Term mod) {
CACHE_REGS CACHE_REGS
Term ts[4]; Term ts[4];
ts[0] = ARG1; ts[0] = ARG1;
ts[1] = cp_as_integer(B PASS_REGS); /* p_current_choice_point */ ts[1] = cp_as_integer(B PASS_REGS); /* p_current_choice_point */
ts[2] = ARG1; ts[2] = ARG1;
@ -141,8 +141,8 @@ Term Yap_ExecuteCallMetaCall(Term mod) {
Term Yap_PredicateIndicator(Term t, Term mod) { Term Yap_PredicateIndicator(Term t, Term mod) {
CACHE_REGS CACHE_REGS
// generate predicate indicator in this case // generate predicate indicator in this case
Term ti[2]; Term ti[2];
t = Yap_YapStripModule(t, &mod); t = Yap_YapStripModule(t, &mod);
if (IsApplTerm(t) && !IsExtensionFunctor(FunctorOfTerm(t))) { if (IsApplTerm(t) && !IsExtensionFunctor(FunctorOfTerm(t))) {
ti[0] = MkAtomTerm(NameOfFunctor(FunctorOfTerm(t))); ti[0] = MkAtomTerm(NameOfFunctor(FunctorOfTerm(t)));
@ -210,12 +210,12 @@ static Int save_env_b(USES_REGS1) {
} }
/** Look for a predicate with same functor as t, /** Look for a predicate with same functor as t,
create a new one of it cannot find it. create a new one of it cannot find it.
*/ */
static PredEntry *new_pred(Term t, Term tmod, char *pname) { static PredEntry *new_pred(Term t, Term tmod, char *pname) {
Term t0 = t; Term t0 = t;
restart: restart:
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, t0, pname); Yap_Error(INSTANTIATION_ERROR, t0, pname);
return NULL; return NULL;
@ -273,7 +273,7 @@ inline static bool do_execute(Term t, Term mod USES_REGS) {
Term t0 = t; Term t0 = t;
t = Yap_YapStripModule(t, &mod); t = Yap_YapStripModule(t, &mod);
/* first do predicate expansion, even before you process signals. /* first do predicate expansion, even before you process signals.
This way you don't get to spy goal_expansion(). */ This way you don't get to spy goal_expansion(). */
if (Yap_has_a_signal() && !LOCAL_InterruptsDisabled && if (Yap_has_a_signal() && !LOCAL_InterruptsDisabled &&
!(LOCAL_PrologMode & (AbortMode | InterruptMode | SystemMode))) { !(LOCAL_PrologMode & (AbortMode | InterruptMode | SystemMode))) {
return EnterCreepMode(t, mod PASS_REGS); return EnterCreepMode(t, mod PASS_REGS);
@ -315,9 +315,9 @@ inline static bool do_execute(Term t, Term mod USES_REGS) {
/* I cannot use the standard macro here because /* I cannot use the standard macro here because
otherwise I would dereference the argument and otherwise I would dereference the argument and
might skip a svar */ might skip a svar */
if (pen->PredFlags & MetaPredFlag) { if (pen->PredFlags & MetaPredFlag) {
return CallMetaCall(t, mod PASS_REGS); return CallMetaCall(t, mod PASS_REGS);
} }
pt = RepAppl(t) + 1; pt = RepAppl(t) + 1;
for (i = 1; i <= arity; i++) { for (i = 1; i <= arity; i++) {
#if YAPOR_SBA #if YAPOR_SBA
@ -393,7 +393,7 @@ inline static bool do_execute_n(Term t, Term mod, unsigned int n USES_REGS) {
int j = -n; int j = -n;
Term t0 = t; Term t0 = t;
restart_exec: restart_exec:
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
return CallError(INSTANTIATION_ERROR, t0, mod PASS_REGS); return CallError(INSTANTIATION_ERROR, t0, mod PASS_REGS);
} else if (IsAtomTerm(t)) { } else if (IsAtomTerm(t)) {
@ -432,8 +432,8 @@ restart_exec:
} }
if (Yap_has_a_signal() && !LOCAL_InterruptsDisabled) { if (Yap_has_a_signal() && !LOCAL_InterruptsDisabled) {
return EnterCreepMode( return EnterCreepMode(
copy_execn_to_heap(f, pt, n, arity, CurrentModule PASS_REGS), copy_execn_to_heap(f, pt, n, arity, CurrentModule PASS_REGS),
mod PASS_REGS); mod PASS_REGS);
} }
if (arity > MaxTemps) { if (arity > MaxTemps) {
return CallError(TYPE_ERROR_CALLABLE, t, mod PASS_REGS); return CallError(TYPE_ERROR_CALLABLE, t, mod PASS_REGS);
@ -650,7 +650,7 @@ static Int execute_clause(USES_REGS1) { /* '$execute_clause'(Goal) */
yamop *code; yamop *code;
Term clt = Deref(ARG3); Term clt = Deref(ARG3);
restart_exec: restart_exec:
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, ARG3, "call/1"); Yap_Error(INSTANTIATION_ERROR, ARG3, "call/1");
return FALSE; return FALSE;
@ -746,7 +746,7 @@ static void prune_inner_computation(choiceptr parent) {
cut_pt = B; cut_pt = B;
while (cut_pt < parent) { while (cut_pt < parent) {
/* make sure we /* make sure we
e C-choicepoints */ e C-choicepoints */
if (POP_CHOICE_POINT(cut_pt->cp_b)) { if (POP_CHOICE_POINT(cut_pt->cp_b)) {
POP_EXECUTE(); POP_EXECUTE();
} }
@ -791,7 +791,7 @@ static void complete_inner_computation(choiceptr old_B) {
static inline Term *GetTermAddress(CELL a) { static inline Term *GetTermAddress(CELL a) {
Term *b = NULL; Term *b = NULL;
restart: restart:
if (!IsVarTerm(a)) { if (!IsVarTerm(a)) {
return (b); return (b);
} else if (a == (CELL)b) { } else if (a == (CELL)b) {
@ -845,8 +845,8 @@ static bool exit_set_call(execution_port exec_result, choiceptr B0, yamop *oCP,
Term rc; Term rc;
switch (exec_result) { switch (exec_result) {
// we failed // we failed
// Exception: we'll pass it through // Exception: we'll pass it through
case CALLED_FROM_EXCEPTION: case CALLED_FROM_EXCEPTION:
// internal exception // internal exception
{ {
@ -905,8 +905,8 @@ static bool exit_set_call(execution_port exec_result, choiceptr B0, yamop *oCP,
choiceptr saved_b = B; choiceptr saved_b = B;
CELL *pt = ASP; CELL *pt = ASP;
CUT_C_PUSH( CUT_C_PUSH(
NEXTOP(NEXTOP(PredProtectStack->cs.p_code.FirstClause, OtapFs), OtapFs), NEXTOP(NEXTOP(PredProtectStack->cs.p_code.FirstClause, OtapFs), OtapFs),
pt); // this is where things get complicated, we need to pt); // this is where things get complicated, we need to
// protect the stack and be able to backtrack // protect the stack and be able to backtrack
pt -= 4; pt -= 4;
pt[3] = t4; pt[3] = t4;
@ -955,7 +955,7 @@ static Int protect_stack_from_cut(USES_REGS1) {
* @param USES_REGS1 [env for threaded execution] * @param USES_REGS1 [env for threaded execution]
* @return c * @return c
[next answer] [next answer]
*/ */
static Int protect_stack_from_retry(USES_REGS1) { static Int protect_stack_from_retry(USES_REGS1) {
// called after backtracking.. // called after backtracking..
// //
@ -1091,9 +1091,9 @@ static Int setup_call_catcher_cleanup(USES_REGS1) {
static bool complete_ge(bool out, Term omod, yhandle_t sl, bool creeping) { static bool complete_ge(bool out, Term omod, yhandle_t sl, bool creeping) {
CACHE_REGS CACHE_REGS
if (creeping) { if (creeping) {
Yap_signal(YAP_CREEP_SIGNAL); Yap_signal(YAP_CREEP_SIGNAL);
} }
CurrentModule = omod; CurrentModule = omod;
Yap_CloseSlots(sl); Yap_CloseSlots(sl);
if (out) { if (out) {
@ -1123,7 +1123,7 @@ static Int _user_expand_goal(USES_REGS1) {
ARG1 = Yap_MkApplTerm(FunctorModule, 2, mg_args); ARG1 = Yap_MkApplTerm(FunctorModule, 2, mg_args);
ARG2 = Yap_GetFromSlot(h2); ARG2 = Yap_GetFromSlot(h2);
if ((pe = RepPredProp( if ((pe = RepPredProp(
Yap_GetPredPropByFunc(FunctorGoalExpansion2, SYSTEM_MODULE))) && Yap_GetPredPropByFunc(FunctorGoalExpansion2, SYSTEM_MODULE))) &&
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE && pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
Yap_execute_pred(pe, NULL, false PASS_REGS)) { Yap_execute_pred(pe, NULL, false PASS_REGS)) {
return complete_ge(true, omod, sl, creeping); return complete_ge(true, omod, sl, creeping);
@ -1133,7 +1133,7 @@ static Int _user_expand_goal(USES_REGS1) {
ARG3 = Yap_GetFromSlot(h2); ARG3 = Yap_GetFromSlot(h2);
/* user:goal_expansion(A,CurMod,B) */ /* user:goal_expansion(A,CurMod,B) */
if ((pe = RepPredProp( if ((pe = RepPredProp(
Yap_GetPredPropByFunc(FunctorGoalExpansion, USER_MODULE))) && Yap_GetPredPropByFunc(FunctorGoalExpansion, USER_MODULE))) &&
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE && pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
Yap_execute_pred(pe, NULL PASS_REGS, false)) { Yap_execute_pred(pe, NULL PASS_REGS, false)) {
return complete_ge(true, omod, sl, creeping); return complete_ge(true, omod, sl, creeping);
@ -1145,7 +1145,7 @@ static Int _user_expand_goal(USES_REGS1) {
/* user:goal_expansion(A,B) */ /* user:goal_expansion(A,B) */
if (cmod != USER_MODULE && /* we have tried this before */ if (cmod != USER_MODULE && /* we have tried this before */
(pe = RepPredProp( (pe = RepPredProp(
Yap_GetPredPropByFunc(FunctorGoalExpansion2, USER_MODULE))) && Yap_GetPredPropByFunc(FunctorGoalExpansion2, USER_MODULE))) &&
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE && pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
Yap_execute_pred(pe, NULL PASS_REGS, false)) { Yap_execute_pred(pe, NULL PASS_REGS, false)) {
return complete_ge(true, omod, sl, creeping); return complete_ge(true, omod, sl, creeping);
@ -1165,7 +1165,7 @@ static Int do_term_expansion(USES_REGS1) {
ARG1 = g; ARG1 = g;
if ((pe = RepPredProp( if ((pe = RepPredProp(
Yap_GetPredPropByFunc(FunctorTermExpansion, USER_MODULE))) && Yap_GetPredPropByFunc(FunctorTermExpansion, USER_MODULE))) &&
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE && pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
Yap_execute_pred(pe, NULL, false PASS_REGS)) { Yap_execute_pred(pe, NULL, false PASS_REGS)) {
return complete_ge(true, omod, sl, creeping); return complete_ge(true, omod, sl, creeping);
@ -1184,7 +1184,7 @@ static Int do_term_expansion(USES_REGS1) {
ARG1 = Yap_MkApplTerm(FunctorModule, 2, mg_args); ARG1 = Yap_MkApplTerm(FunctorModule, 2, mg_args);
ARG2 = Yap_GetFromSlot(h2); ARG2 = Yap_GetFromSlot(h2);
if ((pe = RepPredProp( if ((pe = RepPredProp(
Yap_GetPredPropByFunc(FunctorTermExpansion, SYSTEM_MODULE))) && Yap_GetPredPropByFunc(FunctorTermExpansion, SYSTEM_MODULE))) &&
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE && pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
Yap_execute_pred(pe, NULL, false PASS_REGS)) { Yap_execute_pred(pe, NULL, false PASS_REGS)) {
return complete_ge(true, omod, sl, creeping); return complete_ge(true, omod, sl, creeping);
@ -1202,7 +1202,7 @@ static Int execute0(USES_REGS1) { /* '$execute0'(Goal,Mod) */
return EnterCreepMode(t, mod PASS_REGS); return EnterCreepMode(t, mod PASS_REGS);
} }
t = Yap_YapStripModule(t, &mod); t = Yap_YapStripModule(t, &mod);
restart_exec: restart_exec:
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, ARG3, "call/1"); Yap_Error(INSTANTIATION_ERROR, ARG3, "call/1");
return false; return false;
@ -1421,7 +1421,10 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
int lval, out; int lval, out;
Int OldBorder = LOCAL_CBorder; Int OldBorder = LOCAL_CBorder;
LOCAL_CBorder = LCL0 - (CELL *)B; LOCAL_CBorder = LCL0 - (CELL *)B;
if (top && (lval = sigsetjmp(LOCAL_RestartEnv, 1)) != 0) { sigjmp_buf signew, *sighold = LOCAL_RestartEnv;
LOCAL_RestartEnv = &signew;
if (top && (lval = sigsetjmp(signew, 1)) != 0) {
switch (lval) { switch (lval) {
case 1: { /* restart */ case 1: { /* restart */
/* otherwise, SetDBForThrow will fail entering critical mode */ /* otherwise, SetDBForThrow will fail entering critical mode */
@ -1441,30 +1444,35 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
LOCAL_PrologMode = UserMode; LOCAL_PrologMode = UserMode;
P = (yamop *)FAILCODE; P = (yamop *)FAILCODE;
} break; } break;
case 2: { case 2: {
/* arithmetic exception */ /* arithmetic exception */
/* must be done here, otherwise siglongjmp will clobber all the /* must be done here, otherwise siglongjmp will clobber all the
* registers * registers
*/ */
Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); /* reset the registers so that we don't have trash in abstract
/* reset the registers so that we don't have trash in abstract * machine */
* machine */ Yap_set_fpu_exceptions(
Yap_set_fpu_exceptions( getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG));
getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG)); P = (yamop *)FAILCODE;
P = (yamop *)FAILCODE; LOCAL_PrologMode = UserMode;
LOCAL_PrologMode = UserMode; } break;
} break;
case 4: {
P = (yamop *)FAILCODE;
LOCAL_PrologMode = UserMode;
} break;
case 3: { /* saved state */ case 3: { /* saved state */
LOCAL_CBorder = OldBorder; LOCAL_CBorder = OldBorder;
LOCAL_RestartEnv = sighold;
return false; return false;
} }
default: case 4: {
/* do nothing */ /* abort */
/* can be called from anywgerre, must reset registers,
*/
LOCAL_RestartEnv = sighold;
Yap_JumpToEnv(TermDAbort);
P = (yamop *)FAILCODE;
LOCAL_PrologMode = UserMode; LOCAL_PrologMode = UserMode;
} break;
default:
/* do nothing */
LOCAL_PrologMode = UserMode;
} }
} else { } else {
LOCAL_PrologMode = UserMode; LOCAL_PrologMode = UserMode;
@ -1477,6 +1485,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
if (!Yap_has_a_signal()) if (!Yap_has_a_signal())
CalculateStackGap(PASS_REGS1); CalculateStackGap(PASS_REGS1);
LOCAL_CBorder = OldBorder; LOCAL_CBorder = OldBorder;
LOCAL_RestartEnv = sighold;
return out; return out;
} }
@ -1547,7 +1556,7 @@ static bool do_goal(yamop *CodeAdr, int arity, CELL *pt, bool top USES_REGS) {
bool Yap_exec_absmi(bool top, yap_reset_t has_reset) { bool Yap_exec_absmi(bool top, yap_reset_t has_reset) {
CACHE_REGS CACHE_REGS
return exec_absmi(top, has_reset PASS_REGS); return exec_absmi(top, has_reset PASS_REGS);
} }
/** /**
@ -1576,7 +1585,7 @@ void Yap_fail_all(choiceptr bb USES_REGS) {
DEPTH = B->cp_depth; DEPTH = B->cp_depth;
#endif /* DEPTH_LIMIT */ #endif /* DEPTH_LIMIT */
YENV = ENV = B->cp_env; YENV = ENV = B->cp_env;
/* recover local stack */ /* recover local stack */
#ifdef DEPTH_LIMIT #ifdef DEPTH_LIMIT
DEPTH = ENV[E_DEPTH]; DEPTH = ENV[E_DEPTH];
#endif #endif
@ -1688,7 +1697,7 @@ bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) {
bool Yap_execute_goal(Term t, int nargs, Term mod, bool pass_ex) { bool Yap_execute_goal(Term t, int nargs, Term mod, bool pass_ex) {
CACHE_REGS CACHE_REGS
Prop pe; Prop pe;
PredEntry *ppe; PredEntry *ppe;
CELL *pt; CELL *pt;
/* preserve the current restart environment */ /* preserve the current restart environment */
@ -1725,7 +1734,7 @@ bool Yap_execute_goal(Term t, int nargs, Term mod, bool pass_ex) {
void Yap_trust_last(void) { void Yap_trust_last(void) {
CACHE_REGS CACHE_REGS
ASP = B->cp_env; ASP = B->cp_env;
CP = B->cp_cp; CP = B->cp_cp;
HR = B->cp_h; HR = B->cp_h;
#ifdef DEPTH_LIMIT #ifdef DEPTH_LIMIT
@ -1743,7 +1752,7 @@ void Yap_trust_last(void) {
Term Yap_RunTopGoal(Term t, bool handle_errors) { Term Yap_RunTopGoal(Term t, bool handle_errors) {
CACHE_REGS CACHE_REGS
yamop *CodeAdr; yamop *CodeAdr;
Prop pe; Prop pe;
PredEntry *ppe; PredEntry *ppe;
CELL *pt; CELL *pt;
@ -1966,7 +1975,7 @@ static Int cut_up_to_next_disjunction(USES_REGS1) {
bool Yap_Reset(yap_reset_t mode) { bool Yap_Reset(yap_reset_t mode) {
CACHE_REGS CACHE_REGS
int res = TRUE; int res = TRUE;
Yap_ResetException(worker_id); Yap_ResetException(worker_id);
/* first, backtrack to the root */ /* first, backtrack to the root */
@ -2015,14 +2024,17 @@ static Int JumpToEnv() {
/* find the first choicepoint that may be a catch */ /* find the first choicepoint that may be a catch */
// DBTerm *dbt = Yap_RefToException(); // DBTerm *dbt = Yap_RefToException();
while (handler && Yap_PredForChoicePt(handler, NULL) != PredDollarCatch) { while (handler && Yap_PredForChoicePt(handler, NULL) != PredDollarCatch) {
//printf("--handler=%p, max=%p\n", handler, LCL0-LOCAL_CBorder);
while (POP_CHOICE_POINT(handler)) { while (POP_CHOICE_POINT(handler)) {
POP_FAIL_EXECUTE(handler); POP_FAIL_EXECUTE(handler);
} }
if (handler == (choiceptr)(LCL0-LOCAL_CBorder)) {
break;
}
/* we are already doing a catch */ /* we are already doing a catch */
/* make sure we prune C-choicepoints */ /* make sure we prune C-choicepoints */
if (handler->cp_ap == NOCODE && if ((handler->cp_ap == NOCODE && handler->cp_b == NULL) ||
(handler >= (choiceptr)(LCL0 - LOCAL_CBorder) || (handler->cp_b >= (choiceptr)(LCL0 - LOCAL_CBorder))) {
handler->cp_b == NULL)) {
break; break;
} }
handler = handler->cp_b; handler = handler->cp_b;
@ -2062,7 +2074,7 @@ static Int JumpToEnv() {
bool Yap_JumpToEnv(Term t) { bool Yap_JumpToEnv(Term t) {
CACHE_REGS CACHE_REGS
LOCAL_BallTerm = Yap_StoreTermInDB(t, 0); LOCAL_BallTerm = Yap_StoreTermInDB(t, 0);
if (!LOCAL_BallTerm) if (!LOCAL_BallTerm)
return false; return false;
if (LOCAL_PrologMode & TopGoalMode) if (LOCAL_PrologMode & TopGoalMode)
@ -2077,19 +2089,20 @@ static Int jump_env(USES_REGS1) {
Yap_Error(INSTANTIATION_ERROR, t, "throw ball must be bound"); Yap_Error(INSTANTIATION_ERROR, t, "throw ball must be bound");
return false; return false;
} else if (IsApplTerm(t) && FunctorOfTerm(t) == FunctorError) { } else if (IsApplTerm(t) && FunctorOfTerm(t) == FunctorError) {
Term t2, te; Term t2;
Yap_find_prolog_culprit(PASS_REGS1); Yap_find_prolog_culprit(PASS_REGS1);
te = ArgOfTerm(1, t); // LOCAL_Error_TYPE = ERROR_EVENT;
if (IsApplTerm(te) && IsAtomTerm((t2 = ArgOfTerm(1, te)))) { t = ArgOfTerm(1, t);
if (IsApplTerm(t) && IsAtomTerm((t2 = ArgOfTerm(1, t)))) {
LOCAL_ActiveError->errorAsText = AtomOfTerm(t2); LOCAL_ActiveError->errorAsText = AtomOfTerm(t2);
LOCAL_ActiveError->classAsText = NameOfFunctor(FunctorOfTerm(te)); LOCAL_ActiveError->classAsText = NameOfFunctor(FunctorOfTerm(t));
} else if (IsAtomTerm(te)) { } else if (IsAtomTerm(t)) {
LOCAL_ActiveError->errorAsText = AtomOfTerm(te); LOCAL_ActiveError->errorAsText = AtomOfTerm(t);
LOCAL_ActiveError->classAsText = NULL; LOCAL_ActiveError->classAsText = NULL;
} }
} else { } else {
LOCAL_Error_TYPE = THROW_EVENT; // LOCAL_Error_TYPE = THROW_EVENT;
} }
LOCAL_ActiveError->prologPredName = NULL; LOCAL_ActiveError->prologPredName = NULL;
Yap_PutException(t); Yap_PutException(t);
@ -2111,27 +2124,27 @@ static Int generate_pred_info(USES_REGS1) {
void Yap_InitYaamRegs(int myworker_id) { void Yap_InitYaamRegs(int myworker_id) {
Term h0var; Term h0var;
// getchar(); // getchar();
#if PUSH_REGS #if PUSH_REGS
/* Guarantee that after a longjmp we go back to the original abstract /* Guarantee that after a longjmp we go back to the original abstract
machine registers */ machine registers */
#ifdef THREADS #ifdef THREADS
if (myworker_id) { if (myworker_id) {
REGSTORE *rs = REMOTE_ThreadHandle(myworker_id).default_yaam_regs; REGSTORE *rs = REMOTE_ThreadHandle(myworker_id).default_yaam_regs;
pthread_setspecific(Yap_yaamregs_key, (const void *)rs); pthread_setspecific(Yap_yaamregs_key, (const void *)rs);
REMOTE_ThreadHandle(myworker_id).current_yaam_regs = rs; REMOTE_ThreadHandle(myworker_id).current_yaam_regs = rs;
} }
/* may be run by worker_id on behalf on myworker_id */ /* may be run by worker_id on behalf on myworker_id */
#else #else
Yap_regp = &Yap_standard_regs; Yap_regp = &Yap_standard_regs;
#endif #endif
#endif /* PUSH_REGS */ #endif /* PUSH_REGS */
CACHE_REGS CACHE_REGS
Yap_ResetException(worker_id); Yap_ResetException(worker_id);
Yap_PutValue(AtomBreak, MkIntTerm(0)); Yap_PutValue(AtomBreak, MkIntTerm(0));
TR = (tr_fr_ptr)REMOTE_TrailBase(myworker_id); TR = (tr_fr_ptr)REMOTE_TrailBase(myworker_id);
HR = H0 = ((CELL *)REMOTE_GlobalBase(myworker_id)) + HR = H0 = ((CELL *)REMOTE_GlobalBase(myworker_id)) +
1; // +1: hack to ensure the gc does not try to mark mistakenly 1; // +1: hack to ensure the gc does not try to mark mistakenly
LCL0 = ASP = (CELL *)REMOTE_LocalBase(myworker_id); LCL0 = ASP = (CELL *)REMOTE_LocalBase(myworker_id);
CurrentTrailTop = (tr_fr_ptr)(REMOTE_TrailTop(myworker_id) - MinTrailGap); CurrentTrailTop = (tr_fr_ptr)(REMOTE_TrailTop(myworker_id) - MinTrailGap);
/* notice that an initial choice-point and environment /* notice that an initial choice-point and environment
@ -2155,12 +2168,12 @@ void Yap_InitYaamRegs(int myworker_id) {
#ifdef YAPOR_SBA #ifdef YAPOR_SBA
BSEG = BSEG =
#endif /* YAPOR_SBA */ #endif /* YAPOR_SBA */
BBREG = B_FZ = (choiceptr)REMOTE_LocalBase(myworker_id); BBREG = B_FZ = (choiceptr)REMOTE_LocalBase(myworker_id);
TR = TR_FZ = (tr_fr_ptr)REMOTE_TrailBase(myworker_id); TR = TR_FZ = (tr_fr_ptr)REMOTE_TrailBase(myworker_id);
#endif /* FROZEN_STACKS */ #endif /* FROZEN_STACKS */
CalculateStackGap(PASS_REGS1); CalculateStackGap(PASS_REGS1);
/* the first real choice-point will also have AP=FAIL */ /* the first real choice-point will also have AP=FAIL */
/* always have an empty slots for people to use */ /* always have an empty slots for people to use */
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
LOCAL = REMOTE(myworker_id); LOCAL = REMOTE(myworker_id);
worker_id = myworker_id; worker_id = myworker_id;
@ -2175,7 +2188,7 @@ void Yap_InitYaamRegs(int myworker_id) {
REMOTE_GcGeneration(myworker_id) = Yap_NewTimedVar(h0var); REMOTE_GcGeneration(myworker_id) = Yap_NewTimedVar(h0var);
REMOTE_GcCurrentPhase(myworker_id) = 0L; REMOTE_GcCurrentPhase(myworker_id) = 0L;
REMOTE_GcPhase(myworker_id) = REMOTE_GcPhase(myworker_id) =
Yap_NewTimedVar(MkIntTerm(REMOTE_GcCurrentPhase(myworker_id))); Yap_NewTimedVar(MkIntTerm(REMOTE_GcCurrentPhase(myworker_id)));
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
PP = NULL; PP = NULL;
PREG_ADDR = NULL; PREG_ADDR = NULL;
@ -2188,7 +2201,7 @@ void Yap_InitYaamRegs(int myworker_id) {
#ifdef YAPOR_SBA #ifdef YAPOR_SBA
BSEG = BSEG =
#endif /* YAPOR_SBA */ #endif /* YAPOR_SBA */
BBREG = B_FZ = (choiceptr)REMOTE_LocalBase(myworker_id); BBREG = B_FZ = (choiceptr)REMOTE_LocalBase(myworker_id);
TR = TR_FZ = (tr_fr_ptr)REMOTE_TrailBase(myworker_id); TR = TR_FZ = (tr_fr_ptr)REMOTE_TrailBase(myworker_id);
#endif /* FROZEN_STACKS */ #endif /* FROZEN_STACKS */
CalculateStackGap(PASS_REGS1); CalculateStackGap(PASS_REGS1);
@ -2201,7 +2214,7 @@ void Yap_InitYaamRegs(int myworker_id) {
Term Yap_GetException(void) { Term Yap_GetException(void) {
CACHE_REGS CACHE_REGS
Term t = 0; Term t = 0;
if (LOCAL_BallTerm) { if (LOCAL_BallTerm) {
t = Yap_PopTermFromDB(LOCAL_BallTerm); t = Yap_PopTermFromDB(LOCAL_BallTerm);
@ -2220,8 +2233,8 @@ bool Yap_RaiseException(void) {
bool Yap_PutException(Term t) { bool Yap_PutException(Term t) {
CACHE_REGS CACHE_REGS
if ((LOCAL_BallTerm = Yap_StoreTermInDB(t, 0)) != NULL) if ((LOCAL_BallTerm = Yap_StoreTermInDB(t, 0)) != NULL)
return true; return true;
return false; return false;
} }
@ -2231,7 +2244,6 @@ bool Yap_ResetException(int wid) {
Yap_PopTermFromDB(REMOTE_ActiveError(wid)->errorTerm); Yap_PopTermFromDB(REMOTE_ActiveError(wid)->errorTerm);
} }
REMOTE_ActiveError(wid)->errorTerm = NULL; REMOTE_ActiveError(wid)->errorTerm = NULL;
REMOTE_ActiveError(wid)->errorTerm = NULL;
return true; return true;
} }
@ -2270,7 +2282,7 @@ int Yap_dogc(int extra_args, Term *tp USES_REGS) {
void Yap_InitExecFs(void) { void Yap_InitExecFs(void) {
CACHE_REGS CACHE_REGS
Term cm = CurrentModule; Term cm = CurrentModule;
Yap_InitComma(); Yap_InitComma();
Yap_InitCPred("$execute", 1, execute, 0); Yap_InitCPred("$execute", 1, execute, 0);
Yap_InitCPred("$execute", 2, execute2, 0); Yap_InitCPred("$execute", 2, execute2, 0);

View File

@ -21,7 +21,7 @@
#include "Yap.h" #include "Yap.h"
#include "clause.h" #include "clause.h"
#include "yapio.h" #include "yapio.h"
#include "eval.h" #include "YapEval.h"
#include "tracer.h" #include "tracer.h"
#ifdef YAPOR #ifdef YAPOR
#include "or.macros.h" #include "or.macros.h"

View File

@ -20,7 +20,7 @@
#include "Yap.h" #include "Yap.h"
#include "clause.h" #include "clause.h"
#include "yapio.h" #include "yapio.h"
#include "eval.h" #include "YapEval.h"
#include "tracer.h" #include "tracer.h"
#include "attvar.h" #include "attvar.h"
#ifdef YAPOR #ifdef YAPOR

105
C/flags.c
View File

@ -51,16 +51,16 @@ static Term stream(Term inp);
static bool getenc(Term inp); static bool getenc(Term inp);
static bool typein(Term inp); static bool typein(Term inp);
static bool dqf(Term t2); static bool dqf(Term t2);
static bool set_error_stream( Term inp ); static bool set_error_stream(Term inp);
static bool set_input_stream( Term inp ); static bool set_input_stream(Term inp);
static bool set_output_stream( Term inp ); static bool set_output_stream(Term inp);
static void newFlag(Term fl, Term val); static void newFlag(Term fl, Term val);
static Int current_prolog_flag(USES_REGS1); static Int current_prolog_flag(USES_REGS1);
static Int set_prolog_flag(USES_REGS1); static Int set_prolog_flag(USES_REGS1);
#include "Yatom.h" #include "Yatom.h"
#include "eval.h" #include "YapEval.h"
#include "yapio.h" #include "yapio.h"
#define YAP_FLAG(ID, NAME, WRITABLE, DEF, INIT, HELPER) \ #define YAP_FLAG(ID, NAME, WRITABLE, DEF, INIT, HELPER) \
@ -173,41 +173,38 @@ static Term isaccess(Term inp) {
} }
static Term stream(Term inp) { static Term stream(Term inp) {
if ( IsVarTerm(inp) ) if (IsVarTerm(inp))
return inp; return inp;
if (Yap_CheckStream( inp, Input_Stream_f | Output_Stream_f | if (Yap_CheckStream(inp, Input_Stream_f | Output_Stream_f | Append_Stream_f |
Append_Stream_f | Socket_Stream_f, "yap_flag/3" ) >= 0) Socket_Stream_f,
"yap_flag/3") >= 0)
return inp; return inp;
return 0; return 0;
} }
static bool static bool set_error_stream(Term inp) {
set_error_stream( Term inp ) { if (IsVarTerm(inp))
if( IsVarTerm(inp) ) return Yap_unify(inp, Yap_StreamUserName(LOCAL_c_error_stream));
return Yap_unify( inp, Yap_StreamUserName( LOCAL_c_error_stream ) ); LOCAL_c_error_stream = Yap_CheckStream(
LOCAL_c_error_stream = Yap_CheckStream( inp, Output_Stream_f | inp, Output_Stream_f | Append_Stream_f | Socket_Stream_f, "yap_flag/3");
Append_Stream_f | Socket_Stream_f, "yap_flag/3" );
return true;
}
static bool
set_input_stream( Term inp ) {
if( IsVarTerm(inp) )
return Yap_unify( inp, Yap_StreamUserName( LOCAL_c_input_stream ) );
LOCAL_c_input_stream = Yap_CheckStream( inp, Input_Stream_f | Socket_Stream_f, "yap_flag/3" );
return true; return true;
} }
static bool static bool set_input_stream(Term inp) {
set_output_stream( Term inp ) { if (IsVarTerm(inp))
if( IsVarTerm(inp) ) return Yap_unify(inp, Yap_StreamUserName(LOCAL_c_input_stream));
return Yap_unify( inp, Yap_StreamUserName( LOCAL_c_output_stream ) ); LOCAL_c_input_stream =
LOCAL_c_output_stream = Yap_CheckStream( inp, Output_Stream_f | Yap_CheckStream(inp, Input_Stream_f | Socket_Stream_f, "yap_flag/3");
Append_Stream_f | Socket_Stream_f, "yap_flag/3" );
return true; return true;
} }
static bool set_output_stream(Term inp) {
if (IsVarTerm(inp))
return Yap_unify(inp, Yap_StreamUserName(LOCAL_c_output_stream));
LOCAL_c_output_stream = Yap_CheckStream(
inp, Output_Stream_f | Append_Stream_f | Socket_Stream_f, "yap_flag/3");
return true;
}
static Term isground(Term inp) { static Term isground(Term inp) {
return Yap_IsGroundTerm(inp) ? inp : TermZERO; return Yap_IsGroundTerm(inp) ? inp : TermZERO;
@ -669,12 +666,19 @@ static bool setYapFlagInModule(Term tflag, Term t2, Term mod) {
flag_term *tarr = GLOBAL_Flags; flag_term *tarr = GLOBAL_Flags;
if (!(fv->type(t2))) if (!(fv->type(t2)))
return false; return false;
if (fv->helper && !(fv->helper(t2))) if (fv->helper && !(fv->helper(t2)))
return false; return false;
Term tout = tarr[fv->FlagOfVE].at; Term tout = tarr[fv->FlagOfVE].at;
if (IsVarTerm(tout)) if (IsVarTerm(tout)) {
Yap_PopTermFromDB(tarr[fv->FlagOfVE].DBT); Term t;
if (IsAtomOrIntTerm(t2)) while ((t = Yap_PopTermFromDB(tarr[fv->FlagOfVE].DBT)) == 0) {
if (!Yap_gc(2, ENV, gc_P(P, CP))) {
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
return false;
}
}
} else if (IsAtomOrIntTerm(t2))
tarr[fv->FlagOfVE].at = t2; tarr[fv->FlagOfVE].at = t2;
else { else {
tarr[fv->FlagOfVE].DBT = Yap_StoreTermInDB(t2, 2); tarr[fv->FlagOfVE].DBT = Yap_StoreTermInDB(t2, 2);
@ -1182,24 +1186,26 @@ static Int source_mode(USES_REGS1) {
static bool setInitialValue(bool bootstrap, flag_func f, const char *s, static bool setInitialValue(bool bootstrap, flag_func f, const char *s,
flag_term *tarr) { flag_term *tarr) {
errno = 0; errno = 0;
const char *ss = (const char *)s;
if (f == booleanFlag) { if (f == booleanFlag) {
if (!bootstrap) { if (!bootstrap) {
return 0; return 0;
} }
if (!strcmp(s, "true")) { const char *ss = (const char *)s;
if (!strcmp(ss, "true")) {
tarr->at = TermTrue; tarr->at = TermTrue;
return true; return true;
} }
if (!strcmp(s, "false")) { if (!strcmp(ss, "false")) {
tarr->at = TermFalse; tarr->at = TermFalse;
return true; return true;
} }
if (!strcmp(s, "on")) { if (!strcmp(ss, "on")) {
tarr->at = TermTrue; tarr->at = TermTrue;
return true; return true;
} }
if (!strcmp(s, "off")) { if (!strcmp(ss, "off")) {
tarr->at = TermFalse; tarr->at = TermFalse;
return true; return true;
} }
@ -1210,7 +1216,7 @@ static bool setInitialValue(bool bootstrap, flag_func f, const char *s,
if (!bootstrap) { if (!bootstrap) {
return 0; return 0;
} }
UInt r = strtoul(s, NULL, 10); UInt r = strtoul(ss, NULL, 10);
Term t; Term t;
if (errno) { if (errno) {
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, TermNil, Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, TermNil,
@ -1229,27 +1235,27 @@ static bool setInitialValue(bool bootstrap, flag_func f, const char *s,
if (!bootstrap) { if (!bootstrap) {
return false; return false;
} }
if (!strcmp(s, "INT_MAX")) { if (!strcmp(ss, "INT_MAX")) {
tarr->at = MkIntTerm(Int_MAX); tarr->at = MkIntTerm(Int_MAX);
return true; return true;
} }
if (!strcmp(s, "MAX_THREADS")) { if (!strcmp(ss, "MAX_THREADS")) {
tarr->at = MkIntTerm(MAX_THREADS); tarr->at = MkIntTerm(MAX_THREADS);
return true; return true;
} }
if (!strcmp(s, "MAX_WORKERS")) { if (!strcmp(ss, "MAX_WORKERS")) {
tarr->at = MkIntTerm(MAX_WORKERS); tarr->at = MkIntTerm(MAX_WORKERS);
return true; return true;
} }
if (!strcmp(s, "INT_MIN")) { if (!strcmp(ss, "INT_MIN")) {
tarr->at = MkIntTerm(Int_MIN); tarr->at = MkIntTerm(Int_MIN);
return true; return true;
} }
if (!strcmp(s, "YAP_NUMERIC_VERSION")) { if (!strcmp(ss, "YAP_NUMERIC_VERSION")) {
tarr->at = MkIntTerm(atol(YAP_NUMERIC_VERSION)); tarr->at = MkIntTerm(atol(YAP_NUMERIC_VERSION));
return true; return true;
} }
if (!strcmp(s, "YAP_NUMERIC_VERSION")) { if (!strcmp(ss, "YAP_NUMERIC_VERSION")) {
tarr->at = MkIntTerm(atol(YAP_NUMERIC_VERSION)); tarr->at = MkIntTerm(atol(YAP_NUMERIC_VERSION));
return true; return true;
} }
@ -1297,7 +1303,7 @@ static bool setInitialValue(bool bootstrap, flag_func f, const char *s,
return true; return true;
} }
} }
} else if (strcmp(s, "@boot") == 0) { } else if (strcmp(ss, "@boot") == 0) {
if (bootstrap) { if (bootstrap) {
return true; return true;
} }
@ -1317,9 +1323,9 @@ static bool setInitialValue(bool bootstrap, flag_func f, const char *s,
return false; return false;
} }
CACHE_REGS CACHE_REGS
encoding_t encoding = ENC_ISO_UTF8; const unsigned char *us = (const unsigned char *)s;
t0 = t0 = Yap_BufferToTermWithPrioBindings(us, strlen(s) + 1, TermNil,
Yap_StringToTerm(s, strlen(s) + 1, &encoding, GLOBAL_MaxPriority, 0L); GLOBAL_MaxPriority, 0L);
if (!t0) if (!t0)
return false; return false;
if (IsAtomTerm(t0) || IsIntTerm(t0)) { if (IsAtomTerm(t0) || IsIntTerm(t0)) {
@ -1570,7 +1576,7 @@ static Int do_create_prolog_flag(USES_REGS1) {
fv->type = isground; fv->type = isground;
} break; } break;
case PROLOG_FLAG_PROPERTY_SCOPE: case PROLOG_FLAG_PROPERTY_SCOPE:
free(args); free(args);
return false; return false;
case PROLOG_FLAG_PROPERTY_END: case PROLOG_FLAG_PROPERTY_END:
break; break;
@ -1621,8 +1627,9 @@ void Yap_InitFlags(bool bootstrap) {
while (f->name != NULL) { while (f->name != NULL) {
bool itf = setInitialValue(bootstrap, f->def, f->init, bool itf = setInitialValue(bootstrap, f->def, f->init,
LOCAL_Flags + LOCAL_flagCount); LOCAL_Flags + LOCAL_flagCount);
// Term itf = Yap_StringToTerm(f->init, strlen(f->init)+1, // Term itf = Yap_BufferToTermWithPrioBindings(f->init,
// EBC_ISO_UTF8, GLOBAL_MaxPriority, &tp); // strlen(f->init)+1,
// LOBAL_MaxPriority, &tp);
if (itf) { if (itf) {
initFlag(f, LOCAL_flagCount, false); initFlag(f, LOCAL_flagCount, false);
} }

View File

@ -115,7 +115,7 @@ threads that are created <em>after</em> the registration.
#include "YapHeap.h" #include "YapHeap.h"
#include "yapio.h" #include "yapio.h"
#include "iopreds.h" #include "iopreds.h"
#include "eval.h" #include "YapEval.h"
#include "attvar.h" #include "attvar.h"
#include <math.h> #include <math.h>

View File

@ -18,7 +18,7 @@
#include "Yap.h" #include "Yap.h"
#include "Yatom.h" #include "Yatom.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "eval.h" #include "YapEval.h"
#if HAVE_STRING_H #if HAVE_STRING_H
#include <string.h> #include <string.h>
#endif #endif

View File

@ -20,7 +20,7 @@
#include "yapio.h" #include "yapio.h"
#include "alloc.h" #include "alloc.h"
#include "sshift.h" #include "sshift.h"
#include "compile.h" #include "YapCompile.h"
#include "attvar.h" #include "attvar.h"
#include "cut_c.h" #include "cut_c.h"
#if HAVE_STRING_H #if HAVE_STRING_H

View File

@ -134,7 +134,7 @@ gc_growtrail(int committed, tr_fr_ptr begsTR, cont *old_cont_top0 USES_REGS)
#endif #endif
/* could not find more trail */ /* could not find more trail */
save_machine_regs(); save_machine_regs();
siglongjmp(LOCAL_gc_restore, 2); siglongjmp(*LOCAL_gc_restore, 2);
} }
} }
@ -397,7 +397,7 @@ check_pr_trail( tr_fr_ptr rc USES_REGS)
if (!Yap_locked_growtrail(0, TRUE) || TRUE) { if (!Yap_locked_growtrail(0, TRUE) || TRUE) {
/* could not find more trail */ /* could not find more trail */
save_machine_regs(); save_machine_regs();
siglongjmp(LOCAL_gc_restore, 2); siglongjmp(*LOCAL_gc_restore, 2);
} }
rc = TR-n; rc = TR-n;
} }
@ -525,7 +525,7 @@ pop_registers(Int num_regs, yamop *nextop USES_REGS)
/* error: we don't have enough room */ /* error: we don't have enough room */
/* could not find more trail */ /* could not find more trail */
save_machine_regs(); save_machine_regs();
siglongjmp(LOCAL_gc_restore, 4); siglongjmp(*LOCAL_gc_restore, 4);
} }
} }
} }
@ -1450,7 +1450,7 @@ mark_variable(CELL_PTR current USES_REGS)
/* error: we don't have enough room */ /* error: we don't have enough room */
/* could not find more trail */ /* could not find more trail */
save_machine_regs(); save_machine_regs();
siglongjmp(LOCAL_gc_restore, 3); siglongjmp(*LOCAL_gc_restore, 3);
} else if (n > 0) { } else if (n > 0) {
CELL *ptr = LOCAL_extra_gc_cells; CELL *ptr = LOCAL_extra_gc_cells;
@ -3934,6 +3934,9 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop USES_REGS)
UInt gc_phase; UInt gc_phase;
UInt alloc_sz; UInt alloc_sz;
int jmp_res; int jmp_res;
sigjmp_buf jmp;
LOCAL_gc_restore = &jmp;
heap_cells = HR-H0; heap_cells = HR-H0;
gc_verbose = is_gc_verbose(); gc_verbose = is_gc_verbose();
@ -3989,7 +3992,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop USES_REGS)
} }
#endif #endif
time_start = Yap_cputime(); time_start = Yap_cputime();
jmp_res = sigsetjmp(LOCAL_gc_restore, 0); jmp_res = sigsetjmp(jmp, 0);
if (jmp_res == 2) { if (jmp_res == 2) {
UInt sz; UInt sz;

View File

@ -634,7 +634,7 @@ type_of_verb(rest,passive).
*/ */
#include "absmi.h" #include "absmi.h"
#include "compile.h" #include "YapCompile.h"
#if DEBUG #if DEBUG
#include "yapio.h" #include "yapio.h"
#endif #endif

View File

@ -42,15 +42,15 @@ Yap_FindExecutable(void)
void * void *
Yap_LoadForeignFile(char *file, int flags) Yap_LoadForeignFile(char *file, int flags)
{ {
void *ptr= (void *)LoadLibrary(file); char *buf = malloc(1024);
printf("file=%s\n" , file );
void *ptr= (void *)LoadLibrary(file);
if (!ptr) { if (!ptr) {
CACHE_REGS
LOCAL_ErrorMessage = NULL;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), LOCAL_ErrorMessage, 256, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 1023,
NULL); NULL);
} }
return ptr; return ptr;
} }
@ -83,17 +83,18 @@ LoadForeign(StringList ofiles, StringList libs,
HINSTANCE handle; HINSTANCE handle;
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 (Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true, true) &&
(handle=LoadLibrary(LOCAL_FileNameBuf)) != 0) (handle=LoadLibrary(LOCAL_FileNameBuf)) != 0)
{ {
LOCAL_ErrorMessage = NULL; LOCAL_ErrorMessage = NULL;
if (*init_proc == NULL) if (*init_proc == NULL)
*init_proc = (YapInitProc)GetProcAddress((HMODULE)handle, proc_name); *init_proc = (YapInitProc)GetProcAddress((HMODULE)handle, proc_name);
} else { } else {
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, char *buf = malloc(1024);
NULL, GetLastError(), FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), LOCAL_ErrorMessage, 256, NULL, GetLastError(),
NULL); MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 1023,
NULL);
//fprintf(stderr,"WinError: %s\n", LOCAL_ErrorSay); //fprintf(stderr,"WinError: %s\n", LOCAL_ErrorSay);
} }
ofiles = ofiles->next; ofiles = ofiles->next;

View File

@ -46,7 +46,7 @@ p_load_foreign( USES_REGS1 )
YapInitProc InitProc = NULL; YapInitProc InitProc = NULL;
Term t, t1; Term t, t1;
StringList new; StringList new;
Int returncode = FALSE; bool returncode = FALSE;
yhandle_t CurSlot = Yap_StartSlots(); yhandle_t CurSlot = Yap_StartSlots();
// Yap_DebugPlWrite(ARG1); printf("%s\n", " \n"); // Yap_DebugPlWrite(ARG1); printf("%s\n", " \n");
@ -81,12 +81,16 @@ p_load_foreign( USES_REGS1 )
t1 = Deref(ARG3); t1 = Deref(ARG3);
InitProcName = (char *)RepAtom(AtomOfTerm(t1))->StrOfAE; InitProcName = (char *)RepAtom(AtomOfTerm(t1))->StrOfAE;
// verify if it was waiting for initialization
if (Yap_LateInit( InitProcName ) ){
returncode = true;
} else
/* call the OS specific function for dynamic loading */ /* call the OS specific function for dynamic loading */
if(Yap_LoadForeign(ofiles,libs,InitProcName,&InitProc)==LOAD_SUCCEEDED) { if(Yap_LoadForeign(ofiles,libs,InitProcName,&InitProc)==LOAD_SUCCEEDED) {
Yap_StartSlots( ); Yap_StartSlots( );
(*InitProc)(); (*InitProc)();
Yap_CloseSlots(CurSlot); Yap_CloseSlots(CurSlot);
returncode = TRUE; returncode = true;
} }
/* I should recover space if load foreign fails */ /* I should recover space if load foreign fails */

View File

@ -48,7 +48,7 @@ deterministic computations.
#include "Yatom.h" #include "Yatom.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "eval.h" #include "YapEval.h"
static Int p_setarg( USES_REGS1 ); static Int p_setarg( USES_REGS1 );
static Int p_create_mutable( USES_REGS1 ); static Int p_create_mutable( USES_REGS1 );

View File

@ -141,7 +141,7 @@ dot with single quotes.
#include "YapHeap.h" #include "YapHeap.h"
#include "YapText.h" #include "YapText.h"
#include "Yatom.h" #include "Yatom.h"
#include "eval.h" #include "YapEval.h"
#include "yapio.h" #include "yapio.h"
/* stuff we want to use in standard YAP code */ /* stuff we want to use in standard YAP code */
#include "iopreds.h" #include "iopreds.h"
@ -302,7 +302,7 @@ static Term VarNames(VarEntry *p, Term l USES_REGS) {
VarNames(p->VarLeft, l PASS_REGS) PASS_REGS)); VarNames(p->VarLeft, l PASS_REGS) PASS_REGS));
if (HR > ASP - 4096) { if (HR > ASP - 4096) {
save_machine_regs(); save_machine_regs();
siglongjmp(LOCAL_IOBotch, 1); longjmp(*LOCAL_IOBotch, 1);
} }
return (o); return (o);
} else { } else {
@ -332,7 +332,7 @@ static Term Singletons(VarEntry *p, Term l USES_REGS) {
Singletons(p->VarLeft, l PASS_REGS) PASS_REGS)); Singletons(p->VarLeft, l PASS_REGS) PASS_REGS));
if (HR > ASP - 4096) { if (HR > ASP - 4096) {
save_machine_regs(); save_machine_regs();
siglongjmp(LOCAL_IOBotch, 1); longjmp(*LOCAL_IOBotch, 1);
} }
return (o); return (o);
} else { } else {
@ -357,7 +357,7 @@ static Term Variables(VarEntry *p, Term l USES_REGS) {
Variables(p->VarRight, Variables(p->VarLeft, l PASS_REGS) PASS_REGS)); Variables(p->VarRight, Variables(p->VarLeft, l PASS_REGS) PASS_REGS));
if (HR > ASP - 4096) { if (HR > ASP - 4096) {
save_machine_regs(); save_machine_regs();
siglongjmp(LOCAL_IOBotch, 1); siglongjmp(*LOCAL_IOBotch, 1);
} }
return (o); return (o);
} else { } else {

1047
C/pold.c

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,7 @@ static char SccsId[] = "%W% %G%";
#include "Yap.h" #include "Yap.h"
#include "Yatom.h" #include "Yatom.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "eval.h" #include "YapEval.h"
static Int static Int
p_in_range( USES_REGS1 ) { p_in_range( USES_REGS1 ) {

View File

@ -407,7 +407,7 @@ writing, writing a BOM can be requested using the option
#include "YapHeap.h" #include "YapHeap.h"
#include "Yatom.h" #include "Yatom.h"
#include "alloc.h" #include "alloc.h"
#include "eval.h" #include "YapEval.h"
#include "yapio.h" #include "yapio.h"
/* stuff we want to use in standard YAP code */ /* stuff we want to use in standard YAP code */
#include "YapText.h" #include "YapText.h"
@ -1143,17 +1143,17 @@ Term Yap_scan_num(StreamDesc *inp, bool error_on) {
out = 0; out = 0;
} }
#if HAVE_ISWSPACE #if HAVE_ISWSPACE
while (iswspace(ch = getchr(inp))) while (iswspace(ch = getchr(inp)))
; ;
#else #else
while (isspace(ch = getchr(inp))) while (isspace(ch = getchr(inp)))
; ;
#endif #endif
if (LOCAL_ErrorMessage != NULL || ch != -1 || cherr) { if (LOCAL_ErrorMessage != NULL || ch != -1 || cherr) {
Yap_clean_tokenizer(old_tr, NULL, NULL); Yap_clean_tokenizer(old_tr, NULL, NULL);
if (error_on) if (error_on)
Yap_Error(SYNTAX_ERROR, ARG2, "converting number"); Yap_Error(SYNTAX_ERROR, ARG2, "converting number");
return 0; return 0;
} }
return out; return out;
} }
@ -1172,85 +1172,89 @@ Term Yap_scan_num(StreamDesc *inp, bool error_on) {
} }
Term Yap_tokRep(void *tokptre) { Term Yap_tokRep(void *tokptre) {
CACHE_REGS CACHE_REGS
TokEntry *tokptr = tokptre; TokEntry *tokptr = tokptre;
Term info = tokptr->TokInfo; Term info = tokptr->TokInfo;
switch (tokptr->Tok) { switch (tokptr->Tok) {
case Name_tok: case Name_tok:
if (!info) { if (!info) {
info = TermNil; info = TermNil;
}
return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info);
case QuasiQuotes_tok:
info = MkAtomTerm(Yap_LookupAtom("<QQ>"));
return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info);
case Number_tok:
return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info);
break;
case Var_tok: {
Term t[2];
VarEntry *varinfo = (VarEntry *)info;
if ((t[0]= varinfo->VarAdr) == TermNil) {
t[0] = varinfo->VarAdr = MkVarTerm();
}
t[1] = MkAtomTerm((Atom)(varinfo->VarRep));
return Yap_MkApplTerm(Yap_MkFunctor(AtomGVar, 2), 2, t);
}
case String_tok:
return Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &info);
case BQString_tok:
return Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &info);
case Error_tok:
return MkAtomTerm(AtomError);
case eot_tok:
return MkAtomTerm(Yap_LookupAtom("EOT"));
case Ponctuation_tok:
return info;
} }
return TermDot; return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info);
case QuasiQuotes_tok:
info = MkAtomTerm(Yap_LookupAtom("<QQ>"));
return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info);
case Number_tok:
return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info);
break;
case Var_tok: {
Term t[2];
VarEntry *varinfo = (VarEntry *)info;
if ((t[0] = varinfo->VarAdr) == TermNil) {
t[0] = varinfo->VarAdr = MkVarTerm();
}
t[1] = MkAtomTerm((Atom)(varinfo->VarRep));
return Yap_MkApplTerm(Yap_MkFunctor(AtomGVar, 2), 2, t);
}
case String_tok:
return Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &info);
case BQString_tok:
return Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &info);
case Error_tok:
return MkAtomTerm(AtomError);
case eot_tok:
return MkAtomTerm(Yap_LookupAtom("EOT"));
case Ponctuation_tok:
if (info == Terml)
return TermBeginBracket;
else
return info;
}
return TermDot;
} }
const char *Yap_tokText(void *tokptre) {
CACHE_REGS
TokEntry *tokptr = tokptre;
Term info = tokptr->TokInfo;
const char * Yap_tokText(void *tokptre) { switch (tokptr->Tok) {
CACHE_REGS case eot_tok:
TokEntry *tokptr = tokptre; return "EOT";
Term info = tokptr->TokInfo; case Ponctuation_tok:
if (info == Terml)
switch (tokptr->Tok) { return "(";
case eot_tok: case Error_tok:
return "EOT"; case BQString_tok:
case Ponctuation_tok: case String_tok:
case Error_tok: case Name_tok:
case BQString_tok: return AtomOfTerm(info)->StrOfAE;
case String_tok: case QuasiQuotes_tok:
case Name_tok: return "<QQ>";
return AtomOfTerm(info)->StrOfAE; case Number_tok:
case QuasiQuotes_tok: if (IsIntegerTerm(info)) {
return "<QQ>"; char *s = Malloc(36);
case Number_tok: snprintf(s, 35, Int_FORMAT, IntegerOfTerm(info));
if (IsIntegerTerm(info)) { return s;
char *s = Malloc(36); } else if (IsFloatTerm(info)) {
snprintf(s, 35, Int_FORMAT, IntegerOfTerm(info)); char *s = Malloc(64);
return s; snprintf(s, 63, "%6g", FloatOfTerm(info));
}else if (IsFloatTerm(info)) { return s;
char *s = Malloc( 64); } else {
snprintf(s, 63, "%6g", FloatOfTerm(info)); size_t len = Yap_gmp_to_size(info, 10);
return s; char *s = Malloc(len + 2);
} else { return Yap_gmp_to_string(info, s, len + 1, 10);
size_t len = Yap_gmp_to_size(info,10);
char *s = Malloc(len+2);
return Yap_gmp_to_string(info,s, len+1,10);
}
break;
case Var_tok:
if (info == 0) return "[]";
return ((Atom)info)->StrOfAE;
} }
return "."; break;
case Var_tok:
if (info == 0)
return "[]";
return ((Atom)info)->StrOfAE;
}
return ".";
} }
static void open_comment(int ch, StreamDesc *inp_stream USES_REGS) { static void open_comment(int ch, StreamDesc *inp_stream USES_REGS) {
CELL *h0 = HR; CELL *h0 = HR;
HR += 5; HR += 5;
@ -1311,7 +1315,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
int solo_flag = TRUE; int solo_flag = TRUE;
int32_t ch, och; int32_t ch, och;
struct qq_struct_t *cur_qq = NULL; struct qq_struct_t *cur_qq = NULL;
int sign = 1; int sign = 1;
InitScannerMemory(); InitScannerMemory();
LOCAL_VarTable = NULL; LOCAL_VarTable = NULL;
@ -1424,7 +1428,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
Atom ae; Atom ae;
/* don't do this in iso */ /* don't do this in iso */
ae = Yap_ULookupAtom(TokImage); ae = Yap_ULookupAtom(TokImage);
Free(TokImage); Free(TokImage);
if (ae == NIL) { if (ae == NIL) {
return CodeSpaceError(t, p, l); return CodeSpaceError(t, p, l);
} }
@ -1434,7 +1438,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
t->Tok = Ord(kind = Name_tok); t->Tok = Ord(kind = Name_tok);
} else { } else {
VarEntry *ve = Yap_LookupVar((const char *)TokImage); VarEntry *ve = Yap_LookupVar((const char *)TokImage);
Free(TokImage); Free(TokImage);
t->TokInfo = Unsigned(ve); t->TokInfo = Unsigned(ve);
if (cur_qq) { if (cur_qq) {
ve->refs++; ve->refs++;
@ -1444,14 +1448,14 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
} break; } break;
case NU: { case NU: {
int cherr; int cherr;
int cha; int cha;
sign = 1; sign = 1;
scan_number: scan_number:
cha = ch; cha = ch;
cherr = 0; cherr = 0;
CHECK_SPACE(); CHECK_SPACE();
if ((t->TokInfo = get_num(&cha, &cherr, inp_stream, sign)) == 0L) { if ((t->TokInfo = get_num(&cha, &cherr, inp_stream, sign)) == 0L) {
if (p) { if (p) {
@ -1480,8 +1484,8 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
case 'e': case 'e':
case 'E': case 'E':
och = cherr; och = cherr;
TokImage = Malloc(1024 PASS_REGS); TokImage = Malloc(1024 PASS_REGS);
goto scan_name; goto scan_name;
break; break;
case '=': case '=':
case '_': case '_':
@ -1513,13 +1517,13 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
{ {
TokEntry *e2; TokEntry *e2;
if (chtype(ch) == NU) { if (chtype(ch) == NU) {
if (och == '-') if (och == '-')
sign = -1; sign = -1;
else else
sign = 1; sign = 1;
goto scan_number; goto scan_number;
} }
t->Tok = Name_tok; t->Tok = Name_tok;
if (ch == '(') if (ch == '(')
solo_flag = FALSE; solo_flag = FALSE;
@ -1567,9 +1571,9 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
LOCAL_ErrorMessage = "layout character \n inside quotes"; LOCAL_ErrorMessage = "layout character \n inside quotes";
break; break;
} }
if (ch == EOFCHAR) { if (ch == EOFCHAR) {
break; break;
} }
if (ch == quote) { if (ch == quote) {
ch = getchrq(inp_stream); ch = getchrq(inp_stream);
if (ch != quote) if (ch != quote)
@ -1638,16 +1642,16 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
break; break;
case SY: { case SY: {
int pch; int pch;
if (ch == '.' && (pch = Yap_peek(inp_stream - GLOBAL_Stream)) && if (ch == '.' && (pch = Yap_peek(inp_stream - GLOBAL_Stream)) &&
(chtype(pch) == BS || chtype(pch) == EF || pch == '%')) { (chtype(pch) == BS || chtype(pch) == EF || pch == '%')) {
t->Tok = Ord(kind = eot_tok); t->Tok = Ord(kind = eot_tok);
// consume... // consume...
if (pch == '%') { if (pch == '%') {
t->TokInfo = TermNewLine; t->TokInfo = TermNewLine;
return l; return l;
}
return l;
} }
return l;
}
if (ch == '`') if (ch == '`')
goto quoted_string; goto quoted_string;
och = ch; och = ch;
@ -1668,7 +1672,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
return l; return l;
} }
} }
if (och == '/' && ch == '*') { if (och == '/' && ch == '*') {
if (store_comments) { if (store_comments) {
CHECK_SPACE(); CHECK_SPACE();
open_comment('/', inp_stream PASS_REGS); open_comment('/', inp_stream PASS_REGS);
@ -1925,7 +1929,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
qq->end.byteno = fseek(inp_stream->file, 0, 0); qq->end.byteno = fseek(inp_stream->file, 0, 0);
} else { } else {
qq->end.byteno = inp_stream->charcount - 1; qq->end.byteno = inp_stream->charcount - 1;
} }
qq->end.lineno = inp_stream->linecount; qq->end.lineno = inp_stream->linecount;
qq->end.linepos = inp_stream->linepos - 1; qq->end.linepos = inp_stream->linepos - 1;
qq->end.charno = inp_stream->charcount - 1; qq->end.charno = inp_stream->charcount - 1;
@ -1972,7 +1976,6 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
return (l); return (l);
} }
void Yap_clean_tokenizer(TokEntry *tokstart, VarEntry *vartable, void Yap_clean_tokenizer(TokEntry *tokstart, VarEntry *vartable,
VarEntry *anonvartable) { VarEntry *anonvartable) {
CACHE_REGS CACHE_REGS

View File

@ -25,18 +25,18 @@ static char SccsId[] = "%W% %G%";
#include <unistd.h> #include <unistd.h>
#endif #endif
#if _WIN32 #if _WIN32
#include <stdio.h>
#include <io.h> #include <io.h>
#include <stdio.h>
#endif #endif
#include "Yatom.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "eval.h" #include "Yatom.h"
#include "YapEval.h"
#include "yapio.h" #include "yapio.h"
#ifdef TABLING #ifdef TABLING
#include "tab.macros.h" #include "tab.macros.h"
#endif /* TABLING */ #endif /* TABLING */
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#if HAVE_STRING_H #if HAVE_STRING_H
#include <string.h> #include <string.h>
#endif #endif
@ -63,7 +63,11 @@ static yap_signals InteractSIGINT(int ch) {
#endif #endif
switch (ch) { switch (ch) {
case 'a': case 'a':
/* abort computation */ /* abort computation */
#if PUSH_REGS
// restore_absmi_regs(&Yap_standard_regs);
#endif
siglongjmp(&LOCAL_RestartEnv, 4);
return YAP_ABORT_SIGNAL; return YAP_ABORT_SIGNAL;
case 'b': case 'b':
/* continue */ /* continue */
@ -183,35 +187,32 @@ inline static bool get_signal(yap_signals sig USES_REGS) {
#endif #endif
} }
bool Yap_DisableInterrupts(int wid) bool Yap_DisableInterrupts(int wid) {
{
LOCAL_InterruptsDisabled = true; LOCAL_InterruptsDisabled = true;
YAPEnterCriticalSection(); YAPEnterCriticalSection();
return true; return true;
} }
bool Yap_EnableInterrupts(int wid) bool Yap_EnableInterrupts(int wid) {
{
LOCAL_InterruptsDisabled = false; LOCAL_InterruptsDisabled = false;
YAPLeaveCriticalSection(); YAPLeaveCriticalSection();
return true; return true;
} }
/** /**
Function called to handle delayed interrupts. Function called to handle delayed interrupts.
*/ */
int Yap_HandleInterrupts(void) { bool Yap_HandleSIGINT(void) {
CACHE_REGS CACHE_REGS
yap_signals sig; yap_signals sig;
if (get_signal(YAP_INT_SIGNAL PASS_REGS)) { do {
if ((sig = ProcessSIGINT()) != YAP_NO_SIGNAL) if ((sig = ProcessSIGINT()) != YAP_NO_SIGNAL)
do_signal(worker_id, sig PASS_REGS); do_signal(worker_id, sig PASS_REGS);
LOCAL_PrologMode &= ~InterruptMode; LOCAL_PrologMode &= ~InterruptMode;
return 1; return true;
} } while (get_signal(YAP_INT_SIGNAL PASS_REGS));
return 0; return false;
} }
static Int p_creep(USES_REGS1) { static Int p_creep(USES_REGS1) {

View File

@ -30,7 +30,7 @@
#include "Yap.h" #include "Yap.h"
#include "clause.h" #include "clause.h"
#include "eval.h" #include "YapEval.h"
#include "iopreds.h" #include "iopreds.h"
#include "tracer.h" #include "tracer.h"
#include "yapio.h" #include "yapio.h"

View File

@ -31,7 +31,7 @@
#include "Yap.h" #include "Yap.h"
#include "clause.h" #include "clause.h"
#include "yapio.h" #include "yapio.h"
#include "eval.h" #include "YapEval.h"
#include "tracer.h" #include "tracer.h"
#ifdef YAPOR #ifdef YAPOR
#include "or.macros.h" #include "or.macros.h"

View File

@ -37,7 +37,7 @@ static char SccsId[] = "%W% %G%";
#include "Foreign.h" #include "Foreign.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "Yatom.h" #include "Yatom.h"
#include "eval.h" #include "YapEval.h"
#include "yapio.h" #include "yapio.h"
#ifdef TABLING #ifdef TABLING
#include "tab.macros.h" #include "tab.macros.h"
@ -58,6 +58,9 @@ static char SccsId[] = "%W% %G%";
#include <fcntl.h> #include <fcntl.h>
#include <wchar.h> #include <wchar.h>
extern int init_tries(void);
static Int p_setval(USES_REGS1); static Int p_setval(USES_REGS1);
static Int p_value(USES_REGS1); static Int p_value(USES_REGS1);
static Int p_values(USES_REGS1); static Int p_values(USES_REGS1);
@ -74,7 +77,7 @@ static Int p_halt(USES_REGS1);
#endif #endif
static Int current_predicate(USES_REGS1); static Int current_predicate(USES_REGS1);
static Int cont_current_predicate(USES_REGS1); static Int cont_current_predicate(USES_REGS1);
static OpEntry *NextOp(OpEntry *CACHE_TYPE); static OpEntry *NextOp(Prop CACHE_TYPE);
static Int init_current_op(USES_REGS1); static Int init_current_op(USES_REGS1);
static Int cont_current_op(USES_REGS1); static Int cont_current_op(USES_REGS1);
static Int init_current_atom_op(USES_REGS1); static Int init_current_atom_op(USES_REGS1);
@ -943,22 +946,24 @@ static Int current_predicate(USES_REGS1) {
return cont_current_predicate(PASS_REGS1); return cont_current_predicate(PASS_REGS1);
} }
static OpEntry *NextOp(OpEntry *pp USES_REGS) { static OpEntry *NextOp(Prop pp USES_REGS) {
while (!EndOfPAEntr(pp) && pp->KindOfPE != OpProperty && while (!EndOfPAEntr(pp) && pp->KindOfPE != OpProperty &&
(pp->OpModule != PROLOG_MODULE || pp->OpModule != CurrentModule)) (RepOpProp(pp)->OpModule != PROLOG_MODULE
pp = RepOpProp(pp->NextOfPE); || RepOpProp(pp)->OpModule != CurrentModule) )
return (pp); pp = pp->NextOfPE;
return RepOpProp(pp);
} }
int Yap_IsOp(Atom at) { int Yap_IsOp(Atom at) {
CACHE_REGS CACHE_REGS
OpEntry *op = NextOp(RepOpProp((Prop)(RepAtom(at)->PropsOfAE)) PASS_REGS); OpEntry *op = NextOp(RepAtom(at)->PropsOfAE PASS_REGS);
return (!EndOfPAEntr(op)); return (!EndOfPAEntr(op));
} }
int Yap_IsOpMaxPrio(Atom at) { int Yap_IsOpMaxPrio(Atom at) {
CACHE_REGS CACHE_REGS
OpEntry *op = NextOp(RepOpProp((Prop)(RepAtom(at)->PropsOfAE)) PASS_REGS); OpEntry *op = NextOp(RepAtom(at)->PropsOfAE PASS_REGS);
int max; int max;
if (EndOfPAEntr(op)) if (EndOfPAEntr(op))
@ -1020,7 +1025,7 @@ static Int cont_current_atom_op(USES_REGS1) {
OpEntry *op = (OpEntry *)IntegerOfTerm(EXTRA_CBACK_ARG(5, 1)), *next; OpEntry *op = (OpEntry *)IntegerOfTerm(EXTRA_CBACK_ARG(5, 1)), *next;
READ_LOCK(op->OpRWLock); READ_LOCK(op->OpRWLock);
next = NextOp(RepOpProp(op->NextOfPE) PASS_REGS); next = NextOp(op->NextOfPE PASS_REGS);
if (unify_op(op PASS_REGS)) { if (unify_op(op PASS_REGS)) {
READ_UNLOCK(op->OpRWLock); READ_UNLOCK(op->OpRWLock);
if (next) { if (next) {
@ -1053,7 +1058,7 @@ static Int init_current_atom_op(
cut_fail(); cut_fail();
} }
ae = RepAtom(AtomOfTerm(t)); ae = RepAtom(AtomOfTerm(t));
if (EndOfPAEntr((ope = NextOp(RepOpProp(ae->PropsOfAE) PASS_REGS)))) { if (EndOfPAEntr((ope = NextOp(ae->PropsOfAE PASS_REGS)))) {
cut_fail(); cut_fail();
} }
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((Int)ope); EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((Int)ope);
@ -1074,7 +1079,7 @@ static Int
cut_fail(); cut_fail();
} }
ae = RepAtom(AtomOfTerm(t)); ae = RepAtom(AtomOfTerm(t));
if (EndOfPAEntr((ope = NextOp(RepOpProp(ae->PropsOfAE) PASS_REGS)))) { if (EndOfPAEntr((ope = NextOp(ae->PropsOfAE PASS_REGS)))) {
cut_fail(); cut_fail();
} }
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((Int)ope); EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((Int)ope);
@ -1629,7 +1634,6 @@ void Yap_InitCPreds(void) {
#if SUPPORT_CONDOR #if SUPPORT_CONDOR
init_sys(); init_sys();
init_random(); init_random();
// init_tries();
init_regexp(); init_regexp();
#endif #endif
} }

150
C/text.c
View File

@ -16,10 +16,10 @@
*************************************************************************/ *************************************************************************/
#include "Yap.h" #include "Yap.h"
#include "YapEval.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "YapText.h" #include "YapText.h"
#include "Yatom.h" #include "Yatom.h"
#include "eval.h"
#include "yapio.h" #include "yapio.h"
#include <YapText.h> #include <YapText.h>
@ -51,9 +51,7 @@ typedef struct TextBuffer_manager {
int lvl; int lvl;
} text_buffer_t; } text_buffer_t;
int push_text_stack(USES_REGS1) { int push_text_stack(USES_REGS1) { return LOCAL_TextBuffer->lvl++; }
return LOCAL_TextBuffer->lvl++;
}
int pop_text_stack(int i) { int pop_text_stack(int i) {
int lvl = LOCAL_TextBuffer->lvl; int lvl = LOCAL_TextBuffer->lvl;
@ -72,6 +70,33 @@ int pop_text_stack(int i) {
return lvl; return lvl;
} }
void *protected_pop_text_stack(int i, void *protected, bool tmp,
size_t sz USES_REGS) {
void *out = protected;
int lvl = LOCAL_TextBuffer->lvl;
while (lvl > i) {
struct mblock *p = LOCAL_TextBuffer->first[lvl];
while (p) {
struct mblock *np = p->next;
if (p + 1 == protected) {
if (tmp)
out = LOCAL_FileNameBuf;
else
out = p;
memcpy(out, protected, sz);
} else {
free(p);
}
p = np;
}
LOCAL_TextBuffer->first[lvl] = NULL;
LOCAL_TextBuffer->last[lvl] = NULL;
lvl--;
}
LOCAL_TextBuffer->lvl = lvl;
return out;
}
// void pop_text_stack(int i) { LOCAL_TextBuffer->lvl = i; } // void pop_text_stack(int i) { LOCAL_TextBuffer->lvl = i; }
void *Malloc(size_t sz USES_REGS) { void *Malloc(size_t sz USES_REGS) {
@ -81,9 +106,9 @@ void *Malloc(size_t sz USES_REGS) {
sz = ALIGN_BY_TYPE(sz + sizeof(struct mblock), CELL); sz = ALIGN_BY_TYPE(sz + sizeof(struct mblock), CELL);
struct mblock *o = malloc(sz); struct mblock *o = malloc(sz);
o->prev = LOCAL_TextBuffer->last[lvl]; o->prev = LOCAL_TextBuffer->last[lvl];
if (o->prev) { if (o->prev) {
o->prev->next = o; o->prev->next = o;
} }
if (LOCAL_TextBuffer->first[lvl]) { if (LOCAL_TextBuffer->first[lvl]) {
LOCAL_TextBuffer->last[lvl] = o; LOCAL_TextBuffer->last[lvl] = o;
} else { } else {
@ -111,6 +136,7 @@ void *Realloc(void *pt, size_t sz USES_REGS) {
if (LOCAL_TextBuffer->last[lvl] == old) { if (LOCAL_TextBuffer->last[lvl] == old) {
LOCAL_TextBuffer->last[lvl] = o; LOCAL_TextBuffer->last[lvl] = o;
} }
return o + 1; return o + 1;
} }
@ -206,7 +232,7 @@ static Int SkipListCodes(unsigned char **bufp, Term *l, Term **tailp,
(*atoms)++; (*atoms)++;
if (*atoms < length) { if (*atoms < length) {
*tailp = l; *tailp = l;
return -REPRESENTATION_ERROR_CHARACTER_CODE; return -REPRESENTATION_ERROR_CHARACTER_CODE;
} else { } else {
AtomEntry *ae = RepAtom(AtomOfTerm(hd)); AtomEntry *ae = RepAtom(AtomOfTerm(hd));
if ((ae->StrOfAE)[1] != '\0') { if ((ae->StrOfAE)[1] != '\0') {
@ -356,10 +382,16 @@ static yap_error_number gen_type_error(int flags) {
} }
#endif #endif
// static int cnt;
unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) { unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
unsigned char *s0 = NULL; unsigned char *s0 = NULL;
bool wide; bool wide;
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
fprintf(stderr, "Sourious error %u\n", LOCAL_Error_TYPE);
LOCAL_Error_TYPE = YAP_NO_ERROR;
}
/* we know what the term is */ /* we know what the term is */
if (!(inp->type & (YAP_STRING_CHARS | YAP_STRING_WCHARS))) { if (!(inp->type & (YAP_STRING_CHARS | YAP_STRING_WCHARS))) {
if (!(inp->type & YAP_STRING_TERM)) { if (!(inp->type & YAP_STRING_TERM)) {
@ -386,82 +418,67 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
// this is a term, extract to a buffer, and representation is wide // this is a term, extract to a buffer, and representation is wide
// Yap_DebugPlWriteln(inp->val.t); // Yap_DebugPlWriteln(inp->val.t);
Atom at = AtomOfTerm(inp->val.t); Atom at = AtomOfTerm(inp->val.t);
if (lengp) if (lengp)
*lengp = strlen_utf8(at->UStrOfAE); *lengp = strlen(at->StrOfAE);
return at->UStrOfAE; return at->UStrOfAE;
} }
if (IsStringTerm(inp->val.t) && inp->type & YAP_STRING_STRING) { if (IsStringTerm(inp->val.t) && inp->type & YAP_STRING_STRING) {
// this is a term, extract to a buffer, and representation is wide // this is a term, extract to a buffer, and representation is wide
// Yap_DebugPlWriteln(inp->val.t); // Yap_DebugPlWriteln(inp->val.t);
if (lengp) if (lengp)
*lengp = strlen_utf8(UStringOfTerm(inp->val.t)); *lengp = strlen(StringOfTerm(inp->val.t));
return (unsigned char *)UStringOfTerm(inp->val.t); return (unsigned char *)UStringOfTerm(inp->val.t);
} }
if (((inp->type & (YAP_STRING_CODES | YAP_STRING_ATOMS)) == if (((inp->type & (YAP_STRING_CODES | YAP_STRING_ATOMS)) ==
(YAP_STRING_CODES | YAP_STRING_ATOMS)) && (YAP_STRING_CODES | YAP_STRING_ATOMS)) &&
IsPairOrNilTerm(inp->val.t)) { IsPairOrNilTerm(inp->val.t)) {
// Yap_DebugPlWriteln(inp->val.t); // Yap_DebugPlWriteln(inp->val.t);
return return Yap_ListToBuffer(s0, inp->val.t, inp, &wide, lengp PASS_REGS);
Yap_ListToBuffer(s0, inp->val.t, inp, &wide, lengp PASS_REGS);
// this is a term, extract to a sfer, and representation is wide // this is a term, extract to a sfer, and representation is wide
} }
if (inp->type & YAP_STRING_CODES && IsPairOrNilTerm(inp->val.t)) { if (inp->type & YAP_STRING_CODES && IsPairOrNilTerm(inp->val.t)) {
// Yap_DebugPlWriteln(inp->val.t); // Yap_DebugPlWriteln(inp->val.t);
return Yap_ListOfCodesToBuffer(s0, inp->val.t, inp, &wide, return Yap_ListOfCodesToBuffer(s0, inp->val.t, inp, &wide, lengp PASS_REGS);
lengp PASS_REGS);
// this is a term, extract to a sfer, and representation is wide // this is a term, extract to a sfer, and representation is wide
} }
if (inp->type & YAP_STRING_ATOMS && IsPairOrNilTerm(inp->val.t)) { if (inp->type & YAP_STRING_ATOMS && IsPairOrNilTerm(inp->val.t)) {
// Yap_DebugPlWriteln(inp->val.t); // Yap_DebugPlWriteln(inp->val.t);
return Yap_ListOfAtomsToBuffer(s0, inp->val.t, inp, &wide, return Yap_ListOfAtomsToBuffer(s0, inp->val.t, inp, &wide, lengp PASS_REGS);
lengp PASS_REGS);
// this is a term, extract to a buffer, and representation is wide // this is a term, extract to a buffer, and representation is wide
} }
if (inp->type & YAP_STRING_INT && IsIntegerTerm(inp->val.t)) { if (inp->type & YAP_STRING_INT && IsIntegerTerm(inp->val.t)) {
// ASCII, so both LATIN1 and UTF-8 // ASCII, so both LATIN1 and UTF-8
// Yap_DebugPlWriteln(inp->val.t); // Yap_DebugPlWriteln(inp->val.t);
char *s; char *s;
if (s0) s = Malloc(0);
s = (char *)s0;
else
s = Malloc(0);
if (snprintf(s, MaxTmp(PASS_REGS1) - 1, Int_FORMAT, if (snprintf(s, MaxTmp(PASS_REGS1) - 1, Int_FORMAT,
IntegerOfTerm(inp->val.t)) < 0) { IntegerOfTerm(inp->val.t)) < 0) {
AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char); AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char);
} }
*lengp = strlen(s); if (lengp)
*lengp = strlen(s);
return (unsigned char *)s; return (unsigned char *)s;
} }
if (inp->type & YAP_STRING_FLOAT && IsFloatTerm(inp->val.t)) { if (inp->type & YAP_STRING_FLOAT && IsFloatTerm(inp->val.t)) {
char *s; char *s;
size_t sz = 1024;
// Yap_DebugPlWriteln(inp->val.t); // Yap_DebugPlWriteln(inp->val.t);
if (s0) if (!Yap_FormatFloat(FloatOfTerm(inp->val.t), &s, 1024)) {
{ s = (char *)s0; sz = strlen(s);} return NULL;
else
s = Malloc(sz);
if (!s)
AUX_ERROR(inp->val.t, MaxTmp(PASS_REGS1), s, char);
while (!Yap_FormatFloat(FloatOfTerm(inp->val.t), &s, sz - 1)) {
if (s0) { s = Malloc(sz=1024); s0 = NULL; }
else s = Realloc(s, sz+1024);
} }
*lengp = strlen(s); if (lengp)
return inp->val.uc = (unsigned char *)s; *lengp = strlen(s);
return (unsigned char *)s;
} }
#if USE_GMP #if USE_GMP
if (inp->type & YAP_STRING_BIG && IsBigIntTerm(inp->val.t)) { if (inp->type & YAP_STRING_BIG && IsBigIntTerm(inp->val.t)) {
// Yap_DebugPlWriteln(inp->val.t); // Yap_DebugPlWriteln(inp->val.t);
char *s; char *s;
if (s0)
s = 0;
else
s = Malloc(0); s = Malloc(0);
if (!Yap_mpz_to_string(Yap_BigIntOfTerm(inp->val.t), s, MaxTmp() - 1, 10)) { if (!Yap_mpz_to_string(Yap_BigIntOfTerm(inp->val.t), s, MaxTmp() - 1, 10)) {
AUX_ERROR(inp->val.t, MaxTmp(PASS_REGS1), s, char); AUX_ERROR(inp->val.t, MaxTmp(PASS_REGS1), s, char);
} }
*lengp = strlen(s); if (lengp)
Malloc(*lengp); *lengp = strlen(s);
return inp->val.uc = (unsigned char *)s; return inp->val.uc = (unsigned char *)s;
} }
#endif #endif
@ -471,17 +488,16 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
return inp->val.uc = (unsigned char *)s; return inp->val.uc = (unsigned char *)s;
} }
if (inp->type & YAP_STRING_CHARS) { if (inp->type & YAP_STRING_CHARS) {
// printf("%s\n",inp->val.c); if (inp->enc == ENC_ISO_LATIN1) {
if (inp->enc == ENC_ISO_UTF8) {
if (lengp)
*lengp = strlen_utf8(inp->val.uc);
return inp->val.uc;
} else if (inp->enc == ENC_ISO_LATIN1) {
return latin2utf8(inp, lengp); return latin2utf8(inp, lengp);
} else if (inp->enc == ENC_ISO_ASCII) { } else if (inp->enc == ENC_ISO_ASCII) {
if (lengp) if (lengp)
*lengp = strlen(inp->val.c); *lengp = strlen(inp->val.c);
return inp->val.uc; return inp->val.uc;
}else { //if (inp->enc == ENC_ISO_UTF8) {
if (lengp)
*lengp = strlen(inp->val.c);
return inp->val.uc;
} }
} }
if (inp->type & YAP_STRING_WCHARS) { if (inp->type & YAP_STRING_WCHARS) {
@ -634,11 +650,11 @@ static Term write_codes(void *s0, seq_tv_t *out, size_t leng USES_REGS) {
static Atom write_atom(void *s0, seq_tv_t *out, size_t leng USES_REGS) { static Atom write_atom(void *s0, seq_tv_t *out, size_t leng USES_REGS) {
unsigned char *s = s0; unsigned char *s = s0;
int32_t ch; int32_t ch;
if ( leng == 0) { if (leng == 0) {
return Yap_LookupAtom(""); return Yap_LookupAtom("");
} }
if ( strlen_utf8(s0) <= leng) { if (strlen_utf8(s0) <= leng) {
return Yap_LookupAtom(s0); return Yap_LookupAtom(s0);
} else { } else {
size_t n = get_utf8(s, 1, &ch); size_t n = get_utf8(s, 1, &ch);
unsigned char *buf = Malloc(n + 1); unsigned char *buf = Malloc(n + 1);
@ -651,7 +667,7 @@ size_t write_buffer(unsigned char *s0, seq_tv_t *out, size_t leng USES_REGS) {
size_t min = 0, max = leng, room_end; size_t min = 0, max = leng, room_end;
if (out->enc == ENC_ISO_UTF8) { if (out->enc == ENC_ISO_UTF8) {
room_end = strlen((char *)s0) + 1; room_end = strlen((char *)s0) + 1;
if (out->val.uc == NULL) { if (out->val.uc == NULL) { // this should always be the case
out->val.uc = malloc(room_end < 16 ? 16 : room_end); out->val.uc = malloc(room_end < 16 ? 16 : room_end);
} }
if (out->val.uc != s0) { if (out->val.uc != s0) {
@ -720,18 +736,18 @@ static size_t write_length(const unsigned char *s0, seq_tv_t *out,
return leng; return leng;
} }
static Term write_number(unsigned char *s, seq_tv_t *out, int size, bool error_on USES_REGS) { static Term write_number(unsigned char *s, seq_tv_t *out, int size,
bool error_on USES_REGS) {
Term t; Term t;
int i = push_text_stack(); int i = push_text_stack();
t = Yap_StringToNumberTerm((char *)s, &out->enc, error_on); t = Yap_StringToNumberTerm((char *)s, &out->enc, error_on);
pop_text_stack(i); pop_text_stack(i);
return t; return t;
} }
static Term string_to_term(void *s, seq_tv_t *out, size_t leng USES_REGS) { static Term string_to_term(void *s, seq_tv_t *out, size_t leng USES_REGS) {
Term o; Term o;
o = out->val.t = o = out->val.t = Yap_BufferToTerm(s, strlen(s) + 1, TermNil);
Yap_StringToTerm(s, strlen(s) + 1, &out->enc, GLOBAL_MaxPriority, 0L);
return o; return o;
} }
@ -746,7 +762,8 @@ bool write_Text(unsigned char *inp, seq_tv_t *out, size_t leng USES_REGS) {
return out->val.t != 0; return out->val.t != 0;
} }
if (out->type & (YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG)) { if (out->type & (YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG)) {
if ((out->val.t = write_number(inp, out, leng,!(out->type & YAP_STRING_ATOM) PASS_REGS)) != 0L) { if ((out->val.t = write_number(
inp, out, leng, !(out->type & YAP_STRING_ATOM) PASS_REGS)) != 0L) {
// Yap_DebugPlWriteln(out->val.t); // Yap_DebugPlWriteln(out->val.t);
return true; return true;
@ -800,7 +817,7 @@ bool write_Text(unsigned char *inp, seq_tv_t *out, size_t leng USES_REGS) {
out->val.t = write_number(inp, out, leng, true PASS_REGS); out->val.t = write_number(inp, out, leng, true PASS_REGS);
// Yap_DebugPlWriteln(out->val.t); // Yap_DebugPlWriteln(out->val.t);
return out->val.t != 0; return out->val.t != 0;
default: { return true ; } default: { return true; }
} }
return false; return false;
} }
@ -845,10 +862,11 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
.w); .w);
else fprintf(stderr,"s %s\n", inp->val.c); else fprintf(stderr,"s %s\n", inp->val.c);
*/ */
// cnt++;
buf = Yap_readText(inp, &leng PASS_REGS); buf = Yap_readText(inp, &leng PASS_REGS);
if (out->type & (YAP_STRING_NCHARS | YAP_STRING_TRUNC)) { if (out->type & (YAP_STRING_NCHARS | YAP_STRING_TRUNC)) {
if (out->max < leng) { if (out->max < leng) {
const unsigned char *ptr = skip_utf8(buf, leng); const unsigned char *ptr = skip_utf8(buf, out->max);
size_t diff = (ptr - buf); size_t diff = (ptr - buf);
char *nbuf = Malloc(diff + 1); char *nbuf = Malloc(diff + 1);
memcpy(nbuf, buf, diff); memcpy(nbuf, buf, diff);
@ -858,10 +876,10 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
// else if (out->type & YAP_STRING_NCHARS && // else if (out->type & YAP_STRING_NCHARS &&
// const unsigned char *ptr = skip_utf8(buf, leng) // const unsigned char *ptr = skip_utf8(buf, leng)
} }
if (!buf) { if (!buf) {
return 0L; return 0L;
} }
if (out->type & (YAP_STRING_UPCASE | YAP_STRING_DOWNCASE)) { if (out->type & (YAP_STRING_UPCASE | YAP_STRING_DOWNCASE)) {
if (out->type & YAP_STRING_UPCASE) { if (out->type & YAP_STRING_UPCASE) {
if (!upcase(buf, out)) { if (!upcase(buf, out)) {
@ -917,9 +935,9 @@ static unsigned char *concat(int n, void *sv[] USES_REGS) {
buf = Malloc(room + 1); buf = Malloc(room + 1);
buf0 = buf; buf0 = buf;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
#if _WIN32 || defined( __ANDROID__ ) #if _WIN32 || defined(__ANDROID__)
strcpy(buf, sv[i]); strcpy(buf, sv[i]);
buf = (char*)buf + strlen(buf); buf = (char *)buf + strlen(buf);
#else #else
buf = stpcpy(buf, sv[i]); buf = stpcpy(buf, sv[i]);
#endif #endif
@ -1021,7 +1039,7 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
next = 0; next = 0;
else else
next = cuts[i - 1]; next = cuts[i - 1];
if (i>0 && cuts[i] == 0) if (i > 0 && cuts[i] == 0)
break; break;
void *bufi = slice(next, cuts[i], buf PASS_REGS); void *bufi = slice(next, cuts[i], buf PASS_REGS);
if (!write_Text(bufi, outv + i, cuts[i] - next PASS_REGS)) { if (!write_Text(bufi, outv + i, cuts[i] - next PASS_REGS)) {
@ -1085,7 +1103,7 @@ const char *Yap_TextTermToText(Term t, char *buf, size_t len, encoding_t enc) {
const char *Yap_PredIndicatorToUTF8String(PredEntry *ap) { const char *Yap_PredIndicatorToUTF8String(PredEntry *ap) {
CACHE_REGS CACHE_REGS
Atom at; Atom at;
arity_t arity = 0; arity_t arity = 0;
Functor f; Functor f;
char *s, *smax, *s0; char *s, *smax, *s0;
s = s0 = malloc(1024); s = s0 = malloc(1024);

View File

@ -26,7 +26,7 @@ static char SccsId[] = "%W% %G%";
#include "Yap.h" #include "Yap.h"
#include "Yatom.h" #include "Yatom.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "eval.h" #include "YapEval.h"
#include "yapio.h" #include "yapio.h"
#include "blobs.h" #include "blobs.h"
#include <stdio.h> #include <stdio.h>

View File

@ -28,53 +28,88 @@
#include "tracer.h" #include "tracer.h"
#include "yapio.h" #include "yapio.h"
static char *send_tracer_message(char *start, char *name, Int arity, static char *send_tracer_message(char *start, char *name, arity_t arity,
char *mname, CELL *args, char *s, char *top) { char *mname, CELL *args, char **s0, char *s,
if (name == NULL) { char **top) {
#ifdef YAPOR bool expand = false;
s += snprintf(s, top - s, "(%d)%s", worker_id, start); size_t max = *top - (s + 1);
#else int d, min = 1024;
s += snprintf(s, top - s, "%s", start); char *s1 = s;
#endif do {
} else { if (expand || max < 32) {
int i; Int cbeg = s1 - *s0;
max = *top - *s0;
max += min;
*s0 = Realloc(*s0, max);
if (arity) { *top = *s0 + max;
if (args) max--;
s += snprintf(s, top - s, "%s %s:%s(", start, mname, name); s1 = *s0 + cbeg;
else s = s1;
s += snprintf(s, top - s, "%s %s:%s/%lu", start, mname, name, expand = false;
(unsigned long int)arity);
} else {
s += snprintf(s, top - s, "%s %s:%s", start, mname, name);
} }
min = 1024;
if (name == NULL) {
#ifdef YAPOR
d = snprintf(s, max, "(%d)%s", worker_id, start);
#else
d = snprintf(s, max, "%s", start);
#endif
} else {
if (arity) {
if (args)
d = snprintf(s, max, "%s %s:%s(", start, mname, name);
else
d = snprintf(s, max, "%s %s:%s/%lu", start, mname, name,
(unsigned long int)arity);
} else {
d = snprintf(s, max, "%s %s:%s", start, mname, name);
}
}
if (d >= max) {
expand = true;
min = d + 1024;
continue;
}
max -= d;
s += d;
if (args) { if (args) {
int i;
for (i = 0; i < arity; i++) { for (i = 0; i < arity; i++) {
size_t length = top - (s + 4); if (i > 0) {
if ((ssize_t)length < 16) { if (max > 16) {
s[0] = '\0'; *s++ = ',';
return s; *s++ = ' ';
} max-=2;
if (i > 0) { } else {
*s++ = ','; expand = true;
continue;
}
} }
const char *sn = Yap_TermToString(args[i], NULL, LOCAL_encoding, const char *sn = Yap_TermToString(args[i], NULL, LOCAL_encoding,
Quote_illegal_f | Handle_vars_f); Quote_illegal_f | Handle_vars_f);
size_t sz; size_t sz;
if (sn != s) { if (sn == NULL) {
if (sn == NULL) { sn = "<* error *>";
sn = "<* error *>";
}
strlcpy(s, sn, top - (s + 3));
} }
sz = strlen(s); sz = strlen(sn);
if (max <= sz) {
min = sz + 1024;
expand = true;
continue;
}
strcpy(s, sn);
s += sz; s += sz;
max -= sz;
} }
if (arity) { if (arity) {
*s++ = ' ';
*s++ = ')'; *s++ = ')';
max -= 2;
} }
} }
} } while (expand);
s[0] = '\0'; s[0] = '\0';
return s; return s;
} }
@ -154,22 +189,22 @@ check_area(void)
jmp_deb(i); jmp_deb(i);
} }
*/ */
// PredEntry *old_p[10000]; // PredEntry *old_p[10000];
// Term old_x1[10000], old_x2[10000], old_x3[10000]; // Term old_x1[10000], old_x2[10000], old_x3[10000];
// static CELL oldv = 0; // static CELL oldv = 0;
void low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) { bool low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) {
CACHE_REGS CACHE_REGS
char *s; char *s;
char *mname; char *mname;
Int arity; Int arity;
int l = push_text_stack();
/* extern int gc_calls; */ /* extern int gc_calls; */
vsc_count++; vsc_count++;
// if (HR < ASP ) return; // if (HR < ASP ) return;
// fif (vsc_count == 12534) jmp_deb( 2 ); // fif (vsc_count == 12534) jmp_deb( 2 );
char buf[512], *top = buf + 511, *b = buf; char *buf = Malloc(512), *top = buf + 511, *b = buf;
// if (!worker_id) return; // if (!worker_id) return;
LOCK(Yap_low_level_trace_lock); LOCK(Yap_low_level_trace_lock);
@ -308,12 +343,10 @@ void low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) {
while (env_ptr) { while (env_ptr) {
PredEntry *pe = EnvPreg(env_ptr[E_CP]); PredEntry *pe = EnvPreg(env_ptr[E_CP]);
printf("%p->", env_ptr, pe);
if (vsc_count == 52LL)
printf("\n");
if (p == pe) { if (p == pe) {
UNLOCK(Yap_heap_regs->low_level_trace_lock); UNLOCK(Yap_heap_regs->low_level_trace_lock);
return; pop_text_stack(l);
ReleaseAndReturn(true);
} }
if (env_ptr != NULL) if (env_ptr != NULL)
env_ptr = (CELL *)(env_ptr[E_E]); env_ptr = (CELL *)(env_ptr[E_E]);
@ -329,12 +362,13 @@ void low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) {
/* check_trail_consistency(); */ /* check_trail_consistency(); */
if (pred == NULL) { if (pred == NULL) {
UNLOCK(Yap_low_level_trace_lock); UNLOCK(Yap_low_level_trace_lock);
return; pop_text_stack(l);
ReleaseAndReturn(true);
} }
if (pred->ModuleOfPred == PROLOG_MODULE) { if (pred->ModuleOfPred == PROLOG_MODULE) {
if (!LOCAL_do_trace_primitives) { if (!LOCAL_do_trace_primitives) {
UNLOCK(Yap_low_level_trace_lock); UNLOCK(Yap_low_level_trace_lock);
return; ReleaseAndReturn(true);
} }
mname = "prolog"; mname = "prolog";
} else { } else {
@ -350,42 +384,45 @@ void low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) {
} }
/* if ((pred->ModuleOfPred == 0) && (s[0] == '$')) /* if ((pred->ModuleOfPred == 0) && (s[0] == '$'))
return; */ return; */
b = send_tracer_message("CALL: ", s, arity, mname, args, b, top); b = send_tracer_message("CALL: ", s, arity, mname, args, &buf, b, &top);
break; break;
case try_or: case try_or:
b = send_tracer_message("TRY_OR ", NULL, 0, NULL, args, b, top); b = send_tracer_message("TRY_OR ", NULL, 0, NULL, args, &buf, b, &top);
break; break;
case retry_or: case retry_or:
b = send_tracer_message("FAIL ", NULL, 0, NULL, args, b, top); b = send_tracer_message("FAIL ", NULL, 0, NULL, args, &buf, b, &top);
b = send_tracer_message("RETRY_OR ", NULL, 0, NULL, args, b, top); b = send_tracer_message("RETRY_OR ", NULL, 0, NULL, args, &buf, b, &top);
break; break;
case retry_table_generator: case retry_table_generator:
b = send_tracer_message("FAIL ", NULL, 0, NULL, args, b, top); b = send_tracer_message("FAIL ", NULL, 0, NULL, args, &buf, b, &top);
mname = (char *)RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE; mname = (char *)RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE;
arity = pred->ArityOfPE; arity = pred->ArityOfPE;
if (arity == 0) if (arity == 0)
s = (char *)RepAtom((Atom)pred->FunctorOfPred)->StrOfAE; s = (char *)RepAtom((Atom)pred->FunctorOfPred)->StrOfAE;
else else
s = (char *)RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE; s = (char *)RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE;
b = send_tracer_message("RETRY GENERATOR: ", s, arity, mname, args, b, top); b = send_tracer_message("RETRY GENERATOR: ", s, arity, mname, args, &buf, b,
&top);
break; break;
case retry_table_consumer: case retry_table_consumer:
b = send_tracer_message("FAIL ", NULL, 0, NULL, args, b, top); b = send_tracer_message("FAIL ", NULL, 0, NULL, args, &buf, b, &top);
mname = (char *)RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE; mname = (char *)RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE;
arity = pred->ArityOfPE; arity = pred->ArityOfPE;
if (arity == 0) { if (arity == 0) {
s = (char *)RepAtom((Atom)pred->FunctorOfPred)->StrOfAE; s = (char *)RepAtom((Atom)pred->FunctorOfPred)->StrOfAE;
b = send_tracer_message("RETRY CONSUMER: ", s, 0, mname, NULL, b, top); b = send_tracer_message("RETRY CONSUMER: ", s, 0, mname, NULL, &buf, b,
&top);
} else { } else {
s = (char *)RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE; s = (char *)RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE;
b = send_tracer_message("RETRY CONSUMER: ", s, pred->ArityOfPE, mname, b = send_tracer_message("RETRY CONSUMER: ", s, pred->ArityOfPE, mname,
NULL, b, top); NULL, &buf, b, &top);
} }
break; break;
case retry_table_loader: case retry_table_loader:
b = send_tracer_message("FAIL ", NULL, 0, NULL, args, b, top); b = send_tracer_message("FAIL ", NULL, 0, NULL, args, &buf, b, &top);
if (pred == UndefCode) { if (pred == UndefCode) {
b = send_tracer_message("RETRY LOADER ", NULL, 0, NULL, NULL, b, top); b = send_tracer_message("RETRY LOADER ", NULL, 0, NULL, NULL, &buf, b,
&top);
} else { } else {
mname = (char *)RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE; mname = (char *)RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE;
arity = pred->ArityOfPE; arity = pred->ArityOfPE;
@ -393,11 +430,12 @@ void low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) {
s = (char *)RepAtom((Atom)pred->FunctorOfPred)->StrOfAE; s = (char *)RepAtom((Atom)pred->FunctorOfPred)->StrOfAE;
else else
s = (char *)RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE; s = (char *)RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE;
b = send_tracer_message("RETRY LOADER: ", s, 0, mname, NULL, b, top); b = send_tracer_message("RETRY LOADER: ", s, 0, mname, NULL, &buf, b,
&top);
} }
break; break;
case retry_pred: case retry_pred:
b = send_tracer_message("FAIL ", NULL, 0, NULL, args, b, top); b = send_tracer_message("FAIL ", NULL, 0, NULL, args, &buf, b, &top);
if (pred != NULL) { if (pred != NULL) {
mname = (char *)RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE; mname = (char *)RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE;
arity = pred->ArityOfPE; arity = pred->ArityOfPE;
@ -409,7 +447,7 @@ void low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) {
} else { } else {
s = (char *)RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE; s = (char *)RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE;
} }
b = send_tracer_message("RETRY: ", s, arity, mname, args, b, top); b = send_tracer_message("RETRY: ", s, arity, mname, args, &buf, b, &top);
} }
break; break;
} }
@ -418,9 +456,11 @@ void low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) {
__android_log_print(ANDROID_LOG_DEBUG, "YAPDroid", "%s\n", buf); __android_log_print(ANDROID_LOG_DEBUG, "YAPDroid", "%s\n", buf);
#else #else
*b++ = '\n'; *b++ = '\n';
*b++ = '\0'; *b = '\0';
fputs(buf, stderr); fputs(buf, stderr);
#endif #endif
pop_text_stack(l);
ReleaseAndReturn(true);
} }
void toggle_low_level_trace(void) { void toggle_low_level_trace(void) {
@ -442,7 +482,7 @@ static Int reset_total_choicepoints(USES_REGS1) {
} }
static Int show_low_level_trace(USES_REGS1) { static Int show_low_level_trace(USES_REGS1) {
fprintf(stderr, "Call counter=%lld\n", vsc_count); fprintf(stderr, "Call counter=%llu\n", vsc_count);
return (TRUE); return (TRUE);
} }

View File

@ -385,15 +385,16 @@ int Yap_FormatFloat(Float f, char **s, size_t sz) {
sno = Yap_open_buf_write_stream(GLOBAL_Stream[LOCAL_c_output_stream].encoding, sno = Yap_open_buf_write_stream(GLOBAL_Stream[LOCAL_c_output_stream].encoding,
0); 0);
if (sno < 0) if (sno < 0)
return FALSE; return false;
wglb.lw = separator; wglb.lw = separator;
wglb.stream = GLOBAL_Stream + sno; wglb.stream = GLOBAL_Stream + sno;
wrputf(f, &wglb); wrputf(f, &wglb);
wrputc('\0', wglb.stream); wrputc('\0', wglb.stream);
so = Yap_MemExportStreamPtr(sno); so = Yap_MemExportStreamPtr(sno);
*s = Malloc( strlen(so) )+1;
strcpy(*s, so );
Yap_CloseStream(sno); Yap_CloseStream(sno);
*s = so; return true;
return TRUE;
} }
/* writes a data base reference */ /* writes a data base reference */
@ -568,11 +569,12 @@ static void write_string(const unsigned char *s,
int delta; int delta;
ptr += (delta = get_utf8(ptr, -1, &chr) ); ptr += (delta = get_utf8(ptr, -1, &chr) );
if (chr == '\0') if (chr == '\0') {
break; break;
if (delta == 0) {chr = *ptr++; } }
if (delta == 0) {chr = *ptr++; }
write_quoted(chr, qt, stream); write_quoted(chr, qt, stream);
} while (TRUE); } while (true);
wrputc(qt, stream); wrputc(qt, stream);
} }

View File

@ -369,8 +369,7 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
p++; p++;
} }
} else { } else {
YAP_SetOutputMessage(); YAP_SetOutputMessage();
} }
break; break;
#endif #endif
@ -446,13 +445,13 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
break; break;
case 'n': case 'n':
if (!strcmp("nosignals", p)) { if (!strcmp("nosignals", p)) {
iap->PrologShouldHandleInterrupts = FALSE; iap->PrologCannotHandleInterrupts = true;
break; break;
} }
break; break;
case '-': case '-':
if (!strcmp("-nosignals", p)) { if (!strcmp("-nosignals", p)) {
iap->PrologShouldHandleInterrupts = FALSE; iap->PrologCannotHandleInterrupts = true;
break; break;
} else if (!strncmp("-home=", p, strlen("-home="))) { } else if (!strncmp("-home=", p, strlen("-home="))) {
GLOBAL_Home = p + strlen("-home="); GLOBAL_Home = p + strlen("-home=");

View File

@ -1,9 +1,7 @@
# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower. # value of 3.4.0 or lower.
# Sets the minimum version of CMake required to build the native # Sets the version of CMake required to build the native
# library. You should either keep the default value or only pass a # library. You should either keep the default value or pass a
# value of 3.4.0 or lower. # value of 3.4.0 or lower.
project( YAP ) project( YAP )
@ -15,14 +13,13 @@ if (ANDROID)
else () else ()
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
include(CMakeToolsHelpers OPTIONAL) include(CMakeToolsHelpers OPTIONAL)
endif() endif()
set( set(
CMAKE_MODULE_PATH CMAKE_MODULE_PATH
"${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}"
"${CMAKE_SOURCE_DIR}/cmake") "${CMAKE_SOURCE_DIR}/cmake"
)
include(CheckIncludeFiles) include(CheckIncludeFiles)
include(CheckLibraryExists) include(CheckLibraryExists)
@ -34,14 +31,15 @@ include(MacroOptionalFindPackage)
include(MacroLogFeature) include(MacroLogFeature)
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
include (GNUInstallDirs) include (GNUInstallDirs)
# Creates and names a library, sets it as either STATIC # Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code. # or SHARED, and provides the relative paths to its source code.z
# You can define multiple libraries, and CMake builds it for you. # You can define libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK. # Gradle automatically packages shared libraries with your APK.
#cross-compilation support #cross-compilation support
# Search packages for host system instead of packages for target system # Search packages for host system instead of packages for target system
# in case of cross compilation these macro should be defined by toolchain file # in case of cross compilation define these macro by toolchain file
if(NOT COMMAND find_host_package) if(NOT COMMAND find_host_package)
macro(find_host_package) macro(find_host_package)
find_package(${ARGN}) find_package(${ARGN})
@ -54,6 +52,8 @@ if(NOT COMMAND find_host_program)
endif() endif()
option(BUILD_SHARED_LIBS "Build shared library" ON) option(BUILD_SHARED_LIBS "Build shared library" ON)
set (CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
include(Prelims NO_POLICY_SCOPE) include(Prelims NO_POLICY_SCOPE)
@ -61,15 +61,17 @@ include(Sources NO_POLICY_SCOPE)
include(Model NO_POLICY_SCOPE) include(Model NO_POLICY_SCOPE)
include_directories ( utf8proc packages/myddas packages/myddas/sqlite3) include_directories ( utf8proc packages/myddas packages/myddas/sqlite3/src)
if (ANDROID) if (ANDROID)
include_directories ( include_directories (
packages/myddas/sqlite3/Android/jni/sqlite packages/myddas/sqlite3/src/Android/jni/sqlite
packages/myddas/sqlite3/Android/jni/sqlite/nativehelper packages/myddas/sqlite3/src/Android/jni/sqlite/nativehelper
) )
endif (ANDROID) endif (ANDROID)
set_property( SOURCE ${LIBYAP_SOURCES} APPEND PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1)
add_definitions(-DUSE_MYDDAS=1 -DMYDDAS_SQLITE3=1) add_definitions(-DUSE_MYDDAS=1 -DMYDDAS_SQLITE3=1)
if (MYSQL_FOUND) if (MYSQL_FOUND)
@ -83,37 +85,33 @@ if (ODBC_FOUND)
if (MYSQL_POSTGRES) if (MYSQL_POSTGRES)
add_definitions(= -DMYDDAS_POSTGRES=1) add_definitions(= -DMYDDAS_POSTGRES=1)
endif() endif()
if (MYSQL_POSTGRES)
set(SWIG_SOURCES packages/swig/python/yap_PYTHONwrapper.cxx )
endif()
if (ANDROID)
if (ANDROID)
ADD_SUBDIRECTORY(os) ADD_SUBDIRECTORY(os)
ADD_SUBDIRECTORY(OPTYap) ADD_SUBDIRECTORY(OPTYap)
ADD_SUBDIRECTORY(packages/myddas) ADD_SUBDIRECTORY(packages/myddas)
ADD_SUBDIRECTORY(library/random)
ADD_SUBDIRECTORY(library/system)
ADD_SUBDIRECTORY(utf8proc) ADD_SUBDIRECTORY(utf8proc)
ADD_SUBDIRECTORY(CXX) ADD_SUBDIRECTORY(CXX)
set (SWIG_FILES ${CMAKE_SOURCE_DIR}/../generated/jni/yap_wrap.cpp )
else () else()
set(YLIBS
$<TARGET_OBJECTS:libYAPOs>
$<TARGET_OBJECTS:libOPTYap>
$<TARGET_OBJECTS:myddas>
$<TARGET_OBJECTS:Yapsqlite3>
$<TARGET_OBJECTS:libswi>
$<TARGET_OBJECTS:utf8proc>
)
endif ()
List (APPEND YLIBS $<TARGET_OBJECTS:libOPTYap> )
List (APPEND YLIBS $<TARGET_OBJECTS:libYAPOs> )
List (APPEND YLIBS $<TARGET_OBJECTS:utf8proc> )
List (APPEND YLIBS $<TARGET_OBJECTS:myddas> )
List (APPEND YLIBS $<TARGET_OBJECTS:Yapsqlite3> )
List (APPEND YLIBS $<TARGET_OBJECTS:libswi> )
if (WIN32) if (WIN32)
list (APPEND YLIBS $<TARGET_OBJECTS:Yap++>) List (APPEND YLIBS $<TARGET_OBJECTS:YAP++> )
endif() endif()
add_library( # Sets the name of the library. add_library( # Sets the name of the library.
libYap libYap
@ -121,22 +119,24 @@ add_library( # Sets the name of the library.
SHARED SHARED
${ENGINE_SOURCES} ${ENGINE_SOURCES}
${SWIG_FILES}
${C_INTERFACE_SOURCES} ${C_INTERFACE_SOURCES}
${STATIC_SOURCES} //${STATIC_SOURCES}
${ALL_SOURCES} # cmake object libraries
${YLIBS} ${YLIBS}
${WINDLLS}
) )
if (WIN32)
target_link_libraries(libYap ${WINDLLS})
endif (WIN32)
include(libYap NO_POLICY_SCOPE) include(libYap NO_POLICY_SCOPE)
endif()
if (USE_READLINE) if (USE_READLINE)
target_link_libraries(libYap ${READLINE_LIBRARIES}) target_link_libraries(libYap ${READLINE_LIBRARIES})
endif (USE_READLINE) endif (USE_READLINE)
if (ANDROID) if (ANDROID)
add_dependencies(libYap plmyddas ) add_dependencies(libYap plmyddas )
@ -145,9 +145,8 @@ if (ANDROID)
endif () endif ()
set_target_properties(libYap set_target_properties(libYap
PROPERTIES OUTPUT_NAME Yap PROPERTIES OUTPUT_NAME Yap
) )
MY_include(Packages NO_POLICY_SCOPE) MY_include(Packages NO_POLICY_SCOPE)
include(Config NO_POLICY_SCOPE) include(Config NO_POLICY_SCOPE)

View File

@ -8,18 +8,29 @@ set (CXX_SOURCES
yapi.cpp yapi.cpp
) )
set (CXX_HEADERS
yapa.hh
yapdb.hh
yapi.h
yapie.hh
yapq.hh
- yapt.hh
-)
list(APPEND LIBYAP_SOURCES ${CXX_SOURCES} PARENT_SCOPE) list(APPEND LIBYAP_SOURCES ${CXX_SOURCES} PARENT_SCOPE)
if (ANDROID OR WIN32) if ( WIN32)
add_component (Yap++ ${CXX_SOURCES} ) add_component (YAP++ ${CXX_SOURCES} )
else()
add_external (Yap++ ${CXX_SOURCES} )
MY_target_link_libraries(Yap++ ${CMAKE_DL_LIBS} libYap)
MY_install(TARGETS Yap++ set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_YAP_NOT_INSTALLED_=1;HAVE_CONFIG_H=1;_GNU_SOURCE;YAP_KERNEL=1" )
LIBRARY DESTINATION ${libdir} else()
ARCHIVE DESTINATION ${libdir} add_external (YAP++ ${CXX_SOURCES} )
MY_target_link_libraries(YAP++ ${CMAKE_DL_LIBS} libYap)
MY_install(TARGETS YAP++
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
) )
endif() endif()

View File

@ -1,9 +0,0 @@
set (CXX_SOURCES
yapa.hh
yapdb.hh
yapi.cpp
yapi.hh
yapie.hh
yapq.hh
yapt.hh
)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,142 +0,0 @@
###################
### WARNING!!! ###
###################
# This file has been autogenerated
# Cython imports
from cython.operator cimport dereference as deref
from cython.operator cimport preincrement as inc
from libc cimport stdio
from cpython.version cimport PY_MAJOR_VERSION
from cpython.ref cimport PyTypeObject, Py_INCREF, Py_XDECREF
from cpython.type cimport PyType_Ready
from cpython.object cimport PyObject
from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE
# Python imports
cimport numpy as np
# Local imports
cimport xdress_extra_types
# Cython imports for types
cdef extern from "Python.h":
ctypedef Py_ssize_t Py_ssize_t
cdef long Py_TPFLAGS_DEFAULT
cdef long Py_TPFLAGS_BASETYPE
cdef long Py_TPFLAGS_CHECKTYPES
cdef long Py_TPFLAGS_HEAPTYPE
ctypedef struct PyGetSetDef:
char * name
ctypedef struct PyTypeObject:
char * tp_name
int tp_basicsize
int tp_itemsize
object tp_alloc(PyTypeObject *, Py_ssize_t)
void tp_dealloc(object)
object tp_richcompare(object, object, int)
object tp_new(PyTypeObject *, object, object)
object tp_str(object)
object tp_repr(object)
long tp_hash(object)
long tp_flags
char * tp_doc
PyMemberDef * tp_members
PyGetSetDef * tp_getset
PyTypeObject * tp_base
void tp_free(void *)
# This is a dirty hack by declaring to Cython both the Python 2 & 3 APIs
int (*tp_compare)(object, object) # Python 2
void * (*tp_reserved)(object, object) # Python 3
# structmember.h isn't included in Python.h for some reason
cdef extern from "structmember.h":
ctypedef struct PyMemberDef:
char * name
int type
Py_ssize_t offset
int flags
char * doc
cdef extern from "numpy/arrayobject.h":
ctypedef object (*PyArray_GetItemFunc)(void *, void *)
ctypedef int (*PyArray_SetItemFunc)(object, void *, void *)
ctypedef void (*PyArray_CopySwapNFunc)(void *, np.npy_intp, void *, np.npy_intp, np.npy_intp, int, void *)
ctypedef void (*PyArray_CopySwapFunc)(void *, void *, int, void *)
ctypedef int (*PyArray_CompareFunc)(const void* d1, const void *, void *)
ctypedef int (*PyArray_ArgFunc)(void *, np.npy_intp, np.npy_intp *, void *)
ctypedef void (*PyArray_DotFunc)(void *, np.npy_intp, void *, np.npy_intp, void *, np.npy_intp, void *)
ctypedef int (*PyArray_ScanFunc)(stdio.FILE *, void *, void *, void *)
ctypedef int (*PyArray_FromStrFunc)(char *, void *, char **, void *)
ctypedef np.npy_bool (*PyArray_NonzeroFunc)(void *, void *)
ctypedef void (*PyArray_FillFunc)(void *, np.npy_intp, void *)
ctypedef void (*PyArray_FillWithScalarFunc)(void *, np.npy_intp, void *, void *)
ctypedef int (*PyArray_SortFunc)(void *, np.npy_intp, void *)
ctypedef int (*PyArray_ArgSortFunc)(void *, np.npy_intp *, np.npy_intp, void *)
ctypedef np.NPY_SCALARKIND (*PyArray_ScalarKindFunc)(np.PyArrayObject *)
ctypedef struct PyArray_ArrFuncs:
np.PyArray_VectorUnaryFunc ** cast
PyArray_GetItemFunc *getitem
PyArray_SetItemFunc *setitem
PyArray_CopySwapNFunc *copyswapn
PyArray_CopySwapFunc *copyswap
PyArray_CompareFunc *compare
PyArray_ArgFunc *argmax
PyArray_DotFunc *dotfunc
PyArray_ScanFunc *scanfunc
PyArray_FromStrFunc *fromstr
PyArray_NonzeroFunc *nonzero
PyArray_FillFunc *fill
PyArray_FillWithScalarFunc *fillwithscalar
PyArray_SortFunc *sort
PyArray_ArgSortFunc *argsort
PyObject *castdict
PyArray_ScalarKindFunc *scalarkind
int **cancastscalarkindto
int *cancastto
int listpickle
cdef void PyArray_InitArrFuncs(PyArray_ArrFuncs *)
ctypedef struct PyArray_ArrayDescr:
PyArray_Descr * base
PyObject *shape
cdef void ** PyArray_API
cdef PyTypeObject * PyArrayDescr_Type
ctypedef struct PyArray_Descr:
Py_ssize_t ob_refcnt
PyTypeObject * ob_type
PyTypeObject * typeobj
char kind
char type
char byteorder
int flags
int type_num
int elsize
int alignment
PyArray_ArrayDescr * subarray
PyObject * fields
PyObject * names
PyArray_ArrFuncs * f
cdef int PyArray_RegisterDataType(PyArray_Descr *)
cdef object PyArray_Scalar(void *, PyArray_Descr *, object)
cdef extern from "xdress_extra_types.h" namespace "xdress_extra_types":
cdef cppclass MemoryKnight[T]:
MemoryKnight() nogil except +
T * defnew() nogil except +
T * renew(void *) nogil except +
void deall(T *) nogil except +

View File

@ -1,43 +0,0 @@
###################
### WARNING!!! ###
###################
# This file has been autogenerated
# Cython imports
from cython.operator cimport dereference as deref
from cython.operator cimport preincrement as inc
from libc.stdlib cimport malloc, free
from libc.string cimport memcpy
from cpython.version cimport PY_MAJOR_VERSION
from cpython.ref cimport PyTypeObject
from cpython.type cimport PyType_Ready
from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE
# Python Imports
import collections
cimport numpy as np
import numpy as np
np.import_array()
cimport xdress_extra_types
# Cython imports for types
# imports for types
dtypes = {}
if PY_MAJOR_VERSION >= 3:
basestring = str
# Dirty ifdef, else, else preprocessor hack
# see http://comments.gmane.org/gmane.comp.python.cython.user/4080
cdef extern from *:
cdef void emit_ifpy2k "#if PY_MAJOR_VERSION == 2 //" ()
cdef void emit_ifpy3k "#if PY_MAJOR_VERSION == 3 //" ()
cdef void emit_else "#else //" ()
cdef void emit_endif "#endif //" ()

File diff suppressed because it is too large Load Diff

View File

@ -1,30 +0,0 @@
###################
### WARNING!!! ###
###################
# This file has been autogenerated
# Cython imports
from cython.operator cimport dereference as deref
from cython.operator cimport preincrement as inc
from libcpp.string cimport string as std_string
from libcpp.utility cimport pair
from libcpp.map cimport map as cpp_map
from libcpp.set cimport set as cpp_set
from libcpp.vector cimport vector as cpp_vector
from libcpp cimport bool as cpp_bool
from libc cimport stdio
from cpython.version cimport PY_MAJOR_VERSION
from cpython.ref cimport PyTypeObject, Py_INCREF, Py_XDECREF
# Python Imports
cimport numpy as np
# Local imports
cimport xdress_extra_types
cimport numpy as np
# Cython Imports For Types

View File

@ -1,45 +0,0 @@
###################
### WARNING!!! ###
###################
# This file has been autogenerated
# Cython imports
from cython.operator cimport dereference as deref
from cython.operator cimport preincrement as inc
from libc.stdlib cimport malloc, free
from libc.string cimport memcpy
from libcpp.string cimport string as std_string
from libcpp.utility cimport pair
from libcpp.map cimport map as cpp_map
from libcpp.set cimport set as cpp_set
from libcpp cimport bool as cpp_bool
from libcpp.vector cimport vector as cpp_vector
from cpython.version cimport PY_MAJOR_VERSION
# Python Imports
import collections
cimport numpy as np
import numpy as np
np.import_array()
cimport xdress_extra_types
# Cython Imports For Types
# Imports For Types
if PY_MAJOR_VERSION >= 3:
basestring = str
# Dirty ifdef, else, else preprocessor hack
# see http://comments.gmane.org/gmane.comp.python.cython.user/4080
cdef extern from *:
cdef void emit_ifpy2k "#if PY_MAJOR_VERSION == 2 //" ()
cdef void emit_ifpy3k "#if PY_MAJOR_VERSION == 3 //" ()
cdef void emit_else "#else //" ()
cdef void emit_endif "#endif //" ()

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +0,0 @@
"""Tests the part of dtypes that is accessible from Python."""
###################
### WARNING!!! ###
###################
# This file has been autogenerated
from __future__ import print_function
import nose
from nose.tools import assert_equal, assert_not_equal, assert_raises, raises, \
assert_almost_equal, assert_true, assert_false, assert_in
from numpy.testing import assert_array_equal, assert_array_almost_equal
import os
import numpy as np
from _yap import dtypes
if __name__ == '__main__':
nose.run()

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +0,0 @@
"""Tests the part of stlconverters that is accessible from Python."""
###################
### WARNING!!! ###
###################
# This file has been autogenerated
from __future__ import print_function
from unittest import TestCase
import nose
from nose.tools import assert_equal, assert_not_equal, assert_raises, raises, \
assert_almost_equal, assert_true, assert_false, assert_in
from numpy.testing import assert_array_equal, assert_array_almost_equal
import os
import numpy as np
from collections import Container, Mapping
from _yap import stlcontainers
if __name__ == '__main__':
nose.run()

File diff suppressed because it is too large Load Diff

View File

@ -1,62 +0,0 @@
/// \file extra_types.h
/// \author Anthony Scopatz (scopatz\@gmail.com)
///
/// Provides some extra types that may be generally useful
#if !defined(_XDRESS_EXTRA_TYPES_)
#define _XDRESS_EXTRA_TYPES_
#if defined(__cplusplus)
namespace xdress_extra_types
{
/// complex type struct, matching PyTables definition
// typedef struct {
// double re; ///< real part
// double im; ///< imaginary part
// } complex_t;
/// Chivalrously handles C++ memory issues that Cython does
/// not yet have a syntax for. This is a template class,
/// rather than three template functions, because Cython does
/// not yet support template function wrapping.
template <class T>
class MemoryKnight
{
public:
MemoryKnight(){}; ///< Default constructor
~MemoryKnight(){}; ///< Default Destructor
/// Creates a new instance of type T on the heap using
/// its default constructor.
/// \return T *
T * defnew(){return new T();};
/// Creates a new instance of type T, using T's default
/// constructor, at a given location.
/// \param void * ptr, location to create T instance
/// \return value of ptr recast as T *
T * renew(void * ptr){return new (ptr) T();};
/// Deallocates a location in memory using delete.
/// \param T * ptr, location to remove
void deall(T * ptr){delete ptr;};
};
// End namespace xdress_extra_types
};
#elif defined(__STDC__)
// de nada
#endif
/// complex type struct, matching PyTables definition
typedef struct {
double re; ///< real part
double im; ///< imaginary part
} xd_complex_t;
#endif

View File

@ -1,45 +0,0 @@
"""C++ wrapper for extra types header."""
from libc.stdio cimport FILE
# Dirty ifdef, else, else preprocessor hack
# see http://comments.gmane.org/gmane.comp.python.cython.user/4080
cdef extern from *:
cdef void emit_ifc "#if defined(__STDC__) //" ()
cdef void emit_ifcpp "#if defined(__cplusplus) //" ()
cdef void emit_elifc "#elif defined(__STDC__) //" ()
cdef void emit_elifcpp "#elif defined(__cplusplus) //" ()
cdef void emit_else "#else //" ()
cdef void emit_endif "#endif //" ()
ctypedef unsigned char uchar
ctypedef long long int64
ctypedef unsigned short uint16
ctypedef unsigned int uint32
ctypedef unsigned long long uint64
ctypedef long double float128
cdef extern from "xdress_extra_types.h":
ctypedef struct complex_t "xd_complex_t":
double re
double im
cdef complex_t py2c_complex(object pyv)
cdef extern from "Python.h":
object PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE*))
FILE* PyFile_AsFile(object p)
#emit_ifcpp()
#cdef extern from "<exception>" namespace "std":
# cdef cppclass exception:
# exception()
# exception(const exception&)
# exception& operator= (const exception&)
# ~exception()
# const char * what()
#emit_endif()

View File

@ -1,12 +0,0 @@
#
# This file has been autogenerated by xdress
#
cdef complex_t py2c_complex(object pyv):
cdef complex_t cv = complex_t(0, 0)
pyv = complex(pyv)
cv.re = pyv.real
cv.im = pyv.imag
return cv

View File

@ -58,13 +58,13 @@ class YAPAtom {
YAPAtom( Atom at ) { a = at; } YAPAtom( Atom at ) { a = at; }
public: public:
/// construct new YAPAtom from UTF-8 string /// construct new YAPAtom from UTF-8 string
YAPAtom( const char * s) { a = Yap_LookupAtom( s ); } YAPAtom( const char * s) { a = Yap_LookupAtom( s ); }
/// construct new YAPAtom from UTF-8 string /// construct new YAPAtom from UTF-8 string
YAPAtom( const wchar_t * s) { CACHE_REGS a = UTF32ToAtom( s PASS_REGS ); } YAPAtom( const wchar_t * s) { CACHE_REGS a = UTF32ToAtom( s PASS_REGS ); }
/// construct new YAPAtom from wide string /// construct new YAPAtom from wide string
//YAPAtom( const wchar_t * s) { a = Yap_LookupMaybeWideAtom( s ); } //YAPAtom( const wchar_t * s) { a = Yap_LookupMaybeWideAtom( s ); }
/// construct new YAPAtom from max-length string /// construct new YAPAtom from max-length string
YAPAtom( const char * s, size_t len) { a = Yap_LookupAtomWithLength( s, len ); } YAPAtom( const char * s, size_t len) { a = Yap_LookupAtomWithLength( s, len ); }
/// get name of atom /// get name of atom
const char *getName(void); const char *getName(void);
/// get name of (other way) /// get name of (other way)
@ -89,10 +89,11 @@ class YAPProp {
PropTag tag( Prop p ) { return (PropTag)(p->KindOfPE); } PropTag tag( Prop p ) { return (PropTag)(p->KindOfPE); }
public: public:
/// get name of property /// get name of property
virtual YAPAtom name() = 0; // virtual YAPAtom name();
virtual ~YAPProp() {}; virtual ~YAPProp() {};
}; };
#endif /* YAPA_HH */ #endif /* YAPA_HH */

View File

@ -34,14 +34,14 @@ class YAPModule;
*/ */
class YAPModule : protected YAPAtomTerm { class YAPModule : protected YAPAtomTerm {
friend class YAPPredicate; friend class YAPPredicate;
friend class YAPModuleProp;
YAPModule(Term t) : YAPAtomTerm(t){}; YAPModule(Term t) : YAPAtomTerm(t){};
Term t() { return gt(); } Term t() { return gt(); }
Term curModule() { CACHE_REGS return Yap_CurrentModule(); } Term curModule() { CACHE_REGS return Yap_CurrentModule(); }
public: public:
~YAPModule(){}; YAPModule() : YAPAtomTerm(curModule()){};
YAPModule() : YAPAtomTerm(curModule()){}; YAPModule(YAPAtom t) : YAPAtomTerm(t){};
YAPModule(YAPAtom t) : YAPAtomTerm(t){};
}; };
/** /**
@ -54,12 +54,12 @@ class YAPModuleProp : public YAPProp {
ModEntry *m; ModEntry *m;
YAPModuleProp(ModEntry *mod) { m = mod; }; YAPModuleProp(ModEntry *mod) { m = mod; };
YAPModuleProp(Term tmod) { m = Yap_GetModuleEntry(tmod); }; YAPModuleProp(Term tmod) { m = Yap_GetModuleEntry(tmod); };
public: public:
YAPModuleProp() { CACHE_REGS m = Yap_GetModuleEntry(Yap_CurrentModule()); }; YAPModuleProp(YAPModule tmod) { m = Yap_GetModuleEntry(tmod.gt()); };
YAPModuleProp(YAPModule tmod); YAPModuleProp() { CACHE_REGS m = Yap_GetModuleEntry(Yap_CurrentModule()); };
virtual YAPModule module() { return YAPModule(m->AtomOfME); }; virtual YAPModule module() { return YAPModule(m->AtomOfME); };
}; };
/** /**
@ -80,14 +80,14 @@ public:
/// Constructor: receives name as an atom, plus arity /// Constructor: receives name as an atom, plus arity
/// ///
/// This is the default method, and the most popular /// This is the default method, and the most popular
YAPFunctor(YAPAtom at, uintptr_t arity) { f = Yap_MkFunctor(at.a, arity); } YAPFunctor(YAPAtom at, uintptr_t arity) { f = Yap_MkFunctor(at.a, arity); }
/// Constructor: receives name as a string plus arity /// Constructor: receives name as a string plus arity
/// ///
/// Notice that this is designed for ISO-LATIN-1 right now /// Notice that this is designed for ISO-LATIN-1 right now
/// Note: Python confuses the 3 constructors, /// Note: Python confuses the 3 constructors,
/// use YAPFunctorFromString /// use YAPFunctorFromString
inline YAPFunctor(const char *s, uintptr_t arity, bool isutf8 = true) { inline YAPFunctor(const char *s, uintptr_t arity, bool isutf8 = true) {
f = Yap_MkFunctor(Yap_LookupAtom(s), arity); f = Yap_MkFunctor(Yap_LookupAtom(s), arity);
} }
/// Constructor: receives name as a wide string plus arity /// Constructor: receives name as a wide string plus arity
@ -96,19 +96,18 @@ public:
/// ///
/// Note: Python confuses the 3 constructors, /// Note: Python confuses the 3 constructors,
/// use YAPFunctorFromWideString /// use YAPFunctorFromWideString
inline YAPFunctor(const wchar_t *s, uintptr_t arity) { inline YAPFunctor(const wchar_t *s, uintptr_t arity) {
CACHE_REGS f = Yap_MkFunctor(UTF32ToAtom(s PASS_REGS), arity); CACHE_REGS f = Yap_MkFunctor(UTF32ToAtom(s PASS_REGS), arity);
} }
~YAPFunctor(){};
/// Getter: extract name of functor as an atom /// Getter: extract name of functor as an atom
/// ///
/// this is for external usage. /// this is for external usage.
YAPAtom name(void) { return YAPAtom(NameOfFunctor(f)); } YAPAtom name(void) { return YAPAtom(NameOfFunctor(f)); }
/// Getter: extract arity of functor as an unsigned integer /// Getter: extract arity of functor as an unsigned integer
/// ///
/// this is for external usage. /// this is for external usage.
uintptr_t arity(void) { return ArityOfFunctor(f); } uintptr_t arity(void) { return ArityOfFunctor(f); }
}; };
/** /**
@ -133,12 +132,14 @@ protected:
/// It also communicates the array of arguments t[] /// It also communicates the array of arguments t[]
/// and the array of variables /// and the array of variables
/// back to yapquery /// back to yapquery
YAPPredicate(const char *s0, Term &out, Term &names) { YAPPredicate(const char *s0, Term &out, Term &names) {
CACHE_REGS CACHE_REGS
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
Term *modp = NULL; Term *modp = NULL;
names = MkVarTerm ();
out = Yap_StringToTerm(s0, strlen(s0) + 1, &LOCAL_encoding, 1200, names); const unsigned char *us = (const unsigned char *)s0;
out =
Yap_BufferToTermWithPrioBindings(us, strlen(s0), TermNil, 1200, names);
// extern char *s0; // extern char *s0;
// fprintf(stderr,"ap=%p arity=%d text=%s", ap, ap->ArityOfPE, s); // fprintf(stderr,"ap=%p arity=%d text=%s", ap, ap->ArityOfPE, s);
// Yap_DebugPlWrite(out); // Yap_DebugPlWrite(out);
@ -153,7 +154,7 @@ protected:
/// Term constructor for predicates /// Term constructor for predicates
/// ///
/// It is just a call to getPred /// It is just a call to getPred
inline YAPPredicate(Term t) { inline YAPPredicate(Term t) {
CELL *v = NULL; CELL *v = NULL;
ap = getPred(t, v); ap = getPred(t, v);
} }
@ -173,35 +174,34 @@ protected:
inline YAPPredicate(PredEntry *pe) { ap = pe; } inline YAPPredicate(PredEntry *pe) { ap = pe; }
public: public:
~YAPPredicate(){};
/// Functor constructor for predicates /// Functor constructor for predicates
/// ///
/// Asssumes that we use the current module. /// Asssumes that we use the current module.
YAPPredicate(YAPFunctor f) { YAPPredicate(YAPFunctor f) {
CACHE_REGS CACHE_REGS
ap = RepPredProp(PredPropByFunc(f.f, Yap_CurrentModule())); ap = RepPredProp(PredPropByFunc(f.f, Yap_CurrentModule()));
} }
/// Functor constructor for predicates, is given a specific module. /// Functor constructor for predicates, is given a specific module.
/// ///
inline YAPPredicate(YAPFunctor f, YAPTerm mod) { inline YAPPredicate(YAPFunctor f, YAPTerm mod) {
ap = RepPredProp(PredPropByFunc(f.f, mod.t)); ap = RepPredProp(PredPropByFunc(f.f, mod.t));
} }
/// Name/arity constructor for predicates. /// Name/arity constructor for predicates.
/// ///
inline YAPPredicate(YAPAtom at, YAPTerm mod) { inline YAPPredicate(YAPAtom at, YAPTerm mod) {
ap = RepPredProp(PredPropByAtom(at.a, mod.t)); ap = RepPredProp(PredPropByAtom(at.a, mod.t));
} }
/// Name/0 constructor for predicates. /// Name/0 constructor for predicates.
/// ///
YAPPredicate(YAPAtom at); YAPPredicate(YAPAtom at);
/// Mod:Name/Arity constructor for predicates. /// Mod:Name/Arity constructor for predicates.
/// ///
inline YAPPredicate(YAPAtom at, uintptr_t arity, YAPModule mod) { inline YAPPredicate(YAPAtom at, uintptr_t arity, YAPModule mod) {
if (arity) { if (arity) {
Functor f = Yap_MkFunctor(at.a, arity); Functor f = Yap_MkFunctor(at.a, arity);
ap = RepPredProp(PredPropByFunc(f, mod.t())); ap = RepPredProp(PredPropByFunc(f, mod.t()));
@ -212,30 +212,32 @@ public:
/// Atom/Arity constructor for predicates. /// Atom/Arity constructor for predicates.
/// ///
YAPPredicate(YAPAtom at, uintptr_t arity); YAPPredicate(YAPAtom at, uintptr_t arity);
/// char */module constructor for predicates. /// char */module constructor for predicates.
/// ///
inline YAPPredicate(const char *at, uintptr_t arity) { inline YAPPredicate(const char *at, uintptr_t arity) {
ap = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_LookupAtom(at), arity), CurrentModule)); ap = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_LookupAtom(at), arity),
CurrentModule));
}; };
/// char */module constructor for predicates. /// char */module constructor for predicates.
/// ///
inline YAPPredicate(const char *at, uintptr_t arity, YAPTerm mod) { inline YAPPredicate(const char *at, uintptr_t arity, YAPTerm mod) {
ap = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_LookupAtom(at), arity), mod.t)); ap = RepPredProp(
PredPropByFunc(Yap_MkFunctor(Yap_LookupAtom(at), arity), mod.t));
}; };
/// char */module constructor for predicates. /// char */module constructor for predicates.
/// ///
inline YAPPredicate(const char *at, YAPTerm mod) { inline YAPPredicate(const char *at, YAPTerm mod) {
ap = RepPredProp(PredPropByAtom(Yap_LookupAtom(at), mod.t)); ap = RepPredProp(PredPropByAtom(Yap_LookupAtom(at), mod.t));
} }
/// module of a predicate /// module of a predicate
/// ///
/// notice that modules are currently treated as atoms, this should change. /// notice that modules are currently treated as atoms, this should change.
YAPModule module() { YAPModule module() {
if (ap->ModuleOfPred == PROLOG_MODULE) if (ap->ModuleOfPred == PROLOG_MODULE)
return YAPModule(AtomProlog); return YAPModule(AtomProlog);
else else
@ -252,6 +254,15 @@ public:
return YAPAtom(NameOfFunctor(ap->FunctorOfPred)); return YAPAtom(NameOfFunctor(ap->FunctorOfPred));
} }
/// functor of predicate
///
/// onlu defined if arity >= 1
YAPFunctor functor() {
if (ap->ArityOfPE)
return YAPFunctor(ap->FunctorOfPred);
return NULL;
}
/// arity of predicate /// arity of predicate
/// ///
/// we return a positive number. /// we return a positive number.
@ -266,15 +277,15 @@ public:
*/ */
class YAPPrologPredicate : public YAPPredicate { class YAPPrologPredicate : public YAPPredicate {
public: public:
YAPPrologPredicate(YAPTerm t) : YAPPredicate(t) {}; YAPPrologPredicate(YAPTerm t) : YAPPredicate(t){};
YAPPrologPredicate(const char *s, arity_t arity): YAPPredicate(s, arity) {}; YAPPrologPredicate(const char *s, arity_t arity) : YAPPredicate(s, arity){};
/// add a new clause /// add a new clause
void *assertClause(YAPTerm clause, bool last = true, bool assertClause(YAPTerm clause, bool last = true,
YAPTerm source = YAPTerm()); YAPTerm source = YAPTerm());
/// add a new tuple /// add a new tuple
void *assertFact(YAPTerm *tuple, bool last = true); bool assertFact(YAPTerm *tuple, bool last = true);
/// retract at least the first clause matching the predicate. /// retract at least the first clause matching the predicate.
void *retractClause(YAPTerm skeleton, bool all = false); void *retractClause(YAPTerm skeleton, bool all = false);
/// return the Nth clause (if source is available) /// return the Nth clause (if source is available)
// YAPTerm clause(size_t index, YAPPredicate p) { return YAPTerm(); }; // YAPTerm clause(size_t index, YAPPredicate p) { return YAPTerm(); };
/// return the Nth clause (if source is available) /// return the Nth clause (if source is available)
@ -303,7 +314,7 @@ public:
} }
} }
}; };
YAPFLIP(const char *name, uintptr_t arity, YAPModule module = YAPModule(), YAPFLIP(const char *name, uintptr_t arity, YAPModule module = YAPModule(),
bool backtrackable = false) bool backtrackable = false)
: YAPPredicate(YAPAtom(name), arity, module) { : YAPPredicate(YAPAtom(name), arity, module) {
if (backtrackable) { if (backtrackable) {
@ -312,8 +323,8 @@ public:
YAP_UserCPredicate(name, 0, arity); YAP_UserCPredicate(name, 0, arity);
} }
}; };
bool addCall(CPredicate call) { return Yap_AddCallToFli(ap, call); } bool addCall(CPredicate call) { return Yap_AddCallToFli(ap, call); }
bool addRetry(CPredicate call) { return Yap_AddRetryToFli(ap, call); } bool addRetry(CPredicate call) { return Yap_AddRetryToFli(ap, call); }
bool addCut(CPredicate call) { return Yap_AddCutToFli(ap, call); } bool addCut(CPredicate call) { return Yap_AddCutToFli(ap, call); }
}; };

File diff suppressed because it is too large Load Diff

View File

@ -5,8 +5,10 @@
#include <gmpxx.h> #include <gmpxx.h>
#include <vector> #include <vector>
#include <string>
#include <iostream>
//! @{ //! @{
/** /**
* *
* @defgroup yap-cplus-interface An object oriented interface for YAP. * @defgroup yap-cplus-interface An object oriented interface for YAP.
@ -67,38 +69,6 @@ extern "C" {
// taken from yap_structs.h // taken from yap_structs.h
#include "iopreds.h" #include "iopreds.h"
#ifdef SWIGPYTHON
extern PyObject *yap_to_pythond(YAP_Term t, bool eval);
extern PyObject *term_to_python(yhandle_t t, bool eval);
extern PyObject *deref_term_to_python(yhandle_t t);
X_API bool init_python(void);
extern Term pythonToYAP(PyObject *p);
extern PyObject *py_Main;
extern inline PyObject *AtomToPy(const char *s) {
if (strcmp(s, "true") == 0)
return Py_True;
if (strcmp(s, "false") == 0)
return Py_False;
if (strcmp(s, "none") == 0)
return Py_None;
if (strcmp(s, "[]") == 0)
return PyList_New(0);
else if (strcmp(s, "{}") == 0)
return PyDict_New();
/* return __main__,s */
else if (PyObject_HasAttrString(py_Main, s)) {
return PyObject_GetAttrString(py_Main, s);
}
// no way to translate
return NULL;
}
X_API extern PyObject *yap_to_python(YAP_Term t, bool eval);
#endif
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, YAP_Arity arity); X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, YAP_Arity arity);
/* void UserCPredicateWithArgs(const char *name, int *fn(), unsigned int arity) /* void UserCPredicateWithArgs(const char *name, int *fn(), unsigned int arity)

View File

@ -7,12 +7,17 @@ class YAPTerm;
/// take information on a Prolog error: /// take information on a Prolog error:
class YAPError { class YAPError {
std::string name, errorClass, info; yap_error_number ID;
std::string goal, info;
int swigcode; int swigcode;
public: public:
/// error handling when receiving the error term YAPError(){
YAPError(){}; //ID = LOCAL_ActiveError->errorNo;
}
/// error handler object with initial data when receiving the error term
YAPError(yap_error_number id, YAPTerm culprit, std::string txt);
/// we just know the error number /// we just know the error number
/// exact error ID /// exact error ID
yap_error_number getID() { return LOCAL_ActiveError->errorNo; }; yap_error_number getID() { return LOCAL_ActiveError->errorNo; };
@ -27,7 +32,7 @@ public:
/// the term that caused the bug /// the term that caused the bug
// YAPTerm getCulprit(LOCAL_ActiveError->errorFile){}; // YAPTerm getCulprit(LOCAL_ActiveError->errorFile){};
/// text describing the Error /// text describing the Error
const char *text(); std::string text();
}; };
#endif #endif

View File

@ -13,19 +13,19 @@ class YAPPredicate;
* interface to a YAP Query; * interface to a YAP Query;
* uses an SWI-like status info internally. * uses an SWI-like status info internally.
*/ */
class YAPQuery : public YAPPredicate { class YAPQuery : public YAPPredicate
{
bool q_open; bool q_open;
int q_state; int q_state;
yhandle_t q_g, q_handles; yhandle_t q_g, q_handles;
struct yami *q_p, *q_cp; struct yami *q_p, *q_cp;
jmp_buf q_env; sigjmp_buf q_env;
int q_flags; int q_flags;
YAP_dogoalinfo q_h; YAP_dogoalinfo q_h;
YAPQuery *oq; YAPQuery *oq;
YAPListTerm vnames; Term names;
YAPTerm goal; Term goal;
// temporaries // temporaries
Term tgoal, names;
void openQuery(); void openQuery();
@ -46,20 +46,19 @@ public:
/// ///
/// It is given a functor, and an array of terms that must have at least /// It is given a functor, and an array of terms that must have at least
/// the same arity as the functor. Works within the current module. /// the same arity as the functor. Works within the current module.
YAPQuery(YAPFunctor f, YAPTerm t[]); //YAPQuery(YAPFunctor f, YAPTerm t[]);
/// string constructor without varnames /// string constructor without varnames
/// ///
/// It is given a string, calls the parser and obtains a Prolog term that /// It is given a string, calls the parser and obtains a Prolog term that
/// should be a callable /// should be a callable
/// goal. /// goal.
inline YAPQuery(const char *s) : YAPPredicate(s, tgoal, names) { inline YAPQuery(const char *s) : YAPPredicate(s, goal, names)
{
BACKUP_H(); BACKUP_H();
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %ld", __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %ld",
LOCAL_CurSlot); LOCAL_CurSlot);
if (!ap) if (!ap)
return; return;
goal = YAPTerm(tgoal);
vnames = YAPListTerm(names);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", vnames.text()); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", vnames.text());
openQuery(); openQuery();
RECOVER_H(); RECOVER_H();
@ -68,9 +67,10 @@ public:
/// ///
/// It is given an atom, and a Prolog term that should be a callable /// It is given an atom, and a Prolog term that should be a callable
/// goal, say `main`, `init`, `live`. /// goal, say `main`, `init`, `live`.
inline YAPQuery(YAPAtom g) : YAPPredicate(g) { inline YAPQuery(YAPAtom g) : YAPPredicate(g)
goal = YAPAtomTerm(g); {
vnames = YAPListTerm(); goal = YAPAtomTerm(g).gt();
names = TermNil;
openQuery(); openQuery();
}; };
@ -92,19 +92,20 @@ public:
const char *text(); const char *text();
/// remove alternatives in the current search space, and finish the current /// remove alternatives in the current search space, and finish the current
/// query /// query
void cut();
/// finish the current query: undo all bindings. /// finish the current query: undo all bindings.
void close(); void close();
/// query variables. /// query variables.
YAPListTerm namedVars(); void cut();
Term namedVars();
/// query variables, but copied out /// query variables, but copied out
YAPListTerm namedVarsCopy(); Term namedVarsCopy();
/// convert a ref to a binding. /// convert a ref to a binding.
YAPTerm getTerm(yhandle_t t); YAPTerm getTerm(yhandle_t t);
/// simple YAP Query; /// simple YAP Query;
/// just calls YAP and reports success or failure, Useful when we just /// just calls YAP and reports success or failure, Useful when we just
/// want things done, eg YAPCommand("load_files(library(lists), )") /// want things done, eg YAPCommand("load_files(library(lists), )")
inline bool command() { inline bool command()
{
bool rc = next(); bool rc = next();
close(); close();
return rc; return rc;
@ -116,7 +117,8 @@ public:
/// This class implements a callback Prolog-side. It will be inherited by the /// This class implements a callback Prolog-side. It will be inherited by the
/// Java or Python /// Java or Python
/// class that actually implements the callback. /// class that actually implements the callback.
class YAPCallback { class YAPCallback
{
public: public:
virtual ~YAPCallback() {} virtual ~YAPCallback() {}
virtual void run() { LOG("callback"); } virtual void run() { LOG("callback"); }
@ -129,7 +131,8 @@ public:
* *
* *
*/ */
class YAPEngine { class YAPEngine
{
private: private:
YAPCallback *_callback; YAPCallback *_callback;
YAP_init_args init_args; YAP_init_args init_args;
@ -156,14 +159,16 @@ public:
/// remove current callback /// remove current callback
void delYAPCallback() { _callback = 0; } void delYAPCallback() { _callback = 0; }
/// set a new callback /// set a new callback
void setYAPCallback(YAPCallback *cb) { void setYAPCallback(YAPCallback *cb)
{
delYAPCallback(); delYAPCallback();
_callback = cb; _callback = cb;
} }
/// execute the callback. /// execute the callback.
////void run() { if (_callback) _callback->run(); } ////void run() { if (_callback) _callback->run(); }
/// execute the callback with a text argument. /// execute the callback with a text argument.
void run(char *s) { void run(char *s)
{
if (_callback) if (_callback)
_callback->run(s); _callback->run(s);
} }
@ -181,22 +186,30 @@ public:
/// current directory for the engine /// current directory for the engine
bool call(YAPPredicate ap, YAPTerm ts[]); bool call(YAPPredicate ap, YAPTerm ts[]);
/// current directory for the engine /// current directory for the engine
bool goalt(YAPTerm t); bool goalt(YAPTerm Yt) { return Yt.term(); };
/// current directory for the engine /// current directory for the engine
bool goal(Term t); bool mgoal(Term t, Term tmod);
/// current directory for the engine
bool goal(Term t)
{
return mgoal(t, CurrentModule);
}
/// reset Prolog state /// reset Prolog state
void reSet(); void reSet();
/// release: assune that there are no stack pointers, just release memory /// release: assune that there are no stack pointers, just release memory
// for last execution // for last execution
void release(); void release();
const char *currentDir() { const char *currentDir()
{
char dir[1024]; char dir[1024];
std::string s = Yap_getcwd(dir, 1024 - 1); std::string s = Yap_getcwd(dir, 1024 - 1);
return s.c_str(); return s.c_str();
}; };
/// report YAP version as a string /// report YAP version as a string
const char *version() { const char *version()
{
std::string s = Yap_version(); std::string s = Yap_version();
return s.c_str(); return s.c_str();
}; };

View File

@ -2,9 +2,12 @@
#ifndef YAPT_HH #ifndef YAPT_HH
#define YAPT_HH 1 #define YAPT_HH 1
extern "C" Term YAP_ReadBuffer(const char *s, Term *tp); extern "C" {
Term YAP_ReadBuffer(const char *s, Term *tp);
}
class YAPError; class YAPError;
/** /**
* @brief Generic Prolog Term * @brief Generic Prolog Term
*/ */
@ -18,20 +21,32 @@ class YAPTerm {
friend class YAPListTerm; friend class YAPListTerm;
protected: protected:
yhandle_t t; /// handle to term, equivalent to term_t yhandle_t t; /// handle to term, equivalent to term_t
void mk(Term t0); /// internal method to convert from term to handle
Term gt(); /// get handle and obtain term
public: public:
virtual ~YAPTerm(){ LOCAL_HandleBase[t] = TermFreeTerm; Term gt() {
while ( LOCAL_HandleBase[LOCAL_CurSlot-1] == TermFreeTerm) CACHE_REGS
LOCAL_CurSlot--; // fprintf(stderr,"?%d,%lx,%p\n",t,LOCAL_HandleBase[t], HR);
} // Yap_DebugPlWriteln(LOCAL_HandleBase[t]);
YAPTerm(Term tn) { return Yap_GetFromSlot(t);
mk(tn); };
} /// private method to convert from Term (internal YAP representation) to
void mk(Term t0) {
CACHE_REGS t = Yap_InitSlot(t0);
// fprintf(stderr,"+%d,%lx,%p,%p",t,t0,HR,ASP); Yap_DebugPlWriteln(t0);
};
YAPTerm(Term tn) { mk(tn); };
#ifdef SWIGPYTHON
// YAPTerm(struct _object *inp) {
// Term tinp = pythonToYAP(inp);
// t = Yap_InitSlot(tinp);
//}
#endif
/// private method to convert from Term (internal YAP representation) to
/// YAPTerm /// YAPTerm
// do nothing constructor // do nothing constructor
YAPTerm() { mk(MkVarTerm()); } YAPTerm() { mk(MkVarTerm()); };
// YAPTerm(yhandle_t i) { t = i; }; // YAPTerm(yhandle_t i) { t = i; };
/// pointer to term /// pointer to term
YAPTerm(void *ptr); YAPTerm(void *ptr);
@ -40,6 +55,21 @@ public:
Term tp; Term tp;
mk(YAP_ReadBuffer(s, &tp)); mk(YAP_ReadBuffer(s, &tp));
} }
#if 1
/// Term destructor, tries to recover slot
virtual ~YAPTerm() {
// fprintf(stderr,"-%d,%lx,%p ",t,LOCAL_HandleBase[t] ,HR);
if (!t)
return;
Yap_DebugPlWriteln(LOCAL_HandleBase[t]);
LOCAL_HandleBase[t] = TermFreeTerm;
while (LOCAL_HandleBase[LOCAL_CurSlot - 1] == TermFreeTerm) {
LOCAL_CurSlot--;
}
};
#endif
/// construct a term out of an integer (if you know object type use /// construct a term out of an integer (if you know object type use
/// YAPIntegerTerm) /// YAPIntegerTerm)
/// YAPTerm(long int num) { mk(MkIntegerTerm(num)); } /// YAPTerm(long int num) { mk(MkIntegerTerm(num)); }
@ -51,23 +81,64 @@ public:
/// extract the tag of a term, after dereferencing. /// extract the tag of a term, after dereferencing.
YAP_tag_t tag(); YAP_tag_t tag();
/// copy the term ( term copy ) /// copy the term ( term copy )
YAPTerm deepCopy(); Term deepCopy();
/// numbervars ( int start, bool process=false ) /// numbervars ( int start, bool process=false )
intptr_t numberVars(intptr_t start, bool skip_singletons = false); intptr_t numberVars(intptr_t start, bool skip_singletons = false);
inline Term term() { inline Term term() {
return gt(); return gt();
} /// from YAPTerm to Term (internal YAP representation) } /// from YAPTerm to Term (internal YAP representation)
inline void bind(Term b) { LOCAL_HandleBase[t] = b; }
inline void bind(YAPTerm *b) { LOCAL_HandleBase[t] = b->term(); }
/// from YAPTerm to Term (internal YAP representation)
/// fetch a sub-term /// fetch a sub-term
YAPTerm &operator[](size_t n); Term &operator[](arity_t n);
// const YAPTerm *vars(); // const YAPTerm *vars();
/// this term is == to t1 /// this term is == to t1
virtual bool exactlyEqual(YAPTerm t1); virtual bool exactlyEqual(YAPTerm t1) {
virtual bool unify(YAPTerm t1); /// t = t1 bool out;
virtual bool unifiable(YAPTerm t1); /// we can unify t and t1 BACKUP_MACHINE_REGS();
virtual bool variant( out = Yap_eq(gt(), t1.term());
YAPTerm t1); /// t =@= t1, the two terms are equal up to variable renaming RECOVER_MACHINE_REGS();
virtual intptr_t hashTerm(size_t sz, size_t depth, return out;
bool variant); /// term hash, };
/// t = t1
virtual bool unify(YAPTerm t1) {
intptr_t out;
BACKUP_MACHINE_REGS();
out = Yap_unify(gt(), t1.term());
RECOVER_MACHINE_REGS();
return out;
};
/// we can unify t and t1
virtual bool unifiable(YAPTerm t1) {
bool out;
BACKUP_MACHINE_REGS();
out = Yap_eq(gt(), t1.term());
RECOVER_MACHINE_REGS();
return out;
};
/// t =@= t1, the two terms are equal up to variable renamingvirtual bool
/// variant(
inline virtual YAP_Term variant(YAPTerm t1) {
intptr_t out;
BACKUP_MACHINE_REGS();
out = Yap_Variant(gt(), t1.term());
RECOVER_MACHINE_REGS();
return out;
};
virtual intptr_t hashTerm(size_t sz, size_t depth, bool variant) {
intptr_t out;
BACKUP_MACHINE_REGS();
out = Yap_TermHash(gt(), sz, depth, variant);
RECOVER_MACHINE_REGS();
return out;
};
/// term hash,
virtual bool isVar() { return IsVarTerm(gt()); } /// type check for unound virtual bool isVar() { return IsVarTerm(gt()); } /// type check for unound
virtual bool isAtom() { return IsAtomTerm(gt()); } /// type check for atom virtual bool isAtom() { return IsAtomTerm(gt()); } /// type check for atom
virtual bool isInteger() { virtual bool isInteger() {
@ -88,19 +159,19 @@ public:
virtual bool isList() { return Yap_IsListTerm(gt()); } /// term is a list virtual bool isList() { return Yap_IsListTerm(gt()); } /// term is a list
/// extract the argument i of the term, where i in 1...arity /// extract the argument i of the term, where i in 1...arity
virtual YAPTerm getArg(arity_t i) { virtual Term getArg(arity_t i) {
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
Term tf = 0;
Term t0 = gt(); Term t0 = gt();
YAPTerm tf;
if (IsApplTerm(t0)) if (IsApplTerm(t0))
tf = YAPTerm(ArgOfTerm(i, t0)); tf = (ArgOfTerm(i, t0));
else if (IsPairTerm(t0)) { else if (IsPairTerm(t0)) {
if (i == 1) if (i == 1)
tf = YAPTerm(HeadOfTerm(t0)); tf = (HeadOfTerm(t0));
else if (i == 2) else if (i == 2)
tf = YAPTerm(TailOfTerm(t0)); tf = (TailOfTerm(t0));
} else { } else {
tf = YAPTerm((Term)0); tf = ((Term)0);
} }
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return tf; return tf;
@ -123,7 +194,24 @@ public:
} }
/// return a string with a textual representation of the term /// return a string with a textual representation of the term
virtual const char *text(); virtual const char *text() {
CACHE_REGS
size_t length = 0;
encoding_t enc = LOCAL_encoding;
char *os;
BACKUP_MACHINE_REGS();
if (!(os = Yap_TermToString(Yap_GetFromSlot(t), &length, enc,
Handle_vars_f))) {
RECOVER_MACHINE_REGS();
return 0;
}
RECOVER_MACHINE_REGS();
length = strlen(os) + 1;
char *sm = (char *)malloc(length + 1);
strcpy(sm, os);
return sm;
};
/// return a handle to the term /// return a handle to the term
inline yhandle_t handle() { return t; }; inline yhandle_t handle() { return t; };
@ -169,16 +257,21 @@ class YAPApplTerm : public YAPTerm {
YAPApplTerm(Term t0) { mk(t0); } YAPApplTerm(Term t0) { mk(t0); }
public: public:
~YAPApplTerm() {} YAPApplTerm(Functor f, Term ts[]) {
BACKUP_MACHINE_REGS();
Term t0 = Yap_MkApplTerm(f, f->ArityOfFE, ts);
mk(t0);
RECOVER_MACHINE_REGS();
};
YAPApplTerm(YAPFunctor f, YAPTerm ts[]); YAPApplTerm(YAPFunctor f, YAPTerm ts[]);
YAPApplTerm(const char *s, std::vector<YAPTerm> ts); YAPApplTerm(const std::string s, std::vector<YAPTerm> ts);
YAPApplTerm(YAPFunctor f); YAPApplTerm(YAPFunctor f);
YAPFunctor getFunctor(); YAPFunctor getFunctor();
YAPTerm getArg(arity_t i) { Term getArg(arity_t i) {
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
Term t0 = gt(); Term t0 = gt();
YAPTerm tf; Term tf;
tf = YAPTerm(ArgOfTerm(i, t0)); tf = ArgOfTerm(i, t0);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return tf; return tf;
}; };
@ -209,8 +302,8 @@ class YAPPairTerm : public YAPTerm {
public: public:
YAPPairTerm(YAPTerm hd, YAPTerm tl); YAPPairTerm(YAPTerm hd, YAPTerm tl);
YAPPairTerm(); YAPPairTerm();
YAPTerm getHead() { return YAPTerm(HeadOfTerm(gt())); } Term getHead() { return (HeadOfTerm(gt())); }
YAPTerm getTail() { return YAPTerm(TailOfTerm(gt())); } Term getTail() { return (TailOfTerm(gt())); }
}; };
/** /**
@ -234,8 +327,8 @@ public:
}; };
/** /**
* @brief Floating Point Term * @brief Floating Point Term
*/ */
class YAPFloatTerm : public YAPNumberTerm { class YAPFloatTerm : public YAPNumberTerm {
public: public:
@ -267,28 +360,27 @@ public:
return Yap_SkipList(&t1, &tailp); return Yap_SkipList(&t1, &tailp);
} }
/// Extract the nth element. /// Extract the nth element.
YAPTerm &operator[](size_t n); Term &operator[](size_t n);
/// Extract the first element of a list. /// Extract the first element of a list.
/// ///
/// @param[in] the list /// @param[in] the list
YAPTerm car(); Term car();
/// Extract the tail elements of a list. /// Extract the tail elements of a list.
/// ///
/// @param[in] the list /// @param[in] the list
YAPListTerm cdr() { Term cdr() {
Term to = gt(); Term to = gt();
if (IsPairTerm(to)) if (IsPairTerm(to))
return YAPListTerm(TailOfTerm(to)); return (TailOfTerm(to));
else if (to == TermNil) else if (to == TermNil)
return YAPListTerm(); return TermNil;
/* error */ /* error */
Yap_Error(TYPE_ERROR_LIST, t, 0); throw YAPError(TYPE_ERROR_LIST, YAPTerm(to), "");
throw YAPError();
} }
/// copy a list. /// copy a list.
/// ///
/// @param[in] the list /// @param[in] the list
YAPListTerm dup(); Term dup();
/// Check if the list is empty. /// Check if the list is empty.
/// ///
@ -337,15 +429,15 @@ public:
YAPAtomTerm(wchar_t *s); YAPAtomTerm(wchar_t *s);
// Constructor: receives a sequence of n wchar_ts, whatever they may be; // Constructor: receives a sequence of n wchar_ts, whatever they may be;
YAPAtomTerm(wchar_t *s, size_t len); YAPAtomTerm(wchar_t *s, size_t len);
virtual bool isVar() { return false; } /// type check for unbound bool isVar() { return false; } /// type check for unbound
virtual bool isAtom() { return true; } /// type check for atom bool isAtom() { return true; } /// type check for atom
virtual bool isInteger() { return false; } /// type check for integer bool isInteger() { return false; } /// type check for integer
virtual bool isFloat() { return false; } /// type check for floating-point bool isFloat() { return false; } /// type check for floating-point
virtual bool isString() { return false; } /// type check for a string " ... " bool isString() { return false; } /// type check for a string " ... "
virtual bool isCompound() { return false; } /// is a primitive term bool isCompound() { return false; } /// is a primitive term
virtual bool isAppl() { return false; } /// is a structured term bool isAppl() { return false; } /// is a structured term
virtual bool isPair() { return false; } /// is a pair term bool isPair() { return false; } /// is a pair term
virtual bool isGround() { return true; } /// term is ground virtual bool isGround() { return true; } /// term is ground
virtual bool isList() { return gt() == TermNil; } /// [] is a list virtual bool isList() { return gt() == TermNil; } /// [] is a list
// Getter: outputs the atom; // Getter: outputs the atom;
YAPAtom getAtom() { return YAPAtom(AtomOfTerm(gt())); } YAPAtom getAtom() { return YAPAtom(AtomOfTerm(gt())); }

View File

@ -95,7 +95,7 @@ A Csult F "$csult"
A CurrentModule F "$current_module" A CurrentModule F "$current_module"
A Cut N "!" A Cut N "!"
A CutBy F "$cut_by" A CutBy F "$cut_by"
A DAbort F "$abort" A DAbort N "abort"
A DBLoad F "$db_load" A DBLoad F "$db_load"
A DBREF N "DBRef" A DBREF N "DBRef"
A DBReference N "db_reference" A DBReference N "db_reference"
@ -294,6 +294,7 @@ A PastEndOfStream N "past_end_of_stream"
A PermissionError N "permission_error" A PermissionError N "permission_error"
A Pi N "pi" A Pi N "pi"
A Pipe N "pipe" A Pipe N "pipe"
A Priority N "priority"
A Plus N "+" A Plus N "+"
A Pointer N "pointer" A Pointer N "pointer"
A Portray F "portray" A Portray F "portray"
@ -546,11 +547,13 @@ F NBQueue Queue 4
F Not Not 1 F Not Not 1
F Obj Obj 1 F Obj Obj 1
F Or Semic 2 F Or Semic 2
F Output Output 1
F PermissionError PermissionError 3 F PermissionError PermissionError 3
F Plus Plus 2 F Plus Plus 2
F Portray Portray 1 F Portray Portray 1
F PrintMessage PrintMessage 2 F PrintMessage PrintMessage 2
F Procedure Procedure 5 F Procedure Procedure 5
F Priority Priority 1
F PrologConstraint Prolog 2 F PrologConstraint Prolog 2
F ProtectStack ProtectStack 4 F ProtectStack ProtectStack 4
F Query Query 1 F Query Query 1

View File

@ -145,7 +145,7 @@ ADDR db_vec0 =NULL
struct RB_red_blk_node* db_root =NULL struct RB_red_blk_node* db_root =NULL
struct RB_red_blk_node* db_nil =NULL struct RB_red_blk_node* db_nil =NULL
sigjmp_buf gc_restore void sigjmp_buf* gc_restore void
CELL* extra_gc_cells void CELL* extra_gc_cells void
CELL* extra_gc_cells_base void CELL* extra_gc_cells_base void
CELL* extra_gc_cells_top void CELL* extra_gc_cells_top void
@ -160,8 +160,8 @@ struct mem_blk* CMemFirstBlock =NULL
UInt CMemFirstBlockSz =0L UInt CMemFirstBlockSz =0L
// Variable used by the compiler to store number of permanent vars in a clause // Variable used by the compiler to store number of permanent vars in a clause
int nperm =0L int nperm =0
int jMP =0
// Thread Local Area for Labels // Thread Local Area for Labels
Int* LabelFirstArray =NULL Int* LabelFirstArray =NULL
UInt LabelFirstArraySz =0L UInt LabelFirstArraySz =0L
@ -198,7 +198,7 @@ ADDR TrailTop void
yap_error_descriptor_t* ActiveError =calloc(sizeof(yap_error_descriptor_t),1) yap_error_descriptor_t* ActiveError =calloc(sizeof(yap_error_descriptor_t),1)
/// pointer to an exception term, from throw /// pointer to an exception term, from throw
jmp_buf IOBotch void jmp_buf* IOBotch void
TokEntry* tokptr void TokEntry* tokptr void
TokEntry* toktide void TokEntry* toktide void
VarEntry* VarTable void VarEntry* VarTable void
@ -209,7 +209,7 @@ CELL* CommentsNextChar void
wchar_t* CommentsBuff void wchar_t* CommentsBuff void
size_t CommentsBuffPos void size_t CommentsBuffPos void
size_t CommentsBuffLim void size_t CommentsBuffLim void
sigjmp_buf RestartEnv void sigjmp_buf* RestartEnv void
char FileNameBuf[YAP_FILENAME_MAX+1] void char FileNameBuf[YAP_FILENAME_MAX+1] void
char FileNameBuf2[YAP_FILENAME_MAX+1] void char FileNameBuf2[YAP_FILENAME_MAX+1] void

View File

@ -302,6 +302,8 @@ INLINE_ONLY inline EXTERN Term __MkStringTerm(const char *s USES_REGS) {
return t; return t;
} }
#define MkUStringTerm(i) __MkUStringTerm((i)PASS_REGS)
INLINE_ONLY inline EXTERN Term INLINE_ONLY inline EXTERN Term
__MkUStringTerm(const unsigned char *s USES_REGS); __MkUStringTerm(const unsigned char *s USES_REGS);

39
H/Yap.h
View File

@ -129,37 +129,6 @@
#endif #endif
#endif /* defined(HAVE_NULLPTR) */ #endif /* defined(HAVE_NULLPTR) */
/* Microsoft's Visual C++ Compiler */
#ifdef _MSC_VER /* adjust a config.h from mingw32 to work with vc++ */
#ifdef HAVE_GCC
#undef HAVE_GCC
#endif /* HAVE_GCC */
#ifdef USE_THREADED_CODE
#undef USE_THREADED_CODE
#endif /* USE_THREADED_CODE */
#define inline __inline
#define YAP_VERSION "YAP-6.3.4"
#define BIN_DIR "c:\\Yap\\bin"
#define LIB_DIR "c:\\Yap\\lib\\Yap"
#define SHARE_DIR "c:\\Yap\\share\\Yap"
#ifdef HOST_ALIAS
#undef HOST_ALIAS
#endif /* HOST_ALIAS */
#define HOST_ALIAS "i386-pc-win32"
#ifdef HAVE_IEEEFP_H
#undef HAVE_IEEEFP_H
#endif /* HAVE_IEEEFP_H */
#ifdef HAVE_UNISTD_H
#undef HAVE_UNISTD_H
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_SYS_TIME_H
#undef HAVE_SYS_TIME_H
#endif /* HAVE_SYS_TIME_H */
#endif /* _MSC_VER */
#if HAVE_TIME_H
#include <time.h>
#endif
#ifdef __MINGW32__ #ifdef __MINGW32__
#ifndef _WIN32 #ifndef _WIN32
@ -727,10 +696,10 @@ typedef struct thandle {
struct timeval *start_of_times_sysp; struct timeval *start_of_times_sysp;
struct timeval *last_time_sysp; struct timeval *last_time_sysp;
#elif _WIN32 #elif _WIN32
struct _FILETIME *start_of_timesp; win64_time_t *start_of_timesp;
struct _FILETIME *last_timep; win64_time_t *last_timep;
struct _FILETIME *start_of_times_sysp; win64_time_t *start_of_times_sysp;
struct _FILETIME *last_time_sysp; win64_time_t *last_time_sysp;
#endif #endif
} yap_thandle; } yap_thandle;
#endif /* THREADS */ #endif /* THREADS */

View File

@ -8,7 +8,7 @@
* * * *
************************************************************************** **************************************************************************
* * * *
* File: compile.h * * File: YapCompile.h *
* Last rev: * * Last rev: *
* mods: * * mods: *
* comments: compiler data structures and routines * * comments: compiler data structures and routines *

View File

@ -1,6 +1,6 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog @(#)eval.h 1.2 * YAP Prolog @(#)YapEval.h 1.2
* * * *
* Yap Prolog was developed at NCCUP - Universidade do Porto * * Yap Prolog was developed at NCCUP - Universidade do Porto *
* * * *
@ -8,7 +8,7 @@
* * * *
************************************************************************** **************************************************************************
* * * *
* File: eval.h * * File: YapEval.h *
* Last rev: * * Last rev: *
* mods: * * mods: *
* comments: arithmetical functions info * * comments: arithmetical functions info *
@ -17,7 +17,7 @@
/** /**
@file eval.h @file YapEval.h
@defgroup arithmetic Arithmetic in YAP @defgroup arithmetic Arithmetic in YAP
@ -407,7 +407,7 @@ yamop *Yap_EvalError__(const char *, const char *, int, yap_error_number, Term,
...); ...);
#define Yap_ArithError(id, t, ...) \ #define Yap_ArithError(id, t, ...) \
Yap_ThrowError__(__FILE__, __FUNCTION__, __LINE__, id, t, 2, __VA_ARGS__) Yap_ThrowError__(__FILE__, __FUNCTION__, __LINE__, id, t, __VA_ARGS__)
#define Yap_BinError(id) \ #define Yap_BinError(id) \
Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, 0L, "") Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, 0L, "")
#define Yap_AbsmiError(id) \ #define Yap_AbsmiError(id) \

View File

@ -204,7 +204,7 @@ typedef struct x_el {
} xarg; } xarg;
typedef struct struct_param { typedef struct struct_param {
char *name; const char *name;
flag_func type; flag_func type;
int id; int id;
} param_t; } param_t;

View File

@ -154,7 +154,7 @@ typedef struct thandle {
/******************* /*******************
this is the data base: everything here should be possible to restore this is the data base: everything here should be possible to restore
********************/ ********************/
#if __INIT_C__ #if __INIT_C__ || defined(MSC_VER)
#define EXTERNAL #define EXTERNAL
#else #else
#define EXTERNAL extern #define EXTERNAL extern

View File

@ -166,13 +166,15 @@ INLINE_ONLY inline EXTERN Term *VarOfTerm(Term t) { return (Term *)(t); }
INLINE_ONLY inline EXTERN Term MkVarTerm__(USES_REGS1); INLINE_ONLY inline EXTERN Term MkVarTerm__(USES_REGS1);
INLINE_ONLY inline EXTERN Term MkVarTerm__(USES_REGS1) { INLINE_ONLY
inline EXTERN Term MkVarTerm__(USES_REGS1) {
return (Term)((*HR = 0, HR++)); return (Term)((*HR = 0, HR++));
} }
INLINE_ONLY inline EXTERN bool IsUnboundVar(Term *); INLINE_ONLY inline EXTERN bool IsUnboundVar(Term *);
INLINE_ONLY inline EXTERN bool IsUnboundVar(Term *t) { return (int)(*(t) == INLINE_ONLY
inline EXTERN bool IsUnboundVar(Term *t) { return (int)(*(t) ==
0); } 0); }
#else #else
@ -181,13 +183,15 @@ INLINE_ONLY inline EXTERN bool IsUnboundVar(Term *t) { return (int)(*(t) ==
INLINE_ONLY inline EXTERN Term MkVarTerm__(USES_REGS1); INLINE_ONLY inline EXTERN Term MkVarTerm__(USES_REGS1);
INLINE_ONLY inline EXTERN Term MkVarTerm__(USES_REGS1) { INLINE_ONLY
inline EXTERN Term MkVarTerm__(USES_REGS1) {
return (Term)((*HR = (CELL)HR, HR++)); return (Term)((*HR = (CELL)HR, HR++));
} }
INLINE_ONLY inline EXTERN bool IsUnboundVar(Term *); INLINE_ONLY inline EXTERN bool IsUnboundVar(Term *);
INLINE_ONLY inline EXTERN bool IsUnboundVar(Term *t) { INLINE_ONLY
inline EXTERN bool IsUnboundVar(Term *t) {
return *(t) == (Term)(t); return *(t) == (Term)(t);
} }
@ -195,13 +199,15 @@ INLINE_ONLY inline EXTERN bool IsUnboundVar(Term *t) {
INLINE_ONLY inline EXTERN CELL *PtrOfTerm(Term); INLINE_ONLY inline EXTERN CELL *PtrOfTerm(Term);
INLINE_ONLY inline EXTERN CELL *PtrOfTerm(Term t) { INLINE_ONLY
inline EXTERN CELL *PtrOfTerm(Term t) {
return (CELL *)(*(CELL *)(t)); return (CELL *)(*(CELL *)(t));
} }
INLINE_ONLY inline EXTERN Functor FunctorOfTerm(Term); INLINE_ONLY inline EXTERN Functor FunctorOfTerm(Term);
INLINE_ONLY inline EXTERN Functor FunctorOfTerm(Term t) { INLINE_ONLY
inline EXTERN Functor FunctorOfTerm(Term t) {
return (Functor)(*RepAppl(t)); return (Functor)(*RepAppl(t));
} }
@ -209,13 +215,15 @@ INLINE_ONLY inline EXTERN Functor FunctorOfTerm(Term t) {
INLINE_ONLY inline EXTERN Term MkAtomTerm(Atom); INLINE_ONLY inline EXTERN Term MkAtomTerm(Atom);
INLINE_ONLY inline EXTERN Term MkAtomTerm(Atom a) { INLINE_ONLY
inline EXTERN Term MkAtomTerm(Atom a) {
return (Term)(AtomTag | (CELL)(a)); return (Term)(AtomTag | (CELL)(a));
} }
INLINE_ONLY inline EXTERN Atom AtomOfTerm(Term t); INLINE_ONLY inline EXTERN Atom AtomOfTerm(Term t);
INLINE_ONLY inline EXTERN Atom AtomOfTerm(Term t) { INLINE_ONLY
inline EXTERN Atom AtomOfTerm(Term t) {
return (Atom)((~AtomTag & (CELL)(t))); return (Atom)((~AtomTag & (CELL)(t)));
} }
@ -223,13 +231,15 @@ INLINE_ONLY inline EXTERN Atom AtomOfTerm(Term t) {
INLINE_ONLY inline EXTERN Term MkAtomTerm(Atom); INLINE_ONLY inline EXTERN Term MkAtomTerm(Atom);
INLINE_ONLY inline EXTERN Term MkAtomTerm(Atom at) { INLINE_ONLY
inline EXTERN Term MkAtomTerm(Atom at) {
return (Term)(TAGGEDA((CELL)AtomTag, (CELL)(at))); return (Term)(TAGGEDA((CELL)AtomTag, (CELL)(at)));
} }
INLINE_ONLY inline EXTERN Atom AtomOfTerm(Term t); INLINE_ONLY inline EXTERN Atom AtomOfTerm(Term t);
INLINE_ONLY inline EXTERN Atom AtomOfTerm(Term t) { INLINE_ONLY
inline EXTERN Atom AtomOfTerm(Term t) {
return (Atom)(NonTagPart(t)); return (Atom)(NonTagPart(t));
} }
@ -237,13 +247,15 @@ INLINE_ONLY inline EXTERN Atom AtomOfTerm(Term t) {
INLINE_ONLY inline EXTERN bool IsAtomTerm(Term); INLINE_ONLY inline EXTERN bool IsAtomTerm(Term);
INLINE_ONLY inline EXTERN bool IsAtomTerm(Term t) { INLINE_ONLY
inline EXTERN bool IsAtomTerm(Term t) {
return CHKTAG((t), AtomTag); return CHKTAG((t), AtomTag);
} }
INLINE_ONLY inline EXTERN Term MkIntTerm(Int); INLINE_ONLY inline EXTERN Term MkIntTerm(Int);
INLINE_ONLY inline EXTERN Term MkIntTerm(Int n) { INLINE_ONLY
inline EXTERN Term MkIntTerm(Int n) {
return (Term)(TAGGED(NumberTag, (n))); return (Term)(TAGGED(NumberTag, (n)));
} }
@ -254,19 +266,22 @@ INLINE_ONLY inline EXTERN Term MkIntTerm(Int n) {
INLINE_ONLY inline EXTERN Term MkIntConstant(Int); INLINE_ONLY inline EXTERN Term MkIntConstant(Int);
INLINE_ONLY inline EXTERN Term MkIntConstant(Int n) { INLINE_ONLY
inline EXTERN Term MkIntConstant(Int n) {
return (Term)(NONTAGGED(NumberTag, (n))); return (Term)(NONTAGGED(NumberTag, (n)));
} }
INLINE_ONLY inline EXTERN bool IsIntTerm(Term); INLINE_ONLY inline EXTERN bool IsIntTerm(Term);
INLINE_ONLY inline EXTERN bool IsIntTerm(Term t) { INLINE_ONLY
inline EXTERN bool IsIntTerm(Term t) {
return CHKTAG((t), NumberTag); return CHKTAG((t), NumberTag);
} }
INLINE_ONLY EXTERN inline Term MkPairTerm__(Term head, Term tail USES_REGS); INLINE_ONLY EXTERN inline Term MkPairTerm__(Term head, Term tail USES_REGS);
INLINE_ONLY EXTERN inline Term MkPairTerm__(Term head, Term tail USES_REGS) { INLINE_ONLY
EXTERN inline Term MkPairTerm__(Term head, Term tail USES_REGS) {
CELL *p = HR; CELL *p = HR;
HR[0] = head; HR[0] = head;
@ -308,20 +323,23 @@ INLINE_ONLY EXTERN inline Term MkPairTerm__(Term head, Term tail USES_REGS) {
INLINE_ONLY inline EXTERN Term __MkIntegerTerm(Int USES_REGS); INLINE_ONLY inline EXTERN Term __MkIntegerTerm(Int USES_REGS);
INLINE_ONLY inline EXTERN Term __MkIntegerTerm(Int n USES_REGS) { INLINE_ONLY
inline EXTERN Term __MkIntegerTerm(Int n USES_REGS) {
return (Term)(IntInBnd(n) ? MkIntTerm(n) : MkLongIntTerm(n)); return (Term)(IntInBnd(n) ? MkIntTerm(n) : MkLongIntTerm(n));
} }
#endif #endif
INLINE_ONLY inline EXTERN bool IsIntegerTerm(Term); INLINE_ONLY inline EXTERN bool IsIntegerTerm(Term);
INLINE_ONLY inline EXTERN bool IsIntegerTerm(Term t) { INLINE_ONLY
inline EXTERN bool IsIntegerTerm(Term t) {
return (int)(IsIntTerm(t) || IsLongIntTerm(t)); return (int)(IsIntTerm(t) || IsLongIntTerm(t));
} }
INLINE_ONLY inline EXTERN Int IntegerOfTerm(Term); INLINE_ONLY inline EXTERN Int IntegerOfTerm(Term);
INLINE_ONLY inline EXTERN Int IntegerOfTerm(Term t) { INLINE_ONLY
inline EXTERN Int IntegerOfTerm(Term t) {
return (Int)(IsIntTerm(t) ? IntOfTerm(t) : LongIntOfTerm(t)); return (Int)(IsIntTerm(t) ? IntOfTerm(t) : LongIntOfTerm(t));
} }
@ -332,7 +350,8 @@ INLINE_ONLY inline EXTERN Int IntegerOfTerm(Term t) {
INLINE_ONLY inline EXTERN Term __MkAddressTerm(void *USES_REGS); INLINE_ONLY inline EXTERN Term __MkAddressTerm(void *USES_REGS);
INLINE_ONLY inline EXTERN Term __MkAddressTerm(void *n USES_REGS) { INLINE_ONLY
inline EXTERN Term __MkAddressTerm(void *n USES_REGS) {
return __MkIntegerTerm((Int)n PASS_REGS); return __MkIntegerTerm((Int)n PASS_REGS);
} }
@ -340,20 +359,23 @@ INLINE_ONLY inline EXTERN Term __MkAddressTerm(void *n USES_REGS) {
INLINE_ONLY inline EXTERN bool IsAddressTerm(Term); INLINE_ONLY inline EXTERN bool IsAddressTerm(Term);
INLINE_ONLY inline EXTERN bool IsAddressTerm(Term t) { INLINE_ONLY
inline EXTERN bool IsAddressTerm(Term t) {
return (bool)IsIntegerTerm(t); return (bool)IsIntegerTerm(t);
} }
INLINE_ONLY inline EXTERN void *AddressOfTerm(Term); INLINE_ONLY inline EXTERN void *AddressOfTerm(Term);
INLINE_ONLY inline EXTERN void *AddressOfTerm(Term t) { INLINE_ONLY
inline EXTERN void *AddressOfTerm(Term t) {
return (void *)(IsIntTerm(t) ? IntOfTerm(t) : LongIntOfTerm(t)); return (void *)(IsIntTerm(t) ? IntOfTerm(t) : LongIntOfTerm(t));
} }
INLINE_ONLY inline EXTERN Int IsPairTermOrNil (Term); INLINE_ONLY inline EXTERN Int IsPairTermOrNil (Term);
INLINE_ONLY inline EXTERN Int INLINE_ONLY
inline EXTERN Int
IsPairOrNilTerm (Term t) IsPairOrNilTerm (Term t)
{ {
return IsPairTerm(t) || t == TermNil; return IsPairTerm(t) || t == TermNil;

View File

@ -33,7 +33,7 @@ typedef void *Atom;
(((CELL)(X) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1)) (((CELL)(X) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1))
#ifndef EXTERN #ifndef EXTERN
#ifdef _MSC_VER #ifdef MSC_VER
#define EXTERN #define EXTERN
#else #else
#define EXTERN extern #define EXTERN extern
@ -44,51 +44,30 @@ typedef void *Atom;
** and integer types Short and UShort with half the size of a ptr */ ** and integer types Short and UShort with half the size of a ptr */
#if defined(PRIdPTR) #if defined(PRIdPTR)
#define Int_FORMAT "%" PRIdPTR
#define Int_ANYFORMAT "%" PRIuPTR
#define UInt_FORMAT "%" PRIuPTR
#define Int_F PRIdPTR
#define Int_ANYF PRIuPTR
#define UInt_F PRIuPTR
typedef intptr_t Int; typedef intptr_t Int;
typedef uintptr_t UInt; typedef uintptr_t UInt;
#elif defined(_WIN64) #elif defined(_WIN64)
typedef int64_t Int; typedef int64_t Int;
typedef uint64_t UInt; typedef uint64_t UInt;
#define Int_FORMAT "%I64d"
#define UInt_FORMAT "%I64u"
#define Int_F "I64d"
#define UInt_F "I64u"
#elif defined(_WIN32) #elif defined(_WIN32)
typedef int32_t Int; typedef int32_t Int;
typedef uint32_t UInt; typedef uint32_t UInt;
#define Int_FORMAT "%I32d"
#define UInt_FORMAT "%I32u"
#define Int_F "I32d"
#define UInt_F "I32u"
#elif SIZEOF_LONG_INT == SIZEOF_INT_P #elif SIZEOF_LONG_INT == SIZEOF_INT_P
typedef long int Int; typedef long int Int;
typedef unsigned long int UInt; typedef unsigned long int UInt;
#define Int_FORMAT "%ld"
#define UInt_FORMAT "%uld"
#define Int_F "ld"
#define UInt_F "uld"
#elif SIZEOF_INT == SIZEOF_INT_P #elif SIZEOF_INT == SIZEOF_INT_P
typedef int Int; typedef int Int;
typedef unsigned int UInt; typedef unsigned int UInt;
#define Int_FORMAT "%l"
#define UInt_FORMAT "%ul"
#define Int_F "l"
#define UInt_F "ul"
#else #else
#error Yap require integer types of the same size as a pointer #error Yap require integer types of the same size as a pointer
@ -107,6 +86,8 @@ typedef uint32_t BITS32;
#define CellSize sizeof(CELL) #define CellSize sizeof(CELL)
#define SmallSize sizeof(SMALLUNSGN) #define SmallSize sizeof(SMALLUNSGN)
#include "YapFormat.h"
/************************************************************************************************* /*************************************************************************************************
type casting macros type casting macros
*************************************************************************************************/ *************************************************************************************************/

View File

@ -31,20 +31,39 @@
#include "../utf8proc/utf8proc.h" #include "../utf8proc/utf8proc.h"
#include "Yap.h" #include "Yap.h"
#define ReleaseAndReturn(r) \
{ \
pop_text_stack(l); \
return r; \
}
#define release_cut_fail() \
{ \
pop_text_stack(l); \
cut_fail(); \
}
#define release_cut_succeed() \
{ \
pop_text_stack(l); \
cut_succeed(); \
}
/// allocate a temporary text block /// allocate a temporary text block
/// ///
extern void *Malloc(size_t sz USES_REGS); extern void *Malloc(size_t sz USES_REGS);
extern void *Realloc(void *buf, size_t sz USES_REGS); extern void *Realloc(void *buf, size_t sz USES_REGS);
extern void Free(void *buf USES_REGS); extern void Free(void *buf USES_REGS);
extern int push_text_stack( USES_REGS1 ); extern int push_text_stack(USES_REGS1);
extern int pop_text_stack( int lvl USES_REGS ); extern int pop_text_stack(int lvl USES_REGS);
extern void *protected_pop_text_stack(int lvl, void *safe, bool tmp,
size_t sz USES_REGS);
#ifndef min #ifndef min
#define min(x,y) (x<y ? x : y) #define min(x, y) (x < y ? x : y)
#endif #endif
#define MBYTE (1024*1024) #define MBYTE (1024 * 1024)
/* Character types for tokenizer and write.c */ /* Character types for tokenizer and write.c */
@ -53,6 +72,8 @@ extern int pop_text_stack( int lvl USES_REGS );
#define NUMBER_OF_CHARS 256 #define NUMBER_OF_CHARS 256
extern char *Yap_chtype; extern char *Yap_chtype;
#define Yap_strlen(s) strlen((void *)(s))
typedef enum { typedef enum {
BG = 0, /* initial state */ BG = 0, /* initial state */
UC = 1, /* Upper case */ UC = 1, /* Upper case */
@ -156,24 +177,26 @@ INLINE_ONLY EXTERN inline char_kind_t chtype(Int ch) {
#define __android_log_print(...) #define __android_log_print(...)
#endif #endif
INLINE_ONLY inline EXTERN utf8proc_ssize_t get_utf8(const utf8proc_uint8_t *ptr, size_t n, INLINE_ONLY inline EXTERN utf8proc_ssize_t get_utf8(const utf8proc_uint8_t *ptr,
size_t n,
utf8proc_int32_t *valp); utf8proc_int32_t *valp);
INLINE_ONLY inline EXTERN utf8proc_ssize_t get_utf8(const utf8proc_uint8_t *ptr, size_t n, INLINE_ONLY inline EXTERN utf8proc_ssize_t get_utf8(const utf8proc_uint8_t *ptr,
utf8proc_int32_t *valp) { size_t n,
utf8proc_int32_t *valp) {
return utf8proc_iterate(ptr, n, valp); return utf8proc_iterate(ptr, n, valp);
} }
INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr, INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr,
utf8proc_int32_t val); utf8proc_int32_t val);
INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr, INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr,
utf8proc_int32_t val) { utf8proc_int32_t val) {
return utf8proc_encode_char(val, ptr); return utf8proc_encode_char(val, ptr);
} }
inline static const utf8proc_uint8_t *skip_utf8(const utf8proc_uint8_t *pt, inline static const utf8proc_uint8_t *skip_utf8(const utf8proc_uint8_t *pt,
utf8proc_ssize_t n) { utf8proc_ssize_t n) {
utf8proc_ssize_t i; utf8proc_ssize_t i;
utf8proc_int32_t b; utf8proc_int32_t b;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
@ -198,7 +221,7 @@ inline static utf8proc_ssize_t strlen_utf8(const utf8proc_uint8_t *pt) {
return rc; return rc;
else if (b > 0) { else if (b > 0) {
pt += l; pt += l;
rc ++; rc++;
} else { } else {
pt++; pt++;
} }
@ -294,8 +317,8 @@ inline static int cmpn_utf8(const utf8proc_uint8_t *pt1,
#define SURROGATE_OFFSET \ #define SURROGATE_OFFSET \
((uint32_t)0x10000 - (uint32_t)(0xD800 << 10) - (uint32_t)0xDC00) ((uint32_t)0x10000 - (uint32_t)(0xD800 << 10) - (uint32_t)0xDC00)
extern const char *Yap_tokText(void*tokptr); extern const char *Yap_tokText(void *tokptr);
extern Term Yap_tokRep(void*tokptr); extern Term Yap_tokRep(void *tokptr);
// standard strings // standard strings
@ -1383,18 +1406,17 @@ static inline Term Yap_UTF8ToString(const char *s USES_REGS) {
} }
static inline Atom UTF32ToAtom(const wchar_t *s USES_REGS) { static inline Atom UTF32ToAtom(const wchar_t *s USES_REGS) {
seq_tv_t inp, out; seq_tv_t inp, out;
inp.val.w0 = s; inp.val.w0 = s;
inp.type = YAP_STRING_WCHARS ; inp.type = YAP_STRING_WCHARS;
out.type = YAP_STRING_ATOM; out.type = YAP_STRING_ATOM;
out.max = -1; out.max = -1;
if (!Yap_CVT_Text(&inp, &out PASS_REGS)) if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return 0L; return 0L;
return out.val.a; return out.val.a;
} }
static inline Term Yap_WCharsToListOfCodes(const wchar_t *s USES_REGS) { static inline Term Yap_WCharsToListOfCodes(const wchar_t *s USES_REGS) {
seq_tv_t inp, out; seq_tv_t inp, out;
inp.val.w0 = s; inp.val.w0 = s;

View File

@ -13,12 +13,6 @@
* version: $Id: Yapproto.h,v 1.90 2008-08-07 20:51:23 vsc Exp $ * * version: $Id: Yapproto.h,v 1.90 2008-08-07 20:51:23 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#if defined(_WIN32)
#define X_API __declspec(dllexport)
#else
#define X_API
#endif
/* prototype file for Yap */ /* prototype file for Yap */
/* absmi.c */ /* absmi.c */
@ -309,6 +303,7 @@ extern struct vfs *Yap_InitAssetManager(void);
/* load_foreign.c */ /* load_foreign.c */
extern void Yap_InitLoadForeign(void); extern void Yap_InitLoadForeign(void);
extern bool Yap_LateInit(const char s[]);
/* mavar.c */ /* mavar.c */
extern void Yap_InitMaVarCPreds(void); extern void Yap_InitMaVarCPreds(void);

View File

@ -139,7 +139,7 @@ register struct yami *P1REG asm("bp"); /* can't use yamop before Yap.h */
#include "Yap.h" #include "Yap.h"
#include "clause.h" #include "clause.h"
#include "eval.h" #include "YapEval.h"
#ifdef HAVE_STRING_H #ifdef HAVE_STRING_H
#include <string.h> #include <string.h>
#endif #endif
@ -2327,6 +2327,8 @@ static inline void prune(choiceptr cp USES_REGS) {
if (POP_CHOICE_POINT(B->cp_b)) { if (POP_CHOICE_POINT(B->cp_b)) {
POP_EXECUTE(); POP_EXECUTE();
} }
if (B->cp_b == NULL)
break;
B = B->cp_b; B = B->cp_b;
} }
if (POP_CHOICE_POINT(B->cp_b)) { if (POP_CHOICE_POINT(B->cp_b)) {
@ -2452,10 +2454,10 @@ extern yamop *headoftrace;
ENDD(d0); ENDD(d0);
#endif #endif
#define Yap_AsmError(e, d) \ #define Yap_AsmError(e, d) \
{ \ { \
saveregs(); \ saveregs(); \
Yap_ThrowError(e, d, 4, ""); \ Yap_ThrowError(e, d, "while exwcuting inlined built-in"); \
setregs(); \ setregs(); \
} }

View File

@ -11,7 +11,7 @@
#ifndef BLOBS_H #ifndef BLOBS_H
#define BLOBS_H #define BLOBS_H
#ifndef X_API #if !defined(X_API) && !defined(SWIGYAP)
#if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(PL_KERNEL) #if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(PL_KERNEL)
#define X_API __declspec(dllexport) #define X_API __declspec(dllexport)
#else #else

View File

@ -250,6 +250,8 @@
#define LOCAL_nperm LOCAL->nperm_ #define LOCAL_nperm LOCAL->nperm_
#define REMOTE_nperm(wid) REMOTE(wid)->nperm_ #define REMOTE_nperm(wid) REMOTE(wid)->nperm_
#define LOCAL_jMP LOCAL->jMP_
#define REMOTE_jMP(wid) REMOTE(wid)->jMP_
#define LOCAL_LabelFirstArray LOCAL->LabelFirstArray_ #define LOCAL_LabelFirstArray LOCAL->LabelFirstArray_
#define REMOTE_LabelFirstArray(wid) REMOTE(wid)->LabelFirstArray_ #define REMOTE_LabelFirstArray(wid) REMOTE(wid)->LabelFirstArray_

View File

@ -126,7 +126,7 @@ typedef struct worker_local {
ADDR db_vec0_; ADDR db_vec0_;
struct RB_red_blk_node* db_root_; struct RB_red_blk_node* db_root_;
struct RB_red_blk_node* db_nil_; struct RB_red_blk_node* db_nil_;
sigjmp_buf gc_restore_; sigjmp_buf* gc_restore_;
CELL* extra_gc_cells_; CELL* extra_gc_cells_;
CELL* extra_gc_cells_base_; CELL* extra_gc_cells_base_;
CELL* extra_gc_cells_top_; CELL* extra_gc_cells_top_;
@ -140,6 +140,7 @@ typedef struct worker_local {
UInt CMemFirstBlockSz_; UInt CMemFirstBlockSz_;
// Variable used by the compiler to store number of permanent vars in a clause // Variable used by the compiler to store number of permanent vars in a clause
int nperm_; int nperm_;
int jMP_;
// Thread Local Area for Labels // Thread Local Area for Labels
Int* LabelFirstArray_; Int* LabelFirstArray_;
UInt LabelFirstArraySz_; UInt LabelFirstArraySz_;
@ -166,7 +167,7 @@ typedef struct worker_local {
/* error handling info, designed to be easy to pass to the foreign world */ /* error handling info, designed to be easy to pass to the foreign world */
yap_error_descriptor_t* ActiveError_; yap_error_descriptor_t* ActiveError_;
/// pointer to an exception term, from throw /// pointer to an exception term, from throw
jmp_buf IOBotch_; jmp_buf* IOBotch_;
TokEntry* tokptr_; TokEntry* tokptr_;
TokEntry* toktide_; TokEntry* toktide_;
VarEntry* VarTable_; VarEntry* VarTable_;
@ -177,7 +178,7 @@ typedef struct worker_local {
wchar_t* CommentsBuff_; wchar_t* CommentsBuff_;
size_t CommentsBuffPos_; size_t CommentsBuffPos_;
size_t CommentsBuffLim_; size_t CommentsBuffLim_;
sigjmp_buf RestartEnv_; sigjmp_buf* RestartEnv_;
char FileNameBuf_[YAP_FILENAME_MAX+1]; char FileNameBuf_[YAP_FILENAME_MAX+1];
char FileNameBuf2_[YAP_FILENAME_MAX+1]; char FileNameBuf2_[YAP_FILENAME_MAX+1];
struct TextBuffer_manager* TextBuffer_; struct TextBuffer_manager* TextBuffer_;

View File

@ -90,7 +90,7 @@
AtomCurrentModule = Yap_FullLookupAtom("$current_module"); TermCurrentModule = MkAtomTerm(AtomCurrentModule); AtomCurrentModule = Yap_FullLookupAtom("$current_module"); TermCurrentModule = MkAtomTerm(AtomCurrentModule);
AtomCut = Yap_LookupAtom("!"); TermCut = MkAtomTerm(AtomCut); AtomCut = Yap_LookupAtom("!"); TermCut = MkAtomTerm(AtomCut);
AtomCutBy = Yap_FullLookupAtom("$cut_by"); TermCutBy = MkAtomTerm(AtomCutBy); AtomCutBy = Yap_FullLookupAtom("$cut_by"); TermCutBy = MkAtomTerm(AtomCutBy);
AtomDAbort = Yap_FullLookupAtom("$abort"); TermDAbort = MkAtomTerm(AtomDAbort); AtomDAbort = Yap_LookupAtom("abort"); TermDAbort = MkAtomTerm(AtomDAbort);
AtomDBLoad = Yap_FullLookupAtom("$db_load"); TermDBLoad = MkAtomTerm(AtomDBLoad); AtomDBLoad = Yap_FullLookupAtom("$db_load"); TermDBLoad = MkAtomTerm(AtomDBLoad);
AtomDBREF = Yap_LookupAtom("DBRef"); TermDBREF = MkAtomTerm(AtomDBREF); AtomDBREF = Yap_LookupAtom("DBRef"); TermDBREF = MkAtomTerm(AtomDBREF);
AtomDBReference = Yap_LookupAtom("db_reference"); TermDBReference = MkAtomTerm(AtomDBReference); AtomDBReference = Yap_LookupAtom("db_reference"); TermDBReference = MkAtomTerm(AtomDBReference);
@ -289,6 +289,7 @@
AtomPermissionError = Yap_LookupAtom("permission_error"); TermPermissionError = MkAtomTerm(AtomPermissionError); AtomPermissionError = Yap_LookupAtom("permission_error"); TermPermissionError = MkAtomTerm(AtomPermissionError);
AtomPi = Yap_LookupAtom("pi"); TermPi = MkAtomTerm(AtomPi); AtomPi = Yap_LookupAtom("pi"); TermPi = MkAtomTerm(AtomPi);
AtomPipe = Yap_LookupAtom("pipe"); TermPipe = MkAtomTerm(AtomPipe); AtomPipe = Yap_LookupAtom("pipe"); TermPipe = MkAtomTerm(AtomPipe);
AtomPriority = Yap_LookupAtom("priority"); TermPriority = MkAtomTerm(AtomPriority);
AtomPlus = Yap_LookupAtom("+"); TermPlus = MkAtomTerm(AtomPlus); AtomPlus = Yap_LookupAtom("+"); TermPlus = MkAtomTerm(AtomPlus);
AtomPointer = Yap_LookupAtom("pointer"); TermPointer = MkAtomTerm(AtomPointer); AtomPointer = Yap_LookupAtom("pointer"); TermPointer = MkAtomTerm(AtomPointer);
AtomPortray = Yap_FullLookupAtom("portray"); TermPortray = MkAtomTerm(AtomPortray); AtomPortray = Yap_FullLookupAtom("portray"); TermPortray = MkAtomTerm(AtomPortray);
@ -541,11 +542,13 @@
FunctorNot = Yap_MkFunctor(AtomNot,1); FunctorNot = Yap_MkFunctor(AtomNot,1);
FunctorObj = Yap_MkFunctor(AtomObj,1); FunctorObj = Yap_MkFunctor(AtomObj,1);
FunctorOr = Yap_MkFunctor(AtomSemic,2); FunctorOr = Yap_MkFunctor(AtomSemic,2);
FunctorOutput = Yap_MkFunctor(AtomOutput,1);
FunctorPermissionError = Yap_MkFunctor(AtomPermissionError,3); FunctorPermissionError = Yap_MkFunctor(AtomPermissionError,3);
FunctorPlus = Yap_MkFunctor(AtomPlus,2); FunctorPlus = Yap_MkFunctor(AtomPlus,2);
FunctorPortray = Yap_MkFunctor(AtomPortray,1); FunctorPortray = Yap_MkFunctor(AtomPortray,1);
FunctorPrintMessage = Yap_MkFunctor(AtomPrintMessage,2); FunctorPrintMessage = Yap_MkFunctor(AtomPrintMessage,2);
FunctorProcedure = Yap_MkFunctor(AtomProcedure,5); FunctorProcedure = Yap_MkFunctor(AtomProcedure,5);
FunctorPriority = Yap_MkFunctor(AtomPriority,1);
FunctorPrologConstraint = Yap_MkFunctor(AtomProlog,2); FunctorPrologConstraint = Yap_MkFunctor(AtomProlog,2);
FunctorProtectStack = Yap_MkFunctor(AtomProtectStack,4); FunctorProtectStack = Yap_MkFunctor(AtomProtectStack,4);
FunctorQuery = Yap_MkFunctor(AtomQuery,1); FunctorQuery = Yap_MkFunctor(AtomQuery,1);

View File

@ -139,7 +139,8 @@ static void InitWorker(int wid) {
REMOTE_CMemFirstBlock(wid) = NULL; REMOTE_CMemFirstBlock(wid) = NULL;
REMOTE_CMemFirstBlockSz(wid) = 0L; REMOTE_CMemFirstBlockSz(wid) = 0L;
REMOTE_nperm(wid) = 0L; REMOTE_nperm(wid) = 0;
REMOTE_jMP(wid) = 0;
REMOTE_LabelFirstArray(wid) = NULL; REMOTE_LabelFirstArray(wid) = NULL;
REMOTE_LabelFirstArraySz(wid) = 0L; REMOTE_LabelFirstArraySz(wid) = 0L;

View File

@ -289,6 +289,7 @@
AtomPermissionError = AtomAdjust(AtomPermissionError); TermPermissionError = MkAtomTerm(AtomPermissionError); AtomPermissionError = AtomAdjust(AtomPermissionError); TermPermissionError = MkAtomTerm(AtomPermissionError);
AtomPi = AtomAdjust(AtomPi); TermPi = MkAtomTerm(AtomPi); AtomPi = AtomAdjust(AtomPi); TermPi = MkAtomTerm(AtomPi);
AtomPipe = AtomAdjust(AtomPipe); TermPipe = MkAtomTerm(AtomPipe); AtomPipe = AtomAdjust(AtomPipe); TermPipe = MkAtomTerm(AtomPipe);
AtomPriority = AtomAdjust(AtomPriority); TermPriority = MkAtomTerm(AtomPriority);
AtomPlus = AtomAdjust(AtomPlus); TermPlus = MkAtomTerm(AtomPlus); AtomPlus = AtomAdjust(AtomPlus); TermPlus = MkAtomTerm(AtomPlus);
AtomPointer = AtomAdjust(AtomPointer); TermPointer = MkAtomTerm(AtomPointer); AtomPointer = AtomAdjust(AtomPointer); TermPointer = MkAtomTerm(AtomPointer);
AtomPortray = AtomAdjust(AtomPortray); TermPortray = MkAtomTerm(AtomPortray); AtomPortray = AtomAdjust(AtomPortray); TermPortray = MkAtomTerm(AtomPortray);
@ -541,11 +542,13 @@
FunctorNot = FuncAdjust(FunctorNot); FunctorNot = FuncAdjust(FunctorNot);
FunctorObj = FuncAdjust(FunctorObj); FunctorObj = FuncAdjust(FunctorObj);
FunctorOr = FuncAdjust(FunctorOr); FunctorOr = FuncAdjust(FunctorOr);
FunctorOutput = FuncAdjust(FunctorOutput);
FunctorPermissionError = FuncAdjust(FunctorPermissionError); FunctorPermissionError = FuncAdjust(FunctorPermissionError);
FunctorPlus = FuncAdjust(FunctorPlus); FunctorPlus = FuncAdjust(FunctorPlus);
FunctorPortray = FuncAdjust(FunctorPortray); FunctorPortray = FuncAdjust(FunctorPortray);
FunctorPrintMessage = FuncAdjust(FunctorPrintMessage); FunctorPrintMessage = FuncAdjust(FunctorPrintMessage);
FunctorProcedure = FuncAdjust(FunctorProcedure); FunctorProcedure = FuncAdjust(FunctorProcedure);
FunctorPriority = FuncAdjust(FunctorPriority);
FunctorPrologConstraint = FuncAdjust(FunctorPrologConstraint); FunctorPrologConstraint = FuncAdjust(FunctorPrologConstraint);
FunctorProtectStack = FuncAdjust(FunctorProtectStack); FunctorProtectStack = FuncAdjust(FunctorProtectStack);
FunctorQuery = FuncAdjust(FunctorQuery); FunctorQuery = FuncAdjust(FunctorQuery);

View File

@ -145,6 +145,7 @@ static void RestoreWorker(int wid USES_REGS) {
#ifdef THREADS #ifdef THREADS
#endif /* THREADS */ #endif /* THREADS */

File diff suppressed because it is too large Load Diff

View File

@ -38,8 +38,8 @@ typedef enum {
#define low_level_trace(Port, pred, args) low_level_trace__(Port, pred, args) #define low_level_trace(Port, pred, args) low_level_trace__(Port, pred, args)
#endif #endif
void low_level_trace__(yap_low_level_port, PredEntry *, CELL *); extern bool low_level_trace__(yap_low_level_port, PredEntry *, CELL *);
void Yap_InitLowLevelTrace(void); extern void Yap_InitLowLevelTrace(void);
void toggle_low_level_trace(void); extern void toggle_low_level_trace(void);
#endif #endif

View File

@ -1,7 +1,7 @@
#include "Yap.h" #include "Yap.h"
#include "amijit.h" #include "amijit.h"
#include "clause.h" #include "clause.h"
#include "eval.h" #include "YapEval.h"
#if HAVE_ERRNO_H #if HAVE_ERRNO_H
#include <errno.h> #include <errno.h>
#else #else

View File

@ -76,16 +76,17 @@ endif (WITH_YAPOR_SBA)
if (WITH_YAPOR) if (WITH_YAPOR)
set_property(DIRECTORY .. APPEND PROPERTY COMPILE_DEFINITIONS YAPOR=1) set_property(DIRECTORY .. APPEND PROPERTY COMPILE_DEFINITIONS YAPOR=1;YAP_KERNEL=1)
endif () endif ()
set (POSITION_INDEPENDENT_CODE TRUE) set (POSITION_INDEPENDENT_CODE TRUE)
SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 )
add_component (libOPTYap add_component (libOPTYap
${OPTYap_SOURCES} ) ${OPTYap_SOURCES} )
MY_set_target_properties(libOPTYap My_set_target_properties(libOPTYap
PROPERTIES PROPERTIES
# RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION} # RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION}
# SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION} # SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION}

View File

@ -170,7 +170,7 @@ struct page_statistics {
#define INCREMENT_AUX_STATS(STATS, BYTES, PAGES) \ #define INCREMENT_AUX_STATS(STATS, BYTES, PAGES) \
BYTES += PgEnt_bytes_in_use(STATS) BYTES += PgEnt_bytes_in_use(STATS)
#define SHOW_PAGE_STATS_MSG(STR_NAME) \ #define SHOW_PAGE_STATS_MSG(STR_NAME) \
" %s %10" Int_F "s bytes (%ld structs in use)\n", STR_NAME " %s %10" Int_F "s bytes (%" Sizet_F " ; structs in use)\n", STR_NAME
#define SHOW_PAGE_STATS_ARGS(STATS, STR_TYPE) \ #define SHOW_PAGE_STATS_ARGS(STATS, STR_TYPE) \
PgEnt_strs_in_use(STATS) * sizeof(STR_TYPE), PgEnt_strs_in_use(STATS) PgEnt_strs_in_use(STATS) * sizeof(STR_TYPE), PgEnt_strs_in_use(STATS)
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */

Some files were not shown because too many files have changed in this diff Show More