Skip to content

Commit 98f2372

Browse files
committed
adding whos() functionality. fixes issue #37
1 parent 7f3d400 commit 98f2372

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

j/client.j

+8
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ function _start()
144144
global PGRP = ProcessGroup(0, {}, {})
145145
end
146146

147+
global VARIABLES = {}
148+
149+
# Load customized startup
150+
try
151+
load(strcat(getcwd(),"/custom.j"))
152+
catch
153+
end
154+
147155
(quiet,repl) = process_options(ARGS)
148156

149157
if repl

j/show.j

+14
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,17 @@ function show(a::Array)
283283
print(slice2d(a, idxs), idxs == tail ? "" : "\n\n")),
284284
map(x->Range1(1,x), tail))
285285
end
286+
287+
summary(x) = string(typeof(x))
288+
289+
summary{T}(a::Array{T}) = strcat(join("x",map(string,size(a))),
290+
" ", string(T), " array")
291+
292+
function whos()
293+
global VARIABLES
294+
for v = map(symbol,sort(map(string, VARIABLES)))
295+
if isbound(v)
296+
println(rpad(v, 30), summary(eval(v)))
297+
end
298+
end
299+
end

j/start_image.j

-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,3 @@ libLAPACK = libBLAS
1818
libarpack = dlopen("libarpack")
1919
libfftw = dlopen("libfftw3")
2020
libfftwf = dlopen("libfftw3f")
21-
22-
# Load customized startup
23-
try
24-
load(strcat(getcwd(),"/custom.j"))
25-
catch
26-
end

src/module.c

+13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
jl_module_t *jl_system_module;
1616
jl_module_t *jl_user_module;
1717

18+
static jl_binding_t *varlist_binding=NULL;
19+
1820
jl_module_t *jl_new_module(jl_sym_t *name)
1921
{
2022
jl_module_t *m = (jl_module_t*)allocb(sizeof(jl_module_t));
@@ -37,6 +39,16 @@ jl_binding_t *jl_get_binding(jl_module_t *m, jl_sym_t *var)
3739
b->constp = 0;
3840
b->exportp = 0;
3941
*bp = b;
42+
43+
// keep track of all variables added after the VARIABLES array
44+
// is defined
45+
if (varlist_binding &&
46+
varlist_binding->value != NULL &&
47+
jl_typeis(varlist_binding->value, jl_array_any_type)) {
48+
jl_array_t *a = (jl_array_t*)varlist_binding->value;
49+
jl_array_grow_end(a, 1);
50+
jl_cellset(a, a->length-1, (jl_value_t*)var);
51+
}
4052
}
4153
return *bp;
4254
}
@@ -100,4 +112,5 @@ void jl_init_modules()
100112
{
101113
jl_system_module = jl_new_module(jl_symbol("System"));
102114
jl_user_module = jl_new_module(jl_symbol("User"));
115+
varlist_binding = jl_get_binding(jl_system_module, jl_symbol("VARIABLES"));
103116
}

0 commit comments

Comments
 (0)