/* ** mruby/opcode.h - RiteVM operation codes ** ** See Copyright Notice in mruby.h */ #ifndef MRUBY_OPCODE_H #define MRUBY_OPCODE_H #define MAXARG_Bx (0xffff) #define MAXARG_sBx (MAXARG_Bx>>1) /* 'sBx' is signed */ /* instructions: packed 32 bit */ /* ------------------------------- */ /* A:B:C:OP = 9: 9: 7: 7 */ /* A:Bx:OP = 9:16: 7 */ /* Ax:OP = 25: 7 */ /* A:Bz:Cz:OP = 9:14: 2: 7 */ #define GET_OPCODE(i) ((int)(((mrb_code)(i)) & 0x7f)) #define GETARG_A(i) ((int)((((mrb_code)(i)) >> 23) & 0x1ff)) #define GETARG_B(i) ((int)((((mrb_code)(i)) >> 14) & 0x1ff)) #define GETARG_C(i) ((int)((((mrb_code)(i)) >> 7) & 0x7f)) #define GETARG_Bx(i) ((int)((((mrb_code)(i)) >> 7) & 0xffff)) #define GETARG_sBx(i) ((int)(GETARG_Bx(i)-MAXARG_sBx)) #define GETARG_Ax(i) ((int32_t)((((mrb_code)(i)) >> 7) & 0x1ffffff)) #define GETARG_UNPACK_b(i,n1,n2) ((int)((((mrb_code)(i)) >> (7+(n2))) & (((1<<(n1))-1)))) #define GETARG_UNPACK_c(i,n1,n2) ((int)((((mrb_code)(i)) >> 7) & (((1<<(n2))-1)))) #define GETARG_b(i) GETARG_UNPACK_b(i,14,2) #define GETARG_c(i) GETARG_UNPACK_c(i,14,2) #define MKOPCODE(op) ((op) & 0x7f) #define MKARG_A(c) ((mrb_code)((c) & 0x1ff) << 23) #define MKARG_B(c) ((mrb_code)((c) & 0x1ff) << 14) #define MKARG_C(c) (((c) & 0x7f) << 7) #define MKARG_Bx(v) ((mrb_code)((v) & 0xffff) << 7) #define MKARG_sBx(v) MKARG_Bx((v)+MAXARG_sBx) #define MKARG_Ax(v) ((mrb_code)((v) & 0x1ffffff) << 7) #define MKARG_PACK(b,n1,c,n2) ((((b) & ((1<R(A+1) (Syms[B]=:>,C=1) */ OP_GE,/* A B C R(A) := R(A)>=R(A+1) (Syms[B]=:>=,C=1) */ OP_ARRAY,/* A B C R(A) := ary_new(R(B),R(B+1)..R(B+C)) */ OP_ARYCAT,/* A B ary_cat(R(A),R(B)) */ OP_ARYPUSH,/* A B ary_push(R(A),R(B)) */ OP_AREF,/* A B C R(A) := R(B)[C] */ OP_ASET,/* A B C R(B)[C] := R(A) */ OP_APOST,/* A B C *R(A),R(A+1)..R(A+C) := R(A) */ OP_STRING,/* A Bx R(A) := str_dup(Lit(Bx)) */ OP_STRCAT,/* A B str_cat(R(A),R(B)) */ OP_HASH,/* A B C R(A) := hash_new(R(B),R(B+1)..R(B+C)) */ OP_LAMBDA,/* A Bz Cz R(A) := lambda(SEQ[Bz],Cz) */ OP_RANGE,/* A B C R(A) := range_new(R(B),R(B+1),C) */ OP_OCLASS,/* A R(A) := ::Object */ OP_CLASS,/* A B R(A) := newclass(R(A),Syms(B),R(A+1)) */ OP_MODULE,/* A B R(A) := newmodule(R(A),Syms(B)) */ OP_EXEC,/* A Bx R(A) := blockexec(R(A),SEQ[Bx]) */ OP_METHOD,/* A B R(A).newmethod(Syms(B),R(A+1)) */ OP_SCLASS,/* A B R(A) := R(B).singleton_class */ OP_TCLASS,/* A R(A) := target_class */ OP_DEBUG,/* A B C print R(A),R(B),R(C) */ OP_STOP,/* stop VM */ OP_ERR,/* Bx raise RuntimeError with message Lit(Bx) */ OP_RSVD1,/* reserved instruction #1 */ OP_RSVD2,/* reserved instruction #2 */ OP_RSVD3,/* reserved instruction #3 */ OP_RSVD4,/* reserved instruction #4 */ OP_RSVD5,/* reserved instruction #5 */ }; #define OP_L_STRICT 1 #define OP_L_CAPTURE 2 #define OP_L_METHOD OP_L_STRICT #define OP_L_LAMBDA (OP_L_STRICT|OP_L_CAPTURE) #define OP_L_BLOCK OP_L_CAPTURE #define OP_R_NORMAL 0 #define OP_R_BREAK 1 #define OP_R_RETURN 2 #endif /* MRUBY_OPCODE_H */