aboutsummaryrefslogtreecommitdiff
path: root/eval.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-06-05 21:05:47 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-06-05 21:05:47 +0200
commitc25de36d647a6bc31a8c8b78a983f86eb25dad94 (patch)
treeba9692a46abe6bd5275228acf36cd53e2fc0be1d /eval.go
parentdbb11cdcde7d90cab20cc552218e1811781a92ae (diff)
Still broken
Diffstat (limited to 'eval.go')
-rw-r--r--eval.go43
1 files changed, 33 insertions, 10 deletions
diff --git a/eval.go b/eval.go
index 43ec195..d68268e 100644
--- a/eval.go
+++ b/eval.go
@@ -60,17 +60,17 @@ func (vm *J1) eval(ins Instruction) {
next := vm.pc + 1
switch v := ins.(type) {
case Lit:
- vm.st0 = uint16(v)
vm.dstack[vm.dsp] = vm.st0
vm.dsp++
+ vm.st0 = uint16(v)
case Jump:
next = uint16(v)
case Cond:
if vm.st0 == 0 {
next = uint16(v)
}
- vm.st0 = vm.dstack[vm.dsp]
vm.dsp--
+ vm.st0 = vm.dstack[vm.dsp]
case Call:
vm.rstack[vm.rsp] = next
vm.rsp++
@@ -83,22 +83,45 @@ func (vm *J1) eval(ins Instruction) {
vm.memory[vm.st0] = vm.dstack[vm.dsp]
}
- vm.st0 = vm.newST0(v)
+ newSt0 := vm.newST0(v)
- vm.dsp = uint16(int8(vm.dsp) + v.Ddir)
- vm.rsp = uint16(int8(vm.rsp) + v.Rdir)
- if v.TtoR {
- vm.rstack[vm.rsp] = vm.st0
- }
if v.TtoN {
- vm.dstack[vm.dsp] = vm.st0
+ switch v.Ddir {
+ case 1:
+ vm.dstack[vm.dsp] = vm.st0
+ vm.dsp++
+ case -1:
+ vm.dsp--
+ vm.dstack[vm.dsp] = vm.st0
+ default:
+ vm.dstack[vm.dsp] = vm.st0
+ }
}
+
+ if v.TtoR {
+ switch v.Rdir {
+ case 1:
+ vm.rstack[vm.rsp] = vm.st0
+ vm.rsp++
+ case -1:
+ vm.rsp--
+ vm.rstack[vm.rsp] = vm.st0
+ default:
+ vm.rstack[vm.rsp] = vm.st0
+ }
+ }
+
+ vm.st0 = newSt0
+ //vm.dsp = uint16(int8(vm.dsp) + v.Ddir)
+ //vm.rsp = uint16(int8(vm.rsp) + v.Rdir)
+ //if v.TtoR { vm.rstack[vm.rsp] = vm.st0 }
+ //if v.TtoN { vm.dstack[vm.dsp] = vm.st0 }
}
vm.pc = next
}
func (vm *J1) newST0(v ALU) uint16 {
- T, N, R := vm.st0, vm.dstack[vm.dsp], vm.rstack[vm.rsp]
+ T, N, R := vm.st0, vm.dstack[(vm.dsp-1)%32], vm.rstack[(vm.rsp-1)%32]
switch v.Opcode {
case 0: // T
return T