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.



1083
1084
1085
1086
# File 'lib/wilson.rb', line 1083

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.



1081
1082
1083
# File 'lib/wilson.rb', line 1081

def positions
  @positions
end

Instance Method Details

#add(aPosition) ⇒ Object



1116
1117
1118
# File 'lib/wilson.rb', line 1116

def add aPosition
  positions << aPosition
end

#future_label?Boolean

Returns:

  • (Boolean)


1112
1113
1114
# File 'lib/wilson.rb', line 1112

def future_label?
  position.nil?
end

#plantObject



1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
# File 'lib/wilson.rb', line 1088

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