diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-13 09:32:26 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-13 09:32:26 -0200 |
commit | 2f91f95d94d3a27fee6b45c31ea9ab631924a8bf (patch) | |
tree | bbc605f6643b4958f45536dc5f5f84297eda70c2 /lfunc.c | |
parent | 42dd080a2e3e8fb6887ca1e066f53bb8fd23c9e7 (diff) | |
download | lua-2f91f95d94d3a27fee6b45c31ea9ab631924a8bf.tar.gz lua-2f91f95d94d3a27fee6b45c31ea9ab631924a8bf.tar.bz2 lua-2f91f95d94d3a27fee6b45c31ea9ab631924a8bf.zip |
better control over GCObjects
Diffstat (limited to 'lfunc.c')
-rw-r--r-- | lfunc.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lfunc.c,v 1.60 2002/10/16 20:40:58 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 1.61 2002/10/21 20:41:46 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 | */ |
@@ -26,7 +26,7 @@ | |||
26 | 26 | ||
27 | Closure *luaF_newCclosure (lua_State *L, int nelems) { | 27 | Closure *luaF_newCclosure (lua_State *L, int nelems) { |
28 | 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); | 29 | luaC_link(L, valtogco(c), LUA_TFUNCTION); |
30 | c->c.isC = 1; | 30 | c->c.isC = 1; |
31 | c->c.nupvalues = cast(lu_byte, nelems); | 31 | c->c.nupvalues = cast(lu_byte, nelems); |
32 | return c; | 32 | return c; |
@@ -35,7 +35,7 @@ Closure *luaF_newCclosure (lua_State *L, int nelems) { | |||
35 | 35 | ||
36 | Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *gt) { | 36 | Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *gt) { |
37 | 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); | 38 | luaC_link(L, valtogco(c), LUA_TFUNCTION); |
39 | c->l.isC = 0; | 39 | c->l.isC = 0; |
40 | c->l.g = *gt; | 40 | c->l.g = *gt; |
41 | c->l.nupvalues = cast(lu_byte, nelems); | 41 | c->l.nupvalues = cast(lu_byte, nelems); |
@@ -45,35 +45,36 @@ Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *gt) { | |||
45 | 45 | ||
46 | UpVal *luaF_findupval (lua_State *L, StkId level) { | 46 | UpVal *luaF_findupval (lua_State *L, StkId level) { |
47 | GCObject **pp = &L->openupval; | 47 | GCObject **pp = &L->openupval; |
48 | GCObject *p; | 48 | UpVal *p; |
49 | UpVal *v; | 49 | UpVal *v; |
50 | while ((p = *pp) != NULL && (&p->uv)->v >= level) { | 50 | while ((p = ngcotouv(*pp)) != NULL && p->v >= level) { |
51 | if ((&p->uv)->v == level) return &p->uv; | 51 | if (p->v == level) return p; |
52 | pp = &p->gch.next; | 52 | pp = &p->next; |
53 | } | 53 | } |
54 | v = luaM_new(L, UpVal); /* not found: create a new one */ | 54 | v = luaM_new(L, UpVal); /* not found: create a new one */ |
55 | v->tt = LUA_TUPVAL; | ||
55 | v->marked = 1; /* open upvalues should not be collected */ | 56 | v->marked = 1; /* open upvalues should not be collected */ |
56 | v->v = level; /* current value lives in the stack */ | 57 | v->v = level; /* current value lives in the stack */ |
57 | v->next = *pp; /* chain it in the proper position */ | 58 | v->next = *pp; /* chain it in the proper position */ |
58 | *pp = cast(GCObject *, v); | 59 | *pp = valtogco(v); |
59 | return v; | 60 | return v; |
60 | } | 61 | } |
61 | 62 | ||
62 | 63 | ||
63 | void luaF_close (lua_State *L, StkId level) { | 64 | void luaF_close (lua_State *L, StkId level) { |
64 | UpVal *p; | 65 | UpVal *p; |
65 | while ((p = &(L->openupval)->uv) != NULL && p->v >= level) { | 66 | while ((p = ngcotouv(L->openupval)) != NULL && p->v >= level) { |
66 | setobj(&p->value, p->v); /* save current value */ | 67 | setobj(&p->value, p->v); /* save current value */ |
67 | p->v = &p->value; /* now current value lives here */ | 68 | p->v = &p->value; /* now current value lives here */ |
68 | L->openupval = p->next; /* remove from `open' list */ | 69 | L->openupval = p->next; /* remove from `open' list */ |
69 | luaC_link(L, cast(GCObject *, p), LUA_TUPVAL); | 70 | luaC_link(L, valtogco(p), LUA_TUPVAL); |
70 | } | 71 | } |
71 | } | 72 | } |
72 | 73 | ||
73 | 74 | ||
74 | Proto *luaF_newproto (lua_State *L) { | 75 | Proto *luaF_newproto (lua_State *L) { |
75 | Proto *f = luaM_new(L, Proto); | 76 | Proto *f = luaM_new(L, Proto); |
76 | luaC_link(L, cast(GCObject *, f), LUA_TPROTO); | 77 | luaC_link(L, valtogco(f), LUA_TPROTO); |
77 | f->k = NULL; | 78 | f->k = NULL; |
78 | f->sizek = 0; | 79 | f->sizek = 0; |
79 | f->p = NULL; | 80 | f->p = NULL; |