From 66a160d8abf52313c54487dfde94d7b892755f13 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 19 Mar 2018 13:05:08 +0530 Subject: [PATCH] fix code insertion in method --- lib/common/list.rb | 2 +- lib/risc/method_compiler.rb | 2 +- test/mom/helper.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/common/list.rb b/lib/common/list.rb index 7761f478..4a6c88c5 100644 --- a/lib/common/list.rb +++ b/lib/common/list.rb @@ -32,7 +32,7 @@ module Common # but allowing the instruction to be a list too (ie more than one) def insert( instruction ) instruction.last.set_next @next - @next = instruction.last + @next = instruction end # return last set instruction. ie follow the linked list until it stops diff --git a/lib/risc/method_compiler.rb b/lib/risc/method_compiler.rb index fcfa2d92..65f0e74f 100644 --- a/lib/risc/method_compiler.rb +++ b/lib/risc/method_compiler.rb @@ -107,7 +107,7 @@ module Risc raise "Not an instruction:#{instruction.to_s}" unless instruction.is_a?(Risc::Instruction) raise instruction.to_s if( instruction.class.name.split("::").first == "Arm") @current.insert(instruction) #insert after current - @current = instruction + @current = instruction.last self end diff --git a/test/mom/helper.rb b/test/mom/helper.rb index 97792477..01ac154f 100644 --- a/test/mom/helper.rb +++ b/test/mom/helper.rb @@ -41,7 +41,7 @@ module Risc Parfait.object_space.get_main.instructions end def real_index(index) - index - preamble.length + 1 + index - preamble.length end def compare_instructions( instruction , expect ) index = 0 @@ -50,7 +50,7 @@ module Risc #full_expect = expect begin should = full_expect[index] - return "No instruction at #{index}\n#{should(all)}" unless should + return "No instruction at #{real_index(index)}\n#{should(all)}" unless should return "Expected at #{real_index(index)}\n#{should(all)} was #{instruction.to_s}" unless instruction.class == should #puts instruction.to_s if (index > preamble.length) and (index + postamble.length <= full_expect.length) index += 1