[gforth] / gforth / look.fs  

gforth: gforth/look.fs


1 : anton 1.1 \ LOOK.FS xt -> lfa 22may93jaw
2 :    
3 : anton 1.29 \ Copyright (C) 1995,1996,1997,2000,2003,2007 Free Software Foundation, Inc.
4 : anton 1.3
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 : anton 1.28 \ as published by the Free Software Foundation, either version 3
10 : anton 1.3 \ 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 : anton 1.28 \ along with this program. If not, see http://www.gnu.org/licenses/.
19 : anton 1.3
20 : anton 1.1 \ Look checks first if the word is a primitive. If yes then the
21 :     \ vocabulary in the primitive area is beeing searched, meaning
22 :     \ creating for each word a xt and comparing it...
23 :    
24 :     \ If a word is no primitive look searches backwards to find the nfa.
25 :     \ Problems: A compiled xt via compile, might be created with noname:
26 :     \ a noname: leaves now a empty name field
27 :    
28 : jwilke 1.16 require stuff.fs
29 :     require environ.fs
30 :    
31 : anton 1.1 decimal
32 :    
33 : jwilke 1.8 \ look 17may93jaw
34 : anton 1.1
35 : jwilke 1.8 \ rename to discover!!!
36 : anton 1.1
37 : anton 1.18 : xt>threaded ( xt -- x )
38 :     \G produces the threaded-code cell for the primitive xt
39 :     threading-method 0= if
40 :     @
41 :     then ;
42 :    
43 : anton 1.23 : search-name ( xt startlfa -- nt|0 )
44 : anton 1.22 \ look up name of primitive with code at xt
45 : pazsan 1.20 swap
46 : pazsan 1.21 >r false swap
47 : anton 1.17 BEGIN
48 :     @ dup
49 :     WHILE
50 : anton 1.22 dup name>int
51 : pazsan 1.21 r@ = IF
52 : anton 1.17 nip dup
53 :     THEN
54 :     REPEAT
55 : anton 1.23 drop rdrop ;
56 : anton 1.1
57 : anton 1.22 : threaded>xt ( ca -- xt|0 )
58 :     \G For the code address ca of a primitive, find the xt (or 0).
59 :     [IFDEF] decompile-prim
60 :     decompile-prim
61 :     [THEN]
62 :     \ walk through the array of primitive CAs
63 :     >r ['] noop begin
64 :     dup @ while
65 :     dup xt>threaded r@ = if
66 :     rdrop exit
67 :     endif
68 :     cell+
69 :     repeat
70 :     drop rdrop 0 ;
71 : jwilke 1.8
72 :     \ !!! nicht optimal!
73 :     [IFUNDEF] look
74 : jwilke 1.9 has? ec [IF]
75 :    
76 : jwilke 1.10 has? rom
77 : jwilke 1.8 [IF]
78 : anton 1.23 : prim>name ( xt -- nt|0 )
79 :     forth-wordlist @ search-name ;
80 : anton 1.22
81 : anton 1.23 : look ( xt -- lfa flag )
82 : jwilke 1.9 dup [ unlock rom-dictionary area lock ]
83 :     literal literal within
84 :     IF
85 : anton 1.13 >head-noprim dup ?? <>
86 : jwilke 1.9 ELSE
87 : anton 1.23 prim>name dup 0<>
88 : jwilke 1.9 THEN ;
89 :     [ELSE]
90 : jwilke 1.8 : look ( cfa -- lfa flag )
91 : anton 1.13 >head-noprim dup ??? <> ;
92 : jwilke 1.9 [THEN]
93 : jwilke 1.8
94 :     [ELSE]
95 :    
96 : anton 1.13 : PrimStart ['] true >head-noprim ;
97 : jwilke 1.8
98 : anton 1.23 : prim>name ( xt -- nt|0 )
99 :     PrimStart search-name ;
100 : anton 1.22
101 : anton 1.23 : look ( xt -- lfa flag )
102 : anton 1.12 dup in-dictionary?
103 : jwilke 1.9 IF
104 : anton 1.13 >head-noprim dup ??? <>
105 : anton 1.12 ELSE
106 : anton 1.23 prim>name dup 0<>
107 : jwilke 1.9 THEN ;
108 : anton 1.1
109 : jwilke 1.8 [THEN]
110 :     [THEN]
111 : anton 1.22
112 : anton 1.23 : threaded>name ( ca -- nt|0 )
113 : anton 1.22 threaded>xt prim>name ;
114 : anton 1.13
115 : anton 1.27 : >name ( xt -- nt|0 ) \ gforth to-name
116 :     \G tries to find the name token @var{nt} of the word represented
117 :     \G by @var{xt}; returns 0 if it fails. This word is not
118 :     \G absolutely reliable, it may give false positives and produce
119 :     \G wrong nts.
120 : anton 1.13 look and ;
121 :    
122 : anton 1.27 ' >name ALIAS >head \ gforth to-head
123 :     \G another name of @code{>name}
124 : pazsan 1.30
125 :     \ print recognizer stack
126 :    
127 :     [IFDEF] forth-recognizer
128 :     : .recs ( -- )
129 :     forth-recognizer get-recognizers 0 ?DO
130 :     >name .name
131 :     LOOP ;
132 :     [THEN]

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help