diff options
author | dan <[email protected]> | 2023-05-31 22:06:58 -0400 |
---|---|---|
committer | dan <[email protected]> | 2023-05-31 22:06:58 -0400 |
commit | 25ecb947f3b832c31ea049ba06187580833c90c2 (patch) | |
tree | 6bc161909310aa811639ce58f1cb77b04fc17f0f | |
parent | 4c71c5ac64b9e8b350741dcbe1d2d8b87880dc8a (diff) | |
download | forth-25ecb947f3b832c31ea049ba06187580833c90c2.tar.gz forth-25ecb947f3b832c31ea049ba06187580833c90c2.tar.bz2 forth-25ecb947f3b832c31ea049ba06187580833c90c2.zip |
docs: update readme and rlwrap completions with new commands
-rw-r--r-- | readme.md | 48 | ||||
-rw-r--r-- | rlwrapcompletions.forth | 23 |
2 files changed, 57 insertions, 14 deletions
@@ -1,16 +1,50 @@ -Forth-style Stack Language with C and JS implementations. +Forth-style Stack Language in C. Runs natively or, in browser via wasm. -JS implementation can be run by opening index.html in a web browser or running `node forth.js`. +Live demo at [https://danielrholland.codeberg.page/forth-style-stack-lang/](https://danielrholland.codeberg.page/forth-style-stack-lang/) -Assuming you have clang and make installed, the C implementation can be built with `make build`, then run with `./forth`. +Assuming you have clang and make installed, the native executable can be built with `make build`, then run with `./forth`. If you also have rlwrap installed, you can run `make run-rlwrap`, to get completions, history, and more pleasant line-editing. -_Be aware:_ +`make build-wasm` will build the wasm version. Serve `./forthlib.wasm`, `forthlib.js`, `forth.js` and `index.html` from a web server and open `index.html` to use it. - - Neither implementation is finished - - The implementations have some subtle differences - - This is a toy, not intended for serious use +---- + +Current builtin operations: + + - `.` - pop and print val + - `peek` - peek and print val + - `+` - pop top two vals and push second+top + - `-` - pop top two vals and push second-top + - `*` - pop top two vals and push second*top + - `/` - pop top two vals and push second/top + - `negate` - replace top val with 0 - value + - `abs` - replace top val with its absolute + - `mod` - second modulo top + - `max` - largest of top two vals + - `min` - largest of top two vals + - `dup` - duplicate top val + - `not` - if top val is 0 set to 1, else set to 0 + - `=` - pop top two vals + - `swap` - swap order of top two vals + - `drop` - discard top val + - `over` - copy second val and push it + - `rot` - rotate top three vals - top to third, second to top, third to second + - `pick` - pop a val n, then copy the nth value down from the top and push it + - `roll` - pop a val n, then copy the nth value down from the top and push it + - `depth` - push that stack size + - `clearstack` - clear the stack + - `if <body> then ` - an optional section. `if` pops a val, and if that val is 0, skips to then. (Branch if zero) + - `: <name> <body> ;` - a procedure declaration. A new op is added, when it is run, the tokens in the body are evaluated. e.g. `: decr 1 - ; ` will define a new operation `incr`, that increments the valu at the top of the stack. + - `nip` - discards the second val from the top + - `tuck` - copies the top val and inserts it between the second and third + - `incr` - increments the top value + +Literals are pushed. + +At present only integers are supported. + +At present, loops haven't been added, just use recursion. ---- diff --git a/rlwrapcompletions.forth b/rlwrapcompletions.forth index 80e9a36..75384f1 100644 --- a/rlwrapcompletions.forth +++ b/rlwrapcompletions.forth @@ -1,19 +1,28 @@ -pop -push +. peek -if -then -: -; + - * / +negate +abs +mod +max +min dup -dump not = swap drop over rot +pick +roll +depth +.s +clearstack +if then +: ; +nip +tuck +incr |