[gforth] / gforth / wordinfo.fs  

gforth: gforth/wordinfo.fs


1 : anton 1.1 \ WORDINFO.FS V1.0 17may93jaw
2 :    
3 : anton 1.25 \ Copyright (C) 1995,1996,1998,2000 Free Software Foundation, Inc.
4 : anton 1.8
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 : anton 1.22 \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
20 : anton 1.8
21 : anton 1.1 \ 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 : anton 1.19 require look.fs
26 : anton 1.1
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 :    
31 : anton 1.9 \ 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 : anton 1.20 \ if nfa1 is an alias, nfa2 is the name of the original word.
35 :     \ if the original word has no name, return 0.
36 : anton 1.23 dup cell+ @ alias-mask and 0=
37 : anton 1.12 IF ( nfa1 )
38 : anton 1.20 ((name>)) @ >name
39 : anton 1.9 ELSE
40 :     drop 0
41 :     THEN ;
42 : anton 1.1
43 :     : var? ( nfa -- flag )
44 : anton 1.12 ((name>)) >code-address dovar: = ;
45 : anton 1.1
46 :     : con? ( nfa -- flag )
47 : anton 1.12 ((name>)) >code-address docon: = ;
48 : anton 1.1
49 : pazsan 1.5 : user? ( nfa -- flag )
50 : anton 1.12 ((name>)) >code-address douser: = ;
51 : pazsan 1.5
52 : anton 1.1 : does? ( nfa -- flag )
53 : anton 1.12 ((name>))
54 : anton 1.13 >does-code 0<> ;
55 : anton 1.1
56 :     : defered? ( nfa -- flag )
57 : anton 1.12 ((name>)) >code-address dodefer: = ;
58 : anton 1.1
59 :     : colon? ( nfa -- flag )
60 : anton 1.12 ((name>)) >code-address docol: = ;
61 : anton 1.7
62 :     \ the above words could be factored with create-does>, but this would
63 :     \ probably make this file incompatible with cross.
64 : anton 1.1
65 : jwilke 1.14 [IFDEF] forthstart
66 :     : xtprim? ( xt -- flag )
67 : anton 1.18 in-dictionary? 0= ; \ !! does not work for CODE words
68 : jwilke 1.14 [ELSE]
69 :     : xtprim? ( xt -- flag )
70 : anton 1.15 dup >body swap >code-address = ; \ !! works only for indirect threaded code
71 :     \ !! does not work for primitives
72 : jwilke 1.14 [THEN]
73 : anton 1.1 : prim? ( nfa -- flag )
74 : jwilke 1.14 name>int xtprim? ;
75 : anton 1.1
76 :     \ None nestable IDs:
77 :    
78 :     1 CONSTANT Pri# \ Primitives
79 :     2 CONSTANT Con# \ Constants
80 :     3 CONSTANT Var# \ Variables
81 :     4 CONSTANT Val# \ Values
82 :    
83 :     \ Nestabe IDs:
84 :    
85 :     5 CONSTANT Doe# \ Does part
86 :     6 CONSTANT Def# \ Defer
87 :     7 CONSTANT Col# \ Colon def
88 : pazsan 1.5 8 CONSTANT Use# \ User variable
89 : anton 1.1
90 :     \ Nobody knows:
91 :    
92 : pazsan 1.5 9 CONSTANT Ali# \ Alias
93 : anton 1.1
94 : pazsan 1.5 10 CONSTANT Str# \ Structure words
95 : anton 1.1
96 : pazsan 1.5 11 CONSTANT Com# \ Compiler directives : ; POSTPONE
97 : anton 1.1
98 :     CREATE InfoTable
99 : pazsan 1.5 ' Prim? A, Pri# ,
100 :     ' Alias? A, Ali# ,
101 :     ' Con? A, Con# ,
102 :     ' Var? A, Var# ,
103 :     \ ' Value? A, Val# ,
104 : anton 1.1 ' Defered? A, Def# ,
105 : pazsan 1.5 ' Does? A, Doe# ,
106 :     ' Colon? A, Col# ,
107 :     ' User? A, Use# ,
108 : anton 1.1 0 ,
109 :    
110 :     : WordInfo ( nfa --- code )
111 :     InfoTable
112 :     BEGIN dup @ dup
113 :     WHILE swap 2 cells + swap
114 :     2 pick swap execute
115 :     UNTIL
116 :     1 cells - @ nip
117 :     ELSE
118 :     2drop drop 0
119 :     THEN ;
120 :    

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help