Class: SFRP::Mono::Pattern
- Inherits:
-
Object
- Object
- SFRP::Mono::Pattern
- Defined in:
- lib/sfrp/mono/pattern.rb
Defined Under Namespace
Classes: PatternExample
Instance Method Summary collapse
- #==(other) ⇒ Object
- #accept?(pattern_example) ⇒ Boolean
- #any? ⇒ Boolean
- #comp ⇒ Object
-
#initialize(type_str, vconst_str, ref_var_str, arg_patterns) ⇒ Pattern
constructor
A new instance of Pattern.
-
#low_cond_exps(set, receiver_exp) ⇒ Object
Return whole conditional-low-exps for the pattern-matching.
-
#low_let_exps(set, receiver_exp, env) ⇒ Object
Return whole let-low-exps for the pattern-matching.
- #named? ⇒ Boolean
Constructor Details
#initialize(type_str, vconst_str, ref_var_str, arg_patterns) ⇒ Pattern
Returns a new instance of Pattern.
6 7 8 9 10 11 |
# 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 |
Instance Method Details
#==(other) ⇒ Object
17 18 19 |
# File 'lib/sfrp/mono/pattern.rb', line 17 def ==(other) comp == other.comp end |
#accept?(pattern_example) ⇒ Boolean
29 30 31 32 33 34 35 |
# 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? ⇒ Boolean
21 22 23 |
# File 'lib/sfrp/mono/pattern.rb', line 21 def any? @vconst_str.nil? end |
#comp ⇒ Object
13 14 15 |
# 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) ⇒ Object
Return whole conditional-low-exps for the pattern-matching.
38 39 40 41 42 43 44 45 46 |
# 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) ⇒ Object
Return whole let-low-exps for the pattern-matching.
49 50 51 52 53 54 55 56 57 58 |
# 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? ⇒ Boolean
25 26 27 |
# File 'lib/sfrp/mono/pattern.rb', line 25 def named? @ref_var_str end |