fix helper
and start on arg test
This commit is contained in:
parent
1956f18faa
commit
e68b28d66d
@ -18,14 +18,14 @@ module Risc
|
|||||||
def +( context )
|
def +( context )
|
||||||
source = "plus"
|
source = "plus"
|
||||||
compiler = compiler_for(:Integer,:+ ,{other: :int})
|
compiler = compiler_for(:Integer,:+ ,{other: :int})
|
||||||
me , other = self_and_int_arg(compiler,source)
|
me , other = self_and_int_arg(compiler,source + "1")
|
||||||
# reduce me and other to integers
|
# reduce me and other to integers
|
||||||
compiler.add_slot_to_reg( source , me , 1 , me)
|
compiler.add_slot_to_reg( source + "2" , me , 1 , me)
|
||||||
compiler.add_slot_to_reg( source , other , 1 , other)
|
compiler.add_slot_to_reg( source + "3", other , 1 , other)
|
||||||
compiler.add_code Risc.op( source , :+ , me , other)
|
compiler.add_code Risc.op( source + "4", :+ , me , other)
|
||||||
#TODO must get an Integer and put the value there then return the integer (object not value)
|
#TODO must get an Integer and put the value there then return the integer (object not value)
|
||||||
# and put it back into the return value
|
# and put it back into the return value
|
||||||
compiler.add_reg_to_slot( source , me , :message , :return_value)
|
compiler.add_reg_to_slot( source + "5" , me , :message , :return_value)
|
||||||
return compiler.method
|
return compiler.method
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -52,8 +52,8 @@ module Risc
|
|||||||
#full_expect = expect
|
#full_expect = expect
|
||||||
begin
|
begin
|
||||||
should = full_expect[index]
|
should = full_expect[index]
|
||||||
return "No instruction at #{real_index(index)}\n#{should(all)}" unless should
|
return "No instruction at #{real_index(index)}\n#{should(all)[0..100]}" unless should
|
||||||
return "Expected at #{real_index(index)}\n#{should(all)} was #{instruction.to_s}" unless instruction.class == should
|
return "Expected at #{real_index(index)}\n#{should(all)} was #{instruction.to_s[0..100]}" unless instruction.class == should
|
||||||
#puts instruction.to_s if (index > preamble.length) and (index + postamble.length <= full_expect.length)
|
#puts instruction.to_s if (index > preamble.length) and (index + postamble.length <= full_expect.length)
|
||||||
index += 1
|
index += 1
|
||||||
instruction = instruction.next
|
instruction = instruction.next
|
||||||
@ -63,7 +63,8 @@ module Risc
|
|||||||
def should( all )
|
def should( all )
|
||||||
preamble.each {all.shift}
|
preamble.each {all.shift}
|
||||||
postamble.each {all.pop}
|
postamble.each {all.pop}
|
||||||
str = all.to_s.gsub("Risc::","")
|
str = all.collect{|i| i.class.name}.join(", ").gsub("Risc::","")
|
||||||
|
str = "[#{str}]"
|
||||||
ret = ""
|
ret = ""
|
||||||
str.split(",").each_slice(5).each do |line|
|
str.split(",").each_slice(5).each do |line|
|
||||||
ret += " " + line.join(",") + ",\n"
|
ret += " " + line.join(",") + ",\n"
|
||||||
|
@ -7,11 +7,12 @@ module Risc
|
|||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "5.mod4"
|
@input = "5.mod4"
|
||||||
@expect = [LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
|
@expect = [LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
||||||
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
|
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
|
||||||
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
|
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
|
||||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant ,
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
|
||||||
FunctionCall, Label]
|
SlotToReg, RegToSlot, SlotToReg, LoadConstant, FunctionCall,
|
||||||
|
Label]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_send_instructions
|
def test_send_instructions
|
||||||
|
44
test/mom/test_send_simple_args.rb
Normal file
44
test/mom/test_send_simple_args.rb
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module Risc
|
||||||
|
class TestCallSimpleArgs < MiniTest::Test
|
||||||
|
include Statements
|
||||||
|
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
@input = "5.get_internal_word(1)"
|
||||||
|
@expect = [LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
||||||
|
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
|
||||||
|
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
|
||||||
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
|
||||||
|
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
||||||
|
RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label]
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_send_instructions
|
||||||
|
assert_nil msg = check_nil , msg
|
||||||
|
end
|
||||||
|
def pest_function_call
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal FunctionCall , produced.next(24).class
|
||||||
|
assert_equal :mod4 , produced.next(24).method.name
|
||||||
|
end
|
||||||
|
def pest_check_continue
|
||||||
|
produced = produce_body
|
||||||
|
assert produced.next(25).name.start_with?("continue_")
|
||||||
|
end
|
||||||
|
def pest_load_label
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal Label , produced.next(19).constant.class
|
||||||
|
end
|
||||||
|
def pest_load_5
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal 5 , produced.next(16).constant.value
|
||||||
|
end
|
||||||
|
def pest_call_reg_setup
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal produced.next(23).register , produced.next(24).register
|
||||||
|
end
|
||||||
|
#TODO check the message setup, type and frame moves
|
||||||
|
end
|
||||||
|
end
|
@ -5,29 +5,50 @@ module Risc
|
|||||||
include Ticker
|
include Ticker
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@string_input = as_main("a = 15 ; return 5 + 5")
|
@string_input = as_main("a = 5 + 5")
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_add
|
def est_add
|
||||||
#show_ticks # get output of what is
|
show_ticks # get output of what is
|
||||||
check_chain [Branch, Label, LoadConstant, SlotToReg, LoadConstant,
|
check_chain [Branch, Label, LoadConstant, SlotToReg, LoadConstant,
|
||||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
||||||
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
||||||
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
|
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
|
||||||
SlotToReg, RegToSlot, LoadConstant, RegToSlot, FunctionCall,
|
SlotToReg, RegToSlot, LoadConstant, RegToSlot, FunctionCall,
|
||||||
Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
|
Label, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
||||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
|
||||||
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
RegToSlot, LoadConstant, SlotToReg, SlotToReg, SlotToReg,
|
||||||
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
||||||
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
LoadConstant, SlotToReg, SlotToReg]
|
||||||
SlotToReg]
|
|
||||||
#assert_equal 10 , get_return
|
#assert_equal 10 , get_return
|
||||||
end
|
end
|
||||||
|
|
||||||
def pest_overflow
|
def est_slot3
|
||||||
ticks( 12 )
|
sl = ticks( 49 )
|
||||||
assert @interpreter.flags[:overflow]
|
assert_equal SlotToReg , sl.class
|
||||||
|
assert_equal :r2 , sl.array.symbol #load from message
|
||||||
|
assert_equal 9 , sl.index
|
||||||
|
assert_equal :r3 , sl.register.symbol
|
||||||
|
end
|
||||||
|
def test_slot2 #load arg from args
|
||||||
|
sl = ticks( 48 )
|
||||||
|
assert_equal SlotToReg , sl.class
|
||||||
|
assert_equal :r2 , sl.array.symbol #load from message
|
||||||
|
assert_equal 9 , sl.index
|
||||||
|
assert_equal :r3 , sl.register.symbol
|
||||||
|
end
|
||||||
|
def est_slot1 #load args from message
|
||||||
|
sl = ticks( 47 )
|
||||||
|
assert_equal SlotToReg , sl.class
|
||||||
|
assert_equal :r0 , sl.array.symbol #load from message
|
||||||
|
assert_equal 2 , sl.index
|
||||||
|
assert_equal :r2 , sl.register.symbol
|
||||||
|
end
|
||||||
|
def est_load_2
|
||||||
|
lod = ticks( 46 )
|
||||||
|
assert_equal LoadConstant , lod.class
|
||||||
|
assert_equal 5 , lod.constant.value
|
||||||
end
|
end
|
||||||
|
|
||||||
def pest_zero
|
def pest_zero
|
||||||
|
Loading…
Reference in New Issue
Block a user