This commit is contained in:
Vitor Santos Costa 2018-11-04 10:55:58 +00:00
parent a1f8631844
commit 76cfa609c2
27 changed files with 4500 additions and 4863 deletions

File diff suppressed because it is too large Load Diff

View File

@ -12,8 +12,8 @@
#include <string>
#include <vector>
extern "C"{
#include "config.h"
extern "C" {
#include "YapConfig.h"
}
#if HAVE_GMPXX_H
@ -41,17 +41,14 @@ extern "C"{
extern "C" {
#include <stdlib.h>
// Bad export from Python
#include <config.h>
#include <YapConfig.h>
#include <stddef.h>
#if YAP_PYTHON
#include <Python.h>
@ -102,22 +99,19 @@ X_API extern void YAP_UserCPredicate(const char *, YAP_UserCPred,
X_API extern void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
YAP_Arity, YAP_Term);
X_API extern void YAP_UserBackCPredicate(const char *name,
YAP_UserCPred init,
YAP_UserCPred cont,
YAP_Arity arity, YAP_Arity extra);
X_API extern void YAP_UserBackCPredicate(const char *name, YAP_UserCPred init,
YAP_UserCPred cont, YAP_Arity arity,
YAP_Arity extra);
X_API extern void YAP_UserBackCutCPredicate(const char *name,
YAP_UserCPred init,
YAP_UserCPred init,
YAP_UserCPred cont,
YAP_UserCPred cut,
YAP_Arity arity, YAP_Arity extra);
YAP_UserCPred cut, YAP_Arity arity,
YAP_Arity extra);
X_API extern YAP_Term YAP_ReadBuffer(const char *s, YAP_Term *tp);
extern YAP_Term YAP_MkcharPTerm(char *s);
}
class YAPEngine;
@ -130,7 +124,6 @@ class YAPModule;
class YAPError;
class YAPPredicate;
#include "yapa.hh"
#include "yapie.hh"

View File

@ -1,41 +1,40 @@
#include "config.h"
#include "YapConfig.h"
#include "udi.h"
#include "utarray.h"
#include "uthash.h"
/* Argument Indexing */
struct udi_p_args {
int arg; //indexed arg
void *idxstr; //user indexing structure
UdiControlBlock control; //user indexing structure functions
int arg; // indexed arg
void *idxstr; // user indexing structure
UdiControlBlock control; // user indexing structure functions
};
typedef struct udi_p_args *UdiPArg;
UT_icd arg_icd = {sizeof(struct udi_p_args), NULL, NULL, NULL };
UT_icd arg_icd = {sizeof(struct udi_p_args), NULL, NULL, NULL};
/* clauselist */
UT_icd cl_icd = {sizeof(yamop *), NULL, NULL, NULL };
UT_icd cl_icd = {sizeof(yamop *), NULL, NULL, NULL};
/*
* All the info we need to enter user indexed code
* stored in a uthash
*/
struct udi_info
{
PredEntry *p; //predicate (need to identify asserts)
UT_array *clauselist; //clause list used on returns
UT_array *args; //indexed args
UT_hash_handle hh; //uthash handle
struct udi_info {
PredEntry *p; // predicate (need to identify asserts)
UT_array *clauselist; // clause list used on returns
UT_array *args; // indexed args
UT_hash_handle hh; // uthash handle
};
typedef struct udi_info *UdiInfo;
/* to ease code for a UdiInfo hash table*/
#define HASH_FIND_UdiInfo(head,find,out) \
HASH_FIND(hh,head,find,sizeof(PredEntry),out)
#define HASH_ADD_UdiInfo(head,p,add) \
HASH_ADD_KEYPTR(hh,head,p,sizeof(PredEntry *),add)
#define HASH_FIND_UdiInfo(head, find, out) \
HASH_FIND(hh, head, find, sizeof(PredEntry), out)
#define HASH_ADD_UdiInfo(head, p, add) \
HASH_ADD_KEYPTR(hh, head, p, sizeof(PredEntry *), add)
/* used during init */
static YAP_Int p_new_udi( USES_REGS1 );
static YAP_Int p_new_udi(USES_REGS1);
static YAP_Int p_udi_args_init(Term spec, int arity, UdiInfo blk);
/*
@ -44,18 +43,15 @@ static YAP_Int p_udi_args_init(Term spec, int arity, UdiInfo blk);
/* single indexing helpers (no intersection needed just create clauselist) */
#include "clause_list.h"
struct si_callback_h
{
struct si_callback_h {
clause_list_t cl;
UT_array *clauselist;
void * pred;
void *pred;
};
typedef struct si_callback_h * si_callback_h_t;
typedef struct si_callback_h *si_callback_h_t;
static inline int si_callback(void *key, void *data, void *arg)
{
si_callback_h_t c = (si_callback_h_t) arg;
yamop **cl = (yamop **) utarray_eltptr(c->clauselist, ((YAP_Int) data) - 1);
static inline int si_callback(void *key, void *data, void *arg) {
si_callback_h_t c = (si_callback_h_t)arg;
yamop **cl = (yamop **)utarray_eltptr(c->clauselist, ((YAP_Int)data) - 1);
return Yap_ClauseListExtend(c->cl, *cl, c->pred);
}

View File

@ -1,23 +1,21 @@
/*************************************************************************
* *
* Yap Prolog *
* *
* Yap Prolog Was Developed At Nccup - Universidade Do Porto *
* *
* Copyright L.Damas, V.S.Costa And Universidade Do Porto 1985-1997 *
* *
**************************************************************************
* *
* File: Yap.C *
* Last Rev: *
* Mods: *
* Comments: Yap's Main File *
* *
*************************************************************************/
* *
* Yap Prolog *
* *
* Yap Prolog Was Developed At Nccup - Universidade Do Porto *
* *
* Copyright L.Damas, V.S.Costa And Universidade Do Porto 1985-1997 *
* *
**************************************************************************
* *
* File: Yap.C * Last Rev:
** Mods: * Comments: Yap's Main File *
* *
*************************************************************************/
/* static char SccsId[] = "X 4.3.3"; */
#include "YapConfig.h"
#include "YapInterface.h"
#include "config.h"
#include "cut_c.h"
@ -112,14 +110,13 @@ static bool exec_top_level(int BootMode, YAP_init_args *iap) {
livegoal = YAP_FullLookupAtom("live");
}
return true;
//YAP_Exit(EXIT_SUCCESS);
}
// YAP_Exit(EXIT_SUCCESS);
}
// FILE *debugf;
#ifdef LIGHT
int _main(int argc, char **argv)
#else
int main(int argc, char **argv)
@ -129,7 +126,7 @@ int main(int argc, char **argv)
int i;
YAP_init_args init_args;
BootMode = init_standard_system(argc, argv, &init_args);
if (BootMode == YAP_BOOT_ERROR) {
fprintf(stderr, "[ FATAL ERROR: could not find saved state ]\n");
exit(1);

View File

@ -19,7 +19,7 @@ extern "C" {
//=== includes ===============================================================
#ifdef YAP_KERNEL
#include "config.h"
#include "YapConfig.h"
#ifdef __cplusplus
}
@ -40,8 +40,8 @@ extern "C" {
#include "YapInterface.h"
#else
#if _YAP_NOT_INSTALLED_
#include <YapConfig.h>
#include <YapInterface.h>
#include <config.h>
#else
#include <Yap/YapInterface.h>
#endif

View File

@ -31,6 +31,8 @@ The following routines export the YAP internals and architecture.
#define _yap_c_interface_h 1
#include "YapConfig.h"
#define __YAP_PROLOG__ 1
#ifndef YAPVERSION

View File

@ -13,8 +13,8 @@
* *
*************************************************************************/
#include "YapConfig.h"
#include "YapInterface.h"
#include "config.h"
#include <math.h>
#if defined(__MINGW32__) || _MSC_VER
#include <windows.h>
@ -1281,7 +1281,7 @@ static YAP_Bool matrix_sum(void) {
y; // Alas, sum is big, y small, so low-order digits of y are lost.
c = (t - sum) - y; // (t - sum) cancels the high-order part of y;
// subtracting y recovers negative (low part of y)
sum = t; // Algebraically, c should always be zero. Beware
sum = t; // Algebraically, c should always be zero. Beware
// overly-aggressive optimizing compilers!
}
tf = YAP_MkFloatTerm(sum);

View File

@ -1,67 +1,56 @@
/*************************************************************************
* *
* YAP Prolog *
* *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* *
**************************************************************************
* *
* File: random.c *
* Last rev: *
* mods: *
* comments: regular expression interpreter *
* *
*************************************************************************/
* *
* YAP Prolog *
* *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* *
**************************************************************************
* *
* File: random.c * Last rev:
** mods: * comments: regular expression interpreter *
* *
*************************************************************************/
#include "config.h"
#include "YapInterface.h"
#include <math.h>
#if defined(__MINGW32__) || _MSC_VER
#include <windows.h>
#endif
X_API void init_random( void );
X_API void init_random(void);
static short a1 = 27314, b1 = 9213, c1 = 17773;
static YAP_Bool
p_random(void)
{
static YAP_Bool p_random(void) {
double fli;
long int t1, t2, t3;
t1 = (a1 * 171) % 30269;
t2 = (b1 * 172) % 30307;
t3 = (c1 * 170) % 30323;
fli = (t1/30269.0) + (t2/30307.0) + (t3/30323.0);
fli = (t1 / 30269.0) + (t2 / 30307.0) + (t3 / 30323.0);
a1 = t1;
b1 = t2;
c1 = t3;
return(YAP_Unify(YAP_ARG1, YAP_MkFloatTerm(fli-(int)(fli))));
return (YAP_Unify(YAP_ARG1, YAP_MkFloatTerm(fli - (int)(fli))));
}
static YAP_Bool
p_setrand(void)
{
static YAP_Bool p_setrand(void) {
a1 = YAP_IntOfTerm(YAP_ARG1);
b1 = YAP_IntOfTerm(YAP_ARG2);
c1 = YAP_IntOfTerm(YAP_ARG3);
return(TRUE);
return (TRUE);
}
static YAP_Bool
p_getrand(void)
{
return(YAP_Unify(YAP_ARG1,YAP_MkIntTerm(a1)) &&
YAP_Unify(YAP_ARG2,YAP_MkIntTerm(b1)) &&
YAP_Unify(YAP_ARG3,YAP_MkIntTerm(c1)));
static YAP_Bool p_getrand(void) {
return (YAP_Unify(YAP_ARG1, YAP_MkIntTerm(a1)) &&
YAP_Unify(YAP_ARG2, YAP_MkIntTerm(b1)) &&
YAP_Unify(YAP_ARG3, YAP_MkIntTerm(c1)));
}
X_API void
init_random(void)
{
X_API void init_random(void) {
YAP_UserCPredicate("random", p_random, 1);
YAP_UserCPredicate("setrand", p_setrand, 3);
YAP_UserCPredicate("getrand", p_getrand, 3);
@ -71,19 +60,17 @@ init_random(void)
int WINAPI win_random(HANDLE, DWORD, LPVOID);
int WINAPI win_random(HANDLE hinst, DWORD reason, LPVOID reserved)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
int WINAPI win_random(HANDLE hinst, DWORD reason, LPVOID reserved) {
switch (reason) {
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return 1;
}
#endif

View File

@ -50,7 +50,7 @@ static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
#include "YapInterface.h"
#include "config.h"
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

View File

@ -48,11 +48,10 @@ static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
* macros that code uses. This lets the same code operate on two different
* representations for state sets.
*/
#include "config.h"
#include "YapInterface.h"
#ifndef HAVE_REGEXEC
#include "YapInterface.h"
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
@ -68,8 +67,8 @@ static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
#include <limits.h>
#endif
#include "utils.h"
#include "regex2.h"
#include "utils.h"
#include "yapregex.h"
#if used

View File

@ -22,7 +22,6 @@
*
*/
#include "config.h"
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

View File

@ -38,66 +38,68 @@
*/
#ifndef _REGEX_H_
#define _REGEX_H_
#define _REGEX_H_
#include "YapInterface.h"
/* types */
typedef int regoff_t;
typedef struct {
int re_magic;
int re_nsub; /* number of parenthesized subexpressions */
const char *re_endp; /* end pointer for REG_PEND */
struct re_guts *re_g; /* none of your business :-) */
int re_magic;
int re_nsub; /* number of parenthesized subexpressions */
const char *re_endp; /* end pointer for REG_PEND */
struct re_guts *re_g; /* none of your business :-) */
} regex_t;
typedef struct {
regoff_t rm_so; /* start of match */
regoff_t rm_eo; /* end of match */
regoff_t rm_so; /* start of match */
regoff_t rm_eo; /* end of match */
} regmatch_t;
/* regcomp() flags */
#define REG_BASIC 0000
#define REG_EXTENDED 0001
#define REG_ICASE 0002
#define REG_NOSUB 0004
#define REG_NEWLINE 0010
#define REG_NOSPEC 0020
#define REG_PEND 0040
#define REG_DUMP 0200
#define REG_BASIC 0000
#define REG_EXTENDED 0001
#define REG_ICASE 0002
#define REG_NOSUB 0004
#define REG_NEWLINE 0010
#define REG_NOSPEC 0020
#define REG_PEND 0040
#define REG_DUMP 0200
/* regerror() flags */
#define REG_NOMATCH 1
#define REG_BADPAT 2
#define REG_ECOLLATE 3
#define REG_ECTYPE 4
#define REG_EESCAPE 5
#define REG_ESUBREG 6
#define REG_EBRACK 7
#define REG_EPAREN 8
#define REG_EBRACE 9
#define REG_BADBR 10
#define REG_ERANGE 11
#define REG_ESPACE 12
#define REG_BADRPT 13
#define REG_EMPTY 14
#define REG_ASSERT 15
#define REG_INVARG 16
#define REG_ATOI 255 /* convert name to number (!) */
#define REG_ITOA 0400 /* convert number to name (!) */
#define REG_NOMATCH 1
#define REG_BADPAT 2
#define REG_ECOLLATE 3
#define REG_ECTYPE 4
#define REG_EESCAPE 5
#define REG_ESUBREG 6
#define REG_EBRACK 7
#define REG_EPAREN 8
#define REG_EBRACE 9
#define REG_BADBR 10
#define REG_ERANGE 11
#define REG_ESPACE 12
#define REG_BADRPT 13
#define REG_EMPTY 14
#define REG_ASSERT 15
#define REG_INVARG 16
#define REG_ATOI 255 /* convert name to number (!) */
#define REG_ITOA 0400 /* convert number to name (!) */
/* regexec() flags */
#define REG_NOTBOL 00001
#define REG_NOTEOL 00002
#define REG_STARTEND 00004
#define REG_TRACE 00400 /* tracing of execution */
#define REG_LARGE 01000 /* force large representation */
#define REG_BACKR 02000 /* force use of backref code */
#define REG_NOTBOL 00001
#define REG_NOTEOL 00002
#define REG_STARTEND 00004
#define REG_TRACE 00400 /* tracing of execution */
#define REG_LARGE 01000 /* force large representation */
#define REG_BACKR 02000 /* force use of backref code */
#include "YapInterface.h"
int yap_regcomp(regex_t *, const char *, int);
size_t yap_regerror(int, const regex_t *, char *, size_t);
int yap_regexec(const regex_t *, const char *, size_t, regmatch_t [], int);
void yap_regfree(regex_t *);
int yap_regcomp(regex_t *, const char *, int);
size_t yap_regerror(int, const regex_t *, char *, size_t);
int yap_regexec(const regex_t *, const char *, size_t, regmatch_t[], int);
void yap_regfree(regex_t *);
#endif /* !_REGEX_H_ */

View File

@ -1,20 +1,19 @@
/*************************************************************************
* *
* YAP Prolog *
* *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* *
**************************************************************************
* *
*
* comments: regular expression interpreter *
* *
*************************************************************************/
* *
* YAP Prolog *
* *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* *
**************************************************************************
* *
*
* comments: regular expression interpreter *
* *
*************************************************************************/
#include "YapInterface.h"
#include "config.h"
#include <stdlib.h>
@ -312,22 +311,20 @@ static YAP_Bool rename_file(void) {
return (TRUE);
}
static YAP_Bool read_link(void) {
static YAP_Bool read_link(void) {
char *s1 = (char *)YAP_AtomName(YAP_AtomOfTerm(YAP_ARG1));
#if HAVE_READLINK
char buf[MAXPATHLEN + 1];
if (readlink(s1, buf, MAXPATHLEN) < 0)
return false;
/* return an error number */
/* return an error number */
if (!YAP_Unify(YAP_ARG2, YAP_MkAtomTerm(YAP_LookupAtom(buf)))) {
return false;
return false;
}
#endif
# if _WIN32
#if _WIN32
return false;
#endif
return true;

File diff suppressed because it is too large Load Diff

View File

@ -5,61 +5,55 @@
version: $ID$
*********************************************/
/* -------------------------------------- */
/* Yap Tagging Scheme */
/* -------------------------------------- */
#include "config.h"
#if SIZEOF_INT_P==4
#define TAG_LOW_BITS_32 /* 'Tags_32LowTag.h' tagging scheme */
#include "YapInterface.h"
#if SIZEOF_INT_P == 4
#define TAG_LOW_BITS_32 /* 'Tags_32LowTag.h' tagging scheme */
#define SIZE_FLOAT_AS_TERM 2
#elif SIZEOF_INT_P==8
#define TAG_64BITS /* 'Tags_64bits.h' tagging scheme */
#elif SIZEOF_INT_P == 8
#define TAG_64BITS /* 'Tags_64bits.h' tagging scheme */
#define SIZE_FLOAT_AS_TERM 1
#else
#error Unknown tagging scheme
#endif /* YAP_SCHEME */
/* --------------------------- */
/* Defines */
/* --------------------------- */
#ifdef TAG_LOW_BITS_32
#define ApplTag 1 /* 0x01 */
#else /* TAG_64BITS */
#define ApplTag 5 /* 0x05 */
#endif /* TAG_SCHEME */
#define PairInitTag 3 /* 0x03 */
#define PairEndEmptyTag 19 /* 0x13 */
#define PairEndTermTag 99 /* 0x63 */
#define CommaInitTag 35 /* 0x23 */
#define CommaEndTag 51 /* 0x33 */
#define FloatInitTag 67 /* 0x43 */
#define FloatEndTag 83 /* 0x53 */
#define ApplTag 1 /* 0x01 */
#else /* TAG_64BITS */
#define ApplTag 5 /* 0x05 */
#endif /* TAG_SCHEME */
#define PairInitTag 3 /* 0x03 */
#define PairEndEmptyTag 19 /* 0x13 */
#define PairEndTermTag 99 /* 0x63 */
#define CommaInitTag 35 /* 0x23 */
#define CommaEndTag 51 /* 0x33 */
#define FloatInitTag 67 /* 0x43 */
#define FloatEndTag 83 /* 0x53 */
#define TRIE_MODE_STANDARD 0
#define TRIE_MODE_REVERSE 1
#define TRIE_MODE_MINIMAL 2
#define TRIE_MODE_REVMIN TRIE_MODE_REVERSE || TRIE_MODE_MINIMAL //3
#define TRIE_MODE_STANDARD 0
#define TRIE_MODE_REVERSE 1
#define TRIE_MODE_MINIMAL 2
#define TRIE_MODE_REVMIN TRIE_MODE_REVERSE || TRIE_MODE_MINIMAL // 3
#define TRIE_PRINT_NORMAL 0
#define TRIE_PRINT_FLOAT 1
#define TRIE_PRINT_FLOAT2 2
#define TRIE_PRINT_NORMAL 0
#define TRIE_PRINT_FLOAT 1
#define TRIE_PRINT_FLOAT2 2
#define TRIE_PRINT_FLOAT_END 3
#define BASE_AUXILIARY_TERM_STACK_SIZE 100000
/* --------------------------- */
/* Structs */
/* --------------------------- */
typedef struct trie_engine {
typedef struct trie_engine {
struct trie_node *first_trie;
/* in use */
YAP_Int memory_in_use;
@ -71,17 +65,17 @@ typedef struct trie_engine {
YAP_Int tries_max_used;
YAP_Int entries_max_used;
YAP_Int nodes_max_used;
} *TrEngine;
} * TrEngine;
#define TrEngine_trie(X) ((X)->first_trie)
#define TrEngine_memory(X) ((X)->memory_in_use)
#define TrEngine_tries(X) ((X)->tries_in_use)
#define TrEngine_entries(X) ((X)->entries_in_use)
#define TrEngine_nodes(X) ((X)->nodes_in_use)
#define TrEngine_memory_max(X) ((X)->memory_max_used)
#define TrEngine_tries_max(X) ((X)->tries_max_used)
#define TrEngine_trie(X) ((X)->first_trie)
#define TrEngine_memory(X) ((X)->memory_in_use)
#define TrEngine_tries(X) ((X)->tries_in_use)
#define TrEngine_entries(X) ((X)->entries_in_use)
#define TrEngine_nodes(X) ((X)->nodes_in_use)
#define TrEngine_memory_max(X) ((X)->memory_max_used)
#define TrEngine_tries_max(X) ((X)->tries_max_used)
#define TrEngine_entries_max(X) ((X)->entries_max_used)
#define TrEngine_nodes_max(X) ((X)->nodes_max_used)
#define TrEngine_nodes_max(X) ((X)->nodes_max_used)
typedef struct trie_node {
struct trie_node *parent;
@ -89,230 +83,253 @@ typedef struct trie_node {
struct trie_node *next;
struct trie_node *previous;
YAP_Term entry;
} *TrNode;
} * TrNode;
#define TrNode_parent(X) ((X)->parent)
#define TrNode_child(X) ((X)->child)
#define TrNode_next(X) ((X)->next)
#define TrNode_parent(X) ((X)->parent)
#define TrNode_child(X) ((X)->child)
#define TrNode_next(X) ((X)->next)
#define TrNode_previous(X) ((X)->previous)
#define TrNode_entry(X) ((X)->entry)
#define TrNode_entry(X) ((X)->entry)
typedef struct trie_hash {
struct trie_node *parent; /* for compatibility with the trie_node data structure */
struct trie_node
*parent; /* for compatibility with the trie_node data structure */
struct trie_node **buckets;
int number_of_buckets;
int number_of_nodes;
} *TrHash;
} * TrHash;
#define TrHash_mark(X) ((X)->parent)
#define TrHash_buckets(X) ((X)->buckets)
#define TrHash_bucket(X,N) ((X)->buckets + N)
#define TrHash_mark(X) ((X)->parent)
#define TrHash_buckets(X) ((X)->buckets)
#define TrHash_bucket(X, N) ((X)->buckets + N)
#define TrHash_num_buckets(X) ((X)->number_of_buckets)
#define TrHash_seed(X) ((X)->number_of_buckets - 1)
#define TrHash_num_nodes(X) ((X)->number_of_nodes)
#define TYPE_TR_ENGINE struct trie_engine
#define TYPE_TR_NODE struct trie_node
#define TYPE_TR_HASH struct trie_hash
#define SIZEOF_TR_ENGINE sizeof(TYPE_TR_ENGINE)
#define SIZEOF_TR_NODE sizeof(TYPE_TR_NODE)
#define SIZEOF_TR_HASH sizeof(TYPE_TR_HASH)
#define SIZEOF_TR_BUCKET sizeof(TYPE_TR_NODE *)
#define AS_TR_NODE_NEXT(ADDR) (TrNode)((YAP_UInt)(ADDR) - 2 * sizeof(struct trie_node *))
#define TrHash_seed(X) ((X)->number_of_buckets - 1)
#define TrHash_num_nodes(X) ((X)->number_of_nodes)
#define TYPE_TR_ENGINE struct trie_engine
#define TYPE_TR_NODE struct trie_node
#define TYPE_TR_HASH struct trie_hash
#define SIZEOF_TR_ENGINE sizeof(TYPE_TR_ENGINE)
#define SIZEOF_TR_NODE sizeof(TYPE_TR_NODE)
#define SIZEOF_TR_HASH sizeof(TYPE_TR_HASH)
#define SIZEOF_TR_BUCKET sizeof(TYPE_TR_NODE *)
#define AS_TR_NODE_NEXT(ADDR) \
(TrNode)((YAP_UInt)(ADDR)-2 * sizeof(struct trie_node *))
/* --------------------------- */
/* Macros */
/* --------------------------- */
#define TAG_ADDR(ADDR) ((YAP_UInt)(ADDR) | 0x1)
#define UNTAG_ADDR(ADDR) ((YAP_UInt)(ADDR) & ~(0x1))
#define PUT_DATA_IN_LEAF_TRIE_NODE(TR_NODE, DATA) TrNode_child(TR_NODE) = (TrNode)TAG_ADDR(DATA)
#define GET_DATA_FROM_LEAF_TRIE_NODE(TR_NODE) UNTAG_ADDR(TrNode_child(TR_NODE))
#define MARK_AS_LEAF_TRIE_NODE(TR_NODE) PUT_DATA_IN_LEAF_TRIE_NODE(TR_NODE, TrNode_child(TR_NODE))
#define IS_LEAF_TRIE_NODE(TR_NODE) ((YAP_UInt)(TrNode_child(TR_NODE)) & 0x1)
#define TAG_ADDR(ADDR) ((YAP_UInt)(ADDR) | 0x1)
#define UNTAG_ADDR(ADDR) ((YAP_UInt)(ADDR) & ~(0x1))
#define PUT_DATA_IN_LEAF_TRIE_NODE(TR_NODE, DATA) \
TrNode_child(TR_NODE) = (TrNode)TAG_ADDR(DATA)
#define GET_DATA_FROM_LEAF_TRIE_NODE(TR_NODE) UNTAG_ADDR(TrNode_child(TR_NODE))
#define MARK_AS_LEAF_TRIE_NODE(TR_NODE) \
PUT_DATA_IN_LEAF_TRIE_NODE(TR_NODE, TrNode_child(TR_NODE))
#define IS_LEAF_TRIE_NODE(TR_NODE) ((YAP_UInt)(TrNode_child(TR_NODE)) & 0x1)
#define IsTrieVar(TERM, STACK, STACK_BASE) ((YAP_Term *)(TERM) > STACK && (YAP_Term *)(TERM) <= STACK_BASE)
#define MkTrieVar(INDEX) ((INDEX) << 4)
#define TrieVarIndex(TERM) ((TERM) >> 4)
#define IsTrieVar(TERM, STACK, STACK_BASE) \
((YAP_Term *)(TERM) > STACK && (YAP_Term *)(TERM) <= STACK_BASE)
#define MkTrieVar(INDEX) ((INDEX) << 4)
#define TrieVarIndex(TERM) ((TERM) >> 4)
#define BASE_HASH_BUCKETS 256
#define BASE_HASH_BUCKETS 256
#define MAX_NODES_PER_TRIE_LEVEL 32
#define MAX_NODES_PER_BUCKET (MAX_NODES_PER_TRIE_LEVEL / 2)
#define HASH_TERM(TERM, SEED) (((TERM) >> 4) & (SEED))
#define IS_HASH_NODE(NODE) (TrHash_mark(NODE) == NULL)
#define MAX_NODES_PER_BUCKET (MAX_NODES_PER_TRIE_LEVEL / 2)
#define HASH_TERM(TERM, SEED) (((TERM) >> 4) & (SEED))
#define IS_HASH_NODE(NODE) (TrHash_mark(NODE) == NULL)
#define BASE_SAVE_MARK 10000 /* could lead to errors if the number of different variables in a term is greater than it */
#define HASH_SAVE_MARK ((YAP_Term) MkTrieVar(BASE_SAVE_MARK))
#define ATOM_SAVE_MARK ((YAP_Term) MkTrieVar(BASE_SAVE_MARK + 1))
#define FUNCTOR_SAVE_MARK ((YAP_Term) MkTrieVar(BASE_SAVE_MARK + 2))
#define FLOAT_SAVE_MARK ((YAP_Term) MkTrieVar(BASE_SAVE_MARK + 3))
#define BASE_SAVE_MARK \
10000 /* could lead to errors if the number of different variables in a term \
is greater than it */
#define HASH_SAVE_MARK ((YAP_Term)MkTrieVar(BASE_SAVE_MARK))
#define ATOM_SAVE_MARK ((YAP_Term)MkTrieVar(BASE_SAVE_MARK + 1))
#define FUNCTOR_SAVE_MARK ((YAP_Term)MkTrieVar(BASE_SAVE_MARK + 2))
#define FLOAT_SAVE_MARK ((YAP_Term)MkTrieVar(BASE_SAVE_MARK + 3))
#define STACK_NOT_EMPTY(STACK, STACK_BASE) STACK != STACK_BASE
#define POP_UP(STACK) *--STACK
#define POP_DOWN(STACK) *++STACK
#define PUSH_UP(STACK, ITEM, STACK_TOP) \
{ if (STACK < STACK_TOP) { \
fprintf(stderr, "**************************************\n"); \
fprintf(stderr, " Tries core module: term stack full\n"); \
fprintf(stderr, "**************************************\n"); \
} \
*STACK = (YAP_Term)(ITEM); \
STACK--; \
}
#define PUSH_DOWN(STACK, ITEM, STACK_TOP) \
{ if (STACK > STACK_TOP) { \
fprintf(stderr, "**************************************\n"); \
fprintf(stderr, " Tries core module: term stack empty\n"); \
fprintf(stderr, "**************************************\n"); \
} \
*STACK = (YAP_Term)(ITEM); \
STACK++; \
}
#define POP_UP(STACK) *--STACK
#define POP_DOWN(STACK) *++STACK
#define PUSH_UP(STACK, ITEM, STACK_TOP) \
{ \
if (STACK < STACK_TOP) { \
fprintf(stderr, "**************************************\n"); \
fprintf(stderr, " Tries core module: term stack full\n"); \
fprintf(stderr, "**************************************\n"); \
} \
*STACK = (YAP_Term)(ITEM); \
STACK--; \
}
#define PUSH_DOWN(STACK, ITEM, STACK_TOP) \
{ \
if (STACK > STACK_TOP) { \
fprintf(stderr, "**************************************\n"); \
fprintf(stderr, " Tries core module: term stack empty\n"); \
fprintf(stderr, "**************************************\n"); \
} \
*STACK = (YAP_Term)(ITEM); \
STACK++; \
}
#define new_struct(STR, STR_TYPE, STR_SIZE) \
STR = (STR_TYPE *)YAP_AllocSpaceFromYap(STR_SIZE)
#define new_trie_engine(TR_ENGINE) \
{ \
new_struct(TR_ENGINE, TYPE_TR_ENGINE, SIZEOF_TR_ENGINE); \
TrEngine_trie(TR_ENGINE) = NULL; \
TrEngine_memory(TR_ENGINE) = 0; \
TrEngine_tries(TR_ENGINE) = 0; \
TrEngine_entries(TR_ENGINE) = 0; \
TrEngine_nodes(TR_ENGINE) = 0; \
TrEngine_memory_max(TR_ENGINE) = 0; \
TrEngine_tries_max(TR_ENGINE) = 0; \
TrEngine_entries_max(TR_ENGINE) = 0; \
TrEngine_nodes_max(TR_ENGINE) = 0; \
}
#define new_trie_node(TR_NODE, ENTRY, PARENT, CHILD, NEXT, PREVIOUS) \
{ \
new_struct(TR_NODE, TYPE_TR_NODE, SIZEOF_TR_NODE); \
TrNode_entry(TR_NODE) = ENTRY; \
TrNode_parent(TR_NODE) = PARENT; \
TrNode_child(TR_NODE) = CHILD; \
TrNode_next(TR_NODE) = NEXT; \
TrNode_previous(TR_NODE) = PREVIOUS; \
INCREMENT_NODES(CURRENT_TRIE_ENGINE); \
INCREMENT_MEMORY(CURRENT_TRIE_ENGINE, SIZEOF_TR_NODE); \
}
#define new_trie_hash(TR_HASH, NUM_NODES, NUM_BUCKETS) \
{ \
new_struct(TR_HASH, TYPE_TR_HASH, SIZEOF_TR_HASH); \
TrHash_mark(TR_HASH) = NULL; \
TrHash_num_buckets(TR_HASH) = NUM_BUCKETS; \
new_hash_buckets(TR_HASH, NUM_BUCKETS); \
TrHash_num_nodes(TR_HASH) = NUM_NODES; \
INCREMENT_MEMORY(CURRENT_TRIE_ENGINE, SIZEOF_TR_HASH); \
}
#define new_hash_buckets(TR_HASH, NUM_BUCKETS) \
{ \
int i; \
void **ptr; \
new_struct(ptr, void *, NUM_BUCKETS * sizeof(void *)); \
TrHash_buckets(TR_HASH) = (TYPE_TR_NODE **)ptr; \
for (i = NUM_BUCKETS; i != 0; i--) \
*ptr++ = NULL; \
INCREMENT_MEMORY(CURRENT_TRIE_ENGINE, (NUM_BUCKETS)*SIZEOF_TR_BUCKET); \
}
#define expand_auxiliary_term_stack() \
{ \
YAP_Term *aux_stack; \
YAP_Int aux_size = CURRENT_AUXILIARY_TERM_STACK_SIZE * sizeof(YAP_Term); \
new_struct(aux_stack, YAP_Term, aux_size * 2); \
memmove(aux_stack, AUXILIARY_TERM_STACK, aux_size); \
free_struct(AUXILIARY_TERM_STACK); \
AUXILIARY_TERM_STACK = aux_stack; \
CURRENT_AUXILIARY_TERM_STACK_SIZE *= 2; \
}
#define new_struct(STR, STR_TYPE, STR_SIZE) \
STR = (STR_TYPE *) YAP_AllocSpaceFromYap(STR_SIZE)
#define new_trie_engine(TR_ENGINE) \
{ new_struct(TR_ENGINE, TYPE_TR_ENGINE, SIZEOF_TR_ENGINE); \
TrEngine_trie(TR_ENGINE) = NULL; \
TrEngine_memory(TR_ENGINE) = 0; \
TrEngine_tries(TR_ENGINE) = 0; \
TrEngine_entries(TR_ENGINE) = 0; \
TrEngine_nodes(TR_ENGINE) = 0; \
TrEngine_memory_max(TR_ENGINE) = 0; \
TrEngine_tries_max(TR_ENGINE) = 0; \
TrEngine_entries_max(TR_ENGINE) = 0; \
TrEngine_nodes_max(TR_ENGINE) = 0; \
}
#define new_trie_node(TR_NODE, ENTRY, PARENT, CHILD, NEXT, PREVIOUS) \
{ new_struct(TR_NODE, TYPE_TR_NODE, SIZEOF_TR_NODE); \
TrNode_entry(TR_NODE) = ENTRY; \
TrNode_parent(TR_NODE) = PARENT; \
TrNode_child(TR_NODE) = CHILD; \
TrNode_next(TR_NODE) = NEXT; \
TrNode_previous(TR_NODE) = PREVIOUS; \
INCREMENT_NODES(CURRENT_TRIE_ENGINE); \
INCREMENT_MEMORY(CURRENT_TRIE_ENGINE, SIZEOF_TR_NODE); \
}
#define new_trie_hash(TR_HASH, NUM_NODES, NUM_BUCKETS) \
{ new_struct(TR_HASH, TYPE_TR_HASH, SIZEOF_TR_HASH); \
TrHash_mark(TR_HASH) = NULL; \
TrHash_num_buckets(TR_HASH) = NUM_BUCKETS; \
new_hash_buckets(TR_HASH, NUM_BUCKETS); \
TrHash_num_nodes(TR_HASH) = NUM_NODES; \
INCREMENT_MEMORY(CURRENT_TRIE_ENGINE, SIZEOF_TR_HASH); \
}
#define new_hash_buckets(TR_HASH, NUM_BUCKETS) \
{ int i; void **ptr; \
new_struct(ptr, void *, NUM_BUCKETS * sizeof(void *)); \
TrHash_buckets(TR_HASH) = (TYPE_TR_NODE **) ptr; \
for (i = NUM_BUCKETS; i != 0; i--) \
*ptr++ = NULL; \
INCREMENT_MEMORY(CURRENT_TRIE_ENGINE, (NUM_BUCKETS) * SIZEOF_TR_BUCKET); \
}
#define free_struct(STR) YAP_FreeSpaceFromYap((char *)(STR))
#define free_trie_node(STR) \
{ \
free_struct(STR); \
DECREMENT_NODES(CURRENT_TRIE_ENGINE); \
DECREMENT_MEMORY(CURRENT_TRIE_ENGINE, SIZEOF_TR_NODE); \
}
#define free_trie_hash(STR) \
{ \
free_struct(STR); \
DECREMENT_MEMORY(CURRENT_TRIE_ENGINE, SIZEOF_TR_HASH); \
}
#define free_hash_buckets(STR, NUM_BUCKETS) \
{ \
free_struct(STR); \
DECREMENT_MEMORY(CURRENT_TRIE_ENGINE, (NUM_BUCKETS)*SIZEOF_TR_BUCKET); \
}
#define INCREMENT_MEMORY(TR_ENGINE, SIZE) \
{ \
TrEngine_memory(TR_ENGINE) += SIZE; \
if (TrEngine_memory(TR_ENGINE) > TrEngine_memory_max(TR_ENGINE)) \
TrEngine_memory_max(TR_ENGINE) = TrEngine_memory(TR_ENGINE); \
}
#define INCREMENT_TRIES(TR_ENGINE) \
{ \
TrEngine_tries(TR_ENGINE)++; \
if (TrEngine_tries(TR_ENGINE) > TrEngine_tries_max(TR_ENGINE)) \
TrEngine_tries_max(TR_ENGINE) = TrEngine_tries(TR_ENGINE); \
}
#define INCREMENT_ENTRIES(TR_ENGINE) \
{ \
TrEngine_entries(TR_ENGINE)++; \
if (TrEngine_entries(TR_ENGINE) > TrEngine_entries_max(TR_ENGINE)) \
TrEngine_entries_max(TR_ENGINE) = TrEngine_entries(TR_ENGINE); \
}
#define INCREMENT_NODES(TR_ENGINE) \
{ \
TrEngine_nodes(TR_ENGINE)++; \
if (TrEngine_nodes(TR_ENGINE) > TrEngine_nodes_max(TR_ENGINE)) \
TrEngine_nodes_max(TR_ENGINE) = TrEngine_nodes(TR_ENGINE); \
}
#define DECREMENT_MEMORY(TR_ENGINE, SIZE) TrEngine_memory(TR_ENGINE) -= SIZE
#define DECREMENT_TRIES(TR_ENGINE) TrEngine_tries(TR_ENGINE)--
#define DECREMENT_ENTRIES(TR_ENGINE) TrEngine_entries(TR_ENGINE)--
#define DECREMENT_NODES(TR_ENGINE) TrEngine_nodes(TR_ENGINE)--
#define expand_auxiliary_term_stack() \
{ YAP_Term *aux_stack; \
YAP_Int aux_size = CURRENT_AUXILIARY_TERM_STACK_SIZE * sizeof(YAP_Term); \
new_struct(aux_stack, YAP_Term, aux_size * 2); \
memmove(aux_stack, AUXILIARY_TERM_STACK, aux_size); \
free_struct(AUXILIARY_TERM_STACK); \
AUXILIARY_TERM_STACK = aux_stack; \
CURRENT_AUXILIARY_TERM_STACK_SIZE *= 2; \
}
#define free_struct(STR) \
YAP_FreeSpaceFromYap((char *) (STR))
#define free_trie_node(STR) \
{ free_struct(STR); \
DECREMENT_NODES(CURRENT_TRIE_ENGINE); \
DECREMENT_MEMORY(CURRENT_TRIE_ENGINE, SIZEOF_TR_NODE); \
}
#define free_trie_hash(STR) \
{ free_struct(STR); \
DECREMENT_MEMORY(CURRENT_TRIE_ENGINE, SIZEOF_TR_HASH); \
}
#define free_hash_buckets(STR, NUM_BUCKETS) \
{ free_struct(STR); \
DECREMENT_MEMORY(CURRENT_TRIE_ENGINE, (NUM_BUCKETS) * SIZEOF_TR_BUCKET); \
}
#define INCREMENT_MEMORY(TR_ENGINE, SIZE) \
{ TrEngine_memory(TR_ENGINE) += SIZE; \
if (TrEngine_memory(TR_ENGINE) > TrEngine_memory_max(TR_ENGINE)) \
TrEngine_memory_max(TR_ENGINE) = TrEngine_memory(TR_ENGINE); \
}
#define INCREMENT_TRIES(TR_ENGINE) \
{ TrEngine_tries(TR_ENGINE)++; \
if (TrEngine_tries(TR_ENGINE) > TrEngine_tries_max(TR_ENGINE)) \
TrEngine_tries_max(TR_ENGINE) = TrEngine_tries(TR_ENGINE); \
}
#define INCREMENT_ENTRIES(TR_ENGINE) \
{ TrEngine_entries(TR_ENGINE)++; \
if (TrEngine_entries(TR_ENGINE) > TrEngine_entries_max(TR_ENGINE)) \
TrEngine_entries_max(TR_ENGINE) = TrEngine_entries(TR_ENGINE); \
}
#define INCREMENT_NODES(TR_ENGINE) \
{ TrEngine_nodes(TR_ENGINE)++; \
if (TrEngine_nodes(TR_ENGINE) > TrEngine_nodes_max(TR_ENGINE)) \
TrEngine_nodes_max(TR_ENGINE) = TrEngine_nodes(TR_ENGINE); \
}
#define DECREMENT_MEMORY(TR_ENGINE, SIZE) \
TrEngine_memory(TR_ENGINE) -= SIZE
#define DECREMENT_TRIES(TR_ENGINE) \
TrEngine_tries(TR_ENGINE)--
#define DECREMENT_ENTRIES(TR_ENGINE) \
TrEngine_entries(TR_ENGINE)--
#define DECREMENT_NODES(TR_ENGINE) \
TrEngine_nodes(TR_ENGINE)--
#define IS_FUNCTOR_NODE(N) (((ApplTag & TrNode_entry(N)) == ApplTag) && \
(TrNode_entry(N) != PairInitTag) && \
(TrNode_entry(N) != PairEndEmptyTag) && \
(TrNode_entry(N) != PairEndTermTag))
#define IS_FUNCTOR_NODE(N) \
(((ApplTag & TrNode_entry(N)) == ApplTag) && \
(TrNode_entry(N) != PairInitTag) && (TrNode_entry(N) != PairEndEmptyTag) && \
(TrNode_entry(N) != PairEndTermTag))
/* --------------------------- */
/* API */
/* --------------------------- */
extern TrEngine core_trie_init_module(void);
extern TrNode core_trie_open(TrEngine engine);
extern void core_trie_close(TrEngine engine, TrNode node, void (*destruct_function)(TrNode));
extern void core_trie_close_all(TrEngine engine, void (*destruct_function)(TrNode));
extern void core_trie_set_mode(YAP_Int mode);
extern YAP_Int core_trie_get_mode(void);
extern TrNode core_trie_put_entry(TrEngine engine, TrNode node, YAP_Term entry, YAP_Int *depth);
extern TrNode core_trie_check_entry(TrNode node, YAP_Term entry);
extern TrNode core_trie_open(TrEngine engine);
extern void core_trie_close(TrEngine engine, TrNode node,
void (*destruct_function)(TrNode));
extern void core_trie_close_all(TrEngine engine,
void (*destruct_function)(TrNode));
extern void core_trie_set_mode(YAP_Int mode);
extern YAP_Int core_trie_get_mode(void);
extern TrNode core_trie_put_entry(TrEngine engine, TrNode node, YAP_Term entry,
YAP_Int *depth);
extern TrNode core_trie_check_entry(TrNode node, YAP_Term entry);
extern YAP_Term core_trie_get_entry(TrNode node);
extern void core_trie_remove_entry(TrEngine engine, TrNode node, void (*destruct_function)(TrNode));
extern void core_trie_remove_subtree(TrEngine engine, TrNode node, void (*destruct_function)(TrNode));
extern void core_trie_add(TrNode node_dest, TrNode node_source, void (*add_function)(TrNode, TrNode));
extern void core_trie_join(TrEngine engine, TrNode node_dest, TrNode node_source, void (*add_function)(TrNode, TrNode), void (*copy_function)(TrNode, TrNode));
extern void core_trie_intersect(TrEngine engine, TrNode node_dest, TrNode node_source, void (*add_function)(TrNode, TrNode), void (*destruct_function)(TrNode));
extern YAP_Int core_trie_count_join(TrNode node1, TrNode node2);
extern YAP_Int core_trie_count_intersect(TrNode node1, TrNode node2);
extern void core_trie_save(TrNode node, FILE *file, void (*save_function)(TrNode, FILE *));
extern TrNode core_trie_load(TrEngine engine, FILE *file, void (*load_function)(TrNode, YAP_Int, FILE *));
extern void core_trie_stats(TrEngine engine, YAP_Int *memory, YAP_Int *tries, YAP_Int *entries, YAP_Int *nodes);
extern void core_trie_max_stats(TrEngine engine, YAP_Int *memory, YAP_Int *tries, YAP_Int *entries, YAP_Int *nodes);
extern void core_trie_usage(TrNode node, YAP_Int *entries, YAP_Int *nodes, YAP_Int *virtual_nodes);
extern void core_trie_print(TrNode node, void (*print_function)(TrNode));
extern void core_trie_remove_entry(TrEngine engine, TrNode node,
void (*destruct_function)(TrNode));
extern void core_trie_remove_subtree(TrEngine engine, TrNode node,
void (*destruct_function)(TrNode));
extern void core_trie_add(TrNode node_dest, TrNode node_source,
void (*add_function)(TrNode, TrNode));
extern void core_trie_join(TrEngine engine, TrNode node_dest,
TrNode node_source,
void (*add_function)(TrNode, TrNode),
void (*copy_function)(TrNode, TrNode));
extern void core_trie_intersect(TrEngine engine, TrNode node_dest,
TrNode node_source,
void (*add_function)(TrNode, TrNode),
void (*destruct_function)(TrNode));
extern YAP_Int core_trie_count_join(TrNode node1, TrNode node2);
extern YAP_Int core_trie_count_intersect(TrNode node1, TrNode node2);
extern void core_trie_save(TrNode node, FILE *file,
void (*save_function)(TrNode, FILE *));
extern TrNode core_trie_load(TrEngine engine, FILE *file,
void (*load_function)(TrNode, YAP_Int, FILE *));
extern void core_trie_stats(TrEngine engine, YAP_Int *memory, YAP_Int *tries,
YAP_Int *entries, YAP_Int *nodes);
extern void core_trie_max_stats(TrEngine engine, YAP_Int *memory,
YAP_Int *tries, YAP_Int *entries,
YAP_Int *nodes);
extern void core_trie_usage(TrNode node, YAP_Int *entries, YAP_Int *nodes,
YAP_Int *virtual_nodes);
extern void core_trie_print(TrNode node, void (*print_function)(TrNode));
extern void core_disable_hash_table(void);
extern void core_enable_hash_table(void);
extern void core_disable_hash_table(void);
extern void core_enable_hash_table(void);
extern YAP_Term core_trie_to_list(TrNode node);
extern YAP_Term core_trie_to_list(TrNode node);
#include "core_dbtries.h"

View File

@ -16,8 +16,7 @@
/* Written by Eric Blake <e...@byu.net>, 2010. */
#include "config.h"
#include "YapConfig.h"
/* Specification. */
#include <stdio.h>
@ -32,60 +31,55 @@
#if !HAVE_OPEN_MEMSTREAM && !_WIN32
#if !HAVE_FUNOPEN
# error Sorry, not ported to your platform yet
#error Sorry, not ported to your platform yet
#else
FILE * open_memstream (char **buf, size_t *len);
FILE *open_memstream(char **buf, size_t *len);
# define INITIAL_ALLOC 64
#define INITIAL_ALLOC 64
struct data
{
char **buf; /* User's argument. */
size_t *len; /* User's argument. Smaller of pos or eof. */
size_t pos; /* Current position. */
size_t eof; /* End-of-file position. */
struct data {
char **buf; /* User's argument. */
size_t *len; /* User's argument. Smaller of pos or eof. */
size_t pos; /* Current position. */
size_t eof; /* End-of-file position. */
size_t allocated; /* Allocated size of *buf, always > eof. */
char c; /* Temporary storage for byte overwritten by NUL, if pos < eof. */
};
typedef struct data data;
/* Stupid BSD interface uses int/int instead of ssize_t/size_t. */
//verify (sizeof (int) <= sizeof (size_t));
//verify (sizeof (int) <= sizeof (ssize_t));
// verify (sizeof (int) <= sizeof (size_t));
// verify (sizeof (int) <= sizeof (ssize_t));
static int
mem_write (void *c, const char *buf, int n)
{
static int mem_write(void *c, const char *buf, int n) {
data *cookie = c;
char *cbuf = *cookie->buf;
/* Be sure we don't overflow. */
if ((ssize_t) (cookie->pos + n) < 0)
{
errno = EFBIG;
return EOF;
}
if ((ssize_t)(cookie->pos + n) < 0) {
errno = EFBIG;
return EOF;
}
/* Grow the buffer, if necessary. Use geometric growth to avoid
quadratic realloc behavior. Overallocate, to accomodate the
requirement to always place a trailing NUL not counted by length.
Thus, we want max(prev_size*1.5, cookie->posn1). */
if (cookie->allocated <= cookie->pos + n)
{
size_t newsize = cookie->allocated * 3 / 2;
if (newsize < cookie->pos + n + 1)
newsize = cookie->pos + n + 1;
cbuf = realloc (cbuf, newsize);
if (!cbuf)
return EOF;
*cookie->buf = cbuf;
cookie->allocated = newsize;
}
if (cookie->allocated <= cookie->pos + n) {
size_t newsize = cookie->allocated * 3 / 2;
if (newsize < cookie->pos + n + 1)
newsize = cookie->pos + n + 1;
cbuf = realloc(cbuf, newsize);
if (!cbuf)
return EOF;
*cookie->buf = cbuf;
cookie->allocated = newsize;
}
/* If we have previously done a seek beyond eof, ensure all
intermediate bytges are NUL. */
if (cookie->eof < cookie->pos)
memset (cbuf + cookie->eof, '\0', cookie->pos - cookie->eof);
memmove (cbuf + cookie->pos, buf, n);
memset(cbuf + cookie->eof, '\0', cookie->pos - cookie->eof);
memmove(cbuf + cookie->pos, buf, n);
cookie->pos += n;
/* If the user has previously written beyond the current position,
remember what the trailing NUL is overwriting. Otherwise,
@ -99,9 +93,7 @@ mem_write (void *c, const char *buf, int n)
return n;
}
static fpos_t
mem_seek (void *c, fpos_t pos, int whence)
{
static fpos_t mem_seek(void *c, fpos_t pos, int whence) {
data *cookie = c;
off_t offset = pos;
@ -109,88 +101,71 @@ mem_seek (void *c, fpos_t pos, int whence)
offset = cookie->pos;
else if (whence == SEEK_END)
offset = cookie->eof;
if (offset < 0)
{
errno = EINVAL;
offset = -1;
}
else if ((size_t) offset != offset)
{
errno = ENOSPC;
offset = -1;
}
else
{
if (cookie->pos < cookie->eof)
{
(*cookie->buf)[cookie->pos] = cookie->c;
cookie->c = '\0';
}
cookie->pos = offset;
if (cookie->pos < cookie->eof)
{
cookie->c = (*cookie->buf)[cookie->pos];
(*cookie->buf)[cookie->pos] = '\0';
*cookie->len = cookie->pos;
}
else
*cookie->len = cookie->eof;
if (offset < 0) {
errno = EINVAL;
offset = -1;
} else if ((size_t)offset != offset) {
errno = ENOSPC;
offset = -1;
} else {
if (cookie->pos < cookie->eof) {
(*cookie->buf)[cookie->pos] = cookie->c;
cookie->c = '\0';
}
cookie->pos = offset;
if (cookie->pos < cookie->eof) {
cookie->c = (*cookie->buf)[cookie->pos];
(*cookie->buf)[cookie->pos] = '\0';
*cookie->len = cookie->pos;
} else
*cookie->len = cookie->eof;
}
return offset;
}
static int
mem_close (void *c)
{
static int mem_close(void *c) {
data *cookie = c;
char *buf;
/* Be nice and try to reduce excess memory. */
buf = realloc (*cookie->buf, *cookie->len + 1);
buf = realloc(*cookie->buf, *cookie->len + 1);
if (buf)
*cookie->buf = buf;
free (cookie);
free(cookie);
return 0;
}
FILE *
open_memstream (char **buf, size_t *len)
{
FILE *open_memstream(char **buf, size_t *len) {
FILE *f;
data *cookie;
if (!buf || !len)
{
errno = EINVAL;
return NULL;
}
if (!(cookie = malloc (sizeof *cookie)))
if (!buf || !len) {
errno = EINVAL;
return NULL;
if (!(*buf = malloc (INITIAL_ALLOC)))
{
free (cookie);
errno = ENOMEM;
return NULL;
}
}
if (!(cookie = malloc(sizeof *cookie)))
return NULL;
if (!(*buf = malloc(INITIAL_ALLOC))) {
free(cookie);
errno = ENOMEM;
return NULL;
}
**buf = '\0';
*len = 0;
f = funopen (cookie, NULL, mem_write, mem_seek, mem_close);
if (!f)
{
int saved_errno = errno;
free (cookie);
errno = saved_errno;
}
else
{
cookie->buf = buf;
cookie->len = len;
cookie->pos = 0;
cookie->eof = 0;
cookie->c = '\0';
cookie->allocated = INITIAL_ALLOC;
}
f = funopen(cookie, NULL, mem_write, mem_seek, mem_close);
if (!f) {
int saved_errno = errno;
free(cookie);
errno = saved_errno;
} else {
cookie->buf = buf;
cookie->len = len;
cookie->pos = 0;
cookie->eof = 0;
cookie->c = '\0';
cookie->allocated = INITIAL_ALLOC;
}
return f;
}
#endif /* HAVE_FUNOPEN */

View File

@ -13,7 +13,7 @@
*
*/
#include "config.h"
#include "YapConfig.h"
#if _WIN32 || defined(__MINGW32__)
#if !defined(MINGW_HAS_SECURE_API)
@ -22,10 +22,10 @@
//#undef _POSIX_
#endif
#include "Yap.h"
#include "YapEval.h"
#include "YapHeap.h"
#include "YapText.h"
#include "Yatom.h"
#include "YapEval.h"
#include "yapio.h"
// Win32 InputOutput Support
@ -46,7 +46,6 @@
#endif
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@ -121,7 +120,6 @@
/* windows.h does not like absmi.h, this
should fix it for now */
#include <math.h>
#include <math.h>
#if HAVE_TIME_H
#include <time.h>
#endif

View File

@ -41,7 +41,6 @@ CUDD will generate better/faster code.
#include <stdio.h>
#include "YapInterface.h"
#include "config.h"
#include "cudd_config.h"
#if HAVE_STRING_H
@ -811,7 +810,7 @@ static YAP_Bool p_cudd_print_with_names(void) {
DdManager *manager = (DdManager *)YAP_IntOfTerm(YAP_ARG1);
DdNode *n0 = (DdNode *)YAP_IntOfTerm(YAP_ARG2);
const char *s = YAP_AtomName(YAP_AtomOfTerm(YAP_ARG3));
char ** namesp;
char **namesp;
YAP_Term names = YAP_ARG4;
FILE *f;
YAP_Int len;
@ -850,7 +849,7 @@ static YAP_Bool p_cudd_print_with_names(void) {
names = YAP_TailOfTerm(names);
namesp[i++] = f;
}
Cudd_DumpDot(manager, 1, &n0, (const char * const*)namesp, NULL, f);
Cudd_DumpDot(manager, 1, &n0, (const char *const *)namesp, NULL, f);
if (f != stdout && f != stderr)
fclose(f);
while (i > 0) {
@ -863,8 +862,8 @@ static YAP_Bool p_cudd_print_with_names(void) {
static YAP_Bool p_cudd_die(void) {
DdManager *manager = (DdManager *)YAP_IntOfTerm(YAP_ARG1);
//Cudd_FreeTree(manager);
//cuddFreeTable(manager);
// Cudd_FreeTree(manager);
// cuddFreeTable(manager);
Cudd_CheckZeroRef(manager);
Cudd_Quit(manager);
return TRUE;

View File

@ -186,14 +186,13 @@
* *
\******************************************************************************/
#include "YapInterface.h"
#include "cudd_config.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "config.h"
#include "cudd_config.h"
#if HAVE_CUDD_UTIL_H
#include <cudd/util.h>
@ -214,26 +213,26 @@
#include "general.h"
#define IsHigh(manager, node) HIGH(manager) == node
#define IsLow(manager, node) LOW(manager) == node
#define HIGH(manager) Cudd_ReadOne(manager)
#define LOW(manager) Cudd_Not(Cudd_ReadOne(manager))
#define NOT(node) Cudd_Not(node)
#define GetIndex(node) Cudd_NodeReadIndex(node)
#define IsHigh(manager, node) HIGH(manager) == node
#define IsLow(manager, node) LOW(manager) == node
#define HIGH(manager) Cudd_ReadOne(manager)
#define LOW(manager) Cudd_Not(Cudd_ReadOne(manager))
#define NOT(node) Cudd_Not(node)
#define GetIndex(node) Cudd_NodeReadIndex(node)
#define GetOrder(manager, node) Cudd_ReadPerm(manager, GetIndex(node))
#define GetVar(manager, index) Cudd_bddIthVar(manager, index)
#define NewVar(manager) Cudd_bddNewVar(manager)
#define KillBDD(manager) Cudd_Quit(manager)
#define GetVarCount(manager) Cudd_ReadSize(manager)
#define DEBUGON _debug = 1
#define DEBUGOFF _debug = 0
#define RAPIDLOADON _RapidLoad = 1
#define RAPIDLOADOFF _RapidLoad = 0
#define SETMAXBUFSIZE(size) _maxbufsize = size
#define BDDFILE_ERROR -1
#define BDDFILE_OTHER 0
#define BDDFILE_SCRIPT 1
#define BDDFILE_NODEDUMP 2
#define GetVar(manager, index) Cudd_bddIthVar(manager, index)
#define NewVar(manager) Cudd_bddNewVar(manager)
#define KillBDD(manager) Cudd_Quit(manager)
#define GetVarCount(manager) Cudd_ReadSize(manager)
#define DEBUGON _debug = 1
#define DEBUGOFF _debug = 0
#define RAPIDLOADON _RapidLoad = 1
#define RAPIDLOADOFF _RapidLoad = 0
#define SETMAXBUFSIZE(size) _maxbufsize = size
#define BDDFILE_ERROR -1
#define BDDFILE_OTHER 0
#define BDDFILE_SCRIPT 1
#define BDDFILE_NODEDUMP 2
extern int _RapidLoad;
extern int _debug;
@ -281,28 +280,33 @@ typedef struct _nodeline {
/* Initialization */
DdManager* simpleBDDinit(int varcnt);
DdManager* simpleBDDinitNoReOrder(int varcnt);
DdManager *simpleBDDinit(int varcnt);
DdManager *simpleBDDinitNoReOrder(int varcnt);
/* BDD Generation */
DdNode* D_BDDAnd(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode* D_BDDNand(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode* D_BDDOr(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode* D_BDDNor(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode* D_BDDXor(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode* D_BDDXnor(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode *D_BDDAnd(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode *D_BDDNand(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode *D_BDDOr(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode *D_BDDNor(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode *D_BDDXor(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode *D_BDDXnor(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode* FileGenerateBDD(DdManager *manager, namedvars varmap, bddfileheader fileheader);
DdNode** FileGenerateBDDForest(DdManager *manager, namedvars varmap, bddfileheader fileheader);
DdNode* OnlineGenerateBDD(DdManager *manager, namedvars *varmap);
DdNode* LineParser(DdManager *manager, namedvars varmap, DdNode **inter, int maxinter, char *function, int iline);
DdNode* OnlineLineParser(DdManager *manager, namedvars *varmap, DdNode **inter, int maxinter, char *function, int iline);
DdNode* BDD_Operator(DdManager *manager, DdNode *bdd1, DdNode *bdd2, char Operator, int inegoper);
DdNode *FileGenerateBDD(DdManager *manager, namedvars varmap,
bddfileheader fileheader);
DdNode **FileGenerateBDDForest(DdManager *manager, namedvars varmap,
bddfileheader fileheader);
DdNode *OnlineGenerateBDD(DdManager *manager, namedvars *varmap);
DdNode *LineParser(DdManager *manager, namedvars varmap, DdNode **inter,
int maxinter, char *function, int iline);
DdNode *OnlineLineParser(DdManager *manager, namedvars *varmap, DdNode **inter,
int maxinter, char *function, int iline);
DdNode *BDD_Operator(DdManager *manager, DdNode *bdd1, DdNode *bdd2,
char Operator, int inegoper);
int getInterBDD(char *function);
char* getFileName(const char *function);
char *getFileName(const char *function);
int GetParam(char *inputline, int iParam);
char** GetVariableOrder(char *filename, int varcnt);
char **GetVariableOrder(char *filename, int varcnt);
int LoadVariableData(namedvars varmap, char *filename);
/* Named variables */
@ -313,42 +317,51 @@ namedvars InitNamedVars(int varcnt, int varstart);
void EnlargeNamedVars(namedvars *varmap, int newvarcnt);
int AddNamedVarAt(namedvars varmap, const char *varname, int index);
int AddNamedVar(namedvars varmap, const char *varname);
void SetNamedVarValuesAt(namedvars varmap, int index, double dvalue, int ivalue, void *dynvalue);
int SetNamedVarValues(namedvars varmap, const char *varname, double dvalue, int ivalue, void *dynvalue);
void SetNamedVarValuesAt(namedvars varmap, int index, double dvalue, int ivalue,
void *dynvalue);
int SetNamedVarValues(namedvars varmap, const char *varname, double dvalue,
int ivalue, void *dynvalue);
int GetNamedVarIndex(const namedvars varmap, const char *varname);
int RepairVarcnt(namedvars *varmap);
char* GetNodeVarName(DdManager *manager, namedvars varmap, DdNode *node);
char* GetNodeVarNameDisp(DdManager *manager, namedvars varmap, DdNode *node);
char *GetNodeVarName(DdManager *manager, namedvars varmap, DdNode *node);
char *GetNodeVarNameDisp(DdManager *manager, namedvars varmap, DdNode *node);
int all_loaded(namedvars varmap, int disp);
/* Traversal */
DdNode* HighNodeOf(DdManager *manager, DdNode *node);
DdNode* LowNodeOf(DdManager *manager, DdNode *node);
DdNode *HighNodeOf(DdManager *manager, DdNode *node);
DdNode *LowNodeOf(DdManager *manager, DdNode *node);
/* Traversal - History */
hisqueue* InitHistory(int varcnt);
hisqueue *InitHistory(int varcnt);
void ReInitHistory(hisqueue *HisQueue, int varcnt);
void AddNode(hisqueue *HisQueue, int varstart, DdNode *node, double dvalue, int ivalue, void *dynvalue);
hisnode* GetNode(hisqueue *HisQueue, int varstart, DdNode *node);
void AddNode(hisqueue *HisQueue, int varstart, DdNode *node, double dvalue,
int ivalue, void *dynvalue);
hisnode *GetNode(hisqueue *HisQueue, int varstart, DdNode *node);
int GetNodeIndex(hisqueue *HisQueue, int varstart, DdNode *node);
void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue, DdNode *bdd);
void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue,
DdNode *bdd);
/* Save-load */
bddfileheader ReadFileHeader(char *filename);
int CheckFileVersion(const char *version);
DdNode * LoadNodeDump(DdManager *manager, namedvars varmap, FILE *inputfile);
DdNode * LoadNodeRec(DdManager *manager, namedvars varmap, hisqueue *Nodes, FILE *inputfile, nodeline current);
DdNode * GetIfExists(DdManager *manager, namedvars varmap, hisqueue *Nodes, char *varname, int nodenum);
DdNode *LoadNodeDump(DdManager *manager, namedvars varmap, FILE *inputfile);
DdNode *LoadNodeRec(DdManager *manager, namedvars varmap, hisqueue *Nodes,
FILE *inputfile, nodeline current);
DdNode *GetIfExists(DdManager *manager, namedvars varmap, hisqueue *Nodes,
char *varname, int nodenum);
int SaveNodeDump(DdManager *manager, namedvars varmap, DdNode *bdd, char *filename);
void SaveExpand(DdManager *manager, namedvars varmap, hisqueue *Nodes, DdNode *Current, FILE *outputfile);
int SaveNodeDump(DdManager *manager, namedvars varmap, DdNode *bdd,
char *filename);
void SaveExpand(DdManager *manager, namedvars varmap, hisqueue *Nodes,
DdNode *Current, FILE *outputfile);
void ExpandNodes(hisqueue *Nodes, int index, int nodenum);
/* Export */
int simpleBDDtoDot(DdManager *manager, DdNode *bdd, char *filename);
int simpleNamedBDDtoDot(DdManager *manager, namedvars varmap, DdNode *bdd, char *filename);
int simpleNamedBDDtoDot(DdManager *manager, namedvars varmap, DdNode *bdd,
char *filename);

View File

@ -184,16 +184,15 @@
* *
\******************************************************************************/
#include <unistd.h>
#include "YapInterface.h"
#include "cudd_config.h"
#include "pqueue.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "pqueue.h"
#include "config.h"
#include "cudd_config.h"
#include <unistd.h>
#if HAVE_CUDD_UTIL_H
#include <cudd/util.h>
#elif HAVE_UTIL_H
@ -216,26 +215,26 @@
#include "general.h"
#define IsHigh(manager, node) HIGH(manager) == node
#define IsLow(manager, node) LOW(manager) == node
#define HIGH(manager) Cudd_ReadOne(manager)
#define LOW(manager) Cudd_Not(Cudd_ReadOne(manager))
#define NOT(node) Cudd_Not(node)
#define GetIndex(node) Cudd_NodeReadIndex(node)
#define IsHigh(manager, node) HIGH(manager) == node
#define IsLow(manager, node) LOW(manager) == node
#define HIGH(manager) Cudd_ReadOne(manager)
#define LOW(manager) Cudd_Not(Cudd_ReadOne(manager))
#define NOT(node) Cudd_Not(node)
#define GetIndex(node) Cudd_NodeReadIndex(node)
#define GetOrder(manager, node) Cudd_ReadPerm(manager, GetIndex(node))
#define GetVar(manager, index) Cudd_bddIthVar(manager, index)
#define NewVar(manager) Cudd_bddNewVar(manager)
#define KillBDD(manager) Cudd_Quit(manager)
#define GetVarCount(manager) Cudd_ReadSize(manager)
#define DEBUGON _debug = 1
#define DEBUGOFF _debug = 0
#define RAPIDLOADON _RapidLoad = 1
#define RAPIDLOADOFF _RapidLoad = 0
#define SETMAXBUFSIZE(size) _maxbufsize = size
#define BDDFILE_ERROR -1
#define BDDFILE_OTHER 0
#define BDDFILE_SCRIPT 1
#define BDDFILE_NODEDUMP 2
#define GetVar(manager, index) Cudd_bddIthVar(manager, index)
#define NewVar(manager) Cudd_bddNewVar(manager)
#define KillBDD(manager) Cudd_Quit(manager)
#define GetVarCount(manager) Cudd_ReadSize(manager)
#define DEBUGON _debug = 1
#define DEBUGOFF _debug = 0
#define RAPIDLOADON _RapidLoad = 1
#define RAPIDLOADOFF _RapidLoad = 0
#define SETMAXBUFSIZE(size) _maxbufsize = size
#define BDDFILE_ERROR -1
#define BDDFILE_OTHER 0
#define BDDFILE_SCRIPT 1
#define BDDFILE_NODEDUMP 2
extern int _RapidLoad;
extern int _debug;
@ -253,7 +252,7 @@ typedef struct _bddfileheader {
typedef struct _namedvars {
int varcnt;
int varstart;
char ** vars;
char **vars;
int *loaded;
double *dvalue;
int *ivalue;
@ -265,7 +264,7 @@ typedef struct _namedvars {
typedef struct _hisnode {
DdNode *key;
double dvalue;
double dvalue2;// =0; //needed for expected counts
double dvalue2; // =0; //needed for expected counts
int ivalue;
void *dynvalue;
} hisnode;
@ -286,27 +285,32 @@ typedef struct _nodeline {
/* Initialization */
DdManager* simpleBDDinit(int varcnt);
DdManager *simpleBDDinit(int varcnt);
/* BDD Generation */
DdNode* D_BDDAnd(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode* D_BDDNand(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode* D_BDDOr(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode* D_BDDNor(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode* D_BDDXor(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode* D_BDDXnor(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode *D_BDDAnd(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode *D_BDDNand(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode *D_BDDOr(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode *D_BDDNor(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode *D_BDDXor(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode *D_BDDXnor(DdManager *manager, DdNode *bdd1, DdNode *bdd2);
DdNode* FileGenerateBDD(DdManager *manager, namedvars varmap, bddfileheader fileheader);
DdNode** FileGenerateBDDForest(DdManager *manager, namedvars varmap, bddfileheader fileheader);
DdNode* OnlineGenerateBDD(DdManager *manager, namedvars *varmap);
DdNode* LineParser(DdManager *manager, namedvars varmap, DdNode **inter, int maxinter, char *function, int iline);
DdNode* OnlineLineParser(DdManager *manager, namedvars *varmap, DdNode **inter, int maxinter, char *function, int iline);
DdNode* BDD_Operator(DdManager *manager, DdNode *bdd1, DdNode *bdd2, char Operator, int inegoper);
DdNode *FileGenerateBDD(DdManager *manager, namedvars varmap,
bddfileheader fileheader);
DdNode **FileGenerateBDDForest(DdManager *manager, namedvars varmap,
bddfileheader fileheader);
DdNode *OnlineGenerateBDD(DdManager *manager, namedvars *varmap);
DdNode *LineParser(DdManager *manager, namedvars varmap, DdNode **inter,
int maxinter, char *function, int iline);
DdNode *OnlineLineParser(DdManager *manager, namedvars *varmap, DdNode **inter,
int maxinter, char *function, int iline);
DdNode *BDD_Operator(DdManager *manager, DdNode *bdd1, DdNode *bdd2,
char Operator, int inegoper);
int getInterBDD(char *function);
char* getFileName(const char *function);
char *getFileName(const char *function);
int GetParam(char *inputline, int iParam);
char** GetVariableOrder(char *filename, int varcnt);
char **GetVariableOrder(char *filename, int varcnt);
int LoadVariableData(namedvars varmap, char *filename);
/* Named variables */
@ -317,43 +321,53 @@ namedvars InitNamedVars(int varcnt, int varstart);
void EnlargeNamedVars(namedvars *varmap, int newvarcnt);
int AddNamedVarAt(namedvars varmap, const char *varname, int index);
int AddNamedVar(namedvars varmap, const char *varname);
void SetNamedVarValuesAt(namedvars varmap, int index, double dvalue, int ivalue, void *dynvalue);
int SetNamedVarValues(namedvars varmap, const char *varname, double dvalue, int ivalue, void *dynvalue);
void SetNamedVarValuesAt(namedvars varmap, int index, double dvalue, int ivalue,
void *dynvalue);
int SetNamedVarValues(namedvars varmap, const char *varname, double dvalue,
int ivalue, void *dynvalue);
int GetNamedVarIndex(const namedvars varmap, const char *varname);
int RepairVarcnt(namedvars *varmap);
const char* GetNodeVarName(DdManager *manager, namedvars varmap, DdNode *node);
const char* GetNodeVarNameDisp(DdManager *manager, namedvars varmap, DdNode *node);
const char *GetNodeVarName(DdManager *manager, namedvars varmap, DdNode *node);
const char *GetNodeVarNameDisp(DdManager *manager, namedvars varmap,
DdNode *node);
int all_loaded(namedvars varmap, int disp);
int all_loaded_for_deterministic_variables(namedvars varmap, int disp);
/* Traversal */
DdNode* HighNodeOf(DdManager *manager, DdNode *node);
DdNode* LowNodeOf(DdManager *manager, DdNode *node);
DdNode *HighNodeOf(DdManager *manager, DdNode *node);
DdNode *LowNodeOf(DdManager *manager, DdNode *node);
/* Traversal - History */
hisqueue* InitHistory(int varcnt);
hisqueue *InitHistory(int varcnt);
void ReInitHistory(hisqueue *HisQueue, int varcnt);
void AddNode(hisqueue *HisQueue, int varstart, DdNode *node, double dvalue, int ivalue, void *dynvalue);
hisnode* GetNode(hisqueue *HisQueue, int varstart, DdNode *node);
void AddNode(hisqueue *HisQueue, int varstart, DdNode *node, double dvalue,
int ivalue, void *dynvalue);
hisnode *GetNode(hisqueue *HisQueue, int varstart, DdNode *node);
int GetNodeIndex(hisqueue *HisQueue, int varstart, DdNode *node);
void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue, DdNode *bdd);
void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue,
DdNode *bdd);
/* Save-load */
bddfileheader ReadFileHeader(char *filename);
int CheckFileVersion(const char *version);
DdNode * LoadNodeDump(DdManager *manager, namedvars varmap, FILE *inputfile);
DdNode * LoadNodeRec(DdManager *manager, namedvars varmap, hisqueue *Nodes, FILE *inputfile, nodeline current);
DdNode * GetIfExists(DdManager *manager, namedvars varmap, hisqueue *Nodes, char *varname, int nodenum);
DdNode *LoadNodeDump(DdManager *manager, namedvars varmap, FILE *inputfile);
DdNode *LoadNodeRec(DdManager *manager, namedvars varmap, hisqueue *Nodes,
FILE *inputfile, nodeline current);
DdNode *GetIfExists(DdManager *manager, namedvars varmap, hisqueue *Nodes,
char *varname, int nodenum);
int SaveNodeDump(DdManager *manager, namedvars varmap, DdNode *bdd, char *filename);
void SaveExpand(DdManager *manager, namedvars varmap, hisqueue *Nodes, DdNode *Current, FILE *outputfile);
int SaveNodeDump(DdManager *manager, namedvars varmap, DdNode *bdd,
char *filename);
void SaveExpand(DdManager *manager, namedvars varmap, hisqueue *Nodes,
DdNode *Current, FILE *outputfile);
void ExpandNodes(hisqueue *Nodes, int index, int nodenum);
/* Export */
int simpleBDDtoDot(DdManager *manager, DdNode *bdd, const char *filename);
int simpleNamedBDDtoDot(DdManager *manager, namedvars varmap, DdNode *bdd, const char *filename);
int simpleNamedBDDtoDot(DdManager *manager, namedvars varmap, DdNode *bdd,
const char *filename);

View File

@ -190,7 +190,7 @@ form
variable=value
*/
#include "config.h"
#include "YapInterface.h"
#include "cudd_config.h"
#include <math.h>
#include <stdio.h>

View File

@ -7,7 +7,6 @@ This package uses the library cudd, see http://vlsi.colorado.edu/~fabio/CUDD/
for the relative license.
*/
#include "config.h"
#include "cudd_config.h"
#include <stdio.h>
#if HAVE_CUDDINT_H
@ -18,7 +17,9 @@ for the relative license.
#include "YapInterface.h"
typedef struct { int var, value; } factor;
typedef struct {
int var, value;
} factor;
typedef struct {
int nFact;

View File

@ -9,7 +9,6 @@ for the relative license.
*/
#include "config.h"
#include "cudd_config.h"
#include <math.h>
#include <stdio.h>
@ -366,7 +365,7 @@ static YAP_Bool add_var(void) {
probTerm = arg2;
p0 = 1;
for (i = 0; i < v->nVal - 1; i++) {
//node = Cudd_bddIthVar(mgr_ex[ex], boolVars_ex[ex] + i);
// node = Cudd_bddIthVar(mgr_ex[ex], boolVars_ex[ex] + i);
p = YAP_FloatOfTerm(YAP_HeadOfTerm(probTerm));
bVar2mVar_ex[ex][boolVars_ex[ex] + i] = nVars_ex[ex] - 1;
probs_ex[ex][boolVars_ex[ex] + i] = p / p0;

View File

@ -1,23 +1,22 @@
#ifndef __MYDDAS_H__
#define __MYDDAS_H__
#include "config.h"
#include "YapConfig.h"
#include <stdio.h>
#include "myddas_types.h"
/* Passar para o myddas_statictics.h ???????? */
#ifdef MYDDAS_STATS
#include <time.h>
#include <sys/time.h>
#include <time.h>
#endif
typedef struct myddas_global *MYDDAS_GLOBAL;
#include "myddas_util.h"
//extern void Yap_InitMYDDAS_SQLITE3Preds(void);
//extern void Yap_InitBackMYDDAS_SQLITE3Preds(void);
// extern void Yap_InitMYDDAS_SQLITE3Preds(void);
// extern void Yap_InitBackMYDDAS_SQLITE3Preds(void);
#ifdef MYDDAS_STATS
typedef struct myddas_stats_time_struct *MYDDAS_STATS_TIME;
@ -28,18 +27,17 @@ typedef void *MYDDAS_STATS_TIME;
#endif
#ifdef DEBUG
#define MYDDAS_MEMORY_MALLOC_NR(NUMBER) \
#define MYDDAS_MEMORY_MALLOC_NR(NUMBER) \
NUMBER = Yap_REGS.MYDDAS_GLOBAL_POINTER->malloc_called;
#define MYDDAS_MEMORY_MALLOC_SIZE(NUMBER) \
#define MYDDAS_MEMORY_MALLOC_SIZE(NUMBER) \
NUMBER = Yap_REGS.MYDDAS_GLOBAL_POINTER->memory_allocated;
#define MYDDAS_MEMORY_FREE_NR(NUMBER) \
#define MYDDAS_MEMORY_FREE_NR(NUMBER) \
NUMBER = Yap_REGS.MYDDAS_GLOBAL_POINTER->free_called;
#define MYDDAS_MEMORY_FREE_SIZE(NUMBER) \
#define MYDDAS_MEMORY_FREE_SIZE(NUMBER) \
NUMBER = Yap_REGS.MYDDAS_GLOBAL_POINTER->memory_freed;
#endif
#include "myddas_structs.h"
#include "MyddasProto.h"
#include "myddas_structs.h"
#endif /*__MYDDAS_H__*/

File diff suppressed because it is too large Load Diff

View File

@ -68,9 +68,9 @@ static lbfgsfloatval_t evaluate(void *instance, const lbfgsfloatval_t *x,
}
YAP_Term o;
if (YAP_IsIntTerm((o = YAP_GetFromSlot(sl))))
rc = YAP_IntOfTerm(o);
rc = YAP_IntOfTerm(o);
else
rc = YAP_FloatOfTerm(o);
rc = YAP_FloatOfTerm(o);
YAP_RecoverSlots(1, sl);
return rc;
}
@ -350,7 +350,7 @@ static YAP_Bool lbfgs_release(void) {
/* return FALSE; */
}
static lbfgs_parameter_t * get_params(YAP_Term t) {
static lbfgs_parameter_t *get_params(YAP_Term t) {
YAP_Int ar = YAP_ArityOfFunctor(YAP_FunctorOfTerm(t));
YAP_Term arg = YAP_ArgOfTerm(ar, t);
return (lbfgs_parameter_t *)YAP_IntOfTerm(arg);
@ -516,7 +516,6 @@ static YAP_Bool lbfgs_set_parameter(void) {
return TRUE;
}
/** @pred lbfgs_get_parameter(+Name,-Value)</h3>
Get the current Value for Name
*/

View File

@ -33,10 +33,10 @@
/**
* @defgroup listingGroup List predicates in a module
*
*
* @ingroup builtins
*
* @{
* @{
*/
@ -144,7 +144,7 @@ listing(Stream, [MV|MVs]) :- !,
'$listing'(_,_,_,_).
'$funcspec'(Name/Arity,Name,Arity) :- !, atom(Name).
'$funcspec'(Name,Name,_) :- atom(Name), !.
'$funcspec'(Name,Name,0) :- atom(Name), !.
'$funcspec'(Name,_,_) :-
'$do_error'(domain_error(predicate_spec,Name),listing(Name)).
@ -216,7 +216,7 @@ listing(Stream, [MV|MVs]) :- !,
'$clause'(Pred, M, Body, _),
'$current_module'(Mod),
( M \= Mod -> H = M:Pred ; H = Pred ),
'$portray_clause'(Stream,(H:-Body)),
portray_clause(Stream,(H:-Body)),
fail.
/** @pred portray_clause(+ _S_,+ _C_)
@ -225,7 +225,7 @@ Write clause _C_ on stream _S_ as if written by listing/0.
*/
portray_clause(Stream, Clause) :-
copy_term_nat(Clause, CopiedClause),
'$beautify_vs'(CopiedClause),
'$beautify_vs'(CopiedClause),
'$portray_clause'(Stream, CopiedClause),
fail.
portray_clause(_, _).