Fix div10 and test

fix and use load_data (similar to load_constant)
and integrate into load_object when appropriate (ie for integers)
This commit is contained in:
2020-03-08 12:05:25 +02:00
parent bd02f69824
commit eed9ba082f
6 changed files with 85 additions and 45 deletions

View File

@ -90,12 +90,19 @@ module Risc
copied
end
# Load a constant, meaning create a LoadConstant instruction for the constant
# Load a constant, meaning create a LoadConstant or LoadData instruction for the
# given constant. Integers create LoadData (meaning the integer is encoded into
# the actual instruction), Parfait::Objects create LoadConstant, where a pointer
# to the object is loaded.
# add the instruction to the code and return the register_value that was created
# for further use
# register may be passed in (epecially in mcro building) as second arg
def load_object( object , into = nil)
ins = Risc.load_constant("load to #{object}" , object , into)
if(object.is_a? Integer)
ins = Risc.load_data("load data #{object}" , object , into)
else
ins = Risc.load_constant("load to #{object}" , object , into)
end
ins.register.set_compiler(self)
add_code ins
# todo for constants (not objects)

View File

@ -22,7 +22,10 @@ module Risc
end
end
def self.load_data( source , constant , register )
LoadData.new( source , constant , register)
def self.load_data( source , value , register = nil )
raise "can only load integers, not #{value}" unless value.is_a?(Integer)
type = Parfait.object_space.get_type_by_class_name(:Integer)
register = RegisterValue.new( "fix_#{value}".to_sym , type ) unless register
LoadData.new( source , value , register)
end
end