Class: Haxor::Compiler::Unit
- Inherits:
-
Object
- Object
- Haxor::Compiler::Unit
- Defined in:
- lib/haxor/compiler/unit.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#section ⇒ Object
Returns the value of attribute section.
Class Method Summary collapse
Instance Method Summary collapse
- #add(item) ⇒ Object
-
#initialize(filename) ⇒ Unit
constructor
A new instance of Unit.
- #save(filename) ⇒ Object
- #tokens ⇒ Object
Constructor Details
#initialize(filename) ⇒ Unit
Returns a new instance of Unit.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/haxor/compiler/unit.rb', line 7 def initialize(filename) @section = :text @sections = { text: [], data: [], bss: [] } @filename = filename @hash = Digest::SHA1.hexdigest filename end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
5 6 7 |
# File 'lib/haxor/compiler/unit.rb', line 5 def hash @hash end |
#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
31 32 33 |
# File 'lib/haxor/compiler/unit.rb', line 31 def self.load(filename) Marshal.load File.read(filename) end |
Instance Method Details
#add(item) ⇒ Object
18 19 20 |
# File 'lib/haxor/compiler/unit.rb', line 18 def add(item) @sections[@section] << item end |
#save(filename) ⇒ Object
35 36 37 38 39 |
# File 'lib/haxor/compiler/unit.rb', line 35 def save(filename) fd = File.open(filename, 'wb') fd.write Marshal.dump(self) fd.close end |
#tokens ⇒ Object
27 28 29 |
# File 'lib/haxor/compiler/unit.rb', line 27 def tokens @sections[@section] end |