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
-
.parse(line) ⇒ Object
Try to parse an incbin directive.
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
Display.
Methods inherited from InstructionBase
Constructor Details
#initialize(name = nil) ⇒ EnterScope
Initialize with filename
28 29 30 |
# File 'lib/n65/directives/enter_scope.rb', line 28 def initialize(name = nil) @name = name end |
Class Method Details
.parse(line) ⇒ Object
Try to parse an incbin directive
12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 |
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.
39 40 41 42 43 44 |
# 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 ⇒ Object
Display
49 50 51 |
# File 'lib/n65/directives/enter_scope.rb', line 49 def to_s ".scope #{@name}" end |