From e436581ce88ebea3522e988602b06ba02bf059a4 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 15 Oct 2015 09:07:47 +0300 Subject: [PATCH] adds value to used regs and test for it --- lib/phisol/compiler.rb | 6 +++--- lib/phisol/compiler/basic_values.rb | 2 +- lib/register/register_value.rb | 12 +++--------- test/compiler/expressions/compiler_helper.rb | 1 + test/compiler/expressions/test_basic.rb | 2 +- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/phisol/compiler.rb b/lib/phisol/compiler.rb index 98d371e3..d16083bb 100644 --- a/lib/phisol/compiler.rb +++ b/lib/phisol/compiler.rb @@ -29,11 +29,11 @@ module Phisol end # require a (temporary) register. code must give this back with release_reg - def use_reg type + def use_reg type , value = nil if @regs.empty? - reg = Register.tmp_reg type + reg = Register.tmp_reg(type , value) else - reg = @regs.last.next_reg_use type + reg = @regs.last.next_reg_use(type , value) end @regs << reg return reg diff --git a/lib/phisol/compiler/basic_values.rb b/lib/phisol/compiler/basic_values.rb index 6fe0529e..680fc260 100644 --- a/lib/phisol/compiler/basic_values.rb +++ b/lib/phisol/compiler/basic_values.rb @@ -13,7 +13,7 @@ module Phisol def on_int statement int = statement.first - reg = use_reg :int + reg = use_reg :Integer , int @method.source.add_code Register::LoadConstant.new( statement, int , reg ) return reg end diff --git a/lib/register/register_value.rb b/lib/register/register_value.rb index be4dda38..db266c9f 100644 --- a/lib/register/register_value.rb +++ b/lib/register/register_value.rb @@ -16,13 +16,7 @@ module Register end def to_s - symbol.to_s - end - - def self.convert something - return something unless something.is_a? Symbol - return something unless look_like_reg(something) - return new(something , :int) + "#{symbol}:#{type}:#{value}" end def self.look_like_reg is_it @@ -84,8 +78,8 @@ module Register # The first scratch register. There is a next_reg_use to get a next and next. # Current thinking is that scratch is schatch between instructions - def self.tmp_reg type - RegisterValue.new :r4 , type + def self.tmp_reg type , value = nil + RegisterValue.new :r4 , type , value end # The first arg is a class name (possibly lowercase) and the second an instance variable name. diff --git a/test/compiler/expressions/compiler_helper.rb b/test/compiler/expressions/compiler_helper.rb index 50c1f204..ff4a4b95 100644 --- a/test/compiler/expressions/compiler_helper.rb +++ b/test/compiler/expressions/compiler_helper.rb @@ -26,6 +26,7 @@ module CompilerHelper produced = compiler.process( parts ) assert @output , "No output given" assert_equal produced.class, @output , "Wrong class" + produced end end diff --git a/test/compiler/expressions/test_basic.rb b/test/compiler/expressions/test_basic.rb index f6e213e2..8c416b26 100644 --- a/test/compiler/expressions/test_basic.rb +++ b/test/compiler/expressions/test_basic.rb @@ -11,7 +11,7 @@ class TestBasic < MiniTest::Test def test_number @string_input = '42 ' - check + assert_equal 42 , check.value end def test_true