Branch: Tag:

2004-10-30

2004-10-30 11:38:29 by Martin Stjernholm <mast@lysator.liu.se>

Implemented from-the-end indexing in ranges using the a[..<1] syntax. Added
`[..]. Still to do: Avoid fallback to `[] for ranges if it doesn't take two
args.

Rev: src/docode.c:1.181
Rev: src/interpret.c:1.358
Rev: src/interpret_functions.h:1.176
Rev: src/language.yacc:1.347
Rev: src/las.c:1.351
Rev: src/lexer.h:1.51
Rev: src/opcodes.h:1.41
Rev: src/operators.c:1.198
Rev: src/operators.h:1.16
Rev: src/pike_types.c:1.238
Rev: src/program.c:1.573
Rev: src/program.h:1.213
Rev: src/testsuite.in:1.741
Rev: src/treeopt.in:1.74

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: pike_types.c,v 1.237 2004/09/18 20:50:53 nilsson Exp $ + || $Id: pike_types.c,v 1.238 2004/10/30 11:38:27 mast Exp $   */      #include "global.h"
667:    case T_OBJECT:    case PIKE_T_NAME:    default: -  /* Should not occurr. */ +  /* Should not occur. */    Pike_fatal("Unsupported argument to push_type().\n");    break;   
3635:    while(t->type == PIKE_T_NAME) {    t = t->cdr;    } +  if (index1_type)    while(index1_type->type == PIKE_T_NAME) {    index1_type = index1_type->cdr;    } -  +  if (index2_type)    while(index2_type->type == PIKE_T_NAME) {    index2_type = index2_type->cdr;    }
3651:    if(p)    {    INT32 i; +  +  if((i = FIND_LFUN(p, LFUN_RANGE)) != -1) +  { +  struct pike_type *call_type = NULL; +  type_stack_mark(); +  push_finished_type(mixed_type_string); +  push_finished_type(void_type_string); +  push_type(T_OR); /* Return type */ +  push_finished_type(void_type_string); /* Many type */ +  push_type(T_MANY); +  push_int_type (INDEX_FROM_BEG, OPEN_BOUND); /* arg4 type */ +  push_type(T_FUNCTION); +  if (index2_type) /* arg3 type */ +  push_finished_type(index2_type); +  else +  push_type (T_ZERO); +  push_type(T_FUNCTION); +  push_int_type (INDEX_FROM_BEG, OPEN_BOUND); /* arg2 type */ +  push_type(T_FUNCTION); +  if (index1_type) /* arg1 type */ +  push_finished_type(index1_type); +  else +  push_type (T_ZERO); +  push_type(T_FUNCTION); +  call_type = pop_unfinished_type(); +  +  if((tmp = check_call(call_type, ID_FROM_INT(p, i)->type, 0))) { +  free_type(call_type); +  return tmp; +  } +  +  add_ref(mixed_type_string); +  return mixed_type_string; +  } +     if((i = FIND_LFUN(p, LFUN_INDEX)) != -1)    { -  +  /* FIXME: Should check for a _sizeof operator if from-the-end +  * indexing is done. */ +     struct pike_type *call_type = NULL;    /* FIXME: function_type_string should be replaced with something    * derived from type_string
3663:    push_type(T_OR); /* Return type */    push_finished_type(void_type_string); /* Many type */    push_type(T_MANY); -  push_finished_type(index2_type); /* arg2 type */ +  if (index2_type) /* arg2 type */ +  push_finished_type(index2_type); +  else +  push_int_type (MAX_INT_TYPE, MAX_INT_TYPE);    push_type(T_FUNCTION); -  push_finished_type(index1_type); /* arg1 type */ +  if (index1_type) /* arg1 type */ +  push_finished_type(index1_type); +  else +  push_type (T_ZERO);    push_type(T_FUNCTION);    call_type = pop_unfinished_type();   
3677:    add_ref(mixed_type_string);    return mixed_type_string;    } +     yywarning("Ranging object without index operator.");    return 0;    }
3710:    case T_STRING:    /* Check that the index types are compatible with int. */    { -  if (!low_match_types(int_type_string, index1_type, 0)) { +  if (index1_type && !low_match_types(int_type_string, index1_type, 0)) {    struct pike_string *s = describe_type(t);    yywarning("Bad argument 1 to range operator on %s.",    s->str);
3720:    /* Bad index1 type. */    return 0;    } -  if (!low_match_types(int_type_string, index2_type, 0)) { +  if (index2_type && !low_match_types(int_type_string, index2_type, 0)) {    struct pike_string *s = describe_type(t);    yywarning("Bad argument 2 to range operator on %s.",    s->str);