mruby/c VM Source Code release 3.4
Loading...
Searching...
No Matches
opcode.h
Go to the documentation of this file.
1
14
15#ifndef MRBC_SRC_OPCODE_H_
16#define MRBC_SRC_OPCODE_H_
17
18//@cond
19#include <stdint.h>
20//@endcond
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26
27#define FETCH_Z() (void)0
28
29#if defined(MRBC_SUPPORT_OP_EXT)
30#define FETCH_B() \
31 unsigned int a; \
32 a = *vm->inst++; if( ext & 1 ) a = a << 8 | *vm->inst++; \
33 (void)a
34
35#define FETCH_BB() \
36 unsigned int a, b; \
37 a = *vm->inst++; if( ext & 1 ) a = a << 8 | *vm->inst++; \
38 b = *vm->inst++; if( ext & 2 ) b = b << 8 | *vm->inst++; \
39 (void)a, (void)b
40
41#define FETCH_BBB() \
42 unsigned int a, b, c; \
43 a = *vm->inst++; if( ext & 1 ) a = a << 8 | *vm->inst++; \
44 b = *vm->inst++; if( ext & 2 ) b = b << 8 | *vm->inst++; \
45 c = *vm->inst++; \
46 (void)a, (void)b, (void)c
47
48#define FETCH_BS() \
49 unsigned int a, b; \
50 a = *vm->inst++; if( ext & 1 ) a = a << 8 | *vm->inst++; \
51 b = *vm->inst++; b = b << 8 | *vm->inst++; \
52 (void)a, (void)b
53
54#define FETCH_BSS() \
55 unsigned int a, b, c; \
56 a = *vm->inst++; if( ext & 1 ) a = a << 8 | *vm->inst++; \
57 b = *vm->inst++; b = b << 8 | *vm->inst++; \
58 c = *vm->inst++; c = c << 8 | *vm->inst++; \
59 (void)a, (void)b, (void)c
60
61#else
62#define FETCH_B() \
63 unsigned int a; \
64 a = *vm->inst++; \
65 (void)a
66
67#define FETCH_BB() \
68 unsigned int a, b; \
69 a = *vm->inst++; \
70 b = *vm->inst++; \
71 (void)a, (void)b
72
73#define FETCH_BBB() \
74 unsigned int a, b, c; \
75 a = *vm->inst++; \
76 b = *vm->inst++; \
77 c = *vm->inst++; \
78 (void)a, (void)b, (void)c
79
80#define FETCH_BS() \
81 unsigned int a, b; \
82 a = *vm->inst++; \
83 b = *vm->inst++; b = b << 8 | *vm->inst++; \
84 (void)a, (void)b
85
86#define FETCH_BSS() \
87 unsigned int a, b, c; \
88 a = *vm->inst++; \
89 b = *vm->inst++; b = b << 8 | *vm->inst++; \
90 c = *vm->inst++; c = c << 8 | *vm->inst++; \
91 (void)a, (void)b, (void)c
92
93#endif // defined(MRBC_SUPPORT_OP_EXT)
94
95#define FETCH_S() \
96 unsigned int a; \
97 a = *vm->inst++; a = a << 8 | *vm->inst++; \
98 (void)a
99
100#define FETCH_W() \
101 uint32_t a; \
102 a = *vm->inst++; a = a << 8 | *vm->inst++; a = a << 8 | *vm->inst++; \
103 (void)a
104
105
106//================================================================
120enum OPCODE {
121/*-----------------------------------------------------------------------
122 operation code operands semantics
123------------------------------------------------------------------------*/
124 OP_NOP = 0x00,
125 OP_MOVE = 0x01,
126 OP_LOADL = 0x02,
127 OP_LOADI = 0x03,
128 OP_LOADINEG = 0x04,
129 OP_LOADI__1 = 0x05,
130 OP_LOADI_0 = 0x06,
131 OP_LOADI_1 = 0x07,
132 OP_LOADI_2 = 0x08,
133 OP_LOADI_3 = 0x09,
134 OP_LOADI_4 = 0x0A,
135 OP_LOADI_5 = 0x0B,
136 OP_LOADI_6 = 0x0C,
137 OP_LOADI_7 = 0x0D,
138 OP_LOADI16 = 0x0E,
139 OP_LOADI32 = 0x0F,
140 OP_LOADSYM = 0x10,
141 OP_LOADNIL = 0x11,
142 OP_LOADSELF = 0x12,
143 OP_LOADT = 0x13,
144 OP_LOADF = 0x14,
145 OP_GETGV = 0x15,
146 OP_SETGV = 0x16,
147 OP_GETSV = 0x17,
148 OP_SETSV = 0x18,
149 OP_GETIV = 0x19,
150 OP_SETIV = 0x1A,
151 OP_GETCV = 0x1B,
152 OP_SETCV = 0x1C,
153 OP_GETCONST = 0x1D,
154 OP_SETCONST = 0x1E,
155 OP_GETMCNST = 0x1F,
156 OP_SETMCNST = 0x20,
157 OP_GETUPVAR = 0x21,
158 OP_SETUPVAR = 0x22,
159 OP_GETIDX = 0x23,
160 OP_SETIDX = 0x24,
161 OP_JMP = 0x25,
162 OP_JMPIF = 0x26,
163 OP_JMPNOT = 0x27,
164 OP_JMPNIL = 0x28,
165 OP_JMPUW = 0x29,
166 OP_EXCEPT = 0x2A,
167 OP_RESCUE = 0x2B,
168 OP_RAISEIF = 0x2C,
169 OP_SSEND = 0x2D,
170 OP_SSENDB = 0x2E,
171 OP_SEND = 0x2F,
172 OP_SENDB = 0x30,
173 OP_CALL = 0x31,
174 OP_SUPER = 0x32,
175 OP_ARGARY = 0x33,
176 OP_ENTER = 0x34,
177 OP_KEY_P = 0x35,
178 OP_KEYEND = 0x36,
179 OP_KARG = 0x37,
180 OP_RETURN = 0x38,
182 OP_BREAK = 0x3A,
183 OP_BLKPUSH = 0x3B,
184 OP_ADD = 0x3C,
185 OP_ADDI = 0x3D,
186 OP_SUB = 0x3E,
187 OP_SUBI = 0x3F,
188 OP_MUL = 0x40,
189 OP_DIV = 0x41,
190 OP_EQ = 0x42,
191 OP_LT = 0x43,
192 OP_LE = 0x44,
193 OP_GT = 0x45,
194 OP_GE = 0x46,
195 OP_ARRAY = 0x47,
196 OP_ARRAY2 = 0x48,
197 OP_ARYCAT = 0x49,
198 OP_ARYPUSH = 0x4A,
199 OP_ARYDUP = 0x4B,
200 OP_AREF = 0x4C,
201 OP_ASET = 0x4D,
202 OP_APOST = 0x4E,
203 OP_INTERN = 0x4F,
204 OP_SYMBOL = 0x50,
205 OP_STRING = 0x51,
206 OP_STRCAT = 0x52,
207 OP_HASH = 0x53,
208 OP_HASHADD = 0x54,
209 OP_HASHCAT = 0x55,
210 OP_LAMBDA = 0x56,
211 OP_BLOCK = 0x57,
212 OP_METHOD = 0x58,
215 OP_OCLASS = 0x5B,
216 OP_CLASS = 0x5C,
217 OP_MODULE = 0x5D,
218 OP_EXEC = 0x5E,
219 OP_DEF = 0x5F,
220 OP_ALIAS = 0x60,
221 OP_UNDEF = 0x61,
222 OP_SCLASS = 0x62,
223 OP_TCLASS = 0x63,
224 OP_DEBUG = 0x64,
225 OP_ERR = 0x65,
226 OP_EXT1 = 0x66,
227 OP_EXT2 = 0x67,
228 OP_EXT3 = 0x68,
229 OP_STOP = 0x69,
230};
231
232
233#ifdef __cplusplus
234}
235#endif
236#endif
OPCODE
Operation codes.
Definition opcode.h:120
@ OP_KEY_P
BB R[a] = kdict.key?(Syms[b])
Definition opcode.h:177
@ OP_DEBUG
BBB print a,b,c.
Definition opcode.h:224
@ OP_CALL
Z R[0] = self.call(frame.argc, frame.argv)
Definition opcode.h:173
@ OP_EXT2
Z make 2nd operand (b) 16bit.
Definition opcode.h:227
@ OP_EXEC
BB R[a] = blockexec(R[a],Irep[b])
Definition opcode.h:218
@ 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])
Definition opcode.h:170
@ OP_EQ
B R[a] = R[a]==R[a+1].
Definition opcode.h:190
@ OP_SETIDX
B R[a][R[a+1]] = R[a+2].
Definition opcode.h:160
@ OP_LOADI__1
B R[a] = mrb_int(-1)
Definition opcode.h:129
@ OP_MODULE
BB R[a] = newmodule(R[a],Syms[b])
Definition opcode.h:217
@ OP_RANGE_INC
B R[a] = range_new(R[a],R[a+1],FALSE)
Definition opcode.h:213
@ OP_EXT1
Z make 1st operand (a) 16bit.
Definition opcode.h:226
@ OP_CLASS
BB R[a] = newclass(R[a],Syms[b],R[a+1])
Definition opcode.h:216
@ OP_LOADSELF
B R[a] = self.
Definition opcode.h:142
@ OP_BLKPUSH
BS R[a] = block (16=m5:r1:m5:d1:lv4)
Definition opcode.h:183
@ OP_LOADI_3
B R[a] = mrb_int(3)
Definition opcode.h:133
@ OP_GE
B R[a] = R[a]>=R[a+1].
Definition opcode.h:194
@ OP_LOADI_4
B R[a] = mrb_int(4)
Definition opcode.h:134
@ OP_EXT3
Z make 1st and 2nd operands 16bit.
Definition opcode.h:228
@ OP_SETIV
BB ivset(Syms[b],R[a])
Definition opcode.h:150
@ OP_SUBI
BB R[a] = R[a]-mrb_int(b)
Definition opcode.h:187
@ OP_TCLASS
B R[a] = target_class.
Definition opcode.h:223
@ OP_STOP
Z stop VM.
Definition opcode.h:229
@ OP_AREF
BBB R[a] = R[b][c].
Definition opcode.h:200
@ OP_APOST
BBB *R[a],R[a+1]..R[a+c] = R[a][b..].
Definition opcode.h:202
@ OP_RETURN_BLK
B return R[a] (in-block return)
Definition opcode.h:181
@ OP_LOADI_6
B R[a] = mrb_int(6)
Definition opcode.h:136
@ OP_ALIAS
BB alias_method(target_class,Syms[a],Syms[b])
Definition opcode.h:220
@ OP_SSEND
BBB R[a] = self.send(Syms[b],R[a+1]..,R[a+n+1]:R[a+n+2]..) (c=n|k<<4)
Definition opcode.h:169
@ OP_NOP
Z no operation.
Definition opcode.h:124
@ OP_SETCONST
BB constset(Syms[b],R[a])
Definition opcode.h:154
@ OP_LOADSYM
BB R[a] = Syms[b].
Definition opcode.h:140
@ OP_ARYCAT
B ary_cat(R[a],R[a+1])
Definition opcode.h:197
@ OP_LAMBDA
BB R[a] = lambda(Irep[b],L_LAMBDA)
Definition opcode.h:210
@ OP_RANGE_EXC
B R[a] = range_new(R[a],R[a+1],TRUE)
Definition opcode.h:214
@ OP_LOADI_5
B R[a] = mrb_int(5)
Definition opcode.h:135
@ OP_LOADI_7
B R[a] = mrb_int(7)
Definition opcode.h:137
@ OP_LOADNIL
B R[a] = nil.
Definition opcode.h:141
@ OP_SETGV
BB setglobal(Syms[b], R[a])
Definition opcode.h:146
@ OP_STRCAT
B str_cat(R[a],R[a+1])
Definition opcode.h:206
@ OP_LOADI
BB R[a] = mrb_int(b)
Definition opcode.h:127
@ 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)
Definition opcode.h:171
@ OP_BREAK
B break R[a].
Definition opcode.h:182
@ OP_GETIDX
B R[a] = R[a][R[a+1]].
Definition opcode.h:159
@ OP_SUB
B R[a] = R[a]-R[a+1].
Definition opcode.h:186
@ OP_GETSV
BB R[a] = Special[Syms[b]].
Definition opcode.h:147
@ OP_DIV
B R[a] = R[a]/R[a+1].
Definition opcode.h:189
@ OP_ASET
BBB R[b][c] = R[a].
Definition opcode.h:201
@ OP_RAISEIF
B raise(R[a]) if R[a].
Definition opcode.h:168
@ OP_GETUPVAR
BBB R[a] = uvget(b,c)
Definition opcode.h:157
@ OP_ARRAY2
BBB R[a] = ary_new(R[b],R[b+1]..R[b+c])
Definition opcode.h:196
@ OP_ARYDUP
B R[a] = ary_dup(R[a])
Definition opcode.h:199
@ OP_LOADI_1
B R[a] = mrb_int(1)
Definition opcode.h:131
@ OP_JMPNIL
BS if R[a]==nil pc+=b.
Definition opcode.h:164
@ OP_LT
B R[a] = R[a]<R[a+1].
Definition opcode.h:191
@ OP_JMPUW
S unwind_and_jump_to(a)
Definition opcode.h:165
@ OP_INTERN
B R[a] = intern(R[a])
Definition opcode.h:203
@ OP_SETUPVAR
BBB uvset(b,c,R[a])
Definition opcode.h:158
@ OP_ENTER
W arg setup according to flags (23=m5:o5:r1:m5:k5:d1:b1)
Definition opcode.h:176
@ OP_LOADF
B R[a] = false.
Definition opcode.h:144
@ OP_UNDEF
B undef_method(target_class,Syms[a])
Definition opcode.h:221
@ OP_KARG
BB R[a] = kdict[Syms[b]]; kdict.delete(Syms[b])
Definition opcode.h:179
@ OP_GETCV
BB R[a] = cvget(Syms[b])
Definition opcode.h:151
@ OP_HASHADD
BB hash_push(R[a],R[a+1]..R[a+b*2])
Definition opcode.h:208
@ OP_ARGARY
BS R[a] = argument array (16=m5:r1:m5:d1:lv4)
Definition opcode.h:175
@ OP_METHOD
BB R[a] = lambda(Irep[b],L_METHOD)
Definition opcode.h:212
@ OP_ARYPUSH
BB ary_push(R[a],R[a+1]..R[a+b])
Definition opcode.h:198
@ OP_ADD
B R[a] = R[a]+R[a+1].
Definition opcode.h:184
@ OP_LOADT
B R[a] = true.
Definition opcode.h:143
@ OP_OCLASS
B R[a] = Object.
Definition opcode.h:215
@ OP_SYMBOL
BB R[a] = intern(Pool[b])
Definition opcode.h:204
@ OP_MUL
B R[a] = R[a]*R[a+1].
Definition opcode.h:188
@ OP_STRING
BB R[a] = str_dup(Pool[b])
Definition opcode.h:205
@ OP_ERR
B raise(LocalJumpError, Pool[a])
Definition opcode.h:225
@ OP_RESCUE
BB R[b] = R[a].isa?(R[b])
Definition opcode.h:167
@ OP_GETIV
BB R[a] = ivget(Syms[b])
Definition opcode.h:149
@ OP_LOADI32
BSS R[a] = mrb_int((b<<16)+c)
Definition opcode.h:139
@ OP_LOADINEG
BB R[a] = mrb_int(-b)
Definition opcode.h:128
@ OP_JMPNOT
BS if !R[a] pc+=b.
Definition opcode.h:163
@ OP_HASHCAT
B R[a] = hash_cat(R[a],R[a+1])
Definition opcode.h:209
@ OP_DEF
BB R[a].newmethod(Syms[b],R[a+1]); R[a] = Syms[b].
Definition opcode.h:219
@ OP_LOADI_2
B R[a] = mrb_int(2)
Definition opcode.h:132
@ OP_SETCV
BB cvset(Syms[b],R[a])
Definition opcode.h:152
@ OP_GT
B R[a] = R[a]>R[a+1].
Definition opcode.h:193
@ OP_KEYEND
Z raise unless kdict.empty?
Definition opcode.h:178
@ OP_LOADI_0
B R[a] = mrb_int(0)
Definition opcode.h:130
@ OP_LE
B R[a] = R[a]<=R[a+1].
Definition opcode.h:192
@ OP_GETGV
BB R[a] = getglobal(Syms[b])
Definition opcode.h:145
@ OP_RETURN
B return R[a] (normal)
Definition opcode.h:180
@ OP_EXCEPT
B R[a] = exc.
Definition opcode.h:166
@ OP_MOVE
BB R[a] = R[b].
Definition opcode.h:125
@ OP_SETSV
BB Special[Syms[b]] = R[a].
Definition opcode.h:148
@ OP_ARRAY
BB R[a] = ary_new(R[a],R[a+1]..R[a+b])
Definition opcode.h:195
@ OP_ADDI
BB R[a] = R[a]+mrb_int(b)
Definition opcode.h:185
@ OP_SCLASS
B R[a] = R[a].singleton_class.
Definition opcode.h:222
@ OP_SUPER
BB R[a] = super(R[a+1],... ,R[a+b+1])
Definition opcode.h:174
@ OP_LOADL
BB R[a] = Pool[b].
Definition opcode.h:126
@ OP_GETCONST
BB R[a] = constget(Syms[b])
Definition opcode.h:153
@ OP_SETMCNST
BB R[a+1]Syms[b] = R[a].
Definition opcode.h:156
@ 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])
Definition opcode.h:172
@ OP_BLOCK
BB R[a] = lambda(Irep[b],L_BLOCK)
Definition opcode.h:211
@ OP_GETMCNST
BB R[a] = R[a]Syms[b].
Definition opcode.h:155
@ OP_LOADI16
BS R[a] = mrb_int(b)
Definition opcode.h:138
@ OP_JMPIF
BS if R[a] pc+=b.
Definition opcode.h:162
@ OP_JMP
S pc+=a.
Definition opcode.h:161
@ OP_HASH
BB R[a] = hash_new(R[a],R[a+1]..R[a+b*2-1])
Definition opcode.h:207