Class: Wilson::FutureLabel

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

Overview

FutureLabel is a label in memory that hasn’t been defined yet and will go back and fill in the appropriate memory bytes later

Instance Attribute Summary collapse

Attributes inherited from Label

#position

Attributes inherited from Operand

#bits, #machine

Instance Method Summary collapse

Methods inherited from Label

#bits, #label?, on_at

Methods inherited from Operand

#instructionFromMessage, #method_missing, on, #operand?

Constructor Details

#initializeFutureLabel

Returns a new instance of FutureLabel.



1102
1103
1104
1105
# File 'lib/wilson.rb', line 1102

def initialize
  super
  self.positions = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Wilson::Operand

Instance Attribute Details

#positionsObject

Returns the value of attribute positions.



1100
1101
1102
# File 'lib/wilson.rb', line 1100

def positions
  @positions
end

Instance Method Details

#add(aPosition) ⇒ Object



1135
1136
1137
# File 'lib/wilson.rb', line 1135

def add aPosition
  positions << aPosition
end

#future_label?Boolean

Returns:

  • (Boolean)


1131
1132
1133
# File 'lib/wilson.rb', line 1131

def future_label?
  position.nil?
end

#plantObject



1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
# File 'lib/wilson.rb', line 1107

def plant
  self.position = machine.stream.size

  positions.each do |each|
    size = machine.stream[each + 1]
    address = []
    case size
    when 2 then
      address.push_B(position - each - 2)
    when 3 then
      address.push_W(position - each - 3)
    when 5 then
      address.push_D(position - each - 5)
    else
      raise "unhandled size #{size}"
    end

    address.each_with_index do |byte, index|
      idx = each + index + 1
      machine.stream[idx] = byte
    end
  end
end