From 80c343053677d7aeefc8dd25bb74f801eef3b9b1 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 6 Sep 2017 12:51:24 +0300 Subject: [PATCH] replace arrays with Statements class --- lib/common/statements.rb | 7 ++++++- lib/mom/if_statement.rb | 4 ++++ lib/vool/statements/class_statement.rb | 2 +- lib/vool/statements/return_statement.rb | 4 ++-- lib/vool/statements/send_statement.rb | 2 +- lib/vool/statements/statements.rb | 4 +--- test/vool/to_mom/send/test_send_simple_args.rb | 2 +- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/common/statements.rb b/lib/common/statements.rb index a8b9218c..cb3e2722 100644 --- a/lib/common/statements.rb +++ b/lib/common/statements.rb @@ -15,10 +15,15 @@ module Common def first @statements.first end + def last + @statements.last + end def length @statements.length end - + def [](i) + @statements[i] + end def collect(arr) @statements.each { |s| s.collect(arr) } super diff --git a/lib/mom/if_statement.rb b/lib/mom/if_statement.rb index fbe1ff6a..14c58f0e 100644 --- a/lib/mom/if_statement.rb +++ b/lib/mom/if_statement.rb @@ -9,6 +9,10 @@ module Mom @if_true = if_true @if_false = if_false end + + def flatten + self + end end end diff --git a/lib/vool/statements/class_statement.rb b/lib/vool/statements/class_statement.rb index 6a0e177f..c498ed04 100644 --- a/lib/vool/statements/class_statement.rb +++ b/lib/vool/statements/class_statement.rb @@ -18,7 +18,7 @@ module Vool @body.statements.each do |meth| methods << meth.to_mom( nil ) end - methods + Mom::Statements.new(methods) end def collect(arr) diff --git a/lib/vool/statements/return_statement.rb b/lib/vool/statements/return_statement.rb index 076691a7..b3b71dd2 100644 --- a/lib/vool/statements/return_statement.rb +++ b/lib/vool/statements/return_statement.rb @@ -15,8 +15,8 @@ module Vool # - store the given return value, this is a SlotMove / SlotConstant # - activate return sequence (reinstantiate old message and jump to return address) def to_mom( method ) - [Mom::SlotConstant.new([:message , :return_value] , @return_value) , - Mom::ReturnSequence.new] + Mom::Statements.new [Mom::SlotConstant.new([:message , :return_value] , @return_value) , + Mom::ReturnSequence.new] end end diff --git a/lib/vool/statements/send_statement.rb b/lib/vool/statements/send_statement.rb index bb86ae57..7f9cb989 100644 --- a/lib/vool/statements/send_statement.rb +++ b/lib/vool/statements/send_statement.rb @@ -34,7 +34,7 @@ module Vool # in a not so distant future, temporary variables will have to be created # and complex statements hoisted to assign to them. pps: same as in conditions def to_mom( method ) - message_setup + call_instruction + Mom::Statements.new( message_setup + call_instruction ) end def message_setup diff --git a/lib/vool/statements/statements.rb b/lib/vool/statements/statements.rb index 07201079..9df88aed 100644 --- a/lib/vool/statements/statements.rb +++ b/lib/vool/statements/statements.rb @@ -4,9 +4,7 @@ module Vool # create machine instructions def to_mom( method ) - all = @statements.collect do |statement| - statement.to_mom( method ) - end + all = @statements.collect { |statement| statement.to_mom( method ) } Mom::Statements.new(all) end diff --git a/test/vool/to_mom/send/test_send_simple_args.rb b/test/vool/to_mom/send/test_send_simple_args.rb index a321eb6b..9e96ec9e 100644 --- a/test/vool/to_mom/send/test_send_simple_args.rb +++ b/test/vool/to_mom/send/test_send_simple_args.rb @@ -10,7 +10,7 @@ module Vool end def test_stats - assert_equal Array , @stats.class + assert_equal Mom::Statements , @stats.class end def test_class_compiles assert_equal Mom::SlotConstant , @stats.first.class , @stats