From 5e4d7078ab7ceae94d13e896dc22472142d838c7 Mon Sep 17 00:00:00 2001 From: Ricardo Rocha Date: Sun, 5 Jul 2009 05:14:08 +0100 Subject: [PATCH] support for trie compact lists (version 2): this new version uses different marks to distinguish the lists ending with the empty list from the lists ending with a non-empty list term. --- C/absmi.c | 30 +- C/cdmgr.c | 60 ++- C/heapgc.c | 60 ++- C/index.c | 28 +- H/YapOpcodes.h | 52 ++- H/rclause.h | 52 ++- H/walkclause.h | 52 ++- OPTYap/opt.config.h | 6 +- OPTYap/tab.macros.h | 11 +- OPTYap/tab.tries.c | 276 +++++++------ OPTYap/tab.tries.insts.i | 872 +++++++++++++++++---------------------- 11 files changed, 748 insertions(+), 751 deletions(-) diff --git a/C/absmi.c b/C/absmi.c index 50ff9cb53..53dd170c1 100644 --- a/C/absmi.c +++ b/C/absmi.c @@ -1883,24 +1883,34 @@ Yap_absmi(int inp) case _table_answer_resolution: low_level_trace(retry_table_consumer, CONS_CP(B)->cp_pred_entry, NULL); break; - case _trie_retry_null: case _trie_trust_null: - case _trie_retry_var: + case _trie_retry_null: + case _trie_trust_null_in_new_pair: + case _trie_retry_null_in_new_pair: case _trie_trust_var: - case _trie_retry_val: + case _trie_retry_var: + case _trie_trust_var_in_new_pair: + case _trie_retry_var_in_new_pair: case _trie_trust_val: - case _trie_retry_atom: + case _trie_retry_val: + case _trie_trust_val_in_new_pair: + case _trie_retry_val_in_new_pair: case _trie_trust_atom: - case _trie_retry_list: - case _trie_trust_list: - case _trie_retry_struct: + case _trie_retry_atom: + case _trie_trust_atom_in_new_pair: + case _trie_retry_atom_in_new_pair: + case _trie_trust_pair: + case _trie_retry_pair: case _trie_trust_struct: - case _trie_retry_extension: + case _trie_retry_struct: + case _trie_trust_struct_in_new_pair: + case _trie_retry_struct_in_new_pair: case _trie_trust_extension: - case _trie_retry_float: + case _trie_retry_extension: case _trie_trust_float: - case _trie_retry_long: + case _trie_retry_float: case _trie_trust_long: + case _trie_retry_long: low_level_trace(retry_table_loader, UndefCode, NULL); break; #endif /* TABLING */ diff --git a/C/cdmgr.c b/C/cdmgr.c index ae15542f4..f38df2397 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -558,24 +558,34 @@ PredForChoicePt(yamop *p_code) { case _profiled_trust_logical: return p_code->u.OtaLl.d->ClPred; #ifdef TABLING - case _trie_retry_null: case _trie_trust_null: - case _trie_retry_var: + case _trie_retry_null: + case _trie_trust_null_in_new_pair: + case _trie_retry_null_in_new_pair: case _trie_trust_var: - case _trie_retry_val: + case _trie_retry_var: + case _trie_trust_var_in_new_pair: + case _trie_retry_var_in_new_pair: case _trie_trust_val: - case _trie_retry_atom: + case _trie_retry_val: + case _trie_trust_val_in_new_pair: + case _trie_retry_val_in_new_pair: case _trie_trust_atom: - case _trie_retry_list: - case _trie_trust_list: - case _trie_retry_struct: + case _trie_retry_atom: + case _trie_trust_atom_in_new_pair: + case _trie_retry_atom_in_new_pair: + case _trie_trust_pair: + case _trie_retry_pair: case _trie_trust_struct: - case _trie_retry_extension: + case _trie_retry_struct: + case _trie_trust_struct_in_new_pair: + case _trie_retry_struct_in_new_pair: case _trie_trust_extension: - case _trie_retry_float: + case _trie_retry_extension: case _trie_trust_float: - case _trie_retry_long: + case _trie_retry_float: case _trie_trust_long: + case _trie_retry_long: return NULL; case _table_load_answer: case _table_try_answer: @@ -5415,24 +5425,34 @@ p_choicepoint_info(void) #endif t = MkVarTerm(); break; - case _trie_retry_null: case _trie_trust_null: - case _trie_retry_var: + case _trie_retry_null: + case _trie_trust_null_in_new_pair: + case _trie_retry_null_in_new_pair: case _trie_trust_var: - case _trie_retry_val: + case _trie_retry_var: + case _trie_trust_var_in_new_pair: + case _trie_retry_var_in_new_pair: case _trie_trust_val: - case _trie_retry_atom: + case _trie_retry_val: + case _trie_trust_val_in_new_pair: + case _trie_retry_val_in_new_pair: case _trie_trust_atom: - case _trie_retry_list: - case _trie_trust_list: - case _trie_retry_struct: + case _trie_retry_atom: + case _trie_trust_atom_in_new_pair: + case _trie_retry_atom_in_new_pair: + case _trie_trust_pair: + case _trie_retry_pair: case _trie_trust_struct: - case _trie_retry_extension: + case _trie_retry_struct: + case _trie_trust_struct_in_new_pair: + case _trie_retry_struct_in_new_pair: case _trie_trust_extension: - case _trie_retry_float: + case _trie_retry_extension: case _trie_trust_float: - case _trie_retry_long: + case _trie_retry_float: case _trie_trust_long: + case _trie_retry_long: pe = UndefCode; t = MkVarTerm(); break; diff --git a/C/heapgc.c b/C/heapgc.c index 8a5783835..a2931d435 100644 --- a/C/heapgc.c +++ b/C/heapgc.c @@ -2065,24 +2065,34 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose) } nargs = 0; break; - case _trie_retry_null: case _trie_trust_null: - case _trie_retry_var: + case _trie_retry_null: + case _trie_trust_null_in_new_pair: + case _trie_retry_null_in_new_pair: case _trie_trust_var: - case _trie_retry_val: + case _trie_retry_var: + case _trie_trust_var_in_new_pair: + case _trie_retry_var_in_new_pair: case _trie_trust_val: - case _trie_retry_atom: + case _trie_retry_val: + case _trie_trust_val_in_new_pair: + case _trie_retry_val_in_new_pair: case _trie_trust_atom: - case _trie_retry_list: - case _trie_trust_list: - case _trie_retry_struct: + case _trie_retry_atom: + case _trie_trust_atom_in_new_pair: + case _trie_retry_atom_in_new_pair: + case _trie_trust_pair: + case _trie_retry_pair: case _trie_trust_struct: - case _trie_retry_extension: + case _trie_retry_struct: + case _trie_trust_struct_in_new_pair: + case _trie_retry_struct_in_new_pair: case _trie_trust_extension: - case _trie_retry_float: + case _trie_retry_extension: case _trie_trust_float: - case _trie_retry_long: + case _trie_retry_float: case _trie_trust_long: + case _trie_retry_long: { CELL *vars_ptr; int heap_arity, vars_arity, subs_arity; @@ -2945,24 +2955,34 @@ sweep_choicepoints(choiceptr gc_B) } } break; - case _trie_retry_null: case _trie_trust_null: - case _trie_retry_var: + case _trie_retry_null: + case _trie_trust_null_in_new_pair: + case _trie_retry_null_in_new_pair: case _trie_trust_var: - case _trie_retry_val: + case _trie_retry_var: + case _trie_trust_var_in_new_pair: + case _trie_retry_var_in_new_pair: case _trie_trust_val: - case _trie_retry_atom: + case _trie_retry_val: + case _trie_trust_val_in_new_pair: + case _trie_retry_val_in_new_pair: case _trie_trust_atom: - case _trie_retry_list: - case _trie_trust_list: - case _trie_retry_struct: + case _trie_retry_atom: + case _trie_trust_atom_in_new_pair: + case _trie_retry_atom_in_new_pair: + case _trie_trust_pair: + case _trie_retry_pair: case _trie_trust_struct: - case _trie_retry_extension: + case _trie_retry_struct: + case _trie_trust_struct_in_new_pair: + case _trie_retry_struct_in_new_pair: case _trie_trust_extension: - case _trie_retry_float: + case _trie_retry_extension: case _trie_trust_float: - case _trie_retry_long: + case _trie_retry_float: case _trie_trust_long: + case _trie_retry_long: { CELL *vars_ptr; int heap_arity, vars_arity, subs_arity; diff --git a/C/index.c b/C/index.c index 5924dbc97..96bcae3cf 100644 --- a/C/index.c +++ b/C/index.c @@ -1069,26 +1069,46 @@ has_cut(yamop *pc) case _trie_trust_null: case _trie_try_null: case _trie_retry_null: + case _trie_do_null_in_new_pair: + case _trie_trust_null_in_new_pair: + case _trie_try_null_in_new_pair: + case _trie_retry_null_in_new_pair: case _trie_do_var: case _trie_trust_var: case _trie_try_var: case _trie_retry_var: + case _trie_do_var_in_new_pair: + case _trie_trust_var_in_new_pair: + case _trie_try_var_in_new_pair: + case _trie_retry_var_in_new_pair: case _trie_do_val: case _trie_trust_val: case _trie_try_val: case _trie_retry_val: + case _trie_do_val_in_new_pair: + case _trie_trust_val_in_new_pair: + case _trie_try_val_in_new_pair: + case _trie_retry_val_in_new_pair: case _trie_do_atom: case _trie_trust_atom: case _trie_try_atom: case _trie_retry_atom: - case _trie_do_list: - case _trie_trust_list: - case _trie_try_list: - case _trie_retry_list: + case _trie_do_atom_in_new_pair: + case _trie_trust_atom_in_new_pair: + case _trie_try_atom_in_new_pair: + case _trie_retry_atom_in_new_pair: + case _trie_do_pair: + case _trie_trust_pair: + case _trie_try_pair: + case _trie_retry_pair: case _trie_do_struct: case _trie_trust_struct: case _trie_try_struct: case _trie_retry_struct: + case _trie_do_struct_in_new_pair: + case _trie_trust_struct_in_new_pair: + case _trie_try_struct_in_new_pair: + case _trie_retry_struct_in_new_pair: case _trie_do_extension: case _trie_trust_extension: case _trie_try_extension: diff --git a/H/YapOpcodes.h b/H/YapOpcodes.h index faa289890..8a7ee84b1 100644 --- a/H/YapOpcodes.h +++ b/H/YapOpcodes.h @@ -345,50 +345,46 @@ OPCODE(trie_trust_null ,e), OPCODE(trie_try_null ,e), OPCODE(trie_retry_null ,e), - OPCODE(trie_do_null_in_new_list ,e), - OPCODE(trie_trust_null_in_new_list,e), - OPCODE(trie_try_null_in_new_list ,e), - OPCODE(trie_retry_null_in_new_list,e), + OPCODE(trie_do_null_in_new_pair ,e), + OPCODE(trie_trust_null_in_new_pair,e), + OPCODE(trie_try_null_in_new_pair ,e), + OPCODE(trie_retry_null_in_new_pair,e), OPCODE(trie_do_var ,e), OPCODE(trie_trust_var ,e), OPCODE(trie_try_var ,e), OPCODE(trie_retry_var ,e), - OPCODE(trie_do_var_in_new_list ,e), - OPCODE(trie_trust_var_in_new_list ,e), - OPCODE(trie_try_var_in_new_list ,e), - OPCODE(trie_retry_var_in_new_list ,e), + OPCODE(trie_do_var_in_new_pair ,e), + OPCODE(trie_trust_var_in_new_pair ,e), + OPCODE(trie_try_var_in_new_pair ,e), + OPCODE(trie_retry_var_in_new_pair ,e), OPCODE(trie_do_val ,e), OPCODE(trie_trust_val ,e), OPCODE(trie_try_val ,e), OPCODE(trie_retry_val ,e), - OPCODE(trie_do_val_in_new_list ,e), - OPCODE(trie_trust_val_in_new_list ,e), - OPCODE(trie_try_val_in_new_list ,e), - OPCODE(trie_retry_val_in_new_list ,e), + OPCODE(trie_do_val_in_new_pair ,e), + OPCODE(trie_trust_val_in_new_pair ,e), + OPCODE(trie_try_val_in_new_pair ,e), + OPCODE(trie_retry_val_in_new_pair ,e), OPCODE(trie_do_atom ,e), OPCODE(trie_trust_atom ,e), OPCODE(trie_try_atom ,e), OPCODE(trie_retry_atom ,e), - OPCODE(trie_do_atom_in_new_list ,e), - OPCODE(trie_trust_atom_in_new_list,e), - OPCODE(trie_try_atom_in_new_list ,e), - OPCODE(trie_retry_atom_in_new_list,e), - OPCODE(trie_do_list ,e), - OPCODE(trie_trust_list ,e), - OPCODE(trie_try_list ,e), - OPCODE(trie_retry_list ,e), - OPCODE(trie_do_list_in_new_list ,e), - OPCODE(trie_trust_list_in_new_list,e), - OPCODE(trie_try_list_in_new_list ,e), - OPCODE(trie_retry_list_in_new_list,e), + OPCODE(trie_do_atom_in_new_pair ,e), + OPCODE(trie_trust_atom_in_new_pair,e), + OPCODE(trie_try_atom_in_new_pair ,e), + OPCODE(trie_retry_atom_in_new_pair,e), + OPCODE(trie_do_pair ,e), + OPCODE(trie_trust_pair ,e), + OPCODE(trie_try_pair ,e), + OPCODE(trie_retry_pair ,e), OPCODE(trie_do_struct ,e), OPCODE(trie_trust_struct ,e), OPCODE(trie_try_struct ,e), OPCODE(trie_retry_struct ,e), - OPCODE(trie_do_struct_in_new_list ,e), - OPCODE(trie_trust_struct_in_new_list,e), - OPCODE(trie_try_struct_in_new_list,e), - OPCODE(trie_retry_struct_in_new_list,e), + OPCODE(trie_do_struct_in_new_pair ,e), + OPCODE(trie_trust_struct_in_new_pair,e), + OPCODE(trie_try_struct_in_new_pair,e), + OPCODE(trie_retry_struct_in_new_pair,e), OPCODE(trie_do_extension ,e), OPCODE(trie_trust_extension ,e), OPCODE(trie_try_extension ,e), diff --git a/H/rclause.h b/H/rclause.h index 47c49b69c..2a8b4c486 100644 --- a/H/rclause.h +++ b/H/rclause.h @@ -793,65 +793,61 @@ restore_opcodes(yamop *pc) break; /* instructions type e */ case _trie_do_atom: - case _trie_do_atom_in_new_list: + case _trie_do_atom_in_new_pair: case _trie_do_extension: case _trie_do_float: - case _trie_do_list: - case _trie_do_list_in_new_list: case _trie_do_long: case _trie_do_null: - case _trie_do_null_in_new_list: + case _trie_do_null_in_new_pair: + case _trie_do_pair: case _trie_do_struct: - case _trie_do_struct_in_new_list: + case _trie_do_struct_in_new_pair: case _trie_do_val: - case _trie_do_val_in_new_list: + case _trie_do_val_in_new_pair: case _trie_do_var: - case _trie_do_var_in_new_list: + case _trie_do_var_in_new_pair: case _trie_retry_atom: - case _trie_retry_atom_in_new_list: + case _trie_retry_atom_in_new_pair: case _trie_retry_extension: case _trie_retry_float: - case _trie_retry_list: - case _trie_retry_list_in_new_list: case _trie_retry_long: case _trie_retry_null: - case _trie_retry_null_in_new_list: + case _trie_retry_null_in_new_pair: + case _trie_retry_pair: case _trie_retry_struct: - case _trie_retry_struct_in_new_list: + case _trie_retry_struct_in_new_pair: case _trie_retry_val: - case _trie_retry_val_in_new_list: + case _trie_retry_val_in_new_pair: case _trie_retry_var: - case _trie_retry_var_in_new_list: + case _trie_retry_var_in_new_pair: case _trie_trust_atom: - case _trie_trust_atom_in_new_list: + case _trie_trust_atom_in_new_pair: case _trie_trust_extension: case _trie_trust_float: - case _trie_trust_list: - case _trie_trust_list_in_new_list: case _trie_trust_long: case _trie_trust_null: - case _trie_trust_null_in_new_list: + case _trie_trust_null_in_new_pair: + case _trie_trust_pair: case _trie_trust_struct: - case _trie_trust_struct_in_new_list: + case _trie_trust_struct_in_new_pair: case _trie_trust_val: - case _trie_trust_val_in_new_list: + case _trie_trust_val_in_new_pair: case _trie_trust_var: - case _trie_trust_var_in_new_list: + case _trie_trust_var_in_new_pair: case _trie_try_atom: - case _trie_try_atom_in_new_list: + case _trie_try_atom_in_new_pair: case _trie_try_extension: case _trie_try_float: - case _trie_try_list: - case _trie_try_list_in_new_list: case _trie_try_long: case _trie_try_null: - case _trie_try_null_in_new_list: + case _trie_try_null_in_new_pair: + case _trie_try_pair: case _trie_try_struct: - case _trie_try_struct_in_new_list: + case _trie_try_struct_in_new_pair: case _trie_try_val: - case _trie_try_val_in_new_list: + case _trie_try_val_in_new_pair: case _trie_try_var: - case _trie_try_var_in_new_list: + case _trie_try_var_in_new_pair: if (op == _Nstop || op == _copy_idb_term || op == _unify_idb_term) return; pc = NEXTOP(pc,e); break; diff --git a/H/walkclause.h b/H/walkclause.h index d396071c9..5a0698e16 100644 --- a/H/walkclause.h +++ b/H/walkclause.h @@ -612,65 +612,61 @@ break; /* instructions type e */ case _trie_do_atom: - case _trie_do_atom_in_new_list: + case _trie_do_atom_in_new_pair: case _trie_do_extension: case _trie_do_float: - case _trie_do_list: - case _trie_do_list_in_new_list: case _trie_do_long: case _trie_do_null: - case _trie_do_null_in_new_list: + case _trie_do_null_in_new_pair: + case _trie_do_pair: case _trie_do_struct: - case _trie_do_struct_in_new_list: + case _trie_do_struct_in_new_pair: case _trie_do_val: - case _trie_do_val_in_new_list: + case _trie_do_val_in_new_pair: case _trie_do_var: - case _trie_do_var_in_new_list: + case _trie_do_var_in_new_pair: case _trie_retry_atom: - case _trie_retry_atom_in_new_list: + case _trie_retry_atom_in_new_pair: case _trie_retry_extension: case _trie_retry_float: - case _trie_retry_list: - case _trie_retry_list_in_new_list: case _trie_retry_long: case _trie_retry_null: - case _trie_retry_null_in_new_list: + case _trie_retry_null_in_new_pair: + case _trie_retry_pair: case _trie_retry_struct: - case _trie_retry_struct_in_new_list: + case _trie_retry_struct_in_new_pair: case _trie_retry_val: - case _trie_retry_val_in_new_list: + case _trie_retry_val_in_new_pair: case _trie_retry_var: - case _trie_retry_var_in_new_list: + case _trie_retry_var_in_new_pair: case _trie_trust_atom: - case _trie_trust_atom_in_new_list: + case _trie_trust_atom_in_new_pair: case _trie_trust_extension: case _trie_trust_float: - case _trie_trust_list: - case _trie_trust_list_in_new_list: case _trie_trust_long: case _trie_trust_null: - case _trie_trust_null_in_new_list: + case _trie_trust_null_in_new_pair: + case _trie_trust_pair: case _trie_trust_struct: - case _trie_trust_struct_in_new_list: + case _trie_trust_struct_in_new_pair: case _trie_trust_val: - case _trie_trust_val_in_new_list: + case _trie_trust_val_in_new_pair: case _trie_trust_var: - case _trie_trust_var_in_new_list: + case _trie_trust_var_in_new_pair: case _trie_try_atom: - case _trie_try_atom_in_new_list: + case _trie_try_atom_in_new_pair: case _trie_try_extension: case _trie_try_float: - case _trie_try_list: - case _trie_try_list_in_new_list: case _trie_try_long: case _trie_try_null: - case _trie_try_null_in_new_list: + case _trie_try_null_in_new_pair: + case _trie_try_pair: case _trie_try_struct: - case _trie_try_struct_in_new_list: + case _trie_try_struct_in_new_pair: case _trie_try_val: - case _trie_try_val_in_new_list: + case _trie_try_val_in_new_pair: case _trie_try_var: - case _trie_try_var_in_new_list: + case _trie_try_var_in_new_pair: pc = NEXTOP(pc,e); break; #endif diff --git a/OPTYap/opt.config.h b/OPTYap/opt.config.h index 5917e833a..d7b16baf1 100644 --- a/OPTYap/opt.config.h +++ b/OPTYap/opt.config.h @@ -50,9 +50,9 @@ /* #define INCOMPLETE_TABLING 1 */ /* ------------------------------------------------ ** -** support trie compact lists? (optional) ** +** support trie compact pairs? (optional) ** ** ------------------------------------------------ */ -/* #define TRIE_COMPACT_LISTS 1 */ +#define TRIE_COMPACT_PAIRS 1 /* --------------------------------------------------- ** ** support deterministic tabling? (optional) ** @@ -222,7 +222,7 @@ #undef BBREG_TRAIL_SCHEME #undef LIMIT_TABLING #undef INCOMPLETE_TABLING -#undef TRIE_COMPACT_LISTS +#undef TRIE_COMPACT_PAIRS #undef DETERMINISTIC_TABLING #undef TABLING_ERRORS #endif /* !TABLING */ diff --git a/OPTYap/tab.macros.h b/OPTYap/tab.macros.h index f0a79b6f6..b90ea8bd0 100644 --- a/OPTYap/tab.macros.h +++ b/OPTYap/tab.macros.h @@ -118,11 +118,12 @@ STD_PROTO(static inline tg_sol_fr_ptr CUT_prune_tg_solution_frames, (tg_sol_fr_p #define IsTableVarTerm(TERM) \ ((CELL) TERM) >= GLOBAL_table_var_enumerator(0) && \ ((CELL) TERM) <= GLOBAL_table_var_enumerator(MAX_TABLE_VARS - 1) -#ifdef TRIE_COMPACT_LISTS -#define PairTermMark NULL -#define PairTermInit ((Term *) 0) -#define PairTermLast ((Term *) (LowTagBits + 1)) -#endif /* TRIE_COMPACT_LISTS */ +#ifdef TRIE_COMPACT_PAIRS +#define PairTermMark NULL +#define CompactPairInit AbsPair((Term *) 0) +#define CompactPairEndTerm AbsPair((Term *) (LowTagBits + 1)) +#define CompactPairEndList AbsPair((Term *) (2*(LowTagBits + 1))) +#endif /* TRIE_COMPACT_PAIRS */ #define HASH_TABLE_LOCK(NODE) ((((unsigned long int)NODE) >> 5) & (TABLE_LOCK_BUCKETS - 1)) #define LOCK_TABLE(NODE) LOCK(GLOBAL_table_lock(HASH_TABLE_LOCK(NODE))) diff --git a/OPTYap/tab.tries.c b/OPTYap/tab.tries.c index 2266f39ea..4f83695ae 100644 --- a/OPTYap/tab.tries.c +++ b/OPTYap/tab.tries.c @@ -695,9 +695,9 @@ sg_fr_ptr subgoal_search(yamop *preg, CELL **Yaddr) { #endif /* TABLE_LOCK_LEVEL */ for (i = 1; i <= arity; i++) { STACK_CHECK_EXPAND(stack_terms, stack_terms_limit, stack_terms_base); - STACK_PUSH_UP(XREGS[i], stack_terms); + STACK_PUSH_UP(Deref(XREGS[i]), stack_terms); do { - Term t = Deref(STACK_POP_DOWN(stack_terms)); + Term t = STACK_POP_DOWN(stack_terms); if (IsVarTerm(t)) { if (IsTableVarTerm(t)) { t = MakeTableVarTerm(VarIndexOfTerm(t)); @@ -714,35 +714,45 @@ sg_fr_ptr subgoal_search(yamop *preg, CELL **Yaddr) { } else if (IsAtomOrIntTerm(t)) { current_sg_node = subgoal_trie_node_check_insert(tab_ent, current_sg_node, t); } else if (IsPairTerm(t)) { -#ifdef TRIE_COMPACT_LISTS +#ifdef TRIE_COMPACT_PAIRS CELL *aux = RepPair(t); if (aux == PairTermMark) { - t = Deref(STACK_POP_DOWN(stack_terms)); + t = STACK_POP_DOWN(stack_terms); if (IsPairTerm(t)) { aux = RepPair(t); - /* STACK_CHECK_EXPAND(stack_terms, stack_terms_limit + 2, stack_terms_base); */ - /* STACK_CHECK_EXPAND is not necessary here because the situation of pushing ** - ** up 3 terms has already initially checked for the PairTermInit term */ - STACK_PUSH_UP(*(aux + 1), stack_terms); - STACK_PUSH_UP(AbsPair(PairTermMark), stack_terms); - STACK_PUSH_UP(*(aux), stack_terms); + t = Deref(*(aux + 1)); + if (t == TermNil) { + current_sg_node = subgoal_trie_node_check_insert(tab_ent, current_sg_node, CompactPairEndList); + } else { + /* STACK_CHECK_EXPAND(stack_terms, stack_terms_limit + 2, stack_terms_base); */ + /* STACK_CHECK_EXPAND is not necessary here because the situation of pushing ** + ** up 3 terms has already initially checked for the CompactPairInit term */ + STACK_PUSH_UP(t, stack_terms); + STACK_PUSH_UP(AbsPair(PairTermMark), stack_terms); + } + STACK_PUSH_UP(Deref(*aux), stack_terms); } else { - current_sg_node = subgoal_trie_node_check_insert(tab_ent, current_sg_node, AbsPair(PairTermLast)); + current_sg_node = subgoal_trie_node_check_insert(tab_ent, current_sg_node, CompactPairEndTerm); STACK_PUSH_UP(t, stack_terms); } } else { - current_sg_node = subgoal_trie_node_check_insert(tab_ent, current_sg_node, AbsPair(PairTermInit)); - STACK_CHECK_EXPAND(stack_terms, stack_terms_limit + 2, stack_terms_base); - STACK_PUSH_UP(*(aux + 1), stack_terms); - STACK_PUSH_UP(AbsPair(PairTermMark), stack_terms); - STACK_PUSH_UP(*(aux), stack_terms); + current_sg_node = subgoal_trie_node_check_insert(tab_ent, current_sg_node, CompactPairInit); + t = Deref(*(aux + 1)); + if (t == TermNil) { + current_sg_node = subgoal_trie_node_check_insert(tab_ent, current_sg_node, CompactPairEndList); + } else { + STACK_CHECK_EXPAND(stack_terms, stack_terms_limit + 2, stack_terms_base); + STACK_PUSH_UP(t, stack_terms); + STACK_PUSH_UP(AbsPair(PairTermMark), stack_terms); + } + STACK_PUSH_UP(Deref(*aux), stack_terms); } #else current_sg_node = subgoal_trie_node_check_insert(tab_ent, current_sg_node, AbsPair(NULL)); STACK_CHECK_EXPAND(stack_terms, stack_terms_limit + 1, stack_terms_base); - STACK_PUSH_UP(*(RepPair(t) + 1), stack_terms); - STACK_PUSH_UP(*(RepPair(t)), stack_terms); -#endif /* TRIE_COMPACT_LISTS */ + STACK_PUSH_UP(Deref(*(RepPair(t) + 1)), stack_terms); + STACK_PUSH_UP(Deref(*(RepPair(t))), stack_terms); +#endif /* TRIE_COMPACT_PAIRS */ } else if (IsApplTerm(t)) { Functor f = FunctorOfTerm(t); current_sg_node = subgoal_trie_node_check_insert(tab_ent, current_sg_node, AbsAppl((Term *)f)); @@ -763,7 +773,7 @@ sg_fr_ptr subgoal_search(yamop *preg, CELL **Yaddr) { } else { STACK_CHECK_EXPAND(stack_terms, stack_terms_limit + ArityOfFunctor(f) - 1, stack_terms_base); for (j = ArityOfFunctor(f); j >= 1; j--) - STACK_PUSH_UP(*(RepAppl(t) + j), stack_terms); + STACK_PUSH_UP(Deref(*(RepAppl(t) + j)), stack_terms); } } else { Yap_Error(INTERNAL_ERROR, TermNil, "unknown type tag (subgoal_search)"); @@ -811,11 +821,11 @@ ans_node_ptr answer_search(sg_fr_ptr sg_fr, CELL *subs_ptr) { int i, j, count_vars, subs_arity; CELL *stack_vars, *stack_terms_base, *stack_terms; ans_node_ptr current_ans_node; -#ifdef TRIE_COMPACT_LISTS - int in_new_list = 0; +#ifdef TRIE_COMPACT_PAIRS + int in_new_pair = 0; #else -#define in_new_list 0 -#endif /* TRIE_COMPACT_LISTS */ +#define in_new_pair 0 +#endif /* TRIE_COMPACT_PAIRS */ count_vars = 0; subs_arity = *subs_ptr; @@ -825,17 +835,18 @@ ans_node_ptr answer_search(sg_fr_ptr sg_fr, CELL *subs_ptr) { for (i = subs_arity; i >= 1; i--) { STACK_CHECK_EXPAND(stack_terms, stack_vars, stack_terms_base); - STACK_PUSH_UP(*(subs_ptr + i), stack_terms); + STACK_PUSH_UP(Deref(*(subs_ptr + i)), stack_terms); #ifdef TABLING_ERRORS if (IsNonVarTerm(*stack_terms)) TABLING_ERROR_MESSAGE("IsNonVarTem(*stack_terms) (answer_search)"); #endif /* TABLING_ERRORS */ do { - Term t = Deref(STACK_POP_DOWN(stack_terms)); + Term t = STACK_POP_DOWN(stack_terms); if (IsVarTerm(t)) { + t = Deref(t); if (IsTableVarTerm(t)) { t = MakeTableVarTerm(VarIndexOfTerm(t)); - current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, t, _trie_retry_val + in_new_list); + current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, t, _trie_retry_val + in_new_pair); } else { if (count_vars == MAX_TABLE_VARS) Yap_Error(INTERNAL_ERROR, TermNil, "MAX_TABLE_VARS exceeded (answer_search)"); @@ -843,54 +854,65 @@ ans_node_ptr answer_search(sg_fr_ptr sg_fr, CELL *subs_ptr) { *((CELL *)t) = GLOBAL_table_var_enumerator(count_vars); t = MakeTableVarTerm(count_vars); count_vars++; - current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, t, _trie_retry_var + in_new_list); + current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, t, _trie_retry_var + in_new_pair); } -#ifdef TRIE_COMPACT_LISTS - in_new_list = 0; -#endif /* TRIE_COMPACT_LISTS */ +#ifdef TRIE_COMPACT_PAIRS + in_new_pair = 0; +#endif /* TRIE_COMPACT_PAIRS */ } else if (IsAtomOrIntTerm(t)) { - current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, t, _trie_retry_atom + in_new_list); -#ifdef TRIE_COMPACT_LISTS - in_new_list = 0; -#endif /* TRIE_COMPACT_LISTS */ + current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, t, _trie_retry_atom + in_new_pair); +#ifdef TRIE_COMPACT_PAIRS + in_new_pair = 0; +#endif /* TRIE_COMPACT_PAIRS */ } else if (IsPairTerm(t)) { -#ifdef TRIE_COMPACT_LISTS +#ifdef TRIE_COMPACT_PAIRS CELL *aux = RepPair(t); if (aux == PairTermMark) { - t = Deref(STACK_POP_DOWN(stack_terms)); + t = STACK_POP_DOWN(stack_terms); if (IsPairTerm(t)) { aux = RepPair(t); - /* STACK_CHECK_EXPAND(stack_terms, stack_vars + 2, stack_terms_base); */ - /* STACK_CHECK_EXPAND is not necessary here because the situation of pushing ** - ** up 3 terms has already initially checked for the PairTermInit term */ - STACK_PUSH_UP(*(aux + 1), stack_terms); - STACK_PUSH_UP(AbsPair(PairTermMark), stack_terms); - STACK_PUSH_UP(*(aux), stack_terms); - in_new_list = 4; + t = Deref(*(aux + 1)); + if (t == TermNil) { + current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, CompactPairEndList, _trie_retry_pair); + } else { + /* STACK_CHECK_EXPAND(stack_terms, stack_vars + 2, stack_terms_base); */ + /* STACK_CHECK_EXPAND is not necessary here because the situation of pushing ** + ** up 3 terms has already initially checked for the CompactPairInit term */ + STACK_PUSH_UP(t, stack_terms); + STACK_PUSH_UP(AbsPair(PairTermMark), stack_terms); + in_new_pair = 4; + } + STACK_PUSH_UP(Deref(*aux), stack_terms); } else { - current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsPair(PairTermLast), _trie_retry_null); + current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, CompactPairEndTerm, _trie_retry_null); STACK_PUSH_UP(t, stack_terms); } } else { - current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsPair(PairTermInit), _trie_retry_list + in_new_list); - STACK_CHECK_EXPAND(stack_terms, stack_vars + 2, stack_terms_base); - STACK_PUSH_UP(*(aux + 1), stack_terms); - STACK_PUSH_UP(AbsPair(PairTermMark), stack_terms); - STACK_PUSH_UP(*(aux), stack_terms); - in_new_list = 0; + current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, CompactPairInit, _trie_retry_null + in_new_pair); + t = Deref(*(aux + 1)); + if (t == TermNil) { + current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, CompactPairEndList, _trie_retry_pair); + in_new_pair = 0; + } else { + STACK_CHECK_EXPAND(stack_terms, stack_vars + 2, stack_terms_base); + STACK_PUSH_UP(t, stack_terms); + STACK_PUSH_UP(AbsPair(PairTermMark), stack_terms); + in_new_pair = 4; + } + STACK_PUSH_UP(Deref(*aux), stack_terms); } #else - current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsPair(NULL), _trie_retry_list); + current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsPair(NULL), _trie_retry_pair); STACK_CHECK_EXPAND(stack_terms, stack_vars + 1, stack_terms_base); - STACK_PUSH_UP(*(RepPair(t) + 1), stack_terms); - STACK_PUSH_UP(*(RepPair(t)), stack_terms); -#endif /* TRIE_COMPACT_LISTS */ + STACK_PUSH_UP(Deref(*(RepPair(t) + 1)), stack_terms); + STACK_PUSH_UP(Deref(*(RepPair(t))), stack_terms); +#endif /* TRIE_COMPACT_PAIRS */ } else if (IsApplTerm(t)) { Functor f = FunctorOfTerm(t); if (f == FunctorDouble) { volatile Float dbl = FloatOfTerm(t); volatile Term *t_dbl = (Term *)((void *) &dbl); - current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_null + in_new_list); + current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_null + in_new_pair); #if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, *(t_dbl + 1), _trie_retry_extension); #endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */ @@ -898,7 +920,7 @@ ans_node_ptr answer_search(sg_fr_ptr sg_fr, CELL *subs_ptr) { current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_float); } else if (f == FunctorLongInt) { Int li = LongIntOfTerm (t); - current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_null + in_new_list); + current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_null + in_new_pair); current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, li, _trie_retry_extension); current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_long); } else if (f == FunctorDBRef) { @@ -906,14 +928,14 @@ ans_node_ptr answer_search(sg_fr_ptr sg_fr, CELL *subs_ptr) { } else if (f == FunctorBigInt) { Yap_Error(INTERNAL_ERROR, TermNil, "unsupported type tag (FunctorBigInt in answer_search)"); } else { - current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_struct + in_new_list); + current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_struct + in_new_pair); STACK_CHECK_EXPAND(stack_terms, stack_vars + ArityOfFunctor(f) - 1, stack_terms_base); for (j = ArityOfFunctor(f); j >= 1; j--) - STACK_PUSH_UP(*(RepAppl(t) + j), stack_terms); + STACK_PUSH_UP(Deref(*(RepAppl(t) + j)), stack_terms); } -#ifdef TRIE_COMPACT_LISTS - in_new_list = 0; -#endif /* TRIE_COMPACT_LISTS */ +#ifdef TRIE_COMPACT_PAIRS + in_new_pair = 0; +#endif /* TRIE_COMPACT_PAIRS */ } else { Yap_Error(INTERNAL_ERROR, TermNil, "unknown type tag (answer_search)"); } @@ -934,9 +956,9 @@ void load_answer_trie(ans_node_ptr ans_node, CELL *subs_ptr) { CELL *stack_vars_base, *stack_vars, *stack_terms_base, *stack_terms; int subs_arity, i, n_vars = -1; Term t; -#ifdef TRIE_COMPACT_LISTS +#ifdef TRIE_COMPACT_PAIRS int stack_terms_pair_offset = 0; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ if ((subs_arity = *subs_ptr) == 0) return; @@ -967,8 +989,8 @@ void load_answer_trie(ans_node_ptr ans_node, CELL *subs_ptr) { STACK_CHECK_EXPAND(stack_terms, stack_vars, stack_terms_base); STACK_PUSH_UP(t, stack_terms); } else if (IsPairTerm(t)) { -#ifdef TRIE_COMPACT_LISTS - if (t == AbsPair(PairTermInit)) { +#ifdef TRIE_COMPACT_PAIRS + if (t == CompactPairInit) { Term *stack_aux = stack_terms_base - stack_terms_pair_offset; Term head, tail = STACK_POP_UP(stack_aux); while (STACK_NOT_EMPTY(stack_aux, stack_terms)) { @@ -978,12 +1000,14 @@ void load_answer_trie(ans_node_ptr ans_node, CELL *subs_ptr) { stack_terms = stack_terms_base - stack_terms_pair_offset; stack_terms_pair_offset = (int) STACK_POP_DOWN(stack_terms); STACK_PUSH_UP(tail, stack_terms); - } else { /* AbsPair(PairTermLast)) */ + } else { /* CompactPairEndList / CompactPairEndTerm */ Term last; - STACK_CHECK_EXPAND(stack_terms, stack_vars, stack_terms_base); + STACK_CHECK_EXPAND(stack_terms, stack_vars + 1, stack_terms_base); last = STACK_POP_DOWN(stack_terms); STACK_PUSH_UP(stack_terms_pair_offset, stack_terms); stack_terms_pair_offset = (int) (stack_terms_base - stack_terms); + if (t == CompactPairEndList) + STACK_PUSH_UP(TermNil, stack_terms); STACK_PUSH_UP(last, stack_terms); } #else @@ -991,7 +1015,7 @@ void load_answer_trie(ans_node_ptr ans_node, CELL *subs_ptr) { Term tail = STACK_POP_DOWN(stack_terms); t = MkPairTerm(head, tail); STACK_PUSH_UP(t, stack_terms); -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ } else if (IsApplTerm(t)) { Functor f = (Functor) RepAppl(t); if (f == FunctorDouble) { @@ -1085,17 +1109,17 @@ void free_subgoal_trie_branch(sg_node_ptr node, int nodes_left, int nodes_extra) free_subgoal_trie_branch(TrNode_next(node), nodes_left, nodes_extra); if (nodes_extra) { -#ifdef TRIE_COMPACT_LISTS +#ifdef TRIE_COMPACT_PAIRS if (nodes_extra < 0) { Term t = TrNode_entry(node); if (IsPairTerm(t)) { - if (t == AbsPair(PairTermInit)) + if (t == CompactPairInit) nodes_extra--; - else /* AbsPair(PairTermLast) */ + else /* CompactPairEndList / CompactPairEndTerm */ nodes_extra++; } } else -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ if (--nodes_extra == 0) nodes_left--; } else { @@ -1103,12 +1127,12 @@ void free_subgoal_trie_branch(sg_node_ptr node, int nodes_left, int nodes_extra) if (IsVarTerm(t) || IsAtomOrIntTerm(t)) nodes_left--; else if (IsPairTerm(t)) -#ifdef TRIE_COMPACT_LISTS - /* AbsPair(PairTermInit) */ +#ifdef TRIE_COMPACT_PAIRS + /* CompactPairInit */ nodes_extra = -1; #else nodes_left++; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ else if (IsApplTerm(t)) { Functor f = (Functor) RepAppl(t); if (f == FunctorDouble) @@ -1409,12 +1433,13 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a sg_node = *bucket; traverse_subgoal_trie(sg_node, str, str_index, arity, depth, mode); memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1)); +#ifdef TRIE_COMPACT_PAIRS + if (arity[arity[0]] == -2 && str[str_index - 1] != '[') + str[str_index - 1] = ','; +#else if (arity[arity[0]] == -1) str[str_index - 1] = '|'; -#ifdef TRIE_COMPACT_LISTS - else if (arity[arity[0]] == -2 && str[str_index - 1] != '[') - str[str_index - 1] = ','; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ } } while (++bucket != last_bucket); free(current_arity); @@ -1428,12 +1453,13 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a traverse_subgoal_trie(TrNode_next(sg_node), str, str_index, arity, depth, mode); memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1)); free(current_arity); +#ifdef TRIE_COMPACT_PAIRS + if (arity[arity[0]] == -2 && str[str_index - 1] != '[') + str[str_index - 1] = ','; +#else if (arity[arity[0]] == -1) str[str_index - 1] = '|'; -#ifdef TRIE_COMPACT_LISTS - else if (arity[arity[0]] == -2 && str[str_index - 1] != '[') - str[str_index - 1] = ','; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ } /* test the node type */ @@ -1468,12 +1494,12 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a } } else { if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_LISTS +#ifdef TRIE_COMPACT_PAIRS str_index += sprintf(& str[str_index], ","); #else str_index += sprintf(& str[str_index], "|"); arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ break; } else { str_index += sprintf(& str[str_index], "]"); @@ -1501,12 +1527,12 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a } } else { if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_LISTS +#ifdef TRIE_COMPACT_PAIRS str_index += sprintf(& str[str_index], ","); #else str_index += sprintf(& str[str_index], "|"); arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ break; } else { str_index += sprintf(& str[str_index], "]"); @@ -1533,12 +1559,12 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a } } else { if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_LISTS +#ifdef TRIE_COMPACT_PAIRS str_index += sprintf(& str[str_index], ","); #else str_index += sprintf(& str[str_index], "|"); arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ break; } else { str_index += sprintf(& str[str_index], "]"); @@ -1564,12 +1590,12 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a } } else { if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_LISTS +#ifdef TRIE_COMPACT_PAIRS str_index += sprintf(& str[str_index], ","); #else str_index += sprintf(& str[str_index], "|"); arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ break; } else { str_index += sprintf(& str[str_index], "]"); @@ -1578,10 +1604,12 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a } } } else if (IsAtomTerm(t)) { - if (arity[arity[0]] == -1 && !strcmp("[]", AtomName(AtomOfTerm(t)))) { +#ifndef TRIE_COMPACT_PAIRS + if (arity[arity[0]] == -1 && t == TermNil) { str[str_index - 1] = ']'; arity[0]--; } else +#endif /* TRIE_COMPACT_PAIRS */ str_index += sprintf(& str[str_index], "%s", AtomName(AtomOfTerm(t))); while (arity[0]) { if (arity[arity[0]] > 0) { @@ -1595,12 +1623,12 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a } } else { if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_LISTS +#ifdef TRIE_COMPACT_PAIRS str_index += sprintf(& str[str_index], ","); #else str_index += sprintf(& str[str_index], "|"); arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ break; } else { str_index += sprintf(& str[str_index], "]"); @@ -1609,15 +1637,17 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a } } } else if (IsPairTerm(t)) { -#ifdef TRIE_COMPACT_LISTS - if (t == AbsPair(PairTermLast)) { +#ifdef TRIE_COMPACT_PAIRS + if (t == CompactPairEndList) + arity[arity[0]] = -1; + else if (t == CompactPairEndTerm) { str[str_index - 1] = '|'; arity[arity[0]] = -1; #else if (arity[arity[0]] == -1) { str[str_index - 1] = ','; arity[arity[0]] = -2; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ } else { str_index += sprintf(& str[str_index], "["); arity[0]++; @@ -1706,12 +1736,13 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int * ans_node = *bucket; traverse_answer_trie(ans_node, str, str_index, arity, var_index, depth, mode); memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1)); +#ifdef TRIE_COMPACT_PAIRS + if (arity[arity[0]] == -2 && str[str_index - 1] != '[') + str[str_index - 1] = ','; +#else if (arity[arity[0]] == -1) str[str_index - 1] = '|'; -#ifdef TRIE_COMPACT_LISTS - else if (arity[arity[0]] == -2 && str[str_index - 1] != '[') - str[str_index - 1] = ','; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ } } while (++bucket != last_bucket); free(current_arity); @@ -1725,12 +1756,13 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int * traverse_answer_trie(TrNode_next(ans_node), str, str_index, arity, var_index, depth, mode); memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1)); free(current_arity); +#ifdef TRIE_COMPACT_PAIRS + if (arity[arity[0]] == -2 && str[str_index - 1] != '[') + str[str_index - 1] = ','; +#else if (arity[arity[0]] == -1) str[str_index - 1] = '|'; -#ifdef TRIE_COMPACT_LISTS - else if (arity[arity[0]] == -2 && str[str_index - 1] != '[') - str[str_index - 1] = ','; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ } /* print VAR when starting a term */ @@ -1770,12 +1802,12 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int * } } else { if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_LISTS +#ifdef TRIE_COMPACT_PAIRS str_index += sprintf(& str[str_index], ","); #else str_index += sprintf(& str[str_index], "|"); arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ break; } else { str_index += sprintf(& str[str_index], "]"); @@ -1805,12 +1837,12 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int * } } else { if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_LISTS +#ifdef TRIE_COMPACT_PAIRS str_index += sprintf(& str[str_index], ","); #else str_index += sprintf(& str[str_index], "|"); arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ break; } else { str_index += sprintf(& str[str_index], "]"); @@ -1839,12 +1871,12 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int * } } else { if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_LISTS +#ifdef TRIE_COMPACT_PAIRS str_index += sprintf(& str[str_index], ","); #else str_index += sprintf(& str[str_index], "|"); arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ break; } else { str_index += sprintf(& str[str_index], "]"); @@ -1870,12 +1902,12 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int * } } else { if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_LISTS +#ifdef TRIE_COMPACT_PAIRS str_index += sprintf(& str[str_index], ","); #else str_index += sprintf(& str[str_index], "|"); arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ break; } else { str_index += sprintf(& str[str_index], "]"); @@ -1884,10 +1916,12 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int * } } } else if (IsAtomTerm(t)) { - if (arity[arity[0]] == -1 && !strcmp("[]", AtomName(AtomOfTerm(t)))) { +#ifndef TRIE_COMPACT_PAIRS + if (arity[arity[0]] == -1 && t == TermNil) { str[str_index - 1] = ']'; arity[0]--; } else +#endif /* TRIE_COMPACT_PAIRS */ str_index += sprintf(& str[str_index], "%s", AtomName(AtomOfTerm(t))); while (arity[0]) { if (arity[arity[0]] > 0) { @@ -1901,12 +1935,12 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int * } } else { if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_LISTS +#ifdef TRIE_COMPACT_PAIRS str_index += sprintf(& str[str_index], ","); #else str_index += sprintf(& str[str_index], "|"); arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ break; } else { str_index += sprintf(& str[str_index], "]"); @@ -1915,15 +1949,17 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int * } } } else if (IsPairTerm(t)) { -#ifdef TRIE_COMPACT_LISTS - if (t == AbsPair(PairTermLast)) { +#ifdef TRIE_COMPACT_PAIRS + if (t == CompactPairEndList) + arity[arity[0]] = -1; + else if (t == CompactPairEndTerm) { str[str_index - 1] = '|'; arity[arity[0]] = -1; #else if (arity[arity[0]] == -1) { str[str_index - 1] = ','; arity[arity[0]] = -2; -#endif /* TRIE_COMPACT_LISTS */ +#endif /* TRIE_COMPACT_PAIRS */ } else { str_index += sprintf(& str[str_index], "["); arity[0]++; diff --git a/OPTYap/tab.tries.insts.i b/OPTYap/tab.tries.insts.i index 030f4db91..d2f5d33c4 100644 --- a/OPTYap/tab.tries.insts.i +++ b/OPTYap/tab.tries.insts.i @@ -136,31 +136,37 @@ ** trie_null ** ** ------------------- */ -#define stack_trie_null_instr() \ +#define stack_trie_null_instr() \ next_trie_instruction(node) -#define stack_trie_null_in_new_list_instr() \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ - H += 2; \ - *aux_ptr-- = (CELL) (H - 1); \ - *aux_ptr-- = (CELL) (H - 2); \ - *aux_ptr = heap_arity - 1 + 2; \ - YENV = aux_ptr; \ +#ifdef TRIE_COMPACT_PAIRS +/* trie compiled code for term 'CompactPairInit' */ +#define stack_trie_null_in_new_pair_instr() \ + if (heap_arity) { \ + aux_ptr++; \ + Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ + *aux_ptr-- = (CELL) (H + 1); \ + *aux_ptr-- = (CELL) H; \ + *aux_ptr = heap_arity - 1 + 2; \ + YENV = aux_ptr; \ + } else { \ + int i; \ + *aux_ptr-- = (CELL) (H + 1); \ + *aux_ptr-- = (CELL) H; \ + *aux_ptr = 2; \ + YENV = aux_ptr; \ + aux_ptr += 2 + 2; \ + *aux_ptr = subs_arity - 1; \ + aux_ptr += subs_arity; \ + Bind((CELL *) *aux_ptr, AbsPair(H)); \ + for (i = 0; i < vars_arity; i++) { \ + *aux_ptr = *(aux_ptr + 1); \ + aux_ptr++; \ + } \ + } \ + H += 2; \ next_trie_instruction(node) -/* -#define stack_trie_null_in_new_list_instr() \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ - H += 2; \ - *aux_ptr-- = (CELL) (H - 1); \ - *aux_ptr-- = (CELL) (H - 2); \ - heap_arity = heap_arity - 1 + 2; \ - *aux_ptr = heap_arity; \ - YENV = aux_ptr; \ - \ - next_trie_instruction(node) -*/ +#endif /* TRIE_COMPACT_PAIRS */ @@ -170,9 +176,11 @@ #define stack_trie_var_instr() \ if (heap_arity) { \ + CELL var; \ + int i; \ *aux_ptr = heap_arity - 1; \ - var_ptr = *++aux_ptr; \ - RESET_VARIABLE(var_ptr); \ + var = *++aux_ptr; \ + RESET_VARIABLE(var); \ for (i = 0; i < heap_arity - 1; i++) { \ *aux_ptr = *(aux_ptr + 1); \ aux_ptr++; \ @@ -183,7 +191,7 @@ *aux_ptr = *(aux_ptr + 1); \ aux_ptr++; \ } \ - *aux_ptr = var_ptr; \ + *aux_ptr = var; \ next_instruction(heap_arity - 1 || subs_arity, node); \ } else { \ *++aux_ptr = vars_arity + 1; \ @@ -191,53 +199,41 @@ next_instruction(subs_arity - 1, node); \ } -#define stack_trie_var_in_new_list_instr() \ +#ifdef TRIE_COMPACT_PAIRS +#define stack_trie_var_in_new_pair_instr() \ + if (heap_arity) { \ + int i; \ + *aux_ptr-- = (CELL) (H + 1); \ + *aux_ptr = heap_arity - 1 + 1; \ + YENV = aux_ptr; \ + aux_ptr += 2; \ + Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ + for (i = 0; i < heap_arity - 1; i++) { \ + *aux_ptr = *(aux_ptr + 1); \ + aux_ptr++; \ + } \ + *aux_ptr++ = vars_arity + 1; \ + *aux_ptr++ = subs_arity; \ + for (i = 0; i < subs_arity; i++) { \ + *aux_ptr = *(aux_ptr + 1); \ + aux_ptr++; \ + } \ + *aux_ptr = (CELL) H; \ + } else { \ + *aux_ptr-- = (CELL) (H + 1); \ + *aux_ptr = 1; \ + YENV = aux_ptr; \ + aux_ptr += 2; \ + *aux_ptr++ = vars_arity + 1; \ + *aux_ptr = subs_arity - 1; \ + aux_ptr += subs_arity; \ + Bind((CELL *) *aux_ptr, AbsPair(H)); \ + *aux_ptr = (CELL) H; \ + } \ RESET_VARIABLE((CELL) H); \ - *aux_ptr-- = (CELL) (H + 1); \ - *aux_ptr = heap_arity; \ - YENV = aux_ptr; \ - aux_ptr += 2; \ - Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ - for (i = 0; i < heap_arity - 1; i++) { \ - *aux_ptr = *(aux_ptr + 1); \ - aux_ptr++; \ - } \ - *aux_ptr++ = vars_arity + 1; \ - *aux_ptr++ = subs_arity; \ - for (i = 0; i < subs_arity; i++) { \ - *aux_ptr = *(aux_ptr + 1); \ - aux_ptr++; \ - } \ - *aux_ptr = (CELL) H; \ H += 2; \ next_trie_instruction(node) -/* -#define stack_trie_var_in_new_list_instr() \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ - H += 2; \ - *aux_ptr-- = (CELL) (H - 1); \ - *aux_ptr-- = (CELL) (H - 2); \ - heap_arity = heap_arity - 1 + 2; \ - *aux_ptr = heap_arity; \ - YENV = aux_ptr; \ - \ - *aux_ptr = heap_arity - 1; \ - var_ptr = *++aux_ptr; \ - RESET_VARIABLE(var_ptr); \ - for (i = 0; i < heap_arity - 1; i++) { \ - *aux_ptr = *(aux_ptr + 1); \ - aux_ptr++; \ - } \ - *aux_ptr++ = vars_arity + 1; \ - *aux_ptr++ = subs_arity; \ - for (i = 0; i < subs_arity; i++) { \ - *aux_ptr = *(aux_ptr + 1); \ - aux_ptr++; \ - } \ - *aux_ptr = var_ptr; \ - next_instruction(heap_arity - 1 || subs_arity, node) -*/ +#endif /* TRIE_COMPACT_PAIRS */ @@ -247,6 +243,7 @@ #define stack_trie_val_instr() \ if (heap_arity) { \ + CELL aux, subs, *subs_ptr; \ YENV = ++aux_ptr; \ subs_ptr = aux_ptr + heap_arity + 1 + subs_arity + vars_arity - var_index; \ aux = *aux_ptr; \ @@ -261,6 +258,8 @@ *aux_ptr = heap_arity - 1; \ next_instruction(heap_arity - 1 || subs_arity, node); \ } else { \ + CELL aux, subs, *subs_ptr; \ + int i; \ aux_ptr += 2; \ *aux_ptr = subs_arity - 1; \ aux_ptr += subs_arity; \ @@ -294,47 +293,51 @@ next_instruction(subs_arity - 1, node); \ } -#define stack_trie_val_in_new_list_instr() \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ - H += 2; \ - *aux_ptr = (CELL) (H - 1); \ - aux = (CELL) (H - 2); \ - subs_ptr = aux_ptr + heap_arity + 1 + subs_arity + vars_arity - var_index; \ - subs = *subs_ptr; \ - if (aux > subs) { \ - Bind_Global((CELL *) aux, subs); \ +#ifdef TRIE_COMPACT_PAIRS +#define stack_trie_val_in_new_pair_instr() \ + if (heap_arity) { \ + CELL aux, subs, *subs_ptr; \ + aux_ptr++; \ + Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ + *aux_ptr = (CELL) (H + 1); \ + aux = (CELL) H; \ + subs_ptr = aux_ptr + heap_arity + 1 + subs_arity + vars_arity - var_index; \ + subs = *subs_ptr; \ + if (aux > subs) { \ + Bind_Global((CELL *) aux, subs); \ + } else { \ + RESET_VARIABLE(aux); \ + Bind_Local((CELL *) subs, aux); \ + *subs_ptr = aux; \ + } \ } else { \ - RESET_VARIABLE(aux); \ - Bind_Local((CELL *) subs, aux); \ - *subs_ptr = aux; \ + CELL aux, subs, *subs_ptr; \ + int i; \ + *aux_ptr-- = (CELL) (H + 1); \ + *aux_ptr = 1; \ + YENV = aux_ptr; \ + aux_ptr += 1 + 2; \ + aux = (CELL) H; \ + subs_ptr = aux_ptr + subs_arity + vars_arity - var_index; \ + subs = *subs_ptr; \ + if (aux > subs) { \ + Bind_Global((CELL *) aux, subs); \ + } else { \ + RESET_VARIABLE(aux); \ + Bind_Local((CELL *) subs, aux); \ + *subs_ptr = aux; \ + } \ + *aux_ptr = subs_arity - 1; \ + aux_ptr += subs_arity; \ + Bind((CELL *) *aux_ptr, AbsPair(H)); \ + for (i = 0; i < vars_arity; i++) { \ + *aux_ptr = *(aux_ptr + 1); \ + aux_ptr++; \ + } \ } \ + H += 2; \ next_trie_instruction(node) -/* -#define stack_trie_val_in_new_list_instr() \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ - H += 2; \ - *aux_ptr-- = (CELL) (H - 1); \ - *aux_ptr-- = (CELL) (H - 2); \ - heap_arity = heap_arity - 1 + 2; \ - *aux_ptr = heap_arity; \ - YENV = aux_ptr; \ - \ - YENV = ++aux_ptr; \ - subs_ptr = aux_ptr + heap_arity + 1 + subs_arity + vars_arity - var_index; \ - aux = *aux_ptr; \ - subs = *subs_ptr; \ - if (aux > subs) { \ - Bind_Global((CELL *) aux, subs); \ - } else { \ - RESET_VARIABLE(aux); \ - Bind_Local((CELL *) subs, aux); \ - *subs_ptr = aux; \ - } \ - *aux_ptr = heap_arity - 1; \ - next_instruction(heap_arity - 1 || subs_arity, node) -*/ +#endif /* TRIE_COMPACT_PAIRS */ @@ -342,112 +345,107 @@ ** trie_atom ** ** ------------------- */ -#define stack_trie_atom_instr() \ - if (heap_arity) { \ - YENV = ++aux_ptr; \ - Bind_Global((CELL *) *aux_ptr, TrNode_entry(node)); \ - *aux_ptr = heap_arity - 1; \ - next_instruction(heap_arity - 1 || subs_arity, node); \ - } else { \ - aux_ptr += 2; \ - *aux_ptr = subs_arity - 1; \ - aux_ptr += subs_arity; \ - Bind((CELL *) *aux_ptr, TrNode_entry(node)); \ - for (i = 0; i < vars_arity; i++) { \ - *aux_ptr = *(aux_ptr + 1); \ - aux_ptr++; \ - } \ - next_instruction(subs_arity - 1, node); \ +#define stack_trie_atom_instr() \ + if (heap_arity) { \ + YENV = ++aux_ptr; \ + Bind_Global((CELL *) *aux_ptr, TrNode_entry(node)); \ + *aux_ptr = heap_arity - 1; \ + next_instruction(heap_arity - 1 || subs_arity, node); \ + } else { \ + int i; \ + aux_ptr += 2; \ + *aux_ptr = subs_arity - 1; \ + aux_ptr += subs_arity; \ + Bind((CELL *) *aux_ptr, TrNode_entry(node)); \ + for (i = 0; i < vars_arity; i++) { \ + *aux_ptr = *(aux_ptr + 1); \ + aux_ptr++; \ + } \ + next_instruction(subs_arity - 1, node); \ } -#define stack_trie_atom_in_new_list_instr() \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ - H += 2; \ - *aux_ptr = (CELL) (H - 1); \ - Bind_Global((H - 2), TrNode_entry(node)); \ +#ifdef TRIE_COMPACT_PAIRS +#define stack_trie_atom_in_new_pair_instr() \ + if (heap_arity) { \ + aux_ptr++; \ + Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ + *aux_ptr = (CELL) (H + 1); \ + } else { \ + int i; \ + *aux_ptr-- = (CELL) (H + 1); \ + *aux_ptr = 1; \ + YENV = aux_ptr; \ + aux_ptr += 1 + 2; \ + *aux_ptr = subs_arity - 1; \ + aux_ptr += subs_arity; \ + Bind((CELL *) *aux_ptr, AbsPair(H)); \ + for (i = 0; i < vars_arity; i++) { \ + *aux_ptr = *(aux_ptr + 1); \ + aux_ptr++; \ + } \ + } \ + Bind_Global(H, TrNode_entry(node)); \ + H += 2; \ next_trie_instruction(node) -/* -#define stack_trie_atom_in_new_list_instr() \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ - H += 2; \ - *aux_ptr-- = (CELL) (H - 1); \ - *aux_ptr-- = (CELL) (H - 2); \ - heap_arity = heap_arity - 1 + 2; \ - *aux_ptr = heap_arity; \ - YENV = aux_ptr; \ - \ - YENV = ++aux_ptr; \ - Bind_Global((CELL *) *aux_ptr, TrNode_entry(node)); \ - *aux_ptr = heap_arity - 1; \ - next_instruction(heap_arity - 1 || subs_arity, node) -*/ +#endif /* TRIE_COMPACT_PAIRS */ /* ------------------- ** -** trie_list ** +** trie_pair ** ** ------------------- */ -#define stack_trie_list_instr() \ - if (heap_arity) { \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ - H += 2; \ - *aux_ptr-- = (CELL) (H - 1); \ - *aux_ptr-- = (CELL) (H - 2); \ - *aux_ptr = heap_arity - 1 + 2; \ - YENV = aux_ptr; \ - } else { \ - H += 2; \ - *aux_ptr-- = (CELL) (H - 1); \ - *aux_ptr-- = (CELL) (H - 2); \ - *aux_ptr = 2; \ - YENV = aux_ptr; \ - aux_ptr += 2 + 2; \ - *aux_ptr = subs_arity - 1; \ - aux_ptr += subs_arity; \ - Bind((CELL *) *aux_ptr, AbsPair(H - 2)); \ - for (i = 0; i < vars_arity; i++) { \ - *aux_ptr = *(aux_ptr + 1); \ - aux_ptr++; \ - } \ - } \ +#ifdef TRIE_COMPACT_PAIRS +/* trie compiled code for term 'CompactPairEndList' */ +#define stack_trie_pair_instr() \ + if (heap_arity) { \ + aux_ptr++; \ + Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ + *aux_ptr = (CELL) H; \ + } else { \ + int i; \ + *aux_ptr-- = (CELL) H; \ + *aux_ptr = 1; \ + YENV = aux_ptr; \ + aux_ptr += 1 + 2; \ + *aux_ptr = subs_arity - 1; \ + aux_ptr += subs_arity; \ + Bind((CELL *) *aux_ptr, AbsPair(H)); \ + for (i = 0; i < vars_arity; i++) { \ + *aux_ptr = *(aux_ptr + 1); \ + aux_ptr++; \ + } \ + } \ + Bind_Global(H + 1, TermNil); \ + H += 2; \ next_trie_instruction(node) - -#define stack_trie_list_in_new_list_instr() \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ - H += 2; \ - *aux_ptr-- = (CELL) (H - 1); \ - Bind_Global((H - 2), AbsPair(H)); \ - H += 2; \ - *aux_ptr-- = (CELL) (H - 1); \ - *aux_ptr-- = (CELL) (H - 2); \ - *aux_ptr = heap_arity - 1 + 1 + 2; \ - YENV = aux_ptr; \ +#else +#define stack_trie_pair_instr() \ + if (heap_arity) { \ + aux_ptr++; \ + Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ + *aux_ptr-- = (CELL) (H + 1); \ + *aux_ptr-- = (CELL) H; \ + *aux_ptr = heap_arity - 1 + 2; \ + YENV = aux_ptr; \ + } else { \ + int i; \ + *aux_ptr-- = (CELL) (H + 1); \ + *aux_ptr-- = (CELL) H; \ + *aux_ptr = 2; \ + YENV = aux_ptr; \ + aux_ptr += 2 + 2; \ + *aux_ptr = subs_arity - 1; \ + aux_ptr += subs_arity; \ + Bind((CELL *) *aux_ptr, AbsPair(H)); \ + for (i = 0; i < vars_arity; i++) { \ + *aux_ptr = *(aux_ptr + 1); \ + aux_ptr++; \ + } \ + } \ + H += 2; \ next_trie_instruction(node) -/* -#define stack_trie_list_in_new_list_instr() \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ - H += 2; \ - *aux_ptr-- = (CELL) (H - 1); \ - *aux_ptr-- = (CELL) (H - 2); \ - heap_arity = heap_arity - 1 + 2; \ - *aux_ptr = heap_arity; \ - YENV = aux_ptr; \ - \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ - H += 2; \ - *aux_ptr-- = (CELL) (H - 1); \ - *aux_ptr-- = (CELL) (H - 2); \ - *aux_ptr = heap_arity - 1 + 2; \ - YENV = aux_ptr; \ - next_trie_instruction(node) -*/ +#endif /* TRIE_COMPACT_PAIRS */ @@ -455,68 +453,67 @@ ** trie_struct ** ** --------------------- */ -#define stack_trie_struct_instr() \ - if (heap_arity) { \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsAppl(H)); \ - *H++ = (CELL) func; \ - H += func_arity; \ - for (i = 1; i <= func_arity; i++) \ - *aux_ptr-- = (CELL) (H - i); \ - *aux_ptr = heap_arity - 1 + func_arity; \ - YENV = aux_ptr; \ - } else { \ - *H++ = (CELL) func; \ - H += func_arity; \ - for (i = 1; i <= func_arity; i++) \ - *aux_ptr-- = (CELL) (H - i); \ - *aux_ptr = func_arity; \ - YENV = aux_ptr; \ - aux_ptr += func_arity + 2; \ - *aux_ptr = subs_arity - 1; \ - aux_ptr += subs_arity; \ - Bind((CELL *) *aux_ptr, AbsAppl(H - func_arity - 1)); \ - for (i = 0; i < vars_arity; i++) { \ - *aux_ptr = *(aux_ptr + 1); \ - aux_ptr++; \ - } \ - } \ +#define stack_trie_struct_instr() \ + if (heap_arity) { \ + int i; \ + aux_ptr++; \ + Bind_Global((CELL *) *aux_ptr, AbsAppl(H)); \ + for (i = 0; i < func_arity; i++) \ + *aux_ptr-- = (CELL) (H + func_arity - i); \ + *aux_ptr = heap_arity - 1 + func_arity; \ + YENV = aux_ptr; \ + } else { \ + int i; \ + for (i = 0; i < func_arity; i++) \ + *aux_ptr-- = (CELL) (H + func_arity - i); \ + *aux_ptr = func_arity; \ + YENV = aux_ptr; \ + aux_ptr += func_arity + 2; \ + *aux_ptr = subs_arity - 1; \ + aux_ptr += subs_arity; \ + Bind((CELL *) *aux_ptr, AbsAppl(H)); \ + for (i = 0; i < vars_arity; i++) { \ + *aux_ptr = *(aux_ptr + 1); \ + aux_ptr++; \ + } \ + } \ + *H = (CELL) func; \ + H += 1 + func_arity; \ next_trie_instruction(node) -#define stack_trie_struct_in_new_list_instr() \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ - H += 2; \ - *aux_ptr-- = (CELL) (H - 1); \ - Bind_Global((H - 2), AbsAppl(H)); \ - *H++ = (CELL) func; \ - H += func_arity; \ - for (i = 1; i <= func_arity; i++) \ - *aux_ptr-- = (CELL) (H - i); \ - *aux_ptr = heap_arity - 1 + 1 + func_arity; \ - YENV = aux_ptr; \ +#ifdef TRIE_COMPACT_PAIRS +#define stack_trie_struct_in_new_pair_instr() \ + if (heap_arity) { \ + int i; \ + aux_ptr++; \ + Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ + *aux_ptr-- = (CELL) (H + 1); \ + for (i = 0; i < func_arity; i++) \ + *aux_ptr-- = (CELL) (H + 2 + func_arity - i); \ + *aux_ptr = heap_arity - 1 + 1 + func_arity; \ + YENV = aux_ptr; \ + } else { \ + int i; \ + *aux_ptr-- = (CELL) (H + 1); \ + for (i = 0; i < func_arity; i++) \ + *aux_ptr-- = (CELL) (H + 2 + func_arity - i); \ + *aux_ptr = 1 + func_arity; \ + YENV = aux_ptr; \ + aux_ptr += 1 + func_arity + 2; \ + *aux_ptr = subs_arity - 1; \ + aux_ptr += subs_arity; \ + Bind((CELL *) *aux_ptr, AbsPair(H)); \ + for (i = 0; i < vars_arity; i++) { \ + *aux_ptr = *(aux_ptr + 1); \ + aux_ptr++; \ + } \ + } \ + Bind_Global(H, AbsAppl(H + 2)); \ + H += 2; \ + *H = (CELL) func; \ + H += 1 + func_arity; \ next_trie_instruction(node) -/* -#define stack_trie_struct_in_new_list_instr() \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsPair(H)); \ - H += 2; \ - *aux_ptr-- = (CELL) (H - 1); \ - *aux_ptr-- = (CELL) (H - 2); \ - heap_arity = heap_arity - 1 + 2; \ - *aux_ptr = heap_arity; \ - YENV = aux_ptr; \ - \ - aux_ptr++; \ - Bind_Global((CELL *) *aux_ptr, AbsAppl(H)); \ - *H++ = (CELL) func; \ - H += func_arity; \ - for (i = 1; i <= func_arity; i++) \ - *aux_ptr-- = (CELL) (H - i); \ - *aux_ptr = heap_arity - 1 + func_arity; \ - YENV = aux_ptr; \ - next_trie_instruction(node) -*/ +#endif /* TRIE_COMPACT_PAIRS */ @@ -524,10 +521,10 @@ ** trie_extension ** ** ------------------------ */ -#define stack_trie_extension_instr() \ - *aux_ptr = TrNode_entry(node); \ - *--aux_ptr = heap_arity + 1; \ - YENV = aux_ptr; \ +#define stack_trie_extension_instr() \ + *aux_ptr-- = TrNode_entry(node); \ + *aux_ptr = heap_arity + 1; \ + YENV = aux_ptr; \ next_trie_instruction(node) @@ -543,6 +540,7 @@ *aux_ptr = heap_arity - 1; \ next_instruction(heap_arity - 1 || subs_arity, node); \ } else { \ + int i; \ YENV = aux_ptr; \ *aux_ptr = 0; \ aux_ptr += 2; \ @@ -605,21 +603,23 @@ ENDPBOp(); - PBOp(trie_do_null_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_do_null_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = YENV; int heap_arity = *aux_ptr; + int vars_arity = *(aux_ptr + heap_arity + 1); + int subs_arity = *(aux_ptr + heap_arity + 2); - stack_trie_null_in_new_list_instr(); + stack_trie_null_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_do_null_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_do_null_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_trust_null_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_trust_null_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = (CELL *) (B + 1); int heap_arity = *aux_ptr; @@ -627,15 +627,15 @@ int subs_arity = *(aux_ptr + heap_arity + 2); pop_trie_node(); - stack_trie_null_in_new_list_instr(); + stack_trie_null_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_trust_null_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_trust_null_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_try_null_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_try_null_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = YENV; int heap_arity = *aux_ptr; @@ -643,15 +643,15 @@ int subs_arity = *(aux_ptr + heap_arity + 2); store_trie_node(TrNode_next(node)); - stack_trie_null_in_new_list_instr(); + stack_trie_null_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_try_null_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_try_null_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_retry_null_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_retry_null_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = (CELL *) (B + 1); int heap_arity = *aux_ptr; @@ -659,21 +659,19 @@ int subs_arity = *(aux_ptr + heap_arity + 2); restore_trie_node(TrNode_next(node)); - stack_trie_null_in_new_list_instr(); + stack_trie_null_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_retry_null_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_retry_null_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); PBOp(trie_do_var, e) register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = YENV; - register CELL var_ptr; int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; stack_trie_var_instr(); ENDPBOp(); @@ -682,11 +680,9 @@ PBOp(trie_trust_var, e) register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = (CELL *) (B + 1); - register CELL var_ptr; int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; pop_trie_node(); stack_trie_var_instr(); @@ -696,11 +692,9 @@ PBOp(trie_try_var, e) register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = YENV; - register CELL var_ptr; int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; store_trie_node(TrNode_next(node)); stack_trie_var_instr(); @@ -710,93 +704,85 @@ PBOp(trie_retry_var, e) register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = (CELL *) (B + 1); - register CELL var_ptr; int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; restore_trie_node(TrNode_next(node)); stack_trie_var_instr(); ENDPBOp(); - PBOp(trie_do_var_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_do_var_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = YENV; int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; - stack_trie_var_in_new_list_instr(); + stack_trie_var_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_do_var_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_do_var_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_trust_var_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_trust_var_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = (CELL *) (B + 1); int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; pop_trie_node(); - stack_trie_var_in_new_list_instr(); + stack_trie_var_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_trust_var_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_trust_var_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_try_var_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_try_var_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = YENV; int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; store_trie_node(TrNode_next(node)); - stack_trie_var_in_new_list_instr(); + stack_trie_var_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_try_var_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_try_var_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_retry_var_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_retry_var_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = (CELL *) (B + 1); int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; restore_trie_node(TrNode_next(node)); - stack_trie_var_in_new_list_instr(); + stack_trie_var_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_try_var_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_retry_var_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); PBOp(trie_do_val, e) register ans_node_ptr node = (ans_node_ptr) PREG; - register CELL *aux_ptr = YENV, *subs_ptr; - register CELL aux, subs; + register CELL *aux_ptr = YENV; int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); int var_index = VarIndexOfTableTerm(TrNode_entry(node)); - int i; stack_trie_val_instr(); ENDPBOp(); @@ -804,13 +790,11 @@ PBOp(trie_trust_val, e) register ans_node_ptr node = (ans_node_ptr) PREG; - register CELL *aux_ptr = (CELL *) (B + 1), *subs_ptr; - register CELL aux, subs; + register CELL *aux_ptr = (CELL *) (B + 1); int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); int var_index = VarIndexOfTableTerm(TrNode_entry(node)); - int i; pop_trie_node(); stack_trie_val_instr(); @@ -819,13 +803,11 @@ PBOp(trie_try_val, e) register ans_node_ptr node = (ans_node_ptr) PREG; - register CELL *aux_ptr = YENV, *subs_ptr; - register CELL aux, subs; + register CELL *aux_ptr = YENV; int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); int var_index = VarIndexOfTableTerm(TrNode_entry(node)); - int i; store_trie_node(TrNode_next(node)); stack_trie_val_instr(); @@ -834,87 +816,81 @@ PBOp(trie_retry_val, e) register ans_node_ptr node = (ans_node_ptr) PREG; - register CELL *aux_ptr = (CELL *) (B + 1), *subs_ptr; - register CELL aux, subs; + register CELL *aux_ptr = (CELL *) (B + 1); int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); int var_index = VarIndexOfTableTerm(TrNode_entry(node)); - int i; restore_trie_node(TrNode_next(node)); stack_trie_val_instr(); ENDPBOp(); - PBOp(trie_do_val_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_do_val_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; - register CELL *aux_ptr = YENV, *subs_ptr; - register CELL aux, subs; + register CELL *aux_ptr = YENV; int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); int var_index = VarIndexOfTableTerm(TrNode_entry(node)); - stack_trie_val_in_new_list_instr(); + stack_trie_val_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_do_val_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_do_val_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_trust_val_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_trust_val_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; - register CELL *aux_ptr = (CELL *) (B + 1), *subs_ptr; - register CELL aux, subs; + register CELL *aux_ptr = (CELL *) (B + 1); int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); int var_index = VarIndexOfTableTerm(TrNode_entry(node)); pop_trie_node(); - stack_trie_val_in_new_list_instr(); + stack_trie_val_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_trust_val_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_trust_val_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_try_val_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_try_val_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; - register CELL *aux_ptr = YENV, *subs_ptr; - register CELL aux, subs; + register CELL *aux_ptr = YENV; int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); int var_index = VarIndexOfTableTerm(TrNode_entry(node)); store_trie_node(TrNode_next(node)); - stack_trie_val_in_new_list_instr(); + stack_trie_val_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_try_val_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_try_val_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_retry_val_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_retry_val_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; - register CELL *aux_ptr = (CELL *) (B + 1), *subs_ptr; - register CELL aux, subs; + register CELL *aux_ptr = (CELL *) (B + 1); int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); int var_index = VarIndexOfTableTerm(TrNode_entry(node)); restore_trie_node(TrNode_next(node)); - stack_trie_val_in_new_list_instr(); + stack_trie_val_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_retry_val_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_retry_val_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); @@ -924,7 +900,6 @@ int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; stack_trie_atom_instr(); ENDPBOp(); @@ -936,7 +911,6 @@ int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; pop_trie_node(); stack_trie_atom_instr(); @@ -949,7 +923,6 @@ int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; store_trie_node(TrNode_next(node)); stack_trie_atom_instr(); @@ -962,27 +935,29 @@ int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; restore_trie_node(TrNode_next(node)); stack_trie_atom_instr(); ENDPBOp(); - PBOp(trie_do_atom_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_do_atom_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = YENV; + int heap_arity = *aux_ptr; + int vars_arity = *(aux_ptr + heap_arity + 1); + int subs_arity = *(aux_ptr + heap_arity + 2); - stack_trie_atom_in_new_list_instr(); + stack_trie_atom_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_do_atom_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_do_atom_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_trust_atom_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_trust_atom_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = (CELL *) (B + 1); int heap_arity = *aux_ptr; @@ -990,15 +965,15 @@ int subs_arity = *(aux_ptr + heap_arity + 2); pop_trie_node(); - stack_trie_atom_in_new_list_instr(); + stack_trie_atom_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_trust_atom_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_trust_atom_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_try_atom_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_try_atom_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = YENV; int heap_arity = *aux_ptr; @@ -1006,15 +981,15 @@ int subs_arity = *(aux_ptr + heap_arity + 2); store_trie_node(TrNode_next(node)); - stack_trie_atom_in_new_list_instr(); + stack_trie_atom_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_try_atom_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_try_atom_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_retry_atom_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_retry_atom_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = (CELL *) (B + 1); int heap_arity = *aux_ptr; @@ -1022,79 +997,25 @@ int subs_arity = *(aux_ptr + heap_arity + 2); restore_trie_node(TrNode_next(node)); - stack_trie_atom_in_new_list_instr(); + stack_trie_atom_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_retry_atom_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_retry_atom_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_do_list, e) + PBOp(trie_do_pair, e) register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = YENV; int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; - stack_trie_list_instr(); + stack_trie_pair_instr(); ENDPBOp(); - PBOp(trie_trust_list, e) - register ans_node_ptr node = (ans_node_ptr) PREG; - register CELL *aux_ptr = (CELL *) (B + 1); - int heap_arity = *aux_ptr; - int vars_arity = *(aux_ptr + heap_arity + 1); - int subs_arity = *(aux_ptr + heap_arity + 2); - int i; - - pop_trie_node(); - stack_trie_list_instr(); - ENDPBOp(); - - - PBOp(trie_try_list, e) - register ans_node_ptr node = (ans_node_ptr) PREG; - register CELL *aux_ptr = YENV; - int heap_arity = *aux_ptr; - int vars_arity = *(aux_ptr + heap_arity + 1); - int subs_arity = *(aux_ptr + heap_arity + 2); - int i; - - store_trie_node(TrNode_next(node)); - stack_trie_list_instr(); - ENDPBOp(); - - - PBOp(trie_retry_list, e) - register ans_node_ptr node = (ans_node_ptr) PREG; - register CELL *aux_ptr = (CELL *) (B + 1); - int heap_arity = *aux_ptr; - int vars_arity = *(aux_ptr + heap_arity + 1); - int subs_arity = *(aux_ptr + heap_arity + 2); - int i; - - restore_trie_node(TrNode_next(node)); - stack_trie_list_instr(); - ENDPBOp(); - - - PBOp(trie_do_list_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS - register ans_node_ptr node = (ans_node_ptr) PREG; - register CELL *aux_ptr = YENV; - int heap_arity = *aux_ptr; - - stack_trie_list_in_new_list_instr(); -#else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_do_list_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ - ENDPBOp(); - - - PBOp(trie_trust_list_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_trust_pair, e) register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = (CELL *) (B + 1); int heap_arity = *aux_ptr; @@ -1102,15 +1023,11 @@ int subs_arity = *(aux_ptr + heap_arity + 2); pop_trie_node(); - stack_trie_list_in_new_list_instr(); -#else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_trust_list_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + stack_trie_pair_instr(); ENDPBOp(); - PBOp(trie_try_list_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_try_pair, e) register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = YENV; int heap_arity = *aux_ptr; @@ -1118,15 +1035,11 @@ int subs_arity = *(aux_ptr + heap_arity + 2); store_trie_node(TrNode_next(node)); - stack_trie_list_in_new_list_instr(); -#else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_try_list_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + stack_trie_pair_instr(); ENDPBOp(); - PBOp(trie_retry_list_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_retry_pair, e) register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = (CELL *) (B + 1); int heap_arity = *aux_ptr; @@ -1134,10 +1047,7 @@ int subs_arity = *(aux_ptr + heap_arity + 2); restore_trie_node(TrNode_next(node)); - stack_trie_list_in_new_list_instr(); -#else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_retry_list_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + stack_trie_pair_instr(); ENDPBOp(); @@ -1149,7 +1059,6 @@ int subs_arity = *(aux_ptr + heap_arity + 2); Functor func = (Functor) RepAppl(TrNode_entry(node)); int func_arity = ArityOfFunctor(func); - int i; stack_trie_struct_instr(); ENDPBOp(); @@ -1163,7 +1072,6 @@ int subs_arity = *(aux_ptr + heap_arity + 2); Functor func = (Functor) RepAppl(TrNode_entry(node)); int func_arity = ArityOfFunctor(func); - int i; pop_trie_node(); stack_trie_struct_instr(); @@ -1178,7 +1086,6 @@ int subs_arity = *(aux_ptr + heap_arity + 2); Functor func = (Functor) RepAppl(TrNode_entry(node)); int func_arity = ArityOfFunctor(func); - int i; store_trie_node(TrNode_next(node)); stack_trie_struct_instr(); @@ -1193,31 +1100,31 @@ int subs_arity = *(aux_ptr + heap_arity + 2); Functor func = (Functor) RepAppl(TrNode_entry(node)); int func_arity = ArityOfFunctor(func); - int i; restore_trie_node(TrNode_next(node)); stack_trie_struct_instr(); ENDPBOp(); - PBOp(trie_do_struct_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_do_struct_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = YENV; int heap_arity = *aux_ptr; + int vars_arity = *(aux_ptr + heap_arity + 1); + int subs_arity = *(aux_ptr + heap_arity + 2); Functor func = (Functor) RepAppl(TrNode_entry(node)); int func_arity = ArityOfFunctor(func); - int i; - stack_trie_struct_in_new_list_instr(); + stack_trie_struct_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_do_struct_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_do_struct_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_trust_struct_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_trust_struct_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = (CELL *) (B + 1); int heap_arity = *aux_ptr; @@ -1225,18 +1132,17 @@ int subs_arity = *(aux_ptr + heap_arity + 2); Functor func = (Functor) RepAppl(TrNode_entry(node)); int func_arity = ArityOfFunctor(func); - int i; pop_trie_node(); - stack_trie_struct_in_new_list_instr(); + stack_trie_struct_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_trust_struct_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_trust_struct_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_try_struct_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_try_struct_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = YENV; int heap_arity = *aux_ptr; @@ -1244,18 +1150,17 @@ int subs_arity = *(aux_ptr + heap_arity + 2); Functor func = (Functor) RepAppl(TrNode_entry(node)); int func_arity = ArityOfFunctor(func); - int i; store_trie_node(TrNode_next(node)); - stack_trie_struct_in_new_list_instr(); + stack_trie_struct_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_try_struct_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_try_struct_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); - PBOp(trie_retry_struct_in_new_list, e) -#ifdef TRIE_COMPACT_LISTS + PBOp(trie_retry_struct_in_new_pair, e) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_ptr = (CELL *) (B + 1); int heap_arity = *aux_ptr; @@ -1263,13 +1168,12 @@ int subs_arity = *(aux_ptr + heap_arity + 2); Functor func = (Functor) RepAppl(TrNode_entry(node)); int func_arity = ArityOfFunctor(func); - int i; restore_trie_node(TrNode_next(node)); - stack_trie_struct_in_new_list_instr(); + stack_trie_struct_in_new_pair_instr(); #else - Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_retry_struct_in_new_list)"); -#endif /* TRIE_COMPACT_LISTS */ + Yap_Error(INTERNAL_ERROR, TermNil, "invalid instruction (trie_retry_struct_in_new_pair)"); +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); @@ -1324,10 +1228,9 @@ int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; - Term t; volatile Float dbl; volatile Term *t_dbl = (Term *)((void *) &dbl); + Term t; #if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P *t_dbl = *++aux_ptr; @@ -1363,7 +1266,6 @@ int heap_arity = *aux_ptr; int vars_arity = *(aux_ptr + heap_arity + 1); int subs_arity = *(aux_ptr + heap_arity + 2); - int i; Term t = MkLongIntTerm(*++aux_ptr); heap_arity -= 1;