aboutsummaryrefslogtreecommitdiff
path: root/lparser.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-11-25 16:59:43 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-11-25 16:59:43 -0200
commit33b8a010324863ddb495768ebe9e92403c5116c8 (patch)
tree4007dcc42001b36e739a3af6366547b88dd8ad7b /lparser.c
parentd29ce757376dd309f097e8ff30dd2a9b14567575 (diff)
downloadlua-33b8a010324863ddb495768ebe9e92403c5116c8.tar.gz
lua-33b8a010324863ddb495768ebe9e92403c5116c8.tar.bz2
lua-33b8a010324863ddb495768ebe9e92403c5116c8.zip
new way to code CALLs + passing multiple arguments between function calls
Diffstat (limited to 'lparser.c')
-rw-r--r--lparser.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/lparser.c b/lparser.c
index c96ea0d0..4305cc1d 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.42 1999/11/04 17:23:12 roberto Exp roberto $ 2** $Id: lparser.c,v 1.43 1999/11/22 13:12:07 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*/
@@ -426,12 +426,9 @@ static void close_exp (LexState *ls, int pc, int nresults) {
426 if (pc > 0) { /* expression is an open function call? */ 426 if (pc > 0) { /* expression is an open function call? */
427 Byte *code = ls->fs->f->code; 427 Byte *code = ls->fs->f->code;
428 code[pc-1] = (Byte)nresults; /* set nresults */ 428 code[pc-1] = (Byte)nresults; /* set nresults */
429 /* push results, pop params (at code[pc]) and function */ 429 if (nresults != MULT_RET)
430 deltastack(ls, nresults-(code[pc]+1)); 430 deltastack(ls, nresults); /* push results */
431 } 431 }
432#ifdef DEBUG
433 code_oparg(ls, CHECKSTACK, ls->fs->stacksize, 0);
434#endif
435} 432}
436 433
437 434
@@ -1152,7 +1149,7 @@ static void var_or_func_tail (LexState *ls, vardesc *v) {
1152 1149
1153static int funcparams (LexState *ls, int slf) { 1150static int funcparams (LexState *ls, int slf) {
1154 FuncState *fs = ls->fs; 1151 FuncState *fs = ls->fs;
1155 int nparams = 1; /* in cases STRING and constructor */ 1152 int slevel = fs->stacksize - slf - 1; /* where is func in the stack */
1156 switch (ls->token) { 1153 switch (ls->token) {
1157 case '(': { /* funcparams -> '(' explist ')' */ 1154 case '(': { /* funcparams -> '(' explist ')' */
1158 int line = ls->linenumber; 1155 int line = ls->linenumber;
@@ -1160,8 +1157,7 @@ static int funcparams (LexState *ls, int slf) {
1160 next(ls); 1157 next(ls);
1161 explist(ls, &e); 1158 explist(ls, &e);
1162 check_match(ls, ')', '(', line); 1159 check_match(ls, ')', '(', line);
1163 close_exp(ls, e.pc, 1); 1160 close_exp(ls, e.pc, MULT_RET); /* close 1 for old semantics */
1164 nparams = e.n;
1165 break; 1161 break;
1166 } 1162 }
1167 1163
@@ -1180,7 +1176,8 @@ static int funcparams (LexState *ls, int slf) {
1180 } 1176 }
1181 code_byte(ls, CALL); 1177 code_byte(ls, CALL);
1182 code_byte(ls, 0); /* save space for nresult */ 1178 code_byte(ls, 0); /* save space for nresult */
1183 code_byte(ls, (Byte)(nparams+slf)); 1179 code_byte(ls, (Byte)slevel);
1180 fs->stacksize = slevel; /* call will remove func and params */
1184 return fs->pc-1; 1181 return fs->pc-1;
1185} 1182}
1186 1183