raz / test / libc / Through.raz

35 lines · 830 B · raw · history · last change 264716cb

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. *)
4module Through;
5import Out, Heap, Mem;
6import SYSTEM;
7
8type Node = record next: ^Node; n: I64; end;
9
10proc main*;
11var p, list: ^Node; i, sum: I64; a: [3]I64;
12begin
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");
33end;
34
35end Through.