Rename SlotDefinition to Slot

And the derived XXDefinitions to XXSlot

Just to be more consistent
And possibly free the Definition for the Language side
This commit is contained in:
2020-02-11 16:19:52 +07:00
parent ec8794191d
commit 3c762c4fe7
45 changed files with 102 additions and 106 deletions

View File

@ -9,7 +9,7 @@ module Risc
super(source)
@register = register
@constant = constant
raise "Not Constant #{constant}" if constant.is_a?(SlotMachine::SlotDefinition)
raise "Not Constant #{constant}" if constant.is_a?(SlotMachine::Slot)
raise "Not register #{register}" unless RegisterValue.look_like_reg(register)
end
attr_accessor :register , :constant

View File

@ -18,7 +18,7 @@ module SlotLanguage
end
def slot_def(compiler)
SlotMachine::SlotDefinition.for(:message , leaps)
SlotMachine::Slot.for(:message , leaps)
end
def to_s

View File

@ -25,7 +25,7 @@ module SlotMachine
def initialize( source , receiver,arguments )
super(source)
@receiver , @arguments = receiver , arguments
raise "Receiver not SlotDefinition #{@receiver}" unless @receiver.is_a?(SlotDefinition)
raise "Receiver not Slot #{@receiver}" unless @receiver.is_a?(Slot)
@arguments.each{|a| raise "args not SlotLoad #{a}" unless a.is_a?(SlotLoad)}
end

View File

@ -1,14 +1,14 @@
module SlotMachine
class ConstantDefinition < SlotDefinition
class ConstantSlot < Slot
# get the right definition, depending on the object
def self.for(object , slots)
case object
when :message
MessageDefinition.new(slots)
MessageSlot.new(slots)
when Constant
ConstantDefinition.new(object , slots)
ConstantSlot.new(object , slots)
else
SlotDefinition.new(object,slots)
Slot.new(object,slots)
end
end

View File

@ -1,5 +1,5 @@
module SlotMachine
class MessageDefinition < SlotDefinition
class MessageSlot < Slot
def initialize(slots)
super(:message , slots)

View File

@ -3,7 +3,7 @@ module SlotMachine
# SlotMachine internal check, as the name says to see if two values are not the same
# In other words, we this checks identity, bit-values, pointers
#
# The values that are compared are defined as SlotDefinitions, ie can be anything
# The values that are compared are defined as Slots, ie can be anything
# available to the machine through frame message or self
#
# Acording to SlotMachine::Check logic, we jump to the given label is the values are the same

View File

@ -1,5 +1,5 @@
module SlotMachine
class ObjectDefinition < SlotDefinition
class ObjectSlot < Slot
def initialize( object , slots)
super(object , slots )

View File

@ -1,11 +1,11 @@
module SlotMachine
# A SlotDefinition defines a slot. A bit like a variable name but for objects.
# A Slot defines a slot. A bit like a variable name but for objects.
#
# PS: for the interested: A "development" of Smalltalk was the
# prototype based language (read: JavaScript equivalent)
# called Self https://en.wikipedia.org/wiki/Self_(programming_language)
#
# SlotDefinitions are the instance names of objects. But since the language is dynamic
# Slots are the instance names of objects. But since the language is dynamic
# what is it that we can say about instance names at runtime?
# Start with a known object like the Message (in register one), we know all it's
# variables. But there is a Message in there, and for that we know the instances
@ -14,16 +14,16 @@ module SlotMachine
# The definiion is an array of symbols that we can resolve to SlotLoad
# Instructions. Or in the case of constants to ConstantLoad
#
class SlotDefinition
class Slot
# get the right definition, depending on the object
def self.for(object , slots)
case object
when :message
MessageDefinition.new(slots)
MessageSlot.new(slots)
when Constant
ConstantDefinition.new(object , slots)
ConstantSlot.new(object , slots)
when Parfait::Object , Risc::Label
ObjectDefinition.new(object , slots)
ObjectSlot.new(object , slots)
else
raise "not supported type #{object}"
end

View File

@ -4,9 +4,9 @@ module SlotMachine
# A Slot is basically an instance variable, but it must be of known type
#
# The value loaded (the right hand side) can be a constant (SlotMachine::Constant) or come from
# another Slot (SlotDefinition)
# another Slot (Slot)
#
# The Slot on the left hand side is always a SlotDefinition.
# The Slot on the left hand side is always a Slot.
# The only known object (*) for the left side is the current message, which is a bit like
# the oo version of a Stack (Stack Register, Frame Pointer, ..)
# (* off course all class objects are global, and so they are allowed too)
@ -18,10 +18,10 @@ module SlotMachine
# From the outside a send is neccessary, both for get and set, (which goes through the method
# resolution and guarantees the correct method for a type), in other words perfect data hiding.
#
# @left: A SlotDefinition, or an array that can be passed to the constructor of the
# SlotDefinition (see there)
# @left: A Slot, or an array that can be passed to the constructor of the
# Slot (see there)
#
# @right: A SlotDefinition with slots or a SlotMachine::Constant
# @right: A Slot with slots or a SlotMachine::Constant
# original_source: optinally another slot_machine instruction that will be passed down
# to created risc instructions. (Because SlotLoad is often used internally)
class SlotLoad < Instruction
@ -31,10 +31,10 @@ module SlotMachine
def initialize(source , left , right, original_source = nil)
super(source)
@left , @right = left , right
@left = SlotDefinition.for(@left.shift , @left) if @left.is_a? Array
@right = SlotDefinition.for(@right.shift , @right) if @right.is_a? Array
raise "right not SlotMachine, #{@right.to_s}" unless @right.is_a?( SlotDefinition )
raise "left not SlotMachine, #{@left.to_s}" unless @left.is_a?( SlotDefinition )
@left = Slot.for(@left.shift , @left) if @left.is_a? Array
@right = Slot.for(@right.shift , @right) if @right.is_a? Array
raise "right not SlotMachine, #{@right.to_s}" unless @right.is_a?( Slot )
raise "left not SlotMachine, #{@left.to_s}" unless @left.is_a?( Slot )
@original_source = original_source || self
end
@ -54,7 +54,7 @@ module SlotMachine
end
end
require_relative "slot_definition"
require_relative "message_definition"
require_relative "constant_definition"
require_relative "object_definition"
require_relative "slot"
require_relative "message_slot"
require_relative "constant_slot"
require_relative "object_slot"

View File

@ -11,7 +11,7 @@ module SlotMachine
def initialize(condition , false_jump)
super(false_jump)
@condition = condition
raise "condition must be slot_definition #{condition}" unless condition.is_a?(SlotDefinition)
raise "condition must be slot_definition #{condition}" unless condition.is_a?(Slot)
end
def to_s

View File

@ -32,7 +32,7 @@ module Sol
#
# Derived classes do not implement to_slot, only slot_position
def to_slot(compiler)
to = SlotMachine::SlotDefinition.for(:message , self.slot_position(compiler))
to = SlotMachine::Slot.for(:message , self.slot_position(compiler))
from = @value.to_slot_definition(compiler)
assign = SlotMachine::SlotLoad.new(self,to,from)
return assign unless @value.is_a?(CallStatement)

View File

@ -10,7 +10,7 @@ module Sol
@value = value
end
def to_slot_definition(_)
return SlotMachine::SlotDefinition.for(SlotMachine::IntegerConstant.new(@value) , [])
return SlotMachine::Slot.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_slot_definition(_)
return SlotMachine::SlotDefinition.for(Parfait.object_space.true_object , [])
return SlotMachine::Slot.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_slot_definition(_)
return SlotMachine::SlotDefinition.for(Parfait.object_space.false_object , [])
return SlotMachine::Slot.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_slot_definition(_)
return SlotMachine::SlotDefinition.for(Parfait.object_space.nil_object , [])
return SlotMachine::Slot.for(Parfait.object_space.nil_object , [])
end
def to_s(depth = 0)
"nil"
@ -77,7 +77,7 @@ module Sol
end
def to_slot_definition(compiler)
@my_type = compiler.receiver_type
SlotMachine::SlotDefinition.for(:message , [:receiver])
SlotMachine::Slot.for(:message , [:receiver])
end
def ct_type
@my_type
@ -92,7 +92,7 @@ module Sol
@value = value
end
def to_slot_definition(_)
return SlotMachine::SlotDefinition.for(SlotMachine::StringConstant.new(@value),[])
return SlotMachine::Slot.for(SlotMachine::StringConstant.new(@value),[])
end
def ct_type
Parfait.object_space.get_type_by_class_name(:Word)

View File

@ -11,7 +11,7 @@ module Sol
# When used as right hand side, this tells what data to move to get the result into
# a varaible. It is (off course) the return value of the message
def to_slot_definition(_)
SlotMachine::SlotDefinition.for(:message ,[ :return_value])
SlotMachine::Slot.for(:message ,[ :return_value])
end
def to_s(depth = 0)

View File

@ -15,7 +15,7 @@ module Sol
# fact never called)
def to_slot_definition(compiler)
compile(compiler) unless @parfait_block
return SlotMachine::SlotDefinition.for(SlotMachine::LambdaConstant.new(parfait_block(compiler)) , [])
return SlotMachine::Slot.for(SlotMachine::LambdaConstant.new(parfait_block(compiler)) , [])
end
# create a block, a compiler for it, compile the block and add the compiler(code)

View File

@ -15,7 +15,7 @@ module Sol
# When used as right hand side, this tells what data to move to get the result into
# a varaible. It is (off course) the return value of the message
def to_slot_definition(_)
SlotMachine::SlotDefinition.for(:message ,[ :return_value])
SlotMachine::Slot.for(:message ,[ :return_value])
end
def to_s(depth = 0)

View File

@ -116,7 +116,7 @@ module Sol
defi
end
def build_condition(ok_label, compiler)
cached_type = SlotMachine::SlotDefinition.for(dynamic_call.cache_entry , [:cached_type])
cached_type = SlotMachine::Slot.for(dynamic_call.cache_entry , [:cached_type])
current_type = receiver_type_definition(compiler)
SlotMachine::NotSameCheck.new(cached_type , current_type, ok_label)
end

View File

@ -12,7 +12,7 @@ module Sol
include Named
def to_slot_definition(compiler)
slot_def = compiler.slot_type_for(@name)
SlotMachine::SlotDefinition.for(:message , slot_def)
SlotMachine::Slot.for(:message , slot_def)
end
def to_s(depth = 0)
name.to_s
@ -25,7 +25,7 @@ module Sol
class InstanceVariable < Expression
include Named
def to_slot_definition(_)
SlotMachine::SlotDefinition.for(:message , [ :receiver , @name] )
SlotMachine::Slot.for(:message , [ :receiver , @name] )
end
# used to collect type information
def add_ivar( array )
@ -52,7 +52,7 @@ module Sol
get_named_class.single_class.instance_type
end
def to_slot_definition(_)
return SlotMachine::SlotDefinition.for( get_named_class, [])
return SlotMachine::Slot.for( get_named_class, [])
end
def get_named_class
Parfait.object_space.get_class_by_name(self.name)

View File

@ -34,8 +34,8 @@ 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::SlotDefinition.for( compiler.get_method , [])
runtime_method = SlotMachine::SlotDefinition.for( :message , [ :method] )
compile_method = SlotMachine::Slot.for( compiler.get_method , [])
runtime_method = SlotMachine::Slot.for( :message , [ :method] )
check = SlotMachine::NotSameCheck.new(compile_method , runtime_method, ok_label)
# TODO? Maybe create slot instructions for this
#builder = compiler.builder("yield")