Class: Rbfunge::Memory_Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/rbfunge/memory_stack.rb

Overview

memory stack for Befunge programs

Instance Method Summary collapse

Constructor Details

#initializeMemory_Stack

initialize the memory



6
7
8
# File 'lib/rbfunge/memory_stack.rb', line 6

def initialize
	@stack = []
end

Instance Method Details

#dupObject

duplicate the top item



29
30
31
32
33
# File 'lib/rbfunge/memory_stack.rb', line 29

def dup
	top = pop
	push top
	push top
end

#popObject

pop the first top element off the stack



11
12
13
# File 'lib/rbfunge/memory_stack.rb', line 11

def pop
	return @stack.empty? ? 0 : @stack.pop
end

#push(value) ⇒ Object

push an element onto the stack



16
17
18
# File 'lib/rbfunge/memory_stack.rb', line 16

def push(value)
	@stack.push value
end

#swapObject

swap the top two items in the stack



21
22
23
24
25
26
# File 'lib/rbfunge/memory_stack.rb', line 21

def swap
	first = pop
	second = pop
	push first
	push second
end