aboutsummaryrefslogtreecommitdiff
path: root/opcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1995-10-04 14:13:02 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1995-10-04 14:13:02 -0300
commit68f337dfa617732646a4a974eb33b25daf45a1e2 (patch)
tree81e72eaf0ada8a2246c6cf1af2d96ddaef41d117 /opcode.c
parentf132ac03bcaf0163f1f86b5114c93a753e17f28b (diff)
downloadlua-68f337dfa617732646a4a974eb33b25daf45a1e2.tar.gz
lua-68f337dfa617732646a4a974eb33b25daf45a1e2.tar.bz2
lua-68f337dfa617732646a4a974eb33b25daf45a1e2.zip
Garbage collection of functions + header structure for functions
Diffstat (limited to 'opcode.c')
-rw-r--r--opcode.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/opcode.c b/opcode.c
index d68db2ad..78fabf25 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.38 1995/05/16 17:23:58 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 3.38 1995/05/16 17:23:58 roberto Exp $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdlib.h> 9#include <stdlib.h>
@@ -259,7 +259,7 @@ static void do_call (Object *func, StkId base, int nResults, StkId whereRes)
259 if (tag(func) == LUA_T_CFUNCTION) 259 if (tag(func) == LUA_T_CFUNCTION)
260 firstResult = callC(fvalue(func), base); 260 firstResult = callC(fvalue(func), base);
261 else if (tag(func) == LUA_T_FUNCTION) 261 else if (tag(func) == LUA_T_FUNCTION)
262 firstResult = lua_execute(bvalue(func), base); 262 firstResult = lua_execute(func->value.tf->code, base);
263 else 263 else
264 { /* func is not a function */ 264 { /* func is not a function */
265 call_funcFB(func, base, nResults, whereRes); 265 call_funcFB(func, base, nResults, whereRes);
@@ -360,24 +360,26 @@ static int do_protectedrun (Object *function, int nResults)
360 360
361static int do_protectedmain (void) 361static int do_protectedmain (void)
362{ 362{
363 Byte *code = NULL; 363 TFunc tf;
364 int status; 364 int status;
365 StkId oldCBase = CBase; 365 StkId oldCBase = CBase;
366 jmp_buf myErrorJmp; 366 jmp_buf myErrorJmp;
367 jmp_buf *oldErr = errorJmp; 367 jmp_buf *oldErr = errorJmp;
368 errorJmp = &myErrorJmp; 368 errorJmp = &myErrorJmp;
369 tf.code = NULL;
369 if (setjmp(myErrorJmp) == 0) 370 if (setjmp(myErrorJmp) == 0)
370 { 371 {
371 Object f; 372 Object f;
372 lua_parse(&code); 373 f.tag = LUA_T_FUNCTION;
373 tag(&f) = LUA_T_FUNCTION; bvalue(&f) = code; 374 f.value.tf = &tf;
375 lua_parse(&tf);
374 do_call(&f, CBase, 0, CBase); 376 do_call(&f, CBase, 0, CBase);
375 status = 0; 377 status = 0;
376 } 378 }
377 else 379 else
378 status = 1; 380 status = 1;
379 if (code) 381 if (tf.code)
380 luaI_free(code); 382 luaI_free(tf.code);
381 errorJmp = oldErr; 383 errorJmp = oldErr;
382 CBase = oldCBase; 384 CBase = oldCBase;
383 top = stack+CBase; 385 top = stack+CBase;
@@ -793,7 +795,9 @@ static StkId lua_execute (Byte *pc, StkId base)
793 { 795 {
794 CodeCode code; 796 CodeCode code;
795 get_code(code,pc); 797 get_code(code,pc);
796 tag(top) = LUA_T_FUNCTION; bvalue(top) = code.b; 798 luaI_insertfunction(code.tf); /* may take part in GC */
799 top->tag = LUA_T_FUNCTION;
800 top->value.tf = code.tf;
797 incr_top; 801 incr_top;
798 } 802 }
799 break; 803 break;
@@ -1116,7 +1120,7 @@ static StkId lua_execute (Byte *pc, StkId base)
1116 CodeWord func; 1120 CodeWord func;
1117 get_code(file,pc); 1121 get_code(file,pc);
1118 get_word(func,pc); 1122 get_word(func,pc);
1119 lua_pushfunction ((char *)file.b, func.w); 1123 lua_pushfunction ((char *)file.tf, func.w);
1120 } 1124 }
1121 break; 1125 break;
1122 1126