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 look 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.



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

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



634
635
636
# File 'lib/wilson.rb', line 634

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

Instance Attribute Details

#bitsObject

Returns the value of attribute bits.



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

def bits
  @bits
end

#cachedInstructionsObject

Returns the value of attribute cachedInstructions.



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

def cachedInstructions
  @cachedInstructions
end

#instructionsObject



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

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

#procedureObject

Returns the value of attribute procedure.



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

def procedure
  @procedure
end

#processorsObject

Returns the value of attribute processors.



603
604
605
# File 'lib/wilson.rb', line 603

def processors
  @processors
end

#streamObject

Returns the value of attribute stream.



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

def stream
  @stream
end

Instance Method Details

#assemble(instruction) ⇒ Object



650
651
652
653
654
655
# File 'lib/wilson.rb', line 650

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



646
647
648
# File 'lib/wilson.rb', line 646

def future_label
  FutureLabel.on self
end

#inspectObject



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

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

#instructionFromMessage(msg, *args) ⇒ Object



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

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

#labelObject



642
643
644
# File 'lib/wilson.rb', line 642

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

#supportsProcessor(instructionProcessors) ⇒ Object



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

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