Skip to content

Commit

Permalink
Better document the for ^100 loop optimization
Browse files Browse the repository at this point in the history
Basically, use <foo> instead of ('foo'), reduce indentation to 2 instead of
4, and add the nqp equivalent of the code being codegenned.
  • Loading branch information
lizmat committed Jul 31, 2018
1 parent 7043559 commit d69fd2f
Showing 1 changed file with 45 additions and 34 deletions.
79 changes: 45 additions & 34 deletions src/Perl6/Optimizer.nqp
Expand Up @@ -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<bind>,
QAST::Var.new(
:name($it_var), :scope<local>, :decl<var>, :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<bind>,
QAST::Var.new(
:name($max_var), :scope<local>, :decl<var>, :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<bind>,
QAST::Var.new(:name($callee_var), :scope<local>, :decl<var>),
$callee
),

# nqp::while(
# nqp::isle_i($it,$max),
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('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<call>,
QAST::Var.new(:name($callee_var), :scope<local> ),
QAST::Var.new(:name($it_var), :scope<local>, :returns(int))
),
QAST::WVal.new( :value($!symbols.Nil) )

# nqp::bind($it,nqp::add_i($it,1))
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) )
)
)
),

# return Nil
QAST::WVal.new( :value($!symbols.Nil) )
));
}
}
Expand Down

0 comments on commit d69fd2f

Please sign in to comment.