aboutsummaryrefslogtreecommitdiff
path: root/lua.stx
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 /lua.stx
parentf132ac03bcaf0163f1f86b5114c93a753e17f28b (diff)
downloadlua-68f337dfa617732646a4a974eb33b25daf45a1e2.tar.gz
lua-68f337dfa617732646a4a974eb33b25daf45a1e2.tar.bz2
lua-68f337dfa617732646a4a974eb33b25daf45a1e2.zip
Garbage collection of functions + header structure for functions
Diffstat (limited to 'lua.stx')
-rw-r--r--lua.stx31
1 files changed, 18 insertions, 13 deletions
diff --git a/lua.stx b/lua.stx
index f8bdb9d7..9bb5b1f4 100644
--- a/lua.stx
+++ b/lua.stx
@@ -1,6 +1,6 @@
1%{ 1%{
2 2
3char *rcs_luastx = "$Id: lua.stx,v 3.18 1995/04/11 17:56:30 celes Exp roberto $"; 3char *rcs_luastx = "$Id: lua.stx,v 3.19 1995/06/08 19:47:28 roberto Exp $";
4 4
5#include <stdio.h> 5#include <stdio.h>
6#include <stdlib.h> 6#include <stdlib.h>
@@ -13,6 +13,7 @@ char *rcs_luastx = "$Id: lua.stx,v 3.18 1995/04/11 17:56:30 celes Exp roberto $"
13#include "tree.h" 13#include "tree.h"
14#include "table.h" 14#include "table.h"
15#include "lua.h" 15#include "lua.h"
16#include "func.h"
16 17
17/* to avoid warnings generated by yacc */ 18/* to avoid warnings generated by yacc */
18int yyparse (void); 19int yyparse (void);
@@ -84,10 +85,10 @@ static void code_float (float n)
84 code_byte(code.m.c4); 85 code_byte(code.m.c4);
85} 86}
86 87
87static void code_code (Byte *b) 88static void code_code (TFunc *tf)
88{ 89{
89 CodeCode code; 90 CodeCode code;
90 code.b = b; 91 code.tf = tf;
91 code_byte(code.m.c1); 92 code_byte(code.m.c1);
92 code_byte(code.m.c2); 93 code_byte(code.m.c2);
93 code_byte(code.m.c3); 94 code_byte(code.m.c3);
@@ -246,7 +247,7 @@ static void init_function (TreeNode *func)
246 if (lua_debug) 247 if (lua_debug)
247 { 248 {
248 code_byte(SETFUNCTION); 249 code_byte(SETFUNCTION);
249 code_code((Byte *)luaI_strdup(lua_file[lua_nfile-1])); 250 code_code((TFunc *)luaI_strdup(lua_file[lua_nfile-1]));
250 code_word(luaI_findconstant(func)); 251 code_word(luaI_findconstant(func));
251 } 252 }
252} 253}
@@ -353,14 +354,15 @@ static void yyerror (char *s)
353/* 354/*
354** Parse LUA code. 355** Parse LUA code.
355*/ 356*/
356void lua_parse (Byte **code) 357void lua_parse (TFunc *tf)
357{ 358{
358 initcode = code; 359 initcode = &(tf->code);
359 *initcode = newvector(CODE_BLOCK, Byte); 360 *initcode = newvector(CODE_BLOCK, Byte);
360 maincode = 0; 361 maincode = 0;
361 maxmain = CODE_BLOCK; 362 maxmain = CODE_BLOCK;
362 if (yyparse ()) lua_error("parse error"); 363 if (yyparse ()) lua_error("parse error");
363 (*initcode)[maincode++] = RETCODE0; 364 (*initcode)[maincode++] = RETCODE0;
365 tf->size = maincode;
364#if LISTING 366#if LISTING
365{ static void PrintCode (Byte *c, Byte *end); 367{ static void PrintCode (Byte *c, Byte *end);
366 PrintCode(*initcode,*initcode+maincode); } 368 PrintCode(*initcode,*initcode+maincode); }
@@ -378,7 +380,7 @@ void lua_parse (Byte **code)
378 char *pChar; 380 char *pChar;
379 Word vWord; 381 Word vWord;
380 Long vLong; 382 Long vLong;
381 Byte *pByte; 383 TFunc *pFunc;
382 TreeNode *pNode; 384 TreeNode *pNode;
383} 385}
384 386
@@ -401,7 +403,7 @@ void lua_parse (Byte **code)
401%type <vInt> ffieldlist, ffieldlist1, semicolonpart 403%type <vInt> ffieldlist, ffieldlist1, semicolonpart
402%type <vInt> lfieldlist, lfieldlist1 404%type <vInt> lfieldlist, lfieldlist1
403%type <vLong> var, singlevar 405%type <vLong> var, singlevar
404%type <pByte> body 406%type <pFunc> body
405 407
406%left AND OR 408%left AND OR
407%left EQ NE '>' '<' LE GE 409%left EQ NE '>' '<' LE GE
@@ -437,8 +439,9 @@ function : FUNCTION NAME
437 body 439 body
438 { 440 {
439 Word func = luaI_findsymbol($2); 441 Word func = luaI_findsymbol($2);
442 luaI_insertfunction($4); /* may take part in GC */
440 s_tag(func) = LUA_T_FUNCTION; 443 s_tag(func) = LUA_T_FUNCTION;
441 s_bvalue(func) = $4; 444 lua_table[func].object.value.tf = $4;
442 } 445 }
443 ; 446 ;
444 447
@@ -465,8 +468,10 @@ method : FUNCTION NAME ':' NAME
465body : '(' parlist ')' block END 468body : '(' parlist ')' block END
466 { 469 {
467 codereturn(); 470 codereturn();
468 $$ = newvector(pc, Byte); 471 $$ = new(TFunc);
469 memcpy($$, basepc, pc*sizeof(Byte)); 472 $$->size = pc;
473 $$->code = newvector(pc, Byte);
474 memcpy($$->code, basepc, pc*sizeof(Byte));
470 funcCode = basepc; maxcode=maxcurr; 475 funcCode = basepc; maxcode=maxcurr;
471#if LISTING 476#if LISTING
472 PrintCode(funcCode,funcCode+pc); 477 PrintCode(funcCode,funcCode+pc);
@@ -805,7 +810,7 @@ static void PrintCode (Byte *code, Byte *end)
805 int n = p-code; 810 int n = p-code;
806 p++; 811 p++;
807 get_code(c,p); 812 get_code(c,p);
808 printf ("%d PUSHFUNCTION %p\n", n, c.b); 813 printf ("%d PUSHFUNCTION %p\n", n, c.tf);
809 } 814 }
810 break; 815 break;
811 816
@@ -969,7 +974,7 @@ static void PrintCode (Byte *code, Byte *end)
969 p++; 974 p++;
970 get_code(c1,p); 975 get_code(c1,p);
971 get_word(c2,p); 976 get_word(c2,p);
972 printf ("%d SETFUNCTION %s %d\n", n, (char *)c1.b, c2.w); 977 printf ("%d SETFUNCTION %s %d\n", n, (char *)c1.tf, c2.w);
973 } 978 }
974 break; 979 break;
975 case SETLINE: 980 case SETLINE: