Start nexr level p i SlotLanguage, calling it MacroMaker
Since we already have Macros. Macros are nothing more than a list of SlotMachine Instructions. This is what we are aiming to create (which is also what is created in Sol .to_slot) So the idea came to slot the MacroMaker in there after its done
This commit is contained in:
@ -9,4 +9,10 @@ module SlotLanguage
|
||||
compile(input).class
|
||||
end
|
||||
end
|
||||
module SlotToHelper
|
||||
def setup
|
||||
Parfait.boot!({})
|
||||
@compiler = SlotMachine::SlotCollection.compiler_for( :Space , :main,{},{})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
2
test/slot_language/mini.slot
Normal file
2
test/slot_language/mini.slot
Normal file
@ -0,0 +1,2 @@
|
||||
start_label
|
||||
a = b
|
40
test/slot_language/test_macro_maker.rb
Normal file
40
test/slot_language/test_macro_maker.rb
Normal file
@ -0,0 +1,40 @@
|
||||
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_to_slot
|
||||
assert @slot.is_a?(SlotMachine::Instruction) , @slot.class
|
||||
end
|
||||
def test_length
|
||||
assert_equal 1 , @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
|
@ -15,9 +15,21 @@ module SlotLanguage
|
||||
assert_equal SlotMachine::Label , label.class
|
||||
assert_equal :while_label , label.name
|
||||
end
|
||||
def test_slot_load
|
||||
def test_slot_load_rinst
|
||||
assert_equal LoadMaker , compile_class("a = @b")
|
||||
end
|
||||
def test_slot_load_linst
|
||||
assert_equal LoadMaker , compile_class("@a = b")
|
||||
end
|
||||
def test_slot_load_lrinst
|
||||
assert_equal LoadMaker , compile_class("@a = @b")
|
||||
end
|
||||
def test_slot_load_linst_trav
|
||||
assert_equal LoadMaker , compile_class("@a = b.c")
|
||||
end
|
||||
def test_slot_load_linst_trav2
|
||||
assert_equal LoadMaker , compile_class("@a.c = b.c")
|
||||
end
|
||||
def test_goto
|
||||
assert_equal SlotMachine::Jump , compile_class("goto(exit_label)")
|
||||
end
|
||||
@ -38,5 +50,11 @@ module SlotLanguage
|
||||
assign = compile("c.next = d")
|
||||
assert_equal LoadMaker , assign.class
|
||||
end
|
||||
def test_multiline
|
||||
multi = compile("start_label;c = c.next;goto(start_label)")
|
||||
assert_equal Array , multi.class
|
||||
assert_equal SlotMachine::Label , multi.first.class
|
||||
assert_equal SlotMachine::Jump , multi.last.class
|
||||
end
|
||||
end
|
||||
end
|
||||
|
8
test/slot_language/test_slot_compiler2.rb
Normal file
8
test/slot_language/test_slot_compiler2.rb
Normal file
@ -0,0 +1,8 @@
|
||||
require_relative "helper"
|
||||
|
||||
module SlotLanguage
|
||||
class TestSlotCompiler < MiniTest::Test
|
||||
include SlotHelper
|
||||
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user