From ffc094e25f2ca7f9897c9064d4a532df4828ece4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Mon, 2 Aug 2010 18:20:03 +0100 Subject: [PATCH] make sure we have enough room before we enter a clause. --- C/absmi.c | 15 +++++++++------ C/amasm.c | 10 ++++++---- H/YapOpcodes.h | 2 +- H/amidefs.h | 10 ++++++++++ H/findclause.h | 6 +++--- H/rclause.h | 20 ++++++++++---------- H/walkclause.h | 8 ++++---- 7 files changed, 43 insertions(+), 28 deletions(-) diff --git a/C/absmi.c b/C/absmi.c index 74cb0b05c..ddd1b93ef 100755 --- a/C/absmi.c +++ b/C/absmi.c @@ -1675,18 +1675,21 @@ Yap_absmi(int inp) *****************************************************************/ /* ensure_space */ - BOp(ensure_space, ip); + BOp(ensure_space, Osbpi); { - Int sz = PREG->u.ip.i; - fprintf(stderr,"ensuring %ld\n", sz); - PREG = NEXTOP(PREG,ip); + Int sz = PREG->u.Osbpi.i; + PREG = NEXTOP(PREG,Osbpi); if (Unsigned(H) + sz > Unsigned(YREG)-CreepFlag) { + YENV[E_CP] = (CELL) CPREG; + YENV[E_E] = (CELL) ENV; +#ifdef DEPTH_LIMIT + YENV[E_DEPTH] = DEPTH; +#endif /* DEPTH_LIMIT */ ASP = YREG+E_CB; if (ASP > (CELL *)PROTECT_FROZEN_B(B)) ASP = (CELL *)PROTECT_FROZEN_B(B); saveregs(); - if (!Yap_gcl(sz, 0, ENV, NEXTOP(PREG,ip))) { - PREG = NEXTOP(PREG,ip); + if (!Yap_gcl(sz, 0, YENV, PREG)) { Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage); setregs(); FAIL(); diff --git a/C/amasm.c b/C/amasm.c index e02bdf653..bdcb48a75 100755 --- a/C/amasm.c +++ b/C/amasm.c @@ -1098,13 +1098,15 @@ a_blob(CELL rnd1, op_numbers opcode, int *clause_has_blobsp, yamop *code_p, int static yamop * a_ensure_space(op_numbers opcode, yamop *code_p, int pass_no, struct intermediates *cip, clause_info *clinfo) { - if (cip->cpc->rnd1 > 4096 && FALSE) { + if (cip->cpc->rnd1 > 4096) { if (pass_no) { code_p->opc = emit_op(opcode); - code_p->u.ip.i = sizeof(CELL) * cip->cpc->rnd1; - code_p->u.ip.p = clinfo->CurrentPred; + code_p->u.Osbpi.i = sizeof(CELL) * cip->cpc->rnd1; + code_p->u.Osbpi.p = clinfo->CurrentPred; + code_p->u.Osbpi.bmap = NULL; + code_p->u.Osbpi.s = emit_count(-Signed(RealEnvSize)); } - GONEXT(ip); + GONEXT(Osbpi); } return code_p; } diff --git a/H/YapOpcodes.h b/H/YapOpcodes.h index 9c706e15b..740093710 100644 --- a/H/YapOpcodes.h +++ b/H/YapOpcodes.h @@ -24,7 +24,7 @@ OPCODE(alloc_for_logical_pred ,L), OPCODE(copy_idb_term ,e), OPCODE(unify_idb_term ,e), - OPCODE(ensure_space ,ip), + OPCODE(ensure_space ,Osbpi), OPCODE(spy_or_trymark ,Otapl), OPCODE(try_and_mark ,Otapl), OPCODE(count_retry_and_mark ,Otapl), diff --git a/H/amidefs.h b/H/amidefs.h index e18e68a40..c74c5263b 100644 --- a/H/amidefs.h +++ b/H/amidefs.h @@ -654,6 +654,16 @@ typedef struct yami { struct { #ifdef YAPOR unsigned int or_arg; +#endif + COUNT s; + CELL *bmap; + struct pred_entry *p; + Int i; + CELL next; + } Osbpi; + struct { +#ifdef YAPOR + unsigned int or_arg; #endif COUNT s; CELL *bmap; diff --git a/H/findclause.h b/H/findclause.h index eb8899109..e6fc557f2 100644 --- a/H/findclause.h +++ b/H/findclause.h @@ -9,6 +9,9 @@ case _alloc_for_logical_pred: cl = NEXTOP(cl,L); break; + case _ensure_space: + cl = NEXTOP(cl,Osbpi); + break; case _native_me: cl = NEXTOP(cl,aFlp); break; @@ -289,9 +292,6 @@ case _write_longint: cl = NEXTOP(cl,i); break; - case _ensure_space: - cl = NEXTOP(cl,ip); - break; case _unify_l_list: cl = NEXTOP(cl,o); break; diff --git a/H/rclause.h b/H/rclause.h index 5acb6dfc0..a99ecc17e 100644 --- a/H/rclause.h +++ b/H/rclause.h @@ -44,10 +44,16 @@ restore_opcodes(yamop *pc, yamop *max) case _p_execute: OrArgAdjust(pc->u.Osbmp.or_arg); pc->u.Osbmp.s = ConstantAdjust(pc->u.Osbmp.s); - pc->u.Osbmp.bmap = CellPtoHeapAdjust(pc->u.Osbmp.bmap); - pc->u.Osbmp.mod = ModuleAdjust(pc->u.Osbmp.mod); - pc->u.Osbmp.p0 = PtoPredAdjust(pc->u.Osbmp.p0); - pc = NEXTOP(pc,Osbmp); + pc->u.Osbmp.mod = CellPtoHeapAdjust(pc->u.Osbmp.mod); + pc->u.Osbmp.p0 = ModuleAdjust(pc->u.Osbmp.p0); + /* instructions type Osbpi */ + case _ensure_space: + OrArgAdjust(pc->u.Osbpi.or_arg); + pc->u.Osbpi.s = ConstantAdjust(pc->u.Osbpi.s); + pc->u.Osbpi.bmap = CellPtoHeapAdjust(pc->u.Osbpi.bmap); + pc->u.Osbpi.p = PtoPredAdjust(pc->u.Osbpi.p); + IntegerInCodeAdjust(pc->u.Osbpi.i); + pc = NEXTOP(pc,Osbpi); break; /* instructions type Osbpp */ case _call: @@ -240,12 +246,6 @@ restore_opcodes(yamop *pc, yamop *max) IntegerInCodeAdjust(pc->u.i.i); pc = NEXTOP(pc,i); break; - /* instructions type ip */ - case _ensure_space: - IntegerInCodeAdjust(pc->u.ip.i); - pc->u.ip.p = PtoPredAdjust(pc->u.ip.p); - pc = NEXTOP(pc,ip); - break; /* instructions type l */ case _Ystop: case _jump: diff --git a/H/walkclause.h b/H/walkclause.h index f174a3fc1..f73e9114b 100644 --- a/H/walkclause.h +++ b/H/walkclause.h @@ -26,6 +26,10 @@ case _p_execute: pc = NEXTOP(pc,Osbmp); break; + /* instructions type Osbpi */ + case _ensure_space: + pc = NEXTOP(pc,Osbpi); + break; /* instructions type Osbpp */ case _call_cpred: pp = pc->u.Osbpp.p; @@ -184,10 +188,6 @@ case _write_longint: pc = NEXTOP(pc,i); break; - /* instructions type ip */ - case _ensure_space: - pc = NEXTOP(pc,ip); - break; /* instructions type l */ case _Ystop: return found_ystop(pc, clause_code, startp, endp, pp);