mirror of
https://github.com/lua/lua.git
synced 2025-01-14 05:43:00 +08:00
small modifications (format, small optimizations, etc)
This commit is contained in:
parent
6153200bc2
commit
accd7bc253
4
lapi.c
4
lapi.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lapi.c,v 1.5 1997/11/19 17:29:23 roberto Exp roberto $
|
||||
** $Id: lapi.c,v 1.6 1997/11/19 18:16:33 roberto Exp roberto $
|
||||
** Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -270,7 +270,7 @@ int lua_isfunction (lua_Object o)
|
||||
real lua_getnumber (lua_Object object)
|
||||
{
|
||||
if (object == LUA_NOOBJECT) return 0.0;
|
||||
if (tonumber (Address(object))) return 0.0;
|
||||
if (tonumber(Address(object))) return 0.0;
|
||||
else return (nvalue(Address(object)));
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lauxlib.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
|
||||
** $Id: lauxlib.c,v 1.3 1997/11/04 15:27:53 roberto Exp roberto $
|
||||
** Auxiliar functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
|
||||
|
||||
void luaL_arg_check(int cond, int numarg, char *extramsg)
|
||||
void luaL_arg_check (int cond, int numarg, char *extramsg)
|
||||
{
|
||||
if (!cond) {
|
||||
char *funcname;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lauxlib.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
|
||||
** $Id: lauxlib.h,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
|
||||
** Auxiliar functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -18,7 +18,7 @@ struct luaL_reg {
|
||||
};
|
||||
|
||||
void luaL_openlib (struct luaL_reg *l, int n);
|
||||
void luaL_arg_check(int cond, int numarg, char *extramsg);
|
||||
void luaL_arg_check (int cond, int numarg, char *extramsg);
|
||||
char *luaL_check_string (int numArg);
|
||||
char *luaL_opt_string (int numArg, char *def);
|
||||
double luaL_check_number (int numArg);
|
||||
|
4
ldo.c
4
ldo.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldo.c,v 1.8 1997/11/07 15:09:49 roberto Exp roberto $
|
||||
** $Id: ldo.c,v 1.9 1997/11/19 17:29:23 roberto Exp roberto $
|
||||
** Stack and Call structure of Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -224,7 +224,7 @@ void luaD_travstack (int (*fn)(TObject *))
|
||||
{
|
||||
StkId i;
|
||||
for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--)
|
||||
fn (L->stack.stack+i);
|
||||
fn(L->stack.stack+i);
|
||||
}
|
||||
|
||||
|
||||
|
318
llex.c
318
llex.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: llex.c,v 1.6 1997/11/19 17:29:23 roberto Exp roberto $
|
||||
** $Id: llex.c,v 1.7 1997/11/19 17:35:47 roberto Exp roberto $
|
||||
** Lexical Analizer
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -23,7 +23,7 @@
|
||||
int lua_debug=0;
|
||||
|
||||
|
||||
#define next(LL) (LL->current = zgetc(LL->lex_z))
|
||||
#define next(LS) (LS->current = zgetc(LS->lex_z))
|
||||
|
||||
|
||||
static struct {
|
||||
@ -46,29 +46,29 @@ void luaX_init (void)
|
||||
}
|
||||
|
||||
|
||||
static void firstline (LexState *LL)
|
||||
static void firstline (LexState *LS)
|
||||
{
|
||||
int c = zgetc(LL->lex_z);
|
||||
int c = zgetc(LS->lex_z);
|
||||
if (c == '#')
|
||||
while((c=zgetc(LL->lex_z)) != '\n' && c != EOZ) /* skip first line */;
|
||||
zungetc(LL->lex_z);
|
||||
while ((c=zgetc(LS->lex_z)) != '\n' && c != EOZ) /* skip first line */;
|
||||
zungetc(LS->lex_z);
|
||||
}
|
||||
|
||||
|
||||
void luaX_setinput (ZIO *z)
|
||||
{
|
||||
LexState *LL = L->lexstate;
|
||||
LL->current = '\n';
|
||||
LL->linelasttoken = 0;
|
||||
LL->lastline = 0;
|
||||
LL->linenumber = 0;
|
||||
LL->iflevel = 0;
|
||||
LL->ifstate[0].skip = 0;
|
||||
LL->ifstate[0].elsepart = 1; /* to avoid a free $else */
|
||||
LL->lex_z = z;
|
||||
firstline(LL);
|
||||
LL->textbuff.buffsize = 20;
|
||||
LL->textbuff.text = luaM_buffer(LL->textbuff.buffsize);
|
||||
LexState *LS = L->lexstate;
|
||||
LS->current = '\n';
|
||||
LS->linelasttoken = 0;
|
||||
LS->lastline = 0;
|
||||
LS->linenumber = 0;
|
||||
LS->iflevel = 0;
|
||||
LS->ifstate[0].skip = 0;
|
||||
LS->ifstate[0].elsepart = 1; /* to avoid a free $else */
|
||||
LS->lex_z = z;
|
||||
firstline(LS);
|
||||
LS->textbuff.buffsize = 20;
|
||||
LS->textbuff.text = luaM_buffer(LS->textbuff.buffsize);
|
||||
}
|
||||
|
||||
|
||||
@ -81,10 +81,10 @@ void luaX_setinput (ZIO *z)
|
||||
|
||||
#define PRAGMASIZE 20
|
||||
|
||||
static void skipspace (LexState *LL)
|
||||
static void skipspace (LexState *LS)
|
||||
{
|
||||
while (LL->current == ' ' || LL->current == '\t' || LL->current == '\r')
|
||||
next(LL);
|
||||
while (LS->current == ' ' || LS->current == '\t' || LS->current == '\r')
|
||||
next(LS);
|
||||
}
|
||||
|
||||
|
||||
@ -102,49 +102,49 @@ static int checkcond (char *buff)
|
||||
}
|
||||
|
||||
|
||||
static void readname (LexState *LL, char *buff)
|
||||
static void readname (LexState *LS, char *buff)
|
||||
{
|
||||
int i = 0;
|
||||
skipspace(LL);
|
||||
while (isalnum(LL->current) || LL->current == '_') {
|
||||
skipspace(LS);
|
||||
while (isalnum(LS->current) || LS->current == '_') {
|
||||
if (i >= PRAGMASIZE) {
|
||||
buff[PRAGMASIZE] = 0;
|
||||
luaY_syntaxerror("pragma too long", buff);
|
||||
}
|
||||
buff[i++] = LL->current;
|
||||
next(LL);
|
||||
buff[i++] = LS->current;
|
||||
next(LS);
|
||||
}
|
||||
buff[i] = 0;
|
||||
}
|
||||
|
||||
|
||||
static void inclinenumber (LexState *LL);
|
||||
static void inclinenumber (LexState *LS);
|
||||
|
||||
|
||||
static void ifskip (LexState *LL)
|
||||
static void ifskip (LexState *LS)
|
||||
{
|
||||
while (LL->ifstate[LL->iflevel].skip) {
|
||||
if (LL->current == '\n')
|
||||
inclinenumber(LL);
|
||||
else if (LL->current == EOZ)
|
||||
while (LS->ifstate[LS->iflevel].skip) {
|
||||
if (LS->current == '\n')
|
||||
inclinenumber(LS);
|
||||
else if (LS->current == EOZ)
|
||||
luaY_syntaxerror("input ends inside a $if", "");
|
||||
else next(LL);
|
||||
else next(LS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void inclinenumber (LexState *LL)
|
||||
static void inclinenumber (LexState *LS)
|
||||
{
|
||||
static char *pragmas [] =
|
||||
{"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL};
|
||||
next(LL); /* skip '\n' */
|
||||
++LL->linenumber;
|
||||
if (LL->current == '$') { /* is a pragma? */
|
||||
next(LS); /* skip '\n' */
|
||||
++LS->linenumber;
|
||||
if (LS->current == '$') { /* is a pragma? */
|
||||
char buff[PRAGMASIZE+1];
|
||||
int ifnot = 0;
|
||||
int skip = LL->ifstate[LL->iflevel].skip;
|
||||
next(LL); /* skip $ */
|
||||
readname(LL, buff);
|
||||
int skip = LS->ifstate[LS->iflevel].skip;
|
||||
next(LS); /* skip $ */
|
||||
readname(LS, buff);
|
||||
switch (luaO_findstring(buff, pragmas)) {
|
||||
case 0: /* debug */
|
||||
if (!skip) lua_debug = 1;
|
||||
@ -154,42 +154,42 @@ static void inclinenumber (LexState *LL)
|
||||
break;
|
||||
case 2: /* endinput */
|
||||
if (!skip) {
|
||||
LL->current = EOZ;
|
||||
LL->iflevel = 0; /* to allow $endinput inside a $if */
|
||||
LS->current = EOZ;
|
||||
LS->iflevel = 0; /* to allow $endinput inside a $if */
|
||||
}
|
||||
break;
|
||||
case 3: /* end */
|
||||
if (LL->iflevel-- == 0)
|
||||
if (LS->iflevel-- == 0)
|
||||
luaY_syntaxerror("unmatched $end", "$end");
|
||||
break;
|
||||
case 4: /* ifnot */
|
||||
ifnot = 1;
|
||||
/* go through */
|
||||
case 5: /* if */
|
||||
if (LL->iflevel == MAX_IFS-1)
|
||||
if (LS->iflevel == MAX_IFS-1)
|
||||
luaY_syntaxerror("too many nested `$ifs'", "$if");
|
||||
readname(LL, buff);
|
||||
LL->iflevel++;
|
||||
LL->ifstate[LL->iflevel].elsepart = 0;
|
||||
LL->ifstate[LL->iflevel].condition = checkcond(buff) ? !ifnot : ifnot;
|
||||
LL->ifstate[LL->iflevel].skip = skip || !LL->ifstate[LL->iflevel].condition;
|
||||
readname(LS, buff);
|
||||
LS->iflevel++;
|
||||
LS->ifstate[LS->iflevel].elsepart = 0;
|
||||
LS->ifstate[LS->iflevel].condition = checkcond(buff) ? !ifnot : ifnot;
|
||||
LS->ifstate[LS->iflevel].skip = skip || !LS->ifstate[LS->iflevel].condition;
|
||||
break;
|
||||
case 6: /* else */
|
||||
if (LL->ifstate[LL->iflevel].elsepart)
|
||||
if (LS->ifstate[LS->iflevel].elsepart)
|
||||
luaY_syntaxerror("unmatched $else", "$else");
|
||||
LL->ifstate[LL->iflevel].elsepart = 1;
|
||||
LL->ifstate[LL->iflevel].skip = LL->ifstate[LL->iflevel-1].skip ||
|
||||
LL->ifstate[LL->iflevel].condition;
|
||||
LS->ifstate[LS->iflevel].elsepart = 1;
|
||||
LS->ifstate[LS->iflevel].skip = LS->ifstate[LS->iflevel-1].skip ||
|
||||
LS->ifstate[LS->iflevel].condition;
|
||||
break;
|
||||
default:
|
||||
luaY_syntaxerror("invalid pragma", buff);
|
||||
}
|
||||
skipspace(LL);
|
||||
if (LL->current == '\n') /* pragma must end with a '\n' ... */
|
||||
inclinenumber(LL);
|
||||
else if (LL->current != EOZ) /* or eof */
|
||||
skipspace(LS);
|
||||
if (LS->current == '\n') /* pragma must end with a '\n' ... */
|
||||
inclinenumber(LS);
|
||||
else if (LS->current != EOZ) /* or eof */
|
||||
luaY_syntaxerror("invalid pragma format", buff);
|
||||
ifskip(LL);
|
||||
ifskip(LS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,11 +202,11 @@ static void inclinenumber (LexState *LL)
|
||||
|
||||
|
||||
|
||||
static void save (LexState *LL, int c)
|
||||
static void save (LexState *LS, int c)
|
||||
{
|
||||
if (LL->textbuff.tokensize >= LL->textbuff.buffsize)
|
||||
LL->textbuff.text = luaM_buffer(LL->textbuff.buffsize *= 2);
|
||||
LL->textbuff.text[LL->textbuff.tokensize++] = c;
|
||||
if (LS->textbuff.tokensize >= LS->textbuff.buffsize)
|
||||
LS->textbuff.text = luaM_buffer(LS->textbuff.buffsize *= 2);
|
||||
LS->textbuff.text[LS->textbuff.tokensize++] = c;
|
||||
}
|
||||
|
||||
|
||||
@ -217,44 +217,44 @@ char *luaX_lasttoken (void)
|
||||
}
|
||||
|
||||
|
||||
#define save_and_next(LL) (save(LL, LL->current), next(LL))
|
||||
#define save_and_next(LS) (save(LS, LS->current), next(LS))
|
||||
|
||||
|
||||
static int read_long_string (LexState *LL, YYSTYPE *l)
|
||||
static int read_long_string (LexState *LS, YYSTYPE *l)
|
||||
{
|
||||
int cont = 0;
|
||||
while (1) {
|
||||
switch (LL->current) {
|
||||
switch (LS->current) {
|
||||
case EOZ:
|
||||
save(LL, 0);
|
||||
save(LS, 0);
|
||||
return WRONGTOKEN;
|
||||
case '[':
|
||||
save_and_next(LL);
|
||||
if (LL->current == '[') {
|
||||
save_and_next(LS);
|
||||
if (LS->current == '[') {
|
||||
cont++;
|
||||
save_and_next(LL);
|
||||
save_and_next(LS);
|
||||
}
|
||||
continue;
|
||||
case ']':
|
||||
save_and_next(LL);
|
||||
if (LL->current == ']') {
|
||||
save_and_next(LS);
|
||||
if (LS->current == ']') {
|
||||
if (cont == 0) goto endloop;
|
||||
cont--;
|
||||
save_and_next(LL);
|
||||
save_and_next(LS);
|
||||
}
|
||||
continue;
|
||||
case '\n':
|
||||
save(LL, '\n');
|
||||
inclinenumber(LL);
|
||||
save(LS, '\n');
|
||||
inclinenumber(LS);
|
||||
continue;
|
||||
default:
|
||||
save_and_next(LL);
|
||||
save_and_next(LS);
|
||||
}
|
||||
} endloop:
|
||||
save_and_next(LL); /* pass the second ']' */
|
||||
LL->textbuff.text[LL->textbuff.tokensize-2] = 0; /* erases ']]' */
|
||||
l->pTStr = luaS_new(LL->textbuff.text+2);
|
||||
LL->textbuff.text[LL->textbuff.tokensize-2] = ']'; /* restores ']]' */
|
||||
save_and_next(LS); /* pass the second ']' */
|
||||
LS->textbuff.text[LS->textbuff.tokensize-2] = 0; /* erases ']]' */
|
||||
l->pTStr = luaS_new(LS->textbuff.text+2);
|
||||
LS->textbuff.text[LS->textbuff.tokensize-2] = ']'; /* restores ']]' */
|
||||
return STRING;
|
||||
}
|
||||
|
||||
@ -266,103 +266,103 @@ static int read_long_string (LexState *LL, YYSTYPE *l)
|
||||
int luaY_lex (YYSTYPE *l);
|
||||
int luaY_lex (YYSTYPE *l)
|
||||
{
|
||||
LexState *LL = L->lexstate;
|
||||
LexState *LS = L->lexstate;
|
||||
double a;
|
||||
LL->textbuff.tokensize = 0;
|
||||
LS->textbuff.tokensize = 0;
|
||||
if (lua_debug)
|
||||
luaY_codedebugline(LL->linelasttoken);
|
||||
LL->linelasttoken = LL->linenumber;
|
||||
luaY_codedebugline(LS->linelasttoken);
|
||||
LS->linelasttoken = LS->linenumber;
|
||||
while (1) {
|
||||
switch (LL->current) {
|
||||
switch (LS->current) {
|
||||
case '\n':
|
||||
inclinenumber(LL);
|
||||
LL->linelasttoken = LL->linenumber;
|
||||
inclinenumber(LS);
|
||||
LS->linelasttoken = LS->linenumber;
|
||||
continue;
|
||||
|
||||
case ' ': case '\t': case '\r': /* CR: to avoid problems with DOS */
|
||||
next(LL);
|
||||
next(LS);
|
||||
continue;
|
||||
|
||||
case '-':
|
||||
save_and_next(LL);
|
||||
if (LL->current != '-') return '-';
|
||||
do { next(LL); } while (LL->current != '\n' && LL->current != EOZ);
|
||||
LL->textbuff.tokensize = 0;
|
||||
save_and_next(LS);
|
||||
if (LS->current != '-') return '-';
|
||||
do { next(LS); } while (LS->current != '\n' && LS->current != EOZ);
|
||||
LS->textbuff.tokensize = 0;
|
||||
continue;
|
||||
|
||||
case '[':
|
||||
save_and_next(LL);
|
||||
if (LL->current != '[') return '[';
|
||||
save_and_next(LS);
|
||||
if (LS->current != '[') return '[';
|
||||
else {
|
||||
save_and_next(LL); /* pass the second '[' */
|
||||
return read_long_string(LL, l);
|
||||
save_and_next(LS); /* pass the second '[' */
|
||||
return read_long_string(LS, l);
|
||||
}
|
||||
|
||||
case '=':
|
||||
save_and_next(LL);
|
||||
if (LL->current != '=') return '=';
|
||||
else { save_and_next(LL); return EQ; }
|
||||
save_and_next(LS);
|
||||
if (LS->current != '=') return '=';
|
||||
else { save_and_next(LS); return EQ; }
|
||||
|
||||
case '<':
|
||||
save_and_next(LL);
|
||||
if (LL->current != '=') return '<';
|
||||
else { save_and_next(LL); return LE; }
|
||||
save_and_next(LS);
|
||||
if (LS->current != '=') return '<';
|
||||
else { save_and_next(LS); return LE; }
|
||||
|
||||
case '>':
|
||||
save_and_next(LL);
|
||||
if (LL->current != '=') return '>';
|
||||
else { save_and_next(LL); return GE; }
|
||||
save_and_next(LS);
|
||||
if (LS->current != '=') return '>';
|
||||
else { save_and_next(LS); return GE; }
|
||||
|
||||
case '~':
|
||||
save_and_next(LL);
|
||||
if (LL->current != '=') return '~';
|
||||
else { save_and_next(LL); return NE; }
|
||||
save_and_next(LS);
|
||||
if (LS->current != '=') return '~';
|
||||
else { save_and_next(LS); return NE; }
|
||||
|
||||
case '"':
|
||||
case '\'': {
|
||||
int del = LL->current;
|
||||
save_and_next(LL);
|
||||
while (LL->current != del) {
|
||||
switch (LL->current) {
|
||||
int del = LS->current;
|
||||
save_and_next(LS);
|
||||
while (LS->current != del) {
|
||||
switch (LS->current) {
|
||||
case EOZ:
|
||||
case '\n':
|
||||
save(LL, 0);
|
||||
save(LS, 0);
|
||||
return WRONGTOKEN;
|
||||
case '\\':
|
||||
next(LL); /* do not save the '\' */
|
||||
switch (LL->current) {
|
||||
case 'n': save(LL, '\n'); next(LL); break;
|
||||
case 't': save(LL, '\t'); next(LL); break;
|
||||
case 'r': save(LL, '\r'); next(LL); break;
|
||||
case '\n': save(LL, '\n'); inclinenumber(LL); break;
|
||||
default : save_and_next(LL); break;
|
||||
next(LS); /* do not save the '\' */
|
||||
switch (LS->current) {
|
||||
case 'n': save(LS, '\n'); next(LS); break;
|
||||
case 't': save(LS, '\t'); next(LS); break;
|
||||
case 'r': save(LS, '\r'); next(LS); break;
|
||||
case '\n': save(LS, '\n'); inclinenumber(LS); break;
|
||||
default : save_and_next(LS); break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
save_and_next(LL);
|
||||
save_and_next(LS);
|
||||
}
|
||||
}
|
||||
next(LL); /* skip delimiter */
|
||||
save(LL, 0);
|
||||
l->pTStr = luaS_new(LL->textbuff.text+1);
|
||||
LL->textbuff.text[LL->textbuff.tokensize-1] = del; /* restore delimiter */
|
||||
next(LS); /* skip delimiter */
|
||||
save(LS, 0);
|
||||
l->pTStr = luaS_new(LS->textbuff.text+1);
|
||||
LS->textbuff.text[LS->textbuff.tokensize-1] = del; /* restore delimiter */
|
||||
return STRING;
|
||||
}
|
||||
|
||||
case '.':
|
||||
save_and_next(LL);
|
||||
if (LL->current == '.')
|
||||
save_and_next(LS);
|
||||
if (LS->current == '.')
|
||||
{
|
||||
save_and_next(LL);
|
||||
if (LL->current == '.')
|
||||
save_and_next(LS);
|
||||
if (LS->current == '.')
|
||||
{
|
||||
save_and_next(LL);
|
||||
save_and_next(LS);
|
||||
return DOTS; /* ... */
|
||||
}
|
||||
else return CONC; /* .. */
|
||||
}
|
||||
else if (!isdigit(LL->current)) return '.';
|
||||
/* LL->current is a digit: goes through to number */
|
||||
else if (!isdigit(LS->current)) return '.';
|
||||
/* LS->current is a digit: goes through to number */
|
||||
a=0.0;
|
||||
goto fraction;
|
||||
|
||||
@ -370,38 +370,38 @@ int luaY_lex (YYSTYPE *l)
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
a=0.0;
|
||||
do {
|
||||
a=10.0*a+(LL->current-'0');
|
||||
save_and_next(LL);
|
||||
} while (isdigit(LL->current));
|
||||
if (LL->current == '.') {
|
||||
save_and_next(LL);
|
||||
if (LL->current == '.') {
|
||||
save(LL, 0);
|
||||
a=10.0*a+(LS->current-'0');
|
||||
save_and_next(LS);
|
||||
} while (isdigit(LS->current));
|
||||
if (LS->current == '.') {
|
||||
save_and_next(LS);
|
||||
if (LS->current == '.') {
|
||||
save(LS, 0);
|
||||
luaY_error(
|
||||
"ambiguous syntax (decimal point x string concatenation)");
|
||||
}
|
||||
}
|
||||
fraction:
|
||||
{ double da=0.1;
|
||||
while (isdigit(LL->current))
|
||||
while (isdigit(LS->current))
|
||||
{
|
||||
a+=(LL->current-'0')*da;
|
||||
a+=(LS->current-'0')*da;
|
||||
da/=10.0;
|
||||
save_and_next(LL);
|
||||
save_and_next(LS);
|
||||
}
|
||||
if (toupper(LL->current) == 'E') {
|
||||
if (toupper(LS->current) == 'E') {
|
||||
int e=0;
|
||||
int neg;
|
||||
double ea;
|
||||
save_and_next(LL);
|
||||
neg=(LL->current=='-');
|
||||
if (LL->current == '+' || LL->current == '-') save_and_next(LL);
|
||||
if (!isdigit(LL->current)) {
|
||||
save(LL, 0); return WRONGTOKEN; }
|
||||
save_and_next(LS);
|
||||
neg=(LS->current=='-');
|
||||
if (LS->current == '+' || LS->current == '-') save_and_next(LS);
|
||||
if (!isdigit(LS->current)) {
|
||||
save(LS, 0); return WRONGTOKEN; }
|
||||
do {
|
||||
e=10.0*e+(LL->current-'0');
|
||||
save_and_next(LL);
|
||||
} while (isdigit(LL->current));
|
||||
e=10.0*e+(LS->current-'0');
|
||||
save_and_next(LS);
|
||||
} while (isdigit(LS->current));
|
||||
for (ea=neg?0.1:10.0; e>0; e>>=1)
|
||||
{
|
||||
if (e & 1) a*=ea;
|
||||
@ -413,23 +413,23 @@ int luaY_lex (YYSTYPE *l)
|
||||
}
|
||||
|
||||
case EOZ:
|
||||
save(LL, 0);
|
||||
if (LL->iflevel > 0)
|
||||
save(LS, 0);
|
||||
if (LS->iflevel > 0)
|
||||
luaY_error("missing $endif");
|
||||
return 0;
|
||||
|
||||
default:
|
||||
if (LL->current != '_' && !isalpha(LL->current)) {
|
||||
save_and_next(LL);
|
||||
return LL->textbuff.text[0];
|
||||
if (LS->current != '_' && !isalpha(LS->current)) {
|
||||
save_and_next(LS);
|
||||
return LS->textbuff.text[0];
|
||||
}
|
||||
else { /* identifier or reserved word */
|
||||
TaggedString *ts;
|
||||
do {
|
||||
save_and_next(LL);
|
||||
} while (isalnum(LL->current) || LL->current == '_');
|
||||
save(LL, 0);
|
||||
ts = luaS_new(LL->textbuff.text);
|
||||
save_and_next(LS);
|
||||
} while (isalnum(LS->current) || LS->current == '_');
|
||||
save(LS, 0);
|
||||
ts = luaS_new(LS->textbuff.text);
|
||||
if (ts->head.marked > 255)
|
||||
return ts->head.marked; /* reserved word */
|
||||
l->pTStr = ts;
|
||||
|
12
lstate.h
12
lstate.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: $
|
||||
** $Id: lstate.h,v 1.1 1997/11/19 17:30:36 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -18,9 +18,9 @@
|
||||
typedef int StkId; /* index to stack elements */
|
||||
|
||||
struct Stack {
|
||||
TObject *last;
|
||||
TObject *stack;
|
||||
TObject *top;
|
||||
TObject *stack;
|
||||
TObject *last;
|
||||
};
|
||||
|
||||
struct C_Lua_Stack {
|
||||
@ -45,14 +45,14 @@ struct ref {
|
||||
|
||||
|
||||
typedef struct LState {
|
||||
struct C_Lua_Stack Cblocks[MAX_C_BLOCKS];
|
||||
int numCblocks; /* number of nested Cblocks */
|
||||
TObject *functofind; /* auxiliar */
|
||||
struct Stack stack; /* Lua stack */
|
||||
struct C_Lua_Stack Cstack; /* C2lua struct */
|
||||
int stacklimit; /* limit for stack overflow */
|
||||
void *errorJmp; /* current error recover point */
|
||||
TObject errorim; /* error tag method */
|
||||
struct C_Lua_Stack Cblocks[MAX_C_BLOCKS];
|
||||
int numCblocks; /* number of nested Cblocks */
|
||||
TObject *functofind; /* auxiliar */
|
||||
GCnode rootproto; /* list of all prototypes */
|
||||
GCnode rootcl; /* list of all closures */
|
||||
GCnode roottable; /* list of all tables */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstring.c,v 1.4 1997/11/04 15:27:53 roberto Exp roberto $
|
||||
** $Id: lstring.c,v 1.5 1997/11/19 17:29:23 roberto Exp roberto $
|
||||
** String table (keep all strings handled by Lua)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -74,7 +74,7 @@ static void grow (stringtable *tb)
|
||||
}
|
||||
|
||||
|
||||
static TaggedString *newone(char *buff, int tag, unsigned long h)
|
||||
static TaggedString *newone (char *buff, int tag, unsigned long h)
|
||||
{
|
||||
TaggedString *ts;
|
||||
if (tag == LUA_T_STRING) {
|
||||
|
4
ltable.c
4
ltable.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ltable.c,v 1.5 1997/10/24 17:17:24 roberto Exp roberto $
|
||||
** $Id: ltable.c,v 1.6 1997/11/19 17:29:23 roberto Exp roberto $
|
||||
** Lua tables (hash)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -84,7 +84,7 @@ static Node *hashnodecreate (int nhash)
|
||||
*/
|
||||
static void hashdelete (Hash *t)
|
||||
{
|
||||
luaM_free (nodevector(t));
|
||||
luaM_free(nodevector(t));
|
||||
luaM_free(t);
|
||||
}
|
||||
|
||||
|
4
lua.c
4
lua.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lua.c,v 1.3 1997/10/16 18:35:59 roberto Exp roberto $
|
||||
** $Id: lua.c,v 1.4 1997/11/19 17:29:23 roberto Exp roberto $
|
||||
** Lua stand-alone interpreter
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -72,7 +72,7 @@ int main (int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
else {
|
||||
int result = lua_dofile (argv[i]);
|
||||
int result = lua_dofile(argv[i]);
|
||||
if (result) {
|
||||
if (result == 2) {
|
||||
fprintf(stderr, "lua: cannot execute file ");
|
||||
|
4
lua.stx
4
lua.stx
@ -1,6 +1,6 @@
|
||||
%{
|
||||
/*
|
||||
** $Id: lua.stx,v 1.17 1997/11/07 15:09:49 roberto Exp roberto $
|
||||
** $Id: lua.stx,v 1.18 1997/11/19 17:29:23 roberto Exp roberto $
|
||||
** Syntax analizer and code generator
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -613,7 +613,7 @@ TProtoFunc *luaY_parser (ZIO *z, char *chunkname)
|
||||
L->lexstate = &lexstate;
|
||||
luaX_setinput(z);
|
||||
init_state(luaS_new(chunkname));
|
||||
if (luaY_parse ()) lua_error("parse error");
|
||||
if (luaY_parse()) lua_error("parse error");
|
||||
return close_func();
|
||||
}
|
||||
|
||||
|
210
lvm.c
210
lvm.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lvm.c,v 1.13 1997/10/27 16:14:37 roberto Exp roberto $
|
||||
** $Id: lvm.c,v 1.14 1997/11/19 17:29:23 roberto Exp roberto $
|
||||
** Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -79,12 +79,13 @@ int luaV_tostring (TObject *obj)
|
||||
|
||||
void luaV_closure (int nelems)
|
||||
{
|
||||
struct Stack *S = &L->stack;
|
||||
Closure *c = luaF_newclosure(nelems);
|
||||
c->consts[0] = *(L->stack.top-1);
|
||||
memcpy(&c->consts[1], L->stack.top-(nelems+1), nelems*sizeof(TObject));
|
||||
L->stack.top -= nelems;
|
||||
ttype(L->stack.top-1) = LUA_T_FUNCTION;
|
||||
(L->stack.top-1)->value.cl = c;
|
||||
c->consts[0] = *(S->top-1);
|
||||
memcpy(&c->consts[1], S->top-(nelems+1), nelems*sizeof(TObject));
|
||||
S->top -= nelems;
|
||||
ttype(S->top-1) = LUA_T_FUNCTION;
|
||||
(S->top-1)->value.cl = c;
|
||||
}
|
||||
|
||||
|
||||
@ -94,23 +95,24 @@ void luaV_closure (int nelems)
|
||||
*/
|
||||
void luaV_gettable (void)
|
||||
{
|
||||
struct Stack *S = &L->stack;
|
||||
TObject *im;
|
||||
if (ttype(L->stack.top-2) != LUA_T_ARRAY) /* not a table, get "gettable" method */
|
||||
im = luaT_getimbyObj(L->stack.top-2, IM_GETTABLE);
|
||||
if (ttype(S->top-2) != LUA_T_ARRAY) /* not a table, get "gettable" method */
|
||||
im = luaT_getimbyObj(S->top-2, IM_GETTABLE);
|
||||
else { /* object is a table... */
|
||||
int tg = (L->stack.top-2)->value.a->htag;
|
||||
int tg = (S->top-2)->value.a->htag;
|
||||
im = luaT_getim(tg, IM_GETTABLE);
|
||||
if (ttype(im) == LUA_T_NIL) { /* and does not have a "gettable" method */
|
||||
TObject *h = luaH_get(avalue(L->stack.top-2), L->stack.top-1);
|
||||
TObject *h = luaH_get(avalue(S->top-2), S->top-1);
|
||||
if (h != NULL && ttype(h) != LUA_T_NIL) {
|
||||
--L->stack.top;
|
||||
*(L->stack.top-1) = *h;
|
||||
--S->top;
|
||||
*(S->top-1) = *h;
|
||||
}
|
||||
else if (ttype(im=luaT_getim(tg, IM_INDEX)) != LUA_T_NIL)
|
||||
luaD_callTM(im, 2, 1);
|
||||
else {
|
||||
--L->stack.top;
|
||||
ttype(L->stack.top-1) = LUA_T_NIL;
|
||||
--S->top;
|
||||
ttype(S->top-1) = LUA_T_NIL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -125,26 +127,27 @@ void luaV_gettable (void)
|
||||
|
||||
|
||||
/*
|
||||
** Function to store indexed based on values at the L->stack.top
|
||||
** Function to store indexed based on values at the stack.top
|
||||
** mode = 0: raw store (without internal methods)
|
||||
** mode = 1: normal store (with internal methods)
|
||||
** mode = 2: "deep L->stack.stack" store (with internal methods)
|
||||
*/
|
||||
void luaV_settable (TObject *t, int mode)
|
||||
{
|
||||
struct Stack *S = &L->stack;
|
||||
TObject *im = (mode == 0) ? NULL : luaT_getimbyObj(t, IM_SETTABLE);
|
||||
if (ttype(t) == LUA_T_ARRAY && (im == NULL || ttype(im) == LUA_T_NIL)) {
|
||||
TObject *h = luaH_set(avalue(t), t+1);
|
||||
*h = *(L->stack.top-1);
|
||||
L->stack.top -= (mode == 2) ? 1 : 3;
|
||||
*h = *(S->top-1);
|
||||
S->top -= (mode == 2) ? 1 : 3;
|
||||
}
|
||||
else { /* object is not a table, and/or has a specific "settable" method */
|
||||
if (im && ttype(im) != LUA_T_NIL) {
|
||||
if (mode == 2) {
|
||||
*(L->stack.top+1) = *(L->stack.top-1);
|
||||
*(L->stack.top) = *(t+1);
|
||||
*(L->stack.top-1) = *t;
|
||||
L->stack.top += 2; /* WARNING: caller must assure stack space */
|
||||
*(S->top+1) = *(L->stack.top-1);
|
||||
*(S->top) = *(t+1);
|
||||
*(S->top-1) = *t;
|
||||
S->top += 2; /* WARNING: caller must assure stack space */
|
||||
}
|
||||
luaD_callTM(im, 3, 0);
|
||||
}
|
||||
@ -163,10 +166,11 @@ void luaV_getglobal (TaggedString *ts)
|
||||
*L->stack.top++ = *value;
|
||||
}
|
||||
else {
|
||||
ttype(L->stack.top) = LUA_T_STRING;
|
||||
tsvalue(L->stack.top) = ts;
|
||||
L->stack.top++;
|
||||
*L->stack.top++ = *value;
|
||||
struct Stack *S = &L->stack;
|
||||
ttype(S->top) = LUA_T_STRING;
|
||||
tsvalue(S->top) = ts;
|
||||
S->top++;
|
||||
*S->top++ = *value;
|
||||
luaD_callTM(im, 2, 1);
|
||||
}
|
||||
}
|
||||
@ -180,11 +184,12 @@ void luaV_setglobal (TaggedString *ts)
|
||||
luaS_rawsetglobal(ts, --L->stack.top);
|
||||
else {
|
||||
/* WARNING: caller must assure stack space */
|
||||
TObject newvalue = *(L->stack.top-1);
|
||||
ttype(L->stack.top-1) = LUA_T_STRING;
|
||||
tsvalue(L->stack.top-1) = ts;
|
||||
*L->stack.top++ = *oldvalue;
|
||||
*L->stack.top++ = newvalue;
|
||||
struct Stack *S = &L->stack;
|
||||
TObject newvalue = *(S->top-1);
|
||||
ttype(S->top-1) = LUA_T_STRING;
|
||||
tsvalue(S->top-1) = ts;
|
||||
*S->top++ = *oldvalue;
|
||||
*S->top++ = newvalue;
|
||||
luaD_callTM(im, 3, 0);
|
||||
}
|
||||
}
|
||||
@ -215,8 +220,9 @@ static void call_arith (IMS event)
|
||||
static void comparison (lua_Type ttype_less, lua_Type ttype_equal,
|
||||
lua_Type ttype_great, IMS op)
|
||||
{
|
||||
TObject *l = L->stack.top-2;
|
||||
TObject *r = L->stack.top-1;
|
||||
struct Stack *S = &L->stack;
|
||||
TObject *l = S->top-2;
|
||||
TObject *r = S->top-1;
|
||||
int result;
|
||||
if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER)
|
||||
result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1;
|
||||
@ -226,9 +232,9 @@ static void comparison (lua_Type ttype_less, lua_Type ttype_equal,
|
||||
call_binTM(op, "unexpected type at comparison");
|
||||
return;
|
||||
}
|
||||
L->stack.top--;
|
||||
nvalue(L->stack.top-1) = 1;
|
||||
ttype(L->stack.top-1) = (result < 0) ? ttype_less :
|
||||
S->top--;
|
||||
nvalue(S->top-1) = 1;
|
||||
ttype(S->top-1) = (result < 0) ? ttype_less :
|
||||
(result == 0) ? ttype_equal : ttype_great;
|
||||
}
|
||||
|
||||
@ -275,7 +281,7 @@ static void adjust_varargs (StkId first_extra_arg)
|
||||
*/
|
||||
StkId luaV_execute (Closure *cl, StkId base)
|
||||
{
|
||||
LState *LL = L; /* to optimize */
|
||||
struct Stack *S = &L->stack; /* to optimize */
|
||||
Byte *pc = cl->consts[0].value.tf->code;
|
||||
TObject *consts = cl->consts[0].value.tf->consts;
|
||||
if (lua_callhook)
|
||||
@ -286,13 +292,13 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
switch ((OpCode)(aux = *pc++)) {
|
||||
|
||||
case PUSHNIL0:
|
||||
ttype(LL->stack.top++) = LUA_T_NIL;
|
||||
ttype(S->top++) = LUA_T_NIL;
|
||||
break;
|
||||
|
||||
case PUSHNIL:
|
||||
aux = *pc++;
|
||||
do {
|
||||
ttype(LL->stack.top++) = LUA_T_NIL;
|
||||
ttype(S->top++) = LUA_T_NIL;
|
||||
} while (aux--);
|
||||
break;
|
||||
|
||||
@ -305,9 +311,9 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case PUSHNUMBER0: case PUSHNUMBER1: case PUSHNUMBER2:
|
||||
aux -= PUSHNUMBER0;
|
||||
pushnumber:
|
||||
ttype(LL->stack.top) = LUA_T_NUMBER;
|
||||
nvalue(LL->stack.top) = aux;
|
||||
LL->stack.top++;
|
||||
ttype(S->top) = LUA_T_NUMBER;
|
||||
nvalue(S->top) = aux;
|
||||
S->top++;
|
||||
break;
|
||||
|
||||
case PUSHLOCAL:
|
||||
@ -317,7 +323,7 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7:
|
||||
aux -= PUSHLOCAL0;
|
||||
pushlocal:
|
||||
*LL->stack.top++ = *((LL->stack.stack+base) + aux);
|
||||
*S->top++ = *((S->stack+base) + aux);
|
||||
break;
|
||||
|
||||
case GETGLOBALW:
|
||||
@ -347,7 +353,7 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case GETDOTTED4: case GETDOTTED5: case GETDOTTED6: case GETDOTTED7:
|
||||
aux -= GETDOTTED0;
|
||||
getdotted:
|
||||
*LL->stack.top++ = consts[aux];
|
||||
*S->top++ = consts[aux];
|
||||
luaV_gettable();
|
||||
break;
|
||||
|
||||
@ -357,10 +363,10 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case PUSHSELF:
|
||||
aux = *pc++;
|
||||
pushself: {
|
||||
TObject receiver = *(LL->stack.top-1);
|
||||
*LL->stack.top++ = consts[aux];
|
||||
TObject receiver = *(S->top-1);
|
||||
*S->top++ = consts[aux];
|
||||
luaV_gettable();
|
||||
*LL->stack.top++ = receiver;
|
||||
*S->top++ = receiver;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -375,7 +381,7 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case PUSHCONSTANT6: case PUSHCONSTANT7:
|
||||
aux -= PUSHCONSTANT0;
|
||||
pushconstant:
|
||||
*LL->stack.top++ = consts[aux];
|
||||
*S->top++ = consts[aux];
|
||||
break;
|
||||
|
||||
case PUSHUPVALUE:
|
||||
@ -384,7 +390,7 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case PUSHUPVALUE0: case PUSHUPVALUE1:
|
||||
aux -= PUSHUPVALUE0;
|
||||
pushupvalue:
|
||||
*LL->stack.top++ = cl->consts[aux+1];
|
||||
*S->top++ = cl->consts[aux+1];
|
||||
break;
|
||||
|
||||
case SETLOCAL:
|
||||
@ -394,7 +400,7 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case SETLOCAL4: case SETLOCAL5: case SETLOCAL6: case SETLOCAL7:
|
||||
aux -= SETLOCAL0;
|
||||
setlocal:
|
||||
*((LL->stack.stack+base) + aux) = *(--LL->stack.top);
|
||||
*((S->stack+base) + aux) = *(--S->top);
|
||||
break;
|
||||
|
||||
case SETGLOBALW:
|
||||
@ -411,11 +417,11 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
break;
|
||||
|
||||
case SETTABLE0:
|
||||
luaV_settable(LL->stack.top-3, 1);
|
||||
luaV_settable(S->top-3, 1);
|
||||
break;
|
||||
|
||||
case SETTABLE:
|
||||
luaV_settable(LL->stack.top-3-(*pc++), 2);
|
||||
luaV_settable(S->top-3-(*pc++), 2);
|
||||
break;
|
||||
|
||||
case SETLISTW:
|
||||
@ -428,12 +434,12 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
aux = 0;
|
||||
setlist: {
|
||||
int n = *(pc++);
|
||||
TObject *arr = LL->stack.top-n-1;
|
||||
TObject *arr = S->top-n-1;
|
||||
for (; n; n--) {
|
||||
ttype(LL->stack.top) = LUA_T_NUMBER;
|
||||
nvalue(LL->stack.top) = n+aux;
|
||||
*(luaH_set (avalue(arr), LL->stack.top)) = *(LL->stack.top-1);
|
||||
LL->stack.top--;
|
||||
ttype(S->top) = LUA_T_NUMBER;
|
||||
nvalue(S->top) = n+aux;
|
||||
*(luaH_set(avalue(arr), S->top)) = *(S->top-1);
|
||||
S->top--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -444,10 +450,10 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case SETMAP:
|
||||
aux = *pc++;
|
||||
setmap: {
|
||||
TObject *arr = LL->stack.top-(2*aux)-3;
|
||||
TObject *arr = S->top-(2*aux)-3;
|
||||
do {
|
||||
*(luaH_set (avalue(arr), LL->stack.top-2)) = *(LL->stack.top-1);
|
||||
LL->stack.top-=2;
|
||||
*(luaH_set(avalue(arr), S->top-2)) = *(S->top-1);
|
||||
S->top-=2;
|
||||
} while (aux--);
|
||||
break;
|
||||
}
|
||||
@ -458,7 +464,7 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case POP0: case POP1:
|
||||
aux -= POP0;
|
||||
pop:
|
||||
LL->stack.top -= (aux+1);
|
||||
S->top -= (aux+1);
|
||||
break;
|
||||
|
||||
case ARGS:
|
||||
@ -480,17 +486,17 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
aux = *pc++;
|
||||
createarray:
|
||||
luaC_checkGC();
|
||||
avalue(LL->stack.top) = luaH_new(aux);
|
||||
ttype(LL->stack.top) = LUA_T_ARRAY;
|
||||
LL->stack.top++;
|
||||
avalue(S->top) = luaH_new(aux);
|
||||
ttype(S->top) = LUA_T_ARRAY;
|
||||
S->top++;
|
||||
break;
|
||||
|
||||
case EQOP: case NEQOP: {
|
||||
int res = luaO_equalObj(LL->stack.top-2, LL->stack.top-1);
|
||||
LL->stack.top--;
|
||||
int res = luaO_equalObj(S->top-2, S->top-1);
|
||||
S->top--;
|
||||
if (aux == NEQOP) res = !res;
|
||||
ttype(LL->stack.top-1) = res ? LUA_T_NUMBER : LUA_T_NIL;
|
||||
nvalue(LL->stack.top-1) = 1;
|
||||
ttype(S->top-1) = res ? LUA_T_NUMBER : LUA_T_NIL;
|
||||
nvalue(S->top-1) = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -511,49 +517,49 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
break;
|
||||
|
||||
case ADDOP: {
|
||||
TObject *l = LL->stack.top-2;
|
||||
TObject *r = LL->stack.top-1;
|
||||
TObject *l = S->top-2;
|
||||
TObject *r = S->top-1;
|
||||
if (tonumber(r) || tonumber(l))
|
||||
call_arith(IM_ADD);
|
||||
else {
|
||||
nvalue(l) += nvalue(r);
|
||||
--LL->stack.top;
|
||||
--S->top;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SUBOP: {
|
||||
TObject *l = LL->stack.top-2;
|
||||
TObject *r = LL->stack.top-1;
|
||||
TObject *l = S->top-2;
|
||||
TObject *r = S->top-1;
|
||||
if (tonumber(r) || tonumber(l))
|
||||
call_arith(IM_SUB);
|
||||
else {
|
||||
nvalue(l) -= nvalue(r);
|
||||
--LL->stack.top;
|
||||
--S->top;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case MULTOP: {
|
||||
TObject *l = LL->stack.top-2;
|
||||
TObject *r = LL->stack.top-1;
|
||||
TObject *l = S->top-2;
|
||||
TObject *r = S->top-1;
|
||||
if (tonumber(r) || tonumber(l))
|
||||
call_arith(IM_MUL);
|
||||
else {
|
||||
nvalue(l) *= nvalue(r);
|
||||
--LL->stack.top;
|
||||
--S->top;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case DIVOP: {
|
||||
TObject *l = LL->stack.top-2;
|
||||
TObject *r = LL->stack.top-1;
|
||||
TObject *l = S->top-2;
|
||||
TObject *r = S->top-1;
|
||||
if (tonumber(r) || tonumber(l))
|
||||
call_arith(IM_DIV);
|
||||
else {
|
||||
nvalue(l) /= nvalue(r);
|
||||
--LL->stack.top;
|
||||
--S->top;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -563,32 +569,32 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
break;
|
||||
|
||||
case CONCOP: {
|
||||
TObject *l = LL->stack.top-2;
|
||||
TObject *r = LL->stack.top-1;
|
||||
TObject *l = S->top-2;
|
||||
TObject *r = S->top-1;
|
||||
if (tostring(l) || tostring(r))
|
||||
call_binTM(IM_CONCAT, "unexpected type for concatenation");
|
||||
else {
|
||||
tsvalue(l) = strconc(svalue(l), svalue(r));
|
||||
--LL->stack.top;
|
||||
--S->top;
|
||||
}
|
||||
luaC_checkGC();
|
||||
break;
|
||||
}
|
||||
|
||||
case MINUSOP:
|
||||
if (tonumber(LL->stack.top-1)) {
|
||||
ttype(LL->stack.top) = LUA_T_NIL;
|
||||
LL->stack.top++;
|
||||
if (tonumber(S->top-1)) {
|
||||
ttype(S->top) = LUA_T_NIL;
|
||||
S->top++;
|
||||
call_arith(IM_UNM);
|
||||
}
|
||||
else
|
||||
nvalue(LL->stack.top-1) = - nvalue(LL->stack.top-1);
|
||||
nvalue(S->top-1) = - nvalue(S->top-1);
|
||||
break;
|
||||
|
||||
case NOTOP:
|
||||
ttype(LL->stack.top-1) =
|
||||
(ttype(LL->stack.top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL;
|
||||
nvalue(LL->stack.top-1) = 1;
|
||||
ttype(S->top-1) =
|
||||
(ttype(S->top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL;
|
||||
nvalue(S->top-1) = 1;
|
||||
break;
|
||||
|
||||
case ONTJMPW:
|
||||
@ -597,8 +603,8 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case ONTJMP:
|
||||
aux = *pc++;
|
||||
ontjmp:
|
||||
if (ttype(LL->stack.top-1) != LUA_T_NIL) pc += aux;
|
||||
else LL->stack.top--;
|
||||
if (ttype(S->top-1) != LUA_T_NIL) pc += aux;
|
||||
else S->top--;
|
||||
break;
|
||||
|
||||
case ONFJMPW:
|
||||
@ -607,8 +613,8 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case ONFJMP:
|
||||
aux = *pc++;
|
||||
onfjmp:
|
||||
if (ttype(LL->stack.top-1) == LUA_T_NIL) pc += aux;
|
||||
else LL->stack.top--;
|
||||
if (ttype(S->top-1) == LUA_T_NIL) pc += aux;
|
||||
else S->top--;
|
||||
break;
|
||||
|
||||
case JMPW:
|
||||
@ -626,7 +632,7 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case IFFJMP:
|
||||
aux = *pc++;
|
||||
iffjmp:
|
||||
if (ttype(--LL->stack.top) == LUA_T_NIL) pc += aux;
|
||||
if (ttype(--S->top) == LUA_T_NIL) pc += aux;
|
||||
break;
|
||||
|
||||
case IFTUPJMPW:
|
||||
@ -635,7 +641,7 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case IFTUPJMP:
|
||||
aux = *pc++;
|
||||
iftupjmp:
|
||||
if (ttype(--LL->stack.top) != LUA_T_NIL) pc -= aux;
|
||||
if (ttype(--S->top) != LUA_T_NIL) pc -= aux;
|
||||
break;
|
||||
|
||||
case IFFUPJMPW:
|
||||
@ -644,7 +650,7 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case IFFUPJMP:
|
||||
aux = *pc++;
|
||||
iffupjmp:
|
||||
if (ttype(--LL->stack.top) == LUA_T_NIL) pc -= aux;
|
||||
if (ttype(--S->top) == LUA_T_NIL) pc -= aux;
|
||||
break;
|
||||
|
||||
case CLOSURE:
|
||||
@ -663,13 +669,13 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case CALLFUNC0: case CALLFUNC1:
|
||||
aux -= CALLFUNC0;
|
||||
callfunc: {
|
||||
StkId newBase = (LL->stack.top-LL->stack.stack)-(*pc++);
|
||||
StkId newBase = (S->top-S->stack)-(*pc++);
|
||||
luaD_call(newBase, aux);
|
||||
break;
|
||||
}
|
||||
|
||||
case ENDCODE:
|
||||
LL->stack.top = LL->stack.stack + base;
|
||||
S->top = S->stack + base;
|
||||
/* goes through */
|
||||
case RETCODE:
|
||||
if (lua_callhook)
|
||||
@ -682,13 +688,13 @@ StkId luaV_execute (Closure *cl, StkId base)
|
||||
case SETLINE:
|
||||
aux = *pc++;
|
||||
setline:
|
||||
if ((LL->stack.stack+base-1)->ttype != LUA_T_LINE) {
|
||||
if ((S->stack+base-1)->ttype != LUA_T_LINE) {
|
||||
/* open space for LINE value */
|
||||
luaD_openstack((LL->stack.top-LL->stack.stack)-base);
|
||||
luaD_openstack((S->top-S->stack)-base);
|
||||
base++;
|
||||
(LL->stack.stack+base-1)->ttype = LUA_T_LINE;
|
||||
(S->stack+base-1)->ttype = LUA_T_LINE;
|
||||
}
|
||||
(LL->stack.stack+base-1)->value.i = aux;
|
||||
(S->stack+base-1)->value.i = aux;
|
||||
if (lua_linehook)
|
||||
luaD_lineHook(aux);
|
||||
break;
|
||||
|
14
lzio.c
14
lzio.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: zio.c,v 1.2 1997/06/20 19:25:54 roberto Exp $
|
||||
** $Id: lzio.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
|
||||
** a generic input stream interface
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -15,12 +15,12 @@
|
||||
|
||||
/* ----------------------------------------------------- memory buffers --- */
|
||||
|
||||
static int zmfilbuf(ZIO* z)
|
||||
static int zmfilbuf (ZIO* z)
|
||||
{
|
||||
return EOZ;
|
||||
}
|
||||
|
||||
ZIO* zmopen(ZIO* z, char* b, int size)
|
||||
ZIO* zmopen (ZIO* z, char* b, int size)
|
||||
{
|
||||
if (b==NULL) return NULL;
|
||||
z->n=size;
|
||||
@ -32,7 +32,7 @@ ZIO* zmopen(ZIO* z, char* b, int size)
|
||||
|
||||
/* ------------------------------------------------------------ strings --- */
|
||||
|
||||
ZIO* zsopen(ZIO* z, char* s)
|
||||
ZIO* zsopen (ZIO* z, char* s)
|
||||
{
|
||||
if (s==NULL) return NULL;
|
||||
return zmopen(z,s,strlen(s));
|
||||
@ -40,7 +40,7 @@ ZIO* zsopen(ZIO* z, char* s)
|
||||
|
||||
/* -------------------------------------------------------------- FILEs --- */
|
||||
|
||||
static int zffilbuf(ZIO* z)
|
||||
static int zffilbuf (ZIO* z)
|
||||
{
|
||||
int n=fread(z->buffer,1,ZBSIZE,z->u);
|
||||
if (n==0) return EOZ;
|
||||
@ -50,7 +50,7 @@ static int zffilbuf(ZIO* z)
|
||||
}
|
||||
|
||||
|
||||
ZIO* zFopen(ZIO* z, FILE* f)
|
||||
ZIO* zFopen (ZIO* z, FILE* f)
|
||||
{
|
||||
if (f==NULL) return NULL;
|
||||
z->n=0;
|
||||
@ -62,7 +62,7 @@ ZIO* zFopen(ZIO* z, FILE* f)
|
||||
|
||||
|
||||
/* --------------------------------------------------------------- read --- */
|
||||
int zread(ZIO *z, void *b, int n)
|
||||
int zread (ZIO *z, void *b, int n)
|
||||
{
|
||||
while (n) {
|
||||
int m;
|
||||
|
10
lzio.h
10
lzio.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: $
|
||||
** $Id: lzio.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
|
||||
** Buffered streams
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -22,11 +22,11 @@
|
||||
|
||||
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); /* open FILEs */
|
||||
ZIO* zsopen (ZIO* z, char* s); /* string */
|
||||
ZIO* zmopen (ZIO* z, char* b, int size); /* memory */
|
||||
|
||||
int zread(ZIO* z, void* b, int n); /* read next n bytes */
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user