Class: N65::Label
- Inherits:
-
Object
- Object
- N65::Label
- Defined in:
- lib/n65/directives/label.rb
Overview
This class represents a label, and will create
an entry in the symbol table associated with
the address it appears at.
Class Method Summary collapse
-
.parse(line) ⇒ Object
Try to parse as a label.
Instance Method Summary collapse
-
#exec(assembler) ⇒ Object
Create an entry in the symbol table for this label.
-
#initialize(symbol) ⇒ Label
constructor
Create a new label object.
-
#to_s ⇒ Object
Display.
Constructor Details
#initialize(symbol) ⇒ Label
Create a new label object
24 25 26 |
# File 'lib/n65/directives/label.rb', line 24 def initialize(symbol) @symbol = symbol end |
Class Method Details
.parse(line) ⇒ Object
Try to parse as a label
12 13 14 15 16 17 18 19 |
# File 'lib/n65/directives/label.rb', line 12 def self.parse(line) match_data = line.match(/^([a-zA-Z][a-zA-Z0-9_]+):$/) unless match_data.nil? label = match_data[1].to_sym return self.new(label) end nil end |
Instance Method Details
#exec(assembler) ⇒ Object
Create an entry in the symbol table for this label
31 32 33 34 |
# File 'lib/n65/directives/label.rb', line 31 def exec(assembler) program_counter = assembler.program_counter assembler.symbol_table.define_symbol(@symbol, program_counter) end |
#to_s ⇒ Object
Display
39 40 41 |
# File 'lib/n65/directives/label.rb', line 39 def to_s "#{@symbol}:" end |