Class: Haxor::Compiler::Unit
- Inherits:
-
Object
- Object
- Haxor::Compiler::Unit
- Defined in:
- lib/haxor/compiler/unit.rb
Instance Attribute Summary collapse
-
#section ⇒ Object
Returns the value of attribute section.
Class Method Summary collapse
Instance Method Summary collapse
- #add(item) ⇒ Object
-
#initialize ⇒ Unit
constructor
A new instance of Unit.
- #save(filename) ⇒ Object
- #tokens ⇒ Object
Constructor Details
#initialize ⇒ Unit
Returns a new instance of Unit.
6 7 8 9 10 11 12 13 |
# File 'lib/haxor/compiler/unit.rb', line 6 def initialize @section = :text @sections = { text: [], data: [], bss: [] } end |
Instance Attribute Details
#section ⇒ Object
Returns the value of attribute section.
4 5 6 |
# File 'lib/haxor/compiler/unit.rb', line 4 def section @section end |
Class Method Details
.load(filename) ⇒ Object
28 29 30 |
# File 'lib/haxor/compiler/unit.rb', line 28 def self.load(filename) Marshal.load File.read(filename) end |
Instance Method Details
#add(item) ⇒ Object
15 16 17 |
# File 'lib/haxor/compiler/unit.rb', line 15 def add(item) @sections[@section] << item end |
#save(filename) ⇒ Object
32 33 34 35 36 |
# File 'lib/haxor/compiler/unit.rb', line 32 def save(filename) fd = File.open(filename, 'wb') fd.write Marshal.dump(self) fd.close end |
#tokens ⇒ Object
24 25 26 |
# File 'lib/haxor/compiler/unit.rb', line 24 def tokens @sections[@section] end |