Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't walk whole setting symbol table on load.
This should help avoid some deserialization work, or at least get rid
of one more thing that forces a bunch of it.
  • Loading branch information
jnthn committed Aug 14, 2014
1 parent a5f15a2 commit c2362f4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/HLL/Actions.nqp
Expand Up @@ -55,7 +55,7 @@ class HLL::Actions {
unless $block.symbol($key) {
my $lextype := nqp::lexprimspec($pad, $key);
if $lextype == 0 {
$block.symbol($key, :scope<lexical>, :value(nqp::atkey($pad, $key)));
$block.symbol($key, :scope<lexical>, :lazy_value_from($pad));
}
elsif $lextype == 1 {
$block.symbol($key, :scope<lexical>, :value(nqp::atkey_i($pad, $key)), :type(int));
Expand Down
7 changes: 5 additions & 2 deletions src/NQP/Optimizer.nqp
Expand Up @@ -431,8 +431,11 @@ class NQP::Optimizer {

method find_sym($name) {
my %sym := self.find_lex($name);
if !(%sym =:= NQPMu) && nqp::existskey(%sym, 'value') {
return %sym<value>;
if nqp::ishash(%sym) && nqp::existskey(%sym, 'value') {
%sym<value>;
}
elsif nqp::ishash(%sym) && nqp::existskey(%sym, 'lazy_value_from') {
%sym<value> := nqp::atkey(nqp::atkey(%sym, 'lazy_value_from'), $name)
}
else {
nqp::die("No compile-time value for $name");
Expand Down
34 changes: 18 additions & 16 deletions src/NQP/World.nqp
Expand Up @@ -445,8 +445,8 @@ class NQP::World is HLL::World {
$i := $i - 1;
my %symbols := @!BLOCKS[$i].symtable();
for %symbols {
if !%seen{$_.key} && nqp::existskey($_.value, 'value') {
my $value := ($_.value)<value>;
if !%seen{$_.key} && nqp::existskey($_.value, 'value') || nqp::existskey($_.value, 'lazy_value_from') {
my $value := self.force_value($_.value, $_.key, 0);
unless nqp::isnull(nqp::getobjsc($value)) {
$wrapper[0].push(QAST::Op.new(
:op('bind'),
Expand Down Expand Up @@ -612,12 +612,7 @@ class NQP::World is HLL::World {
$i := $i - 1;
my %sym := @!BLOCKS[$i].symbol($final_name);
if %sym {
if nqp::existskey(%sym, 'value') {
return %sym<value>;
}
else {
nqp::die("No compile-time value for $final_name");
}
return self.force_value(%sym, $final_name, 1);
}
}
}
Expand All @@ -633,14 +628,9 @@ class NQP::World is HLL::World {
$i := $i - 1;
my %sym := @!BLOCKS[$i].symbol($first);
if +%sym {
if nqp::existskey(%sym, 'value') {
$result := %sym<value>;
@name.shift();
$i := 0;
}
else {
nqp::die("No compile-time value for $first");
}
$result := self.force_value(%sym, $first, 1);
@name.shift();
$i := 0;
}
}
}
Expand All @@ -658,4 +648,16 @@ class NQP::World is HLL::World {

$result;
}

method force_value(%sym, $key, int $die) {
if nqp::existskey(%sym, 'value') {
%sym<value>
}
elsif nqp::existskey(%sym, 'lazy_value_from') {
%sym<value> := nqp::atkey(nqp::atkey(%sym, 'lazy_value_from'), $key)
}
else {
$die ?? nqp::die("No compile-time value for $key") !! NQPMu
}
}
}

0 comments on commit c2362f4

Please sign in to comment.