From d84d2081920c3e9469b1be94d3302f02b17cd7aa Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 27 Apr 2018 21:56:41 +0300 Subject: [PATCH] implement assignment normalisation especially when the value is a send that needs normalising fixes several broken tests --- lib/vool/statements/assign_statement.rb | 25 ++++++++++-- lib/vool/statements/local_assignment.rb | 5 --- test/risc/methods/test_call_fibo.rb | 21 +++++++++- test/risc/methods/test_call_simple.rb | 20 ++++++++-- test/vool/normalization/test_assignment.rb | 42 ++++++++++++++++++++ test/vool/to_mom/send/test_send_args_send.rb | 33 +++++++++++++++ 6 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 test/vool/normalization/test_assignment.rb create mode 100644 test/vool/to_mom/send/test_send_args_send.rb diff --git a/lib/vool/statements/assign_statement.rb b/lib/vool/statements/assign_statement.rb index 89ba9dd3..eb181cd9 100644 --- a/lib/vool/statements/assign_statement.rb +++ b/lib/vool/statements/assign_statement.rb @@ -7,9 +7,28 @@ module Vool end def normalize() - raise "not named left #{name.class}" unless @name.is_a?(Symbol) - raise "unsupported right #{value}" unless @value.is_a?(Named) or - @value.is_a?(SendStatement) or @value.is_a?(Constant) + raise "not named left #{name.class}" unless name.is_a?(Symbol) + case value + when Named , Constant + return copy + when SendStatement + return normalize_send + else + raise "unsupported right #{value}" + end + end + + def copy(value = nil) + value ||= @value + self.class.new(name,value) + end + + def normalize_send + statements = value.normalize() + return copy( statements ) if statements.is_a?(SendStatement) + assign = statements.statements.pop + statements << copy(assign) + statements end def chain_assign(assign , method) diff --git a/lib/vool/statements/local_assignment.rb b/lib/vool/statements/local_assignment.rb index a2305e5b..b71f33f5 100644 --- a/lib/vool/statements/local_assignment.rb +++ b/lib/vool/statements/local_assignment.rb @@ -2,11 +2,6 @@ module Vool class LocalAssignment < Assignment - def normalize - super - return LocalAssignment.new(@name , @value) - end - def to_mom( method ) if method.arguments_type.variable_index(@name) type = :arguments diff --git a/test/risc/methods/test_call_fibo.rb b/test/risc/methods/test_call_fibo.rb index ed8ad183..c636bbf9 100644 --- a/test/risc/methods/test_call_fibo.rb +++ b/test/risc/methods/test_call_fibo.rb @@ -3,7 +3,26 @@ require_relative 'helper' module Methods class TestFibo < MethodsTest - def est_ruby_adds + def test_count_down + run_space <