Skip to content

Commit

Permalink
Revise scope of role of mrb_vm_run()
Browse files Browse the repository at this point in the history
`mrb_vm_run()` is,
  - It does not change the fiber context.
  - When control is returned, only one ci prepared by the caller is popped.
    If the ci equals cibase when called, the ci position does not change.

related commits:
  - commit 4e84bdb
  - commit 34dd258
  - commit ebd6636
  - commit c673635
  - commit 23a4e71
  - commit 31a961a
  • Loading branch information
dearblue committed Apr 21, 2024
1 parent ad476c3 commit 5aa20f4
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/vm.c
Expand Up @@ -1357,7 +1357,9 @@ mrb_vm_run(mrb_state *mrb, const struct RProc *proc, mrb_value self, mrb_int sta
const mrb_irep *irep = proc->body.irep;
mrb_value result;
struct mrb_context *c = mrb->c;
#ifdef MRB_DEBUG
ptrdiff_t cioff = c->ci - c->cibase;
#endif
mrb_int nregs = irep->nregs;

if (!c->stbase) {
Expand All @@ -1376,15 +1378,8 @@ mrb_vm_run(mrb_state *mrb, const struct RProc *proc, mrb_value self, mrb_int sta
stack_clear(c->ci->stack + stack_keep, nregs - stack_keep);
c->ci->stack[0] = self;
result = mrb_vm_exec(mrb, proc, irep->iseq);
if (mrb->c != c) {
if (mrb->c->fib) {
mrb_write_barrier(mrb, (struct RBasic*)mrb->c->fib);
}
mrb->c = c;
}
else if (c->ci - c->cibase > cioff) {
c->ci = c->cibase + cioff;
}
mrb_assert(mrb->c == c); /* do not switch fibers via mrb_vm_run(), unlike mrb_vm_exec() */
mrb_assert(c->ci == c->cibase || (c->ci - c->cibase) == cioff - 1);
return result;
}

Expand Down

0 comments on commit 5aa20f4

Please sign in to comment.