aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordan <[email protected]>2023-05-20 11:34:47 -0400
committerdan <[email protected]>2023-05-20 11:34:47 -0400
commit7f247c27073a273c4e0befacf6a94716c360383f (patch)
treefa3ba9ccda3631179a0b705ef031e28e604660c8
parent6c9db0f034a1deacab9532291fead04740db749b (diff)
downloadforth-7f247c27073a273c4e0befacf6a94716c360383f.tar.gz
forth-7f247c27073a273c4e0befacf6a94716c360383f.tar.bz2
forth-7f247c27073a273c4e0befacf6a94716c360383f.zip
feat: swap command
-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()) {