cvsuser     04/06/20 01:10:27

  Modified:    .        MANIFEST
               include/parrot parrot.h sub.h
               src      sub.c
               config/gen/makefiles root.in
  Added:       include/parrot lexical.h
               src      lexical.c
  Log:
  lexicals 1 - split source files
  
  Revision  Changes    Path
  1.681     +2 -0      parrot/MANIFEST
  
  Index: MANIFEST
  ===================================================================
  RCS file: /cvs/public/parrot/MANIFEST,v
  retrieving revision 1.680
  retrieving revision 1.681
  diff -u -w -r1.680 -r1.681
  --- MANIFEST  19 Jun 2004 09:32:59 -0000      1.680
  +++ MANIFEST  20 Jun 2004 08:10:16 -0000      1.681
  @@ -1799,6 +1799,7 @@
   include/parrot/io.h                               [devel]include
   include/parrot/jit.h                              [devel]include
   include/parrot/key.h                              [devel]include
  +include/parrot/lexical.h                          [devel]include
   include/parrot/library.h                          [devel]include
   include/parrot/list.h                             [devel]include
   include/parrot/longopt.h                          [devel]include
  @@ -2613,6 +2614,7 @@
   src/jit_debug.c                                   []
   src/jit_debug_xcoff.c                             []
   src/key.c                                         []
  +src/lexical.c                                     []
   src/list.c                                        []
   src/library.c                                     []
   src/longopt.c                                     []
  
  
  
  1.96      +2 -1      parrot/include/parrot/parrot.h
  
  Index: parrot.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/parrot.h,v
  retrieving revision 1.95
  retrieving revision 1.96
  diff -u -w -r1.95 -r1.96
  --- parrot.h  25 May 2004 12:32:33 -0000      1.95
  +++ parrot.h  20 Jun 2004 08:10:21 -0000      1.96
  @@ -1,7 +1,7 @@
   /* parrot.h
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: parrot.h,v 1.95 2004/05/25 12:32:33 dan Exp $
  + *     $Id: parrot.h,v 1.96 2004/06/20 08:10:21 leo Exp $
    *  Overview:
    *     General header file includes for the parrot interpreter
    *  Data Structure and Algorithms:
  @@ -268,6 +268,7 @@
   #include "parrot/misc.h"
   #include "parrot/debug.h"
   #include "parrot/sub.h"
  +#include "parrot/lexical.h"
   #include "parrot/key.h"
   #include "parrot/exit.h"
   #include "parrot/nci.h"
  
  
  
  1.31      +3 -27     parrot/include/parrot/sub.h
  
  Index: sub.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/sub.h,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -w -r1.30 -r1.31
  --- sub.h     4 May 2004 12:40:49 -0000       1.30
  +++ sub.h     20 Jun 2004 08:10:21 -0000      1.31
  @@ -1,7 +1,7 @@
  -/* subroutine.h
  +/* sub.h
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: sub.h,v 1.30 2004/05/04 12:40:49 leo Exp $
  + *     $Id: sub.h,v 1.31 2004/06/20 08:10:21 leo Exp $
    *  Overview:
    *  Data Structure and Algorithms:
    *     Subroutine, coroutine, closure and continuation structures
  @@ -13,16 +13,10 @@
    */
   
   #if !defined(PARROT_SUB_H_GUARD)
  -#define PARROT_SUB_GUARD
  +#define PARROT_SUB_H_GUARD
   
   #include "parrot/parrot.h"
   
  -/* Used by Scratchpad PMC */
  -typedef struct Parrot_Lexicals {
  -    List * values;    /* lexicals go here */
  -    List * names;     /* names of lexicals go here */
  -} * parrot_lexicals_t;
  -
   /*
    * Sub, Closure, COntinuation have the same structure
    */
  @@ -64,24 +58,6 @@
   void restore_context(struct Parrot_Interp *, struct Parrot_Context *);
   void mark_context(struct Parrot_Interp *, struct Parrot_Context *);
   
  -PMC * scratchpad_new(struct Parrot_Interp * interp, PMC * base, INTVAL depth);
  -
  -PMC * scratchpad_get_current(struct Parrot_Interp * interp);
  -
  -void scratchpad_store(struct Parrot_Interp * interp, PMC * pad,
  -                      STRING * name, INTVAL position, PMC* value);
  -
  -void scratchpad_store_index(struct Parrot_Interp * interp, PMC * pad, INTVAL 
pad_index,
  -                            STRING * name, INTVAL position, PMC* value);
  -
  -PMC * scratchpad_get(struct Parrot_Interp * interp, PMC * pad, STRING * name,
  -                     INTVAL position);
  -
  -PMC * scratchpad_get_index(struct Parrot_Interp * interp, PMC * pad, INTVAL 
pad_index,
  -                           STRING * name, INTVAL position);
  -
  -void lexicals_mark(struct Parrot_Interp * interp, struct Parrot_Lexicals *lex);
  -void scratchpad_delete(Parrot_Interp interp, PMC *pad, STRING *name);
   
   #endif /* PARROT_SUB_H_GUARD */
   
  
  
  
  1.1                  parrot/include/parrot/lexical.h
  
  Index: lexical.h
  ===================================================================
  /* lexcical.h
   *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
   *  CVS Info
   *     $Id: lexical.h,v 1.1 2004/06/20 08:10:21 leo Exp $
   *  Overview:
   *  Data Structure and Algorithms:
   *
   *  History:
   *     Initial version by Melvin on on 2002/06/6
   *     Splitted into separate file by leo 20.06.2004
   *  Notes:
   *  References:
   */
  
  #if !defined(PARROT_LEXICAL_H_GUARD)
  #define PARROT_LEXICAL_H_GUARD
  
  /* Used by Scratchpad PMC */
  typedef struct Parrot_Lexicals {
      List * values;    /* lexicals go here */
      List * names;     /* names of lexicals go here */
  } * parrot_lexicals_t;
  
  PMC * scratchpad_new(struct Parrot_Interp * interp, PMC * base, INTVAL depth);
  
  PMC * scratchpad_get_current(struct Parrot_Interp * interp);
  
  void scratchpad_store(struct Parrot_Interp * interp, PMC * pad,
                        STRING * name, INTVAL position, PMC* value);
  
  void scratchpad_store_index(struct Parrot_Interp * interp, PMC * pad, INTVAL 
pad_index,
                              STRING * name, INTVAL position, PMC* value);
  
  PMC * scratchpad_get(struct Parrot_Interp * interp, PMC * pad, STRING * name,
                       INTVAL position);
  
  PMC * scratchpad_get_index(struct Parrot_Interp * interp, PMC * pad, INTVAL 
pad_index,
                             STRING * name, INTVAL position);
  
  void lexicals_mark(struct Parrot_Interp * interp, struct Parrot_Lexicals *lex);
  void scratchpad_delete(Parrot_Interp interp, PMC *pad, STRING *name);
  #endif /* PARROT_LEXICAL_H_GUARD */
  
  /*
   * Local variables:
   * c-indentation-style: bsd
   * c-basic-offset: 4
   * indent-tabs-mode: nil
   * End:
   *
   * vim: expandtab shiftwidth=4:
   */
  
  
  
  1.62      +1 -351    parrot/src/sub.c
  
  Index: sub.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/sub.c,v
  retrieving revision 1.61
  retrieving revision 1.62
  diff -u -w -r1.61 -r1.62
  --- sub.c     23 Apr 2004 09:21:12 -0000      1.61
  +++ sub.c     20 Jun 2004 08:10:24 -0000      1.62
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: sub.c,v 1.61 2004/04/23 09:21:12 jrieks Exp $
  +$Id: sub.c,v 1.62 2004/06/20 08:10:24 leo Exp $
   
   =head1 NAME
   
  @@ -494,356 +494,6 @@
       return continuation;
   }
   
  -/*
  -
  -=back
  -
  -=head2 Scratchpad Functions
  -
  -=over 4
  -
  -=item C<static struct Parrot_Lexicals *
  -scratchpad_index(Interp* interpreter, PMC* pad,
  -                 INTVAL scope_index)>
  -
  -Uses C<scope_index> to find and return the appropriate scope.
  -
  -=cut
  -
  -*/
  -
  -static struct Parrot_Lexicals *
  -scratchpad_index(Interp* interpreter, PMC* pad,
  -                 INTVAL scope_index)
  -{
  -    /* if scope_index is negative we count out from current pad */
  -    scope_index = scope_index < 0 ?
  -        PMC_int_val(pad) + scope_index : scope_index;
  -
  -    if (scope_index >= PMC_int_val(pad) || scope_index < 0) {
  -        internal_exception(-1, "Pad index out of range");
  -        return NULL;
  -    }
  -
  -    return &(((struct Parrot_Lexicals *)PMC_data(pad))[scope_index]);
  -}
  -
  -/*
  -
  -=item C<PMC *
  -scratchpad_get_current(Interp * interp)>
  -
  -Returns a pointer to the current scratchpad.
  -
  -=cut
  -
  -*/
  -
  -PMC *
  -scratchpad_get_current(Interp * interp)
  -{
  -    return (PMC *)stack_peek(interp, interp->ctx.pad_stack, NULL);
  -}
  -
  -/*
  -
  -=item C<static INTVAL
  -lexicals_get_position(Interp * interp,
  -                      struct Parrot_Lexicals *lex, STRING* name)>
  -
  -Returns the position of the lexical variable corresponding to C<*name>.
  -If such a variable can not be found the length of the list is returned
  -(i.e. the position that this new lexical should be stored in).
  -
  -=cut
  -
  -*/
  -
  -static INTVAL
  -lexicals_get_position(Interp * interp,
  -                      struct Parrot_Lexicals *lex, STRING* name)
  -{
  -    STRING * cur;
  -    INTVAL pos;
  -
  -    for (pos = 0; pos < list_length(interp, lex->names); pos++) {
  -        cur = *(STRING**)list_get(interp, lex->names, pos, enum_type_STRING);
  -        if (cur && string_compare(interp, cur, name) == 0) {
  -            break;
  -        }
  -    }
  -
  -    return pos;
  -}
  -
  -/*
  -
  -=item C<static struct Parrot_Lexicals *
  -scratchpad_find(Interp* interp, PMC* pad, STRING * name,
  -                INTVAL * position)>
  -
  -Returns first lexical scope and position where C<*name> is found, or
  -C<NULL> if it can not be found.
  -
  -=cut
  -
  -*/
  -
  -static struct Parrot_Lexicals *
  -scratchpad_find(Interp* interp, PMC* pad, STRING * name,
  -                INTVAL * position)
  -{
  -    INTVAL i, pos = 0;
  -    struct Parrot_Lexicals * lex = NULL;
  -
  -    for (i = PMC_int_val(pad) - 1; i >= 0; i--) {
  -        lex = &(((struct Parrot_Lexicals *)PMC_data(pad))[i]);
  -        pos = lexicals_get_position(interp, lex, name);
  -        if (pos == list_length(interp, lex->names))
  -            lex = NULL;
  -        else
  -            break;
  -    }
  -
  -    *position = pos;
  -    return lex;
  -}
  -
  -/*
  -
  -=item C<PMC*
  -scratchpad_new(Interp * interp, PMC * base, INTVAL depth)>
  -
  -Creates and initializes a new C<Scratchpad> PMC.
  -
  -=cut
  -
  -*/
  -
  -PMC*
  -scratchpad_new(Interp * interp, PMC * base, INTVAL depth)
  -{
  -    PMC * pad_pmc;
  -
  -    Parrot_block_DOD(interp);
  -    pad_pmc = pmc_new(interp, enum_class_Scratchpad);
  -    if (base && depth < 0) {
  -        depth = PMC_int_val(base) + depth + 1;
  -    }
  -
  -    if ((depth < 0)
  -        || (base && depth > PMC_int_val(base))
  -        || (!base && depth != 0)) {
  -        Parrot_unblock_DOD(interp);
  -        internal_exception(-1, "-scratch_pad: too deep\n");
  -        return NULL;
  -    }
  -
  -    /* XXX JPS: should we use a List * here instead? */
  -    PMC_data(pad_pmc) = mem_sys_allocate((depth + 1) *
  -                                     sizeof(struct Parrot_Lexicals));
  -
  -    if (base) {
  -        /* XXX JPS: I guess this is copying the front, when it should
  -           be copying the end of the parent (base) */
  -        memcpy(PMC_data(pad_pmc), PMC_data(base), depth *
  -               sizeof(struct Parrot_Lexicals));
  -    }
  -
  -    PMC_int_val(pad_pmc) = depth + 1;
  -
  -    /* in case call to list_new triggers gc */
  -    ((struct Parrot_Lexicals *)PMC_data(pad_pmc))[depth].values = NULL;
  -    ((struct Parrot_Lexicals *)PMC_data(pad_pmc))[depth].names = NULL;
  -
  -    ((struct Parrot_Lexicals *)PMC_data(pad_pmc))[depth].values =
  -        list_new(interp, enum_type_PMC);
  -    ((struct Parrot_Lexicals *)PMC_data(pad_pmc))[depth].names =
  -        list_new(interp, enum_type_STRING);
  -
  -    Parrot_unblock_DOD(interp);
  -
  -    return pad_pmc;
  -}
  -
  -/*
  -
  -=item C<void
  -scratchpad_store(Interp * interp, PMC * pad,
  -                 STRING * name, INTVAL position, PMC* value)>
  -
  -Routines for storing and reading lexicals in C<Scratchpad> PMCs. These
  -take both a name and a position, however in general only one of these
  -will be considered. This is to support both by name access and by
  -position (which is faster). If by position access is intended name
  -should be passed as C<NULL>.
  -
  -=cut
  -
  -*/
  -
  -void
  -scratchpad_store(Interp * interp, PMC * pad,
  -                 STRING * name, INTVAL position, PMC* value)
  -{
  -    struct Parrot_Lexicals * lex;
  -
  -    if (name) {
  -        /* use name to find lex and position */
  -        lex = scratchpad_find(interp, pad, name, &position);
  -        if (!lex)
  -            internal_exception(-1, "Lexical '%s' not found",
  -                               (name == NULL) ? "???"
  -                               : string_to_cstring(interp, name));
  -    }
  -    else {
  -        /* assume current lexical pad */
  -        lex = scratchpad_index(interp, pad, -1);
  -    }
  -
  -    list_assign(interp, lex->values, position, value, enum_type_PMC);
  -}
  -
  -/*
  -
  -=item C<void
  -scratchpad_store_index(Interp * interp, PMC * pad,
  -                       INTVAL scope_index, STRING * name, INTVAL position,
  -                       PMC* value)>
  -
  -Stores C<*value> with name C<*name> or index C<position> in the
  -scratchpad at C<scope_index>.
  -
  -=cut
  -
  -*/
  -
  -void
  -scratchpad_store_index(Interp * interp, PMC * pad,
  -                       INTVAL scope_index, STRING * name, INTVAL position,
  -                       PMC* value)
  -{
  -    struct Parrot_Lexicals * lex;
  -
  -    lex = scratchpad_index(interp, pad, scope_index);
  -
  -    if (name) {
  -        position = lexicals_get_position(interp, lex, name);
  -    }
  -
  -    if (position == list_length(interp, lex->names)) {
  -        if (!name) {
  -            /* no name for new variable, give it a default name of "" */
  -            /* XXX JPS: is this the way to make an empty string? */
  -            name = string_make(interp, "        ", 9,"iso-8859-1",0);
  -        }
  -        list_assign(interp, lex->names, position, name, enum_type_STRING);
  -    }
  -
  -    list_assign(interp, lex->values, position, value, enum_type_PMC);
  -}
  -
  -/*
  -
  -=item C<PMC *
  -scratchpad_get(Interp * interp, PMC * pad, STRING * name,
  -               INTVAL position)>
  -
  -Finds and returns the value for name C<*name> in scratchpad C<*pad>.
  -
  -=cut
  -
  -*/
  -
  -PMC *
  -scratchpad_get(Interp * interp, PMC * pad, STRING * name,
  -               INTVAL position)
  -{
  -    struct Parrot_Lexicals * lex = NULL;
  -
  -    if (!pad)
  -        return NULL;
  -    if (name) lex = scratchpad_find(interp, pad, name, &position);
  -    else lex = scratchpad_index(interp, pad, -1);
  -
  -    if (!lex)
  -        return NULL;
  -
  -    return *(PMC **)list_get(interp, lex->values, position, enum_type_PMC);
  -}
  -
  -/*
  -
  -=item C<PMC *
  -scratchpad_get_index(Interp * interp, PMC * pad,
  -                     INTVAL scope_index, STRING * name, INTVAL position)>
  -
  -Finds and returns the value for name C<*name> in scratchpad C<*pad>.
  -
  -=cut
  -
  -*/
  -
  -PMC *
  -scratchpad_get_index(Interp * interp, PMC * pad,
  -                     INTVAL scope_index, STRING * name, INTVAL position)
  -{
  -    struct Parrot_Lexicals * lex;
  -
  -    if (!pad)
  -        return NULL;
  -    lex = scratchpad_index(interp, pad, scope_index);
  -
  -    if (name) {
  -        position = lexicals_get_position(interp, lex, name);
  -    }
  -
  -    if (!lex || position < 0 || position >= list_length(interp, lex->values)) {
  -        return NULL;
  -    }
  -
  -    return *(PMC **)list_get(interp, lex->values, position, enum_type_PMC);
  -}
  -
  -/*
  -
  -=item C<void
  -lexicals_mark(Interp * interp, struct Parrot_Lexicals *lex)>
  -
  -Calls C<list_mark()> on the lexical's names and values.
  -
  -=cut
  -
  -*/
  -
  -void
  -lexicals_mark(Interp * interp, struct Parrot_Lexicals *lex)
  -{
  -    if (lex->names)
  -        list_mark(interp, lex->names);
  -    if (lex->values)
  -        list_mark(interp, lex->values);
  -}
  -
  -/*
  -
  -=item C<void
  -scratchpad_delete(Parrot_Interp interp, PMC *pad, STRING *name)>
  -
  -Deletes scratchpad C<*pad>.
  -
  -=cut
  -
  -*/
  -
  -void
  -scratchpad_delete(Parrot_Interp interp, PMC *pad, STRING *name)
  -{
  -    INTVAL pos;
  -    struct Parrot_Lexicals *lex = scratchpad_find(interp, pad, name, &pos);
  -    if (lex)
  -        list_assign(interp, lex->names, pos, NULL, enum_type_STRING);
  -}
   
   /*
   
  
  
  
  1.1                  parrot/src/lexical.c
  
  Index: lexical.c
  ===================================================================
  /*
  Copyright: 2001-2004 The Perl Foundation.  All Rights Reserved.
  $Id: lexical.c,v 1.1 2004/06/20 08:10:24 leo Exp $
  
  =head1 NAME
  
  src/lexical.c - Lexical Pads
  
  =head1 DESCRIPTION
  
  Lexical pad aka scratchpad functions.
  
  =head2 Functions
  
  =over 4
  
  */
  
  #include "parrot/parrot.h"
  
  /*
  
  =item C<static struct Parrot_Lexicals *
  scratchpad_index(Interp* interpreter, PMC* pad,
                   INTVAL scope_index)>
  
  Uses C<scope_index> to find and return the appropriate scope.
  
  =cut
  
  */
  
  static struct Parrot_Lexicals *
  scratchpad_index(Interp* interpreter, PMC* pad,
                   INTVAL scope_index)
  {
      /* if scope_index is negative we count out from current pad */
      scope_index = scope_index < 0 ?
          PMC_int_val(pad) + scope_index : scope_index;
  
      if (scope_index >= PMC_int_val(pad) || scope_index < 0) {
          internal_exception(-1, "Pad index out of range");
          return NULL;
      }
  
      return &(((struct Parrot_Lexicals *)PMC_data(pad))[scope_index]);
  }
  
  /*
  
  =item C<PMC *
  scratchpad_get_current(Interp * interp)>
  
  Returns a pointer to the current scratchpad.
  
  =cut
  
  */
  
  PMC *
  scratchpad_get_current(Interp * interp)
  {
      return (PMC *)stack_peek(interp, interp->ctx.pad_stack, NULL);
  }
  
  /*
  
  =item C<static INTVAL
  lexicals_get_position(Interp * interp,
                        struct Parrot_Lexicals *lex, STRING* name)>
  
  Returns the position of the lexical variable corresponding to C<*name>.
  If such a variable can not be found the length of the list is returned
  (i.e. the position that this new lexical should be stored in).
  
  =cut
  
  */
  
  static INTVAL
  lexicals_get_position(Interp * interp,
                        struct Parrot_Lexicals *lex, STRING* name)
  {
      STRING * cur;
      INTVAL pos;
  
      for (pos = 0; pos < list_length(interp, lex->names); pos++) {
          cur = *(STRING**)list_get(interp, lex->names, pos, enum_type_STRING);
          if (cur && string_compare(interp, cur, name) == 0) {
              break;
          }
      }
  
      return pos;
  }
  
  /*
  
  =item C<static struct Parrot_Lexicals *
  scratchpad_find(Interp* interp, PMC* pad, STRING * name,
                  INTVAL * position)>
  
  Returns first lexical scope and position where C<*name> is found, or
  C<NULL> if it can not be found.
  
  =cut
  
  */
  
  static struct Parrot_Lexicals *
  scratchpad_find(Interp* interp, PMC* pad, STRING * name,
                  INTVAL * position)
  {
      INTVAL i, pos = 0;
      struct Parrot_Lexicals * lex = NULL;
  
      for (i = PMC_int_val(pad) - 1; i >= 0; i--) {
          lex = &(((struct Parrot_Lexicals *)PMC_data(pad))[i]);
          pos = lexicals_get_position(interp, lex, name);
          if (pos == list_length(interp, lex->names))
              lex = NULL;
          else
              break;
      }
  
      *position = pos;
      return lex;
  }
  
  /*
  
  =item C<PMC*
  scratchpad_new(Interp * interp, PMC * base, INTVAL depth)>
  
  Creates and initializes a new C<Scratchpad> PMC.
  
  =cut
  
  */
  
  PMC*
  scratchpad_new(Interp * interp, PMC * base, INTVAL depth)
  {
      PMC * pad_pmc;
  
      Parrot_block_DOD(interp);
      pad_pmc = pmc_new(interp, enum_class_Scratchpad);
      if (base && depth < 0) {
          depth = PMC_int_val(base) + depth + 1;
      }
  
      if ((depth < 0)
          || (base && depth > PMC_int_val(base))
          || (!base && depth != 0)) {
          Parrot_unblock_DOD(interp);
          internal_exception(-1, "-scratch_pad: too deep\n");
          return NULL;
      }
  
      /* XXX JPS: should we use a List * here instead? */
      PMC_data(pad_pmc) = mem_sys_allocate((depth + 1) *
                                       sizeof(struct Parrot_Lexicals));
  
      if (base) {
          /* XXX JPS: I guess this is copying the front, when it should
             be copying the end of the parent (base) */
          memcpy(PMC_data(pad_pmc), PMC_data(base), depth *
                 sizeof(struct Parrot_Lexicals));
      }
  
      PMC_int_val(pad_pmc) = depth + 1;
  
      /* in case call to list_new triggers gc */
      ((struct Parrot_Lexicals *)PMC_data(pad_pmc))[depth].values = NULL;
      ((struct Parrot_Lexicals *)PMC_data(pad_pmc))[depth].names = NULL;
  
      ((struct Parrot_Lexicals *)PMC_data(pad_pmc))[depth].values =
          list_new(interp, enum_type_PMC);
      ((struct Parrot_Lexicals *)PMC_data(pad_pmc))[depth].names =
          list_new(interp, enum_type_STRING);
  
      Parrot_unblock_DOD(interp);
  
      return pad_pmc;
  }
  
  /*
  
  =item C<void
  scratchpad_store(Interp * interp, PMC * pad,
                   STRING * name, INTVAL position, PMC* value)>
  
  Routines for storing and reading lexicals in C<Scratchpad> PMCs. These
  take both a name and a position, however in general only one of these
  will be considered. This is to support both by name access and by
  position (which is faster). If by position access is intended name
  should be passed as C<NULL>.
  
  =cut
  
  */
  
  void
  scratchpad_store(Interp * interp, PMC * pad,
                   STRING * name, INTVAL position, PMC* value)
  {
      struct Parrot_Lexicals * lex;
  
      if (name) {
          /* use name to find lex and position */
          lex = scratchpad_find(interp, pad, name, &position);
          if (!lex)
              internal_exception(-1, "Lexical '%s' not found",
                                 (name == NULL) ? "???"
                                 : string_to_cstring(interp, name));
      }
      else {
          /* assume current lexical pad */
          lex = scratchpad_index(interp, pad, -1);
      }
  
      list_assign(interp, lex->values, position, value, enum_type_PMC);
  }
  
  /*
  
  =item C<void
  scratchpad_store_index(Interp * interp, PMC * pad,
                         INTVAL scope_index, STRING * name, INTVAL position,
                         PMC* value)>
  
  Stores C<*value> with name C<*name> or index C<position> in the
  scratchpad at C<scope_index>.
  
  =cut
  
  */
  
  void
  scratchpad_store_index(Interp * interp, PMC * pad,
                         INTVAL scope_index, STRING * name, INTVAL position,
                         PMC* value)
  {
      struct Parrot_Lexicals * lex;
  
      lex = scratchpad_index(interp, pad, scope_index);
  
      if (name) {
          position = lexicals_get_position(interp, lex, name);
      }
  
      if (position == list_length(interp, lex->names)) {
          if (!name) {
              /* no name for new variable, give it a default name of "" */
              /* XXX JPS: is this the way to make an empty string? */
              name = string_make(interp, "        ", 9,"iso-8859-1",0);
          }
          list_assign(interp, lex->names, position, name, enum_type_STRING);
      }
  
      list_assign(interp, lex->values, position, value, enum_type_PMC);
  }
  
  /*
  
  =item C<PMC *
  scratchpad_get(Interp * interp, PMC * pad, STRING * name,
                 INTVAL position)>
  
  Finds and returns the value for name C<*name> in scratchpad C<*pad>.
  
  =cut
  
  */
  
  PMC *
  scratchpad_get(Interp * interp, PMC * pad, STRING * name,
                 INTVAL position)
  {
      struct Parrot_Lexicals * lex = NULL;
  
      if (!pad)
          return NULL;
      if (name) lex = scratchpad_find(interp, pad, name, &position);
      else lex = scratchpad_index(interp, pad, -1);
  
      if (!lex)
          return NULL;
  
      return *(PMC **)list_get(interp, lex->values, position, enum_type_PMC);
  }
  
  /*
  
  =item C<PMC *
  scratchpad_get_index(Interp * interp, PMC * pad,
                       INTVAL scope_index, STRING * name, INTVAL position)>
  
  Finds and returns the value for name C<*name> in scratchpad C<*pad>.
  
  =cut
  
  */
  
  PMC *
  scratchpad_get_index(Interp * interp, PMC * pad,
                       INTVAL scope_index, STRING * name, INTVAL position)
  {
      struct Parrot_Lexicals * lex;
  
      if (!pad)
          return NULL;
      lex = scratchpad_index(interp, pad, scope_index);
  
      if (name) {
          position = lexicals_get_position(interp, lex, name);
      }
  
      if (!lex || position < 0 || position >= list_length(interp, lex->values)) {
          return NULL;
      }
  
      return *(PMC **)list_get(interp, lex->values, position, enum_type_PMC);
  }
  
  /*
  
  =item C<void
  lexicals_mark(Interp * interp, struct Parrot_Lexicals *lex)>
  
  Calls C<list_mark()> on the lexical's names and values.
  
  =cut
  
  */
  
  void
  lexicals_mark(Interp * interp, struct Parrot_Lexicals *lex)
  {
      if (lex->names)
          list_mark(interp, lex->names);
      if (lex->values)
          list_mark(interp, lex->values);
  }
  
  /*
  
  =item C<void
  scratchpad_delete(Parrot_Interp interp, PMC *pad, STRING *name)>
  
  Deletes scratchpad C<*pad>.
  
  =cut
  
  */
  
  void
  scratchpad_delete(Parrot_Interp interp, PMC *pad, STRING *name)
  {
      INTVAL pos;
      struct Parrot_Lexicals *lex = scratchpad_find(interp, pad, name, &pos);
      if (lex)
          list_assign(interp, lex->names, pos, NULL, enum_type_STRING);
  }
  /*
  
  =back
  
  =head1 SEE ALSO
  
  F<include/parrot/lexical.h>.
  
  =head1 HISTORY
  
    Initial version by Melvin on 2002/06/6.
    Splitted into separate file by leo.
  
  =cut
  
  */
  
  /*
   * Local variables:
   * c-indentation-style: bsd
   * c-basic-offset: 4
   * indent-tabs-mode: nil
   * End:
   *
   * vim: expandtab shiftwidth=4:
   */
  
  
  
  1.222     +6 -1      parrot/config/gen/makefiles/root.in
  
  Index: root.in
  ===================================================================
  RCS file: /cvs/public/parrot/config/gen/makefiles/root.in,v
  retrieving revision 1.221
  retrieving revision 1.222
  diff -u -w -r1.221 -r1.222
  --- root.in   19 Jun 2004 09:33:06 -0000      1.221
  +++ root.in   20 Jun 2004 08:10:27 -0000      1.222
  @@ -1,4 +1,4 @@
  -# $Id: root.in,v 1.221 2004/06/19 09:33:06 leo Exp $
  +# $Id: root.in,v 1.222 2004/06/20 08:10:27 leo Exp $
   
   ###############################################################################
   #
  @@ -252,6 +252,7 @@
       $(SRC)/string$(O) \
       $(SRC)/string_primitives$(O) \
       $(SRC)/sub$(O) \
  +    $(SRC)/lexical$(O) \
       $(SRC)/runops_cores$(O) \
       $(SRC)/trace$(O) \
       $(SRC)/pmc$(O) \
  @@ -733,6 +734,10 @@
   
   $(SRC)/method_util$(O) : $(GENERAL_H_FILES)
   
  +$(SRC)/sub$(O) : $(GENERAL_H_FILES)
  +
  +$(SRC)/lexical$(O) : $(GENERAL_H_FILES)
  +
   $(SRC)/string$(O) : $(GENERAL_H_FILES) $(INC)/string_private_cstring.h
   
   $(SRC)/string_primitives$(O) : $(GENERAL_H_FILES) $(ICU_H_FILES)
  
  
  

Reply via email to