From f132ac03bcaf0163f1f86b5114c93a753e17f28b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 4 Oct 1995 11:20:26 -0300 Subject: Module to manipulate function headers. --- func.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ func.h | 20 ++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 func.c create mode 100644 func.h diff --git a/func.c b/func.c new file mode 100644 index 00000000..601513d1 --- /dev/null +++ b/func.c @@ -0,0 +1,59 @@ +#include +#include "table.h" +#include "mem.h" +#include "func.h" + +static TFunc *function_root = NULL; + + +/* +** Insert function in list for GC +*/ +void luaI_insertfunction (TFunc *f) +{ + lua_pack(); + f->next = function_root; + function_root = f; + f->marked = 0; +} + + +/* +** Free function +*/ +static void freefunc (TFunc *f) +{ + luaI_free (f->code); + luaI_free (f); +} + +/* +** Garbage collection function. +** This function traverse the function list freeing unindexed functions +*/ +Long luaI_funccollector (void) +{ + TFunc *curr = function_root; + TFunc *prev = NULL; + Long counter = 0; + while (curr) + { + TFunc *next = curr->next; + if (!curr->marked) + { + if (prev == NULL) + function_root = next; + else + prev->next = next; + freefunc (curr); + ++counter; + } + else + { + curr->marked = 0; + prev = curr; + } + curr = next; + } + return counter; +} diff --git a/func.h b/func.h new file mode 100644 index 00000000..8d2d124d --- /dev/null +++ b/func.h @@ -0,0 +1,20 @@ +#ifndef func_h +#define func_h + +#include "types.h" + +/* +** Header para funcoes. +*/ +typedef struct TFunc +{ + struct TFunc *next; + char marked; + int size; + Byte *code; +} TFunc; + +Long luaI_funccollector (void); +void luaI_insertfunction (TFunc *f); + +#endif -- cgit v1.2.3-55-g6feb