weep added by Bunny351 on Sat Sep 17 21:54:28 2022

(define (%string-copy! to tstart from fstart fend)
  (let* ((fstartp (##core#inline "C_utf_position" from fstart))
         (fendp (##core#inline "C_utf_position" from fend))
         (flen (fx- fendp fstartp))
         (len (fx- fend fstart))
         (tstartp (##core#inline "C_utf_position" to tstart))
         (tendp (##core#inline "C_utf_position" to (fx+ tstart len)))
         (tbuf (##sys#slot to 0))
         (rs (##sys#make-bytevector (+ 1 flen))))
    (if (eq? flen (fx- tendp tstartp))
        (##core#inline "C_copy_memory_with_offset" tbuf (##sys#slot from 0)
                       tstartp fstartp flen)
        (let* ((rest (fx- (fx- (##sys#size tbuf) 1) tendp))
               (buf (##sys#make-bytevector (fx+ 1 (fx+ tstartp (fx+ flen rest))))))
          (##core#inline "C_copy_memory_with_offset" buf tbuf 0 0 tstartp)
          (##core#inline "C_copy_memory_with_offset" buf (##sys#slot from 0)
                         tstartp fstartp flen)
          (##core#inline "C_copy_memory_with_offset" buf tbuf tendp tendp 
                         rest)
          (##sys#setslot to 0 buf)
          (##sys#setislot to 1 (fx+ tstart (fx+ flen (fx- (##sys#slot to 1)
                                                          tend))))
          (##sys##setislot to 2 0)
          (##sys##setislot to 3 0)))))