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.
|
# 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:
|
# example:
|
||||||
# space << Parfait.object_space # load constant
|
# space << Parfait.object_space # load constant
|
||||||
# message[:receiver] << space #make current message's (r0) receiver the space
|
# message[:receiver] << space #make current message's (r0) receiver the space
|
||||||
@ -15,7 +15,6 @@ module Risc
|
|||||||
attr_reader :built , :compiler , :names
|
attr_reader :built , :compiler , :names
|
||||||
|
|
||||||
# pass a compiler, to which instruction are added (usually)
|
# 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
|
# call build with a block to build
|
||||||
def initialize(compiler, for_source)
|
def initialize(compiler, for_source)
|
||||||
raise "no compiler" unless compiler
|
raise "no compiler" unless compiler
|
||||||
@ -27,10 +26,10 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
# make the magic: convert incoming names into registers that have the
|
# 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
|
# names are stored, so subsequent calls use the same register
|
||||||
def method_missing(name , *args)
|
def method_missing(name , *args)
|
||||||
super if args.length != 0
|
return super if args.length != 0
|
||||||
name = name.to_s
|
name = name.to_s
|
||||||
return @names[name] if @names.has_key?(name)
|
return @names[name] if @names.has_key?(name)
|
||||||
if name == "message"
|
if name == "message"
|
||||||
@ -72,7 +71,6 @@ module Risc
|
|||||||
as_string = "word" if as_string == "name"
|
as_string = "word" if as_string == "name"
|
||||||
as_string = "message" if as_string == "next_message"
|
as_string = "message" if as_string == "next_message"
|
||||||
as_string = "message" if as_string == "caller"
|
as_string = "message" if as_string == "caller"
|
||||||
as_string = "named_list" if as_string == "arguments"
|
|
||||||
sym = as_string.camelise.to_sym
|
sym = as_string.camelise.to_sym
|
||||||
clazz = Parfait.object_space.get_class_by_name(sym)
|
clazz = Parfait.object_space.get_class_by_name(sym)
|
||||||
raise "Not implemented/found object #{name}:#{sym}" unless clazz
|
raise "Not implemented/found object #{name}:#{sym}" unless clazz
|
||||||
|
@ -26,7 +26,7 @@ module SlotMachine
|
|||||||
super(source)
|
super(source)
|
||||||
@receiver , @arguments = receiver , arguments
|
@receiver , @arguments = receiver , arguments
|
||||||
raise "Receiver not Slot #{@receiver}" unless @receiver.is_a?(Slotted)
|
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
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
@ -38,11 +38,13 @@ module SlotMachine
|
|||||||
def to_risc(compiler)
|
def to_risc(compiler)
|
||||||
transfer = SlotLoad.new(self.source ,[:message , :next_message , :receiver] , @receiver, self).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)
|
#TODO transfer the Number of arguments to :arguments_given (to be checked on entry)
|
||||||
compiler.reset_regs
|
arg_target = [:message , :next_message ]
|
||||||
@arguments.each do |arg|
|
@arguments.each_with_index do |arg , index| # +1 because of type
|
||||||
arg.to_risc(compiler)
|
|
||||||
compiler.reset_regs
|
compiler.reset_regs
|
||||||
|
load = SlotMachine::SlotLoad.new(self.source, arg_target + ["arg#{index+1}".to_sym] , arg)
|
||||||
|
load.to_risc(compiler)
|
||||||
end
|
end
|
||||||
|
compiler.reset_regs
|
||||||
transfer
|
transfer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -68,11 +68,7 @@ module Sol
|
|||||||
def message_setup(compiler,called_method)
|
def message_setup(compiler,called_method)
|
||||||
setup = SlotMachine::MessageSetup.new( called_method )
|
setup = SlotMachine::MessageSetup.new( called_method )
|
||||||
slot_receive = @receiver.to_slotted(compiler)
|
slot_receive = @receiver.to_slotted(compiler)
|
||||||
arg_target = [:message , :next_message ]
|
args = @arguments.collect { |arg| arg.to_slotted(compiler)}
|
||||||
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
|
|
||||||
setup << SlotMachine::ArgumentTransfer.new(self, slot_receive , args )
|
setup << SlotMachine::ArgumentTransfer.new(self, slot_receive , args )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -50,11 +50,7 @@ module Sol
|
|||||||
arg_index = compiler.get_method.arguments_type.get_length - 1
|
arg_index = compiler.get_method.arguments_type.get_length - 1
|
||||||
setup = SlotMachine::MessageSetup.new( arg_index )
|
setup = SlotMachine::MessageSetup.new( arg_index )
|
||||||
slot_receive = @receiver.to_slotted(compiler)
|
slot_receive = @receiver.to_slotted(compiler)
|
||||||
arg_target = [:message , :next_message ]
|
args = @arguments.collect { |arg| arg.to_slotted(compiler)}
|
||||||
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
|
|
||||||
setup << SlotMachine::ArgumentTransfer.new( self , slot_receive , args )
|
setup << SlotMachine::ArgumentTransfer.new( self , slot_receive , args )
|
||||||
setup << SlotMachine::BlockYield.new( self , arg_index )
|
setup << SlotMachine::BlockYield.new( self , arg_index )
|
||||||
end
|
end
|
||||||
|
@ -3,15 +3,15 @@ require_relative "helper"
|
|||||||
module SlotMachine
|
module SlotMachine
|
||||||
class TestArgumentTransfer < SlotMachineInstructionTest
|
class TestArgumentTransfer < SlotMachineInstructionTest
|
||||||
def instruction
|
def instruction
|
||||||
receiver = SlottedMessage.new( [:receiver])
|
receiver = SlottedMessage.new( [:arg1])
|
||||||
arg = SlotLoad.new("test", [:message, :caller] , [:message,:type] )
|
arg = SlottedMessage.new( [:receiver , :type])
|
||||||
ArgumentTransfer.new("" , receiver ,[arg])
|
ArgumentTransfer.new("" , receiver ,[arg])
|
||||||
end
|
end
|
||||||
def test_len
|
def test_len
|
||||||
assert_equal 6 , all.length , all_str
|
assert_equal 8 , all.length , all_str
|
||||||
end
|
end
|
||||||
def test_1_slot
|
def test_1_slot
|
||||||
assert_slot_to_reg risc(1) ,:r0 , 2 , :r2
|
assert_slot_to_reg risc(1) ,:r0 , 9 , :r2
|
||||||
end
|
end
|
||||||
def test_2_slot
|
def test_2_slot
|
||||||
assert_slot_to_reg risc(2) ,:r0 , 1 , :r3
|
assert_slot_to_reg risc(2) ,:r0 , 1 , :r3
|
||||||
@ -20,10 +20,16 @@ module SlotMachine
|
|||||||
assert_reg_to_slot risc(3) , :r2 , :r3 , 2
|
assert_reg_to_slot risc(3) , :r2 , :r3 , 2
|
||||||
end
|
end
|
||||||
def test_4_slot
|
def test_4_slot
|
||||||
assert_slot_to_reg risc(4) ,:r0 , 0 , :r2
|
assert_slot_to_reg risc(4) ,:r0 , 2 , :r2
|
||||||
end
|
end
|
||||||
def test_5_reg
|
def test_5
|
||||||
assert_reg_to_slot risc(5) , :r2 , :r0 , 6
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -45,7 +45,7 @@ module Sol
|
|||||||
assert_equal Parfait::Class, @ins.next.receiver.known_object.class
|
assert_equal Parfait::Class, @ins.next.receiver.known_object.class
|
||||||
end
|
end
|
||||||
def test_arg_one
|
def test_arg_one
|
||||||
assert_equal SlotLoad, @ins.next(1).arguments[0].class
|
assert_equal SlottedConstant, @ins.next(1).arguments[0].class
|
||||||
end
|
end
|
||||||
def test_receiver_move_class
|
def test_receiver_move_class
|
||||||
assert_equal ArgumentTransfer, @ins.next(1).class
|
assert_equal ArgumentTransfer, @ins.next(1).class
|
||||||
|
@ -11,7 +11,7 @@ module Sol
|
|||||||
assert_equal SlottedMessage, @ins.next.receiver.class
|
assert_equal SlottedMessage, @ins.next.receiver.class
|
||||||
end
|
end
|
||||||
def test_arg_one
|
def test_arg_one
|
||||||
assert_equal SlotLoad, @ins.next(1).arguments[0].class
|
assert_equal SlottedConstant, @ins.next(1).arguments[0].class
|
||||||
end
|
end
|
||||||
def test_call_two
|
def test_call_two
|
||||||
assert_equal SimpleCall, @ins.next(2).class
|
assert_equal SimpleCall, @ins.next(2).class
|
||||||
|
@ -12,12 +12,11 @@ module Sol
|
|||||||
[SlotMachine::IntegerConstant , 5]
|
[SlotMachine::IntegerConstant , 5]
|
||||||
end
|
end
|
||||||
def test_args_two_move
|
def test_args_two_move
|
||||||
assert_equal :next_message, @ins.next(1).arguments[1].left.slots.name
|
assert_equal SlottedConstant, @ins.next(1).arguments[1].class
|
||||||
assert_equal :arg2, @ins.next(1).arguments[1].left.slots.next_slot.name
|
|
||||||
end
|
end
|
||||||
def test_args_two_str
|
def test_args_two_str
|
||||||
assert_equal SlotMachine::IntegerConstant, @ins.next(1).arguments[1].right.known_object.class
|
assert_equal SlottedConstant, @ins.next(1).arguments[1].class
|
||||||
assert_equal 2, @ins.next(1).arguments[1].right.known_object.value
|
assert_equal 2, @ins.next(1).arguments[1].known_object.value
|
||||||
end
|
end
|
||||||
def test_array
|
def test_array
|
||||||
check_array [MessageSetup,ArgumentTransfer,SimpleCall, SlotLoad, ReturnJump,
|
check_array [MessageSetup,ArgumentTransfer,SimpleCall, SlotLoad, ReturnJump,
|
||||||
|
@ -22,10 +22,8 @@ module Sol
|
|||||||
assert_equal 1, @ins.next(3).arguments.length
|
assert_equal 1, @ins.next(3).arguments.length
|
||||||
end
|
end
|
||||||
def test_args_one_l
|
def test_args_one_l
|
||||||
left = @ins.next(3).arguments[0].left
|
left = @ins.next(3).arguments[0]
|
||||||
assert_equal Symbol, left.known_object.class
|
assert_equal SlotMachine::IntegerConstant, left.known_object.class
|
||||||
assert_equal :message, left.known_object
|
|
||||||
assert_equal "message.next_message.arg1", left.to_s
|
|
||||||
end
|
end
|
||||||
def test_check_left
|
def test_check_left
|
||||||
assert_equal SlottedObject, @ins.left.class
|
assert_equal SlottedObject, @ins.left.class
|
||||||
|
Loading…
Reference in New Issue
Block a user