From f648bf7bd5d2714e11e96a99fb2f42a1b7e06282 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 25 Dec 2016 18:05:39 +0200 Subject: [PATCH] rename also get_slot, to slot_to_reg makes source and target clear --- CodeStyle.md | 2 +- lib/arm/translator.rb | 2 +- lib/register/builtin/compile_helper.rb | 4 ++-- lib/register/builtin/kernel.rb | 2 +- lib/register/builtin/object.rb | 2 +- lib/register/builtin/word.rb | 4 ++-- lib/register/instruction.rb | 2 +- lib/register/instructions/function_call.rb | 2 +- lib/register/instructions/get_byte.rb | 2 +- lib/register/instructions/getter.rb | 4 ++-- lib/register/instructions/reg_to_slot.rb | 2 +- .../instructions/register_transfer.rb | 2 +- .../{get_slot.rb => slot_to_reg.rb} | 14 ++++++------- lib/register/interpreter.rb | 6 +++--- lib/typed/method_compiler/assignment.rb | 2 +- lib/typed/method_compiler/call_site.rb | 10 +++++----- lib/typed/method_compiler/field_access.rb | 2 +- lib/typed/method_compiler/name_expression.rb | 8 ++++---- test/register/interpreter/test_add.rb | 4 ++-- test/register/interpreter/test_change.rb | 2 +- test/register/interpreter/test_get_byte.rb | 10 +++++----- test/register/interpreter/test_if.rb | 20 +++++++++---------- test/register/interpreter/test_mult.rb | 2 +- test/register/interpreter/test_plus.rb | 2 +- test/register/interpreter/test_puts.rb | 10 +++++----- test/register/interpreter/test_set_byte.rb | 10 +++++----- test/typed/statements/test_assign.rb | 20 +++++++++---------- test/typed/statements/test_call.rb | 20 +++++++++---------- test/typed/statements/test_class.rb | 6 +++--- test/typed/statements/test_fields.rb | 10 +++++----- test/typed/statements/test_return.rb | 10 +++++----- test/typed/statements/test_while.rb | 12 +++++------ 32 files changed, 105 insertions(+), 105 deletions(-) rename lib/register/instructions/{get_slot.rb => slot_to_reg.rb} (68%) diff --git a/CodeStyle.md b/CodeStyle.md index f9152e8d..20a561cd 100644 --- a/CodeStyle.md +++ b/CodeStyle.md @@ -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 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. As the example shows, in this case the module function name should be the instruction class name. diff --git a/lib/arm/translator.rb b/lib/arm/translator.rb index f7b0cb52..023d7b5d 100644 --- a/lib/arm/translator.rb +++ b/lib/arm/translator.rb @@ -37,7 +37,7 @@ module Arm ArmMachine.mov( code.to , code.from) end - def translate_GetSlot( code ) + def translate_SlotToReg( code ) ArmMachine.ldr( *slot_args_for(code) ) end diff --git a/lib/register/builtin/compile_helper.rb b/lib/register/builtin/compile_helper.rb index 63a1ef08..28581269 100644 --- a/lib/register/builtin/compile_helper.rb +++ b/lib/register/builtin/compile_helper.rb @@ -8,7 +8,7 @@ module Register me = compiler.process( Typed::Tree::NameExpression.new( :self) ) # Load the argument 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 end @@ -20,7 +20,7 @@ module Register # Load the value def load_arg_at(compiler, source , at) 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 end diff --git a/lib/register/builtin/kernel.rb b/lib/register/builtin/kernel.rb index 90e31838..c4542152 100644 --- a/lib/register/builtin/kernel.rb +++ b/lib/register/builtin/kernel.rb @@ -19,7 +19,7 @@ module Register compiler.add_code LoadConstant.new(source, space , space_reg) message_ind = Register.resolve_index( :space , :first_message ) # 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) 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}" ) diff --git a/lib/register/builtin/object.rb b/lib/register/builtin/object.rb index 1f4c9250..10534c7d 100644 --- a/lib/register/builtin/object.rb +++ b/lib/register/builtin/object.rb @@ -14,7 +14,7 @@ module Register source = "get_internal_word" me , index = self_and_int_arg(compiler,source) # 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 compiler.add_code Register.reg_to_slot( source , me , :message , :return_value) return compiler.method diff --git a/lib/register/builtin/word.rb b/lib/register/builtin/word.rb index dd52e122..c965a0eb 100644 --- a/lib/register/builtin/word.rb +++ b/lib/register/builtin/word.rb @@ -8,10 +8,10 @@ module Register def putstring context 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 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 ) compiler.method end diff --git a/lib/register/instruction.rb b/lib/register/instruction.rb index 9d92b16a..98f535d4 100644 --- a/lib/register/instruction.rb +++ b/lib/register/instruction.rb @@ -120,7 +120,7 @@ end require_relative "instructions/setter" require_relative "instructions/getter" 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/get_byte" require_relative "instructions/load_constant" diff --git a/lib/register/instructions/function_call.rb b/lib/register/instructions/function_call.rb index dcb8dd07..5cf9d25f 100644 --- a/lib/register/instructions/function_call.rb +++ b/lib/register/instructions/function_call.rb @@ -29,6 +29,6 @@ module Register # move the current message to new_message compiler.add_code Register::RegisterTransfer.new(source, Register.message_reg , Register.new_message_reg ) # 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 diff --git a/lib/register/instructions/get_byte.rb b/lib/register/instructions/get_byte.rb index b888953d..96c35411 100644 --- a/lib/register/instructions/get_byte.rb +++ b/lib/register/instructions/get_byte.rb @@ -10,7 +10,7 @@ module Register # If you had a c array (of int8) and index offset # the instruction would do register = array[index] # 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 # super # end diff --git a/lib/register/instructions/getter.rb b/lib/register/instructions/getter.rb index c3292355..dd4ed964 100644 --- a/lib/register/instructions/getter.rb +++ b/lib/register/instructions/getter.rb @@ -1,6 +1,6 @@ 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 # @@ -16,7 +16,7 @@ module Register # If you had a c array and index offset # the instruction would do register = array[index] # 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 super(source) @array = array diff --git a/lib/register/instructions/reg_to_slot.rb b/lib/register/instructions/reg_to_slot.rb index 00821b91..bb486b1f 100644 --- a/lib/register/instructions/reg_to_slot.rb +++ b/lib/register/instructions/reg_to_slot.rb @@ -1,7 +1,7 @@ module 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) # This is because that is what cpu's can do. In programming terms this would be accessing diff --git a/lib/register/instructions/register_transfer.rb b/lib/register/instructions/register_transfer.rb index 87aa1e2e..7a04bf8c 100644 --- a/lib/register/instructions/register_transfer.rb +++ b/lib/register/instructions/register_transfer.rb @@ -3,7 +3,7 @@ module Register # transfer the constents of one register to another. # 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) # diff --git a/lib/register/instructions/get_slot.rb b/lib/register/instructions/slot_to_reg.rb similarity index 68% rename from lib/register/instructions/get_slot.rb rename to lib/register/instructions/slot_to_reg.rb index f8c6a306..19d0a226 100644 --- a/lib/register/instructions/get_slot.rb +++ b/lib/register/instructions/slot_to_reg.rb @@ -1,20 +1,20 @@ 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. # Both use a base memory (a register) # 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 - class GetSlot < Getter + class SlotToReg < Getter # If you had a c array and index offset # the instruction would do register = array[index] # 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 # super # end @@ -22,13 +22,13 @@ module Register 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 # 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) array = resolve_to_register array to = resolve_to_register to - GetSlot.new( source , array , index , to) + SlotToReg.new( source , array , index , to) end end diff --git a/lib/register/interpreter.rb b/lib/register/interpreter.rb index 5b37a1ce..09e2b5f2 100644 --- a/lib/register/interpreter.rb +++ b/lib/register/interpreter.rb @@ -7,8 +7,8 @@ module Register # interpreting it is not so terribly difficult. # # 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 - # will be executed by method execute_GetSlot + # (as a cpu would), and then there is a method for each instruction. Eg an instruction SlotToReg + # will be executed by method execute_SlotToReg # # 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) @@ -126,7 +126,7 @@ module Register true end - def execute_GetSlot + def execute_SlotToReg object = get_register( @instruction.array ) if( @instruction.index.is_a?(Numeric) ) index = @instruction.index diff --git a/lib/typed/method_compiler/assignment.rb b/lib/typed/method_compiler/assignment.rb index 0809f03c..b15fad87 100644 --- a/lib/typed/method_compiler/assignment.rb +++ b/lib/typed/method_compiler/assignment.rb @@ -26,7 +26,7 @@ module Typed return nil unless index end # 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 ) end end diff --git a/lib/typed/method_compiler/call_site.rb b/lib/typed/method_compiler/call_site.rb index a70e4568..ea4b308b 100644 --- a/lib/typed/method_compiler/call_site.rb +++ b/lib/typed/method_compiler/call_site.rb @@ -7,7 +7,7 @@ module Typed reset_regs #move the new message (that we need to populate to make a call) to std register 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 ) type = get_my_type(me) # move our receiver there @@ -19,7 +19,7 @@ module Typed do_call(type , statement) # the effect of the method is that the NewMessage Return slot will be filled, return it # 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 end @@ -30,7 +30,7 @@ module Typed me = process( statement.receiver ) else 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 me end @@ -67,7 +67,7 @@ module Typed args_reg = use_reg(:Type , @method.arguments ) list_reg = use_reg(:NamedList , arguments ) 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 ) #FIXME need to set type of locals too. sama sama @@ -83,7 +83,7 @@ module Typed val = process( arg) raise "Not register #{val}" unless val.is_a?(Register::RegisterValue) 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) set = Register.reg_to_slot( arg , val , list_reg , i + 1 ) add_code set diff --git a/lib/typed/method_compiler/field_access.rb b/lib/typed/method_compiler/field_access.rb index 52ea1503..8aec8cbe 100644 --- a/lib/typed/method_compiler/field_access.rb +++ b/lib/typed/method_compiler/field_access.rb @@ -15,7 +15,7 @@ module Typed raise "no such field:#{field_name} for class #{type.inspect}" unless 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 end diff --git a/lib/typed/method_compiler/name_expression.rb b/lib/typed/method_compiler/name_expression.rb index cdf5b60e..d5e8f264 100644 --- a/lib/typed/method_compiler/name_expression.rb +++ b/lib/typed/method_compiler/name_expression.rb @@ -14,7 +14,7 @@ module Typed if( index = @method.has_arg(name)) ret = use_reg @method.argument_type(index) #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 end # or a local so it is in the named_list @@ -27,15 +27,15 @@ module Typed index = @method.has_local( statement.name ) raise "must define variable '#{statement.name}' before using it" unless index 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 ) - add_code Register.get_slot(statement , named_list , index, ret ) + add_code Register.slot_to_reg(statement , named_list , index, ret ) return ret end def handle_special_self(statement) 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 end diff --git a/test/register/interpreter/test_add.rb b/test/register/interpreter/test_add.rb index aaf55be9..b22fbb92 100644 --- a/test/register/interpreter/test_add.rb +++ b/test/register/interpreter/test_add.rb @@ -17,14 +17,14 @@ HERE def test_chain #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","OperatorInstruction","RegToSlot","Label","FunctionReturn", "RegisterTransfer","Syscall","NilClass"] end def test_get - assert_equal Register::GetSlot , ticks(4).class + assert_equal Register::SlotToReg , ticks(4).class assert @interpreter.get_register( :r2 ) assert Integer , @interpreter.get_register( :r2 ).class end diff --git a/test/register/interpreter/test_change.rb b/test/register/interpreter/test_change.rb index e2434036..20df0350 100644 --- a/test/register/interpreter/test_change.rb +++ b/test/register/interpreter/test_change.rb @@ -36,7 +36,7 @@ class AddChange < MiniTest::Test def test_chain #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","OperatorInstruction","RegToSlot","Label","FunctionReturn", "RegisterTransfer","Syscall","NilClass"] diff --git a/test/register/interpreter/test_get_byte.rb b/test/register/interpreter/test_get_byte.rb index 5b1f715d..b38173df 100644 --- a/test/register/interpreter/test_get_byte.rb +++ b/test/register/interpreter/test_get_byte.rb @@ -20,13 +20,13 @@ HERE def test_chain #show_ticks # get output of what is - check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot", - "LoadConstant","RegToSlot","FunctionCall","Label","GetSlot", + check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", + "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg", "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", "RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot", "LoadConstant","RegToSlot","RegisterTransfer","FunctionCall","Label", - "GetSlot","GetSlot","GetSlot","SetByte","Label", - "FunctionReturn","RegisterTransfer","GetSlot","GetSlot","Label", + "SlotToReg","SlotToReg","SlotToReg","SetByte","Label", + "FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg","Label", "FunctionReturn","RegisterTransfer","Syscall","NilClass"] end @@ -42,7 +42,7 @@ HERE assert_equal :r2, @interpreter.instruction.array.symbol end def test_get - assert_equal Register::GetSlot , ticks(4).class + assert_equal Register::SlotToReg , ticks(4).class assert @interpreter.get_register( :r1 ) assert Integer , @interpreter.get_register( :r1 ).class end diff --git a/test/register/interpreter/test_if.rb b/test/register/interpreter/test_if.rb index c65c4628..a2a57780 100644 --- a/test/register/interpreter/test_if.rb +++ b/test/register/interpreter/test_if.rb @@ -33,18 +33,18 @@ HERE end def test_if #show_ticks # get output of what is - check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot", - "LoadConstant","RegToSlot","FunctionCall","Label","GetSlot", - "GetSlot","RegToSlot","LoadConstant","RegToSlot","LoadConstant", + check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", + "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg", + "SlotToReg","RegToSlot","LoadConstant","RegToSlot","LoadConstant", "RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot", - "RegisterTransfer","FunctionCall","Label","GetSlot","LoadConstant", - "OperatorInstruction","IsZero","GetSlot","LoadConstant","RegToSlot", + "RegisterTransfer","FunctionCall","Label","SlotToReg","LoadConstant", + "OperatorInstruction","IsZero","SlotToReg","LoadConstant","RegToSlot", "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", - "RegToSlot","RegisterTransfer","FunctionCall","Label","GetSlot", - "GetSlot","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer", - "RegToSlot","Label","FunctionReturn","RegisterTransfer","GetSlot", - "GetSlot","Branch","Label","Label","FunctionReturn", - "RegisterTransfer","GetSlot","GetSlot","Label","FunctionReturn", + "RegToSlot","RegisterTransfer","FunctionCall","Label","SlotToReg", + "SlotToReg","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer", + "RegToSlot","Label","FunctionReturn","RegisterTransfer","SlotToReg", + "SlotToReg","Branch","Label","Label","FunctionReturn", + "RegisterTransfer","SlotToReg","SlotToReg","Label","FunctionReturn", "RegisterTransfer","Syscall","NilClass"] end end diff --git a/test/register/interpreter/test_mult.rb b/test/register/interpreter/test_mult.rb index 703c3f68..127ff8e5 100644 --- a/test/register/interpreter/test_mult.rb +++ b/test/register/interpreter/test_mult.rb @@ -19,7 +19,7 @@ HERE def test_mult #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","OperatorInstruction","RegToSlot","Label","FunctionReturn", "RegisterTransfer","Syscall","NilClass"] diff --git a/test/register/interpreter/test_plus.rb b/test/register/interpreter/test_plus.rb index ed88771d..8d6cd368 100644 --- a/test/register/interpreter/test_plus.rb +++ b/test/register/interpreter/test_plus.rb @@ -17,7 +17,7 @@ HERE def test_add #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","OperatorInstruction","RegToSlot","Label","FunctionReturn", "RegisterTransfer","Syscall","NilClass"] diff --git a/test/register/interpreter/test_puts.rb b/test/register/interpreter/test_puts.rb index b2e9d282..ba5c52f8 100644 --- a/test/register/interpreter/test_puts.rb +++ b/test/register/interpreter/test_puts.rb @@ -17,13 +17,13 @@ HERE def test_chain #show_ticks # get output of what is - check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot", - "LoadConstant","RegToSlot","FunctionCall","Label","GetSlot", + check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", + "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg", "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", "RegToSlot","LoadConstant","RegToSlot","RegisterTransfer","FunctionCall", - "Label","GetSlot","GetSlot","RegisterTransfer","Syscall", + "Label","SlotToReg","SlotToReg","RegisterTransfer","Syscall", "RegisterTransfer","RegisterTransfer","RegToSlot","Label","FunctionReturn", - "RegisterTransfer","GetSlot","GetSlot","Label","FunctionReturn", + "RegisterTransfer","SlotToReg","SlotToReg","Label","FunctionReturn", "RegisterTransfer","Syscall","NilClass"] end @@ -39,7 +39,7 @@ HERE assert_equal :r2, @interpreter.instruction.array.symbol end def test_get - assert_equal Register::GetSlot , ticks(4).class + assert_equal Register::SlotToReg , ticks(4).class assert @interpreter.get_register( :r1 ) assert Integer , @interpreter.get_register( :r1 ).class end diff --git a/test/register/interpreter/test_set_byte.rb b/test/register/interpreter/test_set_byte.rb index 37d9d364..1ea79934 100644 --- a/test/register/interpreter/test_set_byte.rb +++ b/test/register/interpreter/test_set_byte.rb @@ -20,13 +20,13 @@ HERE def test_chain #show_ticks # get output of what is - check_chain ["Branch","Label","LoadConstant","GetSlot","RegToSlot", - "LoadConstant","RegToSlot","FunctionCall","Label","GetSlot", + check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", + "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg", "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", "RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot", - "RegisterTransfer","FunctionCall","Label","GetSlot","GetSlot", + "RegisterTransfer","FunctionCall","Label","SlotToReg","SlotToReg", "GetByte","RegToSlot","Label","FunctionReturn","RegisterTransfer", - "GetSlot","GetSlot","Label","FunctionReturn","RegisterTransfer", + "SlotToReg","SlotToReg","Label","FunctionReturn","RegisterTransfer", "Syscall","NilClass"] end @@ -42,7 +42,7 @@ HERE assert_equal :r2, @interpreter.instruction.array.symbol end def test_get - assert_equal Register::GetSlot , ticks(4).class + assert_equal Register::SlotToReg , ticks(4).class assert @interpreter.get_register( :r1 ) assert Integer , @interpreter.get_register( :r1 ).class end diff --git a/test/typed/statements/test_assign.rb b/test/typed/statements/test_assign.rb index 682fc7fe..422532a6 100644 --- a/test/typed/statements/test_assign.rb +++ b/test/typed/statements/test_assign.rb @@ -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)))) - @expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, GetSlot, RegToSlot, Label , + @expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot, Label , FunctionReturn] check end @@ -18,7 +18,7 @@ class TestAssignStatement < MiniTest::Test Register.machine.space.get_main.add_local(:r , :Integer) @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 end @@ -27,34 +27,34 @@ class TestAssignStatement < MiniTest::Test @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 end def test_assign_call Register.machine.space.get_main.add_local(:r , :Integer) @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 , - GetSlot, GetSlot, GetSlot, RegToSlot, Label, FunctionReturn] + SlotToReg, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn] check end def test_named_list_get 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))) - @expect = [Label, LoadConstant, GetSlot, RegToSlot, GetSlot, GetSlot, RegToSlot , + @expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot , Label, FunctionReturn] was = check 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}" end def test_assign_int Register.machine.space.get_main.add_local(:r , :Integer) @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 set = was.next(3) 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 Register.machine.space.get_main.add_argument(:balr , :Integer) @input = s(:statements, s(:return, s(:name, :balr))) - @expect = [Label, GetSlot, RegToSlot, Label, FunctionReturn] + @expect = [Label, SlotToReg, RegToSlot, Label, FunctionReturn] was = check 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}" end end diff --git a/test/typed/statements/test_call.rb b/test/typed/statements/test_call.rb index 0b4d2c37..3acf0c0e 100644 --- a/test/typed/statements/test_call.rb +++ b/test/typed/statements/test_call.rb @@ -7,9 +7,9 @@ class TestCallStatement < MiniTest::Test def test_call_constant_int clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1))) @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 , - GetSlot, GetSlot, Label, FunctionReturn] + SlotToReg, SlotToReg, Label, FunctionReturn] check end @@ -18,9 +18,9 @@ class TestCallStatement < MiniTest::Test clean_compile :Word, :putstr,{}, s(:statements, s(:return, s(:int, 1))) @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 , - GetSlot, GetSlot, Label, FunctionReturn] + SlotToReg, SlotToReg, Label, FunctionReturn] check end @@ -29,9 +29,9 @@ class TestCallStatement < MiniTest::Test 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)))) - @expect = [Label, LoadConstant, GetSlot, RegToSlot, GetSlot, GetSlot, GetSlot , + @expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg , RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot , - RegisterTransfer, FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, Label , + RegisterTransfer, FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, Label , FunctionReturn] check end @@ -41,9 +41,9 @@ class TestCallStatement < MiniTest::Test 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)))) - @expect = [Label, GetSlot, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot , + @expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot , LoadConstant, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label , - RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn] + RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn] check end @@ -58,9 +58,9 @@ int main() end end HERE - @expect = [Label, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot, LoadConstant , + @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant , RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall , - Label, RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn] + Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn] was = check set = was.next(7) assert_equal RegToSlot , set.class diff --git a/test/typed/statements/test_class.rb b/test/typed/statements/test_class.rb index 9581f176..03f29fa5 100644 --- a/test/typed/statements/test_class.rb +++ b/test/typed/statements/test_class.rb @@ -20,9 +20,9 @@ class TestClassStatements < MiniTest::Test # class_def # @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 , - # GetSlot, GetSlot, RegToSlot, Label, FunctionReturn] + # SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn] # check end @@ -31,7 +31,7 @@ class TestClassStatements < MiniTest::Test #FIXME class_field handling unclear at the moment # @input =s(:statements, s(:return, s(:field_access, s(:receiver, s(:name, :self)), # s(:field,s(:name, :boo2))))) - # @expect = [Label, GetSlot,GetSlot,RegToSlot,Label,FunctionReturn] + # @expect = [Label, SlotToReg,SlotToReg,RegToSlot,Label,FunctionReturn] # check end end diff --git a/test/typed/statements/test_fields.rb b/test/typed/statements/test_fields.rb index 5f218bbc..71054e09 100644 --- a/test/typed/statements/test_fields.rb +++ b/test/typed/statements/test_fields.rb @@ -9,7 +9,7 @@ module Register Register.machine.space.get_main.add_local( :m , :Message) @input = s(:statements, s(:return, s(:field_access, 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 end @@ -20,9 +20,9 @@ module Register 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))))) - @expect = [Label, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot, LoadConstant , - RegToSlot, GetSlot, GetSlot, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer , - FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, RegToSlot, Label , + @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant , + RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer , + FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, Label , FunctionReturn] check end @@ -31,7 +31,7 @@ module Register 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))) - @expect = [Label, RegisterTransfer, GetSlot, GetSlot, RegToSlot, GetSlot, GetSlot , + @expect = [Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg , RegToSlot, Label, FunctionReturn] check end diff --git a/test/typed/statements/test_return.rb b/test/typed/statements/test_return.rb index 996dccc0..a729c269 100644 --- a/test/typed/statements/test_return.rb +++ b/test/typed/statements/test_return.rb @@ -13,30 +13,30 @@ class TestReturnStatement < MiniTest::Test def test_return_local Register.machine.space.get_main.add_local(:runner , :Integer) @input = s(:statements, s(:return, s(:name, :runner))) - @expect = [Label, GetSlot,GetSlot ,RegToSlot,Label,FunctionReturn] + @expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn] check end def test_return_local_assign 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))) - @expect = [Label, LoadConstant,GetSlot,RegToSlot,GetSlot,GetSlot ,RegToSlot, + @expect = [Label, LoadConstant,SlotToReg,RegToSlot,SlotToReg,SlotToReg ,RegToSlot, Label,FunctionReturn] check end def test_return_call @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 , - GetSlot, GetSlot, RegToSlot, Label, FunctionReturn] + SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn] check end def pest_return_space_length # need to add runtime first 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))))) - @expect = [Label, GetSlot,GetSlot ,RegToSlot,Label,FunctionReturn] + @expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn] check end diff --git a/test/typed/statements/test_while.rb b/test/typed/statements/test_while.rb index 890f156b..3a6fbc19 100644 --- a/test/typed/statements/test_while.rb +++ b/test/typed/statements/test_while.rb @@ -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))) - @expect = [Label, LoadConstant, GetSlot, RegToSlot, Branch, Label, GetSlot , - GetSlot, LoadConstant, OperatorInstruction, GetSlot, RegToSlot, Label, GetSlot , - GetSlot, IsPlus, GetSlot, GetSlot, RegToSlot, Label, FunctionReturn] + @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Branch, Label, SlotToReg , + SlotToReg, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot, Label, SlotToReg , + SlotToReg, IsPlus, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn] check 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))))) - @expect = [Label, LoadConstant, GetSlot, RegToSlot, Branch, Label, GetSlot , - GetSlot, LoadConstant, OperatorInstruction, GetSlot, RegToSlot, GetSlot, GetSlot , - RegToSlot, Label, GetSlot, GetSlot, LoadConstant, OperatorInstruction, IsPlus , + @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Branch, Label, SlotToReg , + SlotToReg, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot, SlotToReg, SlotToReg , + RegToSlot, Label, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsPlus , Label, FunctionReturn] check end