Skip to content

Commit

Permalink
Merge branch 'master' of github.com:JuliaLang/julia
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed May 8, 2012
2 parents 74c1d52 + bf10a71 commit 416f11f
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 30 deletions.
6 changes: 1 addition & 5 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ function repl_show(io, v::ANY)
if isgeneric(v)
if isa(v,CompositeKind)
println(io)
name = v.name.name
else
name = string(v)
end
println(io, "Methods for generic function ", name)
ccall(:jl_show_method_table, Void, (Any, Any,), io, v)
show(io, v.env)
end
end

Expand Down
4 changes: 1 addition & 3 deletions base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ type Rational{T<:Integer} <: Real
error("invalid rational: 0//0")
end
g = gcd(den, num)
num = div(num, g)
den = div(den, g)
new(num, den)
new(div(num, g), div(den, g))
end
end
Rational{T<:Integer}(n::T, d::T) = Rational{T}(n,d)
Expand Down
29 changes: 29 additions & 0 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,35 @@ function show(io, bt::BackTrace)
end
end

function show(io, m::Method)
tv = m.tvars
if !isa(tv,Tuple)
tv = (tv,)
end
if !isempty(tv)
show_delim_array(io, tv, '{', ',', '}', false)
end
show(io, m.sig)
li = m.func.code
if li.line > 0
print(io, " at ", li.file, ":", li.line)
end
end

function show(io, mt::MethodTable)
name = mt.name
println(io, "Methods for generic function ", name)
d = mt.defs
while !is(d,())
print(io, name)
show(io, d)
d = d.next
if !is(d,())
println(io)
end
end
end

function dump(io, x)
T = typeof(x)
if isa(x,Array)
Expand Down
19 changes: 19 additions & 0 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ function function_loc(f::Function, types)
end
function_loc(f::Function) = function_loc(f, (Any...))

function whicht(f, types)
for m = getmethods(f, types)
if isa(m[3],LambdaStaticData)
lsd = m[3]::LambdaStaticData
d = f.env.defs
while !is(d,())
if is(d.func.code, lsd)
print(stdout_stream, f.env.name)
show(stdout_stream, d); println(stdout_stream)
return
end
d = d.next
end
end
end
end

which(f, args...) = whicht(f, map(a->(isa(a,Type) ? Type{a} : typeof(a)), args))

edit(file::String) = edit(file, 1)
function edit(file::String, line::Int)
editor = get(ENV, "JULIA_EDITOR", "emacs")
Expand Down
42 changes: 22 additions & 20 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2232,26 +2232,6 @@ void jl_init_types(void)
jl_sym_type->uid = jl_assign_type_uid();

// now they can be used to create the remaining base kinds and types
jl_method_type =
jl_new_struct_type(jl_symbol("Method"), jl_any_type, jl_null,
jl_tuple(6, jl_symbol("sig"), jl_symbol("va"),
jl_symbol("tvars"), jl_symbol("func"),
jl_symbol("invokes"), jl_symbol("next")),
jl_tuple(6, jl_tuple_type, jl_bool_type,
jl_tuple_type, jl_function_type,
jl_any_type, jl_any_type));
jl_method_type->fptr = jl_f_no_function;

jl_methtable_type =
jl_new_struct_type(jl_symbol("MethodTable"), jl_any_type, jl_null,
jl_tuple(6, jl_symbol("name"), jl_symbol("defs"),
jl_symbol("cache"), jl_symbol("cache_arg1"),
jl_symbol("cache_targ"),
jl_symbol("max_args")),
jl_tuple(6, jl_sym_type, jl_any_type, jl_any_type,
jl_any_type, jl_any_type, jl_long_type));
jl_methtable_type->fptr = jl_f_no_function;

jl_union_kind = jl_new_struct_type(jl_symbol("UnionKind"),
jl_type_type, jl_null,
jl_tuple(1, jl_symbol("types")),
Expand Down Expand Up @@ -2327,6 +2307,26 @@ void jl_init_types(void)
jl_false = jl_box8(jl_bool_type, 0);
jl_true = jl_box8(jl_bool_type, 1);

jl_method_type =
jl_new_struct_type(jl_symbol("Method"), jl_any_type, jl_null,
jl_tuple(6, jl_symbol("sig"), jl_symbol("va"),
jl_symbol("tvars"), jl_symbol("func"),
jl_symbol("invokes"), jl_symbol("next")),
jl_tuple(6, jl_tuple_type, jl_bool_type,
jl_tuple_type, jl_function_type,
jl_any_type, jl_any_type));
jl_method_type->fptr = jl_f_no_function;

jl_methtable_type =
jl_new_struct_type(jl_symbol("MethodTable"), jl_any_type, jl_null,
jl_tuple(6, jl_symbol("name"), jl_symbol("defs"),
jl_symbol("cache"), jl_symbol("cache_arg1"),
jl_symbol("cache_targ"),
jl_symbol("max_args")),
jl_tuple(6, jl_sym_type, jl_any_type, jl_any_type,
jl_any_type, jl_any_type, jl_long_type));
jl_methtable_type->fptr = jl_f_no_function;

tv = jl_tuple2(tvar("T"), tvar("N"));
jl_abstractarray_type = jl_new_tagtype((jl_value_t*)jl_symbol("AbstractArray"),
jl_any_type, tv);
Expand Down Expand Up @@ -2434,6 +2434,8 @@ void jl_init_types(void)
jl_lambda_info_type));
jl_function_type->fptr = jl_f_no_function;

jl_tupleset(jl_method_type->types, 3, jl_function_type);

jl_bottom_func = jl_new_closure(jl_f_no_function, JL_NULL, NULL);

jl_intrinsic_type = jl_new_bitstype((jl_value_t*)jl_symbol("IntrinsicFunction"),
Expand Down
1 change: 0 additions & 1 deletion src/julia.expmap
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@
jl_get_global;
jl_set_global;
jl_set_const;
jl_show_method_table;
jl_current_output_stream;
jl_apply_generic;
julia_init;
Expand Down
2 changes: 1 addition & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void *allocobj(size_t sz);
#endif

#define jl_tupleref(t,i) (((jl_value_t**)(t))[2+(i)])
#define jl_tupleset(t,i,x) ((((jl_value_t**)(t))[2+(i)])=(x))
#define jl_tupleset(t,i,x) ((((jl_value_t**)(t))[2+(i)])=(jl_value_t*)(x))
#define jl_t0(t) jl_tupleref(t,0)
#define jl_t1(t) jl_tupleref(t,1)

Expand Down

0 comments on commit 416f11f

Please sign in to comment.