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

clkao at bestpractical.com clkao at bestpractical.com
Sat May 24 03:40:07 EDT 2008


Author: clkao
Date: Sat May 24 03:40:05 2008
New Revision: 12662

Modified:
   pie/branches/named-params/lib/PIE/Builder.pm
   pie/branches/named-params/lib/PIE/Expression.pm
   pie/branches/named-params/lib/PIE/Lambda.pm
   pie/branches/named-params/t/01basic.t

Log:
introduce progn expression and have lambda contain it
and hold its nodes.


Modified: pie/branches/named-params/lib/PIE/Builder.pm
==============================================================================
--- pie/branches/named-params/lib/PIE/Builder.pm	(original)
+++ pie/branches/named-params/lib/PIE/Builder.pm	Sat May 24 03:40:05 2008
@@ -33,7 +33,9 @@
 sub defun {
     my $self = shift;
     my %args = validate( @_, { ops => 1, signature => 1 });
-    return PIE::Lambda->new( nodes => [map { $self->build_expression($_) } @{$args{ops}} ], signature => $args{signature} );
+    return PIE::Lambda->new( progn => PIE::Expression::ProgN->new(
+                                                                  nodes => [map { $self->build_expression($_) } @{$args{ops}} ]),
+                             signature => $args{signature} );
 }
 
 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	Sat May 24 03:40:05 2008
@@ -137,6 +137,25 @@
 
 }
 
+package PIE::Expression::ProgN;
+use Moose;
+extends 'PIE::Expression';
+
+has nodes => (
+    is => 'rw',
+    isa => 'ArrayRef',
+);
+
+sub evaluate {
+    my ($self, $evaluator) = @_;
+    my $res;
+    Carp::cluck unless $self->nodes;
+    foreach my $node (@{$self->nodes}) {
+       $res =  $node->evaluate($evaluator);
+    }
+    return $res;
+}
+
 package PIE::Expression::Symbol;
 use Moose;
 extends 'PIE::Expression';

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	Sat May 24 03:40:05 2008
@@ -2,9 +2,11 @@
 package PIE::Lambda;
 use Moose; use MooseX::Params::Validate;
 
-has nodes => (
-    is => 'rw',
-    isa => 'ArrayRef',
+has progn => (
+    is => 'ro',
+    isa => 'PIE::Expression::ProgN',
+    default => sub { PIE::Expression::ProgN->new },
+    handles => [qw(nodes)]
 );
 
 has signature => (
@@ -55,13 +57,8 @@
 
     $self->validate_args_or_die($args);
 
-
-
     $evaluator->enter_stack_frame( args => $args);
-    my $res;
-    foreach my $node (@{$self->nodes}) {
-       $res =  $node->evaluate($evaluator);
-    }
+    my $res = $self->progn->evaluate($evaluator);
 
     $evaluator->leave_stack_frame(); 
     return $res;

Modified: pie/branches/named-params/t/01basic.t
==============================================================================
--- pie/branches/named-params/t/01basic.t	(original)
+++ pie/branches/named-params/t/01basic.t	Sat May 24 03:40:05 2008
@@ -42,10 +42,11 @@
 ok( $eval4->result->success );
 
 my $script = PIE::Lambda->new(
+   progn => PIE::Expression::ProgN->new(
     nodes => [
         PIE::Expression::True->new()
 
-    ],
+    ]),
 
 );
 
@@ -54,7 +55,9 @@
 ok( $eval7->result->success );
 ok( $eval7->result->value );
 
-my $script2 = PIE::Lambda->new( nodes => [$if_true] );
+my $script2 = PIE::Lambda->new(
+   progn => PIE::Expression::ProgN->new(
+ nodes => [$if_true] ) );
 
 my $eval8 = PIE::Evaluator->new();
 $eval8->apply_script($script2, {});



More information about the Bps-public-commit mailing list