Class: N65::EnterScope
- Inherits:
-
InstructionBase
- Object
- InstructionBase
- N65::EnterScope
- Defined in:
- lib/n65/directives/enter_scope.rb
Overview
This directive to include bytes
Class Method Summary collapse
Instance Method Summary collapse
-
#exec(assembler) ⇒ Object
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.
-
#initialize(name = nil) ⇒ EnterScope
constructor
Initialize with filename.
- #to_s ⇒ Object
Methods inherited from InstructionBase
Constructor Details
#initialize(name = nil) ⇒ EnterScope
Initialize with filename
21 22 23 |
# File 'lib/n65/directives/enter_scope.rb', line 21 def initialize(name = nil) @name = name end |
Class Method Details
.parse(line) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/n65/directives/enter_scope.rb', line 8 def self.parse(line) # Anonymous scope match_data = line.match(/^\.scope$/) return EnterScope.new unless match_data.nil? # 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 |
Instance Method Details
#exec(assembler) ⇒ Object
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.
30 31 32 33 |
# File 'lib/n65/directives/enter_scope.rb', line 30 def exec(assembler) assembler.symbol_table.enter_scope(@name) assembler.symbol_table.define_symbol("-#{@name}", assembler.program_counter) unless @name.nil? end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/n65/directives/enter_scope.rb', line 35 def to_s ".scope #{@name}" end |