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