[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: compound assignment patch for 5.4.0-beta
- From: Dave Hayden <dave@...>
- Date: Mon, 30 Dec 2019 18:38:34 -0600
On Dec 26, 2019, at 7:27 PM, Dave Hayden <dave@panic.com> wrote:
>
> Hopefully this is useful to others, and please let me know what I did wrong! :)
Whoops! I bungled an assignment in the left-hand list case. Here’s that fixed, before it gives anyone any grief:
diff -r lua-5.4.0-beta/src/llex.c lua-5.4-test/src/llex.c
455a456
> if (check_next1(ls, '=')) return TK_MINUSEQ;
491c492,495
< else if (check_next1(ls, '<')) return TK_SHL;
---
> else if (check_next1(ls, '<')) {
> if ( check_next1(ls, '=') ) return TK_SHLEQ;
> else return TK_SHL;
> }
497c501,504
< else if (check_next1(ls, '>')) return TK_SHR;
---
> else if (check_next1(ls, '>')) {
> if ( check_next1(ls, '=') ) return TK_SHREQ;
> else return TK_SHR;
> }
502a510
> if (check_next1(ls, '=')) return TK_DIVEQ;
504a513,537
> case '+': {
> next(ls);
> if (check_next1(ls, '=')) return TK_PLUSEQ;
> else return '+';
> }
> case '*': {
> next(ls);
> if (check_next1(ls, '=')) return TK_MULTEQ;
> else return '*';
> }
> case '&': {
> next(ls);
> if (check_next1(ls, '=')) return TK_BANDEQ;
> else return '*';
> }
> case '|': {
> next(ls);
> if (check_next1(ls, '=')) return TK_BOREQ;
> else return '|';
> }
> case '^': {
> next(ls);
> if (check_next1(ls, '=')) return TK_BXOREQ;
> else return '^';
> }
diff -r lua-5.4.0-beta/src/llex.h lua-5.4-test/src/llex.h
36c36,37
< TK_FLT, TK_INT, TK_NAME, TK_STRING
---
> TK_FLT, TK_INT, TK_NAME, TK_STRING,
> TK_PLUSEQ, TK_MINUSEQ, TK_MULTEQ, TK_DIVEQ, TK_SHLEQ, TK_SHREQ, TK_BANDEQ, TK_BOREQ, TK_BXOREQ
diff -r lua-5.4.0-beta/src/lparser.c lua-5.4-test/src/lparser.c
1208a1209,1219
> // PANIC
> case TK_PLUSEQ: return OPR_ADD;
> case TK_MINUSEQ: return OPR_SUB;
> case TK_MULTEQ: return OPR_MUL;
> case TK_DIVEQ: return OPR_DIV;
> case TK_SHLEQ: return OPR_SHL;
> case TK_SHREQ: return OPR_SHR;
> case TK_BANDEQ: return OPR_BAND;
> case TK_BOREQ: return OPR_BOR;
> case TK_BXOREQ: return OPR_BXOR;
> // end PANIC
1347a1359,1404
> // PANIC
>
> static void compound_assignment(LexState *ls, expdesc* v, int nvars) {
> BinOpr op = getbinopr(ls->t.token);
> FuncState * fs=ls->fs;
> int tolevel=fs->nactvar;
> int old_free=fs->freereg;
> expdesc e,infix;
> int line=ls->linenumber;
> int nextra, i;
> luaX_next(ls);
>
> /* create temporary local variables to lock up any registers needed
> by VINDEXED lvalues. */
> lu_byte top=fs->nactvar;
> /* protect both the table and index result registers,
> ** ensuring that they won't be overwritten prior to the
> ** storevar calls. */
> if(v->k==VINDEXED) {
> if( /*!ISK( v->u.ind.t ) &&*/ v->u.ind.t >= top) {
> top= v->u.ind.t+1;
> }
> if( /*!ISK( v->u.ind.idx ) &&*/ v->u.ind.idx >= top) {
> top= v->u.ind.idx+1;
> }
> }
> nextra=top-fs->nactvar;
> if(nextra) {
> for(i=0;i<nextra;i++) {
> new_localvarliteral(ls,"(temp)");
> }
> adjustlocalvars(ls,nextra);
> }
>
> infix = *v;
> luaK_infix(fs,op,&infix);
> expr(ls, &e);
> luaK_posfix(fs, op, &infix, &e, line);
> luaK_storevar(fs, v, &infix);
> removevars(fs,tolevel);
>
> if(old_free<fs->freereg) {
> fs->freereg=old_free;
> }
> }
>
1353c1410
< ** restassign -> ',' suffixedexp restassign | '=' explist
---
> ** restassign -> ',' suffixedexp restassign | '=' explist | opeq expr
1369,1372c1426,1427
< else { /* restassign -> '=' explist */
< int nexps;
< checknext(ls, '=');
< nexps = explist(ls, &e);
---
> else if (testnext(ls, '=')) { /* restassign -> '=' explist */
> int nexps = explist(ls, &e);
1378c1433
< return; /* avoid default */
---
> return;
1380a1436,1439
> else if ( ls->t.token >= TK_PLUSEQ && ls->t.token <= TK_BXOREQ ) { /* restassign -> opeq expr */
> compound_assignment(ls,&lh->v,nvars);
> return;
> }
1384a1444
> // end PANIC
1819c1879
< if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */
---
> if (ls->t.token == '=' || ls->t.token == ',' || (ls->t.token >= TK_PLUSEQ && ls->t.token <= TK_BXOREQ) ) { /* stat -> assignment ? */