aboutsummaryrefslogtreecommitdiffstats
path: root/forth.js
diff options
context:
space:
mode:
Diffstat (limited to 'forth.js')
-rw-r--r--forth.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/forth.js b/forth.js
index a169ca6..e589387 100644
--- a/forth.js
+++ b/forth.js
@@ -16,6 +16,12 @@ function forth(print = console.log) {
'+' : () => { s.push(popNum() + popNum()) },
'*' : () => { s.push(popNum() * popNum()) },
'=' : () => { s.push(popNum() === popNum()) },
+ 'swap' : () => {
+ const a1 = s.pop();
+ const a2 = s.pop();
+ s.push(a1);
+ s.push(a2);
+ },
'then' : () => {/*Doing nothing skips the token*/},
'if' : (initialIdx, tokens) => {
if (!s.pop()) {