aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-01-09 01:32:41 +0100
committerDimitri Sokolyuk <demon@dim13.org>2018-01-09 01:32:41 +0100
commit6c341b31fc36157be445ad106257a3bba4abc87d (patch)
tree76a639608a538cf0664ed0b2b614c7409d460eec
parentf8a2141c0776a28c6a7107849102154f9a959f48 (diff)
rename
-rw-r--r--eval.go12
-rw-r--r--stack.go7
2 files changed, 10 insertions, 9 deletions
diff --git a/eval.go b/eval.go
index 06b350f..8c6e80a 100644
--- a/eval.go
+++ b/eval.go
@@ -15,11 +15,11 @@ const (
// J1 Forth processor VM
type J1 struct {
- pc uint16 // 13 bit
- st0 uint16 // top of data stack
+ memory [memSize]uint16 // 0..0x3fff main memory, 0x4000 .. 0x7fff mem-mapped i/o
+ pc uint16 // 13 bit
+ st0 uint16 // top of data stack
d stack
r stack
- memory [memSize]uint16 // 0..0x3fff main memory, 0x4000 .. 0x7fff mem-mapped i/o
console io.ReadWriter
}
@@ -124,10 +124,10 @@ func (j1 *J1) eval(ins Instruction) {
}
case ALU:
if v.RtoPC {
- j1.pc = j1.r.peek() >> 1
+ j1.pc = j1.r.get() >> 1
}
if v.NtoAtT {
- j1.write(j1.st0, j1.d.peek())
+ j1.write(j1.st0, j1.d.get())
}
st0 := j1.newST0(v.Opcode)
j1.d.move(v.Ddir)
@@ -150,7 +150,7 @@ func bool2int(b bool) uint16 {
}
func (j1 *J1) newST0(opcode uint16) uint16 {
- T, N, R := j1.st0, j1.d.peek(), j1.r.peek()
+ T, N, R := j1.st0, j1.d.get(), j1.r.get()
switch opcode {
case opT: // T
return T
diff --git a/stack.go b/stack.go
index c192878..dc49570 100644
--- a/stack.go
+++ b/stack.go
@@ -15,11 +15,12 @@ func (s *stack) push(v uint16) {
}
func (s *stack) pop() uint16 {
- defer s.move(-1)
- return s.peek()
+ v := s.get()
+ s.move(-1)
+ return v
}
-func (s *stack) peek() uint16 {
+func (s *stack) get() uint16 {
return s.data[s.sp]
}