new structure for collectable objects, sharing a common header

This commit is contained in:
Roberto Ierusalimschy
2002-08-30 16:09:21 -03:00
parent beeff4ccaf
commit fdafd4f4a8
14 changed files with 276 additions and 302 deletions

45
lfunc.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lfunc.c,v 1.57 2002/06/20 20:41:46 roberto Exp roberto $
** $Id: lfunc.c,v 1.58 2002/08/16 14:45:55 roberto Exp roberto $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
@@ -10,6 +10,7 @@
#include "lua.h"
#include "lfunc.h"
#include "lgc.h"
#include "lmem.h"
#include "lobject.h"
#include "lstate.h"
@@ -25,10 +26,8 @@
Closure *luaF_newCclosure (lua_State *L, int nelems) {
Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems)));
luaC_link(L, cast(GCObject *, c), LUA_TFUNCTION);
c->c.isC = 1;
c->c.next = G(L)->rootcl;
G(L)->rootcl = c;
c->c.marked = 0;
c->c.nupvalues = cast(lu_byte, nelems);
return c;
}
@@ -36,10 +35,8 @@ Closure *luaF_newCclosure (lua_State *L, int nelems) {
Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *gt) {
Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems)));
luaC_link(L, cast(GCObject *, c), LUA_TFUNCTION);
c->l.isC = 0;
c->c.next = G(L)->rootcl;
G(L)->rootcl = c;
c->l.marked = 0;
c->l.g = *gt;
c->l.nupvalues = cast(lu_byte, nelems);
return c;
@@ -47,37 +44,36 @@ Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *gt) {
UpVal *luaF_findupval (lua_State *L, StkId level) {
UpVal **pp = &L->openupval;
UpVal *p;
while ((p = *pp) != NULL && p->v >= level) {
if (p->v == level) return p;
pp = &p->next;
GCObject **pp = &L->openupval;
GCObject *p;
UpVal *v;
while ((p = *pp) != NULL && (&p->uv)->v >= level) {
if ((&p->uv)->v == level) return &p->uv;
pp = &p->gch.next;
}
p = luaM_new(L, UpVal); /* not found: create a new one */
p->marked = 1; /* open upvalues should not be collected */
p->v = level; /* current value lives in the stack */
p->next = *pp; /* chain it in the proper position */
*pp = p;
return p;
v = luaM_new(L, UpVal); /* not found: create a new one */
v->marked = 1; /* open upvalues should not be collected */
v->v = level; /* current value lives in the stack */
v->next = *pp; /* chain it in the proper position */
*pp = cast(GCObject *, v);
return v;
}
void luaF_close (lua_State *L, StkId level) {
UpVal *p;
while ((p = L->openupval) != NULL && p->v >= level) {
lua_assert(p->marked);
p->marked = 0;
while ((p = &(L->openupval)->uv) != NULL && p->v >= level) {
setobj(&p->value, p->v); /* save current value */
p->v = &p->value; /* now current value lives here */
L->openupval = p->next; /* remove from `open' list */
p->next = G(L)->rootupval; /* chain in `closed' list */
G(L)->rootupval = p;
luaC_link(L, cast(GCObject *, p), LUA_TUPVAL);
}
}
Proto *luaF_newproto (lua_State *L) {
Proto *f = luaM_new(L, Proto);
luaC_link(L, cast(GCObject *, f), LUA_TPROTO);
f->k = NULL;
f->sizek = 0;
f->p = NULL;
@@ -88,14 +84,11 @@ Proto *luaF_newproto (lua_State *L) {
f->numparams = 0;
f->is_vararg = 0;
f->maxstacksize = 0;
f->marked = 0;
f->lineinfo = NULL;
f->sizelocvars = 0;
f->locvars = NULL;
f->lineDefined = 0;
f->source = NULL;
f->next = G(L)->rootproto; /* chain in list of protos */
G(L)->rootproto = f;
return f;
}