-
-
Save MasterDuke17/6e09ebc32dce5f703a178a2a0348ef7b to your computer and use it in GitHub Desktop.
changing codegen for -n
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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::Stmts | |
- QAST::Op(call &say) | |
- QAST::Var(lexical $foobar) | |
- QAST::WVal(Block) :code_object<?> :past_block<?> | |
- QAST::WVal(Nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perl6-m --target=ast -ne '' | |
... | |
- QAST::Stmts | |
- QAST::WVal(Array) | |
- QAST::Stmt | |
- QAST::Want | |
- QAST::Op(callmethod sink) | |
- QAST::Op(callmethod map) | |
- QAST::Op(call &lines) | |
- QAST::Op(p6capturelex) | |
- QAST::WVal(Block) :code_object<?> :past_block<?> | |
- v | |
- QAST::Op(callmethod sink) | |
- QAST::Op(callmethod map) | |
- QAST::Op(call &lines) | |
- QAST::Op(p6capturelex) | |
- QAST::WVal(Block) :code_object<?> :past_block<?> | |
- QAST::WVal(Nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Perl6/Actions.nqp b/src/Perl6/Actions.nqp | |
index 3db4207..994375a 100644 | |
--- a/src/Perl6/Actions.nqp | |
+++ b/src/Perl6/Actions.nqp | |
@@ -704,10 +704,16 @@ class Perl6::Actions is HLL::Actions does STDActions { | |
# Turn $code into "for lines() { $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) | |
+ my $bind_stmts := QAST::Stmts.new( | |
+ QAST::Op.new(:op<bind>, | |
+ QAST::Var.new(:name<$_>, :scope<lexical>), | |
+ QAST::Op.new(:op<call>, :name<&get>)) | |
); | |
+ my $cond := QAST::Op.new(:op<p6definite>, $bind_stmts); | |
+ my $body := QAST::Op.new(:op<p6capturelex>, $code); | |
+ my $while := QAST::Op.new($cond, :op<while>, :node($/)); | |
+ $while.push($body); | |
+ my $past := QAST::Stmts.new($while); | |
$past := QAST::Want.new( | |
QAST::Op.new( :op<callmethod>, :name<sink>, $past ), | |
'v', QAST::Op.new( :op<callmethod>, :name<sink>, $past ) | |
./perl6-m --target=ast -ne '' | |
... | |
- QAST::Stmts | |
- QAST::WVal(Array) | |
- QAST::Stmt | |
- QAST::Want | |
- QAST::Op(callmethod sink) | |
- QAST::Stmts | |
- QAST::Op(while) | |
- QAST::Op(p6definite) | |
- QAST::Stmts | |
- QAST::Op(bind) | |
- QAST::Var(lexical $_) | |
- QAST::Op(call &get) | |
- QAST::Op(p6capturelex) | |
- QAST::WVal(Block) :code_object<?> :past_block<?> | |
- v | |
- QAST::Op(callmethod sink) | |
- QAST::Stmts | |
- QAST::Op(while) | |
- QAST::Op(p6definite) | |
- QAST::Stmts | |
- QAST::Op(bind) | |
- QAST::Var(lexical $_) | |
- QAST::Op(call &get) | |
- QAST::Op(p6capturelex) | |
- QAST::WVal(Block) :code_object<?> :past_block<?> | |
- QAST::WVal(Nil) | |
# error if called with actual code to run | |
Cannot call method 'sink' on a null object | |
in block <unit> at -e line 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Perl6/Actions.nqp b/src/Perl6/Actions.nqp | |
index 3db4207..6dae04c 100644 | |
--- a/src/Perl6/Actions.nqp | |
+++ b/src/Perl6/Actions.nqp | |
@@ -701,21 +701,24 @@ 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) | |
+ my $bind := QAST::Op.new(:op<bind>, | |
+ QAST::Var.new(:name<$_>, :scope<lexical>), | |
+ QAST::Op.new(:op<call>, :name<&get>) | |
); | |
+ my $cond := QAST::Op.new(:op<p6definite>, $bind); | |
+ my $body := QAST::Op.new(:op<p6capturelex>, $code); | |
+ my $past := QAST::Op.new(:op<while>, $cond, $body); | |
$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 | |
+ # 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($/, | |
./perl6-m --target=ast -ne '' | |
... | |
- QAST::Stmts | |
- QAST::WVal(Array) | |
- QAST::Stmt | |
- QAST::Want | |
- QAST::Op(callmethod sink) | |
- QAST::Op(while) | |
- QAST::Op(p6definite) | |
- QAST::Op(bind) | |
- QAST::Var(lexical $_) | |
- QAST::Op(call &get) | |
- QAST::Op(p6capturelex) | |
- QAST::WVal(Block) :code_object<?> :past_block<?> | |
- v | |
- QAST::Op(callmethod sink) | |
- QAST::Op(while) | |
- QAST::Op(p6definite) | |
- QAST::Op(bind) | |
- QAST::Var(lexical $_) | |
- QAST::Op(call &get) | |
- QAST::Op(p6capturelex) | |
- QAST::WVal(Block) :code_object<?> :past_block<?> | |
- QAST::WVal(Nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- QAST::Stmts | |
- QAST::WVal(Array) | |
- QAST::Stmt | |
- QAST::Stmts | |
- QAST::Op(p6for) | |
- QAST::Op(p6definite) | |
- QAST::Stmts | |
- QAST::Op(bind) | |
- QAST::Var(lexical $_) | |
- QAST::Op(call &get) | |
- QAST::Op(p6capturelex) | |
- QAST::WVal(Block) :code_object<?> :past_block<?> | |
- QAST::WVal(Nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment