Class: RegularExpression::Bytecode::Compiled
- Inherits:
-
Object
- Object
- RegularExpression::Bytecode::Compiled
- Defined in:
- lib/regular_expression/bytecode.rb
Instance Attribute Summary collapse
-
#insns ⇒ Object
readonly
Returns the value of attribute insns.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
Instance Method Summary collapse
- #dump ⇒ Object
-
#initialize(insns, labels) ⇒ Compiled
constructor
A new instance of Compiled.
Constructor Details
#initialize(insns, labels) ⇒ Compiled
Returns a new instance of Compiled.
164 165 166 167 |
# File 'lib/regular_expression/bytecode.rb', line 164 def initialize(insns, labels) @insns = insns @labels = labels end |
Instance Attribute Details
#insns ⇒ Object (readonly)
Returns the value of attribute insns.
162 163 164 |
# File 'lib/regular_expression/bytecode.rb', line 162 def insns @insns end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
162 163 164 |
# File 'lib/regular_expression/bytecode.rb', line 162 def labels @labels end |
Instance Method Details
#dump ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/regular_expression/bytecode.rb', line 169 def dump output = StringIO.new # Labels store name -> address, but if we want to print the label name # at its address, we need to store the address to the name as well. reverse_labels = {} labels.each do |label, n| reverse_labels[n] = label end insns.each_with_index do |insn, n| label = reverse_labels[n] output.puts("#{label}:") if label output.puts(" #{insn}") end output.string end |