return int32 in len(). Closes #141

This commit is contained in:
Sebastien Bourdeauducq 2021-12-20 17:44:42 +08:00
parent 2008db8097
commit e2b44a066b
1 changed files with 17 additions and 17 deletions

View File

@ -570,7 +570,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
ty: arg_ty.0,
default_value: None
}],
ret: int64,
ret: int32,
vars: vec![(list_var.1, list_var.0), (arg_ty.1, arg_ty.0)].into_iter().collect(),
}))),
var_id: vec![arg_ty.1],
@ -633,14 +633,14 @@ pub fn calculate_len_for_slice_range<'ctx, 'a>(
end: IntValue<'ctx>,
step: IntValue<'ctx>,
) -> IntValue<'ctx> {
let int64 = ctx.ctx.i64_type();
let start = ctx.builder.build_int_s_extend(start, int64, "start");
let end = ctx.builder.build_int_s_extend(end, int64, "end");
let step = ctx.builder.build_int_s_extend(step, int64, "step");
let int32 = ctx.ctx.i32_type();
let start = ctx.builder.build_int_s_extend(start, int32, "start");
let end = ctx.builder.build_int_s_extend(end, int32, "end");
let step = ctx.builder.build_int_s_extend(step, int32, "step");
let diff = ctx.builder.build_int_sub(end, start, "diff");
let diff_pos = ctx.builder.build_int_compare(SGT, diff, int64.const_zero(), "diffpos");
let step_pos = ctx.builder.build_int_compare(SGT, step, int64.const_zero(), "steppos");
let diff_pos = ctx.builder.build_int_compare(SGT, diff, int32.const_zero(), "diffpos");
let step_pos = ctx.builder.build_int_compare(SGT, step, int32.const_zero(), "steppos");
let test_1 = ctx.builder.build_and(diff_pos, step_pos, "bothpos");
let current = ctx.builder.get_insert_block().unwrap().get_parent().unwrap();
@ -654,41 +654,41 @@ pub fn calculate_len_for_slice_range<'ctx, 'a>(
ctx.builder.position_at_end(then_bb);
let length_pos = {
let diff_pos_min_1 = ctx.builder.build_int_sub(diff, int64.const_int(1, false), "diffminone");
let diff_pos_min_1 = ctx.builder.build_int_sub(diff, int32.const_int(1, false), "diffminone");
let length_pos = ctx.builder.build_int_signed_div(diff_pos_min_1, step, "div");
ctx.builder.build_int_add(length_pos, int64.const_int(1, false), "add1")
ctx.builder.build_int_add(length_pos, int32.const_int(1, false), "add1")
};
ctx.builder.build_unconditional_branch(cont_bb);
ctx.builder.position_at_end(else_bb);
let phi_1 = {
let diff_neg = ctx.builder.build_int_compare(SLT, diff, int64.const_zero(), "diffneg");
let step_neg = ctx.builder.build_int_compare(SLT, step, int64.const_zero(), "stepneg");
let diff_neg = ctx.builder.build_int_compare(SLT, diff, int32.const_zero(), "diffneg");
let step_neg = ctx.builder.build_int_compare(SLT, step, int32.const_zero(), "stepneg");
let test_2 = ctx.builder.build_and(diff_neg, step_neg, "bothneg");
ctx.builder.build_conditional_branch(test_2, then_bb_2, else_bb_2);
ctx.builder.position_at_end(then_bb_2);
let length_neg = {
let diff_neg_add_1 = ctx.builder.build_int_add(diff, int64.const_int(1, false), "diffminone");
let diff_neg_add_1 = ctx.builder.build_int_add(diff, int32.const_int(1, false), "diffminone");
let length_neg = ctx.builder.build_int_signed_div(diff_neg_add_1, step, "div");
ctx.builder.build_int_add(length_neg, int64.const_int(1, false), "add1")
ctx.builder.build_int_add(length_neg, int32.const_int(1, false), "add1")
};
ctx.builder.build_unconditional_branch(cont_bb_2);
ctx.builder.position_at_end(else_bb_2);
let length_zero = int64.const_zero();
let length_zero = int32.const_zero();
ctx.builder.build_unconditional_branch(cont_bb_2);
ctx.builder.position_at_end(cont_bb_2);
let phi_1 = ctx.builder.build_phi(int64, "lenphi1");
let phi_1 = ctx.builder.build_phi(int32, "lenphi1");
phi_1.add_incoming(&[(&length_neg, then_bb_2), (&length_zero, else_bb_2)]);
phi_1.as_basic_value().into_int_value()
};
ctx.builder.build_unconditional_branch(cont_bb);
ctx.builder.position_at_end(cont_bb);
let phi = ctx.builder.build_phi(int64, "lenphi");
let phi = ctx.builder.build_phi(int32, "lenphi");
phi.add_incoming(&[(&length_pos, then_bb), (&phi_1, cont_bb_2)]);
phi.as_basic_value().into_int_value()
}
}