Branch: Tag:

2014-12-04

2014-12-04 19:27:11 by Per Hedbor <ph@opera.com>

Fixed support for automap in assignments.

This was handled in a somewhat so-so manner in += and friends.

Specifically, it ignored the [*] on the LHS and just assigned the
variable to the result of the automap.

So, x[*]+=10; was transformed to x = x[*] + 10;

It also only worked for += with friends, not =, so x[*] = x[*] + 1 did
not work.

Now a new opcode is used that assigns array elements individually.
This means that this works:

| array x = ({1,2,3});
| array y = x;
|
| x[*] += 10;
| x==y; // will now be true, was previously false.

Of course, this actually changes how automap works.

The assignment is currently only done on the toplevel, x[*][*] =
x[*][*]+1 still works just fine, but it has some similarities with the
previous situation, the arrays in the toplevel array will be swapped,
not altered.

this will be fixed soonish(tm)

1172:    }       case F_ASSIGN: +  if( CDR(n)->token == F_AUTO_MAP_MARKER ) +  { +  int depth = 0; +  node *lval = CDR(n); +  while( lval->token == F_AUTO_MAP_MARKER ) +  { +  lval = CAR(lval); +  depth++; +  } +  do_docode(lval,0); /* note: not lvalue */ +  if(do_docode(CAR(n),0)!=1) +  yyerror("RHS is void!"); +  emit1(F_ASSIGN_INDICES,depth); +  if( flags & DO_POP ) +  emit0( F_POP_VALUE ); +  return !(flags&DO_POP); +  } +     switch(CAR(n)->token)    {    case F_RANGE:
2694:    return 1;       case F_AUTO_MAP_MARKER: +  if( flags & DO_LVALUE ) +  { +  do_docode(CAR(n),DO_LVALUE); +  } +  else +  {    yyerror("[*] not supported here.\n");    emit0(F_CONST0); -  +  }    return 1;       default: