[Bps-public-commit] r12652 - in pie/branches/named-params: lib/PIE

jesse at bestpractical.com jesse at bestpractical.com
Fri May 23 21:53:13 EDT 2008


Author: jesse
Date: Fri May 23 21:53:12 2008
New Revision: 12652

Modified:
   pie/branches/named-params/lib/PIE/Evaluator.pm
   pie/branches/named-params/lib/PIE/Expression.pm
   pie/branches/named-params/t/leaky-lexicals.t

Log:
 checkpoint for sync

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 21:53:12 2008
@@ -56,6 +56,8 @@
     $self->enter_stack_frame;
     eval {
         Carp::confess unless ($expression);
+        $YAML::DumpCode++;
+        warn YAML::Dump($expression);
         my $ret = $expression->evaluate($self);
         $self->result->value($ret);
         $self->result->success(1);
@@ -82,7 +84,9 @@
 sub resolve_name {
     my ($self, $name) = @_;
     my $stack = $self->stack_vars->[-1] || {};
-    $stack->{$name} || $self->get_named($name);
+    warn YAML::Dump($name); 
+    Carp::cluck if ref($name);
+    $stack->{$name} || $self->get_named($name) || die "Could not find symbol $name in the current lexical context.";
 }
 
 sub apply_script {
@@ -95,7 +99,7 @@
         { ISA => "HASHREF" }
     );
     Carp::confess unless($lambda);
-
+    
     my $ret = $lambda->apply( $self => $args);
     $self->result->value($ret);
     $self->result->success(1);

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 21:53:12 2008
@@ -153,7 +153,9 @@
     
 sub evaluate {
     my ($self, $eval) = validate_pos(@_, { isa => 'PIE::Expression'}, { isa => 'PIE::Evaluator'});
+    warn "About to resolve the symbol name ". $self->args->{'symbol'};
     my $result = $eval->resolve_name($self->args->{'symbol'});
+    warn "Done";
     return $result->isa('PIE::Expression') ? $eval->run($result) : $result; # XXX: figure out evaluation order here
 }
 

Modified: pie/branches/named-params/t/leaky-lexicals.t
==============================================================================
--- pie/branches/named-params/t/leaky-lexicals.t	(original)
+++ pie/branches/named-params/t/leaky-lexicals.t	Fri May 23 21:53:12 2008
@@ -1,28 +1,35 @@
-use Test::More tests => 6;
-
+use Test::More qw'no_plan';
+use strict;
+use_ok('PIE::Expression');
 use_ok('PIE::Evaluator');
+use_ok('PIE::Lambda');
+use_ok('PIE::Lambda::Native');
 use_ok('PIE::Builder');
 use_ok('PIE::FunctionArgument');
-use_ok('PIE::Lambda::Native');
-my $evaluator = PIE::Evaluator->new();
-$evaluator->set_named( 'make-fred', PIE::Lambda::Native->new( body => sub { return 'fred' } ) );
-$evaluator->set_named( 'make-bob', PIE::Lambda::Native->new( body => sub { return 'bob' } ) );
-
-my $args = { name => PIE::Expression::String->new( args => { value => 'Hiro' } ) };
 
 
+my $eval = PIE::Evaluator->new;
+my $builder = PIE::Builder->new();
 
+my $A_SIDE = PIE::Builder->defun( 
+        ops => [ {
+                    name => 'Symbol',
+                    args => { symbol => 'x'},
+                    { name => 'Symbol',
+                        args => { symbol => 'y'}}}],
+        signature => { x => PIE::FunctionArgument->new(name => 'x', type => 'Str')});
 
 
+$eval->set_named( 'a' => $A_SIDE );
+
+my $defined_b = $builder->defun(
+    ops => [{ name => 'a', args => { x => 'x456' }} ],
+    signature =>
+        { y => PIE::FunctionArgument->new( name => 'y', type => 'String' ) }
+);
 
-my $builder = PIE::Builder->new();
 
-my $script3 = $builder->defun( ops => [ { name => 'make-bob' } ],
-    signature => { name => PIE::FunctionArgument->new( name => 'name', type => 'Str' ) }
-);
-my %before = %{ $evaluator->named};
-$evaluator->apply_script( $script3, $args);
-my %after = %{ $evaluator->named};
-is($evaluator->result->value,'bob');
-is_deeply(\%before => \%after);
 
+$eval->apply_script( $defined_b, { y => 'Y123' });
+ok (!$eval->result->success);
+is($eval->result->error,'');



More information about the Bps-public-commit mailing list