Skip to content
Browse files

squaak: Handle return and add a test

  • Loading branch information...
1 parent e293df3 commit 0ea36294abef439f6abab1deeca34e95459cb11e @Benabik Benabik committed
View
4 examples/languages/squaak/src/Squaak/Actions.pm
@@ -258,6 +258,10 @@ method statement:sym<while>($/) {
make PAST::Op.new( $cond, $body, :pasttype('while'), :node($/) );
}
+method statement:sym<return>($/) {
+ make PAST::Op.new( :pirop<return>, $<EXPR>.ast, :node($/) );
+}
+
method begin_block($/) {
our $?BLOCK;
our @?BLOCK;
View
4 examples/languages/squaak/src/Squaak/Grammar.pm
@@ -107,6 +107,10 @@ rule statement:sym<while> {
<sym> <EXPR> 'do' <block> 'end'
}
+rule statement:sym<return> {
+ <sym> <EXPR>
+}
+
token begin_block {
<?>
}
View
9 examples/languages/squaak/t/00-sanity.t
@@ -1,5 +1,5 @@
-print("1..25")
+print("1..26")
# test global variable
g = 1
@@ -110,4 +110,11 @@ while j < 5 do
j = j + 1
end
+# test return and sub as expression
+sub ret(x)
+ return x
+end
+if ret(1) == 1 then
+ print("ok 26")
+end

0 comments on commit 0ea3629

Please sign in to comment.
Something went wrong with that request. Please try again.