fix putstring

mainly returning an integer object rather than fixnum
This commit is contained in:
Torsten Ruger 2018-04-01 18:57:43 +03:00
parent b1376e83bd
commit 1d57c59dab
3 changed files with 81 additions and 74 deletions

View File

@ -56,14 +56,16 @@ module Risc
def restore_message(compiler)
r8 = RiscValue.new( :r8 , :Message)
return_tmp = Risc.tmp_reg :Integer
return_tmp = compiler.use_reg :fixnum
source = "_restore_message"
# get the sys return out of the way
compiler.add_transfer(source, Risc.message_reg , return_tmp )
# load the stored message into the base RiscMachine
# load the stored message into the base register
compiler.add_transfer(source, r8 , Risc.message_reg )
int = compiler.use_reg(:Integer)
compiler.add_new_int(source , return_tmp , int )
# save the return value into the message
compiler.add_reg_to_slot( source , return_tmp , :message , :return_value )
compiler.add_reg_to_slot( source , int , :message , :return_value )
end
end
extend ClassMethods

View File

@ -0,0 +1,76 @@
require_relative "helper"
module Risc
class TestPuts < MiniTest::Test
include Ticker
def setup
@string_input = as_main(" return 'Hello again'.putstring ")
super
end
def test_chain
#show_ticks # get output of what is
check_chain [Branch, Label, LoadConstant, SlotToReg, LoadConstant,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, RegToSlot, LoadConstant, RegToSlot, FunctionCall,
Label, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, SlotToReg, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant,
FunctionCall, Label, SlotToReg, SlotToReg, Transfer,
Syscall, Transfer, Transfer, LoadConstant, SlotToReg,
SlotToReg, RegToSlot, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, FunctionReturn, Transfer, Syscall, NilClass]
assert_equal "Hello again" , @interpreter.stdout
assert_equal Parfait::Integer , get_return.class
assert_equal 11 , get_return.value #bytes written
end
def test_call
cal = ticks(51)
assert_equal FunctionCall , cal.class
assert_equal :putstring , cal.method.name
end
def test_putstring_sys
done = ticks(56)
assert_equal Syscall , done.class
assert_equal "Hello again" , @interpreter.stdout
assert_equal 11 , @interpreter.get_register(:r0)
assert_equal Parfait::Word , @interpreter.get_register(:r1).class
assert_equal "Hello again" , @interpreter.get_register(:r1).to_string
end
def test_move_sys_return
sl = ticks(57)
assert_equal Transfer , sl.class
assert_equal :r0 , sl.from.symbol
assert_equal :r1 , sl.to.symbol
assert_equal 11 , @interpreter.get_register(:r1)
end
def test_restore_message
sl = ticks(58)
assert_equal Transfer , sl.class
assert_equal :r8 , sl.from.symbol
assert_equal :r0 , sl.to.symbol
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
end
def test_save_sys_return
sl = ticks(63)
assert_equal RegToSlot , sl.class
assert_equal :r1 , sl.register.symbol #return
assert_equal :r2 , sl.array.symbol #parfait integer
assert_equal 3 , sl.index
end
def test_return
done = ticks(70)
assert_equal FunctionReturn , done.class
end
end
end

View File

@ -1,71 +0,0 @@
require_relative "../helper"
module Risc
class TestPuts < MiniTest::Test
include Ticker
def setup
@string_input = <<HERE
class Space
int main()
"Hello again".putstring()
end
end
HERE
@input = s(:statements, s(:call, :putstring, s(:arguments), s(:receiver, s(:string, "Hello again"))))
super
end
def pest_chain
#show_ticks # get output of what is
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, RegToSlot, FunctionCall, Label, SlotToReg,
LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant,
SlotToReg, RegToSlot, LoadConstant, RegToSlot, Transfer,
FunctionCall, Label, LoadConstant, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, Transfer, Syscall, Transfer,
Transfer, RegToSlot, Label, FunctionReturn, Transfer,
SlotToReg, SlotToReg, LoadConstant, SlotToReg, RegToSlot,
Label, FunctionReturn, Transfer, Syscall, NilClass]
end
def pest_branch
was = @interpreter.instruction
assert_equal Branch , ticks(1).class
assert was != @interpreter.instruction
assert @interpreter.instruction , "should have gone to next instruction"
end
def pest_load
assert_equal LoadConstant , ticks(3).class
assert_equal Parfait::Space , @interpreter.get_register(:r2).class
assert_equal :r2, @interpreter.instruction.array.symbol
end
def pest_get
assert_equal SlotToReg , ticks(4).class
assert @interpreter.get_register( :r1 )
assert Integer , @interpreter.get_register( :r1 ).class
end
def pest_call
assert_equal FunctionCall , ticks(8).class
end
def pest_putstring
done = ticks(29)
assert_equal Syscall , done.class
assert_equal "Hello again" , @interpreter.stdout
end
def pest_return
done = ticks(34)
assert_equal FunctionReturn , done.class
assert Label , @interpreter.instruction.class
assert @interpreter.instruction.is_a?(Instruction) , "not instruction #{@interpreter.instruction}"
end
def pest_exit
done = ticks(45)
assert_equal NilClass , done.class
assert_equal "Hello again" , @interpreter.stdout
end
end
end