Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | /* | |||
2 | ** $Id: lvm.c $ | |||
3 | ** Lua virtual machine | |||
4 | ** See Copyright Notice in lua.h | |||
5 | */ | |||
6 | ||||
7 | #define lvm_c | |||
8 | #define LUA_CORE | |||
9 | ||||
10 | #include "lprefix.h" | |||
11 | ||||
12 | #include <float.h> | |||
13 | #include <limits.h> | |||
14 | #include <math.h> | |||
15 | #include <stdio.h> | |||
16 | #include <stdlib.h> | |||
17 | #include <string.h> | |||
18 | ||||
19 | #include "lua.h" | |||
20 | ||||
21 | #include "ldebug.h" | |||
22 | #include "ldo.h" | |||
23 | #include "lfunc.h" | |||
24 | #include "lgc.h" | |||
25 | #include "lobject.h" | |||
26 | #include "lopcodes.h" | |||
27 | #include "lstate.h" | |||
28 | #include "lstring.h" | |||
29 | #include "ltable.h" | |||
30 | #include "ltm.h" | |||
31 | #include "lvm.h" | |||
32 | ||||
33 | ||||
34 | /* | |||
35 | ** By default, use jump tables in the main interpreter loop on gcc | |||
36 | ** and compatible compilers. | |||
37 | */ | |||
38 | #if !defined(LUA_USE_JUMPTABLE) | |||
39 | #if defined(__GNUC__) | |||
40 | #define LUA_USE_JUMPTABLE 1 | |||
41 | #else | |||
42 | #define LUA_USE_JUMPTABLE 0 | |||
43 | #endif | |||
44 | #endif | |||
45 | ||||
46 | ||||
47 | ||||
48 | /* limit for table tag-method chains (to avoid infinite loops) */ | |||
49 | #define MAXTAGLOOP 2000 | |||
50 | ||||
51 | ||||
52 | /* | |||
53 | ** 'l_intfitsf' checks whether a given integer is in the range that | |||
54 | ** can be converted to a float without rounding. Used in comparisons. | |||
55 | */ | |||
56 | ||||
57 | /* number of bits in the mantissa of a float */ | |||
58 | #define NBM (l_floatatt(MANT_DIG)) | |||
59 | ||||
60 | /* | |||
61 | ** Check whether some integers may not fit in a float, testing whether | |||
62 | ** (maxinteger >> NBM) > 0. (That implies (1 << NBM) <= maxinteger.) | |||
63 | ** (The shifts are done in parts, to avoid shifting by more than the size | |||
64 | ** of an integer. In a worst case, NBM == 113 for long double and | |||
65 | ** sizeof(long) == 32.) | |||
66 | */ | |||
67 | #if ((((LUA_MAXINTEGER >> (NBM / 4)) >> (NBM / 4)) >> (NBM / 4)) \ | |||
68 | >> (NBM - (3 * (NBM / 4)))) > 0 | |||
69 | ||||
70 | /* limit for integers that fit in a float */ | |||
71 | #define MAXINTFITSF ((lua_Unsigned)1 << NBM) | |||
72 | ||||
73 | /* check whether 'i' is in the interval [-MAXINTFITSF, MAXINTFITSF] */ | |||
74 | #define l_intfitsf(i) ((MAXINTFITSF + l_castS2U(i)) <= (2 * MAXINTFITSF)) | |||
75 | ||||
76 | #else /* all integers fit in a float precisely */ | |||
77 | ||||
78 | #define l_intfitsf(i) 1 | |||
79 | ||||
80 | #endif | |||
81 | ||||
82 | ||||
83 | /* | |||
84 | ** Try to convert a value from string to a number value. | |||
85 | ** If the value is not a string or is a string not representing | |||
86 | ** a valid numeral (or if coercions from strings to numbers | |||
87 | ** are disabled via macro 'cvt2num'), do not modify 'result' | |||
88 | ** and return 0. | |||
89 | */ | |||
90 | 18 | static int l_strton (const TValue *obj, TValue *result) { | ||
91 | lua_assert(obj != result); | |||
92 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 1 time.
|
2/2✓ Decision 'true' taken 17 times.
✓ Decision 'false' taken 1 time.
|
18 | if (!cvt2num(obj)) /* is object not a string? */ |
93 | 17 | return 0; | ||
94 | else | |||
95 |
1/2✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
|
1 | return (luaO_str2num(svalue(obj), result) == vslen(obj) + 1); | |
96 | } | |||
97 | ||||
98 | ||||
99 | /* | |||
100 | ** Try to convert a value to a float. The float case is already handled | |||
101 | ** by the macro 'tonumber'. | |||
102 | */ | |||
103 |
1/1✓ Decision 'true' taken 211 times.
|
211 | int luaV_tonumber_ (const TValue *obj, lua_Number *n) { | |
104 | TValue v; | |||
105 |
2/2✓ Branch 0 taken 201 times.
✓ Branch 1 taken 10 times.
|
2/2✓ Decision 'true' taken 201 times.
✓ Decision 'false' taken 10 times.
|
211 | if (ttisinteger(obj)) { |
106 | 201 | *n = cast_num(ivalue(obj)); | ||
107 | 201 | return 1; | ||
108 | } | |||
109 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 10 times.
|
10 | else if (l_strton(obj, &v)) { /* string coercible to number? */ |
110 | ✗ | *n = nvalue(&v); /* convert result of 'luaO_str2num' to a float */ | ||
111 | ✗ | return 1; | ||
112 | } | |||
113 | else | |||
114 | 10 | return 0; /* conversion failed */ | ||
115 | } | |||
116 | ||||
117 | ||||
118 | /* | |||
119 | ** try to convert a float to an integer, rounding according to 'mode'. | |||
120 | */ | |||
121 | 281 | int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode) { | ||
122 | 281 | lua_Number f = l_floor(n); | ||
123 |
2/2✓ Branch 0 taken 225 times.
✓ Branch 1 taken 56 times.
|
2/2✓ Decision 'true' taken 225 times.
✓ Decision 'false' taken 56 times.
|
281 | if (n != f) { /* not an integral value? */ |
124 |
1/2✓ Branch 0 taken 225 times.
✗ Branch 1 not taken.
|
1/2✓ Decision 'true' taken 225 times.
✗ Decision 'false' not taken.
|
225 | if (mode == F2Ieq) return 0; /* fails if mode demands integral value */ |
125 | ✗ | else if (mode == F2Iceil) /* needs ceil? */ | ||
126 | ✗ | f += 1; /* convert floor to ceil (remember: n != f) */ | ||
127 | } | |||
128 |
2/4✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
|
56 | return lua_numbertointeger(f, p); | |
129 | } | |||
130 | ||||
131 | ||||
132 | /* | |||
133 | ** try to convert a value to an integer, rounding according to 'mode', | |||
134 | ** without string coercion. | |||
135 | ** ("Fast track" handled by macro 'tointegerns'.) | |||
136 | */ | |||
137 | 8 | int luaV_tointegerns (const TValue *obj, lua_Integer *p, F2Imod mode) { | ||
138 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 7 times.
|
2/2✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 7 times.
|
8 | if (ttisfloat(obj)) |
139 | 1 | return luaV_flttointeger(fltvalue(obj), p, mode); | ||
140 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
1/2✓ Decision 'true' taken 7 times.
✗ Decision 'false' not taken.
|
7 | else if (ttisinteger(obj)) { |
141 | 7 | *p = ivalue(obj); | ||
142 | 7 | return 1; | ||
143 | } | |||
144 | else | |||
145 | ✗ | return 0; | ||
146 | } | |||
147 | ||||
148 | ||||
149 | /* | |||
150 | ** try to convert a value to an integer. | |||
151 | */ | |||
152 | 8 | int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode) { | ||
153 | TValue v; | |||
154 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 8 times.
|
8 | if (l_strton(obj, &v)) /* does 'obj' point to a numerical string? */ |
155 | ✗ | obj = &v; /* change it to point to its corresponding number */ | ||
156 | 8 | return luaV_tointegerns(obj, p, mode); | ||
157 | } | |||
158 | ||||
159 | ||||
160 | /* | |||
161 | ** Try to convert a 'for' limit to an integer, preserving the semantics | |||
162 | ** of the loop. Return true if the loop must not run; otherwise, '*p' | |||
163 | ** gets the integer limit. | |||
164 | ** (The following explanation assumes a positive step; it is valid for | |||
165 | ** negative steps mutatis mutandis.) | |||
166 | ** If the limit is an integer or can be converted to an integer, | |||
167 | ** rounding down, that is the limit. | |||
168 | ** Otherwise, check whether the limit can be converted to a float. If | |||
169 | ** the float is too large, clip it to LUA_MAXINTEGER. If the float | |||
170 | ** is too negative, the loop should not run, because any initial | |||
171 | ** integer value is greater than such limit; so, the function returns | |||
172 | ** true to signal that. (For this latter case, no integer limit would be | |||
173 | ** correct; even a limit of LUA_MININTEGER would run the loop once for | |||
174 | ** an initial value equal to LUA_MININTEGER.) | |||
175 | */ | |||
176 | 7 | static int forlimit (lua_State *L, lua_Integer init, const TValue *lim, | ||
177 | lua_Integer *p, lua_Integer step) { | |||
178 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 7 times.
|
7 | if (!luaV_tointeger(lim, p, (step < 0 ? F2Iceil : F2Ifloor))) { |
179 | /* not coercible to in integer */ | |||
180 | lua_Number flim; /* try to convert to float */ | |||
181 | ✗ | if (!tonumber(lim, &flim)) /* cannot convert to float? */ | ||
182 | ✗ | luaG_forerror(L, lim, "limit"); | ||
183 | /* else 'flim' is a float out of integer bounds */ | |||
184 | ✗ | if (luai_numlt(0, flim)) { /* if it is positive, it is too large */ | ||
185 | ✗ | if (step < 0) return 1; /* initial value must be less than it */ | ||
186 | ✗ | *p = LUA_MAXINTEGER; /* truncate */ | ||
187 | } | |||
188 | else { /* it is less than min integer */ | |||
189 | ✗ | if (step > 0) return 1; /* initial value must be greater than it */ | ||
190 | ✗ | *p = LUA_MININTEGER; /* truncate */ | ||
191 | } | |||
192 | } | |||
193 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | return (step > 0 ? init > *p : init < *p); /* not to run? */ | |
194 | } | |||
195 | ||||
196 | ||||
197 | /* | |||
198 | ** Prepare a numerical for loop (opcode OP_FORPREP). | |||
199 | ** Return true to skip the loop. Otherwise, | |||
200 | ** after preparation, stack will be as follows: | |||
201 | ** ra : internal index (safe copy of the control variable) | |||
202 | ** ra + 1 : loop counter (integer loops) or limit (float loops) | |||
203 | ** ra + 2 : step | |||
204 | ** ra + 3 : control variable | |||
205 | */ | |||
206 | 7 | static int forprep (lua_State *L, StkId ra) { | ||
207 | 7 | TValue *pinit = s2v(ra); | ||
208 | 7 | TValue *plimit = s2v(ra + 1); | ||
209 | 7 | TValue *pstep = s2v(ra + 2); | ||
210 |
2/4✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
2/2✓ Decision 'true' taken 7 times.
✓ Decision 'false' taken 7 times.
|
14 | if (ttisinteger(pinit) && ttisinteger(pstep)) { /* integer loop? */ |
211 | 7 | lua_Integer init = ivalue(pinit); | ||
212 | 7 | lua_Integer step = ivalue(pstep); | ||
213 | lua_Integer limit; | |||
214 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 7 times.
|
7 | if (step == 0) |
215 | ✗ | luaG_runerror(L, "'for' step is zero"); | ||
216 | 7 | setivalue(s2v(ra + 3), init); /* control variable */ | ||
217 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 7 times.
|
7 | if (forlimit(L, init, plimit, &limit, step)) |
218 | ✗ | return 1; /* skip the loop */ | ||
219 | else { /* prepare loop counter */ | |||
220 | lua_Unsigned count; | |||
221 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
1/2✓ Decision 'true' taken 7 times.
✗ Decision 'false' not taken.
|
7 | if (step > 0) { /* ascending loop? */ |
222 | 7 | count = l_castS2U(limit) - l_castS2U(init); | ||
223 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 7 times.
|
7 | if (step != 1) /* avoid division in the too common case */ |
224 | ✗ | count /= l_castS2U(step); | ||
225 | } | |||
226 | else { /* step < 0; descending loop */ | |||
227 | ✗ | count = l_castS2U(init) - l_castS2U(limit); | ||
228 | /* 'step+1' avoids negating 'mininteger' */ | |||
229 | ✗ | count /= l_castS2U(-(step + 1)) + 1u; | ||
230 | } | |||
231 | /* store the counter in place of the limit (which won't be | |||
232 | needed anymore) */ | |||
233 | 7 | setivalue(plimit, l_castU2S(count)); | ||
234 | } | |||
235 | } | |||
236 | else { /* try making all values floats */ | |||
237 | lua_Number init; lua_Number limit; lua_Number step; | |||
238 | ✗ | if (l_unlikely(!tonumber(plimit, &limit))) | ||
239 | ✗ | luaG_forerror(L, plimit, "limit"); | ||
240 | ✗ | if (l_unlikely(!tonumber(pstep, &step))) | ||
241 | ✗ | luaG_forerror(L, pstep, "step"); | ||
242 | ✗ | if (l_unlikely(!tonumber(pinit, &init))) | ||
243 | ✗ | luaG_forerror(L, pinit, "initial value"); | ||
244 | ✗ | if (step == 0) | ||
245 | ✗ | luaG_runerror(L, "'for' step is zero"); | ||
246 | ✗ | if (luai_numlt(0, step) ? luai_numlt(limit, init) | ||
247 | : luai_numlt(init, limit)) | |||
248 | ✗ | return 1; /* skip the loop */ | ||
249 | else { | |||
250 | /* make sure internal values are all floats */ | |||
251 | ✗ | setfltvalue(plimit, limit); | ||
252 | ✗ | setfltvalue(pstep, step); | ||
253 | ✗ | setfltvalue(s2v(ra), init); /* internal index */ | ||
254 | ✗ | setfltvalue(s2v(ra + 3), init); /* control variable */ | ||
255 | } | |||
256 | } | |||
257 | 7 | return 0; | ||
258 | } | |||
259 | ||||
260 | ||||
261 | /* | |||
262 | ** Execute a step of a float numerical for loop, returning | |||
263 | ** true iff the loop must continue. (The integer case is | |||
264 | ** written online with opcode OP_FORLOOP, for performance.) | |||
265 | */ | |||
266 | ✗ | static int floatforloop (StkId ra) { | ||
267 | ✗ | lua_Number step = fltvalue(s2v(ra + 2)); | ||
268 | ✗ | lua_Number limit = fltvalue(s2v(ra + 1)); | ||
269 | ✗ | lua_Number idx = fltvalue(s2v(ra)); /* internal index */ | ||
270 | ✗ | idx = luai_numadd(L, idx, step); /* increment index */ | ||
271 | ✗ | if (luai_numlt(0, step) ? luai_numle(idx, limit) | ||
272 | : luai_numle(limit, idx)) { | |||
273 | ✗ | chgfltvalue(s2v(ra), idx); /* update internal index */ | ||
274 | ✗ | setfltvalue(s2v(ra + 3), idx); /* and control variable */ | ||
275 | ✗ | return 1; /* jump back */ | ||
276 | } | |||
277 | else | |||
278 | ✗ | return 0; /* finish the loop */ | ||
279 | } | |||
280 | ||||
281 | ||||
282 | /* | |||
283 | ** Finish the table access 'val = t[key]'. | |||
284 | ** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to | |||
285 | ** t[k] entry (which must be empty). | |||
286 | */ | |||
287 | 6275 | void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, | ||
288 | const TValue *slot) { | |||
289 | int loop; /* counter to avoid infinite loops */ | |||
290 | const TValue *tm; /* metamethod */ | |||
291 |
1/2✓ Branch 0 taken 6275 times.
✗ Branch 1 not taken.
|
6275 | for (loop = 0; loop < MAXTAGLOOP; loop++) { | |
292 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 6235 times.
|
6275 | if (slot == NULL) { /* 't' is not a table? */ | |
293 | lua_assert(!ttistable(t)); | |||
294 | 40 | tm = luaT_gettmbyobj(L, t, TM_INDEX); | ||
295 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | if (l_unlikely(notm(tm))) | |
296 | ✗ | luaG_typeerror(L, t, "index"); /* no metamethod */ | ||
297 | /* else will try the metamethod */ | |||
298 | } | |||
299 | else { /* 't' is a table */ | |||
300 | lua_assert(isempty(slot)); | |||
301 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6235 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
6235 | tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */ | |
302 |
1/2✓ Branch 0 taken 6235 times.
✗ Branch 1 not taken.
|
6235 | if (tm == NULL) { /* no metamethod? */ | |
303 | 6235 | setnilvalue(s2v(val)); /* result is nil */ | ||
304 | 6235 | return; | ||
305 | } | |||
306 | /* else will try the metamethod */ | |||
307 | } | |||
308 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | if (ttisfunction(tm)) { /* is metamethod a function? */ | |
309 | ✗ | luaT_callTMres(L, tm, t, key, val); /* call it */ | ||
310 | ✗ | return; | ||
311 | } | |||
312 | 40 | t = tm; /* else try to access 'tm[key]' */ | ||
313 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
|
40 | if (luaV_fastget(L, t, key, slot, luaH_get)) { /* fast track? */ | |
314 | 40 | setobj2s(L, val, slot); /* done */ | ||
315 | 40 | return; | ||
316 | } | |||
317 | /* else repeat (tail call 'luaV_finishget') */ | |||
318 | } | |||
319 | ✗ | luaG_runerror(L, "'__index' chain too long; possible loop"); | ||
320 | } | |||
321 | ||||
322 | ||||
323 | /* | |||
324 | ** Finish a table assignment 't[key] = val'. | |||
325 | ** If 'slot' is NULL, 't' is not a table. Otherwise, 'slot' points | |||
326 | ** to the entry 't[key]', or to a value with an absent key if there | |||
327 | ** is no such entry. (The value at 'slot' must be empty, otherwise | |||
328 | ** 'luaV_fastget' would have done the job.) | |||
329 | */ | |||
330 | 49216 | void luaV_finishset (lua_State *L, const TValue *t, TValue *key, | ||
331 | TValue *val, const TValue *slot) { | |||
332 | int loop; /* counter to avoid infinite loops */ | |||
333 |
1/2✓ Branch 0 taken 49216 times.
✗ Branch 1 not taken.
|
49216 | for (loop = 0; loop < MAXTAGLOOP; loop++) { | |
334 | const TValue *tm; /* '__newindex' metamethod */ | |||
335 |
1/2✓ Branch 0 taken 49216 times.
✗ Branch 1 not taken.
|
49216 | if (slot != NULL) { /* is 't' a table? */ | |
336 | 49216 | Table *h = hvalue(t); /* save 't' table */ | ||
337 | lua_assert(isempty(slot)); /* slot must be empty */ | |||
338 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 49216 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
49216 | tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */ | |
339 |
1/2✓ Branch 0 taken 49216 times.
✗ Branch 1 not taken.
|
49216 | if (tm == NULL) { /* no metamethod? */ | |
340 | 49216 | luaH_finishset(L, h, key, slot, val); /* set new value */ | ||
341 | 49216 | invalidateTMcache(h); | ||
342 |
3/6✓ Branch 0 taken 19777 times.
✓ Branch 1 taken 29439 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19777 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
49216 | luaC_barrierback(L, obj2gco(h), val); | |
343 | 49216 | return; | ||
344 | } | |||
345 | /* else will try the metamethod */ | |||
346 | } | |||
347 | else { /* not a table; check metamethod */ | |||
348 | ✗ | tm = luaT_gettmbyobj(L, t, TM_NEWINDEX); | ||
349 | ✗ | if (l_unlikely(notm(tm))) | ||
350 | ✗ | luaG_typeerror(L, t, "index"); | ||
351 | } | |||
352 | /* try the metamethod */ | |||
353 | ✗ | if (ttisfunction(tm)) { | ||
354 | ✗ | luaT_callTM(L, tm, t, key, val); | ||
355 | ✗ | return; | ||
356 | } | |||
357 | ✗ | t = tm; /* else repeat assignment over 'tm' */ | ||
358 | ✗ | if (luaV_fastget(L, t, key, slot, luaH_get)) { | ||
359 | ✗ | luaV_finishfastset(L, t, slot, val); | ||
360 | ✗ | return; /* done */ | ||
361 | } | |||
362 | /* else 'return luaV_finishset(L, t, key, val, slot)' (loop) */ | |||
363 | } | |||
364 | ✗ | luaG_runerror(L, "'__newindex' chain too long; possible loop"); | ||
365 | } | |||
366 | ||||
367 | ||||
368 | /* | |||
369 | ** Compare two strings 'ls' x 'rs', returning an integer less-equal- | |||
370 | ** -greater than zero if 'ls' is less-equal-greater than 'rs'. | |||
371 | ** The code is a little tricky because it allows '\0' in the strings | |||
372 | ** and it uses 'strcoll' (to respect locales) for each segments | |||
373 | ** of the strings. | |||
374 | */ | |||
375 | ✗ | static int l_strcmp (const TString *ls, const TString *rs) { | ||
376 | ✗ | const char *l = getstr(ls); | ||
377 | ✗ | size_t ll = tsslen(ls); | ||
378 | ✗ | const char *r = getstr(rs); | ||
379 | ✗ | size_t lr = tsslen(rs); | ||
380 | ✗ | for (;;) { /* for each segment */ | ||
381 | ✗ | int temp = strcoll(l, r); | ||
382 | ✗ | if (temp != 0) /* not equal? */ | ||
383 | ✗ | return temp; /* done */ | ||
384 | else { /* strings are equal up to a '\0' */ | |||
385 | ✗ | size_t len = strlen(l); /* index of first '\0' in both strings */ | ||
386 | ✗ | if (len == lr) /* 'rs' is finished? */ | ||
387 | ✗ | return (len == ll) ? 0 : 1; /* check 'ls' */ | ||
388 | ✗ | else if (len == ll) /* 'ls' is finished? */ | ||
389 | ✗ | return -1; /* 'ls' is less than 'rs' ('rs' is not finished) */ | ||
390 | /* both strings longer than 'len'; go on comparing after the '\0' */ | |||
391 | ✗ | len++; | ||
392 | ✗ | l += len; ll -= len; r += len; lr -= len; | ||
393 | } | |||
394 | } | |||
395 | } | |||
396 | ||||
397 | ||||
398 | /* | |||
399 | ** Check whether integer 'i' is less than float 'f'. If 'i' has an | |||
400 | ** exact representation as a float ('l_intfitsf'), compare numbers as | |||
401 | ** floats. Otherwise, use the equivalence 'i < f <=> i < ceil(f)'. | |||
402 | ** If 'ceil(f)' is out of integer range, either 'f' is greater than | |||
403 | ** all integers or less than all integers. | |||
404 | ** (The test with 'l_intfitsf' is only for performance; the else | |||
405 | ** case is correct for all values, but it is slow due to the conversion | |||
406 | ** from float to int.) | |||
407 | ** When 'f' is NaN, comparisons must result in false. | |||
408 | */ | |||
409 | ✗ | l_sinline int LTintfloat (lua_Integer i, lua_Number f) { | ||
410 | ✗ | if (l_intfitsf(i)) | ||
411 | ✗ | return luai_numlt(cast_num(i), f); /* compare them as floats */ | ||
412 | else { /* i < f <=> i < ceil(f) */ | |||
413 | lua_Integer fi; | |||
414 | ✗ | if (luaV_flttointeger(f, &fi, F2Iceil)) /* fi = ceil(f) */ | ||
415 | ✗ | return i < fi; /* compare them as integers */ | ||
416 | else /* 'f' is either greater or less than all integers */ | |||
417 | ✗ | return f > 0; /* greater? */ | ||
418 | } | |||
419 | } | |||
420 | ||||
421 | ||||
422 | /* | |||
423 | ** Check whether integer 'i' is less than or equal to float 'f'. | |||
424 | ** See comments on previous function. | |||
425 | */ | |||
426 | ✗ | l_sinline int LEintfloat (lua_Integer i, lua_Number f) { | ||
427 | ✗ | if (l_intfitsf(i)) | ||
428 | ✗ | return luai_numle(cast_num(i), f); /* compare them as floats */ | ||
429 | else { /* i <= f <=> i <= floor(f) */ | |||
430 | lua_Integer fi; | |||
431 | ✗ | if (luaV_flttointeger(f, &fi, F2Ifloor)) /* fi = floor(f) */ | ||
432 | ✗ | return i <= fi; /* compare them as integers */ | ||
433 | else /* 'f' is either greater or less than all integers */ | |||
434 | ✗ | return f > 0; /* greater? */ | ||
435 | } | |||
436 | } | |||
437 | ||||
438 | ||||
439 | /* | |||
440 | ** Check whether float 'f' is less than integer 'i'. | |||
441 | ** See comments on previous function. | |||
442 | */ | |||
443 | ✗ | l_sinline int LTfloatint (lua_Number f, lua_Integer i) { | ||
444 | ✗ | if (l_intfitsf(i)) | ||
445 | ✗ | return luai_numlt(f, cast_num(i)); /* compare them as floats */ | ||
446 | else { /* f < i <=> floor(f) < i */ | |||
447 | lua_Integer fi; | |||
448 | ✗ | if (luaV_flttointeger(f, &fi, F2Ifloor)) /* fi = floor(f) */ | ||
449 | ✗ | return fi < i; /* compare them as integers */ | ||
450 | else /* 'f' is either greater or less than all integers */ | |||
451 | ✗ | return f < 0; /* less? */ | ||
452 | } | |||
453 | } | |||
454 | ||||
455 | ||||
456 | /* | |||
457 | ** Check whether float 'f' is less than or equal to integer 'i'. | |||
458 | ** See comments on previous function. | |||
459 | */ | |||
460 | ✗ | l_sinline int LEfloatint (lua_Number f, lua_Integer i) { | ||
461 | ✗ | if (l_intfitsf(i)) | ||
462 | ✗ | return luai_numle(f, cast_num(i)); /* compare them as floats */ | ||
463 | else { /* f <= i <=> ceil(f) <= i */ | |||
464 | lua_Integer fi; | |||
465 | ✗ | if (luaV_flttointeger(f, &fi, F2Iceil)) /* fi = ceil(f) */ | ||
466 | ✗ | return fi <= i; /* compare them as integers */ | ||
467 | else /* 'f' is either greater or less than all integers */ | |||
468 | ✗ | return f < 0; /* less? */ | ||
469 | } | |||
470 | } | |||
471 | ||||
472 | ||||
473 | /* | |||
474 | ** Return 'l < r', for numbers. | |||
475 | */ | |||
476 | 2 | l_sinline int LTnum (const TValue *l, const TValue *r) { | ||
477 | lua_assert(ttisnumber(l) && ttisnumber(r)); | |||
478 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (ttisinteger(l)) { | |
479 | 2 | lua_Integer li = ivalue(l); | ||
480 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (ttisinteger(r)) | |
481 | 2 | return li < ivalue(r); /* both are integers */ | ||
482 | else /* 'l' is int and 'r' is float */ | |||
483 | ✗ | return LTintfloat(li, fltvalue(r)); /* l < r ? */ | ||
484 | } | |||
485 | else { | |||
486 | ✗ | lua_Number lf = fltvalue(l); /* 'l' must be float */ | ||
487 | ✗ | if (ttisfloat(r)) | ||
488 | ✗ | return luai_numlt(lf, fltvalue(r)); /* both are float */ | ||
489 | else /* 'l' is float and 'r' is int */ | |||
490 | ✗ | return LTfloatint(lf, ivalue(r)); | ||
491 | } | |||
492 | } | |||
493 | ||||
494 | ||||
495 | /* | |||
496 | ** Return 'l <= r', for numbers. | |||
497 | */ | |||
498 | ✗ | l_sinline int LEnum (const TValue *l, const TValue *r) { | ||
499 | lua_assert(ttisnumber(l) && ttisnumber(r)); | |||
500 | ✗ | if (ttisinteger(l)) { | ||
501 | ✗ | lua_Integer li = ivalue(l); | ||
502 | ✗ | if (ttisinteger(r)) | ||
503 | ✗ | return li <= ivalue(r); /* both are integers */ | ||
504 | else /* 'l' is int and 'r' is float */ | |||
505 | ✗ | return LEintfloat(li, fltvalue(r)); /* l <= r ? */ | ||
506 | } | |||
507 | else { | |||
508 | ✗ | lua_Number lf = fltvalue(l); /* 'l' must be float */ | ||
509 | ✗ | if (ttisfloat(r)) | ||
510 | ✗ | return luai_numle(lf, fltvalue(r)); /* both are float */ | ||
511 | else /* 'l' is float and 'r' is int */ | |||
512 | ✗ | return LEfloatint(lf, ivalue(r)); | ||
513 | } | |||
514 | } | |||
515 | ||||
516 | ||||
517 | /* | |||
518 | ** return 'l < r' for non-numbers. | |||
519 | */ | |||
520 | ✗ | static int lessthanothers (lua_State *L, const TValue *l, const TValue *r) { | ||
521 | lua_assert(!ttisnumber(l) || !ttisnumber(r)); | |||
522 | ✗ | if (ttisstring(l) && ttisstring(r)) /* both are strings? */ | ||
523 | ✗ | return l_strcmp(tsvalue(l), tsvalue(r)) < 0; | ||
524 | else | |||
525 | ✗ | return luaT_callorderTM(L, l, r, TM_LT); | ||
526 | } | |||
527 | ||||
528 | ||||
529 | /* | |||
530 | ** Main operation less than; return 'l < r'. | |||
531 | */ | |||
532 | 2 | int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { | ||
533 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | if (ttisnumber(l) && ttisnumber(r)) /* both operands are numbers? */ | |
534 | 2 | return LTnum(l, r); | ||
535 | ✗ | else return lessthanothers(L, l, r); | ||
536 | } | |||
537 | ||||
538 | ||||
539 | /* | |||
540 | ** return 'l <= r' for non-numbers. | |||
541 | */ | |||
542 | ✗ | static int lessequalothers (lua_State *L, const TValue *l, const TValue *r) { | ||
543 | lua_assert(!ttisnumber(l) || !ttisnumber(r)); | |||
544 | ✗ | if (ttisstring(l) && ttisstring(r)) /* both are strings? */ | ||
545 | ✗ | return l_strcmp(tsvalue(l), tsvalue(r)) <= 0; | ||
546 | else | |||
547 | ✗ | return luaT_callorderTM(L, l, r, TM_LE); | ||
548 | } | |||
549 | ||||
550 | ||||
551 | /* | |||
552 | ** Main operation less than or equal to; return 'l <= r'. | |||
553 | */ | |||
554 | ✗ | int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { | ||
555 | ✗ | if (ttisnumber(l) && ttisnumber(r)) /* both operands are numbers? */ | ||
556 | ✗ | return LEnum(l, r); | ||
557 | ✗ | else return lessequalothers(L, l, r); | ||
558 | } | |||
559 | ||||
560 | ||||
561 | /* | |||
562 | ** Main operation for equality of Lua values; return 't1 == t2'. | |||
563 | ** L == NULL means raw equality (no metamethods) | |||
564 | */ | |||
565 | 881 | int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { | ||
566 | const TValue *tm; | |||
567 |
2/2✓ Branch 0 taken 198 times.
✓ Branch 1 taken 683 times.
|
881 | if (ttypetag(t1) != ttypetag(t2)) { /* not the same variant? */ | |
568 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
198 | if (ttype(t1) != ttype(t2) || ttype(t1) != LUA_TNUMBER) | |
569 | 198 | return 0; /* only numbers can be equal with different variants */ | ||
570 | else { /* two numbers with different variants */ | |||
571 | /* One of them is an integer. If the other does not have an | |||
572 | integer value, they cannot be equal; otherwise, compare their | |||
573 | integer values. */ | |||
574 | lua_Integer i1, i2; | |||
575 | ✗ | return (luaV_tointegerns(t1, &i1, F2Ieq) && | ||
576 | ✗ | luaV_tointegerns(t2, &i2, F2Ieq) && | ||
577 | ✗ | i1 == i2); | ||
578 | } | |||
579 | } | |||
580 | /* values have same type and same variant */ | |||
581 |
5/10✓ Branch 0 taken 82 times.
✓ Branch 1 taken 147 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 401 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 46 times.
✗ Branch 9 not taken.
|
683 | switch (ttypetag(t1)) { | |
582 | 82 | case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: return 1; | ||
583 | 147 | case LUA_VNUMINT: return (ivalue(t1) == ivalue(t2)); | ||
584 | 7 | case LUA_VNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2)); | ||
585 | ✗ | case LUA_VLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); | ||
586 | ✗ | case LUA_VLCF: return fvalue(t1) == fvalue(t2); | ||
587 | 401 | case LUA_VSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2)); | ||
588 | ✗ | case LUA_VLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2)); | ||
589 | ✗ | case LUA_VUSERDATA: { | ||
590 | ✗ | if (uvalue(t1) == uvalue(t2)) return 1; | ||
591 | ✗ | else if (L == NULL) return 0; | ||
592 | ✗ | tm = fasttm(L, uvalue(t1)->metatable, TM_EQ); | ||
593 | ✗ | if (tm == NULL) | ||
594 | ✗ | tm = fasttm(L, uvalue(t2)->metatable, TM_EQ); | ||
595 | ✗ | break; /* will try TM */ | ||
596 | } | |||
597 | 46 | case LUA_VTABLE: { | ||
598 |
1/2✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
|
46 | if (hvalue(t1) == hvalue(t2)) return 1; | |
599 | ✗ | else if (L == NULL) return 0; | ||
600 | ✗ | tm = fasttm(L, hvalue(t1)->metatable, TM_EQ); | ||
601 | ✗ | if (tm == NULL) | ||
602 | ✗ | tm = fasttm(L, hvalue(t2)->metatable, TM_EQ); | ||
603 | ✗ | break; /* will try TM */ | ||
604 | } | |||
605 | ✗ | default: | ||
606 | ✗ | return gcvalue(t1) == gcvalue(t2); | ||
607 | } | |||
608 | ✗ | if (tm == NULL) /* no TM? */ | ||
609 | ✗ | return 0; /* objects are different */ | ||
610 | else { | |||
611 | ✗ | luaT_callTMres(L, tm, t1, t2, L->top.p); /* call TM */ | ||
612 | ✗ | return !l_isfalse(s2v(L->top.p)); | ||
613 | } | |||
614 | } | |||
615 | ||||
616 | ||||
617 | /* macro used by 'luaV_concat' to ensure that element at 'o' is a string */ | |||
618 | #define tostring(L,o) \ | |||
619 | (ttisstring(o) || (cvt2str(o) && (luaO_tostring(L, o), 1))) | |||
620 | ||||
621 | #define isemptystr(o) (ttisshrstring(o) && tsvalue(o)->shrlen == 0) | |||
622 | ||||
623 | /* copy strings in stack from top - n up to top - 1 to buffer */ | |||
624 | 118 | static void copy2buff (StkId top, int n, char *buff) { | ||
625 | 118 | size_t tl = 0; /* size already copied */ | ||
626 | do { | |||
627 |
2/2✓ Branch 0 taken 301 times.
✓ Branch 1 taken 8 times.
|
309 | size_t l = vslen(s2v(top - n)); /* length of string being copied */ | |
628 | 309 | memcpy(buff + tl, svalue(s2v(top - n)), l * sizeof(char)); | ||
629 | 309 | tl += l; | ||
630 |
2/2✓ Branch 0 taken 191 times.
✓ Branch 1 taken 118 times.
|
309 | } while (--n > 0); | |
631 | 118 | } | ||
632 | ||||
633 | ||||
634 | /* | |||
635 | ** Main operation for concatenation: concat 'total' values in the stack, | |||
636 | ** from 'L->top.p - total' up to 'L->top.p - 1'. | |||
637 | */ | |||
638 | 152 | void luaV_concat (lua_State *L, int total) { | ||
639 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
|
152 | if (total == 1) | |
640 | ✗ | return; /* "all" values already concatenated */ | ||
641 | do { | |||
642 | 152 | StkId top = L->top.p; | ||
643 | 152 | int n = 2; /* number of elements handled in this pass (at least 2) */ | ||
644 |
3/4✓ Branch 0 taken 42 times.
✓ Branch 1 taken 110 times.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
|
152 | if (!(ttisstring(s2v(top - 2)) || cvt2str(s2v(top - 2))) || | |
645 |
3/4✓ Branch 0 taken 19 times.
✓ Branch 1 taken 133 times.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
|
152 | !tostring(L, s2v(top - 1))) | |
646 | ✗ | luaT_tryconcatTM(L); /* may invalidate 'top' */ | ||
647 |
4/4✓ Branch 0 taken 147 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 34 times.
✓ Branch 3 taken 113 times.
|
152 | else if (isemptystr(s2v(top - 1))) /* second operand is empty? */ | |
648 |
3/4✓ Branch 0 taken 23 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
|
34 | cast_void(tostring(L, s2v(top - 2))); /* result is first operand */ | |
649 |
3/4✓ Branch 0 taken 96 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96 times.
|
118 | else if (isemptystr(s2v(top - 2))) { /* first operand is empty string? */ | |
650 | ✗ | setobjs2s(L, top - 2, top - 1); /* result is second op. */ | ||
651 | } | |||
652 | else { | |||
653 | /* at least two non-empty string values; get as many as possible */ | |||
654 |
2/2✓ Branch 0 taken 113 times.
✓ Branch 1 taken 5 times.
|
118 | size_t tl = vslen(s2v(top - 1)); | |
655 | TString *ts; | |||
656 | /* collect total length and number of strings */ | |||
657 |
5/6✓ Branch 0 taken 191 times.
✓ Branch 1 taken 118 times.
✓ Branch 2 taken 168 times.
✓ Branch 3 taken 23 times.
✓ Branch 4 taken 23 times.
✗ Branch 5 not taken.
|
309 | for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) { | |
658 |
2/2✓ Branch 0 taken 188 times.
✓ Branch 1 taken 3 times.
|
191 | size_t l = vslen(s2v(top - n - 1)); | |
659 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 191 times.
|
191 | if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) { | |
660 | ✗ | L->top.p = top - total; /* pop strings to avoid wasting stack */ | ||
661 | ✗ | luaG_runerror(L, "string length overflow"); | ||
662 | } | |||
663 | 191 | tl += l; | ||
664 | } | |||
665 |
2/2✓ Branch 0 taken 110 times.
✓ Branch 1 taken 8 times.
|
118 | if (tl <= LUAI_MAXSHORTLEN) { /* is result a short string? */ | |
666 | char buff[LUAI_MAXSHORTLEN]; | |||
667 | 110 | copy2buff(top, n, buff); /* copy strings to buffer */ | ||
668 | 110 | ts = luaS_newlstr(L, buff, tl); | ||
669 | } | |||
670 | else { /* long string; copy strings directly to final result */ | |||
671 | 8 | ts = luaS_createlngstrobj(L, tl); | ||
672 | 8 | copy2buff(top, n, getstr(ts)); | ||
673 | } | |||
674 | 118 | setsvalue2s(L, top - n, ts); /* create result */ | ||
675 | } | |||
676 | 152 | total -= n - 1; /* got 'n' strings to create one new */ | ||
677 | 152 | L->top.p -= n - 1; /* popped 'n' strings and pushed one */ | ||
678 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 152 times.
|
152 | } while (total > 1); /* repeat until only 1 result left */ | |
679 | } | |||
680 | ||||
681 | ||||
682 | /* | |||
683 | ** Main operation 'ra = #rb'. | |||
684 | */ | |||
685 | ✗ | void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { | ||
686 | const TValue *tm; | |||
687 | ✗ | switch (ttypetag(rb)) { | ||
688 | ✗ | case LUA_VTABLE: { | ||
689 | ✗ | Table *h = hvalue(rb); | ||
690 | ✗ | tm = fasttm(L, h->metatable, TM_LEN); | ||
691 | ✗ | if (tm) break; /* metamethod? break switch to call it */ | ||
692 | ✗ | setivalue(s2v(ra), luaH_getn(h)); /* else primitive len */ | ||
693 | ✗ | return; | ||
694 | } | |||
695 | ✗ | case LUA_VSHRSTR: { | ||
696 | ✗ | setivalue(s2v(ra), tsvalue(rb)->shrlen); | ||
697 | ✗ | return; | ||
698 | } | |||
699 | ✗ | case LUA_VLNGSTR: { | ||
700 | ✗ | setivalue(s2v(ra), tsvalue(rb)->u.lnglen); | ||
701 | ✗ | return; | ||
702 | } | |||
703 | ✗ | default: { /* try metamethod */ | ||
704 | ✗ | tm = luaT_gettmbyobj(L, rb, TM_LEN); | ||
705 | ✗ | if (l_unlikely(notm(tm))) /* no metamethod? */ | ||
706 | ✗ | luaG_typeerror(L, rb, "get length of"); | ||
707 | ✗ | break; | ||
708 | } | |||
709 | } | |||
710 | ✗ | luaT_callTMres(L, tm, rb, rb, ra); | ||
711 | } | |||
712 | ||||
713 | ||||
714 | /* | |||
715 | ** Integer division; return 'm // n', that is, floor(m/n). | |||
716 | ** C division truncates its result (rounds towards zero). | |||
717 | ** 'floor(q) == trunc(q)' when 'q >= 0' or when 'q' is integer, | |||
718 | ** otherwise 'floor(q) == trunc(q) - 1'. | |||
719 | */ | |||
720 | ✗ | lua_Integer luaV_idiv (lua_State *L, lua_Integer m, lua_Integer n) { | ||
721 | ✗ | if (l_unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */ | ||
722 | ✗ | if (n == 0) | ||
723 | ✗ | luaG_runerror(L, "attempt to divide by zero"); | ||
724 | ✗ | return intop(-, 0, m); /* n==-1; avoid overflow with 0x80000...//-1 */ | ||
725 | } | |||
726 | else { | |||
727 | ✗ | lua_Integer q = m / n; /* perform C division */ | ||
728 | ✗ | if ((m ^ n) < 0 && m % n != 0) /* 'm/n' would be negative non-integer? */ | ||
729 | ✗ | q -= 1; /* correct result for different rounding */ | ||
730 | ✗ | return q; | ||
731 | } | |||
732 | } | |||
733 | ||||
734 | ||||
735 | /* | |||
736 | ** Integer modulus; return 'm % n'. (Assume that C '%' with | |||
737 | ** negative operands follows C99 behavior. See previous comment | |||
738 | ** about luaV_idiv.) | |||
739 | */ | |||
740 | 81 | lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) { | ||
741 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 81 times.
|
81 | if (l_unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */ | |
742 | ✗ | if (n == 0) | ||
743 | ✗ | luaG_runerror(L, "attempt to perform 'n%%0'"); | ||
744 | ✗ | return 0; /* m % -1 == 0; avoid overflow with 0x80000...%-1 */ | ||
745 | } | |||
746 | else { | |||
747 | 81 | lua_Integer r = m % n; | ||
748 |
4/4✓ Branch 0 taken 68 times.
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 67 times.
|
81 | if (r != 0 && (r ^ n) < 0) /* 'm/n' would be non-integer negative? */ | |
749 | 1 | r += n; /* correct result for different rounding */ | ||
750 | 81 | return r; | ||
751 | } | |||
752 | } | |||
753 | ||||
754 | ||||
755 | /* | |||
756 | ** Float modulus | |||
757 | */ | |||
758 | ✗ | lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) { | ||
759 | lua_Number r; | |||
760 | ✗ | luai_nummod(L, m, n, r); | ||
761 | ✗ | return r; | ||
762 | } | |||
763 | ||||
764 | ||||
765 | /* number of bits in an integer */ | |||
766 | #define NBITS cast_int(sizeof(lua_Integer) * CHAR_BIT) | |||
767 | ||||
768 | ||||
769 | /* | |||
770 | ** Shift left operation. (Shift right just negates 'y'.) | |||
771 | */ | |||
772 | 220 | lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) { | ||
773 |
2/2✓ Branch 0 taken 81 times.
✓ Branch 1 taken 139 times.
|
220 | if (y < 0) { /* shift right? */ | |
774 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 81 times.
|
81 | if (y <= -NBITS) return 0; | |
775 | 81 | else return intop(>>, x, -y); | ||
776 | } | |||
777 | else { /* shift left */ | |||
778 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 139 times.
|
139 | if (y >= NBITS) return 0; | |
779 | 139 | else return intop(<<, x, y); | ||
780 | } | |||
781 | } | |||
782 | ||||
783 | ||||
784 | /* | |||
785 | ** create a new Lua closure, push it in the stack, and initialize | |||
786 | ** its upvalues. | |||
787 | */ | |||
788 | 215 | static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base, | ||
789 | StkId ra) { | |||
790 | 215 | int nup = p->sizeupvalues; | ||
791 | 215 | Upvaldesc *uv = p->upvalues; | ||
792 | int i; | |||
793 | 215 | LClosure *ncl = luaF_newLclosure(L, nup); | ||
794 | 215 | ncl->p = p; | ||
795 | 215 | setclLvalue2s(L, ra, ncl); /* anchor new closure in stack */ | ||
796 |
2/2✓ Branch 0 taken 150 times.
✓ Branch 1 taken 215 times.
|
365 | for (i = 0; i < nup; i++) { /* fill in its upvalues */ | |
797 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 150 times.
|
150 | if (uv[i].instack) /* upvalue refers to local variable? */ | |
798 | ✗ | ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx); | ||
799 | else /* get upvalue from enclosing function */ | |||
800 | 150 | ncl->upvals[i] = encup[uv[i].idx]; | ||
801 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 150 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
150 | luaC_objbarrier(L, ncl, ncl->upvals[i]); | |
802 | } | |||
803 | 215 | } | ||
804 | ||||
805 | ||||
806 | /* | |||
807 | ** finish execution of an opcode interrupted by a yield | |||
808 | */ | |||
809 | ✗ | void luaV_finishOp (lua_State *L) { | ||
810 | ✗ | CallInfo *ci = L->ci; | ||
811 | ✗ | StkId base = ci->func.p + 1; | ||
812 | ✗ | Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */ | ||
813 | ✗ | OpCode op = GET_OPCODE(inst); | ||
814 | ✗ | switch (op) { /* finish its execution */ | ||
815 | ✗ | case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: { | ||
816 | ✗ | setobjs2s(L, base + GETARG_A(*(ci->u.l.savedpc - 2)), --L->top.p); | ||
817 | ✗ | break; | ||
818 | } | |||
819 | ✗ | case OP_UNM: case OP_BNOT: case OP_LEN: | ||
820 | case OP_GETTABUP: case OP_GETTABLE: case OP_GETI: | |||
821 | case OP_GETFIELD: case OP_SELF: { | |||
822 | ✗ | setobjs2s(L, base + GETARG_A(inst), --L->top.p); | ||
823 | ✗ | break; | ||
824 | } | |||
825 | ✗ | case OP_LT: case OP_LE: | ||
826 | case OP_LTI: case OP_LEI: | |||
827 | case OP_GTI: case OP_GEI: | |||
828 | case OP_EQ: { /* note that 'OP_EQI'/'OP_EQK' cannot yield */ | |||
829 | ✗ | int res = !l_isfalse(s2v(L->top.p - 1)); | ||
830 | ✗ | L->top.p--; | ||
831 | #if defined(LUA_COMPAT_LT_LE) | |||
832 | if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ | |||
833 | ci->callstatus ^= CIST_LEQ; /* clear mark */ | |||
834 | res = !res; /* negate result */ | |||
835 | } | |||
836 | #endif | |||
837 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); | |||
838 | ✗ | if (res != GETARG_k(inst)) /* condition failed? */ | ||
839 | ✗ | ci->u.l.savedpc++; /* skip jump instruction */ | ||
840 | ✗ | break; | ||
841 | } | |||
842 | ✗ | case OP_CONCAT: { | ||
843 | ✗ | StkId top = L->top.p - 1; /* top when 'luaT_tryconcatTM' was called */ | ||
844 | ✗ | int a = GETARG_A(inst); /* first element to concatenate */ | ||
845 | ✗ | int total = cast_int(top - 1 - (base + a)); /* yet to concatenate */ | ||
846 | ✗ | setobjs2s(L, top - 2, top); /* put TM result in proper position */ | ||
847 | ✗ | L->top.p = top - 1; /* top is one after last element (at top-2) */ | ||
848 | ✗ | luaV_concat(L, total); /* concat them (may yield again) */ | ||
849 | ✗ | break; | ||
850 | } | |||
851 | ✗ | case OP_CLOSE: { /* yielded closing variables */ | ||
852 | ✗ | ci->u.l.savedpc--; /* repeat instruction to close other vars. */ | ||
853 | ✗ | break; | ||
854 | } | |||
855 | ✗ | case OP_RETURN: { /* yielded closing variables */ | ||
856 | ✗ | StkId ra = base + GETARG_A(inst); | ||
857 | /* adjust top to signal correct number of returns, in case the | |||
858 | return is "up to top" ('isIT') */ | |||
859 | ✗ | L->top.p = ra + ci->u2.nres; | ||
860 | /* repeat instruction to close other vars. and complete the return */ | |||
861 | ✗ | ci->u.l.savedpc--; | ||
862 | ✗ | break; | ||
863 | } | |||
864 | ✗ | default: { | ||
865 | /* only these other opcodes can yield */ | |||
866 | lua_assert(op == OP_TFORCALL || op == OP_CALL || | |||
867 | op == OP_TAILCALL || op == OP_SETTABUP || op == OP_SETTABLE || | |||
868 | op == OP_SETI || op == OP_SETFIELD); | |||
869 | ✗ | break; | ||
870 | } | |||
871 | } | |||
872 | ✗ | } | ||
873 | ||||
874 | ||||
875 | ||||
876 | ||||
877 | /* | |||
878 | ** {================================================================== | |||
879 | ** Macros for arithmetic/bitwise/comparison opcodes in 'luaV_execute' | |||
880 | ** =================================================================== | |||
881 | */ | |||
882 | ||||
883 | #define l_addi(L,a,b) intop(+, a, b) | |||
884 | #define l_subi(L,a,b) intop(-, a, b) | |||
885 | #define l_muli(L,a,b) intop(*, a, b) | |||
886 | #define l_band(a,b) intop(&, a, b) | |||
887 | #define l_bor(a,b) intop(|, a, b) | |||
888 | #define l_bxor(a,b) intop(^, a, b) | |||
889 | ||||
890 | #define l_lti(a,b) (a < b) | |||
891 | #define l_lei(a,b) (a <= b) | |||
892 | #define l_gti(a,b) (a > b) | |||
893 | #define l_gei(a,b) (a >= b) | |||
894 | ||||
895 | ||||
896 | /* | |||
897 | ** Arithmetic operations with immediate operands. 'iop' is the integer | |||
898 | ** operation, 'fop' is the float operation. | |||
899 | */ | |||
900 | #define op_arithI(L,iop,fop) { \ | |||
901 | StkId ra = RA(i); \ | |||
902 | TValue *v1 = vRB(i); \ | |||
903 | int imm = GETARG_sC(i); \ | |||
904 | if (ttisinteger(v1)) { \ | |||
905 | lua_Integer iv1 = ivalue(v1); \ | |||
906 | pc++; setivalue(s2v(ra), iop(L, iv1, imm)); \ | |||
907 | } \ | |||
908 | else if (ttisfloat(v1)) { \ | |||
909 | lua_Number nb = fltvalue(v1); \ | |||
910 | lua_Number fimm = cast_num(imm); \ | |||
911 | pc++; setfltvalue(s2v(ra), fop(L, nb, fimm)); \ | |||
912 | }} | |||
913 | ||||
914 | ||||
915 | /* | |||
916 | ** Auxiliary function for arithmetic operations over floats and others | |||
917 | ** with two register operands. | |||
918 | */ | |||
919 | #define op_arithf_aux(L,v1,v2,fop) { \ | |||
920 | lua_Number n1; lua_Number n2; \ | |||
921 | if (tonumberns(v1, n1) && tonumberns(v2, n2)) { \ | |||
922 | pc++; setfltvalue(s2v(ra), fop(L, n1, n2)); \ | |||
923 | }} | |||
924 | ||||
925 | ||||
926 | /* | |||
927 | ** Arithmetic operations over floats and others with register operands. | |||
928 | */ | |||
929 | #define op_arithf(L,fop) { \ | |||
930 | StkId ra = RA(i); \ | |||
931 | TValue *v1 = vRB(i); \ | |||
932 | TValue *v2 = vRC(i); \ | |||
933 | op_arithf_aux(L, v1, v2, fop); } | |||
934 | ||||
935 | ||||
936 | /* | |||
937 | ** Arithmetic operations with K operands for floats. | |||
938 | */ | |||
939 | #define op_arithfK(L,fop) { \ | |||
940 | StkId ra = RA(i); \ | |||
941 | TValue *v1 = vRB(i); \ | |||
942 | TValue *v2 = KC(i); lua_assert(ttisnumber(v2)); \ | |||
943 | op_arithf_aux(L, v1, v2, fop); } | |||
944 | ||||
945 | ||||
946 | /* | |||
947 | ** Arithmetic operations over integers and floats. | |||
948 | */ | |||
949 | #define op_arith_aux(L,v1,v2,iop,fop) { \ | |||
950 | StkId ra = RA(i); \ | |||
951 | if (ttisinteger(v1) && ttisinteger(v2)) { \ | |||
952 | lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2); \ | |||
953 | pc++; setivalue(s2v(ra), iop(L, i1, i2)); \ | |||
954 | } \ | |||
955 | else op_arithf_aux(L, v1, v2, fop); } | |||
956 | ||||
957 | ||||
958 | /* | |||
959 | ** Arithmetic operations with register operands. | |||
960 | */ | |||
961 | #define op_arith(L,iop,fop) { \ | |||
962 | TValue *v1 = vRB(i); \ | |||
963 | TValue *v2 = vRC(i); \ | |||
964 | op_arith_aux(L, v1, v2, iop, fop); } | |||
965 | ||||
966 | ||||
967 | /* | |||
968 | ** Arithmetic operations with K operands. | |||
969 | */ | |||
970 | #define op_arithK(L,iop,fop) { \ | |||
971 | TValue *v1 = vRB(i); \ | |||
972 | TValue *v2 = KC(i); lua_assert(ttisnumber(v2)); \ | |||
973 | op_arith_aux(L, v1, v2, iop, fop); } | |||
974 | ||||
975 | ||||
976 | /* | |||
977 | ** Bitwise operations with constant operand. | |||
978 | */ | |||
979 | #define op_bitwiseK(L,op) { \ | |||
980 | StkId ra = RA(i); \ | |||
981 | TValue *v1 = vRB(i); \ | |||
982 | TValue *v2 = KC(i); \ | |||
983 | lua_Integer i1; \ | |||
984 | lua_Integer i2 = ivalue(v2); \ | |||
985 | if (tointegerns(v1, &i1)) { \ | |||
986 | pc++; setivalue(s2v(ra), op(i1, i2)); \ | |||
987 | }} | |||
988 | ||||
989 | ||||
990 | /* | |||
991 | ** Bitwise operations with register operands. | |||
992 | */ | |||
993 | #define op_bitwise(L,op) { \ | |||
994 | StkId ra = RA(i); \ | |||
995 | TValue *v1 = vRB(i); \ | |||
996 | TValue *v2 = vRC(i); \ | |||
997 | lua_Integer i1; lua_Integer i2; \ | |||
998 | if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) { \ | |||
999 | pc++; setivalue(s2v(ra), op(i1, i2)); \ | |||
1000 | }} | |||
1001 | ||||
1002 | ||||
1003 | /* | |||
1004 | ** Order operations with register operands. 'opn' actually works | |||
1005 | ** for all numbers, but the fast track improves performance for | |||
1006 | ** integers. | |||
1007 | */ | |||
1008 | #define op_order(L,opi,opn,other) { \ | |||
1009 | StkId ra = RA(i); \ | |||
1010 | int cond; \ | |||
1011 | TValue *rb = vRB(i); \ | |||
1012 | if (ttisinteger(s2v(ra)) && ttisinteger(rb)) { \ | |||
1013 | lua_Integer ia = ivalue(s2v(ra)); \ | |||
1014 | lua_Integer ib = ivalue(rb); \ | |||
1015 | cond = opi(ia, ib); \ | |||
1016 | } \ | |||
1017 | else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) \ | |||
1018 | cond = opn(s2v(ra), rb); \ | |||
1019 | else \ | |||
1020 | Protect(cond = other(L, s2v(ra), rb)); \ | |||
1021 | docondjump(); } | |||
1022 | ||||
1023 | ||||
1024 | /* | |||
1025 | ** Order operations with immediate operand. (Immediate operand is | |||
1026 | ** always small enough to have an exact representation as a float.) | |||
1027 | */ | |||
1028 | #define op_orderI(L,opi,opf,inv,tm) { \ | |||
1029 | StkId ra = RA(i); \ | |||
1030 | int cond; \ | |||
1031 | int im = GETARG_sB(i); \ | |||
1032 | if (ttisinteger(s2v(ra))) \ | |||
1033 | cond = opi(ivalue(s2v(ra)), im); \ | |||
1034 | else if (ttisfloat(s2v(ra))) { \ | |||
1035 | lua_Number fa = fltvalue(s2v(ra)); \ | |||
1036 | lua_Number fim = cast_num(im); \ | |||
1037 | cond = opf(fa, fim); \ | |||
1038 | } \ | |||
1039 | else { \ | |||
1040 | int isf = GETARG_C(i); \ | |||
1041 | Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm)); \ | |||
1042 | } \ | |||
1043 | docondjump(); } | |||
1044 | ||||
1045 | /* }================================================================== */ | |||
1046 | ||||
1047 | ||||
1048 | /* | |||
1049 | ** {================================================================== | |||
1050 | ** Function 'luaV_execute': main interpreter loop | |||
1051 | ** =================================================================== | |||
1052 | */ | |||
1053 | ||||
1054 | /* | |||
1055 | ** some macros for common tasks in 'luaV_execute' | |||
1056 | */ | |||
1057 | ||||
1058 | ||||
1059 | #define RA(i) (base+GETARG_A(i)) | |||
1060 | #define RB(i) (base+GETARG_B(i)) | |||
1061 | #define vRB(i) s2v(RB(i)) | |||
1062 | #define KB(i) (k+GETARG_B(i)) | |||
1063 | #define RC(i) (base+GETARG_C(i)) | |||
1064 | #define vRC(i) s2v(RC(i)) | |||
1065 | #define KC(i) (k+GETARG_C(i)) | |||
1066 | #define RKC(i) ((TESTARG_k(i)) ? k + GETARG_C(i) : s2v(base + GETARG_C(i))) | |||
1067 | ||||
1068 | ||||
1069 | ||||
1070 | #define updatetrap(ci) (trap = ci->u.l.trap) | |||
1071 | ||||
1072 | #define updatebase(ci) (base = ci->func.p + 1) | |||
1073 | ||||
1074 | ||||
1075 | #define updatestack(ci) \ | |||
1076 | { if (l_unlikely(trap)) { updatebase(ci); ra = RA(i); } } | |||
1077 | ||||
1078 | ||||
1079 | /* | |||
1080 | ** Execute a jump instruction. The 'updatetrap' allows signals to stop | |||
1081 | ** tight loops. (Without it, the local copy of 'trap' could never change.) | |||
1082 | */ | |||
1083 | #define dojump(ci,i,e) { pc += GETARG_sJ(i) + e; updatetrap(ci); } | |||
1084 | ||||
1085 | ||||
1086 | /* for test instructions, execute the jump instruction that follows it */ | |||
1087 | #define donextjump(ci) { Instruction ni = *pc; dojump(ci, ni, 1); } | |||
1088 | ||||
1089 | /* | |||
1090 | ** do a conditional jump: skip next instruction if 'cond' is not what | |||
1091 | ** was expected (parameter 'k'), else do next instruction, which must | |||
1092 | ** be a jump. | |||
1093 | */ | |||
1094 | #define docondjump() if (cond != GETARG_k(i)) pc++; else donextjump(ci); | |||
1095 | ||||
1096 | ||||
1097 | /* | |||
1098 | ** Correct global 'pc'. | |||
1099 | */ | |||
1100 | #define savepc(L) (ci->u.l.savedpc = pc) | |||
1101 | ||||
1102 | ||||
1103 | /* | |||
1104 | ** Whenever code can raise errors, the global 'pc' and the global | |||
1105 | ** 'top' must be correct to report occasional errors. | |||
1106 | */ | |||
1107 | #define savestate(L,ci) (savepc(L), L->top.p = ci->top.p) | |||
1108 | ||||
1109 | ||||
1110 | /* | |||
1111 | ** Protect code that, in general, can raise errors, reallocate the | |||
1112 | ** stack, and change the hooks. | |||
1113 | */ | |||
1114 | #define Protect(exp) (savestate(L,ci), (exp), updatetrap(ci)) | |||
1115 | ||||
1116 | /* special version that does not change the top */ | |||
1117 | #define ProtectNT(exp) (savepc(L), (exp), updatetrap(ci)) | |||
1118 | ||||
1119 | /* | |||
1120 | ** Protect code that can only raise errors. (That is, it cannot change | |||
1121 | ** the stack or hooks.) | |||
1122 | */ | |||
1123 | #define halfProtect(exp) (savestate(L,ci), (exp)) | |||
1124 | ||||
1125 | /* 'c' is the limit of live values in the stack */ | |||
1126 | #define checkGC(L,c) \ | |||
1127 | { luaC_condGC(L, (savepc(L), L->top.p = (c)), \ | |||
1128 | updatetrap(ci)); \ | |||
1129 | luai_threadyield(L); } | |||
1130 | ||||
1131 | ||||
1132 | /* fetch an instruction and prepare its execution */ | |||
1133 | #define vmfetch() { \ | |||
1134 | if (l_unlikely(trap)) { /* stack reallocation or hooks? */ \ | |||
1135 | trap = luaG_traceexec(L, pc); /* handle hooks */ \ | |||
1136 | updatebase(ci); /* correct stack */ \ | |||
1137 | } \ | |||
1138 | i = *(pc++); \ | |||
1139 | } | |||
1140 | ||||
1141 | #define vmdispatch(o) switch(o) | |||
1142 | #define vmcase(l) case l: | |||
1143 | #define vmbreak break | |||
1144 | ||||
1145 | ||||
1146 | 406 | void luaV_execute (lua_State *L, CallInfo *ci) { | ||
1147 | LClosure *cl; | |||
1148 | TValue *k; | |||
1149 | StkId base; | |||
1150 | const Instruction *pc; | |||
1151 | int trap; | |||
1152 | #if LUA_USE_JUMPTABLE | |||
1153 | #include "ljumptab.h" | |||
1154 | #endif | |||
1155 | 191 | startfunc: | ||
1156 | 597 | trap = L->hookmask; | ||
1157 | 747 | returning: /* trap already set */ | ||
1158 | 747 | cl = clLvalue(s2v(ci->func.p)); | ||
1159 | 747 | k = cl->p->k; | ||
1160 | 747 | pc = ci->u.l.savedpc; | ||
1161 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 747 times.
|
747 | if (l_unlikely(trap)) { | |
1162 | ✗ | if (pc == cl->p->code) { /* first instruction (not resuming)? */ | ||
1163 | ✗ | if (cl->p->is_vararg) | ||
1164 | ✗ | trap = 0; /* hooks will start after VARARGPREP instruction */ | ||
1165 | else /* check 'call' hook */ | |||
1166 | ✗ | luaD_hookcall(L, ci); | ||
1167 | } | |||
1168 | ✗ | ci->u.l.trap = 1; /* assume trap is on, for now */ | ||
1169 | } | |||
1170 | 747 | base = ci->func.p + 1; | ||
1171 | /* main loop of interpreter */ | |||
1172 | for (;;) { | |||
1173 | Instruction i; /* instruction being executed */ | |||
1174 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 747 times.
|
747 | vmfetch(); | |
1175 | #if 0 | |||
1176 | /* low-level line tracing for debugging Lua */ | |||
1177 | printf("line: %d\n", luaG_getfuncline(cl->p, pcRel(pc, cl->p))); | |||
1178 | #endif | |||
1179 | lua_assert(base == ci->func.p + 1); | |||
1180 | lua_assert(base <= L->top.p && L->top.p <= L->stack_last.p); | |||
1181 | /* invalidate top for instructions not expecting it */ | |||
1182 | lua_assert(isIT(i) || (cast_void(L->top.p = base), 1)); | |||
1183 | 747 | vmdispatch (GET_OPCODE(i)) { | ||
1184 | 356 | vmcase(OP_MOVE) { | ||
1185 | 356 | StkId ra = RA(i); | ||
1186 | 356 | setobjs2s(L, ra, RB(i)); | ||
1187 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 356 times.
|
356 | vmbreak; | |
1188 | } | |||
1189 | 1035 | vmcase(OP_LOADI) { | ||
1190 | 1035 | StkId ra = RA(i); | ||
1191 | 1035 | lua_Integer b = GETARG_sBx(i); | ||
1192 | 1035 | setivalue(s2v(ra), b); | ||
1193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1035 times.
|
1035 | vmbreak; | |
1194 | } | |||
1195 | 4 | vmcase(OP_LOADF) { | ||
1196 | 4 | StkId ra = RA(i); | ||
1197 | 4 | int b = GETARG_sBx(i); | ||
1198 | 4 | setfltvalue(s2v(ra), cast_num(b)); | ||
1199 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | vmbreak; | |
1200 | } | |||
1201 | 280 | vmcase(OP_LOADK) { | ||
1202 | 280 | StkId ra = RA(i); | ||
1203 | 280 | TValue *rb = k + GETARG_Bx(i); | ||
1204 | 280 | setobj2s(L, ra, rb); | ||
1205 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 280 times.
|
280 | vmbreak; | |
1206 | } | |||
1207 | ✗ | vmcase(OP_LOADKX) { | ||
1208 | ✗ | StkId ra = RA(i); | ||
1209 | TValue *rb; | |||
1210 | ✗ | rb = k + GETARG_Ax(*pc); pc++; | ||
1211 | ✗ | setobj2s(L, ra, rb); | ||
1212 | ✗ | vmbreak; | ||
1213 | } | |||
1214 | 97 | vmcase(OP_LOADFALSE) { | ||
1215 | 97 | StkId ra = RA(i); | ||
1216 | 97 | setbfvalue(s2v(ra)); | ||
1217 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 97 times.
|
97 | vmbreak; | |
1218 | } | |||
1219 | 6 | vmcase(OP_LFALSESKIP) { | ||
1220 | 6 | StkId ra = RA(i); | ||
1221 | 6 | setbfvalue(s2v(ra)); | ||
1222 | 6 | pc++; /* skip next instruction */ | ||
1223 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | vmbreak; | |
1224 | } | |||
1225 | 102 | vmcase(OP_LOADTRUE) { | ||
1226 | 102 | StkId ra = RA(i); | ||
1227 | 102 | setbtvalue(s2v(ra)); | ||
1228 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 102 times.
|
102 | vmbreak; | |
1229 | } | |||
1230 | 2 | vmcase(OP_LOADNIL) { | ||
1231 | 2 | StkId ra = RA(i); | ||
1232 | 2 | int b = GETARG_B(i); | ||
1233 | do { | |||
1234 | 2 | setnilvalue(s2v(ra++)); | ||
1235 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | } while (b--); | |
1236 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | vmbreak; | |
1237 | } | |||
1238 | ✗ | vmcase(OP_GETUPVAL) { | ||
1239 | ✗ | StkId ra = RA(i); | ||
1240 | ✗ | int b = GETARG_B(i); | ||
1241 | ✗ | setobj2s(L, ra, cl->upvals[b]->v.p); | ||
1242 | ✗ | vmbreak; | ||
1243 | } | |||
1244 | ✗ | vmcase(OP_SETUPVAL) { | ||
1245 | ✗ | StkId ra = RA(i); | ||
1246 | ✗ | UpVal *uv = cl->upvals[GETARG_B(i)]; | ||
1247 | ✗ | setobj(L, uv->v.p, s2v(ra)); | ||
1248 | ✗ | luaC_barrier(L, uv, s2v(ra)); | ||
1249 | ✗ | vmbreak; | ||
1250 | } | |||
1251 | 1108 | vmcase(OP_GETTABUP) { | ||
1252 | 1108 | StkId ra = RA(i); | ||
1253 | const TValue *slot; | |||
1254 | 1108 | TValue *upval = cl->upvals[GETARG_B(i)]->v.p; | ||
1255 | 1108 | TValue *rc = KC(i); | ||
1256 | 1108 | TString *key = tsvalue(rc); /* key must be a string */ | ||
1257 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 1108 times.
✓ Branch 3 taken 1108 times.
✗ Branch 4 not taken.
|
1108 | if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) { | |
1258 | 1108 | setobj2s(L, ra, slot); | ||
1259 | } | |||
1260 | else | |||
1261 | ✗ | Protect(luaV_finishget(L, upval, rc, ra, slot)); | ||
1262 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1108 times.
|
1108 | vmbreak; | |
1263 | } | |||
1264 | 689 | vmcase(OP_GETTABLE) { | ||
1265 | 689 | StkId ra = RA(i); | ||
1266 | const TValue *slot; | |||
1267 | 689 | TValue *rb = vRB(i); | ||
1268 | 689 | TValue *rc = vRC(i); | ||
1269 | lua_Unsigned n; | |||
1270 |
3/4✓ Branch 0 taken 689 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 644 times.
✓ Branch 3 taken 45 times.
|
1378 | if (ttisinteger(rc) /* fast track for integers? */ | |
1271 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 689 times.
✓ Branch 2 taken 644 times.
✓ Branch 3 taken 45 times.
|
689 | ? (cast_void(n = ivalue(rc)), luaV_fastgeti(L, rb, n, slot)) | |
1272 | ✗ | : luaV_fastget(L, rb, rc, slot, luaH_get)) { | ||
1273 | 644 | setobj2s(L, ra, slot); | ||
1274 | } | |||
1275 | else | |||
1276 | 45 | Protect(luaV_finishget(L, rb, rc, ra, slot)); | ||
1277 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 689 times.
|
689 | vmbreak; | |
1278 | } | |||
1279 | 3 | vmcase(OP_GETI) { | ||
1280 | 3 | StkId ra = RA(i); | ||
1281 | const TValue *slot; | |||
1282 | 3 | TValue *rb = vRB(i); | ||
1283 | 3 | int c = GETARG_C(i); | ||
1284 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
|
3 | if (luaV_fastgeti(L, rb, c, slot)) { | |
1285 | 3 | setobj2s(L, ra, slot); | ||
1286 | } | |||
1287 | else { | |||
1288 | TValue key; | |||
1289 | ✗ | setivalue(&key, c); | ||
1290 | ✗ | Protect(luaV_finishget(L, rb, &key, ra, slot)); | ||
1291 | } | |||
1292 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | vmbreak; | |
1293 | } | |||
1294 | 292 | vmcase(OP_GETFIELD) { | ||
1295 | 292 | StkId ra = RA(i); | ||
1296 | const TValue *slot; | |||
1297 | 292 | TValue *rb = vRB(i); | ||
1298 | 292 | TValue *rc = KC(i); | ||
1299 | 292 | TString *key = tsvalue(rc); /* key must be a string */ | ||
1300 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 292 times.
✓ Branch 3 taken 292 times.
✗ Branch 4 not taken.
|
292 | if (luaV_fastget(L, rb, key, slot, luaH_getshortstr)) { | |
1301 | 292 | setobj2s(L, ra, slot); | ||
1302 | } | |||
1303 | else | |||
1304 | ✗ | Protect(luaV_finishget(L, rb, rc, ra, slot)); | ||
1305 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 292 times.
|
292 | vmbreak; | |
1306 | } | |||
1307 | 397 | vmcase(OP_SETTABUP) { | ||
1308 | const TValue *slot; | |||
1309 | 397 | TValue *upval = cl->upvals[GETARG_A(i)]->v.p; | ||
1310 | 397 | TValue *rb = KB(i); | ||
1311 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 369 times.
|
397 | TValue *rc = RKC(i); | |
1312 | 397 | TString *key = tsvalue(rb); /* key must be a string */ | ||
1313 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 397 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 388 times.
|
397 | if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) { | |
1314 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
9 | luaV_finishfastset(L, upval, slot, rc); | |
1315 | } | |||
1316 | else | |||
1317 | 388 | Protect(luaV_finishset(L, upval, rb, rc, slot)); | ||
1318 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 397 times.
|
397 | vmbreak; | |
1319 | } | |||
1320 | 68 | vmcase(OP_SETTABLE) { | ||
1321 | 68 | StkId ra = RA(i); | ||
1322 | const TValue *slot; | |||
1323 | 68 | TValue *rb = vRB(i); /* key (table is in 'ra') */ | ||
1324 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
|
68 | TValue *rc = RKC(i); /* value */ | |
1325 | lua_Unsigned n; | |||
1326 |
2/4✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 68 times.
✗ Branch 3 not taken.
|
136 | if (ttisinteger(rb) /* fast track for integers? */ | |
1327 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
✓ Branch 2 taken 68 times.
✗ Branch 3 not taken.
|
68 | ? (cast_void(n = ivalue(rb)), luaV_fastgeti(L, s2v(ra), n, slot)) | |
1328 | ✗ | : luaV_fastget(L, s2v(ra), rb, slot, luaH_get)) { | ||
1329 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
68 | luaV_finishfastset(L, s2v(ra), slot, rc); | |
1330 | } | |||
1331 | else | |||
1332 | ✗ | Protect(luaV_finishset(L, s2v(ra), rb, rc, slot)); | ||
1333 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
|
68 | vmbreak; | |
1334 | } | |||
1335 | 14 | vmcase(OP_SETI) { | ||
1336 | 14 | StkId ra = RA(i); | ||
1337 | const TValue *slot; | |||
1338 | 14 | int c = GETARG_B(i); | ||
1339 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 13 times.
|
14 | TValue *rc = RKC(i); | |
1340 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
|
14 | if (luaV_fastgeti(L, s2v(ra), c, slot)) { | |
1341 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
14 | luaV_finishfastset(L, s2v(ra), slot, rc); | |
1342 | } | |||
1343 | else { | |||
1344 | TValue key; | |||
1345 | ✗ | setivalue(&key, c); | ||
1346 | ✗ | Protect(luaV_finishset(L, s2v(ra), &key, rc, slot)); | ||
1347 | } | |||
1348 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | vmbreak; | |
1349 | } | |||
1350 | ✗ | vmcase(OP_SETFIELD) { | ||
1351 | ✗ | StkId ra = RA(i); | ||
1352 | const TValue *slot; | |||
1353 | ✗ | TValue *rb = KB(i); | ||
1354 | ✗ | TValue *rc = RKC(i); | ||
1355 | ✗ | TString *key = tsvalue(rb); /* key must be a string */ | ||
1356 | ✗ | if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) { | ||
1357 | ✗ | luaV_finishfastset(L, s2v(ra), slot, rc); | ||
1358 | } | |||
1359 | else | |||
1360 | ✗ | Protect(luaV_finishset(L, s2v(ra), rb, rc, slot)); | ||
1361 | ✗ | vmbreak; | ||
1362 | } | |||
1363 | 106 | vmcase(OP_NEWTABLE) { | ||
1364 | 106 | StkId ra = RA(i); | ||
1365 | 106 | int b = GETARG_B(i); /* log2(hash size) + 1 */ | ||
1366 | 106 | int c = GETARG_C(i); /* array size */ | ||
1367 | Table *t; | |||
1368 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
|
106 | if (b > 0) | |
1369 | ✗ | b = 1 << (b - 1); /* size is 2^(b - 1) */ | ||
1370 | lua_assert((!TESTARG_k(i)) == (GETARG_Ax(*pc) == 0)); | |||
1371 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
|
106 | if (TESTARG_k(i)) /* non-zero extra argument? */ | |
1372 | ✗ | c += GETARG_Ax(*pc) * (MAXARG_C + 1); /* add it to size */ | ||
1373 | 106 | pc++; /* skip extra argument */ | ||
1374 | 106 | L->top.p = ra + 1; /* correct top in case of emergency GC */ | ||
1375 | 106 | t = luaH_new(L); /* memory allocation */ | ||
1376 | 106 | sethvalue2s(L, ra, t); | ||
1377 |
3/4✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 105 times.
✓ Branch 3 taken 1 time.
|
106 | if (b != 0 || c != 0) | |
1378 | 105 | luaH_resize(L, t, c, b); /* idem */ | ||
1379 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
|
106 | checkGC(L, ra + 1); | |
1380 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
|
106 | vmbreak; | |
1381 | } | |||
1382 | 40 | vmcase(OP_SELF) { | ||
1383 | 40 | StkId ra = RA(i); | ||
1384 | const TValue *slot; | |||
1385 | 40 | TValue *rb = vRB(i); | ||
1386 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | TValue *rc = RKC(i); | |
1387 | 40 | TString *key = tsvalue(rc); /* key must be a string */ | ||
1388 | 40 | setobj2s(L, ra + 1, rb); | ||
1389 |
2/4✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 40 times.
|
40 | if (luaV_fastget(L, rb, key, slot, luaH_getstr)) { | |
1390 | ✗ | setobj2s(L, ra, slot); | ||
1391 | } | |||
1392 | else | |||
1393 | 40 | Protect(luaV_finishget(L, rb, rc, ra, slot)); | ||
1394 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | vmbreak; | |
1395 | } | |||
1396 | 518 | vmcase(OP_ADDI) { | ||
1397 |
3/4✓ Branch 0 taken 511 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
518 | op_arithI(L, l_addi, luai_numadd); | |
1398 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 518 times.
|
518 | vmbreak; | |
1399 | } | |||
1400 | ✗ | vmcase(OP_ADDK) { | ||
1401 | ✗ | op_arithK(L, l_addi, luai_numadd); | ||
1402 | ✗ | vmbreak; | ||
1403 | } | |||
1404 | ✗ | vmcase(OP_SUBK) { | ||
1405 | ✗ | op_arithK(L, l_subi, luai_numsub); | ||
1406 | ✗ | vmbreak; | ||
1407 | } | |||
1408 | 136 | vmcase(OP_MULK) { | ||
1409 |
12/16✓ Branch 0 taken 115 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 98 times.
✓ Branch 3 taken 17 times.
✓ Branch 4 taken 21 times.
✓ Branch 5 taken 17 times.
✓ Branch 6 taken 17 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 38 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 17 times.
✓ Branch 11 taken 21 times.
✓ Branch 12 taken 21 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 38 times.
✗ Branch 15 not taken.
|
136 | op_arithK(L, l_muli, luai_nummul); | |
1410 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 136 times.
|
136 | vmbreak; | |
1411 | } | |||
1412 | 81 | vmcase(OP_MODK) { | ||
1413 | 81 | savestate(L, ci); /* in case of division by 0 */ | ||
1414 |
2/16✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 81 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
|
81 | op_arithK(L, luaV_mod, luaV_modf); | |
1415 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 81 times.
|
81 | vmbreak; | |
1416 | } | |||
1417 | ✗ | vmcase(OP_POWK) { | ||
1418 | ✗ | op_arithfK(L, luai_numpow); | ||
1419 | ✗ | vmbreak; | ||
1420 | } | |||
1421 | 83 | vmcase(OP_DIVK) { | ||
1422 |
8/12✓ Branch 0 taken 12 times.
✓ Branch 1 taken 71 times.
✓ Branch 2 taken 71 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 83 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 14 times.
✓ Branch 7 taken 69 times.
✓ Branch 8 taken 69 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 83 times.
✗ Branch 11 not taken.
|
83 | op_arithfK(L, luai_numdiv); | |
1423 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
|
83 | vmbreak; | |
1424 | } | |||
1425 | ✗ | vmcase(OP_IDIVK) { | ||
1426 | ✗ | savestate(L, ci); /* in case of division by 0 */ | ||
1427 | ✗ | op_arithK(L, luaV_idiv, luai_numidiv); | ||
1428 | ✗ | vmbreak; | ||
1429 | } | |||
1430 | 4 | vmcase(OP_BANDK) { | ||
1431 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
|
4 | op_bitwiseK(L, l_band); | |
1432 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | vmbreak; | |
1433 | } | |||
1434 | ✗ | vmcase(OP_BORK) { | ||
1435 | ✗ | op_bitwiseK(L, l_bor); | ||
1436 | ✗ | vmbreak; | ||
1437 | } | |||
1438 | ✗ | vmcase(OP_BXORK) { | ||
1439 | ✗ | op_bitwiseK(L, l_bxor); | ||
1440 | ✗ | vmbreak; | ||
1441 | } | |||
1442 | 62 | vmcase(OP_SHRI) { | ||
1443 | 62 | StkId ra = RA(i); | ||
1444 | 62 | TValue *rb = vRB(i); | ||
1445 | 62 | int ic = GETARG_sC(i); | ||
1446 | lua_Integer ib; | |||
1447 |
2/4✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
|
62 | if (tointegerns(rb, &ib)) { | |
1448 | 62 | pc++; setivalue(s2v(ra), luaV_shiftl(ib, -ic)); | ||
1449 | } | |||
1450 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
|
62 | vmbreak; | |
1451 | } | |||
1452 | 58 | vmcase(OP_SHLI) { | ||
1453 | 58 | StkId ra = RA(i); | ||
1454 | 58 | TValue *rb = vRB(i); | ||
1455 | 58 | int ic = GETARG_sC(i); | ||
1456 | lua_Integer ib; | |||
1457 |
2/4✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 58 times.
✗ Branch 4 not taken.
|
58 | if (tointegerns(rb, &ib)) { | |
1458 | 58 | pc++; setivalue(s2v(ra), luaV_shiftl(ic, ib)); | ||
1459 | } | |||
1460 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | vmbreak; | |
1461 | } | |||
1462 | 117 | vmcase(OP_ADD) { | ||
1463 |
7/16✓ Branch 0 taken 115 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 115 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
|
117 | op_arith(L, l_addi, luai_numadd); | |
1464 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
|
117 | vmbreak; | |
1465 | } | |||
1466 | 90 | vmcase(OP_SUB) { | ||
1467 |
10/16✓ Branch 0 taken 88 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 85 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 5 times.
✗ Branch 15 not taken.
|
90 | op_arith(L, l_subi, luai_numsub); | |
1468 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 90 times.
|
90 | vmbreak; | |
1469 | } | |||
1470 | 35 | vmcase(OP_MUL) { | ||
1471 |
10/16✓ Branch 0 taken 15 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 20 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 7 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 27 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 27 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 27 times.
✗ Branch 15 not taken.
|
35 | op_arith(L, l_muli, luai_nummul); | |
1472 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
|
35 | vmbreak; | |
1473 | } | |||
1474 | ✗ | vmcase(OP_MOD) { | ||
1475 | ✗ | savestate(L, ci); /* in case of division by 0 */ | ||
1476 | ✗ | op_arith(L, luaV_mod, luaV_modf); | ||
1477 | ✗ | vmbreak; | ||
1478 | } | |||
1479 | ✗ | vmcase(OP_POW) { | ||
1480 | ✗ | op_arithf(L, luai_numpow); | ||
1481 | ✗ | vmbreak; | ||
1482 | } | |||
1483 | 16 | vmcase(OP_DIV) { /* float division (always with floats) */ | ||
1484 |
8/12✓ Branch 0 taken 7 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 8 times.
✓ Branch 8 taken 8 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
|
16 | op_arithf(L, luai_numdiv); | |
1485 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | vmbreak; | |
1486 | } | |||
1487 | ✗ | vmcase(OP_IDIV) { /* floor division */ | ||
1488 | ✗ | savestate(L, ci); /* in case of division by 0 */ | ||
1489 | ✗ | op_arith(L, luaV_idiv, luai_numidiv); | ||
1490 | ✗ | vmbreak; | ||
1491 | } | |||
1492 | 87 | vmcase(OP_BAND) { | ||
1493 |
4/8✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 87 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 87 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 87 times.
✗ Branch 9 not taken.
|
87 | op_bitwise(L, l_band); | |
1494 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 87 times.
|
87 | vmbreak; | |
1495 | } | |||
1496 | 29 | vmcase(OP_BOR) { | ||
1497 |
4/8✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 29 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 29 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 29 times.
✗ Branch 9 not taken.
|
29 | op_bitwise(L, l_bor); | |
1498 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
|
29 | vmbreak; | |
1499 | } | |||
1500 | 42 | vmcase(OP_BXOR) { | ||
1501 |
4/8✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 42 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 42 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 42 times.
✗ Branch 9 not taken.
|
42 | op_bitwise(L, l_bxor); | |
1502 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
|
42 | vmbreak; | |
1503 | } | |||
1504 | 42 | vmcase(OP_SHR) { | ||
1505 |
4/8✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 42 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 42 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 42 times.
✗ Branch 9 not taken.
|
42 | op_bitwise(L, luaV_shiftr); | |
1506 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
|
42 | vmbreak; | |
1507 | } | |||
1508 | 58 | vmcase(OP_SHL) { | ||
1509 |
4/8✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 58 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 58 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 58 times.
✗ Branch 9 not taken.
|
58 | op_bitwise(L, luaV_shiftl); | |
1510 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | vmbreak; | |
1511 | } | |||
1512 | ✗ | vmcase(OP_MMBIN) { | ||
1513 | ✗ | StkId ra = RA(i); | ||
1514 | ✗ | Instruction pi = *(pc - 2); /* original arith. expression */ | ||
1515 | ✗ | TValue *rb = vRB(i); | ||
1516 | ✗ | TMS tm = (TMS)GETARG_C(i); | ||
1517 | ✗ | StkId result = RA(pi); | ||
1518 | lua_assert(OP_ADD <= GET_OPCODE(pi) && GET_OPCODE(pi) <= OP_SHR); | |||
1519 | ✗ | Protect(luaT_trybinTM(L, s2v(ra), rb, result, tm)); | ||
1520 | ✗ | vmbreak; | ||
1521 | } | |||
1522 | ✗ | vmcase(OP_MMBINI) { | ||
1523 | ✗ | StkId ra = RA(i); | ||
1524 | ✗ | Instruction pi = *(pc - 2); /* original arith. expression */ | ||
1525 | ✗ | int imm = GETARG_sB(i); | ||
1526 | ✗ | TMS tm = (TMS)GETARG_C(i); | ||
1527 | ✗ | int flip = GETARG_k(i); | ||
1528 | ✗ | StkId result = RA(pi); | ||
1529 | ✗ | Protect(luaT_trybiniTM(L, s2v(ra), imm, flip, result, tm)); | ||
1530 | ✗ | vmbreak; | ||
1531 | } | |||
1532 | ✗ | vmcase(OP_MMBINK) { | ||
1533 | ✗ | StkId ra = RA(i); | ||
1534 | ✗ | Instruction pi = *(pc - 2); /* original arith. expression */ | ||
1535 | ✗ | TValue *imm = KB(i); | ||
1536 | ✗ | TMS tm = (TMS)GETARG_C(i); | ||
1537 | ✗ | int flip = GETARG_k(i); | ||
1538 | ✗ | StkId result = RA(pi); | ||
1539 | ✗ | Protect(luaT_trybinassocTM(L, s2v(ra), imm, flip, result, tm)); | ||
1540 | ✗ | vmbreak; | ||
1541 | } | |||
1542 | ✗ | vmcase(OP_UNM) { | ||
1543 | ✗ | StkId ra = RA(i); | ||
1544 | ✗ | TValue *rb = vRB(i); | ||
1545 | lua_Number nb; | |||
1546 | ✗ | if (ttisinteger(rb)) { | ||
1547 | ✗ | lua_Integer ib = ivalue(rb); | ||
1548 | ✗ | setivalue(s2v(ra), intop(-, 0, ib)); | ||
1549 | } | |||
1550 | ✗ | else if (tonumberns(rb, nb)) { | ||
1551 | ✗ | setfltvalue(s2v(ra), luai_numunm(L, nb)); | ||
1552 | } | |||
1553 | else | |||
1554 | ✗ | Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM)); | ||
1555 | ✗ | vmbreak; | ||
1556 | } | |||
1557 | 29 | vmcase(OP_BNOT) { | ||
1558 | 29 | StkId ra = RA(i); | ||
1559 | 29 | TValue *rb = vRB(i); | ||
1560 | lua_Integer ib; | |||
1561 |
2/4✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 29 times.
✗ Branch 4 not taken.
|
29 | if (tointegerns(rb, &ib)) { | |
1562 | 29 | setivalue(s2v(ra), intop(^, ~l_castS2U(0), ib)); | ||
1563 | } | |||
1564 | else | |||
1565 | ✗ | Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT)); | ||
1566 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
|
29 | vmbreak; | |
1567 | } | |||
1568 | ✗ | vmcase(OP_NOT) { | ||
1569 | ✗ | StkId ra = RA(i); | ||
1570 | ✗ | TValue *rb = vRB(i); | ||
1571 | ✗ | if (l_isfalse(rb)) | ||
1572 | ✗ | setbtvalue(s2v(ra)); | ||
1573 | else | |||
1574 | ✗ | setbfvalue(s2v(ra)); | ||
1575 | ✗ | vmbreak; | ||
1576 | } | |||
1577 | ✗ | vmcase(OP_LEN) { | ||
1578 | ✗ | StkId ra = RA(i); | ||
1579 | ✗ | Protect(luaV_objlen(L, ra, vRB(i))); | ||
1580 | ✗ | vmbreak; | ||
1581 | } | |||
1582 | 146 | vmcase(OP_CONCAT) { | ||
1583 | 146 | StkId ra = RA(i); | ||
1584 | 146 | int n = GETARG_B(i); /* number of elements to concatenate */ | ||
1585 | 146 | L->top.p = ra + n; /* mark the end of concat operands */ | ||
1586 | 146 | ProtectNT(luaV_concat(L, n)); | ||
1587 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 146 times.
|
146 | checkGC(L, L->top.p); /* 'luaV_concat' ensures correct top */ | |
1588 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 146 times.
|
146 | vmbreak; | |
1589 | } | |||
1590 | ✗ | vmcase(OP_CLOSE) { | ||
1591 | ✗ | StkId ra = RA(i); | ||
1592 | ✗ | Protect(luaF_close(L, ra, LUA_OK, 1)); | ||
1593 | ✗ | vmbreak; | ||
1594 | } | |||
1595 | ✗ | vmcase(OP_TBC) { | ||
1596 | ✗ | StkId ra = RA(i); | ||
1597 | /* create new to-be-closed upvalue */ | |||
1598 | ✗ | halfProtect(luaF_newtbcupval(L, ra)); | ||
1599 | ✗ | vmbreak; | ||
1600 | } | |||
1601 | 247 | vmcase(OP_JMP) { | ||
1602 | 247 | dojump(ci, i, 0); | ||
1603 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 247 times.
|
247 | vmbreak; | |
1604 | } | |||
1605 | 131 | vmcase(OP_EQ) { | ||
1606 | 131 | StkId ra = RA(i); | ||
1607 | int cond; | |||
1608 | 131 | TValue *rb = vRB(i); | ||
1609 | 131 | Protect(cond = luaV_equalobj(L, s2v(ra), rb)); | ||
1610 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 89 times.
|
131 | docondjump(); | |
1611 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 131 times.
|
131 | vmbreak; | |
1612 | } | |||
1613 | ✗ | vmcase(OP_LT) { | ||
1614 | ✗ | op_order(L, l_lti, LTnum, lessthanothers); | ||
1615 | ✗ | vmbreak; | ||
1616 | } | |||
1617 | ✗ | vmcase(OP_LE) { | ||
1618 | ✗ | op_order(L, l_lei, LEnum, lessequalothers); | ||
1619 | ✗ | vmbreak; | ||
1620 | } | |||
1621 | 243 | vmcase(OP_EQK) { | ||
1622 | 243 | StkId ra = RA(i); | ||
1623 | 243 | TValue *rb = KB(i); | ||
1624 | /* basic types do not use '__eq'; we can use raw equality */ | |||
1625 | 243 | int cond = luaV_rawequalobj(s2v(ra), rb); | ||
1626 |
2/2✓ Branch 0 taken 185 times.
✓ Branch 1 taken 58 times.
|
243 | docondjump(); | |
1627 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 243 times.
|
243 | vmbreak; | |
1628 | } | |||
1629 | 81 | vmcase(OP_EQI) { | ||
1630 | 81 | StkId ra = RA(i); | ||
1631 | int cond; | |||
1632 | 81 | int im = GETARG_sB(i); | ||
1633 |
2/2✓ Branch 0 taken 76 times.
✓ Branch 1 taken 5 times.
|
81 | if (ttisinteger(s2v(ra))) | |
1634 | 76 | cond = (ivalue(s2v(ra)) == im); | ||
1635 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | else if (ttisfloat(s2v(ra))) | |
1636 | 5 | cond = luai_numeq(fltvalue(s2v(ra)), cast_num(im)); | ||
1637 | else | |||
1638 | ✗ | cond = 0; /* other types cannot be equal to a number */ | ||
1639 |
2/2✓ Branch 0 taken 37 times.
✓ Branch 1 taken 44 times.
|
81 | docondjump(); | |
1640 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 81 times.
|
81 | vmbreak; | |
1641 | } | |||
1642 | ✗ | vmcase(OP_LTI) { | ||
1643 | ✗ | op_orderI(L, l_lti, luai_numlt, 0, TM_LT); | ||
1644 | ✗ | vmbreak; | ||
1645 | } | |||
1646 | ✗ | vmcase(OP_LEI) { | ||
1647 | ✗ | op_orderI(L, l_lei, luai_numle, 0, TM_LE); | ||
1648 | ✗ | vmbreak; | ||
1649 | } | |||
1650 | 154 | vmcase(OP_GTI) { | ||
1651 |
3/6✓ Branch 0 taken 154 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 5 taken 90 times.
✓ Branch 6 taken 64 times.
|
154 | op_orderI(L, l_gti, luai_numgt, 1, TM_LT); | |
1652 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 154 times.
|
154 | vmbreak; | |
1653 | } | |||
1654 | ✗ | vmcase(OP_GEI) { | ||
1655 | ✗ | op_orderI(L, l_gei, luai_numge, 1, TM_LE); | ||
1656 | ✗ | vmbreak; | ||
1657 | } | |||
1658 | 3 | vmcase(OP_TEST) { | ||
1659 | 3 | StkId ra = RA(i); | ||
1660 |
4/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 1 time.
|
3 | int cond = !l_isfalse(s2v(ra)); | |
1661 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | docondjump(); | |
1662 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | vmbreak; | |
1663 | } | |||
1664 | ✗ | vmcase(OP_TESTSET) { | ||
1665 | ✗ | StkId ra = RA(i); | ||
1666 | ✗ | TValue *rb = vRB(i); | ||
1667 | ✗ | if (l_isfalse(rb) == GETARG_k(i)) | ||
1668 | ✗ | pc++; | ||
1669 | else { | |||
1670 | ✗ | setobj2s(L, ra, rb); | ||
1671 | ✗ | donextjump(ci); | ||
1672 | } | |||
1673 | ✗ | vmbreak; | ||
1674 | } | |||
1675 | 736 | vmcase(OP_CALL) { | ||
1676 | 736 | StkId ra = RA(i); | ||
1677 | CallInfo *newci; | |||
1678 | 736 | int b = GETARG_B(i); | ||
1679 | 736 | int nresults = GETARG_C(i) - 1; | ||
1680 |
2/2✓ Branch 0 taken 657 times.
✓ Branch 1 taken 79 times.
|
736 | if (b != 0) /* fixed number of arguments? */ | |
1681 | 657 | L->top.p = ra + b; /* top signals number of arguments */ | ||
1682 | /* else previous instruction set top */ | |||
1683 | 736 | savepc(L); /* in case of errors */ | ||
1684 |
2/2✓ Branch 1 taken 580 times.
✓ Branch 2 taken 150 times.
|
736 | if ((newci = luaD_precall(L, ra, nresults)) == NULL) | |
1685 | 580 | updatetrap(ci); /* C call; nothing else to be done */ | ||
1686 | else { /* Lua call: run function in this same C frame */ | |||
1687 | 150 | ci = newci; | ||
1688 | 150 | goto startfunc; | ||
1689 | } | |||
1690 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 580 times.
|
580 | vmbreak; | |
1691 | } | |||
1692 | 59 | vmcase(OP_TAILCALL) { | ||
1693 | 59 | StkId ra = RA(i); | ||
1694 | 59 | int b = GETARG_B(i); /* number of arguments + 1 (function) */ | ||
1695 | int n; /* number of results when calling a C function */ | |||
1696 | 59 | int nparams1 = GETARG_C(i); | ||
1697 | /* delta is virtual 'func' - real 'func' (vararg functions) */ | |||
1698 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
|
59 | int delta = (nparams1) ? ci->u.l.nextraargs + nparams1 : 0; | |
1699 |
1/2✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
|
59 | if (b != 0) | |
1700 | 59 | L->top.p = ra + b; | ||
1701 | else /* previous instruction set top */ | |||
1702 | ✗ | b = cast_int(L->top.p - ra); | ||
1703 | 59 | savepc(ci); /* several calls here can raise errors */ | ||
1704 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
|
59 | if (TESTARG_k(i)) { | |
1705 | ✗ | luaF_closeupval(L, base); /* close upvalues from current call */ | ||
1706 | lua_assert(L->tbclist.p < base); /* no pending tbc variables */ | |||
1707 | lua_assert(base == ci->func.p + 1); | |||
1708 | } | |||
1709 |
2/2✓ Branch 1 taken 41 times.
✓ Branch 2 taken 18 times.
|
59 | if ((n = luaD_pretailcall(L, ci, ra, b, delta)) < 0) /* Lua function? */ | |
1710 | 41 | goto startfunc; /* execute the callee */ | ||
1711 | else { /* C function? */ | |||
1712 | 18 | ci->func.p -= delta; /* restore 'func' (if vararg) */ | ||
1713 | 18 | luaD_poscall(L, ci, n); /* finish caller */ | ||
1714 | 18 | updatetrap(ci); /* 'luaD_poscall' can change hooks */ | ||
1715 | 18 | goto ret; /* caller returns after the tail call */ | ||
1716 | } | |||
1717 | } | |||
1718 | 302 | vmcase(OP_RETURN) { | ||
1719 | 302 | StkId ra = RA(i); | ||
1720 | 302 | int n = GETARG_B(i) - 1; /* number of results */ | ||
1721 | 302 | int nparams1 = GETARG_C(i); | ||
1722 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 302 times.
|
302 | if (n < 0) /* not fixed? */ | |
1723 | ✗ | n = cast_int(L->top.p - ra); /* get what is available */ | ||
1724 | 302 | savepc(ci); | ||
1725 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 302 times.
|
302 | if (TESTARG_k(i)) { /* may there be open upvalues? */ | |
1726 | ✗ | ci->u2.nres = n; /* save number of returns */ | ||
1727 | ✗ | if (L->top.p < ci->top.p) | ||
1728 | ✗ | L->top.p = ci->top.p; | ||
1729 | ✗ | luaF_close(L, base, CLOSEKTOP, 1); | ||
1730 | ✗ | updatetrap(ci); | ||
1731 | ✗ | updatestack(ci); | ||
1732 | } | |||
1733 |
1/2✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
|
302 | if (nparams1) /* vararg function? */ | |
1734 | 302 | ci->func.p -= ci->u.l.nextraargs + nparams1; | ||
1735 | 302 | L->top.p = ra + n; /* set call for 'luaD_poscall' */ | ||
1736 | 302 | luaD_poscall(L, ci, n); | ||
1737 | 302 | updatetrap(ci); /* 'luaD_poscall' can change hooks */ | ||
1738 | 302 | goto ret; | ||
1739 | } | |||
1740 | 47 | vmcase(OP_RETURN0) { | ||
1741 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
|
47 | if (l_unlikely(L->hookmask)) { | |
1742 | ✗ | StkId ra = RA(i); | ||
1743 | ✗ | L->top.p = ra; | ||
1744 | ✗ | savepc(ci); | ||
1745 | ✗ | luaD_poscall(L, ci, 0); /* no hurry... */ | ||
1746 | ✗ | trap = 1; | ||
1747 | } | |||
1748 | else { /* do the 'poscall' here */ | |||
1749 | int nres; | |||
1750 | 47 | L->ci = ci->previous; /* back to caller */ | ||
1751 | 47 | L->top.p = base - 1; | ||
1752 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 47 times.
|
50 | for (nres = ci->nresults; l_unlikely(nres > 0); nres--) | |
1753 | 3 | setnilvalue(s2v(L->top.p++)); /* all results are nil */ | ||
1754 | } | |||
1755 | 47 | goto ret; | ||
1756 | } | |||
1757 | 183 | vmcase(OP_RETURN1) { | ||
1758 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 183 times.
|
183 | if (l_unlikely(L->hookmask)) { | |
1759 | ✗ | StkId ra = RA(i); | ||
1760 | ✗ | L->top.p = ra + 1; | ||
1761 | ✗ | savepc(ci); | ||
1762 | ✗ | luaD_poscall(L, ci, 1); /* no hurry... */ | ||
1763 | ✗ | trap = 1; | ||
1764 | } | |||
1765 | else { /* do the 'poscall' here */ | |||
1766 | 183 | int nres = ci->nresults; | ||
1767 | 183 | L->ci = ci->previous; /* back to caller */ | ||
1768 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 182 times.
|
183 | if (nres == 0) | |
1769 | 1 | L->top.p = base - 1; /* asked for no results */ | ||
1770 | else { | |||
1771 | 182 | StkId ra = RA(i); | ||
1772 | 182 | setobjs2s(L, base - 1, ra); /* at least this result */ | ||
1773 | 182 | L->top.p = base; | ||
1774 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 182 times.
|
182 | for (; l_unlikely(nres > 1); nres--) | |
1775 | ✗ | setnilvalue(s2v(L->top.p++)); /* complete missing results */ | ||
1776 | } | |||
1777 | } | |||
1778 | 182 | ret: /* return from a Lua function */ | ||
1779 |
2/2✓ Branch 0 taken 400 times.
✓ Branch 1 taken 150 times.
|
550 | if (ci->callstatus & CIST_FRESH) | |
1780 | 400 | return; /* end this frame */ | ||
1781 | else { | |||
1782 | 150 | ci = ci->previous; | ||
1783 | 150 | goto returning; /* continue running caller in this frame */ | ||
1784 | } | |||
1785 | } | |||
1786 | 31 | vmcase(OP_FORLOOP) { | ||
1787 | 31 | StkId ra = RA(i); | ||
1788 |
1/2✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
|
31 | if (ttisinteger(s2v(ra + 2))) { /* integer loop? */ | |
1789 | 31 | lua_Unsigned count = l_castS2U(ivalue(s2v(ra + 1))); | ||
1790 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 7 times.
|
31 | if (count > 0) { /* still more iterations? */ | |
1791 | 24 | lua_Integer step = ivalue(s2v(ra + 2)); | ||
1792 | 24 | lua_Integer idx = ivalue(s2v(ra)); /* internal index */ | ||
1793 | 24 | chgivalue(s2v(ra + 1), count - 1); /* update counter */ | ||
1794 | 24 | idx = intop(+, idx, step); /* add step to index */ | ||
1795 | 24 | chgivalue(s2v(ra), idx); /* update internal index */ | ||
1796 | 24 | setivalue(s2v(ra + 3), idx); /* and control variable */ | ||
1797 | 24 | pc -= GETARG_Bx(i); /* jump back */ | ||
1798 | } | |||
1799 | } | |||
1800 | ✗ | else if (floatforloop(ra)) /* float loop */ | ||
1801 | ✗ | pc -= GETARG_Bx(i); /* jump back */ | ||
1802 | 31 | updatetrap(ci); /* allows a signal to break the loop */ | ||
1803 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | vmbreak; | |
1804 | } | |||
1805 | 7 | vmcase(OP_FORPREP) { | ||
1806 | 7 | StkId ra = RA(i); | ||
1807 | 7 | savestate(L, ci); /* in case of errors */ | ||
1808 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
|
7 | if (forprep(L, ra)) | |
1809 | ✗ | pc += GETARG_Bx(i) + 1; /* skip the loop */ | ||
1810 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | vmbreak; | |
1811 | } | |||
1812 | ✗ | vmcase(OP_TFORPREP) { | ||
1813 | ✗ | StkId ra = RA(i); | ||
1814 | /* create to-be-closed upvalue (if needed) */ | |||
1815 | ✗ | halfProtect(luaF_newtbcupval(L, ra + 3)); | ||
1816 | ✗ | pc += GETARG_Bx(i); | ||
1817 | ✗ | i = *(pc++); /* go to next instruction */ | ||
1818 | lua_assert(GET_OPCODE(i) == OP_TFORCALL && ra == RA(i)); | |||
1819 | ✗ | goto l_tforcall; | ||
1820 | } | |||
1821 | ✗ | vmcase(OP_TFORCALL) { | ||
1822 | ✗ | l_tforcall: { | ||
1823 | ✗ | StkId ra = RA(i); | ||
1824 | /* 'ra' has the iterator function, 'ra + 1' has the state, | |||
1825 | 'ra + 2' has the control variable, and 'ra + 3' has the | |||
1826 | to-be-closed variable. The call will use the stack after | |||
1827 | these values (starting at 'ra + 4') | |||
1828 | */ | |||
1829 | /* push function, state, and control variable */ | |||
1830 | ✗ | memcpy(ra + 4, ra, 3 * sizeof(*ra)); | ||
1831 | ✗ | L->top.p = ra + 4 + 3; | ||
1832 | ✗ | ProtectNT(luaD_call(L, ra + 4, GETARG_C(i))); /* do the call */ | ||
1833 | ✗ | updatestack(ci); /* stack may have changed */ | ||
1834 | ✗ | i = *(pc++); /* go to next instruction */ | ||
1835 | lua_assert(GET_OPCODE(i) == OP_TFORLOOP && ra == RA(i)); | |||
1836 | ✗ | goto l_tforloop; | ||
1837 | }} | |||
1838 | ✗ | vmcase(OP_TFORLOOP) { | ||
1839 | ✗ | l_tforloop: { | ||
1840 | ✗ | StkId ra = RA(i); | ||
1841 | ✗ | if (!ttisnil(s2v(ra + 4))) { /* continue loop? */ | ||
1842 | ✗ | setobjs2s(L, ra + 2, ra + 4); /* save control variable */ | ||
1843 | ✗ | pc -= GETARG_Bx(i); /* jump back */ | ||
1844 | } | |||
1845 | ✗ | vmbreak; | ||
1846 | }} | |||
1847 | 105 | vmcase(OP_SETLIST) { | ||
1848 | 105 | StkId ra = RA(i); | ||
1849 | 105 | int n = GETARG_B(i); | ||
1850 | 105 | unsigned int last = GETARG_C(i); | ||
1851 | 105 | Table *h = hvalue(s2v(ra)); | ||
1852 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 105 times.
|
105 | if (n == 0) | |
1853 | ✗ | n = cast_int(L->top.p - ra) - 1; /* get up to the top */ | ||
1854 | else | |||
1855 | 105 | L->top.p = ci->top.p; /* correct top in case of emergency GC */ | ||
1856 | 105 | last += n; | ||
1857 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 105 times.
|
105 | if (TESTARG_k(i)) { | |
1858 | ✗ | last += GETARG_Ax(*pc) * (MAXARG_C + 1); | ||
1859 | ✗ | pc++; | ||
1860 | } | |||
1861 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 105 times.
|
105 | if (last > luaH_realasize(h)) /* needs more space? */ | |
1862 | ✗ | luaH_resizearray(L, h, last); /* preallocate it at once */ | ||
1863 |
2/2✓ Branch 0 taken 796 times.
✓ Branch 1 taken 105 times.
|
901 | for (; n > 0; n--) { | |
1864 | 796 | TValue *val = s2v(ra + n); | ||
1865 | 796 | setobj2t(L, &h->array[last - 1], val); | ||
1866 | 796 | last--; | ||
1867 |
3/6✓ Branch 0 taken 73 times.
✓ Branch 1 taken 723 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 73 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
796 | luaC_barrierback(L, obj2gco(h), val); | |
1868 | } | |||
1869 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 105 times.
|
105 | vmbreak; | |
1870 | } | |||
1871 | 215 | vmcase(OP_CLOSURE) { | ||
1872 | 215 | StkId ra = RA(i); | ||
1873 | 215 | Proto *p = cl->p->p[GETARG_Bx(i)]; | ||
1874 | 215 | halfProtect(pushclosure(L, p, cl->upvals, base, ra)); | ||
1875 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 215 times.
|
215 | checkGC(L, ra + 1); | |
1876 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 215 times.
|
215 | vmbreak; | |
1877 | } | |||
1878 | ✗ | vmcase(OP_VARARG) { | ||
1879 | ✗ | StkId ra = RA(i); | ||
1880 | ✗ | int n = GETARG_C(i) - 1; /* required results */ | ||
1881 | ✗ | Protect(luaT_getvarargs(L, ci, ra, n)); | ||
1882 | ✗ | vmbreak; | ||
1883 | } | |||
1884 | 308 | vmcase(OP_VARARGPREP) { | ||
1885 | 308 | ProtectNT(luaT_adjustvarargs(L, GETARG_A(i), ci, cl->p)); | ||
1886 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 308 times.
|
308 | if (l_unlikely(trap)) { /* previous "Protect" updated trap */ | |
1887 | ✗ | luaD_hookcall(L, ci); | ||
1888 | ✗ | L->oldpc = 1; /* next opcode will be seen as a "new" line */ | ||
1889 | } | |||
1890 | 308 | updatebase(ci); /* function has new base after adjustment */ | ||
1891 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 308 times.
|
308 | vmbreak; | |
1892 | } | |||
1893 | ✗ | vmcase(OP_EXTRAARG) { | ||
1894 | lua_assert(0); | |||
1895 | ✗ | vmbreak; | ||
1896 | } | |||
1897 | } | |||
1898 | } | |||
1899 | } | |||
1900 | ||||
1901 | /* }================================================================== */ | |||
1902 |