class SFRP::Mono::Pattern
Constants
- PatternExample
Public Class Methods
new(type_str, vconst_str, ref_var_str, arg_patterns)
click to toggle source
# File lib/sfrp/mono/pattern.rb, line 6 def initialize(type_str, vconst_str, ref_var_str, arg_patterns) @type_str = type_str @vconst_str = vconst_str @ref_var_str = ref_var_str @arg_patterns = arg_patterns end
Public Instance Methods
==(other)
click to toggle source
# File lib/sfrp/mono/pattern.rb, line 17 def ==(other) comp == other.comp end
accept?(pattern_example)
click to toggle source
# File lib/sfrp/mono/pattern.rb, line 29 def accept?(pattern_example) return true if any? return false unless pattern_example.vconst_str == @vconst_str @arg_patterns.zip(pattern_example.args).all? do |pat, pat_exam| pat.accept?(pat_exam) end end
any?()
click to toggle source
# File lib/sfrp/mono/pattern.rb, line 21 def any? @vconst_str.nil? end
comp()
click to toggle source
# File lib/sfrp/mono/pattern.rb, line 13 def comp [@type_str, @vconst_str, @ref_var_str, @arg_patterns] end
low_cond_exps(set, receiver_exp)
click to toggle source
Return whole conditional-low-exps for the pattern-matching.
# File lib/sfrp/mono/pattern.rb, line 38 def low_cond_exps(set, receiver_exp) return [] if any? vconst = set.vconst(@vconst_str) children = @arg_patterns.each_with_index.flat_map do |pat, mem_id| new_receiver = child_receiver_exp(set, receiver_exp, mem_id) pat.low_cond_exps(set, new_receiver) end vconst.low_compare_exps(set, receiver_exp) + children end
low_let_exps(set, receiver_exp, env)
click to toggle source
Return whole let-low-exps for the pattern-matching.
# File lib/sfrp/mono/pattern.rb, line 49 def low_let_exps(set, receiver_exp, env) env.add_var(@ref_var_str, @type_str) if named? lets = (named? ? ["#{@ref_var_str} = (#{receiver_exp})"] : []) return lets if any? children = @arg_patterns.each_with_index.flat_map do |pat, mem_id| new_receiver = child_receiver_exp(set, receiver_exp, mem_id) pat.low_let_exps(set, new_receiver, env) end lets + children end
named?()
click to toggle source
# File lib/sfrp/mono/pattern.rb, line 25 def named? @ref_var_str end
Private Instance Methods
child_receiver_exp(set, parent_receiver_exp, member_id)
click to toggle source
# File lib/sfrp/mono/pattern.rb, line 62 def child_receiver_exp(set, parent_receiver_exp, member_id) type = set.type(@type_str) terms_str = type.terms_access_str(parent_receiver_exp) "#{terms_str}.term#{type.term_id(@vconst_str)}.member#{member_id}" end