Class: Stupidedi::Builder::ConstraintTable::Shallowest

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

Overview

Chooses the Instruction that pops the greatest 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 always create a new Table 2 and a new 2000 loop under it.

Instance Method Summary collapse

Methods inherited from Stupidedi::Builder::ConstraintTable

build

Constructor Details

#initialize(instructions) ⇒ Shallowest

Returns a new instance of Shallowest.



51
52
53
# File 'lib/stupidedi/builder/constraint_table.rb', line 51

def initialize(instructions)
  @instructions = instructions
end

Instance Method Details

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

Returns:



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/stupidedi/builder/constraint_table.rb', line 56

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

    @instructions.tail.each do |i|
      if i.pop_count > shallowest.pop_count
        shallowest = i
      end
    end

    shallowest.cons
  end
end