From 75d5fff611a3984f57b87598374df308cbf2c8d1 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 18 Apr 2018 19:27:46 +0300 Subject: [PATCH] let builder pass the source down, but inly once --- lib/risc/builder.rb | 16 ++++++++++++---- lib/risc/instruction.rb | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index a97548d7..533f9da6 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -32,7 +32,8 @@ module Risc reg = Risc.message_reg reg.builder = self elsif name.to_s.index("label") - reg = Risc.label( name.to_s , "#{name}_#{object_id}") + reg = Risc.label( @source , "#{name}_#{object_id}") + @source_used = true else type = Risc.resolve_type(name , @compiler) #checking reg = @compiler.use_reg( type.object_class.name ) @@ -43,13 +44,16 @@ module Risc end def if_zero( label ) - add_code Risc::IsZero.new("jump if zero" , label) + @source_used = true + add_code Risc::IsZero.new(@source , label) end def if_not_zero( label ) - add_code Risc::IsNotZero.new("jump if not zero" , label) + @source_used = true + add_code Risc::IsNotZero.new(@source , label) end def branch( label ) - add_code Risc::Branch.new("jump to" , label) + @source_used = true + add_code Risc::Branch.new(@source, label) end # build code using dsl (see __init__ or MessageSetup for examples) @@ -122,6 +126,10 @@ module Risc :function_return , :function_call, :op , :transfer , :reg_to_slot , :byte_to_reg , :reg_to_byte].each do |method| define_method("add_#{method}".to_sym) do |*args| + if not @source_used + args[0] = @source + @source_used = true + end add_code Risc.send( method , *args ) end end diff --git a/lib/risc/instruction.rb b/lib/risc/instruction.rb index 02f0ab20..40d5aa05 100644 --- a/lib/risc/instruction.rb +++ b/lib/risc/instruction.rb @@ -26,7 +26,8 @@ module Risc @source = source @next = nekst return unless source - raise "Source must be string or Instruction, not #{source.class}" unless source.is_a?(String) or source.is_a?(Mom::Instruction) + raise "Source must be string or Instruction, not #{source.class}" unless source.is_a?(String) or + source.is_a?(Mom::Instruction) or source.is_a?(Parfait::TypedMethod) end attr_reader :source