"zio" now keeps its "name".

This commit is contained in:
Roberto Ierusalimschy 1997-12-22 18:57:18 -02:00
parent a78eecee48
commit 03f3f9e707
5 changed files with 32 additions and 29 deletions

28
ldo.c
View File

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 1.16 1997/12/17 20:57:20 roberto Exp roberto $
** $Id: ldo.c,v 1.17 1997/12/18 18:32:39 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -296,7 +296,7 @@ int luaD_protectedrun (int nResults)
/*
** returns 0 = chunk loaded; 1 = error; 2 = no more chunks to load
*/
static int protectedparser (ZIO *z, char *chunkname, int bin)
static int protectedparser (ZIO *z, int bin)
{
int status;
TProtoFunc *tf;
@ -304,7 +304,7 @@ static int protectedparser (ZIO *z, char *chunkname, int bin)
jmp_buf *oldErr = L->errorJmp;
L->errorJmp = &myErrorJmp;
if (setjmp(myErrorJmp) == 0) {
tf = bin ? luaU_undump1(z, chunkname) : luaY_parser(z, chunkname);
tf = bin ? luaU_undump1(z) : luaY_parser(z);
status = 0;
}
else {
@ -322,12 +322,12 @@ static int protectedparser (ZIO *z, char *chunkname, int bin)
}
static int do_main (ZIO *z, char *chunkname, int bin)
static int do_main (ZIO *z, int bin)
{
int status;
do {
long old_blocks = (luaC_checkGC(), L->nblocks);
status = protectedparser(z, chunkname, bin);
status = protectedparser(z, bin);
if (status == 1) return 1; /* error */
else if (status == 2) return 0; /* 'natural' end */
else {
@ -368,8 +368,8 @@ int lua_dofile (char *filename)
bin = (c == ID_CHUNK);
if (bin)
f = freopen(filename, "rb", f); /* set binary mode */
luaZ_Fopen(&z, f);
status = do_main(&z, filename, bin);
luaZ_Fopen(&z, f, filename);
status = do_main(&z, bin);
if (f != stdin)
fclose(f);
return status;
@ -383,15 +383,15 @@ int lua_dofile (char *filename)
int lua_dostring (char *str)
{
int status;
char buff[SIZE_PREF+25];
char name[SIZE_PREF+25];
char *temp;
ZIO z;
if (str == NULL) return 1;
sprintf(buff, "(dostring) >> %." SSIZE_PREF "s", str);
temp = strchr(buff, '\n');
sprintf(name, "(dostring) >> %." SSIZE_PREF "s", str);
temp = strchr(name, '\n');
if (temp) *temp = 0; /* end string after first line */
luaZ_sopen(&z, str);
status = do_main(&z, buff, 0);
luaZ_sopen(&z, str, name);
status = do_main(&z, 0);
return status;
}
@ -401,8 +401,8 @@ int lua_dobuffer (char *buff, int size)
{
int status;
ZIO z;
luaZ_mopen(&z, buff, size);
status = do_main(&z, "(buffer)", 1);
luaZ_mopen(&z, buff, size, "(buffer)");
status = do_main(&z, 1);
return status;
}
#endif

View File

@ -1,5 +1,5 @@
/*
** $Id: $
** $Id: lparser.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
** Syntax analizer and code generator
** See Copyright Notice in lua.h
*/
@ -12,7 +12,7 @@
void luaY_codedebugline (int line);
TProtoFunc *luaY_parser (ZIO *z, char *chunkname);
TProtoFunc *luaY_parser (ZIO *z);
void luaY_error (char *s);
void luaY_syntaxerror (char *s, char *token);

View File

@ -1,6 +1,6 @@
%{
/*
** $Id: lua.stx,v 1.23 1997/12/15 16:17:20 roberto Exp roberto $
** $Id: lua.stx,v 1.24 1997/12/22 17:24:11 roberto Exp roberto $
** Syntax analizer and code generator
** See Copyright Notice in lua.h
*/
@ -619,14 +619,14 @@ static TProtoFunc *close_func (void)
/*
** Parse Lua code.
*/
TProtoFunc *luaY_parser (ZIO *z, char *chunkname)
TProtoFunc *luaY_parser (ZIO *z)
{
struct LexState lexstate;
FuncState state[MAXSTATES];
L->currState = L->mainState = &state[0];
L->lexstate = &lexstate;
luaX_setinput(z);
init_state(luaS_new(chunkname));
init_state(luaS_new(zname(z)));
if (luaY_parse()) lua_error("parse error");
return close_func();
}

12
lzio.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lzio.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
** $Id: lzio.c,v 1.2 1997/11/21 19:00:46 roberto Exp roberto $
** a generic input stream interface
** See Copyright Notice in lua.h
*/
@ -20,22 +20,23 @@ static int zmfilbuf (ZIO* z)
return EOZ;
}
ZIO* zmopen (ZIO* z, char* b, int size)
ZIO* zmopen (ZIO* z, char* b, int size, char *name)
{
if (b==NULL) return NULL;
z->n=size;
z->p= (unsigned char *)b;
z->filbuf=zmfilbuf;
z->u=NULL;
z->name=name;
return z;
}
/* ------------------------------------------------------------ strings --- */
ZIO* zsopen (ZIO* z, char* s)
ZIO* zsopen (ZIO* z, char* s, char *name)
{
if (s==NULL) return NULL;
return zmopen(z,s,strlen(s));
return zmopen(z,s,strlen(s),name);
}
/* -------------------------------------------------------------- FILEs --- */
@ -50,13 +51,14 @@ static int zffilbuf (ZIO* z)
}
ZIO* zFopen (ZIO* z, FILE* f)
ZIO* zFopen (ZIO* z, FILE* f, char *name)
{
if (f==NULL) return NULL;
z->n=0;
z->p=z->buffer;
z->filbuf=zffilbuf;
z->u=f;
z->name=name;
return z;
}

11
lzio.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lzio.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
** $Id: lzio.h,v 1.2 1997/11/21 19:00:46 roberto Exp roberto $
** Buffered streams
** See Copyright Notice in lua.h
*/
@ -22,15 +22,15 @@
typedef struct zio ZIO;
ZIO* zFopen (ZIO* z, FILE* f); /* open FILEs */
ZIO* zsopen (ZIO* z, char* s); /* string */
ZIO* zmopen (ZIO* z, char* b, int size); /* memory */
ZIO* zFopen (ZIO* z, FILE* f, char *name); /* open FILEs */
ZIO* zsopen (ZIO* z, char* s, char *name); /* string */
ZIO* zmopen (ZIO* z, char* b, int size, char *name); /* memory */
int zread (ZIO* z, void* b, int n); /* read next n bytes */
#define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z))
#define zungetc(z) (++(z)->n,--(z)->p)
#define zname(z) ((z)->name)
/* --------- Private Part ------------------ */
@ -43,6 +43,7 @@ struct zio {
int (*filbuf)(ZIO* z);
void* u; /* additional data */
unsigned char buffer[ZBSIZE]; /* buffer */
char *name;
};