From ff08b0f4069e322ec4c2b02aa5553424227357ba Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 16 Sep 1997 16:25:59 -0300 Subject: Lua Function structures --- func.c | 146 ----------------------------------------------------------------- 1 file changed, 146 deletions(-) delete mode 100644 func.c (limited to 'func.c') diff --git a/func.c b/func.c deleted file mode 100644 index a78122da..00000000 --- a/func.c +++ /dev/null @@ -1,146 +0,0 @@ -#include - -#include "luadebug.h" -#include "table.h" -#include "luamem.h" -#include "func.h" -#include "opcode.h" -#include "inout.h" - - -static TFunc *function_root = NULL; - - -static void luaI_insertfunction (TFunc *f) -{ - lua_pack(); - f->next = function_root; - function_root = f; - f->marked = 0; -} - -/* -** Initialize TFunc struct -*/ -void luaI_initTFunc (TFunc *f) -{ - f->next = NULL; - f->marked = 0; - f->code = NULL; - f->lineDefined = 0; - f->fileName = lua_parsedfile; - f->consts = NULL; - f->nconsts = 0; - f->locvars = NULL; - luaI_insertfunction(f); -} - - - -/* -** Free function -*/ -static void luaI_freefunc (TFunc *f) -{ - luaI_free(f->code); - luaI_free(f->locvars); - luaI_free(f->consts); - luaI_free(f); -} - - -void luaI_funcfree (TFunc *l) -{ - while (l) { - TFunc *next = l->next; - luaI_freefunc(l); - l = next; - } -} - - -void luaI_funcmark (TFunc *f) -{ - f->marked = 1; - if (!f->fileName->marked) - f->fileName->marked = 1; - if (f->consts) { - int i; - for (i=0; inconsts; i++) - lua_markobject(&f->consts[i]); - } -} - - -/* -** Garbage collection function. -*/ -TFunc *luaI_funccollector (long *acum) -{ - TFunc *curr = function_root; - TFunc *prev = NULL; - TFunc *frees = NULL; - long counter = 0; - while (curr) { - TFunc *next = curr->next; - if (!curr->marked) { - if (prev == NULL) - function_root = next; - else - prev->next = next; - curr->next = frees; - frees = curr; - ++counter; - } - else { - curr->marked = 0; - prev = curr; - } - curr = next; - } - *acum += counter; - return frees; -} - - -void lua_funcinfo (lua_Object func, char **filename, int *linedefined) -{ - TObject *f = luaI_Address(func); - if (f->ttype == LUA_T_MARK || f->ttype == LUA_T_FUNCTION) - { - *filename = f->value.tf->fileName->str; - *linedefined = f->value.tf->lineDefined; - } - else if (f->ttype == LUA_T_CMARK || f->ttype == LUA_T_CFUNCTION) - { - *filename = "(C)"; - *linedefined = -1; - } -} - - -/* -** Look for n-esim local variable at line "line" in function "func". -** Returns NULL if not found. -*/ -char *luaI_getlocalname (TFunc *func, int local_number, int line) -{ - int count = 0; - char *varname = NULL; - LocVar *lv = func->locvars; - if (lv == NULL) - return NULL; - for (; lv->line != -1 && lv->line < line; lv++) - { - if (lv->varname) /* register */ - { - if (++count == local_number) - varname = lv->varname->str; - } - else /* unregister */ - if (--count < local_number) - varname = NULL; - } - return varname; -} - -- cgit v1.2.3-55-g6feb