simplify method entry exit codes

Basically just a label now
No more implicit returns (needs compiler tests)
Many return points is the new idea
Also setup is done before the enter by MessageSetup
This commit is contained in:
Torsten Ruger 2018-03-21 16:02:46 +05:30
parent 61a801b00c
commit fcbdba4804
5 changed files with 8 additions and 20 deletions

View File

@ -128,7 +128,7 @@ module Risc
#puts "assemble #{method.source.instructions}"
method.instructions.assemble_all( stream )
rescue => e
log.debug "Assembly error #{method.name}\n#{Sof.write(method.instructions).to_s[0...2000]}"
log.debug "Assembly error #{method.name}\n#{method.to_rxf.to_s[0...2000]}"
raise e
end
write_binary_method_to_stream( method, stream)

View File

@ -86,7 +86,7 @@ require_relative "instructions/load_constant"
require_relative "instructions/syscall"
require_relative "instructions/function_call"
require_relative "instructions/function_return"
require_relative "instructions/register_transfer"
require_relative "instructions/transfer"
require_relative "instructions/label"
require_relative "instructions/branch"
require_relative "instructions/operator_instruction"

View File

@ -45,13 +45,13 @@ module Risc
end
def assemble_all io , labels = []
return if labels.include?(self)
return if labels.include?(self) or self.next.nil?
labels << self
self.next.assemble_all(io,labels)
end
def total_byte_length labels = []
return 0 if labels.include?(self)
return 0 if labels.include?(self) or self.next.nil?
labels << self
ret = self.next.total_byte_length(labels)
#puts "#{self.class.name} return #{ret}"
@ -63,7 +63,7 @@ module Risc
return position if labels.include?(self)
labels << self
super(position , labels)
self.next.set_position(position,labels)
self.next.set_position(position,labels) if self.next
end
# shame we need this, just for logging

View File

@ -48,19 +48,7 @@ module Risc
source = "_init_method"
name = "#{method.for_type.name}.#{method.name}"
@current = @method.set_instructions( Risc.label(source, name))
# add the type of the locals to the existing NamedList instance
frame_reg = use_reg(:Type , method.frame )
list_reg = use_reg(:NamedList )
add_load_constant("#{name} load frame type", method.frame , frame_reg)
add_slot_to_reg( "#{name} get frame from method" , :message , :frame , list_reg )
add_reg_to_slot( "#{name} store frame type in frame" , frame_reg , list_reg , 1 )
enter = @current # this is where method body goes
add_label( source, "return #{name}")
#load the return address into pc, affecting return. (other cpus have commands for this, but not arm)
add_function_return( source , Risc.message_reg , Risc.resolve_to_index(:message , :return_address) )
@current = enter
@current << Risc.label( source, "unreachable")
self
end

View File

@ -11,10 +11,10 @@ module Risc
end
def preamble
[Label, LoadConstant, SlotToReg, RegToSlot ]
[Label ]
end
def postamble
[ Label, FunctionReturn]
[ Label]
end
# test hack to in place change object type
def add_space_field(name,type)