adds value to used regs and test for it
This commit is contained in:
parent
300ce24739
commit
e436581ce8
@ -29,11 +29,11 @@ module Phisol
|
|||||||
end
|
end
|
||||||
|
|
||||||
# require a (temporary) register. code must give this back with release_reg
|
# 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?
|
if @regs.empty?
|
||||||
reg = Register.tmp_reg type
|
reg = Register.tmp_reg(type , value)
|
||||||
else
|
else
|
||||||
reg = @regs.last.next_reg_use type
|
reg = @regs.last.next_reg_use(type , value)
|
||||||
end
|
end
|
||||||
@regs << reg
|
@regs << reg
|
||||||
return reg
|
return reg
|
||||||
|
@ -13,7 +13,7 @@ module Phisol
|
|||||||
|
|
||||||
def on_int statement
|
def on_int statement
|
||||||
int = statement.first
|
int = statement.first
|
||||||
reg = use_reg :int
|
reg = use_reg :Integer , int
|
||||||
@method.source.add_code Register::LoadConstant.new( statement, int , reg )
|
@method.source.add_code Register::LoadConstant.new( statement, int , reg )
|
||||||
return reg
|
return reg
|
||||||
end
|
end
|
||||||
|
@ -16,13 +16,7 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
symbol.to_s
|
"#{symbol}:#{type}:#{value}"
|
||||||
end
|
|
||||||
|
|
||||||
def self.convert something
|
|
||||||
return something unless something.is_a? Symbol
|
|
||||||
return something unless look_like_reg(something)
|
|
||||||
return new(something , :int)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.look_like_reg is_it
|
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.
|
# 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
|
# Current thinking is that scratch is schatch between instructions
|
||||||
def self.tmp_reg type
|
def self.tmp_reg type , value = nil
|
||||||
RegisterValue.new :r4 , type
|
RegisterValue.new :r4 , type , value
|
||||||
end
|
end
|
||||||
|
|
||||||
# The first arg is a class name (possibly lowercase) and the second an instance variable name.
|
# The first arg is a class name (possibly lowercase) and the second an instance variable name.
|
||||||
|
@ -26,6 +26,7 @@ module CompilerHelper
|
|||||||
produced = compiler.process( parts )
|
produced = compiler.process( parts )
|
||||||
assert @output , "No output given"
|
assert @output , "No output given"
|
||||||
assert_equal produced.class, @output , "Wrong class"
|
assert_equal produced.class, @output , "Wrong class"
|
||||||
|
produced
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -11,7 +11,7 @@ class TestBasic < MiniTest::Test
|
|||||||
|
|
||||||
def test_number
|
def test_number
|
||||||
@string_input = '42 '
|
@string_input = '42 '
|
||||||
check
|
assert_equal 42 , check.value
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_true
|
def test_true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user