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