Add alternative Linux backend
[rrq/jonasforth.git] / sys.f
diff --git a/sys.f b/sys.f
index 27d540a87cee34e5f172194a21b88812ec72338e..6e7c8539bcdd67ea720b7faf5c2f15c8781b0880 100644 (file)
--- a/sys.f
+++ b/sys.f
@@ -1,4 +1,4 @@
-BUF" :" CREATE ] DOCOL
+S" :" CREATE ] DOCOL
   READ-WORD CREATE
   LIT DOCOL ,
   ]
@@ -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,5 +104,6 @@ EXIT [
 ( Read a number from standard input. )
 : READ-NUMBER READ-WORD PARSE-NUMBER ;
 
-( vim: syntax=forth
-)
+: RESTART S" Ready." TELL NEWLINE ;
+RESTART
+