From: Matt S Trout Date: Sat, 12 Mar 2016 19:20:37 +0000 (+0000) Subject: switch scope to using lex_map to lookup locals X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=af69c845120a593df0fd399f4e7fd955c0f3a376;p=scpubgit%2FDX.git switch scope to using lex_map to lookup locals --- diff --git a/lib/DX/QueryState.pm b/lib/DX/QueryState.pm index 9cc2249..496b983 100644 --- a/lib/DX/QueryState.pm +++ b/lib/DX/QueryState.pm @@ -42,7 +42,10 @@ sub new_search_state_for { ) ), @local_names ) - ] + ], + lex_map => { + map +($_ => [ 0, $_ ]), @local_names + } ); my $hyp = DX::Hypothesis->new( scope => $scope, diff --git a/lib/DX/Scope.pm b/lib/DX/Scope.pm index 76bda01..214eb4f 100644 --- a/lib/DX/Scope.pm +++ b/lib/DX/Scope.pm @@ -9,6 +9,8 @@ has globals => (is => 'ro', isa => DictValue, required => 1); has locals => (is => 'ro', isa => ArrayRef[DictValue], required => 1); +has lex_map => (is => 'ro', isa => HashRef, required => 1); + #has known_facts => (is => 'ro', required => 1); sub lookup_predicate { @@ -17,10 +19,16 @@ sub lookup_predicate { } sub lookup { - my ($self, $name) = @_; - my $lookup_in = ($name =~ /^[_A-Z]/ ? $self->locals->[-1] : $self->globals); - return $lookup_in->get_member_at($name) - or die "No such name in scope: $name"; + my ($self, $symbol) = @_; + if ($symbol =~ /^[_A-Z]/) { + my @mapped = @{$self->lex_map->{$symbol}||[]} + or die "No such name in scope: $symbol"; + my $targ = $self; + $targ = $targ->get_member_at($_) for @mapped; + return $targ; + } + return $self->globals->get_member_at($symbol) + or die "No such name in scope: $symbol"; } sub depth { $#{$_[0]->locals} }