More rename cleanp

This commit is contained in:
2019-10-03 21:07:55 +03:00
parent c43436f35a
commit aa9fc8bc81
57 changed files with 130 additions and 140 deletions

View File

@ -1,4 +1,4 @@
# SlotMachine , Minimal Object Machine
# SlotMachine
This layer sits between the language layer (vool) and the risc machine layer.
It is meant to make the transition (between vool and risc) easier to understand.
@ -48,7 +48,7 @@ no registers (one could see the current message as the only register)
### Instruction based
So mom is a machine layer, rather than a language.
So SlotMachine is a machine layer, rather than a language.
No control structures, but compare and jump instructions.
No send or call, just objects and jump.

View File

@ -1,10 +1,10 @@
module Mom
module SlotMachine
# A BlockCompiler is much like a MehtodCompiler, exept for blocks
#
class BlockCompiler < CallableCompiler
attr_reader :block , :mom_instructions
attr_reader :block , :slot_instructions
alias :block :callable
def initialize( block , method)
@ -17,7 +17,7 @@ module Mom
end
def to_risc
risc_compiler = Risc::BlockCompiler.new(@callable , @method , mom_instructions)
risc_compiler = Risc::BlockCompiler.new(@callable , @method , slot_instructions)
instructions_to_risc(risc_compiler)
#recursive blocks not done
risc_compiler

View File

@ -1,9 +1,9 @@
module Mom
module SlotMachine
# CallableCompiler is used to generate mom instructions. It is an abstact base
# CallableCompiler is used to generate slot instructions. It is an abstact base
# class shared by BlockCompiler and MethodCompiler
# - mom_instructions: The sequence of mom level instructions that mom was compiled to
# - slot_instructions: The sequence of slot level instructions that was compiled to
# Instructions derive from class Instruction and form a linked list
class CallableCompiler
@ -12,17 +12,17 @@ module Mom
def initialize( callable )
@callable = callable
@constants = []
@mom_instructions = Label.new(source_name, source_name)
@current = start = @mom_instructions
@slot_instructions = Label.new(source_name, source_name)
@current = start = @slot_instructions
add_code Label.new( source_name, "return_label")
add_code Mom::ReturnSequence.new(source_name)
add_code SlotMachine::ReturnSequence.new(source_name)
add_code Label.new( source_name, "unreachable")
@current = start
end
attr_reader :mom_instructions , :constants , :callable , :current
attr_reader :slot_instructions , :constants , :callable , :current
def return_label
@mom_instructions.each do |ins|
@slot_instructions.each do |ins|
next unless ins.is_a?(Label)
return ins if ins.name == "return_label"
end
@ -43,7 +43,7 @@ module Mom
# add a risc instruction after the current (insertion point)
# the added instruction will become the new insertion point
def add_code( instruction )
raise "Not an instruction:#{instruction.to_s}:#{instruction.class.name}" unless instruction.is_a?(Mom::Instruction)
raise "Not an instruction:#{instruction.to_s}:#{instruction.class.name}" unless instruction.is_a?(SlotMachine::Instruction)
new_current = instruction.last #after insertion this point is lost
@current.insert(instruction) #insert after current
@current = new_current
@ -60,10 +60,10 @@ module Mom
# convert al instruction to risc
# method is called by Method/BlockCompiler from to_risc
def instructions_to_risc(risc_compiler)
instruction = mom_instructions.next
instruction = slot_instructions.next
while( instruction )
raise "whats this a #{instruction}" unless instruction.is_a?(Mom::Instruction)
#puts "adding mom #{instruction.to_s}:#{instruction.next.to_s}"
raise "whats this a #{instruction}" unless instruction.is_a?(SlotMachine::Instruction)
#puts "adding slot #{instruction.to_s}:#{instruction.next.to_s}"
risc_compiler.reset_regs
instruction.to_risc( risc_compiler )
#puts "adding risc #{risc.to_s}:#{risc.next.to_s}"

View File

@ -1,14 +1,14 @@
module Mom
module SlotMachine
# Base class for MOM instructions
# Base class for SlotMachine instructions
# At the base class level instructions are a linked list.
#
# Mom::Instructions are created by the Vool level as an intermediate step
# SlotMachine::Instructions are created by the Vool level as an intermediate step
# towards the next level down, the Risc level.
# Mom and Risc are both abstract machines (ie have instructions), so both
# SlotMachine and Risc are both abstract machines (ie have instructions), so both
# share the linked list functionality (In Util::List)
#
# To convert a Mom instruction to it's Risc equivalent to_risc is called
# To convert a SlotMachine instruction to it's Risc equivalent to_risc is called
#
class Instruction
include Util::List
@ -26,7 +26,7 @@ module Mom
# to_risc, like the name says, converts the instruction to it's Risc equivalent.
# The Risc machine is basically a simple register machine (kind of arm).
# In other words Mom is the higher abstraction and so mom instructions convert
# In other words SlotMachine is the higher abstraction and so slot instructions convert
# to many (1-10) risc instructions
#
# The argument that is passed is a MethodCompiler, which has the method and some

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
# Transering the arguments from the current frame into the next frame
#

View File

@ -1,5 +1,5 @@
module Mom
# just name scoping the same stuff to mom
module SlotMachine
# just name scoping the same stuff to slot
# so we know we are on the way down, keeping our layers seperated
# and we can put constant adding into the to_risc methods (instead of on vool classes)
class Constant

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
# A BlockYield calls an argument block. All we need to know is the index
# of the argument, and the rest is almost as simple as a SimpleCall

View File

@ -1,6 +1,6 @@
module Mom
module SlotMachine
# A base class for conditions in MOM
# A base class for conditions in SlotMachine
# Checks (if in code, compare in assm) jump or not, depending
# The logic we choose is closer to the code logic (the asm is reversed)
# When we write an if, the true is the next code, so the Check logic is
@ -9,7 +9,7 @@ module Mom
# check does not pass
# Note: In assembler a branch on 0 does just that, it branches if the condition
# is met. This means that the asm implementation is somewhat the reverse
# of the Mom names. But it's easier to understand (imho)
# of the SlotMachine names. But it's easier to understand (imho)
class Check < Instruction
attr_reader :false_jump
def initialize(false_jump)

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
# A dynamic call calls a method at runtime. This off course implies that we don't know the
# method at compile time and so must "find" it. Resolving, or finding the method, is a

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
# Branch jump to the Label given
# Eg used at the end of while or end of if_true branch

View File

@ -1,6 +1,6 @@
module Mom
module SlotMachine
# A Label is the only legal target for a branch (in Mom, in Risc a BinaryCode is ok too)
# A Label is the only legal target for a branch (in SlotMachine, in Risc a BinaryCode is ok too)
#
# In the dynamic view (runtime) where the instructions form a graph,
# branches fan out, Labels collect. In other words a branch is the place where
@ -8,7 +8,7 @@ module Mom
#
# A Label has a name which is mainly used for debugging.
#
# A Mom::Label converts one2one to a Risc::Label. So in a way it could not be more
# A SlotMachine::Label converts one2one to a Risc::Label. So in a way it could not be more
# simple.
# Alas, since almost by definition several roads lead to this label, all those
# several converted instructions must also point to the identical label on the

View File

@ -1,6 +1,6 @@
module Mom
module SlotMachine
# As reminder: a statically resolved call (the simplest one) becomes three Mom Instructions.
# As reminder: a statically resolved call (the simplest one) becomes three SlotMachine Instructions.
# Ie: MessageSetup,ArgumentTransfer,SimpleCall
#
# MessageSetup does Setup before a call can be made, acquiring and filling the message

View File

@ -1,12 +1,12 @@
module Mom
module SlotMachine
# Mom internal check, as the name says to see if two values are not the same
# 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
# available to the machine through frame message or self
#
# Acording to Mom::Check logic, we jump to the given label is the values are the same
# Acording to SlotMachine::Check logic, we jump to the given label is the values are the same
#
class NotSameCheck < Check
attr_reader :left , :right

View File

@ -1,7 +1,7 @@
module Mom
module SlotMachine
# Dynamic method resolution is at the heart of a dynamic language, and here
# is the Mom level instruction to do it.
# is the SlotMachine level instruction to do it.
#
# When the static type can not be determined a CacheEntry is used to store
# type and method of the resolved method. The CacheEntry is shared with

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
# the return jump jumps to the return label
# the method setup is such that there is exactly one return_label in a method

View File

@ -1,11 +1,11 @@
module Mom
module SlotMachine
# The ReturnSequence models the return from a method.
#
# This involves the jump to the return address stored in the message, and
# the reinstantiation of the previous message.
#
# The machine (mom) only ever "knows" one message, the current message.
# The (slot) machine only ever "knows" one message, the current message.
# Messages are a double linked list, calling involves going forward,
# returning means going back.
#

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
# A SimpleCall is just that, a simple call. This could be called a function call too,
# meaning we managed to resolve the function at compile time and all we have to do is

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
# A SlotDefinition defines a slot. A bit like a variable name but for objects.
#
# PS: for the interested: A "developement" of Smalltalk was the

View File

@ -1,9 +1,9 @@
module Mom
module SlotMachine
# SlotLoad is for moving data into a slot, either from another slot, or constant
# 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 (Mom::Constant) or come from
# The value loaded (the right hand side) can be a constant (SlotMachine::Constant) or come from
# another Slot (SlotDefinition)
#
# The Slot on the left hand side is always a SlotDefinition.
@ -21,9 +21,9 @@ module Mom
# @left: A SlotDefinition, or an array that can be passed to the constructor of the
# SlotDefinition (see there)
#
# @right: A SlotDefinition with slots or a Mom::Constant
# original_source: optinally another mom instruction that will be passed down to created
# risc instructions. (Because SlotLoad is often used internally in mom)
# @right: A SlotDefinition 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
attr_reader :left , :right , :original_source
@ -33,7 +33,7 @@ module Mom
@left , @right = left , right
@left = SlotDefinition.new(@left.shift , @left) if @left.is_a? Array
@right = SlotDefinition.new(@right.shift , @right) if @right.is_a? Array
raise "right not Mom, #{@right.to_s}" unless @right.is_a?( SlotDefinition )
raise "right not SlotMachine, #{@right.to_s}" unless @right.is_a?( SlotDefinition )
@original_source = original_source || self
end

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
# The funny thing about the ruby truth is that it is anything but false or nil
#

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
class Comparison < Macro
attr_reader :operator
def initialize(name , operator)

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
class Div10 < Macro
def to_risc(compiler)
s = "div_10 "

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
class Div4 < Macro
def to_risc(compiler)
builder = compiler.builder(compiler.source)

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
class Exit < Macro
def to_risc(compiler)
builder = compiler.builder(compiler.source)

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
class GetInternalByte < Macro
def to_risc(compiler)
builder = compiler.builder(compiler.source)

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
class GetInternalWord < Macro
def to_risc(compiler)
compiler.builder(compiler.source).build do

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
# Init "method" is the first thing that happens in the machine
# There is an inital jump to it, but that's it, no setup, no nothing
#
@ -20,7 +20,7 @@ module Mom
end
builder.reset_names
# Set up the call to main, with space as receiver
Mom::MessageSetup.new(main).build_with( builder )
SlotMachine::MessageSetup.new(main).build_with( builder )
builder.build do
message << message[:next_message]
space? << Parfait.object_space

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
class Macro < Instruction
def to_s

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
class MethodMissing < Macro
attr_reader :name

View File

@ -1,3 +1,3 @@
module Mom
module SlotMachine
end

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
class IntOperator < Macro
attr_reader :operator
def initialize(name , operator)

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
class Putstring < Macro
def to_risc(compiler)
builder = compiler.builder(compiler.source)
@ -7,7 +7,7 @@ module Mom
word! << message[:receiver]
integer! << word[Parfait::Word.get_length_index]
end
Mom::Macro.emit_syscall( builder , :putstring )
SlotMachine::Macro.emit_syscall( builder , :putstring )
compiler
end
end

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
class SetInternalByte < Macro
def to_risc(compiler)
compiler.builder(compiler.source).build do

View File

@ -1,4 +1,4 @@
module Mom
module SlotMachine
class SetInternalWord < Macro
def to_risc(compiler)
compiler.builder(compiler.source).build do

View File

@ -1,6 +1,6 @@
module Mom
module SlotMachine
# MethodCompiler is used to generate Mom instructions for methods
# MethodCompiler is used to generate SlotMachine instructions for methods
# and to instantiate the methods correctly.
class MethodCompiler < CallableCompiler
@ -25,7 +25,7 @@ module Mom
# drop down to risc by converting this compilers instructions to risc.
# and the doing the same for any block_compilers
def to_risc
risc_compiler = Risc::MethodCompiler.new(@callable , mom_instructions)
risc_compiler = Risc::MethodCompiler.new(@callable , slot_instructions)
instructions_to_risc(risc_compiler)
risc_compiler
end
@ -83,8 +83,8 @@ module Mom
# Only for init, as init has no return
# kind of private
def _reset_for_init
@mom_instructions = Label.new(source_name, source_name)
@current = @mom_instructions
@slot_instructions = Label.new(source_name, source_name)
@current = @slot_instructions
end
end

View File

@ -3,7 +3,7 @@ module SlotMachine
# compilers These will transform to Risc MethodCompilers on the way down.
#
# As RubyCompiler pools source at the vool level, when several classes are compiled
# from vool to mom, several SlotMachineCompilers get instantiated. They must be merged before
# from vool to slot, several SlotMachineCompilers get instantiated. They must be merged before
# proceeding with translate. Thus we have a append method.
#
class SlotCollection
@ -49,8 +49,8 @@ module SlotMachine
def to_risc( )
init_compilers
riscs =[]
@method_compilers.each_compiler do | mom_c |
riscs << mom_c.to_risc
@method_compilers.each_compiler do | slot_c |
riscs << slot_c.to_risc
end
# to_risc all compilers
# for each suffling constnts and fist label, then all instructions (see below)