diff --git a/include/YapInterface.h b/include/YapInterface.h index b29d632d5..19b56be16 100755 --- a/include/YapInterface.h +++ b/include/YapInterface.h @@ -1599,6 +1599,20 @@ __BEGIN_DECLS #define X_API #endif +#ifndef Int_FORMAT + +#if _WIN64 +#define Int_FORMAT "%I64d" +#define Int_ANYFORMAT "%I64i" +#define UInt_FORMAT "%I64u" +#else +#define Int_FORMAT "%ld" +#define Int_ANYFORMAT "%li" +#define UInt_FORMAT "%lu" +#endif + +#endif /* portable form of formatted output for Prolog terms */ + /* Primitive Functions */ #define YAP_Deref(t) (t) diff --git a/library/rltree/yap_rl.c b/library/rltree/yap_rl.c index 344d7ed95..2bfab6477 100644 --- a/library/rltree/yap_rl.c +++ b/library/rltree/yap_rl.c @@ -27,9 +27,9 @@ Last rev: $Id: yap_rl.c,v 1.1 2008-03-26 23:05:22 nunofonseca Exp $ #include "range_list.h" #include -#define IDTYPE long -#define PTR2ID(ptr) (IDTYPE)ptr -#define ID2PTR(id) (RL_Tree*)id +#define IDTYPE YAP_Int +#define PTR2ID(ptr) ((IDTYPE)(ptr)) +#define ID2PTR(id) ((RL_Tree*)(id)) /* ############################################################ */ diff --git a/library/tries/base_itries.c b/library/tries/base_itries.c index 7b7554c64..0d912020a 100644 --- a/library/tries/base_itries.c +++ b/library/tries/base_itries.c @@ -45,7 +45,7 @@ void itrie_data_save(TrNode node, FILE *file) { TrData data; data = (TrData) GET_DATA_FROM_LEAF_TRIE_NODE(node); - fprintf(file, "%ld %ld %ld ", TrData_pos(data), TrData_neg(data), TrData_timestamp(data)); + fprintf(file, Int_FORMAT " " Int_FORMAT " " Int_FORMAT " ", TrData_pos(data), TrData_neg(data), TrData_timestamp(data)); return; } @@ -55,7 +55,7 @@ void itrie_data_load(TrNode node, YAP_Int depth, FILE *file) { TrData data; YAP_Int pos, neg, timestamp; - fscanf(file, "%ld %ld %ld", &pos, &neg, ×tamp); + fscanf(file, Int_FORMAT " " Int_FORMAT " " Int_FORMAT, &pos, &neg, ×tamp); new_itrie_data(data, CURRENT_ITRIE, node, pos, neg, timestamp, depth); PUT_DATA_IN_LEAF_TRIE_NODE(node, data); return; @@ -67,7 +67,7 @@ void itrie_data_print(TrNode node) { TrData data; data = (TrData) GET_DATA_FROM_LEAF_TRIE_NODE(node); - printf(" pos: %ld neg: %ld timestamp: %ld\n", TrData_pos(data), TrData_neg(data), TrData_timestamp(data)); + printf(" pos: " Int_FORMAT " neg: " Int_FORMAT " timestamp: " Int_FORMAT "\\n", TrData_pos(data), TrData_neg(data), TrData_timestamp(data)); return; } diff --git a/library/tries/base_itries.h b/library/tries/base_itries.h index f8bab1723..11a08eef9 100644 --- a/library/tries/base_itries.h +++ b/library/tries/base_itries.h @@ -73,8 +73,8 @@ typedef struct itrie_data { #define SIZEOF_TR_DATA sizeof(TYPE_TR_DATA) #define SIZEOF_TR_DATA_BUCKET sizeof(TYPE_TR_DATA *) -#define AS_TR_ENTRY_NEXT(ADDR) (TrEntry)((unsigned long int)(ADDR) - sizeof(struct trie_node *) - sizeof(struct itrie_data **) - sizeof(struct itrie_data *)) -#define AS_TR_DATA_NEXT(ADDR) (TrData)((unsigned long int)(ADDR) - sizeof(struct itrie_entry *) - sizeof(struct trie_node *)) +#define AS_TR_ENTRY_NEXT(ADDR) (TrEntry)((YAP_UInt)(ADDR) - sizeof(struct trie_node *) - sizeof(struct itrie_data **) - sizeof(struct itrie_data *)) +#define AS_TR_DATA_NEXT(ADDR) (TrData)((YAP_UInt)(ADDR) - sizeof(struct itrie_entry *) - sizeof(struct trie_node *)) diff --git a/library/tries/base_tries.h b/library/tries/base_tries.h index e21e3274a..01c070daa 100644 --- a/library/tries/base_tries.h +++ b/library/tries/base_tries.h @@ -52,8 +52,8 @@ typedef struct trie_data { #define SIZEOF_TR_ENTRY sizeof(TYPE_TR_ENTRY) #define SIZEOF_TR_DATA sizeof(TYPE_TR_DATA) -#define AS_TR_ENTRY_NEXT(ADDR) (TrEntry)((unsigned long int)(ADDR) - sizeof(struct trie_node *) - 3 * sizeof(struct trie_data *)) -#define AS_TR_DATA_NEXT(ADDR) (TrData)((unsigned long int)(ADDR) - sizeof(struct trie_entry *) - sizeof(struct trie_node *)) +#define AS_TR_ENTRY_NEXT(ADDR) (TrEntry)((YAP_UInt)(ADDR) - sizeof(struct trie_node *) - 3 * sizeof(struct trie_data *)) +#define AS_TR_DATA_NEXT(ADDR) (TrData)((YAP_UInt)(ADDR) - sizeof(struct trie_entry *) - sizeof(struct trie_node *)) diff --git a/library/tries/core_dbtries.c b/library/tries/core_dbtries.c index fad498621..e780a577b 100644 --- a/library/tries/core_dbtries.c +++ b/library/tries/core_dbtries.c @@ -264,7 +264,7 @@ void displaynode(TrNode node) { {printf("1\n");} else {printf("2\n");} printf("bye\n");*/ if (IS_HASH_NODE(node)) - printf("HASH n%i, b%i, p%li\n", TrHash_num_nodes((TrHash) node), TrHash_num_buckets((TrHash) node), (long) node); + printf("HASH n%i, b%i, p%p\n", TrHash_num_nodes((TrHash) node), TrHash_num_buckets((TrHash) node), node); else if (TrNode_entry(node) == PairInitTag) printf("PairInitTag\n"); else if (TrNode_entry(node) == PairEndTag) @@ -272,7 +272,7 @@ void displaynode(TrNode node) { else if (IS_FUNCTOR_NODE(node)) printf("functor(%s)\n", YAP_AtomName(YAP_NameOfFunctor((YAP_Functor)( ~ApplTag & TrNode_entry(node))))); else if (YAP_IsIntTerm(TrNode_entry(node))) - printf("int(%ld)\n", YAP_IntOfTerm(TrNode_entry(node))); + printf("int(" Int_FORMAT ")\n", YAP_IntOfTerm(TrNode_entry(node))); else if (YAP_IsAtomTerm(TrNode_entry(node))) printf("atom(%s)\n", YAP_AtomName(YAP_AtomOfTerm(TrNode_entry(node)))); else @@ -816,7 +816,7 @@ int traverse_get_counter(TrNode node) { YAP_Term generate_label(YAP_Int Index) { char label[20]; - sprintf(label,"L%ld", Index); + sprintf(label,"L" Int_FORMAT, Index); return YAP_MkAtomTerm(YAP_LookupAtom(label)); } diff --git a/library/tries/core_tries.c b/library/tries/core_tries.c index 7540d8797..c3974a12b 100644 --- a/library/tries/core_tries.c +++ b/library/tries/core_tries.c @@ -1323,7 +1323,7 @@ void traverse_and_save(TrNode node, FILE *file, int float_block) { TrNode *first_bucket, *bucket; TrHash hash; hash = (TrHash) node; - fprintf(file, "%lu %d ", HASH_SAVE_MARK, TrHash_num_buckets(hash)); + fprintf(file, UInt_FORMAT " %d ", HASH_SAVE_MARK, TrHash_num_buckets(hash)); first_bucket = TrHash_buckets(hash); bucket = first_bucket + TrHash_num_buckets(hash); do { @@ -1341,7 +1341,7 @@ void traverse_and_save(TrNode node, FILE *file, int float_block) { t = TrNode_entry(node); if (float_block) { float_block--; - fprintf(file, "%lu %lu ", FLOAT_SAVE_MARK, t); + fprintf(file, UInt_FORMAT " " UInt_FORMAT " ", FLOAT_SAVE_MARK, t); } else if (YAP_IsPairTerm(t)) { if (t == FloatInitTag) { #ifdef TAG_LOW_BITS_32 @@ -1349,9 +1349,9 @@ void traverse_and_save(TrNode node, FILE *file, int float_block) { #endif /* TAG_LOW_BITS_32 */ float_block ++; } - fprintf(file, "%lu ", t); + fprintf(file, UInt_FORMAT " ", t); } else if (YAP_IsVarTerm(t) || YAP_IsIntTerm(t)) - fprintf(file, "%lu ", t); + fprintf(file, UInt_FORMAT" ", t); else { int index; for (index = 0; index <= CURRENT_INDEX; index++) @@ -1363,16 +1363,16 @@ void traverse_and_save(TrNode node, FILE *file, int float_block) { expand_auxiliary_term_stack(); AUXILIARY_TERM_STACK[CURRENT_INDEX] = t; if (YAP_IsAtomTerm(t)) - fprintf(file, "%lu %d %s%c ", ATOM_SAVE_MARK, index, YAP_AtomName(YAP_AtomOfTerm(t)), '\0'); + fprintf(file, UInt_FORMAT " %d %s%c ", ATOM_SAVE_MARK, index, YAP_AtomName(YAP_AtomOfTerm(t)), '\0'); else /* (ApplTag & t) */ - fprintf(file, "%lu %d %s %lu ", FUNCTOR_SAVE_MARK, index, + fprintf(file, UInt_FORMAT " %d %s " UInt_FORMAT " ", FUNCTOR_SAVE_MARK, index, YAP_AtomName(YAP_NameOfFunctor((YAP_Functor)(~ApplTag & t))), YAP_ArityOfFunctor((YAP_Functor)(~ApplTag & t))); } else if (YAP_IsAtomTerm(t)) - fprintf(file, "%lu %d ", ATOM_SAVE_MARK, index); + fprintf(file, UInt_FORMAT " %d ", ATOM_SAVE_MARK, index); else - fprintf(file, "%lu %d ", FUNCTOR_SAVE_MARK, index); + fprintf(file, UInt_FORMAT " %d ", FUNCTOR_SAVE_MARK, index); } if (IS_LEAF_TRIE_NODE(node)) { fprintf(file, "- "); @@ -1393,7 +1393,7 @@ void traverse_and_load(TrNode parent, FILE *file) { YAP_Term t; int n; - if (!fscanf(file, "%lu", &t)) { + if (!fscanf(file, UInt_FORMAT , &t)) { MARK_AS_LEAF_TRIE_NODE(parent); INCREMENT_ENTRIES(CURRENT_TRIE_ENGINE); if (DATA_LOAD_FUNCTION) @@ -1407,7 +1407,7 @@ void traverse_and_load(TrNode parent, FILE *file) { n = fscanf(file, "%d", &num_buckets); new_trie_hash(hash, 0, num_buckets); TrNode_child(parent) = (TrNode) hash; - n = fscanf(file, "%lu", &t); + n = fscanf(file, UInt_FORMAT , &t); } do { TrNode child; @@ -1446,10 +1446,10 @@ void traverse_and_load(TrNode parent, FILE *file) { } t = AUXILIARY_TERM_STACK[index]; } else if (t == FLOAT_SAVE_MARK) - n = fscanf(file, "%lu", &t); + n = fscanf(file, UInt_FORMAT , &t); child = trie_node_insert(parent, t, hash); traverse_and_load(child, file); - } while (fscanf(file, "%lu", &t)); + } while (fscanf(file, UInt_FORMAT , &t)); CURRENT_DEPTH--; if (n) n = 0; // just added to remove the warning of not used! return; @@ -1545,7 +1545,7 @@ void traverse_and_print(TrNode node, int *arity, char *str, int str_index, int m } mode = TRIE_PRINT_NORMAL; } else if (YAP_IsVarTerm(t)) { - str_index += sprintf(& str[str_index], "VAR%ld", TrieVarIndex(t)); + str_index += sprintf(& str[str_index], "VAR" UInt_FORMAT, TrieVarIndex(t)); while (arity[0]) { if (arity[arity[0]] == 1) { str_index += sprintf(& str[str_index], ")"); @@ -1571,7 +1571,7 @@ void traverse_and_print(TrNode node, int *arity, char *str, int str_index, int m } } } else if (YAP_IsIntTerm(t)) { - str_index += sprintf(& str[str_index], "%ld", YAP_IntOfTerm(t)); + str_index += sprintf(& str[str_index], UInt_FORMAT , YAP_IntOfTerm(t)); while (arity[0]) { if (arity[arity[0]] == 1) { str_index += sprintf(& str[str_index], ")"); diff --git a/library/tries/core_tries.h b/library/tries/core_tries.h index 23b25b992..5608c907c 100644 --- a/library/tries/core_tries.h +++ b/library/tries/core_tries.h @@ -119,7 +119,7 @@ typedef struct trie_hash { #define SIZEOF_TR_HASH sizeof(TYPE_TR_HASH) #define SIZEOF_TR_BUCKET sizeof(TYPE_TR_NODE *) -#define AS_TR_NODE_NEXT(ADDR) (TrNode)((unsigned long int)(ADDR) - 2 * sizeof(struct trie_node *)) +#define AS_TR_NODE_NEXT(ADDR) (TrNode)((YAP_UInt)(ADDR) - 2 * sizeof(struct trie_node *)) @@ -127,12 +127,12 @@ typedef struct trie_hash { /* Macros */ /* --------------------------- */ -#define TAG_ADDR(ADDR) ((unsigned long int)(ADDR) | 0x1) -#define UNTAG_ADDR(ADDR) ((unsigned long int)(ADDR) & ~(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) ((unsigned long int)(TrNode_child(TR_NODE)) & 0x1) +#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)