From e0d6430f63c4cbe0c71ce82ee23284671389a818 Mon Sep 17 00:00:00 2001 From: mimaki Date: Fri, 20 Apr 2012 09:39:03 +0900 Subject: add mruby sources --- src/opcode.h | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 src/opcode.h (limited to 'src/opcode.h') diff --git a/src/opcode.h b/src/opcode.h new file mode 100644 index 000000000..e6ea74f79 --- /dev/null +++ b/src/opcode.h @@ -0,0 +1,148 @@ +#ifndef OPCODE_H +#define OPCODE_H + +#define MAXARG_Bx ((1<<16)-1) +#define MAXARG_sBx (MAXARG_Bx>>1) /* `sBx' is signed */ + +/* instructions OP:A:B:C = 7:9:9:7 (32 bits) */ +/* OP:A:Bx = 7:9:16 */ +/* OP:Ax = 7:25 */ + +#define GET_OPCODE(i) (((mrb_code)(i)) & 0x7f) +#define GETARG_A(i) ((((mrb_code)(i)) >> 23) & 0x1ff) +#define GETARG_B(i) ((((mrb_code)(i)) >> 14) & 0x1ff) +#define GETARG_C(i) ((((mrb_code)(i)) >> 7) & 0x7f) +#define GETARG_Bx(i) ((((mrb_code)(i)) >> 7) & 0xffff) +#define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx) +#define GETARG_Ax(i) ((((mrb_code)(i)) >> 7) & 0x1ffffff) +#define GETARG_UNPACK_b(i,n1,n2) ((((mrb_code)(i)) >> (7+n2)) & (((1<> 7) & (((1<R(A+1) (mSyms[B]=:>,C=1) */ +OP_GE,/* A B C R(A) := R(A)>=R(A+1) (mSyms[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],Cm) */ +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),mSym(B),R(A+1)) */ +OP_MODULE,/* A B R(A) := newmodule(R(A),mSym(B)) */ +OP_EXEC,/* A Bx R(A) := blockexec(R(A),SEQ[Bx]) */ +OP_METHOD,/* A B R(A).newmethod(mSym(B),R(A+1)) */ +OP_SCLASS,/* A B R(A) := R(B).singleton_class */ +OP_TCLASS,/* A R(A) := target_class */ + +OP_DEBUG,/* A print R(A) */ +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 /* OPCODE_H */ -- cgit v1.2.3