rubyx/lib/vm/block.rb
Torsten Ruger 04e4dc872e check
2014-05-03 18:51:47 +03:00

44 lines
1.1 KiB
Ruby

require_relative "values"
module Vm
# Think flowcharts: blocks are the boxes. The smallest unit of linear code
# Blocks must end in control instructions (jump/call/return).
# And the only valid argument for a jump is a Block
# Blocks for a double linked list so one can traverse back and forth
# There are four ways for a block to get data (to work on)
# - hard coded constants (embedded in code)
# - memory move
# - values passed in (from previous blocks. ie local variables)
# See Value description on how to create code/instructions
class Block < Value
def initialize(name)
super()
@name = name.to_sym
@next = nil
@previous = nil
@codes = []
end
attr_reader :name , :previous , :next
def verify
end
# set the next executed block after self.
# why is this useful? if it's unconditional, why not merge them:
# So the second block can be used as a jump target. You standard loop needs a block to setup
# and at least one to do the calculation
def next block
block.previous = self
self.next = block
end
end
end