Sha256: 4c3e6d7190026658460c0be2d86194155c33eaff267940857ba95215920f2b78
Contents?: true
Size: 882 Bytes
Versions: 1
Compression:
Stored size: 882 Bytes
Contents
require_relative "data_structures/console" require_relative "data_structures/counter" require_relative "data_structures/memory" require_relative "data_structures/stack" module Whitespace class VM attr_reader :instructions, :vstack, :cstack, :memory, :pc def initialize @instructions = [] reset end def load(instructions) @instructions = Array(instructions) end def run reset loop do instruction = instructions.fetch pc pc.increment execute instruction end end private def reset @vstack = Stack.new # a value stack @cstack = Stack.new # a call stack @memory = Memory.new # heap memory @pc = Counter.new # program counter end def execute(instruction) instruction.execute rescue Halt raise StopIteration end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
whitespace-ruby-1.0.0 | lib/whitespace/vm.rb |