raz / conform / err / FrameSlice.raz

50 lines · 1.0 KiB · raw · history · last change 8aae98b9

1module FrameSlice;
2(* a slice of the procedure's own frame can't be returned (report
3 section 7.3); one of a var parameter, a module variable or what a
4 pointer points at can *)
5
6type
7 Hex = [64]U8;
8 Pair = record a: [4]U8; s: []U8; end;
9
10var g: [8]U8;
11
12proc param(h: Hex): []U8;
13begin
14 return h[0..8]; (* the procedure's copy *)
15end;
16
17proc local: []U8;
18var a: [4]U8;
19begin
20 return a; (* the array, silently a slice *)
21end;
22
23proc field(n: INT): ([]U8, INT);
24var p: Pair;
25begin
26 return p.a[0..n], n; (* one of several results *)
27end;
28
29proc literal: []INT;
30begin
31 return [1, 2, 3]; (* a hidden variable of the call *)
32end;
33
34proc whole: Hex;
35var h: Hex;
36begin
37 return h; (* an array, copied out: fine *)
38end;
39
40proc result: []U8;
41begin
42 return whole()[0..2]; (* the array whole returns, a temporary *)
43end;
44
45proc ok(var h: Hex; s: []U8; p: ^Hex; q: Pair): ([]U8, []U8, []U8, []U8, []U8);
46begin
47 return h[0..8], s[1..2], p^[0..2], g, q.s;
48end;
49
50end FrameSlice.