Skip to content

Commit 209ae86

Browse files
authored
Merge pull request mruby#6670 from dearblue/vm
2 parents 2714280 + 50ecc1f commit 209ae86

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

src/vm.c

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,46 +1517,36 @@ prepare_tagged_break(mrb_state *mrb, uint32_t tag, const mrb_callinfo *return_ci
15171517

15181518
#ifdef MRB_USE_VM_SWITCH_DISPATCH
15191519

1520-
#define INIT_DISPATCH for (;;) { insn = BYTECODE_DECODER(*ci->pc); CODE_FETCH_HOOK(mrb, irep, ci->pc, regs); switch (insn) {
1521-
#define CASE(insn,ops) case insn: { const mrb_code *pc = ci->pc+1; FETCH_ ## ops (); ci->pc = pc; } L_ ## insn ## _BODY:
1520+
#define INIT_DISPATCH for (;;) { CALL_CODE_HOOKS(); switch (insn) {
1521+
#define CASE(insn,ops) case insn: DECODE_OPERANDS(ops); L_ ## insn ## _BODY:
15221522
#define NEXT goto L_END_DISPATCH
15231523
#define JUMP NEXT
1524-
#ifdef MRB_USE_TASK_SCHEDULER
1525-
#define END_DISPATCH L_END_DISPATCH: \
1526-
if (mrb->task.switching || mrb->c->status == MRB_TASK_STOPPED) \
1527-
return mrb_nil_value(); \
1528-
}}
1529-
#else
1530-
#define END_DISPATCH L_END_DISPATCH:;}}
1531-
#endif
1524+
#define END_DISPATCH L_END_DISPATCH: RETURN_IF_TASK_STOPPED(mrb);}}
15321525

15331526
#else
15341527

15351528
#define INIT_DISPATCH JUMP; return mrb_nil_value();
1536-
#define CASE(insn,ops) L_ ## insn: { const mrb_code *pc = ci->pc+1; FETCH_ ## ops (); ci->pc = pc; } L_ ## insn ## _BODY:
1537-
#ifdef MRB_USE_TASK_SCHEDULER
1538-
#define NEXT if (mrb->task.switching || mrb->c->status == MRB_TASK_STOPPED) return mrb_nil_value(); \
1539-
insn=BYTECODE_DECODER(*ci->pc); CODE_FETCH_HOOK(mrb, irep, ci->pc, regs); goto *optable[insn]
1540-
#else
1541-
#define NEXT insn=BYTECODE_DECODER(*ci->pc); CODE_FETCH_HOOK(mrb, irep, ci->pc, regs); goto *optable[insn]
1542-
#endif
1529+
#define CASE(insn,ops) L_ ## insn: DECODE_OPERANDS(ops); L_ ## insn ## _BODY:
1530+
#define NEXT RETURN_IF_TASK_STOPPED(mrb); CALL_CODE_HOOKS(); goto *optable[insn]
15431531
#define JUMP NEXT
1532+
#define END_DISPATCH RETURN_IF_TASK_STOPPED(mrb)
15441533

1545-
#ifdef MRB_USE_TASK_SCHEDULER
1546-
#define END_DISPATCH \
1547-
if (mrb->task.switching || mrb->c->status == MRB_TASK_STOPPED) \
1548-
return mrb_nil_value();
1549-
#else
1550-
#define END_DISPATCH
15511534
#endif
15521535

1553-
#endif
1536+
#define DECODE_OPERANDS(ops) do { const mrb_code *pc = ci->pc+1; FETCH_ ## ops (); ci->pc = pc; } while (0)
1537+
#define CALL_CODE_HOOKS() do { insn = BYTECODE_DECODER(*ci->pc); CODE_FETCH_HOOK(mrb, irep, ci->pc, regs); } while (0)
15541538

15551539
#ifdef MRB_USE_TASK_SCHEDULER
1556-
#define TASK_STOP(mrb) \
1540+
#define RETURN_IF_TASK_STOPPED(mrb) do { \
1541+
if ((mrb)->task.switching || (mrb)->c->status == MRB_TASK_STOPPED) \
1542+
return mrb_nil_value(); \
1543+
} while (0)
1544+
#define TASK_STOP(mrb) do { \
15571545
if (mrb->c->status != MRB_TASK_STOPPED) \
1558-
mrb->c->status = MRB_TASK_STOPPED;
1546+
mrb->c->status = MRB_TASK_STOPPED; \
1547+
} while (0)
15591548
#else
1549+
#define RETURN_IF_TASK_STOPPED(mrb)
15601550
#define TASK_STOP(mrb)
15611551
#endif
15621552

0 commit comments

Comments
 (0)