Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
fd10c723
Unverified
Commit
fd10c723
authored
Jun 05, 2020
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove `OP_EXT[123]` from operands.
parent
ce7508e0
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
112 additions
and
293 deletions
+112
-293
doc/opcode.md
doc/opcode.md
+0
-11
include/mruby/opcode.h
include/mruby/opcode.h
+0
-27
include/mruby/ops.h
include/mruby/ops.h
+0
-3
mrbgems/mruby-compiler/core/codegen.c
mrbgems/mruby-compiler/core/codegen.c
+5
-83
src/codedump.c
src/codedump.c
+104
-135
src/vm.c
src/vm.c
+3
-34
No files found.
doc/opcode.md
View file @
fd10c723
...
...
@@ -20,14 +20,6 @@ sign) of operands.
*
sS: signed 16bit
*
W: 24bit
First two byte operands may be extended to 16bit. When those byte
operands are bigger than 256, the instruction will be prefixed by
`OP_EXT1`
(means 1st operand is 16bit) or
`OP_EXT2`
(means 2nd operand
is 16bit) or
`OP_EXT3`
(means 1st and 2nd operands are 16bit).
For instructions marked by
`'`
,
`OP_EXT1`
can be prefixed. For those
with
`"`
, either
`OP_EXT1`
or
`OP_EXT2`
or
`OP_EXT2`
can be prefixed.
## table.1 Instruction Table
| Instruction Name | Operand type | Semantics |
...
...
@@ -133,8 +125,5 @@ with `"`, either `OP_EXT1` or `OP_EXT2` or `OP_EXT2` can be prefixed.
| OP_TCLASS' | B | R(a) = target_class |
| OP_DEBUG" | BBB | print a,b,c |
| OP_ERR' | B | raise(LocalJumpError, Lit(a)) |
| OP_EXT1 | - | make 1st operand 16bit |
| OP_EXT2 | - | make 2nd operand 16bit |
| OP_EXT3 | - | make 1st and 2nd operands 16bit |
| OP_STOP | - | stop VM |
|------------------|--------------|--------------------------------------------------------|
include/mruby/opcode.h
View file @
fd10c723
...
...
@@ -39,31 +39,4 @@ enum mrb_insn {
#define FETCH_S() do {a=READ_S();} while (0)
#define FETCH_W() do {a=READ_W();} while (0)
/* with OP_EXT1 (1st 16bit) */
#define FETCH_Z_1() FETCH_Z()
#define FETCH_B_1() FETCH_S()
#define FETCH_BB_1() do {a=READ_S(); b=READ_B();} while (0)
#define FETCH_BBB_1() do {a=READ_S(); b=READ_B(); c=READ_B();} while (0)
#define FETCH_BS_1() do {a=READ_S(); b=READ_S();} while (0)
#define FETCH_S_1() FETCH_S()
#define FETCH_W_1() FETCH_W()
/* with OP_EXT2 (2nd 16bit) */
#define FETCH_Z_2() FETCH_Z()
#define FETCH_B_2() FETCH_B()
#define FETCH_BB_2() do {a=READ_B(); b=READ_S();} while (0)
#define FETCH_BBB_2() do {a=READ_B(); b=READ_S(); c=READ_B();} while (0)
#define FETCH_BS_2() FETCH_BS()
#define FETCH_S_2() FETCH_S()
#define FETCH_W_2() FETCH_W()
/* with OP_EXT3 (1st & 2nd 16bit) */
#define FETCH_Z_3() FETCH_Z()
#define FETCH_B_3() FETCH_B()
#define FETCH_BB_3() do {a=READ_S(); b=READ_S();} while (0)
#define FETCH_BBB_3() do {a=READ_S(); b=READ_S(); c=READ_B();} while (0)
#define FETCH_BS_3() do {a=READ_S(); b=READ_S();} while (0)
#define FETCH_S_3() FETCH_S()
#define FETCH_W_3() FETCH_W()
#endif
/* MRUBY_OPCODE_H */
include/mruby/ops.h
View file @
fd10c723
...
...
@@ -111,8 +111,5 @@ OPCODE(SCLASS, B) /* R(a) = R(a).singleton_class */
OPCODE
(
TCLASS
,
B
)
/* R(a) = target_class */
OPCODE
(
DEBUG
,
BBB
)
/* print a,b,c */
OPCODE
(
ERR
,
B
)
/* raise(LocalJumpError, Lit(a)) */
OPCODE
(
EXT1
,
Z
)
/* make 1st operand 16bit */
OPCODE
(
EXT2
,
Z
)
/* make 2nd operand 16bit */
OPCODE
(
EXT3
,
Z
)
/* make 1st and 2nd operands 16bit */
OPCODE
(
STOP
,
Z
)
/* stop VM */
OPCODE
(
LOADI16
,
BS
)
/* R(a) = mrb_int(b) */
mrbgems/mruby-compiler/core/codegen.c
View file @
fd10c723
...
...
@@ -217,9 +217,7 @@ genop_1(codegen_scope *s, mrb_code i, uint16_t a)
{
s
->
lastpc
=
s
->
pc
;
if
(
a
>
0xff
)
{
gen_B
(
s
,
OP_EXT1
);
gen_B
(
s
,
i
);
gen_S
(
s
,
a
);
codegen_error
(
s
,
"too big operand"
);
}
else
{
gen_B
(
s
,
i
);
...
...
@@ -231,23 +229,8 @@ static void
genop_2
(
codegen_scope
*
s
,
mrb_code
i
,
uint16_t
a
,
uint16_t
b
)
{
s
->
lastpc
=
s
->
pc
;
if
(
a
>
0xff
&&
b
>
0xff
)
{
gen_B
(
s
,
OP_EXT3
);
gen_B
(
s
,
i
);
gen_S
(
s
,
a
);
gen_S
(
s
,
b
);
}
else
if
(
b
>
0xff
)
{
gen_B
(
s
,
OP_EXT2
);
gen_B
(
s
,
i
);
gen_B
(
s
,
(
uint8_t
)
a
);
gen_S
(
s
,
b
);
}
else
if
(
a
>
0xff
)
{
gen_B
(
s
,
OP_EXT1
);
gen_B
(
s
,
i
);
gen_S
(
s
,
a
);
gen_B
(
s
,
(
uint8_t
)
b
);
if
(
a
>
0xff
||
b
>
0xff
)
{
codegen_error
(
s
,
"too big operand"
);
}
else
{
gen_B
(
s
,
i
);
...
...
@@ -309,32 +292,6 @@ mrb_decode_insn(const mrb_code *pc)
#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x (); break;
#include "mruby/ops.h"
#undef OPCODE
}
switch
(
insn
)
{
case
OP_EXT1
:
insn
=
READ_B
();
switch
(
insn
)
{
#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _1 (); break;
#include "mruby/ops.h"
#undef OPCODE
}
break
;
case
OP_EXT2
:
insn
=
READ_B
();
switch
(
insn
)
{
#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _2 (); break;
#include "mruby/ops.h"
#undef OPCODE
}
break
;
case
OP_EXT3
:
insn
=
READ_B
();
switch
(
insn
)
{
#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _3 (); break;
#include "mruby/ops.h"
#undef OPCODE
}
break
;
default:
break
;
}
...
...
@@ -391,11 +348,8 @@ genjmp2(codegen_scope *s, mrb_code i, uint16_t a, int pc, int val)
s
->
lastpc
=
s
->
pc
;
if
(
a
>
0xff
)
{
gen_B
(
s
,
OP_EXT1
);
gen_B
(
s
,
i
);
gen_S
(
s
,
a
);
pos
=
s
->
pc
;
gen_S
(
s
,
pc
);
codegen_error
(
s
,
"too big operand"
);
pos
=
0
;
}
else
{
gen_B
(
s
,
i
);
...
...
@@ -3314,35 +3268,3 @@ uint8_t mrb_insn_size[] = {
#undef SB
#undef BBB
};
/* EXT1 instruction sizes */
uint8_t
mrb_insn_size1
[]
=
{
#define B 3
#define BB 4
#define BBB 5
#define BS 5
#define SB 5
#define OPCODE(_,x) x,
#include "mruby/ops.h"
#undef OPCODE
#undef B
};
/* EXT2 instruction sizes */
uint8_t
mrb_insn_size2
[]
=
{
#define B 2
#define OPCODE(_,x) x,
#include "mruby/ops.h"
#undef OPCODE
#undef BB
#undef BBB
#undef BS
#undef SB
};
/* EXT3 instruction sizes */
#define BB 5
#define BBB 6
#define BS 4
#define SB 5
uint8_t
mrb_insn_size3
[]
=
{
#define OPCODE(_,x) x,
#include "mruby/ops.h"
};
src/codedump.c
View file @
fd10c723
This diff is collapsed.
Click to expand it.
src/vm.c
View file @
fd10c723
...
...
@@ -901,7 +901,7 @@ argnum_error(mrb_state *mrb, mrb_int num)
#ifndef DIRECT_THREADED
#define INIT_DISPATCH for (;;) { insn = BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); switch (insn) {
#define CASE(insn,ops) case insn: pc0=pc++; FETCH_ ## ops ();
; L_ ## insn ## _BODY:
#define CASE(insn,ops) case insn: pc0=pc++; FETCH_ ## ops ();
#define NEXT break
#define JUMP NEXT
#define END_DISPATCH }}
...
...
@@ -909,7 +909,7 @@ argnum_error(mrb_state *mrb, mrb_int num)
#else
#define INIT_DISPATCH JUMP; return mrb_nil_value();
#define CASE(insn,ops) L_ ## insn: pc0=pc++; FETCH_ ## ops ();
L_ ## insn ## _BODY:
#define CASE(insn,ops) L_ ## insn: pc0=pc++; FETCH_ ## ops ();
#define NEXT insn=BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); goto *optable[insn]
#define JUMP NEXT
...
...
@@ -1512,7 +1512,7 @@ RETRY_TRY_BLOCK:
mrb
->
c
->
stack
[
0
]
=
mrb_nil_value
();
a
=
0
;
c
=
OP_R_NORMAL
;
goto
L_
OP_RETURN_BODY
;
goto
L_
RETURN
;
}
pool
=
irep
->
pool
;
syms
=
irep
->
syms
;
...
...
@@ -2733,37 +2733,6 @@ RETRY_TRY_BLOCK:
goto
L_RAISE
;
}
CASE
(
OP_EXT1
,
Z
)
{
insn
=
READ_B
();
switch
(
insn
)
{
#define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _1(); goto L_OP_ ## insn ## _BODY;
#include "mruby/ops.h"
#undef OPCODE
}
pc
--
;
NEXT
;
}
CASE
(
OP_EXT2
,
Z
)
{
insn
=
READ_B
();
switch
(
insn
)
{
#define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _2(); goto L_OP_ ## insn ## _BODY;
#include "mruby/ops.h"
#undef OPCODE
}
pc
--
;
NEXT
;
}
CASE
(
OP_EXT3
,
Z
)
{
uint8_t
insn
=
READ_B
();
switch
(
insn
)
{
#define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _3(); goto L_OP_ ## insn ## _BODY;
#include "mruby/ops.h"
#undef OPCODE
}
pc
--
;
NEXT
;
}
CASE
(
OP_STOP
,
Z
)
{
/* stop VM */
L_STOP:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment