Fix calling unknown methods
Before, when the type was determined, it was assumed that the method can be resolved. But off course tis is not true, as methods may be defined later in the file. Two solutions for that. One could (and should) define all methods and only then start to compile. Thus having the type safety. Or (as now) make a dynamic call and let it fail at runtime.
This commit is contained in:
parent
1dad6dee7a
commit
d6c38d15ba
@ -125,7 +125,6 @@ module RubyX
|
||||
parfait = ["object"]
|
||||
parfait.each do |file|
|
||||
path = File.expand_path("../../parfait/#{file}.rb",__FILE__)
|
||||
puts "Loading #{path}"
|
||||
ruby_to_vool(File.read(path))
|
||||
end
|
||||
end
|
||||
|
@ -36,12 +36,13 @@ module Vool
|
||||
# - Setting up the next message, with receiver, arguments, and (importantly) return address
|
||||
# - a CachedCall , or a SimpleCall, depending on wether the receiver type can be determined
|
||||
def to_mom( compiler )
|
||||
puts "Compiling #{self.to_s}"
|
||||
@receiver = SelfExpression.new(compiler.receiver_type) if @receiver.is_a?(SelfExpression)
|
||||
if(@receiver.ct_type)
|
||||
simple_call(compiler)
|
||||
else
|
||||
cached_call(compiler)
|
||||
method = @receiver.ct_type.resolve_method(self.name)
|
||||
return simple_call(compiler, method) if method
|
||||
end
|
||||
cached_call(compiler)
|
||||
end
|
||||
|
||||
def message_setup(compiler,called_method)
|
||||
@ -55,10 +56,7 @@ module Vool
|
||||
setup << Mom::ArgumentTransfer.new(self, mom_receive , args )
|
||||
end
|
||||
|
||||
def simple_call(compiler)
|
||||
type = @receiver.ct_type
|
||||
called_method = type.resolve_method(@name)
|
||||
raise "No method #{@name} for #{type}" unless called_method
|
||||
def simple_call(compiler, called_method)
|
||||
message_setup(compiler,called_method) << Mom::SimpleCall.new(called_method)
|
||||
end
|
||||
|
||||
|
28
test/vool/send/test_not_found.rb
Normal file
28
test/vool/send/test_not_found.rb
Normal file
@ -0,0 +1,28 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Vool
|
||||
class TestSendCachedSimpleMom < MiniTest::Test
|
||||
include VoolCompile
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@compiler = compile_first_method( "5.div8")
|
||||
@ins = @compiler.mom_instructions.next
|
||||
end
|
||||
def test_check_type
|
||||
assert_equal NotSameCheck , @ins.class , @ins
|
||||
end
|
||||
def test_check_resolve_call
|
||||
assert_equal ResolveMethod , @ins.next(2).class , @ins
|
||||
end
|
||||
def test_dynamic_call_last
|
||||
assert_equal DynamicCall , @ins.next(6).class , @ins
|
||||
end
|
||||
|
||||
def test_array
|
||||
check_array [NotSameCheck, SlotLoad, ResolveMethod, Label, MessageSetup ,
|
||||
ArgumentTransfer, DynamicCall, Label, ReturnSequence, Label] , @ins
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user