From 2c137e8c97e4d538f3229b1174139472721273d5 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 24 Mar 2018 12:21:46 +0200 Subject: [PATCH] div10 test for interpreter --- lib/parfait/type.rb | 2 +- lib/risc/interpreter.rb | 2 +- test/risc/interpreter/test_return.rb | 2 +- test/risc/interpreter/test_return_call.rb | 57 +++++++++++++++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 test/risc/interpreter/test_return_call.rb diff --git a/lib/parfait/type.rb b/lib/parfait/type.rb index a41b44e3..cb614e50 100644 --- a/lib/parfait/type.rb +++ b/lib/parfait/type.rb @@ -80,7 +80,7 @@ module Parfait raise "frame must be a type, not:#{frame}" unless frame.is_a?(Type) found = get_method( method_name ) if found - puts "redefining method #{method_name}" #TODO, this surely must get more complicated + #puts "redefining method #{method_name}" #TODO, this surely must get more complicated raise "attempt to redifine method for different type " unless self == found.for_type found.init(arguments , frame) return found diff --git a/lib/risc/interpreter.rb b/lib/risc/interpreter.rb index 8d6864cb..257c2b90 100644 --- a/lib/risc/interpreter.rb +++ b/lib/risc/interpreter.rb @@ -122,7 +122,7 @@ module Risc def execute_LoadConstant to = @instruction.register value = @instruction.constant - #value = value.object_id unless value.is_a?(Fixnum) + value = value.value if value.is_a?(Mom::Constant) set_register( to , value ) true end diff --git a/test/risc/interpreter/test_return.rb b/test/risc/interpreter/test_return.rb index 9cb60ae9..42970eb0 100644 --- a/test/risc/interpreter/test_return.rb +++ b/test/risc/interpreter/test_return.rb @@ -1,7 +1,7 @@ require_relative "helper" module Risc - class InterpreterAdd < MiniTest::Test + class InterpreterReturn < MiniTest::Test include Ticker def setup diff --git a/test/risc/interpreter/test_return_call.rb b/test/risc/interpreter/test_return_call.rb new file mode 100644 index 00000000..99e94de4 --- /dev/null +++ b/test/risc/interpreter/test_return_call.rb @@ -0,0 +1,57 @@ +require_relative "helper" + +module Risc + class InterpreterReturnCall < MiniTest::Test + include Ticker + + def setup + @string_input = as_main("return 15.div10") + super + end + + def test_chain + #show_ticks # get output of what is + check_chain [Branch, Label, LoadConstant, SlotToReg, SlotToReg, + RegToSlot, LoadConstant, RegToSlot, FunctionCall, Label, + 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, SlotToReg, SlotToReg, SlotToReg, LoadConstant, + OperatorInstruction, LoadConstant, OperatorInstruction, OperatorInstruction, LoadConstant, + Transfer, OperatorInstruction, OperatorInstruction, LoadConstant, Transfer, + OperatorInstruction, OperatorInstruction, LoadConstant, Transfer, OperatorInstruction, + OperatorInstruction, LoadConstant, OperatorInstruction, LoadConstant, Transfer, + OperatorInstruction, OperatorInstruction, Transfer, LoadConstant, OperatorInstruction, + LoadConstant, OperatorInstruction, OperatorInstruction, RegToSlot, Label, + NilClass] + assert_equal 1 , get_return + end + + def ttest_call_main + call_ins = ticks(9) + assert_equal FunctionCall , call_ins.class + assert :main , call_ins.method.name + end + def ttest_load_5 + load_ins = ticks 11 + assert_equal LoadConstant , load_ins.class + assert_equal 5 , @interpreter.get_register(load_ins.register).value + end + def ttest_transfer + transfer = ticks(19) + assert_equal Transfer , transfer.class + end + def ttest_sys + sys = ticks(20) + assert_equal Syscall , sys.class + end + def ttest_return + ret = ticks(18) + assert_equal FunctionReturn , ret.class + link = @interpreter.get_register( ret.register ) + assert_equal Label , link.class + end + end +end