fix helper

and start on arg test
This commit is contained in:
Torsten Ruger 2018-03-30 18:05:38 +03:00
parent 1956f18faa
commit e68b28d66d
5 changed files with 93 additions and 26 deletions

View File

@ -18,14 +18,14 @@ module Risc
def +( context )
source = "plus"
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
compiler.add_slot_to_reg( source , me , 1 , me)
compiler.add_slot_to_reg( source , other , 1 , other)
compiler.add_code Risc.op( source , :+ , me , other)
compiler.add_slot_to_reg( source + "2" , me , 1 , me)
compiler.add_slot_to_reg( source + "3", other , 1 , 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)
# 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
end

View File

@ -52,8 +52,8 @@ module Risc
#full_expect = expect
begin
should = full_expect[index]
return "No instruction at #{real_index(index)}\n#{should(all)}" unless should
return "Expected at #{real_index(index)}\n#{should(all)} was #{instruction.to_s}" unless instruction.class == 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[0..100]}" unless instruction.class == should
#puts instruction.to_s if (index > preamble.length) and (index + postamble.length <= full_expect.length)
index += 1
instruction = instruction.next
@ -63,10 +63,11 @@ module Risc
def should( all )
preamble.each {all.shift}
postamble.each {all.pop}
str = all.to_s.gsub("Risc::","")
str = all.collect{|i| i.class.name}.join(", ").gsub("Risc::","")
str = "[#{str}]"
ret = ""
str.split(",").each_slice(5).each do |line|
ret += " " + line.join(",") + " ,\n"
ret += " " + line.join(",") + ",\n"
end
ret
end

View File

@ -7,11 +7,12 @@ module Risc
def setup
super
@input = "5.mod4"
@expect = [LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant ,
FunctionCall, Label]
@expect = [LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, RegToSlot, SlotToReg, LoadConstant, FunctionCall,
Label]
end
def test_send_instructions

View 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

View File

@ -5,29 +5,50 @@ module Risc
include Ticker
def setup
@string_input = as_main("a = 15 ; return 5 + 5")
@string_input = as_main("a = 5 + 5")
super
end
def test_add
#show_ticks # get output of what is
def est_add
show_ticks # get output of what is
check_chain [Branch, Label, LoadConstant, SlotToReg, LoadConstant,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, RegToSlot, LoadConstant, RegToSlot, FunctionCall,
Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
SlotToReg]
Label, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, SlotToReg, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, SlotToReg]
#assert_equal 10 , get_return
end
def pest_overflow
ticks( 12 )
assert @interpreter.flags[:overflow]
def est_slot3
sl = ticks( 49 )
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
def pest_zero