raz / conform / run / CallArrayKept.raz

52 lines · 1.0 KiB · raw · history · last change 264716cb

1(* An array a call returns, or a record holding one, lives to the end of
2 the procedure the call is in (report section 8): a slice of it kept in
3 a variable still reads it after later statements, each call has its
4 own, and a const parameter's temporary holding one lives as long. *)
5module CallArrayKept;
6import Out;
7
8type R = record n: INT; a: [8]U8; end;
9
10(* "name-00" and c *)
11proc name(c: U8): [8]U8;
12var a: [8]U8;
13begin
14 a := "name-000";
15 a[7] := c;
16 return a;
17end;
18
19(* A record holding name(c) *)
20proc rec(c: U8): R;
21begin
22 return {n: 1, a: name(c)};
23end;
24
25(* The array in r, as a slice *)
26proc bytes(const r: R): []const U8;
27begin
28 return r.a[0..8];
29end;
30
31proc main*;
32var s, t, u, v: []const U8; i: INT;
33begin
34 s := name('a')[0..8];
35 t := name('b')[0..8];
36 u := rec('c').a[0..8];
37 v := bytes(rec('d'));
38 for i := 0 to 1 do
39 Out.str(name('x')[0..8]);
40 Out.char(' ');
41 end;
42 Out.str(s);
43 Out.char(' ');
44 Out.str(t);
45 Out.char(' ');
46 Out.str(u);
47 Out.char(' ');
48 Out.str(v);
49 Out.char(10);
50end;
51
52end CallArrayKept.