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.



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

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.



104
105
106
# File 'lib/stupidedi/builder/identifier_stack.rb', line 104

def sequence=(value)
  @sequence = value
end

Instance Method Details

#count(builder) ⇒ Object

Number of segments (ST..SE)



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

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



110
111
112
# File 'lib/stupidedi/builder/identifier_stack.rb', line 110

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

#idObject



114
115
116
# File 'lib/stupidedi/builder/identifier_stack.rb', line 114

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

#popObject



131
132
133
# File 'lib/stupidedi/builder/identifier_stack.rb', line 131

def pop
  @parent
end