Fix if statements hoisting, now that send is working
Same same, just have to remembe to actually execute the condition if it is a send Having send a possible expression, removes one tmp variable and associated move, for a little extra work. Next return and assign (rest)
This commit is contained in:
@ -22,10 +22,10 @@ module Ruby
|
||||
end
|
||||
|
||||
def to_vool
|
||||
cond , rest = *normalize_name(@condition)
|
||||
me = Vool::IfStatement.new(cond.to_vool , @if_true&.to_vool, @if_false&.to_vool)
|
||||
return me unless rest
|
||||
Vool::Statements.new([ rest.to_vool , me])
|
||||
cond , hoisted = *normalized_vool(@condition)
|
||||
me = Vool::IfStatement.new(cond , @if_true&.to_vool, @if_false&.to_vool)
|
||||
return me unless hoisted
|
||||
Vool::Statements.new( hoisted ) << me
|
||||
end
|
||||
|
||||
def has_false?
|
||||
|
@ -15,8 +15,13 @@ module Vool
|
||||
false_label = Mom::Label.new( self , "false_label_#{object_id.to_s(16)}")
|
||||
merge_label = Mom::Label.new( self , "merge_label_#{object_id.to_s(16)}")
|
||||
|
||||
head = @condition.to_mom(compiler) if @condition.is_a?(SendStatement)
|
||||
head << Mom::TruthCheck.new(condition.slot_definition(compiler) , false_label)
|
||||
check = Mom::TruthCheck.new(condition.slot_definition(compiler) , false_label)
|
||||
if @condition.is_a?(SendStatement)
|
||||
head = @condition.to_mom(compiler)
|
||||
head << check
|
||||
else
|
||||
head = check
|
||||
end
|
||||
head << true_label
|
||||
head << if_true.to_mom(compiler) if @if_true
|
||||
head << Mom::Jump.new(merge_label) if @if_false
|
||||
|
@ -16,8 +16,14 @@ module Vool
|
||||
# - store the given return value, this is a SlotMove
|
||||
# - activate return sequence (reinstantiate old message and jump to return address)
|
||||
def to_mom( compiler )
|
||||
ret = Mom::SlotLoad.new( self , [:message , :return_value] ,
|
||||
load = Mom::SlotLoad.new( self , [:message , :return_value] ,
|
||||
@return_value.slot_definition(compiler) )
|
||||
if @return_value.is_a?(SendStatement)
|
||||
ret = @return_value.to_mom(compiler)
|
||||
ret << load
|
||||
else
|
||||
ret = load
|
||||
end
|
||||
ret << Mom::ReturnJump.new(self , compiler.return_label )
|
||||
end
|
||||
|
||||
|
@ -56,6 +56,10 @@ module Vool
|
||||
raise "not iplemented in #{self}"
|
||||
end
|
||||
|
||||
def at_depth(depth , *strings)
|
||||
prefix = " " * 2 * depth
|
||||
strings.collect{|str| prefix + str}.join("\n")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -28,8 +28,8 @@ module Vool
|
||||
def add_ivar( array )
|
||||
array << @name
|
||||
end
|
||||
def to_s
|
||||
"@#{name}"
|
||||
def to_s(depth = 0)
|
||||
at_depth(depth , "@#{name}")
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user