Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81319 / bfinterpreter / bf / mem.go
blob: 8679584bc595d112aada2d09f9b4d882ed64e21c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package bf

const (
	MEMORY_SIZE uint = 1024
)

type memoryState struct {
	memory         [MEMORY_SIZE]cell
	currentCellIdx uint
}

func (m *memoryState) incrementPtr() {
	if m.currentCellIdx == MEMORY_SIZE {
		return
	}
	m.currentCellIdx += 1
}

func (m *memoryState) decrementPtr() {
	if m.currentCellIdx == 0 {
		return
	}
	m.currentCellIdx -= 1
}

func (m *memoryState) incrementCell() {
	m.memory[m.currentCellIdx].increment()
}

func (m *memoryState) decerementCell() {
	m.memory[m.currentCellIdx].decrement()
}

func (m *memoryState) setCell(value byte) {
	m.memory[m.currentCellIdx].setValue(value)
}

func (m *memoryState) getCell() byte {
	return m.memory[m.currentCellIdx].getValue()
}