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:
Torsten Rüger 2019-08-14 14:59:54 +03:00
parent 1dad6dee7a
commit d6c38d15ba
3 changed files with 33 additions and 8 deletions

View File

@ -125,7 +125,6 @@ module RubyX
parfait = ["object"] parfait = ["object"]
parfait.each do |file| parfait.each do |file|
path = File.expand_path("../../parfait/#{file}.rb",__FILE__) path = File.expand_path("../../parfait/#{file}.rb",__FILE__)
puts "Loading #{path}"
ruby_to_vool(File.read(path)) ruby_to_vool(File.read(path))
end end
end end

View File

@ -36,12 +36,13 @@ module Vool
# - Setting up the next message, with receiver, arguments, and (importantly) return address # - 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 # - a CachedCall , or a SimpleCall, depending on wether the receiver type can be determined
def to_mom( compiler ) def to_mom( compiler )
puts "Compiling #{self.to_s}"
@receiver = SelfExpression.new(compiler.receiver_type) if @receiver.is_a?(SelfExpression) @receiver = SelfExpression.new(compiler.receiver_type) if @receiver.is_a?(SelfExpression)
if(@receiver.ct_type) if(@receiver.ct_type)
simple_call(compiler) method = @receiver.ct_type.resolve_method(self.name)
else return simple_call(compiler, method) if method
cached_call(compiler)
end end
cached_call(compiler)
end end
def message_setup(compiler,called_method) def message_setup(compiler,called_method)
@ -55,10 +56,7 @@ module Vool
setup << Mom::ArgumentTransfer.new(self, mom_receive , args ) setup << Mom::ArgumentTransfer.new(self, mom_receive , args )
end end
def simple_call(compiler) def simple_call(compiler, called_method)
type = @receiver.ct_type
called_method = type.resolve_method(@name)
raise "No method #{@name} for #{type}" unless called_method
message_setup(compiler,called_method) << Mom::SimpleCall.new(called_method) message_setup(compiler,called_method) << Mom::SimpleCall.new(called_method)
end end

View 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