[Parrot] #173: lexicals not found in PIRC

Parrot parrot-tickets at lists.parrot.org
Sun Nov 28 16:22:06 UTC 2010


#173: lexicals not found in PIRC
----------------------+-----------------------------------------------------
 Reporter:  kjs       |        Owner:  kjs     
     Type:  bug       |       Status:  reopened
 Priority:  normal    |    Milestone:          
Component:  core      |      Version:          
 Severity:  medium    |   Resolution:          
 Keywords:  lexicals  |         Lang:          
    Patch:            |     Platform:          
----------------------+-----------------------------------------------------

Old description:

> lexicals can't be found in nested .subs.
> the following works in parrot, but the generated bytecode doesn't seem to
> work:
>

> {{{
> .sub main
>  .lex "x", $P0
>  $P0 = new "Integer"
>  $P0 = 42
>  foo()
> .end
>
> .sub foo :outer("main")
>  $P0 = find_lex "x"
>  print $P0
> .end
> }}}
>

> So, apparently, lexicals are not stored correctly.
> This needs fixing.

New description:

 lexicals can't be found in nested .subs.
 the following works in parrot, but the generated bytecode doesn't seem to
 work:


 {{{
 .sub main
  .lex "x", $P0
  $P0 = new "Integer"
  $P0 = 42
  foo()
 .end

 .sub foo :outer("main")
  $P0 = find_lex "x"
  print $P0
 .end
 }}}


 So, apparently, lexicals are not stored correctly.
 This needs fixing.

--

Comment(by pmichaud):

 Note that the original code is missing a "capture_lex" instruction
 required for lexical capture.  Correct code should be:

 {{{
 $ cat lex.pir
 .sub main
     .const 'Sub' foosub = 'foo'
     capture_lex foosub
     .lex "x", $P0
     $P0 = new "Integer"
     $P0 = 42
     foo()
 .end

 .sub foo :outer("main")
     $P0 = find_lex "x"
     say $P0
 .end
 $ ./parrot lex.pir
 42
 $ ./parrot -o lex.pbc lex.pir
 $ ./parrot lex.pbc
 42
 $
 }}}

 Pm

-- 
Ticket URL: <https://trac.parrot.org/parrot/ticket/173#comment:8>
Parrot <https://trac.parrot.org/parrot/>
Parrot Development


More information about the parrot-dev mailing list