diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-08-30 16:09:21 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-08-30 16:09:21 -0300 |
| commit | fdafd4f4a88d1584dea900517445a17d87f8b82f (patch) | |
| tree | 52e38e886d569e77c1df82ebe2bcfbaafd4c6f75 /lfunc.c | |
| parent | beeff4ccafe5877d00119cb3d93f1f937d46dcfb (diff) | |
| download | lua-fdafd4f4a88d1584dea900517445a17d87f8b82f.tar.gz lua-fdafd4f4a88d1584dea900517445a17d87f8b82f.tar.bz2 lua-fdafd4f4a88d1584dea900517445a17d87f8b82f.zip | |
new structure for collectable objects, sharing a common header
Diffstat (limited to 'lfunc.c')
| -rw-r--r-- | lfunc.c | 45 |
1 files changed, 19 insertions, 26 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lfunc.c,v 1.57 2002/06/20 20:41:46 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 1.58 2002/08/16 14:45:55 roberto Exp roberto $ |
| 3 | ** Auxiliary functions to manipulate prototypes and closures | 3 | ** Auxiliary functions to manipulate prototypes and closures |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -10,6 +10,7 @@ | |||
| 10 | #include "lua.h" | 10 | #include "lua.h" |
| 11 | 11 | ||
| 12 | #include "lfunc.h" | 12 | #include "lfunc.h" |
| 13 | #include "lgc.h" | ||
| 13 | #include "lmem.h" | 14 | #include "lmem.h" |
| 14 | #include "lobject.h" | 15 | #include "lobject.h" |
| 15 | #include "lstate.h" | 16 | #include "lstate.h" |
| @@ -25,10 +26,8 @@ | |||
| 25 | 26 | ||
| 26 | Closure *luaF_newCclosure (lua_State *L, int nelems) { | 27 | Closure *luaF_newCclosure (lua_State *L, int nelems) { |
| 27 | Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems))); | 28 | Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems))); |
| 29 | luaC_link(L, cast(GCObject *, c), LUA_TFUNCTION); | ||
| 28 | c->c.isC = 1; | 30 | c->c.isC = 1; |
| 29 | c->c.next = G(L)->rootcl; | ||
| 30 | G(L)->rootcl = c; | ||
| 31 | c->c.marked = 0; | ||
| 32 | c->c.nupvalues = cast(lu_byte, nelems); | 31 | c->c.nupvalues = cast(lu_byte, nelems); |
| 33 | return c; | 32 | return c; |
| 34 | } | 33 | } |
| @@ -36,10 +35,8 @@ Closure *luaF_newCclosure (lua_State *L, int nelems) { | |||
| 36 | 35 | ||
| 37 | Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *gt) { | 36 | Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *gt) { |
| 38 | Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); | 37 | Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); |
| 38 | luaC_link(L, cast(GCObject *, c), LUA_TFUNCTION); | ||
| 39 | c->l.isC = 0; | 39 | c->l.isC = 0; |
| 40 | c->c.next = G(L)->rootcl; | ||
| 41 | G(L)->rootcl = c; | ||
| 42 | c->l.marked = 0; | ||
| 43 | c->l.g = *gt; | 40 | c->l.g = *gt; |
| 44 | c->l.nupvalues = cast(lu_byte, nelems); | 41 | c->l.nupvalues = cast(lu_byte, nelems); |
| 45 | return c; | 42 | return c; |
| @@ -47,37 +44,36 @@ Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *gt) { | |||
| 47 | 44 | ||
| 48 | 45 | ||
| 49 | UpVal *luaF_findupval (lua_State *L, StkId level) { | 46 | UpVal *luaF_findupval (lua_State *L, StkId level) { |
| 50 | UpVal **pp = &L->openupval; | 47 | GCObject **pp = &L->openupval; |
| 51 | UpVal *p; | 48 | GCObject *p; |
| 52 | while ((p = *pp) != NULL && p->v >= level) { | 49 | UpVal *v; |
| 53 | if (p->v == level) return p; | 50 | while ((p = *pp) != NULL && (&p->uv)->v >= level) { |
| 54 | pp = &p->next; | 51 | if ((&p->uv)->v == level) return &p->uv; |
| 52 | pp = &p->gch.next; | ||
| 55 | } | 53 | } |
| 56 | p = luaM_new(L, UpVal); /* not found: create a new one */ | 54 | v = luaM_new(L, UpVal); /* not found: create a new one */ |
| 57 | p->marked = 1; /* open upvalues should not be collected */ | 55 | v->marked = 1; /* open upvalues should not be collected */ |
| 58 | p->v = level; /* current value lives in the stack */ | 56 | v->v = level; /* current value lives in the stack */ |
| 59 | p->next = *pp; /* chain it in the proper position */ | 57 | v->next = *pp; /* chain it in the proper position */ |
| 60 | *pp = p; | 58 | *pp = cast(GCObject *, v); |
| 61 | return p; | 59 | return v; |
| 62 | } | 60 | } |
| 63 | 61 | ||
| 64 | 62 | ||
| 65 | void luaF_close (lua_State *L, StkId level) { | 63 | void luaF_close (lua_State *L, StkId level) { |
| 66 | UpVal *p; | 64 | UpVal *p; |
| 67 | while ((p = L->openupval) != NULL && p->v >= level) { | 65 | while ((p = &(L->openupval)->uv) != NULL && p->v >= level) { |
| 68 | lua_assert(p->marked); | ||
| 69 | p->marked = 0; | ||
| 70 | setobj(&p->value, p->v); /* save current value */ | 66 | setobj(&p->value, p->v); /* save current value */ |
| 71 | p->v = &p->value; /* now current value lives here */ | 67 | p->v = &p->value; /* now current value lives here */ |
| 72 | L->openupval = p->next; /* remove from `open' list */ | 68 | L->openupval = p->next; /* remove from `open' list */ |
| 73 | p->next = G(L)->rootupval; /* chain in `closed' list */ | 69 | luaC_link(L, cast(GCObject *, p), LUA_TUPVAL); |
| 74 | G(L)->rootupval = p; | ||
| 75 | } | 70 | } |
| 76 | } | 71 | } |
| 77 | 72 | ||
| 78 | 73 | ||
| 79 | Proto *luaF_newproto (lua_State *L) { | 74 | Proto *luaF_newproto (lua_State *L) { |
| 80 | Proto *f = luaM_new(L, Proto); | 75 | Proto *f = luaM_new(L, Proto); |
| 76 | luaC_link(L, cast(GCObject *, f), LUA_TPROTO); | ||
| 81 | f->k = NULL; | 77 | f->k = NULL; |
| 82 | f->sizek = 0; | 78 | f->sizek = 0; |
| 83 | f->p = NULL; | 79 | f->p = NULL; |
| @@ -88,14 +84,11 @@ Proto *luaF_newproto (lua_State *L) { | |||
| 88 | f->numparams = 0; | 84 | f->numparams = 0; |
| 89 | f->is_vararg = 0; | 85 | f->is_vararg = 0; |
| 90 | f->maxstacksize = 0; | 86 | f->maxstacksize = 0; |
| 91 | f->marked = 0; | ||
| 92 | f->lineinfo = NULL; | 87 | f->lineinfo = NULL; |
| 93 | f->sizelocvars = 0; | 88 | f->sizelocvars = 0; |
| 94 | f->locvars = NULL; | 89 | f->locvars = NULL; |
| 95 | f->lineDefined = 0; | 90 | f->lineDefined = 0; |
| 96 | f->source = NULL; | 91 | f->source = NULL; |
| 97 | f->next = G(L)->rootproto; /* chain in list of protos */ | ||
| 98 | G(L)->rootproto = f; | ||
| 99 | return f; | 92 | return f; |
| 100 | } | 93 | } |
| 101 | 94 | ||
