diff --git a/base/exports.jl b/base/exports.jl index 0662e6117204a..a828f4ac2d33d 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1059,6 +1059,7 @@ export versioninfo, which, whos, + clear, # loading source files evalfile, diff --git a/base/interactiveutil.jl b/base/interactiveutil.jl index f5e5bd1c7226b..4255ee9143ea1 100644 --- a/base/interactiveutil.jl +++ b/base/interactiveutil.jl @@ -330,3 +330,16 @@ function download(url::String) filename = tempname() download(url, filename) end + +function clear() + last = Core.Main + b = last.Base + ccall(:jl_new_main_module, Any, ()) + m = Core.Main + ccall(:jl_add_standard_imports, Void, (Any,), m) + eval(m, + Expr(:toplevel, + :(const Base = $(Expr(:quote, b))), + :(const LastMain = $(Expr(:quote, last))))) + m +end diff --git a/base/reflection.jl b/base/reflection.jl index 11f25d190a185..5f5360de14dc3 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -3,8 +3,26 @@ module_name(m::Module) = ccall(:jl_module_name, Any, (Any,), m)::Symbol module_parent(m::Module) = ccall(:jl_module_parent, Any, (Any,), m)::Module current_module() = ccall(:jl_get_current_module, Any, ())::Module -fullname(m::Module) = m===Main ? () : tuple(fullname(module_parent(m))..., - module_name(m)) +function fullname(m::Module) + if m === Main + () + elseif module_parent(m) === m + # not Main, but is its own parent, means a prior Main module + n = () + this = Main + while this !== m + if isdefined(this, :LastMain) + n = tuple(n..., :LastMain) + this = this.LastMain + else + error("no reference to module ", module_name(m)) + end + end + return n + else + tuple(fullname(module_parent(m))..., module_name(m)) + end +end names(m::Module, all::Bool, imported::Bool) = ccall(:jl_module_names, Array{Symbol,1}, (Any,Int32,Int32), m, all, imported) names(m::Module, all::Bool) = names(m, all, false) diff --git a/src/julia.h b/src/julia.h index 6076a9021ff2e..1a3382c963d11 100644 --- a/src/julia.h +++ b/src/julia.h @@ -808,7 +808,7 @@ DLLEXPORT void jl_module_import(jl_module_t *to, jl_module_t *from, jl_sym_t *s) DLLEXPORT void jl_module_importall(jl_module_t *to, jl_module_t *from); DLLEXPORT void jl_module_export(jl_module_t *from, jl_sym_t *s); DLLEXPORT jl_module_t *jl_new_main_module(void); -void jl_add_standard_imports(jl_module_t *m); +DLLEXPORT void jl_add_standard_imports(jl_module_t *m); STATIC_INLINE jl_function_t *jl_get_function(jl_module_t *m, const char *name) { return (jl_function_t*) jl_get_global(m, jl_symbol(name));