unite the two resolve_to_index functions
This commit is contained in:
@ -1,9 +1,7 @@
|
||||
require_relative '../helper'
|
||||
|
||||
module Risc
|
||||
|
||||
module Statements
|
||||
include AST::Sexp
|
||||
include CleanCompile
|
||||
|
||||
def setup
|
||||
@ -62,7 +60,7 @@ module Risc
|
||||
postamble.each {all.pop}
|
||||
str = all.collect{|i| i.class.name}.join(", ").gsub("Risc::","")
|
||||
str = "[#{str}]"
|
||||
all = str.split(",").each_slice(5).collect { |line| " " + line.join(",")}
|
||||
all = str.split(",").each_slice(5).collect { |line| " " + line.join(",")}
|
||||
all.join(",\n")
|
||||
end
|
||||
end
|
||||
|
39
test/mom/send/test_setup_simple.rb
Normal file
39
test/mom/send/test_setup_simple.rb
Normal file
@ -0,0 +1,39 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class TestMessageSetupSimple < MiniTest::Test
|
||||
include Statements
|
||||
include Assertions
|
||||
|
||||
def setup
|
||||
super
|
||||
@input = "5.mod4"
|
||||
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, LoadConstant,
|
||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
||||
SlotToReg, LoadConstant, FunctionCall, Label]
|
||||
@produced = produce_body
|
||||
end
|
||||
|
||||
def test_send_instructions
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
def test_load_method
|
||||
method = @produced
|
||||
assert_load( method, Parfait::TypedMethod ,:r1)
|
||||
assert_equal :mod4 , method.constant.name
|
||||
end
|
||||
def test_load_space
|
||||
space = @produced.next(1)
|
||||
assert_load( space , Parfait::Space , :r3 )
|
||||
end
|
||||
def test_load_message
|
||||
sl = @produced.next( 2 )
|
||||
assert_slot_to_reg( sl , :r3 , 4 , :r2 )
|
||||
end
|
||||
def test_load_next_message
|
||||
sl = @produced.next( 3 )
|
||||
assert_slot_to_reg( sl , :r2 , 2 , :r4 )
|
||||
end
|
||||
|
||||
end
|
||||
end
|
15
test/support/risc_assert.rb
Normal file
15
test/support/risc_assert.rb
Normal file
@ -0,0 +1,15 @@
|
||||
module Risc
|
||||
module Assertions
|
||||
def assert_slot_to_reg( slot , array = nil, index = nil , register = nil)
|
||||
assert_equal SlotToReg , slot.class
|
||||
assert_equal( array , slot.array.symbol) if array
|
||||
assert_equal( index , slot.index) if index
|
||||
assert_equal( register , slot.register.symbol) if register
|
||||
end
|
||||
def assert_load(load , clazz = nil , register = nil)
|
||||
assert_equal LoadConstant , load.class
|
||||
assert_equal( clazz , load.constant.class) if clazz
|
||||
assert_equal( register , load.register.symbol) if register
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user