More rename cleanp
This commit is contained in:
parent
c43436f35a
commit
aa9fc8bc81
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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}"
|
||||
|
@ -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
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Mom
|
||||
module SlotMachine
|
||||
|
||||
# Transering the arguments from the current frame into the next frame
|
||||
#
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
#
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Mom
|
||||
module SlotMachine
|
||||
|
||||
# The funny thing about the ruby truth is that it is anything but false or nil
|
||||
#
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Mom
|
||||
module SlotMachine
|
||||
class Comparison < Macro
|
||||
attr_reader :operator
|
||||
def initialize(name , operator)
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Mom
|
||||
module SlotMachine
|
||||
class Div10 < Macro
|
||||
def to_risc(compiler)
|
||||
s = "div_10 "
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Mom
|
||||
module SlotMachine
|
||||
class Div4 < Macro
|
||||
def to_risc(compiler)
|
||||
builder = compiler.builder(compiler.source)
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Mom
|
||||
module SlotMachine
|
||||
class Exit < Macro
|
||||
def to_risc(compiler)
|
||||
builder = compiler.builder(compiler.source)
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Mom
|
||||
module SlotMachine
|
||||
class GetInternalByte < Macro
|
||||
def to_risc(compiler)
|
||||
builder = compiler.builder(compiler.source)
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Mom
|
||||
module SlotMachine
|
||||
class GetInternalWord < Macro
|
||||
def to_risc(compiler)
|
||||
compiler.builder(compiler.source).build do
|
||||
|
@ -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
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Mom
|
||||
module SlotMachine
|
||||
class Macro < Instruction
|
||||
|
||||
def to_s
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Mom
|
||||
module SlotMachine
|
||||
class MethodMissing < Macro
|
||||
attr_reader :name
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
|
||||
module Mom
|
||||
module SlotMachine
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Mom
|
||||
module SlotMachine
|
||||
class IntOperator < Macro
|
||||
attr_reader :operator
|
||||
def initialize(name , operator)
|
||||
|
@ -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
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Mom
|
||||
module SlotMachine
|
||||
class SetInternalByte < Macro
|
||||
def to_risc(compiler)
|
||||
compiler.builder(compiler.source).build do
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Mom
|
||||
module SlotMachine
|
||||
class SetInternalWord < Macro
|
||||
def to_risc(compiler)
|
||||
compiler.builder(compiler.source).build do
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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 )
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -9,7 +9,7 @@ module Risc
|
||||
@string_input = as_main("return 5 + 5")
|
||||
super
|
||||
end
|
||||
#FIXME should be mom macro test, no need to interpret
|
||||
#FIXME should be macro test, no need to interpret
|
||||
def test_chain
|
||||
#show_main_ticks # get output of what is
|
||||
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
||||
|
@ -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
|
||||
|
||||
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
|
||||
|
||||
## Risc
|
||||
|
@ -4,13 +4,13 @@ module RubyX
|
||||
module MacroHelper
|
||||
def setup
|
||||
whole ="class Space;def main(arg);return;end;end;" + source
|
||||
@mom = RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot(whole)
|
||||
@mom.method_compilers
|
||||
assert_equal SlotMachine::SlotCollection , @mom.class
|
||||
@slot = RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot(whole)
|
||||
@slot.method_compilers
|
||||
assert_equal SlotMachine::SlotCollection , @slot.class
|
||||
assert_equal SlotMachine::MethodCompiler , compiler.class
|
||||
end
|
||||
def compiler
|
||||
@mom.method_compilers.last_compiler
|
||||
@slot.method_compilers.last_compiler
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -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)
|
||||
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
|
||||
the RubyXCompiler parfait load list.
|
||||
|
||||
|
@ -28,8 +28,8 @@ module RubyX
|
||||
assert_equal :Data8 , vool[3].name
|
||||
end
|
||||
def test_slot
|
||||
mom = @compiler.ruby_to_slot source
|
||||
assert_equal SlotMachine::SlotCollection , mom.class
|
||||
slot = @compiler.ruby_to_slot source
|
||||
assert_equal SlotMachine::SlotCollection , slot.class
|
||||
end
|
||||
def test_risc
|
||||
risc = compiler.ruby_to_risc( get_preload("Space.main") + source)
|
||||
|
@ -29,8 +29,8 @@ module RubyX
|
||||
vool = @compiler.ruby_to_vool source
|
||||
vool.to_parfait
|
||||
#puts vool
|
||||
mom = vool.to_slot(nil)
|
||||
assert_equal SlotMachine::SlotCollection , mom.class
|
||||
slot = vool.to_slot(nil)
|
||||
assert_equal SlotMachine::SlotCollection , slot.class
|
||||
end
|
||||
def est_risc
|
||||
risc = compiler.ruby_to_risc source
|
||||
|
@ -19,8 +19,8 @@ module RubyX
|
||||
assert_equal :Object , vool.name
|
||||
end
|
||||
def test_slot
|
||||
mom = compiler.ruby_to_slot source
|
||||
assert_equal SlotMachine::SlotCollection , mom.class
|
||||
slot = compiler.ruby_to_slot source
|
||||
assert_equal SlotMachine::SlotCollection , slot.class
|
||||
end
|
||||
def test_risc
|
||||
risc = compiler.ruby_to_risc( get_preload("Space.main") + source)
|
||||
|
@ -13,8 +13,8 @@ module RubyX
|
||||
end
|
||||
|
||||
def test_creates_class_deriviation
|
||||
mom = ruby_to_slot "class Testing ; end"
|
||||
assert mom , "No classes created"
|
||||
slot = ruby_to_slot "class Testing ; end"
|
||||
assert slot , "No classes created"
|
||||
end
|
||||
|
||||
def test_creates_class_with_deriviation
|
||||
|
@ -7,7 +7,7 @@ module SlotMachine
|
||||
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.
|
||||
#
|
||||
# This is done with the assert methods in risc_assert
|
||||
|
@ -1,13 +1,13 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Mom
|
||||
module SlotMachine
|
||||
module Builtin
|
||||
class BootTest < MiniTest::Test
|
||||
include Preloader
|
||||
|
||||
def get_compiler(clazz , name)
|
||||
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
|
||||
end
|
||||
|
@ -62,9 +62,9 @@ module SlotMachine
|
||||
assert_equal 2 , method.frame_type.variable_index(:a)
|
||||
end
|
||||
def constant_setup(input)
|
||||
mom = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot(in_Test(input))
|
||||
assert_equal SlotMachine::SlotCollection , mom.class
|
||||
compiler = mom.method_compilers
|
||||
slot = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot(in_Test(input))
|
||||
assert_equal SlotMachine::SlotCollection , slot.class
|
||||
compiler = slot.method_compilers
|
||||
assert_equal SlotMachine::MethodCompiler , compiler.class
|
||||
compiler
|
||||
end
|
||||
|
@ -43,9 +43,9 @@ module VoolCompile
|
||||
end
|
||||
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}}")
|
||||
mom_col = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot( source )
|
||||
compiler = mom_col.method_compilers.find_compiler_name(:main)
|
||||
block = mom_col.method_compilers.find_compiler_name(:main_block)
|
||||
slot_col = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot( source )
|
||||
compiler = slot_col.method_compilers.find_compiler_name(:main)
|
||||
block = slot_col.method_compilers.find_compiler_name(:main_block)
|
||||
assert block
|
||||
block.slot_instructions.next
|
||||
end
|
||||
|
@ -37,16 +37,16 @@ module Vool
|
||||
assert_equal Vool::MacroExpression , vool.body.first.body.return_value.class
|
||||
end
|
||||
def test_slot_basic
|
||||
mom = as_slot
|
||||
assert_equal SlotMachine::SlotCollection , mom.class
|
||||
assert_equal SlotMachine::MethodCompiler , mom.method_compilers.class
|
||||
slot = as_slot
|
||||
assert_equal SlotMachine::SlotCollection , slot.class
|
||||
assert_equal SlotMachine::MethodCompiler , slot.method_compilers.class
|
||||
end
|
||||
def test_slot_instructions
|
||||
mom_compiler = as_slot.method_compilers
|
||||
assert_equal SlotMachine::Label , mom_compiler.slot_instructions.class
|
||||
assert_equal SlotMachine::IntOperator , mom_compiler.slot_instructions.next.class
|
||||
assert_equal SlotMachine::SlotLoad , mom_compiler.slot_instructions.next(2).class
|
||||
assert_equal SlotMachine::ReturnJump , mom_compiler.slot_instructions.next(3).class
|
||||
slot_compiler = as_slot.method_compilers
|
||||
assert_equal SlotMachine::Label , slot_compiler.slot_instructions.class
|
||||
assert_equal SlotMachine::IntOperator , slot_compiler.slot_instructions.next.class
|
||||
assert_equal SlotMachine::SlotLoad , slot_compiler.slot_instructions.next(2).class
|
||||
assert_equal SlotMachine::ReturnJump , slot_compiler.slot_instructions.next(3).class
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user