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
863671c8
Unverified
Commit
863671c8
authored
Sep 24, 2021
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
codegen.c: refactor `NODE_IF` generation for boolean constants.
In addition, add `NODE_SYM` for always true expression.
parent
a844f896
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
16 deletions
+37
-16
mrbgems/mruby-compiler/core/codegen.c
mrbgems/mruby-compiler/core/codegen.c
+37
-16
No files found.
mrbgems/mruby-compiler/core/codegen.c
View file @
863671c8
...
...
@@ -1942,6 +1942,32 @@ gen_retval(codegen_scope *s, node *tree)
}
}
static
mrb_bool
true_always
(
node
*
tree
)
{
switch
(
nint
(
tree
->
car
))
{
case
NODE_TRUE
:
case
NODE_INT
:
case
NODE_STR
:
case
NODE_SYM
:
return
TRUE
;
default:
return
FALSE
;
}
}
static
mrb_bool
false_always
(
node
*
tree
)
{
switch
(
nint
(
tree
->
car
))
{
case
NODE_FALSE
:
case
NODE_NIL
:
return
TRUE
;
default:
return
FALSE
;
}
}
static
void
codegen
(
codegen_scope
*
s
,
node
*
tree
,
int
val
)
{
...
...
@@ -2133,27 +2159,22 @@ codegen(codegen_scope *s, node *tree, int val)
codegen
(
s
,
elsepart
,
val
);
goto
exit
;
}
switch
(
nint
(
tree
->
car
->
car
))
{
case
NODE_TRUE
:
case
NODE_INT
:
case
NODE_STR
:
if
(
true_always
(
tree
->
car
))
{
codegen
(
s
,
tree
->
cdr
->
car
,
val
);
goto
exit
;
case
NODE_FALSE
:
case
NODE_NIL
:
}
if
(
false_always
(
tree
->
car
))
{
codegen
(
s
,
elsepart
,
val
);
goto
exit
;
case
NODE_CALL
:
{
node
*
n
=
tree
->
car
->
cdr
;
mrb_sym
mid
=
nsym
(
n
->
cdr
->
car
);
mrb_sym
mnil
=
MRB_SYM_Q_2
(
s
->
mrb
,
nil
);
if
(
mid
==
mnil
&&
n
->
cdr
->
cdr
->
car
==
NULL
)
{
nil_p
=
TRUE
;
codegen
(
s
,
n
->
car
,
VAL
);
}
}
if
(
nint
(
tree
->
car
->
car
)
==
NODE_CALL
)
{
node
*
n
=
tree
->
car
->
cdr
;
mrb_sym
mid
=
nsym
(
n
->
cdr
->
car
);
mrb_sym
sym_nil_p
=
MRB_SYM_Q_2
(
s
->
mrb
,
nil
);
if
(
mid
==
sym_nil_p
&&
n
->
cdr
->
cdr
->
car
==
NULL
)
{
nil_p
=
TRUE
;
codegen
(
s
,
n
->
car
,
VAL
);
}
break
;
}
if
(
!
nil_p
)
{
codegen
(
s
,
tree
->
car
,
VAL
);
...
...
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