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