| 1 |
/** |
| 2 |
** @file mruby/opcode.h - RiteVM operation codes |
| 3 |
** |
| 4 |
** See Copyright Notice in mruby.h |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifndef MRUBY_OPCODE_H |
| 8 |
#define MRUBY_OPCODE_H |
| 9 |
|
| 10 |
enum mrb_insn { |
| 11 |
#define OPCODE(x,_) OP_ ## x, |
| 12 |
#include "mruby/ops.h" |
| 13 |
#undef OPCODE |
| 14 |
}; |
| 15 |
|
| 16 |
#define OP_L_STRICT 1 |
| 17 |
#define OP_L_CAPTURE 2 |
| 18 |
#define OP_L_METHOD OP_L_STRICT |
| 19 |
#define OP_L_LAMBDA (OP_L_STRICT|OP_L_CAPTURE) |
| 20 |
#define OP_L_BLOCK OP_L_CAPTURE |
| 21 |
|
| 22 |
#define OP_R_NORMAL 0 |
| 23 |
#define OP_R_BREAK 1 |
| 24 |
#define OP_R_RETURN 2 |
| 25 |
|
| 26 |
#define PEEK_B(pc) (*(pc)) |
| 27 |
#define PEEK_S(pc) ((pc)[0]<<8|(pc)[1]) |
| 28 |
#define PEEK_W(pc) ((pc)[0]<<16|(pc)[1]<<8|(pc)[2]) |
| 29 |
|
| 30 |
#define READ_B() PEEK_B(pc++) |
| 31 |
#define READ_S() (pc+=2, PEEK_S(pc-2)) |
| 32 |
#define READ_W() (pc+=3, PEEK_W(pc-3)) |
| 33 |
|
| 34 |
#define FETCH_Z() /* nothing */ |
| 35 |
#define FETCH_B() do {a=READ_B();} while (0) |
| 36 |
#define FETCH_BB() do {a=READ_B(); b=READ_B();} while (0) |
| 37 |
#define FETCH_BBB() do {a=READ_B(); b=READ_B(); c=READ_B();} while (0) |
| 38 |
#define FETCH_BS() do {a=READ_B(); b=READ_S();} while (0) |
| 39 |
#define FETCH_BSS() do {a=READ_B(); b=READ_S(); c=READ_S();} while (0) |
| 40 |
#define FETCH_S() do {a=READ_S();} while (0) |
| 41 |
#define FETCH_W() do {a=READ_W();} while (0) |
| 42 |
|
| 43 |
/* with OP_EXT1 (1st 16bit) */ |
| 44 |
#define FETCH_Z_1() FETCH_Z() |
| 45 |
#define FETCH_B_1() FETCH_S() |
| 46 |
#define FETCH_BB_1() do {a=READ_S(); b=READ_B();} while (0) |
| 47 |
#define FETCH_BBB_1() do {a=READ_S(); b=READ_B(); c=READ_B();} while (0) |
| 48 |
#define FETCH_BS_1() do {a=READ_S(); b=READ_S();} while (0) |
| 49 |
#define FETCH_BSS_1() do {a=READ_S(); b=READ_S();c=READ_S();} while (0) |
| 50 |
#define FETCH_S_1() FETCH_S() |
| 51 |
#define FETCH_W_1() FETCH_W() |
| 52 |
|
| 53 |
/* with OP_EXT2 (2nd 16bit) */ |
| 54 |
#define FETCH_Z_2() FETCH_Z() |
| 55 |
#define FETCH_B_2() FETCH_B() |
| 56 |
#define FETCH_BB_2() do {a=READ_B(); b=READ_S();} while (0) |
| 57 |
#define FETCH_BBB_2() do {a=READ_B(); b=READ_S(); c=READ_B();} while (0) |
| 58 |
#define FETCH_BS_2() FETCH_BS() |
| 59 |
#define FETCH_BSS_2() FETCH_BSS() |
| 60 |
#define FETCH_S_2() FETCH_S() |
| 61 |
#define FETCH_W_2() FETCH_W() |
| 62 |
|
| 63 |
/* with OP_EXT3 (1st & 2nd 16bit) */ |
| 64 |
#define FETCH_Z_3() FETCH_Z() |
| 65 |
#define FETCH_B_3() FETCH_B() |
| 66 |
#define FETCH_BB_3() do {a=READ_S(); b=READ_S();} while (0) |
| 67 |
#define FETCH_BBB_3() do {a=READ_S(); b=READ_S(); c=READ_B();} while (0) |
| 68 |
#define FETCH_BS_3() do {a=READ_S(); b=READ_S();} while (0) |
| 69 |
#define FETCH_BSS_3() FETCH_BSS_1() |
| 70 |
#define FETCH_S_3() FETCH_S() |
| 71 |
#define FETCH_W_3() FETCH_W() |
| 72 |
|
| 73 |
#endif /* MRUBY_OPCODE_H */ |