Skip to content

Commit

Permalink
Bytecode decoder support, MRB_BYTECODE_DECODE_OPTION
Browse files Browse the repository at this point in the history
  • Loading branch information
kaz0505 committed Sep 20, 2016
1 parent c698c67 commit 968ebac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions include/mruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ typedef struct mrb_state {
void (*debug_op_hook)(struct mrb_state* mrb, struct mrb_irep *irep, mrb_code *pc, mrb_value *regs);
#endif

#ifdef MRB_BYTECODE_DECODE_OPTION
void (*bytecode_decoder)(struct mrb_state* mrb, mrb_code *code);
#endif

struct RClass *eException_class;
struct RClass *eStandardError_class;
struct RObject *nomem_err; /* pre-allocated NoMemoryError */
Expand Down
13 changes: 10 additions & 3 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,13 +719,20 @@ argnum_error(mrb_state *mrb, mrb_int num)
#define CODE_FETCH_HOOK(mrb, irep, pc, regs)
#endif

#ifdef MRB_BYTECODE_DECODE_OPTION
#define BYTECODE_DECODER(x) if( (mrb)->bytecode_decoder ) (mrb)->bytecode_decoder((mrb), (x))
#else
#define BYTECODE_DECODER(x) (x);
#endif


#if defined __GNUC__ || defined __clang__ || defined __INTEL_COMPILER
#define DIRECT_THREADED
#endif

#ifndef DIRECT_THREADED

#define INIT_DISPATCH for (;;) { i = *pc; CODE_FETCH_HOOK(mrb, irep, pc, regs); switch (GET_OPCODE(i)) {
#define INIT_DISPATCH for (;;) { i = BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); switch (GET_OPCODE(i)) {
#define CASE(op) case op:
#define NEXT pc++; break
#define JUMP break
Expand All @@ -735,8 +742,8 @@ argnum_error(mrb_state *mrb, mrb_int num)

#define INIT_DISPATCH JUMP; return mrb_nil_value();
#define CASE(op) L_ ## op:
#define NEXT i=*++pc; CODE_FETCH_HOOK(mrb, irep, pc, regs); goto *optable[GET_OPCODE(i)]
#define JUMP i=*pc; CODE_FETCH_HOOK(mrb, irep, pc, regs); goto *optable[GET_OPCODE(i)]
#define NEXT i=BYTECODE_DECODER(*++pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); goto *optable[GET_OPCODE(i)]
#define JUMP i=BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); goto *optable[GET_OPCODE(i)]

#define END_DISPATCH

Expand Down

0 comments on commit 968ebac

Please sign in to comment.