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)
|
2015-03-06 01:21:51 +00:00
|
|
|
## Anonymous scope
|
|
|
|
match_data = line.match(/^\.scope$/)
|
|
|
|
unless match_data.nil?
|
2015-03-06 02:49:44 +00:00
|
|
|
return EnterScope.new
|
2015-03-06 01:21:51 +00:00
|
|
|
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
|
2015-03-06 01:21:51 +00:00
|
|
|
def initialize(name = nil)
|
2015-03-05 21:45:19 +00:00
|
|
|
@name = name
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
####
|
2015-03-06 00:53:55 +00:00
|
|
|
## 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)
|
2015-03-06 01:21:51 +00:00
|
|
|
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
|