develooper Front page | perl.perl6.internals | Postings from July 2002

[perl #15800] [PATCH] lexical scope ops, test and example

Jonathan Sillito
July 29, 2002 16:09
[perl #15800] [PATCH] lexical scope ops, test and example
Message ID:
# New Ticket Created by  Jonathan Sillito 
# Please include the string:  [perl #15800]
# in the subject line of all future correspondence about this issue. 
# <URL: >

The attached patch implements a set of lexical ops. Lexical pads are
implemented as a stack of PerlHash PMCs. Here is an example of how to
use the ops:

  new P0, .PerlInt
  new P1, .PerlInt
  new P2, .PerlInt
  new P3, .PerlInt
  set P0, 10
  set P1, 11
  set P2, 12
  # outer most lexical scope
  store_lex P0, "a"
  find_lex P3, "a"
  print P3 # prints 10
  print "\n"

    # nested lexical scope
    store_lex P1, "b"
    find_lex P3, "b"
    print P3 # prints 11
    print "\n"

    store_lex P2, "a" # overwrites previous "a"
    find_lex P3, "a"
    print P3 # prints 12
    print "\n"

    close_lex # end of nested lexical scope

  find_lex P3, "a"
  print P3 # prints 12
  print "\n"

The files affected by the patch are:
- core.ops: added implementation for 4 ops: open_lex, close_lex,
store_lex and find_lex.
- dod.c: added interpreter->ctx.pad_stack to the initial first dod pass
(I am not sure how to test if this is correct ...)
- interpreter.c and interpreter.h: added pad_stack to Parrot_Context.

In addition to the patch a test and example pasm file are attached:

- lexicals.t: simple tests for the 4 ops that should to in t/op/
- lexicals.pasm: simple example that should go in examples/assembly/

Comments welcome.
Jonathan Sillito Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About