xref: /csrg-svn/usr.bin/pascal/pdx/test/fproc.p (revision 48079)
1*48079Sbostic(*
2*48079Sbostic * Copyright (c) 1980 The Regents of the University of California.
3*48079Sbostic * All rights reserved.
4*48079Sbostic *
5*48079Sbostic * %sccs.include.redist.c%
6*48079Sbostic *
7*48079Sbostic *	@(#)fproc.p	5.1 (Berkeley) 04/16/91
8*48079Sbostic *)
9*48079Sbostic
10*48079Sbosticprogram fproc(output);
11*48079Sbostic    var
12*48079Sbostic    i :integer;
13*48079Sbostic
14*48079Sbostic    procedure print(function frtn :integer);
15*48079Sbostic	begin
16*48079Sbostic	    write(frtn:3,'   formal routine =');
17*48079Sbostic	end;
18*48079Sbostic
19*48079Sbostic    procedure lvl1(function form: integer);
20*48079Sbostic	label	1;
21*48079Sbostic	var
22*48079Sbostic	loc :integer;
23*48079Sbostic
24*48079Sbostic	function eval :integer;
25*48079Sbostic	    begin
26*48079Sbostic		if loc = 8 then begin
27*48079Sbostic			writeln(' non-local jump');
28*48079Sbostic			goto 1;
29*48079Sbostic		end;
30*48079Sbostic		eval := loc;
31*48079Sbostic	    end;
32*48079Sbostic
33*48079Sbostic    begin
34*48079Sbostic	loc := i;
35*48079Sbostic	i := i - 1;
36*48079Sbostic	if (loc = 4) or (loc = 8) then
37*48079Sbostic		lvl1(eval)
38*48079Sbostic	else if loc > 0 then
39*48079Sbostic		lvl1(form);
40*48079Sbostic1:	write('Stack frame:',loc:3,'   formal print =');
41*48079Sbostic	print(form);
42*48079Sbostic	writeln(form:3);
43*48079Sbostic    end;
44*48079Sbostic
45*48079Sbostic    function geval :integer;
46*48079Sbostic	begin
47*48079Sbostic	    geval := i;
48*48079Sbostic	end;
49*48079Sbostic
50*48079Sbostic    begin
51*48079Sbostic	writeln('This should print levels 0-3, with formal values of 4.');
52*48079Sbostic	writeln('Level 4 should jump to level 8.');
53*48079Sbostic	writeln('Finally levels 8-10 should print with formal values of -1.');
54*48079Sbostic	i := 10;
55*48079Sbostic	lvl1(geval);
56*48079Sbostic    end.
57