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

@ -3,7 +3,8 @@ module Risc
# CallableCompiler is used to generate risc instructions. It is an abstact base
# class shared by BlockCompiler and MethodCompiler
# - risc_instructions: The sequence of risc level instructions that mom was compiled to
# - risc_instructions: The sequence of risc level instructions that slot machine was
# compiled to
# Instructions derive from class Instruction and form a linked list
# - constants is an array of Parfait objects that need to be available
# - callable is a Method of Block

View File

@ -5,8 +5,8 @@ module Risc
class MethodCompiler < CallableCompiler
# Methods starts with a Label, both in risc and mom.
# Pass in the callable(method) and the mom label that the method starts with
# Methods starts with a Label, both in risc and slot.
# Pass in the callable(method) and the slot label that the method starts with
def initialize( method , slot_label)
super(method , slot_label)
end

View File

@ -4,7 +4,7 @@ module RubyX
# Layers are:
# - ruby , always needed as input, string
# - vool - intermediate language layer
# - mom - intermediate machine layer
# - slot_machine - intermediate machine layer
# - risc - "last" intermediate machine layer
# - target - arm or interpreter binary code
# - binary - "linked" code, everything need to create an elf binary
@ -65,7 +65,7 @@ module RubyX
to_risc()
end
# Transform the incoming ruby source (string) to mom
# Transform the incoming ruby source (string) to slot
#
# The vool is stored using ruby_to_vool,the to_slot is called
# Return SlotMachine Statement
@ -97,11 +97,11 @@ module RubyX
# Process previously stored vool source to risc.
# return a Risc::RiscCollection , a collection of MethodCompilers
def to_risc()
mom = to_slot
mom.to_risc()
slot = to_slot
slot.to_risc()
end
# return mom for the previously stored vool source.
# return slot_machine for the previously stored vool source.
def to_slot
@vool.to_parfait
@vool.to_slot(nil)

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)

View File

@ -13,7 +13,7 @@ module Vool
end
# Since the return is normalized to only allow simple values it is simple.
# To return form a method in mom instructions we only need to do two things:
# To return form a method in slot_machine instructions we only need to do two things:
# - store the given return value, this is a SlotMove
# - activate return sequence (reinstantiate old message and jump to return address)
def to_slot( compiler )

View File

@ -67,13 +67,13 @@ module Vool
def message_setup(compiler,called_method)
setup = SlotMachine::MessageSetup.new( called_method )
mom_receive = @receiver.to_slot_definition(compiler)
slot_receive = @receiver.to_slot_definition(compiler)
arg_target = [:message , :next_message ]
args = []
@arguments.each_with_index do |arg , index| # +1 because of type
args << SlotMachine::SlotLoad.new(self, arg_target + ["arg#{index+1}".to_sym] , arg.to_slot_definition(compiler))
end
setup << SlotMachine::ArgumentTransfer.new(self, mom_receive , args )
setup << SlotMachine::ArgumentTransfer.new(self, slot_receive , args )
end
def simple_call(compiler, called_method)

View File

@ -16,7 +16,7 @@
# The protocol is thus two stage:
# - first to_parfait with implicit side-effects of creating parfait objects that
# are added to the Parfait object_space
# - second to_slot , which will return a mom version of the statement. This may be code
# - second to_slot , which will return a slot version of the statement. This may be code
# or a compiler (for methods), or compiler collection (for classes)
#
module Vool
@ -38,8 +38,8 @@ module Vool
raise "Called when it shouldn't #{self.class}"
end
# create mom version of the statement, this is often code, that is added to the
# compiler, but for methods it is a compiler and for classes a collection of those.
# create slot_machine version of the statement, this is often code, that is added
# to the compiler, but for methods it is a compiler and for classes a collection of those.
#
# The argument given most often is a compiler
# The default implementation (this) is to raise an error

View File

@ -71,8 +71,8 @@ module Vool
stats = @statements.dup
first = stats.shift.to_slot(compiler)
while( nekst = stats.shift )
next_mom = nekst.to_slot(compiler)
first.append next_mom
next_slot = nekst.to_slot(compiler)
first.append next_slot
end
first
end

View File

@ -37,7 +37,7 @@ module Vool
compile_method = SlotMachine::SlotDefinition.new( compiler.get_method , [])
runtime_method = SlotMachine::SlotDefinition.new( :message , [ :method] )
check = SlotMachine::NotSameCheck.new(compile_method , runtime_method, ok_label)
# TODO? Maybe create mom instructions for this
# TODO? Maybe create slot instructions for this
#builder = compiler.builder("yield")
#Risc::Macro.exit_sequence(builder)
#check << builder.built
@ -49,13 +49,13 @@ module Vool
def yield_arg_block(compiler)
arg_index = compiler.get_method.arguments_type.get_length - 1
setup = SlotMachine::MessageSetup.new( arg_index )
mom_receive = @receiver.to_slot_definition(compiler)
slot_receive = @receiver.to_slot_definition(compiler)
arg_target = [:message , :next_message ]
args = []
@arguments.each_with_index do |arg , index| # +1 because of type
args << SlotMachine::SlotLoad.new(self, arg_target + ["arg#{index+1}".to_sym] , arg.to_slot_definition(compiler))
end
setup << SlotMachine::ArgumentTransfer.new( self , mom_receive , args )
setup << SlotMachine::ArgumentTransfer.new( self , slot_receive , args )
setup << SlotMachine::BlockYield.new( self , arg_index )
end