diff --git a/lib/arm/constants.rb b/lib/arm/constants.rb index ec139abc..6d843ae3 100644 --- a/lib/arm/constants.rb +++ b/lib/arm/constants.rb @@ -60,7 +60,7 @@ module Arm end def reg_code r_name raise "double r #{r_name}" if( :rr1 == r_name) - if r_name.is_a? ::Risc::RiscValue + if r_name.is_a? ::Risc::RegisterValue r_name = r_name.symbol end if r_name.is_a? Fixnum @@ -93,7 +93,7 @@ module Arm end end - Risc::RiscValue.class_eval do + Risc::RegisterValue.class_eval do def reg_no @symbol.to_s[1 .. -1].to_i end diff --git a/lib/arm/instructions/compare_instruction.rb b/lib/arm/instructions/compare_instruction.rb index 968514bf..0eeae0f7 100644 --- a/lib/arm/instructions/compare_instruction.rb +++ b/lib/arm/instructions/compare_instruction.rb @@ -18,19 +18,19 @@ module Arm rn , operand , immediate= @rn , @operand , 1 arg = @right - operand = Risc::RiscValue.new( arg , :Integer) if( arg.is_a? Symbol ) + operand = Risc::RegisterValue.new( arg , :Integer) if( arg.is_a? Symbol ) case operand when Numeric operand = arg raise "numeric literal operand to large #{arg.inspect}" unless (arg.fits_u8?) - when Symbol , ::Risc::RiscValue + when Symbol , ::Risc::RegisterValue immediate = 0 when Arm::Shift handle_shift else raise "invalid operand argument #{arg.inspect} , #{inspect}" end - val = (operand.is_a?(Symbol) or operand.is_a?(::Risc::RiscValue)) ? reg_code(operand) : operand + val = (operand.is_a?(Symbol) or operand.is_a?(::Risc::RegisterValue)) ? reg_code(operand) : operand val = 0 if val == nil val = shift(val , 0) raise inspect unless reg_code(@rd) diff --git a/lib/arm/instructions/logic_instruction.rb b/lib/arm/instructions/logic_instruction.rb index 77753f45..c454ddda 100644 --- a/lib/arm/instructions/logic_instruction.rb +++ b/lib/arm/instructions/logic_instruction.rb @@ -24,7 +24,7 @@ module Arm if (right.is_a?(Numeric)) operand = handle_numeric(right) - elsif (right.is_a?(Symbol) or right.is_a?(::Risc::RiscValue)) + elsif (right.is_a?(Symbol) or right.is_a?(::Risc::RegisterValue)) operand = reg_code(right) #integer means the register the integer is in (otherwise constant) immediate = 0 # ie not immediate is register else @@ -89,7 +89,7 @@ module Arm # this also loads constants, which are issued as pc relative adds def determine_operands if( @left.is_a?(Parfait::Object) or @left.is_a?(Risc::Label) or - (@left.is_a?(Symbol) and !Risc::RiscValue.look_like_reg(@left))) + (@left.is_a?(Symbol) and !Risc::RegisterValue.look_like_reg(@left))) left = @left left = left.address if left.is_a?(Risc::Label) # do pc relative addressing with the difference to the instuction diff --git a/lib/arm/instructions/memory_instruction.rb b/lib/arm/instructions/memory_instruction.rb index 92a57bc8..22b5c40e 100644 --- a/lib/arm/instructions/memory_instruction.rb +++ b/lib/arm/instructions/memory_instruction.rb @@ -24,8 +24,8 @@ module Arm #TODO better test, this operand integer (register) does not work. def assemble(io) arg = @left - arg = arg.symbol if( arg.is_a? ::Risc::RiscValue ) - is_reg = arg.is_a?(::Risc::RiscValue) + arg = arg.symbol if( arg.is_a? ::Risc::RegisterValue ) + is_reg = arg.is_a?(::Risc::RegisterValue) is_reg = (arg.to_s[0] == "r") if( arg.is_a?(Symbol) and not is_reg) raise "invalid operand argument #{arg.inspect} #{inspect}" unless (is_reg ) @@ -34,7 +34,7 @@ module Arm #not sure about these 2 constants. They produce the correct output for str r0 , r1 # but i can't help thinking that that is because they are not used in that instruction and # so it doesn't matter. Will see - if (operand.is_a?(Symbol) or operand.is_a?(::Risc::RiscValue)) + if (operand.is_a?(Symbol) or operand.is_a?(::Risc::RegisterValue)) val = reg_code(operand) i = 1 # not quite sure about this, but it gives the output of as. read read read. else @@ -66,7 +66,7 @@ module Arm def get_operand return @operand unless @right operand = @right - operand = operand.symbol if operand.is_a? ::Risc::RiscValue + operand = operand.symbol if operand.is_a? ::Risc::RegisterValue unless( operand.is_a? Symbol) # TODO test/check/understand: has no effect in current tests # add_offset = (operand < 0) ? 0 : 1 diff --git a/lib/arm/instructions/move_instruction.rb b/lib/arm/instructions/move_instruction.rb index 7621cd1a..a706d903 100644 --- a/lib/arm/instructions/move_instruction.rb +++ b/lib/arm/instructions/move_instruction.rb @@ -4,8 +4,8 @@ module Arm def initialize( to , from , options = {}) super(nil) @attributes = options - if( from.is_a?(Symbol) and Risc::RiscValue.look_like_reg(from) ) - from = Risc::RiscValue.new(from , :Integer) + if( from.is_a?(Symbol) and Risc::RegisterValue.look_like_reg(from) ) + from = Risc::RegisterValue.new(from , :Integer) end @from = from @to = to @@ -28,7 +28,7 @@ module Arm case right when Numeric operand = numeric_operand(right) - when Risc::RiscValue + when Risc::RegisterValue operand = reg_code(right) immediate = 0 # ie not immediate is register else diff --git a/lib/risc.rb b/lib/risc.rb index 62a9646e..e4583c56 100644 --- a/lib/risc.rb +++ b/lib/risc.rb @@ -35,7 +35,7 @@ end require_relative "risc/instruction" -require_relative "risc/risc_value" +require_relative "risc/register_value" require_relative "risc/text_writer" require_relative "risc/builtin" require_relative "risc/builder" diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index 1b14bf88..7634ffa7 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -162,7 +162,7 @@ module Risc # by the slots. All data (at any time) is in one of the instance variables of these two # objects. Risc defines module methods with the same names (and _reg) def self.resolve_to_register( reference ) - return reference if reference.is_a?(RiscValue) + return reference if reference.is_a?(RegisterValue) case reference when :message return message_reg @@ -175,7 +175,7 @@ module Risc # The first arg is a class name (possibly lowercase) and the second an instance variable name. def self.resolve_type( object , compiler ) - object = object.type if object.is_a?(RiscValue) + object = object.type if object.is_a?(RegisterValue) case object when :name type = Parfait.object_space.get_class_by_name( :Word ).instance_type @@ -206,7 +206,7 @@ module Risc # The class can be mapped to a register, and so we get a memory address (reg+index) # Third arg, compiler, is only needed to resolve receiver/arguments/frame def self.resolve_to_index(object , variable_name ,compiler = nil) - return variable_name if variable_name.is_a?(Integer) or variable_name.is_a?(RiscValue) + return variable_name if variable_name.is_a?(Integer) or variable_name.is_a?(RegisterValue) type = resolve_type(object , compiler) index = type.variable_index(variable_name) raise "Index not found for #{variable_name} in #{object} of type #{type}" unless index diff --git a/lib/risc/builtin/object.rb b/lib/risc/builtin/object.rb index 185c14c4..85b8d6b5 100644 --- a/lib/risc/builtin/object.rb +++ b/lib/risc/builtin/object.rb @@ -104,12 +104,12 @@ module Risc # This relies on linux to save and restore all registers # def save_message(builder) - r8 = RiscValue.new( :r8 , :Message) + r8 = RegisterValue.new( :r8 , :Message) builder.add_code Risc.transfer("save_message", Risc.message_reg , r8 ) end def restore_message(builder) - r8 = RiscValue.new( :r8 , :Message) + r8 = RegisterValue.new( :r8 , :Message) return_tmp = builder.compiler.use_reg :fixnum source = "_restore_message" # get the sys return out of the way diff --git a/lib/risc/builtin/word.rb b/lib/risc/builtin/word.rb index c094a83c..22667512 100644 --- a/lib/risc/builtin/word.rb +++ b/lib/risc/builtin/word.rb @@ -9,7 +9,7 @@ module Risc builder = compiler.builder(true, compiler.method) builder.add_slot_to_reg( "putstring" , :message , :receiver , :new_message ) index = Parfait::Word.get_length_index - reg = RiscValue.new(:r2 , :Integer) + reg = RegisterValue.new(:r2 , :Integer) builder.add_slot_to_reg( "putstring" , :new_message , index , reg ) Risc::Builtin::Object.emit_syscall( builder , :putstring ) compiler.add_mom( Mom::ReturnSequence.new) diff --git a/lib/risc/instructions/function_return.rb b/lib/risc/instructions/function_return.rb index ebcc9dc8..691b5195 100644 --- a/lib/risc/instructions/function_return.rb +++ b/lib/risc/instructions/function_return.rb @@ -7,7 +7,7 @@ module Risc def initialize( source , register ) super(source) @register = register - raise "Not register #{register}" unless RiscValue.look_like_reg(register) + raise "Not register #{register}" unless RegisterValue.look_like_reg(register) end attr_reader :register diff --git a/lib/risc/instructions/getter.rb b/lib/risc/instructions/getter.rb index 0d5cf8d8..564883eb 100644 --- a/lib/risc/instructions/getter.rb +++ b/lib/risc/instructions/getter.rb @@ -23,9 +23,9 @@ module Risc @index = index @register = register raise "index #{index}" if index.is_a?(Numeric) and index < 0 - raise "Not integer or reg #{index}" unless index.is_a?(Numeric) or RiscValue.look_like_reg(index) - raise "Not register #{register}" unless RiscValue.look_like_reg(register) - raise "Not register #{array}" unless RiscValue.look_like_reg(array) + raise "Not integer or reg #{index}" unless index.is_a?(Numeric) or RegisterValue.look_like_reg(index) + raise "Not register #{register}" unless RegisterValue.look_like_reg(register) + raise "Not register #{array}" unless RegisterValue.look_like_reg(array) end attr_accessor :array , :index , :register diff --git a/lib/risc/instructions/load_constant.rb b/lib/risc/instructions/load_constant.rb index bf277a77..55cf20f3 100644 --- a/lib/risc/instructions/load_constant.rb +++ b/lib/risc/instructions/load_constant.rb @@ -10,7 +10,7 @@ module Risc @register = register @constant = constant raise "Not Constant #{constant}" if constant.is_a?(Mom::SlotDefinition) - raise "Not register #{register}" unless RiscValue.look_like_reg(register) + raise "Not register #{register}" unless RegisterValue.look_like_reg(register) end attr_accessor :register , :constant diff --git a/lib/risc/instructions/load_data.rb b/lib/risc/instructions/load_data.rb index 63011187..58ab2d97 100644 --- a/lib/risc/instructions/load_data.rb +++ b/lib/risc/instructions/load_data.rb @@ -13,7 +13,7 @@ module Risc @register = register @constant = constant raise "Not Integer #{constant}" unless constant.is_a?(Integer) - raise "Not register #{register}" unless RiscValue.look_like_reg(register) + raise "Not register #{register}" unless RegisterValue.look_like_reg(register) end attr_accessor :register , :constant diff --git a/lib/risc/instructions/operator_instruction.rb b/lib/risc/instructions/operator_instruction.rb index a396ea91..9a12218b 100644 --- a/lib/risc/instructions/operator_instruction.rb +++ b/lib/risc/instructions/operator_instruction.rb @@ -17,8 +17,8 @@ module Risc raise "unsuported operator :#{operator}:" unless Risc.operators.include?(operator) @left = left @right = right - raise "Not register #{left}" unless RiscValue.look_like_reg(left) - raise "Not register #{right}" unless RiscValue.look_like_reg(right) + raise "Not register #{left}" unless RegisterValue.look_like_reg(left) + raise "Not register #{right}" unless RegisterValue.look_like_reg(right) end attr_reader :operator, :left , :right diff --git a/lib/risc/instructions/setter.rb b/lib/risc/instructions/setter.rb index 6290534d..8a99f159 100644 --- a/lib/risc/instructions/setter.rb +++ b/lib/risc/instructions/setter.rb @@ -22,9 +22,9 @@ module Risc @array = array @index = index # raise "index 0 " if index < 0 - raise "Not integer or reg #{index}" unless index.is_a?(Numeric) or RiscValue.look_like_reg(index) - raise "Not register #{register}" unless RiscValue.look_like_reg(register) - raise "Not register #{array}" unless RiscValue.look_like_reg(array) + raise "Not integer or reg #{index}" unless index.is_a?(Numeric) or RegisterValue.look_like_reg(index) + raise "Not register #{register}" unless RegisterValue.look_like_reg(register) + raise "Not register #{array}" unless RegisterValue.look_like_reg(array) end attr_accessor :register , :array , :index diff --git a/lib/risc/instructions/transfer.rb b/lib/risc/instructions/transfer.rb index 78c6930f..cb870015 100644 --- a/lib/risc/instructions/transfer.rb +++ b/lib/risc/instructions/transfer.rb @@ -20,8 +20,8 @@ module Risc super(source) @from = from @to = to - raise "Fix me #{from}" unless from.is_a? RiscValue - raise "Fix me #{to}" unless to.is_a? RiscValue + raise "Fix me #{from}" unless from.is_a? RegisterValue + raise "Fix me #{to}" unless to.is_a? RegisterValue end attr_reader :from, :to diff --git a/lib/risc/interpreter.rb b/lib/risc/interpreter.rb index 03b847d1..a1069353 100644 --- a/lib/risc/interpreter.rb +++ b/lib/risc/interpreter.rb @@ -70,8 +70,8 @@ module Risc end def get_register( reg ) - reg = reg.symbol if reg.is_a? Risc::RiscValue - raise "Not a register #{reg}" unless Risc::RiscValue.look_like_reg(reg) + reg = reg.symbol if reg.is_a? Risc::RegisterValue + raise "Not a register #{reg}" unless Risc::RegisterValue.look_like_reg(reg) @registers[reg] end @@ -87,7 +87,7 @@ module Risc @flags[:minus] = false end return if old === val - reg = reg.symbol if reg.is_a? Risc::RiscValue + reg = reg.symbol if reg.is_a? Risc::RegisterValue val = Parfait.object_space.nil_object if val.nil? #because that's what real code has @registers[reg] = val trigger(:register_changed, reg , old , val) diff --git a/lib/risc/risc_value.rb b/lib/risc/register_value.rb similarity index 82% rename from lib/risc/risc_value.rb rename to lib/risc/register_value.rb index 1fd1d4cd..49250980 100644 --- a/lib/risc/risc_value.rb +++ b/lib/risc/register_value.rb @@ -1,8 +1,8 @@ module Risc - # RiscValue is like a variable name, a storage location. The location is a register off course. + # RegisterValue is like a variable name, a storage location. The location is a register off course. - class RiscValue + class RegisterValue attr_reader :symbol , :type , :value @@ -26,7 +26,7 @@ module Risc end def self.look_like_reg is_it - return true if is_it.is_a? RiscValue + return true if is_it.is_a? RegisterValue return false unless is_it.is_a? Symbol if( [:lr , :pc].include? is_it ) return true @@ -40,7 +40,7 @@ module Risc def == other return false if other.nil? - return false if other.class != RiscValue + return false if other.class != RegisterValue symbol == other.symbol end @@ -49,7 +49,7 @@ module Risc int = @symbol[1,3].to_i raise "No more registers #{self}" if int > 11 sym = "r#{int + 1}".to_sym - RiscValue.new( sym , type, value) + RegisterValue.new( sym , type, value) end def rxf_reference_name @@ -57,16 +57,16 @@ module Risc end # can't overload "=" , so use shift for it. - # move the right side to the left. Left (this) is a RiscValue + # move the right side to the left. Left (this) is a RegisterValue # right value may be # - constant (Parfait object) , resulting in a LoadConstant - # - another RiscValue, resulting in a Transfer instruction + # - another RegisterValue, resulting in a Transfer instruction # - an RValue, resulting in an SlotToReg def <<( right ) case right when Parfait::Object , Symbol ins = Risc.load_constant("#{right.class} to #{self.type}" , right , self) - when RiscValue + when RegisterValue ins = Risc.transfer("#{right.type} to #{self.type}" , right , self) when RValue ins = Risc.slot_to_reg("#{right.register.type}[#{right.index}] -> #{self.type}" , right.register , right.index , self) @@ -78,7 +78,7 @@ module Risc end def -( right ) - raise "operators only on registers, not #{right.class}" unless right.is_a? RiscValue + raise "operators only on registers, not #{right.class}" unless right.is_a? RegisterValue op = Risc.op("#{self.type} - #{right.type}", :- , self , right ) builder.add_code(op) if builder op @@ -92,7 +92,7 @@ module Risc end end - # Just a struct, see comment for [] of RiscValue + # Just a struct, see comment for [] of RegisterValue # class RValue attr_reader :register , :index , :builder @@ -103,7 +103,7 @@ module Risc # fullfil the objects purpose by creating a RegToSlot instruction from # itself (the slot) and the register given def <<( reg ) - raise "not reg #{reg}" unless reg.is_a?(RiscValue) + raise "not reg #{reg}" unless reg.is_a?(RegisterValue) reg_to_slot = Risc.reg_to_slot("#{reg.type} -> #{register.type}[#{index}]" , reg , register, index) builder.add_code(reg_to_slot) if builder reg_to_slot @@ -113,19 +113,19 @@ module Risc # The register we use to store the current message object is :r0 def self.message_reg - RiscValue.new :r0 , :Message + RegisterValue.new :r0 , :Message end # The register we use to store the new message object is :r3 # The new message is the one being built, to be sent def self.new_message_reg - RiscValue.new :r1 , :Message + RegisterValue.new :r1 , :Message end # The first scratch register. There is a next_reg_use to get a next and next. # Current thinking is that scratch is schatch between instructions def self.tmp_reg( type , value = nil) - RiscValue.new :r1 , type , value + RegisterValue.new :r1 , type , value end end diff --git a/test/arm/test_move.rb b/test/arm/test_move.rb index cc55af17..f3e348c6 100644 --- a/test/arm/test_move.rb +++ b/test/arm/test_move.rb @@ -37,28 +37,28 @@ module Arm end def test_shiftr1 - code = @machine.mov :r1, :r2 , :shift_asr => Risc::RiscValue.new(:r3 , :Integer) + code = @machine.mov :r1, :r2 , :shift_asr => Risc::RegisterValue.new(:r3 , :Integer) assert_code code , :mov , [0x52,0x13,0xb0,0xe1] #e1 b0 13 52 end def test_shiftr2 - code = @machine.mov :r2, :r3 , :shift_asr => Risc::RiscValue.new(:r4 , :Integer) + code = @machine.mov :r2, :r3 , :shift_asr => Risc::RegisterValue.new(:r4 , :Integer) assert_code code , :mov , [0x53,0x24,0xb0,0xe1] #e1 b0 24 53 end def test_shiftr3 - code = @machine.mov :r3, :r4 , :shift_asr => Risc::RiscValue.new(:r5 , :Integer) + code = @machine.mov :r3, :r4 , :shift_asr => Risc::RegisterValue.new(:r5 , :Integer) assert_code code , :mov , [0x54,0x35,0xb0,0xe1] #e1 b0 35 54 end def test_shiftl1 - code = @machine.mov :r1, :r2 , :shift_lsr => Risc::RiscValue.new(:r3 , :Integer) + code = @machine.mov :r1, :r2 , :shift_lsr => Risc::RegisterValue.new(:r3 , :Integer) assert_code code , :mov , [0x32,0x13,0xb0,0xe1] #e1 b0 13 32 end def test_shiftl2 - code = @machine.mov :r2, :r3 , :shift_lsr => Risc::RiscValue.new(:r4 , :Integer) + code = @machine.mov :r2, :r3 , :shift_lsr => Risc::RegisterValue.new(:r4 , :Integer) assert_code code , :mov , [0x33,0x24,0xb0,0xe1] #e1 b0 24 33 end def test_shiftl3 - code = @machine.mov :r3, :r4 , :shift_lsr => Risc::RiscValue.new(:r5 , :Integer) + code = @machine.mov :r3, :r4 , :shift_lsr => Risc::RegisterValue.new(:r5 , :Integer) assert_code code , :mov , [0x34,0x35,0xb0,0xe1] #e1 b0 35 34 end diff --git a/test/risc/test_builder.rb b/test/risc/test_builder.rb index ae3ae19d..903be235 100644 --- a/test/risc/test_builder.rb +++ b/test/risc/test_builder.rb @@ -17,7 +17,7 @@ module Risc end def test_alloc_space reg = @builder.space - assert_equal RiscValue , reg.class + assert_equal RegisterValue , reg.class assert_equal :Space , reg.type end def test_next_message @@ -31,36 +31,36 @@ module Risc assert_equal :Message , reg.type end def test_returns_built - r1 = RiscValue.new(:r1 , :Space) + r1 = RegisterValue.new(:r1 , :Space) built = @builder.build{ space << r1 } assert_equal Transfer , built.class end def test_returns_two - r1 = RiscValue.new(:r1 , :Space) + r1 = RegisterValue.new(:r1 , :Space) built = @builder.build{ space << r1 ; space << r1} assert_equal Transfer , built.next.class end def test_returns_slot - r2 = RiscValue.new(:r2 , :Message) + r2 = RegisterValue.new(:r2 , :Message) r2.builder = @builder built = @builder.build{ r2 << space[:first_message] } assert_equal SlotToReg , built.class assert_equal :r1 , built.array.symbol end def test_returns_slot_reverse - r2 = RiscValue.new(:r2 , :Message) + r2 = RegisterValue.new(:r2 , :Message) r2.builder = @builder built = @builder.build{ r2 << space[:first_message] } assert_equal SlotToReg , built.class assert_equal :r1 , built.array.symbol end def test_reuses_names - r1 = RiscValue.new(:r1 , :Space) + r1 = RegisterValue.new(:r1 , :Space) built = @builder.build{ space << r1 ; space << r1} assert_equal built.to.symbol , built.next.to.symbol end def test_uses_message_as_message - r1 = RiscValue.new(:r1 , :Space) + r1 = RegisterValue.new(:r1 , :Space) built = @builder.build{ message[:receiver] << r1} assert_equal RegToSlot , built.class assert_equal :r0 , built.array.symbol @@ -105,7 +105,7 @@ module Risc @builder = Risc::MethodCompiler.new( @init ).builder(true, @init) end def test_inserts_built - r1 = RiscValue.new(:r1 , :Space) + r1 = RegisterValue.new(:r1 , :Space) @builder.build{ space << r1 } assert_equal Transfer , @init.risc_instructions.next.class , @init.risc_instructions.next end diff --git a/test/risc/test_risc_value.rb b/test/risc/test_risc_value.rb index eab9aaf8..20038feb 100644 --- a/test/risc/test_risc_value.rb +++ b/test/risc/test_risc_value.rb @@ -11,8 +11,8 @@ module Risc def setup Risc.machine.boot - @r0 = RiscValue.new(:r0 , :Message) - @r1 = RiscValue.new(:r1 , :Space) + @r0 = RegisterValue.new(:r0 , :Message) + @r1 = RegisterValue.new(:r1 , :Space) end def test_r0 assert_equal :r0 , @r0.symbol