Class: Stupidedi::Builder::IdentifierStack::ST

Inherits:
Object
  • Object
show all
Defined in:
lib/stupidedi/builder/identifier_stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, id) ⇒ ST

Returns a new instance of ST.



108
109
110
# File 'lib/stupidedi/builder/identifier_stack.rb', line 108

def initialize(parent, id)
  @sequence, @parent, @id = 0, parent, id
end

Instance Attribute Details

#sequence=(value) ⇒ Object (writeonly)

Sets the attribute sequence

Parameters:

  • value

    the value to set the attribute sequence to.



106
107
108
# File 'lib/stupidedi/builder/identifier_stack.rb', line 106

def sequence=(value)
  @sequence = value
end

Instance Method Details

#count(builder) ⇒ Object

Number of segments (ST..SE)



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/stupidedi/builder/identifier_stack.rb', line 121

def count(builder)
  m = Either.success(builder.machine)

  while m.defined?
    if m.flatmap(&:segment).map{|s| s.node.id == :ST }.fetch(false)
      return m.flatmap{|n| n.distance(builder.machine) }.fetch(0) + 2
    else
      m = m.flatmap(&:parent)
    end
  end
end

#hlObject



112
113
114
# File 'lib/stupidedi/builder/identifier_stack.rb', line 112

def hl
  HL.new(self, @sequence += 1)
end

#idObject



116
117
118
# File 'lib/stupidedi/builder/identifier_stack.rb', line 116

def id
  @id.to_s.rjust(4, "0")
end

#popObject



133
134
135
# File 'lib/stupidedi/builder/identifier_stack.rb', line 133

def pop
  @parent
end