From 1a219a7c89494c055489baf5eca101b6cab1a802 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 4 Sep 2017 21:31:49 +0300 Subject: [PATCH] introduce slot_definition and use it --- lib/mom/slot_load.rb | 8 ++++++++ lib/vool/statements/if_statement.rb | 3 ++- lib/vool/statements/local_statement.rb | 2 +- lib/vool/statements/variables.rb | 11 +++++++++++ test/vool/to_mom/test_if_condition.rb | 4 ++-- test/vool/to_mom/test_if_simple.rb | 4 ++-- 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/mom/slot_load.rb b/lib/mom/slot_load.rb index ecf7b25f..6ff157d9 100644 --- a/lib/mom/slot_load.rb +++ b/lib/mom/slot_load.rb @@ -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 diff --git a/lib/vool/statements/if_statement.rb b/lib/vool/statements/if_statement.rb index c675301e..bab08c8b 100644 --- a/lib/vool/statements/if_statement.rb +++ b/lib/vool/statements/if_statement.rb @@ -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 diff --git a/lib/vool/statements/local_statement.rb b/lib/vool/statements/local_statement.rb index 2f261a79..dbfc0562 100644 --- a/lib/vool/statements/local_statement.rb +++ b/lib/vool/statements/local_statement.rb @@ -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 diff --git a/lib/vool/statements/variables.rb b/lib/vool/statements/variables.rb index fcb8fade..5281cfad 100644 --- a/lib/vool/statements/variables.rb +++ b/lib/vool/statements/variables.rb @@ -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 diff --git a/test/vool/to_mom/test_if_condition.rb b/test/vool/to_mom/test_if_condition.rb index 80baf03b..a5f4a5a8 100644 --- a/test/vool/to_mom/test_if_condition.rb +++ b/test/vool/to_mom/test_if_condition.rb @@ -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 diff --git a/test/vool/to_mom/test_if_simple.rb b/test/vool/to_mom/test_if_simple.rb index 9569cf72..2c40de7e 100644 --- a/test/vool/to_mom/test_if_simple.rb +++ b/test/vool/to_mom/test_if_simple.rb @@ -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