rubyx/lib/asm/label.rb

34 lines
872 B
Ruby
Raw Normal View History

require_relative "code"
2014-04-23 12:52:34 +02:00
module Asm
# Labels are, like in assembler, a point to jump/branch to. An address in the stream.
# To allow for forward branches creation does not fix the position. Set does that.
class Label < Code
2014-04-23 12:52:34 +02:00
def initialize(name , asm)
super
2014-04-23 12:52:34 +02:00
@name = name
@asm = asm
end
# setting a label fixes it's position in the stream.
# For backwards jumps, positions of labels are known at creation, but for forward off course not.
# So then one can create a label, branch to it and set it later.
def set!
@asm.add_value self
self
2014-04-23 12:52:34 +02:00
end
# Label has no length , 0
2014-04-23 12:52:34 +02:00
def length
0
end
# nothing to write, we check that the position is what was set
def assemble(io)
raise "Hmm hmm hmm, me thinks i should be somewhere else" if self.position != io.tell
2014-04-23 12:52:34 +02:00
end
end
end