aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2017-04-17 14:28:38 +0200
committerAdrian Kummerlaender2017-04-17 14:28:38 +0200
commitdda2af16ce4ea439ee90390526dbd7f2b8971128 (patch)
tree81b0373dd3dcc5d66804569ad9358aad3f189063
parent399faa1f97390215628d245f006610a9586ff1e9 (diff)
downloadslang-dda2af16ce4ea439ee90390526dbd7f2b8971128.tar
slang-dda2af16ce4ea439ee90390526dbd7f2b8971128.tar.gz
slang-dda2af16ce4ea439ee90390526dbd7f2b8971128.tar.bz2
slang-dda2af16ce4ea439ee90390526dbd7f2b8971128.tar.lz
slang-dda2af16ce4ea439ee90390526dbd7f2b8971128.tar.xz
slang-dda2af16ce4ea439ee90390526dbd7f2b8971128.tar.zst
slang-dda2af16ce4ea439ee90390526dbd7f2b8971128.zip
Add some more Forth stack operators
-rw-r--r--source/primitives/core.d28
1 files changed, 24 insertions, 4 deletions
diff --git a/source/primitives/core.d b/source/primitives/core.d
index ab0b85c..ce3eee2 100644
--- a/source/primitives/core.d
+++ b/source/primitives/core.d
@@ -25,6 +25,8 @@ bool handle(string word) {
case "pop" : unary_op_stack_pop; break;
case "dup" : unary_op_stack_dup; break;
case "swp" : binary_op_stack_swp; break;
+ case "over" : binary_op_stack_over; break;
+ case "rot" : ternary_op_stack_rot; break;
case "true" : nullary_op_value_bool(true); break;
case "false" : nullary_op_value_bool(false); break;
case "<" : binary_cond_lt; break;
@@ -89,7 +91,29 @@ void binary_op_stack_swp() {
stack.push(b);
stack.push(a);
+}
+
+void binary_op_stack_over() {
+ auto b = stack.pop;
+ auto a = stack.pop;
+
+ stack.push(a);
+ stack.push(b);
+ stack.push(a);
+}
+
+void ternary_op_stack_rot() {
+ auto c = stack.pop;
+ auto b = stack.pop;
+ auto a = stack.pop;
+ stack.push(b);
+ stack.push(c);
+ stack.push(a);
+}
+
+void nullary_op_value_bool(bool value) {
+ stack.push(Token(value));
}
void binary_cond_lt() {
@@ -106,8 +130,4 @@ void binary_cond_eq() {
stack.push(a == b);
}
-void nullary_op_value_bool(bool value) {
- stack.push(Token(value));
-}
-
}