Block/Lambda rework done

recovered from all renames and redoing the block compilation
all green
This commit is contained in:
Torsten Rüger 2019-08-19 15:23:57 +03:00
parent a722a4c285
commit d5d1df951c
9 changed files with 74 additions and 81 deletions

View File

@ -14,7 +14,7 @@ end
require "minitest/color"
require "minitest/autorun"
#require "minitest/fail_fast" unless ENV["TEST_ALL"]
require "minitest/fail_fast" unless ENV["TEST_ALL"]
require 'minitest/profile'
#require "minitest/reporters"
#Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new

View File

@ -7,55 +7,48 @@ module Risc
def setup
super
@input = as_block("return 5")
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #4
RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg, #9
RegToSlot, RegToSlot, RegToSlot, RegToSlot, SlotToReg, #14
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, #19
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #24
SlotToReg, FunctionCall, Label] #29
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, LoadConstant, #4
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, #9
RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, #14
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #19
RegToSlot, SlotToReg, FunctionCall, Label] #24
end
def test_send_instructions
assert_nil msg = check_nil(:main) , msg
end
def test_load_5
def test_load_5_block
produced = produce_block.next
assert_load( produced , Parfait::Integer)
assert_equal 5 , produced.constant.value
end
def test_load_5
produced = produce_body
assert_load( produced , Parfait::Integer)
assert_equal 5 , produced.constant.value
end
def test_load_block
produced = produce_body.next(3)
assert_load( produced , Parfait::Block)
assert_equal :main_block , produced.constant.name
end
def test_load_method_to_call
produced = produce_body.next(6)
assert_load( produced , Parfait::CallableMethod)
assert_equal :main , produced.constant.name
end
def test_load_next_message
produced = produce_body.next(7)
produced = produce_body.next(4)
assert_load( produced , Parfait::Factory)
assert_equal "Message_Type" , produced.constant.for_type.name
end
def test_load_block
produced = produce_body.next(14)
assert_load( produced , Parfait::Block)
assert_equal :main_block , produced.constant.name
end
def test_load_return
produced = produce_body.next(22)
produced = produce_body.next(18)
assert_load( produced , Label)
assert produced.constant.name.start_with?("continue_")
end
def test_function_call
produced = produce_body.next(26)
produced = produce_body.next(22)
assert_equal FunctionCall , produced.class
assert_equal :main , produced.method.name
end
def test_check_continue
produced = produce_body.next(27)
produced = produce_body.next(23)
assert_equal Label , produced.class
assert produced.name.start_with?("continue_")
end

View File

@ -13,9 +13,9 @@ module Vool
@clazz.body.first
end
def test_setup
assert_equal ClassStatement , @clazz.class
assert_equal ClassExpression , @clazz.class
assert_equal Statements , @clazz.body.class
assert_equal MethodStatement , method.class
assert_equal MethodExpression , method.class
end
def test_class
assert_equal Parfait::Class , @clazz.create_class_object.class
@ -24,9 +24,5 @@ module Vool
clazz = @clazz.create_class_object
assert_equal Parfait::VoolMethod , method.make_method(clazz).class
end
#create CallableMethod
#create Compiler
end
end

View File

@ -11,52 +11,56 @@ module Risc
def test_chain
# show_main_ticks # get output of what is
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg, # 10
RegToSlot, RegToSlot, RegToSlot, Branch, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, # 20
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, SlotToReg, Branch, FunctionCall, LoadConstant, # 30
SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, # 40
RegToSlot, RegToSlot, Branch, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, LoadConstant, RegToSlot, SlotToReg, # 50
SlotToReg, SlotToReg, DynamicJump, LoadConstant, SlotToReg,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, # 60
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, LoadConstant,
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, # 10
RegToSlot, SlotToReg, SlotToReg, Branch, RegToSlot,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 20
SlotToReg, RegToSlot, SlotToReg, FunctionCall, LoadConstant,
SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg, # 30
LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot,
RegToSlot, RegToSlot, Branch, SlotToReg, SlotToReg, # 40
RegToSlot, SlotToReg, LoadConstant, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, DynamicJump, LoadConstant, SlotToReg, # 50
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot,
Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 60
SlotToReg, Branch, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, RegToSlot, # 70
Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, Branch, RegToSlot, RegToSlot, SlotToReg, # 70
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, RegToSlot,
Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 80
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot, # 90
Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, RegToSlot, RegToSlot, SlotToReg, Branch, # 100
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg,
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 80
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot,
Branch, Branch, SlotToReg, SlotToReg, RegToSlot, # 90
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, # 100
SlotToReg, Syscall, NilClass, ]
assert_equal 10 , get_return
end
def test_block_jump
load_ins = main_ticks(53)
load_ins = main_ticks(48)
assert_equal DynamicJump , load_ins.class
assert_equal Parfait::Block , @interpreter.get_register(load_ins.register).class
end
def test_block_load
load_ins = main_ticks(54)
load_ins = main_ticks(49)
assert_load load_ins , Parfait::Integer , :r1
assert_equal 10 , @interpreter.get_register(load_ins.register).value
end
def test_ret_load
load_ins = main_ticks(54)
assert_load load_ins , Parfait::Integer , :r1
assert_equal 15 , @interpreter.get_register(load_ins.register).value
end
def test_block_slot1
assert_slot_to_reg main_ticks(55) ,:r0 , 6 , :r2
assert_slot_to_reg main_ticks(50) ,:r0 , 6 , :r2
end
def test_block_slot2
assert_slot_to_reg main_ticks(56) ,:r2 , 6 , :r2
assert_slot_to_reg main_ticks(51) ,:r2 , 6 , :r2
end
def test_block_slot3
assert_slot_to_reg main_ticks(57) ,:r2 , 3 , :r2
assert_slot_to_reg main_ticks(52) ,:r2 , 3 , :r2
end
def test_block_reg
assert_reg_to_slot main_ticks(58) ,:r1 , :r2 , 1
assert_reg_to_slot main_ticks(53) ,:r1 , :r2 , 1
end
end
end

View File

@ -11,38 +11,38 @@ module Risc
def test_chain
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, LoadConstant,
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, # 10
RegToSlot, SlotToReg, SlotToReg, Branch, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot, # 20
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall,
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg, # 30
SlotToReg, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, Branch, SlotToReg, # 40
SlotToReg, RegToSlot, SlotToReg, LoadConstant, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, DynamicJump, LoadConstant, # 50
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 60
SlotToReg, SlotToReg, Branch, FunctionReturn, SlotToReg,
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, # 70
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg, # 80
Branch, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 90
SlotToReg, RegToSlot, RegToSlot, SlotToReg, Branch,
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, # 100
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 10
RegToSlot, LoadConstant, SlotToReg, Branch, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, # 20
FunctionCall, LoadConstant, SlotToReg, OperatorInstruction, IsZero,
SlotToReg, SlotToReg, LoadConstant, SlotToReg, SlotToReg, # 30
RegToSlot, RegToSlot, RegToSlot, RegToSlot, Branch,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, LoadConstant, # 40
RegToSlot, SlotToReg, SlotToReg, SlotToReg, DynamicJump,
LoadConstant, RegToSlot, Branch, SlotToReg, SlotToReg, # 50
RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, Branch, FunctionReturn, # 60
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 70
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, # 80
Branch, Branch, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 90
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg,
SlotToReg, Syscall, NilClass, ]
assert_equal 15 , get_return
end
def test_load_return
load_ins = main_ticks(44)
load_ins = main_ticks(40)
assert_equal LoadConstant , load_ins.class
assert_equal Parfait::ReturnAddress , @interpreter.get_register(load_ins.register).class
end
def test_load_block
load_ins = main_ticks(49)
load_ins = main_ticks(45)
assert_equal DynamicJump , load_ins.class
assert_equal Parfait::Block , @interpreter.get_register(load_ins.register).class
assert_equal :main_block , @interpreter.get_register(load_ins.register).name

View File

@ -42,7 +42,7 @@ module Risc
def test_creates_method_statement_in_class
clazz = in_test_vool("def meth; @ivar = 5 ;return;end")
assert_equal Vool::Statements , clazz.body.class
assert_equal Vool::MethodStatement , clazz.body.first.class
assert_equal Vool::MethodExpression , clazz.body.first.class
end
def test_callable_method_instance_type

View File

@ -13,7 +13,7 @@ module RubyX
end
def test_vool
vool = compiler.ruby_to_vool source
assert_equal Vool::ClassStatement , vool.class
assert_equal Vool::ClassExpression , vool.class
assert_equal :Object , vool.name
end
def test_mom

View File

@ -18,7 +18,7 @@ module RubyX
def test_class_body_is_scope
clazz = ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
assert_equal Vool::Statements , clazz.body.class
assert_equal Vool::MethodStatement , clazz.body.first.class
assert_equal Vool::MethodExpression , clazz.body.first.class
end
def test_space_is_unchanged_by_compile

View File

@ -20,7 +20,7 @@ module RubyX
def test_one_vool_call
compiler = RubyXCompiler.new(RubyX.default_test_options)
compiler.ruby_to_vool(space_source_for("main"))
assert_equal Vool::ClassStatement , compiler.vool.class
assert_equal Vool::ClassExpression , compiler.vool.class
end
def test_two_vool_calls
compiler = RubyXCompiler.new(RubyX.default_test_options)