comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:bfdcc3820b32
1 proc double(x: integer): integer;
2 begin
3 return x + x
4 end;
5
6 proc apply3(proc f(x:integer): integer): integer;
7 begin
8 return f(3)
9 end;
10
11 begin
12 print_num(apply3(double));
13 newline()
14 end.
15
16 (*<<
17 6
18 >>*)
19
20 (*[[
21 MODULE Main 0 0
22 IMPORT Lib 0
23 ENDHDR
24
25 PROC _double 0 0 0
26 ! return x + x
27 LDLW 16
28 LDLW 16
29 PLUS
30 RETURNW
31 END
32
33 PROC _apply3 0 0 0
34 ! return f(3)
35 CONST 3
36 LDLW 20
37 LDLW 16
38 PCALLW 1
39 RETURNW
40 END
41
42 PROC MAIN 0 0 0
43 ! print_num(apply3(double));
44 CONST 0
45 GLOBAL _double
46 CONST 0
47 GLOBAL _apply3
48 PCALLW 2
49 CONST 0
50 GLOBAL lib.print_num
51 PCALL 1
52 ! newline()
53 CONST 0
54 GLOBAL lib.newline
55 PCALL 0
56 RETURN
57 END
58
59 ! End
60 ]]*)