Improved decompiler support for non-docol words.
[forth.jl.git] / src / lib.4th
index 745acf6..6b2d8ae 100644 (file)
 ( CONSTANTS AND VARIABLES ------------------------------------------------------ )
 
 : CONSTANT
-        WORD            ( get the name (the name follows CONSTANT) )
-        CREATE          ( make the dictionary entry )
+        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 )
 
 : VARIABLE
         1 CELLS ALLOT   ( allocate 1 cell of memory, push the pointer to this memory )
-        WORD CREATE     ( make the dictionary entry (the name follows VARIABLE) )
+        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 )
 
 
 : VALUE         ( n -- )
-        WORD CREATE     ( make the dictionary entry (the name follows VALUE) )
+        WORD HEADER     ( make the dictionary entry (the name follows VALUE) )
         DOCOL ,         ( append DOCOL )
         ['] LIT ,       ( append the codeword LIT )
         ,               ( append the initial value )
         DROP            ( at this point, the stack is: start-of-word end-of-word )
         SWAP            ( end-of-word start-of-word )
 
+        DUP >CFA @ CASE
+                DOCOL OF
+                        \ Colon definition
+                        ':' EMIT SPACE DUP ID. SPACE
+                        DUP ?IMMEDIATE IF ." IMMEDIATE " THEN CR
+                ENDOF
+                DOVAR OF
+                        \ Variable definition
+                        ." Variable " DUP ID. CR
+                        2DROP EXIT
+                ENDOF
+                DOCON OF
+                        \ Constant definition
+                        ." Constant " DUP ID. CR
+                        2DROP EXIT
+                ENDOF
+
+                \ Unknown codeword
+                ." Primitive or word with unrecognized codeword." CR 
+                DROP 2DROP EXIT
+        ENDCASE
+
         ( begin the definition with : NAME [IMMEDIATE] )
-        ':' EMIT SPACE DUP ID. SPACE
-        DUP ?IMMEDIATE IF ." IMMEDIATE " THEN CR 4 
+        ( ':' EMIT SPACE DUP ID. SPACE
+        DUP ?IMMEDIATE IF ." IMMEDIATE " THEN CR 4 )
+
+        4 SPACES
 
         >DFA            ( get the data address, ie. points after DOCOL | end-of-word start-of-data )
 
         2DROP           ( restore stack )
 ;
 
-
-( WELCOME MESSAGE ------------------------------------------------------------- )
-
-CR CR ."  --- TimForth initialized  --- "
-
-