fix type in call issue
This commit is contained in:
parent
f4a4ccb98e
commit
4e26166dff
@ -53,8 +53,15 @@ module Bosl
|
|||||||
raise "unimplemented: \n#{code} \nfor #{ref.inspect}"
|
raise "unimplemented: \n#{code} \nfor #{ref.inspect}"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
method = @method
|
if( me.type == :int)
|
||||||
@method.source.add_code Virtual::MethodCall.new( @method )
|
name = :plus if name == :+
|
||||||
|
method = Virtual.machine.space.get_class_by_name(:Integer).get_instance_method(name)
|
||||||
|
puts Virtual.machine.space.get_class_by_name(:Integer).method_names.to_a
|
||||||
|
raise "Method not implemented Integer.#{name}" unless method
|
||||||
|
@method.source.add_code Virtual::MethodCall.new( method )
|
||||||
|
else
|
||||||
|
raise "me #{me}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
raise "Method not implemented #{me.value}.#{name}" unless method
|
raise "Method not implemented #{me.value}.#{name}" unless method
|
||||||
# the effect of the method is that the NewMessage Return slot will be filled, return it
|
# the effect of the method is that the NewMessage Return slot will be filled, return it
|
||||||
|
@ -9,18 +9,17 @@ module Bosl
|
|||||||
name = expression.to_a.first
|
name = expression.to_a.first
|
||||||
return Virtual::Self.new( Virtual::Reference.new(@clazz)) if name == :self
|
return Virtual::Self.new( Virtual::Reference.new(@clazz)) if name == :self
|
||||||
# either an argument, so it's stored in message
|
# either an argument, so it's stored in message
|
||||||
ret = Virtual::Return.new :int
|
|
||||||
if( index = @method.has_arg(name))
|
if( index = @method.has_arg(name))
|
||||||
@method.source.add_code Virtual::Set.new( Virtual::ArgSlot.new(index,:int ) , ret)
|
type = @method.arguments[index].type
|
||||||
|
return Virtual::ArgSlot.new(index , type )
|
||||||
else # or a local so it is in the frame
|
else # or a local so it is in the frame
|
||||||
index = @method.has_local( name )
|
index = @method.has_local( name )
|
||||||
if(index)
|
if(index)
|
||||||
@method.source.add_code Virtual::Set.new(Virtual::FrameSlot.new(index,:int ) , ret )
|
type = @method.locals[index].type
|
||||||
else
|
return Virtual::FrameSlot.new(index, type )
|
||||||
raise "must define variable #{name} before using it"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ret
|
raise "must define variable #{name} before using it"
|
||||||
end
|
end
|
||||||
|
|
||||||
end #module
|
end #module
|
||||||
|
@ -8,16 +8,17 @@ module Bosl
|
|||||||
end
|
end
|
||||||
|
|
||||||
def on_assign expression
|
def on_assign expression
|
||||||
|
puts expression.inspect
|
||||||
name , value = *expression
|
name , value = *expression
|
||||||
name = name.to_a.first
|
name = name.to_a.first
|
||||||
v = process(value)
|
v = process(value)
|
||||||
index = @method.has_local( name )
|
index = @method.has_local( name )
|
||||||
if(index)
|
if(index)
|
||||||
@method.source.add_code Virtual::Set.new(Virtual::FrameSlot.new(:int,index ) , v )
|
@method.source.add_code Virtual::Set.new(Virtual::FrameSlot.new(index, :int ) , v )
|
||||||
else
|
else
|
||||||
index = @method.has_arg( name )
|
index = @method.has_arg( name )
|
||||||
if(index)
|
if(index)
|
||||||
@method.source.add_code Virtual::Set.new(Virtual::ArgSlot.new(:int,index ) , v )
|
@method.source.add_code Virtual::Set.new(Virtual::ArgSlot.new(index , :int ) , v )
|
||||||
else
|
else
|
||||||
raise "must define variable #{name} before using it in #{@method.inspect}"
|
raise "must define variable #{name} before using it in #{@method.inspect}"
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,7 @@ module Register
|
|||||||
if( code.from.is_a?(Parfait::Value) or code.from.is_a?(Symbol) or code.from.is_a?(Fixnum) )
|
if( code.from.is_a?(Parfait::Value) or code.from.is_a?(Symbol) or code.from.is_a?(Fixnum) )
|
||||||
move1 = LoadConstant.new(code, code.from , tmp )
|
move1 = LoadConstant.new(code, code.from , tmp )
|
||||||
else # while otherwise we "load"
|
else # while otherwise we "load"
|
||||||
#puts "from #{code.from}"
|
puts "from #{code.from}"
|
||||||
move1 = Register.get_slot(code, code.from.object_name , get_index(code.from) , tmp )
|
move1 = Register.get_slot(code, code.from.object_name , get_index(code.from) , tmp )
|
||||||
end
|
end
|
||||||
#puts "to #{code.to}"
|
#puts "to #{code.to}"
|
||||||
@ -29,9 +29,12 @@ module Register
|
|||||||
return Register.resolve_index( :message , :name)
|
return Register.resolve_index( :message , :name)
|
||||||
when Virtual::Return
|
when Virtual::Return
|
||||||
return Register.resolve_index( :message , :return_value)
|
return Register.resolve_index( :message , :return_value)
|
||||||
when Virtual::NewArgSlot
|
when Virtual::ArgSlot , Virtual::NewArgSlot
|
||||||
#puts "from: #{from.index}"
|
#puts "from: #{from.index}"
|
||||||
return Register.resolve_index( :message , :name) + from.index
|
return Register.resolve_index( :message , :name) + from.index
|
||||||
|
when Virtual::FrameSlot
|
||||||
|
#puts "from: #{from.index}"
|
||||||
|
return Register.resolve_index( :frame , :next_frame) + from.index
|
||||||
else
|
else
|
||||||
raise "not implemented for #{from.class}"
|
raise "not implemented for #{from.class}"
|
||||||
end
|
end
|
||||||
|
@ -8,6 +8,11 @@ module Virtual
|
|||||||
super(type, value)
|
super(type, value)
|
||||||
@index = index
|
@index = index
|
||||||
end
|
end
|
||||||
|
attr_reader :index
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
"#{self.class.name}.new(#{index} , #{type}, #{value})"
|
||||||
|
end
|
||||||
|
|
||||||
def object_name
|
def object_name
|
||||||
return :frame
|
return :frame
|
||||||
|
@ -45,6 +45,9 @@ module Virtual
|
|||||||
super( type , value )
|
super( type , value )
|
||||||
end
|
end
|
||||||
attr_reader :index
|
attr_reader :index
|
||||||
|
def to_s
|
||||||
|
"#{self.class.name}.new(#{index} , #{type}, #{value})"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,13 +42,16 @@ HERE
|
|||||||
@interpreter = Interpreter::Interpreter.new
|
@interpreter = Interpreter::Interpreter.new
|
||||||
@interpreter.start Virtual.machine.init
|
@interpreter.start Virtual.machine.init
|
||||||
# done = ticks(34)
|
# done = ticks(34)
|
||||||
["Branch" , "LoadConstant" , "GetSlot" , "SetSlot" , "RegisterTransfer" ,
|
["Branch" , "LoadConstant" , "GetSlot" , "SetSlot" , "RegisterTransfer" ,
|
||||||
"GetSlot" , "FunctionCall" , "SaveReturn" , "RegisterTransfer" , "GetSlot" ,
|
"GetSlot" , "FunctionCall" , "SaveReturn", "LoadConstant" , "SetSlot" ,
|
||||||
"GetSlot" , "GetSlot" , "SetSlot" , "LoadConstant" , "SetSlot" ,
|
"GetSlot" , "GetSlot" , "SetSlot" , "LoadConstant" , "SetSlot" ,
|
||||||
"LoadConstant" , "SetSlot" , "RegisterTransfer" , "GetSlot" , "FunctionCall" ,
|
"RegisterTransfer" ,"GetSlot" , "FunctionCall" ,"SaveReturn" , "GetSlot" ,
|
||||||
"SaveReturn" , "GetSlot", "OperatorInstruction" , "RegisterTransfer" , "GetSlot" , "GetSlot" ,
|
"LoadConstant", "SetSlot", "GetSlot" , "GetSlot" , "SetSlot" ,
|
||||||
"GetSlot" , "FunctionReturn" ,"RegisterTransfer" , "Syscall", "NilClass"].each_with_index do |name , index|
|
"LoadConstant", "SetSlot" , "GetSlot" , "SetSlot" , "RegisterTransfer",
|
||||||
return if index == 11
|
"GetSlot", "FunctionCall", "SaveReturn", "GetSlot", "GetSlot",
|
||||||
|
"SetSlot", "GetSlot", "SetSlot", "FunctionCall", "FunctionCall",
|
||||||
|
"FunctionCall", "FunctionCall", "FunctionCall", "FunctionCall", "FunctionCall",
|
||||||
|
"NilClass"].each_with_index do |name , index|
|
||||||
got = ticks(1)
|
got = ticks(1)
|
||||||
puts got
|
puts got
|
||||||
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
||||||
|
Loading…
Reference in New Issue
Block a user