X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=sys.f;h=38708d1e1a88f479264951bf154c85509583826d;hb=e3bee6e77d04f68fe14e4a0106f02d9284d7dcac;hp=d222320fcfe931fcf5e54db18749ae045ba4fbc0;hpb=35d467b9ab869cc9a4f1068b112d5f22ca483afd;p=rrq%2Fjonasforth.git diff --git a/sys.f b/sys.f index d222320..38708d1 100644 --- a/sys.f +++ b/sys.f @@ -47,7 +47,7 @@ EXIT [ ELSE DROP THEN - AGAIN ; + AGAIN ; ( Yay! We now have comments! ) : UNTIL IMMEDIATE ' 0BRANCH , @@ -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 + @@ -81,6 +69,12 @@ EXIT [ : OVER ( a b -- a b a ) SWAP DUP ROT ; +( An alternative comment syntax. Reads until the end of the line. ) +: \ IMMEDIATE + BEGIN + KEY + 10 = UNTIL ; + ( Compile the given string into the current word directly. ) : STORE-STRING ( str len -- ) BEGIN @@ -89,16 +83,13 @@ EXIT [ 1 - DUP 0 = UNTIL DROP DROP ; -S" HELLO-ADDR" CREATE -S" Hello!" DUP ROT -STORE-STRING -: HELLO - ' HELLO-ADDR LIT, TELL NEWLINE ; +: NEWLINE 10 EMIT ; +: SPACE 32 EMIT ; -HELLO +( Read a number from standard input. ) +: READ-NUMBER READ-WORD PARSE-NUMBER ; -S" 10 FIB = " TELL -10 FIB .U -S" (Expected: 59)" TELL NEWLINE +S" Ready." TELL NEWLINE -TERMINATE +( vim: syntax=forth +)