Annotation of gforth/wordinfo.fs, revision 1.13

1.1       anton       1: \ WORDINFO.FS  V1.0                                    17may93jaw
                      2: 
1.8       anton       3: \ Copyright (C) 1995 Free Software Foundation, Inc.
                      4: 
                      5: \ This file is part of Gforth.
                      6: 
                      7: \ Gforth is free software; you can redistribute it and/or
                      8: \ modify it under the terms of the GNU General Public License
                      9: \ as published by the Free Software Foundation; either version 2
                     10: \ of the License, or (at your option) any later version.
                     11: 
                     12: \ This program is distributed in the hope that it will be useful,
                     13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
                     14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     15: \ GNU General Public License for more details.
                     16: 
                     17: \ You should have received a copy of the GNU General Public License
                     18: \ along with this program; if not, write to the Free Software
                     19: \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
                     20: 
1.1       anton      21: \ May be cross-compiled
                     22: \ If you want check values then exclude comments,
                     23: \ but keep in mind that this can't be cross-compiled
                     24: 
                     25: INCLUDE look.fs
                     26: 
                     27: \ Wordinfo is a tool that checks a nfa
                     28: \ and finds out what wordtype we have
                     29: \ it is used in SEE.FS
                     30: 
1.9       anton      31: \ the old alias? did not work and it is not used, so I changed
                     32: \ it in many respects - anton
                     33: : alias? ( nfa1 -- nfa2|0 )
                     34:     \ if nfa1 is an alias, nfa2 is the name of the original word
1.12      anton      35:     dup cell+ c@ alias-mask and 0=
                     36:     IF ( nfa1 )
                     37:        ((name>)) @ >name ( use look instead? )
1.9       anton      38:     ELSE
                     39:        drop 0
                     40:     THEN ;
1.1       anton      41: 
                     42: : var?  ( nfa -- flag )
1.12      anton      43:     ((name>)) >code-address dovar: = ;
1.1       anton      44: 
                     45: : con?  ( nfa -- flag )
1.12      anton      46:     ((name>)) >code-address docon: = ;
1.1       anton      47: 
1.5       pazsan     48: : user?  ( nfa -- flag )
1.12      anton      49:     ((name>)) >code-address douser: = ;
1.5       pazsan     50: 
1.1       anton      51: : does? ( nfa -- flag )
1.12      anton      52:     ((name>))
1.13    ! anton      53:     >does-code 0<> ;
1.1       anton      54: 
                     55: : defered? ( nfa -- flag )
1.12      anton      56:     ((name>)) >code-address dodefer: = ;
1.1       anton      57: 
                     58: : colon? ( nfa -- flag )
1.12      anton      59:     ((name>)) >code-address docol: = ;
1.7       anton      60: 
                     61: \ the above words could be factored with create-does>, but this would
                     62: \ probably make this file incompatible with cross.
1.1       anton      63: 
                     64: : prim? ( nfa -- flag )
1.12      anton      65:         name>int
1.1       anton      66:         forthstart u< ;
                     67: 
                     68: \ None nestable IDs:
                     69: 
                     70: 1 CONSTANT Pri#         \ Primitives
                     71: 2 CONSTANT Con#         \ Constants
                     72: 3 CONSTANT Var#         \ Variables
                     73: 4 CONSTANT Val#         \ Values
                     74: 
                     75: \ Nestabe IDs:
                     76: 
                     77: 5 CONSTANT Doe#         \ Does part
                     78: 6 CONSTANT Def#         \ Defer
                     79: 7 CONSTANT Col#         \ Colon def
1.5       pazsan     80: 8 CONSTANT Use#         \ User variable
1.1       anton      81: 
                     82: \ Nobody knows:
                     83: 
1.5       pazsan     84: 9 CONSTANT Ali#         \ Alias
1.1       anton      85: 
1.5       pazsan     86: 10 CONSTANT Str#         \ Structure words
1.1       anton      87: 
1.5       pazsan     88: 11 CONSTANT Com#        \ Compiler directives : ; POSTPONE
1.1       anton      89: 
                     90: CREATE InfoTable
1.5       pazsan     91:         ' Prim?    A, Pri# ,
                     92:         ' Alias?   A, Ali# ,
                     93:         ' Con?     A, Con# ,
                     94:         ' Var?     A, Var# ,
                     95: \        ' Value?  A, Val# ,
1.1       anton      96:         ' Defered? A, Def# ,
1.5       pazsan     97:         ' Does?    A, Doe# ,
                     98:         ' Colon?   A, Col# ,
                     99:        ' User?    A, Use# ,
1.1       anton     100:         0 ,
                    101: 
                    102: : WordInfo ( nfa --- code )
                    103:         InfoTable
                    104:         BEGIN  dup @ dup
                    105:         WHILE  swap 2 cells + swap
                    106:                2 pick swap execute
                    107:         UNTIL
                    108:         1 cells - @ nip
                    109:         ELSE
                    110:         2drop drop 0
                    111:         THEN ;
                    112: 

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