comparison lab4/test/apply.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 (* Passing nested functions as parameters *)
2
3 proc apply(proc f(x: integer));
4 begin
5 f(111)
6 end;
7
8 proc beta(y: integer);
9 proc f(x: integer);
10 begin
11 print_num(x);
12 newline();
13 end;
14
15 proc g(x:integer);
16 begin
17 print_num(y);
18 newline();
19 end;
20
21 begin
22 apply(f);
23 apply(g)
24 end;
25
26 begin
27 beta(222)
28 end.
29
30 (*<<
31 111
32 222
33 >>*)
34
35 (*[[
36 @ picoPascal compiler output
37 .include "fixup.s"
38 .global pmain
39
40 @ proc apply(proc f(x: integer));
41 .text
42 _apply:
43 mov ip, sp
44 stmfd sp!, {r0-r1}
45 stmfd sp!, {r4-r10, fp, ip, lr}
46 mov fp, sp
47 @ f(111)
48 mov r0, #111
49 ldr r10, [fp, #44]
50 ldr r1, [fp, #40]
51 blx r1
52 ldmfd fp, {r4-r10, fp, sp, pc}
53 .ltorg
54
55 @ proc beta(y: integer);
56 _beta:
57 mov ip, sp
58 stmfd sp!, {r0-r1}
59 stmfd sp!, {r4-r10, fp, ip, lr}
60 mov fp, sp
61 @ apply(f);
62 mov r1, fp
63 set r0, _f
64 bl _apply
65 @ apply(g)
66 mov r1, fp
67 set r0, _g
68 bl _apply
69 ldmfd fp, {r4-r10, fp, sp, pc}
70 .ltorg
71
72 @ proc f(x: integer);
73 _f:
74 mov ip, sp
75 stmfd sp!, {r0-r1}
76 stmfd sp!, {r4-r10, fp, ip, lr}
77 mov fp, sp
78 @ print_num(x);
79 ldr r0, [fp, #40]
80 bl print_num
81 @ newline();
82 bl newline
83 ldmfd fp, {r4-r10, fp, sp, pc}
84 .ltorg
85
86 @ proc g(x:integer);
87 _g:
88 mov ip, sp
89 stmfd sp!, {r0-r1}
90 stmfd sp!, {r4-r10, fp, ip, lr}
91 mov fp, sp
92 @ print_num(y);
93 ldr r0, [fp, #24]
94 ldr r0, [r0, #40]
95 bl print_num
96 @ newline();
97 bl newline
98 ldmfd fp, {r4-r10, fp, sp, pc}
99 .ltorg
100
101 pmain:
102 mov ip, sp
103 stmfd sp!, {r4-r10, fp, ip, lr}
104 mov fp, sp
105 @ beta(222)
106 mov r0, #222
107 bl _beta
108 ldmfd fp, {r4-r10, fp, sp, pc}
109 .ltorg
110
111 @ End
112 ]]*)