# Ondrej Jaura # March 2009 # www.valibuk.net class Tape def initialize @pos = 0 @tape = [] end def method_missing(sym, *args, &block) puts "# unknow #{sym} with args #{args} #{block_given? ? '' : 'and code'}" end def right @tape.push nil if @tape.size == @pos @pos += 1 end def left if @pos == 0 @tape.unshift nil else @pos -= 1 end end def write(val) @tape[@pos] = val end def read @tape[@pos] end def check(val, &block) return unless block_given? while read != val do if block.arity == 1 yield read else yield end end end def condition(val, positive, negative) if read == val positive.call else negative.call end end def dump t = @tape.map {|c| " #{c} "} t[@pos] = "|#{@tape[@pos]}|" puts "[#{t.join(',')}]" end def comment(text) puts text end def self.load(filename) new.instance_eval(File.read(filename), filename) end end Tape.load(ARGV.shift)