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:
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user