summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLua Team <team@lua.org>1996-11-19 12:00:00 +0000
committerrepogen <>1996-11-19 12:00:00 +0000
commit47a298a24ad3a8202440051de5938618502302a0 (patch)
tree9be43568f1e90c9219d5e3860b58c8ac1db5f062 /src
parent721542976ebc89f2f8d17d19be7e4426570b69be (diff)
downloadlua-github-47a298a24ad3a8202440051de5938618502302a0.tar.gz
Lua 2.52.5
Diffstat (limited to 'src')
-rw-r--r--src/Makefile4
-rw-r--r--src/func.c2
-rw-r--r--src/hash.c46
-rw-r--r--src/inout.c98
-rw-r--r--src/inout.h3
-rw-r--r--src/lex.c213
-rw-r--r--src/lex.h4
-rw-r--r--src/lua.stx110
-rw-r--r--src/luac/dump.c47
-rw-r--r--src/luac/luac.c5
-rw-r--r--src/luac/print.c43
-rw-r--r--src/mem.c25
-rw-r--r--src/mem.h4
-rw-r--r--src/opcode.c277
-rw-r--r--src/opcode.h155
-rw-r--r--src/parser.c2253
-rw-r--r--src/parser.h57
-rw-r--r--src/table.c17
-rw-r--r--src/undump.c41
-rw-r--r--src/undump.h4
20 files changed, 1757 insertions, 1651 deletions
diff --git a/src/Makefile b/src/Makefile
index 843220dc..1ac2ab85 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -46,8 +46,8 @@ SLIB= $(LIB)/liblua.a
all: $(SLIB)
$(SLIB): $(OBJS)
- ar rcuv $@ $(OBJS)
- ranlib $@
+ ar rcu $@ $(OBJS)
+ $(RANLIB) $@
clean:
rm -f $(OBJS) $(SLIB)
diff --git a/src/func.c b/src/func.c
index 21b19a19..0e15c2fc 100644
--- a/src/func.c
+++ b/src/func.c
@@ -1,4 +1,4 @@
-#include <stdlib.h>
+#include <string.h>
#include "luadebug.h"
#include "table.h"
diff --git a/src/hash.c b/src/hash.c
index e75be129..19ae7b12 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -3,7 +3,7 @@
** hash manager for lua
*/
-char *rcs_hash="$Id: hash.c,v 2.30 1996/05/06 14:30:27 roberto Exp $";
+char *rcs_hash="$Id: hash.c,v 2.32 1996/11/18 13:48:44 roberto Exp $";
#include "mem.h"
@@ -48,24 +48,26 @@ int luaI_redimension (int nhash)
static int hashindex (Hash *t, Object *ref) /* hash function */
{
- switch (tag(ref))
- {
- case LUA_T_NIL:
- lua_error ("unexpected type to index table");
- return -1; /* UNREACHEABLE */
- case LUA_T_NUMBER:
- return (((int)nvalue(ref))%nhash(t));
- case LUA_T_STRING:
- return (int)((tsvalue(ref)->hash)%nhash(t)); /* make it a valid index */
- case LUA_T_FUNCTION:
- return (((IntPoint)ref->value.tf)%nhash(t));
- case LUA_T_CFUNCTION:
- return (((IntPoint)fvalue(ref))%nhash(t));
- case LUA_T_ARRAY:
- return (((IntPoint)avalue(ref))%nhash(t));
- default: /* user data */
- return (((IntPoint)uvalue(ref))%nhash(t));
- }
+ long int h;
+ switch (tag(ref)) {
+ case LUA_T_NIL:
+ lua_error ("unexpected type to index table");
+ h = 0; /* UNREACHEABLE */
+ case LUA_T_NUMBER:
+ h = (long int)nvalue(ref); break;
+ case LUA_T_STRING:
+ h = tsvalue(ref)->hash; break;
+ case LUA_T_FUNCTION:
+ h = (IntPoint)ref->value.tf; break;
+ case LUA_T_CFUNCTION:
+ h = (IntPoint)fvalue(ref); break;
+ case LUA_T_ARRAY:
+ h = (IntPoint)avalue(ref); break;
+ default: /* user data */
+ h = (IntPoint)uvalue(ref); break;
+ }
+ if (h < 0) h = -h;
+ return h%nhash(t); /* make it a valid index */
}
int lua_equalObj (Object *t1, Object *t2)
@@ -283,17 +285,11 @@ Object *lua_hashdefine (Hash *t, Object *ref)
static void hashnext (Hash *t, int i)
{
if (i >= nhash(t))
- {
- lua_pushnil(); lua_pushnil();
return;
- }
while (tag(ref(node(t,i))) == LUA_T_NIL || tag(val(node(t,i))) == LUA_T_NIL)
{
if (++i >= nhash(t))
- {
- lua_pushnil(); lua_pushnil();
return;
- }
}
luaI_pushobject(ref(node(t,i)));
luaI_pushobject(val(node(t,i)));
diff --git a/src/inout.c b/src/inout.c
index 85722c3c..0aa551c0 100644
--- a/src/inout.c
+++ b/src/inout.c
@@ -5,9 +5,10 @@
** Also provides some predefined lua functions.
*/
-char *rcs_inout="$Id: inout.c,v 2.36 1996/03/19 22:28:37 roberto Exp $";
+char *rcs_inout="$Id: inout.c,v 2.43 1996/09/25 12:57:22 roberto Exp $";
#include <stdio.h>
+#include <string.h>
#include "lex.h"
#include "opcode.h"
@@ -31,7 +32,8 @@ static char *st;
*/
static int fileinput (void)
{
- return fgetc (fp);
+ int c = fgetc(fp);
+ return (c == EOF) ? 0 : c;
}
/*
@@ -58,7 +60,6 @@ FILE *lua_openfile (char *fn)
fp = fopen (fn, "r");
if (fp == NULL)
return NULL;
- lua_linenumber = 1;
lua_parsedfile = luaI_createfixedstring(fn)->str;
return fp;
}
@@ -78,12 +79,16 @@ void lua_closefile (void)
/*
** Function to open a string to be input unit
*/
+#define SIZE_PREF 20 /* size of string prefix to appear in error messages */
void lua_openstring (char *s)
{
- lua_setinput (stringinput);
- st = s;
- lua_linenumber = 1;
- lua_parsedfile = luaI_createfixedstring("(string)")->str;
+ char buff[SIZE_PREF+25];
+ lua_setinput(stringinput);
+ st = s;
+ strcpy(buff, "(dostring) >> ");
+ strncat(buff, s, SIZE_PREF);
+ if (strlen(s) > SIZE_PREF) strcat(buff, "...");
+ lua_parsedfile = luaI_createfixedstring(buff)->str;
}
/*
@@ -93,17 +98,36 @@ void lua_closestring (void)
{
}
+
+static void check_arg (int cond, char *func)
+{
+ if (!cond)
+ {
+ char buff[100];
+ sprintf(buff, "incorrect argument to function `%s'", func);
+ lua_error(buff);
+ }
+}
+
+
+static int passresults (void)
+{
+ int arg = 0;
+ lua_Object obj;
+ while ((obj = lua_getresult(++arg)) != LUA_NOOBJECT)
+ lua_pushobject(obj);
+ return arg-1;
+}
/*
** Internal function: do a string
*/
void lua_internaldostring (void)
{
- lua_Object obj = lua_getparam (1);
- if (lua_isstring(obj) && !lua_dostring(lua_getstring(obj)))
- lua_pushnumber(1);
- else
- lua_pushnil();
+ lua_Object obj = lua_getparam (1);
+ if (lua_isstring(obj) && lua_dostring(lua_getstring(obj)) == 0)
+ if (passresults() == 0)
+ lua_pushuserdata(NULL); /* at least one result to signal no errors */
}
/*
@@ -118,10 +142,9 @@ void lua_internaldofile (void)
else if (obj != LUA_NOOBJECT)
lua_error("invalid argument to function `dofile'");
/* else fname = NULL */
- if (!lua_dofile(fname))
- lua_pushnumber(1);
- else
- lua_pushnil();
+ if (lua_dofile(fname) == 0)
+ if (passresults() == 0)
+ lua_pushuserdata(NULL); /* at least one result to signal no errors */
}
@@ -207,8 +230,6 @@ void lua_obj2number (void)
lua_Object o = lua_getparam(1);
if (lua_isnumber(o))
lua_pushnumber(lua_getnumber(o));
- else
- lua_pushnil();
}
@@ -230,8 +251,7 @@ void luaI_setglobal (void)
{
lua_Object name = lua_getparam(1);
lua_Object value = lua_getparam(2);
- if (!lua_isstring(name))
- lua_error("incorrect argument to function `setglobal'");
+ check_arg(lua_isstring(name), "setglobal");
lua_pushobject(value);
lua_storeglobal(lua_getstring(name));
lua_pushobject(value); /* return given value */
@@ -240,7 +260,41 @@ void luaI_setglobal (void)
void luaI_getglobal (void)
{
lua_Object name = lua_getparam(1);
- if (!lua_isstring(name))
- lua_error("incorrect argument to function `getglobal'");
+ check_arg(lua_isstring(name), "getglobal");
lua_pushobject(lua_getglobal(lua_getstring(name)));
}
+
+#define MAXPARAMS 256
+void luaI_call (void)
+{
+ lua_Object f = lua_getparam(1);
+ lua_Object arg = lua_getparam(2);
+ lua_Object temp, params[MAXPARAMS];
+ int narg, i;
+ check_arg(lua_istable(arg), "call");
+ check_arg(lua_isfunction(f), "call");
+ /* narg = arg.n */
+ lua_pushobject(arg);
+ lua_pushstring("n");
+ temp = lua_getsubscript();
+ narg = lua_isnumber(temp) ? lua_getnumber(temp) : MAXPARAMS+1;
+ /* read arg[1...n] */
+ for (i=0; i<narg; i++) {
+ if (i>=MAXPARAMS)
+ lua_error("argument list too long in function `call'");
+ lua_pushobject(arg);
+ lua_pushnumber(i+1);
+ params[i] = lua_getsubscript();
+ if (narg == MAXPARAMS+1 && lua_isnil(params[i])) {
+ narg = i;
+ break;
+ }
+ }
+ /* push parameters and do the call */
+ for (i=0; i<narg; i++)
+ lua_pushobject(params[i]);
+ if (lua_callfunction(f))
+ lua_error(NULL);
+ else
+ passresults();
+}
diff --git a/src/inout.h b/src/inout.h
index e5957753..a26f8e99 100644
--- a/src/inout.h
+++ b/src/inout.h
@@ -1,5 +1,5 @@
/*
-** $Id: inout.h,v 1.15 1996/03/15 18:21:58 roberto Exp $
+** $Id: inout.h,v 1.16 1996/05/28 21:07:32 roberto Exp $
*/
@@ -29,5 +29,6 @@ void luaI_error (void);
void luaI_assert (void);
void luaI_setglobal (void);
void luaI_getglobal (void);
+void luaI_call (void);
#endif
diff --git a/src/lex.c b/src/lex.c
index 299e81b5..bd3233a0 100644
--- a/src/lex.c
+++ b/src/lex.c
@@ -1,5 +1,5 @@
-char *rcs_lex = "$Id: lex.c,v 2.32 1996/03/21 16:33:47 roberto Exp $";
-
+char *rcs_lex = "$Id: lex.c,v 2.39 1996/11/08 19:08:30 roberto Exp $";
+
#include <ctype.h>
#include <string.h>
@@ -14,32 +14,31 @@ char *rcs_lex = "$Id: lex.c,v 2.32 1996/03/21 16:33:47 roberto Exp $";
#define MINBUFF 260
-#define next() { current = input(); }
-#define save(x) { *yytextLast++ = (x); }
-#define save_and_next() { save(current); next(); }
+#define next() (current = input())
+#define save(x) (yytext[tokensize++] = (x))
+#define save_and_next() (save(current), next())
+
-static int current;
-static char *yytext = NULL;
-static int textsize = 0;
-static char *yytextLast;
+static int current; /* look ahead character */
+static Input input; /* input function */
-static Input input;
void lua_setinput (Input fn)
{
- current = ' ';
+ current = '\n';
+ lua_linenumber = 0;
input = fn;
- if (yytext == NULL)
- {
- textsize = MINBUFF;
- yytext = newvector(textsize, char);
- }
}
-char *lua_lasttext (void)
+void luaI_syntaxerror (char *s)
{
- *yytextLast = 0;
- return yytext;
+ char msg[256];
+ char *token = luaI_buffer(1);
+ if (token[0] == 0)
+ token = "<eof>";
+ sprintf (msg,"%s;\n> last token read: \"%s\" at line %d in file %s",
+ s, token, lua_linenumber, lua_parsedfile);
+ lua_error (msg);
}
@@ -79,95 +78,97 @@ void luaI_addReserved (void)
}
}
-
-static void growtext (void)
+static int inclinenumber (int pragma_allowed)
{
- int size = yytextLast - yytext;
- textsize = growvector(&yytext, textsize, char, lexEM, MAX_WORD);
- yytextLast = yytext + size;
+ ++lua_linenumber;
+ if (pragma_allowed && current == '$') { /* is a pragma? */
+ char *buff = luaI_buffer(MINBUFF+1);
+ int i = 0;
+ next(); /* skip $ */
+ while (isalnum(current)) {
+ if (i >= MINBUFF) luaI_syntaxerror("pragma too long");
+ buff[i++] = current;
+ next();
+ }
+ buff[i] = 0;
+ if (strcmp(buff, "debug") == 0)
+ lua_debug = 1;
+ else if (strcmp(buff, "nodebug") == 0)
+ lua_debug = 0;
+ else luaI_syntaxerror("invalid pragma");
+ }
+ return lua_linenumber;
}
-
-static int read_long_string (void)
+static int read_long_string (char *yytext, int buffsize)
{
int cont = 0;
- int spaceleft = textsize - (yytextLast - yytext);
+ int tokensize = 2; /* '[[' already stored */
while (1)
{
- if (spaceleft <= 2) /* may read more than 1 char in one cicle */
- {
- growtext();
- spaceleft = textsize - (yytextLast - yytext);
- }
+ if (buffsize-tokensize <= 2) /* may read more than 1 char in one cicle */
+ yytext = luaI_buffer(buffsize *= 2);
switch (current)
{
- case EOF:
case 0:
+ save(0);
return WRONGTOKEN;
case '[':
- save_and_next(); spaceleft--;
+ save_and_next();
if (current == '[')
{
cont++;
- save_and_next(); spaceleft--;
+ save_and_next();
}
- continue;
+ continue;
case ']':
- save_and_next(); spaceleft--;
+ save_and_next();
if (current == ']')
{
- if (cont == 0) return STRING;
+ if (cont == 0) goto endloop;
cont--;
- save_and_next(); spaceleft--;
+ save_and_next();
}
- continue;
+ continue;
case '\n':
- lua_linenumber++; /* goes through */
+ save_and_next();
+ inclinenumber(0);
+ continue;
default:
- save_and_next(); spaceleft--;
+ save_and_next();
}
- }
+ } endloop:
+ save_and_next(); /* pass the second ']' */
+ yytext[tokensize-2] = 0; /* erases ']]' */
+ luaY_lval.vWord = luaI_findconstantbyname(yytext+2);
+ yytext[tokensize-2] = ']'; /* restores ']]' */
+ save(0);
+ return STRING;
}
-
int luaY_lex (void)
{
- double a;
static int linelasttoken = 0;
+ double a;
+ int buffsize = MINBUFF;
+ char *yytext = luaI_buffer(buffsize);
+ yytext[1] = yytext[2] = yytext[3] = 0;
if (lua_debug)
luaI_codedebugline(linelasttoken);
linelasttoken = lua_linenumber;
while (1)
{
- yytextLast = yytext;
+ int tokensize = 0;
switch (current)
{
- case EOF:
- case 0:
- return 0;
- case '\n': linelasttoken = ++lua_linenumber;
- case ' ':
- case '\r': /* CR: to avoid problems with DOS/Windows */
- case '\t':
+ case '\n':
next();
+ linelasttoken = inclinenumber(1);
continue;
- case '$':
- next();
- while (isalnum(current) || current == '_')
- save_and_next();
- *yytextLast = 0;
- if (strcmp(yytext, "debug") == 0)
- {
- luaY_lval.vInt = 1;
- return DEBUG;
- }
- else if (strcmp(yytext, "nodebug") == 0)
- {
- luaY_lval.vInt = 0;
- return DEBUG;
- }
- return WRONGTOKEN;
+ case ' ': case '\t': case '\r': /* CR: to avoid problems with DOS */
+ next();
+ continue;
case '-':
save_and_next();
@@ -181,12 +182,7 @@ int luaY_lex (void)
else
{
save_and_next(); /* pass the second '[' */
- if (read_long_string() == WRONGTOKEN)
- return WRONGTOKEN;
- save_and_next(); /* pass the second ']' */
- *(yytextLast-2) = 0; /* erases ']]' */
- luaY_lval.vWord = luaI_findconstantbyname(yytext+2);
- return STRING;
+ return read_long_string(yytext, buffsize);
}
case '=':
@@ -213,21 +209,16 @@ int luaY_lex (void)
case '\'':
{
int del = current;
- int spaceleft = textsize - (yytextLast - yytext);
- next(); /* skip the delimiter */
+ save_and_next();
while (current != del)
{
- if (spaceleft <= 2) /* may read more than 1 char in one cicle */
- {
- growtext();
- spaceleft = textsize - (yytextLast - yytext);
- }
- spaceleft--;
+ if (buffsize-tokensize <= 2) /* may read more than 1 char in one cicle */
+ yytext = luaI_buffer(buffsize *= 2);
switch (current)
{
- case EOF:
case 0:
case '\n':
+ save(0);
return WRONGTOKEN;
case '\\':
next(); /* do not save the '\' */
@@ -236,17 +227,19 @@ int luaY_lex (void)
case 'n': save('\n'); next(); break;
case 't': save('\t'); next(); break;
case 'r': save('\r'); next(); break;
- case '\n': lua_linenumber++; /* goes through */
- default : save(current); next(); break;
+ case '\n': save_and_next(); inclinenumber(0); break;
+ default : save_and_next(); break;
}
break;
default:
save_and_next();
}
}
- next(); /* skip the delimiter */
- *yytextLast = 0;
- luaY_lval.vWord = luaI_findconstantbyname(yytext);
+ next(); /* skip delimiter */
+ save(0);
+ luaY_lval.vWord = luaI_findconstantbyname(yytext+1);
+ tokensize--;
+ save(del); save(0); /* restore delimiter */
return STRING;
}
@@ -266,7 +259,7 @@ int luaY_lex (void)
{
TaggedString *ts;
do { save_and_next(); } while (isalnum(current) || current == '_');
- *yytextLast = 0;
+ save(0);
ts = lua_createstring(yytext);
if (ts->marked > 2)
return ts->marked; /* reserved word */
@@ -280,7 +273,12 @@ int luaY_lex (void)
if (current == '.')
{
save_and_next();
- return CONC;
+ if (current == '.')
+ {
+ save_and_next();
+ return DOTS; /* ... */
+ }
+ else return CONC; /* .. */
}
else if (!isdigit(current)) return '.';
/* current is a digit: goes through to number */
@@ -290,12 +288,24 @@ int luaY_lex (void)
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
a=0.0;
- do { a=10.0*a+(current-'0'); save_and_next(); } while (isdigit(current));
- if (current == '.') save_and_next();
-fraction:
+ do {
+ a=10.0*a+(current-'0');
+ save_and_next();
+ } while (isdigit(current));
+ if (current == '.') {
+ save_and_next();
+ if (current == '.')
+ luaI_syntaxerror(
+ "ambiguous syntax (decimal point x string concatenation)");
+ }
+ fraction:
{ double da=0.1;
while (isdigit(current))
- {a+=(current-'0')*da; da/=10.0; save_and_next()};
+ {
+ a+=(current-'0')*da;
+ da/=10.0;
+ save_and_next();
+ }
if (current == 'e' || current == 'E')
{
int e=0;
@@ -304,19 +314,23 @@ fraction:
save_and_next();
neg=(current=='-');
if (current == '+' || current == '-') save_and_next();
- if (!isdigit(current)) return WRONGTOKEN;
- do { e=10.0*e+(current-'0'); save_and_next(); } while (isdigit(current));
- for (ea=neg?0.1:10.0; e>0; e>>=1)
+ if (!isdigit(current)) { save(0); return WRONGTOKEN; }
+ do {
+ e=10.0*e+(current-'0');
+ save_and_next();
+ } while (isdigit(current));
+ for (ea=neg?0.1:10.0; e>0; e>>=1)
{
if (e & 1) a*=ea;
ea*=ea;
}
}
luaY_lval.vFloat = a;
+ save(0);
return NUMBER;
}
- default: /* also end of file */
+ default: /* also end of program (0) */
{
save_and_next();
return yytext[0];
@@ -324,3 +338,4 @@ fraction:
}
}
}
+
diff --git a/src/lex.h b/src/lex.h
index 7ed6fd2d..5245d062 100644
--- a/src/lex.h
+++ b/src/lex.h
@@ -1,7 +1,7 @@
/*
** lex.h
** TecCGraf - PUC-Rio
-** $Id: lex.h,v 1.2 1996/02/14 13:35:51 roberto Exp $
+** $Id: lex.h,v 1.3 1996/11/08 12:49:35 roberto Exp $
*/
#ifndef lex_h
@@ -11,7 +11,7 @@
typedef int (*Input) (void);
void lua_setinput (Input fn);
-char *lua_lasttext (void);
+void luaI_syntaxerror (char *s);
int luaY_lex (void);
void luaI_addReserved (void);
diff --git a/src/lua.stx b/src/lua.stx
index 54c5a38c..00752604 100644
--- a/src/lua.stx
+++ b/src/lua.stx
@@ -1,9 +1,10 @@
%{
-char *rcs_luastx = "$Id: lua.stx,v 3.36 1996/03/21 16:31:32 roberto Exp $";
+char *rcs_luastx = "$Id: lua.stx,v 3.41 1996/11/08 12:49:35 roberto Exp $";
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "luadebug.h"
#include "mem.h"
@@ -58,58 +59,48 @@ int lua_debug = 0;
static void yyerror (char *s)
{
- char msg[256];
- char *token = lua_lasttext();
- if (token[0] == 0)
- token = "<eof>";
- sprintf (msg,"%s; last token read: \"%s\" at line %d in file `%s'",
- s, token, lua_linenumber, lua_parsedfile);
- lua_error (msg);
+ luaI_syntaxerror(s);
+}
+
+static void check_space (int i)
+{
+ if (pc+i>maxcurr-1) /* 1 byte free to code HALT of main code */
+ maxcurr = growvector(&basepc, maxcurr, Byte, codeEM, MAX_INT);
}
static void code_byte (Byte c)
{
- if (pc>maxcurr-2) /* 1 byte free to code HALT of main code */
- maxcurr = growvector(&basepc, maxcurr, Byte, codeEM, MAX_INT);
+ check_space(1);
basepc[pc++] = c;
}
static void code_word (Word n)
{
- CodeWord code;
- code.w = n;
- code_byte(code.m.c1);
- code_byte(code.m.c2);
+ check_space(sizeof(Word));
+ memcpy(basepc+pc, &n, sizeof(Word));
+ pc += sizeof(Word);
}
-static void code_float (float n)
+static void code_float (real n)
{
- CodeFloat code;
- code.f = n;
- code_byte(code.m.c1);
- code_byte(code.m.c2);
- code_byte(code.m.c3);
- code_byte(code.m.c4);
+ check_space(sizeof(real));
+ memcpy(basepc+pc, &n, sizeof(real));
+ pc += sizeof(real);
}
static void code_code (TFunc *tf)
{
- CodeCode code;
- code.tf = tf;
- code_byte(code.m.c1);
- code_byte(code.m.c2);
- code_byte(code.m.c3);
- code_byte(code.m.c4);
+ check_space(sizeof(TFunc *));
+ memcpy(basepc+pc, &tf, sizeof(TFunc *));
+ pc += sizeof(TFunc *);
}
static void code_word_at (Byte *p, int n)
{
- CodeWord code;
- if ((Word)n != n)
- yyerror("block too big");
- code.w = (Word)n;
- *p++ = code.m.c1;
- *p++ = code.m.c2;
+ Word w = n;
+ if (w != n)
+ yyerror("block too big");
+ memcpy(p, &w, sizeof(Word));
}
static void push_field (Word name)
@@ -322,6 +313,19 @@ static void adjust_mult_assign (int vars, Long exps, int temps)
lua_codeadjust(temps);
}
+static int close_parlist (int dots)
+{
+ if (!dots)
+ lua_codeadjust(0);
+ else
+ {
+ code_byte(VARARGS);
+ code_byte(nlocalvar);
+ add_localvar(luaI_createfixedstring("arg"));
+ }
+ return lua_linenumber;
+}
+
static void storesinglevar (Long v)
{
if (v > 0) /* global var */
@@ -418,7 +422,7 @@ void lua_parse (TFunc *tf)
TaggedString *pTStr;
}
-%start functionlist
+%start chunk
%token WRONGTOKEN
%token NIL
@@ -426,10 +430,10 @@ void lua_parse (TFunc *tf)
%token RETURN
%token LOCAL
%token FUNCTION
+%token DOTS
%token <vFloat> NUMBER
%token <vWord> STRING
%token <pTStr> NAME
-%token <vInt> DEBUG
%type <vLong> PrepJump
%type <vLong> exprlist, exprlist1 /* if > 0, points to function return
@@ -440,7 +444,7 @@ void lua_parse (TFunc *tf)
%type <vInt> fieldlist, localdeclist, decinit
%type <vInt> ffieldlist, ffieldlist1, semicolonpart
%type <vInt> lfieldlist, lfieldlist1
-%type <vInt> parlist
+%type <vInt> parlist, parlist1, par
%type <vLong> var, singlevar, funcname
%type <pFunc> body
@@ -455,15 +459,12 @@ void lua_parse (TFunc *tf)
%% /* beginning of rules section */
+chunk : chunklist ret
-functionlist : /* empty */
- | functionlist globalstat
- | functionlist function
- ;
-
-globalstat : stat sc
- | setdebug
- ;
+chunklist : /* empty */
+ | chunklist stat sc
+ | chunklist function
+ ;
function : FUNCTION funcname body
{
@@ -580,6 +581,7 @@ PrepJump : /* empty */
code_byte(0); /* open space */
code_word (0);
}
+ ;
expr1 : expr { adjust_functioncall($1, 1); }
;
@@ -674,13 +676,22 @@ exprlist1 : expr { if ($1 != 0) $$ = $1; else $$ = -1; }
}
;
-parlist : /* empty */ { lua_codeadjust(0); $$ = lua_linenumber; }
- | parlist1 { lua_codeadjust(0); $$ = lua_linenumber; }
+parlist : /* empty */ { $$ = close_parlist(0); }
+ | parlist1 { $$ = close_parlist($1); }
;
-parlist1 : NAME { add_localvar($1); }
- | parlist1 ',' NAME { add_localvar($3); }
+parlist1 : par { $$ = $1; }
+ | parlist1 ',' par
+ {
+ if ($1)
+ lua_error("invalid parameter list");
+ $$ = $3;
+ }
;
+
+par : NAME { add_localvar($1); $$ = 0; }
+ | DOTS { $$ = 1; }
+ ;
fieldlist : lfieldlist
{ flush_list($1/FIELDS_PER_FLUSH, $1%FIELDS_PER_FLUSH); }
@@ -782,7 +793,4 @@ decinit : /* empty */ { $$ = 0; }
| '=' exprlist1 { $$ = $2; }
;
-setdebug : DEBUG { lua_debug = $1; }
- ;
-
%%
diff --git a/src/luac/dump.c b/src/luac/dump.c
index 22db5e36..656cc293 100644
--- a/src/luac/dump.c
+++ b/src/luac/dump.c
@@ -3,9 +3,10 @@
** thread and save bytecodes to file
*/
-char* rcs_dump="$Id: dump.c,v 1.12 1996/03/12 20:00:03 lhf Exp $";
+char* rcs_dump="$Id: dump.c,v 1.17 1996/11/18 11:18:29 lhf Exp $";
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "luac.h"
@@ -104,38 +105,36 @@ static void ThreadCode(Byte* code, Byte* end)
p+=3;
break;
case PUSHFLOAT:
- p+=5;
+ p+=5; /* assumes sizeof(float)==4 */
break;
case PUSHSELF:
case PUSHSTRING:
{
- CodeWord c;
+ Word w;
p++;
- get_word(c,p);
- c.w=SawStr(c.w,at);
- p[-2]=c.m.c1;
- p[-1]=c.m.c2;
+ get_word(w,p);
+ w=SawStr(w,at);
+ memcpy(p-2,&w,sizeof(w));
break;
}
case PUSHFUNCTION:
{
- CodeCode c;
+ TFunc* tf;
p++;
- get_code(c,p);
- c.tf->marked=at;
- c.tf->next=NULL; /* TODO: remove? */
- lastF=lastF->next=c.tf;
+ get_code(tf,p);
+ tf->marked=at;
+ tf->next=NULL; /* TODO: remove? */
+ lastF=lastF->next=tf;
break;
}
case PUSHGLOBAL:
case STOREGLOBAL:
{
- CodeWord c;
+ Word w;
p++;
- get_word(c,p);
- c.w=SawVar(c.w,at);
- p[-2]=c.m.c1;
- p[-1]=c.m.c2;
+ get_word(w,p);
+ w=SawVar(w,at);
+ memcpy(p-2,&w,sizeof(w));
break;
}
case STORERECORD:
@@ -144,12 +143,11 @@ static void ThreadCode(Byte* code, Byte* end)
p++;
while (n--)
{
- CodeWord c;
+ Word w;
at=p-code;
- get_word(c,p);
- c.w=SawStr(c.w,at);
- p[-2]=c.m.c1;
- p[-1]=c.m.c2;
+ get_word(w,p);
+ w=SawStr(w,at);
+ memcpy(p-2,&w,sizeof(w));
}
break;
}
@@ -167,7 +165,7 @@ static void DumpWord(int i, FILE* D)
fwrite(&w,sizeof(w),1,D);
}
-static void DumpBlock(char* b, int size, FILE* D)
+static void DumpBlock(void* b, int size, FILE* D)
{
fwrite(b,size,1,D);
}
@@ -242,6 +240,9 @@ void DumpHeader(FILE* D)
fputc(ID_CHUNK,D);
fputs(SIGNATURE,D);
fputc(VERSION,D);
+ fputc(sizeof(Word),D);
+ fputc(sizeof(float),D);
+ fputc(sizeof(TFunc*),D);
fwrite(&w,sizeof(w),1,D);
fwrite(&f,sizeof(f),1,D);
}
diff --git a/src/luac/luac.c b/src/luac/luac.c
index aa71afcf..7546c1bb 100644
--- a/src/luac/luac.c
+++ b/src/luac/luac.c
@@ -3,9 +3,10 @@
** lua compiler (saves bytecodes to files)
*/
-char* rcs_luac="$Id: luac.c,v 1.16 1996/03/13 17:33:03 lhf Exp $";
+char* rcs_luac="$Id: luac.c,v 1.18 1996/11/16 20:14:23 lhf Exp $";
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "luac.h"
@@ -56,7 +57,7 @@ int main(int argc, char* argv[])
fprintf(stderr,"luac: will not overwrite input file \"%s\"\n",d);
exit(1);
}
- D=(dumping) ? fopen(d,"wb") : stdout; /* must open in binary mode */
+ D=(dumping) ? fopen(d,"wb") : stdout; /* must open in binary mode */
if (D==NULL)
{
fprintf(stderr,"luac: cannot open ");
diff --git a/src/luac/print.c b/src/luac/print.c
index 1b338931..0e1d2569 100644
--- a/src/luac/print.c
+++ b/src/luac/print.c
@@ -3,9 +3,10 @@
** print bytecodes
*/
-char* rcs_print="$Id: print.c,v 1.6 1996/03/12 20:00:24 lhf Exp $";
+char* rcs_print="$Id: print.c,v 1.11 1996/11/18 11:24:16 lhf Exp $";
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "luac.h"
#include "print.h"
@@ -24,7 +25,7 @@ static void PrintCode(Byte* code, Byte* end)
{
OpCode op=(OpCode)*p;
if (op>SETLINE) op=SETLINE+1;
- printf("%6d\t%s",p-code,OpCodeName[op]);
+ printf("%6d\t%s",(int)(p-code),OpCodeName[op]);
switch (op)
{
case PUSHNIL:
@@ -109,44 +110,44 @@ static void PrintCode(Byte* code, Byte* end)
case IFFUPJMP:
case SETLINE:
{
- CodeWord c;
+ Word w;
p++;
- get_word(c,p);
- printf("\t%d",c.w);
+ get_word(w,p);
+ printf("\t%d",w);
break;
}
case PUSHFLOAT:
{
- CodeFloat c;
+ float f;
p++;
- get_float(c,p);
- printf("\t%g",c.f);
+ get_float(f,p);
+ printf("\t%g",f);
break;
}
case PUSHSELF:
case PUSHSTRING:
{
- CodeWord c;
+ Word w;
p++;
- get_word(c,p);
- printf("\t%d\t; \"%s\"",c.w,StrStr(c.w));
+ get_word(w,p);
+ printf("\t%d\t; \"%s\"",w,StrStr(w));
break;
}
case PUSHFUNCTION:
{
- CodeCode c;
+ TFunc* tf;
p++;
- get_code(c,p);
- printf("\t%p\t; \"%s\":%d",c.tf,c.tf->fileName,c.tf->lineDefined);
+ get_code(tf,p);
+ printf("\t%p\t; \"%s\":%d",tf,tf->fileName,tf->lineDefined);
break;
}
case PUSHGLOBAL:
case STOREGLOBAL:
{
- CodeWord c;
+ Word w;
p++;
- get_word(c,p);
- printf("\t%d\t; %s",c.w,VarStr(c.w));
+ get_word(w,p);
+ printf("\t%d\t; %s",w,VarStr(w));
break;
}
case STORELIST:
@@ -161,10 +162,10 @@ static void PrintCode(Byte* code, Byte* end)
p++;
while (n--)
{
- CodeWord c;
- printf("\n%6d\t FIELD",p-code);
- get_word(c,p);
- printf("\t%d\t; \"%s\"",c.w,StrStr(c.w));
+ Word w;
+ printf("\n%6d\t FIELD",(int)(p-code));
+ get_word(w,p);
+ printf("\t%d\t; \"%s\"",w,StrStr(w));
}
break;
}
diff --git a/src/mem.c b/src/mem.c
index 2e410876..4e3bcc52 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio
*/
-char *rcs_mem = "$Id: mem.c,v 1.12 1996/05/06 16:59:00 roberto Exp $";
+char *rcs_mem = "$Id: mem.c,v 1.13 1996/05/24 14:31:10 roberto Exp $";
#include <stdlib.h>
@@ -11,9 +11,6 @@ char *rcs_mem = "$Id: mem.c,v 1.12 1996/05/06 16:59:00 roberto Exp $";
#include "lua.h"
-#define mem_error() lua_error(memEM)
-
-
void luaI_free (void *block)
{
if (block)
@@ -24,21 +21,15 @@ void luaI_free (void *block)
}
-void *luaI_malloc (unsigned long size)
-{
- void *block = malloc((size_t)size);
- if (block == NULL)
- mem_error();
- return block;
-}
-
-
void *luaI_realloc (void *oldblock, unsigned long size)
{
- void *block = oldblock ? realloc(oldblock, (size_t)size) :
- malloc((size_t)size);
+ void *block;
+ size_t s = (size_t)size;
+ if (s != size)
+ lua_error("Allocation Error: Block too big");
+ block = oldblock ? realloc(oldblock, s) : malloc(s);
if (block == NULL)
- mem_error();
+ lua_error(memEM);
return block;
}
@@ -52,7 +43,7 @@ int luaI_growvector (void **block, unsigned long nelems, int size,
if (nelems > limit)
nelems = limit;
*block = luaI_realloc(*block, nelems*size);
- return (int) nelems;
+ return (int)nelems;
}
diff --git a/src/mem.h b/src/mem.h
index 6899c4c1..86f024fc 100644
--- a/src/mem.h
+++ b/src/mem.h
@@ -1,7 +1,7 @@
/*
** mem.c
** memory manager for lua
-** $Id: mem.h,v 1.7 1996/04/22 18:00:37 roberto Exp $
+** $Id: mem.h,v 1.8 1996/05/24 14:31:10 roberto Exp $
*/
#ifndef mem_h
@@ -24,12 +24,12 @@
void luaI_free (void *block);
-void *luaI_malloc (unsigned long size);
void *luaI_realloc (void *oldblock, unsigned long size);
void *luaI_buffer (unsigned long size);
int luaI_growvector (void **block, unsigned long nelems, int size,
char *errormsg, unsigned long limit);
+#define luaI_malloc(s) luaI_realloc(NULL, (s))
#define new(s) ((s *)luaI_malloc(sizeof(s)))
#define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s)))
#define growvector(old,n,s,e,l) \
diff --git a/src/opcode.c b/src/opcode.c
index d3f655be..c3bcf54c 100644
--- a/src/opcode.c
+++ b/src/opcode.c
@@ -3,11 +3,12 @@
** TecCGraf - PUC-Rio
*/
-char *rcs_opcode="$Id: opcode.c,v 3.68 1996/04/25 14:10:00 roberto Exp $";
+char *rcs_opcode="$Id: opcode.c,v 3.77 1996/11/18 13:48:44 roberto Exp $";
#include <setjmp.h>
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include "luadebug.h"
#include "mem.h"
@@ -49,10 +50,14 @@ static Object *top = &initial_stack;
*/
#define incr_top if (++top >= stackLimit) growstack()
-static StkId CBase = 0; /* when Lua calls C or C calls Lua, points to */
- /* the first slot after the last parameter. */
-static int CnResults = 0; /* when Lua calls C, has the number of parameters; */
- /* when C calls Lua, has the number of results. */
+struct C_Lua_Stack {
+ StkId base; /* when Lua calls C or C calls Lua, points to */
+ /* the first slot after the last parameter. */
+ int num; /* when Lua calls C, has the number of parameters; */
+ /* when C calls Lua, has the number of results. */
+};
+
+static struct C_Lua_Stack CLS_current = {0, 0};
static jmp_buf *errorJmp = NULL; /* current error recover point */
@@ -117,7 +122,7 @@ static void growstack (void)
*/
static char *lua_strconc (char *l, char *r)
{
- int nl = strlen(l);
+ size_t nl = strlen(l);
char *buffer = luaI_buffer(nl+strlen(r)+1);
strcpy(buffer, l);
strcpy(buffer+nl, r);
@@ -177,7 +182,7 @@ static void adjust_top (StkId newtop)
top = nt; /* top could be bigger than newtop */
}
-#define adjustC(nParams) adjust_top(CBase+nParams)
+#define adjustC(nParams) adjust_top(CLS_current.base+nParams)
/*
@@ -197,14 +202,12 @@ static void open_stack (int nelems)
*/
static void lineHook (int line)
{
- StkId oldBase = CBase;
- int oldCnResults = CnResults;
- StkId old_top = CBase = top-stack;
- CnResults = 0;
+ struct C_Lua_Stack oldCLS = CLS_current;
+ StkId old_top = CLS_current.base = top-stack;
+ CLS_current.num = 0;
(*lua_linehook)(line);
top = stack+old_top;
- CnResults = oldCnResults;
- CBase = oldBase;
+ CLS_current = oldCLS;
}
@@ -214,10 +217,9 @@ static void lineHook (int line)
*/
static void callHook (StkId base, lua_Type type, int isreturn)
{
- StkId oldBase = CBase;
- int oldCnResults = CnResults;
- StkId old_top = CBase = top-stack;
- CnResults = 0;
+ struct C_Lua_Stack oldCLS = CLS_current;
+ StkId old_top = CLS_current.base = top-stack;
+ CLS_current.num = 0;
if (isreturn)
(*lua_callhook)(LUA_NOOBJECT, "(return)", 0);
else
@@ -229,32 +231,29 @@ static void callHook (StkId base, lua_Type type, int isreturn)
(*lua_callhook)(Ref(f), "(C)", -1);
}
top = stack+old_top;
- CnResults = oldCnResults;
- CBase = oldBase;
+ CLS_current = oldCLS;
}
/*
-** Call a C function. CBase will point to the top of the stack,
-** and CnResults is the number of parameters. Returns an index
+** Call a C function. CLS_current.base will point to the top of the stack,
+** and CLS_current.num is the number of parameters. Returns an index
** to the first result from C.
*/
static StkId callC (lua_CFunction func, StkId base)
{
- StkId oldBase = CBase;
- int oldCnResults = CnResults;
+ struct C_Lua_Stack oldCLS = CLS_current;
StkId firstResult;
- CnResults = (top-stack) - base;
+ CLS_current.num = (top-stack) - base;
/* incorporate parameters on the stack */
- CBase = base+CnResults; /* == top-stack */
+ CLS_current.base = base+CLS_current.num; /* == top-stack */
if (lua_callhook)
callHook(base, LUA_T_CMARK, 0);
(*func)();
if (lua_callhook) /* func may have changed lua_callhook */
callHook(base, LUA_T_CMARK, 1);
- firstResult = CBase;
- CBase = oldBase;
- CnResults = oldCnResults;
+ firstResult = CLS_current.base;
+ CLS_current = oldCLS;
return firstResult;
}
@@ -449,27 +448,27 @@ int lua_setlocal (lua_Function func, int local_number)
/*
-** Execute a protected call. Assumes that function is at CBase and
-** parameters are on top of it. Leave nResults on the stack.
+** Execute a protected call. Assumes that function is at CLS_current.base and
+** parameters are on top of it. Leave nResults on the stack.
*/
static int do_protectedrun (int nResults)
{
jmp_buf myErrorJmp;
int status;
- StkId oldCBase = CBase;
+ struct C_Lua_Stack oldCLS = CLS_current;
jmp_buf *oldErr = errorJmp;
errorJmp = &myErrorJmp;
if (setjmp(myErrorJmp) == 0)
{
- do_call(CBase+1, nResults);
- CnResults = (top-stack) - CBase; /* number of results */
- CBase += CnResults; /* incorporate results on the stack */
+ do_call(CLS_current.base+1, nResults);
+ CLS_current.num = (top-stack) - CLS_current.base; /* number of results */
+ CLS_current.base += CLS_current.num; /* incorporate results on the stack */
status = 0;
}
else
- { /* an error occurred: restore CBase and top */
- CBase = oldCBase;
- top = stack+CBase;
+ { /* an error occurred: restore CLS_current and top */
+ CLS_current = oldCLS;
+ top = stack+CLS_current.base;
status = 1;
}
errorJmp = oldErr;
@@ -480,10 +479,9 @@ int luaI_dorun (TFunc *tf)
{
int status;
adjustC(1); /* one slot for the pseudo-function */
- stack[CBase].tag = LUA_T_FUNCTION;
- stack[CBase].value.tf = tf;
- status = do_protectedrun(0);
- adjustC(0);
+ stack[CLS_current.base].tag = LUA_T_FUNCTION;
+ stack[CLS_current.base].value.tf = tf;
+ status = do_protectedrun(MULT_RET);
return status;
}
@@ -521,8 +519,8 @@ int lua_callfunction (lua_Object function)
return 1;
else
{
- open_stack((top-stack)-CBase);
- stack[CBase] = *Address(function);
+ open_stack((top-stack)-CLS_current.base);
+ stack[CLS_current.base] = *Address(function);
return do_protectedrun (MULT_RET);
}
}
@@ -531,15 +529,15 @@ int lua_callfunction (lua_Object function)
int lua_call (char *funcname)
{
Word n = luaI_findsymbolbyname(funcname);
- open_stack((top-stack)-CBase);
- stack[CBase] = s_object(n);
+ open_stack((top-stack)-CLS_current.base);
+ stack[CLS_current.base] = s_object(n);
return do_protectedrun(MULT_RET);
}
/*
** Open file, generate opcode and execute global statement. Return 0 on
-** success or 1 on error.
+** success or non 0 on error.
*/
int lua_dofile (char *filename)
{
@@ -547,22 +545,32 @@ int lua_dofile (char *filename)
int c;
FILE *f = lua_openfile(filename);
if (f == NULL)
- return 1;
+ return 2;
c = fgetc(f);
ungetc(c, f);
- status = (c == ID_CHUNK) ? luaI_undump(f) : do_protectedmain();
+ if (c == ID_CHUNK) {
+ f = freopen(filename, "rb", f); /* set binary mode */
+ status = luaI_undump(f);
+ }
+ else {
+ if (c == '#')
+ while ((c=fgetc(f)) != '\n') /* skip first line */;
+ status = do_protectedmain();
+ }
lua_closefile();
return status;
}
/*
** Generate opcode stored on string and execute global statement. Return 0 on
-** success or 1 on error.
+** success or non 0 on error.
*/
-int lua_dostring (char *string)
+int lua_dostring (char *str)
{
int status;
- lua_openstring(string);
+ if (str == NULL)
+ return 1;
+ lua_openstring(str);
status = do_protectedmain();
lua_closestring();
return status;
@@ -575,8 +583,8 @@ int lua_dostring (char *string)
lua_Object lua_setfallback (char *name, lua_CFunction fallback)
{
adjustC(1); /* one slot for the pseudo-function */
- stack[CBase].tag = LUA_T_CFUNCTION;
- stack[CBase].value.f = luaI_setfallback;
+ stack[CLS_current.base].tag = LUA_T_CFUNCTION;
+ stack[CLS_current.base].value.f = luaI_setfallback;
lua_pushstring(name);
lua_pushcfunction(fallback);
if (do_protectedrun(1) == 0)
@@ -594,7 +602,7 @@ lua_Object lua_getsubscript (void)
{
adjustC(2);
pushsubscript();
- CBase++; /* incorporate object in the stack */
+ CLS_current.base++; /* incorporate object in the stack */
return (Ref(top-1));
}
@@ -602,7 +610,7 @@ lua_Object lua_getsubscript (void)
#define MAX_C_BLOCKS 10
static int numCblocks = 0;
-static StkId Cblocks[MAX_C_BLOCKS];
+static struct C_Lua_Stack Cblocks[MAX_C_BLOCKS];
/*
** API: starts a new block
@@ -611,7 +619,7 @@ void lua_beginblock (void)
{
if (numCblocks >= MAX_C_BLOCKS)
lua_error("`lua_beginblock': too many nested blocks");
- Cblocks[numCblocks] = CBase;
+ Cblocks[numCblocks] = CLS_current;
numCblocks++;
}
@@ -621,7 +629,7 @@ void lua_beginblock (void)
void lua_endblock (void)
{
--numCblocks;
- CBase = Cblocks[numCblocks];
+ CLS_current = Cblocks[numCblocks];
adjustC(0);
}
@@ -643,7 +651,7 @@ lua_Object lua_createtable (void)
avalue(top) = lua_createarray(0);
tag(top) = LUA_T_ARRAY;
incr_top;
- CBase++; /* incorporate object in the stack */
+ CLS_current.base++; /* incorporate object in the stack */
return Ref(top-1);
}
@@ -653,10 +661,10 @@ lua_Object lua_createtable (void)
*/
lua_Object lua_getparam (int number)
{
- if (number <= 0 || number > CnResults) return LUA_NOOBJECT;
- /* Ref(stack+(CBase-CnResults+number-1)) ==
- stack+(CBase-CnResults+number-1)-stack+1 == */
- return CBase-CnResults+number;
+ if (number <= 0 || number > CLS_current.num) return LUA_NOOBJECT;
+ /* Ref(stack+(CLS_current.base-CLS_current.num+number-1)) ==
+ stack+(CLS_current.base-CLS_current.num+number-1)-stack+1 == */
+ return CLS_current.base-CLS_current.num+number;
}
int lua_isnumber (lua_Object object)
@@ -673,7 +681,8 @@ int lua_isstring (lua_Object object)
int lua_isfunction (lua_Object object)
{
int t = lua_type(object);
- return (t == LUA_T_FUNCTION) || (t == LUA_T_CFUNCTION);
+ return (t == LUA_T_FUNCTION) || (t == LUA_T_CFUNCTION) ||
+ (t == LUA_T_MARK) || (t == LUA_T_CMARK);
}
/*
@@ -701,7 +710,8 @@ char *lua_getstring (lua_Object object)
*/
lua_CFunction lua_getcfunction (lua_Object object)
{
- if (object == LUA_NOOBJECT || tag(Address(object)) != LUA_T_CFUNCTION)
+ if (object == LUA_NOOBJECT || ((tag(Address(object)) != LUA_T_CFUNCTION) &&
+ (tag(Address(object)) != LUA_T_CMARK)))
return NULL;
else return (fvalue(Address(object)));
}
@@ -724,7 +734,7 @@ lua_Object lua_getref (int ref)
return LUA_NOOBJECT;
adjustC(0);
luaI_pushobject(o);
- CBase++; /* incorporate object in the stack */
+ CLS_current.base++; /* incorporate object in the stack */
return Ref(top-1);
}
@@ -753,7 +763,7 @@ lua_Object lua_getglobal (char *name)
{
adjustC(0);
getglobal(luaI_findsymbolbyname(name));
- CBase++; /* incorporate object in the stack */
+ CLS_current.base++; /* incorporate object in the stack */
return Ref(top-1);
}
@@ -838,7 +848,10 @@ void lua_pushobject (lua_Object o)
{
if (o == LUA_NOOBJECT)
lua_error("attempt to push a NOOBJECT");
- luaI_pushobject(Address(o));
+ *top = *Address(o);
+ if (tag(top) == LUA_T_MARK) tag(top) = LUA_T_FUNCTION;
+ else if (tag(top) == LUA_T_CMARK) tag(top) = LUA_T_CFUNCTION;
+ incr_top;
}
int lua_type (lua_Object o)
@@ -886,6 +899,34 @@ static void comparison (lua_Type tag_less, lua_Type tag_equal,
}
+static void adjust_varargs (StkId first_extra_arg)
+{
+ Object arg;
+ Object *firstelem = stack+first_extra_arg;
+ int nvararg = top-firstelem;
+ int i;
+ if (nvararg < 0) nvararg = 0;
+ avalue(&arg) = lua_createarray(nvararg+1); /* +1 for field 'n' */
+ tag(&arg) = LUA_T_ARRAY;
+ for (i=0; i<nvararg; i++) {
+ Object index;
+ tag(&index) = LUA_T_NUMBER;
+ nvalue(&index) = i+1;
+ *(lua_hashdefine(avalue(&arg), &index)) = *(firstelem+i);
+ }
+ /* store counter in field "n" */ {
+ Object index, extra;
+ tag(&index) = LUA_T_STRING;
+ tsvalue(&index) = lua_createstring("n");
+ tag(&extra) = LUA_T_NUMBER;
+ nvalue(&extra) = nvararg;
+ *(lua_hashdefine(avalue(&arg), &index)) = extra;
+ }
+ adjust_top(first_extra_arg);
+ *top = arg; incr_top;
+}
+
+
/*
** Execute the given opcode, until a RET. Parameters are between
@@ -914,38 +955,38 @@ static StkId lua_execute (Byte *pc, StkId base)
case PUSHWORD:
{
- CodeWord code;
- get_word(code,pc);
- tag(top) = LUA_T_NUMBER; nvalue(top) = code.w;
+ Word w;
+ get_word(w,pc);
+ tag(top) = LUA_T_NUMBER; nvalue(top) = w;
incr_top;
}
break;
case PUSHFLOAT:
{
- CodeFloat code;
- get_float(code,pc);
- tag(top) = LUA_T_NUMBER; nvalue(top) = code.f;
+ real num;
+ get_float(num,pc);
+ tag(top) = LUA_T_NUMBER; nvalue(top) = num;
incr_top;
}
break;
case PUSHSTRING:
{
- CodeWord code;
- get_word(code,pc);
- tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[code.w];
+ Word w;
+ get_word(w,pc);
+ tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w];
incr_top;
}
break;
case PUSHFUNCTION:
{
- CodeCode code;
- get_code(code,pc);
- luaI_insertfunction(code.tf); /* may take part in GC */
+ TFunc *f;
+ get_code(f,pc);
+ luaI_insertfunction(f); /* may take part in GC */
top->tag = LUA_T_FUNCTION;
- top->value.tf = code.tf;
+ top->value.tf = f;
incr_top;
}
break;
@@ -960,9 +1001,9 @@ static StkId lua_execute (Byte *pc, StkId base)
case PUSHGLOBAL:
{
- CodeWord code;
- get_word(code,pc);
- getglobal(code.w);
+ Word w;
+ get_word(w,pc);
+ getglobal(w);
}
break;
@@ -973,9 +1014,9 @@ static StkId lua_execute (Byte *pc, StkId base)
case PUSHSELF:
{
Object receiver = *(top-1);
- CodeWord code;
- get_word(code,pc);
- tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[code.w];
+ Word w;
+ get_word(w,pc);
+ tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w];
incr_top;
pushsubscript();
*top = receiver;
@@ -994,9 +1035,9 @@ static StkId lua_execute (Byte *pc, StkId base)
case STOREGLOBAL:
{
- CodeWord code;
- get_word(code,pc);
- s_object(code.w) = *(--top);
+ Word w;
+ get_word(w,pc);
+ s_object(w) = *(--top);
}
break;
@@ -1050,9 +1091,9 @@ static StkId lua_execute (Byte *pc, StkId base)
Object *arr = top-n-1;
while (n)
{
- CodeWord code;
- get_word(code,pc);
- tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[code.w];
+ Word w;
+ get_word(w,pc);
+ tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w];
*(lua_hashdefine (avalue(arr), top)) = *(top-1);
top--;
n--;
@@ -1068,11 +1109,15 @@ static StkId lua_execute (Byte *pc, StkId base)
adjust_top(base + *(pc++));
break;
+ case VARARGS:
+ adjust_varargs(base + *(pc++));
+ break;
+
case CREATEARRAY:
{
- CodeWord size;
+ Word size;
get_word(size,pc);
- avalue(top) = lua_createarray(size.w);
+ avalue(top) = lua_createarray(size);
tag(top) = LUA_T_ARRAY;
incr_top;
}
@@ -1195,51 +1240,51 @@ static StkId lua_execute (Byte *pc, StkId base)
case ONTJMP:
{
- CodeWord code;
- get_word(code,pc);
- if (tag(top-1) != LUA_T_NIL) pc += code.w;
+ Word w;
+ get_word(w,pc);
+ if (tag(top-1) != LUA_T_NIL) pc += w;
}
break;
case ONFJMP:
{
- CodeWord code;
- get_word(code,pc);
- if (tag(top-1) == LUA_T_NIL) pc += code.w;
+ Word w;
+ get_word(w,pc);
+ if (tag(top-1) == LUA_T_NIL) pc += w;
}
break;
case JMP:
{
- CodeWord code;
- get_word(code,pc);
- pc += code.w;
+ Word w;
+ get_word(w,pc);
+ pc += w;
}
break;
case UPJMP:
{
- CodeWord code;
- get_word(code,pc);
- pc -= code.w;
+ Word w;
+ get_word(w,pc);
+ pc -= w;
}
break;
case IFFJMP:
{
- CodeWord code;
- get_word(code,pc);
+ Word w;
+ get_word(w,pc);
top--;
- if (tag(top) == LUA_T_NIL) pc += code.w;
+ if (tag(top) == LUA_T_NIL) pc += w;
}
break;
case IFFUPJMP:
{
- CodeWord code;
- get_word(code,pc);
+ Word w;
+ get_word(w,pc);
top--;
- if (tag(top) == LUA_T_NIL) pc -= code.w;
+ if (tag(top) == LUA_T_NIL) pc -= w;
}
break;
@@ -1262,8 +1307,8 @@ static StkId lua_execute (Byte *pc, StkId base)
case SETLINE:
{
- CodeWord code;
- get_word(code,pc);
+ Word line;
+ get_word(line,pc);
if ((stack+base-1)->tag != LUA_T_LINE)
{
/* open space for LINE value */
@@ -1271,9 +1316,9 @@ static StkId lua_execute (Byte *pc, StkId base)
base++;
(stack+base-1)->tag = LUA_T_LINE;
}
- (stack+base-1)->value.i = code.w;
+ (stack+base-1)->value.i = line;
if (lua_linehook)
- lineHook (code.w);
+ lineHook (line);
break;
}
diff --git a/src/opcode.h b/src/opcode.h
index d42ff3ee..381efbc8 100644
--- a/src/opcode.h
+++ b/src/opcode.h
@@ -1,6 +1,6 @@
/*
** TeCGraf - PUC-Rio
-** $Id: opcode.h,v 3.20 1996/03/15 13:13:13 roberto Exp $
+** $Id: opcode.h,v 3.24 1996/11/01 12:46:59 roberto Exp $
*/
#ifndef opcode_h
@@ -15,59 +15,83 @@
#define FIELDS_PER_FLUSH 40
-typedef enum
-{
- PUSHNIL,
- PUSH0, PUSH1, PUSH2,
- PUSHBYTE,
- PUSHWORD,
- PUSHFLOAT,
- PUSHSTRING,
- PUSHFUNCTION,
- PUSHLOCAL0, PUSHLOCAL1, PUSHLOCAL2, PUSHLOCAL3, PUSHLOCAL4,
- PUSHLOCAL5, PUSHLOCAL6, PUSHLOCAL7, PUSHLOCAL8, PUSHLOCAL9,
- PUSHLOCAL,
- PUSHGLOBAL,
- PUSHINDEXED,
- PUSHSELF,
- STORELOCAL0, STORELOCAL1, STORELOCAL2, STORELOCAL3, STORELOCAL4,
- STORELOCAL5, STORELOCAL6, STORELOCAL7, STORELOCAL8, STORELOCAL9,
- STORELOCAL,
- STOREGLOBAL,
- STOREINDEXED0,
- STOREINDEXED,
- STORELIST0,
- STORELIST,
- STORERECORD,
- ADJUST0,
- ADJUST,
- CREATEARRAY,
- EQOP,
- LTOP,
- LEOP,
- GTOP,
- GEOP,
- ADDOP,
- SUBOP,
- MULTOP,
- DIVOP,
- POWOP,
- CONCOP,
- MINUSOP,
- NOTOP,
- ONTJMP,
- ONFJMP,
- JMP,
- UPJMP,
- IFFJMP,
- IFFUPJMP,
- POP,
- CALLFUNC,
- RETCODE0,
- RETCODE,
- SETLINE
+typedef enum {
+/* name parm before after side effect
+-----------------------------------------------------------------------------*/
+
+PUSHNIL,/* - nil */
+PUSH0,/* - 0.0 */
+PUSH1,/* - 1.0 */
+PUSH2,/* - 2.0 */
+PUSHBYTE,/* b - (float)b */
+PUSHWORD,/* w - (float)w */
+PUSHFLOAT,/* f - f */
+PUSHSTRING,/* w - STR[w] */
+PUSHFUNCTION,/* p - FUN(p) */
+PUSHLOCAL0,/* - LOC[0] */
+PUSHLOCAL1,/* - LOC[1] */
+PUSHLOCAL2,/* - LOC[2] */
+PUSHLOCAL3,/* - LOC[3] */
+PUSHLOCAL4,/* - LOC[4] */
+PUSHLOCAL5,/* - LOC[5] */
+PUSHLOCAL6,/* - LOC[6] */
+PUSHLOCAL7,/* - LOC[7] */
+PUSHLOCAL8,/* - LOC[8] */
+PUSHLOCAL9,/* - LOC[9] */
+PUSHLOCAL,/* w - LOC[w] */
+PUSHGLOBAL,/* w - VAR[w] */
+PUSHINDEXED,/* i t t[i] */
+PUSHSELF,/* w t t t[STR[w]] */
+STORELOCAL0,/* x - LOC[0]=x */
+STORELOCAL1,/* x - LOC[1]=x */
+STORELOCAL2,/* x - LOC[2]=x */
+STORELOCAL3,/* x - LOC[3]=x */
+STORELOCAL4,/* x - LOC[4]=x */
+STORELOCAL5,/* x - LOC[5]=x */
+STORELOCAL6,/* x - LOC[6]=x */
+STORELOCAL7,/* x - LOC[7]=x */
+STORELOCAL8,/* x - LOC[8]=x */
+STORELOCAL9,/* x - LOC[9]=x */
+STORELOCAL,/* w x - LOC[w]=x */
+STOREGLOBAL,/* w x - VAR[w]=x */
+STOREINDEXED0,/* v i t - t[i]=v */
+STOREINDEXED,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */
+STORELIST0,/* w v_w...v_1 t - t[i]=v_i */
+STORELIST,/* w n v_w...v_1 t - t[i+n*FPF]=v_i */
+STORERECORD,/* n
+ w_n...w_1 v_n...v_1 t - t[STR[w_i]]=v_i */
+ADJUST0,/* - - TOP=BASE */
+ADJUST,/* b - - TOP=BASE+b */
+CREATEARRAY,/* w - newarray(size = w) */
+EQOP,/* y x (x==y)? 1 : nil */
+LTOP,/* y x (x<y)? 1 : nil */
+LEOP,/* y x (x<y)? 1 : nil */
+GTOP,/* y x (x>y)? 1 : nil */
+GEOP,/* y x (x>=y)? 1 : nil */
+ADDOP,/* y x x+y */
+SUBOP,/* y x x-y */
+MULTOP,/* y x x*y */
+DIVOP,/* y x x/y */
+POWOP,/* y x x^y */
+CONCOP,/* y x x..y */
+MINUSOP,/* x -x */
+NOTOP,/* x (x==nil)? 1 : nil */
+ONTJMP,/* w x - (x!=nil)? PC+=w */
+ONFJMP,/* w x - (x==nil)? PC+=w */
+JMP,/* w - - PC+=w */
+UPJMP,/* w - - PC-=w */
+IFFJMP,/* w x - (x==nil)? PC+=w */
+IFFUPJMP,/* w x - (x==nil)? PC-=w */
+POP,/* x - */
+CALLFUNC,/* n m v_n...v_1 f r_m...r_1 f(v1,...,v_n) */
+RETCODE0,
+RETCODE,/* b - - */
+SETLINE,/* w - - LINE=w */
+VARARGS/* b v_n...v_1 {v_1...v_n;n=n} */
+
} OpCode;
+
#define MULT_RET 255
@@ -103,32 +127,15 @@ typedef struct Object
#define s_tag(i) (tag(&s_object(i)))
#define s_nvalue(i) (nvalue(&s_object(i)))
#define s_svalue(i) (svalue(&s_object(i)))
+#define s_tsvalue(i) (tsvalue(&s_object(i)))
#define s_avalue(i) (avalue(&s_object(i)))
#define s_fvalue(i) (fvalue(&s_object(i)))
#define s_uvalue(i) (uvalue(&s_object(i)))
-typedef union
-{
- struct {Byte c1; Byte c2;} m;
- Word w;
-} CodeWord;
-#define get_word(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;}
-
-typedef union
-{
- struct {Byte c1; Byte c2; Byte c3; Byte c4;} m;
- float f;
-} CodeFloat;
-#define get_float(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\
- code.m.c3 = *pc++; code.m.c4 = *pc++;}
-
-typedef union
-{
- struct {Byte c1; Byte c2; Byte c3; Byte c4;} m;
- TFunc *tf;
-} CodeCode;
-#define get_code(code,pc) {code.m.c1 = *pc++; code.m.c2 = *pc++;\
- code.m.c3 = *pc++; code.m.c4 = *pc++;}
+#define get_word(code,pc) {memcpy(&code, pc, sizeof(Word)); pc+=sizeof(Word);}
+#define get_float(code,pc){memcpy(&code, pc, sizeof(real)); pc+=sizeof(real);}
+#define get_code(code,pc) {memcpy(&code, pc, sizeof(TFunc *)); \
+ pc+=sizeof(TFunc *);}
/* Exported functions */
diff --git a/src/parser.c b/src/parser.c
index 1cbb3c17..c91ee00e 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1,22 +1,20 @@
-#if defined (__cplusplus) || defined (c_plusplus)
-#include <c_varieties.h>
-#ifdef __EXTERN_C__
- EXTERN_FUNCTION ( extern int luaY_lex, ());
-#else
- extern int luaY_lex();
-#endif
- extern void luaY_error(char *);
- extern int luaY_parse();
+#ifndef lint
+static char luaY_sccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
#endif
+#define YYBYACC 1
+#define YYMAJOR 1
+#define YYMINOR 9
+#define luaY_clearin (luaY_char=(-1))
+#define luaY_errok (luaY_errflag=0)
+#define YYRECOVERING (luaY_errflag!=0)
+#define YYPREFIX "luaY_"
+#line 2 "lua.stx"
-#include <stdlib.h>
-
-# line 2 "lua.stx"
-
-char *rcs_luastx = "$Id: parser.c,v 1.1 1996/05/14 19:44:57 lhf Exp $";
+char *rcs_luastx = "$Id: parser.c,v 1.1 1996/11/21 16:11:40 lhf Exp $";
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "luadebug.h"
#include "mem.h"
@@ -71,58 +69,48 @@ int lua_debug = 0;
static void luaY_error (char *s)
{
- char msg[256];
- char *token = lua_lasttext();
- if (token[0] == 0)
- token = "<eof>";
- sprintf (msg,"%s; last token read: \"%s\" at line %d in file `%s'",
- s, token, lua_linenumber, lua_parsedfile);
- lua_error (msg);
+ luaI_syntaxerror(s);
+}
+
+static void check_space (int i)
+{
+ if (pc+i>maxcurr-1) /* 1 byte free to code HALT of main code */
+ maxcurr = growvector(&basepc, maxcurr, Byte, codeEM, MAX_INT);
}
static void code_byte (Byte c)
{
- if (pc>maxcurr-2) /* 1 byte free to code HALT of main code */
- maxcurr = growvector(&basepc, maxcurr, Byte, codeEM, MAX_INT);
+ check_space(1);
basepc[pc++] = c;
}
static void code_word (Word n)
{
- CodeWord code;
- code.w = n;
- code_byte(code.m.c1);
- code_byte(code.m.c2);
+ check_space(sizeof(Word));
+ memcpy(basepc+pc, &n, sizeof(Word));
+ pc += sizeof(Word);
}
-static void code_float (float n)
+static void code_float (real n)
{
- CodeFloat code;
- code.f = n;
- code_byte(code.m.c1);
- code_byte(code.m.c2);
- code_byte(code.m.c3);
- code_byte(code.m.c4);
+ check_space(sizeof(real));
+ memcpy(basepc+pc, &n, sizeof(real));
+ pc += sizeof(real);
}
static void code_code (TFunc *tf)
{
- CodeCode code;
- code.tf = tf;
- code_byte(code.m.c1);
- code_byte(code.m.c2);
- code_byte(code.m.c3);
- code_byte(code.m.c4);
+ check_space(sizeof(TFunc *));
+ memcpy(basepc+pc, &tf, sizeof(TFunc *));
+ pc += sizeof(TFunc *);
}
static void code_word_at (Byte *p, int n)
{
- CodeWord code;
- if ((Word)n != n)
- luaY_error("block too big");
- code.w = (Word)n;
- *p++ = code.m.c1;
- *p++ = code.m.c2;
+ Word w = n;
+ if (w != n)
+ luaY_error("block too big");
+ memcpy(p, &w, sizeof(Word));
}
static void push_field (Word name)
@@ -335,6 +323,19 @@ static void adjust_mult_assign (int vars, Long exps, int temps)
lua_codeadjust(temps);
}
+static int close_parlist (int dots)
+{
+ if (!dots)
+ lua_codeadjust(0);
+ else
+ {
+ code_byte(VARARGS);
+ code_byte(nlocalvar);
+ add_localvar(luaI_createfixedstring("arg"));
+ }
+ return lua_linenumber;
+}
+
static void storesinglevar (Long v)
{
if (v > 0) /* global var */
@@ -417,9 +418,8 @@ void lua_parse (TFunc *tf)
}
-
-# line 410 "lua.stx"
-typedef union
+#line 414 "lua.stx"
+typedef union
{
int vInt;
float vFloat;
@@ -429,901 +429,739 @@ typedef union
TFunc *pFunc;
TaggedString *pTStr;
} YYSTYPE;
-# define WRONGTOKEN 257
-# define NIL 258
-# define IF 259
-# define THEN 260
-# define ELSE 261
-# define ELSEIF 262
-# define WHILE 263
-# define DO 264
-# define REPEAT 265
-# define UNTIL 266
-# define END 267
-# define RETURN 268
-# define LOCAL 269
-# define FUNCTION 270
-# define NUMBER 271
-# define STRING 272
-# define NAME 273
-# define DEBUG 274
-# define AND 275
-# define OR 276
-# define EQ 277
-# define NE 278
-# define LE 279
-# define GE 280
-# define CONC 281
-# define UNARY 282
-# define NOT 283
-#define luaY_clearin luaY_char = -1
-#define luaY_errok luaY_errflag = 0
-extern int luaY_char;
-extern int luaY_errflag;
-#ifndef YYMAXDEPTH
-#define YYMAXDEPTH 150
-#endif
-YYSTYPE luaY_lval, luaY_val;
-# define YYERRCODE 256
-
-# line 788 "lua.stx"
-
-int luaY_exca[] ={
--1, 1,
- 0, -1,
- -2, 0,
--1, 14,
- 61, 88,
- 44, 88,
- -2, 94,
--1, 22,
- 40, 7,
- -2, 94,
--1, 29,
- 40, 59,
- 123, 59,
- -2, 46,
--1, 44,
- 123, 56,
- -2, 63,
--1, 71,
- 123, 56,
- -2, 84,
--1, 76,
- 275, 30,
- 276, 30,
- 277, 30,
- 278, 30,
- 62, 30,
- 60, 30,
- 279, 30,
- 280, 30,
- 281, 30,
- 43, 30,
- 45, 30,
- 42, 30,
- 47, 30,
- 94, 30,
- -2, 65,
--1, 77,
- 91, 94,
- 46, 94,
- -2, 89,
--1, 132,
- 123, 56,
- -2, 78,
--1, 138,
- 123, 56,
- -2, 63,
--1, 155,
- 275, 30,
- 276, 30,
- 277, 30,
- 278, 30,
- 62, 30,
- 60, 30,
- 279, 30,
- 280, 30,
- 281, 30,
- 43, 30,
- 45, 30,
- 42, 30,
- 47, 30,
- 94, 30,
- -2, 67,
- };
-# define YYNPROD 100
-# define YYLAST 311
-int luaY_act[]={
-
- 61, 59, 148, 60, 141, 62, 118, 61, 59, 90,
- 60, 89, 62, 86, 84, 18, 42, 168, 54, 164,
- 55, 61, 59, 156, 60, 54, 62, 55, 61, 59,
- 115, 60, 73, 62, 157, 61, 59, 19, 60, 54,
- 62, 55, 61, 59, 82, 60, 54, 62, 55, 158,
- 159, 129, 63, 54, 91, 55, 111, 25, 121, 63,
- 54, 109, 55, 127, 26, 61, 59, 26, 60, 27,
- 62, 7, 27, 63, 71, 8, 33, 9, 11, 63,
- 63, 12, 6, 80, 67, 18, 13, 63, 68, 7,
- 48, 40, 4, 8, 63, 9, 24, 76, 138, 12,
- 81, 133, 76, 18, 61, 59, 61, 60, 39, 62,
- 20, 62, 146, 130, 117, 132, 69, 63, 123, 48,
- 104, 105, 122, 70, 124, 120, 72, 106, 48, 50,
- 29, 46, 17, 44, 128, 47, 85, 23, 83, 76,
- 51, 28, 92, 93, 94, 95, 96, 97, 98, 99,
- 100, 101, 102, 103, 88, 140, 63, 45, 63, 36,
- 112, 14, 131, 139, 47, 35, 22, 151, 126, 134,
- 125, 78, 137, 47, 153, 74, 38, 37, 75, 142,
- 116, 5, 3, 154, 2, 49, 21, 147, 16, 87,
- 152, 165, 163, 11, 110, 108, 76, 155, 145, 160,
- 77, 79, 41, 171, 135, 107, 162, 173, 161, 136,
- 15, 43, 10, 167, 143, 144, 1, 0, 169, 0,
- 119, 149, 150, 0, 170, 0, 172, 0, 0, 0,
- 0, 0, 0, 65, 66, 53, 56, 57, 58, 64,
- 65, 66, 53, 56, 57, 58, 64, 17, 166, 0,
- 114, 0, 0, 52, 65, 66, 53, 56, 57, 58,
- 64, 65, 66, 53, 56, 57, 58, 64, 65, 66,
- 53, 56, 57, 58, 64, 0, 14, 53, 56, 57,
- 58, 64, 32, 0, 0, 32, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 30, 31, 18, 30, 31,
- 113, 0, 0, 0, 64, 0, 0, 34, 0, 0,
- 34 };
-int luaY_pact[]={
-
- -1000, -188, -1000, -1000, 51, -1000, -258, 24, -1000, -1000,
- 47, -1000, -257, -1000, -1000, 93, -1000, 73, -1000, -1000,
- -1000, 89, -1000, 82, -7, -1000, 24, 24, -1000, 73,
- -1000, -1000, -1000, -1000, 24, -49, -1000, 24, -1000, 24,
- -258, 39, -1000, -1000, 24, -1000, -259, 24, -260, -1000,
- -262, -264, -1000, 24, 24, 24, 24, 24, 24, 24,
- 24, 24, 24, 24, 24, -1000, -1000, 86, -21, -15,
- -15, 27, -14, -236, -1000, 70, -1000, -1000, 44, -1000,
- -267, 24, 84, 70, -1000, -35, -1000, 81, 74, -1000,
- -1000, -1000, 23, 23, 23, 23, 23, 23, 64, 64,
- -15, -15, -15, 62, -1000, -1000, -1000, -62, -1000, 69,
- 71, -1000, -21, 40, -1000, 24, -170, -1000, -1000, 70,
- -1000, -1000, -1000, -269, -1000, 24, 24, -1000, 53, -1000,
- -271, -1000, 24, 24, -1000, -21, 51, -1000, 24, 24,
- -244, -1000, -212, 0, 0, -1000, -271, -1000, 40, -21,
- -21, -1000, -1000, -1000, 51, -1000, -1000, -248, -1000, 24,
- -1000, 69, -250, -1000, -1000, -1000, -42, -1000, -1000, -1000,
- -1000, -1000, -212, -1000 };
-int luaY_pgo[]={
-
- 0, 216, 54, 44, 138, 76, 57, 212, 211, 210,
- 205, 202, 201, 199, 61, 198, 195, 194, 189, 159,
- 188, 186, 185, 184, 182, 92, 37, 181, 130, 32,
- 180, 88, 34, 177, 176, 175, 172, 141, 170, 168,
- 165, 163, 154, 134, 51, 56 };
-int luaY_r1[]={
-
- 0, 1, 1, 1, 23, 23, 24, 21, 21, 22,
- 30, 30, 26, 26, 25, 33, 25, 34, 25, 25,
- 25, 25, 32, 32, 32, 35, 29, 36, 36, 2,
- 31, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 38, 6, 39, 6, 40, 37, 5, 9,
- 9, 8, 8, 3, 3, 4, 41, 4, 18, 18,
- 42, 42, 43, 10, 10, 15, 15, 44, 44, 13,
- 13, 14, 14, 45, 16, 16, 17, 17, 7, 7,
- 19, 19, 19, 20, 28, 11, 11, 12, 12, 27 };
-int luaY_r2[]={
-
- 0, 0, 4, 4, 4, 2, 7, 3, 7, 11,
- 0, 6, 0, 2, 17, 1, 17, 1, 13, 7,
- 2, 7, 0, 4, 15, 1, 7, 0, 7, 1,
- 3, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 5, 3, 3, 3, 3, 3,
- 3, 5, 1, 11, 1, 11, 1, 9, 5, 3,
- 7, 7, 3, 1, 3, 3, 1, 9, 1, 3,
- 3, 7, 1, 7, 5, 1, 5, 0, 2, 1,
- 5, 3, 7, 7, 1, 5, 3, 7, 3, 7,
- 3, 9, 7, 3, 3, 3, 7, 1, 5, 3 };
-int luaY_chk[]={
-
- -1000, -1, -23, -24, -25, -27, 270, 259, 263, 265,
- -7, -5, 269, 274, -19, -9, -20, -28, 273, -26,
- 59, -21, -19, -28, -31, -6, 40, 45, -37, -28,
- 271, 272, 258, -5, 283, -40, -19, -33, -34, 61,
- 44, -11, 273, -8, 40, -37, 58, 91, 46, -22,
- 40, 58, 260, 277, 60, 62, 278, 279, 280, 43,
- 45, 42, 47, 94, 281, 275, 276, -6, -31, -31,
- -31, 123, -31, -29, -35, -4, -6, -19, -28, -12,
- 44, 61, -3, -4, 273, -31, 273, -18, -42, 273,
- 273, -2, -31, -31, -31, -31, -31, -31, -31, -31,
- -31, -31, -31, -31, -2, -2, 41, -10, -16, -14,
- -17, -45, -31, 273, 264, 266, -30, 44, 273, -4,
- 41, 93, 41, 44, -29, -38, -39, 125, -43, -44,
- 44, -44, 44, 61, -2, -31, -25, -36, 268, -41,
- -29, 273, -2, -31, -31, -15, 59, -45, 273, -31,
- -31, -29, -2, -26, -3, -6, 267, -32, 261, 262,
- -13, -14, -2, -26, 267, -29, -31, -44, 267, 260,
- -2, -29, -2, -32 };
-int luaY_def[]={
-
- 1, -2, 2, 3, 12, 5, 0, 56, 15, 17,
- 0, 20, 0, 99, -2, 56, 90, 59, 93, 4,
- 13, 0, -2, 0, 0, 30, 56, 56, 45, -2,
- 47, 48, 49, 50, 56, 0, 94, 56, 25, 56,
- 0, 97, 95, 58, -2, 62, 0, 56, 0, 6,
- 68, 0, 29, 56, 56, 56, 56, 56, 56, 56,
- 56, 56, 56, 56, 56, 29, 29, 30, 0, 44,
- 51, -2, 0, 0, 10, 19, -2, -2, 0, 21,
- 0, 56, 0, 64, 60, 0, 92, 0, 69, 70,
- 8, 25, 32, 33, 34, 35, 36, 37, 38, 39,
- 40, 41, 42, 43, 52, 54, 31, 0, 72, 77,
- 77, 81, 86, 93, 29, 56, 27, 66, 96, 98,
- 61, 91, 25, 0, 29, 56, 56, 57, 75, 74,
- 78, 85, -2, 56, 25, 29, 12, 26, -2, 56,
- 0, 71, 22, 53, 55, 73, 79, 82, 0, 87,
- 83, 29, 18, 11, 12, -2, 9, 0, 25, 56,
- 76, 77, 0, 28, 14, 23, 0, 80, 16, 29,
- 25, 29, 22, 24 };
-typedef struct { char *t_name; int t_val; } luaY_toktype;
+#line 433 "y.tab.c"
+#define WRONGTOKEN 257
+#define NIL 258
+#define IF 259
+#define THEN 260
+#define ELSE 261
+#define ELSEIF 262
+#define WHILE 263
+#define DO 264
+#define REPEAT 265
+#define UNTIL 266
+#define END 267
+#define RETURN 268
+#define LOCAL 269
+#define FUNCTION 270
+#define DOTS 271
+#define NUMBER 272
+#define STRING 273
+#define NAME 274
+#define AND 275
+#define OR 276
+#define EQ 277
+#define NE 278
+#define LE 279
+#define GE 280
+#define CONC 281
+#define UNARY 282
+#define NOT 283
+#define YYERRCODE 256
+short luaY_lhs[] = { -1,
+ 0, 24, 24, 24, 28, 22, 22, 23, 31, 31,
+ 27, 27, 26, 34, 26, 35, 26, 26, 26, 26,
+ 33, 33, 33, 36, 30, 25, 25, 1, 32, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 38, 5, 39, 5, 40, 37, 4, 8, 8, 7,
+ 7, 2, 2, 3, 41, 3, 17, 17, 18, 18,
+ 19, 19, 42, 9, 9, 14, 14, 43, 43, 12,
+ 12, 13, 13, 44, 15, 15, 16, 16, 6, 6,
+ 20, 20, 20, 21, 29, 10, 10, 11, 11,
+};
+short luaY_len[] = { 2,
+ 2, 0, 3, 2, 3, 1, 3, 5, 0, 3,
+ 0, 1, 8, 0, 8, 0, 6, 3, 1, 3,
+ 0, 2, 7, 0, 3, 0, 3, 0, 1, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 2, 1, 1, 1, 1, 1, 1, 2,
+ 0, 5, 0, 5, 0, 4, 2, 1, 3, 3,
+ 1, 0, 1, 1, 0, 4, 0, 1, 1, 3,
+ 1, 1, 0, 3, 2, 0, 2, 0, 1, 0,
+ 2, 1, 3, 3, 0, 2, 1, 3, 1, 3,
+ 1, 4, 3, 1, 1, 1, 3, 0, 2,
+};
+short luaY_defred[] = { 2,
+ 0, 0, 0, 14, 16, 0, 0, 0, 94, 19,
+ 0, 0, 0, 91, 1, 0, 4, 0, 48, 46,
+ 47, 0, 0, 0, 49, 29, 95, 0, 0, 44,
+ 0, 0, 24, 0, 0, 0, 0, 96, 0, 0,
+ 0, 0, 0, 0, 0, 57, 61, 12, 3, 0,
+ 0, 0, 0, 0, 0, 28, 28, 28, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 9, 27, 65, 0, 0, 20, 0,
+ 5, 0, 0, 0, 0, 0, 59, 0, 93, 30,
+ 24, 51, 53, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 73, 0,
+ 0, 82, 28, 0, 0, 0, 0, 97, 72, 71,
+ 0, 0, 69, 7, 60, 92, 28, 0, 0, 0,
+ 56, 0, 75, 0, 0, 86, 24, 0, 25, 0,
+ 0, 24, 0, 0, 0, 0, 0, 0, 83, 0,
+ 74, 0, 28, 17, 10, 0, 70, 24, 0, 0,
+ 77, 0, 0, 8, 22, 0, 13, 81, 15, 28,
+ 24, 28, 0, 23,
+};
+short luaY_dgoto[] = { 1,
+ 91, 34, 35, 25, 26, 11, 46, 12, 107, 39,
+ 79, 161, 108, 151, 109, 110, 121, 122, 123, 27,
+ 14, 41, 81, 2, 15, 16, 49, 17, 28, 73,
+ 115, 37, 160, 32, 33, 74, 30, 128, 129, 31,
+ 116, 134, 133, 112,
+};
+short luaY_sindex[] = { 0,
+ 0, 332, -38, 0, 0, -38, -239, -223, 0, 0,
+ -23, 17, 0, 0, 0, 3, 0, 137, 0, 0,
+ 0, -38, -38, -38, 0, 0, 0, 137, 547, 0,
+ -25, -38, 0, 3, 45, 0, 212, 0, -22, 0,
+ 52, 140, -38, -223, -38, 0, 0, 0, 0, -166,
+ -38, -154, 40, 40, 102, 0, 0, 0, -38, -38,
+ -38, -38, -38, -38, -38, -38, -38, -38, -38, -38,
+ -34, 481, -130, 0, 0, 0, -38, -129, 0, -194,
+ 0, -123, 45, 0, -17, 103, 0, 753, 0, 0,
+ 0, 0, 0, -30, -30, -30, -30, -30, -30, 95,
+ 11, 11, 40, 40, 40, 97, 41, 123, 0, 124,
+ 212, 0, 0, -38, -59, -38, 45, 0, 0, 0,
+ 128, 131, 0, 0, 0, 0, 0, -38, -38, -38,
+ 0, -97, 0, 120, -38, 0, 0, 212, 0, 3,
+ 0, 0, -194, -183, 118, 118, 212, 97, 0, -97,
+ 0, 212, 0, 0, 0, -85, 0, 0, -38, -82,
+ 0, 123, -80, 0, 0, 1105, 0, 0, 0, 0,
+ 0, 0, -183, 0,
+};
+short luaY_rindex[] = { 0,
+ 0, 191, 69, 0, 0, 173, 0, 0, 0, 0,
+ 0, 69, 150, 0, 0, 146, 0, -36, 0, 0,
+ 0, 69, 69, 69, 0, 0, 0, 1, 0, 0,
+ 0, 69, 0, 47, 461, 436, 0, 0, 197, 130,
+ 0, 0, 69, 0, -33, 0, 0, 0, 0, 0,
+ 69, 0, 24, 59, 1181, 0, 0, 0, 69, 69,
+ 69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
+ -50, 0, 0, 0, 0, 0, 69, 0, 0, 152,
+ 0, 0, 311, -21, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 746, 776, 799, 821, 844, 866, 505,
+ 383, 410, 88, 112, 359, 1174, 0, 74, 0, -40,
+ -26, 0, 0, 69, -230, 69, 921, 0, 0, 0,
+ 0, 160, 0, 0, 0, 0, 0, 69, 69, 69,
+ 0, 77, 0, 78, -9, 0, 0, 939, 0, 289,
+ 474, 0, 0, -60, 894, 1137, -16, 0, 0, 89,
+ 0, -10, 0, 0, 0, 0, 0, 0, 69, 0,
+ 0, 74, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, -60, 0,
+};
+short luaY_gindex[] = { 0,
+ -31, 171, 85, -2, 48, 0, 0, 0, 0, 0,
+ 0, 0, 67, 0, 0, 0, 0, 0, 75, 8,
+ 0, 0, 0, 0, 104, 107, -29, 0, 12, -61,
+ 0, 1260, 50, 0, 0, 0, 213, 0, 0, 0,
+ 0, 0, -107, 94,
+};
+#define YYTABLESIZE 1462
+short luaY_table[] = { 10,
+ 45, 24, 136, 58, 75, 24, 22, 62, 85, 13,
+ 22, 68, 66, 18, 67, 40, 69, 87, 78, 42,
+ 44, 78, 90, 43, 95, 92, 93, 84, 52, 127,
+ 26, 26, 87, 88, 38, 26, 26, 43, 77, 90,
+ 58, 45, 45, 45, 45, 45, 11, 45, 88, 79,
+ 9, 84, 68, 36, 168, 85, 45, 69, 50, 45,
+ 45, 48, 45, 70, 43, 43, 43, 43, 43, 95,
+ 43, 55, 55, 51, 85, 153, 119, 158, 159, 120,
+ 156, 137, 43, 43, 78, 43, 58, 39, 76, 55,
+ 36, 80, 36, 45, 45, 144, 165, 71, 87, 50,
+ 50, 50, 50, 50, 70, 50, 154, 87, 84, 172,
+ 155, 40, 10, 55, 88, 79, 43, 50, 50, 89,
+ 50, 163, 13, 58, 36, 45, 18, 83, 39, 39,
+ 39, 39, 39, 70, 39, 114, 68, 66, 171, 67,
+ 173, 69, 90, 125, 118, 11, 39, 39, 43, 39,
+ 124, 50, 40, 40, 40, 40, 40, 130, 40, 68,
+ 66, 117, 67, 141, 69, 131, 132, 135, 142, 6,
+ 40, 40, 62, 40, 143, 95, 148, 62, 150, 61,
+ 39, 164, 52, 50, 167, 52, 169, 95, 70, 95,
+ 26, 55, 67, 89, 50, 95, 98, 82, 78, 3,
+ 68, 79, 76, 4, 40, 5, 21, 95, 6, 7,
+ 89, 70, 39, 80, 9, 86, 162, 157, 139, 19,
+ 95, 140, 174, 19, 47, 149, 0, 51, 0, 0,
+ 51, 62, 0, 20, 21, 9, 40, 20, 21, 106,
+ 95, 0, 0, 0, 23, 0, 0, 0, 23, 0,
+ 65, 0, 0, 68, 66, 98, 67, 0, 69, 45,
+ 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
+ 45, 62, 95, 61, 45, 45, 45, 45, 45, 45,
+ 45, 45, 43, 43, 43, 43, 43, 43, 43, 43,
+ 43, 43, 43, 43, 0, 55, 0, 43, 43, 43,
+ 43, 43, 43, 43, 43, 70, 0, 11, 11, 0,
+ 18, 0, 11, 11, 0, 0, 0, 50, 50, 50,
+ 50, 50, 50, 50, 50, 50, 50, 50, 50, 0,
+ 0, 0, 50, 50, 50, 50, 50, 50, 50, 50,
+ 0, 0, 0, 0, 0, 0, 39, 39, 39, 39,
+ 39, 39, 39, 39, 39, 39, 39, 39, 41, 0,
+ 0, 39, 39, 39, 39, 39, 39, 39, 39, 18,
+ 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
+ 40, 40, 37, 0, 0, 40, 40, 40, 40, 40,
+ 40, 40, 40, 0, 59, 60, 63, 64, 65, 41,
+ 41, 41, 41, 41, 11, 41, 0, 0, 11, 38,
+ 11, 0, 0, 11, 11, 11, 0, 41, 41, 11,
+ 41, 0, 0, 37, 0, 37, 37, 37, 0, 0,
+ 0, 0, 0, 62, 62, 64, 0, 0, 62, 62,
+ 0, 37, 37, 0, 37, 0, 0, 0, 0, 0,
+ 38, 41, 38, 38, 38, 98, 0, 98, 98, 98,
+ 63, 98, 98, 98, 98, 98, 98, 0, 38, 38,
+ 98, 38, 0, 66, 0, 37, 64, 29, 29, 64,
+ 29, 0, 29, 41, 0, 0, 57, 58, 59, 60,
+ 63, 64, 65, 0, 64, 29, 0, 29, 0, 0,
+ 0, 63, 38, 0, 42, 0, 0, 37, 0, 0,
+ 0, 0, 0, 0, 66, 29, 29, 66, 29, 63,
+ 29, 0, 68, 66, 0, 67, 0, 69, 0, 29,
+ 0, 0, 66, 29, 38, 29, 0, 0, 0, 0,
+ 62, 0, 61, 0, 0, 42, 0, 11, 42, 11,
+ 11, 11, 0, 11, 11, 11, 11, 11, 0, 0,
+ 0, 0, 11, 42, 42, 0, 42, 29, 0, 18,
+ 0, 18, 18, 18, 70, 18, 18, 18, 18, 18,
+ 18, 0, 0, 0, 18, 0, 0, 0, 68, 66,
+ 3, 67, 0, 69, 4, 0, 5, 42, 0, 6,
+ 7, 8, 0, 0, 0, 9, 62, 0, 61, 0,
+ 0, 0, 0, 0, 0, 0, 0, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41, 41, 42,
+ 0, 0, 41, 41, 41, 41, 41, 41, 41, 41,
+ 70, 37, 37, 37, 37, 37, 37, 37, 37, 37,
+ 37, 37, 37, 0, 0, 0, 37, 37, 37, 37,
+ 37, 37, 37, 37, 0, 0, 0, 0, 38, 38,
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
+ 0, 0, 0, 38, 38, 38, 38, 38, 38, 38,
+ 38, 0, 0, 0, 64, 0, 64, 64, 64, 0,
+ 64, 64, 64, 64, 64, 64, 0, 0, 0, 64,
+ 29, 29, 29, 29, 29, 29, 29, 0, 0, 0,
+ 0, 63, 63, 0, 0, 0, 63, 63, 0, 0,
+ 0, 0, 66, 0, 66, 66, 66, 0, 66, 66,
+ 66, 66, 66, 66, 113, 31, 0, 66, 29, 29,
+ 29, 29, 29, 29, 29, 57, 58, 59, 60, 63,
+ 64, 65, 0, 42, 42, 42, 42, 42, 42, 42,
+ 42, 42, 42, 42, 42, 34, 0, 0, 42, 42,
+ 42, 42, 42, 42, 42, 42, 31, 0, 0, 31,
+ 0, 0, 0, 0, 68, 66, 0, 67, 33, 69,
+ 0, 0, 0, 0, 31, 31, 56, 31, 0, 0,
+ 0, 0, 62, 0, 61, 0, 34, 0, 0, 34,
+ 32, 57, 58, 59, 60, 63, 64, 65, 0, 0,
+ 0, 0, 0, 0, 34, 34, 0, 34, 31, 33,
+ 0, 0, 33, 35, 0, 126, 70, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 33, 33, 0,
+ 33, 32, 0, 0, 32, 36, 0, 0, 34, 0,
+ 31, 0, 0, 0, 0, 0, 0, 0, 0, 32,
+ 32, 0, 32, 0, 35, 0, 0, 35, 0, 0,
+ 0, 33, 0, 52, 0, 0, 0, 0, 0, 0,
+ 34, 0, 35, 35, 0, 35, 36, 0, 0, 36,
+ 0, 0, 0, 32, 0, 0, 0, 0, 0, 0,
+ 99, 0, 0, 33, 36, 36, 0, 36, 0, 0,
+ 0, 0, 0, 0, 52, 0, 35, 52, 28, 0,
+ 0, 0, 0, 0, 0, 32, 0, 0, 0, 0,
+ 0, 0, 52, 0, 0, 0, 0, 0, 36, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 35, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 99,
+ 0, 0, 0, 0, 0, 0, 52, 0, 0, 0,
+ 36, 0, 0, 0, 0, 0, 0, 28, 0, 0,
+ 0, 0, 0, 0, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 0, 0, 52, 31,
+ 31, 31, 31, 31, 31, 31, 0, 57, 58, 59,
+ 60, 63, 64, 65, 34, 34, 34, 34, 34, 34,
+ 34, 34, 34, 34, 34, 34, 0, 0, 0, 34,
+ 34, 34, 34, 34, 34, 34, 0, 33, 33, 33,
+ 33, 33, 33, 33, 33, 33, 33, 33, 33, 0,
+ 0, 0, 33, 33, 33, 33, 33, 33, 33, 32,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
+ 32, 0, 0, 0, 32, 32, 32, 32, 32, 32,
+ 32, 0, 35, 35, 35, 35, 35, 35, 35, 35,
+ 35, 35, 35, 35, 0, 0, 0, 35, 35, 35,
+ 35, 35, 35, 35, 36, 36, 36, 36, 36, 36,
+ 36, 36, 36, 36, 36, 36, 54, 0, 0, 36,
+ 36, 36, 36, 36, 36, 36, 68, 66, 0, 67,
+ 0, 69, 52, 52, 52, 52, 52, 52, 52, 52,
+ 52, 52, 52, 52, 62, 0, 61, 52, 52, 52,
+ 0, 0, 0, 0, 0, 0, 0, 54, 0, 99,
+ 54, 99, 99, 99, 0, 99, 99, 99, 99, 99,
+ 99, 0, 0, 0, 99, 54, 0, 28, 70, 28,
+ 28, 28, 0, 28, 28, 28, 28, 28, 28, 0,
+ 0, 0, 28, 94, 0, 94, 94, 94, 94, 94,
+ 94, 0, 29, 29, 0, 29, 0, 29, 0, 54,
+ 0, 94, 94, 94, 0, 94, 0, 0, 0, 0,
+ 29, 0, 29, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 54, 29, 0, 94, 0, 0, 94, 0, 0,
+ 0, 0, 0, 0, 29, 0, 0, 0, 0, 0,
+ 0, 53, 54, 0, 0, 0, 0, 0, 0, 0,
+ 0, 72, 0, 0, 0, 0, 94, 0, 94, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 88, 0, 0, 0, 0, 0, 0, 0, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
+ 111, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 170, 0, 0, 0, 0, 0,
+ 0, 0, 0, 138, 0, 0, 0, 0, 0, 57,
+ 58, 59, 60, 63, 64, 65, 0, 145, 146, 147,
+ 0, 0, 0, 0, 152, 54, 54, 54, 54, 54,
+ 54, 54, 54, 54, 54, 54, 54, 0, 0, 0,
+ 54, 54, 54, 0, 0, 0, 0, 0, 166, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 94, 94,
+ 94, 94, 94, 94, 94, 29, 29, 29, 29, 29,
+ 29, 29,
+};
+short luaY_check[] = { 2,
+ 0, 40, 110, 40, 34, 40, 45, 41, 59, 2,
+ 45, 42, 43, 2, 45, 8, 47, 44, 59, 8,
+ 44, 44, 44, 0, 46, 57, 58, 44, 46, 91,
+ 261, 262, 59, 44, 274, 266, 267, 61, 61, 61,
+ 40, 41, 42, 43, 44, 45, 0, 47, 59, 59,
+ 274, 44, 42, 6, 162, 44, 40, 47, 0, 59,
+ 60, 59, 62, 94, 41, 42, 43, 44, 45, 91,
+ 47, 24, 123, 91, 125, 137, 271, 261, 262, 274,
+ 142, 113, 59, 60, 125, 62, 123, 0, 44, 123,
+ 43, 40, 45, 93, 94, 127, 158, 123, 125, 41,
+ 42, 43, 44, 45, 94, 47, 138, 274, 125, 171,
+ 140, 0, 115, 123, 125, 125, 93, 59, 60, 274,
+ 62, 153, 115, 123, 77, 125, 115, 43, 41, 42,
+ 43, 44, 45, 94, 47, 266, 42, 43, 170, 45,
+ 172, 47, 41, 41, 274, 0, 59, 60, 125, 62,
+ 274, 93, 41, 42, 43, 44, 45, 61, 47, 42,
+ 43, 77, 45, 116, 47, 125, 44, 44, 41, 40,
+ 59, 60, 0, 62, 44, 46, 274, 60, 59, 62,
+ 93, 267, 46, 125, 267, 46, 267, 58, 94, 40,
+ 0, 123, 41, 44, 58, 46, 0, 58, 125, 259,
+ 41, 125, 125, 263, 93, 265, 267, 58, 268, 269,
+ 61, 94, 125, 125, 274, 45, 150, 143, 115, 258,
+ 91, 115, 173, 258, 12, 132, -1, 91, -1, -1,
+ 91, 59, -1, 272, 273, 274, 125, 272, 273, 274,
+ 91, -1, -1, -1, 283, -1, -1, -1, 283, -1,
+ 281, -1, -1, 42, 43, 59, 45, -1, 47, 259,
+ 260, 261, 262, 263, 264, 265, 266, 267, 268, 269,
+ 270, 60, 123, 62, 274, 275, 276, 277, 278, 279,
+ 280, 281, 259, 260, 261, 262, 263, 264, 265, 266,
+ 267, 268, 269, 270, -1, 123, -1, 274, 275, 276,
+ 277, 278, 279, 280, 281, 94, -1, 261, 262, -1,
+ 0, -1, 266, 267, -1, -1, -1, 259, 260, 261,
+ 262, 263, 264, 265, 266, 267, 268, 269, 270, -1,
+ -1, -1, 274, 275, 276, 277, 278, 279, 280, 281,
+ -1, -1, -1, -1, -1, -1, 259, 260, 261, 262,
+ 263, 264, 265, 266, 267, 268, 269, 270, 0, -1,
+ -1, 274, 275, 276, 277, 278, 279, 280, 281, 59,
+ 259, 260, 261, 262, 263, 264, 265, 266, 267, 268,
+ 269, 270, 0, -1, -1, 274, 275, 276, 277, 278,
+ 279, 280, 281, -1, 277, 278, 279, 280, 281, 41,
+ 42, 43, 44, 45, 259, 47, -1, -1, 263, 0,
+ 265, -1, -1, 268, 269, 270, -1, 59, 60, 274,
+ 62, -1, -1, 41, -1, 43, 44, 45, -1, -1,
+ -1, -1, -1, 261, 262, 0, -1, -1, 266, 267,
+ -1, 59, 60, -1, 62, -1, -1, -1, -1, -1,
+ 41, 93, 43, 44, 45, 259, -1, 261, 262, 263,
+ 0, 265, 266, 267, 268, 269, 270, -1, 59, 60,
+ 274, 62, -1, 0, -1, 93, 41, 42, 43, 44,
+ 45, -1, 47, 125, -1, -1, 275, 276, 277, 278,
+ 279, 280, 281, -1, 59, 60, -1, 62, -1, -1,
+ -1, 41, 93, -1, 0, -1, -1, 125, -1, -1,
+ -1, -1, -1, -1, 41, 42, 43, 44, 45, 59,
+ 47, -1, 42, 43, -1, 45, -1, 47, -1, 94,
+ -1, -1, 59, 60, 125, 62, -1, -1, -1, -1,
+ 60, -1, 62, -1, -1, 41, -1, 259, 44, 261,
+ 262, 263, -1, 265, 266, 267, 268, 269, -1, -1,
+ -1, -1, 274, 59, 60, -1, 62, 94, -1, 259,
+ -1, 261, 262, 263, 94, 265, 266, 267, 268, 269,
+ 270, -1, -1, -1, 274, -1, -1, -1, 42, 43,
+ 259, 45, -1, 47, 263, -1, 265, 93, -1, 268,
+ 269, 270, -1, -1, -1, 274, 60, -1, 62, -1,
+ -1, -1, -1, -1, -1, -1, -1, 259, 260, 261,
+ 262, 263, 264, 265, 266, 267, 268, 269, 270, 125,
+ -1, -1, 274, 275, 276, 277, 278, 279, 280, 281,
+ 94, 259, 260, 261, 262, 263, 264, 265, 266, 267,
+ 268, 269, 270, -1, -1, -1, 274, 275, 276, 277,
+ 278, 279, 280, 281, -1, -1, -1, -1, 259, 260,
+ 261, 262, 263, 264, 265, 266, 267, 268, 269, 270,
+ -1, -1, -1, 274, 275, 276, 277, 278, 279, 280,
+ 281, -1, -1, -1, 259, -1, 261, 262, 263, -1,
+ 265, 266, 267, 268, 269, 270, -1, -1, -1, 274,
+ 275, 276, 277, 278, 279, 280, 281, -1, -1, -1,
+ -1, 261, 262, -1, -1, -1, 266, 267, -1, -1,
+ -1, -1, 259, -1, 261, 262, 263, -1, 265, 266,
+ 267, 268, 269, 270, 264, 0, -1, 274, 275, 276,
+ 277, 278, 279, 280, 281, 275, 276, 277, 278, 279,
+ 280, 281, -1, 259, 260, 261, 262, 263, 264, 265,
+ 266, 267, 268, 269, 270, 0, -1, -1, 274, 275,
+ 276, 277, 278, 279, 280, 281, 41, -1, -1, 44,
+ -1, -1, -1, -1, 42, 43, -1, 45, 0, 47,
+ -1, -1, -1, -1, 59, 60, 260, 62, -1, -1,
+ -1, -1, 60, -1, 62, -1, 41, -1, -1, 44,
+ 0, 275, 276, 277, 278, 279, 280, 281, -1, -1,
+ -1, -1, -1, -1, 59, 60, -1, 62, 93, 41,
+ -1, -1, 44, 0, -1, 93, 94, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, 59, 60, -1,
+ 62, 41, -1, -1, 44, 0, -1, -1, 93, -1,
+ 125, -1, -1, -1, -1, -1, -1, -1, -1, 59,
+ 60, -1, 62, -1, 41, -1, -1, 44, -1, -1,
+ -1, 93, -1, 0, -1, -1, -1, -1, -1, -1,
+ 125, -1, 59, 60, -1, 62, 41, -1, -1, 44,
+ -1, -1, -1, 93, -1, -1, -1, -1, -1, -1,
+ 0, -1, -1, 125, 59, 60, -1, 62, -1, -1,
+ -1, -1, -1, -1, 41, -1, 93, 44, 0, -1,
+ -1, -1, -1, -1, -1, 125, -1, -1, -1, -1,
+ -1, -1, 59, -1, -1, -1, -1, -1, 93, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, 125, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, 59,
+ -1, -1, -1, -1, -1, -1, 93, -1, -1, -1,
+ 125, -1, -1, -1, -1, -1, -1, 59, -1, -1,
+ -1, -1, -1, -1, 259, 260, 261, 262, 263, 264,
+ 265, 266, 267, 268, 269, 270, -1, -1, 125, 274,
+ 275, 276, 277, 278, 279, 280, -1, 275, 276, 277,
+ 278, 279, 280, 281, 259, 260, 261, 262, 263, 264,
+ 265, 266, 267, 268, 269, 270, -1, -1, -1, 274,
+ 275, 276, 277, 278, 279, 280, -1, 259, 260, 261,
+ 262, 263, 264, 265, 266, 267, 268, 269, 270, -1,
+ -1, -1, 274, 275, 276, 277, 278, 279, 280, 259,
+ 260, 261, 262, 263, 264, 265, 266, 267, 268, 269,
+ 270, -1, -1, -1, 274, 275, 276, 277, 278, 279,
+ 280, -1, 259, 260, 261, 262, 263, 264, 265, 266,
+ 267, 268, 269, 270, -1, -1, -1, 274, 275, 276,
+ 277, 278, 279, 280, 259, 260, 261, 262, 263, 264,
+ 265, 266, 267, 268, 269, 270, 0, -1, -1, 274,
+ 275, 276, 277, 278, 279, 280, 42, 43, -1, 45,
+ -1, 47, 259, 260, 261, 262, 263, 264, 265, 266,
+ 267, 268, 269, 270, 60, -1, 62, 274, 275, 276,
+ -1, -1, -1, -1, -1, -1, -1, 41, -1, 259,
+ 44, 261, 262, 263, -1, 265, 266, 267, 268, 269,
+ 270, -1, -1, -1, 274, 59, -1, 259, 94, 261,
+ 262, 263, -1, 265, 266, 267, 268, 269, 270, -1,
+ -1, -1, 274, 40, -1, 42, 43, 44, 45, 46,
+ 47, -1, 42, 43, -1, 45, -1, 47, -1, 93,
+ -1, 58, 59, 60, -1, 62, -1, -1, -1, -1,
+ 60, -1, 62, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, 125, 3, -1, 91, -1, -1, 94, -1, -1,
+ -1, -1, -1, -1, 94, -1, -1, -1, -1, -1,
+ -1, 22, 23, -1, -1, -1, -1, -1, -1, -1,
+ -1, 32, -1, -1, -1, -1, 123, -1, 125, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 51, -1, -1, -1, -1, -1, -1, -1, 59, 60,
+ 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
+ 71, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, 260, -1, -1, -1, -1, -1,
+ -1, -1, -1, 114, -1, -1, -1, -1, -1, 275,
+ 276, 277, 278, 279, 280, 281, -1, 128, 129, 130,
+ -1, -1, -1, -1, 135, 259, 260, 261, 262, 263,
+ 264, 265, 266, 267, 268, 269, 270, -1, -1, -1,
+ 274, 275, 276, -1, -1, -1, -1, -1, 159, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, 275, 276,
+ 277, 278, 279, 280, 281, 275, 276, 277, 278, 279,
+ 280, 281,
+};
+#define YYFINAL 1
#ifndef YYDEBUG
-# define YYDEBUG 0 /* don't allow debugging */
+#define YYDEBUG 0
#endif
-
+#define YYMAXTOKEN 283
#if YYDEBUG
-
-luaY_toktype luaY_toks[] =
-{
- "WRONGTOKEN", 257,
- "NIL", 258,
- "IF", 259,
- "THEN", 260,
- "ELSE", 261,
- "ELSEIF", 262,
- "WHILE", 263,
- "DO", 264,
- "REPEAT", 265,
- "UNTIL", 266,
- "END", 267,
- "RETURN", 268,
- "LOCAL", 269,
- "FUNCTION", 270,
- "NUMBER", 271,
- "STRING", 272,
- "NAME", 273,
- "DEBUG", 274,
- "AND", 275,
- "OR", 276,
- "EQ", 277,
- "NE", 278,
- ">", 62,
- "<", 60,
- "LE", 279,
- "GE", 280,
- "CONC", 281,
- "+", 43,
- "-", 45,
- "*", 42,
- "/", 47,
- "UNARY", 282,
- "NOT", 283,
- "^", 94,
- "-unknown-", -1 /* ends search */
+char *luaY_name[] = {
+"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,"'('","')'","'*'","'+'","','","'-'","'.'","'/'",0,0,0,0,0,0,0,0,0,0,
+"':'","';'","'<'","'='","'>'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,"'['",0,"']'","'^'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,"'{'",0,"'}'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"WRONGTOKEN","NIL","IF","THEN","ELSE",
+"ELSEIF","WHILE","DO","REPEAT","UNTIL","END","RETURN","LOCAL","FUNCTION","DOTS",
+"NUMBER","STRING","NAME","AND","OR","EQ","NE","LE","GE","CONC","UNARY","NOT",
};
-
-char * luaY_reds[] =
-{
- "-no such reduction-",
- "functionlist : /* empty */",
- "functionlist : functionlist globalstat",
- "functionlist : functionlist function",
- "globalstat : stat sc",
- "globalstat : setdebug",
- "function : FUNCTION funcname body",
- "funcname : var",
- "funcname : varexp ':' NAME",
- "body : '(' parlist ')' block END",
- "statlist : /* empty */",
- "statlist : statlist stat sc",
- "sc : /* empty */",
- "sc : ';'",
- "stat : IF expr1 THEN PrepJump block PrepJump elsepart END",
- "stat : WHILE",
- "stat : WHILE expr1 DO PrepJump block PrepJump END",
- "stat : REPEAT",
- "stat : REPEAT block UNTIL expr1 PrepJump",
- "stat : varlist1 '=' exprlist1",
- "stat : functioncall",
- "stat : LOCAL localdeclist decinit",
- "elsepart : /* empty */",
- "elsepart : ELSE block",
- "elsepart : ELSEIF expr1 THEN PrepJump block PrepJump elsepart",
- "block : /* empty */",
- "block : statlist ret",
- "ret : /* empty */",
- "ret : RETURN exprlist sc",
- "PrepJump : /* empty */",
- "expr1 : expr",
- "expr : '(' expr ')'",
- "expr : expr1 EQ expr1",
- "expr : expr1 '<' expr1",
- "expr : expr1 '>' expr1",
- "expr : expr1 NE expr1",
- "expr : expr1 LE expr1",
- "expr : expr1 GE expr1",
- "expr : expr1 '+' expr1",
- "expr : expr1 '-' expr1",
- "expr : expr1 '*' expr1",
- "expr : expr1 '/' expr1",
- "expr : expr1 '^' expr1",
- "expr : expr1 CONC expr1",
- "expr : '-' expr1",
- "expr : table",
- "expr : varexp",
- "expr : NUMBER",
- "expr : STRING",
- "expr : NIL",
- "expr : functioncall",
- "expr : NOT expr1",
- "expr : expr1 AND PrepJump",
- "expr : expr1 AND PrepJump expr1",
- "expr : expr1 OR PrepJump",
- "expr : expr1 OR PrepJump expr1",
- "table : /* empty */",
- "table : '{' fieldlist '}'",
- "functioncall : funcvalue funcParams",
- "funcvalue : varexp",
- "funcvalue : varexp ':' NAME",
- "funcParams : '(' exprlist ')'",
- "funcParams : table",
- "exprlist : /* empty */",
- "exprlist : exprlist1",
- "exprlist1 : expr",
- "exprlist1 : exprlist1 ','",
- "exprlist1 : exprlist1 ',' expr",
- "parlist : /* empty */",
- "parlist : parlist1",
- "parlist1 : NAME",
- "parlist1 : parlist1 ',' NAME",
- "fieldlist : lfieldlist",
- "fieldlist : lfieldlist semicolonpart",
- "fieldlist : ffieldlist1 lastcomma",
- "semicolonpart : /* empty */",
- "semicolonpart : ';' ffieldlist",
- "lastcomma : /* empty */",
- "lastcomma : ','",
- "ffieldlist : /* empty */",
- "ffieldlist : ffieldlist1 lastcomma",
- "ffieldlist1 : ffield",
- "ffieldlist1 : ffieldlist1 ',' ffield",
- "ffield : NAME '=' expr1",
- "lfieldlist : /* empty */",
- "lfieldlist : lfieldlist1 lastcomma",
- "lfieldlist1 : expr1",
- "lfieldlist1 : lfieldlist1 ',' expr1",
- "varlist1 : var",
- "varlist1 : varlist1 ',' var",
- "var : singlevar",
- "var : varexp '[' expr1 ']'",
- "var : varexp '.' NAME",
- "singlevar : NAME",
- "varexp : var",
- "localdeclist : NAME",
- "localdeclist : localdeclist ',' NAME",
- "decinit : /* empty */",
- "decinit : '=' exprlist1",
- "setdebug : DEBUG",
+char *luaY_rule[] = {
+"$accept : chunk",
+"chunk : chunklist ret",
+"chunklist :",
+"chunklist : chunklist stat sc",
+"chunklist : chunklist function",
+"function : FUNCTION funcname body",
+"funcname : var",
+"funcname : varexp ':' NAME",
+"body : '(' parlist ')' block END",
+"statlist :",
+"statlist : statlist stat sc",
+"sc :",
+"sc : ';'",
+"stat : IF expr1 THEN PrepJump block PrepJump elsepart END",
+"$$1 :",
+"stat : WHILE $$1 expr1 DO PrepJump block PrepJump END",
+"$$2 :",
+"stat : REPEAT $$2 block UNTIL expr1 PrepJump",
+"stat : varlist1 '=' exprlist1",
+"stat : functioncall",
+"stat : LOCAL localdeclist decinit",
+"elsepart :",
+"elsepart : ELSE block",
+"elsepart : ELSEIF expr1 THEN PrepJump block PrepJump elsepart",
+"$$3 :",
+"block : $$3 statlist ret",
+"ret :",
+"ret : RETURN exprlist sc",
+"PrepJump :",
+"expr1 : expr",
+"expr : '(' expr ')'",
+"expr : expr1 EQ expr1",
+"expr : expr1 '<' expr1",
+"expr : expr1 '>' expr1",
+"expr : expr1 NE expr1",
+"expr : expr1 LE expr1",
+"expr : expr1 GE expr1",
+"expr : expr1 '+' expr1",
+"expr : expr1 '-' expr1",
+"expr : expr1 '*' expr1",
+"expr : expr1 '/' expr1",
+"expr : expr1 '^' expr1",
+"expr : expr1 CONC expr1",
+"expr : '-' expr1",
+"expr : table",
+"expr : varexp",
+"expr : NUMBER",
+"expr : STRING",
+"expr : NIL",
+"expr : functioncall",
+"expr : NOT expr1",
+"$$4 :",
+"expr : expr1 AND PrepJump $$4 expr1",
+"$$5 :",
+"expr : expr1 OR PrepJump $$5 expr1",
+"$$6 :",
+"table : $$6 '{' fieldlist '}'",
+"functioncall : funcvalue funcParams",
+"funcvalue : varexp",
+"funcvalue : varexp ':' NAME",
+"funcParams : '(' exprlist ')'",
+"funcParams : table",
+"exprlist :",
+"exprlist : exprlist1",
+"exprlist1 : expr",
+"$$7 :",
+"exprlist1 : exprlist1 ',' $$7 expr",
+"parlist :",
+"parlist : parlist1",
+"parlist1 : par",
+"parlist1 : parlist1 ',' par",
+"par : NAME",
+"par : DOTS",
+"$$8 :",
+"fieldlist : lfieldlist $$8 semicolonpart",
+"fieldlist : ffieldlist1 lastcomma",
+"semicolonpart :",
+"semicolonpart : ';' ffieldlist",
+"lastcomma :",
+"lastcomma : ','",
+"ffieldlist :",
+"ffieldlist : ffieldlist1 lastcomma",
+"ffieldlist1 : ffield",
+"ffieldlist1 : ffieldlist1 ',' ffield",
+"ffield : NAME '=' expr1",
+"lfieldlist :",
+"lfieldlist : lfieldlist1 lastcomma",
+"lfieldlist1 : expr1",
+"lfieldlist1 : lfieldlist1 ',' expr1",
+"varlist1 : var",
+"varlist1 : varlist1 ',' var",
+"var : singlevar",
+"var : varexp '[' expr1 ']'",
+"var : varexp '.' NAME",
+"singlevar : NAME",
+"varexp : var",
+"localdeclist : NAME",
+"localdeclist : localdeclist ',' NAME",
+"decinit :",
+"decinit : '=' exprlist1",
};
-#endif /* YYDEBUG */
-#line 1 "/usr/lang/SC1.0/yaccpar"
-/* @(#)yaccpar 1.10 89/04/04 SMI; from S5R3 1.10 */
-
-/*
-** Skeleton parser driver for yacc output
-*/
-/*
- @(#)RELEASE SC1.0 C++ 2.1 1Mar1991
-*/
-
-/*
-** yacc user known macros and defines
-*/
-#define YYERROR goto luaY_errlab
-#define YYACCEPT return(0)
-#define YYABORT return(1)
-#define YYBACKUP( newtoken, newvalue )\
-{\
- if ( luaY_char >= 0 || ( luaY_r2[ luaY_tmp ] >> 1 ) != 1 )\
- {\
- luaY_error( "syntax error - cannot backup" );\
- goto luaY_errlab;\
- }\
- luaY_char = newtoken;\
- luaY_state = *luaY_ps;\
- luaY_lval = newvalue;\
- goto luaY_newstate;\
-}
-#define YYRECOVERING() (!!luaY_errflag)
-#define YYCOPY(to, from, type) \
- (type *) memcpy(to, (char *) from, luaY_newmax * sizeof(type))
-#ifndef YYDEBUG
-# define YYDEBUG 1 /* make debugging available */
#endif
-
-
-/*
-** extern declarations for C++ - check your own code for correctness
-** if you have function redefined error messages here.
-*/
-
-#ifdef __cplusplus
-EXTERN_FUNCTION ( extern int printf, (const char*, DOTDOTDOT) );
-EXTERN_FUNCTION ( extern void *memcpy, (void *, const void *, int) );
+#ifdef YYSTACKSIZE
+#undef YYMAXDEPTH
+#define YYMAXDEPTH YYSTACKSIZE
+#else
+#ifdef YYMAXDEPTH
+#define YYSTACKSIZE YYMAXDEPTH
+#else
+#define YYSTACKSIZE 500
+#define YYMAXDEPTH 500
#endif
-
-
-/*
-** user known globals
-*/
-int luaY_debug; /* set to 1 to get debugging */
-
-/*
-** driver internal defines
-*/
-#define YYFLAG (-1000)
-
-/*
-** static variables used by the parser
-*/
-static YYSTYPE luaY__luaY_v[YYMAXDEPTH], *luaY_v = luaY__luaY_v; /* value stack */
-static int luaY__luaY_s[YYMAXDEPTH], *luaY_s = luaY__luaY_s; /* state stack */
-
-static YYSTYPE *luaY_pv; /* top of value stack */
-static int *luaY_ps; /* top of state stack */
-
-static int luaY_state; /* current state */
-static int luaY_tmp; /* extra var (lasts between blocks) */
-
-#if defined(__cplusplus) || defined(__STDC__) || defined(lint)
-static int __yaccpar_lint_hack__ = 0;
- /* if you change the value from 0 to
- something else, make sure you know
- what to do with luaY_errlab reference.
- This is a hack - to make sure C++ and
- lint are happy with the 4.1 yacc code. */
#endif
-
-int luaY_nerrs; /* number of errors */
-
-int luaY_errflag; /* error recovery flag */
-int luaY_char; /* current input token number */
-static unsigned luaY_maxdepth = YYMAXDEPTH;
-
-
-/*
-** luaY_parse - return 0 if worked, 1 if syntax error not recovered from
-*/
+int luaY_debug;
+int luaY_nerrs;
+int luaY_errflag;
+int luaY_char;
+short *luaY_ssp;
+YYSTYPE *luaY_vsp;
+YYSTYPE luaY_val;
+YYSTYPE luaY_lval;
+short luaY_ss[YYSTACKSIZE];
+YYSTYPE luaY_vs[YYSTACKSIZE];
+#define luaY_stacksize YYSTACKSIZE
+#define YYABORT goto luaY_abort
+#define YYREJECT goto luaY_abort
+#define YYACCEPT goto luaY_accept
+#define YYERROR goto luaY_errlab
int
luaY_parse()
{
- register YYSTYPE *luaY_pvt = (YYSTYPE*)0 ; /* top of value stack for
-$vars */
-
- /*
- ** Initialize externals - luaY_parse may be called more than once
- */
- luaY_pv = &luaY_v[-1];
- luaY_ps = &luaY_s[-1];
- luaY_state = 0;
- luaY_tmp = 0;
- luaY_nerrs = 0;
- luaY_errflag = 0;
- luaY_char = -1;
-
-#if defined(__cplusplus) || defined(__STDC__) || defined(lint)
-/*
- Note that the following can never be executed but simply to please
- lint and C++
- */
- switch (__yaccpar_lint_hack__)
- {
- case 1: goto luaY_errlab;
- case 2: goto luaY_newstate;
- }
-#endif
-
- {
- register YYSTYPE *luaY__pv; /* top of value stack */
- register int *luaY__ps; /* top of state stack */
- register int luaY__state; /* current state */
- register int luaY__n; /* internal state number info */
-
- goto luaY_stack;
-
- /*
- ** get globals into registers.
- ** branch to here only if YYBACKUP was called.
- */
- luaY_newstate:
- luaY__pv = luaY_pv;
- luaY__ps = luaY_ps;
- luaY__state = luaY_state;
- goto luaY__newstate;
-
- /*
- ** get globals into registers.
- ** either we just started, or we just finished a reduction
- */
- luaY_stack:
- luaY__pv = luaY_pv;
- luaY__ps = luaY_ps;
- luaY__state = luaY_state;
-
- /*
- ** top of for (;;) loop while no reductions done
- */
- luaY__stack:
- /*
- ** put a state and value onto the stacks
- */
+ register int luaY_m, luaY_n, luaY_state;
#if YYDEBUG
- /*
- ** if debugging, look up token value in list of value vs.
- ** name pairs. 0 and negative (-1) are special values.
- ** Note: linear search is used since time is not a real
- ** consideration while debugging.
- */
- if ( luaY_debug )
- {
- register int luaY__i;
+ register char *luaY_s;
+ extern char *getenv();
- (void)printf( "State %d, token ", luaY__state );
- if ( luaY_char == 0 )
- (void)printf( "end-of-file\n" );
- else if ( luaY_char < 0 )
- (void)printf( "-none-\n" );
- else
- {
- for ( luaY__i = 0; luaY_toks[luaY__i].t_val >= 0;
- luaY__i++ )
- {
- if ( luaY_toks[luaY__i].t_val == luaY_char )
- break;
- }
- (void)printf( "%s\n", luaY_toks[luaY__i].t_name );
- }
- }
-#endif /* YYDEBUG */
- if ( ++luaY__ps >= &luaY_s[ luaY_maxdepth ] ) /* room on stack? */
- {
- /*
- ** reallocate and recover. Note that pointers
- ** have to be reset, or bad things will happen
- */
- int luaY_ps_index = (luaY__ps - luaY_s);
- int luaY_pv_index = (luaY__pv - luaY_v);
- int luaY_pvt_index = (luaY_pvt - luaY_v);
- int luaY_newmax;
+ if (luaY_s = getenv("YYDEBUG"))
+ {
+ luaY_n = *luaY_s;
+ if (luaY_n >= '0' && luaY_n <= '9')
+ luaY_debug = luaY_n - '0';
+ }
+#endif
- luaY_newmax = luaY_maxdepth + YYMAXDEPTH;
- if (luaY_maxdepth == YYMAXDEPTH) /* first time growth */
- {
- YYSTYPE *newluaY_v = (YYSTYPE*)malloc(luaY_newmax*sizeof(YYSTYPE));
- int *newluaY_s = (int*)malloc(luaY_newmax*sizeof(int));
- if (newluaY_s != 0 && newluaY_v != 0)
- {
- luaY_s = YYCOPY(newluaY_s, luaY_s, int);
- luaY_v = YYCOPY(newluaY_v, luaY_v, YYSTYPE);
- }
- else
- luaY_newmax = 0; /* failed */
- }
- else /* not first time */
- {
- luaY_v = (YYSTYPE*)realloc((char*)luaY_v,
- luaY_newmax * sizeof(YYSTYPE));
- luaY_s = (int*)realloc((char*)luaY_s,
- luaY_newmax * sizeof(int));
- if (luaY_s == 0 || luaY_v == 0)
- luaY_newmax = 0; /* failed */
- }
- if (luaY_newmax <= luaY_maxdepth) /* tables not expanded */
- {
- luaY_error( "yacc stack overflow" );
- YYABORT;
- }
- luaY_maxdepth = luaY_newmax;
+ luaY_nerrs = 0;
+ luaY_errflag = 0;
+ luaY_char = (-1);
- luaY__ps = luaY_s + luaY_ps_index;
- luaY__pv = luaY_v + luaY_pv_index;
- luaY_pvt = luaY_v + luaY_pvt_index;
- }
- *luaY__ps = luaY__state;
- *++luaY__pv = luaY_val;
+ luaY_ssp = luaY_ss;
+ luaY_vsp = luaY_vs;
+ *luaY_ssp = luaY_state = 0;
- /*
- ** we have a new state - find out what to do
- */
- luaY__newstate:
- if ( ( luaY__n = luaY_pact[ luaY__state ] ) <= YYFLAG )
- goto luaY_default; /* simple state */
+luaY_loop:
+ if (luaY_n = luaY_defred[luaY_state]) goto luaY_reduce;
+ if (luaY_char < 0)
+ {
+ if ((luaY_char = luaY_lex()) < 0) luaY_char = 0;
#if YYDEBUG
- /*
- ** if debugging, need to mark whether new token grabbed
- */
- luaY_tmp = luaY_char < 0;
+ if (luaY_debug)
+ {
+ luaY_s = 0;
+ if (luaY_char <= YYMAXTOKEN) luaY_s = luaY_name[luaY_char];
+ if (!luaY_s) luaY_s = "illegal-symbol";
+ printf("%sdebug: state %d, reading %d (%s)\n",
+ YYPREFIX, luaY_state, luaY_char, luaY_s);
+ }
#endif
- if ( ( luaY_char < 0 ) && ( ( luaY_char = luaY_lex() ) < 0 ) )
- luaY_char = 0; /* reached EOF */
-#if YYDEBUG
- if ( luaY_debug && luaY_tmp )
- {
- register int luaY__i;
-
- (void)printf( "Received token " );
- if ( luaY_char == 0 )
- (void)printf( "end-of-file\n" );
- else if ( luaY_char < 0 )
- (void)printf( "-none-\n" );
- else
- {
- for ( luaY__i = 0; luaY_toks[luaY__i].t_val >= 0;
- luaY__i++ )
- {
- if ( luaY_toks[luaY__i].t_val == luaY_char )
- break;
- }
- (void)printf( "%s\n", luaY_toks[luaY__i].t_name );
- }
- }
-#endif /* YYDEBUG */
- if ( ( ( luaY__n += luaY_char ) < 0 ) || ( luaY__n >= YYLAST ) )
- goto luaY_default;
- if ( luaY_chk[ luaY__n = luaY_act[ luaY__n ] ] == luaY_char ) /*valid shift*/
- {
- luaY_char = -1;
- luaY_val = luaY_lval;
- luaY__state = luaY__n;
- if ( luaY_errflag > 0 )
- luaY_errflag--;
- goto luaY__stack;
- }
-
- luaY_default:
- if ( ( luaY__n = luaY_def[ luaY__state ] ) == -2 )
- {
+ }
+ if ((luaY_n = luaY_sindex[luaY_state]) && (luaY_n += luaY_char) >= 0 &&
+ luaY_n <= YYTABLESIZE && luaY_check[luaY_n] == luaY_char)
+ {
#if YYDEBUG
- luaY_tmp = luaY_char < 0;
+ if (luaY_debug)
+ printf("%sdebug: state %d, shifting to state %d\n",
+ YYPREFIX, luaY_state, luaY_table[luaY_n]);
+#endif
+ if (luaY_ssp >= luaY_ss + luaY_stacksize - 1)
+ {
+ goto luaY_overflow;
+ }
+ *++luaY_ssp = luaY_state = luaY_table[luaY_n];
+ *++luaY_vsp = luaY_lval;
+ luaY_char = (-1);
+ if (luaY_errflag > 0) --luaY_errflag;
+ goto luaY_loop;
+ }
+ if ((luaY_n = luaY_rindex[luaY_state]) && (luaY_n += luaY_char) >= 0 &&
+ luaY_n <= YYTABLESIZE && luaY_check[luaY_n] == luaY_char)
+ {
+ luaY_n = luaY_table[luaY_n];
+ goto luaY_reduce;
+ }
+ if (luaY_errflag) goto luaY_inrecovery;
+#ifdef lint
+ goto luaY_newerror;
+#endif
+luaY_newerror:
+ luaY_error("syntax error");
+#ifdef lint
+ goto luaY_errlab;
#endif
- if ( ( luaY_char < 0 ) && ( ( luaY_char = luaY_lex() ) < 0 ) )
- luaY_char = 0; /* reached EOF */
+luaY_errlab:
+ ++luaY_nerrs;
+luaY_inrecovery:
+ if (luaY_errflag < 3)
+ {
+ luaY_errflag = 3;
+ for (;;)
+ {
+ if ((luaY_n = luaY_sindex[*luaY_ssp]) && (luaY_n += YYERRCODE) >= 0 &&
+ luaY_n <= YYTABLESIZE && luaY_check[luaY_n] == YYERRCODE)
+ {
#if YYDEBUG
- if ( luaY_debug && luaY_tmp )
- {
- register int luaY__i;
-
- (void)printf( "Received token " );
- if ( luaY_char == 0 )
- (void)printf( "end-of-file\n" );
- else if ( luaY_char < 0 )
- (void)printf( "-none-\n" );
- else
- {
- for ( luaY__i = 0;
- luaY_toks[luaY__i].t_val >= 0;
- luaY__i++ )
- {
- if ( luaY_toks[luaY__i].t_val
- == luaY_char )
- {
- break;
- }
- }
- (void)printf( "%s\n", luaY_toks[luaY__i].t_name );
- }
- }
-#endif /* YYDEBUG */
- /*
- ** look through exception table
- */
- {
- register int *luaY_xi = luaY_exca;
-
- while ( ( *luaY_xi != -1 ) ||
- ( luaY_xi[1] != luaY__state ) )
- {
- luaY_xi += 2;
- }
- while ( ( *(luaY_xi += 2) >= 0 ) &&
- ( *luaY_xi != luaY_char ) )
- ;
- if ( ( luaY__n = luaY_xi[1] ) < 0 )
- YYACCEPT;
- }
- }
-
- /*
- ** check for syntax error
- */
- if ( luaY__n == 0 ) /* have an error */
- {
- /* no worry about speed here! */
- switch ( luaY_errflag )
- {
- case 0: /* new error */
- luaY_error( "syntax error" );
- goto skip_init;
- luaY_errlab:
- /*
- ** get globals into registers.
- ** we have a user generated syntax type error
- */
- luaY__pv = luaY_pv;
- luaY__ps = luaY_ps;
- luaY__state = luaY_state;
- luaY_nerrs++;
- skip_init:
- case 1:
- case 2: /* incompletely recovered error */
- /* try again... */
- luaY_errflag = 3;
- /*
- ** find state where "error" is a legal
- ** shift action
- */
- while ( luaY__ps >= luaY_s )
- {
- luaY__n = luaY_pact[ *luaY__ps ] + YYERRCODE;
- if ( luaY__n >= 0 && luaY__n < YYLAST &&
- luaY_chk[luaY_act[luaY__n]] == YYERRCODE) {
- /*
- ** simulate shift of "error"
- */
- luaY__state = luaY_act[ luaY__n ];
- goto luaY__stack;
- }
- /*
- ** current state has no shift on
- ** "error", pop stack
- */
+ if (luaY_debug)
+ printf("%sdebug: state %d, error recovery shifting\
+ to state %d\n", YYPREFIX, *luaY_ssp, luaY_table[luaY_n]);
+#endif
+ if (luaY_ssp >= luaY_ss + luaY_stacksize - 1)
+ {
+ goto luaY_overflow;
+ }
+ *++luaY_ssp = luaY_state = luaY_table[luaY_n];
+ *++luaY_vsp = luaY_lval;
+ goto luaY_loop;
+ }
+ else
+ {
#if YYDEBUG
-# define _POP_ "Error recovery pops state %d, uncovers state %d\n"
- if ( luaY_debug )
- (void)printf( _POP_, *luaY__ps,
- luaY__ps[-1] );
-# undef _POP_
+ if (luaY_debug)
+ printf("%sdebug: error recovery discarding state %d\n",
+ YYPREFIX, *luaY_ssp);
#endif
- luaY__ps--;
- luaY__pv--;
- }
- /*
- ** there is no state on stack with "error" as
- ** a valid shift. give up.
- */
- YYABORT;
- case 3: /* no shift yet; eat a token */
+ if (luaY_ssp <= luaY_ss) goto luaY_abort;
+ --luaY_ssp;
+ --luaY_vsp;
+ }
+ }
+ }
+ else
+ {
+ if (luaY_char == 0) goto luaY_abort;
#if YYDEBUG
- /*
- ** if debugging, look up token in list of
- ** pairs. 0 and negative shouldn't occur,
- ** but since timing doesn't matter when
- ** debugging, it doesn't hurt to leave the
- ** tests here.
- */
- if ( luaY_debug )
- {
- register int luaY__i;
-
- (void)printf( "Error recovery discards " );
- if ( luaY_char == 0 )
- (void)printf( "token end-of-file\n" );
- else if ( luaY_char < 0 )
- (void)printf( "token -none-\n" );
- else
- {
- for ( luaY__i = 0;
- luaY_toks[luaY__i].t_val >= 0;
- luaY__i++ )
- {
- if ( luaY_toks[luaY__i].t_val
- == luaY_char )
- {
- break;
- }
- }
- (void)printf( "token %s\n",
- luaY_toks[luaY__i].t_name );
- }
- }
-#endif /* YYDEBUG */
- if ( luaY_char == 0 ) /* reached EOF. quit */
- YYABORT;
- luaY_char = -1;
- goto luaY__newstate;
- }
- }/* end if ( luaY__n == 0 ) */
- /*
- ** reduction by production luaY__n
- ** put stack tops, etc. so things right after switch
- */
+ if (luaY_debug)
+ {
+ luaY_s = 0;
+ if (luaY_char <= YYMAXTOKEN) luaY_s = luaY_name[luaY_char];
+ if (!luaY_s) luaY_s = "illegal-symbol";
+ printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
+ YYPREFIX, luaY_state, luaY_char, luaY_s);
+ }
+#endif
+ luaY_char = (-1);
+ goto luaY_loop;
+ }
+luaY_reduce:
#if YYDEBUG
- /*
- ** if debugging, print the string that is the user's
- ** specification of the reduction which is just about
- ** to be done.
- */
- if ( luaY_debug )
- (void)printf( "Reduce by (%d) \"%s\"\n",
- luaY__n, luaY_reds[ luaY__n ] );
+ if (luaY_debug)
+ printf("%sdebug: state %d, reducing by rule %d (%s)\n",
+ YYPREFIX, luaY_state, luaY_n, luaY_rule[luaY_n]);
#endif
- luaY_tmp = luaY__n; /* value to switch over */
- luaY_pvt = luaY__pv; /* $vars top of value stack */
- /*
- ** Look in goto table for next state
- ** Sorry about using luaY__state here as temporary
- ** register variable, but why not, if it works...
- ** If luaY_r2[ luaY__n ] doesn't have the low order bit
- ** set, then there is no action to be done for
- ** this reduction. So, no saving & unsaving of
- ** registers done. The only difference between the
- ** code just after the if and the body of the if is
- ** the goto luaY__stack in the body. This way the test
- ** can be made before the choice of what to do is needed.
- */
- {
- /* length of production doubled with extra bit */
- register int luaY__len = luaY_r2[ luaY__n ];
-
- if ( !( luaY__len & 01 ) )
- {
- luaY__len >>= 1;
- luaY_val = ( luaY__pv -= luaY__len )[1]; /* $$ = $1 */
- luaY__state = luaY_pgo[ luaY__n = luaY_r1[ luaY__n ] ] +
- *( luaY__ps -= luaY__len ) + 1;
- if ( luaY__state >= YYLAST ||
- luaY_chk[ luaY__state =
- luaY_act[ luaY__state ] ] != -luaY__n )
- {
- luaY__state = luaY_act[ luaY_pgo[ luaY__n ] ];
- }
- goto luaY__stack;
- }
- luaY__len >>= 1;
- luaY_val = ( luaY__pv -= luaY__len )[1]; /* $$ = $1 */
- luaY__state = luaY_pgo[ luaY__n = luaY_r1[ luaY__n ] ] +
- *( luaY__ps -= luaY__len ) + 1;
- if ( luaY__state >= YYLAST ||
- luaY_chk[ luaY__state = luaY_act[ luaY__state ] ] != -luaY__n )
- {
- luaY__state = luaY_act[ luaY_pgo[ luaY__n ] ];
- }
- }
- /* save until reenter driver code */
- luaY_state = luaY__state;
- luaY_ps = luaY__ps;
- luaY_pv = luaY__pv;
- }
- /*
- ** code supplied by user is placed in this switch
- */
- switch( luaY_tmp )
- {
-
-case 6:
-# line 469 "lua.stx"
+ luaY_m = luaY_len[luaY_n];
+ luaY_val = luaY_vsp[1-luaY_m];
+ switch (luaY_n)
+ {
+case 5:
+#line 470 "lua.stx"
{
code_byte(PUSHFUNCTION);
- code_code(luaY_pvt[-0].pFunc);
- storesinglevar(luaY_pvt[-1].vLong);
- } break;
+ code_code(luaY_vsp[0].pFunc);
+ storesinglevar(luaY_vsp[-1].vLong);
+ }
+break;
+case 6:
+#line 477 "lua.stx"
+{ luaY_val.vLong =luaY_vsp[0].vLong; init_func(); }
+break;
case 7:
-# line 476 "lua.stx"
-{ luaY_val.vLong =luaY_pvt[-0].vLong; init_func(); } break;
-case 8:
-# line 478 "lua.stx"
+#line 479 "lua.stx"
{
code_byte(PUSHSTRING);
- code_word(luaI_findconstant(luaY_pvt[-0].pTStr));
+ code_word(luaI_findconstant(luaY_vsp[0].pTStr));
luaY_val.vLong = 0; /* indexed variable */
init_func();
add_localvar(luaI_createfixedstring("self"));
- } break;
-case 9:
-# line 488 "lua.stx"
+ }
+break;
+case 8:
+#line 489 "lua.stx"
{
codereturn();
luaY_val.pFunc = new(TFunc);
@@ -1331,7 +1169,7 @@ case 9:
luaY_val.pFunc->size = pc;
luaY_val.pFunc->code = newvector(pc, Byte);
luaY_val.pFunc->fileName = lua_parsedfile;
- luaY_val.pFunc->lineDefined = luaY_pvt[-3].vInt;
+ luaY_val.pFunc->lineDefined = luaY_vsp[-3].vInt;
memcpy(luaY_val.pFunc->code, basepc, pc*sizeof(Byte));
if (lua_debug)
luaI_closelocalvars(luaY_val.pFunc);
@@ -1341,347 +1179,490 @@ case 9:
PrintCode(funcCode,funcCode+pc);
#endif
change2main(); /* change back to main code */
- } break;
+ }
+break;
+case 13:
+#line 516 "lua.stx"
+{ codeIf(luaY_vsp[-4].vLong, luaY_vsp[-2].vLong); }
+break;
case 14:
-# line 515 "lua.stx"
-{ codeIf(luaY_pvt[-4].vLong, luaY_pvt[-2].vLong); } break;
+#line 518 "lua.stx"
+{luaY_val.vLong=pc;}
+break;
case 15:
-# line 517 "lua.stx"
-{luaY_val.vLong=pc;} break;
-case 16:
-# line 518 "lua.stx"
+#line 519 "lua.stx"
{
- basepc[luaY_pvt[-3].vLong] = IFFJMP;
- code_word_at(basepc+luaY_pvt[-3].vLong+1, pc - (luaY_pvt[-3].vLong + sizeof(Word)+1));
- basepc[luaY_pvt[-1].vLong] = UPJMP;
- code_word_at(basepc+luaY_pvt[-1].vLong+1, pc - (luaY_pvt[-6].vLong));
- } break;
+ basepc[luaY_vsp[-3].vLong] = IFFJMP;
+ code_word_at(basepc+luaY_vsp[-3].vLong+1, pc - (luaY_vsp[-3].vLong + sizeof(Word)+1));
+ basepc[luaY_vsp[-1].vLong] = UPJMP;
+ code_word_at(basepc+luaY_vsp[-1].vLong+1, pc - (luaY_vsp[-6].vLong));
+ }
+break;
+case 16:
+#line 526 "lua.stx"
+{luaY_val.vLong=pc;}
+break;
case 17:
-# line 525 "lua.stx"
-{luaY_val.vLong=pc;} break;
-case 18:
-# line 526 "lua.stx"
+#line 527 "lua.stx"
{
- basepc[luaY_pvt[-0].vLong] = IFFUPJMP;
- code_word_at(basepc+luaY_pvt[-0].vLong+1, pc - (luaY_pvt[-4].vLong));
- } break;
-case 19:
-# line 532 "lua.stx"
+ basepc[luaY_vsp[0].vLong] = IFFUPJMP;
+ code_word_at(basepc+luaY_vsp[0].vLong+1, pc - (luaY_vsp[-4].vLong));
+ }
+break;
+case 18:
+#line 533 "lua.stx"
{
{
int i;
- adjust_mult_assign(nvarbuffer, luaY_pvt[-0].vLong, luaY_pvt[-2].vInt * 2 + nvarbuffer);
+ adjust_mult_assign(nvarbuffer, luaY_vsp[0].vLong, luaY_vsp[-2].vInt * 2 + nvarbuffer);
for (i=nvarbuffer-1; i>=0; i--)
lua_codestore (i);
- if (luaY_pvt[-2].vInt > 1 || (luaY_pvt[-2].vInt == 1 && varbuffer[0] != 0))
+ if (luaY_vsp[-2].vInt > 1 || (luaY_vsp[-2].vInt == 1 && varbuffer[0] != 0))
lua_codeadjust (0);
}
- } break;
-case 21:
-# line 544 "lua.stx"
-{ nlocalvar += luaY_pvt[-1].vInt;
- adjust_mult_assign(luaY_pvt[-1].vInt, luaY_pvt[-0].vInt, 0);
- } break;
+ }
+break;
+case 20:
+#line 545 "lua.stx"
+{ nlocalvar += luaY_vsp[-1].vInt;
+ adjust_mult_assign(luaY_vsp[-1].vInt, luaY_vsp[0].vInt, 0);
+ }
+break;
+case 23:
+#line 553 "lua.stx"
+{ codeIf(luaY_vsp[-3].vLong, luaY_vsp[-1].vLong); }
+break;
case 24:
-# line 552 "lua.stx"
-{ codeIf(luaY_pvt[-3].vLong, luaY_pvt[-1].vLong); } break;
+#line 556 "lua.stx"
+{luaY_val.vInt = nlocalvar;}
+break;
case 25:
-# line 555 "lua.stx"
-{luaY_val.vInt = nlocalvar;} break;
-case 26:
-# line 556 "lua.stx"
+#line 557 "lua.stx"
{
- if (nlocalvar != luaY_pvt[-2].vInt)
+ if (nlocalvar != luaY_vsp[-2].vInt)
{
if (lua_debug)
- for (; nlocalvar > luaY_pvt[-2].vInt; nlocalvar--)
+ for (; nlocalvar > luaY_vsp[-2].vInt; nlocalvar--)
luaI_unregisterlocalvar(lua_linenumber);
else
- nlocalvar = luaY_pvt[-2].vInt;
+ nlocalvar = luaY_vsp[-2].vInt;
lua_codeadjust (0);
}
- } break;
-case 28:
-# line 571 "lua.stx"
+ }
+break;
+case 27:
+#line 572 "lua.stx"
{
- adjust_functioncall(luaY_pvt[-1].vLong, MULT_RET);
+ adjust_functioncall(luaY_vsp[-1].vLong, MULT_RET);
codereturn();
- } break;
-case 29:
-# line 578 "lua.stx"
+ }
+break;
+case 28:
+#line 579 "lua.stx"
{
luaY_val.vLong = pc;
code_byte(0); /* open space */
code_word (0);
- } break;
+ }
+break;
+case 29:
+#line 586 "lua.stx"
+{ adjust_functioncall(luaY_vsp[0].vLong, 1); }
+break;
case 30:
-# line 584 "lua.stx"
-{ adjust_functioncall(luaY_pvt[-0].vLong, 1); } break;
+#line 589 "lua.stx"
+{ luaY_val.vLong = luaY_vsp[-1].vLong; }
+break;
case 31:
-# line 587 "lua.stx"
-{ luaY_val.vLong = luaY_pvt[-1].vLong; } break;
+#line 590 "lua.stx"
+{ code_byte(EQOP); luaY_val.vLong = 0; }
+break;
case 32:
-# line 588 "lua.stx"
-{ code_byte(EQOP); luaY_val.vLong = 0; } break;
+#line 591 "lua.stx"
+{ code_byte(LTOP); luaY_val.vLong = 0; }
+break;
case 33:
-# line 589 "lua.stx"
-{ code_byte(LTOP); luaY_val.vLong = 0; } break;
+#line 592 "lua.stx"
+{ code_byte(GTOP); luaY_val.vLong = 0; }
+break;
case 34:
-# line 590 "lua.stx"
-{ code_byte(GTOP); luaY_val.vLong = 0; } break;
+#line 593 "lua.stx"
+{ code_byte(EQOP); code_byte(NOTOP); luaY_val.vLong = 0; }
+break;
case 35:
-# line 591 "lua.stx"
-{ code_byte(EQOP); code_byte(NOTOP); luaY_val.vLong = 0; } break;
+#line 594 "lua.stx"
+{ code_byte(LEOP); luaY_val.vLong = 0; }
+break;
case 36:
-# line 592 "lua.stx"
-{ code_byte(LEOP); luaY_val.vLong = 0; } break;
+#line 595 "lua.stx"
+{ code_byte(GEOP); luaY_val.vLong = 0; }
+break;
case 37:
-# line 593 "lua.stx"
-{ code_byte(GEOP); luaY_val.vLong = 0; } break;
+#line 596 "lua.stx"
+{ code_byte(ADDOP); luaY_val.vLong = 0; }
+break;
case 38:
-# line 594 "lua.stx"
-{ code_byte(ADDOP); luaY_val.vLong = 0; } break;
+#line 597 "lua.stx"
+{ code_byte(SUBOP); luaY_val.vLong = 0; }
+break;
case 39:
-# line 595 "lua.stx"
-{ code_byte(SUBOP); luaY_val.vLong = 0; } break;
+#line 598 "lua.stx"
+{ code_byte(MULTOP); luaY_val.vLong = 0; }
+break;
case 40:
-# line 596 "lua.stx"
-{ code_byte(MULTOP); luaY_val.vLong = 0; } break;
+#line 599 "lua.stx"
+{ code_byte(DIVOP); luaY_val.vLong = 0; }
+break;
case 41:
-# line 597 "lua.stx"
-{ code_byte(DIVOP); luaY_val.vLong = 0; } break;
+#line 600 "lua.stx"
+{ code_byte(POWOP); luaY_val.vLong = 0; }
+break;
case 42:
-# line 598 "lua.stx"
-{ code_byte(POWOP); luaY_val.vLong = 0; } break;
+#line 601 "lua.stx"
+{ code_byte(CONCOP); luaY_val.vLong = 0; }
+break;
case 43:
-# line 599 "lua.stx"
-{ code_byte(CONCOP); luaY_val.vLong = 0; } break;
+#line 602 "lua.stx"
+{ code_byte(MINUSOP); luaY_val.vLong = 0;}
+break;
case 44:
-# line 600 "lua.stx"
-{ code_byte(MINUSOP); luaY_val.vLong = 0;} break;
+#line 603 "lua.stx"
+{ luaY_val.vLong = 0; }
+break;
case 45:
-# line 601 "lua.stx"
-{ luaY_val.vLong = 0; } break;
+#line 604 "lua.stx"
+{ luaY_val.vLong = 0;}
+break;
case 46:
-# line 602 "lua.stx"
-{ luaY_val.vLong = 0;} break;
+#line 605 "lua.stx"
+{ code_number(luaY_vsp[0].vFloat); luaY_val.vLong = 0; }
+break;
case 47:
-# line 603 "lua.stx"
-{ code_number(luaY_pvt[-0].vFloat); luaY_val.vLong = 0; } break;
-case 48:
-# line 605 "lua.stx"
+#line 607 "lua.stx"
{
code_byte(PUSHSTRING);
- code_word(luaY_pvt[-0].vWord);
+ code_word(luaY_vsp[0].vWord);
luaY_val.vLong = 0;
- } break;
+ }
+break;
+case 48:
+#line 612 "lua.stx"
+{code_byte(PUSHNIL); luaY_val.vLong = 0; }
+break;
case 49:
-# line 610 "lua.stx"
-{code_byte(PUSHNIL); luaY_val.vLong = 0; } break;
+#line 613 "lua.stx"
+{ luaY_val.vLong = luaY_vsp[0].vLong; }
+break;
case 50:
-# line 611 "lua.stx"
-{ luaY_val.vLong = luaY_pvt[-0].vLong; } break;
+#line 614 "lua.stx"
+{ code_byte(NOTOP); luaY_val.vLong = 0;}
+break;
case 51:
-# line 612 "lua.stx"
-{ code_byte(NOTOP); luaY_val.vLong = 0;} break;
+#line 615 "lua.stx"
+{code_byte(POP); }
+break;
case 52:
-# line 613 "lua.stx"
-{code_byte(POP); } break;
-case 53:
-# line 614 "lua.stx"
+#line 616 "lua.stx"
{
- basepc[luaY_pvt[-2].vLong] = ONFJMP;
- code_word_at(basepc+luaY_pvt[-2].vLong+1, pc - (luaY_pvt[-2].vLong + sizeof(Word)+1));
+ basepc[luaY_vsp[-2].vLong] = ONFJMP;
+ code_word_at(basepc+luaY_vsp[-2].vLong+1, pc - (luaY_vsp[-2].vLong + sizeof(Word)+1));
luaY_val.vLong = 0;
- } break;
+ }
+break;
+case 53:
+#line 621 "lua.stx"
+{code_byte(POP); }
+break;
case 54:
-# line 619 "lua.stx"
-{code_byte(POP); } break;
-case 55:
-# line 620 "lua.stx"
+#line 622 "lua.stx"
{
- basepc[luaY_pvt[-2].vLong] = ONTJMP;
- code_word_at(basepc+luaY_pvt[-2].vLong+1, pc - (luaY_pvt[-2].vLong + sizeof(Word)+1));
+ basepc[luaY_vsp[-2].vLong] = ONTJMP;
+ code_word_at(basepc+luaY_vsp[-2].vLong+1, pc - (luaY_vsp[-2].vLong + sizeof(Word)+1));
luaY_val.vLong = 0;
- } break;
-case 56:
-# line 628 "lua.stx"
+ }
+break;
+case 55:
+#line 630 "lua.stx"
{
code_byte(CREATEARRAY);
luaY_val.vLong = pc; code_word(0);
- } break;
-case 57:
-# line 633 "lua.stx"
+ }
+break;
+case 56:
+#line 635 "lua.stx"
{
- code_word_at(basepc+luaY_pvt[-3].vLong, luaY_pvt[-1].vInt);
- } break;
-case 58:
-# line 639 "lua.stx"
+ code_word_at(basepc+luaY_vsp[-3].vLong, luaY_vsp[-1].vInt);
+ }
+break;
+case 57:
+#line 641 "lua.stx"
{
code_byte(CALLFUNC);
- code_byte(luaY_pvt[-1].vInt+luaY_pvt[-0].vInt);
+ code_byte(luaY_vsp[-1].vInt+luaY_vsp[0].vInt);
luaY_val.vLong = pc;
code_byte(0); /* may be modified by other rules */
- } break;
+ }
+break;
+case 58:
+#line 649 "lua.stx"
+{ luaY_val.vInt = 0; }
+break;
case 59:
-# line 647 "lua.stx"
-{ luaY_val.vInt = 0; } break;
-case 60:
-# line 649 "lua.stx"
+#line 651 "lua.stx"
{
code_byte(PUSHSELF);
- code_word(luaI_findconstant(luaY_pvt[-0].pTStr));
+ code_word(luaI_findconstant(luaY_vsp[0].pTStr));
luaY_val.vInt = 1;
- } break;
+ }
+break;
+case 60:
+#line 659 "lua.stx"
+{ luaY_val.vInt = adjust_functioncall(luaY_vsp[-1].vLong, 1); }
+break;
case 61:
-# line 657 "lua.stx"
-{ luaY_val.vInt = adjust_functioncall(luaY_pvt[-1].vLong, 1); } break;
+#line 660 "lua.stx"
+{ luaY_val.vInt = 1; }
+break;
case 62:
-# line 658 "lua.stx"
-{ luaY_val.vInt = 1; } break;
+#line 663 "lua.stx"
+{ luaY_val.vLong = 0; }
+break;
case 63:
-# line 661 "lua.stx"
-{ luaY_val.vLong = 0; } break;
+#line 664 "lua.stx"
+{ luaY_val.vLong = luaY_vsp[0].vLong; }
+break;
case 64:
-# line 662 "lua.stx"
-{ luaY_val.vLong = luaY_pvt[-0].vLong; } break;
+#line 667 "lua.stx"
+{ if (luaY_vsp[0].vLong != 0) luaY_val.vLong = luaY_vsp[0].vLong; else luaY_val.vLong = -1; }
+break;
case 65:
-# line 665 "lua.stx"
-{ if (luaY_pvt[-0].vLong != 0) luaY_val.vLong = luaY_pvt[-0].vLong; else luaY_val.vLong = -1; } break;
+#line 668 "lua.stx"
+{ luaY_val.vLong = adjust_functioncall(luaY_vsp[-1].vLong, 1); }
+break;
case 66:
-# line 666 "lua.stx"
-{ luaY_val.vLong = adjust_functioncall(luaY_pvt[-1].vLong, 1); } break;
-case 67:
-# line 667 "lua.stx"
+#line 669 "lua.stx"
{
- if (luaY_pvt[-0].vLong == 0) luaY_val.vLong = -(luaY_pvt[-1].vLong + 1); /* -length */
+ if (luaY_vsp[0].vLong == 0) luaY_val.vLong = -(luaY_vsp[-1].vLong + 1); /* -length */
else
{
- adjust_functioncall(luaY_pvt[-0].vLong, luaY_pvt[-1].vLong);
- luaY_val.vLong = luaY_pvt[-0].vLong;
+ adjust_functioncall(luaY_vsp[0].vLong, luaY_vsp[-1].vLong);
+ luaY_val.vLong = luaY_vsp[0].vLong;
}
- } break;
+ }
+break;
+case 67:
+#line 679 "lua.stx"
+{ luaY_val.vInt = close_parlist(0); }
+break;
case 68:
-# line 677 "lua.stx"
-{ lua_codeadjust(0); luaY_val.vInt = lua_linenumber; } break;
+#line 680 "lua.stx"
+{ luaY_val.vInt = close_parlist(luaY_vsp[0].vInt); }
+break;
case 69:
-# line 678 "lua.stx"
-{ lua_codeadjust(0); luaY_val.vInt = lua_linenumber; } break;
+#line 683 "lua.stx"
+{ luaY_val.vInt = luaY_vsp[0].vInt; }
+break;
case 70:
-# line 681 "lua.stx"
-{ add_localvar(luaY_pvt[-0].pTStr); } break;
+#line 685 "lua.stx"
+{
+ if (luaY_vsp[-2].vInt)
+ lua_error("invalid parameter list");
+ luaY_val.vInt = luaY_vsp[0].vInt;
+ }
+break;
case 71:
-# line 682 "lua.stx"
-{ add_localvar(luaY_pvt[-0].pTStr); } break;
+#line 692 "lua.stx"
+{ add_localvar(luaY_vsp[0].pTStr); luaY_val.vInt = 0; }
+break;
case 72:
-# line 686 "lua.stx"
-{ flush_list(luaY_pvt[-0].vInt/FIELDS_PER_FLUSH, luaY_pvt[-0].vInt%FIELDS_PER_FLUSH); } break;
+#line 693 "lua.stx"
+{ luaY_val.vInt = 1; }
+break;
case 73:
-# line 688 "lua.stx"
-{ luaY_val.vInt = luaY_pvt[-2].vInt+luaY_pvt[-0].vInt; } break;
+#line 697 "lua.stx"
+{ flush_list(luaY_vsp[0].vInt/FIELDS_PER_FLUSH, luaY_vsp[0].vInt%FIELDS_PER_FLUSH); }
+break;
case 74:
-# line 690 "lua.stx"
-{ luaY_val.vInt = luaY_pvt[-1].vInt; flush_record(luaY_pvt[-1].vInt%FIELDS_PER_FLUSH); } break;
+#line 699 "lua.stx"
+{ luaY_val.vInt = luaY_vsp[-2].vInt+luaY_vsp[0].vInt; }
+break;
case 75:
-# line 694 "lua.stx"
-{ luaY_val.vInt = 0; } break;
+#line 701 "lua.stx"
+{ luaY_val.vInt = luaY_vsp[-1].vInt; flush_record(luaY_vsp[-1].vInt%FIELDS_PER_FLUSH); }
+break;
case 76:
-# line 696 "lua.stx"
-{ luaY_val.vInt = luaY_pvt[-0].vInt; flush_record(luaY_pvt[-0].vInt%FIELDS_PER_FLUSH); } break;
-case 79:
-# line 703 "lua.stx"
-{ luaY_val.vInt = 0; } break;
+#line 705 "lua.stx"
+{ luaY_val.vInt = 0; }
+break;
+case 77:
+#line 707 "lua.stx"
+{ luaY_val.vInt = luaY_vsp[0].vInt; flush_record(luaY_vsp[0].vInt%FIELDS_PER_FLUSH); }
+break;
case 80:
-# line 704 "lua.stx"
-{ luaY_val.vInt = luaY_pvt[-1].vInt; } break;
+#line 714 "lua.stx"
+{ luaY_val.vInt = 0; }
+break;
case 81:
-# line 707 "lua.stx"
-{luaY_val.vInt=1;} break;
+#line 715 "lua.stx"
+{ luaY_val.vInt = luaY_vsp[-1].vInt; }
+break;
case 82:
-# line 709 "lua.stx"
+#line 718 "lua.stx"
+{luaY_val.vInt=1;}
+break;
+case 83:
+#line 720 "lua.stx"
{
- luaY_val.vInt=luaY_pvt[-2].vInt+1;
+ luaY_val.vInt=luaY_vsp[-2].vInt+1;
if (luaY_val.vInt%FIELDS_PER_FLUSH == 0) flush_record(FIELDS_PER_FLUSH);
- } break;
-case 83:
-# line 716 "lua.stx"
-{
- push_field(luaI_findconstant(luaY_pvt[-2].pTStr));
- } break;
+ }
+break;
case 84:
-# line 721 "lua.stx"
-{ luaY_val.vInt = 0; } break;
+#line 727 "lua.stx"
+{
+ push_field(luaI_findconstant(luaY_vsp[-2].pTStr));
+ }
+break;
case 85:
-# line 722 "lua.stx"
-{ luaY_val.vInt = luaY_pvt[-1].vInt; } break;
+#line 732 "lua.stx"
+{ luaY_val.vInt = 0; }
+break;
case 86:
-# line 725 "lua.stx"
-{luaY_val.vInt=1;} break;
+#line 733 "lua.stx"
+{ luaY_val.vInt = luaY_vsp[-1].vInt; }
+break;
case 87:
-# line 727 "lua.stx"
+#line 736 "lua.stx"
+{luaY_val.vInt=1;}
+break;
+case 88:
+#line 738 "lua.stx"
{
- luaY_val.vInt=luaY_pvt[-2].vInt+1;
+ luaY_val.vInt=luaY_vsp[-2].vInt+1;
if (luaY_val.vInt%FIELDS_PER_FLUSH == 0)
flush_list(luaY_val.vInt/FIELDS_PER_FLUSH - 1, FIELDS_PER_FLUSH);
- } break;
-case 88:
-# line 735 "lua.stx"
+ }
+break;
+case 89:
+#line 746 "lua.stx"
{
nvarbuffer = 0;
- add_varbuffer(luaY_pvt[-0].vLong);
- luaY_val.vInt = (luaY_pvt[-0].vLong == 0) ? 1 : 0;
- } break;
-case 89:
-# line 741 "lua.stx"
-{
- add_varbuffer(luaY_pvt[-0].vLong);
- luaY_val.vInt = (luaY_pvt[-0].vLong == 0) ? luaY_pvt[-2].vInt + 1 : luaY_pvt[-2].vInt;
- } break;
+ add_varbuffer(luaY_vsp[0].vLong);
+ luaY_val.vInt = (luaY_vsp[0].vLong == 0) ? 1 : 0;
+ }
+break;
case 90:
-# line 747 "lua.stx"
-{ luaY_val.vLong = luaY_pvt[-0].vLong; } break;
+#line 752 "lua.stx"
+{
+ add_varbuffer(luaY_vsp[0].vLong);
+ luaY_val.vInt = (luaY_vsp[0].vLong == 0) ? luaY_vsp[-2].vInt + 1 : luaY_vsp[-2].vInt;
+ }
+break;
case 91:
-# line 749 "lua.stx"
+#line 758 "lua.stx"
+{ luaY_val.vLong = luaY_vsp[0].vLong; }
+break;
+case 92:
+#line 760 "lua.stx"
{
luaY_val.vLong = 0; /* indexed variable */
- } break;
-case 92:
-# line 753 "lua.stx"
+ }
+break;
+case 93:
+#line 764 "lua.stx"
{
code_byte(PUSHSTRING);
- code_word(luaI_findconstant(luaY_pvt[-0].pTStr));
+ code_word(luaI_findconstant(luaY_vsp[0].pTStr));
luaY_val.vLong = 0; /* indexed variable */
- } break;
-case 93:
-# line 761 "lua.stx"
+ }
+break;
+case 94:
+#line 772 "lua.stx"
{
- int local = lua_localname(luaY_pvt[-0].pTStr);
+ int local = lua_localname(luaY_vsp[0].pTStr);
if (local == -1) /* global var */
- luaY_val.vLong = luaI_findsymbol(luaY_pvt[-0].pTStr)+1; /* return positive value */
+ luaY_val.vLong = luaI_findsymbol(luaY_vsp[0].pTStr)+1; /* return positive value */
else
luaY_val.vLong = -(local+1); /* return negative value */
- } break;
-case 94:
-# line 770 "lua.stx"
-{ lua_pushvar(luaY_pvt[-0].vLong); } break;
+ }
+break;
case 95:
-# line 773 "lua.stx"
-{store_localvar(luaY_pvt[-0].pTStr, 0); luaY_val.vInt = 1;} break;
+#line 781 "lua.stx"
+{ lua_pushvar(luaY_vsp[0].vLong); }
+break;
case 96:
-# line 775 "lua.stx"
-{
- store_localvar(luaY_pvt[-0].pTStr, luaY_pvt[-2].vInt);
- luaY_val.vInt = luaY_pvt[-2].vInt+1;
- } break;
+#line 784 "lua.stx"
+{store_localvar(luaY_vsp[0].pTStr, 0); luaY_val.vInt = 1;}
+break;
case 97:
-# line 781 "lua.stx"
-{ luaY_val.vInt = 0; } break;
+#line 786 "lua.stx"
+{
+ store_localvar(luaY_vsp[0].pTStr, luaY_vsp[-2].vInt);
+ luaY_val.vInt = luaY_vsp[-2].vInt+1;
+ }
+break;
case 98:
-# line 782 "lua.stx"
-{ luaY_val.vInt = luaY_pvt[-0].vLong; } break;
+#line 792 "lua.stx"
+{ luaY_val.vInt = 0; }
+break;
case 99:
-# line 785 "lua.stx"
-{ lua_debug = luaY_pvt[-0].vInt; } break;
- }
- goto luaY_stack; /* reset registers in driver code */
+#line 793 "lua.stx"
+{ luaY_val.vInt = luaY_vsp[0].vLong; }
+break;
+#line 1613 "y.tab.c"
+ }
+ luaY_ssp -= luaY_m;
+ luaY_state = *luaY_ssp;
+ luaY_vsp -= luaY_m;
+ luaY_m = luaY_lhs[luaY_n];
+ if (luaY_state == 0 && luaY_m == 0)
+ {
+#if YYDEBUG
+ if (luaY_debug)
+ printf("%sdebug: after reduction, shifting from state 0 to\
+ state %d\n", YYPREFIX, YYFINAL);
+#endif
+ luaY_state = YYFINAL;
+ *++luaY_ssp = YYFINAL;
+ *++luaY_vsp = luaY_val;
+ if (luaY_char < 0)
+ {
+ if ((luaY_char = luaY_lex()) < 0) luaY_char = 0;
+#if YYDEBUG
+ if (luaY_debug)
+ {
+ luaY_s = 0;
+ if (luaY_char <= YYMAXTOKEN) luaY_s = luaY_name[luaY_char];
+ if (!luaY_s) luaY_s = "illegal-symbol";
+ printf("%sdebug: state %d, reading %d (%s)\n",
+ YYPREFIX, YYFINAL, luaY_char, luaY_s);
+ }
+#endif
+ }
+ if (luaY_char == 0) goto luaY_accept;
+ goto luaY_loop;
+ }
+ if ((luaY_n = luaY_gindex[luaY_m]) && (luaY_n += luaY_state) >= 0 &&
+ luaY_n <= YYTABLESIZE && luaY_check[luaY_n] == luaY_state)
+ luaY_state = luaY_table[luaY_n];
+ else
+ luaY_state = luaY_dgoto[luaY_m];
+#if YYDEBUG
+ if (luaY_debug)
+ printf("%sdebug: after reduction, shifting from state %d \
+to state %d\n", YYPREFIX, *luaY_ssp, luaY_state);
+#endif
+ if (luaY_ssp >= luaY_ss + luaY_stacksize - 1)
+ {
+ goto luaY_overflow;
+ }
+ *++luaY_ssp = luaY_state;
+ *++luaY_vsp = luaY_val;
+ goto luaY_loop;
+luaY_overflow:
+ luaY_error("yacc stack overflow");
+luaY_abort:
+ return (1);
+luaY_accept:
+ return (0);
}
diff --git a/src/parser.h b/src/parser.h
index d681cd66..7087ef91 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -1,5 +1,31 @@
-
-typedef union
+#define WRONGTOKEN 257
+#define NIL 258
+#define IF 259
+#define THEN 260
+#define ELSE 261
+#define ELSEIF 262
+#define WHILE 263
+#define DO 264
+#define REPEAT 265
+#define UNTIL 266
+#define END 267
+#define RETURN 268
+#define LOCAL 269
+#define FUNCTION 270
+#define DOTS 271
+#define NUMBER 272
+#define STRING 273
+#define NAME 274
+#define AND 275
+#define OR 276
+#define EQ 277
+#define NE 278
+#define LE 279
+#define GE 280
+#define CONC 281
+#define UNARY 282
+#define NOT 283
+typedef union
{
int vInt;
float vFloat;
@@ -10,30 +36,3 @@ typedef union
TaggedString *pTStr;
} YYSTYPE;
extern YYSTYPE luaY_lval;
-# define WRONGTOKEN 257
-# define NIL 258
-# define IF 259
-# define THEN 260
-# define ELSE 261
-# define ELSEIF 262
-# define WHILE 263
-# define DO 264
-# define REPEAT 265
-# define UNTIL 266
-# define END 267
-# define RETURN 268
-# define LOCAL 269
-# define FUNCTION 270
-# define NUMBER 271
-# define STRING 272
-# define NAME 273
-# define DEBUG 274
-# define AND 275
-# define OR 276
-# define EQ 277
-# define NE 278
-# define LE 279
-# define GE 280
-# define CONC 281
-# define UNARY 282
-# define NOT 283
diff --git a/src/table.c b/src/table.c
index 1d694c4e..b2e60a35 100644
--- a/src/table.c
+++ b/src/table.c
@@ -3,7 +3,7 @@
** Module to control static tables
*/
-char *rcs_table="$Id: table.c,v 2.54 1996/05/06 14:29:35 roberto Exp $";
+char *rcs_table="$Id: table.c,v 2.58 1996/11/01 12:47:45 roberto Exp $";
#include "mem.h"
#include "opcode.h"
@@ -39,6 +39,7 @@ static struct {
lua_CFunction func;
} int_funcs[] = {
{"assert", luaI_assert},
+ {"call", luaI_call},
{"dofile", lua_internaldofile},
{"dostring", lua_internaldostring},
{"error", luaI_error},
@@ -59,13 +60,16 @@ static struct {
void luaI_initsymbol (void)
{
int i;
+ Word n;
lua_maxsymbol = BUFFER_BLOCK;
lua_table = newvector(lua_maxsymbol, Symbol);
for (i=0; i<INTFUNCSIZE; i++)
{
- Word n = luaI_findsymbolbyname(int_funcs[i].name);
+ n = luaI_findsymbolbyname(int_funcs[i].name);
s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = int_funcs[i].func;
}
+ n = luaI_findsymbolbyname("_VERSION_");
+ s_tag(n) = LUA_T_STRING; s_tsvalue(n) = lua_createstring(LUA_VERSION);
}
@@ -213,7 +217,7 @@ void lua_pack (void)
unsigned long recovered = 0;
if (nentity++ < block) return;
recovered = luaI_collectgarbage();
- block = block*2*(1.0 - (float)recovered/nentity);
+ block = 2*(block-recovered);
nentity -= recovered;
}
@@ -239,12 +243,7 @@ static void lua_nextvar (void)
else
next = luaI_findsymbolbyname(lua_getstring(o)) + 1;
while (next < lua_ntable && s_tag(next) == LUA_T_NIL) next++;
- if (next >= lua_ntable)
- {
- lua_pushnil();
- lua_pushnil();
- }
- else
+ if (next < lua_ntable)
{
lua_pushstring(lua_table[next].varname->str);
luaI_pushobject(&s_object(next));
diff --git a/src/undump.c b/src/undump.c
index 744622fc..2e6ee07f 100644
--- a/src/undump.c
+++ b/src/undump.c
@@ -3,7 +3,7 @@
** load bytecodes from files
*/
-char* rcs_undump="$Id: undump.c,v 1.14 1996/03/14 17:31:15 lhf Exp $";
+char* rcs_undump="$Id: undump.c,v 1.21 1996/11/18 11:18:29 lhf Exp $";
#include <stdio.h>
#include <string.h>
@@ -90,7 +90,7 @@ static void FixCode(Byte* code, Byte* end) /* swap words */
p+=3;
break;
case PUSHFUNCTION:
- p+=5;
+ p+=5; /* TODO: use sizeof(TFunc*) or old? */
break;
case PUSHWORD:
case PUSHSELF:
@@ -111,7 +111,7 @@ static void FixCode(Byte* code, Byte* end) /* swap words */
p+=3;
break;
}
- case PUSHFLOAT:
+ case PUSHFLOAT: /* assumes sizeof(float)==4 */
{
Byte t;
t=p[1]; p[1]=p[4]; p[4]=t;
@@ -142,13 +142,11 @@ static void Unthread(Byte* code, int i, int v)
{
while (i!=0)
{
- CodeWord c;
+ Word w;
Byte* p=code+i;
- get_word(c,p);
- i=c.w;
- c.w=v;
- p[-2]=c.m.c1;
- p[-1]=c.m.c2;
+ memcpy(&w,p,sizeof(w));
+ i=w; w=v;
+ memcpy(p,&w,sizeof(w));
}
}
@@ -174,9 +172,9 @@ static int LoadSize(FILE* D)
return s;
}
-static char* LoadBlock(int size, FILE* D)
+static void* LoadBlock(int size, FILE* D)
{
- char* b=luaI_malloc(size);
+ void* b=luaI_malloc(size);
fread(b,size,1,D);
return b;
}
@@ -208,13 +206,9 @@ static void LoadFunction(FILE* D)
}
else /* fix PUSHFUNCTION */
{
- CodeCode c;
- Byte* p;
tf->marked=LoadWord(D);
tf->fileName=Main->fileName;
- p=Main->code+tf->marked;
- c.tf=tf;
- *p++=c.m.c1; *p++=c.m.c2; *p++=c.m.c3; *p++=c.m.c4;
+ memcpy(Main->code+tf->marked,&tf,sizeof(tf));
lastF=lastF->next=tf;
}
tf->code=LoadBlock(tf->size,D);
@@ -256,8 +250,21 @@ static void LoadHeader(FILE* D) /* TODO: error handling */
{
Word w,tw=TEST_WORD;
float f,tf=TEST_FLOAT;
+ int version;
LoadSignature(D);
- getc(D); /* skip version */
+ version=getc(D);
+ if (version>0x23) /* after 2.5 */
+ {
+ int oldsizeofW=getc(D);
+ int oldsizeofF=getc(D);
+ int oldsizeofP=getc(D);
+ if (oldsizeofW!=2)
+ lua_error("cannot load binary file created on machine with sizeof(Word)!=2");
+ if (oldsizeofF!=4)
+ lua_error("cannot load binary file created on machine with sizeof(float)!=4. not an IEEE machine?");
+ if (oldsizeofP!=sizeof(TFunc*)) /* TODO: pack */
+ lua_error("cannot load binary file: different pointer sizes");
+ }
fread(&w,sizeof(w),1,D); /* test word */
if (w!=tw)
{
diff --git a/src/undump.h b/src/undump.h
index 109634ae..8d757e36 100644
--- a/src/undump.h
+++ b/src/undump.h
@@ -1,7 +1,7 @@
/*
** undump.h
** definitions for lua decompiler
-** $Id: undump.h,v 1.2 1996/03/11 21:59:41 lhf Exp $
+** $Id: undump.h,v 1.3 1996/11/14 11:44:34 lhf Exp $
*/
#include "func.h"
@@ -15,7 +15,7 @@
#define ID_VAR 'V'
#define ID_STR 'S'
#define SIGNATURE "Lua"
-#define VERSION 0x23 /* 2.3 */
+#define VERSION 0x25 /* 2.5 */
#define TEST_WORD 0x1234 /* a word for testing byte ordering */
#define TEST_FLOAT 0.123456789e-23 /* a float for testing representation */