Class: Whitespace::VM

Inherits:
Object
  • Object
show all
Defined in:
lib/whitespace/vm.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVM

Returns a new instance of VM.



10
11
12
13
# File 'lib/whitespace/vm.rb', line 10

def initialize
  @instructions = []
  reset
end

Instance Attribute Details

#cstackObject (readonly)

Returns the value of attribute cstack.



8
9
10
# File 'lib/whitespace/vm.rb', line 8

def cstack
  @cstack
end

#instructionsObject (readonly)

Returns the value of attribute instructions.



8
9
10
# File 'lib/whitespace/vm.rb', line 8

def instructions
  @instructions
end

#memoryObject (readonly)

Returns the value of attribute memory.



8
9
10
# File 'lib/whitespace/vm.rb', line 8

def memory
  @memory
end

#pcObject (readonly)

Returns the value of attribute pc.



8
9
10
# File 'lib/whitespace/vm.rb', line 8

def pc
  @pc
end

#vstackObject (readonly)

Returns the value of attribute vstack.



8
9
10
# File 'lib/whitespace/vm.rb', line 8

def vstack
  @vstack
end

Instance Method Details

#load(instructions) ⇒ Object



15
16
17
# File 'lib/whitespace/vm.rb', line 15

def load(instructions)
  @instructions = Array(instructions)
end

#runObject



19
20
21
22
23
24
25
26
27
# File 'lib/whitespace/vm.rb', line 19

def run
  reset

  loop do
    instruction = instructions.fetch pc
    pc.increment
    execute instruction
  end
end