raz / test / run / VecTry.raz

22 lines · 716 B · raw · history · last change 264716cb

1(* Vec's tryPush and tryAdd: false when the allocator runs out, the
2 array as it was, and the program going on. *)
3module VecTry;
4import Arena, Fmt, Rt, Ints := Vec(INT);
5import SYSTEM;
6
7proc main*;
8var ar: Arena.Arena; v: Ints.Vec; n: INT; p: ^INT; ok: BOOL;
9begin
10 if not Arena.init(ar, 4096) then Rt.stop("no arena"); end;
11 Ints.init(v, SYSTEM.ADR(ar.base));
12 n := 0;
13 while Ints.tryPush(v, n) do INC(n); end;
14 p, ok := Ints.tryAdd(v);
15 Fmt.print("{} {} {} {}\n", [Fmt.int(n), Fmt.int(v.len), Fmt.bool(ok), Fmt.bool(p = nil)]);
16 Ints.reset(v);
17 p, ok := Ints.tryAdd(v);
18 p^ := 5;
19 Fmt.print("{} {} {}\n", [Fmt.bool(ok), Fmt.int(v.len), Fmt.int(Ints.all(v)[0])]);
20end;
21
22end VecTry.