This commit is contained in:
Roberto Ierusalimschy 2004-12-02 10:59:10 -02:00
parent 12dacd3c0e
commit e1c2fb6eed
4 changed files with 18 additions and 12 deletions

13
llex.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: llex.c,v 2.5 2004/11/24 19:16:03 roberto Exp roberto $ ** $Id: llex.c,v 2.6 2004/12/01 15:46:18 roberto Exp roberto $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -32,13 +32,14 @@
/* ORDER RESERVED */ /* ORDER RESERVED */
static const char *const token2string [] = { const char *const luaX_tokens [] = {
"and", "break", "do", "else", "elseif", "and", "break", "do", "else", "elseif",
"end", "false", "for", "function", "if", "end", "false", "for", "function", "if",
"in", "local", "nil", "not", "or", "repeat", "in", "local", "nil", "not", "or", "repeat",
"return", "then", "true", "until", "while", "*name", "return", "then", "true", "until", "while", "*name",
"..", "...", "==", ">=", "<=", "~=", "..", "...", "==", ">=", "<=", "~=",
"*number", "*string", "<eof>" "*number", "*string", "<eof>",
NULL
}; };
@ -61,9 +62,9 @@ static void save (LexState *ls, int c) {
void luaX_init (lua_State *L) { void luaX_init (lua_State *L) {
int i; int i;
for (i=0; i<NUM_RESERVED; i++) { for (i=0; i<NUM_RESERVED; i++) {
TString *ts = luaS_new(L, token2string[i]); TString *ts = luaS_new(L, luaX_tokens[i]);
luaS_fix(ts); /* reserved words are never collected */ luaS_fix(ts); /* reserved words are never collected */
lua_assert(strlen(token2string[i])+1 <= TOKEN_LEN); lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN);
ts->tsv.reserved = cast(lu_byte, i+1); /* reserved word */ ts->tsv.reserved = cast(lu_byte, i+1); /* reserved word */
} }
} }
@ -79,7 +80,7 @@ const char *luaX_token2str (LexState *ls, int token) {
luaO_pushfstring(ls->L, "%c", token); luaO_pushfstring(ls->L, "%c", token);
} }
else else
return token2string[token-FIRST_RESERVED]; return luaX_tokens[token-FIRST_RESERVED];
} }

6
llex.h
View File

@ -1,5 +1,5 @@
/* /*
** $Id: llex.h,v 1.49 2003/10/20 12:24:34 roberto Exp roberto $ ** $Id: llex.h,v 1.50 2004/03/12 19:53:56 roberto Exp roberto $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -36,6 +36,10 @@ enum RESERVED {
#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
/* array with token `names' */
extern const char *const luaX_tokens [];
typedef union { typedef union {
lua_Number r; lua_Number r;
TString *ts; TString *ts;

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lopcodes.c,v 1.28 2004/07/16 13:15:32 roberto Exp $ ** $Id: lopcodes.c,v 1.29 2004/10/04 19:01:53 roberto Exp roberto $
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -15,7 +15,7 @@
/* ORDER OP */ /* ORDER OP */
const char *const luaP_opnames[NUM_OPCODES] = { const char *const luaP_opnames[NUM_OPCODES+1] = {
"MOVE", "MOVE",
"LOADK", "LOADK",
"LOADBOOL", "LOADBOOL",
@ -51,7 +51,8 @@ const char *const luaP_opnames[NUM_OPCODES] = {
"SETLIST", "SETLIST",
"CLOSE", "CLOSE",
"CLOSURE", "CLOSURE",
"VARARG" "VARARG",
NULL
}; };

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lopcodes.h,v 1.112 2004/10/04 19:01:53 roberto Exp roberto $ ** $Id: lopcodes.h,v 1.113 2004/10/04 19:07:42 roberto Exp roberto $
** Opcodes for Lua virtual machine ** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -257,7 +257,7 @@ extern const lu_byte luaP_opmodes[NUM_OPCODES];
#define testTMode(m) (luaP_opmodes[m] & (1 << 7)) #define testTMode(m) (luaP_opmodes[m] & (1 << 7))
extern const char *const luaP_opnames[NUM_OPCODES]; /* opcode names */ extern const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */
/* number of list items to accumulate before a SETLIST instruction */ /* number of list items to accumulate before a SETLIST instruction */