| 1 | (* The library over C's Sys, lib/Sys.raz, which this directory puts |
| 2 | first: output, memory from the heap, and a failed check that still |
| 3 | writes out what Out holds. *) |
| 4 | module Through; |
| 5 | import Out, Heap, Mem; |
| 6 | import SYSTEM; |
| 7 | |
| 8 | type Node = record next: ^Node; n: I64; end; |
| 9 | |
| 10 | proc main*; |
| 11 | var p, list: ^Node; i, sum: I64; a: [3]I64; |
| 12 | begin |
| 13 | Out.str("through C\n"); |
| 14 | list := nil; |
| 15 | for i := 1 to 1000 do |
| 16 | NEW(p, Heap.heap); |
| 17 | p^.n := i; |
| 18 | p^.next := list; |
| 19 | list := p; |
| 20 | end; |
| 21 | sum := 0; |
| 22 | while list # nil do |
| 23 | sum := sum + list^.n; |
| 24 | p := list; |
| 25 | list := list^.next; |
| 26 | Mem.free(Heap.heap, ^U8(p)); |
| 27 | end; |
| 28 | Out.int(sum); Out.ln; |
| 29 | p := nil; (* its address would change from run to run *) |
| 30 | i := 3; |
| 31 | a[i] := 1; |
| 32 | Out.str("not reached\n"); |
| 33 | end; |
| 34 | |
| 35 | end Through. |