aboutsummaryrefslogtreecommitdiff
path: root/func.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-07-30 19:00:50 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-07-30 19:00:50 -0300
commit0892f0e5b75c51f1fee07276a3ba13301b83409e (patch)
tree9f3b9ec92f26c05a85c826ffc5f803fda2f48867 /func.c
parent1d7857bc635c0bfe7c5b1f325d31feb7660e9a5a (diff)
downloadlua-0892f0e5b75c51f1fee07276a3ba13301b83409e.tar.gz
lua-0892f0e5b75c51f1fee07276a3ba13301b83409e.tar.bz2
lua-0892f0e5b75c51f1fee07276a3ba13301b83409e.zip
BIG CHANGE: functions have their own "constant table".
Diffstat (limited to 'func.c')
-rw-r--r--func.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/func.c b/func.c
index 1cf5b1e7..a78122da 100644
--- a/func.c
+++ b/func.c
@@ -11,6 +11,14 @@
11static TFunc *function_root = NULL; 11static TFunc *function_root = NULL;
12 12
13 13
14static void luaI_insertfunction (TFunc *f)
15{
16 lua_pack();
17 f->next = function_root;
18 function_root = f;
19 f->marked = 0;
20}
21
14/* 22/*
15** Initialize TFunc struct 23** Initialize TFunc struct
16*/ 24*/
@@ -21,29 +29,23 @@ void luaI_initTFunc (TFunc *f)
21 f->code = NULL; 29 f->code = NULL;
22 f->lineDefined = 0; 30 f->lineDefined = 0;
23 f->fileName = lua_parsedfile; 31 f->fileName = lua_parsedfile;
32 f->consts = NULL;
33 f->nconsts = 0;
24 f->locvars = NULL; 34 f->locvars = NULL;
35 luaI_insertfunction(f);
25} 36}
26 37
27/*
28** Insert function in list for GC
29*/
30void luaI_insertfunction (TFunc *f)
31{
32 lua_pack();
33 f->next = function_root;
34 function_root = f;
35 f->marked = 0;
36}
37 38
38 39
39/* 40/*
40** Free function 41** Free function
41*/ 42*/
42void luaI_freefunc (TFunc *f) 43static void luaI_freefunc (TFunc *f)
43{ 44{
44 luaI_free (f->code); 45 luaI_free(f->code);
45 luaI_free (f->locvars); 46 luaI_free(f->locvars);
46 luaI_free (f); 47 luaI_free(f->consts);
48 luaI_free(f);
47} 49}
48 50
49 51
@@ -56,6 +58,20 @@ void luaI_funcfree (TFunc *l)
56 } 58 }
57} 59}
58 60
61
62void luaI_funcmark (TFunc *f)
63{
64 f->marked = 1;
65 if (!f->fileName->marked)
66 f->fileName->marked = 1;
67 if (f->consts) {
68 int i;
69 for (i=0; i<f->nconsts; i++)
70 lua_markobject(&f->consts[i]);
71 }
72}
73
74
59/* 75/*
60** Garbage collection function. 76** Garbage collection function.
61*/ 77*/
@@ -92,7 +108,7 @@ void lua_funcinfo (lua_Object func, char **filename, int *linedefined)
92 TObject *f = luaI_Address(func); 108 TObject *f = luaI_Address(func);
93 if (f->ttype == LUA_T_MARK || f->ttype == LUA_T_FUNCTION) 109 if (f->ttype == LUA_T_MARK || f->ttype == LUA_T_FUNCTION)
94 { 110 {
95 *filename = f->value.tf->fileName; 111 *filename = f->value.tf->fileName->str;
96 *linedefined = f->value.tf->lineDefined; 112 *linedefined = f->value.tf->lineDefined;
97 } 113 }
98 else if (f->ttype == LUA_T_CMARK || f->ttype == LUA_T_CFUNCTION) 114 else if (f->ttype == LUA_T_CMARK || f->ttype == LUA_T_CFUNCTION)