YAP 7.1.0
control_absmi_insts.h
1/************************************************************************\
2 * Cut & Commit Instructions *
3\************************************************************************/
4
5#ifdef INDENT_CODE
6{
7 {
8 {
9#endif /* INDENT_CODE */
10
11 /* cut */
12 Op(cut, s);
13 CACHE_Y_AS_ENV(YREG);
14 check_stack(NoStackCut, HR);
15 ENDCACHE_Y_AS_ENV();
16
17 SET_ASP(YREG, AS_CELLS(PREG->y_u.s.s));
18 PREG = NEXTOP(NEXTOP(NEXTOP(PREG, s),Osbpp),l);
19 /* assume cut is always in stack */
20 saveregs();
21 prune((choiceptr)YREG[E_CB] PASS_REGS);
22 setregs();
23 GONext();
24
25 NoStackCut:
26 PROCESS_INTERRUPTED_PRUNE(interrupt_cut);
27 JMPNext();
28
29 ENDOp();
30
31 /* cut_t */
32 /* cut_t does the same as cut */
33 Op(cut_t, s);
34 CACHE_Y_AS_ENV(YREG);
35 check_stack(NoStackCutT, HR);
36 ENDCACHE_Y_AS_ENV();
37 SET_ASP(YREG, AS_CELLS( PREG->y_u.s.s) );
38 /* assume cut is always in stack */
39 saveregs();
40 prune((choiceptr)YREG[E_CB] PASS_REGS);
41 setregs();
42 PREG = NEXTOP(NEXTOP(NEXTOP(PREG, s),Osbpp),l);
43 GONext();
44
45 NoStackCutT:
46 PROCESS_INTERRUPTED_PRUNE(interrupt_cut_t);
47 JMPNext();
48
49 ENDOp();
50
51 /* cut_e */
52 Op(cut_e, s);
53 CACHE_Y_AS_ENV(YREG);
54 check_stack(NoStackCutE, HR);
55 ENDCACHE_Y_AS_ENV();
56 SET_ASP(YREG, AS_CELLS( PREG->y_u.s.s));
57 PREG = NEXTOP(NEXTOP(NEXTOP(PREG, s),Osbpp),l);
58 saveregs();
59 prune((choiceptr)SREG[E_CB] PASS_REGS);
60 setregs();
61 GONext();
62
63 NoStackCutE:
64 PROCESS_INTERRUPTED_PRUNE(interrupt_cut_e);
65
66 ENDOp();
67
68 /* save_b_x Xi */
69 Op(save_b_x, x);
70 BEGD(d0);
71 d0 = PREG->y_u.x.x;
72#if defined(YAPOR_SBA) && defined(FROZEN_STACKS)
73 XREG(d0) = MkIntegerTerm((Int)B);
74#else
75 XREG(d0) = MkIntegerTerm(LCL0-(CELL *) (B));
76#endif /* YAPOR_SBA && FROZEN_STACKS */
77 PREG = NEXTOP(PREG, x);
78 ENDD(d0);
79 GONext();
80 ENDOp();
81
82 /* save_b_y Yi */
83 Op(save_b_y, y);
84#if defined(YAPOR_SBA)
85 INITIALIZE_PERMVAR(YREG+PREG->y_u.y.y,MkIntegerTerm((Int)B));
86#else
87 INITIALIZE_PERMVAR(YREG+PREG->y_u.y.y,MkIntegerTerm(LCL0-(CELL *)(B)));
88#endif /* YAPOR_SBA*/
89 PREG = NEXTOP(PREG, y);
90 GONext();
91 ENDOp();
92
93 /* commit_b_x Xi */
94 Op(commit_b_x, xps);
95 CACHE_Y_AS_ENV(YREG);
96 check_stack(NoStackCommitX, HR);
97 ENDCACHE_Y_AS_ENV();
98 BEGD(d0);
99 d0 = XREG(PREG->y_u.xps.x);
100 deref_head(d0, commit_b_x_unk);
101 commit_b_x_nvar:
102 /* skip a void call and a label */
103 SET_ASP(YREG, AS_CELLS(PREG->y_u.xps.s));
104 PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xps),Osbpp),l);
105 {
106 choiceptr pt0;
107#if defined(YAPOR_SBA) && defined(FROZEN_STACKS)
108 pt0 = (choiceptr)IntegerOfTerm(d0);
109#else
110 pt0 = (choiceptr)(LCL0-IntegerOfTerm(d0));
111#endif /* YAPOR_SBA && FROZEN_STACKS */
112 saveregs();
113 prune(pt0 PASS_REGS);
114 setregs();
115 }
116 GONext();
117
118 BEGP(pt1);
119 deref_body(d0, pt1, commit_b_x_unk, commit_b_x_nvar);
120 ENDP(pt1);
121 /* never cut to a variable */
122 /* Abort */
123 FAIL();
124 ENDD(d0);
125
126 /* Problem: have I got an environment or not? */
127 NoStackCommitX:
128 PROCESS_INTERRUPTED_PRUNE(interrupt_commit_x);
129 ENDOp();
130
131 /* commit_b_y Yi */
132 Op(commit_b_y, yps);
133 CACHE_Y_AS_ENV(YREG);
134 check_stack(NoStackCommitY, HR);
135 ENDCACHE_Y_AS_ENV();
136 BEGD(d0);
137 d0 = YREG[PREG->y_u.yps.y];
138 deref_head(d0, commit_b_y_unk);
139 commit_b_y_nvar:
140 SET_ASP(YREG, AS_CELLS(PREG->y_u.yps.s));
141 PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yps),Osbpp),l);
142 {
143 choiceptr pt0;
144#if defined(YAPOR_SBA) && defined(FROZEN_STACKS)
145 pt0 = (choiceptr)IntegerOfTerm(d0);
146#else
147 pt0 = (choiceptr)(LCL0-IntegerOfTerm(d0));
148#endif
149 saveregs();
150 prune(pt0 PASS_REGS);
151 setregs();
152 }
153 GONext();
154
155 BEGP(pt1);
156 deref_body(d0, pt1, commit_b_y_unk, commit_b_y_nvar);
157 ENDP(pt1);
158 /* never cut to a variable */
159 /* Abort */
160 FAIL();
161 ENDD(d0);
162
163
164 /* This is easier: I know there is an environment so I cannot do allocate */
165 NoStackCommitY:
166 PROCESS_INTERRUPTED_PRUNE(interrupt_commit_y);
167 ENDOp();
168
169
170 /* soft_cut_b_x Xi */
171 Op(soft_cut_b_x, xps);
172 CACHE_Y_AS_ENV(YREG);
173 check_stack(NoStackSoft_CutX, HR);
174 ENDCACHE_Y_AS_ENV();
175 BEGD(d0);
176 d0 = XREG(PREG->y_u.xps.x);
177 deref_head(d0, soft_cut_b_x_unk);
178 soft_cut_b_x_nvar:
179 /* skip a void call and a label */
180 SET_ASP(YREG, AS_CELLS(PREG->y_u.xps.s));
181 PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xps),Osbpp),l);
182 {
183 choiceptr pt0;
184#if defined(YAPOR_SBA) && defined(FROZEN_STACKS)
185 pt0 = (choiceptr)IntegerOfTerm(d0);
186#else
187 pt0 = (choiceptr)(LCL0-IntegerOfTerm(d0));
188#endif /* YAPOR_SBA && FROZEN_STACKS */
189 if (pt0==B) {
190 while(pt0->cp_b && pt0->cp_b->cp_ap == TRUSTFAILCODE) {
191 pt0=pt0->cp_b;
192 }
193 saveregs();
194 prune(pt0 PASS_REGS);
195 setregs();
196 } else if (pt0>B) {
197 pt0->cp_ap = TRUSTFAILCODE;
198 }
199 }
200 GONext();
201
202 BEGP(pt1);
203 deref_body(d0, pt1, soft_cut_b_x_unk, soft_cut_b_x_nvar);
204 ENDP(pt1);
205 /* never cut to a variable */
206 /* Abort */
207 FAIL();
208 ENDD(d0);
209
210 /* Problem: have I got an environment or not? */
211 NoStackSoft_CutX:
212 PROCESS_INTERRUPTED_PRUNE(interrupt_soft_cut_x);
213 ENDOp();
214
215 /* soft_cut_b_y Yi */
216 Op(soft_cut_b_y, yps);
217 CACHE_Y_AS_ENV(YREG);
218 check_stack(NoStackSoft_CutY, HR);
219 ENDCACHE_Y_AS_ENV();
220 BEGD(d0);
221 d0 = YREG[PREG->y_u.yps.y];
222 deref_head(d0, soft_cut_b_y_unk);
223 soft_cut_b_y_nvar:
224 SET_ASP(YREG, AS_CELLS(PREG->y_u.yps.s));
225 PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yps),Osbpp),l);
226 {
227 choiceptr pt0;
228#if defined(YAPOR_SBA) && defined(FROZEN_STACKS)
229 pt0 = (choiceptr)IntegerOfTerm(d0);
230#else
231 pt0 = (choiceptr)(LCL0-IntegerOfTerm(d0));
232#endif
233 if (pt0==B) {
234 while(pt0->cp_b && pt0->cp_b->cp_ap == TRUSTFAILCODE) {
235 pt0=pt0->cp_b;
236 }
237 saveregs();
238 prune(pt0 PASS_REGS);
239 setregs();
240 } else if (pt0>B) {
241 pt0->cp_ap = TRUSTFAILCODE;
242 }
243 } GONext();
244
245 BEGP(pt1);
246 deref_body(d0, pt1, soft_cut_b_y_unk, soft_cut_b_y_nvar);
247 ENDP(pt1);
248 /* never cut to a variable */
249 /* Abort */
250
251
252
253 FAIL();
254 ENDD(d0);
255
256
257 /* This is easier: I know there is an environment so I cannot do allocate */
258 NoStackSoft_CutY:
259 PROCESS_INTERRUPTED_PRUNE(interrupt_soft_cut_y);
260 ENDOp();
261
262
263 /*************************************************************************
264 * Call / Proceed instructions *
265 *************************************************************************/
266
267 /* Macros for stack trimming */
268
269 /* execute Label */
270 BOp(execute, Osbpp);
271 {
272 CACHE_Y_AS_ENV(YREG);
273#ifndef NO_CHECKING
274 /* check stacks */
275 check_stack(NoStackExecute, HR);
276#endif
277
278 #ifdef LOW_LEVEL_TRACER
279 if (Yap_do_low_level_trace) {
280 low_level_trace(enter_pred,
281 PREG->y_u.Osbpp.p,XREGS+1);
282 }
283#endif /* LOW_LEVEL_TRACE */
284 PredEntry *pt0;
285 pt0 = PREG->y_u.Osbpp.p;
286 //do_execute:
287 FETCH_Y_FROM_ENV(YREG);
288 pt0 = PREG->y_u.Osbpp.p;
289 CACHE_A1();
290 ALWAYS_LOOKAHEAD(pt0->OpcodeOfPred);
291 BEGD(d0);
292 d0 = (CELL)B;
293 PREG = pt0->CodeOfPred;
294 /* for profiler */
295 save_pc();
296 ENV_YREG[E_CB] = d0;
297 ENDD(d0);
298#ifdef DEPTH_LIMIT
299 if (DEPTH <= MkIntTerm(1)) {/* I assume Module==0 is prolog */
300 if (pt0->ModuleOfPred) {
301 if (DEPTH == MkIntTerm(0)) {
302 FAIL();
303 } else { DEPTH = RESET_DEPTH(); }
304 }
305 } else if (pt0->ModuleOfPred)
306 DEPTH -= MkIntConstant(2);
307#endif /* DEPTH_LIMIT */
308 /* this is the equivalent to setting up the stack */
309 ALWAYS_GONext();
310 ALWAYS_END_PREFETCH();
311 }
312
313 NoStackExecute:
314 PROCESS_INT(interrupt_execute, continue_execute);
315 JMPNext();
316 ENDCACHE_Y_AS_ENV();
317 ENDBOp();
318
319 /* dexecute Label */
320 /* joint deallocate and execute */
321 BOp(dexecute, Osbpp);
322#ifdef LOW_LEVEL_TRACER
323 if (Yap_do_low_level_trace)
324 low_level_trace(enter_pred,PREG->y_u.Osbpp.p,XREGS+1);
325#endif /* LOW_LEVEL_TRACER */
326 CACHE_Y_AS_ENV(YREG);
327#ifndef NO_CHECKING
328 /* check stacks */
329 check_stack(NoStackDExecute, HR);
330#endif
331 {
332 PredEntry *pt0;
333
334 CACHE_A1();
335 //continue_dexecute:
336 FETCH_Y_FROM_ENV(YREG);
337 pt0 = PREG->y_u.Osbpp.p;
338#ifdef DEPTH_LIMIT
339 if (DEPTH <= MkIntTerm(1)) {/* I assume Module==0 is primitives */
340 if (pt0->ModuleOfPred) {
341 if (DEPTH == MkIntTerm(0)) {
342 FAIL();
343 } else {
344 DEPTH = RESET_DEPTH();
345 }
346 }
347 } else if (pt0->ModuleOfPred)
348 DEPTH -= MkIntConstant(2);
349#endif /* DEPTH_LIMIT */
350 PREG = pt0->CodeOfPred;
351 /* for profiler */
352 save_pc();
353 ALWAYS_LOOKAHEAD(pt0->OpcodeOfPred);
354 /* do deallocate */
355 CPREG = (yamop *) ENV_YREG[E_CP];
356 ENV_YREG = ENV = (CELL *) ENV_YREG[E_E];
357#ifdef FROZEN_STACKS
358 {
359 choiceptr top_b = PROTECT_FROZEN_B(B);
360#ifdef YAPOR_SBA
361 if (ENV_YREG > (CELL *) top_b || ENV_YREG < HR) ENV_YREG = (CELL *) top_b;
362#else
363 if (ENV_YREG > (CELL *) top_b) ENV_YREG = (CELL *) top_b;
364#endif /* YAPOR_SBA */
365 else ENV_YREG = (CELL *)((CELL)ENV_YREG + ENV_Size(CPREG));
366 }
367#else
368 if (ENV_YREG > (CELL *)B) {
369 ENV_YREG = (CELL *)B;
370 }
371 else {
372 ENV_YREG = (CELL *) ((CELL) ENV_YREG + ENV_Size(CPREG));
373 }
374#endif /* FROZEN_STACKS */
375 WRITEBACK_Y_AS_ENV();
376 /* setup GB */
377 ENV_YREG[E_CB] = (CELL) B;
378 ALWAYS_GONext();
379 ALWAYS_END_PREFETCH();
380 }
381 ENDCACHE_Y_AS_ENV();
382
383 NoStackDExecute:
384 PROCESS_INT(interrupt_dexecute, continue_dexecute);
385 JMPNext();
386 ENDBOp();
387
388 BOp(fcall, Osbpp);
389 CACHE_Y_AS_ENV(YREG);
390 ENV_YREG[E_CP] = (CELL) CPREG;
391 ENV_YREG[E_E] = (CELL) ENV;
392#ifdef DEPTH_LIMIT
393 ENV_YREG[E_DEPTH] = DEPTH;
394#endif /* DEPTH_LIMIT */
395 ENDCACHE_Y_AS_ENV();
396 ENDBOp();
397
398 BOp(call, Osbpp);
399#ifdef LOW_LEVEL_TRACER
400 if (Yap_do_low_level_trace) {
401 low_level_trace(enter_pred,PREG->y_u.Osbpp.p,XREGS+1);
402 }
403#endif /* LOW_LEVEL_TRACER */
404 call_direct:
405 CACHE_Y_AS_ENV(YREG);
406 {
407 PredEntry *pt;
408 CACHE_A1();
409 pt = PREG->y_u.Osbpp.p;
410#ifndef NO_CHECKING
411 check_stack(NoStackCall, HR);
412#endif
413 ENV = ENV_YREG;
414 /* Try to preserve the environment */
415 ENV_YREG = (CELL *) (((char *) ENV_YREG) + PREG->y_u.Osbpp.s);
416 CPREG = NEXTOP(PREG, Osbpp);
417 ALWAYS_LOOKAHEAD(pt->OpcodeOfPred);
418 PREG = pt->CodeOfPred;
419 /* for profiler */
420 save_pc();
421#ifdef DEPTH_LIMIT
422 if (DEPTH <= MkIntTerm(1)) {/* I assume Module==0 is primitives */
423 if (pt->ModuleOfPred) {
424 if (DEPTH == MkIntTerm(0)) {
425 FAIL();
426 } else {
427 DEPTH = RESET_DEPTH();
428 }
429 }
430 } else if (pt->ModuleOfPred)
431 DEPTH -= MkIntConstant(2);
432#endif /* DEPTH_LIMIT */
433#ifdef FROZEN_STACKS
434 {
435 choiceptr top_b = PROTECT_FROZEN_B(B);
436#ifdef YAPOR_SBA
437 if (ENV_YREG > (CELL *) top_b || ENV_YREG < HR) ENV_YREG = (CELL *) top_b;
438#else
439 if (ENV_YREG > (CELL *) top_b) ENV_YREG = (CELL *) top_b;
440#endif /* YAPOR_SBA */
441 }
442#else
443 if (ENV_YREG > (CELL *) B) {
444 ENV_YREG = (CELL *) B;
445 }
446#endif /* FROZEN_STACKS */
447 WRITEBACK_Y_AS_ENV();
448 /* setup GB */
449 ENV_YREG[E_CB] = (CELL) B;
450#ifdef YAPOR
451 SCH_check_requests();
452#endif /* YAPOR */
453 ALWAYS_GONext();
454 ALWAYS_END_PREFETCH();
455 }
456 ENDCACHE_Y_AS_ENV();
457
458 NoStackCall:
459 PROCESS_INT(interrupt_call, call_body);
460 if (PREG->opc == FCALL_OPCODE)
461 goto call_direct;
462 JMPNext();
463 ENDBOp();
464
465 BOp(procceed, p);
466 CACHE_Y_AS_ENV(YREG);
467 ALWAYS_LOOKAHEAD(CPREG->opc);
468 PREG = CPREG;
469 /* for profiler */
470 save_pc();
471 ENV_YREG = ENV;
472#ifdef DEPTH_LIMIT
473 DEPTH = ENV_YREG[E_DEPTH];
474#endif
475 WRITEBACK_Y_AS_ENV();
476 ALWAYS_GONext();
477 ALWAYS_END_PREFETCH();
478 ENDCACHE_Y_AS_ENV();
479
480 ENDBOp();
481
482 Op(allocate, e);
483 CACHE_Y_AS_ENV(YREG);
484 PREG = NEXTOP(PREG, e);
485 ENV_YREG[E_CP] = (CELL) CPREG;
486 ENV_YREG[E_E] = (CELL) ENV;
487#ifdef DEPTH_LIMIT
488 ENV_YREG[E_DEPTH] = DEPTH;
489#endif /* DEPTH_LIMIT */
490 ENV = ENV_YREG;
491 ENDCACHE_Y_AS_ENV();
492 GONext();
493 ENDOp();
494
495 Op(deallocate, p);
496 CACHE_Y_AS_ENV(YREG);
497 check_trail(TR);
498#if 0 && NO_CHECKING
499 /* check stacks */
500 check_stack(NoStackDeallocate, HR);
501#endif
502 PREG = NEXTOP(PREG, p);
503 /* other instructions do depend on S being set by deallocate
504 :-( */
505 SREG = YREG;
506 CPREG = (yamop *) ENV_YREG[E_CP];
507 ENV = ENV_YREG = (CELL *) ENV_YREG[E_E];
508#ifdef DEPTH_LIMIT
509 DEPTH = ENV_YREG[E_DEPTH];
510#endif /* DEPTH_LIMIT */
511#ifdef FROZEN_STACKS
512 {
513 choiceptr top_b = PROTECT_FROZEN_B(B);
514#ifdef YAPOR_SBA
515 if (ENV_YREG > (CELL *) top_b || ENV_YREG < HR) ENV_YREG = (CELL *) top_b;
516#else
517 if (ENV_YREG > (CELL *) top_b) ENV_YREG = (CELL *) top_b;
518#endif /* YAPOR_SBA */
519 else ENV_YREG = (CELL *)((CELL) ENV_YREG + ENV_Size(CPREG));
520 }
521#else
522 if (ENV_YREG > (CELL *) B)
523 ENV_YREG = (CELL *) B;
524 else
525 ENV_YREG = (CELL *) ((CELL) ENV_YREG + ENV_Size(CPREG));
526#endif /* FROZEN_STACKS */
527 WRITEBACK_Y_AS_ENV();
528 ENDCACHE_Y_AS_ENV();
529 GONext();
530
531 #if 0
532 NoStackDeallocate:
533 BEGD(d0);
534#ifdef SHADOW_S
535 Yap_REGS.S_ = YREG;
536#endif
537 PREG = NEXTOP(PREG,p);
538 saveregs();
539 d0 = interrupt_deallocate( PASS_REGS1 );
540 setregs();
541 PREG = PREVOP(PREG,p);
542#ifdef SHADOW_S
543 SREG = Yap_REGS.S_;
544#endif
545 // return to original deallocate
546 if (!d0) FAIL();
547 JMPNext();
548 ENDD(d0);
549 #endif
550 ENDOp();
551
552 /**********************************************
553 * OPTYap instructions *
554 **********************************************/
555
556#ifdef YAPOR
557#include "or.insts.h"
558#endif /* YAPOR */
559#ifdef TABLING
560#include "tab.insts.h"
561#include "tab.tries.insts.h"
562#endif /* TABLING */
563
564
565
566#ifdef BEAM
567 extern int eam_am(PredEntry *);
568
569 Op(retry_eam, e);
570 printf("Aqui estou eu..................\n");
571 if (!eam_am(2)) {
572 abort_eam("Falhei\n");
573 FAIL();
574 }
575
576 goto procceed;
577 PREG = NEXTOP(PREG, e);
578 GONext();
579 ENDOp();
580
581 Op(run_eam, os);
582 if (inp==-9000) { /* use indexing to find out valid alternatives */
583 extern CELL *beam_ALTERNATIVES;
584 *beam_ALTERNATIVES= (CELL *) PREG->y_u.os.opcw;
585 beam_ALTERNATIVES++;
586 if (OLD_B!=B) goto fail;
587#if PUSH_REGS
588 Yap_regp=old_regs;
589#endif
590 return(0);
591 }
592
593 saveregs();
594 if (!eam_am((PredEntry *) PREG->y_u.os.s)) FAIL();
595 setregs();
596
597 /* cut */
598 BACKUP_B();
599 while (POP_CHOICE_POINT(B->cp_b)) {
600 POP_EXECUTE();
601 }
602 B = B->cp_b; /* cut_fail */
603 HB = B->cp_h; /* cut_fail */
604 RECOVER_B();
605
606 if (0) { register choiceptr ccp;
607 /* initialize ccp */
608#define NORM_CP(CP) ((choiceptr)(CP))
609
610 YREG = (CELL *) (NORM_CP(YREG) - 1);
611 ccp = NORM_CP(YREG);
612 store_yaam_reg_cpdepth(ccp);
613 ccp->cp_tr = TR;
614 ccp->cp_ap = BEAM_RETRY_CODE;
615 ccp->cp_h = HR;
616 ccp->cp_b = B;
617 ccp->cp_env= ENV;
618 ccp->cp_cp = CPREG;
619 B = ccp;
620 SET_BB(B);
621 }
622 goto procceed;
623 PREG = NEXTOP(PREG, os);
624 GONext();
625 ENDOp();
626#endif
627
628
629
Definition: Yatom.h:544
Definition: amidefs.h:264