/*-------------------------------------------------------------------------* * PL_CALL_PROLOG * * * * Call_Prolog runs the execution of one prolog goal. * * The current choice point is updated to set ALTB to Call_Prolog_Fail and * * CP is set to Call_Prolog_Success. At the end ALTB and CP are restored. * * To ensure that a choice point always exists before invoking Call_Prolog,* * Start_Prolog reserve the space for a feint choice point, i.e ALTB can be* * safely modified. * * * * Call_Prolog returns TRUE if the predicate has succeed, FALSE otherwise. * * The called predicate can be non-deterministic. * *-------------------------------------------------------------------------*/ Bool Pl_Call_Prolog(CodePtr codep) { WamWord *query_b = B; WamCont save_CP = CP; WamCont save_ALTB = ALTB(query_b); Bool ok; ALTB(query_b) = (CodePtr) Call_Prolog_Fail; /* modify choice point */ CP = Adjust_CP(Call_Prolog_Success); #if defined(_WIN32) || defined(__CYGWIN__) SEH_PUSH(Win32_SEH_Handler); #endif ok = Call_Next(codep); #if defined(_WIN32) || defined(__CYGWIN__) SEH_POP; #endif CP = save_CP; /* restore continuation */ ALTB(query_b) = save_ALTB; /* restore choice point */ return ok; }
void test_jump_and_c_ret(void) { printf("jump/c_ret...\n"); ALTB(B) = (WamCont) error; Init_CP(error); ma_test_jump_and_c_ret(); }
/*-------------------------------------------------------------------------* * PL_CALL_PROLOG_NEXT_SOL * * * * Call_Prolog_Next_Sol bactracks over the next solution. * *-------------------------------------------------------------------------*/ Bool Pl_Call_Prolog_Next_Sol(WamWord *query_b) { WamCont save_CP = CP; WamCont save_ALTB = ALTB(query_b); Bool ok; ALTB(query_b) = (CodePtr) Call_Prolog_Fail; /* modify choice point */ CP = Adjust_CP(Call_Prolog_Success); /* should be useless since */ /* alternative will restore CP */ ok = Call_Next(ALTB(B)); CP = save_CP; /* restore continuation */ ALTB(query_b) = save_ALTB; /* restore choice point */ return ok; }
/*-------------------------------------------------------------------------* * PL_CALL_PROLOG * * * * Call_Prolog runs the execution of one prolog goal. * * The current choice point is updated to set ALTB to Call_Prolog_Fail and * * CP is set to Call_Prolog_Success. At the end ALTB and CP are restored. * * To ensure that a choice point always exists before invoking Call_Prolog,* * Start_Prolog reserve the space for a feint choice point, i.e ALTB can be* * safely modified. * * * * Call_Prolog returns TRUE if the predicate has succeed, FALSE otherwise. * * The called predicate can be non-deterministic. * *-------------------------------------------------------------------------*/ Bool Pl_Call_Prolog(CodePtr codep) { WamWord *query_b = B; WamCont save_CP = CP; WamCont save_ALTB = ALTB(query_b); Bool ok; ALTB(query_b) = (CodePtr) Call_Prolog_Fail; /* modify choice point */ CP = Adjust_CP(Call_Prolog_Success); ok = Call_Next(codep); CP = save_CP; /* restore continuation */ ALTB(query_b) = save_ALTB; /* restore choice point */ return ok; }
void test_switch_ret(void) { printf("call_c()+switch_ret...\n"); ALTB(B) = (WamCont) error; for (i = 0; swt[i] >= 0; i++) Call_Pl(ma_test_switch_ret, 1); Call_Pl(ma_test_switch_ret, 0); /* here swt[i]= -1 switch should fail */ }
/*-------------------------------------------------------------------------* * PL_QUERY_END * * * *-------------------------------------------------------------------------*/ void Pl_Query_End(int op) { WamWord *query_b, *prev_b, *b; Bool recoverable; if (query_stack_top == query_stack) Pl_Fatal_Error("Pl_Query_End() but no query remaining"); query_b = *--query_stack_top; pl_query_top_b = query_stack_top[-1]; recoverable = (ALTB(query_b) == Prolog_Predicate(PL_QUERY_RECOVER_ALT, 0)); prev_b = BB(query_b); switch (op) { case PL_RECOVER: Assign_B(query_b); if (!recoverable) Pl_Fatal_Error("Pl_Query_End(PL_RECOVER) but unrecoverable query"); Pl_Delete_Choice_Point(0); /* remove recover chc-point */ break; case PL_CUT: Assign_B((recoverable) ? prev_b : query_b); break; default: /* case PL_KEEP_FOR_PROLOG */ if (recoverable) { if (B == query_b) Assign_B(prev_b); else for (b = B; b > query_b; b = BB(b)) /* unlink recover chc-point */ if (BB(b) == query_b) BB(b) = prev_b; } Pl_Keep_Rest_For_Prolog(query_b); } }
void TRANS_pl_fail() { M_Indirect_Goto(ALTB(B)); }