From d69fd2f37019e241064d4329bc85fe386d6caf2c Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Tue, 31 Jul 2018 15:06:38 +0200 Subject: [PATCH] Better document the for ^100 loop optimization Basically, use instead of ('foo'), reduce indentation to 2 instead of 4, and add the nqp equivalent of the code being codegenned. --- src/Perl6/Optimizer.nqp | 79 +++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/src/Perl6/Optimizer.nqp b/src/Perl6/Optimizer.nqp index aac2cc7f2ba..33185550fb2 100644 --- a/src/Perl6/Optimizer.nqp +++ b/src/Perl6/Optimizer.nqp @@ -2195,44 +2195,55 @@ class Perl6::Optimizer { $op.shift while $op.list; $op.op('stmts'); $op.push(QAST::Stmts.new( - QAST::Op.new( - :op('bind'), - QAST::Var.new( :name($it_var), :scope('local'), :decl('var'), :returns(int) ), - @bounds[0] + +# my int $it = @bounds[0] + QAST::Op.new( :op, + QAST::Var.new( + :name($it_var), :scope, :decl, :returns(int) ), - QAST::Op.new( - :op('bind'), - QAST::Var.new( :name($max_var), :scope('local'), :decl('var'), :returns(int) ), - @bounds[1] + @bounds[0] + ), + +# my int $max = @bounds[1] + QAST::Op.new( :op, + QAST::Var.new( + :name($max_var), :scope, :decl, :returns(int) ), - QAST::Op.new( - :op('bind'), - QAST::Var.new( :name($callee_var), :scope('local'), :decl('var') ), - $callee + @bounds[1] + ), + +# my $callee := { }; + QAST::Op.new( :op, + QAST::Var.new(:name($callee_var), :scope, :decl), + $callee + ), + +# nqp::while( +# nqp::isle_i($it,$max), + QAST::Op.new( :op, + QAST::Op.new( :op, + QAST::Var.new(:name($it_var), :scope, :returns(int)), + QAST::Var.new(:name($max_var), :scope, :returns(int)) ), - QAST::Op.new( - :op('while'), - QAST::Op.new( - :op('isle_i'), - QAST::Var.new( :name($it_var), :scope('local'), :returns(int) ), - QAST::Var.new( :name($max_var), :scope('local'), :returns(int) ) - ), - QAST::Op.new( - :op('call'), - QAST::Var.new( :name($callee_var), :scope('local') ), - QAST::Var.new( :name($it_var), :scope('local'), :returns(int) ) - ), - QAST::Op.new( - :op('bind'), - QAST::Var.new( :name($it_var), :scope('local'), :returns(int) ), - QAST::Op.new( - :op('add_i'), - QAST::Var.new( :name($it_var), :scope('local'), :returns(int) ), - QAST::IVal.new( :value(1) ) - ) - ) + +# nqp::call($callee, $it) + QAST::Op.new( :op, + QAST::Var.new(:name($callee_var), :scope ), + QAST::Var.new(:name($it_var), :scope, :returns(int)) ), - QAST::WVal.new( :value($!symbols.Nil) ) + +# nqp::bind($it,nqp::add_i($it,1)) + QAST::Op.new( :op, + QAST::Var.new(:name($it_var), :scope, :returns(int)), + QAST::Op.new( :op, + QAST::Var.new(:name($it_var), :scope, :returns(int)), + QAST::IVal.new( :value(1) ) + ) + ) + ), + +# return Nil + QAST::WVal.new( :value($!symbols.Nil) ) )); } }