From 100e441a44c04f2411a75db5327c331f3b4ab047 Mon Sep 17 00:00:00 2001 From: ychenfo Date: Tue, 5 Apr 2022 15:28:21 +0800 Subject: [PATCH] f --- nac3core/src/codegen/irrt/mod.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/nac3core/src/codegen/irrt/mod.rs b/nac3core/src/codegen/irrt/mod.rs index 8459129a1..923ae9c61 100644 --- a/nac3core/src/codegen/irrt/mod.rs +++ b/nac3core/src/codegen/irrt/mod.rs @@ -329,10 +329,36 @@ pub fn list_slice_assignment<'ctx, 'a>( // index in bound and positive should be done // assert if dest.step == 1 then len(src) <= len(dest) else len(src) == len(dest), and // throw exception if not satisfied + let src_end = ctx.builder + .build_select( + ctx.builder.build_int_compare( + inkwell::IntPredicate::SLT, + src_idx.2, + zero, + "is_neg", + ), + ctx.builder.build_int_sub(src_idx.1, one, "e_min_one"), + ctx.builder.build_int_add(src_idx.1, one, "e_add_one"), + "final_e", + ) + .into_int_value(); + let dest_end = ctx.builder + .build_select( + ctx.builder.build_int_compare( + inkwell::IntPredicate::SLT, + dest_idx.2, + zero, + "is_neg", + ), + ctx.builder.build_int_sub(dest_idx.1, one, "e_min_one"), + ctx.builder.build_int_add(dest_idx.1, one, "e_add_one"), + "final_e", + ) + .into_int_value(); let src_slice_len = - calculate_len_for_slice_range(generator, ctx, src_idx.0, src_idx.1, src_idx.2); + calculate_len_for_slice_range(generator, ctx, src_idx.0, src_end, src_idx.2); let dest_slice_len = - calculate_len_for_slice_range(generator, ctx, dest_idx.0, dest_idx.1, dest_idx.2); + calculate_len_for_slice_range(generator, ctx, dest_idx.0, dest_end, dest_idx.2); let src_eq_dest = ctx.builder.build_int_compare( IntPredicate::EQ, src_slice_len, @@ -357,7 +383,7 @@ pub fn list_slice_assignment<'ctx, 'a>( generator, cond, "0:ValueError", - "attempt to assign sequence of size {0}, to slice of size {1} with step size {2}", + "attempt to assign sequence of size {0} to slice of size {1} with step size {2}", [Some(src_slice_len), Some(dest_slice_len), Some(dest_idx.2)], ctx.current_loc, );