Skip to content

Commit

Permalink
[opsc] add support for do-while loops
Browse files Browse the repository at this point in the history
  • Loading branch information
cotto committed Feb 28, 2011
1 parent 004d6f0 commit 3def685
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions compilers/opsc/src/Ops/Compiler/Actions.pm
Expand Up @@ -548,6 +548,17 @@ method statement_control:sym<while> ($/) {
make $past;
}

method statement_control:sym<do-while> ($/) {
my $past := PAST::Op.new(
:pasttype<do-while>,

$<blockoid>.ast,
$<condition>.ast,
);

make $past;
}

method statement_control:sym<for> ($/) {
my $past := PAST::Op.new(
:pasttype<for>,
Expand Down
2 changes: 1 addition & 1 deletion compilers/opsc/src/Ops/Compiler/Grammar.pm
Expand Up @@ -207,7 +207,7 @@ rule statement_control:sym<for> {
<statement_list>
}

rule statement_control:sym<do> {
rule statement_control:sym<do-while> {
<sym> <blockoid> 'while' '(' <condition=.EXPR> ')'
}

Expand Down
10 changes: 10 additions & 0 deletions compilers/opsc/src/Ops/Op.pm
Expand Up @@ -440,6 +440,16 @@ our method to_c:pasttype<while> ($trans, PAST::Op $chunk) {
);
}

our method to_c:pasttype<do-while> ($trans, PAST::Op $chunk) {
join('',
'do ',
self.to_c($trans, $chunk[0]),
'while (',
self.to_c($trans, $chunk[1]),
')',
);
}

our method to_c:pasttype<for> ($trans, PAST::Op $chunk) {
join('',
'for (',
Expand Down

0 comments on commit 3def685

Please sign in to comment.