Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use str constraint on various paths.
The goal being that we can stick a native `str` on the $name of the
QAST::Block.symbol method, which accounts for an overwhelming amount
of boxing in EVAL-heavy situations.
  • Loading branch information
jnthn committed Mar 9, 2016
1 parent 8e41e49 commit ae15d62
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/NQP/Actions.nqp
Expand Up @@ -571,7 +571,7 @@ class NQP::Actions is HLL::Actions {
$ast.fallback( default_for( $<sigil> ) );
}
else {
my $name := ~@name.pop;
my str $name := ~@name.pop;
my int $is_lex := 0;
if $*IN_DECL eq 'variable' || $name eq '$_' || $name eq '$/' || $name eq ''
|| $name eq '$!' || $<twigil> eq '?' || ($is_lex := $*W.is_lexical($name)) {
Expand Down Expand Up @@ -604,14 +604,14 @@ class NQP::Actions is HLL::Actions {
if $*SCOPE eq 'our' || $*SCOPE eq '' {
$*W.install_package_symbol($*OUTERPACKAGE, $<name><identifier>, $PACKAGE);
if +$<name><identifier> == 1 {
$*W.install_lexical_symbol($*W.cur_lexpad(), $<name><identifier>[0], $PACKAGE);
$*W.install_lexical_symbol($*W.cur_lexpad(), ~$<name><identifier>[0], $PACKAGE);
}
}
elsif $*SCOPE eq 'my' {
if +$<name><identifier> != 1 {
$<name>.CURSOR.panic("A my scoped package cannot have a multi-part name yet");
}
$*W.install_lexical_symbol($*W.cur_lexpad(), $<name><identifier>[0], $PACKAGE);
$*W.install_lexical_symbol($*W.cur_lexpad(), ~$<name><identifier>[0], $PACKAGE);
}
else {
$/.CURSOR.panic("$*SCOPE scoped packages are not supported");
Expand Down Expand Up @@ -1737,7 +1737,7 @@ class NQP::Actions is HLL::Actions {
# then strip it off.
else {
my $path;
if $*W.is_lexical(@name[0]) {
if $*W.is_lexical(~@name[0]) {
try {
my $first := @name.shift();
$path := QAST::WVal.new( :value($*W.find_sym([$first])) );
Expand Down
5 changes: 2 additions & 3 deletions src/NQP/Grammar.nqp
Expand Up @@ -420,14 +420,14 @@ grammar NQP::Grammar is HLL::Grammar {
if $*SCOPE eq 'our' || $*SCOPE eq '' {
$*W.install_package_symbol($*OUTERPACKAGE, $<name><identifier>, $*PACKAGE);
if +$<name><identifier> == 1 {
$*W.install_lexical_symbol($OUTER, $<name><identifier>[0], $*PACKAGE);
$*W.install_lexical_symbol($OUTER, ~$<name><identifier>[0], $*PACKAGE);
}
}
elsif $*SCOPE eq 'my' {
if +$<name><identifier> != 1 {
$<name>.CURSOR.panic("A my scoped package cannot have a multi-part name yet");
}
$*W.install_lexical_symbol($OUTER, $<name><identifier>[0], $*PACKAGE);
$*W.install_lexical_symbol($OUTER, ~$<name><identifier>[0], $*PACKAGE);
}
else {
$/.CURSOR.panic("$*SCOPE scoped packages are not supported");
Expand Down Expand Up @@ -881,4 +881,3 @@ grammar NQP::Regex is QRegex::P6Regex::Grammar {
<quote_EXPR=.LANG('MAIN','quote_EXPR')>
}
}

16 changes: 8 additions & 8 deletions src/NQP/World.nqp
Expand Up @@ -180,7 +180,7 @@ class NQP::World is HLL::World {

# Installs a lexical symbol. Takes a QAST::Block object, name and
# the object to install.
method install_lexical_symbol($block, $name, $obj) {
method install_lexical_symbol($block, str $name, $obj) {
$block.symbol($name, :scope('lexical'), :value($obj));
$block[0].push(QAST::Var.new(
:scope('lexical'), :name($name), :decl('static'), :value($obj)
Expand Down Expand Up @@ -552,19 +552,19 @@ class NQP::World is HLL::World {

# Checks if the given name is known anywhere in the lexpad
# and with lexical scope.
method is_lexical($name) {
method is_lexical(str $name) {
self.is_scope($name, 'lexical')
}

# Checks if the given name is known anywhere in the lexpad
# and with package scope.
method is_package($name) {
method is_package(str $name) {
self.is_scope($name, 'package')
}

# Checks if a given name is known in the lexpad anywhere
# with the specified scope.
method is_scope($name, $wanted_scope) {
method is_scope(str $name, $wanted_scope) {
my $i := +@!BLOCKS;
while $i > 0 {
$i := $i - 1;
Expand All @@ -577,7 +577,7 @@ class NQP::World is HLL::World {
}

# Gets the type of a lexical.
method lexical_type($name) {
method lexical_type(str $name) {
my $i := +@!BLOCKS;
while $i > 0 {
$i := $i - 1;
Expand Down Expand Up @@ -609,7 +609,7 @@ class NQP::World is HLL::World {
# If it's a single-part name, look through the lexical
# scopes.
if +@name == 1 {
my $final_name := @name[0];
my str $final_name := ~@name[0];
my $i := +@!BLOCKS;
while $i > 0 {
$i := $i - 1;
Expand All @@ -625,8 +625,8 @@ class NQP::World is HLL::World {
# in GLOBALish.
my $result := $*GLOBALish;
if +@name >= 2 {
my $first := @name[0];
my $i := +@!BLOCKS;
my str $first := ~@name[0];
my int $i := +@!BLOCKS;
while $i > 0 {
$i := $i - 1;
my %sym := @!BLOCKS[$i].symbol($first);
Expand Down

0 comments on commit ae15d62

Please sign in to comment.