Class: Whitespace::VM
- Inherits:
-
Object
- Object
- Whitespace::VM
- Defined in:
- lib/whitespace/vm.rb
Instance Attribute Summary collapse
-
#cstack ⇒ Object
readonly
Returns the value of attribute cstack.
-
#instructions ⇒ Object
readonly
Returns the value of attribute instructions.
-
#memory ⇒ Object
readonly
Returns the value of attribute memory.
-
#pc ⇒ Object
readonly
Returns the value of attribute pc.
-
#vstack ⇒ Object
readonly
Returns the value of attribute vstack.
Instance Method Summary collapse
-
#initialize ⇒ VM
constructor
A new instance of VM.
- #load(instructions) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ VM
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
#cstack ⇒ Object (readonly)
Returns the value of attribute cstack.
8 9 10 |
# File 'lib/whitespace/vm.rb', line 8 def cstack @cstack end |
#instructions ⇒ Object (readonly)
Returns the value of attribute instructions.
8 9 10 |
# File 'lib/whitespace/vm.rb', line 8 def instructions @instructions end |
#memory ⇒ Object (readonly)
Returns the value of attribute memory.
8 9 10 |
# File 'lib/whitespace/vm.rb', line 8 def memory @memory end |
#pc ⇒ Object (readonly)
Returns the value of attribute pc.
8 9 10 |
# File 'lib/whitespace/vm.rb', line 8 def pc @pc end |
#vstack ⇒ Object (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 |
#run ⇒ Object
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 |