first local assignment risc test
comes with casualties slot_load needs more work
This commit is contained in:
@ -21,11 +21,18 @@ module Risc
|
||||
class_type = Parfait.object_space.get_class_by_name(:Space).instance_type
|
||||
class_type.send(:private_add_instance_variable, name , type)
|
||||
end
|
||||
|
||||
def check_nil
|
||||
def produce_body
|
||||
produced = produce_instructions
|
||||
preamble.each{ produced = produced.next }
|
||||
produced
|
||||
end
|
||||
def produce_instructions
|
||||
assert @expect , "No output given"
|
||||
Vool::VoolCompiler.ruby_to_vool "class Space; def main(arg);#{@input};end;end"
|
||||
produced = Parfait.object_space.get_main.instructions
|
||||
Parfait.object_space.get_main.instructions
|
||||
end
|
||||
def check_nil
|
||||
produced = produce_instructions
|
||||
compare_instructions produced , @expect
|
||||
end
|
||||
def check_return
|
||||
@ -33,7 +40,9 @@ module Risc
|
||||
raise was if was
|
||||
Parfait.object_space.get_main.instructions
|
||||
end
|
||||
|
||||
def real_index(index)
|
||||
index - preamble.length + 1
|
||||
end
|
||||
def compare_instructions( instruction , expect )
|
||||
index = 0
|
||||
all = instruction.to_arr
|
||||
@ -42,8 +51,8 @@ module Risc
|
||||
begin
|
||||
should = full_expect[index]
|
||||
return "No instruction at #{index}\n#{should(all)}" unless should
|
||||
return "Expected at #{index+1}\n#{should(all)}" unless instruction.class == should
|
||||
#puts instruction.to_s
|
||||
return "Expected at #{real_index(index)}\n#{should(all)} was #{instruction.to_s}" unless instruction.class == should
|
||||
#puts instruction.to_s if (index > preamble.length) and (index + postamble.length <= full_expect.length)
|
||||
index += 1
|
||||
instruction = instruction.next
|
||||
end while( instruction )
|
||||
|
@ -4,33 +4,16 @@ module Risc
|
||||
class TestAssignStatement < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
def pest_assign_local_assign
|
||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
||||
@input = "r = 5"
|
||||
@expect = [LoadConstant, RegToSlot]
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
|
||||
def pest_assign_op
|
||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
||||
@input = "r = 10.mod4"
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
|
||||
def pest_assign_ivar_notpresent
|
||||
@input = "@r = 5"
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
@expect = [Label, Label, Label, Label, Label]
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
|
||||
def pest_assign_ivar
|
||||
add_space_field(:r , :Integer)
|
||||
|
||||
@input =s(:statements, s(:i_assignment, s(:ivar, :r), s(:int, 5)))
|
||||
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
|
||||
RegToSlot, Label, FunctionReturn]
|
||||
@input = "@r = 5"
|
||||
@expect = [Label]
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
|
||||
|
27
test/mom/test_local_assignment.rb
Normal file
27
test/mom/test_local_assignment.rb
Normal file
@ -0,0 +1,27 @@
|
||||
require_relative 'helper'
|
||||
|
||||
module Risc
|
||||
class TestLocalAssign < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
def setup
|
||||
super
|
||||
@input = "r = 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.value
|
||||
end
|
||||
|
||||
def test_slot_move
|
||||
produced = produce_body
|
||||
assert_equal produced.next.register , produced.register
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user