Class: Stupidedi::Builder::ConstraintTable::DepthBased

Inherits:
Stupidedi::Builder::ConstraintTable show all
Defined in:
lib/stupidedi/builder/constraint_table.rb

Overview

Chooses the Instruction that pops the fewest number of states. For example, in the X222 837P an HL segment signals the start of a new 2000 loop, but may or may not begin a new Table 2 – the specifications aren’t actually clear. This rule will avoid creating a new Table 2 if possible, and instead create a new 2000 loop under the current Table 2.

Instance Method Summary collapse

Methods inherited from Stupidedi::Builder::ConstraintTable

build

Constructor Details

#initialize(instructions) ⇒ DepthBased

Returns a new instance of DepthBased.



47
48
49
# File 'lib/stupidedi/builder/constraint_table.rb', line 47

def initialize(instructions)
  @instructions = instructions
end

Instance Method Details

#matches(segment_tok, strict) ⇒ Array<Instruction>

Returns:



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/stupidedi/builder/constraint_table.rb', line 52

def matches(segment_tok, strict)
  @__matches ||= begin
    deepest = @instructions.head

    @instructions.tail.each do |i|
      if i.pop_count < deepest.pop_count
        deepest = i
      end
    end

    deepest.cons
  end
end