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_S() do {a=READ_S();} while (0) 40 #define FETCH_W() do {a=READ_W();} while (0) 41 42 /* with OP_EXT1 (1st 16bit) */ 43 #define FETCH_Z_1() FETCH_Z() 44 #define FETCH_B_1() FETCH_S() 45 #define FETCH_BB_1() do {a=READ_S(); b=READ_B();} while (0) 46 #define FETCH_BBB_1() do {a=READ_S(); b=READ_B(); c=READ_B();} while (0) 47 #define FETCH_BS_1() do {a=READ_S(); b=READ_S();} while (0) 48 #define FETCH_S_1() FETCH_S() 49 #define FETCH_W_1() FETCH_W() 50 51 /* with OP_EXT2 (2nd 16bit) */ 52 #define FETCH_Z_2() FETCH_Z() 53 #define FETCH_B_2() FETCH_B() 54 #define FETCH_BB_2() do {a=READ_B(); b=READ_S();} while (0) 55 #define FETCH_BBB_2() do {a=READ_B(); b=READ_S(); c=READ_B();} while (0) 56 #define FETCH_BS_2() FETCH_BS() 57 #define FETCH_S_2() FETCH_S() 58 #define FETCH_W_2() FETCH_W() 59 60 /* with OP_EXT3 (1st & 2nd 16bit) */ 61 #define FETCH_Z_3() FETCH_Z() 62 #define FETCH_B_3() FETCH_B() 63 #define FETCH_BB_3() do {a=READ_S(); b=READ_S();} while (0) 64 #define FETCH_BBB_3() do {a=READ_S(); b=READ_S(); c=READ_B();} while (0) 65 #define FETCH_BS_3() do {a=READ_S(); b=READ_S();} while (0) 66 #define FETCH_S_3() FETCH_S() 67 #define FETCH_W_3() FETCH_W() 68 69 #endif /* MRUBY_OPCODE_H */ 70