]> gitweb.factorcode.org Git - factor.git/blob - extra/fuel/fuel.factor
FUEL: refactoring to eliminate the eval-result variable
[factor.git] / extra / fuel / fuel.factor
1 ! Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs compiler.units continuations fry fuel.eval
4 fuel.help fuel.xref help.topics io.pathnames kernel namespaces parser
5 parser.notes sequences source-files tools.scaffold vocabs vocabs.files
6 vocabs.hierarchy vocabs.loader vocabs.metadata vocabs.parser words ;
7 IN: fuel
8
9 ! Evaluation
10 : fuel-eval-restartable ( -- )
11     t eval-res-flag set-global ; inline
12
13 : fuel-eval-non-restartable ( -- )
14     f eval-res-flag set-global ; inline
15
16 : fuel-eval-in-context ( lines in usings -- )
17     eval-in-context ;
18
19 : fuel-retort ( -- ) f f "" send-retort ; inline
20
21 ! Loading files
22
23 <PRIVATE
24
25 SYMBOL: :uses
26 SYMBOL: :uses-suggestions
27
28 : is-use-restart? ( restart -- ? )
29     name>> [ "Use the " head? ] [ " vocabulary" tail? ] bi and ;
30
31 : get-restart-vocab ( restart -- vocab/f )
32     obj>> dup word? [ vocabulary>> ] [ drop f ] if ;
33
34 : is-suggested-restart? ( restart -- ? )
35     dup is-use-restart? [
36         get-restart-vocab :uses-suggestions get member?
37     ] [ drop f ] if ;
38
39 : try-suggested-restarts ( -- )
40     restarts get [ is-suggested-restart? ] filter
41     dup length 1 = [ first continue-restart ] [ drop ] if ;
42
43 SYMBOL: auto-uses
44
45 : set-use-hook ( -- )
46     [
47         manifest get auto-used>> clone :uses prefix
48         clone auto-uses set-global
49     ] print-use-hook set ;
50
51 PRIVATE>
52
53 : fuel-use-suggested-vocabs ( ..a suggestions quot: ( ..a -- ..b )
54                               -- ..b result )
55     f auto-uses set-global
56     [ :uses-suggestions set ] dip
57     [ try-suggested-restarts rethrow ] recover
58     auto-uses get-global ; inline
59
60 : fuel-run-file ( path -- result )
61     f auto-uses set-global
62     '[ set-use-hook _ run-file ] with-scope
63     auto-uses get-global ; inline
64
65 : fuel-with-autouse ( ..a quot: ( ..a -- ..b ) -- ..b )
66     '[ set-use-hook _ call ] with-scope ; inline
67
68 : fuel-get-uses ( name lines -- )
69     '[
70         [
71             _ [
72                 parser-quiet? on
73                 _ parse-fresh drop
74             ] with-source-file
75         ] with-compilation-unit
76     ] fuel-with-autouse ;
77
78 ! Edit locations
79 : fuel-get-word-location ( word -- result )
80     word-location ;
81
82 : fuel-get-vocab-location ( vocab -- result )
83     vocab-location  ;
84
85 : fuel-get-doc-location ( word -- result )
86     doc-location ;
87
88 : fuel-get-article-location ( name -- result )
89     article-location ;
90
91 : fuel-get-vocabs ( -- reuslt )
92     all-disk-vocab-names ;
93
94 : fuel-get-vocabs/prefix ( prefix -- result )
95     get-vocabs/prefix ;
96
97 : fuel-get-words ( prefix names -- result )
98     get-vocabs-words/prefix ;
99
100 ! Cross-references
101
102 : fuel-callers-xref ( word -- result ) callers-xref ;
103
104 : fuel-callees-xref ( word -- result ) callees-xref ;
105
106 : fuel-apropos-xref ( str -- result ) apropos-xref ;
107
108 : fuel-vocab-xref ( vocab -- result ) vocab-xref ;
109
110 : fuel-vocab-uses-xref ( vocab -- result ) vocab-uses-xref ;
111
112 : fuel-vocab-usage-xref ( vocab -- result ) vocab-usage-xref ;
113
114 ! Help support
115
116 : fuel-get-article ( name -- result )
117     fuel.help:get-article ;
118
119 : fuel-get-article-title ( name -- result )
120     articles get at [ article-title ] [ f ] if* ;
121
122 : fuel-word-help ( name -- result ) word-help ;
123
124 : fuel-word-def ( name -- result ) word-def ;
125
126 : fuel-vocab-help ( name -- result ) fuel.help:vocab-help ;
127
128 : fuel-word-synopsis ( word -- synopsis )
129     word-synopsis ;
130
131 : fuel-vocab-summary ( name -- summary )
132     fuel.help:vocab-summary ;
133
134 : fuel-index ( quot -- result )
135     call( -- seq ) format-index ;
136
137 : fuel-get-vocabs/tag ( tag -- result )
138     get-vocabs/tag ;
139
140 : fuel-get-vocabs/author ( author -- result )
141     get-vocabs/author ;
142
143 ! Scaffold support
144
145 : scaffold-name ( devname -- )
146     [ developer-name set ] when* ;
147
148 : fuel-scaffold-vocab ( root name devname -- result )
149     [ scaffold-name dup [ scaffold-vocab ] dip ] with-scope
150     dup require vocab-source-path absolute-path ;
151
152 : fuel-scaffold-help ( name devname -- result )
153     [ scaffold-name dup require dup scaffold-docs ] with-scope
154     vocab-docs-path absolute-path ;
155
156 : fuel-scaffold-tests ( name devname -- result )
157     [ scaffold-name dup require dup scaffold-tests ] with-scope
158     vocab-tests-file absolute-path ;
159
160 : fuel-scaffold-authors ( name devname -- result )
161     [ scaffold-name dup require dup scaffold-authors ] with-scope
162     [ vocab-authors-path ] keep swap vocab-append-path absolute-path ;
163
164 : fuel-scaffold-tags ( name tags -- result )
165     [ scaffold-tags ]
166     [
167         drop [ vocab-tags-path ] keep swap
168         vocab-append-path absolute-path
169     ] 2bi ;
170
171 : fuel-scaffold-summary ( name summary -- result )
172     [ scaffold-summary ]
173     [
174         drop [ vocab-summary-path ] keep swap
175         vocab-append-path absolute-path
176     ] 2bi ;
177
178 : fuel-scaffold-platforms ( name platforms -- result )
179     [ scaffold-platforms ]
180     [
181         drop [ vocab-platforms-path ] keep swap
182         vocab-append-path absolute-path
183     ] 2bi ;
184
185 : fuel-scaffold-get-root ( name -- result )
186     find-vocab-root ;