Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lfunc.h File Reference
#include "lobject.h"

Go to the source code of this file.

Macros

#define sizeCclosure(n)
 
#define sizeLclosure(n)
 
#define isintwups(L)   (L->twups != L)
 
#define MAXUPVAL   255
 
#define upisopen(up)   ((up)->v != &(up)->u.value)
 
#define uplevel(up)   check_exp(upisopen(up), cast(StkId, (up)->v))
 
#define MAXMISS   10
 
#define CLOSEKTOP   (-1)
 

Functions

LUAI_FUNC ProtoluaF_newproto (lua_State *L)
 
LUAI_FUNC CClosureluaF_newCclosure (lua_State *L, int nupvals)
 
LUAI_FUNC LClosureluaF_newLclosure (lua_State *L, int nupvals)
 
LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl)
 
LUAI_FUNC UpValluaF_findupval (lua_State *L, StkId level)
 
LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level)
 
LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level)
 
LUAI_FUNC void luaF_close (lua_State *L, StkId level, int status, int yy)
 
LUAI_FUNC void luaF_unlinkupval (UpVal *uv)
 
LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f)
 
LUAI_FUNC const char * luaF_getlocalname (const Proto *func, int local_number, int pc)
 

Macro Definition Documentation

◆ CLOSEKTOP

#define CLOSEKTOP   (-1)

◆ isintwups

#define isintwups ( L)    (L->twups != L)

Definition at line 22 of file lua-5.4.3/src/lfunc.h.

◆ MAXMISS

#define MAXMISS   10

Definition at line 42 of file lua-5.4.3/src/lfunc.h.

◆ MAXUPVAL

#define MAXUPVAL   255

Definition at line 29 of file lua-5.4.3/src/lfunc.h.

◆ sizeCclosure

#define sizeCclosure ( n)
Value:
(cast_int(offsetof(CClosure, upvalue)) + \
cast_int(sizeof(TValue)) * (n))
#define cast_int(i)
#define offsetof(STRUCTURE, FIELD)
Definition sqlite3.c:14256

Definition at line 14 of file lua-5.4.3/src/lfunc.h.

14#define sizeCclosure(n) (cast_int(offsetof(CClosure, upvalue)) + \
15 cast_int(sizeof(TValue)) * (n))

◆ sizeLclosure

#define sizeLclosure ( n)
Value:
(cast_int(offsetof(LClosure, upvals)) + \
cast_int(sizeof(TValue *)) * (n))

Definition at line 17 of file lua-5.4.3/src/lfunc.h.

17#define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \
18 cast_int(sizeof(TValue *)) * (n))

◆ upisopen

#define upisopen ( up)    ((up)->v != &(up)->u.value)

Definition at line 32 of file lua-5.4.3/src/lfunc.h.

◆ uplevel

#define uplevel ( up)    check_exp(upisopen(up), cast(StkId, (up)->v))

Definition at line 35 of file lua-5.4.3/src/lfunc.h.

Referenced by correctstack(), luaF_closeupval(), and luaF_findupval().

Function Documentation

◆ luaF_close()

LUAI_FUNC void luaF_close ( lua_State * L,
StkId level,
int status,
int yy )

Definition at line 228 of file lua-5.4.3/src/lfunc.c.

228 {
229 ptrdiff_t levelrel = savestack(L, level);
230 luaF_closeupval(L, level); /* first, close the upvalues */
231 while (L->tbclist >= level) { /* traverse tbc's down to that level */
232 StkId tbc = L->tbclist; /* get variable index */
233 poptbclist(L); /* remove it from list */
234 prepcallclosemth(L, tbc, status, yy); /* close variable */
235 level = restorestack(L, levelrel);
236 }
237}
#define savestack(L, p)
#define restorestack(L, n)
static void poptbclist(lua_State *L)
static void prepcallclosemth(lua_State *L, StkId level, int status, int yy)
void luaF_closeupval(lua_State *L, StkId level)

References luaF_closeupval(), poptbclist(), prepcallclosemth(), restorestack, savestack, and lua_State::tbclist.

◆ luaF_closeupval()

LUAI_FUNC void luaF_closeupval ( lua_State * L,
StkId level )

Definition at line 194 of file lua-5.4.3/src/lfunc.c.

194 {
195 UpVal *uv;
196 StkId upl; /* stack index pointed by 'uv' */
197 while ((uv = L->openupval) != NULL && (upl = uplevel(uv)) >= level) {
198 TValue *slot = &uv->u.value; /* new position for value */
199 lua_assert(uplevel(uv) < L->top);
200 luaF_unlinkupval(uv); /* remove upvalue from 'openupval' list */
201 setobj(L, slot, uv->v); /* move value to upvalue slot */
202 uv->v = slot; /* now current value lives here */
203 if (!iswhite(uv)) { /* neither white nor dead? */
204 nw2black(uv); /* closed upvalues cannot be gray */
205 luaC_barrier(L, uv, slot);
206 }
207 }
208}
#define NULL
Definition gmacros.h:924
#define luaC_barrier(L, p, v)
#define iswhite(x)
#define lua_assert(c)
#define setobj(L, obj1, obj2)
void luaF_unlinkupval(UpVal *uv)
#define uplevel(up)
#define nw2black(x)
union UpVal::@48 u
GCObject * openupval

References iswhite, lua_assert, luaC_barrier, luaF_unlinkupval(), NULL, nw2black, lua_State::openupval, setobj, lua_State::top, UpVal::u, uplevel, UpVal::v, and UpVal::value.

Referenced by luaE_freethread(), luaF_close(), and luaV_execute().

◆ luaF_findupval()

LUAI_FUNC UpVal * luaF_findupval ( lua_State * L,
StkId level )

Definition at line 53 of file lua-5.1.5/src/lfunc.c.

53 {
54 global_State *g = G(L);
55 GCObject **pp = &L->openupval;
56 UpVal *p;
57 UpVal *uv;
58 while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) {
59 lua_assert(p->v != &p->u.value);
60 if (p->v == level) { /* found a corresponding upvalue? */
61 if (isdead(g, obj2gco(p))) /* is it dead? */
62 changewhite(obj2gco(p)); /* ressurect it */
63 return p;
64 }
65 pp = &p->next;
66 }
67 uv = luaM_new(L, UpVal); /* not found: create a new one */
68 uv->tt = LUA_TUPVAL;
69 uv->marked = luaC_white(g);
70 uv->v = level; /* current value lives in the stack */
71 uv->next = *pp; /* chain it in the proper position */
72 *pp = obj2gco(uv);
73 uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */
74 uv->u.l.next = g->uvhead.u.l.next;
75 uv->u.l.next->u.l.prev = uv;
76 g->uvhead.u.l.next = uv;
77 lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
78 return uv;
79}
#define changewhite(x)
#define isdead(g, v)
#define luaC_white(g)
#define luaM_new(L, t)
#define LUA_TUPVAL
#define G(L)
#define obj2gco(v)
#define ngcotouv(o)
struct UpVal * prev
struct UpVal * next
struct UpVal::@48::@49 l

References changewhite, G, gco2uv, isdead, isintwups, isold, UpVal::l, lua_assert, LUA_TUPVAL, luaC_newobj(), luaC_white, luaM_new, newupval(), UpVal::next, ngcotouv, NULL, obj2gco, UpVal::open, lua_State::openupval, UpVal::prev, UpVal::refcount, UpVal::touched, lua_State::twups, UpVal::u, upisopen, uplevel, GCObject::uv, global_State::uvhead, UpVal::v, and UpVal::value.

Referenced by luaV_execute(), pushclosure(), pushclosure(), and pushclosure().

◆ luaF_freeproto()

LUAI_FUNC void luaF_freeproto ( lua_State * L,
Proto * f )

Definition at line 141 of file lua-5.1.5/src/lfunc.c.

141 {
143 luaM_freearray(L, f->p, f->sizep, Proto *);
144 luaM_freearray(L, f->k, f->sizek, TValue);
145 luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
146 luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
148 luaM_free(L, f);
149}
lu_int32 Instruction
#define luaM_freearray(L, b, n, t)
#define luaM_free(L, b)
Instruction * code
struct LocVar * locvars
struct Proto ** p
TString ** upvalues

References Proto::abslineinfo, Proto::code, Proto::k, Proto::lineinfo, Proto::locvars, luaM_free, luaM_freearray, Proto::p, Proto::sizeabslineinfo, Proto::sizecode, Proto::sizek, Proto::sizelineinfo, Proto::sizelocvars, Proto::sizep, Proto::sizeupvalues, and Proto::upvalues.

Referenced by freeobj(), freeobj(), freeobj(), and freeobj().

◆ luaF_getlocalname()

LUAI_FUNC const char * luaF_getlocalname ( const Proto * func,
int local_number,
int pc )

Definition at line 163 of file lua-5.1.5/src/lfunc.c.

163 {
164 int i;
165 for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {
166 if (pc < f->locvars[i].endpc) { /* is variable active? */
167 local_number--;
168 if (local_number == 0)
169 return getstr(f->locvars[i].varname);
170 }
171 }
172 return NULL; /* not found */
173}
#define getstr(ts)

References getstr, Proto::locvars, NULL, Proto::sizelocvars, LocVar::startpc, and LocVar::varname.

Referenced by findlocal(), findlocal(), findlocal(), getobjname(), getobjname(), getobjname(), getobjname(), lua_getlocal(), and luaG_findlocal().

◆ luaF_initupvals()

LUAI_FUNC void luaF_initupvals ( lua_State * L,
LClosure * cl )

Definition at line 45 of file lua-5.3.6/src/lfunc.c.

45 {
46 int i;
47 for (i = 0; i < cl->nupvalues; i++) {
48 UpVal *uv = luaM_new(L, UpVal);
49 uv->refcount = 1;
50 uv->v = &uv->u.value; /* make it closed */
51 setnilvalue(uv->v);
52 cl->upvals[i] = uv;
53 }
54}
#define setnilvalue(obj)
lu_mem refcount

References gco2upv, LUA_VUPVAL, luaC_newobj(), luaC_objbarrier, luaM_new, UpVal::refcount, setnilvalue, UpVal::u, LClosure::upvals, UpVal::v, and UpVal::value.

Referenced by f_parser(), and f_parser().

◆ luaF_newCclosure()

LUAI_FUNC CClosure * luaF_newCclosure ( lua_State * L,
int nupvals )

Definition at line 23 of file lua-5.2.4/src/lfunc.c.

23 {
25 c->c.nupvalues = cast_byte(n);
26 return c;
27}
#define sizeCclosure(n)
#define cast_byte(i)
GCObject * luaC_newobj(lua_State *L, int tt, size_t sz, GCObject **list, int offset)
#define LUA_TCCL
union Closure cl

References Closure::c, cast_byte, GCObject::cl, gco2ccl, LUA_TCCL, LUA_VCCL, luaC_newobj(), NULL, and sizeCclosure.

◆ luaF_newLclosure()

LUAI_FUNC LClosure * luaF_newLclosure ( lua_State * L,
int nupvals )

Definition at line 30 of file lua-5.2.4/src/lfunc.c.

30 {
32 c->l.p = NULL;
33 c->l.nupvalues = cast_byte(n);
34 while (n--) c->l.upvals[n] = NULL;
35 return c;
36}
#define sizeLclosure(n)
#define LUA_TLCL
struct Proto * p

References cast_byte, GCObject::cl, gco2lcl, Closure::l, LUA_TLCL, LUA_VLCL, luaC_newobj(), NULL, LClosure::p, sizeLclosure, and LClosure::upvals.

◆ luaF_newproto()

LUAI_FUNC Proto * luaF_newproto ( lua_State * L)

Definition at line 115 of file lua-5.1.5/src/lfunc.c.

115 {
116 Proto *f = luaM_new(L, Proto);
118 f->k = NULL;
119 f->sizek = 0;
120 f->p = NULL;
121 f->sizep = 0;
122 f->code = NULL;
123 f->sizecode = 0;
124 f->sizelineinfo = 0;
125 f->sizeupvalues = 0;
126 f->nups = 0;
127 f->upvalues = NULL;
128 f->numparams = 0;
129 f->is_vararg = 0;
130 f->maxstacksize = 0;
131 f->lineinfo = NULL;
132 f->sizelocvars = 0;
133 f->locvars = NULL;
134 f->linedefined = 0;
135 f->lastlinedefined = 0;
136 f->source = NULL;
137 return f;
138}
void luaC_link(lua_State *L, GCObject *o, lu_byte tt)
#define LUA_TPROTO
lu_byte maxstacksize
TString * source

References Proto::abslineinfo, Proto::cache, Proto::code, gco2p, Proto::is_vararg, Proto::k, Proto::lastlinedefined, Proto::linedefined, Proto::lineinfo, Proto::locvars, LUA_TPROTO, LUA_VPROTO, luaC_link(), luaC_newobj(), luaM_new, Proto::maxstacksize, NULL, Proto::numparams, Proto::nups, obj2gco, Proto::p, GCObject::p, Proto::sizeabslineinfo, Proto::sizecode, Proto::sizek, Proto::sizelineinfo, Proto::sizelocvars, Proto::sizep, Proto::sizeupvalues, Proto::source, and Proto::upvalues.

Referenced by addprototype(), addprototype(), addprototype(), combine(), LoadConstants(), LoadFunction(), LoadProtos(), loadProtos(), luaU_undump(), luaU_undump(), luaY_parser(), and open_func().

◆ luaF_newtbcupval()

LUAI_FUNC void luaF_newtbcupval ( lua_State * L,
StkId level )

Definition at line 169 of file lua-5.4.3/src/lfunc.c.

169 {
170 lua_assert(level > L->tbclist);
171 if (l_isfalse(s2v(level)))
172 return; /* false doesn't need to be closed */
173 checkclosemth(L, level); /* value must have a close method */
174 while (cast_uint(level - L->tbclist) > MAXDELTA) {
175 L->tbclist += MAXDELTA; /* create a dummy node at maximum delta */
176 L->tbclist->tbclist.delta = 0;
177 }
178 level->tbclist.delta = cast(unsigned short, level - L->tbclist);
179 L->tbclist = level;
180}
#define cast(t, exp)
#define l_isfalse(o)
#define MAXDELTA
static void checkclosemth(lua_State *L, StkId level)
#define cast_uint(i)
#define s2v(o)

References cast, cast_uint, checkclosemth(), l_isfalse, lua_assert, MAXDELTA, s2v, and lua_State::tbclist.

Referenced by lua_toclose(), and luaV_execute().

◆ luaF_unlinkupval()

LUAI_FUNC void luaF_unlinkupval ( UpVal * uv)

Definition at line 183 of file lua-5.4.3/src/lfunc.c.

183 {
184 lua_assert(upisopen(uv));
185 *uv->u.open.previous = uv->u.open.next;
186 if (uv->u.open.next)
187 uv->u.open.next->u.open.previous = uv->u.open.previous;
188}
#define upisopen(up)
struct UpVal::@68::@69 open
struct UpVal ** previous

References lua_assert, UpVal::next, UpVal::open, UpVal::previous, UpVal::u, and upisopen.

Referenced by freeupval(), and luaF_closeupval().