[Bps-public-commit] r12675 - in pie/branches/named-params: lib/PIE
clkao at bestpractical.com
clkao at bestpractical.com
Sun May 25 01:14:26 EDT 2008
Author: clkao
Date: Sun May 25 01:14:25 2008
New Revision: 12675
Added:
pie/branches/named-params/t/builder.t
Modified:
pie/branches/named-params/lib/PIE/Builder.pm
pie/branches/named-params/lib/PIE/Expression.pm
Log:
* have builder use signatures.
* in progn, handle nodes from builder.
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 Sun May 25 01:14:25 2008
@@ -16,7 +16,10 @@
# XXX: in case of primitive-ops, we should only bulid the args we
# know about
- return $class->new( name => $name, args => { map { $_ => $self->build_expression( $args->{$_} ) } keys %$args } );
+ warn "==> orz $class";
+ my @known_args = $class eq 'PIE::Expression' ? keys %$args : keys %{ $class->signature };
+ return $class->new( name => $name, builder => $self, builder_args => $args,
+ args => { map { $_ => $self->build_expression( $args->{$_} ) } @known_args } );
}
@@ -28,7 +31,7 @@
elsif (ref($tree) eq 'HASH') {
return $self->build_op_expression($tree->{name}, $tree->{args});
} else {
- Carp::confess("Don't know what to do with a tree that looksl ike ". YAML::Dump($tree));
+ Carp::confess("Don't know what to do with a tree that looksl ike ". YAML::Dump($tree));use YAML;
}
}
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 Sun May 25 01:14:25 2008
@@ -124,11 +124,20 @@
extends 'PIE::Expression';
class_has signature => ( is => 'ro', default => sub { { }});
- has nodes => (
+has nodes => (
is => 'rw',
isa => 'ArrayRef',
);
+sub BUILD {
+ my ($self, $params) = @_;
+
+ return unless $params->{builder};
+ my $nodes = $params->{builder_args}{nodes};
+
+ $self->nodes( [ map { $params->{builder}->build_expression($_) } @$nodes ] );
+}
+
sub evaluate {
my ($self, $evaluator) = @_;
my $res;
Added: pie/branches/named-params/t/builder.t
==============================================================================
--- (empty file)
+++ pie/branches/named-params/t/builder.t Sun May 25 01:14:25 2008
@@ -0,0 +1,29 @@
+use Test::More qw'no_plan';
+use strict;
+use_ok('PIE::Expression');
+use_ok('PIE::Evaluator');
+use_ok('PIE::Builder');
+
+my $builder = PIE::Builder->new();
+my $eval = PIE::Evaluator->new();
+#$eval->set_global_symbol( 'match-regexp' => $MATCH_REGEX );
+
+my $script = $builder->defun(
+ ops => [
+ { name => 'ProgN',
+ args => {
+ nodes => [
+ { name => 'True', args => {} },
+ { name => 'False', args => {} },
+ ],
+ } } ],
+ signature => {});
+
+#warn Dumper($script);use Data::Dumper;
+# XXX: ensure $script structure
+is(scalar @{$script->progn->nodes}, 1);
+isa_ok($script->progn->nodes->[0], 'PIE::Expression::ProgN');
+is(scalar @{$script->progn->nodes->[0]->nodes}, 2);
+
+isa_ok($script->progn->nodes->[0]->nodes->[0], 'PIE::Expression::True');
+isa_ok($script->progn->nodes->[0]->nodes->[1], 'PIE::Expression::False');
More information about the Bps-public-commit
mailing list