52#define HEAP_ARITY_ENTRY (0)
53#define VARS_ARITY_ENTRY (1 + heap_arity)
54#define SUBS_ARITY_ENTRY (1 + heap_arity + 1 + vars_arity)
58#define HEAP_ENTRY(INDEX) (HEAP_ARITY_ENTRY + (INDEX))
59#define VARS_ENTRY(INDEX) (VARS_ARITY_ENTRY + 1 + vars_arity - (INDEX))
60#define SUBS_ENTRY(INDEX) (SUBS_ARITY_ENTRY + 1 + subs_arity - (INDEX))
62#define next_trie_instruction(NODE) \
63 PREG = (yamop *) TrNode_child(NODE); \
67#define next_instruction(CONDITION, NODE) \
69 PREG = (yamop *) TrNode_child(NODE); \
71 PREG = (yamop *) CPREG; \
77#define copy_aux_stack() \
78 { int size = 3 + heap_arity + subs_arity + vars_arity; \
80 memcpy(TOP_STACK, aux_stack, size * sizeof(CELL *)); \
81 aux_stack = TOP_STACK; \
85#define store_trie_node(AP) \
86 { register choiceptr cp; \
87 TOP_STACK = (CELL *) (NORM_CP(TOP_STACK) - 1); \
88 cp = NORM_CP(TOP_STACK); \
90 store_yaam_reg_cpdepth(cp); \
95 cp->cp_ap = (yamop *) AP; \
100 TABLING_ERROR_CHECKING_STACK; \
104#define restore_trie_node(AP) \
105 HR = HBREG = PROTECT_FROZEN_H(B); \
106 restore_yaam_reg_cpdepth(B); \
109 YAPOR_update_alternative(PREG, (yamop *) AP) \
110 B->cp_ap = (yamop *) AP; \
111 TOP_STACK = (CELL *) PROTECT_FROZEN_B(B); \
112 SET_BB(NORM_CP(TOP_STACK)); \
115#define really_pop_trie_node() \
116 TOP_STACK = (CELL *) PROTECT_FROZEN_B((B + 1)); \
117 HR = PROTECT_FROZEN_H(B); \
118 pop_yaam_reg_cpdepth(B); \
120 TABLING_close_alt(B); \
123 HBREG = PROTECT_FROZEN_H(B); \
124 SET_BB(PROTECT_FROZEN_B(B)); \
125 if ((choiceptr) TOP_STACK == B_FZ) { \
130#define pop_trie_node() \
131 if (SCH_top_shared_cp(B)) { \
132 restore_trie_node(NULL); \
134 really_pop_trie_node(); \
137#define pop_trie_node() \
138 really_pop_trie_node()
147#define aux_stack_null_instr() \
148 next_trie_instruction(node)
156#define aux_stack_extension_instr() \
157 TOP_STACK = &aux_stack[-2]; \
158 TOP_STACK[HEAP_ARITY_ENTRY] = heap_arity + 2; \
159 TOP_STACK[HEAP_ENTRY(1)] = TrNode_entry(node); \
160 TOP_STACK[HEAP_ENTRY(2)] = 0; \
161 next_trie_instruction(node)
169#define aux_stack_term_instr() \
171 Bind_Global((CELL *) aux_stack[HEAP_ENTRY(1)], t); \
172 TOP_STACK = &aux_stack[1]; \
173 TOP_STACK[HEAP_ARITY_ENTRY] = heap_arity - 1; \
174 next_instruction(heap_arity - 1 || subs_arity, node); \
176 YapBind((CELL *) aux_stack[SUBS_ENTRY(1)], t); \
177 aux_stack[SUBS_ARITY_ENTRY] = subs_arity - 1; \
178 next_instruction(subs_arity - 1, node); \
181#define aux_stack_term_in_pair_instr() \
183 Bind_Global((CELL *) aux_stack[HEAP_ENTRY(1)], AbsPair(HR)); \
185 YapBind((CELL *) aux_stack[SUBS_ENTRY(1)], AbsPair(HR)); \
186 aux_stack[SUBS_ARITY_ENTRY] = subs_arity - 1; \
187 TOP_STACK = &aux_stack[-1]; \
188 TOP_STACK[HEAP_ARITY_ENTRY] = 1; \
190 Bind_Global(HR, TrNode_entry(node)); \
191 TOP_STACK[HEAP_ENTRY(1)] = (CELL) (HR + 1); \
193 next_trie_instruction(node)
201#define aux_stack_new_pair_instr() \
203 Bind_Global((CELL *) aux_stack[HEAP_ENTRY(1)], AbsPair(HR)); \
204 TOP_STACK = &aux_stack[-1]; \
205 TOP_STACK[HEAP_ARITY_ENTRY] = heap_arity + 1; \
207 YapBind((CELL *) aux_stack[SUBS_ENTRY(1)], AbsPair(HR)); \
208 aux_stack[SUBS_ARITY_ENTRY] = subs_arity - 1; \
209 TOP_STACK = &aux_stack[-2]; \
210 TOP_STACK[HEAP_ARITY_ENTRY] = 2; \
212 TOP_STACK[HEAP_ENTRY(1)] = (CELL) HR; \
213 TOP_STACK[HEAP_ENTRY(2)] = (CELL) (HR + 1); \
215 next_trie_instruction(node)
217#ifdef TRIE_COMPACT_PAIRS
218#define aux_stack_pair_instr() \
220 Bind_Global((CELL *) aux_stack[HEAP_ENTRY(1)], AbsPair(HR)); \
222 YapBind((CELL *) aux_stack[SUBS_ENTRY(1)], AbsPair(HR)); \
223 aux_stack[SUBS_ARITY_ENTRY] = subs_arity - 1; \
224 TOP_STACK = &aux_stack[-1]; \
225 TOP_STACK[HEAP_ARITY_ENTRY] = 1; \
227 TOP_STACK[HEAP_ENTRY(1)] = (CELL) HR; \
228 Bind_Global(HR + 1, TermNil); \
230 next_trie_instruction(node)
232#define aux_stack_pair_instr() \
233 aux_stack_new_pair_instr()
242#define aux_stack_appl_instr() \
244 Bind_Global((CELL *) aux_stack[HEAP_ENTRY(1)], AbsAppl(HR)); \
245 TOP_STACK = &aux_stack[-func_arity + 1]; \
246 TOP_STACK[HEAP_ARITY_ENTRY] = heap_arity + func_arity - 1; \
248 YapBind((CELL *) aux_stack[SUBS_ENTRY(1)], AbsAppl(HR)); \
249 aux_stack[SUBS_ARITY_ENTRY] = subs_arity - 1; \
250 TOP_STACK = &aux_stack[-func_arity]; \
251 TOP_STACK[HEAP_ARITY_ENTRY] = func_arity; \
255 for (i = 1; i <= func_arity; i++) \
256 TOP_STACK[HEAP_ENTRY(i)] = (CELL) (HR + i); \
258 HR += 1 + func_arity; \
259 next_trie_instruction(node)
261#define aux_stack_appl_in_pair_instr() \
263 Bind_Global((CELL *) aux_stack[HEAP_ENTRY(1)], AbsPair(HR)); \
264 TOP_STACK = &aux_stack[-func_arity]; \
265 TOP_STACK[HEAP_ARITY_ENTRY] = heap_arity + func_arity; \
267 YapBind((CELL *) aux_stack[SUBS_ENTRY(1)], AbsPair(HR)); \
268 aux_stack[SUBS_ARITY_ENTRY] = subs_arity - 1; \
269 TOP_STACK = &aux_stack[-func_arity - 1]; \
270 TOP_STACK[HEAP_ARITY_ENTRY] = func_arity + 1; \
272 TOP_STACK[HEAP_ENTRY(func_arity + 1)] = (CELL) (HR + 1); \
273 Bind_Global(HR, AbsAppl(HR + 2)); \
277 for (i = 1; i <= func_arity; i++) \
278 TOP_STACK[HEAP_ENTRY(i)] = (CELL) (HR + i); \
280 HR += 1 + func_arity; \
281 next_trie_instruction(node)
289#define aux_stack_var_instr() \
292 CELL var = aux_stack[HEAP_ENTRY(1)]; \
293 RESET_VARIABLE(var); \
294 TOP_STACK[HEAP_ARITY_ENTRY] = heap_arity - 1; \
295 for (i = 2; i <= heap_arity; i++) \
296 TOP_STACK[HEAP_ENTRY(i - 1)] = aux_stack[HEAP_ENTRY(i)]; \
297 aux_stack[VARS_ARITY_ENTRY - 1] = vars_arity + 1; \
298 aux_stack[VARS_ENTRY(vars_arity + 1)] = var; \
299 next_instruction(heap_arity - 1 || subs_arity, node); \
301 CELL var = aux_stack[SUBS_ENTRY(1)]; \
302 aux_stack[SUBS_ARITY_ENTRY] = subs_arity - 1; \
303 TOP_STACK = &aux_stack[-1]; \
304 TOP_STACK[HEAP_ARITY_ENTRY] = 0; \
305 aux_stack[VARS_ARITY_ENTRY - 1] = vars_arity + 1; \
306 aux_stack[VARS_ENTRY(vars_arity + 1)] = var; \
307 next_instruction(subs_arity - 1, node); \
310#define aux_stack_var_in_pair_instr() \
313 Bind_Global((CELL *) aux_stack[HEAP_ENTRY(1)], AbsPair(HR)); \
314 TOP_STACK = &aux_stack[-1]; \
315 TOP_STACK[HEAP_ARITY_ENTRY] = heap_arity; \
316 TOP_STACK[HEAP_ENTRY(1)] = (CELL) (HR + 1); \
317 for (i = 2; i <= heap_arity; i++) \
318 TOP_STACK[HEAP_ENTRY(i)] = aux_stack[HEAP_ENTRY(i)]; \
320 YapBind((CELL *) aux_stack[SUBS_ENTRY(1)], AbsPair(HR)); \
321 aux_stack[SUBS_ARITY_ENTRY] = subs_arity - 1; \
322 TOP_STACK = &aux_stack[-2]; \
323 TOP_STACK[HEAP_ARITY_ENTRY] = 1; \
324 TOP_STACK[HEAP_ENTRY(1)] = (CELL) (HR + 1); \
326 aux_stack[VARS_ARITY_ENTRY - 1] = vars_arity + 1; \
327 aux_stack[VARS_ENTRY(vars_arity + 1)] = (CELL) HR; \
328 RESET_VARIABLE((CELL) HR); \
330 next_trie_instruction(node)
338#define aux_stack_val_instr() \
340 CELL aux_sub, aux_var; \
341 aux_sub = aux_stack[HEAP_ENTRY(1)]; \
342 aux_var = aux_stack[VARS_ENTRY(var_index + 1)]; \
343 if (aux_sub > aux_var) { \
344 Bind_Global((CELL *) aux_sub, aux_var); \
346 RESET_VARIABLE(aux_sub); \
347 Bind_Local((CELL *) aux_var, aux_sub); \
348 aux_stack[VARS_ENTRY(var_index + 1)] = aux_sub; \
350 TOP_STACK = &aux_stack[1]; \
351 TOP_STACK[HEAP_ARITY_ENTRY] = heap_arity - 1; \
352 next_instruction(heap_arity - 1 || subs_arity, node); \
354 CELL aux_sub, aux_var; \
355 aux_sub = aux_stack[SUBS_ENTRY(1)]; \
356 aux_stack[SUBS_ARITY_ENTRY] = subs_arity - 1; \
357 aux_var = aux_stack[VARS_ENTRY(var_index + 1)]; \
358 if (aux_sub > aux_var) { \
359 if ((CELL *) aux_sub <= HR) { \
360 Bind_Global((CELL *) aux_sub, aux_var); \
361 } else if ((CELL *) aux_var <= HR) { \
362 Bind_Local((CELL *) aux_sub, aux_var); \
364 Bind_Local((CELL *) aux_var, aux_sub); \
365 aux_stack[VARS_ENTRY(var_index + 1)] = aux_sub; \
368 if ((CELL *) aux_var <= HR) { \
369 Bind_Global((CELL *) aux_var, aux_sub); \
370 aux_stack[VARS_ENTRY(var_index + 1)] = aux_sub; \
371 } else if ((CELL *) aux_sub <= HR) { \
372 Bind_Local((CELL *) aux_var, aux_sub); \
373 aux_stack[VARS_ENTRY(var_index + 1)] = aux_sub; \
375 Bind_Local((CELL *) aux_sub, aux_var); \
378 next_instruction(subs_arity - 1, node); \
381#define aux_stack_val_in_pair_instr() \
383 Bind_Global((CELL *) aux_stack[HEAP_ENTRY(1)], AbsPair(HR)); \
385 YapBind((CELL *) aux_stack[SUBS_ENTRY(1)], AbsPair(HR)); \
386 aux_stack[SUBS_ARITY_ENTRY] = subs_arity - 1; \
387 TOP_STACK = &aux_stack[-1]; \
388 TOP_STACK[HEAP_ARITY_ENTRY] = 1; \
390 { CELL aux_sub, aux_var; \
391 aux_sub = (CELL) HR; \
392 aux_var = aux_stack[VARS_ENTRY(var_index + 1)]; \
393 if (aux_sub > aux_var) { \
394 Bind_Global((CELL *) aux_sub, aux_var); \
396 RESET_VARIABLE(aux_sub); \
397 Bind_Local((CELL *) aux_var, aux_sub); \
398 aux_stack[VARS_ENTRY(var_index + 1)] = aux_sub; \
401 TOP_STACK[HEAP_ENTRY(1)] = (CELL) (HR + 1); \
403 next_trie_instruction(node)
411{ printf(
"Tries not supported by JIT!!\n"); exit(1); }
416PBOp(trie_trust_var, e)
417{ printf(
"Tries not supported by JIT!!\n"); exit(1); }
422 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
427PBOp(trie_retry_var, e)
428{ printf(
"Tries not supported by JIT!!\n"); exit(1); }
432 PBOp(trie_do_var_in_pair, e)
433 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
437 PBOp(trie_trust_var_in_pair, e)
438 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
442 PBOp(trie_try_var_in_pair, e)
443 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
447 PBOp(trie_retry_var_in_pair, e)
448 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
453 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
457 PBOp(trie_trust_val, e)
458 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
462 PBOp(trie_try_val, e)
463 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
467 PBOp(trie_retry_val, e)
468 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
472 PBOp(trie_do_val_in_pair, e)
473 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
477 PBOp(trie_trust_val_in_pair, e)
478 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
482 PBOp(trie_try_val_in_pair, e)
483 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
487 PBOp(trie_retry_val_in_pair, e)
488 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
492 PBOp(trie_do_atom, e)
493 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
497 PBOp(trie_trust_atom, e)
498 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
502 PBOp(trie_try_atom, e)
503 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
507 PBOp(trie_retry_atom, e)
508 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
512 PBOp(trie_do_atom_in_pair, e)
513 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
517 PBOp(trie_trust_atom_in_pair, e)
518 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
522 PBOp(trie_try_atom_in_pair, e)
523 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
527 PBOp(trie_retry_atom_in_pair, e)
528 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
532 PBOp(trie_do_null, e)
533 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
537 PBOp(trie_trust_null, e)
538 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
542 PBOp(trie_try_null, e)
543 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
547 PBOp(trie_retry_null, e)
548 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
552 PBOp(trie_do_null_in_pair, e)
553 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
557 PBOp(trie_trust_null_in_pair, e)
558{ printf(
"Tries not supported by JIT!!\n"); exit(1); }
562PBOp(trie_try_null_in_pair, e)
563 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
567 PBOp(trie_retry_null_in_pair, e)
568{ printf(
"Tries not supported by JIT!!\n"); exit(1); }
573 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
577 PBOp(trie_trust_pair, e)
578 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
582 PBOp(trie_try_pair, e)
583 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
587 PBOp(trie_retry_pair, e)
588 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
592 PBOp(trie_do_appl, e)
593 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
597 PBOp(trie_trust_appl, e)
598 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
602 PBOp(trie_try_appl, e)
603 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
607 PBOp(trie_retry_appl, e)
608 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
612 PBOp(trie_do_appl_in_pair, e)
613{ printf(
"Tries not supported by JIT!!\n"); exit(1); }
617 PBOp(trie_trust_appl_in_pair, e)
618 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
622 PBOp(trie_try_appl_in_pair, e)
623 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
627 PBOp(trie_retry_appl_in_pair, e)
628 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
632 PBOp(trie_do_extension, e)
633 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
637 PBOp(trie_trust_extension, e)
638 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
642 PBOp(trie_try_extension, e)
643 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
647 PBOp(trie_retry_extension, e)
648 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
652 PBOp(trie_do_double, e)
654 register CELL *aux_stack = TOP_STACK;
655 int heap_arity = aux_stack[HEAP_ARITY_ENTRY];
656 int vars_arity = aux_stack[VARS_ARITY_ENTRY];
657 int subs_arity = aux_stack[SUBS_ARITY_ENTRY];
660 Term ts[SIZEOF_DOUBLE/SIZEOF_INT_P];
664#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P
665 td.ts[0] = aux_stack[HEAP_ENTRY(1)];
666 td.ts[1] = aux_stack[HEAP_ENTRY(3)];
668 TOP_STACK = aux_stack = &aux_stack[4];
670 td.ts[0] = aux_stack[HEAP_ENTRY(1)];
672 TOP_STACK = aux_stack = &aux_stack[2];
674 TOP_STACK[HEAP_ARITY_ENTRY] = heap_arity;
675 t = MkFloatTerm(td.dbl);
676 aux_stack_term_instr();
677 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
681 BOp(trie_trust_double, e)
682 Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
"trie_trust_double: invalid instruction");
686 BOp(trie_try_double, e)
687 Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
"trie_try_double: invalid instruction");
691 BOp(trie_retry_double, e)
692 Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
"trie_retry_double: invalid instruction");
696 PBOp(trie_do_longint, e)
698 register CELL *aux_stack = TOP_STACK;
699 int heap_arity = aux_stack[HEAP_ARITY_ENTRY];
700 int vars_arity = aux_stack[VARS_ARITY_ENTRY];
701 int subs_arity = aux_stack[SUBS_ARITY_ENTRY];
702 Term t = MkLongIntTerm(aux_stack[HEAP_ENTRY(1)]);
705 TOP_STACK = aux_stack = &aux_stack[2];
706 TOP_STACK[HEAP_ARITY_ENTRY] = heap_arity;
707 aux_stack_term_instr();
708 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
712 BOp(trie_trust_longint, e)
713 Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
"trie_trust_longint: invalid instruction");
717 BOp(trie_try_longint, e)
718 Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
"trie_try_longint: invalid instruction");
722 BOp(trie_retry_longint, e)
726 PBOp(trie_do_bigint, e)
727 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
731 BOp(trie_trust_bigint, e)
735 BOp(trie_try_bigint, e)
739 BOp(trie_retry_bigint, e)
744 PBOp(trie_do_gterm, e)
746 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
750 PBOp(trie_trust_gterm, e)
751 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
755 PBOp(trie_try_gterm, e)
756 { printf(
"Tries not supported by JIT!!\n"); exit(1); }
760 PBOp(trie_retry_gterm, e)
761 { printf(
"Tries not supported by JIT!!\n"); exit(1); }