annotate ppc/test/prob3-3.p @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
rev   line source
0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
1 proc double(x: integer): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3 return x + x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 proc apply3(proc f(x:integer): integer): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 return f(3)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 print_num(apply3(double));
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 end.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 (*<<
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 6
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 >>*)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 (*[[
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 MODULE Main 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 IMPORT Lib 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 ENDHDR
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25 PROC _double 0 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 ! return x + x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30 RETURNW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 END
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 PROC _apply3 0 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 ! return f(3)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 CONST 3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 LDLW 20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38 PCALLW 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 RETURNW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 END
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 PROC MAIN 0 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 ! print_num(apply3(double));
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 GLOBAL _double
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47 GLOBAL _apply3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 PCALLW 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 GLOBAL lib.print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 PCALL 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 ! newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 GLOBAL lib.newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 PCALL 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56 RETURN
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 END
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59 ! End
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 ]]*)