aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ldo.c6
-rw-r--r--llex.c7
-rw-r--r--llex.h4
-rw-r--r--lparser.c6
-rw-r--r--lparser.h4
-rw-r--r--lundump.c6
-rw-r--r--lzio.c33
-rw-r--r--lzio.h4
8 files changed, 29 insertions, 41 deletions
diff --git a/ldo.c b/ldo.c
index 1b4768b6..7c59e663 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.91 2011/02/04 17:34:43 roberto Exp roberto $ 2** $Id: ldo.c,v 2.92 2011/02/07 17:14:50 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -625,10 +625,10 @@ static void f_parser (lua_State *L, void *ud) {
625 Proto *tf; 625 Proto *tf;
626 Closure *cl; 626 Closure *cl;
627 struct SParser *p = cast(struct SParser *, ud); 627 struct SParser *p = cast(struct SParser *, ud);
628 int c = luaZ_lookahead(p->z); 628 int c = zgetc(p->z); /* read first character */
629 tf = (c == LUA_SIGNATURE[0]) 629 tf = (c == LUA_SIGNATURE[0])
630 ? luaU_undump(L, p->z, &p->buff, p->name) 630 ? luaU_undump(L, p->z, &p->buff, p->name)
631 : luaY_parser(L, p->z, &p->buff, &p->dyd, p->name); 631 : luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);
632 setptvalue2s(L, L->top, tf); 632 setptvalue2s(L, L->top, tf);
633 incr_top(L); 633 incr_top(L);
634 cl = luaF_newLclosure(L, tf); 634 cl = luaF_newLclosure(L, tf);
diff --git a/llex.c b/llex.c
index 68ccfc82..4e0b7a58 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 2.44 2011/01/26 16:30:02 roberto Exp roberto $ 2** $Id: llex.c,v 2.45 2011/02/02 14:55:17 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*/
@@ -152,9 +152,11 @@ static void inclinenumber (LexState *ls) {
152} 152}
153 153
154 154
155void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { 155void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
156 int firstchar) {
156 ls->decpoint = '.'; 157 ls->decpoint = '.';
157 ls->L = L; 158 ls->L = L;
159 ls->current = firstchar;
158 ls->lookahead.token = TK_EOS; /* no look-ahead token */ 160 ls->lookahead.token = TK_EOS; /* no look-ahead token */
159 ls->z = z; 161 ls->z = z;
160 ls->fs = NULL; 162 ls->fs = NULL;
@@ -164,7 +166,6 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
164 ls->envn = luaS_new(L, LUA_ENV); /* create env name */ 166 ls->envn = luaS_new(L, LUA_ENV); /* create env name */
165 luaS_fix(ls->envn); /* never collect this name */ 167 luaS_fix(ls->envn); /* never collect this name */
166 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ 168 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
167 next(ls); /* read first char */
168} 169}
169 170
170 171
diff --git a/llex.h b/llex.h
index 3c45f845..01a40317 100644
--- a/llex.h
+++ b/llex.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.h,v 1.67 2011/02/04 17:34:43 roberto Exp roberto $ 2** $Id: llex.h,v 1.68 2011/02/07 17:14:50 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*/
@@ -69,7 +69,7 @@ typedef struct LexState {
69 69
70LUAI_FUNC void luaX_init (lua_State *L); 70LUAI_FUNC void luaX_init (lua_State *L);
71LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 71LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
72 TString *source); 72 TString *source, int firstchar);
73LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 73LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
74LUAI_FUNC void luaX_next (LexState *ls); 74LUAI_FUNC void luaX_next (LexState *ls);
75LUAI_FUNC int luaX_lookahead (LexState *ls); 75LUAI_FUNC int luaX_lookahead (LexState *ls);
diff --git a/lparser.c b/lparser.c
index 56cd417a..41ba802d 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.105 2011/02/14 14:59:28 roberto Exp roberto $ 2** $Id: lparser.c,v 2.106 2011/02/14 16:36:34 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -1568,7 +1568,7 @@ static void statement (LexState *ls) {
1568 1568
1569 1569
1570Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 1570Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
1571 Dyndata *dyd, const char *name) { 1571 Dyndata *dyd, const char *name, int firstchar) {
1572 LexState lexstate; 1572 LexState lexstate;
1573 FuncState funcstate; 1573 FuncState funcstate;
1574 BlockCnt bl; 1574 BlockCnt bl;
@@ -1578,7 +1578,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
1578 lexstate.buff = buff; 1578 lexstate.buff = buff;
1579 lexstate.dyd = dyd; 1579 lexstate.dyd = dyd;
1580 dyd->actvar.n = dyd->gt.n = dyd->label.n = 0; 1580 dyd->actvar.n = dyd->gt.n = dyd->label.n = 0;
1581 luaX_setinput(L, &lexstate, z, tname); 1581 luaX_setinput(L, &lexstate, z, tname, firstchar);
1582 open_mainfunc(&lexstate, &funcstate, &bl); 1582 open_mainfunc(&lexstate, &funcstate, &bl);
1583 luaX_next(&lexstate); /* read first token */ 1583 luaX_next(&lexstate); /* read first token */
1584 statlist(&lexstate); /* main body */ 1584 statlist(&lexstate); /* main body */
diff --git a/lparser.h b/lparser.h
index 5626d100..de37e125 100644
--- a/lparser.h
+++ b/lparser.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.h,v 1.66 2011/02/04 17:34:43 roberto Exp roberto $ 2** $Id: lparser.h,v 1.67 2011/02/07 17:14:50 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -114,7 +114,7 @@ typedef struct FuncState {
114 114
115 115
116LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 116LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
117 Dyndata *dyd, const char *name); 117 Dyndata *dyd, const char *name, int firstchar);
118 118
119 119
120#endif 120#endif
diff --git a/lundump.c b/lundump.c
index 161ef1d4..170c9ece 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 2.14 2010/10/25 14:33:38 roberto Exp roberto $ 2** $Id: lundump.c,v 2.15 2011/02/07 19:15:24 roberto Exp roberto $
3** load precompiled Lua chunks 3** load precompiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -180,8 +180,8 @@ static void LoadHeader(LoadState* S)
180 char h[LUAC_HEADERSIZE]; 180 char h[LUAC_HEADERSIZE];
181 char s[LUAC_HEADERSIZE]; 181 char s[LUAC_HEADERSIZE];
182 luaU_header(h); 182 luaU_header(h);
183 LoadBlock(S,s,LUAC_HEADERSIZE); 183 LoadBlock(S,s,LUAC_HEADERSIZE-1); /* 1st char already read */
184 if (memcmp(h,s,LUAC_HEADERSIZE)!=0) error(S,"incompatible"); 184 if (memcmp(h+1,s,LUAC_HEADERSIZE-1)!=0) error(S,"incompatible");
185} 185}
186 186
187/* 187/*
diff --git a/lzio.c b/lzio.c
index 24826f68..a2720333 100644
--- a/lzio.c
+++ b/lzio.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lzio.c,v 1.31 2005/06/03 20:15:29 roberto Exp roberto $ 2** $Id: lzio.c,v 1.32 2011/02/17 17:34:16 roberto Exp roberto $
3** a generic input stream interface 3** a generic input stream interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -22,40 +22,23 @@ int luaZ_fill (ZIO *z) {
22 size_t size; 22 size_t size;
23 lua_State *L = z->L; 23 lua_State *L = z->L;
24 const char *buff; 24 const char *buff;
25 if (z->eoz) return EOZ;
26 lua_unlock(L); 25 lua_unlock(L);
27 buff = z->reader(L, z->data, &size); 26 buff = z->reader(L, z->data, &size);
28 lua_lock(L); 27 lua_lock(L);
29 if (buff == NULL || size == 0) { 28 if (buff == NULL || size == 0)
30 z->eoz = 1; /* avoid calling reader function next time */
31 return EOZ; 29 return EOZ;
32 } 30 z->n = size - 1; /* discount char being returned */
33 z->n = size - 1;
34 z->p = buff; 31 z->p = buff;
35 return char2int(*(z->p++)); 32 return char2int(*(z->p++));
36} 33}
37 34
38 35
39int luaZ_lookahead (ZIO *z) {
40 if (z->n == 0) {
41 if (luaZ_fill(z) == EOZ)
42 return EOZ;
43 else {
44 z->n++; /* luaZ_fill removed first byte; put back it */
45 z->p--;
46 }
47 }
48 return char2int(*z->p);
49}
50
51
52void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 36void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
53 z->L = L; 37 z->L = L;
54 z->reader = reader; 38 z->reader = reader;
55 z->data = data; 39 z->data = data;
56 z->n = 0; 40 z->n = 0;
57 z->p = NULL; 41 z->p = NULL;
58 z->eoz = 0;
59} 42}
60 43
61 44
@@ -63,8 +46,14 @@ void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
63size_t luaZ_read (ZIO *z, void *b, size_t n) { 46size_t luaZ_read (ZIO *z, void *b, size_t n) {
64 while (n) { 47 while (n) {
65 size_t m; 48 size_t m;
66 if (luaZ_lookahead(z) == EOZ) 49 if (z->n == 0) { /* no bytes in buffer? */
67 return n; /* return number of missing bytes */ 50 if (luaZ_fill(z) == EOZ) /* try to read more */
51 return n; /* no more input; return number of missing bytes */
52 else {
53 z->n++; /* luaZ_fill consumed first byte; put it back */
54 z->p--;
55 }
56 }
68 m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 57 m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
69 memcpy(b, z->p, m); 58 memcpy(b, z->p, m);
70 z->n -= m; 59 z->n -= m;
diff --git a/lzio.h b/lzio.h
index 36a00900..2c666ab3 100644
--- a/lzio.h
+++ b/lzio.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lzio.h,v 1.22 2009/05/18 17:26:25 roberto Exp roberto $ 2** $Id: lzio.h,v 1.23 2011/02/17 17:34:16 roberto Exp roberto $
3** Buffered streams 3** Buffered streams
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -50,7 +50,6 @@ LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
50LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 50LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
51 void *data); 51 void *data);
52LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ 52LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
53LUAI_FUNC int luaZ_lookahead (ZIO *z);
54 53
55 54
56 55
@@ -62,7 +61,6 @@ struct Zio {
62 lua_Reader reader; /* reader function */ 61 lua_Reader reader; /* reader function */
63 void* data; /* additional data */ 62 void* data; /* additional data */
64 lua_State *L; /* Lua state (for reader) */ 63 lua_State *L; /* Lua state (for reader) */
65 int eoz; /* true if reader has no more data */
66}; 64};
67 65
68 66