From 130d28ceb37b125bcafeb32afa0f6977aee7beaa Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Thu, 23 Oct 2014 02:10:55 +0100 Subject: [PATCH] recover space after portray --- C/exec.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ C/write.c | 3 +++ H/Yapproto.h | 1 + 3 files changed, 49 insertions(+) diff --git a/C/exec.c b/C/exec.c index c9259b2e6..30999f03c 100755 --- a/C/exec.c +++ b/C/exec.c @@ -1206,6 +1206,51 @@ Yap_exec_absmi(bool top, yap_reset_t has_reset) } +void +Yap_fail_all( choiceptr bb USES_REGS ) +{ + yamop *saved_p, *saved_cp; + + saved_p = P; + saved_cp = CP; + /* prune away choicepoints */ + while (B && B->cp_b != bb) { + B = B->cp_b; +#ifdef YAPOR + CUT_prune_to(B); +#endif + } + P = FAILCODE; + Yap_exec_absmi( true, YAP_EXEC_ABSMI); + /* recover stack space */ + HR = B->cp_h; + TR = B->cp_tr; +#ifdef DEPTH_LIMIT + DEPTH = B->cp_depth; +#endif /* DEPTH_LIMIT */ + YENV = ENV = B->cp_env; + /* recover local stack */ +#ifdef DEPTH_LIMIT + DEPTH= ENV[E_DEPTH]; +#endif + /* make sure we prune C-choicepoints */ + if (POP_CHOICE_POINT(B->cp_b)) + { + POP_EXECUTE(); + } + ENV = (CELL *)(ENV[E_E]); + /* ASP should be set to the top of the local stack when we + did the call */ + ASP = B->cp_env; + /* YENV should be set to the current environment */ + YENV = ENV = (CELL *)((B->cp_env)[E_E]); + B = B->cp_b; + //SET_BB(B); + HB = PROTECT_FROZEN_H(B); + CP = saved_cp; + P = saved_p; +} + int Yap_execute_pred(PredEntry *ppe, CELL *pt USES_REGS) { diff --git a/C/write.c b/C/write.c index bba608e45..ec7df439a 100644 --- a/C/write.c +++ b/C/write.c @@ -87,13 +87,16 @@ static bool callPortray(Term t, struct DB_TERM **old_EXp USES_REGS) { PredEntry *pe; + Int b0 = LCL0-(CELL*)B; EX = NULL; if ( (pe = RepPredProp(Yap_GetPredPropByFunc(FunctorPortray, USER_MODULE) ) ) && pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE && Yap_execute_pred(pe, &t PASS_REGS) ) { + choiceptr B0 = (choiceptr)(LCL0-b0); if (EX && !*old_EXp) *old_EXp = EX; + Yap_fail_all(B0 PASS_REGS); return true; } if (EX && !*old_EXp) *old_EXp = EX; diff --git a/H/Yapproto.h b/H/Yapproto.h index 471d33976..a624f2be0 100755 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -176,6 +176,7 @@ int Yap_SWIHandleError( const char *, ... ); void Yap_InitEval(void); /* exec.c */ +void Yap_fail_all( choiceptr bb USES_REGS); Term Yap_ExecuteCallMetaCall(Term); void Yap_InitExecFs(void); Int Yap_JumpToEnv(Term);