mirror of
https://github.com/lua/lua
synced 2025-04-09 14:32:55 +03:00
removing implementation for better error messages (must rethink it...)
This commit is contained in:
parent
74f1c3d025
commit
52aad0ab59
41
ldebug.c
41
ldebug.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ldebug.c,v 1.6 2000/01/25 13:57:18 roberto Exp roberto $
|
** $Id: ldebug.c,v 1.7 2000/01/28 16:53:00 roberto Exp roberto $
|
||||||
** Debug Interface
|
** Debug Interface
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -85,21 +85,6 @@ int lua_getstack (lua_State *L, int level, lua_Dbgactreg *ar) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char *luaG_getname (lua_State *L, const char **name, StkId top) {
|
|
||||||
StkId f = aux_stackedfunction(L, 0, top);
|
|
||||||
if (f == NULL || !hasdebuginfo(L, f) || ttype(f+2) == LUA_T_NIL)
|
|
||||||
return ""; /* no name available */
|
|
||||||
else {
|
|
||||||
int i = (f+2)->value.i;
|
|
||||||
if (ttype(f) == LUA_T_LCLMARK)
|
|
||||||
f = protovalue(f);
|
|
||||||
LUA_ASSERT(L, ttype(f) == LUA_T_LMARK, "must be a Lua function");
|
|
||||||
*name = tfvalue(f)->kstr[i]->str;
|
|
||||||
return luaO_typename(f+2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int lua_nups (StkId f) {
|
static int lua_nups (StkId f) {
|
||||||
switch (ttype(f)) {
|
switch (ttype(f)) {
|
||||||
case LUA_T_LCLOSURE: case LUA_T_CCLOSURE:
|
case LUA_T_LCLOSURE: case LUA_T_CCLOSURE:
|
||||||
@ -131,10 +116,10 @@ int lua_getlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) {
|
|||||||
if (!fp) return 0; /* `f' is not a Lua function? */
|
if (!fp) return 0; /* `f' is not a Lua function? */
|
||||||
v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f));
|
v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f));
|
||||||
if (!v->name) return 0;
|
if (!v->name) return 0;
|
||||||
/* if `name', there must be a LUA_T_LINE and a NAME */
|
/* if `name', there must be a LUA_T_LINE */
|
||||||
/* therefore, f+3 points to function base */
|
/* therefore, f+2 points to function base */
|
||||||
LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, "");
|
LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, "");
|
||||||
v->value = luaA_putluaObject(L, (f+3)+(v->index-1));
|
v->value = luaA_putluaObject(L, (f+2)+(v->index-1));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +131,7 @@ int lua_setlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) {
|
|||||||
v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f));
|
v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f));
|
||||||
if (!v->name) return 0;
|
if (!v->name) return 0;
|
||||||
LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, "");
|
LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, "");
|
||||||
*((f+3)+(v->index-1)) = *v->value;
|
*((f+2)+(v->index-1)) = *v->value;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,8 +166,6 @@ static int checkfunc (lua_State *L, TObject *o) {
|
|||||||
|
|
||||||
static void lua_getobjname (lua_State *L, StkId f, lua_Dbgactreg *ar) {
|
static void lua_getobjname (lua_State *L, StkId f, lua_Dbgactreg *ar) {
|
||||||
GlobalVar *g;
|
GlobalVar *g;
|
||||||
ar->namewhat = luaG_getname(L, &ar->name, f); /* caller debug information */
|
|
||||||
if (*ar->namewhat) return;
|
|
||||||
/* try to find a name for given function */
|
/* try to find a name for given function */
|
||||||
setnormalized(L->top, f); /* to be used by `checkfunc' */
|
setnormalized(L->top, f); /* to be used by `checkfunc' */
|
||||||
for (g=L->rootglobal; g; g=g->next) {
|
for (g=L->rootglobal; g; g=g->next) {
|
||||||
@ -229,24 +212,16 @@ int lua_getinfo (lua_State *L, const char *what, lua_Dbgactreg *ar) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void call_index_error (lua_State *L, TObject *o, const char *tp,
|
static void call_index_error (lua_State *L, TObject *o, const char *v) {
|
||||||
const char *v) {
|
|
||||||
const char *name;
|
|
||||||
const char *kind = luaG_getname(L, &name, L->top);
|
|
||||||
if (*kind) { /* is there a name? */
|
|
||||||
luaL_verror(L, "%.10s `%.30s' is not a %.10s", kind, name, tp);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
luaL_verror(L, "attempt to %.10s a %.10s value", v, lua_type(L, o));
|
luaL_verror(L, "attempt to %.10s a %.10s value", v, lua_type(L, o));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaG_callerror (lua_State *L, TObject *func) {
|
void luaG_callerror (lua_State *L, TObject *func) {
|
||||||
call_index_error(L, func, "function", "call");
|
call_index_error(L, func, "call");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaG_indexerror (lua_State *L, TObject *t) {
|
void luaG_indexerror (lua_State *L, TObject *t) {
|
||||||
call_index_error(L, t, "table", "index");
|
call_index_error(L, t, "index");
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lobject.h,v 1.44 2000/01/25 13:57:18 roberto Exp roberto $
|
** $Id: lobject.h,v 1.45 2000/01/28 16:53:00 roberto Exp roberto $
|
||||||
** Type definitions for Lua objects
|
** Type definitions for Lua objects
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -81,10 +81,7 @@ typedef enum {
|
|||||||
LUA_T_LMARK = -11, /* mark for Lua prototypes */
|
LUA_T_LMARK = -11, /* mark for Lua prototypes */
|
||||||
LUA_T_CMARK = -12, /* mark for C prototypes */
|
LUA_T_CMARK = -12, /* mark for C prototypes */
|
||||||
|
|
||||||
LUA_T_LINE = -13,
|
LUA_T_LINE = -13
|
||||||
LUA_T_NGLOBAL = -14,
|
|
||||||
LUA_T_NLOCAL = -15,
|
|
||||||
LUA_T_NDOT = -16
|
|
||||||
} lua_Type;
|
} lua_Type;
|
||||||
|
|
||||||
#define NUM_TAGS 7 /* tags for values visible from Lua */
|
#define NUM_TAGS 7 /* tags for values visible from Lua */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lopcodes.h,v 1.37 2000/01/25 13:57:18 roberto Exp roberto $
|
** $Id: lopcodes.h,v 1.38 2000/01/28 16:53:00 roberto Exp roberto $
|
||||||
** Opcodes for Lua virtual machine
|
** Opcodes for Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -104,9 +104,6 @@ CLOSURE,/* b c v_c-v_1 closure(CNST[b], v_c-v_1) */
|
|||||||
SETLINEW,/* w - - LINE=w */
|
SETLINEW,/* w - - LINE=w */
|
||||||
SETLINE,/* b - - LINE=b */
|
SETLINE,/* b - - LINE=b */
|
||||||
|
|
||||||
SETNAMEW,/* w c - - NAME=CNST[w],c */
|
|
||||||
SETNAME,/* b c - - NAME=CNST[b],c */
|
|
||||||
|
|
||||||
LONGARGW,/* w (add w*(1<<16) to arg of next instruction) */
|
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) */
|
||||||
|
|
||||||
|
45
lparser.c
45
lparser.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lparser.c,v 1.56 2000/01/25 18:44:21 roberto Exp roberto $
|
** $Id: lparser.c,v 1.57 2000/01/28 16:53:00 roberto Exp roberto $
|
||||||
** LL(1) Parser and code generator for Lua
|
** LL(1) Parser and code generator for Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -63,8 +63,6 @@ typedef enum {
|
|||||||
typedef struct vardesc {
|
typedef struct vardesc {
|
||||||
varkind k;
|
varkind k;
|
||||||
int info;
|
int info;
|
||||||
varkind prev_k; /* for debug information (NAMEs) */
|
|
||||||
int prev_info;
|
|
||||||
} vardesc;
|
} vardesc;
|
||||||
|
|
||||||
|
|
||||||
@ -386,31 +384,6 @@ static void check_debugline (LexState *ls) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void code_setname (LexState *ls, const vardesc *v) {
|
|
||||||
if (ls->L->debug) {
|
|
||||||
switch (v->prev_k) {
|
|
||||||
case VGLOBAL:
|
|
||||||
code_oparg(ls, SETNAME, v->prev_info, 0);
|
|
||||||
code_byte(ls, -LUA_T_NGLOBAL);
|
|
||||||
break;
|
|
||||||
case VLOCAL: {
|
|
||||||
TaggedString *varname = ls->fs->localvar[v->prev_info];
|
|
||||||
code_oparg(ls, SETNAME, string_constant(ls, ls->fs, varname), 0);
|
|
||||||
code_byte(ls, -LUA_T_NLOCAL);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case VDOT:
|
|
||||||
code_oparg(ls, SETNAME, v->prev_info, 0);
|
|
||||||
code_byte(ls, -LUA_T_NDOT);
|
|
||||||
break;
|
|
||||||
default: /* VINDEXED or VEXP: no debug information */
|
|
||||||
code_oparg(ls, SETNAME, 0, 0);
|
|
||||||
code_byte(ls, -LUA_T_NIL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void adjuststack (LexState *ls, int n) {
|
static void adjuststack (LexState *ls, int n) {
|
||||||
if (n > 0)
|
if (n > 0)
|
||||||
code_oparg(ls, POP, n, -n);
|
code_oparg(ls, POP, n, -n);
|
||||||
@ -485,19 +458,15 @@ static void lua_pushvar (LexState *ls, vardesc *var) {
|
|||||||
assertglobal(ls, var->info); /* make sure that there is a global */
|
assertglobal(ls, var->info); /* make sure that there is a global */
|
||||||
break;
|
break;
|
||||||
case VDOT:
|
case VDOT:
|
||||||
code_setname(ls, var);
|
|
||||||
code_oparg(ls, GETDOTTED, var->info, 0);
|
code_oparg(ls, GETDOTTED, var->info, 0);
|
||||||
break;
|
break;
|
||||||
case VINDEXED:
|
case VINDEXED:
|
||||||
code_setname(ls, var);
|
|
||||||
code_opcode(ls, GETTABLE, -1);
|
code_opcode(ls, GETTABLE, -1);
|
||||||
break;
|
break;
|
||||||
case VEXP:
|
case VEXP:
|
||||||
close_exp(ls, var->info, 1); /* function must return 1 value */
|
close_exp(ls, var->info, 1); /* function must return 1 value */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var->prev_k = var->k; /* save previous var kind and info */
|
|
||||||
var->prev_info = var->info;
|
|
||||||
var->k = VEXP;
|
var->k = VEXP;
|
||||||
var->info = 0; /* now this is a closed expression */
|
var->info = 0; /* now this is a closed expression */
|
||||||
}
|
}
|
||||||
@ -513,7 +482,6 @@ static void storevar (LexState *ls, const vardesc *var) {
|
|||||||
assertglobal(ls, var->info); /* make sure that there is a global */
|
assertglobal(ls, var->info); /* make sure that there is a global */
|
||||||
break;
|
break;
|
||||||
case VINDEXED:
|
case VINDEXED:
|
||||||
code_setname(ls, var);
|
|
||||||
code_opcode(ls, SETTABLEPOP, -3);
|
code_opcode(ls, SETTABLEPOP, -3);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -749,7 +717,7 @@ static void explist (LexState *ls, listdesc *d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int funcparams (LexState *ls, int slf, vardesc *v) {
|
static int funcparams (LexState *ls, int slf) {
|
||||||
FuncState *fs = ls->fs;
|
FuncState *fs = ls->fs;
|
||||||
int slevel = fs->stacksize - slf - 1; /* where is func in the stack */
|
int slevel = fs->stacksize - slf - 1; /* where is func in the stack */
|
||||||
switch (ls->token) {
|
switch (ls->token) {
|
||||||
@ -776,7 +744,6 @@ static int funcparams (LexState *ls, int slf, vardesc *v) {
|
|||||||
luaY_error(ls, "function arguments expected");
|
luaY_error(ls, "function arguments expected");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
code_setname(ls, v);
|
|
||||||
code_byte(ls, CALL);
|
code_byte(ls, CALL);
|
||||||
code_byte(ls, 0); /* save space for nresult */
|
code_byte(ls, 0); /* save space for nresult */
|
||||||
code_byte(ls, (Byte)slevel);
|
code_byte(ls, (Byte)slevel);
|
||||||
@ -808,19 +775,16 @@ static void var_or_func_tail (LexState *ls, vardesc *v) {
|
|||||||
next(ls);
|
next(ls);
|
||||||
name = checkname(ls);
|
name = checkname(ls);
|
||||||
lua_pushvar(ls, v); /* `v' must be on stack */
|
lua_pushvar(ls, v); /* `v' must be on stack */
|
||||||
code_setname(ls, v);
|
|
||||||
code_oparg(ls, PUSHSELF, name, 1);
|
code_oparg(ls, PUSHSELF, name, 1);
|
||||||
v->prev_k = VDOT; /* ':' is syntactic sugar for '.' */
|
|
||||||
v->prev_info = name;
|
|
||||||
v->k = VEXP;
|
v->k = VEXP;
|
||||||
v->info = funcparams(ls, 1, v);
|
v->info = funcparams(ls, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case '(': case STRING: case '{': /* var_or_func_tail -> funcparams */
|
case '(': case STRING: case '{': /* var_or_func_tail -> funcparams */
|
||||||
lua_pushvar(ls, v); /* `v' must be on stack */
|
lua_pushvar(ls, v); /* `v' must be on stack */
|
||||||
v->k = VEXP;
|
v->k = VEXP;
|
||||||
v->info = funcparams(ls, 0, v);
|
v->info = funcparams(ls, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: return; /* should be follow... */
|
default: return; /* should be follow... */
|
||||||
@ -1203,7 +1167,6 @@ static int assignment (LexState *ls, vardesc *v, int nvars) {
|
|||||||
storevar(ls, v);
|
storevar(ls, v);
|
||||||
}
|
}
|
||||||
else { /* indexed var with values in between*/
|
else { /* indexed var with values in between*/
|
||||||
code_setname(ls, v);
|
|
||||||
code_oparg(ls, SETTABLE, left+(nvars-1), -1);
|
code_oparg(ls, SETTABLE, left+(nvars-1), -1);
|
||||||
left += 2; /* table&index are not popped, because they aren't on top */
|
left += 2; /* table&index are not popped, because they aren't on top */
|
||||||
}
|
}
|
||||||
|
27
lvm.c
27
lvm.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lvm.c,v 1.84 2000/01/28 16:53:00 roberto Exp roberto $
|
** $Id: lvm.c,v 1.85 2000/02/08 16:39:42 roberto Exp roberto $
|
||||||
** Lua virtual machine
|
** Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -642,27 +642,18 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
|
|||||||
|
|
||||||
case SETLINEW: aux += highbyte(L, *pc++);
|
case SETLINEW: aux += highbyte(L, *pc++);
|
||||||
case SETLINE: aux += *pc++;
|
case SETLINE: aux += *pc++;
|
||||||
if ((base-2)->ttype != LUA_T_LINE) {
|
if ((base-1)->ttype != LUA_T_LINE) {
|
||||||
/* open space for LINE and NAME values */
|
/* open space for LINE value */
|
||||||
int i = top-base;
|
int i = top-base;
|
||||||
while (i--) base[i+2] = base[i];
|
while (i--) base[i+1] = base[i];
|
||||||
base += 2;
|
base++;
|
||||||
top += 2;
|
top++;
|
||||||
(base-1)->ttype = LUA_T_NIL; /* initial value for NAME */
|
(base-1)->ttype = LUA_T_LINE;
|
||||||
(base-2)->ttype = LUA_T_LINE;
|
|
||||||
}
|
}
|
||||||
(base-2)->value.i = aux;
|
(base-1)->value.i = aux;
|
||||||
if (L->linehook) {
|
if (L->linehook) {
|
||||||
L->top = top;
|
L->top = top;
|
||||||
luaD_lineHook(L, base-3, aux);
|
luaD_lineHook(L, base-2, aux);
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SETNAMEW: aux += highbyte(L, *pc++);
|
|
||||||
case SETNAME: aux += *pc++;
|
|
||||||
if ((base-2)->ttype == LUA_T_LINE) { /* function has debug info? */
|
|
||||||
(base-1)->ttype = (lua_Type)(-(*pc++));
|
|
||||||
(base-1)->value.i = aux;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user