class Pione::Lang::PioneMethod
PioneMethod
is a class represents method in PIONE system.
Public Instance Methods
call(env, receiver, args)
click to toggle source
Call the method with recevier and arguemnts.
# File lib/pione/lang/pione-method.rb, line 41 def call(env, receiver, args) _output = receiver.pione_type(env).instance_exec(env, receiver, *args, &body) if _output.nil? p self p receiver p args end validate_output(env, receiver, _output) return _output end
get_input_types(env, receiver)
click to toggle source
Get the input types of receiver.
# File lib/pione/lang/pione-method.rb, line 83 def get_input_types(env, receiver) inputs.map{|input| get_type(env, input, receiver)} end
get_output_type(env, receiver)
click to toggle source
Get the output type of receiver.
# File lib/pione/lang/pione-method.rb, line 88 def get_output_type(env, receiver) get_type(env, output, receiver) end
validate_inputs(env, rec, args)
click to toggle source
Validate inputs data types for the method.
@param receiver_type [Type]
receiver type
@param args [Array<Object>]
arguments
@return [Boolean]
true if input data are valid
# File lib/pione/lang/pione-method.rb, line 60 def validate_inputs(env, rec, args) # check size return false unless inputs.size == args.size # check type inputs.each_with_index do |input, i| input = get_type(env, input, rec) unless input.match(env, args[i]) return false end end return true end
validate_output(env, receiver, value)
click to toggle source
Validate output data type for the method.
# File lib/pione/lang/pione-method.rb, line 75 def validate_output(env, receiver, value) _output = get_type(env, output, receiver) unless _output.match(env, value) raise MethodInterfaceError.new(:output, name, [_output], [value]) end end
Private Instance Methods
get_type(env, type, receiver)
click to toggle source
Get a type object.
# File lib/pione/lang/pione-method.rb, line 95 def get_type(env, type, receiver) case type when :index_type receiver.index_type(env) when :element_type receiver.element_type(env) when :receiver_type receiver.pione_type(env) else type end end