Merge branch 'master' of http://www.github.com/vscosta/yap-6.3
This commit is contained in:
commit
477772e703
203
#.gitignore#
Normal file
203
#.gitignore#
Normal 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
2
#GitSHA1.c.in#
Normal file
@ -0,0 +1,2 @@
|
||||
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee#define GIT_SHA1 "@GIT_SHA1@"
|
||||
const char g_GIT_SHA1[] = GIT_SHA1;
|
@ -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"
|
||||
WITH_VARS="swig|yes|WITH_SWIG gecode|yes|WITH_GECODE R|yes|WITH_REAL cudd|yes|WITH_BDD python|yes|WITH_PYTHON "
|
||||
ENABLE_VARS="clpbn|yes|WITH_CLPBN \
|
||||
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
6
.ctags
@ -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
|
||||
|
||||
|
14
.gitignore
vendored
14
.gitignore
vendored
@ -80,15 +80,11 @@ GitSHA1.c
|
||||
CMakeLists.txt.*
|
||||
FindPackageLog.txt
|
||||
GitSHA1.c
|
||||
|
||||
GitSHA1.c
|
||||
|
||||
clang
|
||||
cmake-build-debug
|
||||
os/YapIOConfig.h
|
||||
|
||||
os/YapIOConfig.h
|
||||
|
||||
os/YapIOConfig.h
|
||||
|
||||
CodeBlocks
|
||||
x
|
||||
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
|
||||
|
||||
*.gch
|
||||
mxe
|
||||
build
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*************************************************************************
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
@ -78,7 +78,7 @@ void *my_malloc(size_t sz) {
|
||||
p = malloc(sz);
|
||||
// Yap_DebugPuts(stderr,"gof\n");
|
||||
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)
|
||||
__android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "+ %d %p", write_malloc,
|
||||
p);
|
||||
@ -90,7 +90,7 @@ void *my_realloc(void *ptr, size_t sz) {
|
||||
|
||||
p = realloc(ptr, sz);
|
||||
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");
|
||||
if (sz > 500 && write_malloc++ > 0)
|
||||
__android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "* %d %p", write_malloc,
|
||||
|
@ -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
|
||||
|
@ -111,7 +111,7 @@ static char SccsId[] = "%W% %G%";
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
|
||||
|
||||
|
||||
|
49
C/arith1.c
49
C/arith1.c
@ -20,9 +20,9 @@ static char SccsId[] = "%W% %G%";
|
||||
|
||||
/**
|
||||
@file arith1.c
|
||||
|
||||
|
||||
@addtogroup arithmetic_operators
|
||||
|
||||
|
||||
- <b>exp( _X_) [ISO]</b><p> @anchor exp_1
|
||||
|
||||
Natural exponential.
|
||||
@ -109,7 +109,7 @@ static char SccsId[] = "%W% %G%";
|
||||
|
||||
- <b>integer( _X_)</b><p> @anchor integer_1_op
|
||||
|
||||
If _X_ evaluates to a float, the integer between the value of _X_ and 0 closest to the value of _X_, else if _X_ evaluates to an
|
||||
If _X_ evaluates to a float, the integer between the value of _X_ and 0 closest to the value of _X_, else if _X_ evaluates to an
|
||||
integer, the value of _X_.
|
||||
|
||||
- <b>float( _X_) [ISO]</b><p> @anchor float_1_op
|
||||
@ -178,7 +178,7 @@ A = 3602879701896397 rdiv 36028797018963968
|
||||
Convert the expression _X_ to a rational number or integer. The function is
|
||||
similar to [rational/1](@ref rational_1), but the result is only accurate within the
|
||||
rounding error of floating point numbers, generally producing a much
|
||||
smaller denominator.
|
||||
smaller denominator.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~prolog
|
||||
?- A is rationalize(0.25).
|
||||
@ -228,7 +228,7 @@ X is Y*10+C-48.
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
|
||||
static Term
|
||||
float_to_int(Float v USES_REGS)
|
||||
@ -298,24 +298,24 @@ get_float(Term t) {
|
||||
#else
|
||||
static
|
||||
double my_rint(double x)
|
||||
{
|
||||
double y, z;
|
||||
Int n;
|
||||
|
||||
if (x >= 0) {
|
||||
y = x + 0.5;
|
||||
z = floor(y);
|
||||
n = (Int) z;
|
||||
{
|
||||
double y, z;
|
||||
Int n;
|
||||
|
||||
if (x >= 0) {
|
||||
y = x + 0.5;
|
||||
z = floor(y);
|
||||
n = (Int) z;
|
||||
if (y == z && n % 2)
|
||||
return(z-1);
|
||||
} else {
|
||||
y = x - 0.5;
|
||||
z = ceil(y);
|
||||
n = (Int) z;
|
||||
return(z-1);
|
||||
} else {
|
||||
y = x - 0.5;
|
||||
z = ceil(y);
|
||||
n = (Int) z;
|
||||
if (y == z && n % 2)
|
||||
return(z+1);
|
||||
return(z+1);
|
||||
}
|
||||
return(z);
|
||||
return(z);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -412,7 +412,7 @@ eval1(Int fi, Term t USES_REGS) {
|
||||
{
|
||||
#ifdef USE_GMP
|
||||
Int i = IntegerOfTerm(t);
|
||||
|
||||
|
||||
if (i == Int_MIN) {
|
||||
return Yap_gmp_neg_int(i);
|
||||
}
|
||||
@ -745,7 +745,7 @@ eval1(Int fi, Term t USES_REGS) {
|
||||
if (dbl < 0.0)
|
||||
RBIG_FL(ceil(dbl));
|
||||
else
|
||||
RBIG_FL(floor(dbl));
|
||||
RBIG_FL(floor(dbl));
|
||||
}
|
||||
case op_float:
|
||||
switch (ETypeOfTerm(t)) {
|
||||
@ -967,7 +967,7 @@ Yap_NameOfUnaryOp(int i)
|
||||
return Yap_LookupAtom(InitUnTab[i].OpName);
|
||||
}
|
||||
|
||||
static Int
|
||||
static Int
|
||||
p_unary_is( USES_REGS1 )
|
||||
{ /* X is Y */
|
||||
Term t = Deref(ARG2);
|
||||
@ -1017,7 +1017,7 @@ p_unary_is( USES_REGS1 )
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
static Int
|
||||
static Int
|
||||
p_unary_op_as_integer( USES_REGS1 )
|
||||
{ /* X is Y */
|
||||
Term t = Deref(ARG1);
|
||||
@ -1075,4 +1075,3 @@ Yap_ReInitUnaryExps(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ These are the binary numeric operators currently supported by YAP.
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
|
||||
#include "arith2.h"
|
||||
|
||||
|
@ -102,7 +102,7 @@ The following predicates manipulate arrays:
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "clause.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#include "heapgc.h"
|
||||
#if HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
|
1152
C/atomic.c
Normal file → Executable file
1152
C/atomic.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
@ -28,10 +28,11 @@ static char SccsId[] = "%W% %G%";
|
||||
#define NULL (void *)0
|
||||
#endif
|
||||
|
||||
/** @{ */
|
||||
/** @file attvars.c
|
||||
@{ */
|
||||
|
||||
/** @defgroup AttributeVariables_Builtins Implementation of Attribute
|
||||
Declarations
|
||||
/**
|
||||
* @defgroup AttributeVariables_Builtins Implementation of Attribute Declarations
|
||||
@ingroup AttributeVariables
|
||||
*/
|
||||
|
||||
|
@ -30,7 +30,7 @@ static char SccsId[] = "%W% %G%";
|
||||
|
||||
#ifdef USE_GMP
|
||||
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#include "alloc.h"
|
||||
|
||||
Term
|
||||
|
141
C/c_interface.c
141
C/c_interface.c
@ -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);
|
||||
@ -399,11 +426,11 @@ X_API Term YAP_MkAtomTerm(Atom n) {
|
||||
X_API Atom YAP_AtomOfTerm(Term t) { return (AtomOfTerm(t)); }
|
||||
|
||||
X_API bool YAP_IsWideAtom(Atom a) {
|
||||
const unsigned char *s = RepAtom(a)->UStrOfAE;
|
||||
int32_t v;
|
||||
const unsigned char *s = RepAtom(a)->UStrOfAE;
|
||||
int32_t v;
|
||||
while (*s) {
|
||||
size_t n = get_utf8(s,1,&v);
|
||||
if (n>1)
|
||||
size_t n = get_utf8(s, 1, &v);
|
||||
if (n > 1)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -419,15 +446,15 @@ X_API const char *YAP_AtomName(Atom a) {
|
||||
X_API const wchar_t *YAP_WideAtomName(Atom a) {
|
||||
int32_t v;
|
||||
const unsigned char *s = RepAtom(a)->UStrOfAE;
|
||||
size_t n = strlen_utf8( s );
|
||||
wchar_t *dest = Malloc( (n+1)* sizeof(wchar_t)), *o = dest;
|
||||
size_t n = strlen_utf8(s);
|
||||
wchar_t *dest = Malloc((n + 1) * sizeof(wchar_t)), *o = dest;
|
||||
while (*s) {
|
||||
size_t n = get_utf8(s,1,&v);
|
||||
if (n==0)
|
||||
return NULL;
|
||||
size_t n = get_utf8(s, 1, &v);
|
||||
if (n == 0)
|
||||
return NULL;
|
||||
*o++ = v;
|
||||
}
|
||||
o[0] = '\0';
|
||||
o[0] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
@ -453,9 +480,8 @@ X_API Atom YAP_LookupWideAtom(const wchar_t *c) {
|
||||
CACHE_REGS
|
||||
Atom a;
|
||||
|
||||
|
||||
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 (!Yap_locked_growheap(FALSE, 0, NULL)) {
|
||||
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)) {
|
||||
return RepAtom(at)->rep.blob->length;
|
||||
}
|
||||
unsigned char *c = RepAtom(at)->UStrOfAE;
|
||||
|
||||
return strlen_utf8(c);
|
||||
unsigned char *c = RepAtom(at)->UStrOfAE;
|
||||
|
||||
return strlen_utf8(c);
|
||||
}
|
||||
|
||||
X_API Term YAP_MkVarTerm(void) {
|
||||
@ -1376,10 +1401,14 @@ X_API Term YAP_ReadBuffer(const char *s, Term *tp) {
|
||||
Term tv, t;
|
||||
BACKUP_H();
|
||||
|
||||
if (*tp) tv = *tp; else tv = 0;
|
||||
if (*tp)
|
||||
tv = *tp;
|
||||
else
|
||||
tv = 0;
|
||||
LOCAL_ErrorMessage = NULL;
|
||||
while (!(t = Yap_StringToTerm(s, strlen(s) + 1, &LOCAL_encoding,
|
||||
GLOBAL_MaxPriority,tv))) {
|
||||
const unsigned char *us = (const unsigned char *)s;
|
||||
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)) {
|
||||
@ -1636,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;
|
||||
@ -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),
|
||||
// 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;
|
||||
@ -2107,7 +2135,7 @@ X_API void YAP_Write(Term t, FILE *f, int flags) {
|
||||
RECOVER_MACHINE_REGS();
|
||||
}
|
||||
|
||||
X_API Term YAP_CopyTerm(Term t) {
|
||||
X_API YAP_Term YAP_CopyTerm(Term t) {
|
||||
Term tn;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
@ -2115,21 +2143,25 @@ X_API Term YAP_CopyTerm(Term t) {
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
|
||||
return tn;
|
||||
return (tn);
|
||||
}
|
||||
|
||||
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
|
||||
@ -2251,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 {
|
||||
@ -2269,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;
|
||||
@ -2280,7 +2321,7 @@ static void start_modules(void) {
|
||||
}
|
||||
|
||||
/// 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
|
||||
that wants to control Yap */
|
||||
@ -2294,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
|
||||
@ -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)
|
||||
Yap_init_yapor_global_local_memory();
|
||||
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
|
||||
GLOBAL_PrologShouldHandleInterrupts = yap_init->PrologShouldHandleInterrupts;
|
||||
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_argv = yap_init->Argv;
|
||||
GLOBAL_argc = yap_init->Argc;
|
||||
if (0 && ((YAP_QLY && yap_init->SavedState) ||
|
||||
(YAP_BOOT_PL && (yap_init->YapPrologBootFile)))) {
|
||||
@ -2368,10 +2410,10 @@ YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
|
||||
//
|
||||
|
||||
CACHE_REGS
|
||||
if (Yap_embedded)
|
||||
if (yap_init->QuietMode) {
|
||||
setVerbosity(TermSilent);
|
||||
}
|
||||
if (Yap_embedded)
|
||||
if (yap_init->QuietMode) {
|
||||
setVerbosity(TermSilent);
|
||||
}
|
||||
{
|
||||
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);
|
||||
}
|
||||
start_modules();
|
||||
YAP_initialized = true;
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -3209,10 +3252,10 @@ size_t YAP_UTF8_TextLength(Term t) {
|
||||
Term hd = HeadOfTerm(t);
|
||||
if (IsAtomTerm(hd)) {
|
||||
Atom at = AtomOfTerm(hd);
|
||||
unsigned char *s = RepAtom(at)->UStrOfAE;
|
||||
int32_t ch;
|
||||
get_utf8(s, 1, &ch);
|
||||
c = ch;
|
||||
unsigned char *s = RepAtom(at)->UStrOfAE;
|
||||
int32_t ch;
|
||||
get_utf8(s, 1, &ch);
|
||||
c = ch;
|
||||
} else if (IsIntegerTerm(hd)) {
|
||||
c = IntegerOfTerm(hd);
|
||||
} else {
|
||||
@ -3223,8 +3266,8 @@ size_t YAP_UTF8_TextLength(Term t) {
|
||||
}
|
||||
} else if (IsAtomTerm(t)) {
|
||||
Atom at = AtomOfTerm(t);
|
||||
sz = strlen(RepAtom(at)->StrOfAE);
|
||||
} else if (IsStringTerm(t)) {
|
||||
sz = strlen(RepAtom(at)->StrOfAE);
|
||||
} else if (IsStringTerm(t)) {
|
||||
sz = strlen(StringOfTerm(t));
|
||||
}
|
||||
return sz;
|
||||
|
@ -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
|
||||
|
26
C/cmppreds.c
26
C/cmppreds.c
@ -57,7 +57,7 @@ static char SccsId[] = "%W% %G%";
|
||||
#include "Yap.h"
|
||||
#include "YapHeap.h"
|
||||
#include "Yatom.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#if HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
@ -83,7 +83,7 @@ static Int a_gen_ge(Term, Term);
|
||||
#define rfloat(X) (X > 0.0 ? 1 : (X == 0.0 ? 0 : -1))
|
||||
|
||||
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,
|
||||
@ -382,7 +382,7 @@ inline static Int compare(Term t1, Term t2) /* compare terms t1 and t2 */
|
||||
if (f != FunctorDot)
|
||||
return strcmp(".", RepAtom(NameOfFunctor(f))->StrOfAE);
|
||||
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) {
|
||||
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)) {
|
||||
Yap_ThrowError( INSTANTIATION_ERROR, t1, 4, "while doing arithmetic comparison" );
|
||||
Yap_ArithError(INSTANTIATION_ERROR, t2,
|
||||
"while doing arithmetic comparison");
|
||||
}
|
||||
if (IsFloatTerm(t1) && IsFloatTerm(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);
|
||||
#if HAVE_ISNAN
|
||||
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
|
||||
return flt_cmp(i1 - f2);
|
||||
@ -636,7 +639,8 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) {
|
||||
Float f1 = FloatOfTerm(t1);
|
||||
#if HAVE_ISNAN
|
||||
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
|
||||
t2 = Yap_Eval(t2);
|
||||
@ -652,8 +656,9 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) {
|
||||
Float f2 = FloatOfTerm(t2);
|
||||
#if HAVE_ISNAN
|
||||
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
|
||||
return flt_cmp(f1 - f2);
|
||||
#ifdef USE_GMP
|
||||
@ -674,7 +679,8 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) {
|
||||
Float f2 = FloatOfTerm(t2);
|
||||
#if HAVE_ISNAN
|
||||
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
|
||||
return Yap_gmp_cmp_big_float(t1, f2);
|
||||
|
23
C/compiler.c
23
C/compiler.c
@ -174,7 +174,7 @@ static char SccsId[] = "%W% %G%";
|
||||
#include "Yap.h"
|
||||
#include "alloc.h"
|
||||
#include "clause.h"
|
||||
#include "compile.h"
|
||||
#include "YapCompile.h"
|
||||
#include "yapio.h"
|
||||
#if HAVE_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];
|
||||
|
||||
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();
|
||||
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];
|
||||
|
||||
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();
|
||||
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;
|
||||
|
||||
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();
|
||||
siglongjmp(cglobs->cint.CompilerBotch, 1);
|
||||
}
|
||||
i2 = IntegerOfTerm(t2);
|
||||
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();
|
||||
siglongjmp(cglobs->cint.CompilerBotch, 1);
|
||||
|
||||
}
|
||||
if (IsNumTerm(t1)) {
|
||||
/* 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)) {
|
||||
char s[32];
|
||||
|
||||
LOCAL_Error_TYPE = TYPE_ERROR_ATOM;
|
||||
Yap_bip_name(Op, s);
|
||||
sprintf(LOCAL_ErrorMessage, "compiling functor/3");
|
||||
Yap_ThrowError(TYPE_ERROR_ATOM, t2, 4, "compiling functor/3");
|
||||
save_machine_regs();
|
||||
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 {
|
||||
char s[32];
|
||||
|
||||
LOCAL_Error_TYPE = TYPE_ERROR_INTEGER;
|
||||
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();
|
||||
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;
|
||||
Yap_bip_name(Op, s);
|
||||
Yap_ThrowError(TYPE_ERROR_COMPOUND, t2, 1, "compiling %s/2", 1, s);
|
||||
|
||||
save_machine_regs();
|
||||
siglongjmp(cglobs->cint.CompilerBotch, 1);
|
||||
} else if (IsApplTerm(t2)) {
|
||||
@ -1476,7 +1477,7 @@ static void c_goal(Term Goal, Term mod, compiler_struct *cglobs) {
|
||||
PredEntry *p;
|
||||
Prop p0;
|
||||
|
||||
Goal = Yap_YapStripModule( Goal, &mod);
|
||||
Goal = Yap_YapStripModule(Goal, &mod);
|
||||
if (IsVarTerm(Goal)) {
|
||||
Goal = Yap_MkApplTerm(FunctorCall, 1, &Goal);
|
||||
} else if (IsNumTerm(Goal)) {
|
||||
|
@ -54,13 +54,13 @@ static char SccsId[] = "%W% %G%";
|
||||
|
||||
/*
|
||||
* This file includes a set of utilities, useful to the several compilation
|
||||
* modules
|
||||
* modules
|
||||
*/
|
||||
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "compile.h"
|
||||
#include "YapCompile.h"
|
||||
#include "yapio.h"
|
||||
#if HAVE_STRING_H
|
||||
#include <string.h>
|
||||
@ -69,7 +69,7 @@ static char SccsId[] = "%W% %G%";
|
||||
|
||||
/*
|
||||
* The compiler creates an instruction chain which will be assembled after
|
||||
* afterwards
|
||||
* afterwards
|
||||
*/
|
||||
|
||||
|
||||
@ -146,7 +146,7 @@ AllocCMem (UInt size, struct intermediates *cip)
|
||||
LOCAL_Error_Size = 256+((char *)cip->freep - (char *)HR);
|
||||
save_machine_regs();
|
||||
siglongjmp(cip->CompilerBotch, OUT_OF_STACK_BOTCH);
|
||||
}
|
||||
}
|
||||
p = cip->freep;
|
||||
cip->freep += size;
|
||||
return p;
|
||||
@ -216,7 +216,7 @@ is_a_test(Term arg, Term mod)
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return pe->PredFlags & (TestPredFlag|BinaryPredFlag);
|
||||
}
|
||||
}
|
||||
@ -315,7 +315,7 @@ Yap_emit_6ops (compiler_vm_op o, CELL r1, CELL r2, CELL r3, CELL r4, CELL r5, CE
|
||||
p->rnd1 = r1;
|
||||
p->rnd2 = r2;
|
||||
p->rnd3 = r3;
|
||||
p->rnd4 = r4;
|
||||
p->rnd4 = r4;
|
||||
p->rnd5 = r5;
|
||||
p->rnd6 = r6;
|
||||
p->nextInst = NIL;
|
||||
@ -337,7 +337,7 @@ Yap_emit_7ops (compiler_vm_op o, CELL r1, CELL r2, CELL r3, CELL r4, CELL r5, CE
|
||||
p->rnd1 = r1;
|
||||
p->rnd2 = r2;
|
||||
p->rnd3 = r3;
|
||||
p->rnd4 = r4;
|
||||
p->rnd4 = r4;
|
||||
p->rnd5 = r5;
|
||||
p->rnd6 = r6;
|
||||
p->rnd7 = r7;
|
||||
@ -520,7 +520,7 @@ write_special_label(special_label_op arg, special_label_id rn, UInt lab)
|
||||
Yap_DebugErrorPuts("fail");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -616,7 +616,7 @@ ShowOp (compiler_vm_op ic, const char *f, struct PSEUDO *cpc)
|
||||
Yap_DebugPlWrite(MkIntegerTerm((Int)(*ptr++)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case 'l':
|
||||
write_address (arg);
|
||||
break;
|
||||
@ -645,7 +645,7 @@ ShowOp (compiler_vm_op ic, const char *f, struct PSEUDO *cpc)
|
||||
Yap_DebugPlWrite (MkIntTerm ((v->NoOfVE) & MaskVarAdrs));
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case 'N':
|
||||
{
|
||||
Ventry *v;
|
||||
@ -795,4 +795,3 @@ Yap_ShowCode (struct intermediates *cint)
|
||||
}
|
||||
|
||||
#endif /* DEBUG */
|
||||
|
||||
|
@ -22,7 +22,7 @@ static char SccsId[] = "%W% %G%";
|
||||
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
|
||||
#ifdef DEPTH_LIMIT
|
||||
|
||||
|
30
C/errors.c
30
C/errors.c
@ -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) {
|
||||
@ -311,24 +311,24 @@ yap_error_descriptor_t *Yap_popErrorContext(void) {
|
||||
}
|
||||
|
||||
void Yap_ThrowError__(const char *file, const char *function, int lineno,
|
||||
yap_error_number type, Term where, ...) {
|
||||
va_list ap;
|
||||
char tmpbuf[MAXPATHLEN];
|
||||
yap_error_number type, Term where, ...) {
|
||||
va_list ap;
|
||||
char tmpbuf[MAXPATHLEN];
|
||||
|
||||
va_start(ap, where);
|
||||
char *format = va_arg(ap, char *);
|
||||
if (format != NULL) {
|
||||
va_start(ap, where);
|
||||
char *format = va_arg(ap, char *);
|
||||
if (format != NULL) {
|
||||
#if HAVE_VSNPRINTF
|
||||
(void)vsnprintf(tmpbuf, MAXPATHLEN - 1, format, ap);
|
||||
(void)vsnprintf(tmpbuf, MAXPATHLEN - 1, format, ap);
|
||||
#else
|
||||
(void)vsprintf(tnpbuf, format, ap);
|
||||
(void)vsprintf(tnpbuf, format, ap);
|
||||
#endif
|
||||
// fprintf(stderr, "warning: ");
|
||||
Yap_Error__(file, function, lineno, type, where, tmpbuf);
|
||||
} else {
|
||||
Yap_Error__(file, function, lineno, type, where);
|
||||
}
|
||||
siglongjmp(LOCAL_RestartEnv, 4);
|
||||
// fprintf(stderr, "warning: ");
|
||||
Yap_Error__(file, function, lineno, type, where, tmpbuf);
|
||||
} else {
|
||||
Yap_Error__(file, function, lineno, type, where);
|
||||
}
|
||||
siglongjmp(*LOCAL_RestartEnv, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
2
C/eval.c
2
C/eval.c
@ -31,7 +31,7 @@ static char SccsId[] = "%W% %G%";
|
||||
|
||||
#include "YapHeap.h"
|
||||
#include "Yatom.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#if HAVE_STDARG_H
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
|
212
C/exec.c
212
C/exec.c
@ -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);
|
||||
@ -315,9 +315,9 @@ inline static bool do_execute(Term t, Term mod USES_REGS) {
|
||||
/* I cannot use the standard macro here because
|
||||
otherwise I would dereference the argument and
|
||||
might skip a svar */
|
||||
if (pen->PredFlags & MetaPredFlag) {
|
||||
return CallMetaCall(t, mod PASS_REGS);
|
||||
}
|
||||
if (pen->PredFlags & MetaPredFlag) {
|
||||
return CallMetaCall(t, mod PASS_REGS);
|
||||
}
|
||||
pt = RepAppl(t) + 1;
|
||||
for (i = 1; i <= arity; i++) {
|
||||
#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;
|
||||
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 */
|
||||
@ -1441,30 +1444,35 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
|
||||
LOCAL_PrologMode = UserMode;
|
||||
P = (yamop *)FAILCODE;
|
||||
} break;
|
||||
case 2: {
|
||||
/* arithmetic exception */
|
||||
/* must be done here, otherwise siglongjmp will clobber all the
|
||||
* registers
|
||||
*/
|
||||
Yap_Error(LOCAL_Error_TYPE, TermNil, NULL);
|
||||
/* reset the registers so that we don't have trash in abstract
|
||||
* machine */
|
||||
Yap_set_fpu_exceptions(
|
||||
getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG));
|
||||
P = (yamop *)FAILCODE;
|
||||
LOCAL_PrologMode = UserMode;
|
||||
} break;
|
||||
case 4: {
|
||||
P = (yamop *)FAILCODE;
|
||||
LOCAL_PrologMode = UserMode;
|
||||
} break;
|
||||
case 2: {
|
||||
/* arithmetic exception */
|
||||
/* must be done here, otherwise siglongjmp will clobber all the
|
||||
* registers
|
||||
*/
|
||||
/* reset the registers so that we don't have trash in abstract
|
||||
* machine */
|
||||
Yap_set_fpu_exceptions(
|
||||
getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG));
|
||||
P = (yamop *)FAILCODE;
|
||||
LOCAL_PrologMode = UserMode;
|
||||
} break;
|
||||
case 3: { /* saved state */
|
||||
LOCAL_CBorder = OldBorder;
|
||||
LOCAL_RestartEnv = sighold;
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
/* do nothing */
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
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())
|
||||
CalculateStackGap(PASS_REGS1);
|
||||
LOCAL_CBorder = OldBorder;
|
||||
LOCAL_RestartEnv = sighold;
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -1527,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();
|
||||
@ -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) {
|
||||
CACHE_REGS
|
||||
return exec_absmi(top, has_reset PASS_REGS);
|
||||
return exec_absmi(top, has_reset PASS_REGS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1557,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 */
|
||||
@ -1576,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
|
||||
@ -1603,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 */
|
||||
@ -1688,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;
|
||||
@ -1725,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
|
||||
@ -1743,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;
|
||||
@ -1751,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");
|
||||
@ -1764,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;
|
||||
@ -1796,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);
|
||||
@ -1806,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,
|
||||
@ -1822,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]));
|
||||
@ -1852,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);
|
||||
@ -1966,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 */
|
||||
@ -2015,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;
|
||||
@ -2062,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)
|
||||
@ -2077,19 +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);
|
||||
te = ArgOfTerm(1, t);
|
||||
if (IsApplTerm(te) && IsAtomTerm((t2 = ArgOfTerm(1, te)))) {
|
||||
// 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(te));
|
||||
} else if (IsAtomTerm(te)) {
|
||||
LOCAL_ActiveError->errorAsText = AtomOfTerm(te);
|
||||
LOCAL_ActiveError->classAsText = NameOfFunctor(FunctorOfTerm(t));
|
||||
} else if (IsAtomTerm(t)) {
|
||||
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);
|
||||
@ -2111,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
|
||||
@ -2155,12 +2168,12 @@ void Yap_InitYaamRegs(int myworker_id) {
|
||||
#ifdef YAPOR_SBA
|
||||
BSEG =
|
||||
#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);
|
||||
#endif /* FROZEN_STACKS */
|
||||
CalculateStackGap(PASS_REGS1);
|
||||
/* the first real choice-point will also have AP=FAIL */
|
||||
/* always have an empty slots for people to use */
|
||||
/* the first real choice-point will also have AP=FAIL */
|
||||
/* always have an empty slots for people to use */
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
LOCAL = REMOTE(myworker_id);
|
||||
worker_id = myworker_id;
|
||||
@ -2175,7 +2188,7 @@ void Yap_InitYaamRegs(int myworker_id) {
|
||||
REMOTE_GcGeneration(myworker_id) = Yap_NewTimedVar(h0var);
|
||||
REMOTE_GcCurrentPhase(myworker_id) = 0L;
|
||||
REMOTE_GcPhase(myworker_id) =
|
||||
Yap_NewTimedVar(MkIntTerm(REMOTE_GcCurrentPhase(myworker_id)));
|
||||
Yap_NewTimedVar(MkIntTerm(REMOTE_GcCurrentPhase(myworker_id)));
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
PP = NULL;
|
||||
PREG_ADDR = NULL;
|
||||
@ -2188,7 +2201,7 @@ void Yap_InitYaamRegs(int myworker_id) {
|
||||
#ifdef YAPOR_SBA
|
||||
BSEG =
|
||||
#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);
|
||||
#endif /* FROZEN_STACKS */
|
||||
CalculateStackGap(PASS_REGS1);
|
||||
@ -2201,7 +2214,7 @@ void Yap_InitYaamRegs(int myworker_id) {
|
||||
|
||||
Term Yap_GetException(void) {
|
||||
CACHE_REGS
|
||||
Term t = 0;
|
||||
Term t = 0;
|
||||
|
||||
if (LOCAL_BallTerm) {
|
||||
t = Yap_PopTermFromDB(LOCAL_BallTerm);
|
||||
@ -2220,8 +2233,8 @@ bool Yap_RaiseException(void) {
|
||||
|
||||
bool Yap_PutException(Term t) {
|
||||
CACHE_REGS
|
||||
if ((LOCAL_BallTerm = Yap_StoreTermInDB(t, 0)) != NULL)
|
||||
return true;
|
||||
if ((LOCAL_BallTerm = Yap_StoreTermInDB(t, 0)) != NULL)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -2231,7 +2244,6 @@ bool Yap_ResetException(int wid) {
|
||||
Yap_PopTermFromDB(REMOTE_ActiveError(wid)->errorTerm);
|
||||
}
|
||||
REMOTE_ActiveError(wid)->errorTerm = NULL;
|
||||
REMOTE_ActiveError(wid)->errorTerm = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2270,7 +2282,7 @@ int Yap_dogc(int extra_args, Term *tp USES_REGS) {
|
||||
|
||||
void Yap_InitExecFs(void) {
|
||||
CACHE_REGS
|
||||
Term cm = CurrentModule;
|
||||
Term cm = CurrentModule;
|
||||
Yap_InitComma();
|
||||
Yap_InitCPred("$execute", 1, execute, 0);
|
||||
Yap_InitCPred("$execute", 2, execute2, 0);
|
||||
|
2
C/exo.c
2
C/exo.c
@ -21,7 +21,7 @@
|
||||
#include "Yap.h"
|
||||
#include "clause.h"
|
||||
#include "yapio.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#include "tracer.h"
|
||||
#ifdef YAPOR
|
||||
#include "or.macros.h"
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "Yap.h"
|
||||
#include "clause.h"
|
||||
#include "yapio.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#include "tracer.h"
|
||||
#include "attvar.h"
|
||||
#ifdef YAPOR
|
||||
|
105
C/flags.c
105
C/flags.c
@ -51,16 +51,16 @@ static Term stream(Term inp);
|
||||
static bool getenc(Term inp);
|
||||
static bool typein(Term inp);
|
||||
static bool dqf(Term t2);
|
||||
static bool set_error_stream( Term inp );
|
||||
static bool set_input_stream( Term inp );
|
||||
static bool set_output_stream( Term inp );
|
||||
static bool set_error_stream(Term inp);
|
||||
static bool set_input_stream(Term inp);
|
||||
static bool set_output_stream(Term inp);
|
||||
|
||||
static void newFlag(Term fl, Term val);
|
||||
static Int current_prolog_flag(USES_REGS1);
|
||||
static Int set_prolog_flag(USES_REGS1);
|
||||
|
||||
#include "Yatom.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#include "yapio.h"
|
||||
|
||||
#define YAP_FLAG(ID, NAME, WRITABLE, DEF, INIT, HELPER) \
|
||||
@ -173,41 +173,38 @@ static Term isaccess(Term inp) {
|
||||
}
|
||||
|
||||
static Term stream(Term inp) {
|
||||
if ( IsVarTerm(inp) )
|
||||
if (IsVarTerm(inp))
|
||||
return inp;
|
||||
if (Yap_CheckStream( inp, Input_Stream_f | Output_Stream_f |
|
||||
Append_Stream_f | Socket_Stream_f, "yap_flag/3" ) >= 0)
|
||||
if (Yap_CheckStream(inp, Input_Stream_f | Output_Stream_f | Append_Stream_f |
|
||||
Socket_Stream_f,
|
||||
"yap_flag/3") >= 0)
|
||||
return inp;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static bool
|
||||
set_error_stream( Term inp ) {
|
||||
if( IsVarTerm(inp) )
|
||||
return Yap_unify( inp, Yap_StreamUserName( LOCAL_c_error_stream ) );
|
||||
LOCAL_c_error_stream = Yap_CheckStream( inp, Output_Stream_f |
|
||||
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" );
|
||||
static bool set_error_stream(Term inp) {
|
||||
if (IsVarTerm(inp))
|
||||
return Yap_unify(inp, Yap_StreamUserName(LOCAL_c_error_stream));
|
||||
LOCAL_c_error_stream = Yap_CheckStream(
|
||||
inp, Output_Stream_f | Append_Stream_f | Socket_Stream_f, "yap_flag/3");
|
||||
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" );
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
return Yap_IsGroundTerm(inp) ? inp : TermZERO;
|
||||
@ -669,12 +666,19 @@ static bool setYapFlagInModule(Term tflag, Term t2, Term mod) {
|
||||
flag_term *tarr = GLOBAL_Flags;
|
||||
if (!(fv->type(t2)))
|
||||
return false;
|
||||
|
||||
if (fv->helper && !(fv->helper(t2)))
|
||||
return false;
|
||||
Term tout = tarr[fv->FlagOfVE].at;
|
||||
if (IsVarTerm(tout))
|
||||
Yap_PopTermFromDB(tarr[fv->FlagOfVE].DBT);
|
||||
if (IsAtomOrIntTerm(t2))
|
||||
if (IsVarTerm(tout)) {
|
||||
Term t;
|
||||
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;
|
||||
else {
|
||||
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,
|
||||
flag_term *tarr) {
|
||||
errno = 0;
|
||||
const char *ss = (const char *)s;
|
||||
|
||||
if (f == booleanFlag) {
|
||||
if (!bootstrap) {
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(s, "true")) {
|
||||
const char *ss = (const char *)s;
|
||||
if (!strcmp(ss, "true")) {
|
||||
tarr->at = TermTrue;
|
||||
return true;
|
||||
}
|
||||
if (!strcmp(s, "false")) {
|
||||
if (!strcmp(ss, "false")) {
|
||||
tarr->at = TermFalse;
|
||||
return true;
|
||||
}
|
||||
if (!strcmp(s, "on")) {
|
||||
if (!strcmp(ss, "on")) {
|
||||
tarr->at = TermTrue;
|
||||
return true;
|
||||
}
|
||||
if (!strcmp(s, "off")) {
|
||||
if (!strcmp(ss, "off")) {
|
||||
tarr->at = TermFalse;
|
||||
return true;
|
||||
}
|
||||
@ -1210,7 +1216,7 @@ static bool setInitialValue(bool bootstrap, flag_func f, const char *s,
|
||||
if (!bootstrap) {
|
||||
return 0;
|
||||
}
|
||||
UInt r = strtoul(s, NULL, 10);
|
||||
UInt r = strtoul(ss, NULL, 10);
|
||||
Term t;
|
||||
if (errno) {
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
if (!strcmp(s, "INT_MAX")) {
|
||||
if (!strcmp(ss, "INT_MAX")) {
|
||||
tarr->at = MkIntTerm(Int_MAX);
|
||||
return true;
|
||||
}
|
||||
if (!strcmp(s, "MAX_THREADS")) {
|
||||
if (!strcmp(ss, "MAX_THREADS")) {
|
||||
tarr->at = MkIntTerm(MAX_THREADS);
|
||||
return true;
|
||||
}
|
||||
if (!strcmp(s, "MAX_WORKERS")) {
|
||||
if (!strcmp(ss, "MAX_WORKERS")) {
|
||||
tarr->at = MkIntTerm(MAX_WORKERS);
|
||||
return true;
|
||||
}
|
||||
if (!strcmp(s, "INT_MIN")) {
|
||||
if (!strcmp(ss, "INT_MIN")) {
|
||||
tarr->at = MkIntTerm(Int_MIN);
|
||||
return true;
|
||||
}
|
||||
if (!strcmp(s, "YAP_NUMERIC_VERSION")) {
|
||||
if (!strcmp(ss, "YAP_NUMERIC_VERSION")) {
|
||||
tarr->at = MkIntTerm(atol(YAP_NUMERIC_VERSION));
|
||||
return true;
|
||||
}
|
||||
if (!strcmp(s, "YAP_NUMERIC_VERSION")) {
|
||||
if (!strcmp(ss, "YAP_NUMERIC_VERSION")) {
|
||||
tarr->at = MkIntTerm(atol(YAP_NUMERIC_VERSION));
|
||||
return true;
|
||||
}
|
||||
@ -1297,7 +1303,7 @@ static bool setInitialValue(bool bootstrap, flag_func f, const char *s,
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (strcmp(s, "@boot") == 0) {
|
||||
} else if (strcmp(ss, "@boot") == 0) {
|
||||
if (bootstrap) {
|
||||
return true;
|
||||
}
|
||||
@ -1317,9 +1323,9 @@ static bool setInitialValue(bool bootstrap, flag_func f, const char *s,
|
||||
return false;
|
||||
}
|
||||
CACHE_REGS
|
||||
encoding_t encoding = ENC_ISO_UTF8;
|
||||
t0 =
|
||||
Yap_StringToTerm(s, strlen(s) + 1, &encoding, GLOBAL_MaxPriority, 0L);
|
||||
const unsigned char *us = (const unsigned char *)s;
|
||||
t0 = Yap_BufferToTermWithPrioBindings(us, strlen(s) + 1, TermNil,
|
||||
GLOBAL_MaxPriority, 0L);
|
||||
if (!t0)
|
||||
return false;
|
||||
if (IsAtomTerm(t0) || IsIntTerm(t0)) {
|
||||
@ -1570,7 +1576,7 @@ static Int do_create_prolog_flag(USES_REGS1) {
|
||||
fv->type = isground;
|
||||
} break;
|
||||
case PROLOG_FLAG_PROPERTY_SCOPE:
|
||||
free(args);
|
||||
free(args);
|
||||
return false;
|
||||
case PROLOG_FLAG_PROPERTY_END:
|
||||
break;
|
||||
@ -1621,8 +1627,9 @@ void Yap_InitFlags(bool bootstrap) {
|
||||
while (f->name != NULL) {
|
||||
bool itf = setInitialValue(bootstrap, f->def, f->init,
|
||||
LOCAL_Flags + LOCAL_flagCount);
|
||||
// Term itf = Yap_StringToTerm(f->init, strlen(f->init)+1,
|
||||
// EBC_ISO_UTF8, GLOBAL_MaxPriority, &tp);
|
||||
// Term itf = Yap_BufferToTermWithPrioBindings(f->init,
|
||||
// strlen(f->init)+1,
|
||||
// LOBAL_MaxPriority, &tp);
|
||||
if (itf) {
|
||||
initFlag(f, LOCAL_flagCount, false);
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ threads that are created <em>after</em> the registration.
|
||||
#include "YapHeap.h"
|
||||
#include "yapio.h"
|
||||
#include "iopreds.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#include "attvar.h"
|
||||
#include <math.h>
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#if HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
2
C/grow.c
2
C/grow.c
@ -20,7 +20,7 @@
|
||||
#include "yapio.h"
|
||||
#include "alloc.h"
|
||||
#include "sshift.h"
|
||||
#include "compile.h"
|
||||
#include "YapCompile.h"
|
||||
#include "attvar.h"
|
||||
#include "cut_c.h"
|
||||
#if HAVE_STRING_H
|
||||
|
13
C/heapgc.c
13
C/heapgc.c
@ -134,7 +134,7 @@ gc_growtrail(int committed, tr_fr_ptr begsTR, cont *old_cont_top0 USES_REGS)
|
||||
#endif
|
||||
/* could not find more trail */
|
||||
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) {
|
||||
/* could not find more trail */
|
||||
save_machine_regs();
|
||||
siglongjmp(LOCAL_gc_restore, 2);
|
||||
siglongjmp(*LOCAL_gc_restore, 2);
|
||||
}
|
||||
rc = TR-n;
|
||||
}
|
||||
@ -525,7 +525,7 @@ pop_registers(Int num_regs, yamop *nextop USES_REGS)
|
||||
/* error: we don't have enough room */
|
||||
/* could not find more trail */
|
||||
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 */
|
||||
/* could not find more trail */
|
||||
save_machine_regs();
|
||||
siglongjmp(LOCAL_gc_restore, 3);
|
||||
siglongjmp(*LOCAL_gc_restore, 3);
|
||||
} else if (n > 0) {
|
||||
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 alloc_sz;
|
||||
int jmp_res;
|
||||
sigjmp_buf jmp;
|
||||
|
||||
LOCAL_gc_restore = &jmp;
|
||||
|
||||
heap_cells = HR-H0;
|
||||
gc_verbose = is_gc_verbose();
|
||||
@ -3989,7 +3992,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop USES_REGS)
|
||||
}
|
||||
#endif
|
||||
time_start = Yap_cputime();
|
||||
jmp_res = sigsetjmp(LOCAL_gc_restore, 0);
|
||||
jmp_res = sigsetjmp(jmp, 0);
|
||||
if (jmp_res == 2) {
|
||||
UInt sz;
|
||||
|
||||
|
@ -634,7 +634,7 @@ type_of_verb(rest,passive).
|
||||
*/
|
||||
|
||||
#include "absmi.h"
|
||||
#include "compile.h"
|
||||
#include "YapCompile.h"
|
||||
#if DEBUG
|
||||
#include "yapio.h"
|
||||
#endif
|
||||
|
21
C/load_dll.c
21
C/load_dll.c
@ -42,15 +42,15 @@ Yap_FindExecutable(void)
|
||||
void *
|
||||
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) {
|
||||
CACHE_REGS
|
||||
LOCAL_ErrorMessage = NULL;
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, GetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), LOCAL_ErrorMessage, 256,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 1023,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@ -83,17 +83,18 @@ LoadForeign(StringList ofiles, StringList libs,
|
||||
HINSTANCE handle;
|
||||
|
||||
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)
|
||||
{
|
||||
LOCAL_ErrorMessage = NULL;
|
||||
if (*init_proc == NULL)
|
||||
*init_proc = (YapInitProc)GetProcAddress((HMODULE)handle, proc_name);
|
||||
} else {
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, GetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), LOCAL_ErrorMessage, 256,
|
||||
NULL);
|
||||
char *buf = malloc(1024);
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, GetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 1023,
|
||||
NULL);
|
||||
//fprintf(stderr,"WinError: %s\n", LOCAL_ErrorSay);
|
||||
}
|
||||
ofiles = ofiles->next;
|
||||
|
@ -46,7 +46,7 @@ p_load_foreign( USES_REGS1 )
|
||||
YapInitProc InitProc = NULL;
|
||||
Term t, t1;
|
||||
StringList new;
|
||||
Int returncode = FALSE;
|
||||
bool returncode = FALSE;
|
||||
yhandle_t CurSlot = Yap_StartSlots();
|
||||
|
||||
// Yap_DebugPlWrite(ARG1); printf("%s\n", " \n");
|
||||
@ -80,13 +80,17 @@ p_load_foreign( USES_REGS1 )
|
||||
/* get the initialization function name */
|
||||
t1 = Deref(ARG3);
|
||||
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 */
|
||||
if(Yap_LoadForeign(ofiles,libs,InitProcName,&InitProc)==LOAD_SUCCEEDED) {
|
||||
Yap_StartSlots( );
|
||||
(*InitProc)();
|
||||
Yap_CloseSlots(CurSlot);
|
||||
returncode = TRUE;
|
||||
returncode = true;
|
||||
}
|
||||
|
||||
/* I should recover space if load foreign fails */
|
||||
|
@ -48,7 +48,7 @@ deterministic computations.
|
||||
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
|
||||
static Int p_setarg( USES_REGS1 );
|
||||
static Int p_create_mutable( USES_REGS1 );
|
||||
|
@ -141,7 +141,7 @@ dot with single quotes.
|
||||
#include "YapHeap.h"
|
||||
#include "YapText.h"
|
||||
#include "Yatom.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#include "yapio.h"
|
||||
/* stuff we want to use in standard YAP code */
|
||||
#include "iopreds.h"
|
||||
@ -302,7 +302,7 @@ static Term VarNames(VarEntry *p, Term l USES_REGS) {
|
||||
VarNames(p->VarLeft, l PASS_REGS) PASS_REGS));
|
||||
if (HR > ASP - 4096) {
|
||||
save_machine_regs();
|
||||
siglongjmp(LOCAL_IOBotch, 1);
|
||||
longjmp(*LOCAL_IOBotch, 1);
|
||||
}
|
||||
return (o);
|
||||
} else {
|
||||
@ -332,7 +332,7 @@ static Term Singletons(VarEntry *p, Term l USES_REGS) {
|
||||
Singletons(p->VarLeft, l PASS_REGS) PASS_REGS));
|
||||
if (HR > ASP - 4096) {
|
||||
save_machine_regs();
|
||||
siglongjmp(LOCAL_IOBotch, 1);
|
||||
longjmp(*LOCAL_IOBotch, 1);
|
||||
}
|
||||
return (o);
|
||||
} 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));
|
||||
if (HR > ASP - 4096) {
|
||||
save_machine_regs();
|
||||
siglongjmp(LOCAL_IOBotch, 1);
|
||||
siglongjmp(*LOCAL_IOBotch, 1);
|
||||
}
|
||||
return (o);
|
||||
} else {
|
||||
|
@ -21,7 +21,7 @@ static char SccsId[] = "%W% %G%";
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
|
||||
static Int
|
||||
p_in_range( USES_REGS1 ) {
|
||||
|
227
C/scanner.c
227
C/scanner.c
@ -407,7 +407,7 @@ writing, writing a BOM can be requested using the option
|
||||
#include "YapHeap.h"
|
||||
#include "Yatom.h"
|
||||
#include "alloc.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#include "yapio.h"
|
||||
/* stuff we want to use in standard YAP code */
|
||||
#include "YapText.h"
|
||||
@ -1143,17 +1143,17 @@ Term Yap_scan_num(StreamDesc *inp, bool error_on) {
|
||||
out = 0;
|
||||
}
|
||||
#if HAVE_ISWSPACE
|
||||
while (iswspace(ch = getchr(inp)))
|
||||
;
|
||||
while (iswspace(ch = getchr(inp)))
|
||||
;
|
||||
#else
|
||||
while (isspace(ch = getchr(inp)))
|
||||
;
|
||||
while (isspace(ch = getchr(inp)))
|
||||
;
|
||||
#endif
|
||||
if (LOCAL_ErrorMessage != NULL || ch != -1 || cherr) {
|
||||
Yap_clean_tokenizer(old_tr, NULL, NULL);
|
||||
if (error_on)
|
||||
Yap_clean_tokenizer(old_tr, NULL, NULL);
|
||||
if (error_on)
|
||||
Yap_Error(SYNTAX_ERROR, ARG2, "converting number");
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@ -1172,85 +1172,89 @@ Term Yap_scan_num(StreamDesc *inp, bool error_on) {
|
||||
}
|
||||
|
||||
Term Yap_tokRep(void *tokptre) {
|
||||
CACHE_REGS
|
||||
TokEntry *tokptr = tokptre;
|
||||
Term info = tokptr->TokInfo;
|
||||
|
||||
switch (tokptr->Tok) {
|
||||
case Name_tok:
|
||||
if (!info) {
|
||||
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;
|
||||
CACHE_REGS
|
||||
TokEntry *tokptr = tokptre;
|
||||
Term info = tokptr->TokInfo;
|
||||
|
||||
switch (tokptr->Tok) {
|
||||
case Name_tok:
|
||||
if (!info) {
|
||||
info = TermNil;
|
||||
}
|
||||
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) {
|
||||
CACHE_REGS
|
||||
TokEntry *tokptr = tokptre;
|
||||
Term info = tokptr->TokInfo;
|
||||
|
||||
switch (tokptr->Tok) {
|
||||
case eot_tok:
|
||||
return "EOT";
|
||||
case Ponctuation_tok:
|
||||
case Error_tok:
|
||||
case BQString_tok:
|
||||
case String_tok:
|
||||
case Name_tok:
|
||||
return AtomOfTerm(info)->StrOfAE;
|
||||
case QuasiQuotes_tok:
|
||||
return "<QQ>";
|
||||
case Number_tok:
|
||||
if (IsIntegerTerm(info)) {
|
||||
char *s = Malloc(36);
|
||||
snprintf(s, 35, Int_FORMAT, IntegerOfTerm(info));
|
||||
return s;
|
||||
}else if (IsFloatTerm(info)) {
|
||||
char *s = Malloc( 64);
|
||||
snprintf(s, 63, "%6g", FloatOfTerm(info));
|
||||
return s;
|
||||
} else {
|
||||
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;
|
||||
switch (tokptr->Tok) {
|
||||
case eot_tok:
|
||||
return "EOT";
|
||||
case Ponctuation_tok:
|
||||
if (info == Terml)
|
||||
return "(";
|
||||
case Error_tok:
|
||||
case BQString_tok:
|
||||
case String_tok:
|
||||
case Name_tok:
|
||||
return AtomOfTerm(info)->StrOfAE;
|
||||
case QuasiQuotes_tok:
|
||||
return "<QQ>";
|
||||
case Number_tok:
|
||||
if (IsIntegerTerm(info)) {
|
||||
char *s = Malloc(36);
|
||||
snprintf(s, 35, Int_FORMAT, IntegerOfTerm(info));
|
||||
return s;
|
||||
} else if (IsFloatTerm(info)) {
|
||||
char *s = Malloc(64);
|
||||
snprintf(s, 63, "%6g", FloatOfTerm(info));
|
||||
return s;
|
||||
} else {
|
||||
size_t len = Yap_gmp_to_size(info, 10);
|
||||
char *s = Malloc(len + 2);
|
||||
return Yap_gmp_to_string(info, s, len + 1, 10);
|
||||
}
|
||||
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) {
|
||||
CELL *h0 = HR;
|
||||
HR += 5;
|
||||
@ -1311,7 +1315,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
int solo_flag = TRUE;
|
||||
int32_t ch, och;
|
||||
struct qq_struct_t *cur_qq = NULL;
|
||||
int sign = 1;
|
||||
int sign = 1;
|
||||
|
||||
InitScannerMemory();
|
||||
LOCAL_VarTable = NULL;
|
||||
@ -1424,7 +1428,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
Atom ae;
|
||||
/* don't do this in iso */
|
||||
ae = Yap_ULookupAtom(TokImage);
|
||||
Free(TokImage);
|
||||
Free(TokImage);
|
||||
if (ae == NIL) {
|
||||
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);
|
||||
} else {
|
||||
VarEntry *ve = Yap_LookupVar((const char *)TokImage);
|
||||
Free(TokImage);
|
||||
Free(TokImage);
|
||||
t->TokInfo = Unsigned(ve);
|
||||
if (cur_qq) {
|
||||
ve->refs++;
|
||||
@ -1444,14 +1448,14 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
|
||||
} break;
|
||||
|
||||
case NU: {
|
||||
case NU: {
|
||||
int cherr;
|
||||
int cha;
|
||||
sign = 1;
|
||||
sign = 1;
|
||||
|
||||
scan_number:
|
||||
cha = ch;
|
||||
cherr = 0;
|
||||
scan_number:
|
||||
cha = ch;
|
||||
cherr = 0;
|
||||
CHECK_SPACE();
|
||||
if ((t->TokInfo = get_num(&cha, &cherr, inp_stream, sign)) == 0L) {
|
||||
if (p) {
|
||||
@ -1480,8 +1484,8 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
case 'e':
|
||||
case 'E':
|
||||
och = cherr;
|
||||
TokImage = Malloc(1024 PASS_REGS);
|
||||
goto scan_name;
|
||||
TokImage = Malloc(1024 PASS_REGS);
|
||||
goto scan_name;
|
||||
break;
|
||||
case '=':
|
||||
case '_':
|
||||
@ -1513,13 +1517,13 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
{
|
||||
TokEntry *e2;
|
||||
|
||||
if (chtype(ch) == NU) {
|
||||
if (och == '-')
|
||||
sign = -1;
|
||||
else
|
||||
sign = 1;
|
||||
goto scan_number;
|
||||
}
|
||||
if (chtype(ch) == NU) {
|
||||
if (och == '-')
|
||||
sign = -1;
|
||||
else
|
||||
sign = 1;
|
||||
goto scan_number;
|
||||
}
|
||||
t->Tok = Name_tok;
|
||||
if (ch == '(')
|
||||
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";
|
||||
break;
|
||||
}
|
||||
if (ch == EOFCHAR) {
|
||||
break;
|
||||
}
|
||||
if (ch == EOFCHAR) {
|
||||
break;
|
||||
}
|
||||
if (ch == quote) {
|
||||
ch = getchrq(inp_stream);
|
||||
if (ch != quote)
|
||||
@ -1638,16 +1642,16 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
break;
|
||||
case SY: {
|
||||
int pch;
|
||||
if (ch == '.' && (pch = Yap_peek(inp_stream - GLOBAL_Stream)) &&
|
||||
(chtype(pch) == BS || chtype(pch) == EF || pch == '%')) {
|
||||
t->Tok = Ord(kind = eot_tok);
|
||||
// consume...
|
||||
if (pch == '%') {
|
||||
t->TokInfo = TermNewLine;
|
||||
return l;
|
||||
}
|
||||
return l;
|
||||
if (ch == '.' && (pch = Yap_peek(inp_stream - GLOBAL_Stream)) &&
|
||||
(chtype(pch) == BS || chtype(pch) == EF || pch == '%')) {
|
||||
t->Tok = Ord(kind = eot_tok);
|
||||
// consume...
|
||||
if (pch == '%') {
|
||||
t->TokInfo = TermNewLine;
|
||||
return l;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
if (ch == '`')
|
||||
goto quoted_string;
|
||||
och = ch;
|
||||
@ -1668,7 +1672,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
return l;
|
||||
}
|
||||
}
|
||||
if (och == '/' && ch == '*') {
|
||||
if (och == '/' && ch == '*') {
|
||||
if (store_comments) {
|
||||
CHECK_SPACE();
|
||||
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);
|
||||
} else {
|
||||
qq->end.byteno = inp_stream->charcount - 1;
|
||||
}
|
||||
}
|
||||
qq->end.lineno = inp_stream->linecount;
|
||||
qq->end.linepos = inp_stream->linepos - 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);
|
||||
}
|
||||
|
||||
|
||||
void Yap_clean_tokenizer(TokEntry *tokstart, VarEntry *vartable,
|
||||
VarEntry *anonvartable) {
|
||||
CACHE_REGS
|
||||
|
31
C/signals.c
31
C/signals.c
@ -25,18 +25,18 @@ static char SccsId[] = "%W% %G%";
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if _WIN32
|
||||
#include <stdio.h>
|
||||
#include <io.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "eval.h"
|
||||
#include "Yatom.h"
|
||||
#include "YapEval.h"
|
||||
#include "yapio.h"
|
||||
#ifdef TABLING
|
||||
#include "tab.macros.h"
|
||||
#endif /* TABLING */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
@ -63,7 +63,11 @@ static yap_signals InteractSIGINT(int ch) {
|
||||
#endif
|
||||
switch (ch) {
|
||||
case 'a':
|
||||
/* abort computation */
|
||||
/* abort computation */
|
||||
#if PUSH_REGS
|
||||
// restore_absmi_regs(&Yap_standard_regs);
|
||||
#endif
|
||||
siglongjmp(&LOCAL_RestartEnv, 4);
|
||||
return YAP_ABORT_SIGNAL;
|
||||
case 'b':
|
||||
/* continue */
|
||||
@ -183,35 +187,32 @@ inline static bool get_signal(yap_signals sig USES_REGS) {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Yap_DisableInterrupts(int wid)
|
||||
{
|
||||
bool Yap_DisableInterrupts(int wid) {
|
||||
LOCAL_InterruptsDisabled = true;
|
||||
YAPEnterCriticalSection();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Yap_EnableInterrupts(int wid)
|
||||
{
|
||||
bool Yap_EnableInterrupts(int wid) {
|
||||
LOCAL_InterruptsDisabled = false;
|
||||
YAPLeaveCriticalSection();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Function called to handle delayed interrupts.
|
||||
*/
|
||||
int Yap_HandleInterrupts(void) {
|
||||
bool Yap_HandleSIGINT(void) {
|
||||
CACHE_REGS
|
||||
yap_signals sig;
|
||||
|
||||
if (get_signal(YAP_INT_SIGNAL PASS_REGS)) {
|
||||
do {
|
||||
if ((sig = ProcessSIGINT()) != YAP_NO_SIGNAL)
|
||||
do_signal(worker_id, sig PASS_REGS);
|
||||
LOCAL_PrologMode &= ~InterruptMode;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
return true;
|
||||
} while (get_signal(YAP_INT_SIGNAL PASS_REGS));
|
||||
return false;
|
||||
}
|
||||
|
||||
static Int p_creep(USES_REGS1) {
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
#include "Yap.h"
|
||||
#include "clause.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#include "iopreds.h"
|
||||
#include "tracer.h"
|
||||
#include "yapio.h"
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include "Yap.h"
|
||||
#include "clause.h"
|
||||
#include "yapio.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#include "tracer.h"
|
||||
#ifdef YAPOR
|
||||
#include "or.macros.h"
|
||||
|
28
C/stdpreds.c
28
C/stdpreds.c
@ -37,7 +37,7 @@ static char SccsId[] = "%W% %G%";
|
||||
#include "Foreign.h"
|
||||
#include "YapHeap.h"
|
||||
#include "Yatom.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#include "yapio.h"
|
||||
#ifdef TABLING
|
||||
#include "tab.macros.h"
|
||||
@ -58,6 +58,9 @@ static char SccsId[] = "%W% %G%";
|
||||
#include <fcntl.h>
|
||||
#include <wchar.h>
|
||||
|
||||
extern int init_tries(void);
|
||||
|
||||
|
||||
static Int p_setval(USES_REGS1);
|
||||
static Int p_value(USES_REGS1);
|
||||
static Int p_values(USES_REGS1);
|
||||
@ -74,7 +77,7 @@ static Int p_halt(USES_REGS1);
|
||||
#endif
|
||||
static Int 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 cont_current_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);
|
||||
}
|
||||
|
||||
static OpEntry *NextOp(OpEntry *pp USES_REGS) {
|
||||
static OpEntry *NextOp(Prop pp USES_REGS) {
|
||||
|
||||
while (!EndOfPAEntr(pp) && pp->KindOfPE != OpProperty &&
|
||||
(pp->OpModule != PROLOG_MODULE || pp->OpModule != CurrentModule))
|
||||
pp = RepOpProp(pp->NextOfPE);
|
||||
return (pp);
|
||||
(RepOpProp(pp)->OpModule != PROLOG_MODULE
|
||||
|| RepOpProp(pp)->OpModule != CurrentModule) )
|
||||
pp = pp->NextOfPE;
|
||||
return RepOpProp(pp);
|
||||
}
|
||||
|
||||
int Yap_IsOp(Atom at) {
|
||||
CACHE_REGS
|
||||
OpEntry *op = NextOp(RepOpProp((Prop)(RepAtom(at)->PropsOfAE)) PASS_REGS);
|
||||
OpEntry *op = NextOp(RepAtom(at)->PropsOfAE PASS_REGS);
|
||||
return (!EndOfPAEntr(op));
|
||||
}
|
||||
|
||||
int Yap_IsOpMaxPrio(Atom at) {
|
||||
CACHE_REGS
|
||||
OpEntry *op = NextOp(RepOpProp((Prop)(RepAtom(at)->PropsOfAE)) PASS_REGS);
|
||||
OpEntry *op = NextOp(RepAtom(at)->PropsOfAE PASS_REGS);
|
||||
int max;
|
||||
|
||||
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;
|
||||
|
||||
READ_LOCK(op->OpRWLock);
|
||||
next = NextOp(RepOpProp(op->NextOfPE) PASS_REGS);
|
||||
next = NextOp(op->NextOfPE PASS_REGS);
|
||||
if (unify_op(op PASS_REGS)) {
|
||||
READ_UNLOCK(op->OpRWLock);
|
||||
if (next) {
|
||||
@ -1053,7 +1058,7 @@ static Int init_current_atom_op(
|
||||
cut_fail();
|
||||
}
|
||||
ae = RepAtom(AtomOfTerm(t));
|
||||
if (EndOfPAEntr((ope = NextOp(RepOpProp(ae->PropsOfAE) PASS_REGS)))) {
|
||||
if (EndOfPAEntr((ope = NextOp(ae->PropsOfAE PASS_REGS)))) {
|
||||
cut_fail();
|
||||
}
|
||||
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((Int)ope);
|
||||
@ -1074,7 +1079,7 @@ static Int
|
||||
cut_fail();
|
||||
}
|
||||
ae = RepAtom(AtomOfTerm(t));
|
||||
if (EndOfPAEntr((ope = NextOp(RepOpProp(ae->PropsOfAE) PASS_REGS)))) {
|
||||
if (EndOfPAEntr((ope = NextOp(ae->PropsOfAE PASS_REGS)))) {
|
||||
cut_fail();
|
||||
}
|
||||
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((Int)ope);
|
||||
@ -1629,7 +1634,6 @@ void Yap_InitCPreds(void) {
|
||||
#if SUPPORT_CONDOR
|
||||
init_sys();
|
||||
init_random();
|
||||
// init_tries();
|
||||
init_regexp();
|
||||
#endif
|
||||
}
|
||||
|
154
C/text.c
154
C/text.c
@ -16,10 +16,10 @@
|
||||
*************************************************************************/
|
||||
|
||||
#include "Yap.h"
|
||||
#include "YapEval.h"
|
||||
#include "YapHeap.h"
|
||||
#include "YapText.h"
|
||||
#include "Yatom.h"
|
||||
#include "eval.h"
|
||||
#include "yapio.h"
|
||||
|
||||
#include <YapText.h>
|
||||
@ -51,9 +51,7 @@ typedef struct TextBuffer_manager {
|
||||
int lvl;
|
||||
} text_buffer_t;
|
||||
|
||||
int push_text_stack(USES_REGS1) {
|
||||
return LOCAL_TextBuffer->lvl++;
|
||||
}
|
||||
int push_text_stack(USES_REGS1) { return LOCAL_TextBuffer->lvl++; }
|
||||
|
||||
int pop_text_stack(int i) {
|
||||
int lvl = LOCAL_TextBuffer->lvl;
|
||||
@ -72,6 +70,33 @@ int pop_text_stack(int i) {
|
||||
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 *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);
|
||||
struct mblock *o = malloc(sz);
|
||||
o->prev = LOCAL_TextBuffer->last[lvl];
|
||||
if (o->prev) {
|
||||
o->prev->next = o;
|
||||
}
|
||||
if (o->prev) {
|
||||
o->prev->next = o;
|
||||
}
|
||||
if (LOCAL_TextBuffer->first[lvl]) {
|
||||
LOCAL_TextBuffer->last[lvl] = o;
|
||||
} else {
|
||||
@ -111,6 +136,7 @@ void *Realloc(void *pt, size_t sz USES_REGS) {
|
||||
if (LOCAL_TextBuffer->last[lvl] == old) {
|
||||
LOCAL_TextBuffer->last[lvl] = o;
|
||||
}
|
||||
|
||||
return o + 1;
|
||||
}
|
||||
|
||||
@ -206,7 +232,7 @@ static Int SkipListCodes(unsigned char **bufp, Term *l, Term **tailp,
|
||||
(*atoms)++;
|
||||
if (*atoms < length) {
|
||||
*tailp = l;
|
||||
return -REPRESENTATION_ERROR_CHARACTER_CODE;
|
||||
return -REPRESENTATION_ERROR_CHARACTER_CODE;
|
||||
} else {
|
||||
AtomEntry *ae = RepAtom(AtomOfTerm(hd));
|
||||
if ((ae->StrOfAE)[1] != '\0') {
|
||||
@ -356,10 +382,16 @@ static yap_error_number gen_type_error(int flags) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// static int cnt;
|
||||
|
||||
unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
|
||||
unsigned char *s0 = NULL;
|
||||
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 */
|
||||
if (!(inp->type & (YAP_STRING_CHARS | YAP_STRING_WCHARS))) {
|
||||
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
|
||||
// Yap_DebugPlWriteln(inp->val.t);
|
||||
Atom at = AtomOfTerm(inp->val.t);
|
||||
if (lengp)
|
||||
*lengp = strlen_utf8(at->UStrOfAE);
|
||||
if (lengp)
|
||||
*lengp = strlen(at->StrOfAE);
|
||||
return at->UStrOfAE;
|
||||
}
|
||||
if (IsStringTerm(inp->val.t) && inp->type & YAP_STRING_STRING) {
|
||||
// this is a term, extract to a buffer, and representation is wide
|
||||
// Yap_DebugPlWriteln(inp->val.t);
|
||||
if (lengp)
|
||||
*lengp = strlen_utf8(UStringOfTerm(inp->val.t));
|
||||
return (unsigned char *)UStringOfTerm(inp->val.t);
|
||||
if (lengp)
|
||||
*lengp = strlen(StringOfTerm(inp->val.t));
|
||||
return (unsigned char *)UStringOfTerm(inp->val.t);
|
||||
}
|
||||
if (((inp->type & (YAP_STRING_CODES | YAP_STRING_ATOMS)) ==
|
||||
(YAP_STRING_CODES | YAP_STRING_ATOMS)) &&
|
||||
IsPairOrNilTerm(inp->val.t)) {
|
||||
// Yap_DebugPlWriteln(inp->val.t);
|
||||
return
|
||||
Yap_ListToBuffer(s0, inp->val.t, inp, &wide, lengp PASS_REGS);
|
||||
return Yap_ListToBuffer(s0, inp->val.t, inp, &wide, lengp PASS_REGS);
|
||||
// this is a term, extract to a sfer, and representation is wide
|
||||
}
|
||||
if (inp->type & YAP_STRING_CODES && IsPairOrNilTerm(inp->val.t)) {
|
||||
// Yap_DebugPlWriteln(inp->val.t);
|
||||
return Yap_ListOfCodesToBuffer(s0, inp->val.t, inp, &wide,
|
||||
lengp PASS_REGS);
|
||||
return Yap_ListOfCodesToBuffer(s0, inp->val.t, inp, &wide, lengp PASS_REGS);
|
||||
// this is a term, extract to a sfer, and representation is wide
|
||||
}
|
||||
if (inp->type & YAP_STRING_ATOMS && IsPairOrNilTerm(inp->val.t)) {
|
||||
// Yap_DebugPlWriteln(inp->val.t);
|
||||
return Yap_ListOfAtomsToBuffer(s0, inp->val.t, inp, &wide,
|
||||
lengp PASS_REGS);
|
||||
return Yap_ListOfAtomsToBuffer(s0, inp->val.t, inp, &wide, lengp PASS_REGS);
|
||||
// this is a term, extract to a buffer, and representation is wide
|
||||
}
|
||||
if (inp->type & YAP_STRING_INT && IsIntegerTerm(inp->val.t)) {
|
||||
// ASCII, so both LATIN1 and UTF-8
|
||||
// Yap_DebugPlWriteln(inp->val.t);
|
||||
char *s;
|
||||
if (s0)
|
||||
s = (char *)s0;
|
||||
else
|
||||
s = Malloc(0);
|
||||
s = Malloc(0);
|
||||
if (snprintf(s, MaxTmp(PASS_REGS1) - 1, Int_FORMAT,
|
||||
IntegerOfTerm(inp->val.t)) < 0) {
|
||||
AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char);
|
||||
}
|
||||
*lengp = strlen(s);
|
||||
if (lengp)
|
||||
*lengp = strlen(s);
|
||||
return (unsigned char *)s;
|
||||
}
|
||||
if (inp->type & YAP_STRING_FLOAT && IsFloatTerm(inp->val.t)) {
|
||||
char *s;
|
||||
size_t sz = 1024;
|
||||
// Yap_DebugPlWriteln(inp->val.t);
|
||||
if (s0)
|
||||
{ s = (char *)s0; sz = strlen(s);}
|
||||
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);
|
||||
if (!Yap_FormatFloat(FloatOfTerm(inp->val.t), &s, 1024)) {
|
||||
return NULL;
|
||||
}
|
||||
*lengp = strlen(s);
|
||||
return inp->val.uc = (unsigned char *)s;
|
||||
if (lengp)
|
||||
*lengp = strlen(s);
|
||||
return (unsigned char *)s;
|
||||
}
|
||||
#if USE_GMP
|
||||
if (inp->type & YAP_STRING_BIG && IsBigIntTerm(inp->val.t)) {
|
||||
// Yap_DebugPlWriteln(inp->val.t);
|
||||
char *s;
|
||||
if (s0)
|
||||
s = 0;
|
||||
else
|
||||
s = Malloc(0);
|
||||
if (!Yap_mpz_to_string(Yap_BigIntOfTerm(inp->val.t), s, MaxTmp() - 1, 10)) {
|
||||
AUX_ERROR(inp->val.t, MaxTmp(PASS_REGS1), s, char);
|
||||
}
|
||||
*lengp = strlen(s);
|
||||
Malloc(*lengp);
|
||||
if (lengp)
|
||||
*lengp = strlen(s);
|
||||
return inp->val.uc = (unsigned char *)s;
|
||||
}
|
||||
#endif
|
||||
@ -471,18 +488,17 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
|
||||
return inp->val.uc = (unsigned char *)s;
|
||||
}
|
||||
if (inp->type & YAP_STRING_CHARS) {
|
||||
// printf("%s\n",inp->val.c);
|
||||
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) {
|
||||
if (inp->enc == ENC_ISO_LATIN1) {
|
||||
return latin2utf8(inp, lengp);
|
||||
} else if (inp->enc == ENC_ISO_ASCII) {
|
||||
if (lengp)
|
||||
*lengp = strlen(inp->val.c);
|
||||
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) {
|
||||
// printf("%S\n",inp->val.w);
|
||||
@ -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) {
|
||||
unsigned char *s = s0;
|
||||
int32_t ch;
|
||||
if ( leng == 0) {
|
||||
return Yap_LookupAtom("");
|
||||
}
|
||||
if ( strlen_utf8(s0) <= leng) {
|
||||
return Yap_LookupAtom(s0);
|
||||
if (leng == 0) {
|
||||
return Yap_LookupAtom("");
|
||||
}
|
||||
if (strlen_utf8(s0) <= leng) {
|
||||
return Yap_LookupAtom(s0);
|
||||
} else {
|
||||
size_t n = get_utf8(s, 1, &ch);
|
||||
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;
|
||||
if (out->enc == ENC_ISO_UTF8) {
|
||||
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);
|
||||
}
|
||||
if (out->val.uc != s0) {
|
||||
@ -720,18 +736,18 @@ static size_t write_length(const unsigned char *s0, seq_tv_t *out,
|
||||
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;
|
||||
int i = push_text_stack();
|
||||
t = Yap_StringToNumberTerm((char *)s, &out->enc, error_on);
|
||||
pop_text_stack(i);
|
||||
return t;
|
||||
pop_text_stack(i);
|
||||
return t;
|
||||
}
|
||||
|
||||
static Term string_to_term(void *s, seq_tv_t *out, size_t leng USES_REGS) {
|
||||
Term o;
|
||||
o = out->val.t =
|
||||
Yap_StringToTerm(s, strlen(s) + 1, &out->enc, GLOBAL_MaxPriority, 0L);
|
||||
o = out->val.t = Yap_BufferToTerm(s, strlen(s) + 1, TermNil);
|
||||
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;
|
||||
}
|
||||
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);
|
||||
|
||||
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);
|
||||
// Yap_DebugPlWriteln(out->val.t);
|
||||
return out->val.t != 0;
|
||||
default: { return true ; }
|
||||
default: { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -845,10 +862,11 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
|
||||
.w);
|
||||
else fprintf(stderr,"s %s\n", inp->val.c);
|
||||
*/
|
||||
// cnt++;
|
||||
buf = Yap_readText(inp, &leng PASS_REGS);
|
||||
if (out->type & (YAP_STRING_NCHARS | YAP_STRING_TRUNC)) {
|
||||
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);
|
||||
char *nbuf = Malloc(diff + 1);
|
||||
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 &&
|
||||
// const unsigned char *ptr = skip_utf8(buf, leng)
|
||||
}
|
||||
|
||||
if (!buf) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
if (out->type & (YAP_STRING_UPCASE | YAP_STRING_DOWNCASE)) {
|
||||
if (out->type & YAP_STRING_UPCASE) {
|
||||
if (!upcase(buf, out)) {
|
||||
@ -917,9 +935,9 @@ static unsigned char *concat(int n, void *sv[] USES_REGS) {
|
||||
buf = Malloc(room + 1);
|
||||
buf0 = buf;
|
||||
for (i = 0; i < n; i++) {
|
||||
#if _WIN32 || defined( __ANDROID__ )
|
||||
#if _WIN32 || defined(__ANDROID__)
|
||||
strcpy(buf, sv[i]);
|
||||
buf = (char*)buf + strlen(buf);
|
||||
buf = (char *)buf + strlen(buf);
|
||||
#else
|
||||
buf = stpcpy(buf, sv[i]);
|
||||
#endif
|
||||
@ -1021,14 +1039,14 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
|
||||
next = 0;
|
||||
else
|
||||
next = cuts[i - 1];
|
||||
if (i>0 && cuts[i] == 0)
|
||||
if (i > 0 && cuts[i] == 0)
|
||||
break;
|
||||
void *bufi = slice(next, cuts[i], buf PASS_REGS);
|
||||
if (!write_Text(bufi, outv + i, cuts[i] - next PASS_REGS)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1085,7 +1103,7 @@ const char *Yap_TextTermToText(Term t, char *buf, size_t len, encoding_t enc) {
|
||||
const char *Yap_PredIndicatorToUTF8String(PredEntry *ap) {
|
||||
CACHE_REGS
|
||||
Atom at;
|
||||
arity_t arity = 0;
|
||||
arity_t arity = 0;
|
||||
Functor f;
|
||||
char *s, *smax, *s0;
|
||||
s = s0 = malloc(1024);
|
||||
|
@ -26,7 +26,7 @@ static char SccsId[] = "%W% %G%";
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#include "yapio.h"
|
||||
#include "blobs.h"
|
||||
#include <stdio.h>
|
||||
|
156
C/tracer.c
156
C/tracer.c
@ -28,53 +28,88 @@
|
||||
#include "tracer.h"
|
||||
#include "yapio.h"
|
||||
|
||||
static char *send_tracer_message(char *start, char *name, Int arity,
|
||||
char *mname, CELL *args, char *s, char *top) {
|
||||
if (name == NULL) {
|
||||
#ifdef YAPOR
|
||||
s += snprintf(s, top - s, "(%d)%s", worker_id, start);
|
||||
#else
|
||||
s += snprintf(s, top - s, "%s", start);
|
||||
#endif
|
||||
} else {
|
||||
int i;
|
||||
static char *send_tracer_message(char *start, char *name, arity_t arity,
|
||||
char *mname, CELL *args, char **s0, char *s,
|
||||
char **top) {
|
||||
bool expand = false;
|
||||
size_t max = *top - (s + 1);
|
||||
int d, min = 1024;
|
||||
char *s1 = s;
|
||||
do {
|
||||
if (expand || max < 32) {
|
||||
Int cbeg = s1 - *s0;
|
||||
max = *top - *s0;
|
||||
max += min;
|
||||
*s0 = Realloc(*s0, max);
|
||||
|
||||
if (arity) {
|
||||
if (args)
|
||||
s += snprintf(s, top - s, "%s %s:%s(", start, mname, name);
|
||||
else
|
||||
s += snprintf(s, top - s, "%s %s:%s/%lu", start, mname, name,
|
||||
(unsigned long int)arity);
|
||||
} else {
|
||||
s += snprintf(s, top - s, "%s %s:%s", start, mname, name);
|
||||
*top = *s0 + max;
|
||||
max--;
|
||||
s1 = *s0 + cbeg;
|
||||
s = s1;
|
||||
expand = false;
|
||||
}
|
||||
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) {
|
||||
int i;
|
||||
for (i = 0; i < arity; i++) {
|
||||
size_t length = top - (s + 4);
|
||||
if ((ssize_t)length < 16) {
|
||||
s[0] = '\0';
|
||||
return s;
|
||||
}
|
||||
if (i > 0) {
|
||||
*s++ = ',';
|
||||
if (i > 0) {
|
||||
if (max > 16) {
|
||||
*s++ = ',';
|
||||
*s++ = ' ';
|
||||
max-=2;
|
||||
} else {
|
||||
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);
|
||||
size_t sz;
|
||||
if (sn != s) {
|
||||
if (sn == NULL) {
|
||||
sn = "<* error *>";
|
||||
}
|
||||
strlcpy(s, sn, top - (s + 3));
|
||||
if (sn == NULL) {
|
||||
sn = "<* error *>";
|
||||
}
|
||||
sz = strlen(s);
|
||||
sz = strlen(sn);
|
||||
if (max <= sz) {
|
||||
min = sz + 1024;
|
||||
expand = true;
|
||||
continue;
|
||||
}
|
||||
strcpy(s, sn);
|
||||
s += sz;
|
||||
max -= sz;
|
||||
}
|
||||
if (arity) {
|
||||
*s++ = ' ';
|
||||
*s++ = ')';
|
||||
max -= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (expand);
|
||||
s[0] = '\0';
|
||||
return s;
|
||||
}
|
||||
@ -154,22 +189,22 @@ check_area(void)
|
||||
jmp_deb(i);
|
||||
}
|
||||
*/
|
||||
|
||||
// PredEntry *old_p[10000];
|
||||
// Term old_x1[10000], old_x2[10000], old_x3[10000];
|
||||
|
||||
// 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
|
||||
char *s;
|
||||
char *mname;
|
||||
Int arity;
|
||||
int l = push_text_stack();
|
||||
/* extern int gc_calls; */
|
||||
vsc_count++;
|
||||
// if (HR < ASP ) return;
|
||||
// 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;
|
||||
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) {
|
||||
PredEntry *pe = EnvPreg(env_ptr[E_CP]);
|
||||
|
||||
printf("%p->", env_ptr, pe);
|
||||
if (vsc_count == 52LL)
|
||||
printf("\n");
|
||||
if (p == pe) {
|
||||
UNLOCK(Yap_heap_regs->low_level_trace_lock);
|
||||
return;
|
||||
pop_text_stack(l);
|
||||
ReleaseAndReturn(true);
|
||||
}
|
||||
if (env_ptr != NULL)
|
||||
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(); */
|
||||
if (pred == NULL) {
|
||||
UNLOCK(Yap_low_level_trace_lock);
|
||||
return;
|
||||
pop_text_stack(l);
|
||||
ReleaseAndReturn(true);
|
||||
}
|
||||
if (pred->ModuleOfPred == PROLOG_MODULE) {
|
||||
if (!LOCAL_do_trace_primitives) {
|
||||
UNLOCK(Yap_low_level_trace_lock);
|
||||
return;
|
||||
ReleaseAndReturn(true);
|
||||
}
|
||||
mname = "prolog";
|
||||
} else {
|
||||
@ -350,42 +384,45 @@ void low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) {
|
||||
}
|
||||
/* if ((pred->ModuleOfPred == 0) && (s[0] == '$'))
|
||||
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;
|
||||
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;
|
||||
case retry_or:
|
||||
b = send_tracer_message("FAIL ", NULL, 0, NULL, args, b, top);
|
||||
b = send_tracer_message("RETRY_OR ", 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, &buf, b, &top);
|
||||
break;
|
||||
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;
|
||||
arity = pred->ArityOfPE;
|
||||
if (arity == 0)
|
||||
s = (char *)RepAtom((Atom)pred->FunctorOfPred)->StrOfAE;
|
||||
else
|
||||
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;
|
||||
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;
|
||||
arity = pred->ArityOfPE;
|
||||
if (arity == 0) {
|
||||
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 {
|
||||
s = (char *)RepAtom(NameOfFunctor((pred->FunctorOfPred)))->StrOfAE;
|
||||
b = send_tracer_message("RETRY CONSUMER: ", s, pred->ArityOfPE, mname,
|
||||
NULL, b, top);
|
||||
NULL, &buf, b, &top);
|
||||
}
|
||||
break;
|
||||
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) {
|
||||
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 {
|
||||
mname = (char *)RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE;
|
||||
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;
|
||||
else
|
||||
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;
|
||||
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) {
|
||||
mname = (char *)RepAtom(AtomOfTerm(Yap_Module_Name(pred)))->StrOfAE;
|
||||
arity = pred->ArityOfPE;
|
||||
@ -409,7 +447,7 @@ void low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) {
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
@ -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);
|
||||
#else
|
||||
*b++ = '\n';
|
||||
*b++ = '\0';
|
||||
*b = '\0';
|
||||
fputs(buf, stderr);
|
||||
#endif
|
||||
pop_text_stack(l);
|
||||
ReleaseAndReturn(true);
|
||||
}
|
||||
|
||||
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) {
|
||||
fprintf(stderr, "Call counter=%lld\n", vsc_count);
|
||||
fprintf(stderr, "Call counter=%llu\n", vsc_count);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
18
C/write.c
18
C/write.c
@ -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,
|
||||
0);
|
||||
if (sno < 0)
|
||||
return FALSE;
|
||||
return false;
|
||||
wglb.lw = separator;
|
||||
wglb.stream = GLOBAL_Stream + sno;
|
||||
wrputf(f, &wglb);
|
||||
wrputc('\0', wglb.stream);
|
||||
so = Yap_MemExportStreamPtr(sno);
|
||||
*s = Malloc( strlen(so) )+1;
|
||||
strcpy(*s, so );
|
||||
Yap_CloseStream(sno);
|
||||
*s = so;
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* writes a data base reference */
|
||||
@ -567,12 +568,13 @@ static void write_string(const unsigned char *s,
|
||||
do {
|
||||
int delta;
|
||||
ptr += (delta = get_utf8(ptr, -1, &chr) );
|
||||
|
||||
if (chr == '\0')
|
||||
|
||||
if (chr == '\0') {
|
||||
break;
|
||||
if (delta == 0) {chr = *ptr++; }
|
||||
}
|
||||
if (delta == 0) {chr = *ptr++; }
|
||||
write_quoted(chr, qt, stream);
|
||||
} while (TRUE);
|
||||
} while (true);
|
||||
wrputc(qt, stream);
|
||||
}
|
||||
|
||||
@ -1259,7 +1261,7 @@ char *Yap_TermToString(Term t, size_t *lengthp, encoding_t enc, int flags) {
|
||||
int sno = Yap_open_buf_write_stream(enc, flags);
|
||||
const char *sf;
|
||||
DBTerm *e = LOCAL_BallTerm;
|
||||
|
||||
|
||||
if (sno < 0)
|
||||
return NULL;
|
||||
LOCAL_c_output_stream = sno;
|
||||
|
@ -369,8 +369,7 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
|
||||
p++;
|
||||
}
|
||||
} else {
|
||||
YAP_SetOutputMessage();
|
||||
|
||||
YAP_SetOutputMessage();
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
@ -446,13 +445,13 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
|
||||
break;
|
||||
case 'n':
|
||||
if (!strcmp("nosignals", p)) {
|
||||
iap->PrologShouldHandleInterrupts = FALSE;
|
||||
iap->PrologCannotHandleInterrupts = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
if (!strcmp("-nosignals", p)) {
|
||||
iap->PrologShouldHandleInterrupts = FALSE;
|
||||
iap->PrologCannotHandleInterrupts = true;
|
||||
break;
|
||||
} else if (!strncmp("-home=", p, strlen("-home="))) {
|
||||
GLOBAL_Home = p + strlen("-home=");
|
||||
|
@ -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.
|
||||
|
||||
# Sets the minimum version of CMake required to build the native
|
||||
# library. You should either keep the default value or only pass a
|
||||
# Sets the version of CMake required to build the native
|
||||
# library. You should either keep the default value or pass a
|
||||
# value of 3.4.0 or lower.
|
||||
|
||||
project( YAP )
|
||||
@ -15,14 +13,13 @@ if (ANDROID)
|
||||
else ()
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
include(CMakeToolsHelpers OPTIONAL)
|
||||
|
||||
|
||||
endif()
|
||||
|
||||
set(
|
||||
CMAKE_MODULE_PATH
|
||||
"${CMAKE_SOURCE_DIR}"
|
||||
"${CMAKE_SOURCE_DIR}/cmake")
|
||||
CMAKE_MODULE_PATH
|
||||
"${CMAKE_SOURCE_DIR}"
|
||||
"${CMAKE_SOURCE_DIR}/cmake"
|
||||
)
|
||||
|
||||
include(CheckIncludeFiles)
|
||||
include(CheckLibraryExists)
|
||||
@ -34,14 +31,15 @@ include(MacroOptionalFindPackage)
|
||||
include(MacroLogFeature)
|
||||
include(FindPackageHandleStandardArgs)
|
||||
include (GNUInstallDirs)
|
||||
|
||||
# Creates and names a library, sets it as either STATIC
|
||||
# or SHARED, and provides the relative paths to its source code.
|
||||
# You can define multiple libraries, and CMake builds it for you.
|
||||
# or SHARED, and provides the relative paths to its source code.z
|
||||
# You can define libraries, and CMake builds it for you.
|
||||
# Gradle automatically packages shared libraries with your APK.
|
||||
|
||||
#cross-compilation support
|
||||
# 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)
|
||||
macro(find_host_package)
|
||||
find_package(${ARGN})
|
||||
@ -54,6 +52,8 @@ if(NOT COMMAND find_host_program)
|
||||
endif()
|
||||
|
||||
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)
|
||||
|
||||
@ -61,15 +61,17 @@ include(Sources 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)
|
||||
include_directories (
|
||||
packages/myddas/sqlite3/Android/jni/sqlite
|
||||
packages/myddas/sqlite3/Android/jni/sqlite/nativehelper
|
||||
packages/myddas/sqlite3/src/Android/jni/sqlite
|
||||
packages/myddas/sqlite3/src/Android/jni/sqlite/nativehelper
|
||||
)
|
||||
endif (ANDROID)
|
||||
|
||||
set_property( SOURCE ${LIBYAP_SOURCES} APPEND PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1)
|
||||
|
||||
add_definitions(-DUSE_MYDDAS=1 -DMYDDAS_SQLITE3=1)
|
||||
|
||||
if (MYSQL_FOUND)
|
||||
@ -83,37 +85,33 @@ if (ODBC_FOUND)
|
||||
if (MYSQL_POSTGRES)
|
||||
add_definitions(= -DMYDDAS_POSTGRES=1)
|
||||
endif()
|
||||
if (MYSQL_POSTGRES)
|
||||
set(SWIG_SOURCES packages/swig/python/yap_PYTHONwrapper.cxx )
|
||||
endif()
|
||||
|
||||
if (ANDROID)
|
||||
|
||||
if (ANDROID)
|
||||
|
||||
ADD_SUBDIRECTORY(os)
|
||||
ADD_SUBDIRECTORY(OPTYap)
|
||||
ADD_SUBDIRECTORY(packages/myddas)
|
||||
ADD_SUBDIRECTORY(library/random)
|
||||
ADD_SUBDIRECTORY(library/system)
|
||||
ADD_SUBDIRECTORY(utf8proc)
|
||||
ADD_SUBDIRECTORY(CXX)
|
||||
|
||||
set (SWIG_FILES ${CMAKE_SOURCE_DIR}/../generated/jni/yap_wrap.cpp )
|
||||
|
||||
else ()
|
||||
set(YLIBS
|
||||
$<TARGET_OBJECTS:libYAPOs>
|
||||
$<TARGET_OBJECTS:libOPTYap>
|
||||
$<TARGET_OBJECTS:myddas>
|
||||
$<TARGET_OBJECTS:Yapsqlite3>
|
||||
$<TARGET_OBJECTS:libswi>
|
||||
$<TARGET_OBJECTS:utf8proc>
|
||||
)
|
||||
|
||||
|
||||
endif ()
|
||||
else()
|
||||
|
||||
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)
|
||||
list (APPEND YLIBS $<TARGET_OBJECTS:Yap++>)
|
||||
|
||||
List (APPEND YLIBS $<TARGET_OBJECTS:YAP++> )
|
||||
endif()
|
||||
|
||||
|
||||
add_library( # Sets the name of the library.
|
||||
libYap
|
||||
|
||||
@ -121,22 +119,24 @@ add_library( # Sets the name of the library.
|
||||
SHARED
|
||||
|
||||
${ENGINE_SOURCES}
|
||||
${SWIG_FILES}
|
||||
${C_INTERFACE_SOURCES}
|
||||
${STATIC_SOURCES}
|
||||
${ALL_SOURCES}
|
||||
//${STATIC_SOURCES}
|
||||
# cmake object libraries
|
||||
${YLIBS}
|
||||
${WINDLLS}
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(libYap ${WINDLLS})
|
||||
endif (WIN32)
|
||||
|
||||
include(libYap NO_POLICY_SCOPE)
|
||||
|
||||
endif()
|
||||
|
||||
if (USE_READLINE)
|
||||
target_link_libraries(libYap ${READLINE_LIBRARIES})
|
||||
endif (USE_READLINE)
|
||||
|
||||
|
||||
if (ANDROID)
|
||||
add_dependencies(libYap plmyddas )
|
||||
|
||||
@ -145,9 +145,8 @@ if (ANDROID)
|
||||
endif ()
|
||||
|
||||
set_target_properties(libYap
|
||||
PROPERTIES OUTPUT_NAME Yap
|
||||
)
|
||||
|
||||
PROPERTIES OUTPUT_NAME Yap
|
||||
)
|
||||
|
||||
MY_include(Packages NO_POLICY_SCOPE)
|
||||
include(Config NO_POLICY_SCOPE)
|
||||
include(Config NO_POLICY_SCOPE)
|
||||
|
@ -8,18 +8,29 @@ set (CXX_SOURCES
|
||||
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)
|
||||
|
||||
if (ANDROID OR WIN32)
|
||||
add_component (Yap++ ${CXX_SOURCES} )
|
||||
else()
|
||||
add_external (Yap++ ${CXX_SOURCES} )
|
||||
MY_target_link_libraries(Yap++ ${CMAKE_DL_LIBS} libYap)
|
||||
if ( WIN32)
|
||||
add_component (YAP++ ${CXX_SOURCES} )
|
||||
|
||||
MY_install(TARGETS Yap++
|
||||
LIBRARY DESTINATION ${libdir}
|
||||
ARCHIVE DESTINATION ${libdir}
|
||||
set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_YAP_NOT_INSTALLED_=1;HAVE_CONFIG_H=1;_GNU_SOURCE;YAP_KERNEL=1" )
|
||||
else()
|
||||
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()
|
||||
|
||||
|
@ -1,9 +0,0 @@
|
||||
set (CXX_SOURCES
|
||||
yapa.hh
|
||||
yapdb.hh
|
||||
yapi.cpp
|
||||
yapi.hh
|
||||
yapie.hh
|
||||
yapq.hh
|
||||
yapt.hh
|
||||
)
|
1684
CXX/_yap/__init__.c
1684
CXX/_yap/__init__.c
File diff suppressed because it is too large
Load Diff
5233
CXX/_yap/dtypes.c
5233
CXX/_yap/dtypes.c
File diff suppressed because it is too large
Load Diff
@ -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 +
|
||||
|
@ -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
@ -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
|
||||
|
||||
|
@ -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
@ -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
@ -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
@ -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
|
||||
|
@ -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()
|
@ -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
|
||||
|
||||
|
@ -58,13 +58,13 @@ class YAPAtom {
|
||||
YAPAtom( Atom at ) { a = at; }
|
||||
public:
|
||||
/// 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
|
||||
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
|
||||
//YAPAtom( const wchar_t * s) { a = Yap_LookupMaybeWideAtom( s ); }
|
||||
/// 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
|
||||
const char *getName(void);
|
||||
/// get name of (other way)
|
||||
@ -89,10 +89,11 @@ class YAPProp {
|
||||
PropTag tag( Prop p ) { return (PropTag)(p->KindOfPE); }
|
||||
public:
|
||||
/// get name of property
|
||||
virtual YAPAtom name() = 0;
|
||||
// virtual YAPAtom name();
|
||||
virtual ~YAPProp() {};
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* YAPA_HH */
|
||||
|
||||
|
87
CXX/yapdb.hh
87
CXX/yapdb.hh
@ -34,14 +34,14 @@ class YAPModule;
|
||||
*/
|
||||
class YAPModule : protected YAPAtomTerm {
|
||||
friend class YAPPredicate;
|
||||
friend class YAPModuleProp;
|
||||
YAPModule(Term t) : YAPAtomTerm(t){};
|
||||
Term t() { return gt(); }
|
||||
Term curModule() { CACHE_REGS return Yap_CurrentModule(); }
|
||||
|
||||
public:
|
||||
~YAPModule(){};
|
||||
YAPModule() : YAPAtomTerm(curModule()){};
|
||||
YAPModule(YAPAtom t) : YAPAtomTerm(t){};
|
||||
YAPModule() : YAPAtomTerm(curModule()){};
|
||||
YAPModule(YAPAtom t) : YAPAtomTerm(t){};
|
||||
};
|
||||
|
||||
/**
|
||||
@ -54,12 +54,12 @@ class YAPModuleProp : public YAPProp {
|
||||
ModEntry *m;
|
||||
|
||||
YAPModuleProp(ModEntry *mod) { m = mod; };
|
||||
YAPModuleProp(Term tmod) { m = Yap_GetModuleEntry(tmod); };
|
||||
YAPModuleProp(Term tmod) { m = Yap_GetModuleEntry(tmod); };
|
||||
|
||||
public:
|
||||
YAPModuleProp() { CACHE_REGS m = Yap_GetModuleEntry(Yap_CurrentModule()); };
|
||||
YAPModuleProp(YAPModule tmod);
|
||||
virtual YAPModule module() { return YAPModule(m->AtomOfME); };
|
||||
YAPModuleProp(YAPModule tmod) { m = Yap_GetModuleEntry(tmod.gt()); };
|
||||
YAPModuleProp() { CACHE_REGS m = Yap_GetModuleEntry(Yap_CurrentModule()); };
|
||||
virtual YAPModule module() { return YAPModule(m->AtomOfME); };
|
||||
};
|
||||
|
||||
/**
|
||||
@ -80,14 +80,14 @@ public:
|
||||
/// Constructor: receives name as an atom, plus arity
|
||||
///
|
||||
/// 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
|
||||
///
|
||||
/// Notice that this is designed for ISO-LATIN-1 right now
|
||||
/// Note: Python confuses the 3 constructors,
|
||||
/// 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);
|
||||
}
|
||||
/// Constructor: receives name as a wide string plus arity
|
||||
@ -96,19 +96,18 @@ public:
|
||||
///
|
||||
/// Note: Python confuses the 3 constructors,
|
||||
/// 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);
|
||||
}
|
||||
~YAPFunctor(){};
|
||||
/// Getter: extract name of functor as an atom
|
||||
///
|
||||
/// 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
|
||||
///
|
||||
/// 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[]
|
||||
/// and the array of variables
|
||||
/// back to yapquery
|
||||
YAPPredicate(const char *s0, Term &out, Term &names) {
|
||||
YAPPredicate(const char *s0, Term &out, Term &names) {
|
||||
CACHE_REGS
|
||||
BACKUP_MACHINE_REGS();
|
||||
Term *modp = NULL;
|
||||
|
||||
out = Yap_StringToTerm(s0, strlen(s0) + 1, &LOCAL_encoding, 1200, names);
|
||||
names = MkVarTerm ();
|
||||
const unsigned char *us = (const unsigned char *)s0;
|
||||
out =
|
||||
Yap_BufferToTermWithPrioBindings(us, strlen(s0), TermNil, 1200, names);
|
||||
// extern char *s0;
|
||||
// fprintf(stderr,"ap=%p arity=%d text=%s", ap, ap->ArityOfPE, s);
|
||||
// Yap_DebugPlWrite(out);
|
||||
@ -153,7 +154,7 @@ protected:
|
||||
/// Term constructor for predicates
|
||||
///
|
||||
/// It is just a call to getPred
|
||||
inline YAPPredicate(Term t) {
|
||||
inline YAPPredicate(Term t) {
|
||||
CELL *v = NULL;
|
||||
ap = getPred(t, v);
|
||||
}
|
||||
@ -173,35 +174,34 @@ protected:
|
||||
inline YAPPredicate(PredEntry *pe) { ap = pe; }
|
||||
|
||||
public:
|
||||
~YAPPredicate(){};
|
||||
|
||||
/// Functor constructor for predicates
|
||||
///
|
||||
/// Asssumes that we use the current module.
|
||||
YAPPredicate(YAPFunctor f) {
|
||||
YAPPredicate(YAPFunctor f) {
|
||||
CACHE_REGS
|
||||
ap = RepPredProp(PredPropByFunc(f.f, Yap_CurrentModule()));
|
||||
}
|
||||
|
||||
/// 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));
|
||||
}
|
||||
|
||||
/// Name/arity constructor for predicates.
|
||||
///
|
||||
inline YAPPredicate(YAPAtom at, YAPTerm mod) {
|
||||
inline YAPPredicate(YAPAtom at, YAPTerm mod) {
|
||||
ap = RepPredProp(PredPropByAtom(at.a, mod.t));
|
||||
}
|
||||
|
||||
/// Name/0 constructor for predicates.
|
||||
///
|
||||
YAPPredicate(YAPAtom at);
|
||||
YAPPredicate(YAPAtom at);
|
||||
|
||||
/// 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) {
|
||||
Functor f = Yap_MkFunctor(at.a, arity);
|
||||
ap = RepPredProp(PredPropByFunc(f, mod.t()));
|
||||
@ -212,30 +212,32 @@ public:
|
||||
|
||||
/// Atom/Arity constructor for predicates.
|
||||
///
|
||||
YAPPredicate(YAPAtom at, uintptr_t arity);
|
||||
YAPPredicate(YAPAtom at, uintptr_t arity);
|
||||
|
||||
/// char */module constructor for predicates.
|
||||
///
|
||||
inline YAPPredicate(const char *at, uintptr_t arity) {
|
||||
ap = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_LookupAtom(at), arity), CurrentModule));
|
||||
inline YAPPredicate(const char *at, uintptr_t arity) {
|
||||
ap = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_LookupAtom(at), arity),
|
||||
CurrentModule));
|
||||
};
|
||||
|
||||
/// char */module constructor for predicates.
|
||||
///
|
||||
inline YAPPredicate(const char *at, uintptr_t arity, YAPTerm mod) {
|
||||
ap = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_LookupAtom(at), arity), mod.t));
|
||||
inline YAPPredicate(const char *at, uintptr_t arity, YAPTerm mod) {
|
||||
ap = RepPredProp(
|
||||
PredPropByFunc(Yap_MkFunctor(Yap_LookupAtom(at), arity), mod.t));
|
||||
};
|
||||
|
||||
/// 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));
|
||||
}
|
||||
|
||||
/// module of a predicate
|
||||
///
|
||||
/// notice that modules are currently treated as atoms, this should change.
|
||||
YAPModule module() {
|
||||
YAPModule module() {
|
||||
if (ap->ModuleOfPred == PROLOG_MODULE)
|
||||
return YAPModule(AtomProlog);
|
||||
else
|
||||
@ -252,6 +254,15 @@ public:
|
||||
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
|
||||
///
|
||||
/// we return a positive number.
|
||||
@ -266,15 +277,15 @@ public:
|
||||
*/
|
||||
class YAPPrologPredicate : public YAPPredicate {
|
||||
public:
|
||||
YAPPrologPredicate(YAPTerm t) : YAPPredicate(t) {};
|
||||
YAPPrologPredicate(const char *s, arity_t arity): YAPPredicate(s, arity) {};
|
||||
YAPPrologPredicate(YAPTerm t) : YAPPredicate(t){};
|
||||
YAPPrologPredicate(const char *s, arity_t arity) : YAPPredicate(s, arity){};
|
||||
/// add a new clause
|
||||
void *assertClause(YAPTerm clause, bool last = true,
|
||||
bool assertClause(YAPTerm clause, bool last = true,
|
||||
YAPTerm source = YAPTerm());
|
||||
/// 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.
|
||||
void *retractClause(YAPTerm skeleton, bool all = false);
|
||||
void *retractClause(YAPTerm skeleton, bool all = false);
|
||||
/// return the Nth clause (if source is available)
|
||||
// YAPTerm clause(size_t index, YAPPredicate p) { return YAPTerm(); };
|
||||
/// 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)
|
||||
: YAPPredicate(YAPAtom(name), arity, module) {
|
||||
if (backtrackable) {
|
||||
@ -312,8 +323,8 @@ public:
|
||||
YAP_UserCPredicate(name, 0, arity);
|
||||
}
|
||||
};
|
||||
bool addCall(CPredicate call) { return Yap_AddCallToFli(ap, call); }
|
||||
bool addRetry(CPredicate call) { return Yap_AddRetryToFli(ap, call); }
|
||||
bool addCall(CPredicate call) { return Yap_AddCallToFli(ap, call); }
|
||||
bool addRetry(CPredicate call) { return Yap_AddRetryToFli(ap, call); }
|
||||
bool addCut(CPredicate call) { return Yap_AddCutToFli(ap, call); }
|
||||
};
|
||||
|
||||
|
922
CXX/yapi.cpp
922
CXX/yapi.cpp
File diff suppressed because it is too large
Load Diff
36
CXX/yapi.hh
36
CXX/yapi.hh
@ -5,8 +5,10 @@
|
||||
|
||||
#include <gmpxx.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
//! @{
|
||||
//! @{
|
||||
/**
|
||||
*
|
||||
* @defgroup yap-cplus-interface An object oriented interface for YAP.
|
||||
@ -67,38 +69,6 @@ extern "C" {
|
||||
// taken from yap_structs.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);
|
||||
|
||||
/* void UserCPredicateWithArgs(const char *name, int *fn(), unsigned int arity)
|
||||
|
15
CXX/yapie.hh
15
CXX/yapie.hh
@ -7,12 +7,17 @@ class YAPTerm;
|
||||
|
||||
/// take information on a Prolog error:
|
||||
class YAPError {
|
||||
std::string name, errorClass, info;
|
||||
yap_error_number ID;
|
||||
std::string goal, info;
|
||||
int swigcode;
|
||||
|
||||
|
||||
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
|
||||
/// exact error ID
|
||||
yap_error_number getID() { return LOCAL_ActiveError->errorNo; };
|
||||
@ -27,7 +32,7 @@ public:
|
||||
/// the term that caused the bug
|
||||
// YAPTerm getCulprit(LOCAL_ActiveError->errorFile){};
|
||||
/// text describing the Error
|
||||
const char *text();
|
||||
std::string text();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
61
CXX/yapq.hh
61
CXX/yapq.hh
@ -13,19 +13,19 @@ class YAPPredicate;
|
||||
* interface to a YAP Query;
|
||||
* uses an SWI-like status info internally.
|
||||
*/
|
||||
class YAPQuery : public YAPPredicate {
|
||||
class YAPQuery : public YAPPredicate
|
||||
{
|
||||
bool q_open;
|
||||
int q_state;
|
||||
yhandle_t q_g, q_handles;
|
||||
struct yami *q_p, *q_cp;
|
||||
jmp_buf q_env;
|
||||
sigjmp_buf q_env;
|
||||
int q_flags;
|
||||
YAP_dogoalinfo q_h;
|
||||
YAPQuery *oq;
|
||||
YAPListTerm vnames;
|
||||
YAPTerm goal;
|
||||
Term names;
|
||||
Term goal;
|
||||
// temporaries
|
||||
Term tgoal, names;
|
||||
|
||||
void openQuery();
|
||||
|
||||
@ -46,20 +46,19 @@ public:
|
||||
///
|
||||
/// 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.
|
||||
YAPQuery(YAPFunctor f, YAPTerm t[]);
|
||||
//YAPQuery(YAPFunctor f, YAPTerm t[]);
|
||||
/// string constructor without varnames
|
||||
///
|
||||
/// It is given a string, calls the parser and obtains a Prolog term that
|
||||
/// should be a callable
|
||||
/// goal.
|
||||
inline YAPQuery(const char *s) : YAPPredicate(s, tgoal, names) {
|
||||
inline YAPQuery(const char *s) : YAPPredicate(s, goal, names)
|
||||
{
|
||||
BACKUP_H();
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %ld",
|
||||
LOCAL_CurSlot);
|
||||
if (!ap)
|
||||
return;
|
||||
goal = YAPTerm(tgoal);
|
||||
vnames = YAPListTerm(names);
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", vnames.text());
|
||||
openQuery();
|
||||
RECOVER_H();
|
||||
@ -68,9 +67,10 @@ public:
|
||||
///
|
||||
/// It is given an atom, and a Prolog term that should be a callable
|
||||
/// goal, say `main`, `init`, `live`.
|
||||
inline YAPQuery(YAPAtom g) : YAPPredicate(g) {
|
||||
goal = YAPAtomTerm(g);
|
||||
vnames = YAPListTerm();
|
||||
inline YAPQuery(YAPAtom g) : YAPPredicate(g)
|
||||
{
|
||||
goal = YAPAtomTerm(g).gt();
|
||||
names = TermNil;
|
||||
openQuery();
|
||||
};
|
||||
|
||||
@ -92,19 +92,20 @@ public:
|
||||
const char *text();
|
||||
/// remove alternatives in the current search space, and finish the current
|
||||
/// query
|
||||
void cut();
|
||||
/// finish the current query: undo all bindings.
|
||||
void close();
|
||||
/// query variables.
|
||||
YAPListTerm namedVars();
|
||||
void cut();
|
||||
Term namedVars();
|
||||
/// query variables, but copied out
|
||||
YAPListTerm namedVarsCopy();
|
||||
Term namedVarsCopy();
|
||||
/// convert a ref to a binding.
|
||||
YAPTerm getTerm(yhandle_t t);
|
||||
/// simple YAP Query;
|
||||
/// just calls YAP and reports success or failure, Useful when we just
|
||||
/// want things done, eg YAPCommand("load_files(library(lists), )")
|
||||
inline bool command() {
|
||||
inline bool command()
|
||||
{
|
||||
bool rc = next();
|
||||
close();
|
||||
return rc;
|
||||
@ -116,7 +117,8 @@ public:
|
||||
/// This class implements a callback Prolog-side. It will be inherited by the
|
||||
/// Java or Python
|
||||
/// class that actually implements the callback.
|
||||
class YAPCallback {
|
||||
class YAPCallback
|
||||
{
|
||||
public:
|
||||
virtual ~YAPCallback() {}
|
||||
virtual void run() { LOG("callback"); }
|
||||
@ -129,7 +131,8 @@ public:
|
||||
*
|
||||
*
|
||||
*/
|
||||
class YAPEngine {
|
||||
class YAPEngine
|
||||
{
|
||||
private:
|
||||
YAPCallback *_callback;
|
||||
YAP_init_args init_args;
|
||||
@ -156,14 +159,16 @@ public:
|
||||
/// remove current callback
|
||||
void delYAPCallback() { _callback = 0; }
|
||||
/// set a new callback
|
||||
void setYAPCallback(YAPCallback *cb) {
|
||||
void setYAPCallback(YAPCallback *cb)
|
||||
{
|
||||
delYAPCallback();
|
||||
_callback = cb;
|
||||
}
|
||||
/// execute the callback.
|
||||
////void run() { if (_callback) _callback->run(); }
|
||||
/// execute the callback with a text argument.
|
||||
void run(char *s) {
|
||||
void run(char *s)
|
||||
{
|
||||
if (_callback)
|
||||
_callback->run(s);
|
||||
}
|
||||
@ -181,22 +186,30 @@ public:
|
||||
/// current directory for the engine
|
||||
bool call(YAPPredicate ap, YAPTerm ts[]);
|
||||
/// current directory for the engine
|
||||
bool goalt(YAPTerm t);
|
||||
bool goalt(YAPTerm Yt) { return Yt.term(); };
|
||||
/// 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
|
||||
void reSet();
|
||||
/// release: assune that there are no stack pointers, just release memory
|
||||
// for last execution
|
||||
void release();
|
||||
|
||||
const char *currentDir() {
|
||||
const char *currentDir()
|
||||
{
|
||||
char dir[1024];
|
||||
std::string s = Yap_getcwd(dir, 1024 - 1);
|
||||
return s.c_str();
|
||||
};
|
||||
/// report YAP version as a string
|
||||
const char *version() {
|
||||
const char *version()
|
||||
{
|
||||
std::string s = Yap_version();
|
||||
return s.c_str();
|
||||
};
|
||||
|
200
CXX/yapt.hh
200
CXX/yapt.hh
@ -2,9 +2,12 @@
|
||||
#ifndef YAPT_HH
|
||||
#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;
|
||||
|
||||
/**
|
||||
* @brief Generic Prolog Term
|
||||
*/
|
||||
@ -18,20 +21,32 @@ class YAPTerm {
|
||||
friend class YAPListTerm;
|
||||
|
||||
protected:
|
||||
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
|
||||
yhandle_t t; /// handle to term, equivalent to term_t
|
||||
|
||||
public:
|
||||
virtual ~YAPTerm(){ LOCAL_HandleBase[t] = TermFreeTerm;
|
||||
while ( LOCAL_HandleBase[LOCAL_CurSlot-1] == TermFreeTerm)
|
||||
LOCAL_CurSlot--;
|
||||
}
|
||||
YAPTerm(Term tn) {
|
||||
mk(tn);
|
||||
} /// private method to convert from Term (internal YAP representation) to
|
||||
Term gt() {
|
||||
CACHE_REGS
|
||||
// fprintf(stderr,"?%d,%lx,%p\n",t,LOCAL_HandleBase[t], HR);
|
||||
// Yap_DebugPlWriteln(LOCAL_HandleBase[t]);
|
||||
return Yap_GetFromSlot(t);
|
||||
};
|
||||
|
||||
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
|
||||
// do nothing constructor
|
||||
YAPTerm() { mk(MkVarTerm()); }
|
||||
YAPTerm() { mk(MkVarTerm()); };
|
||||
// YAPTerm(yhandle_t i) { t = i; };
|
||||
/// pointer to term
|
||||
YAPTerm(void *ptr);
|
||||
@ -40,6 +55,21 @@ public:
|
||||
Term 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
|
||||
/// YAPIntegerTerm)
|
||||
/// YAPTerm(long int num) { mk(MkIntegerTerm(num)); }
|
||||
@ -51,23 +81,64 @@ public:
|
||||
/// extract the tag of a term, after dereferencing.
|
||||
YAP_tag_t tag();
|
||||
/// copy the term ( term copy )
|
||||
YAPTerm deepCopy();
|
||||
Term deepCopy();
|
||||
/// numbervars ( int start, bool process=false )
|
||||
intptr_t numberVars(intptr_t start, bool skip_singletons = false);
|
||||
inline Term term() {
|
||||
return gt();
|
||||
} /// 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
|
||||
YAPTerm &operator[](size_t n);
|
||||
Term &operator[](arity_t n);
|
||||
// const YAPTerm *vars();
|
||||
/// this term is == to t1
|
||||
virtual bool exactlyEqual(YAPTerm t1);
|
||||
virtual bool unify(YAPTerm t1); /// t = t1
|
||||
virtual bool unifiable(YAPTerm t1); /// we can unify t and t1
|
||||
virtual bool variant(
|
||||
YAPTerm t1); /// t =@= t1, the two terms are equal up to variable renaming
|
||||
virtual intptr_t hashTerm(size_t sz, size_t depth,
|
||||
bool variant); /// term hash,
|
||||
virtual bool exactlyEqual(YAPTerm t1) {
|
||||
bool out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
out = Yap_eq(gt(), t1.term());
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
};
|
||||
|
||||
/// 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 isAtom() { return IsAtomTerm(gt()); } /// type check for atom
|
||||
virtual bool isInteger() {
|
||||
@ -88,19 +159,19 @@ public:
|
||||
virtual bool isList() { return Yap_IsListTerm(gt()); } /// term is a list
|
||||
|
||||
/// 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();
|
||||
Term tf = 0;
|
||||
Term t0 = gt();
|
||||
YAPTerm tf;
|
||||
if (IsApplTerm(t0))
|
||||
tf = YAPTerm(ArgOfTerm(i, t0));
|
||||
tf = (ArgOfTerm(i, t0));
|
||||
else if (IsPairTerm(t0)) {
|
||||
if (i == 1)
|
||||
tf = YAPTerm(HeadOfTerm(t0));
|
||||
tf = (HeadOfTerm(t0));
|
||||
else if (i == 2)
|
||||
tf = YAPTerm(TailOfTerm(t0));
|
||||
tf = (TailOfTerm(t0));
|
||||
} else {
|
||||
tf = YAPTerm((Term)0);
|
||||
tf = ((Term)0);
|
||||
}
|
||||
RECOVER_MACHINE_REGS();
|
||||
return tf;
|
||||
@ -123,7 +194,24 @@ public:
|
||||
}
|
||||
|
||||
/// 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
|
||||
inline yhandle_t handle() { return t; };
|
||||
@ -169,16 +257,21 @@ class YAPApplTerm : public YAPTerm {
|
||||
YAPApplTerm(Term t0) { mk(t0); }
|
||||
|
||||
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(const char *s, std::vector<YAPTerm> ts);
|
||||
YAPApplTerm(const std::string s, std::vector<YAPTerm> ts);
|
||||
YAPApplTerm(YAPFunctor f);
|
||||
YAPFunctor getFunctor();
|
||||
YAPTerm getArg(arity_t i) {
|
||||
Term getArg(arity_t i) {
|
||||
BACKUP_MACHINE_REGS();
|
||||
Term t0 = gt();
|
||||
YAPTerm tf;
|
||||
tf = YAPTerm(ArgOfTerm(i, t0));
|
||||
Term tf;
|
||||
tf = ArgOfTerm(i, t0);
|
||||
RECOVER_MACHINE_REGS();
|
||||
return tf;
|
||||
};
|
||||
@ -209,8 +302,8 @@ class YAPPairTerm : public YAPTerm {
|
||||
public:
|
||||
YAPPairTerm(YAPTerm hd, YAPTerm tl);
|
||||
YAPPairTerm();
|
||||
YAPTerm getHead() { return YAPTerm(HeadOfTerm(gt())); }
|
||||
YAPTerm getTail() { return YAPTerm(TailOfTerm(gt())); }
|
||||
Term getHead() { return (HeadOfTerm(gt())); }
|
||||
Term getTail() { return (TailOfTerm(gt())); }
|
||||
};
|
||||
|
||||
/**
|
||||
@ -234,8 +327,8 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Floating Point Term
|
||||
*/
|
||||
* @brief Floating Point Term
|
||||
*/
|
||||
|
||||
class YAPFloatTerm : public YAPNumberTerm {
|
||||
public:
|
||||
@ -267,28 +360,27 @@ public:
|
||||
return Yap_SkipList(&t1, &tailp);
|
||||
}
|
||||
/// Extract the nth element.
|
||||
YAPTerm &operator[](size_t n);
|
||||
Term &operator[](size_t n);
|
||||
/// Extract the first element of a list.
|
||||
///
|
||||
/// @param[in] the list
|
||||
YAPTerm car();
|
||||
Term car();
|
||||
/// Extract the tail elements of a list.
|
||||
///
|
||||
/// @param[in] the list
|
||||
YAPListTerm cdr() {
|
||||
Term cdr() {
|
||||
Term to = gt();
|
||||
if (IsPairTerm(to))
|
||||
return YAPListTerm(TailOfTerm(to));
|
||||
return (TailOfTerm(to));
|
||||
else if (to == TermNil)
|
||||
return YAPListTerm();
|
||||
return TermNil;
|
||||
/* error */
|
||||
Yap_Error(TYPE_ERROR_LIST, t, 0);
|
||||
throw YAPError();
|
||||
throw YAPError(TYPE_ERROR_LIST, YAPTerm(to), "");
|
||||
}
|
||||
/// copy a list.
|
||||
///
|
||||
/// @param[in] the list
|
||||
YAPListTerm dup();
|
||||
Term dup();
|
||||
|
||||
/// Check if the list is empty.
|
||||
///
|
||||
@ -337,15 +429,15 @@ public:
|
||||
YAPAtomTerm(wchar_t *s);
|
||||
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
|
||||
YAPAtomTerm(wchar_t *s, size_t len);
|
||||
virtual bool isVar() { return false; } /// type check for unbound
|
||||
virtual bool isAtom() { return true; } /// type check for atom
|
||||
virtual bool isInteger() { return false; } /// type check for integer
|
||||
virtual bool isFloat() { return false; } /// type check for floating-point
|
||||
virtual bool isString() { return false; } /// type check for a string " ... "
|
||||
virtual bool isCompound() { return false; } /// is a primitive term
|
||||
virtual bool isAppl() { return false; } /// is a structured term
|
||||
virtual bool isPair() { return false; } /// is a pair term
|
||||
virtual bool isGround() { return true; } /// term is ground
|
||||
bool isVar() { return false; } /// type check for unbound
|
||||
bool isAtom() { return true; } /// type check for atom
|
||||
bool isInteger() { return false; } /// type check for integer
|
||||
bool isFloat() { return false; } /// type check for floating-point
|
||||
bool isString() { return false; } /// type check for a string " ... "
|
||||
bool isCompound() { return false; } /// is a primitive term
|
||||
bool isAppl() { return false; } /// is a structured term
|
||||
bool isPair() { return false; } /// is a pair term
|
||||
virtual bool isGround() { return true; } /// term is ground
|
||||
virtual bool isList() { return gt() == TermNil; } /// [] is a list
|
||||
// Getter: outputs the atom;
|
||||
YAPAtom getAtom() { return YAPAtom(AtomOfTerm(gt())); }
|
||||
|
5
H/ATOMS
5
H/ATOMS
@ -95,7 +95,7 @@ A Csult F "$csult"
|
||||
A CurrentModule F "$current_module"
|
||||
A Cut N "!"
|
||||
A CutBy F "$cut_by"
|
||||
A DAbort F "$abort"
|
||||
A DAbort N "abort"
|
||||
A DBLoad F "$db_load"
|
||||
A DBREF N "DBRef"
|
||||
A DBReference N "db_reference"
|
||||
@ -294,6 +294,7 @@ A PastEndOfStream N "past_end_of_stream"
|
||||
A PermissionError N "permission_error"
|
||||
A Pi N "pi"
|
||||
A Pipe N "pipe"
|
||||
A Priority N "priority"
|
||||
A Plus N "+"
|
||||
A Pointer N "pointer"
|
||||
A Portray F "portray"
|
||||
@ -546,11 +547,13 @@ F NBQueue Queue 4
|
||||
F Not Not 1
|
||||
F Obj Obj 1
|
||||
F Or Semic 2
|
||||
F Output Output 1
|
||||
F PermissionError PermissionError 3
|
||||
F Plus Plus 2
|
||||
F Portray Portray 1
|
||||
F PrintMessage PrintMessage 2
|
||||
F Procedure Procedure 5
|
||||
F Priority Priority 1
|
||||
F PrologConstraint Prolog 2
|
||||
F ProtectStack ProtectStack 4
|
||||
F Query Query 1
|
||||
|
10
H/LOCALS
10
H/LOCALS
@ -145,7 +145,7 @@ ADDR db_vec0 =NULL
|
||||
struct RB_red_blk_node* db_root =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_base void
|
||||
CELL* extra_gc_cells_top void
|
||||
@ -160,8 +160,8 @@ struct mem_blk* CMemFirstBlock =NULL
|
||||
UInt CMemFirstBlockSz =0L
|
||||
|
||||
// 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
|
||||
Int* LabelFirstArray =NULL
|
||||
UInt LabelFirstArraySz =0L
|
||||
@ -198,7 +198,7 @@ ADDR TrailTop void
|
||||
yap_error_descriptor_t* ActiveError =calloc(sizeof(yap_error_descriptor_t),1)
|
||||
/// pointer to an exception term, from throw
|
||||
|
||||
jmp_buf IOBotch void
|
||||
jmp_buf* IOBotch void
|
||||
TokEntry* tokptr void
|
||||
TokEntry* toktide void
|
||||
VarEntry* VarTable void
|
||||
@ -209,7 +209,7 @@ CELL* CommentsNextChar void
|
||||
wchar_t* CommentsBuff void
|
||||
size_t CommentsBuffPos void
|
||||
size_t CommentsBuffLim void
|
||||
sigjmp_buf RestartEnv void
|
||||
sigjmp_buf* RestartEnv void
|
||||
char FileNameBuf[YAP_FILENAME_MAX+1] void
|
||||
char FileNameBuf2[YAP_FILENAME_MAX+1] void
|
||||
|
||||
|
@ -302,6 +302,8 @@ INLINE_ONLY inline EXTERN Term __MkStringTerm(const char *s USES_REGS) {
|
||||
return t;
|
||||
}
|
||||
|
||||
#define MkUStringTerm(i) __MkUStringTerm((i)PASS_REGS)
|
||||
|
||||
INLINE_ONLY inline EXTERN Term
|
||||
__MkUStringTerm(const unsigned char *s USES_REGS);
|
||||
|
||||
|
39
H/Yap.h
39
H/Yap.h
@ -129,37 +129,6 @@
|
||||
#endif
|
||||
#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__
|
||||
#ifndef _WIN32
|
||||
@ -727,10 +696,10 @@ typedef struct thandle {
|
||||
struct timeval *start_of_times_sysp;
|
||||
struct timeval *last_time_sysp;
|
||||
#elif _WIN32
|
||||
struct _FILETIME *start_of_timesp;
|
||||
struct _FILETIME *last_timep;
|
||||
struct _FILETIME *start_of_times_sysp;
|
||||
struct _FILETIME *last_time_sysp;
|
||||
win64_time_t *start_of_timesp;
|
||||
win64_time_t *last_timep;
|
||||
win64_time_t *start_of_times_sysp;
|
||||
win64_time_t *last_time_sysp;
|
||||
#endif
|
||||
} yap_thandle;
|
||||
#endif /* THREADS */
|
||||
|
@ -8,7 +8,7 @@
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: compile.h *
|
||||
* File: YapCompile.h *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: compiler data structures and routines *
|
@ -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 *
|
||||
* *
|
||||
@ -8,7 +8,7 @@
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: eval.h *
|
||||
* File: YapEval.h *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: arithmetical functions info *
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
/**
|
||||
|
||||
@file eval.h
|
||||
@file YapEval.h
|
||||
|
||||
@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, ...) \
|
||||
Yap_ThrowError__(__FILE__, __FUNCTION__, __LINE__, id, t, 2, __VA_ARGS__)
|
||||
Yap_ThrowError__(__FILE__, __FUNCTION__, __LINE__, id, t, __VA_ARGS__)
|
||||
#define Yap_BinError(id) \
|
||||
Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, 0L, "")
|
||||
#define Yap_AbsmiError(id) \
|
@ -204,7 +204,7 @@ typedef struct x_el {
|
||||
} xarg;
|
||||
|
||||
typedef struct struct_param {
|
||||
char *name;
|
||||
const char *name;
|
||||
flag_func type;
|
||||
int id;
|
||||
} param_t;
|
||||
|
@ -154,7 +154,7 @@ typedef struct thandle {
|
||||
/*******************
|
||||
this is the data base: everything here should be possible to restore
|
||||
********************/
|
||||
#if __INIT_C__
|
||||
#if __INIT_C__ || defined(MSC_VER)
|
||||
#define EXTERNAL
|
||||
#else
|
||||
#define EXTERNAL extern
|
||||
|
66
H/YapTags.h
66
H/YapTags.h
@ -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) {
|
||||
return (Term)((*HR = 0, HR++));
|
||||
}
|
||||
|
||||
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); }
|
||||
|
||||
#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) {
|
||||
return (Term)((*HR = (CELL)HR, HR++));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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 t) {
|
||||
INLINE_ONLY
|
||||
inline EXTERN CELL *PtrOfTerm(Term t) {
|
||||
return (CELL *)(*(CELL *)(t));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@ -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 a) {
|
||||
INLINE_ONLY
|
||||
inline EXTERN Term MkAtomTerm(Atom 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) {
|
||||
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 at) {
|
||||
INLINE_ONLY
|
||||
inline EXTERN Term MkAtomTerm(Atom 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) {
|
||||
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 t) {
|
||||
INLINE_ONLY
|
||||
inline EXTERN bool IsAtomTerm(Term t) {
|
||||
return CHKTAG((t), AtomTag);
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
@ -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 n) {
|
||||
INLINE_ONLY
|
||||
inline EXTERN Term MkIntConstant(Int n) {
|
||||
return (Term)(NONTAGGED(NumberTag, (n)));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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 n USES_REGS) {
|
||||
INLINE_ONLY
|
||||
inline EXTERN Term __MkIntegerTerm(Int n USES_REGS) {
|
||||
return (Term)(IntInBnd(n) ? MkIntTerm(n) : MkLongIntTerm(n));
|
||||
}
|
||||
#endif
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
@ -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 *n USES_REGS) {
|
||||
INLINE_ONLY
|
||||
inline EXTERN Term __MkAddressTerm(void *n USES_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 t) {
|
||||
INLINE_ONLY
|
||||
inline EXTERN bool IsAddressTerm(Term t) {
|
||||
return (bool)IsIntegerTerm(t);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
INLINE_ONLY inline EXTERN Int IsPairTermOrNil (Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN Int
|
||||
INLINE_ONLY
|
||||
inline EXTERN Int
|
||||
IsPairOrNilTerm (Term t)
|
||||
{
|
||||
return IsPairTerm(t) || t == TermNil;
|
||||
|
27
H/YapTerm.h
27
H/YapTerm.h
@ -33,7 +33,7 @@ typedef void *Atom;
|
||||
(((CELL)(X) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1))
|
||||
|
||||
#ifndef EXTERN
|
||||
#ifdef _MSC_VER
|
||||
#ifdef MSC_VER
|
||||
#define EXTERN
|
||||
#else
|
||||
#define EXTERN extern
|
||||
@ -44,51 +44,30 @@ typedef void *Atom;
|
||||
** and integer types Short and UShort with half the size of a ptr */
|
||||
|
||||
#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 uintptr_t UInt;
|
||||
|
||||
#elif defined(_WIN64)
|
||||
|
||||
|
||||
typedef int64_t Int;
|
||||
typedef uint64_t UInt;
|
||||
#define Int_FORMAT "%I64d"
|
||||
#define UInt_FORMAT "%I64u"
|
||||
#define Int_F "I64d"
|
||||
#define UInt_F "I64u"
|
||||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
typedef int32_t Int;
|
||||
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
|
||||
|
||||
typedef long int Int;
|
||||
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
|
||||
|
||||
typedef int Int;
|
||||
typedef unsigned int UInt;
|
||||
#define Int_FORMAT "%l"
|
||||
#define UInt_FORMAT "%ul"
|
||||
#define Int_F "l"
|
||||
#define UInt_F "ul"
|
||||
|
||||
#else
|
||||
#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 SmallSize sizeof(SMALLUNSGN)
|
||||
|
||||
#include "YapFormat.h"
|
||||
|
||||
/*************************************************************************************************
|
||||
type casting macros
|
||||
*************************************************************************************************/
|
||||
|
74
H/YapText.h
74
H/YapText.h
@ -31,20 +31,39 @@
|
||||
#include "../utf8proc/utf8proc.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
|
||||
///
|
||||
extern void *Malloc(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 pop_text_stack( int lvl USES_REGS );
|
||||
extern int push_text_stack(USES_REGS1);
|
||||
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
|
||||
#define min(x,y) (x<y ? x : y)
|
||||
#define min(x, y) (x < y ? x : y)
|
||||
#endif
|
||||
|
||||
#define MBYTE (1024*1024)
|
||||
#define MBYTE (1024 * 1024)
|
||||
|
||||
/* 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
|
||||
extern char *Yap_chtype;
|
||||
|
||||
#define Yap_strlen(s) strlen((void *)(s))
|
||||
|
||||
typedef enum {
|
||||
BG = 0, /* initial state */
|
||||
UC = 1, /* Upper case */
|
||||
@ -156,24 +177,26 @@ INLINE_ONLY EXTERN inline char_kind_t chtype(Int ch) {
|
||||
#define __android_log_print(...)
|
||||
#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);
|
||||
|
||||
INLINE_ONLY inline EXTERN utf8proc_ssize_t get_utf8(const utf8proc_uint8_t *ptr, size_t n,
|
||||
utf8proc_int32_t *valp) {
|
||||
INLINE_ONLY inline EXTERN utf8proc_ssize_t get_utf8(const utf8proc_uint8_t *ptr,
|
||||
size_t n,
|
||||
utf8proc_int32_t *valp) {
|
||||
return utf8proc_iterate(ptr, n, valp);
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr,
|
||||
utf8proc_int32_t val);
|
||||
INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr,
|
||||
utf8proc_int32_t val);
|
||||
|
||||
INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr,
|
||||
utf8proc_int32_t val) {
|
||||
INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr,
|
||||
utf8proc_int32_t val) {
|
||||
return utf8proc_encode_char(val, ptr);
|
||||
}
|
||||
|
||||
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_int32_t b;
|
||||
for (i = 0; i < n; i++) {
|
||||
@ -198,7 +221,7 @@ inline static utf8proc_ssize_t strlen_utf8(const utf8proc_uint8_t *pt) {
|
||||
return rc;
|
||||
else if (b > 0) {
|
||||
pt += l;
|
||||
rc ++;
|
||||
rc++;
|
||||
} else {
|
||||
pt++;
|
||||
}
|
||||
@ -294,8 +317,8 @@ inline static int cmpn_utf8(const utf8proc_uint8_t *pt1,
|
||||
#define SURROGATE_OFFSET \
|
||||
((uint32_t)0x10000 - (uint32_t)(0xD800 << 10) - (uint32_t)0xDC00)
|
||||
|
||||
extern const char *Yap_tokText(void*tokptr);
|
||||
extern Term Yap_tokRep(void*tokptr);
|
||||
extern const char *Yap_tokText(void *tokptr);
|
||||
extern Term Yap_tokRep(void *tokptr);
|
||||
|
||||
// standard strings
|
||||
|
||||
@ -1383,17 +1406,16 @@ static inline Term Yap_UTF8ToString(const char *s USES_REGS) {
|
||||
}
|
||||
|
||||
static inline Atom UTF32ToAtom(const wchar_t *s USES_REGS) {
|
||||
seq_tv_t inp, out;
|
||||
|
||||
inp.val.w0 = s;
|
||||
inp.type = YAP_STRING_WCHARS ;
|
||||
out.type = YAP_STRING_ATOM;
|
||||
out.max = -1;
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
return 0L;
|
||||
return out.val.a;
|
||||
}
|
||||
seq_tv_t inp, out;
|
||||
|
||||
inp.val.w0 = s;
|
||||
inp.type = YAP_STRING_WCHARS;
|
||||
out.type = YAP_STRING_ATOM;
|
||||
out.max = -1;
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
return 0L;
|
||||
return out.val.a;
|
||||
}
|
||||
|
||||
static inline Term Yap_WCharsToListOfCodes(const wchar_t *s USES_REGS) {
|
||||
seq_tv_t inp, out;
|
||||
|
@ -13,12 +13,6 @@
|
||||
* 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 */
|
||||
|
||||
/* absmi.c */
|
||||
@ -309,6 +303,7 @@ extern struct vfs *Yap_InitAssetManager(void);
|
||||
|
||||
/* load_foreign.c */
|
||||
extern void Yap_InitLoadForeign(void);
|
||||
extern bool Yap_LateInit(const char s[]);
|
||||
|
||||
/* mavar.c */
|
||||
extern void Yap_InitMaVarCPreds(void);
|
||||
|
@ -139,7 +139,7 @@ register struct yami *P1REG asm("bp"); /* can't use yamop before Yap.h */
|
||||
|
||||
#include "Yap.h"
|
||||
#include "clause.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
@ -2327,6 +2327,8 @@ static inline void prune(choiceptr cp USES_REGS) {
|
||||
if (POP_CHOICE_POINT(B->cp_b)) {
|
||||
POP_EXECUTE();
|
||||
}
|
||||
if (B->cp_b == NULL)
|
||||
break;
|
||||
B = B->cp_b;
|
||||
}
|
||||
if (POP_CHOICE_POINT(B->cp_b)) {
|
||||
@ -2452,10 +2454,10 @@ extern yamop *headoftrace;
|
||||
ENDD(d0);
|
||||
#endif
|
||||
|
||||
#define Yap_AsmError(e, d) \
|
||||
#define Yap_AsmError(e, d) \
|
||||
{ \
|
||||
saveregs(); \
|
||||
Yap_ThrowError(e, d, 4, ""); \
|
||||
Yap_ThrowError(e, d, "while exwcuting inlined built-in"); \
|
||||
setregs(); \
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
#ifndef BLOBS_H
|
||||
#define BLOBS_H
|
||||
|
||||
#ifndef X_API
|
||||
#if !defined(X_API) && !defined(SWIGYAP)
|
||||
#if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(PL_KERNEL)
|
||||
#define X_API __declspec(dllexport)
|
||||
#else
|
||||
|
@ -250,6 +250,8 @@
|
||||
|
||||
#define LOCAL_nperm LOCAL->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 REMOTE_LabelFirstArray(wid) REMOTE(wid)->LabelFirstArray_
|
||||
|
@ -126,7 +126,7 @@ typedef struct worker_local {
|
||||
ADDR db_vec0_;
|
||||
struct RB_red_blk_node* db_root_;
|
||||
struct RB_red_blk_node* db_nil_;
|
||||
sigjmp_buf gc_restore_;
|
||||
sigjmp_buf* gc_restore_;
|
||||
CELL* extra_gc_cells_;
|
||||
CELL* extra_gc_cells_base_;
|
||||
CELL* extra_gc_cells_top_;
|
||||
@ -140,6 +140,7 @@ typedef struct worker_local {
|
||||
UInt CMemFirstBlockSz_;
|
||||
// Variable used by the compiler to store number of permanent vars in a clause
|
||||
int nperm_;
|
||||
int jMP_;
|
||||
// Thread Local Area for Labels
|
||||
Int* LabelFirstArray_;
|
||||
UInt LabelFirstArraySz_;
|
||||
@ -166,7 +167,7 @@ typedef struct worker_local {
|
||||
/* error handling info, designed to be easy to pass to the foreign world */
|
||||
yap_error_descriptor_t* ActiveError_;
|
||||
/// pointer to an exception term, from throw
|
||||
jmp_buf IOBotch_;
|
||||
jmp_buf* IOBotch_;
|
||||
TokEntry* tokptr_;
|
||||
TokEntry* toktide_;
|
||||
VarEntry* VarTable_;
|
||||
@ -177,7 +178,7 @@ typedef struct worker_local {
|
||||
wchar_t* CommentsBuff_;
|
||||
size_t CommentsBuffPos_;
|
||||
size_t CommentsBuffLim_;
|
||||
sigjmp_buf RestartEnv_;
|
||||
sigjmp_buf* RestartEnv_;
|
||||
char FileNameBuf_[YAP_FILENAME_MAX+1];
|
||||
char FileNameBuf2_[YAP_FILENAME_MAX+1];
|
||||
struct TextBuffer_manager* TextBuffer_;
|
||||
|
1165
H/generated/iatoms.h
1165
H/generated/iatoms.h
File diff suppressed because it is too large
Load Diff
@ -139,7 +139,8 @@ static void InitWorker(int wid) {
|
||||
REMOTE_CMemFirstBlock(wid) = NULL;
|
||||
REMOTE_CMemFirstBlockSz(wid) = 0L;
|
||||
|
||||
REMOTE_nperm(wid) = 0L;
|
||||
REMOTE_nperm(wid) = 0;
|
||||
REMOTE_jMP(wid) = 0;
|
||||
|
||||
REMOTE_LabelFirstArray(wid) = NULL;
|
||||
REMOTE_LabelFirstArraySz(wid) = 0L;
|
||||
|
1165
H/generated/ratoms.h
1165
H/generated/ratoms.h
File diff suppressed because it is too large
Load Diff
@ -145,6 +145,7 @@ static void RestoreWorker(int wid USES_REGS) {
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef THREADS
|
||||
|
||||
#endif /* THREADS */
|
||||
|
1884
H/generated/tatoms.h
1884
H/generated/tatoms.h
File diff suppressed because it is too large
Load Diff
@ -38,8 +38,8 @@ typedef enum {
|
||||
#define low_level_trace(Port, pred, args) low_level_trace__(Port, pred, args)
|
||||
#endif
|
||||
|
||||
void low_level_trace__(yap_low_level_port, PredEntry *, CELL *);
|
||||
void Yap_InitLowLevelTrace(void);
|
||||
void toggle_low_level_trace(void);
|
||||
extern bool low_level_trace__(yap_low_level_port, PredEntry *, CELL *);
|
||||
extern void Yap_InitLowLevelTrace(void);
|
||||
extern void toggle_low_level_trace(void);
|
||||
|
||||
#endif
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "Yap.h"
|
||||
#include "amijit.h"
|
||||
#include "clause.h"
|
||||
#include "eval.h"
|
||||
#include "YapEval.h"
|
||||
#if HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#else
|
||||
|
@ -76,16 +76,17 @@ endif (WITH_YAPOR_SBA)
|
||||
|
||||
|
||||
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 ()
|
||||
|
||||
set (POSITION_INDEPENDENT_CODE TRUE)
|
||||
SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 )
|
||||
|
||||
add_component (libOPTYap
|
||||
${OPTYap_SOURCES} )
|
||||
|
||||
|
||||
MY_set_target_properties(libOPTYap
|
||||
My_set_target_properties(libOPTYap
|
||||
PROPERTIES
|
||||
# RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION}
|
||||
# SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION}
|
||||
|
@ -170,7 +170,7 @@ struct page_statistics {
|
||||
#define INCREMENT_AUX_STATS(STATS, BYTES, PAGES) \
|
||||
BYTES += PgEnt_bytes_in_use(STATS)
|
||||
#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) \
|
||||
PgEnt_strs_in_use(STATS) * sizeof(STR_TYPE), PgEnt_strs_in_use(STATS)
|
||||
#endif /* USE_PAGES_MALLOC */
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user