aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-10 15:36:54 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-10 15:36:54 -0200
commit8a0521fa529ce5091877683bc6f235ff8de7185b (patch)
tree309518c1d073c214e130d7634c2b5a24d7cf7ff6
parent9deac27704eee47f858f6b41a386c3198bc49587 (diff)
downloadlua-8a0521fa529ce5091877683bc6f235ff8de7185b.tar.gz
lua-8a0521fa529ce5091877683bc6f235ff8de7185b.tar.bz2
lua-8a0521fa529ce5091877683bc6f235ff8de7185b.zip
fallback for garbage collection
-rw-r--r--fallback.c42
-rw-r--r--fallback.h9
-rw-r--r--hash.c20
-rw-r--r--opcode.c9
-rw-r--r--opcode.h3
5 files changed, 58 insertions, 25 deletions
diff --git a/fallback.c b/fallback.c
index eee16c28..b9584032 100644
--- a/fallback.c
+++ b/fallback.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_fallback="$Id: fallback.c,v 1.3 1994/11/09 18:12:42 roberto Exp roberto $"; 6char *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
17static void errorFB (void);
18static void indexFB (void);
19static void gettableFB (void);
20static void arithFB (void);
21static void concatFB (void);
22static void orderFB (void);
23static 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*/
20struct FB luaI_fallBacks[] = { 29struct 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
57void luaI_errorFB (void) 67static 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
67void luaI_indexFB (void) 77static void indexFB (void)
68{ 78{
69 lua_pushnil(); 79 lua_pushnil();
70} 80}
71 81
72 82
73void luaI_gettableFB (void) 83static 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
79void luaI_arithFB (void) 89static 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
84void luaI_concatFB (void) 94static 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
90void luaI_orderFB (void) 100static void orderFB (void)
91{ 101{
92 lua_reportbug("unexpected type at comparison"); 102 lua_reportbug("unexpected type at comparison");
93} 103}
94 104
105static void GDFB (void) { }
106
95 107
96/* 108/*
97** Lock routines 109** Lock routines
diff --git a/fallback.h b/fallback.h
index 694ca538..bde3c5ce 100644
--- a/fallback.h
+++ b/fallback.h
@@ -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
24void luaI_setfallback (void); 25void luaI_setfallback (void);
25void luaI_errorFB (void);
26void luaI_indexFB (void);
27void luaI_gettableFB (void);
28void luaI_arithFB (void);
29void luaI_concatFB (void);
30void luaI_orderFB (void);
31Object *luaI_getlocked (int ref); 26Object *luaI_getlocked (int ref);
32void luaI_travlock (void (*fn)(Object *)); 27void luaI_travlock (void (*fn)(Object *));
33 28
diff --git a/hash.c b/hash.c
index dd7db8f5..09ef8bcb 100644
--- a/hash.c
+++ b/hash.c
@@ -3,7 +3,7 @@
3** hash manager for lua 3** hash manager for lua
4*/ 4*/
5 5
6char *rcs_hash="$Id: hash.c,v 2.13 1994/11/07 15:19:51 roberto Exp roberto $"; 6char *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
174static 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)
177void lua_hashcollector (void) 194void 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;
diff --git a/opcode.c b/opcode.c
index dec7fa3e..d967c2cc 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 3.7 1994/11/09 18:13:29 roberto Exp roberto $"; 6char *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
636void 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
636static void call_arith (char *op) 643static void call_arith (char *op)
637{ 644{
638 lua_pushstring(op); 645 lua_pushstring(op);
diff --git a/opcode.h b/opcode.h
index f2a482b6..e26fcce1 100644
--- a/opcode.h
+++ b/opcode.h
@@ -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 */
162void lua_travstack (void (*fn)(Object *)); 162void lua_travstack (void (*fn)(Object *));
163Object *luaI_Address (lua_Object o); 163Object *luaI_Address (lua_Object o);
164void luaI_pushobject (Object *o); 164void luaI_pushobject (Object *o);
165void luaI_gcFB (Object *o);
165 166
166#endif 167#endif