Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81319 / bfinterpreter / bf / mem.go
diff options
context:
space:
mode:
1 files changed, 40 insertions, 0 deletions
-rw-r--r--homework/81319/bfinterpreter/bf/mem.go40
diff --git a/homework/81319/bfinterpreter/bf/mem.go b/homework/81319/bfinterpreter/bf/mem.go
new file mode 100644
index 0000000..8679584
--- /dev/null
+++ b/homework/81319/bfinterpreter/bf/mem.go
@@ -0,0 +1,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()
+}