rename risc_value to register_value

almost to register, but it still carries that value
This commit is contained in:
Torsten Ruger 2018-06-29 11:39:07 +03:00
parent 606c7bf906
commit d50893bb0f
21 changed files with 67 additions and 67 deletions

View File

@ -60,7 +60,7 @@ module Arm
end end
def reg_code r_name def reg_code r_name
raise "double r #{r_name}" if( :rr1 == 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 r_name = r_name.symbol
end end
if r_name.is_a? Fixnum if r_name.is_a? Fixnum
@ -93,7 +93,7 @@ module Arm
end end
end end
Risc::RiscValue.class_eval do Risc::RegisterValue.class_eval do
def reg_no def reg_no
@symbol.to_s[1 .. -1].to_i @symbol.to_s[1 .. -1].to_i
end end

View File

@ -18,19 +18,19 @@ module Arm
rn , operand , immediate= @rn , @operand , 1 rn , operand , immediate= @rn , @operand , 1
arg = @right 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 case operand
when Numeric when Numeric
operand = arg operand = arg
raise "numeric literal operand to large #{arg.inspect}" unless (arg.fits_u8?) raise "numeric literal operand to large #{arg.inspect}" unless (arg.fits_u8?)
when Symbol , ::Risc::RiscValue when Symbol , ::Risc::RegisterValue
immediate = 0 immediate = 0
when Arm::Shift when Arm::Shift
handle_shift handle_shift
else else
raise "invalid operand argument #{arg.inspect} , #{inspect}" raise "invalid operand argument #{arg.inspect} , #{inspect}"
end 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 = 0 if val == nil
val = shift(val , 0) val = shift(val , 0)
raise inspect unless reg_code(@rd) raise inspect unless reg_code(@rd)

View File

@ -24,7 +24,7 @@ module Arm
if (right.is_a?(Numeric)) if (right.is_a?(Numeric))
operand = handle_numeric(right) 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) operand = reg_code(right) #integer means the register the integer is in (otherwise constant)
immediate = 0 # ie not immediate is register immediate = 0 # ie not immediate is register
else else
@ -89,7 +89,7 @@ module Arm
# this also loads constants, which are issued as pc relative adds # this also loads constants, which are issued as pc relative adds
def determine_operands def determine_operands
if( @left.is_a?(Parfait::Object) or @left.is_a?(Risc::Label) or 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
left = left.address if left.is_a?(Risc::Label) left = left.address if left.is_a?(Risc::Label)
# do pc relative addressing with the difference to the instuction # do pc relative addressing with the difference to the instuction

View File

@ -24,8 +24,8 @@ module Arm
#TODO better test, this operand integer (register) does not work. #TODO better test, this operand integer (register) does not work.
def assemble(io) def assemble(io)
arg = @left arg = @left
arg = arg.symbol if( arg.is_a? ::Risc::RiscValue ) arg = arg.symbol if( arg.is_a? ::Risc::RegisterValue )
is_reg = arg.is_a?(::Risc::RiscValue) is_reg = arg.is_a?(::Risc::RegisterValue)
is_reg = (arg.to_s[0] == "r") if( arg.is_a?(Symbol) and not is_reg) 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 ) 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 #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 # 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 # 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) val = reg_code(operand)
i = 1 # not quite sure about this, but it gives the output of as. read read read. i = 1 # not quite sure about this, but it gives the output of as. read read read.
else else
@ -66,7 +66,7 @@ module Arm
def get_operand def get_operand
return @operand unless @right return @operand unless @right
operand = @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) unless( operand.is_a? Symbol)
# TODO test/check/understand: has no effect in current tests # TODO test/check/understand: has no effect in current tests
# add_offset = (operand < 0) ? 0 : 1 # add_offset = (operand < 0) ? 0 : 1

View File

@ -4,8 +4,8 @@ module Arm
def initialize( to , from , options = {}) def initialize( to , from , options = {})
super(nil) super(nil)
@attributes = options @attributes = options
if( from.is_a?(Symbol) and Risc::RiscValue.look_like_reg(from) ) if( from.is_a?(Symbol) and Risc::RegisterValue.look_like_reg(from) )
from = Risc::RiscValue.new(from , :Integer) from = Risc::RegisterValue.new(from , :Integer)
end end
@from = from @from = from
@to = to @to = to
@ -28,7 +28,7 @@ module Arm
case right case right
when Numeric when Numeric
operand = numeric_operand(right) operand = numeric_operand(right)
when Risc::RiscValue when Risc::RegisterValue
operand = reg_code(right) operand = reg_code(right)
immediate = 0 # ie not immediate is register immediate = 0 # ie not immediate is register
else else

View File

@ -35,7 +35,7 @@ end
require_relative "risc/instruction" require_relative "risc/instruction"
require_relative "risc/risc_value" require_relative "risc/register_value"
require_relative "risc/text_writer" require_relative "risc/text_writer"
require_relative "risc/builtin" require_relative "risc/builtin"
require_relative "risc/builder" require_relative "risc/builder"

View File

@ -162,7 +162,7 @@ module Risc
# by the slots. All data (at any time) is in one of the instance variables of these two # 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) # objects. Risc defines module methods with the same names (and _reg)
def self.resolve_to_register( reference ) def self.resolve_to_register( reference )
return reference if reference.is_a?(RiscValue) return reference if reference.is_a?(RegisterValue)
case reference case reference
when :message when :message
return message_reg 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. # The first arg is a class name (possibly lowercase) and the second an instance variable name.
def self.resolve_type( object , compiler ) def self.resolve_type( object , compiler )
object = object.type if object.is_a?(RiscValue) object = object.type if object.is_a?(RegisterValue)
case object case object
when :name when :name
type = Parfait.object_space.get_class_by_name( :Word ).instance_type 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) # 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 # Third arg, compiler, is only needed to resolve receiver/arguments/frame
def self.resolve_to_index(object , variable_name ,compiler = nil) 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) type = resolve_type(object , compiler)
index = type.variable_index(variable_name) index = type.variable_index(variable_name)
raise "Index not found for #{variable_name} in #{object} of type #{type}" unless index raise "Index not found for #{variable_name} in #{object} of type #{type}" unless index

View File

@ -104,12 +104,12 @@ module Risc
# This relies on linux to save and restore all registers # This relies on linux to save and restore all registers
# #
def save_message(builder) 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 ) builder.add_code Risc.transfer("save_message", Risc.message_reg , r8 )
end end
def restore_message(builder) def restore_message(builder)
r8 = RiscValue.new( :r8 , :Message) r8 = RegisterValue.new( :r8 , :Message)
return_tmp = builder.compiler.use_reg :fixnum return_tmp = builder.compiler.use_reg :fixnum
source = "_restore_message" source = "_restore_message"
# get the sys return out of the way # get the sys return out of the way

View File

@ -9,7 +9,7 @@ module Risc
builder = compiler.builder(true, compiler.method) builder = compiler.builder(true, compiler.method)
builder.add_slot_to_reg( "putstring" , :message , :receiver , :new_message ) builder.add_slot_to_reg( "putstring" , :message , :receiver , :new_message )
index = Parfait::Word.get_length_index 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 ) builder.add_slot_to_reg( "putstring" , :new_message , index , reg )
Risc::Builtin::Object.emit_syscall( builder , :putstring ) Risc::Builtin::Object.emit_syscall( builder , :putstring )
compiler.add_mom( Mom::ReturnSequence.new) compiler.add_mom( Mom::ReturnSequence.new)

View File

@ -7,7 +7,7 @@ module Risc
def initialize( source , register ) def initialize( source , register )
super(source) super(source)
@register = register @register = register
raise "Not register #{register}" unless RiscValue.look_like_reg(register) raise "Not register #{register}" unless RegisterValue.look_like_reg(register)
end end
attr_reader :register attr_reader :register

View File

@ -23,9 +23,9 @@ module Risc
@index = index @index = index
@register = register @register = register
raise "index #{index}" if index.is_a?(Numeric) and index < 0 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 integer or reg #{index}" unless index.is_a?(Numeric) or RegisterValue.look_like_reg(index)
raise "Not register #{register}" unless RiscValue.look_like_reg(register) raise "Not register #{register}" unless RegisterValue.look_like_reg(register)
raise "Not register #{array}" unless RiscValue.look_like_reg(array) raise "Not register #{array}" unless RegisterValue.look_like_reg(array)
end end
attr_accessor :array , :index , :register attr_accessor :array , :index , :register

View File

@ -10,7 +10,7 @@ module Risc
@register = register @register = register
@constant = constant @constant = constant
raise "Not Constant #{constant}" if constant.is_a?(Mom::SlotDefinition) 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 end
attr_accessor :register , :constant attr_accessor :register , :constant

View File

@ -13,7 +13,7 @@ module Risc
@register = register @register = register
@constant = constant @constant = constant
raise "Not Integer #{constant}" unless constant.is_a?(Integer) 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 end
attr_accessor :register , :constant attr_accessor :register , :constant

View File

@ -17,8 +17,8 @@ module Risc
raise "unsuported operator :#{operator}:" unless Risc.operators.include?(operator) raise "unsuported operator :#{operator}:" unless Risc.operators.include?(operator)
@left = left @left = left
@right = right @right = right
raise "Not register #{left}" unless RiscValue.look_like_reg(left) raise "Not register #{left}" unless RegisterValue.look_like_reg(left)
raise "Not register #{right}" unless RiscValue.look_like_reg(right) raise "Not register #{right}" unless RegisterValue.look_like_reg(right)
end end
attr_reader :operator, :left , :right attr_reader :operator, :left , :right

View File

@ -22,9 +22,9 @@ module Risc
@array = array @array = array
@index = index @index = index
# raise "index 0 " if index < 0 # 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 integer or reg #{index}" unless index.is_a?(Numeric) or RegisterValue.look_like_reg(index)
raise "Not register #{register}" unless RiscValue.look_like_reg(register) raise "Not register #{register}" unless RegisterValue.look_like_reg(register)
raise "Not register #{array}" unless RiscValue.look_like_reg(array) raise "Not register #{array}" unless RegisterValue.look_like_reg(array)
end end
attr_accessor :register , :array , :index attr_accessor :register , :array , :index

View File

@ -20,8 +20,8 @@ module Risc
super(source) super(source)
@from = from @from = from
@to = to @to = to
raise "Fix me #{from}" unless from.is_a? RiscValue raise "Fix me #{from}" unless from.is_a? RegisterValue
raise "Fix me #{to}" unless to.is_a? RiscValue raise "Fix me #{to}" unless to.is_a? RegisterValue
end end
attr_reader :from, :to attr_reader :from, :to

View File

@ -70,8 +70,8 @@ module Risc
end end
def get_register( reg ) def get_register( reg )
reg = reg.symbol if reg.is_a? Risc::RiscValue reg = reg.symbol if reg.is_a? Risc::RegisterValue
raise "Not a register #{reg}" unless Risc::RiscValue.look_like_reg(reg) raise "Not a register #{reg}" unless Risc::RegisterValue.look_like_reg(reg)
@registers[reg] @registers[reg]
end end
@ -87,7 +87,7 @@ module Risc
@flags[:minus] = false @flags[:minus] = false
end end
return if old === val 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 val = Parfait.object_space.nil_object if val.nil? #because that's what real code has
@registers[reg] = val @registers[reg] = val
trigger(:register_changed, reg , old , val) trigger(:register_changed, reg , old , val)

View File

@ -1,8 +1,8 @@
module Risc 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 attr_reader :symbol , :type , :value
@ -26,7 +26,7 @@ module Risc
end end
def self.look_like_reg is_it 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 return false unless is_it.is_a? Symbol
if( [:lr , :pc].include? is_it ) if( [:lr , :pc].include? is_it )
return true return true
@ -40,7 +40,7 @@ module Risc
def == other def == other
return false if other.nil? return false if other.nil?
return false if other.class != RiscValue return false if other.class != RegisterValue
symbol == other.symbol symbol == other.symbol
end end
@ -49,7 +49,7 @@ module Risc
int = @symbol[1,3].to_i int = @symbol[1,3].to_i
raise "No more registers #{self}" if int > 11 raise "No more registers #{self}" if int > 11
sym = "r#{int + 1}".to_sym sym = "r#{int + 1}".to_sym
RiscValue.new( sym , type, value) RegisterValue.new( sym , type, value)
end end
def rxf_reference_name def rxf_reference_name
@ -57,16 +57,16 @@ module Risc
end end
# can't overload "=" , so use shift for it. # 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 # right value may be
# - constant (Parfait object) , resulting in a LoadConstant # - 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 # - an RValue, resulting in an SlotToReg
def <<( right ) def <<( right )
case right case right
when Parfait::Object , Symbol when Parfait::Object , Symbol
ins = Risc.load_constant("#{right.class} to #{self.type}" , right , self) 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) ins = Risc.transfer("#{right.type} to #{self.type}" , right , self)
when RValue when RValue
ins = Risc.slot_to_reg("#{right.register.type}[#{right.index}] -> #{self.type}" , right.register , right.index , self) ins = Risc.slot_to_reg("#{right.register.type}[#{right.index}] -> #{self.type}" , right.register , right.index , self)
@ -78,7 +78,7 @@ module Risc
end end
def -( right ) 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 ) op = Risc.op("#{self.type} - #{right.type}", :- , self , right )
builder.add_code(op) if builder builder.add_code(op) if builder
op op
@ -92,7 +92,7 @@ module Risc
end end
end end
# Just a struct, see comment for [] of RiscValue # Just a struct, see comment for [] of RegisterValue
# #
class RValue class RValue
attr_reader :register , :index , :builder attr_reader :register , :index , :builder
@ -103,7 +103,7 @@ module Risc
# fullfil the objects purpose by creating a RegToSlot instruction from # fullfil the objects purpose by creating a RegToSlot instruction from
# itself (the slot) and the register given # itself (the slot) and the register given
def <<( reg ) 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) reg_to_slot = Risc.reg_to_slot("#{reg.type} -> #{register.type}[#{index}]" , reg , register, index)
builder.add_code(reg_to_slot) if builder builder.add_code(reg_to_slot) if builder
reg_to_slot reg_to_slot
@ -113,19 +113,19 @@ module Risc
# The register we use to store the current message object is :r0 # The register we use to store the current message object is :r0
def self.message_reg def self.message_reg
RiscValue.new :r0 , :Message RegisterValue.new :r0 , :Message
end end
# The register we use to store the new message object is :r3 # The register we use to store the new message object is :r3
# The new message is the one being built, to be sent # The new message is the one being built, to be sent
def self.new_message_reg def self.new_message_reg
RiscValue.new :r1 , :Message RegisterValue.new :r1 , :Message
end end
# The first scratch register. There is a next_reg_use to get a next and next. # 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 # Current thinking is that scratch is schatch between instructions
def self.tmp_reg( type , value = nil) def self.tmp_reg( type , value = nil)
RiscValue.new :r1 , type , value RegisterValue.new :r1 , type , value
end end
end end

View File

@ -37,28 +37,28 @@ module Arm
end end
def test_shiftr1 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 assert_code code , :mov , [0x52,0x13,0xb0,0xe1] #e1 b0 13 52
end end
def test_shiftr2 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 assert_code code , :mov , [0x53,0x24,0xb0,0xe1] #e1 b0 24 53
end end
def test_shiftr3 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 assert_code code , :mov , [0x54,0x35,0xb0,0xe1] #e1 b0 35 54
end end
def test_shiftl1 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 assert_code code , :mov , [0x32,0x13,0xb0,0xe1] #e1 b0 13 32
end end
def test_shiftl2 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 assert_code code , :mov , [0x33,0x24,0xb0,0xe1] #e1 b0 24 33
end end
def test_shiftl3 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 assert_code code , :mov , [0x34,0x35,0xb0,0xe1] #e1 b0 35 34
end end

View File

@ -17,7 +17,7 @@ module Risc
end end
def test_alloc_space def test_alloc_space
reg = @builder.space reg = @builder.space
assert_equal RiscValue , reg.class assert_equal RegisterValue , reg.class
assert_equal :Space , reg.type assert_equal :Space , reg.type
end end
def test_next_message def test_next_message
@ -31,36 +31,36 @@ module Risc
assert_equal :Message , reg.type assert_equal :Message , reg.type
end end
def test_returns_built def test_returns_built
r1 = RiscValue.new(:r1 , :Space) r1 = RegisterValue.new(:r1 , :Space)
built = @builder.build{ space << r1 } built = @builder.build{ space << r1 }
assert_equal Transfer , built.class assert_equal Transfer , built.class
end end
def test_returns_two def test_returns_two
r1 = RiscValue.new(:r1 , :Space) r1 = RegisterValue.new(:r1 , :Space)
built = @builder.build{ space << r1 ; space << r1} built = @builder.build{ space << r1 ; space << r1}
assert_equal Transfer , built.next.class assert_equal Transfer , built.next.class
end end
def test_returns_slot def test_returns_slot
r2 = RiscValue.new(:r2 , :Message) r2 = RegisterValue.new(:r2 , :Message)
r2.builder = @builder r2.builder = @builder
built = @builder.build{ r2 << space[:first_message] } built = @builder.build{ r2 << space[:first_message] }
assert_equal SlotToReg , built.class assert_equal SlotToReg , built.class
assert_equal :r1 , built.array.symbol assert_equal :r1 , built.array.symbol
end end
def test_returns_slot_reverse def test_returns_slot_reverse
r2 = RiscValue.new(:r2 , :Message) r2 = RegisterValue.new(:r2 , :Message)
r2.builder = @builder r2.builder = @builder
built = @builder.build{ r2 << space[:first_message] } built = @builder.build{ r2 << space[:first_message] }
assert_equal SlotToReg , built.class assert_equal SlotToReg , built.class
assert_equal :r1 , built.array.symbol assert_equal :r1 , built.array.symbol
end end
def test_reuses_names def test_reuses_names
r1 = RiscValue.new(:r1 , :Space) r1 = RegisterValue.new(:r1 , :Space)
built = @builder.build{ space << r1 ; space << r1} built = @builder.build{ space << r1 ; space << r1}
assert_equal built.to.symbol , built.next.to.symbol assert_equal built.to.symbol , built.next.to.symbol
end end
def test_uses_message_as_message def test_uses_message_as_message
r1 = RiscValue.new(:r1 , :Space) r1 = RegisterValue.new(:r1 , :Space)
built = @builder.build{ message[:receiver] << r1} built = @builder.build{ message[:receiver] << r1}
assert_equal RegToSlot , built.class assert_equal RegToSlot , built.class
assert_equal :r0 , built.array.symbol assert_equal :r0 , built.array.symbol
@ -105,7 +105,7 @@ module Risc
@builder = Risc::MethodCompiler.new( @init ).builder(true, @init) @builder = Risc::MethodCompiler.new( @init ).builder(true, @init)
end end
def test_inserts_built def test_inserts_built
r1 = RiscValue.new(:r1 , :Space) r1 = RegisterValue.new(:r1 , :Space)
@builder.build{ space << r1 } @builder.build{ space << r1 }
assert_equal Transfer , @init.risc_instructions.next.class , @init.risc_instructions.next assert_equal Transfer , @init.risc_instructions.next.class , @init.risc_instructions.next
end end

View File

@ -11,8 +11,8 @@ module Risc
def setup def setup
Risc.machine.boot Risc.machine.boot
@r0 = RiscValue.new(:r0 , :Message) @r0 = RegisterValue.new(:r0 , :Message)
@r1 = RiscValue.new(:r1 , :Space) @r1 = RegisterValue.new(:r1 , :Space)
end end
def test_r0 def test_r0
assert_equal :r0 , @r0.symbol assert_equal :r0 , @r0.symbol