implement simple_calls to_risc
This commit is contained in:
parent
71c59e5bc0
commit
a9196e9cd6
@ -5,7 +5,7 @@ module Mom
|
|||||||
# actually call it.
|
# actually call it.
|
||||||
#
|
#
|
||||||
# As the call setup is done beforehand (for both simple and cached call), the
|
# As the call setup is done beforehand (for both simple and cached call), the
|
||||||
# calling really means just jumping to the address. Simple.
|
# calling really means mostly jumping to the address. Simple.
|
||||||
#
|
#
|
||||||
class SimpleCall < Instruction
|
class SimpleCall < Instruction
|
||||||
attr_reader :method
|
attr_reader :method
|
||||||
@ -13,8 +13,19 @@ module Mom
|
|||||||
def initialize(method)
|
def initialize(method)
|
||||||
@method = method
|
@method = method
|
||||||
end
|
end
|
||||||
def to_risc(context)
|
|
||||||
Risc::Label.new(self,"SimpleCall")
|
# To call the method, we determine the jumpable address (method.binary), move that
|
||||||
|
# into a register and issue a FunctionCall
|
||||||
|
#
|
||||||
|
# For returning, we add a label after the call, and load it's address into the
|
||||||
|
# return_address of the next_message, for the ReturnSequence to pick it up.
|
||||||
|
def to_risc(compiler)
|
||||||
|
reg = compiler.use_reg(:int)
|
||||||
|
return_label = Risc::Label.new(self,"continue")
|
||||||
|
load = SlotLoad.new([:message,:next_message,:return_address],[return_label])
|
||||||
|
moves = load.to_risc(compiler)
|
||||||
|
moves << Risc::FunctionCall.new(self, reg)
|
||||||
|
moves << return_label
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -102,7 +102,7 @@ module Mom
|
|||||||
type = known_object.respond_to?(:ct_type) ? known_object.ct_type : :int
|
type = known_object.respond_to?(:ct_type) ? known_object.ct_type : :int
|
||||||
right = compiler.use_reg( type )
|
right = compiler.use_reg( type )
|
||||||
case known_object
|
case known_object
|
||||||
when Constant , Parfait::Object
|
when Constant , Parfait::Object , Risc::Label
|
||||||
const = Risc.load_constant(instruction, self , right)
|
const = Risc.load_constant(instruction, self , right)
|
||||||
when Symbol
|
when Symbol
|
||||||
const = Risc::SlotToReg.new( instruction , Risc.resolve_to_register(known_object) ,
|
const = Risc::SlotToReg.new( instruction , Risc.resolve_to_register(known_object) ,
|
||||||
|
@ -9,21 +9,16 @@ module Risc
|
|||||||
@input = "r = 5.mod4"
|
@input = "r = 5.mod4"
|
||||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg ,
|
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg ,
|
||||||
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant ,
|
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant ,
|
||||||
SlotToReg, RegToSlot, Label, SlotToReg, SlotToReg, RegToSlot]
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, FunctionCall ,
|
||||||
|
Label, SlotToReg, SlotToReg, RegToSlot]
|
||||||
end
|
end
|
||||||
def test_local_assign_instructions
|
def test_local_assign_instructions
|
||||||
assert_nil msg = check_nil , msg
|
assert_nil msg = check_nil , msg
|
||||||
end
|
end
|
||||||
|
|
||||||
def ttest_constant_load
|
def test_constant_load
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal 5 , produced.constant.known_object.value
|
assert_equal 5 , produced.next(11).constant.known_object.value
|
||||||
end
|
end
|
||||||
|
|
||||||
def ttest_slot_move
|
|
||||||
produced = produce_body
|
|
||||||
assert_equal produced.next.register , produced.register
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,19 +12,18 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_condition
|
def test_condition
|
||||||
assert_equal TruthCheck , @ins.next(11).class
|
assert_equal TruthCheck , @ins.next(4).class
|
||||||
end
|
end
|
||||||
def test_condition_is_slot
|
def test_condition_is_slot
|
||||||
assert_equal SlotDefinition , @ins.next(11).condition.class , @ins
|
assert_equal SlotDefinition , @ins.next(4).condition.class , @ins
|
||||||
end
|
end
|
||||||
def test_hoisted_dynamic_call
|
def test_hoisted_dynamic_call
|
||||||
assert_equal DynamicCall , @ins.next(9).class
|
assert_equal SimpleCall , @ins.next(2).class
|
||||||
|
assert_equal :mod4 , @ins.next(2).method.name
|
||||||
end
|
end
|
||||||
def test_array
|
def test_array
|
||||||
check_array [NotSameCheck, SlotLoad, MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad ,
|
check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, TruthCheck, Label ,
|
||||||
Label, MessageSetup, ArgumentTransfer, DynamicCall, SlotLoad, TruthCheck ,
|
SlotLoad, Jump, Label, SlotLoad, Label] , @ins
|
||||||
Label, MessageSetup, ArgumentTransfer, SimpleCall, Jump, Label ,
|
|
||||||
MessageSetup, ArgumentTransfer, SimpleCall, Label] , @ins
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user