block test

working on return semanitcs
(still avoiding the implicit return)
This commit is contained in:
Torsten Ruger 2018-07-30 14:10:24 +03:00
parent a3059108eb
commit 9c6a099cde
5 changed files with 63 additions and 5 deletions

View File

@ -53,7 +53,7 @@ module Mom
cpu_instructions << cpu if cpu cpu_instructions << cpu if cpu
nekst = nekst.next nekst = nekst.next
end end
Risc::Assembler.new(compiler.get_method , cpu_instructions ) Risc::Assembler.new(compiler.callable , cpu_instructions )
end end
end end

View File

@ -27,7 +27,7 @@ module Risc
@next = nekst @next = nekst
return unless source return unless source
raise "Source must be string or Instruction, not #{source.class}" unless source.is_a?(String) or raise "Source must be string or Instruction, not #{source.class}" unless source.is_a?(String) or
source.is_a?(Mom::Instruction) or source.is_a?(Parfait::CallableMethod) source.is_a?(Mom::Instruction) or source.is_a?(Parfait::Callable)
end end
attr_reader :source attr_reader :source

View File

@ -38,7 +38,7 @@ module Mom
@linker.assemblers.each do |asm| @linker.assemblers.each do |asm|
all = [] all = []
asm.instructions.each do |ins| asm.instructions.each do |ins|
assert !all.include?(ins) , "Double in #{asm.method.name}:#{ins}" assert !all.include?(ins) , "Double in #{asm.callable.name}:#{ins}"
all << ins all << ins
end end
end end

View File

@ -0,0 +1,58 @@
require_relative "../helper"
module Risc
class BlockAssignLocal < MiniTest::Test
include Ticker
def setup
@string_input = block_main("a = yielder {return 15} ; return a")
super
end
def test_chain
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, LoadConstant,
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, Branch, RegToSlot,
RegToSlot, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, Branch, SlotToReg, RegToSlot,
SlotToReg, FunctionCall, LoadConstant, SlotToReg, OperatorInstruction,
IsZero, SlotToReg, SlotToReg, LoadConstant, SlotToReg,
RegToSlot, RegToSlot, SlotToReg, SlotToReg]
assert_equal 15 , get_return.class
end
def est_call_main
call_ins = ticks(main_at)
assert_equal FunctionCall , call_ins.class
assert :main , call_ins.method.name
end
def est_load_yield
load_ins = main_ticks(4)
assert_equal LoadConstant , load_ins.class
assert_equal Parfait::CallableMethod , @interpreter.get_register(load_ins.register).class
assert_equal :yielder , @interpreter.get_register(load_ins.register).name
end
def est_load_space
load_ins = main_ticks(5)
assert_equal LoadConstant , load_ins.class
assert_equal Parfait::Space , @interpreter.get_register(load_ins.register).class
end
def est_op
op = main_ticks(35)
assert_equal OperatorInstruction , op.class
assert_equal :- , op.operator
end
def est_load_block
load_ins = main_ticks(39)
assert_equal LoadConstant , load_ins.class
assert_equal Parfait::Space , @interpreter.get_register(load_ins.register).class
end
def pest_sys
sys = main_ticks(18)
assert_equal Syscall , sys.class
end
end
end

View File

@ -14,7 +14,7 @@ module Risc
alias :do_setup :setup alias :do_setup :setup
def yielder def yielder
"def yielder; yield ; end" "def yielder; return yield ; end"
end end
def block_main( main , extra = yielder) def block_main( main , extra = yielder)
@ -42,7 +42,7 @@ module Risc
end end
def get_return def get_return
assert_equal Parfait::Message , @interpreter.get_register(:r8).class #assert_equal Parfait::Message , @interpreter.get_register(:r8).class
@interpreter.get_register(:r0) @interpreter.get_register(:r0)
end end