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.



520
521
522
523
524
525
526
527
# File 'lib/wilson.rb', line 520

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



550
551
552
# File 'lib/wilson.rb', line 550

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

Instance Attribute Details

#bitsObject

Returns the value of attribute bits.



516
517
518
# File 'lib/wilson.rb', line 516

def bits
  @bits
end

#cachedInstructionsObject

Returns the value of attribute cachedInstructions.



516
517
518
# File 'lib/wilson.rb', line 516

def cachedInstructions
  @cachedInstructions
end

#instructionsObject



543
544
545
546
547
548
# File 'lib/wilson.rb', line 543

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

#procedureObject

Returns the value of attribute procedure.



516
517
518
# File 'lib/wilson.rb', line 516

def procedure
  @procedure
end

#processorsObject

Returns the value of attribute processors.



517
518
519
# File 'lib/wilson.rb', line 517

def processors
  @processors
end

#streamObject

Returns the value of attribute stream.



516
517
518
# File 'lib/wilson.rb', line 516

def stream
  @stream
end

Instance Method Details

#assemble(instruction) ⇒ Object



566
567
568
569
570
571
# File 'lib/wilson.rb', line 566

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



562
563
564
# File 'lib/wilson.rb', line 562

def future_label
  FutureLabel.on self
end

#inspectObject



529
530
531
# File 'lib/wilson.rb', line 529

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

#instructionFromMessage(msg, *args) ⇒ Object



554
555
556
# File 'lib/wilson.rb', line 554

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

#labelObject



558
559
560
# File 'lib/wilson.rb', line 558

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

#supportsProcessor(instructionProcessors) ⇒ Object



538
539
540
541
# File 'lib/wilson.rb', line 538

def supportsProcessor instructionProcessors
  # TODO: can still be improved. hashes, caching... something
  ! (processors & instructionProcessors).empty?
end