aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-06-19 15:05:14 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-06-19 15:05:14 -0300
commitfeb2083730c718b8fa7de6824db1c1dfe7a5542a (patch)
tree29dda71837b7085a1d87caf8c95022442f0c70a8
parent8d2baf719cf8687dba1648da4c5d9450d0bb2c14 (diff)
downloadlua-feb2083730c718b8fa7de6824db1c1dfe7a5542a.tar.gz
lua-feb2083730c718b8fa7de6824db1c1dfe7a5542a.tar.bz2
lua-feb2083730c718b8fa7de6824db1c1dfe7a5542a.zip
better control of source name
-rw-r--r--llex.c7
-rw-r--r--llex.h5
-rw-r--r--lparser.c12
3 files changed, 13 insertions, 11 deletions
diff --git a/llex.c b/llex.c
index a49358f8..f251ab9c 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 1.62 2000/05/26 14:04:04 roberto Exp roberto $ 2** $Id: llex.c,v 1.63 2000/06/12 13:52:05 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -63,7 +63,7 @@ void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) {
63 63
64void luaX_syntaxerror (LexState *ls, const char *s, const char *token) { 64void luaX_syntaxerror (LexState *ls, const char *s, const char *token) {
65 char buff[MAXSRC]; 65 char buff[MAXSRC];
66 luaL_chunkid(buff, zname(ls->z), sizeof(buff)); 66 luaL_chunkid(buff, ls->source->str, sizeof(buff));
67 luaL_verror(ls->L, "%.100s;\n last token read: `%.50s' at line %d in %.80s", 67 luaL_verror(ls->L, "%.100s;\n last token read: `%.50s' at line %d in %.80s",
68 s, token, ls->linenumber, buff); 68 s, token, ls->linenumber, buff);
69} 69}
@@ -132,12 +132,13 @@ static void checkpragma (lua_State *L, LexState *LS) {
132} 132}
133 133
134 134
135void luaX_setinput (lua_State *L, LexState *LS, ZIO *z) { 135void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source) {
136 LS->L = L; 136 LS->L = L;
137 LS->lookahead.token = TK_EOS; /* no look-ahead token */ 137 LS->lookahead.token = TK_EOS; /* no look-ahead token */
138 LS->z = z; 138 LS->z = z;
139 LS->fs = NULL; 139 LS->fs = NULL;
140 LS->linenumber = 1; 140 LS->linenumber = 1;
141 LS->source = source;
141 next(LS); /* read first char */ 142 next(LS); /* read first char */
142 if (LS->current == '#') { 143 if (LS->current == '#') {
143 do { /* skip first line */ 144 do { /* skip first line */
diff --git a/llex.h b/llex.h
index 8dba8721..8528dc20 100644
--- a/llex.h
+++ b/llex.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.h,v 1.27 2000/05/25 18:59:59 roberto Exp roberto $ 2** $Id: llex.h,v 1.28 2000/05/26 14:04:04 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -51,11 +51,12 @@ typedef struct LexState {
51 struct lua_State *L; 51 struct lua_State *L;
52 struct zio *z; /* input stream */ 52 struct zio *z; /* input stream */
53 int linenumber; /* input line counter */ 53 int linenumber; /* input line counter */
54 TString *source; /* current source name */
54} LexState; 55} LexState;
55 56
56 57
57void luaX_init (lua_State *L); 58void luaX_init (lua_State *L);
58void luaX_setinput (lua_State *L, LexState *LS, ZIO *z); 59void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source);
59int luaX_lex (LexState *LS); 60int luaX_lex (LexState *LS);
60void luaX_checklimit (LexState *ls, int val, int limit, const char *msg); 61void luaX_checklimit (LexState *ls, int val, int limit, const char *msg);
61void luaX_syntaxerror (LexState *ls, const char *s, const char *token); 62void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
diff --git a/lparser.c b/lparser.c
index daa796b6..9955f6db 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.94 2000/06/05 14:56:18 roberto Exp roberto $ 2** $Id: lparser.c,v 1.95 2000/06/12 13:52:05 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*/
@@ -352,7 +352,7 @@ static void pushclosure (LexState *ls, FuncState *func) {
352} 352}
353 353
354 354
355static void open_func (LexState *ls, FuncState *fs, TString *source) { 355static void open_func (LexState *ls, FuncState *fs) {
356 Proto *f = luaF_newproto(ls->L); 356 Proto *f = luaF_newproto(ls->L);
357 fs->prev = ls->fs; /* linked list of funcstates */ 357 fs->prev = ls->fs; /* linked list of funcstates */
358 fs->ls = ls; 358 fs->ls = ls;
@@ -364,7 +364,7 @@ static void open_func (LexState *ls, FuncState *fs, TString *source) {
364 fs->lastsetline = 0; 364 fs->lastsetline = 0;
365 fs->bl = NULL; 365 fs->bl = NULL;
366 fs->f = f; 366 fs->f = f;
367 f->source = source; 367 f->source = ls->source;
368 fs->pc = 0; 368 fs->pc = 0;
369 fs->lasttarget = 0; 369 fs->lasttarget = 0;
370 fs->jlt = NO_JUMP; 370 fs->jlt = NO_JUMP;
@@ -398,8 +398,8 @@ static void close_func (LexState *ls) {
398Proto *luaY_parser (lua_State *L, ZIO *z) { 398Proto *luaY_parser (lua_State *L, ZIO *z) {
399 struct LexState lexstate; 399 struct LexState lexstate;
400 struct FuncState funcstate; 400 struct FuncState funcstate;
401 luaX_setinput(L, &lexstate, z); 401 luaX_setinput(L, &lexstate, z, luaS_new(L, zname(z)));
402 open_func(&lexstate, &funcstate, luaS_new(L, zname(z))); 402 open_func(&lexstate, &funcstate);
403 next(&lexstate); /* read first token */ 403 next(&lexstate); /* read first token */
404 chunk(&lexstate); 404 chunk(&lexstate);
405 check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected"); 405 check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected");
@@ -1128,7 +1128,7 @@ static void parlist (LexState *ls) {
1128static void body (LexState *ls, int needself, int line) { 1128static void body (LexState *ls, int needself, int line) {
1129 /* body -> '(' parlist ')' chunk END */ 1129 /* body -> '(' parlist ')' chunk END */
1130 FuncState new_fs; 1130 FuncState new_fs;
1131 open_func(ls, &new_fs, ls->fs->f->source); 1131 open_func(ls, &new_fs);
1132 new_fs.f->lineDefined = line; 1132 new_fs.f->lineDefined = line;
1133 check(ls, '('); 1133 check(ls, '(');
1134 if (needself) 1134 if (needself)