class SFRP::Poly::Function

Attributes

str[R]

Public Class Methods

new(str, param_strs, ftype_annot, exp = nil, ffi_str = nil) click to toggle source
# File lib/sfrp/poly/elements.rb, line 6
def initialize(str, param_strs, ftype_annot, exp = nil, ffi_str = nil)
  raise ArgumentError if exp.nil? && ffi_str.nil?
  @str = str
  @param_strs = param_strs
  @ftype_annot = ftype_annot
  @exp = exp
  @ffi_str = ffi_str
end

Public Instance Methods

check_recursion(set, path = []) click to toggle source
# File lib/sfrp/poly/elements.rb, line 28
def check_recursion(set, path = [])
  return if @exp == nil
  if path.include?(@str)
    raise RecursiveError.new(path.drop_while { |s| s != @str })
  end
  @exp.called_func_strs.each do |str|
    set.func(str).check_recursion(set, path + [@str])
  end
end
clone() click to toggle source
# File lib/sfrp/poly/elements.rb, line 23
def clone
  exp = (@exp ? @exp.clone : nil)
  Function.new(@str, @param_strs, @ftype_annot, exp, @ffi_str)
end
ftyping(set) click to toggle source
# File lib/sfrp/poly/elements.rb, line 15
def ftyping(set)
  @ftyping ||= @ftype_annot.to_ftyping.instance do |ft|
    var_env = {}
    @param_strs.zip(ft.params) { |str, typing| var_env[str] = typing }
    ft.body.unify(@exp.typing(set, var_env)) if @exp
  end
end
to_mono(monofier, mono_func_str) click to toggle source
# File lib/sfrp/poly/elements.rb, line 38
def to_mono(monofier, mono_func_str)
  raise UndeterminableTypeError.new(@str, @ftyping) unless @ftyping.mono?
  mono_type_str = monofier.use_type(@ftyping.body)
  M.func(mono_type_str, mono_func_str) do |f|
    @param_strs.zip(@ftyping.params) do |str, typing|
      f.param(monofier.use_type(typing), str)
    end
    f.exp { @exp.to_mono(monofier) } if @exp
    f.ffi_str(@ffi_str) if @ffi_str
  end
end