Smaller updates:

constant use of longjmp
conflict with python headers
win32 support
dll support
This commit is contained in:
Vitor Santos Costa 2017-02-20 15:28:46 +00:00
parent 55879dbd6c
commit 65ff3ed471
131 changed files with 8125 additions and 5154 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;

6
.ctags
View File

@ -6,6 +6,7 @@
--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]*Yap_InitCPred[ \t]*\"(\$?[A-Za-z0-9_]*)\"([ \t]*).*/\1/p,predicate,predicate definition/
--langmap=C:+.(h.cmake).(h.config)
--exclude=\._*
--exclude=*\.bak
--exclude=\.svn
@ -22,3 +23,8 @@
--exclude=\#.*
--exclude=(.)\#*
--exclude=*.dylib
--exclude=docs
--exclude=build
--exclude=cmake-build-debug
--exclude=clang

2
.gitignore vendored
View File

@ -84,7 +84,7 @@ clang
cmake-build-debug
os/YapIOConfig.h
CodeBlocks
x
os/readterm.c.cpp
os/readterm.c.cpp

View File

@ -12,8 +12,8 @@
#ifdef BEAM
#include "Yap.h"
#include "compile.h"
#include "clause.h"
#include "YapCompile.h"
#include "clause.h"
#include "eam.h"
#include "eamamasm.h"
#include <stdio.h>
@ -85,7 +85,7 @@ int X_Var(Ventry *ve)
int var;
if (ve->KindOfVE == PermVar || ve->KindOfVE == VoidVar ) {
printf("Erro no tipo de variavel X ->eamamas.c \n");
printf("Erro no tipo de variavel X ->eamamas.c \n");
exit(1);
}
var = ((ve->NoOfVE) & MaskVarAdrs);
@ -99,7 +99,7 @@ int Y_Var(Ventry *ve)
{
int var;
if (ve->KindOfVE != PermVar) {
printf("Erro no tipo de variavel Y ->eamamas.c \n");
printf("Erro no tipo de variavel Y ->eamamas.c \n");
exit(1);
}
var = ((ve->NoOfVE) & MaskVarAdrs);
@ -119,7 +119,7 @@ void eam_pass(CInstr *ppc)
{
int alloc_found=0;
int body=0;
while (ppc) {
switch ((int) ppc->op) {
@ -184,7 +184,7 @@ void eam_pass(CInstr *ppc)
} else {
emit_inst(_unify_val_Y_op);
emit_par(Y_Var((Ventry *) ppc->new4));
}
} else { emit_inst(_unify_void_op); }
break;
@ -268,7 +268,7 @@ void eam_pass(CInstr *ppc)
case put_atom_op:
emit_inst(_put_atom_op);
emit_par(ppc->new1);
emit_par(ppc->new4);
emit_par(ppc->new4);
break;
case put_list_op:
emit_inst(_put_list_op);
@ -349,7 +349,7 @@ void eam_pass(CInstr *ppc)
case cut_op:
emit_inst(_cut_op);
break;
break;
case commit_op:
emit_inst(_commit_op);
break;
@ -402,7 +402,7 @@ void eam_pass(CInstr *ppc)
}
emit_par(ppc->new4);
break;
case direct_safe_call_op:
if (ppc->new1==1) {
emit_inst(_direct_safe_call_unary_op);
@ -434,8 +434,8 @@ void eam_pass(CInstr *ppc)
if (a==NULL) a=Yap_LookupAtom("\n");
emit_inst(_put_atom_op);
emit_par(1);
emit_par((Cell) MkAtomTerm(a));
}
emit_par((Cell) MkAtomTerm(a));
}
emit_inst(_write_call);
break;
case is_op:
@ -468,50 +468,50 @@ void eam_pass(CInstr *ppc)
case remove_box_op:
case remove_last_box_op:
break;
case jump_op:
emit_inst(_jump_op);
emit_upar((Cell) Code_Start+ (Cell) labels[ppc->new4]);
break;
case label_op:
if (pass==0) labels[ppc->new4] = get_addr();
if (pass==0) labels[ppc->new4] = get_addr();
break;
case run_op:
/* se ficar vazio, retirar no eam_am.c o +5 das linhas pc=clause->code+5 no only_1_clause e no call */
emit_inst(_try_me_op);
emit_par(0);
emit_par(0);
emit_par(0);
emit_par(0);
emit_par(0);
emit_par(0);
break;
case only_1_clause_op:
emit_inst(_only_1_clause_op);
emit_par(ppc->new4);
emit_par(((struct Clauses *)ppc->new4)->predi->arity);
emit_par(((struct Clauses *)ppc->new4)->nr_vars);
emit_par(((struct Clauses *)ppc->new4)->nr_vars);
emit_par(0); /* Nr da alternativa */
break;
case try_me_op:
emit_inst(_try_me_op);
emit_par(ppc->new4);
emit_par(ppc->new4);
emit_par(((struct Clauses *)ppc->new4)->predi->arity);
emit_par(((struct Clauses *)ppc->new4)->nr_vars);
emit_par(((struct Clauses *)ppc->new4)->nr_vars);
emit_par(0); /* Nr da alternativa */
break;
case retry_me_op:
emit_inst(_retry_me_op);
emit_par(ppc->new4);
emit_par(((struct Clauses *)ppc->new4)->predi->arity);
emit_par(((struct Clauses *)ppc->new4)->nr_vars);
emit_par(((struct Clauses *)ppc->new4)->nr_vars);
emit_par(ppc->new1);
break;
case trust_me_op:
emit_inst(_trust_me_op);
emit_par(ppc->new4);
emit_par(((struct Clauses *)ppc->new4)->predi->arity);
emit_par(((struct Clauses *)ppc->new4)->nr_vars);
emit_par(((struct Clauses *)ppc->new4)->nr_vars);
emit_par(ppc->new1);
break;
@ -529,11 +529,11 @@ void eam_pass(CInstr *ppc)
}
body=1;
break;
case prepare_tries:
emit_inst(_prepare_tries);
emit_par(ppc->new1);
emit_par(ppc->new4);
emit_par(ppc->new1);
emit_par(ppc->new4);
break;
case exit_op:
@ -559,7 +559,7 @@ void eam_pass(CInstr *ppc)
printf("[ please note that beam still does not support a lot of builtins ]\n");
}
emit_inst(_fail_op);
}
ppc = ppc->nextInst;
}

View File

@ -12,8 +12,8 @@
#ifdef BEAM
#include "Yap.h"
#include "compile.h"
#include "clause.h"
#include "YapCompile.h"
#include "clause.h"
#include "eam.h"
#include <stdio.h>
#include <stdlib.h>
@ -40,13 +40,13 @@ int exists_on_table(Cell a,struct HASH_TABLE **table, int i)
struct HASH_TABLE *t;
t=table[i];
while(t) {
if (t->value==a) return(1);
t=t->next;
}
return(0);
}
@ -61,20 +61,20 @@ Cell *gera_codigo_try(struct Predicates *predi) /* gerar os try's para o predic
emit_new(prepare_tries,predi->nr_alt,predi->arity);
if (predi->nr_alt==1) {
emit_new(only_1_clause_op,0,(unsigned long) c);
} else if (predi->nr_alt>1) {
emit_new(only_1_clause_op,0,(unsigned long) c);
} else if (predi->nr_alt>1) {
while(c!=NULL) {
if (nr+1==predi->nr_alt) emit_new(trust_me_op,nr,(unsigned long) c);
if (nr+1==predi->nr_alt) emit_new(trust_me_op,nr,(unsigned long) c);
else if (nr==0) emit_new(try_me_op,predi->nr_alt,(unsigned long) c);
else emit_new(retry_me_op,nr,(unsigned long) c);
c=c->next;
nr++;
}
} else {
} else {
emit_new(fail_op,0,0);
}
return(eam_assemble(StartCode));
}
@ -91,7 +91,7 @@ Cell *gera_codigo_try_list(struct Predicates *predi) /* gerar os try's para o p
c=predi->first;
emit_new(prepare_tries,nr_preds,predi->arity);
if (nr_preds>=1) {
if (nr_preds>=1) {
while(c!=NULL) {
if (c->predi==predi && (c->idx==Lista || c->idx==Variavel)) {
if (nr_preds==1) {
@ -108,20 +108,20 @@ Cell *gera_codigo_try_list(struct Predicates *predi) /* gerar os try's para o p
} else {
emit_new(fail_op,0,0);
}
return(eam_assemble(StartCode));
}
struct HASH_TABLE **gera_codigo_try_atom(struct Predicates *predi)
struct HASH_TABLE **gera_codigo_try_atom(struct Predicates *predi)
{
int j,nr_preds,nr_atoms;
struct HASH_TABLE **table;
struct HASH_TABLE *t;
struct Clauses *cla;
nr_atoms=predi->idx_atom;
nr_atoms=predi->idx_atom;
nr_preds=nr_atoms+predi->idx_var;
table=malloc(sizeof(struct HASH_TABLE *)*(nr_atoms+1));
for (j=0;j<=nr_atoms;j++) table[j]=NULL;
@ -132,7 +132,7 @@ struct Clauses *cla;
Cell a;
unsigned int index;
int nr;
a=cla->val;
if (a && nr_atoms) {
index=index_of_hash_table_atom(a,nr_atoms);
@ -187,18 +187,18 @@ struct HASH_TABLE **table;
struct HASH_TABLE *t;
struct Clauses *cla;
nr_appls=predi->idx_functor;
nr_appls=predi->idx_functor;
nr_preds=nr_appls+predi->idx_var;
table=malloc(sizeof(struct HASH_TABLE *)*(nr_appls+1));
for (j=0;j<=nr_appls;j++) table[j]=NULL;
cla=predi->first;
while(cla) {
if (cla->idx==Estrutura) {
Cell a;
long int index;
int nr;
a=cla->val;
if (a && nr_appls) {
index=index_of_hash_table_appl(a,nr_appls);
@ -257,7 +257,7 @@ Cell *gera_codigo_try_only_vars(struct Predicates *predi) /* gerar os try's de V
c=predi->first;
emit_new(prepare_tries,nr_preds,predi->arity);
if (nr_preds>=1) {
if (nr_preds>=1) {
while(c!=NULL) {
if (c->predi==predi && c->idx==Variavel) {
if (nr_preds==1) {
@ -274,7 +274,7 @@ Cell *gera_codigo_try_only_vars(struct Predicates *predi) /* gerar os try's de V
} else {
emit_new(fail_op,0,0);
}
return(eam_assemble(StartCode));
}
@ -292,7 +292,7 @@ void do_eam_indexing(struct Predicates *p)
p->idx=1;
}
if((Print_Code & 4) && (Print_Code & 8)) {
if((Print_Code & 4) && (Print_Code & 8)) {
printf("General Case :\n");
eam_showcode(p->code);
}
@ -309,10 +309,10 @@ void ver_predicados(struct Predicates *p)
c=p->first;
while(c!=NULL) {
printf("Clausula %d do tipo %d (%d locals %d args) (val=0x%X)\n",++i,c->idx,c->nr_vars,c->predi->arity, (unsigned )c->val);
printf("Clausula %d do tipo %d (%d locals %d args) (val=0x%X)\n",++i,c->idx,c->nr_vars,c->predi->arity, (unsigned )c->val);
c=c->next;
}
}

View File

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

View File

@ -127,8 +127,7 @@ X_API yhandle_t YAP_CurrentSlot(void);
/// @brief allocate n empty new slots
///
/// Return a handle to the system's default slot.
X_API yhandle_t YAP_NewSlots(int NumberOfSlots);
/// Return a handle to the system's default slo t. iX_API yhandle_t YAP_NewSlots(int NumberOfSlots);
/// @brief allocate n empty new slots
///
@ -246,6 +245,8 @@ X_API YAP_Bool YAP_IsRationalTerm(YAP_Term t) {
#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_IsNonVarTerm(YAP_Term t) { return (IsNonVarTerm(t)); }
@ -277,6 +278,32 @@ X_API Term YAP_MkIntTerm(Int n) {
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) {
if (!IsApplTerm(t))
return IntOfTerm(t);
@ -1380,8 +1407,8 @@ X_API Term YAP_ReadBuffer(const char *s, Term *tp) {
tv = 0;
LOCAL_ErrorMessage = NULL;
const unsigned char *us = (const unsigned char *)s;
while (!(t = Yap_BufferToTermWithPrioBindings(
us, strlen(s) + 1, TermNil, GLOBAL_MaxPriority, tv))) {
while (!(t = Yap_BufferToTermWithPrioBindings(us, strlen(s) + 1, TermNil,
GLOBAL_MaxPriority, tv))) {
if (LOCAL_ErrorMessage) {
if (!strcmp(LOCAL_ErrorMessage, "Stack Overflow")) {
if (!Yap_dogc(0, NULL PASS_REGS)) {
@ -1638,7 +1665,6 @@ X_API PredEntry *YAP_AtomToPredInModule(Atom at, Term mod) {
static int run_emulator(USES_REGS1) {
int out;
LOCAL_PrologMode &= ~(UserCCallMode | CCallMode);
out = Yap_absmi(0);
LOCAL_PrologMode |= UserCCallMode;
return out;
@ -1661,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),
// LOCAL_CurSlot);
dgi->b = LCL0 - (CELL *)B;
out = run_emulator(PASS_REGS1);
out = Yap_exec_absmi(true, false);
RECOVER_MACHINE_REGS();
if (out) {
dgi->EndSlot = LOCAL_CurSlot;
@ -2122,16 +2148,20 @@ X_API YAP_Term YAP_CopyTerm(Term t) {
X_API char *YAP_WriteBuffer(Term t, char *buf, size_t sze, int flags) {
CACHE_REGS
size_t length;
seq_tv_t inp, out;
size_t length = sze;
char *b;
BACKUP_MACHINE_REGS();
if ((b = Yap_TermToString(t, &length, LOCAL_encoding, flags)) != buf) {
RECOVER_MACHINE_REGS();
return b;
}
inp.val.t = t;
inp.type = YAP_STRING_TERM;
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();
return buf;
return out.val.c;
}
/// write a a term to n user-provided buffer: make sure not tp
@ -2253,13 +2283,11 @@ static void do_bootfile(const char *bootfilename USES_REGS) {
the module.
*/
static bool initialized = false;
X_API bool YAP_initialized = false;
static int n_mdelays = 0;
static YAP_delaymodule_t *m_delays;
X_API bool YAP_DelayInit(YAP_ModInit_t f, const char s[]) {
if (initialized)
return false;
if (m_delays) {
m_delays = realloc(m_delays, (n_mdelays + 1) * sizeof(YAP_delaymodule_t));
} else {
@ -2271,6 +2299,17 @@ X_API bool YAP_DelayInit(YAP_ModInit_t f, const char s[]) {
return true;
}
bool Yap_LateInit(const char s[]) {
int i;
for (i = 0; i < n_mdelays; i++) {
if (!strcmp(m_delays[i].s, s)) {
m_delays[i].f();
return true;
}
}
return false;
}
static void start_modules(void) {
Term cm = CurrentModule;
size_t i;
@ -2296,9 +2335,8 @@ YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
const char *yroot;
/* ignore repeated calls to YAP_Init */
if (initialized)
if (YAP_initialized)
return YAP_FOUND_BOOT_ERROR;
initialized = true;
Yap_embedded = yap_init->Embedded;
Yap_page_size = Yap_InitPageSize(); /* init memory page size, required by
@ -2306,9 +2344,10 @@ YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
Yap_init_yapor_global_local_memory();
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
GLOBAL_PrologShouldHandleInterrupts = yap_init->PrologShouldHandleInterrupts &&
!yap_init->Embedded;
Yap_InitSysbits(0); /* init signal handling and time, required by later
// GLOBAL_PrologShouldHandleInterrupts =
// yap_init->PrologShouldHandleInterrupts &&
if (!yap_init->Embedded)
Yap_InitSysbits(0); /* init signal handling and time, required by later
functions */
GLOBAL_argv = yap_init->Argv;
GLOBAL_argc = yap_init->Argc;
@ -2492,6 +2531,7 @@ YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
}
start_modules();
YAP_initialized = true;
return rc;
}

View File

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

View File

@ -207,7 +207,7 @@ void Yap_RestartYap(int flag) {
#if PUSH_REGS
restore_absmi_regs(&Yap_standard_regs);
#endif
siglongjmp(LOCAL_RestartEnv, 1);
siglongjmp(*LOCAL_RestartEnv, 1);
}
static void error_exit_yap(int value) {
@ -328,7 +328,7 @@ void Yap_ThrowError__(const char *file, const char *function, int lineno,
} else {
Yap_Error__(file, function, lineno, type, where);
}
siglongjmp(LOCAL_RestartEnv, 4);
siglongjmp(*LOCAL_RestartEnv, 4);
}
/**

168
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) {
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) {
CACHE_REGS
Term ts[4];
Term ts[4];
ts[0] = ARG1;
ts[1] = cp_as_integer(B PASS_REGS); /* p_current_choice_point */
ts[2] = ARG1;
@ -141,8 +141,8 @@ Term Yap_ExecuteCallMetaCall(Term mod) {
Term Yap_PredicateIndicator(Term t, Term mod) {
CACHE_REGS
// generate predicate indicator in this case
Term ti[2];
// generate predicate indicator in this case
Term ti[2];
t = Yap_YapStripModule(t, &mod);
if (IsApplTerm(t) && !IsExtensionFunctor(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,
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) {
Term t0 = t;
restart:
restart:
if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, t0, pname);
return NULL;
@ -273,7 +273,7 @@ inline static bool do_execute(Term t, Term mod USES_REGS) {
Term t0 = t;
t = Yap_YapStripModule(t, &mod);
/* 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 &&
!(LOCAL_PrologMode & (AbortMode | InterruptMode | SystemMode))) {
return EnterCreepMode(t, mod PASS_REGS);
@ -393,7 +393,7 @@ inline static bool do_execute_n(Term t, Term mod, unsigned int n USES_REGS) {
int j = -n;
Term t0 = t;
restart_exec:
restart_exec:
if (IsVarTerm(t)) {
return CallError(INSTANTIATION_ERROR, t0, mod PASS_REGS);
} else if (IsAtomTerm(t)) {
@ -432,8 +432,8 @@ restart_exec:
}
if (Yap_has_a_signal() && !LOCAL_InterruptsDisabled) {
return EnterCreepMode(
copy_execn_to_heap(f, pt, n, arity, CurrentModule PASS_REGS),
mod PASS_REGS);
copy_execn_to_heap(f, pt, n, arity, CurrentModule PASS_REGS),
mod PASS_REGS);
}
if (arity > MaxTemps) {
return CallError(TYPE_ERROR_CALLABLE, t, mod PASS_REGS);
@ -650,7 +650,7 @@ static Int execute_clause(USES_REGS1) { /* '$execute_clause'(Goal) */
yamop *code;
Term clt = Deref(ARG3);
restart_exec:
restart_exec:
if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, ARG3, "call/1");
return FALSE;
@ -746,7 +746,7 @@ static void prune_inner_computation(choiceptr parent) {
cut_pt = B;
while (cut_pt < parent) {
/* make sure we
e C-choicepoints */
e C-choicepoints */
if (POP_CHOICE_POINT(cut_pt->cp_b)) {
POP_EXECUTE();
}
@ -791,7 +791,7 @@ static void complete_inner_computation(choiceptr old_B) {
static inline Term *GetTermAddress(CELL a) {
Term *b = NULL;
restart:
restart:
if (!IsVarTerm(a)) {
return (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;
switch (exec_result) {
// we failed
// Exception: we'll pass it through
// we failed
// Exception: we'll pass it through
case CALLED_FROM_EXCEPTION:
// internal exception
{
@ -905,8 +905,8 @@ static bool exit_set_call(execution_port exec_result, choiceptr B0, yamop *oCP,
choiceptr saved_b = B;
CELL *pt = ASP;
CUT_C_PUSH(
NEXTOP(NEXTOP(PredProtectStack->cs.p_code.FirstClause, OtapFs), OtapFs),
pt); // this is where things get complicated, we need to
NEXTOP(NEXTOP(PredProtectStack->cs.p_code.FirstClause, OtapFs), OtapFs),
pt); // this is where things get complicated, we need to
// protect the stack and be able to backtrack
pt -= 4;
pt[3] = t4;
@ -955,7 +955,7 @@ static Int protect_stack_from_cut(USES_REGS1) {
* @param USES_REGS1 [env for threaded execution]
* @return c
[next answer]
*/
*/
static Int protect_stack_from_retry(USES_REGS1) {
// 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) {
CACHE_REGS
if (creeping) {
Yap_signal(YAP_CREEP_SIGNAL);
}
if (creeping) {
Yap_signal(YAP_CREEP_SIGNAL);
}
CurrentModule = omod;
Yap_CloseSlots(sl);
if (out) {
@ -1123,7 +1123,7 @@ static Int _user_expand_goal(USES_REGS1) {
ARG1 = Yap_MkApplTerm(FunctorModule, 2, mg_args);
ARG2 = Yap_GetFromSlot(h2);
if ((pe = RepPredProp(
Yap_GetPredPropByFunc(FunctorGoalExpansion2, SYSTEM_MODULE))) &&
Yap_GetPredPropByFunc(FunctorGoalExpansion2, SYSTEM_MODULE))) &&
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
return complete_ge(true, omod, sl, creeping);
@ -1133,7 +1133,7 @@ static Int _user_expand_goal(USES_REGS1) {
ARG3 = Yap_GetFromSlot(h2);
/* user:goal_expansion(A,CurMod,B) */
if ((pe = RepPredProp(
Yap_GetPredPropByFunc(FunctorGoalExpansion, USER_MODULE))) &&
Yap_GetPredPropByFunc(FunctorGoalExpansion, USER_MODULE))) &&
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
Yap_execute_pred(pe, NULL PASS_REGS, false)) {
return complete_ge(true, omod, sl, creeping);
@ -1145,7 +1145,7 @@ static Int _user_expand_goal(USES_REGS1) {
/* user:goal_expansion(A,B) */
if (cmod != USER_MODULE && /* we have tried this before */
(pe = RepPredProp(
Yap_GetPredPropByFunc(FunctorGoalExpansion2, USER_MODULE))) &&
Yap_GetPredPropByFunc(FunctorGoalExpansion2, USER_MODULE))) &&
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
Yap_execute_pred(pe, NULL PASS_REGS, false)) {
return complete_ge(true, omod, sl, creeping);
@ -1165,7 +1165,7 @@ static Int do_term_expansion(USES_REGS1) {
ARG1 = g;
if ((pe = RepPredProp(
Yap_GetPredPropByFunc(FunctorTermExpansion, USER_MODULE))) &&
Yap_GetPredPropByFunc(FunctorTermExpansion, USER_MODULE))) &&
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
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);
ARG2 = Yap_GetFromSlot(h2);
if ((pe = RepPredProp(
Yap_GetPredPropByFunc(FunctorTermExpansion, SYSTEM_MODULE))) &&
Yap_GetPredPropByFunc(FunctorTermExpansion, SYSTEM_MODULE))) &&
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
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);
}
t = Yap_YapStripModule(t, &mod);
restart_exec:
restart_exec:
if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, ARG3, "call/1");
return false;
@ -1421,7 +1421,10 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
int lval, out;
Int OldBorder = LOCAL_CBorder;
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) {
case 1: { /* restart */
/* otherwise, SetDBForThrow will fail entering critical mode */
@ -1449,25 +1452,27 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
/* reset the registers so that we don't have trash in abstract
* machine */
Yap_set_fpu_exceptions(
getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG));
getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG));
P = (yamop *)FAILCODE;
LOCAL_PrologMode = UserMode;
} break;
case 3: { /* saved state */
LOCAL_CBorder = OldBorder;
LOCAL_RestartEnv = sighold;
return false;
}
case 4: {
/* abort */
/* can be called from anywgerre, must reset registers,
*/
LOCAL_RestartEnv = sighold;
Yap_JumpToEnv(TermDAbort);
P = (yamop *)FAILCODE;
LOCAL_PrologMode = UserMode;
} break;
default:
/* do nothing */
LOCAL_PrologMode = UserMode;
/* do nothing */
LOCAL_PrologMode = UserMode;
}
} else {
LOCAL_PrologMode = UserMode;
@ -1480,6 +1485,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
if (!Yap_has_a_signal())
CalculateStackGap(PASS_REGS1);
LOCAL_CBorder = OldBorder;
LOCAL_RestartEnv = sighold;
return out;
}
@ -1530,13 +1536,13 @@ void Yap_PrepGoal(arity_t arity, CELL *pt, choiceptr saved_b USES_REGS) {
static bool do_goal(yamop *CodeAdr, int arity, CELL *pt, bool top USES_REGS) {
choiceptr saved_b = B;
bool out;
Yap_PrepGoal(arity, pt, saved_b PASS_REGS);
CACHE_A1();
P = (yamop *)CodeAdr;
// S = CellPtr(RepPredProp(
// PredPropByFunc(Yap_MkFunctor(AtomCall, 1), 0))); /* A1 mishaps */
out = exec_absmi(top, YAP_EXEC_ABSMI PASS_REGS);
if (top)
Yap_flush();
@ -1550,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) {
CACHE_REGS
return exec_absmi(top, has_reset PASS_REGS);
return exec_absmi(top, has_reset PASS_REGS);
}
/**
@ -1560,7 +1566,7 @@ bool Yap_exec_absmi(bool top, yap_reset_t has_reset) {
*/
void Yap_fail_all(choiceptr bb USES_REGS) {
yamop *saved_p, *saved_cp;
saved_p = P;
saved_cp = CP;
/* prune away choicepoints */
@ -1579,7 +1585,7 @@ void Yap_fail_all(choiceptr bb USES_REGS) {
DEPTH = B->cp_depth;
#endif /* DEPTH_LIMIT */
YENV = ENV = B->cp_env;
/* recover local stack */
/* recover local stack */
#ifdef DEPTH_LIMIT
DEPTH = ENV[E_DEPTH];
#endif
@ -1606,16 +1612,16 @@ bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) {
yamop *saved_p, *saved_cp;
yamop *CodeAdr;
bool out;
saved_p = P;
saved_cp = CP;
LOCAL_PrologMode |= TopGoalMode;
PELOCK(81, ppe);
CodeAdr = ppe->CodeOfPred;
UNLOCK(ppe->PELock);
out = do_goal(CodeAdr, ppe->ArityOfPE, pt, false PASS_REGS);
if (out) {
choiceptr cut_B;
/* we succeeded, let's prune */
@ -1691,21 +1697,21 @@ 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) {
CACHE_REGS
Prop pe;
Prop pe;
PredEntry *ppe;
CELL *pt;
/* preserve the current restart environment */
/* visualc*/
/* just keep the difference because of possible garbage collections
*/
if (IsAtomTerm(t)) {
Atom a = AtomOfTerm(t);
pt = NULL;
pe = PredPropByAtom(a, mod);
} else if (IsApplTerm(t)) {
Functor f = FunctorOfTerm(t);
if (IsBlobFunctor(f)) {
Yap_Error(TYPE_ERROR_CALLABLE, t, "call/1");
return false;
@ -1728,7 +1734,7 @@ bool Yap_execute_goal(Term t, int nargs, Term mod, bool pass_ex) {
void Yap_trust_last(void) {
CACHE_REGS
ASP = B->cp_env;
ASP = B->cp_env;
CP = B->cp_cp;
HR = B->cp_h;
#ifdef DEPTH_LIMIT
@ -1746,7 +1752,7 @@ void Yap_trust_last(void) {
Term Yap_RunTopGoal(Term t, bool handle_errors) {
CACHE_REGS
yamop *CodeAdr;
yamop *CodeAdr;
Prop pe;
PredEntry *ppe;
CELL *pt;
@ -1754,7 +1760,7 @@ Term Yap_RunTopGoal(Term t, bool handle_errors) {
Term tmod = CurrentModule;
Term goal_out = 0;
LOCAL_PrologMode |= TopGoalMode;
t = Yap_YapStripModule(t, &tmod);
if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, t, "call/1");
@ -1767,7 +1773,7 @@ Term Yap_RunTopGoal(Term t, bool handle_errors) {
arity = 0;
} else if (IsApplTerm(t)) {
Functor f = FunctorOfTerm(t);
if (IsBlobFunctor(f)) {
Yap_Error(TYPE_ERROR_CALLABLE, t, "call/1");
LOCAL_PrologMode &= ~TopGoalMode;
@ -1799,7 +1805,7 @@ Term Yap_RunTopGoal(Term t, bool handle_errors) {
ts[0] = tmod;
ts[1] = t;
Functor f = Yap_MkFunctor(Yap_LookupAtom("call"), 1);
pt = &t;
t = Yap_MkApplTerm(FunctorModule, 2, ts);
pe = Yap_GetPredPropByFunc(f, tmod);
@ -1809,7 +1815,7 @@ Term Yap_RunTopGoal(Term t, bool handle_errors) {
PELOCK(82, ppe);
CodeAdr = ppe->CodeOfPred;
UNLOCK(ppe->PELock);
#if !USE_SYSTEM_MALLOC
if (LOCAL_TrailTop - HeapTop < 2048) {
Yap_Error(RESOURCE_ERROR_TRAIL, TermNil,
@ -1825,7 +1831,7 @@ static void do_restore_regs(Term t, int restore_all USES_REGS) {
Int i;
Int max = ArityOfFunctor(FunctorOfTerm(t)) - 4;
CELL *ptr = RepAppl(t) + 5;
P = (yamop *)IntegerOfTerm(ptr[-4]);
CP = (yamop *)IntegerOfTerm(ptr[-3]);
ENV = (CELL *)(LCL0 - IntegerOfTerm(ptr[-2]));
@ -1855,11 +1861,11 @@ static Int restore_regs(USES_REGS1) {
* a
* call */
static Int restore_regs2(USES_REGS1) {
Term t = Deref(ARG1), d0;
choiceptr pt0;
Int d;
if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, t, "support for coroutining");
return (FALSE);
@ -1969,7 +1975,7 @@ static Int cut_up_to_next_disjunction(USES_REGS1) {
bool Yap_Reset(yap_reset_t mode) {
CACHE_REGS
int res = TRUE;
int res = TRUE;
Yap_ResetException(worker_id);
/* first, backtrack to the root */
@ -2018,14 +2024,17 @@ static Int JumpToEnv() {
/* find the first choicepoint that may be a catch */
// DBTerm *dbt = Yap_RefToException();
while (handler && Yap_PredForChoicePt(handler, NULL) != PredDollarCatch) {
//printf("--handler=%p, max=%p\n", handler, LCL0-LOCAL_CBorder);
while (POP_CHOICE_POINT(handler)) {
POP_FAIL_EXECUTE(handler);
}
if (handler == (choiceptr)(LCL0-LOCAL_CBorder)) {
break;
}
/* we are already doing a catch */
/* make sure we prune C-choicepoints */
if (handler->cp_ap == NOCODE &&
(handler >= (choiceptr)(LCL0 - LOCAL_CBorder) ||
handler->cp_b == NULL)) {
if ((handler->cp_ap == NOCODE && handler->cp_b == NULL) ||
(handler->cp_b >= (choiceptr)(LCL0 - LOCAL_CBorder))) {
break;
}
handler = handler->cp_b;
@ -2065,7 +2074,7 @@ static Int JumpToEnv() {
bool Yap_JumpToEnv(Term t) {
CACHE_REGS
LOCAL_BallTerm = Yap_StoreTermInDB(t, 0);
LOCAL_BallTerm = Yap_StoreTermInDB(t, 0);
if (!LOCAL_BallTerm)
return false;
if (LOCAL_PrologMode & TopGoalMode)
@ -2080,20 +2089,20 @@ static Int jump_env(USES_REGS1) {
Yap_Error(INSTANTIATION_ERROR, t, "throw ball must be bound");
return false;
} else if (IsApplTerm(t) && FunctorOfTerm(t) == FunctorError) {
Term t2, te;
Term t2;
Yap_find_prolog_culprit(PASS_REGS1);
// LOCAL_Error_TYPE = ERROR_EVENT;
t = ArgOfTerm(1, t);
if (IsApplTerm(t) && IsAtomTerm((t2 = ArgOfTerm(1, t)))) {
LOCAL_ActiveError.errorAsText = AtomOfTerm(t2);
LOCAL_ActiveError.classAsText = NameOfFunctor(FunctorOfTerm(t));
LOCAL_ActiveError->errorAsText = AtomOfTerm(t2);
LOCAL_ActiveError->classAsText = NameOfFunctor(FunctorOfTerm(t));
} else if (IsAtomTerm(t)) {
LOCAL_ActiveError.errorAsText = AtomOfTerm(t);
LOCAL_ActiveError.classAsText = NULL;
LOCAL_ActiveError->errorAsText = AtomOfTerm(t);
LOCAL_ActiveError->classAsText = NULL;
}
} else {
//LOCAL_Error_TYPE = THROW_EVENT;
// LOCAL_Error_TYPE = THROW_EVENT;
}
LOCAL_ActiveError->prologPredName = NULL;
Yap_PutException(t);
@ -2115,27 +2124,27 @@ static Int generate_pred_info(USES_REGS1) {
void Yap_InitYaamRegs(int myworker_id) {
Term h0var;
// getchar();
// getchar();
#if PUSH_REGS
/* Guarantee that after a longjmp we go back to the original abstract
machine registers */
/* Guarantee that after a longjmp we go back to the original abstract
machine registers */
#ifdef THREADS
if (myworker_id) {
REGSTORE *rs = REMOTE_ThreadHandle(myworker_id).default_yaam_regs;
pthread_setspecific(Yap_yaamregs_key, (const void *)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
Yap_regp = &Yap_standard_regs;
#endif
#endif /* PUSH_REGS */
CACHE_REGS
Yap_ResetException(worker_id);
Yap_ResetException(worker_id);
Yap_PutValue(AtomBreak, MkIntTerm(0));
TR = (tr_fr_ptr)REMOTE_TrailBase(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);
CurrentTrailTop = (tr_fr_ptr)(REMOTE_TrailTop(myworker_id) - MinTrailGap);
/* notice that an initial choice-point and environment
@ -2159,12 +2168,12 @@ void Yap_InitYaamRegs(int myworker_id) {
#ifdef YAPOR_SBA