Annotation of gforth/wordinfo.fs, revision 1.7

1.1       anton       1: \ WORDINFO.FS  V1.0                                    17may93jaw
                      2: 
                      3: \ May be cross-compiled
                      4: \ If you want check values then exclude comments,
                      5: \ but keep in mind that this can't be cross-compiled
                      6: 
                      7: INCLUDE look.fs
                      8: 
                      9: \ Wordinfo is a tool that checks a nfa
                     10: \ and finds out what wordtype we have
                     11: \ it is used in SEE.FS
                     12: 
                     13: : alias? ( nfa -- flag )
                     14:         dup name> look
                     15:         0= ABORT" WINFO: CFA not found"
1.4       pazsan     16: \       cell+
1.1       anton      17:         2dup <>
                     18:         IF   nip dup 1 cells - here !
                     19:              count $1f and here cell+ place true
                     20:         ELSE 2drop false THEN ;
                     21: 
                     22: : var?  ( nfa -- flag )
1.7     ! anton      23:     cell+ (name>) >code-address dovar: = ;
1.1       anton      24: 
                     25: : con?  ( nfa -- flag )
1.7     ! anton      26:     cell+ (name>) >code-address docon: = ;
1.1       anton      27: 
1.5       pazsan     28: : user?  ( nfa -- flag )
1.7     ! anton      29:     cell+ (name>) >code-address douser: = ;
1.5       pazsan     30: 
1.1       anton      31: : does? ( nfa -- flag )
1.7     ! anton      32:     \ !! does not work on all installations
        !            33:     cell+ (name>)
        !            34:     >code-address ['] bits >code-address = ;
1.1       anton      35: 
                     36: : defered? ( nfa -- flag )
1.7     ! anton      37:     cell+ (name>) >code-address dodefer: = ;
1.1       anton      38: 
                     39: : colon? ( nfa -- flag )
1.7     ! anton      40:     cell+ (name>) >code-address docol: = ;
        !            41: 
        !            42: \ the above words could be factored with create-does>, but this would
        !            43: \ probably make this file incompatible with cross.
1.1       anton      44: 
                     45: \ VALUE VCheck
                     46: 
                     47: \ : value? ( nfa -- flag )
                     48: \         dup does?
                     49: \         IF here @ ['] VCheck cell+ @ =
                     50: \            dup IF swap (name>) >body @ here ! ELSE nip THEN
                     51: \         ELSE drop false THEN ;
                     52: 
                     53: : prim? ( nfa -- flag )
                     54:         name>
                     55:         forthstart u< ;
                     56: 
                     57: \ None nestable IDs:
                     58: 
                     59: 1 CONSTANT Pri#         \ Primitives
                     60: 2 CONSTANT Con#         \ Constants
                     61: 3 CONSTANT Var#         \ Variables
                     62: 4 CONSTANT Val#         \ Values
                     63: 
                     64: \ Nestabe IDs:
                     65: 
                     66: 5 CONSTANT Doe#         \ Does part
                     67: 6 CONSTANT Def#         \ Defer
                     68: 7 CONSTANT Col#         \ Colon def
1.5       pazsan     69: 8 CONSTANT Use#         \ User variable
1.1       anton      70: 
                     71: \ Nobody knows:
                     72: 
1.5       pazsan     73: 9 CONSTANT Ali#         \ Alias
1.1       anton      74: 
1.5       pazsan     75: 10 CONSTANT Str#         \ Structure words
1.1       anton      76: 
1.5       pazsan     77: 11 CONSTANT Com#        \ Compiler directives : ; POSTPONE
1.1       anton      78: 
                     79: CREATE InfoTable
1.5       pazsan     80:         ' Prim?    A, Pri# ,
                     81:         ' Alias?   A, Ali# ,
                     82:         ' Con?     A, Con# ,
                     83:         ' Var?     A, Var# ,
                     84: \        ' Value?  A, Val# ,
1.1       anton      85:         ' Defered? A, Def# ,
1.5       pazsan     86:         ' Does?    A, Doe# ,
                     87:         ' Colon?   A, Col# ,
                     88:        ' User?    A, Use# ,
1.1       anton      89:         0 ,
                     90: 
                     91: : WordInfo ( nfa --- code )
                     92:         InfoTable
                     93:         BEGIN  dup @ dup
                     94:         WHILE  swap 2 cells + swap
                     95:                2 pick swap execute
                     96:         UNTIL
                     97:         1 cells - @ nip
                     98:         ELSE
                     99:         2drop drop 0
                    100:         THEN ;
                    101: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>