fix while back jump
while normalising the condition had gone before the jump target accidentally
This commit is contained in:
@ -3,33 +3,34 @@ require_relative "normalizer"
|
||||
module Vool
|
||||
class WhileStatement < Statement
|
||||
include Normalizer
|
||||
attr_reader :condition , :body
|
||||
attr_reader :condition , :body , :hoisted
|
||||
|
||||
def initialize( condition , body )
|
||||
def initialize( condition , body , hoisted = nil)
|
||||
@hoisted = hoisted
|
||||
@condition = condition
|
||||
@body = body
|
||||
end
|
||||
|
||||
def normalize
|
||||
cond , rest = *normalize_name(@condition)
|
||||
me = WhileStatement.new(cond , @body.normalize)
|
||||
return me unless rest
|
||||
rest << me
|
||||
rest
|
||||
WhileStatement.new(cond , @body.normalize , rest)
|
||||
end
|
||||
|
||||
def to_mom( method )
|
||||
merge_label = Mom::Label.new( "merge_label_#{object_id}")
|
||||
cond_label = Mom::Label.new( "cond_label_#{object_id}")
|
||||
cond_label << Mom::TruthCheck.new(condition.slot_definition(method) , merge_label)
|
||||
cond_label << @body.to_mom(method)
|
||||
cond_label << Mom::Jump.new(cond_label)
|
||||
cond_label << merge_label
|
||||
codes = cond_label
|
||||
codes << @hoisted.to_mom(method) if @hoisted
|
||||
codes << Mom::TruthCheck.new(condition.slot_definition(method) , merge_label)
|
||||
codes << @body.to_mom(method)
|
||||
codes << Mom::Jump.new(cond_label)
|
||||
codes << merge_label
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
block.call(self)
|
||||
block.call(@condition)
|
||||
@hoisted.each(&block) if @hoisted
|
||||
@body.each(&block)
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user