clean and refactor
This commit is contained in:
parent
091900ef1c
commit
7223ca9a1c
@ -32,7 +32,7 @@ module Melon
|
||||
w = Vm::Tree::CallSite.new()
|
||||
puts "receiver #{statement}"
|
||||
w.name = name
|
||||
w.arguments = process(args)
|
||||
w.arguments = process(args) || []
|
||||
w.receiver = process(receiver)
|
||||
w
|
||||
end
|
||||
|
@ -6,6 +6,9 @@ module Melon
|
||||
|
||||
def initialize(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
|
||||
|
||||
def normalize_source
|
||||
|
@ -2,24 +2,22 @@ module Vm
|
||||
module CallSite
|
||||
|
||||
def on_CallSite( statement )
|
||||
# name_s , arguments , receiver = *statement
|
||||
raise "not inside method " unless @method
|
||||
reset_regs
|
||||
#move the new message (that we need to populate to make a call) to std register
|
||||
new_message = Register.resolve_to_register(:new_message)
|
||||
add_slot_to_reg(statement, :message , :next_message , new_message )
|
||||
load_new_message(statement)
|
||||
me = get_me( statement )
|
||||
type = get_my_type(me)
|
||||
|
||||
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
|
||||
add_reg_to_slot( statement , me , :new_message , :receiver)
|
||||
|
||||
set_message_details(method , statement , 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 )
|
||||
|
||||
@ -31,6 +29,12 @@ module Vm
|
||||
|
||||
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 )
|
||||
if statement.receiver
|
||||
me = process( statement.receiver )
|
||||
@ -40,6 +44,7 @@ module Vm
|
||||
end
|
||||
me
|
||||
end
|
||||
|
||||
def get_my_type( me )
|
||||
# now we have to resolve the method name (+ receiver) into a callable method
|
||||
case me.type
|
||||
|
@ -41,7 +41,7 @@ module Register
|
||||
end
|
||||
|
||||
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))))
|
||||
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot ,
|
||||
LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer ,
|
||||
|
Loading…
Reference in New Issue
Block a user