new style for debug information about functions: no more SETFUNCTION
opcodes. When a function is called, its entry in the stack is marked with LUA_T_(C)MARK, so function 'luaD_stackedfunction' can find it if needed. Functions now have their file names in the headers, so there is no need of 'addfile' and the like.
This commit is contained in:
4
func.h
4
func.h
@@ -12,6 +12,10 @@ typedef struct TFunc
|
|||||||
char marked;
|
char marked;
|
||||||
int size;
|
int size;
|
||||||
Byte *code;
|
Byte *code;
|
||||||
|
int lineDefined;
|
||||||
|
char *name1; /* function or method name (or null if main) */
|
||||||
|
char *name2; /* object name (or null if not method) */
|
||||||
|
char *fileName;
|
||||||
} TFunc;
|
} TFunc;
|
||||||
|
|
||||||
Long luaI_funccollector (void);
|
Long luaI_funccollector (void);
|
||||||
|
|||||||
109
inout.c
109
inout.c
@@ -5,7 +5,7 @@
|
|||||||
** Also provides some predefined lua functions.
|
** Also provides some predefined lua functions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_inout="$Id: inout.c,v 2.21 1995/10/04 14:20:26 roberto Exp roberto $";
|
char *rcs_inout="$Id: inout.c,v 2.22 1995/10/09 13:06:20 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -31,20 +31,9 @@ char *rcs_inout="$Id: inout.c,v 2.21 1995/10/04 14:20:26 roberto Exp roberto $";
|
|||||||
Word lua_linenumber;
|
Word lua_linenumber;
|
||||||
Bool lua_debug;
|
Bool lua_debug;
|
||||||
Word lua_debugline = 0;
|
Word lua_debugline = 0;
|
||||||
|
char *lua_parsedfile;
|
||||||
|
|
||||||
|
|
||||||
/* Internal variables */
|
|
||||||
|
|
||||||
typedef struct FuncStackNode {
|
|
||||||
struct FuncStackNode *next;
|
|
||||||
char *file;
|
|
||||||
Word function;
|
|
||||||
Word line;
|
|
||||||
} FuncStackNode;
|
|
||||||
|
|
||||||
static FuncStackNode *funcStack = NULL;
|
|
||||||
static Word nfuncstack=0;
|
|
||||||
|
|
||||||
static FILE *fp;
|
static FILE *fp;
|
||||||
static char *st;
|
static char *st;
|
||||||
|
|
||||||
@@ -70,16 +59,17 @@ static int stringinput (void)
|
|||||||
*/
|
*/
|
||||||
char *lua_openfile (char *fn)
|
char *lua_openfile (char *fn)
|
||||||
{
|
{
|
||||||
lua_linenumber = 1;
|
|
||||||
lua_setinput (fileinput);
|
lua_setinput (fileinput);
|
||||||
fp = fopen (fn, "r");
|
fp = fopen (fn, "r");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
{
|
{
|
||||||
static char buff[255];
|
static char buff[255];
|
||||||
sprintf(buff, "unable to open file %.230s", fn);
|
sprintf(buff, "unable to open file `%.200s'", fn);
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
return lua_addfile (fn);
|
lua_linenumber = 1;
|
||||||
|
lua_parsedfile = lua_constcreate(fn)->ts.str;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -89,7 +79,6 @@ void lua_closefile (void)
|
|||||||
{
|
{
|
||||||
if (fp != NULL)
|
if (fp != NULL)
|
||||||
{
|
{
|
||||||
lua_delfile();
|
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
fp = NULL;
|
fp = NULL;
|
||||||
}
|
}
|
||||||
@@ -98,16 +87,12 @@ void lua_closefile (void)
|
|||||||
/*
|
/*
|
||||||
** Function to open a string to be input unit
|
** Function to open a string to be input unit
|
||||||
*/
|
*/
|
||||||
char *lua_openstring (char *s)
|
void lua_openstring (char *s)
|
||||||
{
|
{
|
||||||
lua_linenumber = 1;
|
|
||||||
lua_setinput (stringinput);
|
lua_setinput (stringinput);
|
||||||
st = s;
|
st = s;
|
||||||
{
|
lua_linenumber = 1;
|
||||||
char sn[64];
|
lua_parsedfile = lua_constcreate("(string)")->ts.str;
|
||||||
sprintf (sn, "String: %10.10s...", s);
|
|
||||||
return lua_addfile (sn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -115,75 +100,6 @@ char *lua_openstring (char *s)
|
|||||||
*/
|
*/
|
||||||
void lua_closestring (void)
|
void lua_closestring (void)
|
||||||
{
|
{
|
||||||
lua_delfile();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Called to execute SETFUNCTION opcode, this function pushs a function into
|
|
||||||
** function stack.
|
|
||||||
*/
|
|
||||||
void lua_pushfunction (char *file, Word function)
|
|
||||||
{
|
|
||||||
FuncStackNode *newNode;
|
|
||||||
if (nfuncstack++ >= MAXFUNCSTACK)
|
|
||||||
{
|
|
||||||
lua_error("function stack overflow");
|
|
||||||
}
|
|
||||||
newNode = new(FuncStackNode);
|
|
||||||
newNode->function = function;
|
|
||||||
newNode->file = file;
|
|
||||||
newNode->line= lua_debugline;
|
|
||||||
newNode->next = funcStack;
|
|
||||||
funcStack = newNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Called to execute RESET opcode, this function pops a function from
|
|
||||||
** function stack.
|
|
||||||
*/
|
|
||||||
void lua_popfunction (void)
|
|
||||||
{
|
|
||||||
FuncStackNode *temp = funcStack;
|
|
||||||
if (temp == NULL) return;
|
|
||||||
--nfuncstack;
|
|
||||||
lua_debugline = temp->line;
|
|
||||||
funcStack = temp->next;
|
|
||||||
luaI_free(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Report bug building a message and pushing it on the stack.
|
|
||||||
*/
|
|
||||||
void luaI_reportbug (char *s, int err)
|
|
||||||
{
|
|
||||||
char msg[MAXMESSAGE];
|
|
||||||
strcpy (msg, s);
|
|
||||||
if (lua_debugline != 0)
|
|
||||||
{
|
|
||||||
if (funcStack)
|
|
||||||
{
|
|
||||||
FuncStackNode *func = funcStack;
|
|
||||||
int line = lua_debugline;
|
|
||||||
sprintf (strchr(msg,0), "\n\tactive stack:\n");
|
|
||||||
do
|
|
||||||
{
|
|
||||||
sprintf (strchr(msg,0),
|
|
||||||
"\t-> function \"%s\" at file \"%s\":%u\n",
|
|
||||||
lua_constant[func->function]->str, func->file, line);
|
|
||||||
line = func->line;
|
|
||||||
func = func->next;
|
|
||||||
if (err) lua_popfunction();
|
|
||||||
} while (func);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprintf (strchr(msg,0),
|
|
||||||
"\n\tin statement begining at line %u of file \"%s\"",
|
|
||||||
lua_debugline, lua_filename());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lua_pushstring(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -297,10 +213,3 @@ void luaI_error (void)
|
|||||||
lua_error(s);
|
lua_error(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void luaI_getstack (void)
|
|
||||||
{
|
|
||||||
char *s = lua_getstring(lua_getparam(1));
|
|
||||||
if (s == NULL) s = "";
|
|
||||||
luaI_reportbug(s, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
9
inout.h
9
inout.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: inout.h,v 1.8 1995/05/02 18:43:03 roberto Exp roberto $
|
** $Id: inout.h,v 1.9 1995/05/16 17:23:58 roberto Exp roberto $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -12,21 +12,18 @@
|
|||||||
extern Word lua_linenumber;
|
extern Word lua_linenumber;
|
||||||
extern Bool lua_debug;
|
extern Bool lua_debug;
|
||||||
extern Word lua_debugline;
|
extern Word lua_debugline;
|
||||||
|
extern char *lua_parsedfile;
|
||||||
|
|
||||||
char *lua_openfile (char *fn);
|
char *lua_openfile (char *fn);
|
||||||
void lua_closefile (void);
|
void lua_closefile (void);
|
||||||
char *lua_openstring (char *s);
|
void lua_openstring (char *s);
|
||||||
void lua_closestring (void);
|
void lua_closestring (void);
|
||||||
void lua_pushfunction (char *file, Word function);
|
|
||||||
void lua_popfunction (void);
|
|
||||||
void luaI_reportbug (char *s, int err);
|
|
||||||
|
|
||||||
void lua_internaldofile (void);
|
void lua_internaldofile (void);
|
||||||
void lua_internaldostring (void);
|
void lua_internaldostring (void);
|
||||||
void lua_print (void);
|
void lua_print (void);
|
||||||
void luaI_type (void);
|
void luaI_type (void);
|
||||||
void lua_obj2number (void);
|
void lua_obj2number (void);
|
||||||
void luaI_getstack (void);
|
|
||||||
void luaI_error (void);
|
void luaI_error (void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
35
lua.stx
35
lua.stx
@@ -1,6 +1,6 @@
|
|||||||
%{
|
%{
|
||||||
|
|
||||||
char *rcs_luastx = "$Id: lua.stx,v 3.19 1995/06/08 19:47:28 roberto Exp $";
|
char *rcs_luastx = "$Id: lua.stx,v 3.20 1995/10/04 14:20:26 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -244,17 +244,10 @@ static void init_function (TreeNode *func)
|
|||||||
}
|
}
|
||||||
pc=0; basepc=funcCode; maxcurr=maxcode;
|
pc=0; basepc=funcCode; maxcurr=maxcode;
|
||||||
nlocalvar=0;
|
nlocalvar=0;
|
||||||
if (lua_debug)
|
|
||||||
{
|
|
||||||
code_byte(SETFUNCTION);
|
|
||||||
code_code((TFunc *)luaI_strdup(lua_file[lua_nfile-1]));
|
|
||||||
code_word(luaI_findconstant(func));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void codereturn (void)
|
static void codereturn (void)
|
||||||
{
|
{
|
||||||
if (lua_debug) code_byte(RESET);
|
|
||||||
if (nlocalvar == 0)
|
if (nlocalvar == 0)
|
||||||
code_byte(RETCODE0);
|
code_byte(RETCODE0);
|
||||||
else
|
else
|
||||||
@@ -345,8 +338,8 @@ static void codeIf (Long thenAdd, Long elseAdd)
|
|||||||
static void yyerror (char *s)
|
static void yyerror (char *s)
|
||||||
{
|
{
|
||||||
static char msg[256];
|
static char msg[256];
|
||||||
sprintf (msg,"%s near \"%s\" at line %d in file \"%s\"",
|
sprintf (msg,"%s near \"%s\" at line %d in file `%s'",
|
||||||
s, lua_lasttext (), lua_linenumber, lua_filename());
|
s, lua_lasttext (), lua_linenumber, lua_parsedfile);
|
||||||
lua_error (msg);
|
lua_error (msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,6 +428,7 @@ functionlist : /* empty */
|
|||||||
function : FUNCTION NAME
|
function : FUNCTION NAME
|
||||||
{
|
{
|
||||||
init_function($2);
|
init_function($2);
|
||||||
|
$<vInt>$ = lua_linenumber;
|
||||||
}
|
}
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
@@ -442,6 +436,10 @@ function : FUNCTION NAME
|
|||||||
luaI_insertfunction($4); /* may take part in GC */
|
luaI_insertfunction($4); /* may take part in GC */
|
||||||
s_tag(func) = LUA_T_FUNCTION;
|
s_tag(func) = LUA_T_FUNCTION;
|
||||||
lua_table[func].object.value.tf = $4;
|
lua_table[func].object.value.tf = $4;
|
||||||
|
$4->lineDefined = $<vInt>3;
|
||||||
|
$4->name1 = $2->ts.str;
|
||||||
|
$4->name2 = NULL;
|
||||||
|
$4->fileName = lua_parsedfile;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -449,6 +447,7 @@ method : FUNCTION NAME ':' NAME
|
|||||||
{
|
{
|
||||||
init_function($4);
|
init_function($4);
|
||||||
add_localvar(luaI_findsymbolbyname("self"));
|
add_localvar(luaI_findsymbolbyname("self"));
|
||||||
|
$<vInt>$ = lua_linenumber;
|
||||||
}
|
}
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
@@ -462,6 +461,10 @@ method : FUNCTION NAME ':' NAME
|
|||||||
code_code($6);
|
code_code($6);
|
||||||
code_byte(STOREINDEXED0);
|
code_byte(STOREINDEXED0);
|
||||||
maincode=pc; *initcode=basepc; maxmain=maxcurr;
|
maincode=pc; *initcode=basepc; maxmain=maxcurr;
|
||||||
|
$6->lineDefined = $<vInt>5;
|
||||||
|
$6->name1 = $4->ts.str;
|
||||||
|
$6->name2 = $2->ts.str;
|
||||||
|
$6->fileName = lua_parsedfile;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -966,17 +969,6 @@ static void PrintCode (Byte *code, Byte *end)
|
|||||||
printf ("%d RETCODE %d\n", p-code, *(++p));
|
printf ("%d RETCODE %d\n", p-code, *(++p));
|
||||||
p++;
|
p++;
|
||||||
break;
|
break;
|
||||||
case SETFUNCTION:
|
|
||||||
{
|
|
||||||
CodeCode c1;
|
|
||||||
CodeWord c2;
|
|
||||||
int n = p-code;
|
|
||||||
p++;
|
|
||||||
get_code(c1,p);
|
|
||||||
get_word(c2,p);
|
|
||||||
printf ("%d SETFUNCTION %s %d\n", n, (char *)c1.tf, c2.w);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SETLINE:
|
case SETLINE:
|
||||||
{
|
{
|
||||||
CodeWord c;
|
CodeWord c;
|
||||||
@@ -987,7 +979,6 @@ static void PrintCode (Byte *code, Byte *end)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RESET: printf ("%d RESET\n", (p++)-code); break;
|
|
||||||
default: printf ("%d Cannot happen: code %d\n", (p++)-code, *(p-1)); break;
|
default: printf ("%d Cannot happen: code %d\n", (p++)-code, *(p-1)); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
59
opcode.c
59
opcode.c
@@ -3,7 +3,7 @@
|
|||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_opcode="$Id: opcode.c,v 3.42 1995/10/09 18:45:59 roberto Exp roberto $";
|
char *rcs_opcode="$Id: opcode.c,v 3.43 1995/10/13 15:16:25 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -248,9 +248,15 @@ static void do_call (StkId base, int nResults)
|
|||||||
StkId firstResult;
|
StkId firstResult;
|
||||||
Object *func = stack+base-1;
|
Object *func = stack+base-1;
|
||||||
if (tag(func) == LUA_T_CFUNCTION)
|
if (tag(func) == LUA_T_CFUNCTION)
|
||||||
|
{
|
||||||
|
tag(func) = LUA_T_CMARK;
|
||||||
firstResult = callC(fvalue(func), base);
|
firstResult = callC(fvalue(func), base);
|
||||||
|
}
|
||||||
else if (tag(func) == LUA_T_FUNCTION)
|
else if (tag(func) == LUA_T_FUNCTION)
|
||||||
|
{
|
||||||
|
tag(func) = LUA_T_MARK;
|
||||||
firstResult = lua_execute(func->value.tf->code, base);
|
firstResult = lua_execute(func->value.tf->code, base);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{ /* func is not a function */
|
{ /* func is not a function */
|
||||||
call_funcFB(base, nResults);
|
call_funcFB(base, nResults);
|
||||||
@@ -313,21 +319,21 @@ static void storesubscript (void)
|
|||||||
/*
|
/*
|
||||||
** Traverse all objects on stack
|
** Traverse all objects on stack
|
||||||
*/
|
*/
|
||||||
void lua_travstack (void (*fn)(Object *))
|
void lua_travstack (int (*fn)(Object *))
|
||||||
{
|
{
|
||||||
Object *o;
|
Object *o;
|
||||||
for (o = top-1; o >= stack; o--)
|
for (o = top-1; o >= stack; o--)
|
||||||
fn (o);
|
fn (o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Error messages
|
** Error messages and debug functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void lua_message (char *s)
|
static void lua_message (char *s)
|
||||||
{
|
{
|
||||||
luaI_reportbug(s, 1);
|
lua_pushstring(s);
|
||||||
callFB(FB_ERROR);
|
callFB(FB_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,6 +353,25 @@ void lua_error (char *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
lua_Object luaD_stackedfunction (int level)
|
||||||
|
{
|
||||||
|
Object *p = top;
|
||||||
|
while (--p >= stack)
|
||||||
|
if (p->tag == LUA_T_MARK || p->tag == LUA_T_CMARK)
|
||||||
|
if (level-- == 0)
|
||||||
|
return Ref(p);
|
||||||
|
return LUA_NOOBJECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void luaD_funcInfo (lua_Object func, char **filename, char **funcname,
|
||||||
|
char **objname, int *linedefined)
|
||||||
|
{
|
||||||
|
return luaI_funcInfo(Address(func), filename, funcname, objname, linedefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Execute a protected call. Assumes that function is at CBase and
|
** Execute a protected call. Assumes that function is at CBase and
|
||||||
** parameters are on top of it. Leave nResults on the stack.
|
** parameters are on top of it. Leave nResults on the stack.
|
||||||
@@ -386,6 +411,9 @@ static int do_protectedmain (void)
|
|||||||
adjustC(1); /* one slot for the pseudo-function */
|
adjustC(1); /* one slot for the pseudo-function */
|
||||||
stack[CBase].tag = LUA_T_FUNCTION;
|
stack[CBase].tag = LUA_T_FUNCTION;
|
||||||
stack[CBase].value.tf = &tf;
|
stack[CBase].value.tf = &tf;
|
||||||
|
tf.lineDefined = 0;
|
||||||
|
tf.name1 = tf.name2 = NULL;
|
||||||
|
tf.fileName = lua_parsedfile;
|
||||||
tf.code = NULL;
|
tf.code = NULL;
|
||||||
if (setjmp(myErrorJmp) == 0)
|
if (setjmp(myErrorJmp) == 0)
|
||||||
{
|
{
|
||||||
@@ -454,12 +482,7 @@ int lua_dofile (char *filename)
|
|||||||
int lua_dostring (char *string)
|
int lua_dostring (char *string)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
char *message = lua_openstring(string);
|
lua_openstring(string);
|
||||||
if (message)
|
|
||||||
{
|
|
||||||
lua_message(message);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
status = do_protectedmain();
|
status = do_protectedmain();
|
||||||
lua_closestring();
|
lua_closestring();
|
||||||
return status;
|
return status;
|
||||||
@@ -1138,16 +1161,6 @@ static StkId lua_execute (Byte *pc, StkId base)
|
|||||||
case RETCODE:
|
case RETCODE:
|
||||||
return base+*pc;
|
return base+*pc;
|
||||||
|
|
||||||
case SETFUNCTION:
|
|
||||||
{
|
|
||||||
CodeCode file;
|
|
||||||
CodeWord func;
|
|
||||||
get_code(file,pc);
|
|
||||||
get_word(func,pc);
|
|
||||||
lua_pushfunction ((char *)file.tf, func.w);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SETLINE:
|
case SETLINE:
|
||||||
{
|
{
|
||||||
CodeWord code;
|
CodeWord code;
|
||||||
@@ -1156,10 +1169,6 @@ static StkId lua_execute (Byte *pc, StkId base)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RESET:
|
|
||||||
lua_popfunction ();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
lua_error ("internal error - opcode doesn't match");
|
lua_error ("internal error - opcode doesn't match");
|
||||||
}
|
}
|
||||||
|
|||||||
6
opcode.h
6
opcode.h
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
** TeCGraf - PUC-Rio
|
** TeCGraf - PUC-Rio
|
||||||
** $Id: opcode.h,v 3.11 1995/04/11 17:56:30 celes Exp $
|
** $Id: opcode.h,v 3.12 1995/10/04 17:13:02 roberto Exp roberto $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef opcode_h
|
#ifndef opcode_h
|
||||||
@@ -68,9 +68,7 @@ typedef enum
|
|||||||
CALLFUNC,
|
CALLFUNC,
|
||||||
RETCODE0,
|
RETCODE0,
|
||||||
RETCODE,
|
RETCODE,
|
||||||
SETFUNCTION,
|
|
||||||
SETLINE,
|
SETLINE,
|
||||||
RESET
|
|
||||||
} OpCode;
|
} OpCode;
|
||||||
|
|
||||||
#define MULT_RET 255
|
#define MULT_RET 255
|
||||||
@@ -149,7 +147,7 @@ void lua_setinput (Input fn); /* from "lex.c" module */
|
|||||||
char *lua_lasttext (void); /* from "lex.c" module */
|
char *lua_lasttext (void); /* from "lex.c" module */
|
||||||
int yylex (void); /* from "lex.c" module */
|
int yylex (void); /* from "lex.c" module */
|
||||||
void lua_parse (TFunc *tf); /* from "lua.stx" module */
|
void lua_parse (TFunc *tf); /* from "lua.stx" module */
|
||||||
void lua_travstack (void (*fn)(Object *));
|
void lua_travstack (int (*fn)(Object *));
|
||||||
Object *luaI_Address (lua_Object o);
|
Object *luaI_Address (lua_Object o);
|
||||||
void luaI_pushobject (Object *o);
|
void luaI_pushobject (Object *o);
|
||||||
void luaI_gcFB (Object *o);
|
void luaI_gcFB (Object *o);
|
||||||
|
|||||||
102
table.c
102
table.c
@@ -3,7 +3,7 @@
|
|||||||
** Module to control static tables
|
** Module to control static tables
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_table="$Id: table.c,v 2.33 1995/10/04 14:20:26 roberto Exp roberto $";
|
char *rcs_table="$Id: table.c,v 2.34 1995/10/13 15:16:25 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -28,11 +28,6 @@ static Word lua_nconstant = 0;
|
|||||||
static Long lua_maxconstant = 0;
|
static Long lua_maxconstant = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define MAXFILE 20
|
|
||||||
char *lua_file[MAXFILE];
|
|
||||||
int lua_nfile;
|
|
||||||
|
|
||||||
#define GARBAGE_BLOCK 1024
|
#define GARBAGE_BLOCK 1024
|
||||||
#define MIN_GARBAGE_BLOCK (GARBAGE_BLOCK/2)
|
#define MIN_GARBAGE_BLOCK (GARBAGE_BLOCK/2)
|
||||||
|
|
||||||
@@ -68,8 +63,6 @@ static void lua_initsymbol (void)
|
|||||||
s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldostring;
|
s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldostring;
|
||||||
n = luaI_findsymbolbyname("setfallback");
|
n = luaI_findsymbolbyname("setfallback");
|
||||||
s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_setfallback;
|
s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_setfallback;
|
||||||
n = luaI_findsymbolbyname("getstack");
|
|
||||||
s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_getstack;
|
|
||||||
n = luaI_findsymbolbyname("error");
|
n = luaI_findsymbolbyname("error");
|
||||||
s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_error;
|
s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_error;
|
||||||
}
|
}
|
||||||
@@ -154,25 +147,29 @@ Word luaI_findconstantbyname (char *name)
|
|||||||
/*
|
/*
|
||||||
** Traverse symbol table objects
|
** Traverse symbol table objects
|
||||||
*/
|
*/
|
||||||
void lua_travsymbol (void (*fn)(Object *))
|
static char *lua_travsymbol (int (*fn)(Object *))
|
||||||
{
|
{
|
||||||
Word i;
|
Word i;
|
||||||
for (i=0; i<lua_ntable; i++)
|
for (i=0; i<lua_ntable; i++)
|
||||||
fn(&s_object(i));
|
if (fn(&s_object(i)))
|
||||||
|
return luaI_nodebysymbol(i)->ts.str;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Mark an object if it is a string or a unmarked array.
|
** Mark an object if it is a string or a unmarked array.
|
||||||
*/
|
*/
|
||||||
void lua_markobject (Object *o)
|
int lua_markobject (Object *o)
|
||||||
{
|
{
|
||||||
if (tag(o) == LUA_T_STRING && !tsvalue(o)->marked)
|
if (tag(o) == LUA_T_STRING && !tsvalue(o)->marked)
|
||||||
tsvalue(o)->marked = 1;
|
tsvalue(o)->marked = 1;
|
||||||
else if (tag(o) == LUA_T_ARRAY)
|
else if (tag(o) == LUA_T_ARRAY)
|
||||||
lua_hashmark (avalue(o));
|
lua_hashmark (avalue(o));
|
||||||
else if (o->tag == LUA_T_FUNCTION && !o->value.tf->marked)
|
else if ((o->tag == LUA_T_FUNCTION || o->tag == LUA_T_MARK)
|
||||||
|
&& !o->value.tf->marked)
|
||||||
o->value.tf->marked = 1;
|
o->value.tf->marked = 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -199,71 +196,40 @@ void lua_pack (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Add a file name at file table, checking overflow. This function also set
|
|
||||||
** the external variable "lua_filename" with the function filename set.
|
|
||||||
** Return 0 on success or error message on error.
|
|
||||||
*/
|
|
||||||
char *lua_addfile (char *fn)
|
|
||||||
{
|
|
||||||
if (lua_nfile >= MAXFILE)
|
|
||||||
return "too many files";
|
|
||||||
if ((lua_file[lua_nfile++] = luaI_strdup (fn)) == NULL)
|
|
||||||
return "not enough memory";
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Delete a file from file stack
|
|
||||||
*/
|
|
||||||
int lua_delfile (void)
|
|
||||||
{
|
|
||||||
luaI_free(lua_file[--lua_nfile]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Return the last file name set.
|
|
||||||
*/
|
|
||||||
char *lua_filename (void)
|
|
||||||
{
|
|
||||||
return lua_file[lua_nfile-1];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Internal function: return next global variable
|
** Internal function: return next global variable
|
||||||
*/
|
*/
|
||||||
static void lua_nextvar (void)
|
static void lua_nextvar (void)
|
||||||
{
|
{
|
||||||
char *varname;
|
Word next;
|
||||||
TreeNode *next;
|
|
||||||
lua_Object o = lua_getparam(1);
|
lua_Object o = lua_getparam(1);
|
||||||
if (o == LUA_NOOBJECT)
|
if (o == LUA_NOOBJECT)
|
||||||
lua_error("too few arguments to function `nextvar'");
|
lua_error("too few arguments to function `nextvar'");
|
||||||
if (lua_getparam(2) != LUA_NOOBJECT)
|
if (lua_getparam(2) != LUA_NOOBJECT)
|
||||||
lua_error("too many arguments to function `nextvar'");
|
lua_error("too many arguments to function `nextvar'");
|
||||||
if (lua_isnil(o))
|
if (lua_isnil(o))
|
||||||
varname = NULL;
|
next = 0;
|
||||||
else if (!lua_isstring(o))
|
else if (!lua_isstring(o))
|
||||||
{
|
{
|
||||||
lua_error("incorrect argument to function `nextvar'");
|
lua_error("incorrect argument to function `nextvar'");
|
||||||
return; /* to avoid warnings */
|
return; /* to avoid warnings */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
varname = lua_getstring(o);
|
next = luaI_findsymbolbyname(lua_getstring(o)) + 1;
|
||||||
next = lua_varnext(varname);
|
while (next < lua_ntable && s_tag(next) == LUA_T_NIL) next++;
|
||||||
if (next == NULL)
|
if (next >= lua_ntable)
|
||||||
{
|
{
|
||||||
lua_pushnil();
|
lua_pushnil();
|
||||||
lua_pushnil();
|
lua_pushnil();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
TreeNode *t = luaI_nodebysymbol(next);
|
||||||
Object name;
|
Object name;
|
||||||
tag(&name) = LUA_T_STRING;
|
tag(&name) = LUA_T_STRING;
|
||||||
tsvalue(&name) = &(next->ts);
|
tsvalue(&name) = &(t->ts);
|
||||||
luaI_pushobject(&name);
|
luaI_pushobject(&name);
|
||||||
luaI_pushobject(&s_object(next->varindex));
|
luaI_pushobject(&s_object(next));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,3 +252,37 @@ static void getglobal (void)
|
|||||||
lua_error("incorrect argument to function `getglobal'");
|
lua_error("incorrect argument to function `getglobal'");
|
||||||
lua_pushobject(lua_getglobal(lua_getstring(name)));
|
lua_pushobject(lua_getglobal(lua_getstring(name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static lua_CFunction cfunc = NULL;
|
||||||
|
static int checkfunc (Object *o)
|
||||||
|
{
|
||||||
|
return ((o->tag == LUA_T_CMARK || o->tag == LUA_T_CFUNCTION) &&
|
||||||
|
o->value.f == cfunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void luaI_funcInfo (struct Object *func, char **filename, char **funcname,
|
||||||
|
char **objname, int *linedefined)
|
||||||
|
{
|
||||||
|
if (func->tag == LUA_T_MARK || func->tag == LUA_T_FUNCTION)
|
||||||
|
{
|
||||||
|
TFunc *f = func->value.tf;
|
||||||
|
*filename = f->fileName;
|
||||||
|
*funcname = f->name1;
|
||||||
|
*objname = f->name2;
|
||||||
|
*linedefined = f->lineDefined;
|
||||||
|
}
|
||||||
|
else if (func->tag == LUA_T_CMARK || func->tag == LUA_T_CFUNCTION)
|
||||||
|
{
|
||||||
|
/* temporario: */
|
||||||
|
cfunc = func->value.f;
|
||||||
|
*filename = "(?)";
|
||||||
|
*objname = 0;
|
||||||
|
*linedefined = 0;
|
||||||
|
*funcname = lua_travsymbol(checkfunc);
|
||||||
|
if (*funcname == NULL)
|
||||||
|
*funcname = luaI_travfallbacks(checkfunc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
11
table.h
11
table.h
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** Module to control static tables
|
** Module to control static tables
|
||||||
** TeCGraf - PUC-Rio
|
** TeCGraf - PUC-Rio
|
||||||
** $Id: table.h,v 2.10 1994/12/20 21:20:36 roberto Exp roberto $
|
** $Id: table.h,v 2.11 1995/10/13 15:16:25 roberto Exp roberto $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef table_h
|
#ifndef table_h
|
||||||
@@ -22,11 +22,10 @@ Word luaI_findsymbolbyname (char *name);
|
|||||||
Word luaI_findsymbol (TreeNode *t);
|
Word luaI_findsymbol (TreeNode *t);
|
||||||
Word luaI_findconstant (TreeNode *t);
|
Word luaI_findconstant (TreeNode *t);
|
||||||
Word luaI_findconstantbyname (char *name);
|
Word luaI_findconstantbyname (char *name);
|
||||||
void lua_travsymbol (void (*fn)(Object *));
|
int lua_markobject (Object *o);
|
||||||
void lua_markobject (Object *o);
|
|
||||||
void lua_pack (void);
|
void lua_pack (void);
|
||||||
char *lua_addfile (char *fn);
|
|
||||||
int lua_delfile (void);
|
void luaI_funcInfo (Object *func, char **filename, char **funcname,
|
||||||
char *lua_filename (void);
|
char **objname, int *linedefined);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user