diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-02-11 14:52:54 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-02-11 14:52:54 -0200 |
commit | 52aad0ab5937d4df6fe07aedbf9987f2f792698c (patch) | |
tree | 9598361f6d635751fe3eb93c66acd1520f2619af | |
parent | 74f1c3d025c6d8a714454470a953f383a1c6a641 (diff) | |
download | lua-52aad0ab5937d4df6fe07aedbf9987f2f792698c.tar.gz lua-52aad0ab5937d4df6fe07aedbf9987f2f792698c.tar.bz2 lua-52aad0ab5937d4df6fe07aedbf9987f2f792698c.zip |
removing implementation for better error messages (must rethink it...)
-rw-r--r-- | ldebug.c | 43 | ||||
-rw-r--r-- | lobject.h | 7 | ||||
-rw-r--r-- | lopcodes.h | 5 | ||||
-rw-r--r-- | lparser.c | 45 | ||||
-rw-r--r-- | lvm.c | 27 |
5 files changed, 25 insertions, 102 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.6 2000/01/25 13:57:18 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.7 2000/01/28 16:53:00 roberto Exp roberto $ |
3 | ** Debug Interface | 3 | ** Debug Interface |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -85,21 +85,6 @@ int lua_getstack (lua_State *L, int level, lua_Dbgactreg *ar) { | |||
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | static const char *luaG_getname (lua_State *L, const char **name, StkId top) { | ||
89 | StkId f = aux_stackedfunction(L, 0, top); | ||
90 | if (f == NULL || !hasdebuginfo(L, f) || ttype(f+2) == LUA_T_NIL) | ||
91 | return ""; /* no name available */ | ||
92 | else { | ||
93 | int i = (f+2)->value.i; | ||
94 | if (ttype(f) == LUA_T_LCLMARK) | ||
95 | f = protovalue(f); | ||
96 | LUA_ASSERT(L, ttype(f) == LUA_T_LMARK, "must be a Lua function"); | ||
97 | *name = tfvalue(f)->kstr[i]->str; | ||
98 | return luaO_typename(f+2); | ||
99 | } | ||
100 | } | ||
101 | |||
102 | |||
103 | static int lua_nups (StkId f) { | 88 | static int lua_nups (StkId f) { |
104 | switch (ttype(f)) { | 89 | switch (ttype(f)) { |
105 | case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: | 90 | 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) { | |||
131 | if (!fp) return 0; /* `f' is not a Lua function? */ | 116 | if (!fp) return 0; /* `f' is not a Lua function? */ |
132 | v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f)); | 117 | v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f)); |
133 | if (!v->name) return 0; | 118 | if (!v->name) return 0; |
134 | /* if `name', there must be a LUA_T_LINE and a NAME */ | 119 | /* if `name', there must be a LUA_T_LINE */ |
135 | /* therefore, f+3 points to function base */ | 120 | /* therefore, f+2 points to function base */ |
136 | LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, ""); | 121 | LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, ""); |
137 | v->value = luaA_putluaObject(L, (f+3)+(v->index-1)); | 122 | v->value = luaA_putluaObject(L, (f+2)+(v->index-1)); |
138 | return 1; | 123 | return 1; |
139 | } | 124 | } |
140 | 125 | ||
@@ -146,7 +131,7 @@ int lua_setlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) { | |||
146 | v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f)); | 131 | v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f)); |
147 | if (!v->name) return 0; | 132 | if (!v->name) return 0; |
148 | LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, ""); | 133 | LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, ""); |
149 | *((f+3)+(v->index-1)) = *v->value; | 134 | *((f+2)+(v->index-1)) = *v->value; |
150 | return 1; | 135 | return 1; |
151 | } | 136 | } |
152 | 137 | ||
@@ -181,8 +166,6 @@ static int checkfunc (lua_State *L, TObject *o) { | |||
181 | 166 | ||
182 | static void lua_getobjname (lua_State *L, StkId f, lua_Dbgactreg *ar) { | 167 | static void lua_getobjname (lua_State *L, StkId f, lua_Dbgactreg *ar) { |
183 | GlobalVar *g; | 168 | GlobalVar *g; |
184 | ar->namewhat = luaG_getname(L, &ar->name, f); /* caller debug information */ | ||
185 | if (*ar->namewhat) return; | ||
186 | /* try to find a name for given function */ | 169 | /* try to find a name for given function */ |
187 | setnormalized(L->top, f); /* to be used by `checkfunc' */ | 170 | setnormalized(L->top, f); /* to be used by `checkfunc' */ |
188 | for (g=L->rootglobal; g; g=g->next) { | 171 | for (g=L->rootglobal; g; g=g->next) { |
@@ -229,24 +212,16 @@ int lua_getinfo (lua_State *L, const char *what, lua_Dbgactreg *ar) { | |||
229 | 212 | ||
230 | 213 | ||
231 | 214 | ||
232 | static void call_index_error (lua_State *L, TObject *o, const char *tp, | 215 | static void call_index_error (lua_State *L, TObject *o, const char *v) { |
233 | const char *v) { | 216 | luaL_verror(L, "attempt to %.10s a %.10s value", v, lua_type(L, o)); |
234 | const char *name; | ||
235 | const char *kind = luaG_getname(L, &name, L->top); | ||
236 | if (*kind) { /* is there a name? */ | ||
237 | luaL_verror(L, "%.10s `%.30s' is not a %.10s", kind, name, tp); | ||
238 | } | ||
239 | else { | ||
240 | luaL_verror(L, "attempt to %.10s a %.10s value", v, lua_type(L, o)); | ||
241 | } | ||
242 | } | 217 | } |
243 | 218 | ||
244 | 219 | ||
245 | void luaG_callerror (lua_State *L, TObject *func) { | 220 | void luaG_callerror (lua_State *L, TObject *func) { |
246 | call_index_error(L, func, "function", "call"); | 221 | call_index_error(L, func, "call"); |
247 | } | 222 | } |
248 | 223 | ||
249 | 224 | ||
250 | void luaG_indexerror (lua_State *L, TObject *t) { | 225 | void luaG_indexerror (lua_State *L, TObject *t) { |
251 | call_index_error(L, t, "table", "index"); | 226 | call_index_error(L, t, "index"); |
252 | } | 227 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.44 2000/01/25 13:57:18 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.45 2000/01/28 16:53:00 roberto Exp roberto $ |
3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -81,10 +81,7 @@ typedef enum { | |||
81 | LUA_T_LMARK = -11, /* mark for Lua prototypes */ | 81 | LUA_T_LMARK = -11, /* mark for Lua prototypes */ |
82 | LUA_T_CMARK = -12, /* mark for C prototypes */ | 82 | LUA_T_CMARK = -12, /* mark for C prototypes */ |
83 | 83 | ||
84 | LUA_T_LINE = -13, | 84 | LUA_T_LINE = -13 |
85 | LUA_T_NGLOBAL = -14, | ||
86 | LUA_T_NLOCAL = -15, | ||
87 | LUA_T_NDOT = -16 | ||
88 | } lua_Type; | 85 | } lua_Type; |
89 | 86 | ||
90 | #define NUM_TAGS 7 /* tags for values visible from Lua */ | 87 | #define NUM_TAGS 7 /* tags for values visible from Lua */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.37 2000/01/25 13:57:18 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.38 2000/01/28 16:53:00 roberto Exp roberto $ |
3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -104,9 +104,6 @@ CLOSURE,/* b c v_c-v_1 closure(CNST[b], v_c-v_1) */ | |||
104 | SETLINEW,/* w - - LINE=w */ | 104 | SETLINEW,/* w - - LINE=w */ |
105 | SETLINE,/* b - - LINE=b */ | 105 | SETLINE,/* b - - LINE=b */ |
106 | 106 | ||
107 | SETNAMEW,/* w c - - NAME=CNST[w],c */ | ||
108 | SETNAME,/* b c - - NAME=CNST[b],c */ | ||
109 | |||
110 | LONGARGW,/* w (add w*(1<<16) to arg of next instruction) */ | 107 | LONGARGW,/* w (add w*(1<<16) to arg of next instruction) */ |
111 | LONGARG /* b (add b*(1<<16) to arg of next instruction) */ | 108 | LONGARG /* b (add b*(1<<16) to arg of next instruction) */ |
112 | 109 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.56 2000/01/25 18:44:21 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.57 2000/01/28 16:53:00 roberto Exp roberto $ |
3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -63,8 +63,6 @@ typedef enum { | |||
63 | typedef struct vardesc { | 63 | typedef struct vardesc { |
64 | varkind k; | 64 | varkind k; |
65 | int info; | 65 | int info; |
66 | varkind prev_k; /* for debug information (NAMEs) */ | ||
67 | int prev_info; | ||
68 | } vardesc; | 66 | } vardesc; |
69 | 67 | ||
70 | 68 | ||
@@ -386,31 +384,6 @@ static void check_debugline (LexState *ls) { | |||
386 | } | 384 | } |
387 | 385 | ||
388 | 386 | ||
389 | static void code_setname (LexState *ls, const vardesc *v) { | ||
390 | if (ls->L->debug) { | ||
391 | switch (v->prev_k) { | ||
392 | case VGLOBAL: | ||
393 | code_oparg(ls, SETNAME, v->prev_info, 0); | ||
394 | code_byte(ls, -LUA_T_NGLOBAL); | ||
395 | break; | ||
396 | case VLOCAL: { | ||
397 | TaggedString *varname = ls->fs->localvar[v->prev_info]; | ||
398 | code_oparg(ls, SETNAME, string_constant(ls, ls->fs, varname), 0); | ||
399 | code_byte(ls, -LUA_T_NLOCAL); | ||
400 | break; | ||
401 | } | ||
402 | case VDOT: | ||
403 | code_oparg(ls, SETNAME, v->prev_info, 0); | ||
404 | code_byte(ls, -LUA_T_NDOT); | ||
405 | break; | ||
406 | default: /* VINDEXED or VEXP: no debug information */ | ||
407 | code_oparg(ls, SETNAME, 0, 0); | ||
408 | code_byte(ls, -LUA_T_NIL); | ||
409 | } | ||
410 | } | ||
411 | } | ||
412 | |||
413 | |||
414 | static void adjuststack (LexState *ls, int n) { | 387 | static void adjuststack (LexState *ls, int n) { |
415 | if (n > 0) | 388 | if (n > 0) |
416 | code_oparg(ls, POP, n, -n); | 389 | code_oparg(ls, POP, n, -n); |
@@ -485,19 +458,15 @@ static void lua_pushvar (LexState *ls, vardesc *var) { | |||
485 | assertglobal(ls, var->info); /* make sure that there is a global */ | 458 | assertglobal(ls, var->info); /* make sure that there is a global */ |
486 | break; | 459 | break; |
487 | case VDOT: | 460 | case VDOT: |
488 | code_setname(ls, var); | ||
489 | code_oparg(ls, GETDOTTED, var->info, 0); | 461 | code_oparg(ls, GETDOTTED, var->info, 0); |
490 | break; | 462 | break; |
491 | case VINDEXED: | 463 | case VINDEXED: |
492 | code_setname(ls, var); | ||
493 | code_opcode(ls, GETTABLE, -1); | 464 | code_opcode(ls, GETTABLE, -1); |
494 | break; | 465 | break; |
495 | case VEXP: | 466 | case VEXP: |
496 | close_exp(ls, var->info, 1); /* function must return 1 value */ | 467 | close_exp(ls, var->info, 1); /* function must return 1 value */ |
497 | break; | 468 | break; |
498 | } | 469 | } |
499 | var->prev_k = var->k; /* save previous var kind and info */ | ||
500 | var->prev_info = var->info; | ||
501 | var->k = VEXP; | 470 | var->k = VEXP; |
502 | var->info = 0; /* now this is a closed expression */ | 471 | var->info = 0; /* now this is a closed expression */ |
503 | } | 472 | } |
@@ -513,7 +482,6 @@ static void storevar (LexState *ls, const vardesc *var) { | |||
513 | assertglobal(ls, var->info); /* make sure that there is a global */ | 482 | assertglobal(ls, var->info); /* make sure that there is a global */ |
514 | break; | 483 | break; |
515 | case VINDEXED: | 484 | case VINDEXED: |
516 | code_setname(ls, var); | ||
517 | code_opcode(ls, SETTABLEPOP, -3); | 485 | code_opcode(ls, SETTABLEPOP, -3); |
518 | break; | 486 | break; |
519 | default: | 487 | default: |
@@ -749,7 +717,7 @@ static void explist (LexState *ls, listdesc *d) { | |||
749 | } | 717 | } |
750 | 718 | ||
751 | 719 | ||
752 | static int funcparams (LexState *ls, int slf, vardesc *v) { | 720 | static int funcparams (LexState *ls, int slf) { |
753 | FuncState *fs = ls->fs; | 721 | FuncState *fs = ls->fs; |
754 | int slevel = fs->stacksize - slf - 1; /* where is func in the stack */ | 722 | int slevel = fs->stacksize - slf - 1; /* where is func in the stack */ |
755 | switch (ls->token) { | 723 | switch (ls->token) { |
@@ -776,7 +744,6 @@ static int funcparams (LexState *ls, int slf, vardesc *v) { | |||
776 | luaY_error(ls, "function arguments expected"); | 744 | luaY_error(ls, "function arguments expected"); |
777 | break; | 745 | break; |
778 | } | 746 | } |
779 | code_setname(ls, v); | ||
780 | code_byte(ls, CALL); | 747 | code_byte(ls, CALL); |
781 | code_byte(ls, 0); /* save space for nresult */ | 748 | code_byte(ls, 0); /* save space for nresult */ |
782 | code_byte(ls, (Byte)slevel); | 749 | code_byte(ls, (Byte)slevel); |
@@ -808,19 +775,16 @@ static void var_or_func_tail (LexState *ls, vardesc *v) { | |||
808 | next(ls); | 775 | next(ls); |
809 | name = checkname(ls); | 776 | name = checkname(ls); |
810 | lua_pushvar(ls, v); /* `v' must be on stack */ | 777 | lua_pushvar(ls, v); /* `v' must be on stack */ |
811 | code_setname(ls, v); | ||
812 | code_oparg(ls, PUSHSELF, name, 1); | 778 | code_oparg(ls, PUSHSELF, name, 1); |
813 | v->prev_k = VDOT; /* ':' is syntactic sugar for '.' */ | ||
814 | v->prev_info = name; | ||
815 | v->k = VEXP; | 779 | v->k = VEXP; |
816 | v->info = funcparams(ls, 1, v); | 780 | v->info = funcparams(ls, 1); |
817 | break; | 781 | break; |
818 | } | 782 | } |
819 | 783 | ||
820 | case '(': case STRING: case '{': /* var_or_func_tail -> funcparams */ | 784 | case '(': case STRING: case '{': /* var_or_func_tail -> funcparams */ |
821 | lua_pushvar(ls, v); /* `v' must be on stack */ | 785 | lua_pushvar(ls, v); /* `v' must be on stack */ |
822 | v->k = VEXP; | 786 | v->k = VEXP; |
823 | v->info = funcparams(ls, 0, v); | 787 | v->info = funcparams(ls, 0); |
824 | break; | 788 | break; |
825 | 789 | ||
826 | default: return; /* should be follow... */ | 790 | default: return; /* should be follow... */ |
@@ -1203,7 +1167,6 @@ static int assignment (LexState *ls, vardesc *v, int nvars) { | |||
1203 | storevar(ls, v); | 1167 | storevar(ls, v); |
1204 | } | 1168 | } |
1205 | else { /* indexed var with values in between*/ | 1169 | else { /* indexed var with values in between*/ |
1206 | code_setname(ls, v); | ||
1207 | code_oparg(ls, SETTABLE, left+(nvars-1), -1); | 1170 | code_oparg(ls, SETTABLE, left+(nvars-1), -1); |
1208 | left += 2; /* table&index are not popped, because they aren't on top */ | 1171 | left += 2; /* table&index are not popped, because they aren't on top */ |
1209 | } | 1172 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.84 2000/01/28 16:53:00 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.85 2000/02/08 16:39:42 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -642,27 +642,18 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, | |||
642 | 642 | ||
643 | case SETLINEW: aux += highbyte(L, *pc++); | 643 | case SETLINEW: aux += highbyte(L, *pc++); |
644 | case SETLINE: aux += *pc++; | 644 | case SETLINE: aux += *pc++; |
645 | if ((base-2)->ttype != LUA_T_LINE) { | 645 | if ((base-1)->ttype != LUA_T_LINE) { |
646 | /* open space for LINE and NAME values */ | 646 | /* open space for LINE value */ |
647 | int i = top-base; | 647 | int i = top-base; |
648 | while (i--) base[i+2] = base[i]; | 648 | while (i--) base[i+1] = base[i]; |
649 | base += 2; | 649 | base++; |
650 | top += 2; | 650 | top++; |
651 | (base-1)->ttype = LUA_T_NIL; /* initial value for NAME */ | 651 | (base-1)->ttype = LUA_T_LINE; |
652 | (base-2)->ttype = LUA_T_LINE; | ||
653 | } | 652 | } |
654 | (base-2)->value.i = aux; | 653 | (base-1)->value.i = aux; |
655 | if (L->linehook) { | 654 | if (L->linehook) { |
656 | L->top = top; | 655 | L->top = top; |
657 | luaD_lineHook(L, base-3, aux); | 656 | luaD_lineHook(L, base-2, aux); |
658 | } | ||
659 | break; | ||
660 | |||
661 | case SETNAMEW: aux += highbyte(L, *pc++); | ||
662 | case SETNAME: aux += *pc++; | ||
663 | if ((base-2)->ttype == LUA_T_LINE) { /* function has debug info? */ | ||
664 | (base-1)->ttype = (lua_Type)(-(*pc++)); | ||
665 | (base-1)->value.i = aux; | ||
666 | } | 657 | } |
667 | break; | 658 | break; |
668 | 659 | ||