Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc changes for REPL.jl #3229

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ function push!(a::Array{Any,1}, item::ANY)
return a
end

function append!{T}(a::Array{T,1}, items::Array{T,1})
function append!{T}(a::Array{T,1}, items::Vector)
if is(T,None)
error("[] cannot grow. Instead, initialize the array with \"T[]\".")
end
Expand Down
10 changes: 10 additions & 0 deletions base/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type IOBuffer <: IO
new(data,readable,writable,seekable,append,length(data),maxsize,1)
end

copy(b::IOBuffer) = (ret=IOBuffer(copy(b.data),b.readable,b.writable,b.seekable,b.append,b.maxsize);ret.size=b.size;ret.ptr = b.ptr;ret)

# PipeBuffers behave like Unix Pipes. They are readable and writable, the act appendable, and not seekable.
PipeBuffer(data::Vector{Uint8},maxsize::Int) = IOBuffer(data,true,true,false,true,maxsize)
PipeBuffer(data::Vector{Uint8}) = PipeBuffer(data,typemax(Int))
Expand Down Expand Up @@ -55,6 +57,14 @@ function read(from::IOBuffer, ::Type{Uint8})
return byte
end

function peek(from::IOBuffer)
if !from.readable error("read failed") end
if from.ptr > from.size
throw(EOFError())
end
return from.data[from.ptr]
end

read{T}(from::IOBuffer, ::Type{Ptr{T}}) = convert(Ptr{T}, read(from, Uint))

# TODO: IOBuffer is not iterable, so doesn't really have a length.
Expand Down
4 changes: 2 additions & 2 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ 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

names(m::Module, all::Bool) = ccall(:jl_module_names, Array{Symbol,1}, (Any,Int32), m, all)
names(m::Module) = names(m,false)
names(m::Module, all::Bool, imported::Bool) = ccall(:jl_module_names, Array{Symbol,1}, (Any,Int32,Int32), m, all, imported)
names(m::Module) = names(m,false,false)
names(t::DataType) = t.names

function names(v)
Expand Down
1 change: 1 addition & 0 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jl_typename_t *jl_array_typename;
jl_value_t *jl_array_uint8_type;
jl_value_t *jl_array_any_type=NULL;
jl_value_t *jl_array_symbol_type;
jl_value_t *jl_array_module_type;
jl_function_t *jl_bottom_func;
jl_datatype_t *jl_weakref_type;
jl_datatype_t *jl_ascii_string_type;
Expand Down
2 changes: 1 addition & 1 deletion src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ void jl_init_serializer(void)
jl_typename_type, jl_task_type, jl_uniontype_type,
jl_typetype_type, jl_typetype_tvar, jl_ANY_flag,
jl_array_any_type, jl_intrinsic_type, jl_method_type,
jl_methtable_type, jl_voidpointer_type,
jl_methtable_type, jl_voidpointer_type, jl_array_module_type,
jl_array_symbol_type, jl_tupleref(jl_tuple_type,0),

jl_symbol_type->name, jl_pointer_type->name,
Expand Down
5 changes: 5 additions & 0 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2645,6 +2645,11 @@ void jl_init_types(void)

jl_tupleset(jl_typename_type->types, 1, jl_module_type);

jl_array_module_type =
(jl_value_t*)jl_apply_type((jl_value_t*)jl_array_type,
jl_tuple(2, jl_module_type,
jl_box_long(1)));

jl_lambda_info_type =
jl_new_datatype(jl_symbol("LambdaStaticData"),
jl_any_type, jl_null,
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ extern jl_datatype_t *jl_pointer_type;
extern jl_value_t *jl_array_uint8_type;
extern jl_value_t *jl_array_any_type;
extern jl_value_t *jl_array_symbol_type;
extern jl_value_t *jl_array_module_type;
extern DLLEXPORT jl_datatype_t *jl_expr_type;
extern jl_datatype_t *jl_symbolnode_type;
extern jl_datatype_t *jl_getfieldnode_type;
Expand Down
17 changes: 15 additions & 2 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,20 @@ DLLEXPORT void jl_set_current_module(jl_value_t *m)
jl_current_module = (jl_module_t*)m;
}

DLLEXPORT jl_value_t *jl_module_names(jl_module_t *m, int all)
DLLEXPORT jl_value_t *jl_module_usings(jl_module_t *m)
{
jl_array_t *a = jl_alloc_array_1d(jl_array_module_type, 0);
JL_GC_PUSH1(&a);
for(int i=(int)m->usings.len-1; i >= 0; --i) {
jl_array_grow_end(a, 1);
jl_module_t *imp = (jl_module_t*)m->usings.items[i];
jl_cellset(a,jl_array_dim0(a)-1, (jl_value_t*)imp);
}
JL_GC_POP();
return (jl_value_t*)a;
}

DLLEXPORT jl_value_t *jl_module_names(jl_module_t *m, int all, int imported)
{
jl_array_t *a = jl_alloc_array_1d(jl_array_symbol_type, 0);
JL_GC_PUSH1(&a);
Expand All @@ -385,7 +398,7 @@ DLLEXPORT jl_value_t *jl_module_names(jl_module_t *m, int all)
for(i=1; i < m->bindings.size; i+=2) {
if (table[i] != HT_NOTFOUND) {
jl_binding_t *b = (jl_binding_t*)table[i];
if (b->exportp || (b->owner == m && (all || m == jl_main_module))) {
if (b->exportp || ((imported || b->owner == m) && (all || m == jl_main_module))) {
jl_array_grow_end(a, 1);
//XXX: change to jl_arrayset if array storage allocation for Array{Symbols,1} changes:
jl_cellset(a, jl_array_dim0(a)-1, (jl_value_t*)b->name);
Expand Down