Pure-but-allocs: heap string of length n; exercises HeapPool::alloc from extern context. */
(heap: &mut HeapPool, args: &[Val], _kw: Option<Val>)
| 205 | |
| 206 | /* Pure-but-allocs: heap string of length n; exercises HeapPool::alloc from extern context. */ |
| 207 | fn make_str(heap: &mut HeapPool, args: &[Val], _kw: Option<Val>) -> Result<Val, VmErr> { |
| 208 | if args.len() != 1 { return Err(VmErr::Type("make_str: expected 1 arg")); } |
| 209 | let n = if args[0].is_int() { args[0].as_int() } else { return Err(VmErr::Type("make_str: arg not int")); }; |
| 210 | let s: String = "x".repeat(n.max(0) as usize); |
| 211 | heap.alloc(HeapObj::Str(s)) |
| 212 | } |
| 213 | |
| 214 | /* Impure counter; verifies impurity taints the caller and skips memo. */ |
| 215 | fn counter(_: &mut HeapPool, _args: &[Val], _kw: Option<Val>) -> Result<Val, VmErr> { |