| 354 | src[0] = 72 |
| 355 | src[1] = 105 |
| 356 | src[2] = 33 |
| 357 | dst: u8[3] = [] |
| 358 | src_ptr: u8* = &src[0] |
| 359 | dst_ptr: u8* = &dst[0] |
| 360 | mem.copy(dst_ptr, src_ptr, 3) |
| 361 | console.putchar(dst_ptr[0] as i32) |
| 362 | console.putchar(dst_ptr[1] as i32) |
| 363 | console.putchar(dst_ptr[2] as i32) |
| 364 | return 0 |
| 365 | } |
| 366 | "#, |
| 367 | ); |
| 368 | assert_eq!(uart, "Hi!"); |
| 369 | assert_eq!(exit, Some(0)); |
| 370 | } |
| 371 | |
| 372 | #[test] |
| 373 | fn mem_move_dst_greater_than_src() { |
| 374 | // High-to-low copying keeps an overlapping destination above the source safe. |
| 375 | let (uart, exit) = run_hll( |
| 376 | r#" |
| 377 | console := import("console") |
| 378 | mem := import("mem") |
| 379 | alloc := import("alloc") |
| 380 | vec := import("vec") |
| 381 | owned := import("owned_string") |
| 382 | arena := import("arena") |
| 383 | pool := import("pool") |
| 384 | |
| 385 | main: () -> i32 { |
| 386 | buf: u8* = alloc.malloc(5) |
| 387 | buf[0] = 65 |
| 388 | buf[1] = 66 |