@@ -15,6 +15,11 @@ const debug = Ref(false)
15
15
const V6_COMPAT = VERSION < v " 0.7.0-DEV"
16
16
const BIG_ENDIAN = (ENDIAN_BOM == 0x01020304 )
17
17
18
+ @static if ! V6_COMPAT
19
+ using Pkg
20
+ export Pkg
21
+ end
22
+
18
23
Base. parse (:: Type{Expr} , args... ; kwargs... ) =
19
24
Meta. parse (args... ; kwargs... )
20
25
70
75
""" Get current module"""
71
76
cur_mod () = ccall (:jl_get_current_module , Ref{Module}, ())
72
77
73
- m_eval (mod, expr) = Core. eval (mod, expr)
78
+ function m_eval (mod, expr)
79
+ try
80
+ Core. eval (mod, expr)
81
+ catch ex
82
+ println (" m_eval($mod , $expr )" );
83
+ rethrow (ex)
84
+ end
85
+ end
74
86
m_eval (expr) = m_eval (cur_mod (), expr)
75
87
76
88
"""
77
89
@api <cmd> [<symbols>...]
78
90
79
- * @api freeze # use at end of module, to " freeze" API
91
+ * freeze # use at end of module to freeze API
80
92
81
- * @api list <modules>... # list API(s) of given modules (or current if none given)
93
+ * list <modules>... # list API(s) of given modules (or current if none given)
82
94
83
- * @api use <modules>... # use, without importing (i.e. can't extend)
84
- * @api test <modules>... # using public and develop APIs, for testing purposes
85
- * @api extend <modules>... # for development, imports api & dev, use api & dev definitions
86
- * @api export <modules>... # export public definitions
95
+ * use <modules>... # use, without importing (i.e. can't extend)
96
+ * use! <modules>... # use, without importing (i.e. can't extend), "export"
97
+ * test <modules>... # using public and develop APIs, for testing purposes
98
+ * extend <modules>... # for development, imports api & dev, use api & dev definitions
99
+ * extend! <modules>... # for development, imports api & dev, use api & dev definitions, "export"
100
+ * export <modules>... # export public definitions
87
101
88
- * @api base <names...> # Add functions from Base that are part of the API
89
- * @api public! <names...> # Add other symbols that are part of the public API (structs, consts)
90
- * @api develop! <names...> # Add other symbols that are part of the development API
91
- * @api public <names...> # Add functions that are part of the public API
92
- * @api develop <names...> # Add functions that are part of the development API
93
- * @api modules <names...> # Add submodule names that are part of the API
102
+ * base <names...> # Add functions from Base that are part of the API (extendible)
103
+ * base! <names...> # Add functions from Base or define them if not in Base
104
+ * public <names...> # Add other symbols that are part of the public API (structs, consts)
105
+ * public! <names...> # Add functions that are part of the public API (extendible)
106
+ * develop <names...> # Add other symbols that are part of the development API
107
+ * develop! <names...> # Add functions that are part of the development API (extendible)
108
+ * modules <names...> # Add submodule names that are part of the API
94
109
95
- * @api def <name> <expr> # Same as the @def macro, creates a macro with the given name
110
+ * def <name> <expr> # Same as the @def macro, creates a macro with the given name
96
111
97
112
"""
98
113
macro api (cmd:: Symbol )
@@ -113,7 +128,7 @@ function _api_freeze(mod::Module)
113
128
nothing
114
129
end
115
130
116
- const _cmduse = (:use , :test , :extend , :export , :list )
131
+ const _cmduse = (:use , :use! , : test , :extend , :extend! , :export , :list )
117
132
const _cmdadd =
118
133
(:modules , :public , :develop , :public! , :develop! , :base , :base! )
119
134
@@ -138,6 +153,20 @@ function _add_def!(curmod, grp, exp)
138
153
end
139
154
end
140
155
156
+ function push_args! (symbols, lst, grp)
157
+ for ex in lst
158
+ if isa (ex, Expr) && ex. head == :tuple
159
+ push_args! (symbols, ex. args)
160
+ elseif isa (ex, Symbol)
161
+ push! (symbols, ex)
162
+ elseif isa (ex, AbstractString)
163
+ push! (symbols, Symbol (ex))
164
+ else
165
+ error (" @api $grp : syntax error $ex " )
166
+ end
167
+ end
168
+ end
169
+
141
170
""" Add symbols"""
142
171
function _add_symbols (curmod, grp, exprs)
143
172
if debug[]
@@ -161,7 +190,7 @@ function _add_symbols(curmod, grp, exprs)
161
190
symbols = SymSet ()
162
191
for ex in exprs
163
192
if isa (ex, Expr) && ex. head == :tuple
164
- push ! (symbols, ex. args... )
193
+ push_args ! (symbols, ex. args, grp )
165
194
elseif isa (ex, Symbol)
166
195
push! (symbols, ex)
167
196
elseif isa (ex, AbstractString)
@@ -183,34 +212,32 @@ function _add_symbols(curmod, grp, exprs)
183
212
nothing
184
213
end
185
214
186
- function _api_extend (curmod, modules)
187
- imp = :import
188
- use = :using
189
-
215
+ function _api_extend (curmod, modules, cpy:: Bool )
190
216
for nam in modules
191
217
mod = m_eval (curmod, nam)
192
218
if isdefined (mod, :__api__ )
193
219
api = m_eval (mod, :__api__ )
194
- _do_list (curmod, imp, api , :Base , :base )
195
- _do_list (curmod, imp, api , nam, :public! )
196
- _do_list (curmod, imp, api , nam, :develop! )
197
- _do_list (curmod, use, api, nam, :public )
198
- _do_list (curmod, use, api, nam, :develop )
220
+ _do_list (curmod, cpy, :import , :Base , :base , api )
221
+ _do_list (curmod, cpy, :import , nam, :public! , api )
222
+ _do_list (curmod, cpy, :import , nam, :develop! , api )
223
+ _do_list (curmod, cpy, :using , nam, :public , api )
224
+ _do_list (curmod, cpy, :using , nam, :develop , api )
199
225
else
200
- println ( " API not found for module: $ mod" )
226
+ _do_list (curmod, cpy, :import , nam, :public! , names ( mod) )
201
227
end
202
228
end
203
-
204
229
nothing
205
230
end
206
231
207
- function _api_use (curmod, modules)
232
+ function _api_use (curmod, modules, cpy :: Bool )
208
233
for nam in modules
209
234
mod = m_eval (curmod, nam)
210
235
if isdefined (mod, :__api__ )
211
236
api = m_eval (mod, :__api__ )
212
- _do_list (curmod, :using , api, nam, :public )
213
- _do_list (curmod, :using , api, nam, :public! )
237
+ _do_list (curmod, cpy, :using , nam, :public , api)
238
+ _do_list (curmod, cpy, :using , nam, :public! , api)
239
+ else
240
+ _do_list (curmod, cpy, :using , nam, :public! , names (mod))
214
241
end
215
242
end
216
243
nothing
@@ -248,8 +275,17 @@ function _api(curmod::Module, cmd::Symbol, exprs)
248
275
modules = SymSet ()
249
276
for ex in exprs
250
277
if isa (ex, Expr) && ex. head == :tuple
251
- push! (modules, ex. args... )
252
- for sym in ex. args ; m_eval (curmod, :(import $ sym)) ; end
278
+ # Some of these might not just be modules
279
+ # might have module(symbols, !syms, sym => other), need to add support for that
280
+ for sym in ex. args
281
+ if isa (sym, Symbol)
282
+ push! (modules, sym)
283
+ m_eval (curmod, :(import $ sym))
284
+ else
285
+ println (" Not a symbol: $sym " );
286
+ dump (sym);
287
+ end
288
+ end
253
289
elseif isa (ex, Symbol)
254
290
push! (modules, ex)
255
291
m_eval (curmod, :(import $ ex))
@@ -272,13 +308,17 @@ function _api(curmod::Module, cmd::Symbol, exprs)
272
308
# Be nice and set up standard Test
273
309
cmd == :test && m_eval (curmod, V6_COMPAT ? :(using Base. Test) : :(using Test))
274
310
275
- cmd == :use ? _api_use (curmod, modules) : _api_extend (curmod, modules)
311
+ ((cmd == :use || cmd == :use! )
312
+ ? _api_use (curmod, modules, cmd == :use! )
313
+ : _api_extend (curmod, modules, cmd == :extend! ))
276
314
end
277
315
278
316
@static V6_COMPAT || (_dot_name (nam) = Expr (:., nam))
279
317
280
- function _do_list (curmod, cmd, api, mod, grp)
281
- lst = getfield (api, grp)
318
+ _do_list (curmod, cpy, cmd, mod, grp, api:: API ) =
319
+ _do_list (curmod, cpy, cmd, mod, grp, getfield (api, grp))
320
+
321
+ function _do_list (curmod, cpy, cmd, mod, grp, lst)
282
322
isempty (lst) && return
283
323
@static if V6_COMPAT
284
324
for nam in lst
@@ -297,6 +337,7 @@ function _do_list(curmod, cmd, api, mod, grp)
297
337
println (sprint (showerror, ex, catch_backtrace ()))
298
338
end
299
339
end
340
+ cpy && for sym in lst; m_eval (curmod, :( push! (__tmp_api__.$ grp, $ (QuoteNode (sym)) ))); end
300
341
end
301
342
302
343
macro api (cmd:: Symbol , exprs... )
0 commit comments