annotate ppc/test/mutual.p @ 1:b5139af1a420 tip basis

Fixed permissions on compile scripts
author Mike Spivey <mike@cs.ox.ac.uk>
date Fri, 13 Oct 2017 17:27:58 +0100
parents bfdcc3820b32
children
rev   line source
mike@0 1 (* mutual.p *)
mike@0 2
mike@0 3 proc flip(i: integer): integer;
mike@0 4 var r: integer;
mike@0 5 begin
mike@0 6 if i = 0 then
mike@0 7 r := 1
mike@0 8 else
mike@0 9 r := 2 * flop(i-1)
mike@0 10 end;
mike@0 11 print_string("flip("); print_num(i);
mike@0 12 print_string(") = "); print_num(r);
mike@0 13 newline();
mike@0 14 return r
mike@0 15 end;
mike@0 16
mike@0 17 proc flop(i: integer): integer;
mike@0 18 var r: integer;
mike@0 19 begin
mike@0 20 if i = 0 then
mike@0 21 r := 1
mike@0 22 else
mike@0 23 r := flip(i-1) + k
mike@0 24 end;
mike@0 25 print_string("flop("); print_num(i);
mike@0 26 print_string(") = "); print_num(r);
mike@0 27 newline();
mike@0 28 return r
mike@0 29 end;
mike@0 30
mike@0 31 const k = 5;
mike@0 32
mike@0 33 begin
mike@0 34 print_num(flip(5));
mike@0 35 newline()
mike@0 36 end.
mike@0 37
mike@0 38 (*<<
mike@0 39 flop(0) = 1
mike@0 40 flip(1) = 2
mike@0 41 flop(2) = 7
mike@0 42 flip(3) = 14
mike@0 43 flop(4) = 19
mike@0 44 flip(5) = 38
mike@0 45 38
mike@0 46 >>*)
mike@0 47
mike@0 48 (*[[
mike@0 49 MODULE Main 0 0
mike@0 50 IMPORT Lib 0
mike@0 51 ENDHDR
mike@0 52
mike@0 53 PROC _flip 4 0 0
mike@0 54 ! if i = 0 then
mike@0 55 LDLW 16
mike@0 56 JEQZ L5
mike@0 57 JUMP L6
mike@0 58 LABEL L5
mike@0 59 ! r := 1
mike@0 60 CONST 1
mike@0 61 STLW -4
mike@0 62 JUMP L7
mike@0 63 LABEL L6
mike@0 64 ! r := 2 * flop(i-1)
mike@0 65 CONST 2
mike@0 66 LDLW 16
mike@0 67 CONST 1
mike@0 68 MINUS
mike@0 69 CONST 0
mike@0 70 GLOBAL _flop
mike@0 71 PCALLW 1
mike@0 72 TIMES
mike@0 73 STLW -4
mike@0 74 LABEL L7
mike@0 75 ! print_string("flip("); print_num(i);
mike@0 76 CONST 5
mike@0 77 GLOBAL g1
mike@0 78 CONST 0
mike@0 79 GLOBAL lib.print_string
mike@0 80 PCALL 2
mike@0 81 LDLW 16
mike@0 82 CONST 0
mike@0 83 GLOBAL lib.print_num
mike@0 84 PCALL 1
mike@0 85 ! print_string(") = "); print_num(r);
mike@0 86 CONST 4
mike@0 87 GLOBAL g2
mike@0 88 CONST 0
mike@0 89 GLOBAL lib.print_string
mike@0 90 PCALL 2
mike@0 91 LDLW -4
mike@0 92 CONST 0
mike@0 93 GLOBAL lib.print_num
mike@0 94 PCALL 1
mike@0 95 ! newline();
mike@0 96 CONST 0
mike@0 97 GLOBAL lib.newline
mike@0 98 PCALL 0
mike@0 99 ! return r
mike@0 100 LDLW -4
mike@0 101 RETURNW
mike@0 102 END
mike@0 103
mike@0 104 PROC _flop 4 0 0
mike@0 105 ! if i = 0 then
mike@0 106 LDLW 16
mike@0 107 JEQZ L8
mike@0 108 JUMP L9
mike@0 109 LABEL L8
mike@0 110 ! r := 1
mike@0 111 CONST 1
mike@0 112 STLW -4
mike@0 113 JUMP L10
mike@0 114 LABEL L9
mike@0 115 ! r := flip(i-1) + k
mike@0 116 LDLW 16
mike@0 117 CONST 1
mike@0 118 MINUS
mike@0 119 CONST 0
mike@0 120 GLOBAL _flip
mike@0 121 PCALLW 1
mike@0 122 CONST 5
mike@0 123 PLUS
mike@0 124 STLW -4
mike@0 125 LABEL L10
mike@0 126 ! print_string("flop("); print_num(i);
mike@0 127 CONST 5
mike@0 128 GLOBAL g3
mike@0 129 CONST 0
mike@0 130 GLOBAL lib.print_string
mike@0 131 PCALL 2
mike@0 132 LDLW 16
mike@0 133 CONST 0
mike@0 134 GLOBAL lib.print_num
mike@0 135 PCALL 1
mike@0 136 ! print_string(") = "); print_num(r);
mike@0 137 CONST 4
mike@0 138 GLOBAL g4
mike@0 139 CONST 0
mike@0 140 GLOBAL lib.print_string
mike@0 141 PCALL 2
mike@0 142 LDLW -4
mike@0 143 CONST 0
mike@0 144 GLOBAL lib.print_num
mike@0 145 PCALL 1
mike@0 146 ! newline();
mike@0 147 CONST 0
mike@0 148 GLOBAL lib.newline
mike@0 149 PCALL 0
mike@0 150 ! return r
mike@0 151 LDLW -4
mike@0 152 RETURNW
mike@0 153 END
mike@0 154
mike@0 155 PROC MAIN 0 0 0
mike@0 156 ! print_num(flip(5));
mike@0 157 CONST 5
mike@0 158 CONST 0
mike@0 159 GLOBAL _flip
mike@0 160 PCALLW 1
mike@0 161 CONST 0
mike@0 162 GLOBAL lib.print_num
mike@0 163 PCALL 1
mike@0 164 ! newline()
mike@0 165 CONST 0
mike@0 166 GLOBAL lib.newline
mike@0 167 PCALL 0
mike@0 168 RETURN
mike@0 169 END
mike@0 170
mike@0 171 ! String "flip("
mike@0 172 DEFINE g1
mike@0 173 STRING 666C69702800
mike@0 174
mike@0 175 ! String ") = "
mike@0 176 DEFINE g2
mike@0 177 STRING 29203D2000
mike@0 178
mike@0 179 ! String "flop("
mike@0 180 DEFINE g3
mike@0 181 STRING 666C6F702800
mike@0 182
mike@0 183 ! String ") = "
mike@0 184 DEFINE g4
mike@0 185 STRING 29203D2000
mike@0 186
mike@0 187 ! End
mike@0 188 ]]*)