Will Coleda wrote:
On Tue, Aug 26, 2008 at 10:53 AM, luben <[EMAIL PROTECTED]> wrote:
I have noticed that Rakudo (and NQP) generates different PIR code for
implicit and explicit returns.

Example for implicit return:

sub foo($n){
  $n;
}

And example for explicit return:

sub foo($n){
  return $n;
}


Is this on purpose? The implicit return is 4-5 times faster than explicit
return.


Best regards
luben


CC'ing perl6-compiler (where rakudo-particular items should go), and
wondering if you can attach the generated PIR for those of us who are
interested but unwilling at the moment to sync up and try this out.

Thanks. ^_^

Here comes the code.

The compiled (implicit) example:

sub foo($n){
   $n;
}

say(42);

Attached to the message are 4 pir files:
rakudo generated explicit and implicit return and NQP generated explicit and implicit code.

I can run the NQP generated PIR after addition of:

load_bytecode 'compilers/nqp/nqp.pbc'

in the first sub. But I can not find how to run rakudo generated PIR code. The "load_bytecode" seems no be not enought (some months ago it was running with just adding "load_bytecode 'languages/perl6/perl6.pbc'"),

best regards
luben
.namespace 
.sub "_block11"  :anon :lexid("24")
.include "interpinfo.pasm"
    new $P12, "Perl6Scalar"
    .lex "$_", $P12
    new $P13, "Perl6Scalar"
    .lex "$!", $P13
    new $P14, "Perl6Scalar"
    .lex "$/", $P14
    new $P29, "Int"
    assign $P29, 42
    $P30 = "say"($P29)
    .return ($P30)
    .const .Sub $P32 = "_block31" 
    .return ($P32)
.end


.namespace 
.sub "foo"  :lexid("25") :outer("24")
    .param pmc param_16
    push_eh control_15
    .lex "$n", param_16
    find_lex $P17, "$n"
    $P18 = new "Perl6Scalar", $P17
    $P0 = get_hll_global ["Bool"], "True"
    setprop $P18, "readonly", $P0
    store_lex "$n", $P18
    new $P23, "Perl6Scalar"
    .lex "$_", $P23
    new $P24, "Perl6Scalar"
    .lex "$!", $P24
    new $P25, "Perl6Scalar"
    .lex "$/", $P25
    find_lex $P26, "$n"
    unless_null $P26, vivify_10
    new $P26, "Perl6Scalar"
  vivify_10:
    $P27 = "return"($P26)
    .return ($P27)
  control_15:
    .local pmc exception 
    .get_results (exception, $S10) 
    getattribute $P28, exception, "type"
    if_null $P28, control_15_rethrow
    ne $P28, 57, control_15_rethrow
    getattribute $P28, exception, "payload"
    .return ($P28)
  control_15_rethrow:
    rethrow exception
.end


.namespace 
.sub "_block19" :immediate :anon :lexid("26") :outer("25")
    get_global $P20, "Sub"
    .local pmc desc
    $P0 = interpinfo .INTERPINFO_CURRENT_SUB
    $P0 = $P0."get_outer"()
    setprop $P0, "$!proto", $P20
    get_hll_global $P21, "Signature"
    $P22 = $P21."!create"()
    setprop $P0, "$!signature", $P22
    .return ()
.end


.namespace 
.sub "_block31" :load :anon :lexid("27") :outer("24")
$P0 = interpinfo .INTERPINFO_CURRENT_SUB
$P0 = $P0."get_outer"()
$P0()
    .return ()
.end

.namespace 
.sub "_block11"  :anon :lexid("24")
.include "interpinfo.pasm"
    new $P12, "Perl6Scalar"
    .lex "$_", $P12
    new $P13, "Perl6Scalar"
    .lex "$!", $P13
    new $P14, "Perl6Scalar"
    .lex "$/", $P14
    new $P28, "Int"
    assign $P28, 42
    $P29 = "say"($P28)
    .return ($P29)
    .const .Sub $P31 = "_block30" 
    .return ($P31)
.end


.namespace 
.sub "foo"  :lexid("25") :outer("24")
    .param pmc param_16
    push_eh control_15
    .lex "$n", param_16
    find_lex $P17, "$n"
    $P18 = new "Perl6Scalar", $P17
    $P0 = get_hll_global ["Bool"], "True"
    setprop $P18, "readonly", $P0
    store_lex "$n", $P18
    new $P23, "Perl6Scalar"
    .lex "$_", $P23
    new $P24, "Perl6Scalar"
    .lex "$!", $P24
    new $P25, "Perl6Scalar"
    .lex "$/", $P25
    find_lex $P26, "$n"
    unless_null $P26, vivify_10
    new $P26, "Perl6Scalar"
  vivify_10:
    .return ($P26)
  control_15:
    .local pmc exception 
    .get_results (exception, $S10) 
    getattribute $P27, exception, "type"
    if_null $P27, control_15_rethrow
    ne $P27, 57, control_15_rethrow
    getattribute $P27, exception, "payload"
    .return ($P27)
  control_15_rethrow:
    rethrow exception
.end


.namespace 
.sub "_block19" :immediate :anon :lexid("26") :outer("25")
    get_global $P20, "Sub"
    .local pmc desc
    $P0 = interpinfo .INTERPINFO_CURRENT_SUB
    $P0 = $P0."get_outer"()
    setprop $P0, "$!proto", $P20
    get_hll_global $P21, "Signature"
    $P22 = $P21."!create"()
    setprop $P0, "$!signature", $P22
    .return ()
.end


.namespace 
.sub "_block30" :load :anon :lexid("27") :outer("24")
$P0 = interpinfo .INTERPINFO_CURRENT_SUB
$P0 = $P0."get_outer"()
$P0()
    .return ()
.end

.namespace 
.sub "_block11"  :anon :lexid("12")
    $P17 = "say"(42)
    .return ($P17)
.end


.namespace 
.sub "foo"  :lexid("13") :outer("12")
    .param pmc param_13
    push_eh control_12
    .lex "$n", param_13
    new $P14, "Exception"
    set $P14['type'], 57
    find_lex $P15, "$n"
    unless_null $P15, vivify_10
    new $P15, "Undef"
  vivify_10:
    setattribute $P14, 'payload', $P15
    throw $P14
    .return ()
  control_12:
    .local pmc exception 
    .get_results (exception, $S10) 
    getattribute $P16, exception, "type"
    if_null $P16, control_12_rethrow
    ne $P16, 57, control_12_rethrow
    getattribute $P16, exception, "payload"
    .return ($P16)
  control_12_rethrow:
    rethrow exception
.end

.namespace 
.sub "_block11"  :anon :lexid("12")
    $P16 = "say"(42)
    .return ($P16)
.end


.namespace 
.sub "foo"  :lexid("13") :outer("12")
    .param pmc param_13
    push_eh control_12
    .lex "$n", param_13
    find_lex $P14, "$n"
    unless_null $P14, vivify_10
    new $P14, "Undef"
  vivify_10:
    .return ($P14)
  control_12:
    .local pmc exception 
    .get_results (exception, $S10) 
    getattribute $P15, exception, "type"
    if_null $P15, control_12_rethrow
    ne $P15, 57, control_12_rethrow
    getattribute $P15, exception, "payload"
    .return ($P15)
  control_12_rethrow:
    rethrow exception
.end

Reply via email to