Skip to content

Commit

Permalink
First crack at LAD-specific optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Sep 13, 2010
1 parent 1bf77fa commit 1705097
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/Optimizer/RxSimple.pm
Expand Up @@ -9,7 +9,42 @@ sub run {
}

sub run_lad {
$_[0];
my $lad = shift;
my ($op, @zyg) = @$lad;
if ($op eq 'Sequence') {
my @ozyg;
for my $z (@{ $zyg[0] }) {
my $oz = run_lad($z);
if ($oz->[0] eq 'Sequence') {
push @ozyg, @{ $oz->[1] };
} elsif ($oz->[0] eq 'Null') {
} else {
push @ozyg, $oz;
}
}
for (my $ix = 0; $ix < @ozyg; ) {
return ['None'] if ($ozyg[$ix][0] eq 'None');
if ($ozyg[$ix][0] eq 'Imp') {
$#ozyg = $ix;
last;
} elsif ($ix >= 1 && $ozyg[$ix][0] eq 'Str' &&
$ozyg[$ix-1][0] eq 'Str') {
$ozyg[$ix-1][1] .= $ozyg[$ix][1];
splice @ozyg, $ix, 1;
} else {
$ix++;
}
}
if (@ozyg == 0) {
return [ 'Null' ];
} elsif (@ozyg == 1) {
return $ozyg[0];
} else {
return [ 'Sequence', [ @ozyg ] ];
}
} else {
return $lad;
}
}

# XXX should use a multi sub.
Expand Down

0 comments on commit 1705097

Please sign in to comment.