[gforth] / gforth / wordinfo.fs  

gforth: gforth/wordinfo.fs


1 : anton 1.1 \ WORDINFO.FS V1.0 17may93jaw
2 :    
3 : anton 1.8 \ 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 :    
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 :     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 :    
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 :     \ if nfa1 is an alias, nfa2 is the name of the original word
35 :     cell+ dup c@ $80 and 0=
36 :     IF
37 :     (name>) @ >name ( use look instead? )
38 :     ELSE
39 :     drop 0
40 :     THEN ;
41 : anton 1.1
42 :     : var? ( nfa -- flag )
43 : anton 1.7 cell+ (name>) >code-address dovar: = ;
44 : anton 1.1
45 :     : con? ( nfa -- flag )
46 : anton 1.7 cell+ (name>) >code-address docon: = ;
47 : anton 1.1
48 : pazsan 1.5 : user? ( nfa -- flag )
49 : anton 1.7 cell+ (name>) >code-address douser: = ;
50 : pazsan 1.5
51 : anton 1.1 : does? ( nfa -- flag )
52 : anton 1.7 \ !! does not work on all installations
53 :     cell+ (name>)
54 : anton 1.10 >code-address ['] spaces >code-address = ;
55 : anton 1.1
56 :     : defered? ( nfa -- flag )
57 : anton 1.7 cell+ (name>) >code-address dodefer: = ;
58 : anton 1.1
59 :     : colon? ( nfa -- flag )
60 : anton 1.7 cell+ (name>) >code-address docol: = ;
61 :    
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 :     \ VALUE VCheck
66 :    
67 :     \ : value? ( nfa -- flag )
68 :     \ dup does?
69 :     \ IF here @ ['] VCheck cell+ @ =
70 :     \ dup IF swap (name>) >body @ here ! ELSE nip THEN
71 :     \ ELSE drop false THEN ;
72 :    
73 :     : prim? ( nfa -- flag )
74 :     name>
75 :     forthstart u< ;
76 :    
77 :     \ None nestable IDs:
78 :    
79 :     1 CONSTANT Pri# \ Primitives
80 :     2 CONSTANT Con# \ Constants
81 :     3 CONSTANT Var# \ Variables
82 :     4 CONSTANT Val# \ Values
83 :    
84 :     \ Nestabe IDs:
85 :    
86 :     5 CONSTANT Doe# \ Does part
87 :     6 CONSTANT Def# \ Defer
88 :     7 CONSTANT Col# \ Colon def
89 : pazsan 1.5 8 CONSTANT Use# \ User variable
90 : anton 1.1
91 :     \ Nobody knows:
92 :    
93 : pazsan 1.5 9 CONSTANT Ali# \ Alias
94 : anton 1.1
95 : pazsan 1.5 10 CONSTANT Str# \ Structure words
96 : anton 1.1
97 : pazsan 1.5 11 CONSTANT Com# \ Compiler directives : ; POSTPONE
98 : anton 1.1
99 :     CREATE InfoTable
100 : pazsan 1.5 ' Prim? A, Pri# ,
101 :     ' Alias? A, Ali# ,
102 :     ' Con? A, Con# ,
103 :     ' Var? A, Var# ,
104 :     \ ' Value? A, Val# ,
105 : anton 1.1 ' Defered? A, Def# ,
106 : pazsan 1.5 ' Does? A, Doe# ,
107 :     ' Colon? A, Col# ,
108 :     ' User? A, Use# ,
109 : anton 1.1 0 ,
110 :    
111 :     : WordInfo ( nfa --- code )
112 :     InfoTable
113 :     BEGIN dup @ dup
114 :     WHILE swap 2 cells + swap
115 :     2 pick swap execute
116 :     UNTIL
117 :     1 cells - @ nip
118 :     ELSE
119 :     2drop drop 0
120 :     THEN ;
121 :    

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help