Skip to content

Commit

Permalink
Merge pull request #4042 from JuliaLang/kf/tuples
Browse files Browse the repository at this point in the history
Tuples made me sad (so I fixed them)
  • Loading branch information
JeffBezanson committed Dec 7, 2013
2 parents d952dae + d5ad8e6 commit 3db073d
Show file tree
Hide file tree
Showing 9 changed files with 873 additions and 304 deletions.
2 changes: 1 addition & 1 deletion base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ function inlining_pass(e::Expr, sv, ast)
end

function add_variable(ast, name, typ)
vinf = {name,typ,2}
vinf = {name,typ,18}
locllist = ast.args[2][1]::Array{Any,1}
vinflist = ast.args[2][2]::Array{Any,1}
push!(locllist, name)
Expand Down
8 changes: 4 additions & 4 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ done(mt::MethodTable, i::()) = true
uncompressed_ast(l::LambdaStaticData) =
isa(l.ast,Expr) ? l.ast : ccall(:jl_uncompress_ast, Any, (Any,Any), l, l.ast)

function _dump_function(f, t::ANY, native)
str = ccall(:jl_dump_function, Any, (Any,Any,Bool), f, t, native)::ByteString
function _dump_function(f, t::ANY, native, wrapper)
str = ccall(:jl_dump_function, Any, (Any,Any,Bool,Bool), f, t, native, wrapper)::ByteString
if str == ""
error("no method found for the specified argument types")
end
str
end

code_llvm (f::Callable, types::Tuple) = print(_dump_function(f, types, false))
code_native(f::Callable, types::Tuple) = print(_dump_function(f, types, true))
code_llvm (f::Callable, types::Tuple) = print(_dump_function(f, types, false, false))
code_native(f::Callable, types::Tuple) = print(_dump_function(f, types, true, false))

function functionlocs(f::Function, types=(Any...))
locs = Any[]
Expand Down
2 changes: 1 addition & 1 deletion src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ value_t fl_invoke_julia_macro(value_t *args, uint32_t nargs)
int i;
for(i=0; i < nargs; i++) margs[i] = NULL;
for(i=1; i < nargs; i++) margs[i] = scm_to_julia(args[i], 1);
jl_value_t *result=NULL;
jl_value_t *result = NULL;

JL_TRY {
margs[0] = scm_to_julia(args[0], 1);
Expand Down
19 changes: 10 additions & 9 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static Value *julia_to_native(Type *ty, jl_value_t *jt, Value *jv,
{
Type *vt = jv->getType();
if (ty == jl_pvalue_llvmt) {
return boxed(jv);
return boxed(jv,ctx);
}
else if (ty == vt && !addressOf) {
return jv;
Expand All @@ -272,7 +272,7 @@ static Value *julia_to_native(Type *ty, jl_value_t *jt, Value *jv,
}
}
// error. box for error handling.
jv = boxed(jv);
jv = boxed(jv,ctx);
}
else if (jl_is_cpointer_type(jt)) {
assert(ty->isPointerTy());
Expand Down Expand Up @@ -317,6 +317,8 @@ static Value *julia_to_native(Type *ty, jl_value_t *jt, Value *jv,
// //safe thing would be to also check that jl_typeof(aty)->size > sizeof(ty) here and/or at runtime
Value *pjv = builder.CreateBitCast(emit_nthptr_addr(jv, (size_t)1), PointerType::get(ty,0));
return builder.CreateLoad(pjv, false);
} else if (jl_is_tuple(jt)) {
return emit_unbox(ty,jv,jt);
}
// TODO: error for & with non-pointer argument type
assert(jl_is_bitstype(jt));
Expand Down Expand Up @@ -356,7 +358,7 @@ static native_sym_arg_t interpret_symbol_arg(jl_value_t *arg, jl_codectx_t *ctx,
"cglobal: first argument not a pointer or valid constant expression",
ctx);
}
jl_ptr = emit_unbox(T_size, T_psize, arg1);
jl_ptr = emit_unbox(T_size, arg1, ptr_ty);
}

void *fptr=NULL;
Expand Down Expand Up @@ -673,7 +675,7 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
addressOf = true;
argi = jl_exprarg(argi,0);
}
Value *ary = boxed(emit_expr(argi, ctx));
Value *ary = boxed(emit_expr(argi, ctx),ctx);
JL_GC_POP();
return mark_julia_type(
builder.CreateBitCast(emit_nthptr_addr(ary, addressOf?1:0),lrt),
Expand Down Expand Up @@ -793,23 +795,22 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
if (largty == jl_pvalue_llvmt || largty->isStructTy()) {
arg = emit_expr(argi, ctx, true);
if (largty == jl_pvalue_llvmt && arg->getType() != jl_pvalue_llvmt) {
arg = boxed(arg);
arg = boxed(arg,ctx);
needroot = true;
}
}
}
else {
arg = emit_unboxed(argi, ctx);
if (jl_is_bitstype(expr_type(argi, ctx))) {
Type *totype = addressOf ? largty->getContainedType(0) : largty;
Type *ptype = addressOf ? largty : PointerType::get(largty,0);
Type *at = arg->getType();
Type *totype = addressOf ? largty->getContainedType(0) : largty;
if (at != jl_pvalue_llvmt && at != totype &&
!(at->isPointerTy() && jargty==(jl_value_t*)jl_voidpointer_type)) {
emit_type_error(arg, jargty, "ccall", ctx);
arg = UndefValue::get(totype);
}
else {
arg = emit_unbox(totype, ptype, arg);
arg = emit_unbox(totype, arg, jargty);
}
}
}
Expand Down
Loading

0 comments on commit 3db073d

Please sign in to comment.