[gforth] / gforth / wordinfo.fs  

gforth: gforth/wordinfo.fs


1 : anton 1.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"
16 : pazsan 1.4 \ cell+
17 : anton 1.1 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 )
23 : pazsan 1.4 cell+ (name>)
24 : pazsan 1.3 >code-address ['] udp >code-address = ;
25 : anton 1.1
26 :     : con? ( nfa -- flag )
27 : pazsan 1.4 cell+ (name>)
28 : pazsan 1.2 >code-address ['] bl >code-address = ;
29 : anton 1.1
30 : pazsan 1.5 : user? ( nfa -- flag )
31 :     cell+ (name>)
32 :     >code-address ['] s0 >code-address = ;
33 :    
34 : anton 1.1 : does? ( nfa -- flag )
35 : pazsan 1.4 cell+ dup (name>)
36 : pazsan 1.2 >code-address ['] source >code-address =
37 : anton 1.1 dup IF swap (name>) cell+ @ here ! ELSE nip THEN ;
38 :    
39 :     : defered? ( nfa -- flag )
40 :     dup does?
41 :     IF here @ ['] source cell+ @ =
42 : pazsan 1.4 dup IF swap cell+ (name>) >body @ here ! ELSE nip THEN
43 : anton 1.1 ELSE drop false THEN ;
44 :    
45 :     : colon? ( nfa -- flag )
46 : pazsan 1.4 cell+ (name>)
47 : pazsan 1.2 >code-address ['] does? >code-address = ;
48 : anton 1.1
49 :     \ VALUE VCheck
50 :    
51 :     \ : value? ( nfa -- flag )
52 :     \ dup does?
53 :     \ IF here @ ['] VCheck cell+ @ =
54 :     \ dup IF swap (name>) >body @ here ! ELSE nip THEN
55 :     \ ELSE drop false THEN ;
56 :    
57 :     : prim? ( nfa -- flag )
58 :     name>
59 :     forthstart u< ;
60 :    
61 :     \ None nestable IDs:
62 :    
63 :     1 CONSTANT Pri# \ Primitives
64 :     2 CONSTANT Con# \ Constants
65 :     3 CONSTANT Var# \ Variables
66 :     4 CONSTANT Val# \ Values
67 :    
68 :     \ Nestabe IDs:
69 :    
70 :     5 CONSTANT Doe# \ Does part
71 :     6 CONSTANT Def# \ Defer
72 :     7 CONSTANT Col# \ Colon def
73 : pazsan 1.5 8 CONSTANT Use# \ User variable
74 : anton 1.1
75 :     \ Nobody knows:
76 :    
77 : pazsan 1.5 9 CONSTANT Ali# \ Alias
78 : anton 1.1
79 : pazsan 1.5 10 CONSTANT Str# \ Structure words
80 : anton 1.1
81 : pazsan 1.5 11 CONSTANT Com# \ Compiler directives : ; POSTPONE
82 : anton 1.1
83 :     CREATE InfoTable
84 : pazsan 1.5 ' Prim? A, Pri# ,
85 :     ' Alias? A, Ali# ,
86 :     ' Con? A, Con# ,
87 :     ' Var? A, Var# ,
88 :     \ ' Value? A, Val# ,
89 : anton 1.1 ' Defered? A, Def# ,
90 : pazsan 1.5 ' Does? A, Doe# ,
91 :     ' Colon? A, Col# ,
92 :     ' User? A, Use# ,
93 : anton 1.1 0 ,
94 :    
95 :     : WordInfo ( nfa --- code )
96 :     InfoTable
97 :     BEGIN dup @ dup
98 :     WHILE swap 2 cells + swap
99 :     2 pick swap execute
100 :     UNTIL
101 :     1 cells - @ nip
102 :     ELSE
103 :     2drop drop 0
104 :     THEN ;
105 :    

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help