aboutsummaryrefslogtreecommitdiff
path: root/opcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1995-10-25 11:05:51 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1995-10-25 11:05:51 -0200
commit9efc257d9d774501af4538a289729f3e8e5e3d7e (patch)
treec4113f56f9bdcf6e1e66ac11f2cf5483387f3bc8 /opcode.c
parentfa71304e54f304ceceddef3a4b97b38228822e94 (diff)
downloadlua-9efc257d9d774501af4538a289729f3e8e5e3d7e.tar.gz
lua-9efc257d9d774501af4538a289729f3e8e5e3d7e.tar.bz2
lua-9efc257d9d774501af4538a289729f3e8e5e3d7e.zip
new method to keep debug line information: current line is stored on the
Lua stack, just below (new) base, with tag LUA_T_LINE. SETLINE opcodes are generated by lex.
Diffstat (limited to 'opcode.c')
-rw-r--r--opcode.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/opcode.c b/opcode.c
index 9804f82b..768b2595 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 3.45 1995/10/17 14:12:45 roberto Exp $"; 6char *rcs_opcode="$Id: opcode.c,v 3.46 1995/10/17 14:30:05 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdlib.h> 9#include <stdlib.h>
@@ -75,7 +75,7 @@ static void lua_initstack (void)
75 stack = newvector(maxstack, Object); 75 stack = newvector(maxstack, Object);
76 stackLimit = stack+maxstack; 76 stackLimit = stack+maxstack;
77 top = stack; 77 top = stack;
78 *top = initial_stack; 78 *(top++) = initial_stack;
79} 79}
80 80
81 81
@@ -86,19 +86,19 @@ static void lua_initstack (void)
86 86
87static void growstack (void) 87static void growstack (void)
88{ 88{
89 StkId t = top-stack;
90 if (stack == &initial_stack) 89 if (stack == &initial_stack)
91 lua_initstack(); 90 lua_initstack();
92 else 91 else
93 { 92 {
93 StkId t = top-stack;
94 Long maxstack = stackLimit - stack; 94 Long maxstack = stackLimit - stack;
95 maxstack *= 2; 95 maxstack *= 2;
96 stack = growvector(stack, maxstack, Object); 96 stack = growvector(stack, maxstack, Object);
97 stackLimit = stack+maxstack; 97 stackLimit = stack+maxstack;
98 top = stack + t;
98 if (maxstack >= MAX_WORD/2) 99 if (maxstack >= MAX_WORD/2)
99 lua_error("stack size overflow"); 100 lua_error("stack size overflow");
100 } 101 }
101 top = stack + t;
102} 102}
103 103
104 104
@@ -227,16 +227,6 @@ static void callFB (int fb)
227 do_call((top-stack)-nParams, luaI_fallBacks[fb].nResults); 227 do_call((top-stack)-nParams, luaI_fallBacks[fb].nResults);
228} 228}
229 229
230/*
231** Call the fallback for invalid functions (see do_call)
232*/
233static void call_funcFB (StkId base, int nResults)
234{
235 open_stack((top-stack)-(base-1));
236 stack[base-1] = luaI_fallBacks[FB_FUNCTION].function;
237 do_call(base, nResults);
238}
239
240 230
241/* 231/*
242** Call a function (C or Lua). The parameters must be on the stack, 232** Call a function (C or Lua). The parameters must be on the stack,
@@ -248,6 +238,7 @@ static void do_call (StkId base, int nResults)
248{ 238{
249 StkId firstResult; 239 StkId firstResult;
250 Object *func = stack+base-1; 240 Object *func = stack+base-1;
241 int i;
251 if (tag(func) == LUA_T_CFUNCTION) 242 if (tag(func) == LUA_T_CFUNCTION)
252 { 243 {
253 tag(func) = LUA_T_CMARK; 244 tag(func) = LUA_T_CMARK;
@@ -260,7 +251,10 @@ static void do_call (StkId base, int nResults)
260 } 251 }
261 else 252 else
262 { /* func is not a function */ 253 { /* func is not a function */
263 call_funcFB(base, nResults); 254 /* Call the fallback for invalid functions */
255 open_stack((top-stack)-(base-1));
256 stack[base-1] = luaI_fallBacks[FB_FUNCTION].function;
257 do_call(base, nResults);
264 return; 258 return;
265 } 259 }
266 /* adjust the number of results */ 260 /* adjust the number of results */
@@ -268,14 +262,10 @@ static void do_call (StkId base, int nResults)
268 adjust_top(firstResult+nResults); 262 adjust_top(firstResult+nResults);
269 /* move results to base-1 (to erase parameters and function) */ 263 /* move results to base-1 (to erase parameters and function) */
270 base--; 264 base--;
271 if (firstResult != base) 265 nResults = top - (stack+firstResult); /* actual number of results */
272 { 266 for (i=0; i<nResults; i++)
273 int i; 267 *(stack+base+i) = *(stack+firstResult+i);
274 nResults = top - (stack+firstResult); /* actual number of results */ 268 top -= firstResult-base;
275 for (i=0; i<nResults; i++)
276 *(stack+base+i) = *(stack+firstResult+i);
277 top -= firstResult-base;
278 }
279} 269}
280 270
281 271
@@ -366,9 +356,12 @@ lua_Object lua_stackedfunction (int level)
366 356
367 357
368void lua_funcinfo (lua_Object func, char **filename, char **funcname, 358void lua_funcinfo (lua_Object func, char **filename, char **funcname,
369 char **objname, int *linedefined) 359 char **objname, int *line)
370{ 360{
371 return luaI_funcInfo(Address(func), filename, funcname, objname, linedefined); 361 Object *f = Address(func);
362 luaI_funcInfo(f, filename, funcname, objname, line);
363 *line = (f+1 < top && (f+1)->tag == LUA_T_LINE) ?
364 (f+1)->value.i : -1;
372} 365}
373 366
374 367
@@ -587,9 +580,9 @@ lua_Object lua_getparam (int number)
587*/ 580*/
588real lua_getnumber (lua_Object object) 581real lua_getnumber (lua_Object object)
589{ 582{
590 if (object == LUA_NOOBJECT || tag(Address(object)) == LUA_T_NIL) return 0.0; 583 if (object == LUA_NOOBJECT) return 0.0;
591 if (tonumber (Address(object))) return 0.0; 584 if (tonumber (Address(object))) return 0.0;
592 else return (nvalue(Address(object))); 585 else return (nvalue(Address(object)));
593} 586}
594 587
595/* 588/*
@@ -597,7 +590,7 @@ real lua_getnumber (lua_Object object)
597*/ 590*/
598char *lua_getstring (lua_Object object) 591char *lua_getstring (lua_Object object)
599{ 592{
600 if (object == LUA_NOOBJECT || tag(Address(object)) == LUA_T_NIL) return NULL; 593 if (object == LUA_NOOBJECT) return NULL;
601 if (tostring (Address(object))) return NULL; 594 if (tostring (Address(object))) return NULL;
602 else return (svalue(Address(object))); 595 else return (svalue(Address(object)));
603} 596}
@@ -1168,9 +1161,16 @@ static StkId lua_execute (Byte *pc, StkId base)
1168 { 1161 {
1169 CodeWord code; 1162 CodeWord code;
1170 get_word(code,pc); 1163 get_word(code,pc);
1171 lua_debugline = code.w; 1164 if ((stack+base-1)->tag != LUA_T_LINE)
1165 {
1166 /* open space for LINE value */
1167 open_stack((top-stack)-base);
1168 base++;
1169 (stack+base-1)->tag = LUA_T_LINE;
1170 }
1171 (stack+base-1)->value.i = code.w;
1172 break;
1172 } 1173 }
1173 break;
1174 1174
1175 default: 1175 default:
1176 lua_error ("internal error - opcode doesn't match"); 1176 lua_error ("internal error - opcode doesn't match");