Skip to content

Commit 2be348a

Browse files
committed
mv opcode.h -> include/mruby/opcode.h and remove duplication from mruby-eval gem
1 parent f10331c commit 2be348a

6 files changed

Lines changed: 6 additions & 164 deletions

File tree

mrbgems/mruby-eval/src/eval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "mruby/compile.h"
33
#include "mruby/irep.h"
44
#include "mruby/proc.h"
5-
#include "opcode.h"
5+
#include "mruby/opcode.h"
66

77
static struct mrb_irep *
88
get_closure_irep(mrb_state *mrb, int level)

src/codegen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "mruby/string.h"
1616
#include "mruby/debug.h"
1717
#include "node.h"
18-
#include "opcode.h"
18+
#include "mruby/opcode.h"
1919
#include "mruby/re.h"
2020
#include "mrb_throw.h"
2121

src/opcode.h

Lines changed: 2 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,2 @@
1-
/*
2-
** opcode.h - RiteVM operation codes
3-
**
4-
** See Copyright Notice in mruby.h
5-
*/
6-
7-
#ifndef OPCODE_H
8-
#define OPCODE_H
9-
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) := Lit(Bx) */
59-
OP_LOADI,/* A sBx R(A) := sBx */
60-
OP_LOADSYM,/* A Bx R(A) := Sym(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(Sym(Bx)) */
67-
OP_SETGLOBAL,/* A Bx setglobal(Sym(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(Sym(Bx)) */
71-
OP_SETIV,/* A Bx ivset(Sym(Bx),R(A)) */
72-
OP_GETCV,/* A Bx R(A) := cvget(Sym(Bx)) */
73-
OP_SETCV,/* A Bx cvset(Sym(Bx),R(A)) */
74-
OP_GETCONST,/* A Bx R(A) := constget(Sym(Bx)) */
75-
OP_SETCONST,/* A Bx constset(Sym(Bx),R(A)) */
76-
OP_GETMCNST,/* A Bx R(A) := R(A)::Sym(Bx) */
77-
OP_SETMCNST,/* A Bx R(A+1)::Sym(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 clear(exc); R(A) := exception (ignore when A=0) */
86-
OP_POPERR,/* A A.times{rescue_pop()} */
87-
OP_RAISE,/* A raise(R(A)) */
88-
OP_EPUSH,/* Bx ensure_push(SEQ[Bx]) */
89-
OP_EPOP,/* A A.times{ensure_pop().call} */
90-
91-
OP_SEND,/* A B C R(A) := call(R(A),mSym(B),R(A+1),...,R(A+C)) */
92-
OP_SENDB,/* A B C R(A) := call(R(A),mSym(B),R(A+1),...,R(A+C),&R(A+C+1))*/
93-
OP_FSEND,/* A B C R(A) := fcall(R(A),mSym(B),R(A+1),...,R(A+C-1)) */
94-
OP_CALL,/* A B C R(A) := self.call(R(A),.., R(A+C)) */
95-
OP_SUPER,/* A B C R(A) := super(R(A+1),... ,R(A+C-1)) */
96-
OP_ARGARY,/* A Bx R(A) := argument array (16=6:1:5:4) */
97-
OP_ENTER,/* Ax arg setup according to flags (23=5:5:1:5:5:1:1) */
98-
OP_KARG,/* A B C R(A) := kdict[mSym(B)]; if C kdict.rm(mSym(B)) */
99-
OP_KDICT,/* A C R(A) := kdict */
100-
101-
OP_RETURN,/* A B return R(A) (B=normal,in-block return/break) */
102-
OP_TAILCALL,/* A B C return call(R(A),mSym(B),*R(C)) */
103-
OP_BLKPUSH,/* A Bx R(A) := block (16=6:1:5:4) */
104-
105-
OP_ADD,/* A B C R(A) := R(A)+R(A+1) (mSyms[B]=:+,C=1) */
106-
OP_ADDI,/* A B C R(A) := R(A)+C (mSyms[B]=:+) */
107-
OP_SUB,/* A B C R(A) := R(A)-R(A+1) (mSyms[B]=:-,C=1) */
108-
OP_SUBI,/* A B C R(A) := R(A)-C (mSyms[B]=:-) */
109-
OP_MUL,/* A B C R(A) := R(A)*R(A+1) (mSyms[B]=:*,C=1) */
110-
OP_DIV,/* A B C R(A) := R(A)/R(A+1) (mSyms[B]=:/,C=1) */
111-
OP_EQ,/* A B C R(A) := R(A)==R(A+1) (mSyms[B]=:==,C=1) */
112-
OP_LT,/* A B C R(A) := R(A)<R(A+1) (mSyms[B]=:<,C=1) */
113-
OP_LE,/* A B C R(A) := R(A)<=R(A+1) (mSyms[B]=:<=,C=1) */
114-
OP_GT,/* A B C R(A) := R(A)>R(A+1) (mSyms[B]=:>,C=1) */
115-
OP_GE,/* A B C R(A) := R(A)>=R(A+1) (mSyms[B]=:>=,C=1) */
116-
117-
OP_ARRAY,/* A B C R(A) := ary_new(R(B),R(B+1)..R(B+C)) */
118-
OP_ARYCAT,/* A B ary_cat(R(A),R(B)) */
119-
OP_ARYPUSH,/* A B ary_push(R(A),R(B)) */
120-
OP_AREF,/* A B C R(A) := R(B)[C] */
121-
OP_ASET,/* A B C R(B)[C] := R(A) */
122-
OP_APOST,/* A B C *R(A),R(A+1)..R(A+C) := R(A) */
123-
124-
OP_STRING,/* A Bx R(A) := str_dup(Lit(Bx)) */
125-
OP_STRCAT,/* A B str_cat(R(A),R(B)) */
126-
127-
OP_HASH,/* A B C R(A) := hash_new(R(B),R(B+1)..R(B+C)) */
128-
OP_LAMBDA,/* A Bz Cz R(A) := lambda(SEQ[Bz],Cz) */
129-
OP_RANGE,/* A B C R(A) := range_new(R(B),R(B+1),C) */
130-
131-
OP_OCLASS,/* A R(A) := ::Object */
132-
OP_CLASS,/* A B R(A) := newclass(R(A),mSym(B),R(A+1)) */
133-
OP_MODULE,/* A B R(A) := newmodule(R(A),mSym(B)) */
134-
OP_EXEC,/* A Bx R(A) := blockexec(R(A),SEQ[Bx]) */
135-
OP_METHOD,/* A B R(A).newmethod(mSym(B),R(A+1)) */
136-
OP_SCLASS,/* A B R(A) := R(B).singleton_class */
137-
OP_TCLASS,/* A R(A) := target_class */
138-
139-
OP_DEBUG,/* A print R(A) */
140-
OP_STOP,/* stop VM */
141-
OP_ERR,/* Bx raise RuntimeError with message Lit(Bx) */
142-
143-
OP_RSVD1,/* reserved instruction #1 */
144-
OP_RSVD2,/* reserved instruction #2 */
145-
OP_RSVD3,/* reserved instruction #3 */
146-
OP_RSVD4,/* reserved instruction #4 */
147-
OP_RSVD5,/* reserved instruction #5 */
148-
};
149-
150-
#define OP_L_STRICT 1
151-
#define OP_L_CAPTURE 2
152-
#define OP_L_METHOD OP_L_STRICT
153-
#define OP_L_LAMBDA (OP_L_STRICT|OP_L_CAPTURE)
154-
#define OP_L_BLOCK OP_L_CAPTURE
155-
156-
#define OP_R_NORMAL 0
157-
#define OP_R_BREAK 1
158-
#define OP_R_RETURN 2
159-
160-
#endif /* OPCODE_H */
1+
/* this header file is to be removed soon. */
2+
#include "mruby/opcode.h"

src/proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "mruby.h"
88
#include "mruby/class.h"
99
#include "mruby/proc.h"
10-
#include "opcode.h"
10+
#include "mruby/opcode.h"
1111

1212
static mrb_code call_iseq[] = {
1313
MKOP_A(OP_CALL, 0),

src/vm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "mruby/string.h"
1919
#include "mruby/variable.h"
2020
#include "mruby/error.h"
21-
#include "opcode.h"
21+
#include "mruby/opcode.h"
2222
#include "value_array.h"
2323
#include "mrb_throw.h"
2424

0 commit comments

Comments
 (0)