diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-10-04 11:20:26 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-10-04 11:20:26 -0300 |
| commit | f132ac03bcaf0163f1f86b5114c93a753e17f28b (patch) | |
| tree | 72bb57bf43d5f38ce00a81f05cff6db2744bf9fe | |
| parent | ec785a1d6517a3c247f4e6682deb1c9e2610db0e (diff) | |
| download | lua-f132ac03bcaf0163f1f86b5114c93a753e17f28b.tar.gz lua-f132ac03bcaf0163f1f86b5114c93a753e17f28b.tar.bz2 lua-f132ac03bcaf0163f1f86b5114c93a753e17f28b.zip | |
Module to manipulate function headers.
| -rw-r--r-- | func.c | 59 | ||||
| -rw-r--r-- | func.h | 20 |
2 files changed, 79 insertions, 0 deletions
| @@ -0,0 +1,59 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include "table.h" | ||
| 3 | #include "mem.h" | ||
| 4 | #include "func.h" | ||
| 5 | |||
| 6 | static TFunc *function_root = NULL; | ||
| 7 | |||
| 8 | |||
| 9 | /* | ||
| 10 | ** Insert function in list for GC | ||
| 11 | */ | ||
| 12 | void 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 | */ | ||
| 24 | static 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 | */ | ||
| 34 | Long 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 | } | ||
| @@ -0,0 +1,20 @@ | |||
| 1 | #ifndef func_h | ||
| 2 | #define func_h | ||
| 3 | |||
| 4 | #include "types.h" | ||
| 5 | |||
| 6 | /* | ||
| 7 | ** Header para funcoes. | ||
| 8 | */ | ||
| 9 | typedef struct TFunc | ||
| 10 | { | ||
| 11 | struct TFunc *next; | ||
| 12 | char marked; | ||
| 13 | int size; | ||
| 14 | Byte *code; | ||
| 15 | } TFunc; | ||
| 16 | |||
| 17 | Long luaI_funccollector (void); | ||
| 18 | void luaI_insertfunction (TFunc *f); | ||
| 19 | |||
| 20 | #endif | ||
