1
0
mirror of https://github.com/safiire/n65.git synced 2024-06-10 15:29:53 +00:00
n65/lib/n65/directives/label.rb
2020-08-30 13:57:46 -07:00

34 lines
758 B
Ruby

# frozen_string_literal: true
module N65
# This class represents a label, and will create
# an entry in the symbol table associated with
# the address it appears at.
class Label
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 new(label)
end
nil
end
# Create a new label object
def initialize(symbol)
@symbol = symbol
end
# Create an entry in the symbol table for this label
def exec(assembler)
program_counter = assembler.program_counter
assembler.symbol_table.define_symbol(@symbol, program_counter)
end
# Display
def to_s
"#{@symbol}:"
end
end
end