Class: Jade::Frontend::PatternAnalysis::Matrix

Inherits:
Data
  • Object
show all
Defined in:
lib/jade/frontend/pattern_analysis/matrix.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rowsObject (readonly)

Returns the value of attribute rows

Returns:

  • (Object)

    the current value of rows



4
5
6
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 4

def rows
  @rows
end

#typesObject (readonly)

Returns the value of attribute types

Returns:

  • (Object)

    the current value of 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

.wildcard(types) ⇒ Object



5
6
7
8
9
10
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 5

def self.wildcard(types)
  types
    .map { Wildcard[] }
    .then { [it] }
    .then { Matrix[it, types] }
end

Instance Method Details

#any?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


30
31
32
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 30

def empty?
  rows.empty?
end

#include?(row) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 22

def include?(row)
  rows.include?(row)
end

#mapObject



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) ⇒ 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
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 42

def missing_patterns(env)
  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?

  heads = head_constructors

  if infinite?(type) || type_var?(type)
    unmatched_column(env)

  elsif expandable?(type, env)
    expand(env).missing_patterns(env)

  elsif heads.empty?
    unmatched_column(env)

  else
    constructors_of(type, env)
      .reduce(Matrix.empty.with(types:)) do |acc, constructor|
        witnesses(constructor, env, heads.include?(constructor.name))
          .then { acc.concat(it) }
      end
  end
end

#sizeObject



26
27
28
# File 'lib/jade/frontend/pattern_analysis/matrix.rb', line 26

def size
  rows.size
end