fix argument transfer (to be logical)
This commit is contained in:
parent
685022a6e0
commit
393f0d9a60
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -3,15 +3,15 @@ require_relative "helper"
|
||||
module SlotMachine
|
||||
class TestArgumentTransfer < SlotMachineInstructionTest
|
||||
def instruction
|
||||
receiver = SlottedMessage.new( [:receiver])
|
||||
arg = SlotLoad.new("test", [:message, :caller] , [:message,:type] )
|
||||
receiver = SlottedMessage.new( [:arg1])
|
||||
arg = SlottedMessage.new( [:receiver , :type])
|
||||
ArgumentTransfer.new("" , receiver ,[arg])
|
||||
end
|
||||
def test_len
|
||||
assert_equal 6 , all.length , all_str
|
||||
assert_equal 8 , all.length , all_str
|
||||
end
|
||||
def test_1_slot
|
||||
assert_slot_to_reg risc(1) ,:r0 , 2 , :r2
|
||||
assert_slot_to_reg risc(1) ,:r0 , 9 , :r2
|
||||
end
|
||||
def test_2_slot
|
||||
assert_slot_to_reg risc(2) ,:r0 , 1 , :r3
|
||||
@ -20,10 +20,16 @@ module SlotMachine
|
||||
assert_reg_to_slot risc(3) , :r2 , :r3 , 2
|
||||
end
|
||||
def test_4_slot
|
||||
assert_slot_to_reg risc(4) ,:r0 , 0 , :r2
|
||||
assert_slot_to_reg risc(4) ,:r0 , 2 , :r2
|
||||
end
|
||||
def test_5_reg
|
||||
assert_reg_to_slot risc(5) , :r2 , :r0 , 6
|
||||
def test_5
|
||||
assert_slot_to_reg risc(5) ,:r2 , 0 , :r2
|
||||
end
|
||||
def test_6
|
||||
assert_slot_to_reg risc(6) ,:r0 , 1 , :r3
|
||||
end
|
||||
def test_7
|
||||
assert_reg_to_slot risc(7) , :r2 , :r3 , 9
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -45,7 +45,7 @@ module Sol
|
||||
assert_equal Parfait::Class, @ins.next.receiver.known_object.class
|
||||
end
|
||||
def test_arg_one
|
||||
assert_equal SlotLoad, @ins.next(1).arguments[0].class
|
||||
assert_equal SlottedConstant, @ins.next(1).arguments[0].class
|
||||
end
|
||||
def test_receiver_move_class
|
||||
assert_equal ArgumentTransfer, @ins.next(1).class
|
||||
|
@ -11,7 +11,7 @@ module Sol
|
||||
assert_equal SlottedMessage, @ins.next.receiver.class
|
||||
end
|
||||
def test_arg_one
|
||||
assert_equal SlotLoad, @ins.next(1).arguments[0].class
|
||||
assert_equal SlottedConstant, @ins.next(1).arguments[0].class
|
||||
end
|
||||
def test_call_two
|
||||
assert_equal SimpleCall, @ins.next(2).class
|
||||
|
@ -12,12 +12,11 @@ module Sol
|
||||
[SlotMachine::IntegerConstant , 5]
|
||||
end
|
||||
def test_args_two_move
|
||||
assert_equal :next_message, @ins.next(1).arguments[1].left.slots.name
|
||||
assert_equal :arg2, @ins.next(1).arguments[1].left.slots.next_slot.name
|
||||
assert_equal SlottedConstant, @ins.next(1).arguments[1].class
|
||||
end
|
||||
def test_args_two_str
|
||||
assert_equal SlotMachine::IntegerConstant, @ins.next(1).arguments[1].right.known_object.class
|
||||
assert_equal 2, @ins.next(1).arguments[1].right.known_object.value
|
||||
assert_equal SlottedConstant, @ins.next(1).arguments[1].class
|
||||
assert_equal 2, @ins.next(1).arguments[1].known_object.value
|
||||
end
|
||||
def test_array
|
||||
check_array [MessageSetup,ArgumentTransfer,SimpleCall, SlotLoad, ReturnJump,
|
||||
|
@ -22,10 +22,8 @@ module Sol
|
||||
assert_equal 1, @ins.next(3).arguments.length
|
||||
end
|
||||
def test_args_one_l
|
||||
left = @ins.next(3).arguments[0].left
|
||||
assert_equal Symbol, left.known_object.class
|
||||
assert_equal :message, left.known_object
|
||||
assert_equal "message.next_message.arg1", left.to_s
|
||||
left = @ins.next(3).arguments[0]
|
||||
assert_equal SlotMachine::IntegerConstant, left.known_object.class
|
||||
end
|
||||
def test_check_left
|
||||
assert_equal SlottedObject, @ins.left.class
|
||||
|
Loading…
Reference in New Issue
Block a user