aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lfunc.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/lfunc.c b/lfunc.c
index a3cb42a1..07484700 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 1.69 2003/10/20 17:42:41 roberto Exp roberto $ 2** $Id: lfunc.c,v 1.70 2003/11/17 19:50:05 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*/
@@ -46,39 +46,40 @@ Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e) {
46 46
47 47
48UpVal *luaF_newupval (lua_State *L) { 48UpVal *luaF_newupval (lua_State *L) {
49 UpVal *p = luaM_new(L, UpVal); 49 UpVal *uv = luaM_new(L, UpVal);
50 luaC_link(L, valtogco(p), LUA_TUPVAL); 50 luaC_link(L, valtogco(uv), LUA_TUPVAL);
51 p->v = &p->value; 51 uv->v = &uv->value;
52 setnilvalue(p->v); 52 setnilvalue(uv->v);
53 return p; 53 return uv;
54} 54}
55 55
56 56
57UpVal *luaF_findupval (lua_State *L, StkId level) { 57UpVal *luaF_findupval (lua_State *L, StkId level) {
58 GCObject **pp = &L->openupval; 58 GCObject **pp = &L->openupval;
59 UpVal *p; 59 UpVal *p;
60 UpVal *v; 60 UpVal *uv;
61 while ((p = ngcotouv(*pp)) != NULL && p->v >= level) { 61 while ((p = ngcotouv(*pp)) != NULL && p->v >= level) {
62 if (p->v == level) return p; 62 if (p->v == level) return p;
63 pp = &p->next; 63 pp = &p->next;
64 } 64 }
65 v = luaM_new(L, UpVal); /* not found: create a new one */ 65 uv = luaM_new(L, UpVal); /* not found: create a new one */
66 v->tt = LUA_TUPVAL; 66 uv->tt = LUA_TUPVAL;
67 v->marked = bitmask(BLACKBIT); /* open upvalues should not be collected */ 67 uv->marked = bitmask(FIXEDBIT); /* open upvalues cannot be collected */
68 v->v = level; /* current value lives in the stack */ 68 uv->v = level; /* current value lives in the stack */
69 v->next = *pp; /* chain it in the proper position */ 69 uv->next = *pp; /* chain it in the proper position */
70 *pp = valtogco(v); 70 *pp = valtogco(uv);
71 return v; 71 return uv;
72} 72}
73 73
74 74
75void luaF_close (lua_State *L, StkId level) { 75void luaF_close (lua_State *L, StkId level) {
76 UpVal *p; 76 UpVal *uv;
77 while ((p = ngcotouv(L->openupval)) != NULL && p->v >= level) { 77 while ((uv = ngcotouv(L->openupval)) != NULL && uv->v >= level) {
78 setobj(&p->value, p->v); /* save current value (write barrier) */ 78 setobj(&uv->value, uv->v); /* save current value (write barrier) */
79 p->v = &p->value; /* now current value lives here */ 79 uv->v = &uv->value; /* now current value lives here */
80 L->openupval = p->next; /* remove from `open' list */ 80 L->openupval = uv->next; /* remove from `open' list */
81 luaC_link(L, valtogco(p), LUA_TUPVAL); 81 resetbit(uv->marked, FIXEDBIT); /* closed upvalues can be collected */
82 luaC_link(L, valtogco(uv), LUA_TUPVAL);
82 } 83 }
83} 84}
84 85