Slotted constructor cleanup
This commit is contained in:
parent
c1679bd6ff
commit
2d11078a37
@ -26,7 +26,7 @@ module SlotLanguage
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_slot(compiler)
|
def to_slot(compiler)
|
||||||
SlotMachine::Slotted.for(:message , name)
|
SlotMachine::Slotted.for(:message , [name])
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
@ -2,7 +2,7 @@ module SlotMachine
|
|||||||
|
|
||||||
class Slotted
|
class Slotted
|
||||||
|
|
||||||
def self.for(object , slots)
|
def self.for(object , slots = nil)
|
||||||
case object
|
case object
|
||||||
when :message
|
when :message
|
||||||
SlottedMessage.new(slots)
|
SlottedMessage.new(slots)
|
||||||
@ -19,11 +19,11 @@ module SlotMachine
|
|||||||
# previous object
|
# previous object
|
||||||
attr_reader :slots
|
attr_reader :slots
|
||||||
|
|
||||||
def initialize( slots )
|
def initialize( slots = nil )
|
||||||
raise "No slots #{object}" unless slots
|
return unless slots
|
||||||
slots = [slots] unless slots.is_a?(Array)
|
raise "stopped" unless slots.is_a?(Array)
|
||||||
first = slots.shift
|
first = slots.shift
|
||||||
return unless first
|
raise "ended" unless first
|
||||||
@slots = Slot.new(first)
|
@slots = Slot.new(first)
|
||||||
until(slots.empty?)
|
until(slots.empty?)
|
||||||
@slots.set_next( Slot.new( slots.shift ))
|
@slots.set_next( Slot.new( slots.shift ))
|
||||||
|
@ -6,6 +6,10 @@ module SlotMachine
|
|||||||
end
|
end
|
||||||
alias :known_object :known_name
|
alias :known_object :known_name
|
||||||
|
|
||||||
|
def initialize(slots)
|
||||||
|
super(slots)
|
||||||
|
raise "Message must have slots, but none given" unless slots
|
||||||
|
end
|
||||||
# load the slots into a register
|
# load the slots into a register
|
||||||
# the code is added to compiler
|
# the code is added to compiler
|
||||||
# the register returned
|
# the register returned
|
||||||
|
@ -10,7 +10,7 @@ module Sol
|
|||||||
@value = value
|
@value = value
|
||||||
end
|
end
|
||||||
def to_slotted(_)
|
def to_slotted(_)
|
||||||
return SlotMachine::Slotted.for(SlotMachine::IntegerConstant.new(@value) , [])
|
return SlotMachine::Slotted.for(SlotMachine::IntegerConstant.new(@value) )
|
||||||
end
|
end
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_type_by_class_name(:Integer)
|
Parfait.object_space.get_type_by_class_name(:Integer)
|
||||||
@ -38,7 +38,7 @@ module Sol
|
|||||||
Parfait.object_space.get_type_by_class_name(:True)
|
Parfait.object_space.get_type_by_class_name(:True)
|
||||||
end
|
end
|
||||||
def to_slotted(_)
|
def to_slotted(_)
|
||||||
return SlotMachine::Slotted.for(Parfait.object_space.true_object , [])
|
return SlotMachine::Slotted.for(Parfait.object_space.true_object )
|
||||||
end
|
end
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
"true"
|
"true"
|
||||||
@ -50,7 +50,7 @@ module Sol
|
|||||||
Parfait.object_space.get_type_by_class_name(:False)
|
Parfait.object_space.get_type_by_class_name(:False)
|
||||||
end
|
end
|
||||||
def to_slotted(_)
|
def to_slotted(_)
|
||||||
return SlotMachine::Slotted.for(Parfait.object_space.false_object , [])
|
return SlotMachine::Slotted.for(Parfait.object_space.false_object )
|
||||||
end
|
end
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
"false"
|
"false"
|
||||||
@ -62,7 +62,7 @@ module Sol
|
|||||||
Parfait.object_space.get_type_by_class_name(:Nil)
|
Parfait.object_space.get_type_by_class_name(:Nil)
|
||||||
end
|
end
|
||||||
def to_slotted(_)
|
def to_slotted(_)
|
||||||
return SlotMachine::Slotted.for(Parfait.object_space.nil_object , [])
|
return SlotMachine::Slotted.for(Parfait.object_space.nil_object )
|
||||||
end
|
end
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
"nil"
|
"nil"
|
||||||
@ -92,7 +92,7 @@ module Sol
|
|||||||
@value = value
|
@value = value
|
||||||
end
|
end
|
||||||
def to_slotted(_)
|
def to_slotted(_)
|
||||||
return SlotMachine::Slotted.for(SlotMachine::StringConstant.new(@value),[])
|
return SlotMachine::Slotted.for(SlotMachine::StringConstant.new(@value))
|
||||||
end
|
end
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_type_by_class_name(:Word)
|
Parfait.object_space.get_type_by_class_name(:Word)
|
||||||
|
@ -15,7 +15,7 @@ module Sol
|
|||||||
# fact never called)
|
# fact never called)
|
||||||
def to_slotted(compiler)
|
def to_slotted(compiler)
|
||||||
compile(compiler) unless @parfait_block
|
compile(compiler) unless @parfait_block
|
||||||
return SlotMachine::Slotted.for(SlotMachine::LambdaConstant.new(parfait_block(compiler)) , [])
|
return SlotMachine::Slotted.for(SlotMachine::LambdaConstant.new(parfait_block(compiler)) )
|
||||||
end
|
end
|
||||||
|
|
||||||
# create a block, a compiler for it, compile the block and add the compiler(code)
|
# create a block, a compiler for it, compile the block and add the compiler(code)
|
||||||
|
@ -52,7 +52,7 @@ module Sol
|
|||||||
get_named_class.single_class.instance_type
|
get_named_class.single_class.instance_type
|
||||||
end
|
end
|
||||||
def to_slotted(_)
|
def to_slotted(_)
|
||||||
return SlotMachine::Slotted.for( get_named_class, [])
|
return SlotMachine::Slotted.for( get_named_class)
|
||||||
end
|
end
|
||||||
def get_named_class
|
def get_named_class
|
||||||
Parfait.object_space.get_class_by_name(self.name)
|
Parfait.object_space.get_class_by_name(self.name)
|
||||||
|
@ -34,7 +34,7 @@ module Sol
|
|||||||
# we brace ourselves with the check, and exit (later raise) if . . .
|
# we brace ourselves with the check, and exit (later raise) if . . .
|
||||||
def method_check(compiler)
|
def method_check(compiler)
|
||||||
ok_label = SlotMachine::Label.new(self,"method_ok_#{self.object_id}")
|
ok_label = SlotMachine::Label.new(self,"method_ok_#{self.object_id}")
|
||||||
compile_method = SlotMachine::Slotted.for( compiler.get_method , [])
|
compile_method = SlotMachine::Slotted.for( compiler.get_method )
|
||||||
runtime_method = SlotMachine::Slotted.for( :message , [ :method] )
|
runtime_method = SlotMachine::Slotted.for( :message , [ :method] )
|
||||||
check = SlotMachine::NotSameCheck.new(compile_method , runtime_method, ok_label)
|
check = SlotMachine::NotSameCheck.new(compile_method , runtime_method, ok_label)
|
||||||
# TODO? Maybe create slot instructions for this
|
# TODO? Maybe create slot instructions for this
|
||||||
|
@ -3,7 +3,7 @@ require_relative "helper"
|
|||||||
module SlotMachine
|
module SlotMachine
|
||||||
class TestNotSameCheck < SlotMachineInstructionTest
|
class TestNotSameCheck < SlotMachineInstructionTest
|
||||||
def instruction
|
def instruction
|
||||||
target = Slotted.for(:message , :caller)
|
target = Slotted.for(:message , [:caller])
|
||||||
NotSameCheck.new(target , target , Label.new("ok" , "target"))
|
NotSameCheck.new(target , target , Label.new("ok" , "target"))
|
||||||
end
|
end
|
||||||
def test_len
|
def test_len
|
||||||
|
@ -3,7 +3,7 @@ require_relative "helper"
|
|||||||
module SlotMachine
|
module SlotMachine
|
||||||
class TestSameCheck < SlotMachineInstructionTest
|
class TestSameCheck < SlotMachineInstructionTest
|
||||||
def instruction
|
def instruction
|
||||||
target = SlottedMessage.new( :caller)
|
target = SlottedMessage.new( [:caller])
|
||||||
TruthCheck.new(target , Label.new("ok" , "target"))
|
TruthCheck.new(target , Label.new("ok" , "target"))
|
||||||
end
|
end
|
||||||
def test_len
|
def test_len
|
||||||
|
@ -3,13 +3,13 @@ require_relative "helper"
|
|||||||
module SlotMachine
|
module SlotMachine
|
||||||
class TestSlotted < MiniTest::Test
|
class TestSlotted < MiniTest::Test
|
||||||
def test_to_s
|
def test_to_s
|
||||||
assert_equal "message.caller" , SlottedMessage.new(:caller).to_s
|
assert_equal "message.caller" , SlottedMessage.new([:caller]).to_s
|
||||||
end
|
end
|
||||||
def test_for_mess
|
def test_for_mess
|
||||||
assert_equal 2 , SlottedMessage.new(:caller).slots_length
|
assert_equal 2 , SlottedMessage.new([:caller]).slots_length
|
||||||
end
|
end
|
||||||
def test_for_const
|
def test_for_const
|
||||||
slotted = Slotted.for(StringConstant.new("hi") , [])
|
slotted = Slotted.for(StringConstant.new("hi") , nil)
|
||||||
assert_equal "StringConstant" , slotted.to_s
|
assert_equal "StringConstant" , slotted.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ module SlotMachine
|
|||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
compiler = Risc::FakeCompiler.new
|
compiler = Risc::FakeCompiler.new
|
||||||
@slotted = Slotted.for(StringConstant.new("hi") , [])
|
@slotted = Slotted.for(StringConstant.new("hi") , nil)
|
||||||
register = @slotted.to_register(compiler , InstructionMock.new)
|
register = @slotted.to_register(compiler , InstructionMock.new)
|
||||||
@instruction = compiler.instructions.first
|
@instruction = compiler.instructions.first
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@ require_relative "helper"
|
|||||||
module SlotMachine
|
module SlotMachine
|
||||||
class TestSlottedMessage < MiniTest::Test
|
class TestSlottedMessage < MiniTest::Test
|
||||||
|
|
||||||
def slotted(slot = :caller)
|
def slotted(slot = [:caller])
|
||||||
SlottedMessage.new(slot)
|
SlottedMessage.new(slot)
|
||||||
end
|
end
|
||||||
def test_create_ok1
|
def test_create_ok1
|
||||||
|
@ -5,7 +5,7 @@ module SlotMachine
|
|||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
compiler = Risc::FakeCompiler.new
|
compiler = Risc::FakeCompiler.new
|
||||||
slotted = SlottedMessage.new(:caller)
|
slotted = SlottedMessage.new([:caller])
|
||||||
@register = slotted.to_register(compiler , "fake source")
|
@register = slotted.to_register(compiler , "fake source")
|
||||||
@instruction = compiler.instructions.first
|
@instruction = compiler.instructions.first
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user