From 6194148fc56a71da05a42c64e74ad66e1badad71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Thu, 13 Feb 2020 13:10:04 +0700 Subject: [PATCH] Rename SlotMaker to Variable Feels like now with better names, i can start to work. --- lib/slot_language/assignment.rb | 10 +++++----- lib/slot_language/slot_compiler.rb | 10 +++++----- lib/slot_language/{slot_maker.rb => variable.rb} | 8 ++++---- test/slot_language/test_assignment.rb | 2 +- test/slot_language/test_equal_goto.rb | 8 ++++---- test/slot_language/test_slot_compiler.rb | 4 ++-- test/slot_language/test_slot_maker.rb | 14 -------------- test/slot_language/test_variable.rb | 10 ++++++++++ 8 files changed, 31 insertions(+), 35 deletions(-) rename lib/slot_language/{slot_maker.rb => variable.rb} (80%) delete mode 100644 test/slot_language/test_slot_maker.rb create mode 100644 test/slot_language/test_variable.rb diff --git a/lib/slot_language/assignment.rb b/lib/slot_language/assignment.rb index 075db043..b5969f26 100644 --- a/lib/slot_language/assignment.rb +++ b/lib/slot_language/assignment.rb @@ -2,20 +2,20 @@ module SlotLanguage # A Assignment makes SlotLoad. That means it stores the information # to be able to create a SlotLoad # - # Just like the SlotLoad stores two Slots, here we store two SlotMakers + # Just like the SlotLoad stores two Slots, here we store two Variables # class Assignment - # The two SlotMakers that become Slots in to_slot + # The two Variables that become Slots in to_slot attr_reader :left , :right def initialize(left , right) @left = left @right = right - raise "No Slot #{left}" unless left.is_a?(SlotMaker) - raise "No Slot #{right}" unless right.is_a?(SlotMaker) + raise "No Slot #{left}" unless left.is_a?(Variable) + raise "No Slot #{right}" unless right.is_a?(Variable) end - # create the SlotLoad, by creating the two Slots from the SlotMakers + # create the SlotLoad, by creating the two Slots from the Variables def to_slot(compiler) left_d = @left.to_slot(compiler) right_d = @right.to_slot(compiler) diff --git a/lib/slot_language/slot_compiler.rb b/lib/slot_language/slot_compiler.rb index bcd2ee77..03930091 100644 --- a/lib/slot_language/slot_compiler.rb +++ b/lib/slot_language/slot_compiler.rb @@ -35,17 +35,17 @@ module SlotLanguage return check(name,receiver, kids) if SlotCompiler.checks.include?(name) return assign(receiver, name , kids) if(name.to_s.end_with?("=")) puts "Send #{name} , #{receiver} kids=#{kids}" if DEBUG - SlotMaker.new( name ) + Variable.new( name ) end def on_lvar(lvar) puts "lvar #{lvar}" if DEBUG - SlotMaker.new(lvar.children.first ) + Variable.new(lvar.children.first ) end def on_lvasgn( expression) puts "lvasgn #{expression}" if DEBUG name = expression.children[0] value = process(expression.children[1]) - Assignment.new(SlotMaker.new(name),value) + Assignment.new(Variable.new(name),value) end alias :on_ivasgn :on_lvasgn @@ -64,7 +64,7 @@ module SlotLanguage end def on_ivar( expression) puts "ivar #{expression}" if DEBUG - SlotMaker.new(expression.children.first) + Variable.new(expression.children.first) end private @@ -105,7 +105,7 @@ module SlotLanguage end require_relative "named_slot" require_relative "message_slot" -require_relative "slot_maker" +require_relative "variable" require_relative "assignment" require_relative "macro_maker" require_relative "goto" diff --git a/lib/slot_language/slot_maker.rb b/lib/slot_language/variable.rb similarity index 80% rename from lib/slot_language/slot_maker.rb rename to lib/slot_language/variable.rb index 4d202443..c8fb9a51 100644 --- a/lib/slot_language/slot_maker.rb +++ b/lib/slot_language/variable.rb @@ -1,12 +1,12 @@ module SlotLanguage - # A SlotMaker makes Slots. A Slot s the central SlotMachines description of a - # variable in an object. This Language level "Maker" holds the information + # A Variable makes Slots. A Slot is the central SlotMachines description of a + # variable in an object. At the Language level this holds the information # (names of instance variables) to be able to create the Slot instance # # In the SlotLanguage this is used in the Assignment. Just as a Slotload stores # two slots to define what is loaded where, the Assignment, that creates a SlotLoad, - # uses two SlotMakers. - class SlotMaker + # uses two Variables. + class Variable # stores the (instance) names that allow us to create a Slot attr_reader :names diff --git a/test/slot_language/test_assignment.rb b/test/slot_language/test_assignment.rb index c6900b3a..16ed3200 100644 --- a/test/slot_language/test_assignment.rb +++ b/test/slot_language/test_assignment.rb @@ -35,7 +35,7 @@ module SlotLanguage load = compile("word = name.member") assert_equal Assignment , load.class assert_equal :word , load.left.names.first - assert_equal SlotMaker , load.right.class + assert_equal Variable , load.right.class end end end diff --git a/test/slot_language/test_equal_goto.rb b/test/slot_language/test_equal_goto.rb index ef088f2e..74cac7e9 100644 --- a/test/slot_language/test_equal_goto.rb +++ b/test/slot_language/test_equal_goto.rb @@ -7,8 +7,8 @@ module SlotLanguage def do_check(check) assert_equal EqualGoto , check.class assert_equal Goto , check.goto.class - assert_equal SlotMaker , check.left.class - assert_equal SlotMaker , check.right.class + assert_equal Variable , check.left.class + assert_equal Variable , check.right.class end def test_equal_local check = compile("goto(exit_label) if(a == b)") @@ -49,11 +49,11 @@ module SlotLanguage assert_equal @expr.first.object_id , @expr.last.goto.label.object_id end def test_expression_left - assert_equal SlotMaker , @expr.last.left.class + assert_equal Variable , @expr.last.left.class assert_equal [:b] , @expr.last.left.names end def test_expression_right - assert_equal SlotMaker , @expr.last.right.class + assert_equal Variable , @expr.last.right.class assert_equal [:c] , @expr.last.right.names end end diff --git a/test/slot_language/test_slot_compiler.rb b/test/slot_language/test_slot_compiler.rb index a10dcedd..11cf6e15 100644 --- a/test/slot_language/test_slot_compiler.rb +++ b/test/slot_language/test_slot_compiler.rb @@ -10,8 +10,8 @@ module SlotLanguage def test_labels assert SlotCompiler.new.labels.empty? end - def test_compile - assert_equal SlotMaker , compile("a").class + def test_basic_compile + assert_equal Variable , compile("a").class end end end diff --git a/test/slot_language/test_slot_maker.rb b/test/slot_language/test_slot_maker.rb deleted file mode 100644 index bd4193af..00000000 --- a/test/slot_language/test_slot_maker.rb +++ /dev/null @@ -1,14 +0,0 @@ -require_relative "helper" - -module SlotLanguage - class TestSlotMaker < MiniTest::Test - include SlotToHelper - def setup - super - @maker = SlotMaker.new(:hi ) - end - def test_slot - @maker.to_slot(@compiler) - end - end -end diff --git a/test/slot_language/test_variable.rb b/test/slot_language/test_variable.rb new file mode 100644 index 00000000..90f98db1 --- /dev/null +++ b/test/slot_language/test_variable.rb @@ -0,0 +1,10 @@ +require_relative "helper" + +module SlotLanguage + class TestVariable < MiniTest::Test + include SlotHelper + def test_basic_compile + assert_equal Variable , compile("a").class + end + end +end