class Nydp::Invocation::Base

Public Class Methods

new(expr, source, sig=nil) click to toggle source
# File lib/nydp/function_invocation.rb, line 8
def initialize expr, source, sig=nil
  @expr, @source, @sig = expr, source, sig
end

Public Instance Methods

compile_do_expr_to_ruby(indent, srcs) click to toggle source
# File lib/nydp/function_invocation.rb, line 20
def compile_do_expr_to_ruby indent, srcs
  if @expr.car.is_a?(InterpretedFunction) && !@expr.cdr && @expr.car.can_do?
    @expr.car.compile_do_expr_to_ruby indent, srcs
  end
end
compile_to_ruby(indent, srcs, opts={}) click to toggle source
# File lib/nydp/function_invocation.rb, line 12
def compile_to_ruby indent, srcs, opts={}
  ruby = if opts[:cando]
           compile_do_expr_to_ruby indent, srcs
         end

  ruby ||= normal_compile_to_ruby indent, srcs
end
handle(e, f, invoker, *args) click to toggle source
if ra.empty?
  "#{indent}#{fn}._nydp_callable(#{@expr.first.to_s.inspect})._nydp_call()"
else
  "#{indent}#{fn}._nydp_callable(#{@expr.first.to_s.inspect})._nydp_call(

#{ra.join(ā€œ,nā€)} #{indent})ā€œ

  end
end
# File lib/nydp/function_invocation.rb, line 65
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._nydp_inspect} is not a function: args were #{args._nydp_inspect} in #{source._nydp_inspect}")
    else
      msg  = args.map { |a| "  #{a._nydp_inspect}"}.join("\n")
      msg  =  "failed to execute invocation #{f._nydp_inspect}\n#{msg}"
      msg +=  "\nsource was #{source._nydp_inspect}"
      msg +=  "\nfunction name was #{source.car._nydp_inspect}"
      raise InvocationFailed.new msg
    end
  end
end
inspect() click to toggle source
# File lib/nydp/function_invocation.rb, line 87
def inspect ; "(" + @expr.map { |x| x._nydp_inspect }.join(' ') + ")" ; end
lexical_reach(n) click to toggle source

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

# File lib/nydp/function_invocation.rb, line 83
def lexical_reach n
  @expr.map { |x| x.lexical_reach n}.max
end
normal_compile_to_ruby(indent, srcs) click to toggle source
# File lib/nydp/function_invocation.rb, line 26
      def normal_compile_to_ruby indent, srcs
        ra = @expr.map { |e| e.compile_to_ruby "#{indent}  ", srcs}.to_a
        fn_expr = @expr.first.to_s.inspect.gsub("\'", "\\\\'")
        fn = ra.shift

        src_expr = @expr.inspect.split(/\n/).join('\n')

        if ra.empty?
          "#{indent}  ##> #{src_expr}
#{indent}  (begin ; #{fn}.
#{indent}    ##> #{src_expr}
#{indent}    _nydp_call()
#{indent}   rescue CantCallNil => e
#{indent}    (raise 'can\\'t call nil : #{fn_expr}')
#{indent}   end)"
        else
          "#{indent}  ##> #{src_expr}
#{indent}  (begin ; #{fn}.
#{indent}    ##> #{src_expr}
#{indent}    _nydp_call(#{ra.join(",\n")})
#{indent}   rescue CantCallNil => e
#{indent}    (raise 'can\\'t call nil : #{fn_expr}')
#{indent}   end)"
        end
      end
source() click to toggle source
# File lib/nydp/function_invocation.rb, line 88
def source  ; @source       ; end
to_s() click to toggle source
# File lib/nydp/function_invocation.rb, line 89
def to_s    ; source.to_s   ; end