aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1995-10-04 11:20:26 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1995-10-04 11:20:26 -0300
commitf132ac03bcaf0163f1f86b5114c93a753e17f28b (patch)
tree72bb57bf43d5f38ce00a81f05cff6db2744bf9fe
parentec785a1d6517a3c247f4e6682deb1c9e2610db0e (diff)
downloadlua-f132ac03bcaf0163f1f86b5114c93a753e17f28b.tar.gz
lua-f132ac03bcaf0163f1f86b5114c93a753e17f28b.tar.bz2
lua-f132ac03bcaf0163f1f86b5114c93a753e17f28b.zip
Module to manipulate function headers.
-rw-r--r--func.c59
-rw-r--r--func.h20
2 files changed, 79 insertions, 0 deletions
diff --git a/func.c b/func.c
new file mode 100644
index 00000000..601513d1
--- /dev/null
+++ b/func.c
@@ -0,0 +1,59 @@
1#include <stdio.h>
2#include "table.h"
3#include "mem.h"
4#include "func.h"
5
6static TFunc *function_root = NULL;
7
8
9/*
10** Insert function in list for GC
11*/
12void luaI_insertfunction (TFunc *f)
13{
14 lua_pack();
15 f->next = function_root;
16 function_root = f;
17 f->marked = 0;
18}
19
20
21/*
22** Free function
23*/
24static void freefunc (TFunc *f)
25{
26 luaI_free (f->code);
27 luaI_free (f);
28}
29
30/*
31** Garbage collection function.
32** This function traverse the function list freeing unindexed functions
33*/
34Long luaI_funccollector (void)
35{
36 TFunc *curr = function_root;
37 TFunc *prev = NULL;
38 Long counter = 0;
39 while (curr)
40 {
41 TFunc *next = curr->next;
42 if (!curr->marked)
43 {
44 if (prev == NULL)
45 function_root = next;
46 else
47 prev->next = next;
48 freefunc (curr);
49 ++counter;
50 }
51 else
52 {
53 curr->marked = 0;
54 prev = curr;
55 }
56 curr = next;
57 }
58 return counter;
59}
diff --git a/func.h b/func.h
new file mode 100644
index 00000000..8d2d124d
--- /dev/null
+++ b/func.h
@@ -0,0 +1,20 @@
1#ifndef func_h
2#define func_h
3
4#include "types.h"
5
6/*
7** Header para funcoes.
8*/
9typedef struct TFunc
10{
11 struct TFunc *next;
12 char marked;
13 int size;
14 Byte *code;
15} TFunc;
16
17Long luaI_funccollector (void);
18void luaI_insertfunction (TFunc *f);
19
20#endif