Class: Jade::Frontend::PatternAnalysis::Matrix
- Inherits:
-
Data
- Object
- Data
- Jade::Frontend::PatternAnalysis::Matrix
- Defined in:
- lib/jade/frontend/pattern_analysis/matrix.rb
Instance Attribute Summary collapse
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Class Method Summary collapse
Instance Method Summary collapse
- #any? ⇒ Boolean
- #concat(other) ⇒ Object
- #empty? ⇒ Boolean
- #include?(row) ⇒ Boolean
- #map ⇒ Object
- #missing_patterns(env, seen_recursive_types = ::Set.new) ⇒ Object
- #size ⇒ Object
Instance Attribute Details
#rows ⇒ Object (readonly)
Returns the value of attribute rows
4 5 6 |
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 4 def rows @rows end |
#types ⇒ Object (readonly)
Returns the value of attribute types
4 5 6 |
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 4 def types @types end |
Class Method Details
.empty(types = []) ⇒ Object
12 13 14 |
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 12 def self.empty(types = []) self.new([], types) end |
Instance Method Details
#any? ⇒ Boolean
34 35 36 |
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 34 def any? rows.any? end |
#concat(other) ⇒ Object
38 39 40 |
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 38 def concat(other) with(rows: rows + other.rows) end |
#empty? ⇒ Boolean
30 31 32 |
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 30 def empty? rows.empty? end |
#include?(row) ⇒ Boolean
22 23 24 |
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 22 def include?(row) rows.include?(row) end |
#map ⇒ Object
16 17 18 19 20 |
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 16 def map rows .map { yield it } .then { with(rows: it) } end |
#missing_patterns(env, seen_recursive_types = ::Set.new) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 42 def missing_patterns(env, seen_recursive_types = ::Set.new) if types.empty? return rows.empty? ? Matrix[[[]], types] : Matrix.empty end type = types.first return Matrix.empty if never?(type) return Matrix.wildcard(types) if rows.empty? if infinite?(type) || type_var?(type) || seen_recursive_types.include?(type) matrix = default .missing_patterns(env, seen_recursive_types) matrix .map { [Wildcard[]] + it } elsif (type, env) (env).missing_patterns(env, seen_recursive_types) else new_seen = seen_recursive_types | ::Set[type] constructors_of(type, env) .reduce(Matrix.empty.with(types:)) do |acc, constructor| missing = specialize(constructor) .missing_patterns(env, new_seen) missing .map do |row| new_args = row.take(constructor.args.size) tail = row.drop(constructor.args.size) [Constructor[constructor.name, new_args]] + tail end .then { acc.concat(it) } end end end |
#size ⇒ Object
26 27 28 |
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 26 def size rows.size end |