div10 test for interpreter
This commit is contained in:
parent
30d2cd3af7
commit
2c137e8c97
@ -80,7 +80,7 @@ module Parfait
|
|||||||
raise "frame must be a type, not:#{frame}" unless frame.is_a?(Type)
|
raise "frame must be a type, not:#{frame}" unless frame.is_a?(Type)
|
||||||
found = get_method( method_name )
|
found = get_method( method_name )
|
||||||
if found
|
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
|
raise "attempt to redifine method for different type " unless self == found.for_type
|
||||||
found.init(arguments , frame)
|
found.init(arguments , frame)
|
||||||
return found
|
return found
|
||||||
|
@ -122,7 +122,7 @@ module Risc
|
|||||||
def execute_LoadConstant
|
def execute_LoadConstant
|
||||||
to = @instruction.register
|
to = @instruction.register
|
||||||
value = @instruction.constant
|
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 )
|
set_register( to , value )
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Risc
|
module Risc
|
||||||
class InterpreterAdd < MiniTest::Test
|
class InterpreterReturn < MiniTest::Test
|
||||||
include Ticker
|
include Ticker
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
|
57
test/risc/interpreter/test_return_call.rb
Normal file
57
test/risc/interpreter/test_return_call.rb
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user