Skip to content

Commit

Permalink
Streamline INDIRECT_NAME_LOOKUP a bit
Browse files Browse the repository at this point in the history
- don't need to check for elems after split, name check will do
- don't need to specifically unbox strings
- use EXISTS-KEY vs :exists
- use AT-KEY vs {}
- remove TABs and other readability tweaks
  • Loading branch information
lizmat committed Dec 3, 2017
1 parent c9699ab commit 7615813
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/core/operators.pm
Expand Up @@ -584,9 +584,9 @@ sub INDIRECT_NAME_LOOKUP($root, *@chunks) is raw {
nqp::if(
# Note that each part of @chunks itself can contain double colons.
# That's why joining and re-splitting is necessary
nqp::elems(my $parts :=
nqp::split('::',my str $name = @chunks.join('::'))),
(my str $name = @chunks.join('::')),
nqp::stmts(
(my $parts := nqp::split('::',$name)),
(my str $first = nqp::shift($parts)),
nqp::if( # move the sigil to the last part of the name if available
nqp::elems($parts),
Expand All @@ -598,8 +598,7 @@ sub INDIRECT_NAME_LOOKUP($root, *@chunks) is raw {
|| nqp::iseq_s($sigil,'%')
|| nqp::iseq_s($sigil,'&'),
nqp::stmts(
nqp::push($parts,
nqp::concat($sigil,nqp::unbox_s(nqp::pop($parts)))),
nqp::push($parts,nqp::concat($sigil,nqp::pop($parts))),
($first = nqp::substr($first,1))
)
),
Expand All @@ -615,21 +614,22 @@ sub INDIRECT_NAME_LOOKUP($root, *@chunks) is raw {
(my Mu $thing := nqp::if(
$root.EXISTS-KEY('%REQUIRE_SYMBOLS')
&& (my $REQUIRE_SYMBOLS := $root.AT-KEY('%REQUIRE_SYMBOLS'))
&& ($REQUIRE_SYMBOLS{$first}:exists),
$REQUIRE_SYMBOLS{$first},
&& $REQUIRE_SYMBOLS.EXISTS-KEY($first),
$REQUIRE_SYMBOLS.AT-KEY($first),
nqp::if(
$root.EXISTS-KEY($first),
$root.AT-KEY($first),
nqp::if(
GLOBAL::.EXISTS-KEY($first),
GLOBAL::.AT-KEY($first),
nqp::if(
nqp::iseq_s($first, 'GLOBAL'),
GLOBAL,
nqp::iseq_s($first,'GLOBAL'),
GLOBAL,
X::NoSuchSymbol.new(symbol => $name).fail
)
)
))),
)
)),
nqp::while(
nqp::elems($parts),
nqp::if(
Expand All @@ -640,7 +640,7 @@ sub INDIRECT_NAME_LOOKUP($root, *@chunks) is raw {
),
$thing
),
X::NoSuchSymbol.new(symbol => $name).fail
Failure.new(X::NoSuchSymbol.new(symbol => ""))
)
}

Expand Down

0 comments on commit 7615813

Please sign in to comment.