diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/LuaJIT-1.1.7/src/lfunc.c | 182 |
1 files changed, 0 insertions, 182 deletions
diff --git a/libraries/LuaJIT-1.1.7/src/lfunc.c b/libraries/LuaJIT-1.1.7/src/lfunc.c deleted file mode 100644 index 334e305..0000000 --- a/libraries/LuaJIT-1.1.7/src/lfunc.c +++ /dev/null | |||
@@ -1,182 +0,0 @@ | |||
1 | /* | ||
2 | ** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $ | ||
3 | ** Auxiliary functions to manipulate prototypes and closures | ||
4 | ** See Copyright Notice in lua.h | ||
5 | */ | ||
6 | |||
7 | |||
8 | #include <stddef.h> | ||
9 | |||
10 | #define lfunc_c | ||
11 | #define LUA_CORE | ||
12 | |||
13 | #include "lua.h" | ||
14 | |||
15 | #include "lfunc.h" | ||
16 | #include "lgc.h" | ||
17 | #include "lmem.h" | ||
18 | #include "lobject.h" | ||
19 | #include "lstate.h" | ||
20 | #include "ljit.h" | ||
21 | |||
22 | |||
23 | |||
24 | Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { | ||
25 | Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems))); | ||
26 | luaC_link(L, obj2gco(c), LUA_TFUNCTION); | ||
27 | c->c.isC = 1; | ||
28 | c->c.env = e; | ||
29 | c->c.nupvalues = cast_byte(nelems); | ||
30 | c->c.jit_gate = G(L)->jit_gateJC; | ||
31 | return c; | ||
32 | } | ||
33 | |||
34 | |||
35 | Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { | ||
36 | Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); | ||
37 | luaC_link(L, obj2gco(c), LUA_TFUNCTION); | ||
38 | c->l.isC = 0; | ||
39 | c->l.env = e; | ||
40 | c->l.jit_gate = G(L)->jit_gateJL; | ||
41 | c->l.nupvalues = cast_byte(nelems); | ||
42 | while (nelems--) c->l.upvals[nelems] = NULL; | ||
43 | return c; | ||
44 | } | ||
45 | |||
46 | |||
47 | UpVal *luaF_newupval (lua_State *L) { | ||
48 | UpVal *uv = luaM_new(L, UpVal); | ||
49 | luaC_link(L, obj2gco(uv), LUA_TUPVAL); | ||
50 | uv->v = &uv->u.value; | ||
51 | setnilvalue(uv->v); | ||
52 | return uv; | ||
53 | } | ||
54 | |||
55 | |||
56 | UpVal *luaF_findupval (lua_State *L, StkId level) { | ||
57 | global_State *g = G(L); | ||
58 | GCObject **pp = &L->openupval; | ||
59 | UpVal *p; | ||
60 | UpVal *uv; | ||
61 | while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) { | ||
62 | lua_assert(p->v != &p->u.value); | ||
63 | if (p->v == level) { /* found a corresponding upvalue? */ | ||
64 | if (isdead(g, obj2gco(p))) /* is it dead? */ | ||
65 | changewhite(obj2gco(p)); /* ressurect it */ | ||
66 | return p; | ||
67 | } | ||
68 | pp = &p->next; | ||
69 | } | ||
70 | uv = luaM_new(L, UpVal); /* not found: create a new one */ | ||
71 | uv->tt = LUA_TUPVAL; | ||
72 | uv->marked = luaC_white(g); | ||
73 | uv->v = level; /* current value lives in the stack */ | ||
74 | uv->next = *pp; /* chain it in the proper position */ | ||
75 | *pp = obj2gco(uv); | ||
76 | uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */ | ||
77 | uv->u.l.next = g->uvhead.u.l.next; | ||
78 | uv->u.l.next->u.l.prev = uv; | ||
79 | g->uvhead.u.l.next = uv; | ||
80 | lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); | ||
81 | return uv; | ||
82 | } | ||
83 | |||
84 | |||
85 | static void unlinkupval (UpVal *uv) { | ||
86 | lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); | ||
87 | uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */ | ||
88 | uv->u.l.prev->u.l.next = uv->u.l.next; | ||
89 | } | ||
90 | |||
91 | |||
92 | void luaF_freeupval (lua_State *L, UpVal *uv) { | ||
93 | if (uv->v != &uv->u.value) /* is it open? */ | ||
94 | unlinkupval(uv); /* remove from open list */ | ||
95 | luaM_free(L, uv); /* free upvalue */ | ||
96 | } | ||
97 | |||
98 | |||
99 | void luaF_close (lua_State *L, StkId level) { | ||
100 | UpVal *uv; | ||
101 | global_State *g = G(L); | ||
102 | while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) { | ||
103 | GCObject *o = obj2gco(uv); | ||
104 | lua_assert(!isblack(o) && uv->v != &uv->u.value); | ||
105 | L->openupval = uv->next; /* remove from `open' list */ | ||
106 | if (isdead(g, o)) | ||
107 | luaF_freeupval(L, uv); /* free upvalue */ | ||
108 | else { | ||
109 | unlinkupval(uv); | ||
110 | setobj(L, &uv->u.value, uv->v); | ||
111 | uv->v = &uv->u.value; /* now current value lives here */ | ||
112 | luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */ | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | |||
117 | |||
118 | Proto *luaF_newproto (lua_State *L) { | ||
119 | Proto *f = luaM_new(L, Proto); | ||
120 | luaC_link(L, obj2gco(f), LUA_TPROTO); | ||
121 | f->k = NULL; | ||
122 | f->sizek = 0; | ||
123 | f->p = NULL; | ||
124 | f->sizep = 0; | ||
125 | f->code = NULL; | ||
126 | f->sizecode = 0; | ||
127 | f->sizelineinfo = 0; | ||
128 | f->sizeupvalues = 0; | ||
129 | f->nups = 0; | ||
130 | f->upvalues = NULL; | ||
131 | f->numparams = 0; | ||
132 | f->is_vararg = 0; | ||
133 | f->maxstacksize = 0; | ||
134 | f->lineinfo = NULL; | ||
135 | f->sizelocvars = 0; | ||
136 | f->locvars = NULL; | ||
137 | f->linedefined = 0; | ||
138 | f->lastlinedefined = 0; | ||
139 | f->source = NULL; | ||
140 | /* LuaJIT extensions */ | ||
141 | f->jit_mcode = NULL; | ||
142 | f->jit_szmcode = 0; | ||
143 | f->jit_status = JIT_S_NONE; | ||
144 | return f; | ||
145 | } | ||
146 | |||
147 | |||
148 | void luaF_freeproto (lua_State *L, Proto *f) { | ||
149 | luaJIT_freeproto(L, f); | ||
150 | luaM_freearray(L, f->code, f->sizecode, Instruction); | ||
151 | luaM_freearray(L, f->p, f->sizep, Proto *); | ||
152 | luaM_freearray(L, f->k, f->sizek, TValue); | ||
153 | luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); | ||
154 | luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); | ||
155 | luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); | ||
156 | luaM_free(L, f); | ||
157 | } | ||
158 | |||
159 | |||
160 | void luaF_freeclosure (lua_State *L, Closure *c) { | ||
161 | int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) : | ||
162 | sizeLclosure(c->l.nupvalues); | ||
163 | luaM_freemem(L, c, size); | ||
164 | } | ||
165 | |||
166 | |||
167 | /* | ||
168 | ** Look for n-th local variable at line `line' in function `func'. | ||
169 | ** Returns NULL if not found. | ||
170 | */ | ||
171 | const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { | ||
172 | int i; | ||
173 | for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) { | ||
174 | if (pc < f->locvars[i].endpc) { /* is variable active? */ | ||
175 | local_number--; | ||
176 | if (local_number == 0) | ||
177 | return getstr(f->locvars[i].varname); | ||
178 | } | ||
179 | } | ||
180 | return NULL; /* not found */ | ||
181 | } | ||
182 | |||