Class: Wilson::Operand

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

Overview

Operand is any kind of operand used in a command or instruction, eg: registers, memory addresses, labels, immediates, etc.

Direct Known Subclasses

Address, Immediate, Label, Register, SpecialRegister

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bits = nil, machine = nil) ⇒ Operand

TODO: fix all initialize methods from here down to have cleaner args



886
887
888
889
# File 'lib/wilson.rb', line 886

def initialize bits = nil, machine = nil
  @bits = bits
  @machine = machine
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(msg, *args, &b) ⇒ Object



891
892
893
# File 'lib/wilson.rb', line 891

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

Instance Attribute Details

#bitsObject

Returns the value of attribute bits.



877
878
879
# File 'lib/wilson.rb', line 877

def bits
  @bits
end

#machineObject

Returns the value of attribute machine.



877
878
879
# File 'lib/wilson.rb', line 877

def machine
  @machine
end

Class Method Details

.on(machine) ⇒ Object



879
880
881
882
883
# File 'lib/wilson.rb', line 879

def self.on machine
  x = self.new
  x.machine = machine
  x
end

Instance Method Details

#instructionFromMessage(msg, *args, &b) ⇒ Object



895
896
897
# File 'lib/wilson.rb', line 895

def instructionFromMessage msg, *args, &b
  Instruction.on_message machine, [msg, self, *args] + (b ? [b] : [])
end

#operand?Boolean

Returns:

  • (Boolean)


899
900
901
# File 'lib/wilson.rb', line 899

def operand?
  true
end