2014-04-25 11:28:23 +02:00
|
|
|
require_relative "code"
|
2014-04-23 12:52:34 +02:00
|
|
|
|
2014-04-25 11:28:23 +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)
|
2014-04-25 11:28:23 +02:00
|
|
|
super
|
2014-04-23 12:52:34 +02:00
|
|
|
@name = name
|
|
|
|
@asm = asm
|
|
|
|
end
|
|
|
|
|
2014-04-25 11:28:23 +02:00
|
|
|
# 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
|
2014-04-25 11:28:23 +02:00
|
|
|
|
|
|
|
# Label has no length , 0
|
2014-04-23 12:52:34 +02:00
|
|
|
def length
|
|
|
|
0
|
|
|
|
end
|
|
|
|
|
2014-04-25 11:28:23 +02:00
|
|
|
# nothing to write, we check that the position is what was set
|
2014-04-25 10:56:53 +02:00
|
|
|
def assemble(io)
|
2014-04-25 11:28:23 +02:00
|
|
|
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
|