diff options
author | dan <[email protected]> | 2023-05-20 11:34:47 -0400 |
---|---|---|
committer | dan <[email protected]> | 2023-05-20 11:34:47 -0400 |
commit | 7f247c27073a273c4e0befacf6a94716c360383f (patch) | |
tree | fa3ba9ccda3631179a0b705ef031e28e604660c8 /forth.js | |
parent | 6c9db0f034a1deacab9532291fead04740db749b (diff) | |
download | forth-7f247c27073a273c4e0befacf6a94716c360383f.tar.gz forth-7f247c27073a273c4e0befacf6a94716c360383f.tar.bz2 forth-7f247c27073a273c4e0befacf6a94716c360383f.zip |
feat: swap command
Diffstat (limited to 'forth.js')
-rw-r--r-- | forth.js | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -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()) { |