Ticket #482: pod_t.patch
File pod_t.patch, 4.1 KB (added by mikehh, 13 years ago) |
---|
-
docs/book/ch04_pir_subroutines.pod
104 104 to the calling subroutine, and optionally returns result output values. 105 105 106 106 Here's a complete code example that implements the factorial algorithm. 107 The subroutine C<fact > is a separate compilation unit, assembled and107 The subroutine C<factr> is a separate compilation unit, assembled and 108 108 processed after the C<main> function. Parrot resolves global symbols 109 like the C<fact > label between different units.109 like the C<factr> label between different units. 110 110 111 111 =begin PIR 112 112 … … 117 117 count = 5 118 118 product = 1 119 119 120 $I0 = fact (count, product)120 $I0 = factr(count, product) 121 121 122 122 print $I0 123 123 print "\n" 124 124 end 125 125 .end 126 126 127 .sub fact 127 .sub factr 128 128 .param int c 129 129 .param int p 130 130 … … 134 134 dec c 135 135 branch loop 136 136 fin: 137 .return p137 .return (p) 138 138 .end 139 139 140 140 =end PIR … … 171 171 .param int yrs :named("age") 172 172 .param string call :named("name") 173 173 $S0 = "Hello " . call 174 $S1 = "You are " . yrs 175 $S1 = $S1 . " years old 174 $S1 = yrs 175 $S1 = ", you are " . $S1 176 $S1 = $S1 . " years old\n" 176 177 print $S0 177 178 print $S1 178 179 .end … … 411 412 .sub add_two 412 413 .param int value 413 414 .local int val2 414 val2 = add_one(value 415 val2 = add_one(value) 415 416 .tailcall add_one(val2) 416 417 .end 417 418 … … 419 420 .param int a 420 421 .local int b 421 422 b = a + 1 422 return b423 return (b) 423 424 .end 424 425 425 426 =end PIR … … 536 537 in PIR that have their own scope besides subroutines. Fortunately, we can use 537 538 these lexical subroutines to simulate this behavior that HLLs require: 538 539 539 =begin PIR 540 # =begin PIR # to be reinserted later when fixed TT#482 540 541 541 542 .sub 'MyOuter' 542 543 .lex int x … … 550 551 #x, y, and z are all "visible" here 551 552 .end 552 553 553 =end PIR554 # =end PIR 554 555 555 556 In the example above we put the word C<"visible"> in quotes. This is because 556 557 lexically-defined variables need to be accessed with the C<get_lex> and … … 636 637 637 638 .sub main 638 639 $I1 = 5 # counter 639 call fact # same as "bsr fact"640 bsr fact # call fact 640 641 print $I0 641 642 print "\n" 642 643 $I1 = 6 # counter 643 callfact644 bsr fact 644 645 print $I0 645 646 print "\n" 646 647 end … … 867 868 You can also use the C<:invocant> flag to define a new name for the invocant 868 869 object: 869 870 870 =begin PIR 871 # =begin PIR # to be reinserted later when fixed TT#482 871 872 872 873 .sub "MyMethod" :method 873 874 $S0 = self # Already defined as "self" … … 880 881 say $S0 881 882 .end 882 883 883 =end PIR884 # =end PIR 884 885 885 886 This example defines two methods in the C<Foo> class. It calls one 886 887 from the main body of the subroutine and the other from within the -
docs/user/pir/pmcs.pod
335 335 336 336 =head3 Example 9: Setting a timer 337 337 338 =begin PIR 338 # =begin PIR # to be reinserted later when fixed TT#482 339 339 340 340 .include "timer.pasm" # for the timer constants 341 341 … … 362 362 goto loop 363 363 .end 364 364 365 =end PIR365 # =end PIR 366 366 367 367 =head2 Author 368 368 -
docs/user/pir/intro.pod
256 256 .return ($I2) 257 257 .end 258 258 259 = cut259 =end PIR 260 260 261 261 This example also shows that PIR subroutines may be recursive just as in 262 262 a high-level language. … … 284 284 Note that with named arguments, you may rearrange the order of your 285 285 parameters at will. 286 286 287 =begin PIR 287 # =begin PIR # to be reinserted later when fixed TT#482 288 288 289 289 .sub foo 290 290 .param string "name" => a … … 293 293 # ... 294 294 .end 295 295 296 =end PIR296 # =end PIR 297 297 298 298 This subroutine may be called in any of the following ways: 299 299