MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / make_str

Function make_str

compiler/tests/common.rs:207–212  ·  view source on GitHub ↗

Pure-but-allocs: heap string of length n; exercises HeapPool::alloc from extern context. */

(heap: &mut HeapPool, args: &[Val], _kw: Option<Val>)

Source from the content-addressed store, hash-verified

205
206/* Pure-but-allocs: heap string of length n; exercises HeapPool::alloc from extern context. */
207fn 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. */
215fn counter(_: &mut HeapPool, _args: &[Val], _kw: Option<Val>) -> Result<Val, VmErr> {

Callers

nothing calls this directly

Calls 5

is_intMethod · 0.80
as_intMethod · 0.80
lenMethod · 0.45
repeatMethod · 0.45
allocMethod · 0.45

Tested by

no test coverage detected