1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
|
# File 'lib/BOAST/Algorithm.rb', line 1588
def unroll(*args)
raise "Block not given!" if not @block
BOAST::push_env( :replace_constants => true )
begin
if @begin.kind_of?(Variable) then
start = @begin.constant
elsif @begin.kind_of?(Expression) then
start = eval "#{@begin}"
else
start = @begin.to_i
end
if @end.kind_of?(Variable) then
e = @end.constant
elsif @end.kind_of?(Expression) then
e = eval "#{@end}"
else
e = @end.to_i
end
if @step.kind_of?(Variable) then
step = @step.constant
elsif @step.kind_of?(Expression) then
step = eval "#{@step}"
else
step = @step.to_i
end
raise "Invalid bounds (not constants)!" if not ( start and e and step )
rescue Exception => ex
if not ( start and e and step ) then
BOAST::pop_env( :replace_constants )
return self.print(*args) if not ( start and e and step )
end
end
BOAST::pop_env( :replace_constants )
range = start..e
@iterator.force_replace_constant = true
range.step(step) { |i|
@iterator.constant = i
@block.call(*args)
}
@iterator.force_replace_constant = false
@iterator.constant = nil
end
|