mbed I/F binding for mruby

Dependents:   mruby_mbed_web mirb_mbed

mbed-mruby

How to use

Class

Committer:
mzta
Date:
Mon Apr 13 05:20:15 2015 +0000
Revision:
1:8ccd1d494a4b
Parent:
0:158c61bb030f
- code refactoring.; - add SPI, SPISlave, I2C class to mruby-mbed (Incomplete).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mzta 0:158c61bb030f 1 /*
mzta 0:158c61bb030f 2 ** mruby/opcode.h - RiteVM operation codes
mzta 0:158c61bb030f 3 **
mzta 0:158c61bb030f 4 ** See Copyright Notice in mruby.h
mzta 0:158c61bb030f 5 */
mzta 0:158c61bb030f 6
mzta 0:158c61bb030f 7 #ifndef MRUBY_OPCODE_H
mzta 0:158c61bb030f 8 #define MRUBY_OPCODE_H
mzta 0:158c61bb030f 9
mzta 0:158c61bb030f 10 #define MAXARG_Bx (0xffff)
mzta 0:158c61bb030f 11 #define MAXARG_sBx (MAXARG_Bx>>1) /* `sBx' is signed */
mzta 0:158c61bb030f 12
mzta 0:158c61bb030f 13 /* instructions: packed 32 bit */
mzta 0:158c61bb030f 14 /* ------------------------------- */
mzta 0:158c61bb030f 15 /* A:B:C:OP = 9: 9: 7: 7 */
mzta 0:158c61bb030f 16 /* A:Bx:OP = 9:16: 7 */
mzta 0:158c61bb030f 17 /* Ax:OP = 25: 7 */
mzta 0:158c61bb030f 18 /* A:Bz:Cz:OP = 9:14: 2: 7 */
mzta 0:158c61bb030f 19
mzta 0:158c61bb030f 20 #define GET_OPCODE(i) ((int)(((mrb_code)(i)) & 0x7f))
mzta 0:158c61bb030f 21 #define GETARG_A(i) ((int)((((mrb_code)(i)) >> 23) & 0x1ff))
mzta 0:158c61bb030f 22 #define GETARG_B(i) ((int)((((mrb_code)(i)) >> 14) & 0x1ff))
mzta 0:158c61bb030f 23 #define GETARG_C(i) ((int)((((mrb_code)(i)) >> 7) & 0x7f))
mzta 0:158c61bb030f 24 #define GETARG_Bx(i) ((int)((((mrb_code)(i)) >> 7) & 0xffff))
mzta 0:158c61bb030f 25 #define GETARG_sBx(i) ((int)(GETARG_Bx(i)-MAXARG_sBx))
mzta 0:158c61bb030f 26 #define GETARG_Ax(i) ((int32_t)((((mrb_code)(i)) >> 7) & 0x1ffffff))
mzta 0:158c61bb030f 27 #define GETARG_UNPACK_b(i,n1,n2) ((int)((((mrb_code)(i)) >> (7+(n2))) & (((1<<(n1))-1))))
mzta 0:158c61bb030f 28 #define GETARG_UNPACK_c(i,n1,n2) ((int)((((mrb_code)(i)) >> 7) & (((1<<(n2))-1))))
mzta 0:158c61bb030f 29 #define GETARG_b(i) GETARG_UNPACK_b(i,14,2)
mzta 0:158c61bb030f 30 #define GETARG_c(i) GETARG_UNPACK_c(i,14,2)
mzta 0:158c61bb030f 31
mzta 0:158c61bb030f 32 #define MKOPCODE(op) ((op) & 0x7f)
mzta 0:158c61bb030f 33 #define MKARG_A(c) ((mrb_code)((c) & 0x1ff) << 23)
mzta 0:158c61bb030f 34 #define MKARG_B(c) ((mrb_code)((c) & 0x1ff) << 14)
mzta 0:158c61bb030f 35 #define MKARG_C(c) (((c) & 0x7f) << 7)
mzta 0:158c61bb030f 36 #define MKARG_Bx(v) ((mrb_code)((v) & 0xffff) << 7)
mzta 0:158c61bb030f 37 #define MKARG_sBx(v) MKARG_Bx((v)+MAXARG_sBx)
mzta 0:158c61bb030f 38 #define MKARG_Ax(v) ((mrb_code)((v) & 0x1ffffff) << 7)
mzta 0:158c61bb030f 39 #define MKARG_PACK(b,n1,c,n2) ((((b) & ((1<<n1)-1)) << (7+n2))|(((c) & ((1<<n2)-1)) << 7))
mzta 0:158c61bb030f 40 #define MKARG_bc(b,c) MKARG_PACK(b,14,c,2)
mzta 0:158c61bb030f 41
mzta 0:158c61bb030f 42 #define MKOP_A(op,a) (MKOPCODE(op)|MKARG_A(a))
mzta 0:158c61bb030f 43 #define MKOP_AB(op,a,b) (MKOP_A(op,a)|MKARG_B(b))
mzta 0:158c61bb030f 44 #define MKOP_ABC(op,a,b,c) (MKOP_AB(op,a,b)|MKARG_C(c))
mzta 0:158c61bb030f 45 #define MKOP_ABx(op,a,bx) (MKOP_A(op,a)|MKARG_Bx(bx))
mzta 0:158c61bb030f 46 #define MKOP_Bx(op,bx) (MKOPCODE(op)|MKARG_Bx(bx))
mzta 0:158c61bb030f 47 #define MKOP_sBx(op,sbx) (MKOPCODE(op)|MKARG_sBx(sbx))
mzta 0:158c61bb030f 48 #define MKOP_AsBx(op,a,sbx) (MKOP_A(op,a)|MKARG_sBx(sbx))
mzta 0:158c61bb030f 49 #define MKOP_Ax(op,ax) (MKOPCODE(op)|MKARG_Ax(ax))
mzta 0:158c61bb030f 50 #define MKOP_Abc(op,a,b,c) (MKOP_A(op,a)|MKARG_bc(b,c))
mzta 0:158c61bb030f 51
mzta 0:158c61bb030f 52 enum {
mzta 0:158c61bb030f 53 /*-----------------------------------------------------------------------
mzta 0:158c61bb030f 54 operation code operand description
mzta 0:158c61bb030f 55 ------------------------------------------------------------------------*/
mzta 0:158c61bb030f 56 OP_NOP=0,/* */
mzta 0:158c61bb030f 57 OP_MOVE,/* A B R(A) := R(B) */
mzta 0:158c61bb030f 58 OP_LOADL,/* A Bx R(A) := Pool(Bx) */
mzta 0:158c61bb030f 59 OP_LOADI,/* A sBx R(A) := sBx */
mzta 0:158c61bb030f 60 OP_LOADSYM,/* A Bx R(A) := Syms(Bx) */
mzta 0:158c61bb030f 61 OP_LOADNIL,/* A R(A) := nil */
mzta 0:158c61bb030f 62 OP_LOADSELF,/* A R(A) := self */
mzta 0:158c61bb030f 63 OP_LOADT,/* A R(A) := true */
mzta 0:158c61bb030f 64 OP_LOADF,/* A R(A) := false */
mzta 0:158c61bb030f 65
mzta 0:158c61bb030f 66 OP_GETGLOBAL,/* A Bx R(A) := getglobal(Syms(Bx)) */
mzta 0:158c61bb030f 67 OP_SETGLOBAL,/* A Bx setglobal(Syms(Bx), R(A)) */
mzta 0:158c61bb030f 68 OP_GETSPECIAL,/*A Bx R(A) := Special[Bx] */
mzta 0:158c61bb030f 69 OP_SETSPECIAL,/*A Bx Special[Bx] := R(A) */
mzta 0:158c61bb030f 70 OP_GETIV,/* A Bx R(A) := ivget(Syms(Bx)) */
mzta 0:158c61bb030f 71 OP_SETIV,/* A Bx ivset(Syms(Bx),R(A)) */
mzta 0:158c61bb030f 72 OP_GETCV,/* A Bx R(A) := cvget(Syms(Bx)) */
mzta 0:158c61bb030f 73 OP_SETCV,/* A Bx cvset(Syms(Bx),R(A)) */
mzta 0:158c61bb030f 74 OP_GETCONST,/* A Bx R(A) := constget(Syms(Bx)) */
mzta 0:158c61bb030f 75 OP_SETCONST,/* A Bx constset(Syms(Bx),R(A)) */
mzta 0:158c61bb030f 76 OP_GETMCNST,/* A Bx R(A) := R(A)::Syms(Bx) */
mzta 0:158c61bb030f 77 OP_SETMCNST,/* A Bx R(A+1)::Syms(Bx) := R(A) */
mzta 0:158c61bb030f 78 OP_GETUPVAR,/* A B C R(A) := uvget(B,C) */
mzta 0:158c61bb030f 79 OP_SETUPVAR,/* A B C uvset(B,C,R(A)) */
mzta 0:158c61bb030f 80
mzta 0:158c61bb030f 81 OP_JMP,/* sBx pc+=sBx */
mzta 0:158c61bb030f 82 OP_JMPIF,/* A sBx if R(A) pc+=sBx */
mzta 0:158c61bb030f 83 OP_JMPNOT,/* A sBx if !R(A) pc+=sBx */
mzta 0:158c61bb030f 84 OP_ONERR,/* sBx rescue_push(pc+sBx) */
mzta 0:158c61bb030f 85 OP_RESCUE,/* A clear(exc); R(A) := exception (ignore when A=0) */
mzta 0:158c61bb030f 86 OP_POPERR,/* A A.times{rescue_pop()} */
mzta 0:158c61bb030f 87 OP_RAISE,/* A raise(R(A)) */
mzta 0:158c61bb030f 88 OP_EPUSH,/* Bx ensure_push(SEQ[Bx]) */
mzta 0:158c61bb030f 89 OP_EPOP,/* A A.times{ensure_pop().call} */
mzta 0:158c61bb030f 90
mzta 0:158c61bb030f 91 OP_SEND,/* A B C R(A) := call(R(A),Syms(B),R(A+1),...,R(A+C)) */
mzta 0:158c61bb030f 92 OP_SENDB,/* A B C R(A) := call(R(A),Syms(B),R(A+1),...,R(A+C),&R(A+C+1))*/
mzta 0:158c61bb030f 93 OP_FSEND,/* A B C R(A) := fcall(R(A),Syms(B),R(A+1),...,R(A+C-1)) */
mzta 0:158c61bb030f 94 OP_CALL,/* A R(A) := self.call(frame.argc, frame.argv) */
mzta 0:158c61bb030f 95 OP_SUPER,/* A C R(A) := super(R(A+1),... ,R(A+C+1)) */
mzta 0:158c61bb030f 96 OP_ARGARY,/* A Bx R(A) := argument array (16=6:1:5:4) */
mzta 0:158c61bb030f 97 OP_ENTER,/* Ax arg setup according to flags (23=5:5:1:5:5:1:1) */
mzta 0:158c61bb030f 98 OP_KARG,/* A B C R(A) := kdict[Syms(B)]; if C kdict.rm(Syms(B)) */
mzta 0:158c61bb030f 99 OP_KDICT,/* A C R(A) := kdict */
mzta 0:158c61bb030f 100
mzta 0:158c61bb030f 101 OP_RETURN,/* A B return R(A) (B=normal,in-block return/break) */
mzta 0:158c61bb030f 102 OP_TAILCALL,/* A B C return call(R(A),Syms(B),*R(C)) */
mzta 0:158c61bb030f 103 OP_BLKPUSH,/* A Bx R(A) := block (16=6:1:5:4) */
mzta 0:158c61bb030f 104
mzta 0:158c61bb030f 105 OP_ADD,/* A B C R(A) := R(A)+R(A+1) (Syms[B]=:+,C=1) */
mzta 0:158c61bb030f 106 OP_ADDI,/* A B C R(A) := R(A)+C (Syms[B]=:+) */
mzta 0:158c61bb030f 107 OP_SUB,/* A B C R(A) := R(A)-R(A+1) (Syms[B]=:-,C=1) */
mzta 0:158c61bb030f 108 OP_SUBI,/* A B C R(A) := R(A)-C (Syms[B]=:-) */
mzta 0:158c61bb030f 109 OP_MUL,/* A B C R(A) := R(A)*R(A+1) (Syms[B]=:*,C=1) */
mzta 0:158c61bb030f 110 OP_DIV,/* A B C R(A) := R(A)/R(A+1) (Syms[B]=:/,C=1) */
mzta 0:158c61bb030f 111 OP_EQ,/* A B C R(A) := R(A)==R(A+1) (Syms[B]=:==,C=1) */
mzta 0:158c61bb030f 112 OP_LT,/* A B C R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1) */
mzta 0:158c61bb030f 113 OP_LE,/* A B C R(A) := R(A)<=R(A+1) (Syms[B]=:<=,C=1) */
mzta 0:158c61bb030f 114 OP_GT,/* A B C R(A) := R(A)>R(A+1) (Syms[B]=:>,C=1) */
mzta 0:158c61bb030f 115 OP_GE,/* A B C R(A) := R(A)>=R(A+1) (Syms[B]=:>=,C=1) */
mzta 0:158c61bb030f 116
mzta 0:158c61bb030f 117 OP_ARRAY,/* A B C R(A) := ary_new(R(B),R(B+1)..R(B+C)) */
mzta 0:158c61bb030f 118 OP_ARYCAT,/* A B ary_cat(R(A),R(B)) */
mzta 0:158c61bb030f 119 OP_ARYPUSH,/* A B ary_push(R(A),R(B)) */
mzta 0:158c61bb030f 120 OP_AREF,/* A B C R(A) := R(B)[C] */
mzta 0:158c61bb030f 121 OP_ASET,/* A B C R(B)[C] := R(A) */
mzta 0:158c61bb030f 122 OP_APOST,/* A B C *R(A),R(A+1)..R(A+C) := R(A) */
mzta 0:158c61bb030f 123
mzta 0:158c61bb030f 124 OP_STRING,/* A Bx R(A) := str_dup(Lit(Bx)) */
mzta 0:158c61bb030f 125 OP_STRCAT,/* A B str_cat(R(A),R(B)) */
mzta 0:158c61bb030f 126
mzta 0:158c61bb030f 127 OP_HASH,/* A B C R(A) := hash_new(R(B),R(B+1)..R(B+C)) */
mzta 0:158c61bb030f 128 OP_LAMBDA,/* A Bz Cz R(A) := lambda(SEQ[Bz],Cz) */
mzta 0:158c61bb030f 129 OP_RANGE,/* A B C R(A) := range_new(R(B),R(B+1),C) */
mzta 0:158c61bb030f 130
mzta 0:158c61bb030f 131 OP_OCLASS,/* A R(A) := ::Object */
mzta 0:158c61bb030f 132 OP_CLASS,/* A B R(A) := newclass(R(A),Syms(B),R(A+1)) */
mzta 0:158c61bb030f 133 OP_MODULE,/* A B R(A) := newmodule(R(A),Syms(B)) */
mzta 0:158c61bb030f 134 OP_EXEC,/* A Bx R(A) := blockexec(R(A),SEQ[Bx]) */
mzta 0:158c61bb030f 135 OP_METHOD,/* A B R(A).newmethod(Syms(B),R(A+1)) */
mzta 0:158c61bb030f 136 OP_SCLASS,/* A B R(A) := R(B).singleton_class */
mzta 0:158c61bb030f 137 OP_TCLASS,/* A R(A) := target_class */
mzta 0:158c61bb030f 138
mzta 0:158c61bb030f 139 OP_DEBUG,/* A B C print R(A),R(B),R(C) */
mzta 0:158c61bb030f 140 OP_STOP,/* stop VM */
mzta 0:158c61bb030f 141 OP_ERR,/* Bx raise RuntimeError with message Lit(Bx) */
mzta 0:158c61bb030f 142
mzta 0:158c61bb030f 143 OP_RSVD1,/* reserved instruction #1 */
mzta 0:158c61bb030f 144 OP_RSVD2,/* reserved instruction #2 */
mzta 0:158c61bb030f 145 OP_RSVD3,/* reserved instruction #3 */
mzta 0:158c61bb030f 146 OP_RSVD4,/* reserved instruction #4 */
mzta 0:158c61bb030f 147 OP_RSVD5,/* reserved instruction #5 */
mzta 0:158c61bb030f 148 };
mzta 0:158c61bb030f 149
mzta 0:158c61bb030f 150 #define OP_L_STRICT 1
mzta 0:158c61bb030f 151 #define OP_L_CAPTURE 2
mzta 0:158c61bb030f 152 #define OP_L_METHOD OP_L_STRICT
mzta 0:158c61bb030f 153 #define OP_L_LAMBDA (OP_L_STRICT|OP_L_CAPTURE)
mzta 0:158c61bb030f 154 #define OP_L_BLOCK OP_L_CAPTURE
mzta 0:158c61bb030f 155
mzta 0:158c61bb030f 156 #define OP_R_NORMAL 0
mzta 0:158c61bb030f 157 #define OP_R_BREAK 1
mzta 0:158c61bb030f 158 #define OP_R_RETURN 2
mzta 0:158c61bb030f 159
mzta 0:158c61bb030f 160 #endif /* MRUBY_OPCODE_H */
mzta 0:158c61bb030f 161