Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Last active December 15, 2016 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasterDuke17/a19a5cfadd0e450d1dd74d2f048db905 to your computer and use it in GitHub Desktop.
Save MasterDuke17/a19a5cfadd0e450d1dd74d2f048db905 to your computer and use it in GitHub Desktop.
AST
- QAST::Stmts
- QAST::WVal(Array)
- QAST::Stmt
- QAST::Op(while)
- QAST::Op(p6definite)
- QAST::Op(bind)
- QAST::Var(lexical $_)
- QAST::Op(call &get)
- QAST::Block(:blocktype(immediate))
- QAST::Op(call)
- QAST::Op(p6capturelex)
- QAST::Stmts <sunk> .say
- QAST::Stmt <sunk final> .say
- QAST::Want <sunk>
- QAST::Op(callmethod sink) <sunk>
- QAST::Op(hllize) <sunk> :statement_id<?>
- QAST::Op(callmethod say) say
- QAST::Var(lexical $_) <wanted>
- v
- QAST::Op(p6sink)
- QAST::Op(hllize) <sunk> :statement_id<?>
- QAST::Op(callmethod say) say
- QAST::Var(lexical $_) <wanted>
- QAST::WVal(Nil)
diff --git a/src/Perl6/Actions.nqp b/src/Perl6/Actions.nqp
index 0ea6797..7e05dd1 100644
--- a/src/Perl6/Actions.nqp
+++ b/src/Perl6/Actions.nqp
@@ -710,21 +710,25 @@ class Perl6::Actions is HLL::Actions does STDActions {
make $name;
}
- # Turn $code into "for lines() { $code }"
+ # Turn $code into "while ($_ := get()).DEFINITE { $code }"
sub wrap_option_n_code($/, $code) {
- $code := make_topic_block_ref($/, $code, copy => 1);
- my $past := QAST::Op.new(:op<callmethod>, :name<map>,
- QAST::Op.new(:op<call>, :name<&lines>),
- QAST::Op.new(:op<p6capturelex>, $code)
+ #$code := make_topic_block_ref($/, $code, copy => 1);
+ my $bind_get := QAST::Op.new(:op<bind>,
+ QAST::Var.new(:name<$_>, :scope<lexical>),
+ QAST::Op.new(:op<call>, :name<&get>)
);
- $past := QAST::Want.new(
- QAST::Op.new( :op<callmethod>, :name<sink>, $past ),
- 'v', QAST::Op.new( :op<callmethod>, :name<sink>, $past )
- );
- }
-
- # Turn $code into "for lines() { $code; say $_ }"
- # &wrap_option_n_code already does the C<for> loop, so we just add the
+ my $cond := QAST::Op.new(:op<p6definite>, $bind_get);
+ my $body := QAST::Block.new(:blocktype<immediate>, QAST::Op.new(:op<call>, QAST::Op.new(:op<p6capturelex>, $code)));
+ my $past := QAST::Op.new(:op<while>, $cond, $body);
+ #tweak_loop($past);
+ #$past := QAST::Want.new(
+ # $past,
+ # 'v', $past
+ #);
+ }
+
+ # Turn $code into "while ($_ := get()).DEFINITE { $code; say $_ }"
+ # &wrap_option_n_code already does the C<while> loop, so we just add the
# C<say> call here
sub wrap_option_p_code($/, $code) {
wrap_option_n_code($/,
[dan@alexandria rakudo]$ ./perl6-m -ne '.say' perl6-valgrind-m
#!/bin/sh
Cannot find method 'Nil' on object of type List
in block <unit> at -e line 1
[dan@alexandria rakudo]$ ./perl6-m -ne 'say "hi"' perl6-valgrind-m
hi
No such method 'CALL-ME' for invocant of type 'Bool'
in block <unit> at -e line 1
[dan@alexandria rakudo]$ ./perl6-m -ne 'sub { say "hi" }' perl6-valgrind-m
hi
hi
hi
hi
hi
hi
hi
hi
hi
hi
hi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment