fix argument transfer (to be logical)

This commit is contained in:
2020-02-27 18:19:27 +02:00
parent 685022a6e0
commit 393f0d9a60
9 changed files with 31 additions and 36 deletions

View File

@ -4,7 +4,7 @@ module Risc
#
# The code is added to the method_compiler.
#
# Basically this allows to many Risc instructions with extremely readable code.
# Basically this allows to express many Risc instructions with extremely readable code.
# example:
# space << Parfait.object_space # load constant
# message[:receiver] << space #make current message's (r0) receiver the space
@ -15,7 +15,6 @@ module Risc
attr_reader :built , :compiler , :names
# pass a compiler, to which instruction are added (usually)
# second arg determines weather instructions are added (default true)
# call build with a block to build
def initialize(compiler, for_source)
raise "no compiler" unless compiler
@ -27,10 +26,10 @@ module Risc
end
# make the magic: convert incoming names into registers that have the
# type set according to the name (using resolve_type)
# type set according to the name (using infer_type)
# names are stored, so subsequent calls use the same register
def method_missing(name , *args)
super if args.length != 0
return super if args.length != 0
name = name.to_s
return @names[name] if @names.has_key?(name)
if name == "message"
@ -72,7 +71,6 @@ module Risc
as_string = "word" if as_string == "name"
as_string = "message" if as_string == "next_message"
as_string = "message" if as_string == "caller"
as_string = "named_list" if as_string == "arguments"
sym = as_string.camelise.to_sym
clazz = Parfait.object_space.get_class_by_name(sym)
raise "Not implemented/found object #{name}:#{sym}" unless clazz

View File

@ -26,7 +26,7 @@ module SlotMachine
super(source)
@receiver , @arguments = receiver , arguments
raise "Receiver not Slot #{@receiver}" unless @receiver.is_a?(Slotted)
@arguments.each{|a| raise "args not SlotLoad #{a}" unless a.is_a?(SlotLoad)}
@arguments.each{|a| raise "args not Slotted #{a}" unless a.is_a?(Slotted)}
end
def to_s
@ -38,11 +38,13 @@ module SlotMachine
def to_risc(compiler)
transfer = SlotLoad.new(self.source ,[:message , :next_message , :receiver] , @receiver, self).to_risc(compiler)
#TODO transfer the Number of arguments to :arguments_given (to be checked on entry)
compiler.reset_regs
@arguments.each do |arg|
arg.to_risc(compiler)
arg_target = [:message , :next_message ]
@arguments.each_with_index do |arg , index| # +1 because of type
compiler.reset_regs
load = SlotMachine::SlotLoad.new(self.source, arg_target + ["arg#{index+1}".to_sym] , arg)
load.to_risc(compiler)
end
compiler.reset_regs
transfer
end
end

View File

@ -68,11 +68,7 @@ module Sol
def message_setup(compiler,called_method)
setup = SlotMachine::MessageSetup.new( called_method )
slot_receive = @receiver.to_slotted(compiler)
arg_target = [:message , :next_message ]
args = []
@arguments.each_with_index do |arg , index| # +1 because of type
args << SlotMachine::SlotLoad.new(self, arg_target + ["arg#{index+1}".to_sym] , arg.to_slotted(compiler))
end
args = @arguments.collect { |arg| arg.to_slotted(compiler)}
setup << SlotMachine::ArgumentTransfer.new(self, slot_receive , args )
end

View File

@ -50,11 +50,7 @@ module Sol
arg_index = compiler.get_method.arguments_type.get_length - 1
setup = SlotMachine::MessageSetup.new( arg_index )
slot_receive = @receiver.to_slotted(compiler)
arg_target = [:message , :next_message ]
args = []
@arguments.each_with_index do |arg , index| # +1 because of type
args << SlotMachine::SlotLoad.new(self, arg_target + ["arg#{index+1}".to_sym] , arg.to_slotted(compiler))
end
args = @arguments.collect { |arg| arg.to_slotted(compiler)}
setup << SlotMachine::ArgumentTransfer.new( self , slot_receive , args )
setup << SlotMachine::BlockYield.new( self , arg_index )
end