fallback for garbage collection

This commit is contained in:
Roberto Ierusalimschy 1994-11-10 15:36:54 -02:00
parent 9deac27704
commit 8a0521fa52
5 changed files with 58 additions and 25 deletions

View File

@ -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 <stdio.h>
#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
#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

View File

@ -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 *));

20
hash.c
View File

@ -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 <string.h>
#include <stdlib.h>
@ -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;

View File

@ -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 <stdio.h>
#include <stdlib.h>
@ -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);

View File

@ -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