Rename SlotMaker to Variable
Feels like now with better names, i can start to work.
This commit is contained in:
parent
c194d373fb
commit
6194148fc5
@ -2,20 +2,20 @@ module SlotLanguage
|
|||||||
# A Assignment makes SlotLoad. That means it stores the information
|
# A Assignment makes SlotLoad. That means it stores the information
|
||||||
# to be able to create a SlotLoad
|
# 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
|
class Assignment
|
||||||
# The two SlotMakers that become Slots in to_slot
|
# The two Variables that become Slots in to_slot
|
||||||
attr_reader :left , :right
|
attr_reader :left , :right
|
||||||
|
|
||||||
def initialize(left , right)
|
def initialize(left , right)
|
||||||
@left = left
|
@left = left
|
||||||
@right = right
|
@right = right
|
||||||
raise "No Slot #{left}" unless left.is_a?(SlotMaker)
|
raise "No Slot #{left}" unless left.is_a?(Variable)
|
||||||
raise "No Slot #{right}" unless right.is_a?(SlotMaker)
|
raise "No Slot #{right}" unless right.is_a?(Variable)
|
||||||
end
|
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)
|
def to_slot(compiler)
|
||||||
left_d = @left.to_slot(compiler)
|
left_d = @left.to_slot(compiler)
|
||||||
right_d = @right.to_slot(compiler)
|
right_d = @right.to_slot(compiler)
|
||||||
|
@ -35,17 +35,17 @@ module SlotLanguage
|
|||||||
return check(name,receiver, kids) if SlotCompiler.checks.include?(name)
|
return check(name,receiver, kids) if SlotCompiler.checks.include?(name)
|
||||||
return assign(receiver, name , kids) if(name.to_s.end_with?("="))
|
return assign(receiver, name , kids) if(name.to_s.end_with?("="))
|
||||||
puts "Send #{name} , #{receiver} kids=#{kids}" if DEBUG
|
puts "Send #{name} , #{receiver} kids=#{kids}" if DEBUG
|
||||||
SlotMaker.new( name )
|
Variable.new( name )
|
||||||
end
|
end
|
||||||
def on_lvar(lvar)
|
def on_lvar(lvar)
|
||||||
puts "lvar #{lvar}" if DEBUG
|
puts "lvar #{lvar}" if DEBUG
|
||||||
SlotMaker.new(lvar.children.first )
|
Variable.new(lvar.children.first )
|
||||||
end
|
end
|
||||||
def on_lvasgn( expression)
|
def on_lvasgn( expression)
|
||||||
puts "lvasgn #{expression}" if DEBUG
|
puts "lvasgn #{expression}" if DEBUG
|
||||||
name = expression.children[0]
|
name = expression.children[0]
|
||||||
value = process(expression.children[1])
|
value = process(expression.children[1])
|
||||||
Assignment.new(SlotMaker.new(name),value)
|
Assignment.new(Variable.new(name),value)
|
||||||
end
|
end
|
||||||
alias :on_ivasgn :on_lvasgn
|
alias :on_ivasgn :on_lvasgn
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ module SlotLanguage
|
|||||||
end
|
end
|
||||||
def on_ivar( expression)
|
def on_ivar( expression)
|
||||||
puts "ivar #{expression}" if DEBUG
|
puts "ivar #{expression}" if DEBUG
|
||||||
SlotMaker.new(expression.children.first)
|
Variable.new(expression.children.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -105,7 +105,7 @@ module SlotLanguage
|
|||||||
end
|
end
|
||||||
require_relative "named_slot"
|
require_relative "named_slot"
|
||||||
require_relative "message_slot"
|
require_relative "message_slot"
|
||||||
require_relative "slot_maker"
|
require_relative "variable"
|
||||||
require_relative "assignment"
|
require_relative "assignment"
|
||||||
require_relative "macro_maker"
|
require_relative "macro_maker"
|
||||||
require_relative "goto"
|
require_relative "goto"
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
module SlotLanguage
|
module SlotLanguage
|
||||||
# A SlotMaker makes Slots. A Slot s the central SlotMachines description of a
|
# A Variable makes Slots. A Slot is the central SlotMachines description of a
|
||||||
# variable in an object. This Language level "Maker" holds the information
|
# variable in an object. At the Language level this holds the information
|
||||||
# (names of instance variables) to be able to create the Slot instance
|
# (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
|
# 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,
|
# two slots to define what is loaded where, the Assignment, that creates a SlotLoad,
|
||||||
# uses two SlotMakers.
|
# uses two Variables.
|
||||||
class SlotMaker
|
class Variable
|
||||||
# stores the (instance) names that allow us to create a Slot
|
# stores the (instance) names that allow us to create a Slot
|
||||||
attr_reader :names
|
attr_reader :names
|
||||||
|
|
@ -35,7 +35,7 @@ module SlotLanguage
|
|||||||
load = compile("word = name.member")
|
load = compile("word = name.member")
|
||||||
assert_equal Assignment , load.class
|
assert_equal Assignment , load.class
|
||||||
assert_equal :word , load.left.names.first
|
assert_equal :word , load.left.names.first
|
||||||
assert_equal SlotMaker , load.right.class
|
assert_equal Variable , load.right.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,8 +7,8 @@ module SlotLanguage
|
|||||||
def do_check(check)
|
def do_check(check)
|
||||||
assert_equal EqualGoto , check.class
|
assert_equal EqualGoto , check.class
|
||||||
assert_equal Goto , check.goto.class
|
assert_equal Goto , check.goto.class
|
||||||
assert_equal SlotMaker , check.left.class
|
assert_equal Variable , check.left.class
|
||||||
assert_equal SlotMaker , check.right.class
|
assert_equal Variable , check.right.class
|
||||||
end
|
end
|
||||||
def test_equal_local
|
def test_equal_local
|
||||||
check = compile("goto(exit_label) if(a == b)")
|
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
|
assert_equal @expr.first.object_id , @expr.last.goto.label.object_id
|
||||||
end
|
end
|
||||||
def test_expression_left
|
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
|
assert_equal [:b] , @expr.last.left.names
|
||||||
end
|
end
|
||||||
def test_expression_right
|
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
|
assert_equal [:c] , @expr.last.right.names
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -10,8 +10,8 @@ module SlotLanguage
|
|||||||
def test_labels
|
def test_labels
|
||||||
assert SlotCompiler.new.labels.empty?
|
assert SlotCompiler.new.labels.empty?
|
||||||
end
|
end
|
||||||
def test_compile
|
def test_basic_compile
|
||||||
assert_equal SlotMaker , compile("a").class
|
assert_equal Variable , compile("a").class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -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
|
|
10
test/slot_language/test_variable.rb
Normal file
10
test/slot_language/test_variable.rb
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user