Branch: Tag:

2003-09-05

2003-09-05 15:19:20 by Martin Stjernholm <mast@lysator.liu.se>

Changed foreach to step the iterator after the loop instead of before it, so
that the iterator points to the current element instead of the next one.
Also some cleanup in iterators.cmod and a bit better error checking in
get_iterator.

Rev: src/builtin_functions.h:1.27
Rev: src/docode.c:1.166
Rev: src/interpret_functions.h:1.156
Rev: src/iterators.cmod:1.47
Rev: src/testsuite.in:1.673

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: interpret_functions.h,v 1.155 2003/08/13 15:58:04 grubba Exp $ + || $Id: interpret_functions.h,v 1.156 2003/09/05 15:19:20 mast Exp $   */      /*
1407:    f_get_iterator(1);   });    - OPCODE0_BRANCH(F_NEW_FOREACH, "foreach++", 0, { /* iterator, lvalue, lvalue */ -  extern int foreach_iterate(struct object *o); + /* Stack is: iterator, index lvalue, value lvalue. */ + OPCODE0_BRANCH (F_FOREACH_START, "foreach start", 0, { +  DO_IF_DEBUG ( +  if(Pike_sp[-5].type != PIKE_T_OBJECT) +  Pike_fatal ("Iterator gone from stack.\n"); +  ); +  if (foreach_iterate (Pike_sp[-5].u.object, 0)) +  DONT_BRANCH(); +  else { +  DO_BRANCH(); +  } + });    -  + /* Stack is: iterator, index lvalue, value lvalue. */ + OPCODE0_BRANCH(F_FOREACH_LOOP, "foreach loop", 0, { +  DO_IF_DEBUG (    if(Pike_sp[-5].type != PIKE_T_OBJECT) -  PIKE_ERROR("foreach", "Bad argument 1.\n", Pike_sp-3, 1); -  if(foreach_iterate(Pike_sp[-5].u.object)) +  Pike_fatal ("Iterator gone from stack.\n"); +  ); +  if(foreach_iterate(Pike_sp[-5].u.object, 1))    {    DO_BRANCH();    }else{ -  /* write_to_stderr("foreach\n", 8); */ +     DONT_BRANCH();    }   });