diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-10 15:36:54 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-10 15:36:54 -0200 |
commit | 8a0521fa529ce5091877683bc6f235ff8de7185b (patch) | |
tree | 309518c1d073c214e130d7634c2b5a24d7cf7ff6 | |
parent | 9deac27704eee47f858f6b41a386c3198bc49587 (diff) | |
download | lua-8a0521fa529ce5091877683bc6f235ff8de7185b.tar.gz lua-8a0521fa529ce5091877683bc6f235ff8de7185b.tar.bz2 lua-8a0521fa529ce5091877683bc6f235ff8de7185b.zip |
fallback for garbage collection
-rw-r--r-- | fallback.c | 42 | ||||
-rw-r--r-- | fallback.h | 9 | ||||
-rw-r--r-- | hash.c | 20 | ||||
-rw-r--r-- | opcode.c | 9 | ||||
-rw-r--r-- | opcode.h | 3 |
5 files changed, 58 insertions, 25 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_fallback="$Id: fallback.c,v 1.3 1994/11/09 18:12:42 roberto Exp roberto $"; | 6 | char *rcs_fallback="$Id: fallback.c,v 1.4 1994/11/10 17:11:52 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -14,18 +14,28 @@ char *rcs_fallback="$Id: fallback.c,v 1.3 1994/11/09 18:12:42 roberto Exp robert | |||
14 | #include "lua.h" | 14 | #include "lua.h" |
15 | 15 | ||
16 | 16 | ||
17 | static void errorFB (void); | ||
18 | static void indexFB (void); | ||
19 | static void gettableFB (void); | ||
20 | static void arithFB (void); | ||
21 | static void concatFB (void); | ||
22 | static void orderFB (void); | ||
23 | static void GDFB (void); | ||
24 | |||
25 | |||
17 | /* | 26 | /* |
18 | ** Warning: This list must be in the same order as the #define's | 27 | ** Warning: This list must be in the same order as the #define's |
19 | */ | 28 | */ |
20 | struct FB luaI_fallBacks[] = { | 29 | struct FB luaI_fallBacks[] = { |
21 | {"error", {LUA_T_CFUNCTION, luaI_errorFB}}, | 30 | {"error", {LUA_T_CFUNCTION, errorFB}}, |
22 | {"index", {LUA_T_CFUNCTION, luaI_indexFB}}, | 31 | {"index", {LUA_T_CFUNCTION, indexFB}}, |
23 | {"gettable", {LUA_T_CFUNCTION, luaI_gettableFB}}, | 32 | {"gettable", {LUA_T_CFUNCTION, gettableFB}}, |
24 | {"arith", {LUA_T_CFUNCTION, luaI_arithFB}}, | 33 | {"arith", {LUA_T_CFUNCTION, arithFB}}, |
25 | {"order", {LUA_T_CFUNCTION, luaI_orderFB}}, | 34 | {"order", {LUA_T_CFUNCTION, orderFB}}, |
26 | {"concat", {LUA_T_CFUNCTION, luaI_concatFB}}, | 35 | {"concat", {LUA_T_CFUNCTION, concatFB}}, |
27 | {"unminus", {LUA_T_CFUNCTION, luaI_arithFB}}, | 36 | {"unminus", {LUA_T_CFUNCTION, arithFB}}, |
28 | {"settable", {LUA_T_CFUNCTION, luaI_gettableFB}} | 37 | {"settable", {LUA_T_CFUNCTION, gettableFB}}, |
38 | {"gc", {LUA_T_CFUNCTION, GDFB}} | ||
29 | }; | 39 | }; |
30 | 40 | ||
31 | #define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB)) | 41 | #define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB)) |
@@ -54,7 +64,7 @@ void luaI_setfallback (void) | |||
54 | } | 64 | } |
55 | 65 | ||
56 | 66 | ||
57 | void luaI_errorFB (void) | 67 | static void errorFB (void) |
58 | { | 68 | { |
59 | lua_Object o = lua_getparam(1); | 69 | lua_Object o = lua_getparam(1); |
60 | if (lua_isstring(o)) | 70 | if (lua_isstring(o)) |
@@ -64,34 +74,36 @@ void luaI_errorFB (void) | |||
64 | } | 74 | } |
65 | 75 | ||
66 | 76 | ||
67 | void luaI_indexFB (void) | 77 | static void indexFB (void) |
68 | { | 78 | { |
69 | lua_pushnil(); | 79 | lua_pushnil(); |
70 | } | 80 | } |
71 | 81 | ||
72 | 82 | ||
73 | void luaI_gettableFB (void) | 83 | static void gettableFB (void) |
74 | { | 84 | { |
75 | lua_reportbug("indexed expression not a table"); | 85 | lua_reportbug("indexed expression not a table"); |
76 | } | 86 | } |
77 | 87 | ||
78 | 88 | ||
79 | void luaI_arithFB (void) | 89 | static void arithFB (void) |
80 | { | 90 | { |
81 | lua_reportbug("unexpected type at conversion to number"); | 91 | lua_reportbug("unexpected type at conversion to number"); |
82 | } | 92 | } |
83 | 93 | ||
84 | void luaI_concatFB (void) | 94 | static void concatFB (void) |
85 | { | 95 | { |
86 | lua_reportbug("unexpected type at conversion to string"); | 96 | lua_reportbug("unexpected type at conversion to string"); |
87 | } | 97 | } |
88 | 98 | ||
89 | 99 | ||
90 | void luaI_orderFB (void) | 100 | static void orderFB (void) |
91 | { | 101 | { |
92 | lua_reportbug("unexpected type at comparison"); | 102 | lua_reportbug("unexpected type at comparison"); |
93 | } | 103 | } |
94 | 104 | ||
105 | static void GDFB (void) { } | ||
106 | |||
95 | 107 | ||
96 | /* | 108 | /* |
97 | ** Lock routines | 109 | ** Lock routines |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: fallback.h,v 1.2 1994/11/08 19:56:39 roberto Exp roberto $ | 2 | ** $Id: fallback.h,v 1.3 1994/11/10 17:11:52 roberto Exp roberto $ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #ifndef fallback_h | 5 | #ifndef fallback_h |
@@ -20,14 +20,9 @@ extern struct FB { | |||
20 | #define FB_CONCAT 5 | 20 | #define FB_CONCAT 5 |
21 | #define FB_UNMINUS 6 | 21 | #define FB_UNMINUS 6 |
22 | #define FB_SETTABLE 7 | 22 | #define FB_SETTABLE 7 |
23 | #define FB_GC 8 | ||
23 | 24 | ||
24 | void luaI_setfallback (void); | 25 | void luaI_setfallback (void); |
25 | void luaI_errorFB (void); | ||
26 | void luaI_indexFB (void); | ||
27 | void luaI_gettableFB (void); | ||
28 | void luaI_arithFB (void); | ||
29 | void luaI_concatFB (void); | ||
30 | void luaI_orderFB (void); | ||
31 | Object *luaI_getlocked (int ref); | 26 | Object *luaI_getlocked (int ref); |
32 | void luaI_travlock (void (*fn)(Object *)); | 27 | void luaI_travlock (void (*fn)(Object *)); |
33 | 28 | ||
@@ -3,7 +3,7 @@ | |||
3 | ** hash manager for lua | 3 | ** hash manager for lua |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_hash="$Id: hash.c,v 2.13 1994/11/07 15:19:51 roberto Exp roberto $"; | 6 | char *rcs_hash="$Id: hash.c,v 2.14 1994/11/07 16:34:44 roberto Exp $"; |
7 | 7 | ||
8 | #include <string.h> | 8 | #include <string.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -169,6 +169,23 @@ void lua_hashmark (Hash *h) | |||
169 | } | 169 | } |
170 | } | 170 | } |
171 | } | 171 | } |
172 | |||
173 | |||
174 | static void call_fallbacks (void) | ||
175 | { | ||
176 | Hash *curr_array; | ||
177 | Object t; | ||
178 | tag(&t) = LUA_T_ARRAY; | ||
179 | for (curr_array = listhead; curr_array; curr_array = curr_array->next) | ||
180 | if (markarray(curr_array) != 1) | ||
181 | { | ||
182 | avalue(&t) = curr_array; | ||
183 | luaI_gcFB(&t); | ||
184 | } | ||
185 | tag(&t) = LUA_T_NIL; | ||
186 | luaI_gcFB(&t); /* end of list */ | ||
187 | } | ||
188 | |||
172 | 189 | ||
173 | /* | 190 | /* |
174 | ** Garbage collection to arrays | 191 | ** Garbage collection to arrays |
@@ -177,6 +194,7 @@ void lua_hashmark (Hash *h) | |||
177 | void lua_hashcollector (void) | 194 | void lua_hashcollector (void) |
178 | { | 195 | { |
179 | Hash *curr_array = listhead, *prev = NULL; | 196 | Hash *curr_array = listhead, *prev = NULL; |
197 | call_fallbacks(); | ||
180 | while (curr_array != NULL) | 198 | while (curr_array != NULL) |
181 | { | 199 | { |
182 | Hash *next = curr_array->next; | 200 | Hash *next = curr_array->next; |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.7 1994/11/09 18:13:29 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.8 1994/11/10 17:11:52 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -633,6 +633,13 @@ int lua_type (lua_Object o) | |||
633 | } | 633 | } |
634 | 634 | ||
635 | 635 | ||
636 | void luaI_gcFB (Object *o) | ||
637 | { | ||
638 | *(top++) = *o; | ||
639 | do_call(&luaI_fallBacks[FB_GC].function, (top-stack)-1, 0, (top-stack)-1); | ||
640 | } | ||
641 | |||
642 | |||
636 | static void call_arith (char *op) | 643 | static void call_arith (char *op) |
637 | { | 644 | { |
638 | lua_pushstring(op); | 645 | lua_pushstring(op); |
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | ** TeCGraf - PUC-Rio | 2 | ** TeCGraf - PUC-Rio |
3 | ** $Id: opcode.h,v 3.6 1994/11/09 18:10:58 roberto Exp roberto $ | 3 | ** $Id: opcode.h,v 3.7 1994/11/10 17:11:52 roberto Exp roberto $ |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #ifndef opcode_h | 6 | #ifndef opcode_h |
@@ -162,5 +162,6 @@ void lua_parse (Byte **code); /* from "lua.stx" module */ | |||
162 | void lua_travstack (void (*fn)(Object *)); | 162 | void lua_travstack (void (*fn)(Object *)); |
163 | Object *luaI_Address (lua_Object o); | 163 | Object *luaI_Address (lua_Object o); |
164 | void luaI_pushobject (Object *o); | 164 | void luaI_pushobject (Object *o); |
165 | void luaI_gcFB (Object *o); | ||
165 | 166 | ||
166 | #endif | 167 | #endif |