better instrumentation for internal debugging

This commit is contained in:
Roberto Ierusalimschy 1999-02-24 14:55:51 -03:00
parent 082aded149
commit 9d7bae0b6a
4 changed files with 29 additions and 8 deletions

19
lmem.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lmem.c,v 1.8 1999/01/22 17:28:00 roberto Exp roberto $
** $Id: lmem.c,v 1.9 1999/01/22 18:08:57 roberto Exp roberto $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@ -24,6 +24,8 @@
#ifndef DEBUG
int luaM_growaux (void **block, unsigned long nelems, int size,
char *errormsg, unsigned long limit) {
if (nelems >= limit)
@ -36,9 +38,6 @@ int luaM_growaux (void **block, unsigned long nelems, int size,
}
#ifndef DEBUG
/*
** generic allocation routine.
*/
@ -64,6 +63,18 @@ void *luaM_realloc (void *block, unsigned long size) {
#include <string.h>
int luaM_growaux (void **block, unsigned long nelems, int size,
char *errormsg, unsigned long limit) {
if (nelems >= limit)
lua_error(errormsg);
nelems = nelems+1;
if (nelems > limit)
nelems = limit;
*block = luaM_realloc(*block, nelems*size);
return (int)nelems;
}
#define HEADER (sizeof(double))
#define MARK 55

View File

@ -1,5 +1,5 @@
/*
** $Id: lopcodes.h,v 1.25 1999/02/09 18:01:55 roberto Exp roberto $
** $Id: lopcodes.h,v 1.26 1999/02/23 13:38:38 roberto Exp roberto $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -107,7 +107,9 @@ SETLINEW,/* w - - LINE=w */
SETLINE,/* b - - LINE=b */
LONGARGW,/* w (add w*(1<<16) to arg of next instruction) */
LONGARG /* b (add b*(1<<16) to arg of next instruction) */
LONGARG,/* b (add b*(1<<16) to arg of next instruction) */
CHECKSTACK /* b (assert #temporaries == b; only for internal debuging!) */
} OpCode;

View File

@ -1,5 +1,5 @@
/*
** $Id: lparser.c,v 1.20 1999/02/09 18:01:55 roberto Exp roberto $
** $Id: lparser.c,v 1.21 1999/02/24 15:37:19 roberto Exp roberto $
** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h
*/
@ -403,6 +403,10 @@ static void close_exp (LexState *ls, int pc, int nresults) {
deltastack(ls, nresults); /* push results */
deltastack(ls, -(code[pc]+1)); /* pop params (at code[pc]) and function */
}
#ifdef DEBUG
if (nresults != MULT_RET)
code_oparg(ls, CHECKSTACK, ls->fs->stacksize, 0);
#endif
}

6
lvm.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 1.49 1999/02/09 18:01:55 roberto Exp roberto $
** $Id: lvm.c,v 1.50 1999/02/23 13:38:38 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -643,6 +643,10 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) {
aux = highbyte(highbyte(aux));
goto switchentry; /* do not reset "aux" */
case CHECKSTACK: aux = *pc++;
LUA_ASSERT((S->top-S->stack)-base == aux, "wrong stack size");
break;
}
}
}