From 8a0521fa529ce5091877683bc6f235ff8de7185b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 10 Nov 1994 15:36:54 -0200 Subject: fallback for garbage collection --- fallback.c | 42 +++++++++++++++++++++++++++--------------- fallback.h | 9 ++------- hash.c | 20 +++++++++++++++++++- opcode.c | 9 ++++++++- opcode.h | 3 ++- 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 @@ ** TecCGraf - PUC-Rio */ -char *rcs_fallback="$Id: fallback.c,v 1.3 1994/11/09 18:12:42 roberto Exp roberto $"; +char *rcs_fallback="$Id: fallback.c,v 1.4 1994/11/10 17:11:52 roberto Exp roberto $"; #include #include @@ -14,18 +14,28 @@ char *rcs_fallback="$Id: fallback.c,v 1.3 1994/11/09 18:12:42 roberto Exp robert #include "lua.h" +static void errorFB (void); +static void indexFB (void); +static void gettableFB (void); +static void arithFB (void); +static void concatFB (void); +static void orderFB (void); +static void GDFB (void); + + /* ** Warning: This list must be in the same order as the #define's */ struct FB luaI_fallBacks[] = { -{"error", {LUA_T_CFUNCTION, luaI_errorFB}}, -{"index", {LUA_T_CFUNCTION, luaI_indexFB}}, -{"gettable", {LUA_T_CFUNCTION, luaI_gettableFB}}, -{"arith", {LUA_T_CFUNCTION, luaI_arithFB}}, -{"order", {LUA_T_CFUNCTION, luaI_orderFB}}, -{"concat", {LUA_T_CFUNCTION, luaI_concatFB}}, -{"unminus", {LUA_T_CFUNCTION, luaI_arithFB}}, -{"settable", {LUA_T_CFUNCTION, luaI_gettableFB}} +{"error", {LUA_T_CFUNCTION, errorFB}}, +{"index", {LUA_T_CFUNCTION, indexFB}}, +{"gettable", {LUA_T_CFUNCTION, gettableFB}}, +{"arith", {LUA_T_CFUNCTION, arithFB}}, +{"order", {LUA_T_CFUNCTION, orderFB}}, +{"concat", {LUA_T_CFUNCTION, concatFB}}, +{"unminus", {LUA_T_CFUNCTION, arithFB}}, +{"settable", {LUA_T_CFUNCTION, gettableFB}}, +{"gc", {LUA_T_CFUNCTION, GDFB}} }; #define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB)) @@ -54,7 +64,7 @@ void luaI_setfallback (void) } -void luaI_errorFB (void) +static void errorFB (void) { lua_Object o = lua_getparam(1); if (lua_isstring(o)) @@ -64,34 +74,36 @@ void luaI_errorFB (void) } -void luaI_indexFB (void) +static void indexFB (void) { lua_pushnil(); } -void luaI_gettableFB (void) +static void gettableFB (void) { lua_reportbug("indexed expression not a table"); } -void luaI_arithFB (void) +static void arithFB (void) { lua_reportbug("unexpected type at conversion to number"); } -void luaI_concatFB (void) +static void concatFB (void) { lua_reportbug("unexpected type at conversion to string"); } -void luaI_orderFB (void) +static void orderFB (void) { lua_reportbug("unexpected type at comparison"); } +static void GDFB (void) { } + /* ** Lock routines diff --git a/fallback.h b/fallback.h index 694ca538..bde3c5ce 100644 --- a/fallback.h +++ b/fallback.h @@ -1,5 +1,5 @@ /* -** $Id: fallback.h,v 1.2 1994/11/08 19:56:39 roberto Exp roberto $ +** $Id: fallback.h,v 1.3 1994/11/10 17:11:52 roberto Exp roberto $ */ #ifndef fallback_h @@ -20,14 +20,9 @@ extern struct FB { #define FB_CONCAT 5 #define FB_UNMINUS 6 #define FB_SETTABLE 7 +#define FB_GC 8 void luaI_setfallback (void); -void luaI_errorFB (void); -void luaI_indexFB (void); -void luaI_gettableFB (void); -void luaI_arithFB (void); -void luaI_concatFB (void); -void luaI_orderFB (void); Object *luaI_getlocked (int ref); void luaI_travlock (void (*fn)(Object *)); diff --git a/hash.c b/hash.c index dd7db8f5..09ef8bcb 100644 --- a/hash.c +++ b/hash.c @@ -3,7 +3,7 @@ ** hash manager for lua */ -char *rcs_hash="$Id: hash.c,v 2.13 1994/11/07 15:19:51 roberto Exp roberto $"; +char *rcs_hash="$Id: hash.c,v 2.14 1994/11/07 16:34:44 roberto Exp $"; #include #include @@ -169,6 +169,23 @@ void lua_hashmark (Hash *h) } } } + + +static void call_fallbacks (void) +{ + Hash *curr_array; + Object t; + tag(&t) = LUA_T_ARRAY; + for (curr_array = listhead; curr_array; curr_array = curr_array->next) + if (markarray(curr_array) != 1) + { + avalue(&t) = curr_array; + luaI_gcFB(&t); + } + tag(&t) = LUA_T_NIL; + luaI_gcFB(&t); /* end of list */ +} + /* ** Garbage collection to arrays @@ -177,6 +194,7 @@ void lua_hashmark (Hash *h) void lua_hashcollector (void) { Hash *curr_array = listhead, *prev = NULL; + call_fallbacks(); while (curr_array != NULL) { 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 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 3.7 1994/11/09 18:13:29 roberto Exp roberto $"; +char *rcs_opcode="$Id: opcode.c,v 3.8 1994/11/10 17:11:52 roberto Exp roberto $"; #include #include @@ -633,6 +633,13 @@ int lua_type (lua_Object o) } +void luaI_gcFB (Object *o) +{ + *(top++) = *o; + do_call(&luaI_fallBacks[FB_GC].function, (top-stack)-1, 0, (top-stack)-1); +} + + static void call_arith (char *op) { 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 @@ /* ** TeCGraf - PUC-Rio -** $Id: opcode.h,v 3.6 1994/11/09 18:10:58 roberto Exp roberto $ +** $Id: opcode.h,v 3.7 1994/11/10 17:11:52 roberto Exp roberto $ */ #ifndef opcode_h @@ -162,5 +162,6 @@ void lua_parse (Byte **code); /* from "lua.stx" module */ void lua_travstack (void (*fn)(Object *)); Object *luaI_Address (lua_Object o); void luaI_pushobject (Object *o); +void luaI_gcFB (Object *o); #endif -- cgit v1.2.3-55-g6feb