raz / conform / run / AtExit.raz

41 lines · 750 B · raw · history · last change 9ca6cfc3

1(* Rt.exit runs what Rt.atExit registered, the last first, each once,
2 then ends the program with main's status. *)
3module AtExit;
4import Out, Rt;
5
6proc first;
7begin
8 Out.str("first\n");
9end;
10
11proc second;
12begin
13 Out.str("second, which exits again\n");
14 Rt.exit(5); (* the rest still run, once each; the status is now 5 *)
15end;
16
17proc third;
18begin
19 Out.str("third\n");
20end;
21
22proc nothing;
23begin
24end;
25
26proc main*: INT;
27var i, full: I64;
28begin
29 _ := Rt.atExit(first);
30 _ := Rt.atExit(second);
31 _ := Rt.atExit(third);
32 full := 0;
33 for i := 1 to 40 do
34 if Rt.atExit(nothing) = Rt.Full then INC(full); end;
35 end;
36 Out.int(full); Out.str(" refused\n");
37 Out.str("main ends\n");
38 return 3;
39end;
40
41end AtExit.