diff options
Diffstat (limited to 'stack.go')
-rw-r--r-- | stack.go | 12 |
1 files changed, 5 insertions, 7 deletions
@@ -1,24 +1,22 @@ package j1 -const stackSize = 0x20 - type stack struct { - data [stackSize]uint16 // stack - sp int8 // 5 bit stack pointer + data [0x20]uint16 // stack + sp int8 // 5 bit stack pointer } func (s *stack) move(dir int8) { - s.sp = (s.sp + dir) & (stackSize - 1) + s.sp = (s.sp + dir) & int8(len(s.data)-1) } func (s *stack) push(v uint16) { - s.sp = (s.sp + 1) & (stackSize - 1) + s.sp = (s.sp + 1) & int8(len(s.data)-1) s.data[s.sp] = v } func (s *stack) pop() uint16 { sp := s.sp - s.sp = (s.sp - 1) & (stackSize - 1) + s.sp = (s.sp - 1) & int8(len(s.data)-1) return s.data[sp] } |