mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 14:31:55 +00:00
Add [X].len() to core, use it in trans modules
This commit is contained in:
parent
f3dba33043
commit
f2e880b750
@ -106,7 +106,7 @@ fn expand_nested_bindings(m: match, col: uint, val: ValueRef) -> match {
|
|||||||
alt br.pats[col].node {
|
alt br.pats[col].node {
|
||||||
ast::pat_ident(name, some(inner)) {
|
ast::pat_ident(name, some(inner)) {
|
||||||
let pats = vec::slice(br.pats, 0u, col) + [inner] +
|
let pats = vec::slice(br.pats, 0u, col) + [inner] +
|
||||||
vec::slice(br.pats, col + 1u, vec::len(br.pats));
|
vec::slice(br.pats, col + 1u, br.pats.len());
|
||||||
result += [@{pats: pats,
|
result += [@{pats: pats,
|
||||||
bound: br.bound + [{ident: path_to_ident(name),
|
bound: br.bound + [{ident: path_to_ident(name),
|
||||||
val: val}]
|
val: val}]
|
||||||
@ -126,7 +126,7 @@ fn enter_match(m: match, col: uint, val: ValueRef, e: enter_pat) -> match {
|
|||||||
alt e(br.pats[col]) {
|
alt e(br.pats[col]) {
|
||||||
some(sub) {
|
some(sub) {
|
||||||
let pats = sub + vec::slice(br.pats, 0u, col) +
|
let pats = sub + vec::slice(br.pats, 0u, col) +
|
||||||
vec::slice(br.pats, col + 1u, vec::len(br.pats));
|
vec::slice(br.pats, col + 1u, br.pats.len());
|
||||||
let new_br = @{pats: pats,
|
let new_br = @{pats: pats,
|
||||||
bound: alt br.pats[col].node {
|
bound: alt br.pats[col].node {
|
||||||
ast::pat_ident(name, none) {
|
ast::pat_ident(name, none) {
|
||||||
@ -197,7 +197,7 @@ fn enter_rec(m: match, col: uint, fields: [ast::ident], val: ValueRef) ->
|
|||||||
}
|
}
|
||||||
ret some(pats);
|
ret some(pats);
|
||||||
}
|
}
|
||||||
_ { ret some(vec::init_elt(vec::len(fields), dummy)); }
|
_ { ret some(vec::init_elt(fields.len(), dummy)); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret enter_match(m, col, val, bind e(dummy, fields, _));
|
ret enter_match(m, col, val, bind e(dummy, fields, _));
|
||||||
@ -269,9 +269,9 @@ fn extract_variant_args(bcx: @block_ctxt, pat_id: ast::node_id,
|
|||||||
let blobptr = val;
|
let blobptr = val;
|
||||||
let variants = ty::enum_variants(ccx.tcx, vdefs.enm);
|
let variants = ty::enum_variants(ccx.tcx, vdefs.enm);
|
||||||
let args = [];
|
let args = [];
|
||||||
let size =
|
let size = ty::enum_variant_with_id(ccx.tcx, vdefs.enm,
|
||||||
vec::len(ty::enum_variant_with_id(ccx.tcx, vdefs.enm, vdefs.var).args);
|
vdefs.var).args.len();
|
||||||
if size > 0u && vec::len(*variants) != 1u {
|
if size > 0u && (*variants).len() != 1u {
|
||||||
let enumptr =
|
let enumptr =
|
||||||
PointerCast(bcx, val, T_opaque_enum_ptr(ccx));
|
PointerCast(bcx, val, T_opaque_enum_ptr(ccx));
|
||||||
blobptr = GEPi(bcx, enumptr, [0, 1]);
|
blobptr = GEPi(bcx, enumptr, [0, 1]);
|
||||||
@ -343,7 +343,7 @@ fn pick_col(m: match) -> uint {
|
|||||||
_ { 0u }
|
_ { 0u }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let scores = vec::init_elt_mut(vec::len(m[0].pats), 0u);
|
let scores = vec::init_elt_mut(m[0].pats.len(), 0u);
|
||||||
for br: match_branch in m {
|
for br: match_branch in m {
|
||||||
let i = 0u;
|
let i = 0u;
|
||||||
for p: @ast::pat in br.pats { scores[i] += score(p); i += 1u; }
|
for p: @ast::pat in br.pats { scores[i] += score(p); i += 1u; }
|
||||||
@ -366,8 +366,8 @@ fn pick_col(m: match) -> uint {
|
|||||||
fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
|
fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
|
||||||
&exits: [exit_node]) {
|
&exits: [exit_node]) {
|
||||||
let bcx = bcx;
|
let bcx = bcx;
|
||||||
if vec::len(m) == 0u { Br(bcx, f()); ret; }
|
if m.len() == 0u { Br(bcx, f()); ret; }
|
||||||
if vec::len(m[0].pats) == 0u {
|
if m[0].pats.len() == 0u {
|
||||||
let data = m[0].data;
|
let data = m[0].data;
|
||||||
alt data.guard {
|
alt data.guard {
|
||||||
some(e) {
|
some(e) {
|
||||||
@ -385,7 +385,7 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
|
|||||||
let next_cx = new_sub_block_ctxt(guard_cx, "submatch_next");
|
let next_cx = new_sub_block_ctxt(guard_cx, "submatch_next");
|
||||||
let else_cx = new_sub_block_ctxt(guard_cx, "submatch_else");
|
let else_cx = new_sub_block_ctxt(guard_cx, "submatch_else");
|
||||||
CondBr(guard_bcx, guard_val, next_cx.llbb, else_cx.llbb);
|
CondBr(guard_bcx, guard_val, next_cx.llbb, else_cx.llbb);
|
||||||
compile_submatch(else_cx, vec::slice(m, 1u, vec::len(m)), vals, f,
|
compile_submatch(else_cx, vec::slice(m, 1u, m.len()), vals, f,
|
||||||
exits);
|
exits);
|
||||||
bcx = next_cx;
|
bcx = next_cx;
|
||||||
}
|
}
|
||||||
@ -408,7 +408,7 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
|
|||||||
|
|
||||||
let vals_left =
|
let vals_left =
|
||||||
vec::slice(vals, 0u, col) +
|
vec::slice(vals, 0u, col) +
|
||||||
vec::slice(vals, col + 1u, vec::len(vals));
|
vec::slice(vals, col + 1u, vals.len());
|
||||||
let ccx = bcx.fcx.ccx;
|
let ccx = bcx.fcx.ccx;
|
||||||
let pat_id = 0;
|
let pat_id = 0;
|
||||||
for br: match_branch in m {
|
for br: match_branch in m {
|
||||||
@ -419,7 +419,7 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
|
|||||||
|
|
||||||
let rec_fields = collect_record_fields(m, col);
|
let rec_fields = collect_record_fields(m, col);
|
||||||
// Separate path for extracting and binding record fields
|
// Separate path for extracting and binding record fields
|
||||||
if vec::len(rec_fields) > 0u {
|
if rec_fields.len() > 0u {
|
||||||
let rec_ty = node_id_type(bcx, pat_id);
|
let rec_ty = node_id_type(bcx, pat_id);
|
||||||
let fields = ty::get_fields(rec_ty);
|
let fields = ty::get_fields(rec_ty);
|
||||||
let rec_vals = [];
|
let rec_vals = [];
|
||||||
@ -437,7 +437,7 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
|
|||||||
if any_tup_pat(m, col) {
|
if any_tup_pat(m, col) {
|
||||||
let tup_ty = node_id_type(bcx, pat_id);
|
let tup_ty = node_id_type(bcx, pat_id);
|
||||||
let n_tup_elts = alt ty::get(tup_ty).struct {
|
let n_tup_elts = alt ty::get(tup_ty).struct {
|
||||||
ty::ty_tup(elts) { vec::len(elts) }
|
ty::ty_tup(elts) { elts.len() }
|
||||||
_ { ccx.sess.bug("Non-tuple type in tuple pattern"); }
|
_ { ccx.sess.bug("Non-tuple type in tuple pattern"); }
|
||||||
};
|
};
|
||||||
let tup_vals = [], i = 0u;
|
let tup_vals = [], i = 0u;
|
||||||
@ -473,10 +473,10 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
|
|||||||
enum branch_kind { no_branch, single, switch, compare, }
|
enum branch_kind { no_branch, single, switch, compare, }
|
||||||
let kind = no_branch;
|
let kind = no_branch;
|
||||||
let test_val = val;
|
let test_val = val;
|
||||||
if vec::len(opts) > 0u {
|
if opts.len() > 0u {
|
||||||
alt opts[0] {
|
alt opts[0] {
|
||||||
var(_, vdef) {
|
var(_, vdef) {
|
||||||
if vec::len(*ty::enum_variants(ccx.tcx, vdef.enm)) == 1u {
|
if (*ty::enum_variants(ccx.tcx, vdef.enm)).len() == 1u {
|
||||||
kind = single;
|
kind = single;
|
||||||
} else {
|
} else {
|
||||||
let enumptr =
|
let enumptr =
|
||||||
@ -511,7 +511,7 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
|
|||||||
};
|
};
|
||||||
let sw;
|
let sw;
|
||||||
if kind == switch {
|
if kind == switch {
|
||||||
sw = Switch(bcx, test_val, else_cx.llbb, vec::len(opts));
|
sw = Switch(bcx, test_val, else_cx.llbb, opts.len());
|
||||||
// FIXME This statement is purely here as a work-around for a bug that
|
// FIXME This statement is purely here as a work-around for a bug that
|
||||||
// I expect to be the same as issue #951. If I remove it, sw ends up
|
// I expect to be the same as issue #951. If I remove it, sw ends up
|
||||||
// holding a corrupted value (when the compiler is optimized).
|
// holding a corrupted value (when the compiler is optimized).
|
||||||
@ -573,7 +573,7 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
|
|||||||
alt opt {
|
alt opt {
|
||||||
var(_, vdef) {
|
var(_, vdef) {
|
||||||
let args = extract_variant_args(opt_cx, pat_id, vdef, val);
|
let args = extract_variant_args(opt_cx, pat_id, vdef, val);
|
||||||
size = vec::len(args.vals);
|
size = args.vals.len();
|
||||||
unpacked = args.vals;
|
unpacked = args.vals;
|
||||||
opt_cx = args.bcx;
|
opt_cx = args.bcx;
|
||||||
}
|
}
|
||||||
@ -607,7 +607,7 @@ fn make_phi_bindings(bcx: @block_ctxt, map: [exit_node],
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if vec::len(vals) > 0u {
|
if vals.len() > 0u {
|
||||||
let local = Phi(bcx, val_ty(vals[0]), vals, llbbs);
|
let local = Phi(bcx, val_ty(vals[0]), vals, llbbs);
|
||||||
bcx.fcx.lllocals.insert(node_id, local_mem(local));
|
bcx.fcx.lllocals.insert(node_id, local_mem(local));
|
||||||
} else { success = false; }
|
} else { success = false; }
|
||||||
@ -728,7 +728,7 @@ fn bind_irrefutable_pat(bcx: @block_ctxt, pat: @ast::pat, val: ValueRef,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::pat_enum(_, sub) {
|
ast::pat_enum(_, sub) {
|
||||||
if vec::len(sub) == 0u { ret bcx; }
|
if sub.len() == 0u { ret bcx; }
|
||||||
let vdefs = ast_util::variant_def_ids(ccx.tcx.def_map.get(pat.id));
|
let vdefs = ast_util::variant_def_ids(ccx.tcx.def_map.get(pat.id));
|
||||||
let args = extract_variant_args(bcx, pat.id, vdefs, val);
|
let args = extract_variant_args(bcx, pat.id, vdefs, val);
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
@ -162,7 +162,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
|
|||||||
|
|
||||||
fn type_of_enum(cx: @crate_ctxt, did: ast::def_id, t: ty::t)
|
fn type_of_enum(cx: @crate_ctxt, did: ast::def_id, t: ty::t)
|
||||||
-> TypeRef {
|
-> TypeRef {
|
||||||
let degen = vec::len(*ty::enum_variants(cx.tcx, did)) == 1u;
|
let degen = (*ty::enum_variants(cx.tcx, did)).len() == 1u;
|
||||||
if check type_has_static_size(cx, t) {
|
if check type_has_static_size(cx, t) {
|
||||||
let size = static_size_of_enum(cx, t);
|
let size = static_size_of_enum(cx, t);
|
||||||
if !degen { T_enum(cx, size) }
|
if !degen { T_enum(cx, size) }
|
||||||
@ -289,7 +289,7 @@ fn get_simple_extern_fn(cx: @block_ctxt,
|
|||||||
fn trans_native_call(cx: @block_ctxt, externs: hashmap<str, ValueRef>,
|
fn trans_native_call(cx: @block_ctxt, externs: hashmap<str, ValueRef>,
|
||||||
llmod: ModuleRef, name: str, args: [ValueRef]) ->
|
llmod: ModuleRef, name: str, args: [ValueRef]) ->
|
||||||
ValueRef {
|
ValueRef {
|
||||||
let n: int = vec::len::<ValueRef>(args) as int;
|
let n = args.len() as int;
|
||||||
let llnative: ValueRef =
|
let llnative: ValueRef =
|
||||||
get_simple_extern_fn(cx, externs, llmod, name, n);
|
get_simple_extern_fn(cx, externs, llmod, name, n);
|
||||||
let call_args: [ValueRef] = [];
|
let call_args: [ValueRef] = [];
|
||||||
@ -388,7 +388,7 @@ fn GEP_tup_like(bcx: @block_ctxt, t: ty::t, base: ValueRef, ixs: [int])
|
|||||||
t: ty::t,
|
t: ty::t,
|
||||||
ixs: [int],
|
ixs: [int],
|
||||||
n: uint) -> (@block_ctxt, ValueRef, ty::t) {
|
n: uint) -> (@block_ctxt, ValueRef, ty::t) {
|
||||||
if n == vec::len(ixs) {
|
if n == ixs.len() {
|
||||||
ret (bcx, off, t);
|
ret (bcx, off, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,8 +638,8 @@ fn get_derived_tydesc(cx: @block_ctxt, t: ty::t, escapes: bool,
|
|||||||
// promising to do so itself.
|
// promising to do so itself.
|
||||||
let n_params = ty::count_ty_params(bcx_tcx(bcx), t);
|
let n_params = ty::count_ty_params(bcx_tcx(bcx), t);
|
||||||
|
|
||||||
assert (n_params == vec::len::<uint>(tys.params));
|
assert n_params == tys.params.len();
|
||||||
assert (n_params == vec::len::<ValueRef>(tys.descs));
|
assert n_params == tys.descs.len();
|
||||||
|
|
||||||
let llparamtydescs =
|
let llparamtydescs =
|
||||||
alloca(bcx, T_array(T_ptr(bcx_ccx(bcx).tydesc_type), n_params + 1u));
|
alloca(bcx, T_array(T_ptr(bcx_ccx(bcx).tydesc_type), n_params + 1u));
|
||||||
@ -687,7 +687,7 @@ fn get_tydesc(cx: @block_ctxt, t: ty::t, escapes: bool,
|
|||||||
// Is the supplied type a type param? If so, return the passed-in tydesc.
|
// Is the supplied type a type param? If so, return the passed-in tydesc.
|
||||||
alt ty::type_param(t) {
|
alt ty::type_param(t) {
|
||||||
some(id) {
|
some(id) {
|
||||||
if id < vec::len(cx.fcx.lltyparams) {
|
if id < cx.fcx.lltyparams.len() {
|
||||||
ret {kind: tk_param,
|
ret {kind: tk_param,
|
||||||
result: rslt(cx, cx.fcx.lltyparams[id].desc)};
|
result: rslt(cx, cx.fcx.lltyparams[id].desc)};
|
||||||
} else {
|
} else {
|
||||||
@ -821,7 +821,7 @@ fn make_generic_glue_inner(ccx: @crate_ctxt, t: ty::t,
|
|||||||
T_ptr(type_of(ccx, t))
|
T_ptr(type_of(ccx, t))
|
||||||
} else { T_ptr(T_i8()) };
|
} else { T_ptr(T_i8()) };
|
||||||
|
|
||||||
let ty_param_count = vec::len(ty_params);
|
let ty_param_count = ty_params.len();
|
||||||
let lltyparams = llvm::LLVMGetParam(llfn, 2u as c_uint);
|
let lltyparams = llvm::LLVMGetParam(llfn, 2u as c_uint);
|
||||||
let load_env_bcx = new_raw_block_ctxt(fcx, fcx.llloadenv);
|
let load_env_bcx = new_raw_block_ctxt(fcx, fcx.llloadenv);
|
||||||
let lltydescs = [mutable];
|
let lltydescs = [mutable];
|
||||||
@ -1072,7 +1072,7 @@ fn trans_res_drop(cx: @block_ctxt, rs: ValueRef, did: ast::def_id,
|
|||||||
// for type variables.
|
// for type variables.
|
||||||
let val_llty = lib::llvm::fn_ty_param_tys
|
let val_llty = lib::llvm::fn_ty_param_tys
|
||||||
(llvm::LLVMGetElementType
|
(llvm::LLVMGetElementType
|
||||||
(llvm::LLVMTypeOf(dtor_addr)))[vec::len(args)];
|
(llvm::LLVMTypeOf(dtor_addr)))[args.len()];
|
||||||
let val_cast = BitCast(cx, val.val, val_llty);
|
let val_cast = BitCast(cx, val.val, val_llty);
|
||||||
Call(cx, dtor_addr, args + [val_cast]);
|
Call(cx, dtor_addr, args + [val_cast]);
|
||||||
|
|
||||||
@ -1244,7 +1244,7 @@ fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t,
|
|||||||
fn iter_variant(cx: @block_ctxt, a_tup: ValueRef,
|
fn iter_variant(cx: @block_ctxt, a_tup: ValueRef,
|
||||||
variant: ty::variant_info, tps: [ty::t], tid: ast::def_id,
|
variant: ty::variant_info, tps: [ty::t], tid: ast::def_id,
|
||||||
f: val_and_ty_fn) -> @block_ctxt {
|
f: val_and_ty_fn) -> @block_ctxt {
|
||||||
if vec::len::<ty::t>(variant.args) == 0u { ret cx; }
|
if variant.args.len() == 0u { ret cx; }
|
||||||
let fn_ty = variant.ctor_ty;
|
let fn_ty = variant.ctor_ty;
|
||||||
let ccx = bcx_ccx(cx);
|
let ccx = bcx_ccx(cx);
|
||||||
let cx = cx;
|
let cx = cx;
|
||||||
@ -1299,7 +1299,7 @@ fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t,
|
|||||||
}
|
}
|
||||||
ty::ty_enum(tid, tps) {
|
ty::ty_enum(tid, tps) {
|
||||||
let variants = ty::enum_variants(bcx_tcx(cx), tid);
|
let variants = ty::enum_variants(bcx_tcx(cx), tid);
|
||||||
let n_variants = vec::len(*variants);
|
let n_variants = (*variants).len();
|
||||||
|
|
||||||
// Cast the enums to types we can GEP into.
|
// Cast the enums to types we can GEP into.
|
||||||
if n_variants == 1u {
|
if n_variants == 1u {
|
||||||
@ -1912,8 +1912,7 @@ fn autoderef(cx: @block_ctxt, v: ValueRef, t: ty::t) -> result_t {
|
|||||||
}
|
}
|
||||||
ty::ty_enum(did, tps) {
|
ty::ty_enum(did, tps) {
|
||||||
let variants = ty::enum_variants(ccx.tcx, did);
|
let variants = ty::enum_variants(ccx.tcx, did);
|
||||||
if vec::len(*variants) != 1u ||
|
if (*variants).len() != 1u || variants[0].args.len() != 1u {
|
||||||
vec::len(variants[0].args) != 1u {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
t1 =
|
t1 =
|
||||||
@ -2278,7 +2277,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
|
|||||||
let this_tv = option::get(vec::find(*tvs, {|tv|
|
let this_tv = option::get(vec::find(*tvs, {|tv|
|
||||||
tv.id.node == fn_id.node}));
|
tv.id.node == fn_id.node}));
|
||||||
trans_enum_variant(ccx, enum_id.node, v, this_tv.disr_val,
|
trans_enum_variant(ccx, enum_id.node, v, this_tv.disr_val,
|
||||||
vec::len(*tvs) == 1u, [], psubsts, lldecl);
|
(*tvs).len() == 1u, [], psubsts, lldecl);
|
||||||
}
|
}
|
||||||
ast_map::node_method(mth, impl_id, _) {
|
ast_map::node_method(mth, impl_id, _) {
|
||||||
let selfty = ty::node_id_to_type(ccx.tcx, impl_id);
|
let selfty = ty::node_id_to_type(ccx.tcx, impl_id);
|
||||||
@ -2301,12 +2300,12 @@ fn lval_static_fn(bcx: @block_ctxt, fn_id: ast::def_id, id: ast::node_id,
|
|||||||
// monomorphized and non-monomorphized functions at the moment. If
|
// monomorphized and non-monomorphized functions at the moment. If
|
||||||
// monomorphizing becomes the only approach, this'll be much simpler.
|
// monomorphizing becomes the only approach, this'll be much simpler.
|
||||||
if ccx.sess.opts.monomorphize &&
|
if ccx.sess.opts.monomorphize &&
|
||||||
(option::is_some(substs) || vec::len(tys) > 0u) &&
|
(option::is_some(substs) || tys.len() > 0u) &&
|
||||||
fn_id.crate == ast::local_crate &&
|
fn_id.crate == ast::local_crate &&
|
||||||
!vec::any(tys, {|t| ty::type_has_params(t)}) {
|
!vec::any(tys, {|t| ty::type_has_params(t)}) {
|
||||||
let mono = alt substs {
|
let mono = alt substs {
|
||||||
some((stys, dicts)) {
|
some((stys, dicts)) {
|
||||||
if (vec::len(stys) + vec::len(tys)) > 0u {
|
if (stys.len() + tys.len()) > 0u {
|
||||||
monomorphic_fn(ccx, fn_id, stys + tys, some(dicts))
|
monomorphic_fn(ccx, fn_id, stys + tys, some(dicts))
|
||||||
} else { none }
|
} else { none }
|
||||||
}
|
}
|
||||||
@ -2340,7 +2339,7 @@ fn lval_static_fn(bcx: @block_ctxt, fn_id: ast::def_id, id: ast::node_id,
|
|||||||
trans_external_path(bcx, fn_id, tpt)
|
trans_external_path(bcx, fn_id, tpt)
|
||||||
};
|
};
|
||||||
let gen = generic_none, bcx = bcx;
|
let gen = generic_none, bcx = bcx;
|
||||||
if vec::len(tys) > 0u {
|
if tys.len() > 0u {
|
||||||
let tydescs = [], tis = [];
|
let tydescs = [], tis = [];
|
||||||
for t in tys {
|
for t in tys {
|
||||||
// TODO: Doesn't always escape.
|
// TODO: Doesn't always escape.
|
||||||
@ -2424,7 +2423,7 @@ fn trans_var(cx: @block_ctxt, def: ast::def, id: ast::node_id)
|
|||||||
ret lval_static_fn(cx, did, id, none);
|
ret lval_static_fn(cx, did, id, none);
|
||||||
}
|
}
|
||||||
ast::def_variant(tid, vid) {
|
ast::def_variant(tid, vid) {
|
||||||
if vec::len(ty::enum_variant_with_id(ccx.tcx, tid, vid).args) > 0u {
|
if ty::enum_variant_with_id(ccx.tcx, tid, vid).args.len() > 0u {
|
||||||
// N-ary variant.
|
// N-ary variant.
|
||||||
ret lval_static_fn(cx, vid, id, none);
|
ret lval_static_fn(cx, vid, id, none);
|
||||||
} else {
|
} else {
|
||||||
@ -2616,7 +2615,7 @@ fn maybe_add_env(bcx: @block_ctxt, c: lval_maybe_callee)
|
|||||||
fn lval_maybe_callee_to_lval(c: lval_maybe_callee, ty: ty::t) -> lval_result {
|
fn lval_maybe_callee_to_lval(c: lval_maybe_callee, ty: ty::t) -> lval_result {
|
||||||
alt c.generic {
|
alt c.generic {
|
||||||
generic_full(gi) {
|
generic_full(gi) {
|
||||||
let n_args = vec::len(ty::ty_fn_args(ty));
|
let n_args = ty::ty_fn_args(ty).len();
|
||||||
let args = vec::init_elt(n_args, none::<@ast::expr>);
|
let args = vec::init_elt(n_args, none::<@ast::expr>);
|
||||||
let space = alloc_ty(c.bcx, ty);
|
let space = alloc_ty(c.bcx, ty);
|
||||||
let bcx = closure::trans_bind_1(space.bcx, ty, c, args, ty,
|
let bcx = closure::trans_bind_1(space.bcx, ty, c, args, ty,
|
||||||
@ -3877,10 +3876,8 @@ fn new_raw_block_ctxt(fcx: @fn_ctxt, llbb: BasicBlockRef) -> @block_ctxt {
|
|||||||
fn trans_block_cleanups(bcx: @block_ctxt, cleanup_cx: @block_ctxt) ->
|
fn trans_block_cleanups(bcx: @block_ctxt, cleanup_cx: @block_ctxt) ->
|
||||||
@block_ctxt {
|
@block_ctxt {
|
||||||
if bcx.unreachable { ret bcx; }
|
if bcx.unreachable { ret bcx; }
|
||||||
if cleanup_cx.kind == NON_SCOPE_BLOCK {
|
let i = cleanup_cx.cleanups.len(), bcx = bcx;
|
||||||
assert (vec::len::<cleanup>(cleanup_cx.cleanups) == 0u);
|
if cleanup_cx.kind == NON_SCOPE_BLOCK { assert i == 0u; }
|
||||||
}
|
|
||||||
let i = vec::len::<cleanup>(cleanup_cx.cleanups), bcx = bcx;
|
|
||||||
while i > 0u {
|
while i > 0u {
|
||||||
i -= 1u;
|
i -= 1u;
|
||||||
let c = cleanup_cx.cleanups[i];
|
let c = cleanup_cx.cleanups[i];
|
||||||
@ -4535,7 +4532,7 @@ fn trans_native_mod(ccx: @crate_ctxt,
|
|||||||
let bcx = new_top_block_ctxt(fcx, none);
|
let bcx = new_top_block_ctxt(fcx, none);
|
||||||
let lltop = bcx.llbb;
|
let lltop = bcx.llbb;
|
||||||
let llargbundle = llvm::LLVMGetParam(llshimfn, 0 as c_uint);
|
let llargbundle = llvm::LLVMGetParam(llshimfn, 0 as c_uint);
|
||||||
let i = 0u, n = vec::len(tys.arg_tys);
|
let i = 0u, n = tys.arg_tys.len();
|
||||||
let llargvals = [];
|
let llargvals = [];
|
||||||
while i < n {
|
while i < n {
|
||||||
let llargval = load_inbounds(bcx, llargbundle, [0, i as int]);
|
let llargval = load_inbounds(bcx, llargbundle, [0, i as int]);
|
||||||
@ -4573,7 +4570,7 @@ fn trans_native_mod(ccx: @crate_ctxt,
|
|||||||
|
|
||||||
// Allocate the struct and write the arguments into it.
|
// Allocate the struct and write the arguments into it.
|
||||||
let llargbundle = alloca(bcx, tys.bundle_ty);
|
let llargbundle = alloca(bcx, tys.bundle_ty);
|
||||||
let i = 0u, n = vec::len(tys.arg_tys);
|
let i = 0u, n = tys.arg_tys.len();
|
||||||
let implicit_args = 2u + num_tps; // ret + env
|
let implicit_args = 2u + num_tps; // ret + env
|
||||||
while i < n {
|
while i < n {
|
||||||
let llargval = llvm::LLVMGetParam(llwrapfn,
|
let llargval = llvm::LLVMGetParam(llwrapfn,
|
||||||
@ -4608,7 +4605,7 @@ fn trans_native_mod(ccx: @crate_ctxt,
|
|||||||
alt ccx.item_ids.find(id) {
|
alt ccx.item_ids.find(id) {
|
||||||
some(llwrapfn) {
|
some(llwrapfn) {
|
||||||
let llshimfn = build_shim_fn(ccx, native_item, tys, cc);
|
let llshimfn = build_shim_fn(ccx, native_item, tys, cc);
|
||||||
build_wrap_fn(ccx, tys, vec::len(tps), llshimfn, llwrapfn);
|
build_wrap_fn(ccx, tys, tps.len(), llshimfn, llwrapfn);
|
||||||
}
|
}
|
||||||
none {
|
none {
|
||||||
ccx.sess.span_fatal(
|
ccx.sess.span_fatal(
|
||||||
@ -4661,11 +4658,11 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
|
|||||||
trans_mod(ccx, m);
|
trans_mod(ccx, m);
|
||||||
}
|
}
|
||||||
ast::item_enum(variants, tps) {
|
ast::item_enum(variants, tps) {
|
||||||
let degen = vec::len(variants) == 1u;
|
let degen = variants.len() == 1u;
|
||||||
let vi = ty::enum_variants(ccx.tcx, local_def(item.id));
|
let vi = ty::enum_variants(ccx.tcx, local_def(item.id));
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for variant: ast::variant in variants {
|
for variant: ast::variant in variants {
|
||||||
if vec::len(variant.node.args) > 0u {
|
if variant.node.args.len() > 0u {
|
||||||
trans_enum_variant(ccx, item.id, variant,
|
trans_enum_variant(ccx, item.id, variant,
|
||||||
vi[i].disr_val, degen, tps,
|
vi[i].disr_val, degen, tps,
|
||||||
none, ccx.item_ids.get(variant.node.id));
|
none, ccx.item_ids.get(variant.node.id));
|
||||||
@ -4737,7 +4734,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
|
|||||||
let main_takes_argv =
|
let main_takes_argv =
|
||||||
// invariant!
|
// invariant!
|
||||||
alt ty::get(main_node_type).struct {
|
alt ty::get(main_node_type).struct {
|
||||||
ty::ty_fn({inputs, _}) { vec::len(inputs) != 0u }
|
ty::ty_fn({inputs, _}) { inputs.len() != 0u }
|
||||||
_ { ccx.sess.span_fatal(sp, "main has a non-function type"); }
|
_ { ccx.sess.span_fatal(sp, "main has a non-function type"); }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -4800,7 +4797,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
|
|||||||
llvm::LLVMGetParam(llfn, 1 as c_uint), crate_map];
|
llvm::LLVMGetParam(llfn, 1 as c_uint), crate_map];
|
||||||
let result = unsafe {
|
let result = unsafe {
|
||||||
llvm::LLVMBuildCall(bld, start, vec::to_ptr(args),
|
llvm::LLVMBuildCall(bld, start, vec::to_ptr(args),
|
||||||
vec::len(args) as c_uint, noname())
|
args.len() as c_uint, noname())
|
||||||
};
|
};
|
||||||
llvm::LLVMBuildRet(bld, result);
|
llvm::LLVMBuildRet(bld, result);
|
||||||
}
|
}
|
||||||
@ -4938,7 +4935,7 @@ fn collect_item(ccx: @crate_ctxt, abi: @mutable option<ast::native_abi>,
|
|||||||
}
|
}
|
||||||
ast::item_enum(variants, tps) {
|
ast::item_enum(variants, tps) {
|
||||||
for variant in variants {
|
for variant in variants {
|
||||||
if vec::len(variant.node.args) != 0u {
|
if variant.node.args.len() != 0u {
|
||||||
register_fn(ccx, i.span,
|
register_fn(ccx, i.span,
|
||||||
my_path + [path_name(variant.node.name)],
|
my_path + [path_name(variant.node.name)],
|
||||||
"enum", tps, variant.node.id);
|
"enum", tps, variant.node.id);
|
||||||
|
@ -43,7 +43,7 @@ fn AggregateRet(cx: @block_ctxt, RetVals: [ValueRef]) {
|
|||||||
cx.terminated = true;
|
cx.terminated = true;
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMBuildAggregateRet(B(cx), vec::to_ptr(RetVals),
|
llvm::LLVMBuildAggregateRet(B(cx), vec::to_ptr(RetVals),
|
||||||
vec::len(RetVals) as c_uint);
|
RetVals.len() as c_uint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ fn Invoke(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef],
|
|||||||
", ")];
|
", ")];
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
|
llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
|
||||||
vec::len(Args) as c_uint, Then, Catch,
|
Args.len() as c_uint, Then, Catch,
|
||||||
noname());
|
noname());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ fn FastInvoke(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef],
|
|||||||
cx.terminated = true;
|
cx.terminated = true;
|
||||||
unsafe {
|
unsafe {
|
||||||
let v = llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
|
let v = llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
|
||||||
vec::len(Args) as c_uint,
|
Args.len() as c_uint,
|
||||||
Then, Catch, noname());
|
Then, Catch, noname());
|
||||||
lib::llvm::SetInstructionCallConv(v, lib::llvm::FastCallConv);
|
lib::llvm::SetInstructionCallConv(v, lib::llvm::FastCallConv);
|
||||||
}
|
}
|
||||||
@ -330,7 +330,7 @@ fn GEP(cx: @block_ctxt, Pointer: ValueRef, Indices: [ValueRef]) -> ValueRef {
|
|||||||
if cx.unreachable { ret llvm::LLVMGetUndef(T_ptr(T_nil())); }
|
if cx.unreachable { ret llvm::LLVMGetUndef(T_ptr(T_nil())); }
|
||||||
unsafe {
|
unsafe {
|
||||||
ret llvm::LLVMBuildGEP(B(cx), Pointer, vec::to_ptr(Indices),
|
ret llvm::LLVMBuildGEP(B(cx), Pointer, vec::to_ptr(Indices),
|
||||||
vec::len(Indices) as c_uint, noname());
|
Indices.len() as c_uint, noname());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,7 +348,7 @@ fn InBoundsGEP(cx: @block_ctxt, Pointer: ValueRef, Indices: [ValueRef]) ->
|
|||||||
unsafe {
|
unsafe {
|
||||||
ret llvm::LLVMBuildInBoundsGEP(B(cx), Pointer,
|
ret llvm::LLVMBuildInBoundsGEP(B(cx), Pointer,
|
||||||
vec::to_ptr(Indices),
|
vec::to_ptr(Indices),
|
||||||
vec::len(Indices) as c_uint,
|
Indices.len() as c_uint,
|
||||||
noname());
|
noname());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -491,11 +491,11 @@ fn EmptyPhi(cx: @block_ctxt, Ty: TypeRef) -> ValueRef {
|
|||||||
fn Phi(cx: @block_ctxt, Ty: TypeRef, vals: [ValueRef], bbs: [BasicBlockRef])
|
fn Phi(cx: @block_ctxt, Ty: TypeRef, vals: [ValueRef], bbs: [BasicBlockRef])
|
||||||
-> ValueRef {
|
-> ValueRef {
|
||||||
if cx.unreachable { ret llvm::LLVMGetUndef(Ty); }
|
if cx.unreachable { ret llvm::LLVMGetUndef(Ty); }
|
||||||
assert (vec::len::<ValueRef>(vals) == vec::len::<BasicBlockRef>(bbs));
|
assert vals.len() == bbs.len();
|
||||||
let phi = EmptyPhi(cx, Ty);
|
let phi = EmptyPhi(cx, Ty);
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMAddIncoming(phi, vec::to_ptr(vals), vec::to_ptr(bbs),
|
llvm::LLVMAddIncoming(phi, vec::to_ptr(vals), vec::to_ptr(bbs),
|
||||||
vec::len(vals) as c_uint);
|
vals.len() as c_uint);
|
||||||
ret phi;
|
ret phi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -547,7 +547,7 @@ fn Call(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
|
|||||||
if cx.unreachable { ret _UndefReturn(cx, Fn); }
|
if cx.unreachable { ret _UndefReturn(cx, Fn); }
|
||||||
unsafe {
|
unsafe {
|
||||||
ret llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
|
ret llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
|
||||||
vec::len(Args) as c_uint, noname());
|
Args.len() as c_uint, noname());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,7 +555,7 @@ fn FastCall(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
|
|||||||
if cx.unreachable { ret _UndefReturn(cx, Fn); }
|
if cx.unreachable { ret _UndefReturn(cx, Fn); }
|
||||||
unsafe {
|
unsafe {
|
||||||
let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
|
let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
|
||||||
vec::len(Args) as c_uint, noname());
|
Args.len() as c_uint, noname());
|
||||||
lib::llvm::SetInstructionCallConv(v, lib::llvm::FastCallConv);
|
lib::llvm::SetInstructionCallConv(v, lib::llvm::FastCallConv);
|
||||||
ret v;
|
ret v;
|
||||||
}
|
}
|
||||||
@ -566,7 +566,7 @@ fn CallWithConv(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef],
|
|||||||
if cx.unreachable { ret _UndefReturn(cx, Fn); }
|
if cx.unreachable { ret _UndefReturn(cx, Fn); }
|
||||||
unsafe {
|
unsafe {
|
||||||
let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
|
let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
|
||||||
vec::len(Args) as c_uint, noname());
|
Args.len() as c_uint, noname());
|
||||||
lib::llvm::SetInstructionCallConv(v, Conv);
|
lib::llvm::SetInstructionCallConv(v, Conv);
|
||||||
ret v;
|
ret v;
|
||||||
}
|
}
|
||||||
@ -642,7 +642,7 @@ fn Trap(cx: @block_ctxt) {
|
|||||||
let Args: [ValueRef] = [];
|
let Args: [ValueRef] = [];
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMBuildCall(b, T, vec::to_ptr(Args),
|
llvm::LLVMBuildCall(b, T, vec::to_ptr(Args),
|
||||||
vec::len(Args) as c_uint, noname());
|
Args.len() as c_uint, noname());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,7 +529,7 @@ fn trans_bind_1(cx: @block_ctxt, outgoing_fty: ty::t,
|
|||||||
_ { (outgoing_fty, [], @[]) }
|
_ { (outgoing_fty, [], @[]) }
|
||||||
};
|
};
|
||||||
|
|
||||||
if vec::len(bound) == 0u && vec::len(lltydescs) == 0u {
|
if bound.len() == 0u && lltydescs.len() == 0u {
|
||||||
// Trivial 'binding': just return the closure
|
// Trivial 'binding': just return the closure
|
||||||
let lv = lval_maybe_callee_to_lval(f_res, pair_ty);
|
let lv = lval_maybe_callee_to_lval(f_res, pair_ty);
|
||||||
bcx = lv.bcx;
|
bcx = lv.bcx;
|
||||||
|
@ -283,7 +283,7 @@ fn revoke_clean(cx: @block_ctxt, val: ValueRef) {
|
|||||||
sc_cx.cleanups =
|
sc_cx.cleanups =
|
||||||
vec::slice(sc_cx.cleanups, 0u, found as uint) +
|
vec::slice(sc_cx.cleanups, 0u, found as uint) +
|
||||||
vec::slice(sc_cx.cleanups, (found as uint) + 1u,
|
vec::slice(sc_cx.cleanups, (found as uint) + 1u,
|
||||||
vec::len(sc_cx.cleanups));
|
sc_cx.cleanups.len());
|
||||||
sc_cx.lpad_dirty = true;
|
sc_cx.lpad_dirty = true;
|
||||||
ret;
|
ret;
|
||||||
}
|
}
|
||||||
@ -495,7 +495,7 @@ fn T_size_t(targ_cfg: @session::config) -> TypeRef {
|
|||||||
|
|
||||||
fn T_fn(inputs: [TypeRef], output: TypeRef) -> TypeRef unsafe {
|
fn T_fn(inputs: [TypeRef], output: TypeRef) -> TypeRef unsafe {
|
||||||
ret llvm::LLVMFunctionType(output, to_ptr(inputs),
|
ret llvm::LLVMFunctionType(output, to_ptr(inputs),
|
||||||
vec::len::<TypeRef>(inputs) as unsigned,
|
inputs.len() as unsigned,
|
||||||
False);
|
False);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,7 +508,7 @@ fn T_ptr(t: TypeRef) -> TypeRef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn T_struct(elts: [TypeRef]) -> TypeRef unsafe {
|
fn T_struct(elts: [TypeRef]) -> TypeRef unsafe {
|
||||||
ret llvm::LLVMStructType(to_ptr(elts), vec::len(elts) as unsigned, False);
|
ret llvm::LLVMStructType(to_ptr(elts), elts.len() as unsigned, False);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn T_named_struct(name: str) -> TypeRef {
|
fn T_named_struct(name: str) -> TypeRef {
|
||||||
@ -518,7 +518,7 @@ fn T_named_struct(name: str) -> TypeRef {
|
|||||||
|
|
||||||
fn set_struct_body(t: TypeRef, elts: [TypeRef]) unsafe {
|
fn set_struct_body(t: TypeRef, elts: [TypeRef]) unsafe {
|
||||||
llvm::LLVMStructSetBody(t, to_ptr(elts),
|
llvm::LLVMStructSetBody(t, to_ptr(elts),
|
||||||
vec::len(elts) as unsigned, False);
|
elts.len() as unsigned, False);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn T_empty_struct() -> TypeRef { ret T_struct([]); }
|
fn T_empty_struct() -> TypeRef { ret T_struct([]); }
|
||||||
@ -790,28 +790,28 @@ fn C_zero_byte_arr(size: uint) -> ValueRef unsafe {
|
|||||||
let elts: [ValueRef] = [];
|
let elts: [ValueRef] = [];
|
||||||
while i < size { elts += [C_u8(0u)]; i += 1u; }
|
while i < size { elts += [C_u8(0u)]; i += 1u; }
|
||||||
ret llvm::LLVMConstArray(T_i8(), vec::to_ptr(elts),
|
ret llvm::LLVMConstArray(T_i8(), vec::to_ptr(elts),
|
||||||
vec::len(elts) as unsigned);
|
elts.len() as unsigned);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn C_struct(elts: [ValueRef]) -> ValueRef unsafe {
|
fn C_struct(elts: [ValueRef]) -> ValueRef unsafe {
|
||||||
ret llvm::LLVMConstStruct(vec::to_ptr(elts), vec::len(elts) as unsigned,
|
ret llvm::LLVMConstStruct(vec::to_ptr(elts), elts.len() as unsigned,
|
||||||
False);
|
False);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn C_named_struct(T: TypeRef, elts: [ValueRef]) -> ValueRef unsafe {
|
fn C_named_struct(T: TypeRef, elts: [ValueRef]) -> ValueRef unsafe {
|
||||||
ret llvm::LLVMConstNamedStruct(T, vec::to_ptr(elts),
|
ret llvm::LLVMConstNamedStruct(T, vec::to_ptr(elts),
|
||||||
vec::len(elts) as unsigned);
|
elts.len() as unsigned);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn C_array(ty: TypeRef, elts: [ValueRef]) -> ValueRef unsafe {
|
fn C_array(ty: TypeRef, elts: [ValueRef]) -> ValueRef unsafe {
|
||||||
ret llvm::LLVMConstArray(ty, vec::to_ptr(elts),
|
ret llvm::LLVMConstArray(ty, vec::to_ptr(elts),
|
||||||
vec::len(elts) as unsigned);
|
elts.len() as unsigned);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn C_bytes(bytes: [u8]) -> ValueRef unsafe {
|
fn C_bytes(bytes: [u8]) -> ValueRef unsafe {
|
||||||
ret llvm::LLVMConstString(
|
ret llvm::LLVMConstString(
|
||||||
unsafe::reinterpret_cast(vec::to_ptr(bytes)),
|
unsafe::reinterpret_cast(vec::to_ptr(bytes)),
|
||||||
vec::len(bytes) as unsigned, False);
|
bytes.len() as unsigned, False);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef {
|
fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef {
|
||||||
@ -835,7 +835,7 @@ pure fn valid_variant_index(ix: uint, cx: @block_ctxt, enum_id: ast::def_id,
|
|||||||
unchecked{
|
unchecked{
|
||||||
let variant =
|
let variant =
|
||||||
ty::enum_variant_with_id(bcx_tcx(cx), enum_id, variant_id);
|
ty::enum_variant_with_id(bcx_tcx(cx), enum_id, variant_id);
|
||||||
ix < vec::len(variant.args)
|
ix < variant.args.len()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,10 +122,10 @@ fn trans_vtable_callee(bcx: @block_ctxt, self: ValueRef, dict: ValueRef,
|
|||||||
T_ptr(T_array(T_ptr(llfty), n_method + 1u)));
|
T_ptr(T_array(T_ptr(llfty), n_method + 1u)));
|
||||||
let mptr = Load(bcx, GEPi(bcx, vtable, [0, n_method as int]));
|
let mptr = Load(bcx, GEPi(bcx, vtable, [0, n_method as int]));
|
||||||
let generic = generic_none;
|
let generic = generic_none;
|
||||||
if vec::len(*method.tps) > 0u || ty::type_has_params(fty) {
|
if (*method.tps).len() > 0u || ty::type_has_params(fty) {
|
||||||
let tydescs = [], tis = [];
|
let tydescs = [], tis = [];
|
||||||
let tptys = node_id_type_params(bcx, callee_id);
|
let tptys = node_id_type_params(bcx, callee_id);
|
||||||
for t in vec::tail_n(tptys, vec::len(tptys) - vec::len(*method.tps)) {
|
for t in vec::tail_n(tptys, tptys.len() - (*method.tps).len()) {
|
||||||
let ti = none;
|
let ti = none;
|
||||||
let td = get_tydesc(bcx, t, true, ti).result;
|
let td = get_tydesc(bcx, t, true, ti).result;
|
||||||
tis += [ti];
|
tis += [ti];
|
||||||
@ -297,10 +297,10 @@ fn trans_impl_wrapper(ccx: @crate_ctxt, pt: path,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let env_ty = T_ptr(T_struct([T_ptr(T_i8())] + extra_ptrs));
|
let env_ty = T_ptr(T_struct([T_ptr(T_i8())] + extra_ptrs));
|
||||||
let n_extra_ptrs = vec::len(extra_ptrs);
|
let n_extra_ptrs = extra_ptrs.len();
|
||||||
|
|
||||||
let wrap_args = [T_ptr(T_dict())] + vec::slice(real_args, 0u, 2u) +
|
let wrap_args = [T_ptr(T_dict())] + vec::slice(real_args, 0u, 2u) +
|
||||||
vec::slice(real_args, 2u + vec::len(extra_ptrs), vec::len(real_args));
|
vec::slice(real_args, 2u + n_extra_ptrs, real_args.len());
|
||||||
let llfn_ty = T_fn(wrap_args, real_ret);
|
let llfn_ty = T_fn(wrap_args, real_ret);
|
||||||
trans_wrapper(ccx, pt, llfn_ty, {|llfn, bcx|
|
trans_wrapper(ccx, pt, llfn_ty, {|llfn, bcx|
|
||||||
let dict = PointerCast(bcx, LLVMGetParam(llfn, 0 as c_uint), env_ty);
|
let dict = PointerCast(bcx, LLVMGetParam(llfn, 0 as c_uint), env_ty);
|
||||||
@ -407,14 +407,14 @@ fn get_dict(bcx: @block_ctxt, origin: typeck::dict_origin) -> result {
|
|||||||
ret rslt(bcx, get_static_dict(bcx, origin));
|
ret rslt(bcx, get_static_dict(bcx, origin));
|
||||||
}
|
}
|
||||||
let {bcx, ptrs} = get_dict_ptrs(bcx, origin);
|
let {bcx, ptrs} = get_dict_ptrs(bcx, origin);
|
||||||
let pty = T_ptr(T_i8()), dict_ty = T_array(pty, vec::len(ptrs));
|
let pty = T_ptr(T_i8()), dict_ty = T_array(pty, ptrs.len());
|
||||||
let dict = alloca(bcx, dict_ty), i = 0;
|
let dict = alloca(bcx, dict_ty), i = 0;
|
||||||
for ptr in ptrs {
|
for ptr in ptrs {
|
||||||
Store(bcx, PointerCast(bcx, ptr, pty), GEPi(bcx, dict, [0, i]));
|
Store(bcx, PointerCast(bcx, ptr, pty), GEPi(bcx, dict, [0, i]));
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
dict = Call(bcx, ccx.upcalls.intern_dict,
|
dict = Call(bcx, ccx.upcalls.intern_dict,
|
||||||
[C_uint(ccx, vec::len(ptrs)),
|
[C_uint(ccx, ptrs.len()),
|
||||||
PointerCast(bcx, dict, T_ptr(T_dict()))]);
|
PointerCast(bcx, dict, T_ptr(T_dict()))]);
|
||||||
rslt(bcx, dict)
|
rslt(bcx, dict)
|
||||||
}
|
}
|
||||||
@ -431,7 +431,7 @@ fn dict_id(tcx: ty::ctxt, origin: typeck::dict_origin) -> dict_id {
|
|||||||
alt origin {
|
alt origin {
|
||||||
typeck::dict_static(did, ts, origs) {
|
typeck::dict_static(did, ts, origs) {
|
||||||
let d_params = [], orig = 0u;
|
let d_params = [], orig = 0u;
|
||||||
if vec::len(ts) == 0u { ret @{def: did, params: d_params}; }
|
if ts.len() == 0u { ret @{def: did, params: d_params}; }
|
||||||
let impl_params = ty::lookup_item_type(tcx, did).bounds;
|
let impl_params = ty::lookup_item_type(tcx, did).bounds;
|
||||||
vec::iter2(ts, *impl_params) {|t, bounds|
|
vec::iter2(ts, *impl_params) {|t, bounds|
|
||||||
d_params += [dict_param_ty(t)];
|
d_params += [dict_param_ty(t)];
|
||||||
|
@ -110,7 +110,7 @@ fn trans_vec(bcx: @block_ctxt, args: [@ast::expr], id: ast::node_id,
|
|||||||
llunitsz: llunitsz,
|
llunitsz: llunitsz,
|
||||||
unit_ty: unit_ty,
|
unit_ty: unit_ty,
|
||||||
llunitty: llunitty} =
|
llunitty: llunitty} =
|
||||||
alloc(bcx, vec_ty, vec::len(args));
|
alloc(bcx, vec_ty, args.len());
|
||||||
|
|
||||||
add_clean_free(bcx, vptr, true);
|
add_clean_free(bcx, vptr, true);
|
||||||
// Store the individual elements.
|
// Store the individual elements.
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
|
|
||||||
import option::{some, none};
|
import option::{some, none};
|
||||||
import option = option::t;
|
import option = option::t;
|
||||||
export option, some, none;
|
import vec::vec_len;
|
||||||
|
export option, some, none, vec_len;
|
||||||
|
|
||||||
// Export the log levels as global constants. Higher levels mean
|
// Export the log levels as global constants. Higher levels mean
|
||||||
// more-verbosity. Error is the bottom level, default logging level is
|
// more-verbosity. Error is the bottom level, default logging level is
|
||||||
|
@ -1088,6 +1088,9 @@ fn as_buf<E,T>(v: [const E], f: fn(*E) -> T) -> T unsafe {
|
|||||||
let buf = unsafe::to_ptr(v); f(buf)
|
let buf = unsafe::to_ptr(v); f(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl vec_len<T> for [T] {
|
||||||
|
fn len() -> uint { len(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Module: unsafe
|
Module: unsafe
|
||||||
|
@ -18,7 +18,7 @@ impl util for uint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl util<T> for [T] {
|
impl util<T> for [T] {
|
||||||
fn len() -> uint { vec::len(self) }
|
fn length() -> uint { vec::len(self) }
|
||||||
fn iter(f: fn(T)) { for x in self { f(x); } }
|
fn iter(f: fn(T)) { for x in self { f(x); } }
|
||||||
fn map<U>(f: fn(T) -> U) -> [U] {
|
fn map<U>(f: fn(T) -> U) -> [U] {
|
||||||
let r = [];
|
let r = [];
|
||||||
@ -33,7 +33,7 @@ fn main() {
|
|||||||
assert 10u.plus() == 30;
|
assert 10u.plus() == 30;
|
||||||
assert "hi".plus() == 200;
|
assert "hi".plus() == 200;
|
||||||
|
|
||||||
assert [1].len().str() == "1";
|
assert [1].length().str() == "1";
|
||||||
assert [3, 4].map({|a| a + 4})[0] == 7;
|
assert [3, 4].map({|a| a + 4})[0] == 7;
|
||||||
assert [3, 4].map::<uint>({|a| a as uint + 4u})[0] == 7u;
|
assert [3, 4].map::<uint>({|a| a as uint + 4u})[0] == 7u;
|
||||||
let x = 0u;
|
let x = 0u;
|
||||||
|
Loading…
Reference in New Issue
Block a user