From a6faff31f03d96b6a62188f330848004119d5165 Mon Sep 17 00:00:00 2001 From: Jonas Hvid Date: Fri, 6 Mar 2020 14:12:18 +0100 Subject: [PATCH] Separate example code from sys.f and add build instructions --- notes.md => README.md | 20 ++++++++++++++------ example.f | 25 +++++++++++++++++++++++++ sys.f | 26 -------------------------- 3 files changed, 39 insertions(+), 32 deletions(-) rename notes.md => README.md (94%) create mode 100644 example.f diff --git a/notes.md b/README.md similarity index 94% rename from notes.md rename to README.md index e828a80..2ed38d5 100644 --- a/notes.md +++ b/README.md @@ -1,10 +1,18 @@ -FASM: -- https://flatassembler.net/docs.php?article=fasmg (Introduction) -- https://flatassembler.net/docs.php?article=fasmg_manual (Manual) -- https://flatassembler.net/docs.php?article=manual (Other manual) +# Building and running -JONESFORTH: -- https://github.com/nornagon/jonesforth/blob/master/jonesforth.S +Create the executable: + + $ make main + +The `sys.f` file contains code that defines some of the usual words that you +would expect in a Forth distribution. To run this code and then read from +standard input, run: + + $ cat sys.f - | ./main + +The `example.f` file contains an example that you can run with: + + $ cat sys.f example.f | ./main # Notes on implementation diff --git a/example.f b/example.f new file mode 100644 index 0000000..2443f32 --- /dev/null +++ b/example.f @@ -0,0 +1,25 @@ +: FIB ( n -- Fn ) + 0 1 ( n a b ) + 0 ( n a b i ) + BEGIN + ROT ( n i a b ) + DUP ROT + ( n i b a+b ) + ROT ROT ( n b a+b i ) + + 1 + ( n b a+b i+1 ) + DUP 4 PICK = UNTIL + DROP SWAP DROP SWAP DROP ; ( a+b ) + +S" HELLO-ADDR" CREATE +S" Hello!" DUP ROT +STORE-STRING +: HELLO + ' HELLO-ADDR LIT, TELL NEWLINE ; + +HELLO + +S" 10 FIB = " TELL +10 FIB .U +S" (Expected: 59)" TELL NEWLINE + +TERMINATE diff --git a/sys.f b/sys.f index d222320..92efcb4 100644 --- a/sys.f +++ b/sys.f @@ -62,18 +62,6 @@ EXIT [ : MOD /MOD SWAP DROP ; : NEG 0 SWAP - ; -: FIB ( n -- Fn ) - 0 1 ( n a b ) - 0 ( n a b i ) - BEGIN - ROT ( n i a b ) - DUP ROT + ( n i b a+b ) - ROT ROT ( n b a+b i ) - - 1 + ( n b a+b i+1 ) - DUP 4 PICK = UNTIL - DROP SWAP DROP SWAP DROP ; ( a+b ) - : C, HERE @ C! HERE @ 1 + @@ -88,17 +76,3 @@ EXIT [ SWAP 1 + SWAP 1 - DUP 0 = UNTIL DROP DROP ; - -S" HELLO-ADDR" CREATE -S" Hello!" DUP ROT -STORE-STRING -: HELLO - ' HELLO-ADDR LIT, TELL NEWLINE ; - -HELLO - -S" 10 FIB = " TELL -10 FIB .U -S" (Expected: 59)" TELL NEWLINE - -TERMINATE -- 2.39.2