From dda2af16ce4ea439ee90390526dbd7f2b8971128 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 17 Apr 2017 14:28:38 +0200 Subject: Add some more Forth stack operators --- source/primitives/core.d | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'source/primitives') 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)); -} - } -- cgit v1.2.3