From e3673e579cb48e3f2691a0ef30d73001e42f0bc8 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 16 Jul 2018 11:23:09 +0300 Subject: [PATCH] pass extra info into register init, not just value extra info may be hash, maybe just type info --- lib/risc/builtin/integer.rb | 4 ++-- lib/risc/callable_compiler.rb | 7 ++++--- lib/risc/method_compiler.rb | 6 +++--- lib/risc/register_value.rb | 20 ++++++++++++-------- test/mom/instruction/helper.rb | 2 +- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/risc/builtin/integer.rb b/lib/risc/builtin/integer.rb index 9548ef3c..7718a4b3 100644 --- a/lib/risc/builtin/integer.rb +++ b/lib/risc/builtin/integer.rb @@ -11,7 +11,7 @@ module Risc builder = compiler.compiler_builder(compiler.source) me = builder.add_known( :receiver ) builder.reduce_int( source , me ) - two = compiler.use_reg :fixnum , 2 + two = compiler.use_reg :fixnum , value: 2 builder.add_load_data( source , 2 , two ) builder.add_code Risc.op( source , :>> , me , two) builder.add_new_int(source,me , two) @@ -84,7 +84,7 @@ module Risc builder.reduce_int( s , me ) builder.reduce_int( s , tmp ) builder.reduce_int( s , q ) - const = compiler.use_reg :fixnum , 1 + const = compiler.use_reg :fixnum , value: 1 builder.add_load_data( s , 1 , const ) # int tmp = self >> 1 builder.add_code Risc.op( s , :>> , tmp , const) diff --git a/lib/risc/callable_compiler.rb b/lib/risc/callable_compiler.rb index fc85d92e..a9145f75 100644 --- a/lib/risc/callable_compiler.rb +++ b/lib/risc/callable_compiler.rb @@ -53,12 +53,13 @@ module Risc end # require a (temporary) register. code must give this back with release_reg - def use_reg( type , value = nil ) + # Second extra parameter may give extra info about the value, see RegisterValue + def use_reg( type , extra = {} ) raise "Not type #{type.inspect}" unless type.is_a?(Symbol) or type.is_a?(Parfait::Type) if @regs.empty? - reg = Risc.tmp_reg(type , value) + reg = Risc.tmp_reg(type , extra) else - reg = @regs.last.next_reg_use(type , value) + reg = @regs.last.next_reg_use(type , extra) end @regs << reg return reg diff --git a/lib/risc/method_compiler.rb b/lib/risc/method_compiler.rb index ccd6d6ad..194895ab 100644 --- a/lib/risc/method_compiler.rb +++ b/lib/risc/method_compiler.rb @@ -122,12 +122,12 @@ module Risc end # require a (temporary) register. code must give this back with release_reg - def use_reg( type , value = nil ) + def use_reg( type , extra = {} ) raise "Not type #{type.inspect}" unless type.is_a?(Symbol) or type.is_a?(Parfait::Type) if @regs.empty? - reg = Risc.tmp_reg(type , value) + reg = Risc.tmp_reg(type , extra) else - reg = @regs.last.next_reg_use(type , value) + reg = @regs.last.next_reg_use(type , extra) end @regs << reg return reg diff --git a/lib/risc/register_value.rb b/lib/risc/register_value.rb index d4b62395..62cdeaf2 100644 --- a/lib/risc/register_value.rb +++ b/lib/risc/register_value.rb @@ -3,6 +3,7 @@ module Risc # RegisterValue is like a variable name, a storage location. # The location is a register off course. # The type is always known, and sometimes the value too + # Or something about the value, like some instances types # # When participating in the builder dsl, a builder may be set to get the # results of dsl operations (like <<) back to the builder @@ -15,12 +16,16 @@ module Risc # The first arg is a symbol :r0 - :r12 # Second arg is the type, which may be given as the symbol of the class name # (internally we store the actual type instance, resolving any symbols) - def initialize( reg , type , value = nil) + # A third value may give extra information. This is a hash, where keys may + # be :value, or :value_XX or :type_XX to indicate value or type information + # for an XX instance + def initialize( reg , type , extra = {}) + raise "Not Hash #{extra}" unless extra.is_a?(Hash) raise "not reg #{reg}" unless self.class.look_like_reg( reg ) type = Parfait.object_space.get_type_by_class_name(type) if type.is_a?(Symbol) @type = type @symbol = reg - @value = value + @value = extra end # using the registers type, resolve the slot to an index @@ -57,20 +62,19 @@ module Risc new_left end - # resolve the type of the slot, by inferring from it's name - # Currently this is implemented in Risc.resolve_type , but code shoudl be moved here + # resolve the type of the slot, by inferring from it's name, using the type + # scope related slots are resolved by the compiler def resolve_new_type(slot, compiler) case slot when :frame , :arguments , :receiver type = compiler.resolve_type(slot) - when :name - type = Parfait.object_space.get_type_by_class_name( :Word ) when Symbol type = @type.type_for(slot) raise "Not found object #{slot}: in #{@type}" unless type else raise "Not implemented object #{slot}:#{slot.class}" end + #puts "RESOLVE in #{@type.class_name} #{slot}->#{type}" return type end @@ -183,8 +187,8 @@ module Risc # 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) - RegisterValue.new :r1 , type , value + def self.tmp_reg( type , extra = {}) + RegisterValue.new :r1 , type , extra end end diff --git a/test/mom/instruction/helper.rb b/test/mom/instruction/helper.rb index 968115db..b5562a64 100644 --- a/test/mom/instruction/helper.rb +++ b/test/mom/instruction/helper.rb @@ -8,7 +8,7 @@ module Mom return nil end def use_reg( type ) - Risc.tmp_reg(type , nil) + Risc.tmp_reg(type ) end def reset_regs