X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=sys.f;h=6e7c8539bcdd67ea720b7faf5c2f15c8781b0880;hb=61b721d365efaaae4d5ebb8d13972faa697be54b;hp=0815e0fe0ca89d729a068e5072a4e8b721635460;hpb=7677dbbdce584a64e63946b39879f5edd114f36a;p=rrq%2Fjonasforth.git diff --git a/sys.f b/sys.f index 0815e0f..6e7c853 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 , @@ -69,6 +69,27 @@ 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 ; + +\ So far, S" has only worked in immediate mode, which is backwards -- actually, +\ the main use-case of this is as a compile-time word. Let's fix that. +: S" IMMEDIATE + ' LITSTRING , + HERE @ 0 C, \ We will put the length here + 0 + BEGIN + 1 + + KEY DUP C, + 34 = UNTIL + \ Remove final " + HERE @ 1 - HERE ! + 1 - + SWAP C! ; + ( Compile the given string into the current word directly. ) : STORE-STRING ( str len -- ) BEGIN @@ -83,7 +104,6 @@ EXIT [ ( Read a number from standard input. ) : READ-NUMBER READ-WORD PARSE-NUMBER ; -S" Ready." TELL NEWLINE +: RESTART S" Ready." TELL NEWLINE ; +RESTART -( vim: syntax=forth -)