Ticket #482: pod_t.patch

File pod_t.patch, 4.1 KB (added by mikehh, 6 years ago)
  • docs/book/ch04_pir_subroutines.pod

     
    104104to the calling subroutine, and optionally returns result output values. 
    105105 
    106106Here's a complete code example that implements the factorial algorithm. 
    107 The subroutine C<fact> is a separate compilation unit, assembled and 
     107The subroutine C<factr> is a separate compilation unit, assembled and 
    108108processed after the C<main> function.  Parrot resolves global symbols 
    109 like the C<fact> label between different units. 
     109like the C<factr> label between different units. 
    110110 
    111111=begin PIR 
    112112 
     
    117117     count = 5 
    118118     product = 1 
    119119 
    120      $I0 = fact(count, product) 
     120     $I0 = factr(count, product) 
    121121 
    122122     print $I0 
    123123     print "\n" 
    124124     end 
    125125  .end 
    126126 
    127   .sub fact 
     127  .sub factr 
    128128     .param int c 
    129129     .param int p 
    130130 
     
    134134     dec c 
    135135     branch loop 
    136136  fin: 
    137      .return p 
     137     .return (p) 
    138138  .end 
    139139 
    140140=end PIR 
     
    171171    .param int yrs :named("age") 
    172172    .param string call :named("name") 
    173173    $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" 
    176177    print $S0 
    177178    print $S1 
    178179 .end 
     
    411412  .sub add_two 
    412413      .param int value 
    413414      .local int val2 
    414       val2 = add_one(value 
     415      val2 = add_one(value) 
    415416      .tailcall add_one(val2) 
    416417  .end 
    417418 
     
    419420      .param int a 
    420421      .local int b 
    421422      b = a + 1 
    422       return b 
     423      return (b) 
    423424  .end 
    424425 
    425426=end PIR 
     
    536537in PIR that have their own scope besides subroutines. Fortunately, we can use 
    537538these lexical subroutines to simulate this behavior that HLLs require: 
    538539 
    539 =begin PIR 
     540# =begin PIR # to be reinserted later when fixed TT#482 
    540541 
    541542  .sub 'MyOuter' 
    542543      .lex int x 
     
    550551      #x, y, and z are all "visible" here 
    551552  .end 
    552553 
    553 =end PIR 
     554# =end PIR 
    554555 
    555556In the example above we put the word C<"visible"> in quotes. This is because 
    556557lexically-defined variables need to be accessed with the C<get_lex> and 
     
    636637 
    637638  .sub main 
    638639      $I1 = 5           # counter 
    639       call fact         # same as "bsr fact" 
     640      bsr fact          # call fact 
    640641      print $I0 
    641642      print "\n" 
    642643      $I1 = 6           # counter 
    643       call fact 
     644      bsr fact 
    644645      print $I0 
    645646      print "\n" 
    646647      end 
     
    867868You can also use the C<:invocant> flag to define a new name for the invocant 
    868869object: 
    869870 
    870 =begin PIR 
     871# =begin PIR # to be reinserted later when fixed TT#482 
    871872 
    872873  .sub "MyMethod" :method 
    873874    $S0 = self                    # Already defined as "self" 
     
    880881    say $S0 
    881882  .end 
    882883 
    883 =end PIR 
     884# =end PIR 
    884885 
    885886This example defines two methods in the C<Foo> class. It calls one 
    886887from the main body of the subroutine and the other from within the 
  • docs/user/pir/pmcs.pod

     
    335335 
    336336=head3 Example 9: Setting a timer 
    337337 
    338 =begin PIR 
     338# =begin PIR # to be reinserted later when fixed TT#482 
    339339 
    340340    .include "timer.pasm"                   # for the timer constants 
    341341 
     
    362362       goto loop 
    363363    .end 
    364364 
    365 =end PIR 
     365# =end PIR 
    366366 
    367367=head2 Author 
    368368 
  • docs/user/pir/intro.pod

     
    256256     .return ($I2) 
    257257  .end 
    258258 
    259 =cut 
     259=end PIR 
    260260 
    261261This example also shows that PIR subroutines may be recursive just as in 
    262262a high-level language. 
     
    284284Note that with named arguments, you may rearrange the order of your 
    285285parameters at will. 
    286286 
    287 =begin PIR 
     287# =begin PIR # to be reinserted later when fixed TT#482 
    288288 
    289289  .sub foo 
    290290    .param string "name"    => a 
     
    293293    # ... 
    294294  .end 
    295295 
    296 =end PIR 
     296# =end PIR 
    297297 
    298298This subroutine may be called in any of the following ways: 
    299299