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
e42f1928
Unverified
Commit
e42f1928
authored
Jul 21, 2021
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
codegen.c: skip `-@` call if the argument is a literal integer.
parent
2ef6e944
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
14 deletions
+29
-14
mrbgems/mruby-compiler/core/codegen.c
mrbgems/mruby-compiler/core/codegen.c
+17
-2
mrbgems/mruby-compiler/core/parse.y
mrbgems/mruby-compiler/core/parse.y
+6
-6
mrbgems/mruby-compiler/core/y.tab.c
mrbgems/mruby-compiler/core/y.tab.c
+6
-6
No files found.
mrbgems/mruby-compiler/core/codegen.c
View file @
e42f1928
...
...
@@ -858,6 +858,21 @@ gen_int(codegen_scope *s, uint16_t dst, mrb_int i)
}
}
static
void
gen_uminus
(
codegen_scope
*
s
,
uint16_t
dst
)
{
struct
mrb_insn_data
data
=
mrb_last_insn
(
s
);
int32_t
n
;
if
(
get_int_operand
(
&
data
,
&
n
))
{
s
->
pc
=
s
->
lastpc
;
gen_int
(
s
,
dst
,
-
n
);
}
else
{
genop_3
(
s
,
OP_SEND
,
dst
,
new_sym
(
s
,
MRB_OPSYM_2
(
s
->
mrb
,
minus
)),
0
);
}
}
static
int
node_len
(
node
*
tree
)
{
...
...
@@ -2695,10 +2710,10 @@ codegen(codegen_scope *s, node *tree, int val)
default:
if
(
val
)
{
int
sym
=
new_sym
(
s
,
MRB_OPSYM_2
(
s
->
mrb
,
minus
));
codegen
(
s
,
tree
,
VAL
);
pop
();
genop_3
(
s
,
OP_SEND
,
cursp
(),
sym
,
0
);
push_n
(
2
);
pop_n
(
2
);
/* space for receiver&block */
gen_uminus
(
s
,
cursp
());
push
();
}
else
{
...
...
mrbgems/mruby-compiler/core/parse.y
View file @
e42f1928
...
...
@@ -1248,7 +1248,7 @@ call_with_block(parser_state *p, node *a, node *b)
}
static node*
ne
gate_lit
(parser_state *p, node *n)
ne
w_negate
(parser_state *p, node *n)
{
return cons((node*)NODE_NEGATE, n);
}
...
...
@@ -2292,11 +2292,11 @@ arg : lhs '=' arg_rhs
}
| tUMINUS_NUM tINTEGER tPOW arg
{
$$ =
call_uni_op(p, call_bin_op(p, $2, "**", $4), "-@"
);
$$ =
new_negate(p, call_bin_op(p, $2, "**", $4)
);
}
| tUMINUS_NUM tFLOAT tPOW arg
{
$$ =
call_uni_op(p, call_bin_op(p, $2, "**", $4), "-@"
);
$$ =
new_negate(p, call_bin_op(p, $2, "**", $4)
);
}
| tUPLUS arg
{
...
...
@@ -2304,7 +2304,7 @@ arg : lhs '=' arg_rhs
}
| tUMINUS arg
{
$$ =
call_uni_op(p, $2, "-@"
);
$$ =
new_negate(p, $2
);
}
| arg '|' arg
{
...
...
@@ -3463,11 +3463,11 @@ numeric : tINTEGER
| tFLOAT
| tUMINUS_NUM tINTEGER %prec tLOWEST
{
$$ = ne
gate_lit
(p, $2);
$$ = ne
w_negate
(p, $2);
}
| tUMINUS_NUM tFLOAT %prec tLOWEST
{
$$ = ne
gate_lit
(p, $2);
$$ = ne
w_negate
(p, $2);
}
;
...
...
mrbgems/mruby-compiler/core/y.tab.c
View file @
e42f1928
...
...
@@ -1311,7 +1311,7 @@ call_with_block(parser_state *p, node *a, node *b)
}
static
node
*
ne
gate_lit
(
parser_state
*
p
,
node
*
n
)
ne
w_negate
(
parser_state
*
p
,
node
*
n
)
{
return
cons
((
node
*
)
NODE_NEGATE
,
n
);
}
...
...
@@ -7376,7 +7376,7 @@ yyreduce:
case
219
:
#line 2294 "mrbgems/mruby-compiler/core/parse.y"
{
(
yyval
.
nd
)
=
call_uni_op
(
p
,
call_bin_op
(
p
,
(
yyvsp
[
-
2
].
nd
),
"**"
,
(
yyvsp
[
0
].
nd
)),
"-@"
);
(
yyval
.
nd
)
=
new_negate
(
p
,
call_bin_op
(
p
,
(
yyvsp
[
-
2
].
nd
),
"**"
,
(
yyvsp
[
0
].
nd
))
);
}
#line 7382 "mrbgems/mruby-compiler/core/y.tab.c"
break
;
...
...
@@ -7384,7 +7384,7 @@ yyreduce:
case
220
:
#line 2298 "mrbgems/mruby-compiler/core/parse.y"
{
(
yyval
.
nd
)
=
call_uni_op
(
p
,
call_bin_op
(
p
,
(
yyvsp
[
-
2
].
nd
),
"**"
,
(
yyvsp
[
0
].
nd
)),
"-@"
);
(
yyval
.
nd
)
=
new_negate
(
p
,
call_bin_op
(
p
,
(
yyvsp
[
-
2
].
nd
),
"**"
,
(
yyvsp
[
0
].
nd
))
);
}
#line 7390 "mrbgems/mruby-compiler/core/y.tab.c"
break
;
...
...
@@ -7400,7 +7400,7 @@ yyreduce:
case
222
:
#line 2306 "mrbgems/mruby-compiler/core/parse.y"
{
(
yyval
.
nd
)
=
call_uni_op
(
p
,
(
yyvsp
[
0
].
nd
),
"-@"
);
(
yyval
.
nd
)
=
new_negate
(
p
,
(
yyvsp
[
0
].
nd
)
);
}
#line 7406 "mrbgems/mruby-compiler/core/y.tab.c"
break
;
...
...
@@ -9183,7 +9183,7 @@ yyreduce:
case
477
:
#line 3465 "mrbgems/mruby-compiler/core/parse.y"
{
(
yyval
.
nd
)
=
ne
gate_lit
(
p
,
(
yyvsp
[
0
].
nd
));
(
yyval
.
nd
)
=
ne
w_negate
(
p
,
(
yyvsp
[
0
].
nd
));
}
#line 9189 "mrbgems/mruby-compiler/core/y.tab.c"
break
;
...
...
@@ -9191,7 +9191,7 @@ yyreduce:
case
478
:
#line 3469 "mrbgems/mruby-compiler/core/parse.y"
{
(
yyval
.
nd
)
=
ne
gate_lit
(
p
,
(
yyvsp
[
0
].
nd
));
(
yyval
.
nd
)
=
ne
w_negate
(
p
,
(
yyvsp
[
0
].
nd
));
}
#line 9197 "mrbgems/mruby-compiler/core/y.tab.c"
break
;
...
...
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