class N65::EnterScope

This directive to include bytes

Public Class Methods

new(name = nil) click to toggle source

Initialize with filename

# File lib/n65/directives/enter_scope.rb, line 28
def initialize(name = nil)
  @name = name
end
parse(line) click to toggle source

Try to parse an incbin directive

# File lib/n65/directives/enter_scope.rb, line 12
def self.parse(line)
  ##  Anonymous scope
  match_data = line.match(/^\.scope$/)
  unless match_data.nil?
    return EnterScope.new
  end

  ##  Named scope
  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

Public Instance Methods

exec(assembler) click to toggle source

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.

# File lib/n65/directives/enter_scope.rb, line 39
def exec(assembler)
  assembler.symbol_table.enter_scope(@name)
  unless @name.nil?
    assembler.symbol_table.define_symbol("-#{@name}", assembler.program_counter)
  end
end
to_s() click to toggle source

Display

# File lib/n65/directives/enter_scope.rb, line 49
def to_s
  ".scope #{@name}"
end