introduce slot_definition and use it

This commit is contained in:
Torsten Ruger 2017-09-04 21:31:49 +03:00
parent c6e241adeb
commit 1a219a7c89
6 changed files with 26 additions and 6 deletions

View File

@ -43,4 +43,12 @@ module Mom
class SlotMove < SlotLoad
end
class SlotDefinition
attr_reader :known_object , :slots
def initialize( object , slots)
@known_object , @slots = object , slots
slot = [slot] unless slot.is_a?(Array)
end
end
end

View File

@ -13,7 +13,8 @@ module Vool
if_true = @if_true.to_mom( method )
if_false = @if_false.to_mom( method )
condition , hoisted = hoist_condition( method )
check = Mom::IfStatement.new( Mom::TruthCheck.new(condition) , if_true , if_false )
cond = Mom::TruthCheck.new(condition.to_mom(method))
check = Mom::IfStatement.new( cond , if_true , if_false )
check.hoisted = hoisted.to_mom(method) if hoisted
check
end

View File

@ -12,7 +12,7 @@ module Vool
else
type = :frame
end
Mom::SlotConstant.new([:message , type , @name] , @value)
Mom::SlotConstant.new(Mom::SlotDefinition.new(:message , [type , @name]) , @value)
end
end

View File

@ -8,10 +8,21 @@ module Vool
class LocalVariable < Statement
include Named
def to_mom(method)
if method.args_type.variable_index(@name)
type = :arguments
else
type = :frame
end
Mom::SlotDefinition.new(:message , [type , @name])
end
end
class InstanceVariable < Statement
include Named
def to_mom(method)
Mom::SlotDefinition.new(:message , [ :self , @name] )
end
# used to collect type information
def add_ivar( array )
array << @name

View File

@ -17,8 +17,8 @@ module Vool
def test_condition_compiles_to_slot
assert_equal Mom::TruthCheck , @first.condition.class
end
def test_condition_is_send
assert_equal Vool::LocalVariable , @first.condition.condition.class
def test_condition_is_slot
assert_equal Mom::SlotDefinition , @first.condition.condition.class , @stats
end
def test_hoisetd
assert_equal Mom::SlotConstant , @first.hoisted.class

View File

@ -17,8 +17,8 @@ module Vool
def test_condition_compiles_to_check
assert_equal Mom::TruthCheck , @first.condition.class , @stats
end
def test_condition_is_instance
assert_equal Vool::InstanceVariable , @first.condition.condition.class , @stats
def test_condition_is_slot
assert_equal Mom::SlotDefinition , @first.condition.condition.class , @stats
end
def test_nothing_hoisted
assert_nil @first.hoisted , @stats