aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lparser.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/lparser.c b/lparser.c
index 0ba30b5e..92effa5a 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.38 1999/07/22 19:29:42 roberto Exp roberto $ 2** $Id: lparser.c,v 1.39 1999/08/16 20:52:00 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*/
@@ -52,7 +52,7 @@
52 52
53/* 53/*
54** Variable descriptor: 54** Variable descriptor:
55** must include an "exp" option because LL(1) cannot distinguish 55** must include an `exp' option because LL(1) cannot distinguish
56** between variables, upvalues and function calls on first sight. 56** between variables, upvalues and function calls on first sight.
57*/ 57*/
58typedef enum { 58typedef enum {
@@ -60,7 +60,7 @@ typedef enum {
60 VLOCAL, /* info is stack index */ 60 VLOCAL, /* info is stack index */
61 VDOT, /* info is constant index of index name */ 61 VDOT, /* info is constant index of index name */
62 VINDEXED, /* no info (table and index are on the stack) */ 62 VINDEXED, /* no info (table and index are on the stack) */
63 VEXP /* info is pc index of "nparam" of a call (or 0 if exp is closed) */ 63 VEXP /* info is pc index of `nparam' of a call (or 0 if exp is closed) */
64} varkind; 64} varkind;
65 65
66typedef struct vardesc { 66typedef struct vardesc {
@@ -83,7 +83,7 @@ typedef struct listdesc {
83 83
84/* 84/*
85** Constructors descriptor: 85** Constructors descriptor:
86** "n" indicates number of elements, and "k" signals whether 86** `n' indicates number of elements, and `k' signals whether
87** it is a list constructor (k = 0) or a record constructor (k = 1) 87** it is a list constructor (k = 0) or a record constructor (k = 1)
88** or empty (k = ';' or '}') 88** or empty (k = ';' or '}')
89*/ 89*/
@@ -451,7 +451,7 @@ static void adjust_mult_assign (LexState *ls, int nvars, listdesc *d) {
451 451
452static void code_args (LexState *ls, int nparams, int dots) { 452static void code_args (LexState *ls, int nparams, int dots) {
453 FuncState *fs = ls->fs; 453 FuncState *fs = ls->fs;
454 fs->nlocalvar += nparams; /* "self" may already be there */ 454 fs->nlocalvar += nparams; /* `self' may already be there */
455 checklimit(ls, fs->nlocalvar, MAXPARAMS, "parameters"); 455 checklimit(ls, fs->nlocalvar, MAXPARAMS, "parameters");
456 nparams = fs->nlocalvar; 456 nparams = fs->nlocalvar;
457 if (!dots) { 457 if (!dots) {
@@ -666,7 +666,8 @@ static int checkname (LexState *ls) {
666 666
667 667
668static TaggedString *str_checkname (LexState *ls) { 668static TaggedString *str_checkname (LexState *ls) {
669 return tsvalue(&ls->fs->f->consts[checkname(ls)]); 669 int i = checkname(ls); /* this call may realloc `f->consts' */
670 return tsvalue(&ls->fs->f->consts[i]);
670} 671}
671 672
672 673
@@ -794,7 +795,7 @@ static int stat (LexState *ls) {
794 } 795 }
795 else { /* stat -> ['%'] NAME assignment */ 796 else { /* stat -> ['%'] NAME assignment */
796 int left = assignment(ls, &v, 1); 797 int left = assignment(ls, &v, 1);
797 adjuststack(ls, left); /* remove eventual 'garbage' left on stack */ 798 adjuststack(ls, left); /* remove eventual garbage left on stack */
798 } 799 }
799 return 1; 800 return 1;
800 } 801 }
@@ -987,7 +988,7 @@ static void simpleexp (LexState *ls, vardesc *v, stack_op *s) {
987 real r = ls->seminfo.r; 988 real r = ls->seminfo.r;
988 next(ls); 989 next(ls);
989 /* dirty trick: check whether it is a -NUMBER not followed by '^' */ 990 /* dirty trick: check whether it is a -NUMBER not followed by '^' */
990 /* (because the priority of '^' is closer than '-'...) */ 991 /* (because the priority of '^' is higher than '-'...) */
991 if (s->top > 0 && s->ops[s->top-1] == INDMINUS && ls->token != '^') { 992 if (s->top > 0 && s->ops[s->top-1] == INDMINUS && ls->token != '^') {
992 s->top--; /* remove '-' from stack */ 993 s->top--; /* remove '-' from stack */
993 r = -r; 994 r = -r;
@@ -997,7 +998,7 @@ static void simpleexp (LexState *ls, vardesc *v, stack_op *s) {
997 } 998 }
998 999
999 case STRING: /* simpleexp -> STRING */ 1000 case STRING: /* simpleexp -> STRING */
1000 code_string(ls, ls->seminfo.ts); /* must use 'seminfo' before "next" */ 1001 code_string(ls, ls->seminfo.ts); /* must use 'seminfo' before `next' */
1001 next(ls); 1002 next(ls);
1002 break; 1003 break;
1003 1004
@@ -1083,14 +1084,14 @@ static void var_or_func_tail (LexState *ls, vardesc *v) {
1083 switch (ls->token) { 1084 switch (ls->token) {
1084 case '.': /* var_or_func_tail -> '.' NAME */ 1085 case '.': /* var_or_func_tail -> '.' NAME */
1085 next(ls); 1086 next(ls);
1086 lua_pushvar(ls, v); /* 'v' must be on stack */ 1087 lua_pushvar(ls, v); /* `v' must be on stack */
1087 v->k = VDOT; 1088 v->k = VDOT;
1088 v->info = checkname(ls); 1089 v->info = checkname(ls);
1089 break; 1090 break;
1090 1091
1091 case '[': /* var_or_func_tail -> '[' exp1 ']' */ 1092 case '[': /* var_or_func_tail -> '[' exp1 ']' */
1092 next(ls); 1093 next(ls);
1093 lua_pushvar(ls, v); /* 'v' must be on stack */ 1094 lua_pushvar(ls, v); /* `v' must be on stack */
1094 exp1(ls); 1095 exp1(ls);
1095 check(ls, ']'); 1096 check(ls, ']');
1096 v->k = VINDEXED; 1097 v->k = VINDEXED;
@@ -1098,14 +1099,14 @@ static void var_or_func_tail (LexState *ls, vardesc *v) {
1098 1099
1099 case ':': /* var_or_func_tail -> ':' NAME funcparams */ 1100 case ':': /* var_or_func_tail -> ':' NAME funcparams */
1100 next(ls); 1101 next(ls);
1101 lua_pushvar(ls, v); /* 'v' must be on stack */ 1102 lua_pushvar(ls, v); /* `v' must be on stack */
1102 code_oparg(ls, PUSHSELF, checkname(ls), 1); 1103 code_oparg(ls, PUSHSELF, checkname(ls), 1);
1103 v->k = VEXP; 1104 v->k = VEXP;
1104 v->info = funcparams(ls, 1); 1105 v->info = funcparams(ls, 1);
1105 break; 1106 break;
1106 1107
1107 case '(': case STRING: case '{': /* var_or_func_tail -> funcparams */ 1108 case '(': case STRING: case '{': /* var_or_func_tail -> funcparams */
1108 lua_pushvar(ls, v); /* 'v' must be on stack */ 1109 lua_pushvar(ls, v); /* `v' must be on stack */
1109 v->k = VEXP; 1110 v->k = VEXP;
1110 v->info = funcparams(ls, 0); 1111 v->info = funcparams(ls, 0);
1111 break; 1112 break;
@@ -1135,7 +1136,7 @@ static int funcparams (LexState *ls, int slf) {
1135 break; 1136 break;
1136 1137
1137 case STRING: /* funcparams -> STRING */ 1138 case STRING: /* funcparams -> STRING */
1138 code_string(ls, ls->seminfo.ts); /* must use 'seminfo' before "next" */ 1139 code_string(ls, ls->seminfo.ts); /* must use 'seminfo' before `next' */
1139 next(ls); 1140 next(ls);
1140 break; 1141 break;
1141 1142