Skip to content

Commit 3c3421e

Browse files
committed
When translating vec-append, delay destination string's null-byte-accounting length decrement until the destination string has already been resized. Closes #163.
1 parent 7ab3b30 commit 3c3421e

File tree

1 file changed

+43
-45
lines changed

1 file changed

+43
-45
lines changed

Diff for: src/boot/me/trans.ml

+43-45
Original file line numberDiff line numberDiff line change
@@ -4612,11 +4612,6 @@ let trans_visitor
46124612
let src_cell = need_cell src_oper in
46134613
let src_vec = deref src_cell in
46144614
let src_fill = get_element_ptr src_vec Abi.vec_elt_fill in
4615-
let dst_vec = deref dst_cell in
4616-
let dst_fill = get_element_ptr dst_vec Abi.vec_elt_fill in
4617-
4618-
if trailing_null
4619-
then sub_from dst_fill (imm 1L);
46204615

46214616
aliasing true dst_cell
46224617
begin
@@ -4635,49 +4630,52 @@ let trans_visitor
46354630
* to add to.
46364631
*)
46374632

4638-
(* Reload dst vec, fill; might have changed. *)
46394633
let dst_vec = deref dst_cell in
46404634
let dst_fill = get_element_ptr dst_vec Abi.vec_elt_fill in
46414635

4642-
(* Copy loop: *)
4643-
let eltp_rty = Il.AddrTy (referent_type cx elt_ty) in
4644-
let dptr = next_vreg_cell eltp_rty in
4645-
let sptr = next_vreg_cell eltp_rty in
4646-
let dlim = next_vreg_cell eltp_rty in
4647-
let elt_sz = ty_sz_in_current_frame elt_ty in
4648-
let dst_data =
4649-
get_element_ptr_dyn_in_current_frame
4650-
dst_vec Abi.vec_elt_data
4651-
in
4652-
let src_data =
4653-
get_element_ptr_dyn_in_current_frame
4654-
src_vec Abi.vec_elt_data
4655-
in
4656-
lea dptr (fst (need_mem_cell dst_data));
4657-
lea sptr (fst (need_mem_cell src_data));
4658-
add_to dptr (Il.Cell dst_fill);
4659-
mov dlim (Il.Cell dptr);
4660-
add_to dlim (Il.Cell src_fill);
4661-
let fwd_jmp = mark () in
4662-
emit (Il.jmp Il.JMP Il.CodeNone);
4663-
let back_jmp_targ = mark () in
4664-
(* copy slot *)
4665-
trans_copy_ty
4666-
(get_ty_params_of_current_frame()) true
4667-
(deref dptr) elt_ty
4668-
(deref sptr) elt_ty;
4669-
add_to dptr elt_sz;
4670-
add_to sptr elt_sz;
4671-
patch fwd_jmp;
4672-
check_interrupt_flag ();
4673-
let back_jmp =
4674-
trans_compare_simple Il.JB (Il.Cell dptr) (Il.Cell dlim)
4675-
in
4676-
List.iter
4677-
(fun j -> patch_existing j back_jmp_targ) back_jmp;
4678-
let v = next_vreg_cell word_sty in
4679-
mov v (Il.Cell src_fill);
4680-
add_to dst_fill (Il.Cell v);
4636+
if trailing_null
4637+
then sub_from dst_fill (imm 1L);
4638+
4639+
(* Copy loop: *)
4640+
let eltp_rty = Il.AddrTy (referent_type cx elt_ty) in
4641+
let dptr = next_vreg_cell eltp_rty in
4642+
let sptr = next_vreg_cell eltp_rty in
4643+
let dlim = next_vreg_cell eltp_rty in
4644+
let elt_sz = ty_sz_in_current_frame elt_ty in
4645+
let dst_data =
4646+
get_element_ptr_dyn_in_current_frame
4647+
dst_vec Abi.vec_elt_data
4648+
in
4649+
let src_data =
4650+
get_element_ptr_dyn_in_current_frame
4651+
src_vec Abi.vec_elt_data
4652+
in
4653+
lea dptr (fst (need_mem_cell dst_data));
4654+
lea sptr (fst (need_mem_cell src_data));
4655+
add_to dptr (Il.Cell dst_fill);
4656+
mov dlim (Il.Cell dptr);
4657+
add_to dlim (Il.Cell src_fill);
4658+
let fwd_jmp = mark () in
4659+
emit (Il.jmp Il.JMP Il.CodeNone);
4660+
let back_jmp_targ = mark () in
4661+
(* copy slot *)
4662+
trans_copy_ty
4663+
(get_ty_params_of_current_frame()) true
4664+
(deref dptr) elt_ty
4665+
(deref sptr) elt_ty;
4666+
add_to dptr elt_sz;
4667+
add_to sptr elt_sz;
4668+
patch fwd_jmp;
4669+
check_interrupt_flag ();
4670+
let back_jmp =
4671+
trans_compare_simple
4672+
Il.JB (Il.Cell dptr) (Il.Cell dlim)
4673+
in
4674+
List.iter
4675+
(fun j -> patch_existing j back_jmp_targ) back_jmp;
4676+
let v = next_vreg_cell word_sty in
4677+
mov v (Il.Cell src_fill);
4678+
add_to dst_fill (Il.Cell v);
46814679

46824680
| (Ast.TY_str, e)
46834681
| (Ast.TY_vec _, e)

0 commit comments

Comments
 (0)