mruby/c VM Source Code release 3.4
Loading...
Searching...
No Matches
opcode.h File Reference

Define operation codes and associated macros. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FETCH_Z()
#define FETCH_B()
#define FETCH_BB()
#define FETCH_BBB()
#define FETCH_BS()
#define FETCH_BSS()
#define FETCH_S()
#define FETCH_W()

Enumerations

enum  OPCODE {
  OP_NOP = 0x00 , OP_MOVE = 0x01 , OP_LOADL = 0x02 , OP_LOADI = 0x03 ,
  OP_LOADINEG = 0x04 , OP_LOADI__1 = 0x05 , OP_LOADI_0 = 0x06 , OP_LOADI_1 = 0x07 ,
  OP_LOADI_2 = 0x08 , OP_LOADI_3 = 0x09 , OP_LOADI_4 = 0x0A , OP_LOADI_5 = 0x0B ,
  OP_LOADI_6 = 0x0C , OP_LOADI_7 = 0x0D , OP_LOADI16 = 0x0E , OP_LOADI32 = 0x0F ,
  OP_LOADSYM = 0x10 , OP_LOADNIL = 0x11 , OP_LOADSELF = 0x12 , OP_LOADT = 0x13 ,
  OP_LOADF = 0x14 , OP_GETGV = 0x15 , OP_SETGV = 0x16 , OP_GETSV = 0x17 ,
  OP_SETSV = 0x18 , OP_GETIV = 0x19 , OP_SETIV = 0x1A , OP_GETCV = 0x1B ,
  OP_SETCV = 0x1C , OP_GETCONST = 0x1D , OP_SETCONST = 0x1E , OP_GETMCNST = 0x1F ,
  OP_SETMCNST = 0x20 , OP_GETUPVAR = 0x21 , OP_SETUPVAR = 0x22 , OP_GETIDX = 0x23 ,
  OP_SETIDX = 0x24 , OP_JMP = 0x25 , OP_JMPIF = 0x26 , OP_JMPNOT = 0x27 ,
  OP_JMPNIL = 0x28 , OP_JMPUW = 0x29 , OP_EXCEPT = 0x2A , OP_RESCUE = 0x2B ,
  OP_RAISEIF = 0x2C , OP_SSEND = 0x2D , OP_SSENDB = 0x2E , OP_SEND = 0x2F ,
  OP_SENDB = 0x30 , OP_CALL = 0x31 , OP_SUPER = 0x32 , OP_ARGARY = 0x33 ,
  OP_ENTER = 0x34 , OP_KEY_P = 0x35 , OP_KEYEND = 0x36 , OP_KARG = 0x37 ,
  OP_RETURN = 0x38 , OP_RETURN_BLK = 0x39 , OP_BREAK = 0x3A , OP_BLKPUSH = 0x3B ,
  OP_ADD = 0x3C , OP_ADDI = 0x3D , OP_SUB = 0x3E , OP_SUBI = 0x3F ,
  OP_MUL = 0x40 , OP_DIV = 0x41 , OP_EQ = 0x42 , OP_LT = 0x43 ,
  OP_LE = 0x44 , OP_GT = 0x45 , OP_GE = 0x46 , OP_ARRAY = 0x47 ,
  OP_ARRAY2 = 0x48 , OP_ARYCAT = 0x49 , OP_ARYPUSH = 0x4A , OP_ARYDUP = 0x4B ,
  OP_AREF = 0x4C , OP_ASET = 0x4D , OP_APOST = 0x4E , OP_INTERN = 0x4F ,
  OP_SYMBOL = 0x50 , OP_STRING = 0x51 , OP_STRCAT = 0x52 , OP_HASH = 0x53 ,
  OP_HASHADD = 0x54 , OP_HASHCAT = 0x55 , OP_LAMBDA = 0x56 , OP_BLOCK = 0x57 ,
  OP_METHOD = 0x58 , OP_RANGE_INC = 0x59 , OP_RANGE_EXC = 0x5A , OP_OCLASS = 0x5B ,
  OP_CLASS = 0x5C , OP_MODULE = 0x5D , OP_EXEC = 0x5E , OP_DEF = 0x5F ,
  OP_ALIAS = 0x60 , OP_UNDEF = 0x61 , OP_SCLASS = 0x62 , OP_TCLASS = 0x63 ,
  OP_DEBUG = 0x64 , OP_ERR = 0x65 , OP_EXT1 = 0x66 , OP_EXT2 = 0x67 ,
  OP_EXT3 = 0x68 , OP_STOP = 0x69
}
 Operation codes. More...

Detailed Description

Define operation codes and associated macros.

Copyright (C) 2015- Kyushu Institute of Technology.
Copyright (C) 2015- Shimane IT Open-Innovation Center.

This file is distributed under BSD 3-Clause License.


Definition in file opcode.h.

Macro Definition Documentation

◆ FETCH_B

#define FETCH_B ( )
Value:
unsigned int a; \
a = *vm->inst++; \
(void)a

Definition at line 62 of file opcode.h.

◆ FETCH_BB

#define FETCH_BB ( )
Value:
unsigned int a, b; \
a = *vm->inst++; \
b = *vm->inst++; \
(void)a, (void)b

Definition at line 67 of file opcode.h.

◆ FETCH_BBB

#define FETCH_BBB ( )
Value:
unsigned int a, b, c; \
a = *vm->inst++; \
b = *vm->inst++; \
c = *vm->inst++; \
(void)a, (void)b, (void)c

Definition at line 73 of file opcode.h.

◆ FETCH_BS

#define FETCH_BS ( )
Value:
unsigned int a, b; \
a = *vm->inst++; \
b = *vm->inst++; b = b << 8 | *vm->inst++; \
(void)a, (void)b

Definition at line 80 of file opcode.h.

◆ FETCH_BSS

#define FETCH_BSS ( )
Value:
unsigned int a, b, c; \
a = *vm->inst++; \
b = *vm->inst++; b = b << 8 | *vm->inst++; \
c = *vm->inst++; c = c << 8 | *vm->inst++; \
(void)a, (void)b, (void)c

Definition at line 86 of file opcode.h.

◆ FETCH_S

#define FETCH_S ( )
Value:
unsigned int a; \
a = *vm->inst++; a = a << 8 | *vm->inst++; \
(void)a

Definition at line 95 of file opcode.h.

◆ FETCH_W

#define FETCH_W ( )
Value:
uint32_t a; \
a = *vm->inst++; a = a << 8 | *vm->inst++; a = a << 8 | *vm->inst++; \
(void)a

Definition at line 100 of file opcode.h.

◆ FETCH_Z

#define FETCH_Z ( )
Value:
(void)0

Definition at line 27 of file opcode.h.

Enumeration Type Documentation

◆ OPCODE

enum OPCODE

Operation codes.

operand types: Z: no operand B: 8bit (a) BB: 8+8bit (a,b) BBB: 8+8+8bit (a,b,c) BS: 8+16bit (a,b) BSS: 8+16+16bit (a,b,c) S: 16bit (a) W: 24bit (a)

Enumerator
OP_NOP 

Z no operation.

OP_MOVE 

BB R[a] = R[b].

OP_LOADL 

BB R[a] = Pool[b].

OP_LOADI 

BB R[a] = mrb_int(b)

OP_LOADINEG 

BB R[a] = mrb_int(-b)

OP_LOADI__1 

B R[a] = mrb_int(-1)

OP_LOADI_0 

B R[a] = mrb_int(0)

OP_LOADI_1 

B R[a] = mrb_int(1)

OP_LOADI_2 

B R[a] = mrb_int(2)

OP_LOADI_3 

B R[a] = mrb_int(3)

OP_LOADI_4 

B R[a] = mrb_int(4)

OP_LOADI_5 

B R[a] = mrb_int(5)

OP_LOADI_6 

B R[a] = mrb_int(6)

OP_LOADI_7 

B R[a] = mrb_int(7)

OP_LOADI16 

BS R[a] = mrb_int(b)

OP_LOADI32 

BSS R[a] = mrb_int((b<<16)+c)

OP_LOADSYM 

BB R[a] = Syms[b].

OP_LOADNIL 

B R[a] = nil.

OP_LOADSELF 

B R[a] = self.

OP_LOADT 

B R[a] = true.

OP_LOADF 

B R[a] = false.

OP_GETGV 

BB R[a] = getglobal(Syms[b])

OP_SETGV 

BB setglobal(Syms[b], R[a])

OP_GETSV 

BB R[a] = Special[Syms[b]].

OP_SETSV 

BB Special[Syms[b]] = R[a].

OP_GETIV 

BB R[a] = ivget(Syms[b])

OP_SETIV 

BB ivset(Syms[b],R[a])

OP_GETCV 

BB R[a] = cvget(Syms[b])

OP_SETCV 

BB cvset(Syms[b],R[a])

OP_GETCONST 

BB R[a] = constget(Syms[b])

OP_SETCONST 

BB constset(Syms[b],R[a])

OP_GETMCNST 

BB R[a] = R[a]::Syms[b].

OP_SETMCNST 

BB R[a+1]::Syms[b] = R[a].

OP_GETUPVAR 

BBB R[a] = uvget(b,c)

OP_SETUPVAR 

BBB uvset(b,c,R[a])

OP_GETIDX 

B R[a] = R[a][R[a+1]].

OP_SETIDX 

B R[a][R[a+1]] = R[a+2].

OP_JMP 

S pc+=a.

OP_JMPIF 

BS if R[a] pc+=b.

OP_JMPNOT 

BS if !R[a] pc+=b.

OP_JMPNIL 

BS if R[a]==nil pc+=b.

OP_JMPUW 

S unwind_and_jump_to(a)

OP_EXCEPT 

B R[a] = exc.

OP_RESCUE 

BB R[b] = R[a].isa?(R[b])

OP_RAISEIF 

B raise(R[a]) if R[a].

OP_SSEND 

BBB R[a] = self.send(Syms[b],R[a+1]..,R[a+n+1]:R[a+n+2]..) (c=n|k<<4)

OP_SSENDB 

BBB R[a] = self.send(Syms[b],R[a+1]..,R[a+n+1]:R[a+n+2]..,&R[a+n+2k+1])

OP_SEND 

BBB R[a] = R[a].send(Syms[b],R[a+1]..,R[a+n+1]:R[a+n+2]..) (c=n|k<<4)

OP_SENDB 

BBB R[a] = R[a].send(Syms[b],R[a+1]..,R[a+n+1]:R[a+n+2]..,&R[a+n+2k+1])

OP_CALL 

Z R[0] = self.call(frame.argc, frame.argv)

OP_SUPER 

BB R[a] = super(R[a+1],... ,R[a+b+1])

OP_ARGARY 

BS R[a] = argument array (16=m5:r1:m5:d1:lv4)

OP_ENTER 

W arg setup according to flags (23=m5:o5:r1:m5:k5:d1:b1)

OP_KEY_P 

BB R[a] = kdict.key?(Syms[b])

OP_KEYEND 

Z raise unless kdict.empty?

OP_KARG 

BB R[a] = kdict[Syms[b]]; kdict.delete(Syms[b])

OP_RETURN 

B return R[a] (normal)

OP_RETURN_BLK 

B return R[a] (in-block return)

OP_BREAK 

B break R[a].

OP_BLKPUSH 

BS R[a] = block (16=m5:r1:m5:d1:lv4)

OP_ADD 

B R[a] = R[a]+R[a+1].

OP_ADDI 

BB R[a] = R[a]+mrb_int(b)

OP_SUB 

B R[a] = R[a]-R[a+1].

OP_SUBI 

BB R[a] = R[a]-mrb_int(b)

OP_MUL 

B R[a] = R[a]*R[a+1].

OP_DIV 

B R[a] = R[a]/R[a+1].

OP_EQ 

B R[a] = R[a]==R[a+1].

OP_LT 

B R[a] = R[a]<R[a+1].

OP_LE 

B R[a] = R[a]<=R[a+1].

OP_GT 

B R[a] = R[a]>R[a+1].

OP_GE 

B R[a] = R[a]>=R[a+1].

OP_ARRAY 

BB R[a] = ary_new(R[a],R[a+1]..R[a+b])

OP_ARRAY2 

BBB R[a] = ary_new(R[b],R[b+1]..R[b+c])

OP_ARYCAT 

B ary_cat(R[a],R[a+1])

OP_ARYPUSH 

BB ary_push(R[a],R[a+1]..R[a+b])

OP_ARYDUP 

B R[a] = ary_dup(R[a])

OP_AREF 

BBB R[a] = R[b][c].

OP_ASET 

BBB R[b][c] = R[a].

OP_APOST 

BBB *R[a],R[a+1]..R[a+c] = R[a][b..].

OP_INTERN 

B R[a] = intern(R[a])

OP_SYMBOL 

BB R[a] = intern(Pool[b])

OP_STRING 

BB R[a] = str_dup(Pool[b])

OP_STRCAT 

B str_cat(R[a],R[a+1])

OP_HASH 

BB R[a] = hash_new(R[a],R[a+1]..R[a+b*2-1])

OP_HASHADD 

BB hash_push(R[a],R[a+1]..R[a+b*2])

OP_HASHCAT 

B R[a] = hash_cat(R[a],R[a+1])

OP_LAMBDA 

BB R[a] = lambda(Irep[b],L_LAMBDA)

OP_BLOCK 

BB R[a] = lambda(Irep[b],L_BLOCK)

OP_METHOD 

BB R[a] = lambda(Irep[b],L_METHOD)

OP_RANGE_INC 

B R[a] = range_new(R[a],R[a+1],FALSE)

OP_RANGE_EXC 

B R[a] = range_new(R[a],R[a+1],TRUE)

OP_OCLASS 

B R[a] = ::Object.

OP_CLASS 

BB R[a] = newclass(R[a],Syms[b],R[a+1])

OP_MODULE 

BB R[a] = newmodule(R[a],Syms[b])

OP_EXEC 

BB R[a] = blockexec(R[a],Irep[b])

OP_DEF 

BB R[a].newmethod(Syms[b],R[a+1]); R[a] = Syms[b].

OP_ALIAS 

BB alias_method(target_class,Syms[a],Syms[b])

OP_UNDEF 

B undef_method(target_class,Syms[a])

OP_SCLASS 

B R[a] = R[a].singleton_class.

OP_TCLASS 

B R[a] = target_class.

OP_DEBUG 

BBB print a,b,c.

OP_ERR 

B raise(LocalJumpError, Pool[a])

OP_EXT1 

Z make 1st operand (a) 16bit.

OP_EXT2 

Z make 2nd operand (b) 16bit.

OP_EXT3 

Z make 1st and 2nd operands 16bit.

OP_STOP 

Z stop VM.

Definition at line 120 of file opcode.h.