Class: Wardite::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/wardite.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(import_object, &blk) ⇒ Instance

Returns a new instance of Instance.



595
596
597
598
599
600
601
602
# File 'lib/wardite.rb', line 595

def initialize(import_object, &blk)
  blk.call(self)
  @import_object = import_object

  @store = Store.new(self)
  @exports = Exports.new(self.export_section, store)
  @runtime = Runtime.new(self)
end

Instance Attribute Details

#exportsObject

: Exports



589
590
591
# File 'lib/wardite.rb', line 589

def exports
  @exports
end

#import_objectObject (readonly)

: Hash[Symbol, Hash[Symbol, Proc]]



591
592
593
# File 'lib/wardite.rb', line 591

def import_object
  @import_object
end

#runtimeObject

: Runtime



585
586
587
# File 'lib/wardite.rb', line 585

def runtime
  @runtime
end

#sectionsObject

: Array



583
584
585
# File 'lib/wardite.rb', line 583

def sections
  @sections
end

#storeObject

: Store



587
588
589
# File 'lib/wardite.rb', line 587

def store
  @store
end

#versionObject

: Integer



581
582
583
# File 'lib/wardite.rb', line 581

def version
  @version
end

Instance Method Details

#code_sectionObject



663
664
665
666
667
668
669
670
671
672
# File 'lib/wardite.rb', line 663

def code_section
  sec = @sections.find{|s| s.code == Const::SectionCode }
  if !sec
    return nil
  end
  if !sec.is_a?(CodeSection)
    raise(GenericError, "instance doesn't have required section")
  end
  sec
end

#data_sectionObject



639
640
641
642
643
644
645
646
647
648
# File 'lib/wardite.rb', line 639

def data_section
  sec = @sections.find{|s| s.code == Const::SectionData }
  if !sec
    return nil
  end
  if !sec.is_a?(DataSection)
    raise(GenericError, "[BUG] found invalid data section")
  end
  sec
end

#export_sectionObject



675
676
677
678
679
680
681
682
683
684
# File 'lib/wardite.rb', line 675

def export_section
  sec = @sections.find{|s| s.code == Const::SectionExport }
  if !sec
    return ExportSection.new
  end
  if !sec.is_a?(ExportSection)
    raise(GenericError, "instance doesn't have required section")
  end
  sec
end

#function_sectionObject



651
652
653
654
655
656
657
658
659
660
# File 'lib/wardite.rb', line 651

def function_section
  sec = @sections.find{|s| s.code == Const::SectionFunction }
  if !sec
    return nil
  end
  if !sec.is_a?(FunctionSection)
    raise(GenericError, "instance doesn't have required section")
  end
  sec
end

#import_sectionObject



605
606
607
608
609
610
611
612
# File 'lib/wardite.rb', line 605

def import_section
  sec = @sections.find{|s| s.code == Const::SectionImport }
  if !sec.is_a?(ImportSection)
    # returns dummy empty section
    return ImportSection.new
  end
  sec
end

#memory_sectionObject



627
628
629
630
631
632
633
634
635
636
# File 'lib/wardite.rb', line 627

def memory_section
  sec = @sections.find{|s| s.code == Const::SectionMemory }
  if !sec
    return nil
  end
  if !sec.is_a?(MemorySection)
    raise(GenericError, "[BUG] found invalid memory section")
  end
  sec
end

#type_sectionObject



615
616
617
618
619
620
621
622
623
624
# File 'lib/wardite.rb', line 615

def type_section
  sec = @sections.find{|s| s.code == Wardite::Const::SectionType }
  if !sec
    return nil
  end
  if !sec.is_a?(TypeSection)
    raise(GenericError, "instance doesn't have required section")
  end
  sec
end