Branch: Tag:

2001-09-28

2001-09-28 00:01:45 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

automap implemented x[*] + y[*] now works

Rev: src/builtin.cmod:1.67
Rev: src/docode.c:1.133
Rev: src/interpret_functions.h:1.94
Rev: src/language.yacc:1.261
Rev: src/las.c:1.268
Rev: src/opcodes.h:1.24
Rev: src/testsuite.in:1.454

5:   \*/   /**/   #include "global.h" - RCSID("$Id: las.c,v 1.267 2001/09/24 17:01:41 grubba Exp $"); + RCSID("$Id: las.c,v 1.268 2001/09/28 00:01:45 hubbe Exp $");      #include "language.h"   #include "interpret.h"
851:      #define mkemptynode() dmalloc_touch(node *, debug_mkemptynode())    +  + static int is_automap_arg_list(node *n) + { +  if(!n) return 0; +  switch(n->token) +  { +  default: return 0; +  case F_ARG_LIST: +  return is_automap_arg_list(CAR(n)) || +  is_automap_arg_list(CDR(n)); +  +  case F_AUTO_MAP_MARKER: return 1; +  } + } +  +    node *debug_mknode(short token, node *a, node *b)   {    node *res;    -  +  switch(token) +  { +  case F_APPLY: +  if(is_automap_arg_list(b)) +  token=F_AUTO_MAP; +  break; +  +  case F_INDEX: +  switch((is_automap_arg_list(a) << 1) | +  is_automap_arg_list(b)) +  { +  case 1: +  res=mkefuncallnode("rows",mknode(F_ARG_LIST,a,copy_node(CAR(b)))); +  free_node(b); +  return res; +  +  case 2: +  res=mkefuncallnode("column",mknode(F_ARG_LIST,copy_node(CAR(a)),b)); +  free_node(a); +  return res; +  +  case 3: +  return mkefuncallnode("`[]",mknode(F_ARG_LIST,a,b)); +  } +  } +    #if defined(PIKE_DEBUG) && !defined(SHARED_NODES)    if(b && a==b)    fatal("mknode: a and be are the same!\n");
889:    }    break;    +  case F_AUTO_MAP:    case F_APPLY:    {    unsigned INT16 opt_flags = OPT_SIDE_EFFECT | OPT_EXTERNAL_DEPEND;
1170:   {    struct pike_string *name;    node *n; -  name = findstring(function); +  name = make_shared_string(function);    if(!name || !(n=find_module_identifier(name,0)))    { -  +  free_string(name);    my_yyerror("Internally used efun undefined: %s",function);    return mkintnode(0);    } -  +  free_string(name);    n = mkapplynode(n, args);    return n;   }
1625:   #endif    break;    +  case F_AUTO_MAP:    case F_APPLY:    if(CAR(n)->token == F_CONSTANT &&    CAR(n)->u.sval.type == T_FUNCTION &&
2239:   {    switch(n->token)    { +  case F_AUTO_MAP:    case F_APPLY:    if(CAR(n) &&    CAR(n)->token == F_CONSTANT &&
2422:    low_print_tree(_CDR(foo),0);    return;    +  case F_AUTO_MAP: +  fprintf(stderr, "__automap__ "); +  low_print_tree(_CAR(foo),0); +  fprintf(stderr, "("); +  low_print_tree(_CDR(foo),0); +  fprintf(stderr, ")"); +  return; +  case F_AUTO_MAP_MARKER: +  low_print_tree(_CAR(foo),0); +  fprintf(stderr, "[*]"); +  return;    case F_APPLY:    low_print_tree(_CAR(foo),0);    fprintf(stderr, "(");
2840:    break;       case F_APPLY: +  case F_AUTO_MAP:    if(n->tree_info & OPT_SIDE_EFFECT) {    p->ext_flags = VAR_USED;    }    break;    -  +  case F_AUTO_MAP_MARKER: +  find_written_vars(CAR(n), p, lvalue); +  break; +     case F_INDEX:    case F_ARROW:    find_written_vars(CAR(n), p, lvalue);
3244:    fix_type_field(CDR(n));    if (!pike_types_le(CAR(n)->type, CDR(n)->type)) {    /* a["b"]=c and a->b=c can be valid when a is an array */ -  if (CDR(n)->token != F_INDEX && CDR(n)->token != F_ARROW && +  if (CDR(n)->token != F_INDEX && +  CDR(n)->token != F_ARROW &&    !match_types(CDR(n)->type,CAR(n)->type)) {    yytype_error("Bad type in assignment.",    CDR(n)->type, CAR(n)->type, 0);
3284:    }    break;    +  case F_AUTO_MAP_MARKER: +  if (!CAR(n) || (CAR(n)->type == void_type_string)) { +  my_yyerror("Indexing a void expression."); +  /* The optimizer converts this to an expression returning 0. */ +  copy_pike_type(n->type, zero_type_string); +  } else { +  type_a=CAR(n)->type; +  if(!check_indexing(type_a, int_type_string, n)) +  if(!Pike_compiler->catch_level) +  my_yyerror("[*] on non-array."); +  n->type=index_type(type_a, int_type_string, n); +  } +  break; +  +  case F_AUTO_MAP:    case F_APPLY:    if (!CAR(n) || (CAR(n)->type == void_type_string)) {    my_yyerror("Calling a void expression.");
3304: Inside #if defined(USE_PIKE_TYPE) && defined(NEW_ARG_CHECK)
   if (f && (n->type = get_ret_type(f))) {    /* Type/argument-check OK. */    free_type(f); +  if(n->token == F_AUTO_MAP) +  { +  push_finished_type(n->type); +  push_type(T_ARRAY); +  free_type(n->type); +  n->type = pop_type(); +  }    break;    }   
3333:    if (n->type) {    /* Type/argument-check OK. */    free_type(s); +  +  if(n->token == F_AUTO_MAP) +  { +  push_finished_type(n->type); +  push_type(T_ARRAY); +  free_type(n->type); +  n->type = pop_type(); +  } +     break;    }   
4031: Inside #if defined(SHARED_NODES) && !defined(IN_TPIKE)
   return;    }    +  case F_AUTO_MAP:    case F_APPLY:    {    int i;
4323: Inside #if defined(SHARED_NODES) && !defined(IN_TPIKE)
   }    break;    +  case F_AUTO_MAP:    case F_APPLY:    {    int i;
4333: Inside #if defined(SHARED_NODES) && !defined(IN_TPIKE)
   }    cdr = low_localopt(CDR(n), usage, switch_u, cont_u, break_u, catch_u);    car = low_localopt(CAR(n), usage, switch_u, cont_u, break_u, catch_u); -  return mknode(F_APPLY, car, cdr); +  return mknode(n->token, car, cdr);    }       case F_LVALUE_LIST: