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}"
|
||||
end
|
||||
else
|
||||
method = @method
|
||||
@method.source.add_code Virtual::MethodCall.new( @method )
|
||||
if( me.type == :int)
|
||||
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
|
||||
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
|
||||
|
@ -9,18 +9,17 @@ module Bosl
|
||||
name = expression.to_a.first
|
||||
return Virtual::Self.new( Virtual::Reference.new(@clazz)) if name == :self
|
||||
# either an argument, so it's stored in message
|
||||
ret = Virtual::Return.new :int
|
||||
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
|
||||
index = @method.has_local( name )
|
||||
if(index)
|
||||
@method.source.add_code Virtual::Set.new(Virtual::FrameSlot.new(index,:int ) , ret )
|
||||
else
|
||||
raise "must define variable #{name} before using it"
|
||||
type = @method.locals[index].type
|
||||
return Virtual::FrameSlot.new(index, type )
|
||||
end
|
||||
end
|
||||
return ret
|
||||
raise "must define variable #{name} before using it"
|
||||
end
|
||||
|
||||
end #module
|
||||
|
@ -8,16 +8,17 @@ module Bosl
|
||||
end
|
||||
|
||||
def on_assign expression
|
||||
puts expression.inspect
|
||||
name , value = *expression
|
||||
name = name.to_a.first
|
||||
v = process(value)
|
||||
index = @method.has_local( name )
|
||||
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
|
||||
index = @method.has_arg( name )
|
||||
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
|
||||
raise "must define variable #{name} before using it in #{@method.inspect}"
|
||||
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) )
|
||||
move1 = LoadConstant.new(code, code.from , tmp )
|
||||
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 )
|
||||
end
|
||||
#puts "to #{code.to}"
|
||||
@ -29,9 +29,12 @@ module Register
|
||||
return Register.resolve_index( :message , :name)
|
||||
when Virtual::Return
|
||||
return Register.resolve_index( :message , :return_value)
|
||||
when Virtual::NewArgSlot
|
||||
when Virtual::ArgSlot , Virtual::NewArgSlot
|
||||
#puts "from: #{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
|
||||
raise "not implemented for #{from.class}"
|
||||
end
|
||||
|
@ -8,6 +8,11 @@ module Virtual
|
||||
super(type, value)
|
||||
@index = index
|
||||
end
|
||||
attr_reader :index
|
||||
|
||||
def to_s
|
||||
"#{self.class.name}.new(#{index} , #{type}, #{value})"
|
||||
end
|
||||
|
||||
def object_name
|
||||
return :frame
|
||||
|
@ -45,6 +45,9 @@ module Virtual
|
||||
super( type , value )
|
||||
end
|
||||
attr_reader :index
|
||||
def to_s
|
||||
"#{self.class.name}.new(#{index} , #{type}, #{value})"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@ -42,13 +42,16 @@ HERE
|
||||
@interpreter = Interpreter::Interpreter.new
|
||||
@interpreter.start Virtual.machine.init
|
||||
# done = ticks(34)
|
||||
["Branch" , "LoadConstant" , "GetSlot" , "SetSlot" , "RegisterTransfer" ,
|
||||
"GetSlot" , "FunctionCall" , "SaveReturn" , "RegisterTransfer" , "GetSlot" ,
|
||||
"GetSlot" , "GetSlot" , "SetSlot" , "LoadConstant" , "SetSlot" ,
|
||||
"LoadConstant" , "SetSlot" , "RegisterTransfer" , "GetSlot" , "FunctionCall" ,
|
||||
"SaveReturn" , "GetSlot", "OperatorInstruction" , "RegisterTransfer" , "GetSlot" , "GetSlot" ,
|
||||
"GetSlot" , "FunctionReturn" ,"RegisterTransfer" , "Syscall", "NilClass"].each_with_index do |name , index|
|
||||
return if index == 11
|
||||
["Branch" , "LoadConstant" , "GetSlot" , "SetSlot" , "RegisterTransfer" ,
|
||||
"GetSlot" , "FunctionCall" , "SaveReturn", "LoadConstant" , "SetSlot" ,
|
||||
"GetSlot" , "GetSlot" , "SetSlot" , "LoadConstant" , "SetSlot" ,
|
||||
"RegisterTransfer" ,"GetSlot" , "FunctionCall" ,"SaveReturn" , "GetSlot" ,
|
||||
"LoadConstant", "SetSlot", "GetSlot" , "GetSlot" , "SetSlot" ,
|
||||
"LoadConstant", "SetSlot" , "GetSlot" , "SetSlot" , "RegisterTransfer",
|
||||
"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)
|
||||
puts got
|
||||
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
||||
|
Loading…
Reference in New Issue
Block a user