More rename cleanp

This commit is contained in:
Torsten Rüger 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 # CallableCompiler is used to generate risc instructions. It is an abstact base
# class shared by BlockCompiler and MethodCompiler # 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 # Instructions derive from class Instruction and form a linked list
# - constants is an array of Parfait objects that need to be available # - constants is an array of Parfait objects that need to be available
# - callable is a Method of Block # - callable is a Method of Block

View File

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

View File

@ -4,7 +4,7 @@ module RubyX
# Layers are: # Layers are:
# - ruby , always needed as input, string # - ruby , always needed as input, string
# - vool - intermediate language layer # - vool - intermediate language layer
# - mom - intermediate machine layer # - slot_machine - intermediate machine layer
# - risc - "last" intermediate machine layer # - risc - "last" intermediate machine layer
# - target - arm or interpreter binary code # - target - arm or interpreter binary code
# - binary - "linked" code, everything need to create an elf binary # - binary - "linked" code, everything need to create an elf binary
@ -65,7 +65,7 @@ module RubyX
to_risc() to_risc()
end 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 # The vool is stored using ruby_to_vool,the to_slot is called
# Return SlotMachine Statement # Return SlotMachine Statement
@ -97,11 +97,11 @@ module RubyX
# Process previously stored vool source to risc. # Process previously stored vool source to risc.
# return a Risc::RiscCollection , a collection of MethodCompilers # return a Risc::RiscCollection , a collection of MethodCompilers
def to_risc() def to_risc()
mom = to_slot slot = to_slot
mom.to_risc() slot.to_risc()
end end
# return mom for the previously stored vool source. # return slot_machine for the previously stored vool source.
def to_slot def to_slot
@vool.to_parfait @vool.to_parfait
@vool.to_slot(nil) @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. 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. 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 ### 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 control structures, but compare and jump instructions.
No send or call, just objects and jump. 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 # A BlockCompiler is much like a MehtodCompiler, exept for blocks
# #
class BlockCompiler < CallableCompiler class BlockCompiler < CallableCompiler
attr_reader :block , :mom_instructions attr_reader :block , :slot_instructions
alias :block :callable alias :block :callable
def initialize( block , method) def initialize( block , method)
@ -17,7 +17,7 @@ module Mom
end end
def to_risc 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) instructions_to_risc(risc_compiler)
#recursive blocks not done #recursive blocks not done
risc_compiler 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 # 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 # Instructions derive from class Instruction and form a linked list
class CallableCompiler class CallableCompiler
@ -12,17 +12,17 @@ module Mom
def initialize( callable ) def initialize( callable )
@callable = callable @callable = callable
@constants = [] @constants = []
@mom_instructions = Label.new(source_name, source_name) @slot_instructions = Label.new(source_name, source_name)
@current = start = @mom_instructions @current = start = @slot_instructions
add_code Label.new( source_name, "return_label") 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") add_code Label.new( source_name, "unreachable")
@current = start @current = start
end end
attr_reader :mom_instructions , :constants , :callable , :current attr_reader :slot_instructions , :constants , :callable , :current
def return_label def return_label
@mom_instructions.each do |ins| @slot_instructions.each do |ins|
next unless ins.is_a?(Label) next unless ins.is_a?(Label)
return ins if ins.name == "return_label" return ins if ins.name == "return_label"
end end
@ -43,7 +43,7 @@ module Mom
# add a risc instruction after the current (insertion point) # add a risc instruction after the current (insertion point)
# the added instruction will become the new insertion point # the added instruction will become the new insertion point
def add_code( instruction ) 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 new_current = instruction.last #after insertion this point is lost
@current.insert(instruction) #insert after current @current.insert(instruction) #insert after current
@current = new_current @current = new_current
@ -60,10 +60,10 @@ module Mom
# convert al instruction to risc # convert al instruction to risc
# method is called by Method/BlockCompiler from to_risc # method is called by Method/BlockCompiler from to_risc
def instructions_to_risc(risc_compiler) def instructions_to_risc(risc_compiler)
instruction = mom_instructions.next instruction = slot_instructions.next
while( instruction ) while( instruction )
raise "whats this a #{instruction}" unless instruction.is_a?(Mom::Instruction) raise "whats this a #{instruction}" unless instruction.is_a?(SlotMachine::Instruction)
#puts "adding mom #{instruction.to_s}:#{instruction.next.to_s}" #puts "adding slot #{instruction.to_s}:#{instruction.next.to_s}"
risc_compiler.reset_regs risc_compiler.reset_regs
instruction.to_risc( risc_compiler ) instruction.to_risc( risc_compiler )
#puts "adding risc #{risc.to_s}:#{risc.next.to_s}" #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. # 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. # 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) # 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 class Instruction
include Util::List include Util::List
@ -26,7 +26,7 @@ module Mom
# to_risc, like the name says, converts the instruction to it's Risc equivalent. # 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). # 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 # to many (1-10) risc instructions
# #
# The argument that is passed is a MethodCompiler, which has the method and some # 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 # Transering the arguments from the current frame into the next frame
# #

View File

@ -1,5 +1,5 @@
module Mom module SlotMachine
# just name scoping the same stuff to mom # just name scoping the same stuff to slot
# so we know we are on the way down, keeping our layers seperated # 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) # and we can put constant adding into the to_risc methods (instead of on vool classes)
class Constant 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 # 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 # 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 # 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) # 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 # 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 # check does not pass
# Note: In assembler a branch on 0 does just that, it branches if the condition # 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 # 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 class Check < Instruction
attr_reader :false_jump attr_reader :false_jump
def initialize(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 # 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 # 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 # Branch jump to the Label given
# Eg used at the end of while or end of if_true branch # 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, # 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 # 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 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. # simple.
# Alas, since almost by definition several roads lead to this label, all those # 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 # 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 # Ie: MessageSetup,ArgumentTransfer,SimpleCall
# #
# MessageSetup does Setup before a call can be made, acquiring and filling the message # 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 # 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 SlotDefinitions, ie can be anything
# available to the machine through frame message or self # 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 class NotSameCheck < Check
attr_reader :left , :right 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 # 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 # 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 # 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 return jump jumps to the return label
# the method setup is such that there is exactly one return_label in a method # 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. # The ReturnSequence models the return from a method.
# #
# This involves the jump to the return address stored in the message, and # This involves the jump to the return address stored in the message, and
# the reinstantiation of the previous message. # 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, # Messages are a double linked list, calling involves going forward,
# returning means going back. # 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, # 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 # 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. # A SlotDefinition defines a slot. A bit like a variable name but for objects.
# #
# PS: for the interested: A "developement" of Smalltalk was the # 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 # 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 # 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) # another Slot (SlotDefinition)
# #
# The Slot on the left hand side is always a 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 # @left: A SlotDefinition, or an array that can be passed to the constructor of the
# SlotDefinition (see there) # SlotDefinition (see there)
# #
# @right: A SlotDefinition with slots or a Mom::Constant # @right: A SlotDefinition with slots or a SlotMachine::Constant
# original_source: optinally another mom instruction that will be passed down to created # original_source: optinally another slot_machine instruction that will be passed down
# risc instructions. (Because SlotLoad is often used internally in mom) # to created risc instructions. (Because SlotLoad is often used internally)
class SlotLoad < Instruction class SlotLoad < Instruction
attr_reader :left , :right , :original_source attr_reader :left , :right , :original_source
@ -33,7 +33,7 @@ module Mom
@left , @right = left , right @left , @right = left , right
@left = SlotDefinition.new(@left.shift , @left) if @left.is_a? Array @left = SlotDefinition.new(@left.shift , @left) if @left.is_a? Array
@right = SlotDefinition.new(@right.shift , @right) if @right.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 @original_source = original_source || self
end 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 # 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 class Comparison < Macro
attr_reader :operator attr_reader :operator
def initialize(name , operator) def initialize(name , operator)

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
module Mom module SlotMachine
class GetInternalWord < Macro class GetInternalWord < Macro
def to_risc(compiler) def to_risc(compiler)
compiler.builder(compiler.source).build do 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 # 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 # There is an inital jump to it, but that's it, no setup, no nothing
# #
@ -20,7 +20,7 @@ module Mom
end end
builder.reset_names builder.reset_names
# Set up the call to main, with space as receiver # 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 builder.build do
message << message[:next_message] message << message[:next_message]
space? << Parfait.object_space space? << Parfait.object_space

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
module Mom module SlotMachine
class SetInternalWord < Macro class SetInternalWord < Macro
def to_risc(compiler) def to_risc(compiler)
compiler.builder(compiler.source).build do 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. # and to instantiate the methods correctly.
class MethodCompiler < CallableCompiler class MethodCompiler < CallableCompiler
@ -25,7 +25,7 @@ module Mom
# drop down to risc by converting this compilers instructions to risc. # drop down to risc by converting this compilers instructions to risc.
# and the doing the same for any block_compilers # and the doing the same for any block_compilers
def to_risc def to_risc
risc_compiler = Risc::MethodCompiler.new(@callable , mom_instructions) risc_compiler = Risc::MethodCompiler.new(@callable , slot_instructions)
instructions_to_risc(risc_compiler) instructions_to_risc(risc_compiler)
risc_compiler risc_compiler
end end
@ -83,8 +83,8 @@ module Mom
# Only for init, as init has no return # Only for init, as init has no return
# kind of private # kind of private
def _reset_for_init def _reset_for_init
@mom_instructions = Label.new(source_name, source_name) @slot_instructions = Label.new(source_name, source_name)
@current = @mom_instructions @current = @slot_instructions
end end
end end

View File

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

View File

@ -13,7 +13,7 @@ module Vool
end end
# Since the return is normalized to only allow simple values it is simple. # 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 # - store the given return value, this is a SlotMove
# - activate return sequence (reinstantiate old message and jump to return address) # - activate return sequence (reinstantiate old message and jump to return address)
def to_slot( compiler ) def to_slot( compiler )

View File

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

View File

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

View File

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

View File

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

View File

@ -9,7 +9,7 @@ module Risc
@string_input = as_main("return 5 + 5") @string_input = as_main("return 5 + 5")
super super
end end
#FIXME should be mom macro test, no need to interpret #FIXME should be macro test, no need to interpret
def test_chain def test_chain
#show_main_ticks # get output of what is #show_main_ticks # get output of what is
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5 check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5

View File

@ -1,18 +1,7 @@
## Pre - testing builtin
In the process of moving builtin from mom to parfait. Considering we started at risc, this
is progress.
Builtin methods should (will) use the Macro idea to actually become code and land in
the parfait code.
On the way there, we start by Testing and moving the old ones. Since we want to be able
to test some methods even after the move, without parsing/processing the whole of parfait
we have to have a method of "injecting" the single? methods.
## SlotMachine level ## SlotMachine level
There a re two test levels to every method. SlotMachine being the first, where we basically just There are two test levels to every method. SlotMachine being the first, where we basically just
see if the right SlotMachine instruction has been generated see if the right SlotMachine instruction has been generated
## Risc ## Risc

View File

@ -4,13 +4,13 @@ module RubyX
module MacroHelper module MacroHelper
def setup def setup
whole ="class Space;def main(arg);return;end;end;" + source whole ="class Space;def main(arg);return;end;end;" + source
@mom = RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot(whole) @slot = RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot(whole)
@mom.method_compilers @slot.method_compilers
assert_equal SlotMachine::SlotCollection , @mom.class assert_equal SlotMachine::SlotCollection , @slot.class
assert_equal SlotMachine::MethodCompiler , compiler.class assert_equal SlotMachine::MethodCompiler , compiler.class
end end
def compiler def compiler
@mom.method_compilers.last_compiler @slot.method_compilers.last_compiler
end end
end end

View File

@ -11,7 +11,7 @@ means testing every layer for every file.
Rather than create parfait tests for every layer (ie in the vool/slot_machine/risc directories) Rather than create parfait tests for every layer (ie in the vool/slot_machine/risc directories)
we have one file per parfait file here. Each file tests all layers. we have one file per parfait file here. Each file tests all layers.
The usual workflow is to start with a new file and create tests for vool, mom, risc,binary The usual workflow is to start with a new file and create tests for vool, slot_machine, risc,binary
in that order. Possibly fixing the compiler on the way. Then adding the file to in that order. Possibly fixing the compiler on the way. Then adding the file to
the RubyXCompiler parfait load list. the RubyXCompiler parfait load list.

View File

@ -28,8 +28,8 @@ module RubyX
assert_equal :Data8 , vool[3].name assert_equal :Data8 , vool[3].name
end end
def test_slot def test_slot
mom = @compiler.ruby_to_slot source slot = @compiler.ruby_to_slot source
assert_equal SlotMachine::SlotCollection , mom.class assert_equal SlotMachine::SlotCollection , slot.class
end end
def test_risc def test_risc
risc = compiler.ruby_to_risc( get_preload("Space.main") + source) risc = compiler.ruby_to_risc( get_preload("Space.main") + source)

View File

@ -29,8 +29,8 @@ module RubyX
vool = @compiler.ruby_to_vool source vool = @compiler.ruby_to_vool source
vool.to_parfait vool.to_parfait
#puts vool #puts vool
mom = vool.to_slot(nil) slot = vool.to_slot(nil)
assert_equal SlotMachine::SlotCollection , mom.class assert_equal SlotMachine::SlotCollection , slot.class
end end
def est_risc def est_risc
risc = compiler.ruby_to_risc source risc = compiler.ruby_to_risc source

View File

@ -19,8 +19,8 @@ module RubyX
assert_equal :Object , vool.name assert_equal :Object , vool.name
end end
def test_slot def test_slot
mom = compiler.ruby_to_slot source slot = compiler.ruby_to_slot source
assert_equal SlotMachine::SlotCollection , mom.class assert_equal SlotMachine::SlotCollection , slot.class
end end
def test_risc def test_risc
risc = compiler.ruby_to_risc( get_preload("Space.main") + source) risc = compiler.ruby_to_risc( get_preload("Space.main") + source)

View File

@ -13,8 +13,8 @@ module RubyX
end end
def test_creates_class_deriviation def test_creates_class_deriviation
mom = ruby_to_slot "class Testing ; end" slot = ruby_to_slot "class Testing ; end"
assert mom , "No classes created" assert slot , "No classes created"
end end
def test_creates_class_with_deriviation def test_creates_class_with_deriviation

View File

@ -7,7 +7,7 @@ module SlotMachine
end end
end end
# Most SlotMachineInstructionTests test the risc instructions of the mom instruction # Most SlotMachineInstructionTests test the risc instructions of the slot instruction
# quite carefully, ie every instruction, every register. # quite carefully, ie every instruction, every register.
# #
# This is done with the assert methods in risc_assert # This is done with the assert methods in risc_assert

View File

@ -1,13 +1,13 @@
require_relative "../helper" require_relative "../helper"
module Mom module SlotMachine
module Builtin module Builtin
class BootTest < MiniTest::Test class BootTest < MiniTest::Test
include Preloader include Preloader
def get_compiler(clazz , name) def get_compiler(clazz , name)
compiler = RubyX::RubyXCompiler.new(RubyX.default_test_options) compiler = RubyX::RubyXCompiler.new(RubyX.default_test_options)
coll = compiler.ruby_to_mom( get_preload("Space.main;#{clazz}.#{name}") ) coll = compiler.ruby_to_slot( get_preload("Space.main;#{clazz}.#{name}") )
@method = coll.method_compilers.last_compiler @method = coll.method_compilers.last_compiler
@method @method
end end

View File

@ -62,9 +62,9 @@ module SlotMachine
assert_equal 2 , method.frame_type.variable_index(:a) assert_equal 2 , method.frame_type.variable_index(:a)
end end
def constant_setup(input) def constant_setup(input)
mom = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot(in_Test(input)) slot = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot(in_Test(input))
assert_equal SlotMachine::SlotCollection , mom.class assert_equal SlotMachine::SlotCollection , slot.class
compiler = mom.method_compilers compiler = slot.method_compilers
assert_equal SlotMachine::MethodCompiler , compiler.class assert_equal SlotMachine::MethodCompiler , compiler.class
compiler compiler
end end

View File

@ -43,9 +43,9 @@ module VoolCompile
end end
def compile_main_block( block_input , method_input = "main_local = 5" , preload = nil) def compile_main_block( block_input , method_input = "main_local = 5" , preload = nil)
source = get_preload(preload) + as_main("#{method_input} ; self.main{|val| #{block_input}}") source = get_preload(preload) + as_main("#{method_input} ; self.main{|val| #{block_input}}")
mom_col = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot( source ) slot_col = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot( source )
compiler = mom_col.method_compilers.find_compiler_name(:main) compiler = slot_col.method_compilers.find_compiler_name(:main)
block = mom_col.method_compilers.find_compiler_name(:main_block) block = slot_col.method_compilers.find_compiler_name(:main_block)
assert block assert block
block.slot_instructions.next block.slot_instructions.next
end end

View File

@ -37,16 +37,16 @@ module Vool
assert_equal Vool::MacroExpression , vool.body.first.body.return_value.class assert_equal Vool::MacroExpression , vool.body.first.body.return_value.class
end end
def test_slot_basic def test_slot_basic
mom = as_slot slot = as_slot
assert_equal SlotMachine::SlotCollection , mom.class assert_equal SlotMachine::SlotCollection , slot.class
assert_equal SlotMachine::MethodCompiler , mom.method_compilers.class assert_equal SlotMachine::MethodCompiler , slot.method_compilers.class
end end
def test_slot_instructions def test_slot_instructions
mom_compiler = as_slot.method_compilers slot_compiler = as_slot.method_compilers
assert_equal SlotMachine::Label , mom_compiler.slot_instructions.class assert_equal SlotMachine::Label , slot_compiler.slot_instructions.class
assert_equal SlotMachine::IntOperator , mom_compiler.slot_instructions.next.class assert_equal SlotMachine::IntOperator , slot_compiler.slot_instructions.next.class
assert_equal SlotMachine::SlotLoad , mom_compiler.slot_instructions.next(2).class assert_equal SlotMachine::SlotLoad , slot_compiler.slot_instructions.next(2).class
assert_equal SlotMachine::ReturnJump , mom_compiler.slot_instructions.next(3).class assert_equal SlotMachine::ReturnJump , slot_compiler.slot_instructions.next(3).class
end end
end end
end end