aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-12-04 17:40:03 +0100
committerDimitri Sokolyuk <demon@dim13.org>2017-12-04 17:40:03 +0100
commit34141270f4a6fd17c4020ed713f86f41f56e3916 (patch)
tree1599b86e2f839166be50bc0225380800e2ffdc59
parentc77363a4cfc1df05671abb7a080504704e97936d (diff)
bool2int
-rw-r--r--eval.go22
1 files changed, 10 insertions, 12 deletions
diff --git a/eval.go b/eval.go
index 3f1cb8b..e6c515b 100644
--- a/eval.go
+++ b/eval.go
@@ -105,6 +105,13 @@ func (j1 *J1) eval(ins Instruction) {
}
}
+func bool2int(b bool) uint16 {
+ if b {
+ return 1
+ }
+ return 0
+}
+
func (j1 *J1) newST0(opcode uint16) uint16 {
T, N, R := j1.st0, j1.dstack[j1.dsp], j1.rstack[j1.rsp]
switch opcode {
@@ -123,15 +130,9 @@ func (j1 *J1) newST0(opcode uint16) uint16 {
case opNotT: // ~T
return ^T
case opNeqT: // N==T
- if N == T {
- return 1
- }
- return 0
+ return bool2int(N == T)
case opNleT: // N<T
- if int16(N) < int16(T) {
- return 1
- }
- return 0
+ return bool2int(int16(N) < int16(T))
case opNrshiftT: // N>>T
return N >> (T & 0xf)
case opTminus1: // T-1
@@ -145,10 +146,7 @@ func (j1 *J1) newST0(opcode uint16) uint16 {
case opDepth: // depth (dsp)
return (uint16(j1.rsp) << 8) | uint16(j1.dsp)
case opNuleT: // Nu<T
- if N < T {
- return 1
- }
- return 0
+ return bool2int(N < T)
default:
panic("invalid instruction")
}