YAP 7.1.0
meta_absmi_insts.h
1
2#ifdef INDENT_CODE
3{
4 {
5 {
6#endif /* INDENT_CODE */
7
8 /* join all the meta-call code into a single procedure with three entry points */
9 {
10 CACHE_Y_AS_ENV(YREG);
11 BEGD(d0); /* term to be meta-called */
12 Term mod; /* module to be used */
13 PredEntry *pen; /* predicate */
14 choiceptr b_ptr; /* cut point */
15 Functor f;
16
17 /* we are doing the rhs of a , */
18 BOp(p_execute_tail, Osbmp);
19
20 FETCH_Y_FROM_ENV(YREG);
21 /* place to cut to */
22 b_ptr = (choiceptr)ENV_YREG[E_CB];
23 /* original goal */
24 d0 = ENV_YREG[-EnvSizeInCells-1];
25 /* predicate we had used */
26 pen = RepPredProp(AddressOfTerm(ENV_YREG[-EnvSizeInCells-2]));
27 /* current module at the time */
28 mod = ENV_YREG[-EnvSizeInCells-3];
29 /* set YREG */
30 /* Try to preserve the environment */
31 ENV_YREG = (CELL *) (((char *) YREG) + PREG->y_u.Osbmp.s);
32#ifdef FROZEN_STACKS
33 {
34 choiceptr top_b = PROTECT_FROZEN_B(B);
35#ifdef YAPOR_SBA
36 if (ENV_YREG > (CELL *) top_b || ENV_YREG < HR) ENV_YREG = (CELL *) top_b;
37#else
38 if (ENV_YREG > (CELL *) top_b) ENV_YREG = (CELL *) top_b;
39#endif /* YAPOR_SBA */
40 }
41#else
42 if (ENV_YREG > (CELL *) B) {
43 ENV_YREG = (CELL *) B;
44 ≈ }
45#endif /* FROZEN_STACKS */
46 /* now, jump to actual execution */
47 if (pen->ArityOfPE) {
48 f = pen->FunctorOfPred;
49 /* reuse environment if we are continuining a comma, ie, (g1,g2,g3) */
50 /* can only do it deterministically */
51 /* broken
52 if (f == FunctorComma && (CELL *)B >= ENV) {
53 ENV_YREG = ENV;
54 ENV = (CELL *)ENV[E_E];
55 }
56 */
57 goto execute_pred_f;
58 } else
59 goto execute_pred_a;
60 ENDBOp();
61
62 /* fetch the module from ARG2 */
63 BOp(p_execute2, Osbpp);
64
65 mod = ARG2;
66 deref_head(mod, execute2_unk0);
67 execute2_nvar0:
68 if (!IsAtomTerm(mod)) {
69 saveregs();
70 Yap_Error(TYPE_ERROR_ATOM, mod, "call/2");
71 setregs();
72 }
73 goto start_execute;
74
75 BEGP(pt1);
76 deref_body(mod, pt1, execute2_unk0, execute2_nvar0);
77 saveregs();
78 Yap_Error(INSTANTIATION_ERROR, mod, "call/2");
79 setregs();
80 ENDP(pt1);
81 /* Oops, second argument was unbound too */
82 FAIL();
83 ENDBOp();
84
85 BOp(p_execute, Osbmp);
86 /* fetch the module from PREG */
87#ifndef NO_CHECKING
88 check_stack(NoStackPExecute, HR);
89#endif
90 mod = PREG->y_u.Osbmp.p0->ModuleOfPred;
91 start_execute:
92 /* place to cut to */
93 b_ptr = B;
94 /* we have mod, and ARG1 has the goal, let us roll */
95 /* Try to preserve the environment */
96 ENV_YREG = (CELL *) (((char *) YREG) + PREG->y_u.Osbmp.s);
97#ifdef FROZEN_STACKS
98 {
99 choiceptr top_b = PROTECT_FROZEN_B(B);
100#ifdef YAPOR_SBA
101 if (ENV_YREG > (CELL *) top_b || ENV_YREG < HR) ENV_YREG = (CELL *) top_b;
102#else
103 if (ENV_YREG > (CELL *) top_b) ENV_YREG = (CELL *) top_b;
104#endif /* YAPOR_SBA */
105 }
106#else
107 if (ENV_YREG > (CELL *) B) {
108 ENV_YREG = (CELL *) B;
109 }
110#endif /* FROZEN_STACKS */
111 d0 = ARG1;
112 d0 = Yap_YapStripModule(d0,&mod);
113 restart_execute:
114 deref_head(d0, execute_unk);
115 execute_nvar:
116 if (IsApplTerm(d0)) {
117 f = FunctorOfTerm(d0);
118 if (IsExtensionFunctor(f)) {
119 goto execute_metacall;
120 }
121 pen = RepPredProp(PredPropByFunc(f, mod));
122 execute_pred_f:
123
124 if (f == FunctorComma) {
125 Term nmod = mod;
126
127 /* optimise conj */
128 SREG = RepAppl(d0);
129 BEGD(d1);
130 d1 = SREG[2];
131 /* create an environment to execute the call */
132 deref_head(d1, execute_comma_unk);
133 execute_comma_nvar:
134 if (IsAtomTerm(d1)) {
135 /* atomic goal is simpler */
136 ENV_YREG[-EnvSizeInCells-2] = MkIntegerTerm((Int)PredPropByAtom(AtomOfTerm(d1),nmod));
137 } else if (IsApplTerm(d1)) {
138 Term nmod = mod;
139 d1 = Yap_YapStripModule(d1, &nmod);
140 Functor f1 = FunctorOfTerm(d1);
141 ENV_YREG[-EnvSizeInCells-2] = MkIntegerTerm((Int)PredPropByFunc(f1,nmod));
142 }
143 ENV_YREG[-EnvSizeInCells-3] = mod;
144 /* now, we can create the new environment for the meta-call */
145 /* notice that we are at a call, so we should ignore CP */
146 ENV_YREG[E_CP] = (CELL)NEXTOP(PREG,Osbmp);
147 ENV_YREG[E_CB] = (CELL)b_ptr;
148 ENV_YREG[E_E] = (CELL)ENV;
149#ifdef DEPTH_LIMIT
150 ENV_YREG[E_DEPTH] = DEPTH;
151#endif /* DEPTH_LIMIT */
152 ENV_YREG[-EnvSizeInCells-1] = d1;
153 ENV = ENV_YREG;
154 ENV_YREG -= EnvSizeInCells+3;
155 CPREG = NEXTOP(PREG, Osbmp);
156 PREG = COMMA_CODE;
157 /* for profiler */
158 save_pc();
159 d0 = SREG[1];
160 goto restart_execute;
161
162 BEGP(pt1);
163 deref_body(d1, pt1, execute_comma_unk, execute_comma_nvar);
164 goto execute_metacall;
165 ENDP(pt1);
166 ENDD(d1);
167 } else if (mod != CurrentModule) {
168 goto execute_metacall;
169 }
170
171
172 /* copy arguments of meta-call to XREGS */
173 BEGP(pt1);
174 pt1 = RepAppl(d0);
175 BEGD(d2);
176 for (d2 = ArityOfFunctor(f); d2; d2--) {
177#ifdef YAPOR_SBA
178 d1 = pt1[d2];
179 if (d1 == 0) {
180 XREGS[d2] = (CELL)(pt1+d2);
181 } else {
182 XREGS[d2] = d1;
183 }
184#else
185 XREGS[d2] = pt1[d2];
186#endif
187 }
188 ENDD(d2);
189 ENDP(pt1);
190 CACHE_A1();
191
192 }else if (IsAtomTerm(d0)) {
193 pen = RepPredProp(PredPropByAtom(AtomOfTerm(d0), mod));
194 execute_pred_a:
195 /* handle extra pruning */
196 if (pen->FunctorOfPred == (Functor)AtomCut) {
197 if (b_ptr != B) {
198 saveregs();
199 prune(b_ptr PASS_REGS);
200 setregs();
201 }
202 }
203 } else {
204 goto execute_metacall;
205 }
206 }
207
208 /* execute, but test first for interrupts */
209 execute_end:
210 /* code copied from call */
211 execute_stack_checked:
212 CPREG = NEXTOP(PREG, Osbmp);
213 ALWAYS_LOOKAHEAD(pen->OpcodeOfPred);
214 PREG = pen->CodeOfPred;
215 /* for profiler */
216 save_pc();
217#ifdef DEPTH_LIMIT
218 if (DEPTH <= MkIntTerm(1)) {/* I assume Module==0 is primitives */
219 if (pen->ModuleOfPred) {
220 if (DEPTH == MkIntTerm(0)) {
221 FAIL();
222 } else {
223 DEPTH = RESET_DEPTH();
224 }
225 }
226 } else if (pen->ModuleOfPred)
227 DEPTH -= MkIntConstant(2);
228#endif /* DEPTH_LIMIT */
229#ifdef LOW_LEVEL_TRACER
230 if (Yap_do_low_level_trace)
231 low_level_trace(enter_pred,pen,XREGS+1);
232#endif /* LOW_LEVEL_TRACER */
233 WRITEBACK_Y_AS_ENV();
234 /* setup GB */
235 ENV_YREG[E_CB] = (CELL) B;
236#ifdef YAPOR
237 SCH_check_requests();
238#endif /* YAPOR */
239 CACHE_A1();
240 ALWAYS_GONext();
241 ALWAYS_END_PREFETCH();
242
243 /* meta-call: Prolog to the rescue */
244 BEGP(pt1);
245 deref_body(d0, pt1, execute_unk, execute_nvar);
246 execute_metacall:
247 ARG1 = ARG3 = d0;
248 pen = PredMetaCall;
249 ARG2 = Yap_cp_as_integer(b_ptr);
250 if (mod)
251 ARG4 = mod;
252 else
253 ARG4 = TermProlog;
254 goto execute_end;
255 ENDP(pt1);
256
257 /* at this point, we have the arguments all set in the argument registers, pen says who is the current predicate. don't remove. */
258 NoStackPExecute:
259 WRITEBACK_Y_AS_ENV();
260#ifdef SHADOW_S
261 Yap_REGS.S_ = SREG;
262#endif
263 saveregs_and_ycache();
264 d0 = interrupt_pexecute( PASS_REGS1 );
265 setregs_and_ycache();
266#ifdef SHADOW_S
267 SREG = Yap_REGS.S_;
268#endif
269 if (!d0) FAIL();
270 if (d0 == 2) goto execute_stack_checked;
271 goto execute_end;
272 ENDBOp();
273
274 ENDD(d0);
275 ENDCACHE_Y_AS_ENV();
276#ifdef INDENT_CODE
277 }
278 }
279}
280#endif
Definition: Yatom.h:544