adds set_byte interpreter test

This commit is contained in:
Torsten Ruger 2016-12-16 01:43:54 +02:00
parent b2579a2b82
commit 190a0ffa47
4 changed files with 73 additions and 13 deletions

View File

@ -134,11 +134,8 @@ module Register
index = get_register(@instruction.index)
end
if object.is_a?(Symbol)
if( index == 2 )
raise "Must convert symbol to word:#{object}" unless( index == 2 )
value = object.to_s.length
else
raise "Unsupported action, must convert symbol to word:#{object}"
end
else
value = object.get_internal_word( index )
end
@ -167,11 +164,8 @@ module Register
else
index = get_register(@instruction.index)
end
if object.is_a?(Symbol)
raise "Unsupported action, must convert symbol to word:#{object}"
else
raise "Unsupported action, must convert symbol to word:#{object}" if object.is_a?(Symbol)
value = object.get_char( index )
end
#value = value.object_id unless value.is_a? Fixnum
set_register( @instruction.register , value )
true
@ -185,7 +179,7 @@ module Register
else
index = get_register(@instruction.index)
end
object.set_internal_byte( index , value )
object.set_char( index , value )
trigger(:object_changed, @instruction.array , index / 4 )
true
end

View File

@ -1,7 +1,8 @@
require_relative "test_add"
require_relative "test_change"
require_relative "test_get_byte"
require_relative "test_if"
require_relative "test_puts"
require_relative "test_plus"
require_relative "test_mult"
require_relative "test_word"
require_relative "test_set_byte"

View File

@ -0,0 +1,65 @@
require_relative "helper"
class TestInterpretSetByte < MiniTest::Test
include Ticker
def setup
@string_input = <<HERE
class Space
int main()
"Hello".set_internal_byte(1,104)
end
end
HERE
@input = s(:statements, s(:class, :Space, s(:derives, nil), s(:statements,
s(:function, :Integer, s(:name, :main), s(:parameters),
s(:statements, s(:call,
s(:name, :set_internal_byte),
s(:arguments, s(:int, 1), s(:int, 104)),
s(:receiver, s(:string, "Hello"))))))))
super
end
def test_chain
#show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
"LoadConstant","SetSlot","FunctionCall","Label","GetSlot",
"LoadConstant","SetSlot","LoadConstant","SetSlot","LoadConstant",
"SetSlot","LoadConstant","SetSlot","LoadConstant","SetSlot",
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","Label",
"GetSlot","GetSlot","GetSlot","SetByte","Label",
"FunctionReturn","RegisterTransfer","GetSlot","GetSlot","Label",
"FunctionReturn","RegisterTransfer","Syscall","NilClass"]
end
def test_branch
was = @interpreter.instruction
assert_equal Register::Branch , ticks(1).class
assert was != @interpreter.instruction
assert @interpreter.instruction , "should have gone to next instruction"
end
def test_load
assert_equal Register::LoadConstant , ticks(3).class
assert_equal Parfait::Space , @interpreter.get_register(:r2).class
assert_equal :r2, @interpreter.instruction.array.symbol
end
def test_get
assert_equal Register::GetSlot , ticks(4).class
assert @interpreter.get_register( :r1 )
assert Integer , @interpreter.get_register( :r1 ).class
end
def test_call
assert_equal Register::FunctionCall , ticks(8).class
end
def test_exit
done = ticks(39)
assert_equal NilClass , done.class
end
def test_set_byte
done = ticks(29)
assert_equal Register::SetByte , done.class
assert_equal "h".ord , @interpreter.get_register(done.register)
end
end

View File

@ -1,6 +1,6 @@
require_relative "helper"
class TestInterpretWord < MiniTest::Test
class TestInterpretGetByte < MiniTest::Test
include Ticker
def setup