diff options
author | Adrian Kummerlaender | 2017-04-12 18:06:10 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2017-04-12 18:06:10 +0200 |
commit | d0c6994a0c3706a3eb09d32c8bf33513b1dbd3be (patch) | |
tree | 796e0f6afb0cbad508bdea426e4f59d822aef56f | |
parent | 4804893a6616a312ac8028e42d2aa990018ffbe6 (diff) | |
download | slang-d0c6994a0c3706a3eb09d32c8bf33513b1dbd3be.tar slang-d0c6994a0c3706a3eb09d32c8bf33513b1dbd3be.tar.gz slang-d0c6994a0c3706a3eb09d32c8bf33513b1dbd3be.tar.bz2 slang-d0c6994a0c3706a3eb09d32c8bf33513b1dbd3be.tar.lz slang-d0c6994a0c3706a3eb09d32c8bf33513b1dbd3be.tar.xz slang-d0c6994a0c3706a3eb09d32c8bf33513b1dbd3be.tar.zst slang-d0c6994a0c3706a3eb09d32c8bf33513b1dbd3be.zip |
Implement integer comparsion primitives
-rw-r--r-- | src/primitives/eval.d | 4 | ||||
-rw-r--r-- | src/primitives/impl.d | 16 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/primitives/eval.d b/src/primitives/eval.d index 3f91e80..3f52e6d 100644 --- a/src/primitives/eval.d +++ b/src/primitives/eval.d @@ -42,6 +42,10 @@ bool evaluate(string word) { return unary_op_stack_dup; case "swp": return binary_op_stack_swp; + case "<": + return binary_cond_lt; + case "=": + return binary_cond_eq; default: return false; } diff --git a/src/primitives/impl.d b/src/primitives/impl.d index 4ec9019..56ea4ce 100644 --- a/src/primitives/impl.d +++ b/src/primitives/impl.d @@ -117,3 +117,19 @@ bool binary_op_stack_swp() { return true; } + +bool binary_cond_lt() { + int b = stack.pop.get!int; + int a = stack.pop.get!int; + + stack.push(a < b); + return true; +} + +bool binary_cond_eq() { + int b = stack.pop.get!int; + int a = stack.pop.get!int; + + stack.push(a == b); + return true; +} |