Removing the SlotLanguage

I turned out that that layer did not provide benefit. Data was being shuffled, without gain, so i moved the compiler to the SlotMachine
This commit is contained in:
2020-02-19 02:13:50 +07:00
parent 2d11078a37
commit b88c5ff498
17 changed files with 0 additions and 677 deletions

View File

@ -1,18 +0,0 @@
require_relative "../helper"
module SlotLanguage
module SlotHelper
def compile(input)
SlotCompiler.compile(input)
end
def compile_class(input)
compile(input).class
end
end
module SlotToHelper
def setup
Parfait.boot!({})
@compiler = SlotMachine::SlotCollection.compiler_for( :Space , :main,{},{})
end
end
end

View File

@ -1,2 +0,0 @@
start_label
a = b

View File

@ -1,64 +0,0 @@
require_relative "helper"
module SlotLanguage
class TestAssignment < MiniTest::Test
include SlotHelper
def compile_assign(str)
assign = compile(str)
assert_equal Assignment , assign.class
assert_equal :a , assign.left.name
assert_equal :b , assign.right.name
assign
end
def test_slot_load_rinst
assign = compile_assign("a = @b")
end
def test_slot_load_linst
assign = compile_assign("@a = b")
end
def test_slot_load_lrinst
compile_assign("@a = @b")
end
def test_assign
assign = compile_assign("a = b")
assert_equal Assignment , assign.class
end
end
class TestAssignment2 < MiniTest::Test
include SlotHelper
def test_slot_load_linst_trav
assert_equal Assignment , compile_class("@a = b.c")
end
def test_assign1
assign = compile("c = c.next")
assert_equal Assignment , assign.class
end
def test_shift
load = compile("a = b.c")
assert_equal Assignment , load.class
assert_equal :a , load.left.name
assert_equal Variable , load.right.class
end
end
class TestAssignment3 < MiniTest::Test
include SlotHelper
def test_inst_ass
assign = compile("@a.b = c")
assert_equal Assignment , assign.class
assert_equal MessageVariable , assign.left.class
assert_equal :a , assign.left.name
assert_equal Variable , assign.left.chain.class
assert_equal :b , assign.left.chain.name
end
def test_local_ass
assign = compile("a.b = c")
assert_equal Assignment , assign.class
assert_equal Variable , assign.left.class
assert_equal :a , assign.left.name
assert_equal Variable , assign.left.chain.class
assert_equal :b , assign.left.chain.name
end
end
end

View File

@ -1,92 +0,0 @@
require_relative "helper"
module SlotLanguage
class TestEqualGoto < MiniTest::Test
include SlotHelper
def do_check(check)
assert_equal EqualGoto , check.class
assert_equal Goto , check.goto.class
assert check.left.is_a?(Variable)
assert check.right.is_a?(Variable)
assert_equal :a , check.left.name
assert_equal :b , check.right.name
end
def test_equal_local
check = compile("goto(exit_label) if(a == b)")
do_check(check)
end
def test_equal_inst_left
check = compile("goto(exit_label) if(@a == b)")
do_check(check)
end
def test_equal_inst_right
check = compile("goto(exit_label) if(a == @b)")
do_check(check)
end
end
class TestEqualGotoFull < MiniTest::Test
include SlotHelper
def setup
@expr = compile("start_label;goto(start_label) if( b == c)")
end
def test_2
assert_equal Array , @expr.class
assert_equal 2 , @expr.length
end
def test_label
assert_equal SlotMachine::Label , @expr.first.class
assert_equal :start_label , @expr.first.name
end
def test_conditional
assert_equal EqualGoto , @expr.last.class
assert_equal :start_label , @expr.last.goto.label.name
end
def test_same_label
assert_equal @expr.first.object_id , @expr.last.goto.label.object_id
end
def test_expression_left
assert_equal Variable , @expr.last.left.class
assert_equal :b , @expr.last.left.name
end
def test_expression_right
assert_equal Variable , @expr.last.right.class
assert_equal :c , @expr.last.right.name
end
end
class TestEqualGotoChain < MiniTest::Test
include SlotHelper
def setup
@expr = compile("goto(start_label) if( a.b == c)")
end
def test_eq
assert_equal EqualGoto , @expr.class
end
def test_left
assert_equal Variable , @expr.left.class
assert_equal :a , @expr.left.name
end
def test_left_chain
assert_equal Variable , @expr.left.chain.class
assert_equal :b , @expr.left.chain.name
end
end
class TestEqualGotoChain2 < MiniTest::Test
include SlotHelper
def setup
@expr = compile("goto(start_label) if( a == @b.c)")
end
def test_eq
assert_equal EqualGoto , @expr.class
end
def test_left
assert_equal MessageVariable , @expr.right.class
assert_equal :b , @expr.right.name
end
def test_left_chain
assert_equal Variable , @expr.right.chain.class
assert_equal :c , @expr.right.chain.name
end
end
end

View File

@ -1,36 +0,0 @@
require_relative "helper"
module SlotLanguage
class TestGoto < MiniTest::Test
include SlotHelper
def test_goto_class
assert_equal Goto , compile_class("goto(exit_label)")
end
def test_goto_label
goto = compile("goto(exit_label)")
assert_equal SlotMachine::Label , goto.label.class
assert_equal :exit_label , goto.label.name
end
def test_label
label = compile("while_label")
assert_equal SlotMachine::Label , label.class
assert_equal :while_label , label.name
end
def test_2_label
labels = compile("exit_label;exit_label")
assert_equal :exit_label , labels[0].name
assert_equal :exit_label , labels[1].name
assert_equal labels[0].object_id , labels[1].object_id
end
def test_goto_with_label
gotos = compile("exit_label;goto(exit_label)")
assert_equal :exit_label , gotos[0].name
assert_equal :exit_label , gotos[1].label.name
assert_equal gotos[0].object_id , gotos[1].label.object_id
end
end
end

View File

@ -1,45 +0,0 @@
require_relative "helper"
module SlotLanguage
class TestMacroMakerLoad < MiniTest::Test
include SlotToHelper
def setup
super
@slot = MacroMaker.load_string( mini_file ).to_slot(@compiler)
end
def test_label
assert_equal SlotMachine::Label , @slot.class
end
def test_assign
assert_equal SlotMachine::SlotLoad , @slot.next.class
assert_equal "message.a" , @slot.next.left.to_s
assert_equal "message.b" , @slot.next.right.to_s
end
def test_length
assert_equal 2 , @slot.length
end
end
class TestMacroMakerLoad < MiniTest::Test
include SlotHelper
def check_mini(maker)
assert_equal MacroMaker , maker.class
assert_equal Array , maker.source.class
assert_equal SlotMachine::Label , maker.source.first.class
assert_equal 2 , maker.source.length
end
def mini_file
File.read(File.expand_path( "../mini.slot" , __FILE__))
end
def test_mini_file
check_mini MacroMaker.load_file("../../../test/slot_language/mini.slot")
end
def test_mini_string
check_mini MacroMaker.load_string( mini_file )
end
def test_mini_source
check_mini MacroMaker.new( SlotCompiler.compile(mini_file))
end
end
end

View File

@ -1,17 +0,0 @@
require_relative "helper"
module SlotLanguage
class TestSlotCompiler < MiniTest::Test
include SlotHelper
def test_init
assert SlotCompiler.new
end
def test_labels
assert SlotCompiler.new.labels.empty?
end
def test_basic_compile
assert_equal Variable , compile("a").class
end
end
end

View File

@ -1,35 +0,0 @@
require_relative "helper"
module SlotLanguage
class TestVariable < MiniTest::Test
include SlotHelper
def compile_var(str)
var = compile(str)
assert var.is_a?(Variable)
assert_equal :a , var.name
var
end
def test_local
assert_equal Variable , compile_var("a").class
end
def test_inst
assert_equal MessageVariable , compile_var("@a").class
end
def test_local_chain
chain = compile_var("a.b")
assert_equal Variable , chain.chain.class
assert_equal :b , chain.chain.name
end
def test_local_chain2
chain = compile_var("a.b.c")
assert_equal Variable , chain.chain.chain.class
assert_equal :c , chain.chain.chain.name
end
def test_inst_chain
chain = compile_var("@a.b")
assert_equal MessageVariable , chain.class
assert_equal Variable , chain.chain.class
assert_equal :b , chain.chain.name
end
end
end