Class: Nydp::Invocation::Base

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/nydp/function_invocation.rb

Overview

def self.whazzup

puts @@sig_counts.to_a.sort_by { |c| c[1] }.map { |c| "#{c[1]}\t#{c[0]}"}

end

Instance Method Summary collapse

Methods included from Helper

#cons, #list, #literal?, #pair?, #sig, #sym, #sym?

Methods included from Converter

#n2r, #r2n

Constructor Details

#initialize(expr, source, sig = nil) ⇒ Base

Returns a new instance of Base.



16
17
18
# File 'lib/nydp/function_invocation.rb', line 16

def initialize expr, source, sig=nil
  @expr, @source, @sig = expr, source, sig
end

Instance Method Details

#handle(e, f, invoker, *args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nydp/function_invocation.rb', line 20

def handle e, f, invoker, *args
  case e
  when Nydp::Error, InvocationFailed
    raise
  else
    if e.is_a?(NoMethodError) && !f.respond_to?(invoker)
      raise InvocationFailed.new("#{f.inspect} is not a function: args were #{args.inspect} in #{source.inspect}")
    else
      msg  = args.map { |a| "  #{a.inspect}"}.join("\n")
      msg  =  "failed to execute invocation #{f.inspect}\n#{msg}"
      msg +=  "\nsource was #{source.inspect}"
      msg +=  "\nfunction name was #{source.car.inspect}"
      raise InvocationFailed.new msg
    end
  end
end

#inspectObject



42
# File 'lib/nydp/function_invocation.rb', line 42

def inspect ; @expr.map { |x| x.inspect }.join(' ') ; end

#lexical_reach(n) ⇒ Object

TODO: speed up compilation by writing custom #lexical_reach for sig-based subclasses (when you know which elements of #expr are lexical symbols)



38
39
40
# File 'lib/nydp/function_invocation.rb', line 38

def lexical_reach n
  @expr.map { |x| x.lexical_reach n}.max
end

#sourceObject



43
# File 'lib/nydp/function_invocation.rb', line 43

def source  ; @source       ; end

#to_sObject



44
# File 'lib/nydp/function_invocation.rb', line 44

def to_s    ; source.to_s   ; end