actually adding risc instructions
fix test harness 1 working test (yeh)
This commit is contained in:
@ -34,7 +34,7 @@ module Risc
|
||||
end
|
||||
|
||||
def preamble
|
||||
[Label, SlotToReg , LoadConstant, RegToSlot, LoadConstant,RegToSlot, LoadConstant, SlotToReg, SlotToReg ]
|
||||
[Label, LoadConstant, SlotToReg, RegToSlot ]
|
||||
end
|
||||
def postamble
|
||||
[ Label, FunctionReturn]
|
||||
@ -57,19 +57,20 @@ module Risc
|
||||
index = 0
|
||||
all = instruction.to_arr
|
||||
full_expect = preamble + expect + postamble
|
||||
full_expect = expect
|
||||
#full_expect = expect
|
||||
begin
|
||||
should = full_expect[index]
|
||||
return "No instruction at #{index}" unless should
|
||||
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
|
||||
index += 1
|
||||
instruction = instruction.next
|
||||
end while( instruction )
|
||||
nil
|
||||
end
|
||||
def should( all )
|
||||
#preamble.each {all.shift}
|
||||
#postamble.each {all.pop}
|
||||
preamble.each {all.shift}
|
||||
postamble.each {all.pop}
|
||||
str = all.to_s.gsub("Risc::","")
|
||||
ret = ""
|
||||
str.split(",").each_slice(6).each do |line|
|
||||
|
@ -5,7 +5,18 @@ module Risc
|
||||
class TestAssignStatement < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
def test_assign_op
|
||||
def test_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"
|
||||
@ -15,9 +26,9 @@ module Risc
|
||||
end
|
||||
|
||||
def pest_assign_ivar_notpresent
|
||||
@input =s(:statements, s(:i_assignment, s(:ivar, :r), s(:int, 5)))
|
||||
@expect = []
|
||||
assert_raises{ check_nil }
|
||||
@input = "@r = 5"
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
|
||||
def pest_assign_ivar
|
||||
@ -30,16 +41,6 @@ module Risc
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
|
||||
def pest_assign_local_assign
|
||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
||||
|
||||
@input = s(:statements, s(:l_assignment, s(:local, :r), s(:int, 5)))
|
||||
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
|
||||
RegToSlot, Label, FunctionReturn]
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
|
||||
def pest_assign_call
|
||||
Parfait.object_space.get_main.add_local(:r , :Object)
|
||||
@input = s(:statements, s(:l_assignment, s(:local, :r), s(:call, :main, s(:arguments))))
|
||||
|
Reference in New Issue
Block a user