rename also get_slot, to slot_to_reg

makes source and target clear
This commit is contained in:
Torsten Ruger 2016-12-25 18:05:39 +02:00
parent 35adf9a5e6
commit f648bf7bd5
32 changed files with 105 additions and 105 deletions

View File

@ -31,7 +31,7 @@ way of generating code is by new of the Class. This is ok for some.
But often one finds a little massaging of the incoming data is better, while keeping that logic But often one finds a little massaging of the incoming data is better, while keeping that logic
out of the Instructions classes. In such cases Module functions are again quite nice. Example: out of the Instructions classes. In such cases Module functions are again quite nice. Example:
Instead of GetSlot.new( register, index , register) we use Register.get_slot( name , name , name). Instead of SlotToReg.new( register, index , register) we use Register.slot_to_reg( name , name , name).
All names are resolved to registers, or index via Type. More readable code less repetition. All names are resolved to registers, or index via Type. More readable code less repetition.
As the example shows, in this case the module function name should be the instruction class name. As the example shows, in this case the module function name should be the instruction class name.

View File

@ -37,7 +37,7 @@ module Arm
ArmMachine.mov( code.to , code.from) ArmMachine.mov( code.to , code.from)
end end
def translate_GetSlot( code ) def translate_SlotToReg( code )
ArmMachine.ldr( *slot_args_for(code) ) ArmMachine.ldr( *slot_args_for(code) )
end end

View File

@ -8,7 +8,7 @@ module Register
me = compiler.process( Typed::Tree::NameExpression.new( :self) ) me = compiler.process( Typed::Tree::NameExpression.new( :self) )
# Load the argument # Load the argument
index = compiler.use_reg :Integer index = compiler.use_reg :Integer
compiler.add_code Register.get_slot(source , :message , 1 , index ) compiler.add_code Register.slot_to_reg(source , :message , 1 , index )
return me , index return me , index
end end
@ -20,7 +20,7 @@ module Register
# Load the value # Load the value
def load_arg_at(compiler, source , at) def load_arg_at(compiler, source , at)
value = compiler.use_reg :Integer value = compiler.use_reg :Integer
compiler.add_code Register.get_slot(source , :message , at , value ) compiler.add_code Register.slot_to_reg(source , :message , at , value )
value value
end end

View File

@ -19,7 +19,7 @@ module Register
compiler.add_code LoadConstant.new(source, space , space_reg) compiler.add_code LoadConstant.new(source, space , space_reg)
message_ind = Register.resolve_index( :space , :first_message ) message_ind = Register.resolve_index( :space , :first_message )
# Load the message to new message register (r1) # Load the message to new message register (r1)
compiler.add_code Register.get_slot( source , space_reg , message_ind , :message) compiler.add_code Register.slot_to_reg( source , space_reg , message_ind , :message)
# And store the space as the new self (so the call can move it back as self) # And store the space as the new self (so the call can move it back as self)
compiler.add_code Register.reg_to_slot( source, space_reg , :message , :receiver) compiler.add_code Register.reg_to_slot( source, space_reg , :message , :receiver)
exit_label = Label.new("_exit_label" , "#{compiler.type.object_class.name}.#{compiler.method.name}" ) exit_label = Label.new("_exit_label" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )

View File

@ -14,7 +14,7 @@ module Register
source = "get_internal_word" source = "get_internal_word"
me , index = self_and_int_arg(compiler,source) me , index = self_and_int_arg(compiler,source)
# reduce me to me[index] # reduce me to me[index]
compiler.add_code GetSlot.new( source , me , index , me) compiler.add_code SlotToReg.new( source , me , index , me)
# and put it back into the return value # and put it back into the return value
compiler.add_code Register.reg_to_slot( source , me , :message , :return_value) compiler.add_code Register.reg_to_slot( source , me , :message , :return_value)
return compiler.method return compiler.method

View File

@ -8,10 +8,10 @@ module Register
def putstring context def putstring context
compiler = Typed::MethodCompiler.new.create_method(:Word , :putstring ).init_method compiler = Typed::MethodCompiler.new.create_method(:Word , :putstring ).init_method
compiler.add_code Register.get_slot( "putstring" , :message , :receiver , :new_message ) compiler.add_code Register.slot_to_reg( "putstring" , :message , :receiver , :new_message )
index = Parfait::Word.get_length_index index = Parfait::Word.get_length_index
reg = RegisterValue.new(:r2 , :Integer) reg = RegisterValue.new(:r2 , :Integer)
compiler.add_code Register.get_slot( "putstring" , :new_message , index , reg ) compiler.add_code Register.slot_to_reg( "putstring" , :new_message , index , reg )
Kernel.emit_syscall( compiler , :putstring ) Kernel.emit_syscall( compiler , :putstring )
compiler.method compiler.method
end end

View File

@ -120,7 +120,7 @@ end
require_relative "instructions/setter" require_relative "instructions/setter"
require_relative "instructions/getter" require_relative "instructions/getter"
require_relative "instructions/reg_to_slot" require_relative "instructions/reg_to_slot"
require_relative "instructions/get_slot" require_relative "instructions/slot_to_reg"
require_relative "instructions/set_byte" require_relative "instructions/set_byte"
require_relative "instructions/get_byte" require_relative "instructions/get_byte"
require_relative "instructions/load_constant" require_relative "instructions/load_constant"

View File

@ -29,6 +29,6 @@ module Register
# move the current message to new_message # move the current message to new_message
compiler.add_code Register::RegisterTransfer.new(source, Register.message_reg , Register.new_message_reg ) compiler.add_code Register::RegisterTransfer.new(source, Register.message_reg , Register.new_message_reg )
# and restore the message from saved value in new_message # and restore the message from saved value in new_message
compiler.add_code Register.get_slot(source , :new_message , :caller , :message ) compiler.add_code Register.slot_to_reg(source , :new_message , :caller , :message )
end end
end end

View File

@ -10,7 +10,7 @@ module Register
# If you had a c array (of int8) and index offset # If you had a c array (of int8) and index offset
# the instruction would do register = array[index] # the instruction would do register = array[index]
# The arguments are in the order that makes sense for the Instruction name # The arguments are in the order that makes sense for the Instruction name
# So GetSlot means the slot (array and index) moves to the register (last argument) # So SlotToReg means the slot (array and index) moves to the register (last argument)
# def initialize source , array , index , register # def initialize source , array , index , register
# super # super
# end # end

View File

@ -1,6 +1,6 @@
module Register module Register
# Getter is a base class for get instructions (GetSlot and GetByte , possibly more coming) # Getter is a base class for get instructions (SlotToReg and GetByte , possibly more coming)
# #
# The instruction that is modelled is loading data from an array into a register # The instruction that is modelled is loading data from an array into a register
# #
@ -16,7 +16,7 @@ module Register
# If you had a c array and index offset # If you had a c array and index offset
# the instruction would do register = array[index] # the instruction would do register = array[index]
# The arguments are in the order that makes sense for the Instruction name # The arguments are in the order that makes sense for the Instruction name
# So GetSlot means the slot (array and index) moves to the register (last argument) # So SlotToReg means the slot (array and index) moves to the register (last argument)
def initialize source , array , index , register def initialize source , array , index , register
super(source) super(source)
@array = array @array = array

View File

@ -1,7 +1,7 @@
module Register module Register
# RegToSlot moves data into memory from a register. # RegToSlot moves data into memory from a register.
# GetSlot moves data into a register from memory. # SlotToReg moves data into a register from memory.
# Both use a base memory (a register) # Both use a base memory (a register)
# This is because that is what cpu's can do. In programming terms this would be accessing # This is because that is what cpu's can do. In programming terms this would be accessing

View File

@ -3,7 +3,7 @@ module Register
# transfer the constents of one register to another. # transfer the constents of one register to another.
# possibly called move in some cpus # possibly called move in some cpus
# There are other instructions to move data from / to memory, namely GetSlot and RegToSlot # There are other instructions to move data from / to memory, namely SlotToReg and RegToSlot
# Get/Set Slot move data around in vm objects, but transfer moves the objects (in the machine) # Get/Set Slot move data around in vm objects, but transfer moves the objects (in the machine)
# #

View File

@ -1,20 +1,20 @@
module Register module Register
# GetSlot moves data into a register from memory. # SlotToReg moves data into a register from memory.
# RegToSlot moves data into memory from a register. # RegToSlot moves data into memory from a register.
# Both use a base memory (a register) # Both use a base memory (a register)
# This is because that is what cpu's can do. In programming terms this would be accessing # This is because that is what cpu's can do. In programming terms this would be accessing
# an element in an array, in the case of GetSlot setting the value in the array. # an element in an array, in the case of SlotToReg setting the value in the array.
# btw: to move data between registers, use RegisterTransfer # btw: to move data between registers, use RegisterTransfer
class GetSlot < Getter class SlotToReg < Getter
# If you had a c array and index offset # If you had a c array and index offset
# the instruction would do register = array[index] # the instruction would do register = array[index]
# The arguments are in the order that makes sense for the Instruction name # The arguments are in the order that makes sense for the Instruction name
# So GetSlot means the slot (array and index) moves to the register (last argument) # So SlotToReg means the slot (array and index) moves to the register (last argument)
# def initialize source , array , index , register # def initialize source , array , index , register
# super # super
# end # end
@ -22,13 +22,13 @@ module Register
end end
# Produce a GetSlot instruction. # Produce a SlotToReg instruction.
# Array and to are registers or symbols that can be transformed to a register by resolve_to_register # Array and to are registers or symbols that can be transformed to a register by resolve_to_register
# index resolves with resolve_index. # index resolves with resolve_index.
def self.get_slot source , array , index , to def self.slot_to_reg source , array , index , to
index = resolve_index( array , index) index = resolve_index( array , index)
array = resolve_to_register array array = resolve_to_register array
to = resolve_to_register to to = resolve_to_register to
GetSlot.new( source , array , index , to) SlotToReg.new( source , array , index , to)
end end
end end

View File

@ -7,8 +7,8 @@ module Register
# interpreting it is not so terribly difficult. # interpreting it is not so terribly difficult.
# #
# There is a certain amount of basic machinery to fetch and execute the next instruction # There is a certain amount of basic machinery to fetch and execute the next instruction
# (as a cpu would), and then there is a method for each instruction. Eg an instruction GetSlot # (as a cpu would), and then there is a method for each instruction. Eg an instruction SlotToReg
# will be executed by method execute_GetSlot # will be executed by method execute_SlotToReg
# #
# The Interpreter (a bit like a cpu) has a state flag, a current instruction and registers # The Interpreter (a bit like a cpu) has a state flag, a current instruction and registers
# We collect the stdout (as a hack not to interpret the OS) # We collect the stdout (as a hack not to interpret the OS)
@ -126,7 +126,7 @@ module Register
true true
end end
def execute_GetSlot def execute_SlotToReg
object = get_register( @instruction.array ) object = get_register( @instruction.array )
if( @instruction.index.is_a?(Numeric) ) if( @instruction.index.is_a?(Numeric) )
index = @instruction.index index = @instruction.index

View File

@ -26,7 +26,7 @@ module Typed
return nil unless index return nil unless index
end end
# TODO, check type @method.locals[index].type # TODO, check type @method.locals[index].type
add_code Register.get_slot(statement , :message , type , named_list ) add_code Register.slot_to_reg(statement , :message , type , named_list )
return Register.reg_to_slot(statement , value , named_list , index ) return Register.reg_to_slot(statement , value , named_list , index )
end end
end end

View File

@ -7,7 +7,7 @@ module Typed
reset_regs reset_regs
#move the new message (that we need to populate to make a call) to std register #move the new message (that we need to populate to make a call) to std register
new_message = Register.resolve_to_register(:new_message) new_message = Register.resolve_to_register(:new_message)
add_code Register.get_slot(statement, :message , :next_message , new_message ) add_code Register.slot_to_reg(statement, :message , :next_message , new_message )
me = get_me( statement ) me = get_me( statement )
type = get_my_type(me) type = get_my_type(me)
# move our receiver there # move our receiver there
@ -19,7 +19,7 @@ module Typed
do_call(type , statement) do_call(type , statement)
# the effect of the method is that the NewMessage Return slot will be filled, return it # the effect of the method is that the NewMessage Return slot will be filled, return it
# but move it into a register too # but move it into a register too
add_code Register.get_slot(statement, :new_message , :return_value , ret ) add_code Register.slot_to_reg(statement, :new_message , :return_value , ret )
ret ret
end end
@ -30,7 +30,7 @@ module Typed
me = process( statement.receiver ) me = process( statement.receiver )
else else
me = use_reg @method.for_type me = use_reg @method.for_type
add_code Register.get_slot(statement, :message , :receiver , me ) add_code Register.slot_to_reg(statement, :message , :receiver , me )
end end
me me
end end
@ -67,7 +67,7 @@ module Typed
args_reg = use_reg(:Type , @method.arguments ) args_reg = use_reg(:Type , @method.arguments )
list_reg = use_reg(:NamedList , arguments ) list_reg = use_reg(:NamedList , arguments )
add_code Register::LoadConstant.new(name_s, @method , args_reg) add_code Register::LoadConstant.new(name_s, @method , args_reg)
add_code Register.get_slot( name_s , :message , :arguments , list_reg ) add_code Register.slot_to_reg( name_s , :message , :arguments , list_reg )
add_code Register.reg_to_slot( name_s , args_reg , list_reg , 1 ) add_code Register.reg_to_slot( name_s , args_reg , list_reg , 1 )
#FIXME need to set type of locals too. sama sama #FIXME need to set type of locals too. sama sama
@ -83,7 +83,7 @@ module Typed
val = process( arg) val = process( arg)
raise "Not register #{val}" unless val.is_a?(Register::RegisterValue) raise "Not register #{val}" unless val.is_a?(Register::RegisterValue)
list_reg = use_reg(:NamedList , arguments ) list_reg = use_reg(:NamedList , arguments )
add_code Register.get_slot( "Set arg #{i}#{arg}" , :message , :arguments , list_reg ) add_code Register.slot_to_reg( "Set arg #{i}#{arg}" , :message , :arguments , list_reg )
# which we load int the new_message at the argument's index (the one comes from c index) # which we load int the new_message at the argument's index (the one comes from c index)
set = Register.reg_to_slot( arg , val , list_reg , i + 1 ) set = Register.reg_to_slot( arg , val , list_reg , i + 1 )
add_code set add_code set

View File

@ -15,7 +15,7 @@ module Typed
raise "no such field:#{field_name} for class #{type.inspect}" unless index raise "no such field:#{field_name} for class #{type.inspect}" unless index
value = use_reg(type.type_at(index)) value = use_reg(type.type_at(index))
add_code Register.get_slot(statement , receiver , index, value) add_code Register.slot_to_reg(statement , receiver , index, value)
value value
end end

View File

@ -14,7 +14,7 @@ module Typed
if( index = @method.has_arg(name)) if( index = @method.has_arg(name))
ret = use_reg @method.argument_type(index) ret = use_reg @method.argument_type(index)
#puts "For #{name} at #{index} got #{@method.arguments.inspect}" #puts "For #{name} at #{index} got #{@method.arguments.inspect}"
add_code Register.get_slot(statement , :message , index, ret ) add_code Register.slot_to_reg(statement , :message , index, ret )
return ret return ret
end end
# or a local so it is in the named_list # or a local so it is in the named_list
@ -27,15 +27,15 @@ module Typed
index = @method.has_local( statement.name ) index = @method.has_local( statement.name )
raise "must define variable '#{statement.name}' before using it" unless index raise "must define variable '#{statement.name}' before using it" unless index
named_list = use_reg :NamedList named_list = use_reg :NamedList
add_code Register.get_slot(statement , :message , :locals , named_list ) add_code Register.slot_to_reg(statement , :message , :locals , named_list )
ret = use_reg @method.locals_type( index ) ret = use_reg @method.locals_type( index )
add_code Register.get_slot(statement , named_list , index, ret ) add_code Register.slot_to_reg(statement , named_list , index, ret )
return ret return ret
end end
def handle_special_self(statement) def handle_special_self(statement)
ret = use_reg @type ret = use_reg @type
add_code Register.get_slot(statement , :message , :receiver , ret ) add_code Register.slot_to_reg(statement , :message , :receiver , ret )
return ret return ret
end end

View File

@ -17,14 +17,14 @@ HERE
def test_chain def test_chain
#show_ticks # get output of what is #show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot", check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant", "LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant",
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn", "LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn",
"RegisterTransfer","Syscall","NilClass"] "RegisterTransfer","Syscall","NilClass"]
end end
def test_get def test_get
assert_equal Register::GetSlot , ticks(4).class assert_equal Register::SlotToReg , ticks(4).class
assert @interpreter.get_register( :r2 ) assert @interpreter.get_register( :r2 )
assert Integer , @interpreter.get_register( :r2 ).class assert Integer , @interpreter.get_register( :r2 ).class
end end

View File

@ -36,7 +36,7 @@ class AddChange < MiniTest::Test
def test_chain def test_chain
#show_ticks # get output of what is #show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot", check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant", "LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant",
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn", "LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn",
"RegisterTransfer","Syscall","NilClass"] "RegisterTransfer","Syscall","NilClass"]

View File

@ -20,13 +20,13 @@ HERE
def test_chain def test_chain
#show_ticks # get output of what is #show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot", check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","GetSlot", "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg",
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot", "RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot",
"LoadConstant","RegToSlot","RegisterTransfer","FunctionCall","Label", "LoadConstant","RegToSlot","RegisterTransfer","FunctionCall","Label",
"GetSlot","GetSlot","GetSlot","SetByte","Label", "SlotToReg","SlotToReg","SlotToReg","SetByte","Label",
"FunctionReturn","RegisterTransfer","GetSlot","GetSlot","Label", "FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg","Label",
"FunctionReturn","RegisterTransfer","Syscall","NilClass"] "FunctionReturn","RegisterTransfer","Syscall","NilClass"]
end end
@ -42,7 +42,7 @@ HERE
assert_equal :r2, @interpreter.instruction.array.symbol assert_equal :r2, @interpreter.instruction.array.symbol
end end
def test_get def test_get
assert_equal Register::GetSlot , ticks(4).class assert_equal Register::SlotToReg , ticks(4).class
assert @interpreter.get_register( :r1 ) assert @interpreter.get_register( :r1 )
assert Integer , @interpreter.get_register( :r1 ).class assert Integer , @interpreter.get_register( :r1 ).class
end end

View File

@ -33,18 +33,18 @@ HERE
end end
def test_if def test_if
#show_ticks # get output of what is #show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot", check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","GetSlot", "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg",
"GetSlot","RegToSlot","LoadConstant","RegToSlot","LoadConstant", "SlotToReg","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot", "RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot",
"RegisterTransfer","FunctionCall","Label","GetSlot","LoadConstant", "RegisterTransfer","FunctionCall","Label","SlotToReg","LoadConstant",
"OperatorInstruction","IsZero","GetSlot","LoadConstant","RegToSlot", "OperatorInstruction","IsZero","SlotToReg","LoadConstant","RegToSlot",
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
"RegToSlot","RegisterTransfer","FunctionCall","Label","GetSlot", "RegToSlot","RegisterTransfer","FunctionCall","Label","SlotToReg",
"GetSlot","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer", "SlotToReg","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer",
"RegToSlot","Label","FunctionReturn","RegisterTransfer","GetSlot", "RegToSlot","Label","FunctionReturn","RegisterTransfer","SlotToReg",
"GetSlot","Branch","Label","Label","FunctionReturn", "SlotToReg","Branch","Label","Label","FunctionReturn",
"RegisterTransfer","GetSlot","GetSlot","Label","FunctionReturn", "RegisterTransfer","SlotToReg","SlotToReg","Label","FunctionReturn",
"RegisterTransfer","Syscall","NilClass"] "RegisterTransfer","Syscall","NilClass"]
end end
end end

View File

@ -19,7 +19,7 @@ HERE
def test_mult def test_mult
#show_ticks # get output of what is #show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot", check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant", "LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant",
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn", "LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn",
"RegisterTransfer","Syscall","NilClass"] "RegisterTransfer","Syscall","NilClass"]

View File

@ -17,7 +17,7 @@ HERE
def test_add def test_add
#show_ticks # get output of what is #show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot", check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant", "LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant",
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn", "LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn",
"RegisterTransfer","Syscall","NilClass"] "RegisterTransfer","Syscall","NilClass"]

View File

@ -17,13 +17,13 @@ HERE
def test_chain def test_chain
#show_ticks # get output of what is #show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot", check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","GetSlot", "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg",
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
"RegToSlot","LoadConstant","RegToSlot","RegisterTransfer","FunctionCall", "RegToSlot","LoadConstant","RegToSlot","RegisterTransfer","FunctionCall",
"Label","GetSlot","GetSlot","RegisterTransfer","Syscall", "Label","SlotToReg","SlotToReg","RegisterTransfer","Syscall",
"RegisterTransfer","RegisterTransfer","RegToSlot","Label","FunctionReturn", "RegisterTransfer","RegisterTransfer","RegToSlot","Label","FunctionReturn",
"RegisterTransfer","GetSlot","GetSlot","Label","FunctionReturn", "RegisterTransfer","SlotToReg","SlotToReg","Label","FunctionReturn",
"RegisterTransfer","Syscall","NilClass"] "RegisterTransfer","Syscall","NilClass"]
end end
@ -39,7 +39,7 @@ HERE
assert_equal :r2, @interpreter.instruction.array.symbol assert_equal :r2, @interpreter.instruction.array.symbol
end end
def test_get def test_get
assert_equal Register::GetSlot , ticks(4).class assert_equal Register::SlotToReg , ticks(4).class
assert @interpreter.get_register( :r1 ) assert @interpreter.get_register( :r1 )
assert Integer , @interpreter.get_register( :r1 ).class assert Integer , @interpreter.get_register( :r1 ).class
end end

View File

@ -20,13 +20,13 @@ HERE
def test_chain def test_chain
#show_ticks # get output of what is #show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot", check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","GetSlot", "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg",
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot", "RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot",
"RegisterTransfer","FunctionCall","Label","GetSlot","GetSlot", "RegisterTransfer","FunctionCall","Label","SlotToReg","SlotToReg",
"GetByte","RegToSlot","Label","FunctionReturn","RegisterTransfer", "GetByte","RegToSlot","Label","FunctionReturn","RegisterTransfer",
"GetSlot","GetSlot","Label","FunctionReturn","RegisterTransfer", "SlotToReg","SlotToReg","Label","FunctionReturn","RegisterTransfer",
"Syscall","NilClass"] "Syscall","NilClass"]
end end
@ -42,7 +42,7 @@ HERE
assert_equal :r2, @interpreter.instruction.array.symbol assert_equal :r2, @interpreter.instruction.array.symbol
end end
def test_get def test_get
assert_equal Register::GetSlot , ticks(4).class assert_equal Register::SlotToReg , ticks(4).class
assert @interpreter.get_register( :r1 ) assert @interpreter.get_register( :r1 )
assert Integer , @interpreter.get_register( :r1 ).class assert Integer , @interpreter.get_register( :r1 ).class
end end

View File

@ -9,7 +9,7 @@ class TestAssignStatement < MiniTest::Test
@input = s(:statements, s(:assignment, s(:name, :r), s(:operator_value, :+, s(:int, 10), s(:int, 1)))) @input = s(:statements, s(:assignment, s(:name, :r), s(:operator_value, :+, s(:int, 10), s(:int, 1))))
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, GetSlot, RegToSlot, Label , @expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot, Label ,
FunctionReturn] FunctionReturn]
check check
end end
@ -18,7 +18,7 @@ class TestAssignStatement < MiniTest::Test
Register.machine.space.get_main.add_local(:r , :Integer) Register.machine.space.get_main.add_local(:r , :Integer)
@input =s(:statements, s(:assignment, s(:name, :r), s(:int, 5))) @input =s(:statements, s(:assignment, s(:name, :r), s(:int, 5)))
@expect = [Label, LoadConstant, GetSlot, RegToSlot, Label, FunctionReturn] @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
check check
end end
@ -27,34 +27,34 @@ class TestAssignStatement < MiniTest::Test
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5))) @input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)))
@expect = [Label, LoadConstant, GetSlot, RegToSlot, Label, FunctionReturn] @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
check check
end end
def test_assign_call def test_assign_call
Register.machine.space.get_main.add_local(:r , :Integer) Register.machine.space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:call, s(:name, :main), s(:arguments)))) @input = s(:statements, s(:assignment, s(:name, :r), s(:call, s(:name, :main), s(:arguments))))
@expect = [Label, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot, LoadConstant , @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, GetSlot, RegToSlot, Label, FunctionReturn] SlotToReg, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
check check
end end
def test_named_list_get def test_named_list_get
Register.machine.space.get_main.add_local(:r , :Integer) Register.machine.space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)), s(:return, s(:name, :r))) @input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)), s(:return, s(:name, :r)))
@expect = [Label, LoadConstant, GetSlot, RegToSlot, GetSlot, GetSlot, RegToSlot , @expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot ,
Label, FunctionReturn] Label, FunctionReturn]
was = check was = check
get = was.next(5) get = was.next(5)
assert_equal GetSlot , get.class assert_equal SlotToReg , get.class
assert_equal 1, get.index , "Get to named_list index must be offset, not #{get.index}" assert_equal 1, get.index , "Get to named_list index must be offset, not #{get.index}"
end end
def test_assign_int def test_assign_int
Register.machine.space.get_main.add_local(:r , :Integer) Register.machine.space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)) ) @input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)) )
@expect = [Label, LoadConstant, GetSlot, RegToSlot, Label, FunctionReturn] @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
was = check was = check
set = was.next(3) set = was.next(3)
assert_equal RegToSlot , set.class assert_equal RegToSlot , set.class
@ -75,10 +75,10 @@ class TestAssignStatement < MiniTest::Test
# have to define bar externally, just because redefining main. Otherwise that would be automatic # have to define bar externally, just because redefining main. Otherwise that would be automatic
Register.machine.space.get_main.add_argument(:balr , :Integer) Register.machine.space.get_main.add_argument(:balr , :Integer)
@input = s(:statements, s(:return, s(:name, :balr))) @input = s(:statements, s(:return, s(:name, :balr)))
@expect = [Label, GetSlot, RegToSlot, Label, FunctionReturn] @expect = [Label, SlotToReg, RegToSlot, Label, FunctionReturn]
was = check was = check
get = was.next(1) get = was.next(1)
assert_equal GetSlot , get.class assert_equal SlotToReg , get.class
assert_equal 1, get.index , "Get to args index must be offset, not #{get.index}" assert_equal 1, get.index , "Get to args index must be offset, not #{get.index}"
end end
end end

View File

@ -7,9 +7,9 @@ class TestCallStatement < MiniTest::Test
def test_call_constant_int def test_call_constant_int
clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1))) clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1)))
@input = s(:call, s(:name, :puti), s(:arguments), s(:receiver, s(:int, 42))) @input = s(:call, s(:name, :puti), s(:arguments), s(:receiver, s(:int, 42)))
@expect = [Label, GetSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant , @expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, Label, FunctionReturn] SlotToReg, SlotToReg, Label, FunctionReturn]
check check
end end
@ -18,9 +18,9 @@ class TestCallStatement < MiniTest::Test
clean_compile :Word, :putstr,{}, s(:statements, s(:return, s(:int, 1))) clean_compile :Word, :putstr,{}, s(:statements, s(:return, s(:int, 1)))
@input =s(:call, s(:name, :putstr), s(:arguments), s(:receiver, s(:string, "Hello"))) @input =s(:call, s(:name, :putstr), s(:arguments), s(:receiver, s(:string, "Hello")))
@expect = [Label, GetSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant , @expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, Label, FunctionReturn] SlotToReg, SlotToReg, Label, FunctionReturn]
check check
end end
@ -29,9 +29,9 @@ class TestCallStatement < MiniTest::Test
clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1))) clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1)))
@input = s(:statements, s(:assignment, s(:name, :testi), s(:int, 20)), s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi)))) @input = s(:statements, s(:assignment, s(:name, :testi), s(:int, 20)), s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi))))
@expect = [Label, LoadConstant, GetSlot, RegToSlot, GetSlot, GetSlot, GetSlot , @expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg ,
RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot , RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot ,
RegisterTransfer, FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, Label , RegisterTransfer, FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, Label ,
FunctionReturn] FunctionReturn]
check check
end end
@ -41,9 +41,9 @@ class TestCallStatement < MiniTest::Test
clean_compile :List, :add, {}, s(:statements, s(:return, s(:int, 1))) clean_compile :List, :add, {}, s(:statements, s(:return, s(:int, 1)))
@input =s(:statements, s(:call, s(:name, :add), s(:arguments), s(:receiver, s(:name, :test_l)))) @input =s(:statements, s(:call, s(:name, :add), s(:arguments), s(:receiver, s(:name, :test_l))))
@expect = [Label, GetSlot, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot , @expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot ,
LoadConstant, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label , LoadConstant, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label ,
RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn] RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn]
check check
end end
@ -58,9 +58,9 @@ int main()
end end
end end
HERE HERE
@expect = [Label, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot, LoadConstant , @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall , RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
Label, RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn] Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn]
was = check was = check
set = was.next(7) set = was.next(7)
assert_equal RegToSlot , set.class assert_equal RegToSlot , set.class

View File

@ -20,9 +20,9 @@ class TestClassStatements < MiniTest::Test
# class_def # class_def
# @input = s(:statements, s(:return, s(:call, s(:name, :buh), s(:arguments), s(:receiver, s(:class_name, :Bar))))) # @input = s(:statements, s(:return, s(:call, s(:name, :buh), s(:arguments), s(:receiver, s(:class_name, :Bar)))))
# #
# @expect = [Label, GetSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant , # @expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
# RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , # RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
# GetSlot, GetSlot, RegToSlot, Label, FunctionReturn] # SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
# check # check
end end
@ -31,7 +31,7 @@ class TestClassStatements < MiniTest::Test
#FIXME class_field handling unclear at the moment #FIXME class_field handling unclear at the moment
# @input =s(:statements, s(:return, s(:field_access, s(:receiver, s(:name, :self)), # @input =s(:statements, s(:return, s(:field_access, s(:receiver, s(:name, :self)),
# s(:field,s(:name, :boo2))))) # s(:field,s(:name, :boo2)))))
# @expect = [Label, GetSlot,GetSlot,RegToSlot,Label,FunctionReturn] # @expect = [Label, SlotToReg,SlotToReg,RegToSlot,Label,FunctionReturn]
# check # check
end end
end end

View File

@ -9,7 +9,7 @@ module Register
Register.machine.space.get_main.add_local( :m , :Message) Register.machine.space.get_main.add_local( :m , :Message)
@input = s(:statements, s(:return, s(:field_access, @input = s(:statements, s(:return, s(:field_access,
s(:receiver, s(:name, :m)), s(:field, s(:name, :name))))) s(:receiver, s(:name, :m)), s(:field, s(:name, :name)))))
@expect = [Label, GetSlot, GetSlot, GetSlot, RegToSlot, Label, FunctionReturn] @expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
check check
end end
@ -20,9 +20,9 @@ module Register
s(:receiver, s(:name, :main)), s(:field, s(:name, :name))))) s(:receiver, s(:name, :main)), s(:field, s(:name, :name)))))
@input =s(:statements, s(:return, s(:call, s(:name, :get_name), s(:arguments, s(:name, :m))))) @input =s(:statements, s(:return, s(:call, s(:name, :get_name), s(:arguments, s(:name, :m)))))
@expect = [Label, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot, LoadConstant , @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
RegToSlot, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer , RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer ,
FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, RegToSlot, Label , FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, Label ,
FunctionReturn] FunctionReturn]
check check
end end
@ -31,7 +31,7 @@ module Register
Register.machine.space.get_main.add_local(:name , :Word) Register.machine.space.get_main.add_local(:name , :Word)
@input = s(:statements, s(:assignment, s(:name, :name), s(:field_access, s(:receiver, s(:name, :message)), s(:field, s(:name, :name)))), s(:return, s(:name, :name))) @input = s(:statements, s(:assignment, s(:name, :name), s(:field_access, s(:receiver, s(:name, :message)), s(:field, s(:name, :name)))), s(:return, s(:name, :name)))
@expect = [Label, RegisterTransfer, GetSlot, GetSlot, RegToSlot, GetSlot, GetSlot , @expect = [Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg ,
RegToSlot, Label, FunctionReturn] RegToSlot, Label, FunctionReturn]
check check
end end

View File

@ -13,30 +13,30 @@ class TestReturnStatement < MiniTest::Test
def test_return_local def test_return_local
Register.machine.space.get_main.add_local(:runner , :Integer) Register.machine.space.get_main.add_local(:runner , :Integer)
@input = s(:statements, s(:return, s(:name, :runner))) @input = s(:statements, s(:return, s(:name, :runner)))
@expect = [Label, GetSlot,GetSlot ,RegToSlot,Label,FunctionReturn] @expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
check check
end end
def test_return_local_assign def test_return_local_assign
Register.machine.space.get_main.add_local(:runner , :Integer) Register.machine.space.get_main.add_local(:runner , :Integer)
@input = s(:statements, s(:assignment, s(:name, :runner), s(:int, 5)), s(:return, s(:name, :runner))) @input = s(:statements, s(:assignment, s(:name, :runner), s(:int, 5)), s(:return, s(:name, :runner)))
@expect = [Label, LoadConstant,GetSlot,RegToSlot,GetSlot,GetSlot ,RegToSlot, @expect = [Label, LoadConstant,SlotToReg,RegToSlot,SlotToReg,SlotToReg ,RegToSlot,
Label,FunctionReturn] Label,FunctionReturn]
check check
end end
def test_return_call def test_return_call
@input =s(:statements, s(:return, s(:call, s(:name, :main), s(:arguments)))) @input =s(:statements, s(:return, s(:call, s(:name, :main), s(:arguments))))
@expect = [Label, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot, LoadConstant , @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, RegToSlot, Label, FunctionReturn] SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
check check
end end
def pest_return_space_length # need to add runtime first def pest_return_space_length # need to add runtime first
Register.machine.space.get_main.add_local(:l , :Type) Register.machine.space.get_main.add_local(:l , :Type)
@input = s(:statements, s(:assignment, s(:name, :l), s(:call, s(:name, :get_type), s(:arguments), s(:receiver, s(:name, :space)))), s(:return, s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :runner))))) @input = s(:statements, s(:assignment, s(:name, :l), s(:call, s(:name, :get_type), s(:arguments), s(:receiver, s(:name, :space)))), s(:return, s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :runner)))))
@expect = [Label, GetSlot,GetSlot ,RegToSlot,Label,FunctionReturn] @expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
check check
end end

View File

@ -18,9 +18,9 @@ module Register
@input = s(:statements, s(:assignment, s(:name, :n), s(:int, 5)), s(:while_statement, :plus, s(:conditional, s(:name, :n)), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :-, s(:name, :n), s(:int, 1))))), s(:return, s(:name, :n))) @input = s(:statements, s(:assignment, s(:name, :n), s(:int, 5)), s(:while_statement, :plus, s(:conditional, s(:name, :n)), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :-, s(:name, :n), s(:int, 1))))), s(:return, s(:name, :n)))
@expect = [Label, LoadConstant, GetSlot, RegToSlot, Branch, Label, GetSlot , @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Branch, Label, SlotToReg ,
GetSlot, LoadConstant, OperatorInstruction, GetSlot, RegToSlot, Label, GetSlot , SlotToReg, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot, Label, SlotToReg ,
GetSlot, IsPlus, GetSlot, GetSlot, RegToSlot, Label, FunctionReturn] SlotToReg, IsPlus, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
check check
end end
@ -30,9 +30,9 @@ module Register
@input = s(:statements, s(:assignment, s(:name, :n), s(:int, 10)), s(:while_statement, :plus, s(:conditional, s(:operator_value, :-, s(:name, :n), s(:int, 5))), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :+, s(:name, :n), s(:int, 1))), s(:return, s(:name, :n))))) @input = s(:statements, s(:assignment, s(:name, :n), s(:int, 10)), s(:while_statement, :plus, s(:conditional, s(:operator_value, :-, s(:name, :n), s(:int, 5))), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :+, s(:name, :n), s(:int, 1))), s(:return, s(:name, :n)))))
@expect = [Label, LoadConstant, GetSlot, RegToSlot, Branch, Label, GetSlot , @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Branch, Label, SlotToReg ,
GetSlot, LoadConstant, OperatorInstruction, GetSlot, RegToSlot, GetSlot, GetSlot , SlotToReg, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot, SlotToReg, SlotToReg ,
RegToSlot, Label, GetSlot, GetSlot, LoadConstant, OperatorInstruction, IsPlus , RegToSlot, Label, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsPlus ,
Label, FunctionReturn] Label, FunctionReturn]
check check
end end