aboutsummaryrefslogtreecommitdiff
path: root/lparser.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-03-05 18:16:07 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-03-05 18:16:07 -0300
commit0870a2d1d8a1434eecae1923886ba219c4e699c7 (patch)
tree3ca86564265ec369f3108ac286c61445ad50db14 /lparser.c
parent78edc241e95d467e2b6c9a26b5311a62c7b04459 (diff)
downloadlua-0870a2d1d8a1434eecae1923886ba219c4e699c7.tar.gz
lua-0870a2d1d8a1434eecae1923886ba219c4e699c7.tar.bz2
lua-0870a2d1d8a1434eecae1923886ba219c4e699c7.zip
new opcode TAILCALL
Diffstat (limited to 'lparser.c')
-rw-r--r--lparser.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/lparser.c b/lparser.c
index a30c3777..eb1e0236 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.25 1999/02/26 15:48:55 roberto Exp roberto $ 2** $Id: lparser.c,v 1.26 1999/03/04 21:17:26 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*/
@@ -387,16 +387,14 @@ static void adjuststack (LexState *ls, int n) {
387 387
388 388
389static void close_exp (LexState *ls, int pc, int nresults) { 389static void close_exp (LexState *ls, int pc, int nresults) {
390 if (pc > 0) { /* expression is an open function call */ 390 if (pc > 0) { /* expression is an open function call? */
391 Byte *code = ls->fs->f->code; 391 Byte *code = ls->fs->f->code;
392 code[pc-1] = (Byte)nresults; /* set nresults */ 392 code[pc-1] = (Byte)nresults; /* set nresults */
393 if (nresults != MULT_RET) 393 /* push results, pop params (at code[pc]) and function */
394 deltastack(ls, nresults); /* push results */ 394 deltastack(ls, nresults-(code[pc]+1));
395 deltastack(ls, -(code[pc]+1)); /* pop params (at code[pc]) and function */
396 } 395 }
397#ifdef DEBUG 396#ifdef DEBUG
398 if (nresults != MULT_RET) 397 code_oparg(ls, CHECKSTACK, ls->fs->stacksize, 0);
399 code_oparg(ls, CHECKSTACK, ls->fs->stacksize, 0);
400#endif 398#endif
401} 399}
402 400
@@ -878,9 +876,14 @@ static void ret (LexState *ls) {
878 check_debugline(ls); 876 check_debugline(ls);
879 if (optional(ls, RETURN)) { 877 if (optional(ls, RETURN)) {
880 listdesc e; 878 listdesc e;
881 explist(ls, &e); 879 explist(ls, &e);
882 close_exp(ls, e.pc, MULT_RET); 880 if (e.pc > 0) { /* expression is an open function call? */
883 code_oparg(ls, RETCODE, ls->fs->nlocalvar, 0); 881 Byte *code = ls->fs->f->code;
882 code[e.pc-2] = TAILCALL; /* instead of a conventional CALL */
883 code[e.pc-1] = (Byte)ls->fs->nlocalvar;
884 }
885 else
886 code_oparg(ls, RETCODE, ls->fs->nlocalvar, 0);
884 ls->fs->stacksize = ls->fs->nlocalvar; /* removes all temp values */ 887 ls->fs->stacksize = ls->fs->nlocalvar; /* removes all temp values */
885 optional(ls, ';'); 888 optional(ls, ';');
886 } 889 }