[teu] / trunk / tertius / src / lua / src / lparser.c Repository:
ViewVC logotype

Diff of /trunk/tertius/src/lua/src/lparser.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 40, Wed Nov 7 22:02:52 2007 UTC revision 243, Thu Apr 22 02:46:50 2010 UTC
# Line 928  Line 928 
928  }  }
929    
930    
931  static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {  static void assignment (LexState *ls, struct LHS_assign *lh, int nvars, BinOpr *opr) {
932    expdesc e;    expdesc e;
933    check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,    check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,
934                        "syntax error");                        "syntax error");
# Line 938  Line 938 
938      primaryexp(ls, &nv.v);      primaryexp(ls, &nv.v);
939      if (nv.v.k == VLOCAL)      if (nv.v.k == VLOCAL)
940        check_conflict(ls, lh, &nv.v);        check_conflict(ls, lh, &nv.v);
941      assignment(ls, &nv, nvars+1);      assignment(ls, &nv, nvars+1, opr);
942    }    }
943    else {  /* assignment -> `=' explist1 */    else {  /* assignment -> `=' explist1 */
944      int nexps;      int nexps;
945      checknext(ls, '=');  
946            *opr = OPR_NOBINOPR;
947            switch(ls->t.token)
948            {
949            case '=': break;
950            case TK_CONCATASSIGN: *opr = OPR_CONCAT; break;
951            case TK_ADDASSIGN: *opr = OPR_ADD; break;
952            case TK_SUBASSIGN: *opr = OPR_SUB; break;
953            case TK_MULASSIGN: *opr = OPR_MUL; break;
954            case TK_DIVASSIGN: *opr = OPR_DIV; break;
955            case TK_POWASSIGN: *opr = OPR_POW; break;
956            case TK_MODASSIGN: *opr = OPR_MOD; break;
957            default:
958                    luaX_syntaxerror(ls, "unexpected symbol");
959                    break;
960            };
961            luaX_next(ls);
962      nexps = explist1(ls, &e);      nexps = explist1(ls, &e);
963      if (nexps != nvars) {      if (nexps != nvars) {
964        adjust_assign(ls, nvars, nexps, &e);        adjust_assign(ls, nvars, nexps, &e);
# Line 951  Line 967 
967      }      }
968      else {      else {
969        luaK_setoneret(ls->fs, &e);  /* close last expression */        luaK_setoneret(ls->fs, &e);  /* close last expression */
970        luaK_storevar(ls->fs, &lh->v, &e);        luaK_storevar(ls->fs, &lh->v, &e, *opr);
971        return;  /* avoid default */        return;  /* avoid default */
972      }      }
973    }    }
974    init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */    init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */
975    luaK_storevar(ls->fs, &lh->v, &e);    luaK_storevar(ls->fs, &lh->v, &e, *opr);
976  }  }
977    
978    
# Line 1168  Line 1184 
1184    luaK_reserveregs(fs, 1);    luaK_reserveregs(fs, 1);
1185    adjustlocalvars(ls, 1);    adjustlocalvars(ls, 1);
1186    body(ls, &b, 0, ls->linenumber);    body(ls, &b, 0, ls->linenumber);
1187    luaK_storevar(fs, &v, &b);    luaK_storevar(fs, &v, &b, OPR_NOBINOPR);
1188    /* debug information will only see the variable after this point! */    /* debug information will only see the variable after this point! */
1189    getlocvar(fs, fs->nactvar - 1).startpc = fs->pc;    getlocvar(fs, fs->nactvar - 1).startpc = fs->pc;
1190  }  }
# Line 1214  Line 1230 
1230    luaX_next(ls);  /* skip FUNCTION */    luaX_next(ls);  /* skip FUNCTION */
1231    needself = funcname(ls, &v);    needself = funcname(ls, &v);
1232    body(ls, &b, needself, line);    body(ls, &b, needself, line);
1233    luaK_storevar(ls->fs, &v, &b);    luaK_storevar(ls->fs, &v, &b, OPR_NOBINOPR);
1234    luaK_fixline(ls->fs, line);  /* definition `happens' in the first line */    luaK_fixline(ls->fs, line);  /* definition `happens' in the first line */
1235  }  }
1236    
# Line 1223  Line 1239 
1239    /* stat -> func | assignment */    /* stat -> func | assignment */
1240    FuncState *fs = ls->fs;    FuncState *fs = ls->fs;
1241    struct LHS_assign v;    struct LHS_assign v;
1242      BinOpr opr;
1243    primaryexp(ls, &v.v);    primaryexp(ls, &v.v);
1244    if (v.v.k == VCALL)  /* stat -> func */    if (v.v.k == VCALL)  /* stat -> func */
1245      SETARG_C(getcode(fs, &v.v), 1);  /* call statement uses no results */      SETARG_C(getcode(fs, &v.v), 1);  /* call statement uses no results */
1246    else {  /* stat -> assignment */    else {  /* stat -> assignment */
1247      v.prev = NULL;      v.prev = NULL;
1248      assignment(ls, &v, 1);      assignment(ls, &v, 1, &opr);
1249    }    }
1250  }  }
1251    

Legend:
Removed from v.40  
changed lines
  Added in v.243

svnmaster@icculus.org
ViewVC Help
Powered by ViewVC 1.0.4