support for tabling of bignums and strings
This commit is contained in:
@@ -54,24 +54,35 @@ Int unify(Term t0, Term t1)
|
||||
EXTERN inline Int unify_constant(register Term a, register Term cons)
|
||||
{
|
||||
CELL *pt;
|
||||
CELL *pt0, *pt1;
|
||||
|
||||
deref_head(a,unify_cons_unk);
|
||||
unify_cons_nonvar:
|
||||
{
|
||||
if (a == cons) return(TRUE);
|
||||
else if (IsApplTerm(a) && IsExtensionFunctor(FunctorOfTerm(a))) {
|
||||
Functor fun = FunctorOfTerm(a);
|
||||
if (fun == FunctorDouble)
|
||||
return(IsFloatTerm(cons) && FloatOfTerm(a) == FloatOfTerm(cons));
|
||||
else if (fun == FunctorLongInt) {
|
||||
return(IsLongIntTerm(cons) && LongIntOfTerm(a) == LongIntOfTerm(cons));
|
||||
#ifdef TERM_EXTENSIONS
|
||||
} else if (IsAttachFunc(fun)) {
|
||||
return(GLOBAL_attas[ExtFromFunctor(fun)].bind_op(SBIND,a,cons));
|
||||
#endif /* TERM_EXTENSIONS */
|
||||
} else
|
||||
if (!IsApplTerm(cons) || FunctorOfTerm(cons) != fun)
|
||||
return FALSE;
|
||||
switch((CELL)fun) {
|
||||
case (CELL)FunctorDBRef:
|
||||
return(pt0 == pt1);
|
||||
case (CELL)FunctorLongInt:
|
||||
return(pt0[1] == pt1[1]);
|
||||
case (CELL)FunctorString:
|
||||
return(strcmp( (const char *)(pt0+2), (const char *)(pt1+2)) == 0);
|
||||
case (CELL)FunctorDouble:
|
||||
return(FloatOfTerm(AbsAppl(pt0)) == FloatOfTerm(AbsAppl(pt1)));
|
||||
#ifdef USE_GMP
|
||||
case (CELL)FunctorBigInt:
|
||||
return(Yap_gmp_tcmp_big_big(AbsAppl(pt0),AbsAppl(pt0)) == 0);
|
||||
#endif /* USE_GMP */
|
||||
default:
|
||||
return(FALSE);
|
||||
/* no other factors are accepted as arguments */
|
||||
} else return(FALSE);
|
||||
}
|
||||
}
|
||||
/* no other factors are accepted as arguments */
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -111,12 +111,16 @@ static inline tg_sol_fr_ptr CUT_prune_tg_solution_frames(tg_sol_fr_ptr, int);
|
||||
/* traverse macros */
|
||||
#define SHOW_MODE_STRUCTURE 0
|
||||
#define SHOW_MODE_STATISTICS 1
|
||||
#define TRAVERSE_MODE_NORMAL 0
|
||||
#define TRAVERSE_MODE_DOUBLE 1
|
||||
#define TRAVERSE_MODE_DOUBLE2 2
|
||||
#define TRAVERSE_MODE_DOUBLE_END 3
|
||||
#define TRAVERSE_MODE_LONGINT 4
|
||||
#define TRAVERSE_MODE_LONGINT_END 5
|
||||
typedef enum {
|
||||
TRAVERSE_MODE_NORMAL = 0,
|
||||
TRAVERSE_MODE_DOUBLE = 1,
|
||||
TRAVERSE_MODE_DOUBLE2 = 2,
|
||||
TRAVERSE_MODE_DOUBLE_END = 3,
|
||||
TRAVERSE_MODE_BIGINT_OR_STRING = 4,
|
||||
TRAVERSE_MODE_BIGINT_OR_STRING_END = 5,
|
||||
TRAVERSE_MODE_LONGINT = 6,
|
||||
TRAVERSE_MODE_LONGINT_END = 7
|
||||
} traverse_mode_t;
|
||||
/* do not change order !!! */
|
||||
#define TRAVERSE_TYPE_SUBGOAL 0
|
||||
#define TRAVERSE_TYPE_ANSWER 1
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#ifdef TABLING
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "eval.h"
|
||||
#include "tab.macros.h"
|
||||
|
||||
static inline sg_node_ptr subgoal_trie_check_insert_entry(tab_ent_ptr, sg_node_ptr, Term USES_REGS);
|
||||
@@ -376,6 +377,11 @@ static inline CELL *exec_substitution_loop(gt_node_ptr current_node, CELL **stac
|
||||
current_node = TrNode_parent(current_node);
|
||||
current_node = TrNode_parent(current_node);
|
||||
t = MkLongIntTerm(li);
|
||||
} else if (f == FunctorBigInt || f == FunctorString) {
|
||||
CELL *li = (CELL *)TrNode_entry(current_node);
|
||||
current_node = TrNode_parent(current_node);
|
||||
current_node = TrNode_parent(current_node);
|
||||
t = AbsAppl(li);
|
||||
} else {
|
||||
int f_arity = ArityOfFunctor(f);
|
||||
t = Yap_MkApplTerm(f, f_arity, stack_terms);
|
||||
@@ -517,12 +523,16 @@ static void free_global_trie_branch(gt_node_ptr current_node USES_REGS) {
|
||||
mode = TRAVERSE_MODE_DOUBLE;
|
||||
else if (f == FunctorLongInt)
|
||||
mode = TRAVERSE_MODE_LONGINT;
|
||||
else if (f == FunctorBigInt || f == FunctorString)
|
||||
mode = TRAVERSE_MODE_BIGINT_OR_STRING;
|
||||
else
|
||||
mode = TRAVERSE_MODE_NORMAL;
|
||||
} else
|
||||
mode = TRAVERSE_MODE_NORMAL;
|
||||
} else if (mode == TRAVERSE_MODE_LONGINT)
|
||||
mode = TRAVERSE_MODE_LONGINT_END;
|
||||
} else if (mode == TRAVERSE_MODE_BIGINT_OR_STRING)
|
||||
mode = TRAVERSE_MODE_BIGINT_OR_STRING_END;
|
||||
else if (mode == TRAVERSE_MODE_DOUBLE)
|
||||
#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P
|
||||
mode = TRAVERSE_MODE_DOUBLE2;
|
||||
@@ -555,12 +565,16 @@ static void free_global_trie_branch(gt_node_ptr current_node USES_REGS) {
|
||||
mode = TRAVERSE_MODE_DOUBLE;
|
||||
else if (f == FunctorLongInt)
|
||||
mode = TRAVERSE_MODE_LONGINT;
|
||||
else if (f == FunctorBigInt || f == FunctorString)
|
||||
mode = TRAVERSE_MODE_BIGINT_OR_STRING;
|
||||
else
|
||||
mode = TRAVERSE_MODE_NORMAL;
|
||||
} else
|
||||
mode = TRAVERSE_MODE_NORMAL;
|
||||
} else if (mode == TRAVERSE_MODE_LONGINT)
|
||||
mode = TRAVERSE_MODE_LONGINT_END;
|
||||
} else if (mode == TRAVERSE_MODE_BIGINT_OR_STRING)
|
||||
mode = TRAVERSE_MODE_BIGINT_OR_STRING_END;
|
||||
else if (mode == TRAVERSE_MODE_DOUBLE)
|
||||
#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P
|
||||
mode = TRAVERSE_MODE_DOUBLE2;
|
||||
@@ -898,6 +912,15 @@ static inline void traverse_trie_node(Term t, char *str, int *str_index_ptr, int
|
||||
mode = TRAVERSE_MODE_LONGINT_END;
|
||||
} else if (mode == TRAVERSE_MODE_LONGINT_END) {
|
||||
mode = TRAVERSE_MODE_NORMAL;
|
||||
} else if (mode == TRAVERSE_MODE_BIGINT_OR_STRING) {
|
||||
str_index += Yap_OpaqueTermToString(AbsAppl((CELL *)t), str+str_index, 0);
|
||||
traverse_update_arity(str, &str_index, arity);
|
||||
if (type == TRAVERSE_TYPE_SUBGOAL)
|
||||
mode = TRAVERSE_MODE_NORMAL;
|
||||
else /* TRAVERSE_TYPE_ANSWER || TRAVERSE_TYPE_GT_SUBGOAL || TRAVERSE_TYPE_GT_ANSWER */
|
||||
mode = TRAVERSE_MODE_BIGINT_OR_STRING_END;
|
||||
} else if (mode == TRAVERSE_MODE_BIGINT_OR_STRING_END) {
|
||||
mode = TRAVERSE_MODE_NORMAL;
|
||||
} else if (IsVarTerm(t)) {
|
||||
if (t > VarIndexOfTableTerm(MAX_TABLE_VARS)) {
|
||||
TrStat_gt_refs++;
|
||||
@@ -950,6 +973,8 @@ static inline void traverse_trie_node(Term t, char *str, int *str_index_ptr, int
|
||||
mode = TRAVERSE_MODE_DOUBLE;
|
||||
} else if (f == FunctorLongInt) {
|
||||
mode = TRAVERSE_MODE_LONGINT;
|
||||
} else if (f == FunctorBigInt || f == FunctorString) {
|
||||
mode = TRAVERSE_MODE_BIGINT_OR_STRING;
|
||||
} else if (f == FunctorComma) {
|
||||
if (arity[arity[0]] != -3) {
|
||||
str_index += sprintf(& str[str_index], "(");
|
||||
@@ -1369,20 +1394,26 @@ void free_subgoal_trie(sg_node_ptr current_node, int mode, int position) {
|
||||
child_mode = TRAVERSE_MODE_DOUBLE;
|
||||
else if (f == FunctorLongInt)
|
||||
child_mode = TRAVERSE_MODE_LONGINT;
|
||||
else if (f == FunctorBigInt || f == FunctorString)
|
||||
child_mode = TRAVERSE_MODE_BIGINT_OR_STRING;
|
||||
else
|
||||
child_mode = TRAVERSE_MODE_NORMAL;
|
||||
} else
|
||||
child_mode = TRAVERSE_MODE_NORMAL;
|
||||
} else if (mode == TRAVERSE_MODE_LONGINT)
|
||||
} else if (mode == TRAVERSE_MODE_LONGINT) {
|
||||
child_mode = TRAVERSE_MODE_LONGINT_END;
|
||||
else if (mode == TRAVERSE_MODE_DOUBLE)
|
||||
} else if (mode == TRAVERSE_MODE_BIGINT_OR_STRING) {
|
||||
Yap_FreeCodeSpace((char *)TrNode_entry(current_node));
|
||||
child_mode = TRAVERSE_MODE_BIGINT_OR_STRING_END;
|
||||
} else if (mode == TRAVERSE_MODE_DOUBLE) {
|
||||
#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P
|
||||
child_mode = TRAVERSE_MODE_DOUBLE2;
|
||||
else if (mode == TRAVERSE_MODE_DOUBLE2)
|
||||
} else if (mode == TRAVERSE_MODE_DOUBLE2) {
|
||||
#endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */
|
||||
child_mode = TRAVERSE_MODE_DOUBLE_END;
|
||||
else
|
||||
} else {
|
||||
child_mode = TRAVERSE_MODE_NORMAL;
|
||||
}
|
||||
free_subgoal_trie(TrNode_child(current_node), child_mode, TRAVERSE_POSITION_FIRST);
|
||||
} else {
|
||||
sg_fr_ptr sg_fr = get_subgoal_frame_for_abolish(current_node PASS_REGS);
|
||||
@@ -1461,20 +1492,26 @@ void free_answer_trie(ans_node_ptr current_node, int mode, int position) {
|
||||
child_mode = TRAVERSE_MODE_DOUBLE;
|
||||
else if (f == FunctorLongInt)
|
||||
child_mode = TRAVERSE_MODE_LONGINT;
|
||||
else if (f == FunctorBigInt || f == FunctorString)
|
||||
child_mode = TRAVERSE_MODE_BIGINT_OR_STRING;
|
||||
else
|
||||
child_mode = TRAVERSE_MODE_NORMAL;
|
||||
} else
|
||||
child_mode = TRAVERSE_MODE_NORMAL;
|
||||
} else if (mode == TRAVERSE_MODE_LONGINT)
|
||||
} else if (mode == TRAVERSE_MODE_LONGINT) {
|
||||
child_mode = TRAVERSE_MODE_LONGINT_END;
|
||||
else if (mode == TRAVERSE_MODE_DOUBLE)
|
||||
} else if (mode == TRAVERSE_MODE_BIGINT_OR_STRING) {
|
||||
Yap_FreeCodeSpace((char *)TrNode_entry(current_node));
|
||||
child_mode = TRAVERSE_MODE_BIGINT_OR_STRING_END;
|
||||
} else if (mode == TRAVERSE_MODE_DOUBLE) {
|
||||
#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P
|
||||
child_mode = TRAVERSE_MODE_DOUBLE2;
|
||||
else if (mode == TRAVERSE_MODE_DOUBLE2)
|
||||
} else if (mode == TRAVERSE_MODE_DOUBLE2) {
|
||||
#endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */
|
||||
child_mode = TRAVERSE_MODE_DOUBLE_END;
|
||||
else
|
||||
} else {
|
||||
child_mode = TRAVERSE_MODE_NORMAL;
|
||||
}
|
||||
free_answer_trie(TrNode_child(current_node), child_mode, TRAVERSE_POSITION_FIRST);
|
||||
}
|
||||
if (position == TRAVERSE_POSITION_FIRST) {
|
||||
|
@@ -1160,10 +1160,15 @@ static inline sg_node_ptr subgoal_search_loop(tab_ent_ptr tab_ent, sg_node_ptr c
|
||||
#ifdef MODE_GLOBAL_TRIE_LOOP
|
||||
SUBGOAL_CHECK_INSERT_ENTRY(tab_ent, current_node, AbsAppl((Term *)f));
|
||||
#endif /* MODE_GLOBAL_TRIE_LOOP */
|
||||
} else if (f == FunctorBigInt || f == FunctorString) {
|
||||
CELL *new = Yap_HeapStoreOpaqueTerm(t);
|
||||
SUBGOAL_CHECK_INSERT_ENTRY(tab_ent, current_node, AbsAppl((Term *)f));
|
||||
SUBGOAL_CHECK_INSERT_ENTRY(tab_ent, current_node, (CELL)new);
|
||||
#ifdef MODE_GLOBAL_TRIE_LOOP
|
||||
SUBGOAL_CHECK_INSERT_ENTRY(tab_ent, current_node, AbsAppl((Term *)f));
|
||||
#endif /* MODE_GLOBAL_TRIE_LOOP */
|
||||
} else if (f == FunctorDBRef) {
|
||||
Yap_Error(INTERNAL_ERROR, TermNil, "subgoal_search_loop: unsupported type tag FunctorDBRef");
|
||||
} else if (f == FunctorBigInt) {
|
||||
Yap_Error(INTERNAL_ERROR, TermNil, "subgoal_search_loop: unsupported type tag FunctorBigInt");
|
||||
} else {
|
||||
int i;
|
||||
CELL *aux_appl = RepAppl(t);
|
||||
@@ -1374,10 +1379,13 @@ static inline ans_node_ptr answer_search_loop(sg_fr_ptr sg_fr, ans_node_ptr curr
|
||||
ANSWER_CHECK_INSERT_ENTRY(sg_fr, current_node, AbsAppl((Term *)f), _trie_retry_null + in_pair);
|
||||
ANSWER_CHECK_INSERT_ENTRY(sg_fr, current_node, li, _trie_retry_extension);
|
||||
ANSWER_CHECK_INSERT_ENTRY(sg_fr, current_node, AbsAppl((Term *)f), _trie_retry_longint);
|
||||
} else if (f == FunctorBigInt || FunctorString) {
|
||||
CELL *opq = Yap_HeapStoreOpaqueTerm(t);
|
||||
ANSWER_CHECK_INSERT_ENTRY(sg_fr, current_node, AbsAppl((Term *)f), _trie_retry_null + in_pair);
|
||||
ANSWER_CHECK_INSERT_ENTRY(sg_fr, current_node, (CELL)opq, _trie_retry_extension);
|
||||
ANSWER_CHECK_INSERT_ENTRY(sg_fr, current_node, AbsAppl((Term *)f), _trie_retry_bigint);
|
||||
} else if (f == FunctorDBRef) {
|
||||
Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_loop: unsupported type tag FunctorDBRef");
|
||||
} else if (f == FunctorBigInt) {
|
||||
Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_loop: unsupported type tag FunctorBigInt");
|
||||
} else {
|
||||
int i;
|
||||
CELL *aux_appl = RepAppl(t);
|
||||
@@ -1416,18 +1424,19 @@ static inline ans_node_ptr answer_search_loop(sg_fr_ptr sg_fr, ans_node_ptr curr
|
||||
static inline ans_node_ptr answer_search_min_max(sg_fr_ptr sg_fr, ans_node_ptr current_node, Term t, int mode USES_REGS) {
|
||||
ans_node_ptr child_node;
|
||||
Term child_term;
|
||||
Float trie_value = 0, term_value = 0;
|
||||
Term trie_value = 0, term_value = t;
|
||||
int cmp;
|
||||
|
||||
/* start by computing the current value on the trie (trie_value) */
|
||||
child_node = TrNode_child(current_node);
|
||||
child_term = TrNode_entry(child_node);
|
||||
if (IsIntTerm(child_term)) {
|
||||
trie_value = (Float) IntOfTerm(child_term);
|
||||
trie_value = child_term;
|
||||
} else if (IsApplTerm(child_term)) {
|
||||
Functor f = (Functor) RepAppl(child_term);
|
||||
child_node = TrNode_child(child_node);
|
||||
if (f == FunctorLongInt) {
|
||||
trie_value = (Float) TrNode_entry(child_node);
|
||||
trie_value = MkLongIntTerm( (Int) TrNode_entry(child_node) );
|
||||
} else if (f == FunctorDouble) {
|
||||
union {
|
||||
Term t_dbl[sizeof(Float)/sizeof(Term)];
|
||||
@@ -1438,30 +1447,20 @@ static inline ans_node_ptr answer_search_min_max(sg_fr_ptr sg_fr, ans_node_ptr c
|
||||
child_node = TrNode_child(child_node);
|
||||
u.t_dbl[1] = TrNode_entry(child_node);
|
||||
#endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */
|
||||
trie_value = u.dbl;
|
||||
trie_value = MkFloatTerm(u.dbl);
|
||||
} else if (f == FunctorBigInt) {
|
||||
trie_value = AbsAppl( (CELL *) TrNode_entry(child_node) );
|
||||
} else
|
||||
Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_min_max: invalid arithmetic value");
|
||||
child_node = TrNode_child(child_node);
|
||||
}
|
||||
|
||||
/* then compute the value for the new term (term_value) */
|
||||
if (IsAtomOrIntTerm(t))
|
||||
term_value = (Float) IntOfTerm(t);
|
||||
else if (IsApplTerm(t)) {
|
||||
Functor f = FunctorOfTerm(t);
|
||||
if (f == FunctorLongInt)
|
||||
term_value = (Float) LongIntOfTerm(t);
|
||||
else if (f == FunctorDouble)
|
||||
term_value = FloatOfTerm(t);
|
||||
else
|
||||
Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_min_max: invalid arithmetic value");
|
||||
}
|
||||
|
||||
cmp = Yap_acmp( term_value, trie_value PASS_REGS);
|
||||
/* worse answer */
|
||||
if ((mode == MODE_DIRECTED_MIN && term_value > trie_value) || (mode == MODE_DIRECTED_MAX && term_value < trie_value))
|
||||
if ((mode == MODE_DIRECTED_MIN && cmp > 0) || (mode == MODE_DIRECTED_MAX && cmp < 0))
|
||||
return NULL;
|
||||
/* equal answer */
|
||||
if (term_value == trie_value)
|
||||
if (cmp == 0)
|
||||
return child_node;
|
||||
/* better answer */
|
||||
if (IsAtomOrIntTerm(t)) {
|
||||
@@ -1485,6 +1484,11 @@ static inline ans_node_ptr answer_search_min_max(sg_fr_ptr sg_fr, ans_node_ptr c
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, AbsAppl((Term *)f), _trie_retry_null);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, li, _trie_retry_extension);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, AbsAppl((Term *)f), _trie_retry_longint);
|
||||
} else if (f == FunctorBigInt) {
|
||||
CELL *li = Yap_HeapStoreOpaqueTerm(t);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, AbsAppl((Term *)f), _trie_retry_null);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, (CELL)li, _trie_retry_extension);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, AbsAppl((Term *)f), _trie_retry_bigint);
|
||||
}
|
||||
}
|
||||
return current_node;
|
||||
@@ -1501,19 +1505,18 @@ static inline ans_node_ptr answer_search_min_max(sg_fr_ptr sg_fr, ans_node_ptr c
|
||||
static inline ans_node_ptr answer_search_sum(sg_fr_ptr sg_fr, ans_node_ptr current_node, Term t USES_REGS) {
|
||||
ans_node_ptr child_node;
|
||||
Term child_term;
|
||||
Float trie_value = 0, term_value = 0, sum_value = 0;
|
||||
int sum_value_as_int;
|
||||
Term trie_value = 0, term_value = t, sum_value = 0;
|
||||
|
||||
/* start by computing the current value on the trie (trie_value) */
|
||||
child_node = TrNode_child(current_node);
|
||||
child_term = TrNode_entry(child_node);
|
||||
if (IsIntTerm(child_term)) {
|
||||
trie_value = (Float) IntOfTerm(child_term);
|
||||
trie_value = child_term;
|
||||
} else if (IsApplTerm(child_term)) {
|
||||
Functor f = (Functor) RepAppl(child_term);
|
||||
child_node = TrNode_child(child_node);
|
||||
if (f == FunctorLongInt) {
|
||||
trie_value = (Float) TrNode_entry(child_node);
|
||||
trie_value = MkLongIntTerm( (Int) TrNode_entry(child_node) );
|
||||
} else if (f == FunctorDouble) {
|
||||
union {
|
||||
Term t_dbl[sizeof(Float)/sizeof(Term)];
|
||||
@@ -1524,41 +1527,43 @@ static inline ans_node_ptr answer_search_sum(sg_fr_ptr sg_fr, ans_node_ptr curre
|
||||
child_node = TrNode_child(child_node);
|
||||
u.t_dbl[1] = TrNode_entry(child_node);
|
||||
#endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */
|
||||
trie_value = u.dbl;
|
||||
trie_value = MkFloatTerm(u.dbl);
|
||||
} else if (f == FunctorBigInt) {
|
||||
trie_value = AbsAppl( (CELL *) TrNode_entry(child_node) );
|
||||
} else
|
||||
Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_sum: invalid arithmetic value");
|
||||
Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_min_max: invalid arithmetic value");
|
||||
child_node = TrNode_child(child_node);
|
||||
}
|
||||
|
||||
/* then compute the value for the new term (term_value) */
|
||||
if (IsAtomOrIntTerm(t))
|
||||
term_value = (Float) IntOfTerm(t);
|
||||
else if (IsApplTerm(t)) {
|
||||
Functor f = FunctorOfTerm(t);
|
||||
if (f == FunctorLongInt)
|
||||
term_value = (Float) LongIntOfTerm(t);
|
||||
else if (f == FunctorDouble)
|
||||
term_value = FloatOfTerm(t);
|
||||
else
|
||||
Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_sum: invalid arithmetic value");
|
||||
}
|
||||
sum_value = trie_value + term_value;
|
||||
sum_value_as_int = (int) sum_value;
|
||||
if (sum_value == (float) sum_value_as_int && IntInBnd(sum_value_as_int)) {
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, MkIntegerTerm(sum_value_as_int), _trie_retry_atom);
|
||||
} else {
|
||||
union {
|
||||
Term t_dbl[sizeof(Float)/sizeof(Term)];
|
||||
Float dbl;
|
||||
} u;
|
||||
u.dbl = sum_value;
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, AbsAppl((Term *)FunctorDouble), _trie_retry_null);
|
||||
sum_value = p_plus(trie_value, term_value PASS_REGS);
|
||||
if (IsAtomOrIntTerm(sum_value)) {
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, sum_value, _trie_retry_atom);
|
||||
} else if (IsApplTerm(sum_value)) {
|
||||
Functor f = FunctorOfTerm(sum_value);
|
||||
if (f == FunctorDouble) {
|
||||
union {
|
||||
Term t_dbl[sizeof(Float)/sizeof(Term)];
|
||||
Float dbl;
|
||||
} u;
|
||||
u.dbl = FloatOfTerm(sum_value);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, AbsAppl((Term *)f), _trie_retry_null);
|
||||
#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, u.t_dbl[1], _trie_retry_extension);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, u.t_dbl[1], _trie_retry_extension);
|
||||
#endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, u.t_dbl[0], _trie_retry_extension);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, AbsAppl((Term *)FunctorDouble), _trie_retry_double);
|
||||
}
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, u.t_dbl[0], _trie_retry_extension);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, AbsAppl((Term *)f), _trie_retry_double);
|
||||
} else if (f == FunctorLongInt) {
|
||||
Int li = LongIntOfTerm(sum_value);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, AbsAppl((Term *)f), _trie_retry_null);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, li, _trie_retry_extension);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, AbsAppl((Term *)f), _trie_retry_longint);
|
||||
} else if (f == FunctorBigInt) {
|
||||
CELL *li = Yap_HeapStoreOpaqueTerm(sum_value);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, AbsAppl((Term *)f), _trie_retry_null);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, (CELL)li, _trie_retry_extension);
|
||||
ANSWER_SAFE_INSERT_ENTRY(current_node, AbsAppl((Term *)f), _trie_retry_bigint);
|
||||
}
|
||||
}
|
||||
return current_node;
|
||||
}
|
||||
#endif /* INCLUDE_ANSWER_SEARCH_MODE_DIRECTED */
|
||||
@@ -1757,6 +1762,11 @@ static inline CELL *load_answer_loop(ans_node_ptr current_node USES_REGS) {
|
||||
current_node = TrNode_parent(current_node);
|
||||
current_node = TrNode_parent(current_node);
|
||||
t = MkLongIntTerm(li);
|
||||
} else if (f == FunctorBigInt || f == FunctorString) {
|
||||
CELL *ptr = (CELL *)TrNode_entry(current_node);
|
||||
current_node = TrNode_parent(current_node);
|
||||
current_node = TrNode_parent(current_node);
|
||||
t = AbsAppl( ptr );
|
||||
} else {
|
||||
int f_arity = ArityOfFunctor(f);
|
||||
t = Yap_MkApplTerm(f, f_arity, stack_terms);
|
||||
|
@@ -1149,6 +1149,37 @@
|
||||
ENDBOp();
|
||||
|
||||
|
||||
PBOp(trie_do_bigint, e)
|
||||
register ans_node_ptr node = (ans_node_ptr) PREG;
|
||||
register CELL *aux_stack = TOP_STACK;
|
||||
int heap_arity = aux_stack[HEAP_ARITY_ENTRY];
|
||||
int vars_arity = aux_stack[VARS_ARITY_ENTRY];
|
||||
int subs_arity = aux_stack[SUBS_ARITY_ENTRY];
|
||||
Term t = AbsAppl((CELL*)aux_stack[HEAP_ENTRY(1)]);
|
||||
|
||||
heap_arity -= 2;
|
||||
TOP_STACK = aux_stack = &aux_stack[2]; /* jump until the extension mark */
|
||||
TOP_STACK[HEAP_ARITY_ENTRY] = heap_arity;
|
||||
aux_stack_term_instr();
|
||||
ENDPBOp();
|
||||
|
||||
|
||||
BOp(trie_trust_bigint, e)
|
||||
Yap_Error(INTERNAL_ERROR, TermNil, "trie_trust_bigint: invalid instruction");
|
||||
ENDBOp();
|
||||
|
||||
|
||||
BOp(trie_try_bigint, e)
|
||||
Yap_Error(INTERNAL_ERROR, TermNil, "trie_try_bigint: invalid instruction");
|
||||
ENDBOp();
|
||||
|
||||
|
||||
BOp(trie_retry_bigint, e)
|
||||
Yap_Error(INTERNAL_ERROR, TermNil, "trie_retry_bigint: invalid instruction");
|
||||
ENDBOp();
|
||||
|
||||
|
||||
|
||||
PBOp(trie_do_gterm, e)
|
||||
register ans_node_ptr node = (ans_node_ptr) PREG;
|
||||
register CELL *aux_stack = TOP_STACK;
|
||||
|
Reference in New Issue
Block a user