let builder pass the source down, but inly once

This commit is contained in:
Torsten Ruger 2018-04-18 19:27:46 +03:00
parent 059ff4a868
commit 75d5fff611
2 changed files with 14 additions and 5 deletions

View File

@ -32,7 +32,8 @@ module Risc
reg = Risc.message_reg reg = Risc.message_reg
reg.builder = self reg.builder = self
elsif name.to_s.index("label") 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 else
type = Risc.resolve_type(name , @compiler) #checking type = Risc.resolve_type(name , @compiler) #checking
reg = @compiler.use_reg( type.object_class.name ) reg = @compiler.use_reg( type.object_class.name )
@ -43,13 +44,16 @@ module Risc
end end
def if_zero( label ) def if_zero( label )
add_code Risc::IsZero.new("jump if zero" , label) @source_used = true
add_code Risc::IsZero.new(@source , label)
end end
def if_not_zero( label ) 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 end
def branch( label ) def branch( label )
add_code Risc::Branch.new("jump to" , label) @source_used = true
add_code Risc::Branch.new(@source, label)
end end
# build code using dsl (see __init__ or MessageSetup for examples) # build code using dsl (see __init__ or MessageSetup for examples)
@ -122,6 +126,10 @@ module Risc
:function_return , :function_call, :op , :function_return , :function_call, :op ,
:transfer , :reg_to_slot , :byte_to_reg , :reg_to_byte].each do |method| :transfer , :reg_to_slot , :byte_to_reg , :reg_to_byte].each do |method|
define_method("add_#{method}".to_sym) do |*args| 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 ) add_code Risc.send( method , *args )
end end
end end

View File

@ -26,7 +26,8 @@ module Risc
@source = source @source = source
@next = nekst @next = nekst
return unless source 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 end
attr_reader :source attr_reader :source