clean and refactor
This commit is contained in:
parent
091900ef1c
commit
7223ca9a1c
@ -32,7 +32,7 @@ module Melon
|
|||||||
w = Vm::Tree::CallSite.new()
|
w = Vm::Tree::CallSite.new()
|
||||||
puts "receiver #{statement}"
|
puts "receiver #{statement}"
|
||||||
w.name = name
|
w.name = name
|
||||||
w.arguments = process(args)
|
w.arguments = process(args) || []
|
||||||
w.receiver = process(receiver)
|
w.receiver = process(receiver)
|
||||||
w
|
w
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,9 @@ module Melon
|
|||||||
|
|
||||||
def initialize(name , args_type , locals_type , source )
|
def initialize(name , args_type , locals_type , source )
|
||||||
@name , @args_type , @locals_type , @source = name , args_type, locals_type , source
|
@name , @args_type , @locals_type , @source = name , args_type, locals_type , source
|
||||||
|
raise "Name must be symbol" unless name.is_a?(Symbol)
|
||||||
|
raise "args_type must be type" unless args_type.is_a?(Parfait::Type)
|
||||||
|
raise "locals_type must be type" unless locals_type.is_a?(Parfait::Type)
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_source
|
def normalize_source
|
||||||
|
@ -2,24 +2,22 @@ module Vm
|
|||||||
module CallSite
|
module CallSite
|
||||||
|
|
||||||
def on_CallSite( statement )
|
def on_CallSite( statement )
|
||||||
# name_s , arguments , receiver = *statement
|
|
||||||
raise "not inside method " unless @method
|
raise "not inside method " unless @method
|
||||||
reset_regs
|
reset_regs
|
||||||
#move the new message (that we need to populate to make a call) to std register
|
#move the new message (that we need to populate to make a call) to std register
|
||||||
new_message = Register.resolve_to_register(:new_message)
|
load_new_message(statement)
|
||||||
add_slot_to_reg(statement, :message , :next_message , new_message )
|
|
||||||
me = get_me( statement )
|
me = get_me( statement )
|
||||||
type = get_my_type(me)
|
type = get_my_type(me)
|
||||||
|
|
||||||
method = type.get_method(statement.name)
|
method = type.get_method(statement.name)
|
||||||
raise "Method not implementedfor me#{type} #{type.inspect}.#{statement.name}" unless method
|
raise "Method not implemented for me:#{me} #{type.inspect}.#{statement.name}" unless method
|
||||||
|
|
||||||
# move our receiver there
|
# move our receiver there
|
||||||
add_reg_to_slot( statement , me , :new_message , :receiver)
|
add_reg_to_slot( statement , me , :new_message , :receiver)
|
||||||
|
|
||||||
set_message_details(method , statement , statement.arguments)
|
set_message_details(method , statement , statement.arguments)
|
||||||
set_arguments(method , statement.arguments)
|
set_arguments(method , statement.arguments)
|
||||||
ret = use_reg( :Integer ) #FIXME real return type
|
ret = use_reg( :Object ) #FIXME real return type
|
||||||
|
|
||||||
Register.issue_call( self , method )
|
Register.issue_call( self , method )
|
||||||
|
|
||||||
@ -31,6 +29,12 @@ module Vm
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def load_new_message(statement)
|
||||||
|
new_message = Register.resolve_to_register(:new_message)
|
||||||
|
add_slot_to_reg(statement, :message , :next_message , new_message )
|
||||||
|
new_message
|
||||||
|
end
|
||||||
|
|
||||||
def get_me( statement )
|
def get_me( statement )
|
||||||
if statement.receiver
|
if statement.receiver
|
||||||
me = process( statement.receiver )
|
me = process( statement.receiver )
|
||||||
@ -40,6 +44,7 @@ module Vm
|
|||||||
end
|
end
|
||||||
me
|
me
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_my_type( me )
|
def get_my_type( me )
|
||||||
# now we have to resolve the method name (+ receiver) into a callable method
|
# now we have to resolve the method name (+ receiver) into a callable method
|
||||||
case me.type
|
case me.type
|
||||||
|
@ -41,7 +41,7 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_assign_call
|
def test_assign_call
|
||||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
Parfait.object_space.get_main.add_local(:r , :Object)
|
||||||
@input = s(:statements, s(:l_assignment, s(:local, :r), s(:call, :main, s(:arguments))))
|
@input = s(:statements, s(:l_assignment, s(:local, :r), s(:call, :main, s(:arguments))))
|
||||||
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot ,
|
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot ,
|
||||||
LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer ,
|
LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer ,
|
||||||
|
Loading…
Reference in New Issue
Block a user