Ignore:
Timestamp:
Jul 9, 2020, 8:51:43 AM (4 years ago)
Author:
coas-nagasima
Message:

mrubyを2.1.1に更新

Location:
EcnlProtoTool/trunk/mruby-2.1.1
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/opcode.h

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