diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-12-22 18:57:18 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-12-22 18:57:18 -0200 |
| commit | 03f3f9e707ceaf46efb4917f8d32ea62283b9358 (patch) | |
| tree | cdf8e8d255fc95e09b94521dff35cd4f0f57d1e6 | |
| parent | a78eecee48c725549316629b9a8d936c990b65de (diff) | |
| download | lua-03f3f9e707ceaf46efb4917f8d32ea62283b9358.tar.gz lua-03f3f9e707ceaf46efb4917f8d32ea62283b9358.tar.bz2 lua-03f3f9e707ceaf46efb4917f8d32ea62283b9358.zip | |
"zio" now keeps its "name".
| -rw-r--r-- | ldo.c | 28 | ||||
| -rw-r--r-- | lparser.h | 4 | ||||
| -rw-r--r-- | lua.stx | 6 | ||||
| -rw-r--r-- | lzio.c | 12 | ||||
| -rw-r--r-- | lzio.h | 11 |
5 files changed, 32 insertions, 29 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.16 1997/12/17 20:57:20 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.17 1997/12/18 18:32:39 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 | */ |
| @@ -296,7 +296,7 @@ int luaD_protectedrun (int nResults) | |||
| 296 | /* | 296 | /* |
| 297 | ** returns 0 = chunk loaded; 1 = error; 2 = no more chunks to load | 297 | ** returns 0 = chunk loaded; 1 = error; 2 = no more chunks to load |
| 298 | */ | 298 | */ |
| 299 | static int protectedparser (ZIO *z, char *chunkname, int bin) | 299 | static int protectedparser (ZIO *z, int bin) |
| 300 | { | 300 | { |
| 301 | int status; | 301 | int status; |
| 302 | TProtoFunc *tf; | 302 | TProtoFunc *tf; |
| @@ -304,7 +304,7 @@ static int protectedparser (ZIO *z, char *chunkname, int bin) | |||
| 304 | jmp_buf *oldErr = L->errorJmp; | 304 | jmp_buf *oldErr = L->errorJmp; |
| 305 | L->errorJmp = &myErrorJmp; | 305 | L->errorJmp = &myErrorJmp; |
| 306 | if (setjmp(myErrorJmp) == 0) { | 306 | if (setjmp(myErrorJmp) == 0) { |
| 307 | tf = bin ? luaU_undump1(z, chunkname) : luaY_parser(z, chunkname); | 307 | tf = bin ? luaU_undump1(z) : luaY_parser(z); |
| 308 | status = 0; | 308 | status = 0; |
| 309 | } | 309 | } |
| 310 | else { | 310 | else { |
| @@ -322,12 +322,12 @@ static int protectedparser (ZIO *z, char *chunkname, int bin) | |||
| 322 | } | 322 | } |
| 323 | 323 | ||
| 324 | 324 | ||
| 325 | static int do_main (ZIO *z, char *chunkname, int bin) | 325 | static int do_main (ZIO *z, int bin) |
| 326 | { | 326 | { |
| 327 | int status; | 327 | int status; |
| 328 | do { | 328 | do { |
| 329 | long old_blocks = (luaC_checkGC(), L->nblocks); | 329 | long old_blocks = (luaC_checkGC(), L->nblocks); |
| 330 | status = protectedparser(z, chunkname, bin); | 330 | status = protectedparser(z, bin); |
| 331 | if (status == 1) return 1; /* error */ | 331 | if (status == 1) return 1; /* error */ |
| 332 | else if (status == 2) return 0; /* 'natural' end */ | 332 | else if (status == 2) return 0; /* 'natural' end */ |
| 333 | else { | 333 | else { |
| @@ -368,8 +368,8 @@ int lua_dofile (char *filename) | |||
| 368 | bin = (c == ID_CHUNK); | 368 | bin = (c == ID_CHUNK); |
| 369 | if (bin) | 369 | if (bin) |
| 370 | f = freopen(filename, "rb", f); /* set binary mode */ | 370 | f = freopen(filename, "rb", f); /* set binary mode */ |
| 371 | luaZ_Fopen(&z, f); | 371 | luaZ_Fopen(&z, f, filename); |
| 372 | status = do_main(&z, filename, bin); | 372 | status = do_main(&z, bin); |
| 373 | if (f != stdin) | 373 | if (f != stdin) |
| 374 | fclose(f); | 374 | fclose(f); |
| 375 | return status; | 375 | return status; |
| @@ -383,15 +383,15 @@ int lua_dofile (char *filename) | |||
| 383 | int lua_dostring (char *str) | 383 | int lua_dostring (char *str) |
| 384 | { | 384 | { |
| 385 | int status; | 385 | int status; |
| 386 | char buff[SIZE_PREF+25]; | 386 | char name[SIZE_PREF+25]; |
| 387 | char *temp; | 387 | char *temp; |
| 388 | ZIO z; | 388 | ZIO z; |
| 389 | if (str == NULL) return 1; | 389 | if (str == NULL) return 1; |
| 390 | sprintf(buff, "(dostring) >> %." SSIZE_PREF "s", str); | 390 | sprintf(name, "(dostring) >> %." SSIZE_PREF "s", str); |
| 391 | temp = strchr(buff, '\n'); | 391 | temp = strchr(name, '\n'); |
| 392 | if (temp) *temp = 0; /* end string after first line */ | 392 | if (temp) *temp = 0; /* end string after first line */ |
| 393 | luaZ_sopen(&z, str); | 393 | luaZ_sopen(&z, str, name); |
| 394 | status = do_main(&z, buff, 0); | 394 | status = do_main(&z, 0); |
| 395 | return status; | 395 | return status; |
| 396 | } | 396 | } |
| 397 | 397 | ||
| @@ -401,8 +401,8 @@ int lua_dobuffer (char *buff, int size) | |||
| 401 | { | 401 | { |
| 402 | int status; | 402 | int status; |
| 403 | ZIO z; | 403 | ZIO z; |
| 404 | luaZ_mopen(&z, buff, size); | 404 | luaZ_mopen(&z, buff, size, "(buffer)"); |
| 405 | status = do_main(&z, "(buffer)", 1); | 405 | status = do_main(&z, 1); |
| 406 | return status; | 406 | return status; |
| 407 | } | 407 | } |
| 408 | #endif | 408 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: $ | 2 | ** $Id: lparser.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ |
| 3 | ** Syntax analizer and code generator | 3 | ** Syntax analizer and code generator |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -12,7 +12,7 @@ | |||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | void luaY_codedebugline (int line); | 14 | void luaY_codedebugline (int line); |
| 15 | TProtoFunc *luaY_parser (ZIO *z, char *chunkname); | 15 | TProtoFunc *luaY_parser (ZIO *z); |
| 16 | void luaY_error (char *s); | 16 | void luaY_error (char *s); |
| 17 | void luaY_syntaxerror (char *s, char *token); | 17 | void luaY_syntaxerror (char *s, char *token); |
| 18 | 18 | ||
| @@ -1,6 +1,6 @@ | |||
| 1 | %{ | 1 | %{ |
| 2 | /* | 2 | /* |
| 3 | ** $Id: lua.stx,v 1.23 1997/12/15 16:17:20 roberto Exp roberto $ | 3 | ** $Id: lua.stx,v 1.24 1997/12/22 17:24:11 roberto Exp roberto $ |
| 4 | ** Syntax analizer and code generator | 4 | ** Syntax analizer and code generator |
| 5 | ** See Copyright Notice in lua.h | 5 | ** See Copyright Notice in lua.h |
| 6 | */ | 6 | */ |
| @@ -619,14 +619,14 @@ static TProtoFunc *close_func (void) | |||
| 619 | /* | 619 | /* |
| 620 | ** Parse Lua code. | 620 | ** Parse Lua code. |
| 621 | */ | 621 | */ |
| 622 | TProtoFunc *luaY_parser (ZIO *z, char *chunkname) | 622 | TProtoFunc *luaY_parser (ZIO *z) |
| 623 | { | 623 | { |
| 624 | struct LexState lexstate; | 624 | struct LexState lexstate; |
| 625 | FuncState state[MAXSTATES]; | 625 | FuncState state[MAXSTATES]; |
| 626 | L->currState = L->mainState = &state[0]; | 626 | L->currState = L->mainState = &state[0]; |
| 627 | L->lexstate = &lexstate; | 627 | L->lexstate = &lexstate; |
| 628 | luaX_setinput(z); | 628 | luaX_setinput(z); |
| 629 | init_state(luaS_new(chunkname)); | 629 | init_state(luaS_new(zname(z))); |
| 630 | if (luaY_parse()) lua_error("parse error"); | 630 | if (luaY_parse()) lua_error("parse error"); |
| 631 | return close_func(); | 631 | return close_func(); |
| 632 | } | 632 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lzio.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ | 2 | ** $Id: lzio.c,v 1.2 1997/11/21 19:00:46 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 | */ |
| @@ -20,22 +20,23 @@ static int zmfilbuf (ZIO* z) | |||
| 20 | return EOZ; | 20 | return EOZ; |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | ZIO* zmopen (ZIO* z, char* b, int size) | 23 | ZIO* zmopen (ZIO* z, char* b, int size, char *name) |
| 24 | { | 24 | { |
| 25 | if (b==NULL) return NULL; | 25 | if (b==NULL) return NULL; |
| 26 | z->n=size; | 26 | z->n=size; |
| 27 | z->p= (unsigned char *)b; | 27 | z->p= (unsigned char *)b; |
| 28 | z->filbuf=zmfilbuf; | 28 | z->filbuf=zmfilbuf; |
| 29 | z->u=NULL; | 29 | z->u=NULL; |
| 30 | z->name=name; | ||
| 30 | return z; | 31 | return z; |
| 31 | } | 32 | } |
| 32 | 33 | ||
| 33 | /* ------------------------------------------------------------ strings --- */ | 34 | /* ------------------------------------------------------------ strings --- */ |
| 34 | 35 | ||
| 35 | ZIO* zsopen (ZIO* z, char* s) | 36 | ZIO* zsopen (ZIO* z, char* s, char *name) |
| 36 | { | 37 | { |
| 37 | if (s==NULL) return NULL; | 38 | if (s==NULL) return NULL; |
| 38 | return zmopen(z,s,strlen(s)); | 39 | return zmopen(z,s,strlen(s),name); |
| 39 | } | 40 | } |
| 40 | 41 | ||
| 41 | /* -------------------------------------------------------------- FILEs --- */ | 42 | /* -------------------------------------------------------------- FILEs --- */ |
| @@ -50,13 +51,14 @@ static int zffilbuf (ZIO* z) | |||
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | 53 | ||
| 53 | ZIO* zFopen (ZIO* z, FILE* f) | 54 | ZIO* zFopen (ZIO* z, FILE* f, char *name) |
| 54 | { | 55 | { |
| 55 | if (f==NULL) return NULL; | 56 | if (f==NULL) return NULL; |
| 56 | z->n=0; | 57 | z->n=0; |
| 57 | z->p=z->buffer; | 58 | z->p=z->buffer; |
| 58 | z->filbuf=zffilbuf; | 59 | z->filbuf=zffilbuf; |
| 59 | z->u=f; | 60 | z->u=f; |
| 61 | z->name=name; | ||
| 60 | return z; | 62 | return z; |
| 61 | } | 63 | } |
| 62 | 64 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lzio.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ | 2 | ** $Id: lzio.h,v 1.2 1997/11/21 19:00:46 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 | */ |
| @@ -22,15 +22,15 @@ | |||
| 22 | 22 | ||
| 23 | typedef struct zio ZIO; | 23 | typedef struct zio ZIO; |
| 24 | 24 | ||
| 25 | ZIO* zFopen (ZIO* z, FILE* f); /* open FILEs */ | 25 | ZIO* zFopen (ZIO* z, FILE* f, char *name); /* open FILEs */ |
| 26 | ZIO* zsopen (ZIO* z, char* s); /* string */ | 26 | ZIO* zsopen (ZIO* z, char* s, char *name); /* string */ |
| 27 | ZIO* zmopen (ZIO* z, char* b, int size); /* memory */ | 27 | ZIO* zmopen (ZIO* z, char* b, int size, char *name); /* memory */ |
| 28 | 28 | ||
| 29 | int zread (ZIO* z, void* b, int n); /* read next n bytes */ | 29 | int zread (ZIO* z, void* b, int n); /* read next n bytes */ |
| 30 | 30 | ||
| 31 | #define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z)) | 31 | #define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z)) |
| 32 | #define zungetc(z) (++(z)->n,--(z)->p) | 32 | #define zungetc(z) (++(z)->n,--(z)->p) |
| 33 | 33 | #define zname(z) ((z)->name) | |
| 34 | 34 | ||
| 35 | 35 | ||
| 36 | /* --------- Private Part ------------------ */ | 36 | /* --------- Private Part ------------------ */ |
| @@ -43,6 +43,7 @@ struct zio { | |||
| 43 | int (*filbuf)(ZIO* z); | 43 | int (*filbuf)(ZIO* z); |
| 44 | void* u; /* additional data */ | 44 | void* u; /* additional data */ |
| 45 | unsigned char buffer[ZBSIZE]; /* buffer */ | 45 | unsigned char buffer[ZBSIZE]; /* buffer */ |
| 46 | char *name; | ||
| 46 | }; | 47 | }; |
| 47 | 48 | ||
| 48 | 49 | ||
