[Bps-public-commit] r12687 - in pie/branches/named-params: lib/PIE
jesse at bestpractical.com
jesse at bestpractical.com
Mon May 26 06:02:42 EDT 2008
Author: jesse
Date: Mon May 26 06:02:31 2008
New Revision: 12687
Modified:
pie/branches/named-params/lib/PIE/Evaluator.pm
pie/branches/named-params/t/let.t
Log:
* removing feature. same functionality.
Modified: pie/branches/named-params/lib/PIE/Evaluator.pm
==============================================================================
--- pie/branches/named-params/lib/PIE/Evaluator.pm (original)
+++ pie/branches/named-params/lib/PIE/Evaluator.pm Mon May 26 06:02:31 2008
@@ -27,17 +27,6 @@
default => sub { {} },
);
-has stack_vars => (
- is => 'rw',
- metaclass => 'Collection::Array',
- isa => 'ArrayRef[HashRef]',
- default => sub { [] },
- provides => {
- 'push' => 'push_stack_vars',
- 'pop' => 'pop_stack_vars',
- }
-);
-
has stack_block => (
is => 'rw',
metaclass => 'Collection::Array',
@@ -61,16 +50,17 @@
my %args = validate(@_, {args => 1, block => 1});
$self->stack_depth($self->stack_depth+1);
- $self->push_stack_vars($args{'args'});
$self->push_stack_block($args{'block'});
- push @{ $self->lex_block_map->{ $args{'block'}->block_id } ||= [] }, $#{ $self->stack_vars };
+ # lex_block_map is a mapping from a block id to an array of stack indexes.
+ # if we're entereing block 3, we push the current stack frame onto the lex_block_map entry for block 3
+ # The last entry of the current block is where we can see its lexical context
+ push @{ $self->lex_block_map->{ $args{'block'}->block_id } ||= [] }, $args{'args'};
}
sub leave_stack_frame {
my $self = shift;
die "Trying to leave stack frame 0. Too many returns. Something relaly bad happened" if ($self->stack_depth == 0);
- $self->pop_stack_vars();
my $block = $self->pop_stack_block();
$self->stack_depth($self->stack_depth-1);
@@ -101,11 +91,15 @@
sub lookup_lex_name {
my ($self, $name) = @_;
- return unless @{ $self->stack_block };
+ return unless @{ $self->stack_block };
+ # look at the current block on the stack
my $block = $self->stack_block->[-1];
do {
- my $stack = $self->stack_vars->[ $self->lex_block_map->{ $block->block_id }[-1] ];
+ # grab the stack frame from the lexical block map pointer for the 'current' block (the one we're inspecting
+ my $stack =$self->lex_block_map->{ $block->block_id }[-1] ;
+ # if we find the variable, we can return it
+
return $stack->{$name} if exists $stack->{$name};
} while ($block = $block->outter_block);
@@ -114,9 +108,8 @@
sub resolve_symbol_name {
my ($self, $name) = @_;
- my $stack = $self->stack_vars->[-1] || {};
Carp::cluck if ref($name);
- $stack->{$name} || $self->lookup_lex_name($name) || $self->get_global_symbol($name)
+ $self->lookup_lex_name($name) || $self->get_global_symbol($name)
|| die "Could not find symbol $name in the current lexical context.";
}
Modified: pie/branches/named-params/t/let.t
==============================================================================
--- pie/branches/named-params/t/let.t (original)
+++ pie/branches/named-params/t/let.t Mon May 26 06:02:31 2008
@@ -27,9 +27,9 @@
$eval->set_global_symbol( 'match-regexp' => $MATCH_REGEX );
my $script =
- $builder->defun(
+ $builder->defun( # outer block
ops => [
- { name => 'Let',
+ { name => 'Let', #inner block. each block has a lexical pad structure
args => {
bindings => { REGEXP => 'software' },
nodes => [
@@ -42,7 +42,7 @@
args => {
regexp => { name => 'Symbol', args => { symbol => 'REGEXP' } },
'tested-string' =>
- { name => 'Symbol', args => { symbol => 'tested-string' } },
+ { name => 'Symbol', args => { symbol => 'tested-string' } }, # lookup to tested string needs to query the outer block's lexpad
}
}
}
More information about the Bps-public-commit
mailing list