Skip to content

Commit

Permalink
Perlito5 - perl6: implement for-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Feb 25, 2012
1 parent 097a2e4 commit 0b7ce9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
12 changes: 2 additions & 10 deletions lib5/Perlito5/Perl6/Emitter.pm
Expand Up @@ -547,20 +547,12 @@ package For;
((my $self) = shift());
((my $level) = shift());
((my $cond) = $self->{('cond')});
if ((!((($cond->isa('Var') && ($cond->sigil() eq chr(64))))))) {
($cond = Lit::Array->new(('array1' => (do {
(my @a);
(my @v);
push(@a, $cond );
\@a
}))))
};
((my $body) = Perlito5::Perl6::LexicalBlock->new(('block' => $self->{('body')}->stmts()), ('needs_return' => 0)));
((my $sig) = 'v__');
((my $sig) = chr(36) . '_');
if (($self->{('body')}->sig())) {
($sig = $self->{('body')}->sig()->emit_perl6_indented(($level + 1)))
};
(Perl6::tab($level) . '(function (a_) ' . chr(123) . ' for (var i_ ' . chr(61) . ' 0' . chr(59) . ' i_ < a_.length ' . chr(59) . ' i_++) ' . chr(123) . ' ' . ('(function (' . $sig . ') ' . chr(123) . chr(10)) . $body->emit_perl6_indented(($level + 1)) . ' ' . chr(125) . ')(a_[i_]) ' . chr(125) . ' ' . chr(125) . ')' . '(' . $cond->emit_perl6() . ')')
(Perl6::tab($level) . 'for ' . $cond->emit_perl6() . ' -> ' . $sig . ' ' . chr(123) . ' ' . $body->emit_perl6_indented(($level + 1)) . chr(125) . (chr(10)))
}
});
package Decl;
Expand Down
14 changes: 6 additions & 8 deletions src5/lib/Perlito5/Perl6/Emitter.pm
Expand Up @@ -642,19 +642,17 @@ package For;
my $self = shift;
my $level = shift;
my $cond = $self->{"cond"};
if (!( $cond->isa( 'Var' ) && $cond->sigil eq '@' )) {
$cond = Lit::Array->new( array1 => [$cond] )
}
# if (!( $cond->isa( 'Var' ) && $cond->sigil eq '@' )) {
# $cond = Lit::Array->new( array1 => [$cond] )
# }
my $body = Perlito5::Perl6::LexicalBlock->new( block => $self->{"body"}->stmts, needs_return => 0 );
my $sig = 'v__';
my $sig = '$_';
if ($self->{"body"}->sig()) {
$sig = $self->{"body"}->sig->emit_perl6_indented( $level + 1 );
}
Perl6::tab($level) . '(function (a_) { for (var i_ = 0; i_ < a_.length ; i_++) { '
. "(function ($sig) {\n"
Perl6::tab($level) . 'for ' . $cond->emit_perl6() . ' -> ' . $sig . ' { '
. $body->emit_perl6_indented( $level + 1 )
. ' })(a_[i_]) } })'
. '(' . $cond->emit_perl6() . ')'
. '}' . "\n"
}
}

Expand Down

0 comments on commit 0b7ce9b

Please sign in to comment.