Added C,
[forth.jl.git] / src / lib.4th
index 6b2d8ae..a43f6c1 100644 (file)
@@ -8,7 +8,15 @@
 : FALSE 0 ;
 : NOT 0= ;
 
-: CELLS ; \ Allow for slightly more portable code
+ \ Allow for slightly more portable code
+: CELLS ;
+
+\ Since the smallest unit of memory in our system is 64 bits and since strings
+\ are stored as arrays of 64 bit integers, the character store/fetch words are
+\ just aliases of the standard store/fetch words.
+: C! ! ;
+: C@ @ ;
+: C, , ;
 
 : DEPTH PSP@ PSP0 @ - ;
 
 
 ( STRINGS ---------------------------------------------------------------------- )
 
-( Since the smallest unit of memory in our system is 64 bits and since strings
-  are stored as arrays of 64 bit integers, the character store/fetch words are
-  just aliases of the standard store/fetch words. )
-: C! ! ;
-: C@ @ ;
 
 ( Block copy, however, is important and novel: )
 : CMOVE ( src dest length -- )
 ;
 
 : ." IMMEDIATE          ( -- )
-        STATE @ IF      ( compiling? )
-                [COMPILE] S"    ( read the string, and compile LITSTRING, etc. )
-                ['] TELL ,        ( compile the final TELL )
-        ELSE
-                ( In immediate mode, just read characters and print them until we get
-                  to the ending double quote. )
-                KEY DROP
-                BEGIN
-                        KEY
-                        DUP '"' = IF
-                                DROP    ( drop the double quote character )
-                                EXIT    ( return from this function )
-                        THEN
-                        EMIT
-                AGAIN
-        THEN
+        [COMPILE] S"    ( read the string, and compile LITSTRING, etc. )
+        ['] TELL ,      ( compile the final TELL )
+;
+
+: .( 
+        KEY DROP
+        BEGIN
+                KEY
+                DUP ')' = IF
+                        DROP    ( drop the double quote character )
+                        EXIT    ( return from this function )
+                THEN
+                EMIT
+        AGAIN
 ;
 
 
         ['] EXIT ,      ( append the codeword EXIT )
 ;
 
-: ALLOT         ( n -- addr )
-        HERE @ SWAP     ( here n )
+: ALLOT         ( n -- )
         HERE +!         ( adds n to HERE, after this the old value of HERE is still on the stack )
 ;
 
 : VARIABLE
+        CREATE
         1 CELLS ALLOT   ( allocate 1 cell of memory, push the pointer to this memory )
-        WORD HEADER     ( make the dictionary entry (the name follows VARIABLE) )
-        DOCOL ,         ( append DOCOL (the codeword field of this word) )
-        ['] LIT ,         ( append the codeword LIT )
-        ,               ( append the pointer to the new memory )
-        ['] EXIT ,        ( append the codeword EXIT )
 ;
 
 
         THEN
 ;
 
+( Fill u ints, starting at a, with the value b )
+: FILL          ( a u b -- )
+        -ROT OVER + SWAP ?DO
+                DUP I !
+        LOOP
+        DROP
+;
+
+: ERASE         ( a u -- )
+        0 FILL
+;
 
 ( PRINTING THE DICTIONARY ------------------------------------------------------ )
 
         2DROP           ( restore stack )
 ;
 
+
+( MEMORY  ------------------------------------------------------------------ )
+
+: UNUSED  ( -- cells )
+        MEMSIZE HERE @ - ;