Simplify rescue stack management; ref #3683

parent 7ff90b52
...@@ -112,7 +112,7 @@ typedef struct { ...@@ -112,7 +112,7 @@ typedef struct {
struct RProc *proc; struct RProc *proc;
mrb_value *stackent; mrb_value *stackent;
int nregs; int nregs;
int ridx; int rpos;
int epos; int epos;
struct REnv *env; struct REnv *env;
mrb_code *pc; /* return address */ mrb_code *pc; /* return address */
...@@ -141,7 +141,7 @@ struct mrb_context { ...@@ -141,7 +141,7 @@ struct mrb_context {
mrb_callinfo *cibase, *ciend; mrb_callinfo *cibase, *ciend;
mrb_code **rescue; /* exception handler stack */ mrb_code **rescue; /* exception handler stack */
int rsize; int rsize, ridx;
struct RProc **ensure; /* ensure handler stack */ struct RProc **ensure; /* ensure handler stack */
int esize, eidx; int esize, eidx;
......
...@@ -234,8 +234,6 @@ cipush(mrb_state *mrb) ...@@ -234,8 +234,6 @@ cipush(mrb_state *mrb)
struct mrb_context *c = mrb->c; struct mrb_context *c = mrb->c;
mrb_callinfo *ci = c->ci; mrb_callinfo *ci = c->ci;
int ridx = ci->ridx;
if (ci + 1 == c->ciend) { if (ci + 1 == c->ciend) {
ptrdiff_t size = ci - c->cibase; ptrdiff_t size = ci - c->cibase;
...@@ -245,7 +243,7 @@ cipush(mrb_state *mrb) ...@@ -245,7 +243,7 @@ cipush(mrb_state *mrb)
} }
ci = ++c->ci; ci = ++c->ci;
ci->epos = mrb->c->eidx; ci->epos = mrb->c->eidx;
ci->ridx = ridx; ci->rpos = mrb->c->ridx;
ci->env = 0; ci->env = 0;
ci->pc = 0; ci->pc = 0;
ci->err = 0; ci->err = 0;
...@@ -1125,12 +1123,12 @@ RETRY_TRY_BLOCK: ...@@ -1125,12 +1123,12 @@ RETRY_TRY_BLOCK:
CASE(OP_ONERR) { CASE(OP_ONERR) {
/* sBx pc+=sBx on exception */ /* sBx pc+=sBx on exception */
if (mrb->c->rsize <= mrb->c->ci->ridx) { if (mrb->c->rsize <= mrb->c->ridx) {
if (mrb->c->rsize == 0) mrb->c->rsize = RESCUE_STACK_INIT_SIZE; if (mrb->c->rsize == 0) mrb->c->rsize = RESCUE_STACK_INIT_SIZE;
else mrb->c->rsize *= 2; else mrb->c->rsize *= 2;
mrb->c->rescue = (mrb_code **)mrb_realloc(mrb, mrb->c->rescue, sizeof(mrb_code*) * mrb->c->rsize); mrb->c->rescue = (mrb_code **)mrb_realloc(mrb, mrb->c->rescue, sizeof(mrb_code*) * mrb->c->rsize);
} }
mrb->c->rescue[mrb->c->ci->ridx++] = pc + GETARG_sBx(i); mrb->c->rescue[mrb->c->ridx++] = pc + GETARG_sBx(i);
NEXT; NEXT;
} }
...@@ -1180,7 +1178,7 @@ RETRY_TRY_BLOCK: ...@@ -1180,7 +1178,7 @@ RETRY_TRY_BLOCK:
int a = GETARG_A(i); int a = GETARG_A(i);
while (a--) { while (a--) {
mrb->c->ci->ridx--; mrb->c->ridx--;
} }
NEXT; NEXT;
} }
...@@ -1757,11 +1755,11 @@ RETRY_TRY_BLOCK: ...@@ -1757,11 +1755,11 @@ RETRY_TRY_BLOCK:
L_RAISE: L_RAISE:
ci0 = ci = mrb->c->ci; ci0 = ci = mrb->c->ci;
if (ci == mrb->c->cibase) { if (ci == mrb->c->cibase) {
if (ci->ridx == 0) goto L_FTOP; if (mrb->c->ridx == 0) goto L_FTOP;
goto L_RESCUE; goto L_RESCUE;
} }
stk = mrb->c->stack; stk = mrb->c->stack;
while (ci[0].ridx == ci[-1].ridx) { while (mrb->c->ridx == ci->rpos) {
cipop(mrb); cipop(mrb);
mrb->c->stack = ci->stackent; mrb->c->stack = ci->stackent;
if (ci->acc == CI_ACC_SKIP && prev_jmp) { if (ci->acc == CI_ACC_SKIP && prev_jmp) {
...@@ -1771,7 +1769,7 @@ RETRY_TRY_BLOCK: ...@@ -1771,7 +1769,7 @@ RETRY_TRY_BLOCK:
ci = mrb->c->ci; ci = mrb->c->ci;
if (ci == mrb->c->cibase) { if (ci == mrb->c->cibase) {
mrb->c->stack = stk; mrb->c->stack = stk;
if (ci->ridx == 0) { if (mrb->c->ridx == 0) {
L_FTOP: /* fiber top */ L_FTOP: /* fiber top */
if (mrb->c == mrb->root_c) { if (mrb->c == mrb->root_c) {
mrb->c->stack = mrb->c->stbase; mrb->c->stack = mrb->c->stbase;
...@@ -1788,7 +1786,7 @@ RETRY_TRY_BLOCK: ...@@ -1788,7 +1786,7 @@ RETRY_TRY_BLOCK:
break; break;
} }
/* call ensure only when we skip this callinfo */ /* call ensure only when we skip this callinfo */
if (ci[0].ridx == ci[-1].ridx) { if (mrb->c->ridx == ci->rpos) {
while (mrb->c->eidx > ci->epos) { while (mrb->c->eidx > ci->epos) {
ecall(mrb, --mrb->c->eidx); ecall(mrb, --mrb->c->eidx);
ci = mrb->c->ci; ci = mrb->c->ci;
...@@ -1796,7 +1794,7 @@ RETRY_TRY_BLOCK: ...@@ -1796,7 +1794,7 @@ RETRY_TRY_BLOCK:
} }
} }
L_RESCUE: L_RESCUE:
if (ci->ridx == 0) goto L_STOP; if (mrb->c->ridx == 0) goto L_STOP;
proc = ci->proc; proc = ci->proc;
irep = proc->body.irep; irep = proc->body.irep;
pool = irep->pool; pool = irep->pool;
...@@ -1804,7 +1802,7 @@ RETRY_TRY_BLOCK: ...@@ -1804,7 +1802,7 @@ RETRY_TRY_BLOCK:
if (ci != ci0) { if (ci != ci0) {
mrb->c->stack = ci[1].stackent; mrb->c->stack = ci[1].stackent;
} }
pc = mrb->c->rescue[--ci->ridx]; pc = mrb->c->rescue[--mrb->c->ridx];
} }
else { else {
mrb_callinfo *ci = mrb->c->ci; mrb_callinfo *ci = mrb->c->ci;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment