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
d0fed634
Unverified
Commit
d0fed634
authored
Jul 22, 2021
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
codegen.c: add constant folding for unary numeric operators (+, -, ~).
parent
3e9ed1cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
8 deletions
+20
-8
mrbgems/mruby-compiler/core/codegen.c
mrbgems/mruby-compiler/core/codegen.c
+20
-8
No files found.
mrbgems/mruby-compiler/core/codegen.c
View file @
d0fed634
...
...
@@ -549,7 +549,7 @@ gen_return(codegen_scope *s, uint8_t op, uint16_t src)
}
static
mrb_bool
get_int_operand
(
struct
mrb_insn_data
*
data
,
int32_
t
*
n
)
get_int_operand
(
struct
mrb_insn_data
*
data
,
mrb_in
t
*
n
)
{
switch
(
data
->
insn
)
{
case
OP_LOADI__1
:
...
...
@@ -571,7 +571,7 @@ get_int_operand(struct mrb_insn_data *data, int32_t *n)
return
TRUE
;
case
OP_LOADI32
:
*
n
=
(
int32_
t
)((
uint32_t
)
data
->
b
<<
16
)
+
data
->
c
;
*
n
=
(
mrb_in
t
)((
uint32_t
)
data
->
b
<<
16
)
+
data
->
c
;
return
TRUE
;
default:
...
...
@@ -589,7 +589,7 @@ gen_addsub(codegen_scope *s, uint8_t op, uint16_t dst)
}
else
{
struct
mrb_insn_data
data
=
mrb_last_insn
(
s
);
int32_
t
n
;
mrb_in
t
n
;
if
(
!
get_int_operand
(
&
data
,
&
n
))
{
/* not integer immediate */
...
...
@@ -859,17 +859,23 @@ gen_int(codegen_scope *s, uint16_t dst, mrb_int i)
}
static
void
gen_u
minus
(
codegen_scope
*
s
,
uint16_t
dst
)
gen_u
niop
(
codegen_scope
*
s
,
mrb_sym
sym
,
uint16_t
dst
)
{
struct
mrb_insn_data
data
=
mrb_last_insn
(
s
);
int32_
t
n
;
mrb_in
t
n
;
if
(
get_int_operand
(
&
data
,
&
n
))
{
s
->
pc
=
s
->
lastpc
;
gen_int
(
s
,
dst
,
-
n
);
if
(
sym
==
MRB_OPSYM_2
(
s
->
mrb
,
minus
))
{
n
=
-
n
;
}
else
if
(
sym
==
MRB_OPSYM_2
(
s
->
mrb
,
neg
))
{
n
=
~
n
;
}
gen_int
(
s
,
dst
,
n
);
}
else
{
genop_3
(
s
,
OP_SEND
,
dst
,
new_sym
(
s
,
MRB_OPSYM_2
(
s
->
mrb
,
minus
)
),
0
);
genop_3
(
s
,
OP_SEND
,
dst
,
new_sym
(
s
,
sym
),
0
);
}
}
...
...
@@ -1348,6 +1354,12 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
else
if
(
!
noop
&&
sym
==
MRB_OPSYM_2
(
s
->
mrb
,
eq
)
&&
n
==
1
)
{
genop_1
(
s
,
OP_EQ
,
cursp
());
}
else
if
(
!
noop
&&
n
==
0
&&
(
sym
==
MRB_OPSYM_2
(
s
->
mrb
,
plus
)
||
sym
==
MRB_OPSYM_2
(
s
->
mrb
,
minus
)
||
sym
==
MRB_OPSYM_2
(
s
->
mrb
,
neg
)))
{
gen_uniop
(
s
,
sym
,
cursp
());
}
else
{
int
idx
=
new_sym
(
s
,
sym
);
...
...
@@ -2708,7 +2720,7 @@ codegen(codegen_scope *s, node *tree, int val)
codegen
(
s
,
tree
,
VAL
);
pop
();
push_n
(
2
);
pop_n
(
2
);
/* space for receiver&block */
gen_u
minus
(
s
,
cursp
());
gen_u
niop
(
s
,
MRB_OPSYM_2
(
s
->
mrb
,
minus
)
,
cursp
());
push
();
}
else
{
...
...
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