Class: Wilson::MachineCode

Inherits:
Object show all
Defined in:
lib/wilson.rb

Overview

MachineCode is an abstract machine that has subclasses for each concrete machine type that you can write assembly language for. Right now this library only supports X86, so loko at MachineCodeX86 for more details on how to use it.

Direct Known Subclasses

MachineCodeX86

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMachineCode

Returns a new instance of MachineCode.



592
593
594
595
596
597
598
599
# File 'lib/wilson.rb', line 592

def initialize
  self.procedure  = nil
  self.bits       = self.defaultBits
  self.processors = self.defaultProcessors
  self.stream     = []

  self.setupMachine
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(msg, *args) ⇒ Object



620
621
622
# File 'lib/wilson.rb', line 620

def method_missing msg, *args
  super unless self.instructionFromMessage(msg, *args).assemble
end

Instance Attribute Details

#bitsObject

Returns the value of attribute bits.



588
589
590
# File 'lib/wilson.rb', line 588

def bits
  @bits
end

#cachedInstructionsObject

Returns the value of attribute cachedInstructions.



588
589
590
# File 'lib/wilson.rb', line 588

def cachedInstructions
  @cachedInstructions
end

#instructionsObject



614
615
616
617
618
# File 'lib/wilson.rb', line 614

def instructions
  self.cachedInstructions ||= @instructions.select { |e|
    self.supportsProcessor e.processors
  }
end

#procedureObject

Returns the value of attribute procedure.



588
589
590
# File 'lib/wilson.rb', line 588

def procedure
  @procedure
end

#processorsObject

Returns the value of attribute processors.



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

def processors
  @processors
end

#streamObject

Returns the value of attribute stream.



588
589
590
# File 'lib/wilson.rb', line 588

def stream
  @stream
end

Instance Method Details

#assemble(instruction) ⇒ Object



636
637
638
639
640
641
# File 'lib/wilson.rb', line 636

def assemble instruction
  raise "no"
  #     aBlock on: MessageNotUnderstood do: [:ex |
  #         ex originator class = BlockClosure ifFalse: [ex pass].
  #         ex resume: (ex originator value m perform: ex parameter selector withArguments: ex parameter arguments)]</body>
end

#future_labelObject



632
633
634
# File 'lib/wilson.rb', line 632

def future_label
  FutureLabel.on self
end

#inspectObject



601
602
603
# File 'lib/wilson.rb', line 601

def inspect
  "#{self.class}#{stream.inspect}"
end

#instructionFromMessage(msg, *args) ⇒ Object



624
625
626
# File 'lib/wilson.rb', line 624

def instructionFromMessage msg, *args
  Instruction.on_message self, [msg, *args]
end

#labelObject



628
629
630
# File 'lib/wilson.rb', line 628

def label
  Label.on_at(self, stream.size)
end

#supportsProcessor(instructionProcessors) ⇒ Object



610
611
612
# File 'lib/wilson.rb', line 610

def supportsProcessor instructionProcessors
  processors.any? { |e| instructionProcessors.include? e }
end