1
0
mirror of https://github.com/safiire/n65.git synced 2024-12-12 00:29:03 +00:00
n65/lib/directives/enter_scope.rb

56 lines
1.2 KiB
Ruby
Raw Normal View History

2015-03-05 21:45:19 +00:00
require_relative '../instruction_base'
module Assembler6502
####
## This directive to include bytes
class EnterScope < InstructionBase
####
## Try to parse an incbin directive
def self.parse(line)
## Anonymous scope
match_data = line.match(/^\.scope$/)
unless match_data.nil?
2015-03-06 02:49:44 +00:00
return EnterScope.new
end
## Named scope
2015-03-05 21:45:19 +00:00
match_data = line.match(/^\.scope\s+([a-zA-Z][a-zA-Z0-9_]+)$/)
return nil if match_data.nil?
EnterScope.new(match_data[1])
end
####
## Initialize with filename
def initialize(name = nil)
2015-03-05 21:45:19 +00:00
@name = name
end
####
## Execute on the assembler, also create a symbol referring to
## the current pc which contains a hyphen, and is impossible for
## the user to create. This makes a scope simultaneously act as
## a label to the current PC. If someone tries to use a scope
## name as a label, it can return the address when the scope opened.
2015-03-05 21:45:19 +00:00
def exec(assembler)
assembler.symbol_table.enter_scope(@name)
unless @name.nil?
assembler.symbol_table.define_symbol("-#{@name}", assembler.program_counter)
end
2015-03-05 21:45:19 +00:00
end
####
## Display
def to_s
".scope #{@name}"
end
end
end