Sha256: 9c6733a324d18fd0271785a2f6ec26012b5b11fc8e98c1e21271e216b9b6b073

Contents?: true

Size: 791 Bytes

Versions: 3

Compression:

Stored size: 791 Bytes

Contents

module Haxor
  module Compiler
    class Unit
      attr_reader :section
      attr_reader :hash

      def initialize(filename)
        @section = :text
        @sections = {
          text: [],
          data: [],
          bss: []
        }
        @filename = filename
        @hash = Digest::SHA1.hexdigest filename
      end

      def add(item)
        @sections[@section] << item
      end

      def section=(section)
        fail unless @sections.key? section
        @section = section
      end

      def tokens
        @sections[@section]
      end

      def self.load(filename)
        Marshal.load File.read(filename)
      end

      def save(filename)
        fd = File.open(filename, 'wb')
        fd.write Marshal.dump(self)
        fd.close
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
haxor-0.5.0 lib/haxor/compiler/unit.rb
haxor-0.4.0 lib/haxor/compiler/unit.rb
haxor-0.3.0 lib/haxor/compiler/unit.rb