Working on standardizing FIND.
[forth.jl.git] / src / lib.4th
index 647b499..840ed4b 100644 (file)
 ( CONSTANTS AND VARIABLES ------------------------------------------------------ )
 
 : CONSTANT
-        BL WORD HEADER  ( make dictionary entry (the name follows CONSTANT) )
-        DOCOL ,         ( append DOCOL (the codeword field of this word) )
-        ['] LIT ,       ( append the codeword LIT )
-        ,               ( append the value on the top of the stack )
-        ['] EXIT ,      ( append the codeword EXIT )
+        CREATE ,
+DOES>   @
 ;
 
 : ALLOT         ( n -- )
 ;
 
 : VARIABLE
-        BL WORD HEADER
-        DOVAR ,
+        CREATE
         1 CELLS ALLOT   ( allocate 1 cell of memory, push the pointer to this memory )
 ;
 
 : VALUE         ( n -- )
-        BL WORD HEADER  ( make the dictionary entry (the name follows VALUE) )
-        DOCOL ,         ( append DOCOL )
-        ['] LIT ,       ( append the codeword LIT )
-        ,               ( append the initial value )
-        ['] EXIT ,      ( append the codeword EXIT )
+        CREATE ,
+DOES>   @
 ;
 
 : TO IMMEDIATE  ( n -- )
         BL WORD         ( get the name of the value )
         FIND            ( look it up in the dictionary )
-        >PFA            ( get a pointer to the first data field (the 'LIT') )
-        1+              ( increment to point at the value )
+        >CFA >BODY            ( get a pointer to the first data field (the 'LIT') )
         STATE @ IF      ( compiling? )
                 ['] LIT ,         ( compile LIT )
                 ,               ( compile the address of the value )
 : +TO IMMEDIATE
         BL WORD         ( get the name of the value )
         FIND            ( look it up in the dictionary )
-        >PFA            ( get a pointer to the first data field (the 'LIT') )
-        1+              ( increment to point at the value )
+        >CFA >BODY            ( get a pointer to the first data field (the 'LIT') )
         STATE @ IF      ( compiling? )
                 ['] LIT ,         ( compile LIT )
                 ,               ( compile the address of the value )
 
         4 SPACES
 
-        >PFA            ( get the data address, ie. points after DOCOL | end-of-word start-of-data )
+        >CFA >BODY            ( get the data address, ie. points after DOCOL | end-of-word start-of-data )
 
         ( now we start decompiling until we hit the end of the word )
         BEGIN           ( end start )