more assignment tests

move to writing code to Test class
To use space as before one would have to implement re-opening classes
This commit is contained in:
Torsten Ruger 2018-03-19 13:30:14 +05:30
parent c0a7f1d284
commit dda2ff9049
3 changed files with 59 additions and 3 deletions

View File

@ -28,8 +28,9 @@ module Risc
end
def produce_instructions
assert @expect , "No output given"
Vool::VoolCompiler.ruby_to_vool "class Space; def main(arg);#{@input};end;end"
Parfait.object_space.get_main.instructions
Vool::VoolCompiler.ruby_to_vool "class Test; def main(arg);#{@input};end;end"
test = Parfait.object_space.get_class_by_name :Test
test.instance_type.get_method( :main).instructions
end
def check_nil
produced = produce_instructions
@ -38,7 +39,8 @@ module Risc
def check_return
was = check_nil
raise was if was
Parfait.object_space.get_main.instructions
test = Parfait.object_space.get_class_by_name :Test
test.instance_type.get_method :main
end
def real_index(index)
index - preamble.length

View File

@ -0,0 +1,27 @@
require_relative 'helper'
module Risc
class TestAssignIvarConst < MiniTest::Test
include Statements
def setup
super
@input = "@ivar = 5"
@expect = [LoadConstant, RegToSlot]
end
def test_local_assign_instructions
assert_nil msg = check_nil , msg
end
def test_constant_load
produced = produce_body
assert_equal 5 , produced.constant.known_object.value
end
def test_slot_move
produced = produce_body
assert_equal produced.next.register , produced.register
end
end
end

View File

@ -0,0 +1,27 @@
require_relative 'helper'
module Risc
class TestAssignLocalIvar < MiniTest::Test
include Statements
def setup
super
@input = "@ivar = 5 ; r = @ivar"
@expect = [LoadConstant, RegToSlot, SlotToReg, SlotToReg, RegToSlot]
end
def test_local_assign_instructions
assert_nil msg = check_nil , msg
end
def test_constant_load
produced = produce_body
assert_equal 5 , produced.constant.known_object.value
end
def test_slot_move
produced = produce_body
assert_equal produced.next.register , produced.register
end
end
end