adds value to used regs and test for it

This commit is contained in:
Torsten Ruger 2015-10-15 09:07:47 +03:00
parent 300ce24739
commit e436581ce8
5 changed files with 9 additions and 14 deletions

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -11,7 +11,7 @@ class TestBasic < MiniTest::Test
def test_number
@string_input = '42 '
check
assert_equal 42 , check.value
end
def test_true