diff --git a/lib/common/statements.rb b/lib/common/statements.rb index 4ace6907..87176bcc 100644 --- a/lib/common/statements.rb +++ b/lib/common/statements.rb @@ -31,5 +31,8 @@ module Common @statements.each { |s| s.collect(arr) } super end + def add_array(a) + @statements += a + end end end diff --git a/lib/mom/while_statement.rb b/lib/mom/while_statement.rb index 18de8e07..531f3a97 100644 --- a/lib/mom/while_statement.rb +++ b/lib/mom/while_statement.rb @@ -10,7 +10,7 @@ module Mom @statements = statements end - def flatten + def flatten(options = {}) cond_label = Label.new( "cond_label_#{object_id}") head = cond_label head.append hoisted.flatten diff --git a/lib/vool/statements/send_statement.rb b/lib/vool/statements/send_statement.rb index 0cb72b05..b9a8d24e 100644 --- a/lib/vool/statements/send_statement.rb +++ b/lib/vool/statements/send_statement.rb @@ -77,7 +77,8 @@ module Vool # if cached_type != current_type # cached_type = current_type # cached_method = current_type.resolve_method(method.name) - if_true = [*build_type_cache_update , *build_method_cache_update(in_method)] + if_true = Mom::Statements.new(build_type_cache_update) + if_true.add_array build_method_cache_update(in_method) #@if_true.to_mom( in_method ) #find and assign [Mom::IfStatement.new( build_condition , if_true )] end diff --git a/lib/vool/vool_compiler.rb b/lib/vool/vool_compiler.rb index 36a73883..4beefca5 100644 --- a/lib/vool/vool_compiler.rb +++ b/lib/vool/vool_compiler.rb @@ -8,5 +8,9 @@ module Vool statements.create_objects statements end + def self.ruby_to_mom(source) + statements = elf.ruby_to_vool(source) + statements.to_mom + end end end diff --git a/test/mom/test_dynamic_call_statement.rb b/test/mom/test_dynamic_call_statement.rb new file mode 100644 index 00000000..f92db4b3 --- /dev/null +++ b/test/mom/test_dynamic_call_statement.rb @@ -0,0 +1,29 @@ +require_relative "helper" + +module Mom + class TestCall < MiniTest::Test + include MomCompile + + def setup + Risc.machine.boot + @stats = compile_first_method_flat( "a = 5; a.mod4") + @first = @stats.next + end + + def test_if_compiles + assert_equal @stats.last.class , DynamicCall , @stats + end + def test_check + assert_equal NotSameCheck , @first.class + end + def test_condition_is_slot + assert_equal SlotDefinition , @first.left.class , @first + end + def test_length + assert_equal 12 , @stats.length + end + def test_array + check_array [SlotConstant,NotSameCheck,Label,SlotMove,MessageSetup,ArgumentTransfer,SimpleCall,SlotMove,Label,MessageSetup,ArgumentTransfer,DynamicCall] , @stats + end + end +end