raz / conform / run / StopStack.raz

27 lines · 490 B · raw · history · last change 7e721e08

1(* Running out of stack stops the program. The program ends with status 2, after the procedures registered
2 with Rt.atExit, so that what it wrote is out. *)
3module StopStack;
4import Out, Rt;
5
6proc down(n: INT): INT;
7var pad: [65536]INT;
8begin
9 pad[n mod 65536] := n;
10 return down(n + 1) + pad[0];
11end;
12
13proc bye;
14begin
15 Out.str("bye\n");
16end;
17
18proc main*;
19var n: INT;
20begin
21 _ := Rt.atExit(bye);
22 Out.str("before\n");
23 n := down(0);
24 Out.int(n);
25end;
26
27end StopStack.