Garbage collection of functions + header structure for functions

This commit is contained in:
Roberto Ierusalimschy
1995-10-04 14:13:02 -03:00
parent f132ac03bc
commit 68f337dfa6
8 changed files with 56 additions and 36 deletions

31
lua.stx
View File

@@ -1,6 +1,6 @@
%{
char *rcs_luastx = "$Id: lua.stx,v 3.18 1995/04/11 17:56:30 celes Exp roberto $";
char *rcs_luastx = "$Id: lua.stx,v 3.19 1995/06/08 19:47:28 roberto Exp $";
#include <stdio.h>
#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 $"
#include "tree.h"
#include "table.h"
#include "lua.h"
#include "func.h"
/* to avoid warnings generated by yacc */
int yyparse (void);
@@ -84,10 +85,10 @@ static void code_float (float n)
code_byte(code.m.c4);
}
static void code_code (Byte *b)
static void code_code (TFunc *tf)
{
CodeCode code;
code.b = b;
code.tf = tf;
code_byte(code.m.c1);
code_byte(code.m.c2);
code_byte(code.m.c3);
@@ -246,7 +247,7 @@ static void init_function (TreeNode *func)
if (lua_debug)
{
code_byte(SETFUNCTION);
code_code((Byte *)luaI_strdup(lua_file[lua_nfile-1]));
code_code((TFunc *)luaI_strdup(lua_file[lua_nfile-1]));
code_word(luaI_findconstant(func));
}
}
@@ -353,14 +354,15 @@ static void yyerror (char *s)
/*
** Parse LUA code.
*/
void lua_parse (Byte **code)
void lua_parse (TFunc *tf)
{
initcode = code;
initcode = &(tf->code);
*initcode = newvector(CODE_BLOCK, Byte);
maincode = 0;
maxmain = CODE_BLOCK;
if (yyparse ()) lua_error("parse error");
(*initcode)[maincode++] = RETCODE0;
tf->size = maincode;
#if LISTING
{ static void PrintCode (Byte *c, Byte *end);
PrintCode(*initcode,*initcode+maincode); }
@@ -378,7 +380,7 @@ void lua_parse (Byte **code)
char *pChar;
Word vWord;
Long vLong;
Byte *pByte;
TFunc *pFunc;
TreeNode *pNode;
}
@@ -401,7 +403,7 @@ void lua_parse (Byte **code)
%type <vInt> ffieldlist, ffieldlist1, semicolonpart
%type <vInt> lfieldlist, lfieldlist1
%type <vLong> var, singlevar
%type <pByte> body
%type <pFunc> body
%left AND OR
%left EQ NE '>' '<' LE GE
@@ -437,8 +439,9 @@ function : FUNCTION NAME
body
{
Word func = luaI_findsymbol($2);
luaI_insertfunction($4); /* may take part in GC */
s_tag(func) = LUA_T_FUNCTION;
s_bvalue(func) = $4;
lua_table[func].object.value.tf = $4;
}
;
@@ -465,8 +468,10 @@ method : FUNCTION NAME ':' NAME
body : '(' parlist ')' block END
{
codereturn();
$$ = newvector(pc, Byte);
memcpy($$, basepc, pc*sizeof(Byte));
$$ = new(TFunc);
$$->size = pc;
$$->code = newvector(pc, Byte);
memcpy($$->code, basepc, pc*sizeof(Byte));
funcCode = basepc; maxcode=maxcurr;
#if LISTING
PrintCode(funcCode,funcCode+pc);
@@ -805,7 +810,7 @@ static void PrintCode (Byte *code, Byte *end)
int n = p-code;
p++;
get_code(c,p);
printf ("%d PUSHFUNCTION %p\n", n, c.b);
printf ("%d PUSHFUNCTION %p\n", n, c.tf);
}
break;
@@ -969,7 +974,7 @@ static void PrintCode (Byte *code, Byte *end)
p++;
get_code(c1,p);
get_word(c2,p);
printf ("%d SETFUNCTION %s %d\n", n, (char *)c1.b, c2.w);
printf ("%d SETFUNCTION %s %d\n", n, (char *)c1.tf, c2.w);
}
break;
case SETLINE: