Class: Whitespace::ISA::Readc

Inherits:
Instruction show all
Defined in:
lib/whitespace/instructions/io/readc.rb

Instance Attribute Summary collapse

Attributes inherited from Instruction

#vm

Instance Method Summary collapse

Constructor Details

#initialize(vm, console) ⇒ Readc

Returns a new instance of Readc.



5
6
7
8
# File 'lib/whitespace/instructions/io/readc.rb', line 5

def initialize(vm, console)
  super(vm)
  @console = console
end

Instance Attribute Details

#consoleObject (readonly)

Returns the value of attribute console.



3
4
5
# File 'lib/whitespace/instructions/io/readc.rb', line 3

def console
  @console
end

Instance Method Details

#executeObject



10
11
12
13
14
# File 'lib/whitespace/instructions/io/readc.rb', line 10

def execute
  ch = console.getc
  address = vm.vstack.pop
  vm.memory[address] = ch.ord
end