Branch: Tag:

2001-06-18

2001-06-18 18:04:34 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Support for the second argument to backtrace_frame->`[]().
Added backtrace_frame->_is_type().
array(backtrace_frame) is now compatible with describe_backtrace().

Rev: src/builtin.cmod:1.34

1:   /* -*- c -*- -  * $Id: builtin.cmod,v 1.33 2001/06/18 15:45:29 grubba Exp $ +  * $Id: builtin.cmod,v 1.34 2001/06/18 18:04:34 grubba Exp $    */      #include "global.h"
667:    THIS->lineno = 0;    }    +  PIKEFUN int(0..1) _is_type(string t) +  { +  INT_TYPE res = (t == findstring("array")); +  pop_n_elems(args); +  push_int(res); +  } +     PIKEFUN string _sprintf(int c, mapping|void opts)    {    struct pike_frame *f = THIS->frame;
737:    push_int(numargs + 3);    }    -  PIKEFUN mixed `[](int index) +  PIKEFUN mixed `[](int index, int|void end_or_none)    {    struct pike_frame *f = THIS->frame; -  +  INT_TYPE end = index; +  INT32 numargs = 0; +  INT32 i;    -  +  if (f) { +  if (f->locals) { +  numargs = +  DO_NOT_WARN((INT32) MINIMUM(f->num_args, Pike_sp - f->locals)); +  if (numargs < 0) numargs = 0; +  } +  } +  +  numargs += 3; +  +  if (!end_or_none) {    if (!f) {    index_error("pike_frame->`[]", Pike_sp-args, args, NULL, Pike_sp-args,    "Indexing the empty array with %"PRINTPIKEINT"d.\n", index);
748:    if (index < 0) {    index_error("pike_frame->`[]", Pike_sp-args, args, NULL, Pike_sp-args,    "Indexing with negative index (%"PRINTPIKEINT"d)\n", index); +  } else if (index >= numargs) { +  index_error("pike_frame->`[]", Pike_sp-args, args, NULL, Pike_sp-args, +  "Indexing with too large index (%"PRINTPIKEINT"d)\n", index);    }    if (!(f->current_object && f->context.prog)) {    index_error("pike_frame->`[]", Pike_sp-args, args, NULL, Pike_sp-args,    "Indexing the NULL value with %"PRINTPIKEINT"d.\n", index);    } -  +  } else { +  if (end_or_none->type != PIKE_T_INT) { +  SIMPLE_BAD_ARG_ERROR("`[]",2,"int|void"); +  } +  end = end_or_none->u.integer; +  }       pop_n_elems(args);    -  switch(index) { +  if (end_or_none) { +  if ((!f) || (end < 0) || (end < index) || (index >= numargs)) { +  f_aggregate(0); +  return; +  } +  +  if (end >= numargs) { +  end = numargs-1; +  } +  } +  +  for (i = index; i <= end; i++) { +  switch(i) {    case 0: /* Filename */    if (f->pc) {    if (!THIS->filename) {
768:    } else {    push_int(0);    } -  return; +  break;    case 1: /* Linenumber */    if (f->pc) {    if (!THIS->filename) {
780:    } else {    push_int(0);    } -  return; +  break;    case 2: /* Function */    if (f->current_object->prog) {    ref_push_object(f->current_object);
790:    push_int(0);    Pike_sp[-1].subtype = NUMBER_DESTRUCTED;    } -  return; +  break;    default: /* Arguments */    { -  INT32 numargs = 0; -  if ((index > 2) && (f->locals)) { -  numargs = -  DO_NOT_WARN((INT32) MINIMUM(f->num_args, Pike_sp - f->locals)); -  if (numargs < 0) numargs = 0; -  index -= 3; -  if (index < numargs) { -  push_svalue(f->locals + index); -  return; +  if ((i > 2) && (i < numargs)) { +  push_svalue(f->locals + i - 3); +  break;    } -  } +     bad_arg_error("backtrace_frame->`[]", Pike_sp-args, args, 1,    "int(0..)", Pike_sp-args,    "Bad argument 1 to backtrace_frame->`[](): "    "Expected int(0..%d)\n", -  numargs+2); +  numargs + 2);    }    /* NOT_REACHED */ -  return; +  break;    }    } -  +  if (end_or_none) { +  f_aggregate(1 + end - index); +  } +  } +    };      /*! @endclass