Class: SFRP::Poly::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/sfrp/poly/elements.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str, param_strs, ftype_annot, exp = nil, ffi_str = nil) ⇒ Function

Returns a new instance of Function.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
# 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

Instance Attribute Details

#strObject (readonly)

Returns the value of attribute str.



4
5
6
# File 'lib/sfrp/poly/elements.rb', line 4

def str
  @str
end

Instance Method Details

#check_recursion(set, path = []) ⇒ Object



28
29
30
31
32
33
34
35
36
# 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

#cloneObject



23
24
25
26
# 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) ⇒ Object



15
16
17
18
19
20
21
# 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) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# 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