diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-06-11 11:56:42 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-06-11 11:56:42 -0300 |
| commit | 0a1b1acdd36a3ed4e6f1cadf62eec8531a437cbf (patch) | |
| tree | f7c4e2b02380381e65fb19956ab7921bba33be97 /lparser.c | |
| parent | 79acf5ea6083fe4aebeb24740d25ddf35654944a (diff) | |
| download | lua-0a1b1acdd36a3ed4e6f1cadf62eec8531a437cbf.tar.gz lua-0a1b1acdd36a3ed4e6f1cadf62eec8531a437cbf.tar.bz2 lua-0a1b1acdd36a3ed4e6f1cadf62eec8531a437cbf.zip | |
details about opcode parameters
Diffstat (limited to 'lparser.c')
| -rw-r--r-- | lparser.c | 22 |
1 files changed, 11 insertions, 11 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.146 2001/06/08 12:29:27 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.147 2001/06/08 19:00:57 roberto Exp roberto $ |
| 3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -415,7 +415,7 @@ static int explist1 (LexState *ls, expdesc *v) { | |||
| 415 | static void funcargs (LexState *ls, expdesc *f) { | 415 | static void funcargs (LexState *ls, expdesc *f) { |
| 416 | FuncState *fs = ls->fs; | 416 | FuncState *fs = ls->fs; |
| 417 | expdesc args; | 417 | expdesc args; |
| 418 | int base, top; | 418 | int base, nparams; |
| 419 | switch (ls->t.token) { | 419 | switch (ls->t.token) { |
| 420 | case l_c('('): { /* funcargs -> `(' [ explist1 ] `)' */ | 420 | case l_c('('): { /* funcargs -> `(' [ explist1 ] `)' */ |
| 421 | int line = ls->linenumber; | 421 | int line = ls->linenumber; |
| @@ -446,13 +446,13 @@ static void funcargs (LexState *ls, expdesc *f) { | |||
| 446 | lua_assert(f->k == VNONRELOC); | 446 | lua_assert(f->k == VNONRELOC); |
| 447 | base = f->u.i.info; /* base register for call */ | 447 | base = f->u.i.info; /* base register for call */ |
| 448 | if (args.k == VCALL) | 448 | if (args.k == VCALL) |
| 449 | top = NO_REG; /* open call */ | 449 | nparams = NO_REG; /* open call */ |
| 450 | else { | 450 | else { |
| 451 | if (args.k != VVOID) | 451 | if (args.k != VVOID) |
| 452 | luaK_exp2nextreg(fs, &args); /* close last argument */ | 452 | luaK_exp2nextreg(fs, &args); /* close last argument */ |
| 453 | top = fs->freereg; | 453 | nparams = fs->freereg - (base+1); |
| 454 | } | 454 | } |
| 455 | init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, top, base+1)); | 455 | init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams, 1)); |
| 456 | fs->freereg = base+1; /* call remove function and arguments and leaves | 456 | fs->freereg = base+1; /* call remove function and arguments and leaves |
| 457 | (unless changed) one result */ | 457 | (unless changed) one result */ |
| 458 | } | 458 | } |
| @@ -1091,31 +1091,31 @@ static void retstat (LexState *ls) { | |||
| 1091 | /* stat -> RETURN explist */ | 1091 | /* stat -> RETURN explist */ |
| 1092 | FuncState *fs = ls->fs; | 1092 | FuncState *fs = ls->fs; |
| 1093 | expdesc e; | 1093 | expdesc e; |
| 1094 | int first, last1; /* registers with returned values */ | 1094 | int first, nret; /* registers with returned values */ |
| 1095 | next(ls); /* skip RETURN */ | 1095 | next(ls); /* skip RETURN */ |
| 1096 | if (block_follow(ls->t.token) || ls->t.token == l_c(';')) | 1096 | if (block_follow(ls->t.token) || ls->t.token == l_c(';')) |
| 1097 | first = last1 = 0; /* return no values */ | 1097 | first = nret = 0; /* return no values */ |
| 1098 | else { | 1098 | else { |
| 1099 | int n = explist1(ls, &e); /* optional return values */ | 1099 | int n = explist1(ls, &e); /* optional return values */ |
| 1100 | if (e.k == VCALL) { | 1100 | if (e.k == VCALL) { |
| 1101 | luaK_setcallreturns(fs, &e, LUA_MULTRET); | 1101 | luaK_setcallreturns(fs, &e, LUA_MULTRET); |
| 1102 | first = fs->nactloc; | 1102 | first = fs->nactloc; |
| 1103 | last1 = NO_REG; /* return all values */ | 1103 | nret = NO_REG; /* return all values */ |
| 1104 | } | 1104 | } |
| 1105 | else { | 1105 | else { |
| 1106 | if (n == 1) { /* only one value? */ | 1106 | if (n == 1) { /* only one value? */ |
| 1107 | luaK_exp2anyreg(fs, &e); | 1107 | luaK_exp2anyreg(fs, &e); |
| 1108 | first = e.u.i.info; | 1108 | first = e.u.i.info; |
| 1109 | last1 = first+1; /* return only this value */ | 1109 | nret = 1; /* return only this value */ |
| 1110 | } | 1110 | } |
| 1111 | else { | 1111 | else { |
| 1112 | luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */ | 1112 | luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */ |
| 1113 | first = fs->nactloc; | 1113 | first = fs->nactloc; |
| 1114 | last1 = fs->freereg; /* return all `active' values */ | 1114 | nret = fs->freereg - first; /* return all `active' values */ |
| 1115 | } | 1115 | } |
| 1116 | } | 1116 | } |
| 1117 | } | 1117 | } |
| 1118 | luaK_codeABC(fs, OP_RETURN, first, last1, 0); | 1118 | luaK_codeABC(fs, OP_RETURN, first, nret, 0); |
| 1119 | fs->freereg = fs->nactloc; /* removes all temp values */ | 1119 | fs->freereg = fs->nactloc; /* removes all temp values */ |
| 1120 | } | 1120 | } |
| 1121 | 1121 | ||
