Skip to content

Commit

Permalink
adding whos() functionality. fixes issue #37
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Aug 4, 2011
1 parent 7f3d400 commit 98f2372
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
8 changes: 8 additions & 0 deletions j/client.j
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ function _start()
global PGRP = ProcessGroup(0, {}, {})
end

global VARIABLES = {}

# Load customized startup
try
load(strcat(getcwd(),"/custom.j"))
catch
end

(quiet,repl) = process_options(ARGS)

if repl
Expand Down
14 changes: 14 additions & 0 deletions j/show.j
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,17 @@ function show(a::Array)
print(slice2d(a, idxs), idxs == tail ? "" : "\n\n")),
map(x->Range1(1,x), tail))
end
summary(x) = string(typeof(x))
summary{T}(a::Array{T}) = strcat(join("x",map(string,size(a))),
" ", string(T), " array")
function whos()
global VARIABLES
for v = map(symbol,sort(map(string, VARIABLES)))
if isbound(v)
println(rpad(v, 30), summary(eval(v)))
end
end
end
6 changes: 0 additions & 6 deletions j/start_image.j
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,3 @@ libLAPACK = libBLAS
libarpack = dlopen("libarpack")
libfftw = dlopen("libfftw3")
libfftwf = dlopen("libfftw3f")

# Load customized startup
try
load(strcat(getcwd(),"/custom.j"))
catch
end
13 changes: 13 additions & 0 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
jl_module_t *jl_system_module;
jl_module_t *jl_user_module;

static jl_binding_t *varlist_binding=NULL;

jl_module_t *jl_new_module(jl_sym_t *name)
{
jl_module_t *m = (jl_module_t*)allocb(sizeof(jl_module_t));
Expand All @@ -37,6 +39,16 @@ jl_binding_t *jl_get_binding(jl_module_t *m, jl_sym_t *var)
b->constp = 0;
b->exportp = 0;
*bp = b;

// keep track of all variables added after the VARIABLES array
// is defined
if (varlist_binding &&
varlist_binding->value != NULL &&
jl_typeis(varlist_binding->value, jl_array_any_type)) {
jl_array_t *a = (jl_array_t*)varlist_binding->value;
jl_array_grow_end(a, 1);
jl_cellset(a, a->length-1, (jl_value_t*)var);
}
}
return *bp;
}
Expand Down Expand Up @@ -100,4 +112,5 @@ void jl_init_modules()
{
jl_system_module = jl_new_module(jl_symbol("System"));
jl_user_module = jl_new_module(jl_symbol("User"));
varlist_binding = jl_get_binding(jl_system_module, jl_symbol("VARIABLES"));
}

0 comments on commit 98f2372

Please sign in to comment.