[Bps-public-commit] r12643 - pie/branches/named-params/lib/PIE

clkao at bestpractical.com clkao at bestpractical.com
Fri May 23 08:51:53 EDT 2008


Author: clkao
Date: Fri May 23 08:51:53 2008
New Revision: 12643

Modified:
   pie/branches/named-params/lib/PIE/Evaluator.pm
   pie/branches/named-params/lib/PIE/Expression.pm
   pie/branches/named-params/lib/PIE/Lambda.pm

Log:
lexical vars.


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	Fri May 23 08:51:53 2008
@@ -21,6 +21,17 @@
                  set       => 'set_named',
              });
 
+has stack_vars => (
+    is => 'rw',
+    metaclass => 'Collection::Array',
+    isa       => 'ArrayRef[HashRef]',
+    default   => sub { [] },
+    provides  => {
+        'push' => 'push_stack_vars',
+        'pop'  => 'pop_stack_vars',
+    }
+);
+
 has stack_depth => ( 
             is => 'rw',
             isa => 'Int',
@@ -39,8 +50,6 @@
     $self->stack_depth($self->stack_depth-1);
 }
 
-
-
 sub run {
     my $self       = shift;
     my $expression = shift;
@@ -72,10 +81,10 @@
 
 sub resolve_name {
     my ($self, $name) = @_;
-    $self->get_named($name);
+    my $stack = $self->stack_vars->[-1] || {};
+    $stack->{$name} || $self->get_named($name);
 }
 
-
 sub apply_script {
 
 # self, a lambda, any number of positional params. (to be replaced with a params object?)

Modified: pie/branches/named-params/lib/PIE/Expression.pm
==============================================================================
--- pie/branches/named-params/lib/PIE/Expression.pm	(original)
+++ pie/branches/named-params/lib/PIE/Expression.pm	Fri May 23 08:51:53 2008
@@ -151,7 +151,7 @@
     
 sub evaluate {
     my ($self, $eval) = validate_pos(@_, { isa => 'PIE::Expression'}, { isa => 'PIE::Evaluator'});
-    my $result = $eval->get_named($self->args->{'symbol'});
+    my $result = $eval->resolve_name($self->args->{'symbol'});
     return $result->isa('PIE::Expression') ? $eval->run($result) : $result; # XXX: figure out evaluation order here
 }
 

Modified: pie/branches/named-params/lib/PIE/Lambda.pm
==============================================================================
--- pie/branches/named-params/lib/PIE/Lambda.pm	(original)
+++ pie/branches/named-params/lib/PIE/Lambda.pm	Fri May 23 08:51:53 2008
@@ -63,13 +63,14 @@
     $self->validate_args_or_die($args);
 
     my $arguments = $self->signature;
-    for (sort keys %$arguments) {
-        $evaluator->set_named( $_ => $args->{$_} );
-    }
 
+    $evaluator->push_stack_vars( $args );
     foreach my $node (@{$self->nodes}) {
         $evaluator->run($node);
     }
+
+    $evaluator->pop_stack_vars( $args );
+
     return $evaluator->result->value; 
     
 }



More information about the Bps-public-commit mailing list