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

Go to the source code of this file.

Macros

#define cvt2str(o)   ttisnumber(o)
 
#define cvt2num(o)   ttisstring(o)
 
#define LUA_FLOORN2I   0
 
#define tonumber(o, n)    (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))
 
#define tointeger(o, i)    (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I))
 
#define intop(op, v1, v2)   l_castU2S(l_castS2U(v1) op l_castS2U(v2))
 
#define luaV_rawequalobj(t1, t2)   luaV_equalobj(NULL,t1,t2)
 
#define luaV_fastget(L, t, k, slot, f)
 
#define luaV_gettable(L, t, k, v)
 
#define luaV_fastset(L, t, k, slot, f, v)
 
#define luaV_settable(L, t, k, v)
 

Functions

LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2)
 
LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r)
 
LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r)
 
LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n)
 
LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode)
 
LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, const TValue *slot)
 
LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, StkId val, const TValue *slot)
 
LUAI_FUNC void luaV_finishOp (lua_State *L)
 
LUAI_FUNC void luaV_execute (lua_State *L)
 
LUAI_FUNC void luaV_concat (lua_State *L, int total)
 
LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y)
 
LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y)
 
LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y)
 
LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb)
 

Macro Definition Documentation

◆ cvt2num

#define cvt2num ( o)    ttisstring(o)

Definition at line 24 of file lua-5.3.6/src/lvm.h.

Referenced by l_strton(), luaV_tointeger(), and luaV_tonumber_().

◆ cvt2str

#define cvt2str ( o)    ttisnumber(o)

Definition at line 17 of file lua-5.3.6/src/lvm.h.

Referenced by lua_isstring(), lua_tolstring(), luaG_concaterror(), and luaV_concat().

◆ intop

#define intop ( op,
v1,
v2 )   l_castU2S(l_castS2U(v1) op l_castS2U(v2))

◆ LUA_FLOORN2I

#define LUA_FLOORN2I   0

Definition at line 36 of file lua-5.3.6/src/lvm.h.

Referenced by luaG_tointerror(), and validop().

◆ luaV_fastget

#define luaV_fastget ( L,
t,
k,
slot,
f )
Value:
(!ttistable(t) \
? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \
: (slot = f(hvalue(t), k), /* else, do raw access */ \
!ttisnil(slot))) /* result not nil? */
#define NULL
Definition gmacros.h:924
#define hvalue(o)
#define ttisnil(o)
#define ttistable(o)

Definition at line 58 of file lua-5.3.6/src/lvm.h.

58#define luaV_fastget(L,t,k,slot,f) \
59 (!ttistable(t) \
60 ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \
61 : (slot = f(hvalue(t), k), /* else, do raw access */ \
62 !ttisnil(slot))) /* result not nil? */

Referenced by auxgetstr(), auxgetstr(), auxsetstr(), lua_geti(), lua_gettable(), lua_settable(), luaV_execute(), luaV_execute(), luaV_finishget(), and luaV_finishset().

◆ luaV_fastset

#define luaV_fastset ( L,
t,
k,
slot,
f,
v )
Value:
(!ttistable(t) \
? (slot = NULL, 0) \
: (slot = f(hvalue(t), k), \
ttisnil(slot) ? 0 \
: (luaC_barrierback(L, hvalue(t), v), \
setobj2t(L, cast(TValue *,slot), v), \
1)))
#define cast(t, exp)
#define setobj2t
#define luaC_barrierback(L, p, v)

Definition at line 80 of file lua-5.3.6/src/lvm.h.

80#define luaV_fastset(L,t,k,slot,f,v) \
81 (!ttistable(t) \
82 ? (slot = NULL, 0) \
83 : (slot = f(hvalue(t), k), \
84 ttisnil(slot) ? 0 \
85 : (luaC_barrierback(L, hvalue(t), v), \
86 setobj2t(L, cast(TValue *,slot), v), \
87 1)))

Referenced by auxsetstr(), lua_seti(), and luaV_finishset().

◆ luaV_gettable

#define luaV_gettable ( L,
t,
k,
v )
Value:
{ const TValue *slot; \
if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \
else luaV_finishget(L,t,k,v,slot); }
#define setobj2s
const TValue * luaH_get(Table *t, const TValue *key)
#define luaV_fastget(L, t, k, slot, f)
LUAI_FUNC void luaV_finishget(lua_State *L, const TValue *t, TValue *key, StkId val, const TValue *slot)

Definition at line 67 of file lua-5.3.6/src/lvm.h.

67#define luaV_gettable(L,t,k,v) { const TValue *slot; \
68 if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \
69 else luaV_finishget(L,t,k,v,slot); }

Referenced by lua_getfield(), lua_getglobal(), lua_gettable(), luaV_execute(), and luaV_execute().

◆ luaV_rawequalobj

#define luaV_rawequalobj ( t1,
t2 )   luaV_equalobj(NULL,t1,t2)

Definition at line 48 of file lua-5.3.6/src/lvm.h.

◆ luaV_settable

#define luaV_settable ( L,
t,
k,
v )
Value:
{ const TValue *slot; \
if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \
luaV_finishset(L,t,k,v,slot); }
#define luaV_fastset(L, t, k, slot, f, v)

Definition at line 90 of file lua-5.3.6/src/lvm.h.

90#define luaV_settable(L,t,k,v) { const TValue *slot; \
91 if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \
92 luaV_finishset(L,t,k,v,slot); }

Referenced by lua_setfield(), lua_setglobal(), lua_settable(), luaV_execute(), and luaV_execute().

◆ tointeger

#define tointeger ( o,
i )    (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I))

Definition at line 43 of file lua-5.3.6/src/lvm.h.

43#define tointeger(o,i) \
44 (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I))

Referenced by lua_tointegerx(), luaG_tointerror(), luaO_arith(), luaV_equalobj(), luaV_execute(), and validop().

◆ tonumber

#define tonumber ( o,
n )    (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))

Definition at line 40 of file lua-5.3.6/src/lvm.h.

40#define tonumber(o,n) \
41 (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))

Function Documentation

◆ luaV_concat()

LUAI_FUNC void luaV_concat ( lua_State * L,
int total )

Definition at line 293 of file lua-5.2.4/src/lvm.c.

293 {
294 lua_assert(total >= 2);
295 do {
296 StkId top = L->top;
297 int n = 2; /* number of elements handled in this pass (at least 2) */
298 if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
299 if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
300 luaG_concaterror(L, top-2, top-1);
301 }
302 else if (tsvalue(top-1)->len == 0) /* second operand is empty? */
303 (void)tostring(L, top - 2); /* result is first operand */
304 else if (ttisstring(top-2) && tsvalue(top-2)->len == 0) {
305 setobjs2s(L, top - 2, top - 1); /* result is second op. */
306 }
307 else {
308 /* at least two non-empty string values; get as many as possible */
309 size_t tl = tsvalue(top-1)->len;
310 char *buffer;
311 int i;
312 /* collect total length */
313 for (i = 1; i < total && tostring(L, top-i-1); i++) {
314 size_t l = tsvalue(top-i-1)->len;
315 if (l >= (MAX_SIZET/sizeof(char)) - tl)
316 luaG_runerror(L, "string length overflow");
317 tl += l;
318 }
319 buffer = luaZ_openspace(L, &G(L)->buff, tl);
320 tl = 0;
321 n = i;
322 do { /* concat all strings */
323 size_t l = tsvalue(top-i)->len;
324 memcpy(buffer+tl, svalue(top-i), l * sizeof(char));
325 tl += l;
326 } while (--i > 0);
327 setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
328 }
329 total -= n-1; /* got 'n' strings to create 1 new */
330 L->top -= n-1; /* popped 'n' strings and pushed one */
331 } while (total > 1); /* repeat until only 1 result left */
332}
void luaG_concaterror(lua_State *L, StkId p1, StkId p2)
void luaG_runerror(lua_State *L, const char *fmt,...)
#define lua_assert(c)
#define MAX_SIZET
#define setsvalue2s
#define setobjs2s
#define ttisnumber(o)
#define tsvalue(o)
#define ttisstring(o)
#define svalue(o)
#define G(L)
TString * luaS_newlstr(lua_State *L, const char *str, size_t l)
@ TM_CONCAT
#define tostring(L, o)
char * luaZ_openspace(lua_State *L, Mbuffer *buff, size_t n)
static int call_binTM(lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event)

◆ luaV_div()

Definition at line 552 of file lua-5.3.6/src/lvm.c.

552 {
553 if (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */
554 if (n == 0)
555 luaG_runerror(L, "attempt to divide by zero");
556 return intop(-, 0, m); /* n==-1; avoid overflow with 0x80000...//-1 */
557 }
558 else {
559 lua_Integer q = m / n; /* perform C division */
560 if ((m ^ n) < 0 && m % n != 0) /* 'm/n' would be negative non-integer? */
561 q -= 1; /* correct result for different rounding */
562 return q;
563 }
564}
LUA_INTEGER lua_Integer
#define l_castS2U(i)
#define intop(op, v1, v2)

References intop, l_castS2U, and luaG_runerror().

Referenced by intarith(), and luaV_execute().

◆ luaV_equalobj()

LUAI_FUNC int luaV_equalobj ( lua_State * L,
const TValue * t1,
const TValue * t2 )

Definition at line 407 of file lua-5.3.6/src/lvm.c.

407 {
408 const TValue *tm;
409 if (ttype(t1) != ttype(t2)) { /* not the same variant? */
410 if (ttnov(t1) != ttnov(t2) || ttnov(t1) != LUA_TNUMBER)
411 return 0; /* only numbers can be equal with different variants */
412 else { /* two numbers with different variants */
413 lua_Integer i1, i2; /* compare them as integers */
414 return (tointeger(t1, &i1) && tointeger(t2, &i2) && i1 == i2);
415 }
416 }
417 /* values have same type and same variant */
418 switch (ttype(t1)) {
419 case LUA_TNIL: return 1;
420 case LUA_TNUMINT: return (ivalue(t1) == ivalue(t2));
421 case LUA_TNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));
422 case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
423 case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
424 case LUA_TLCF: return fvalue(t1) == fvalue(t2);
425 case LUA_TSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));
426 case LUA_TLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));
427 case LUA_TUSERDATA: {
428 if (uvalue(t1) == uvalue(t2)) return 1;
429 else if (L == NULL) return 0;
430 tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);
431 if (tm == NULL)
432 tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);
433 break; /* will try TM */
434 }
435 case LUA_TTABLE: {
436 if (hvalue(t1) == hvalue(t2)) return 1;
437 else if (L == NULL) return 0;
438 tm = fasttm(L, hvalue(t1)->metatable, TM_EQ);
439 if (tm == NULL)
440 tm = fasttm(L, hvalue(t2)->metatable, TM_EQ);
441 break; /* will try TM */
442 }
443 default:
444 return gcvalue(t1) == gcvalue(t2);
445 }
446 if (tm == NULL) /* no TM? */
447 return 0; /* objects are different */
448 luaT_callTM(L, tm, t1, t2, L->top, 1); /* call TM */
449 return !l_isfalse(L->top);
450}
#define gcvalue(o)
#define pvalue(o)
#define l_isfalse(o)
#define uvalue(o)
#define bvalue(o)
#define ttype(o)
#define fasttm(l, et, e)
@ TM_EQ
#define LUA_TTABLE
#define LUA_TBOOLEAN
#define LUA_TNUMBER
#define LUA_TUSERDATA
#define LUA_TLIGHTUSERDATA
#define LUA_TNIL
#define LUA_TSHRSTR
#define fvalue(o)
#define LUA_TLNGSTR
#define LUA_TLCF
int luaS_eqlngstr(TString *a, TString *b)
#define eqshrstr(a, b)
#define luai_numeq(a, b)
#define LUA_TNUMINT
#define ttnov(o)
#define fltvalue(o)
#define ivalue(o)
#define LUA_TNUMFLT
void luaT_callTM(lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, TValue *p3, int hasres)
#define tointeger(o, i)

◆ luaV_execute()

LUAI_FUNC void luaV_execute ( lua_State * L)

Definition at line 534 of file lua-5.2.4/src/lvm.c.

534 {
535 CallInfo *ci = L->ci;
536 LClosure *cl;
537 TValue *k;
538 StkId base;
539 newframe: /* reentry point when frame changes (call/return) */
540 lua_assert(ci == L->ci);
541 cl = clLvalue(ci->func);
542 k = cl->p->k;
543 base = ci->u.l.base;
544 /* main loop of interpreter */
545 for (;;) {
546 Instruction i = *(ci->u.l.savedpc++);
547 StkId ra;
548 if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
549 (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
550 Protect(traceexec(L));
551 }
552 /* WARNING: several calls may realloc the stack and invalidate `ra' */
553 ra = RA(i);
554 lua_assert(base == ci->u.l.base);
555 lua_assert(base <= L->top && L->top < L->stack + L->stacksize);
558 setobjs2s(L, ra, RB(i));
559 )
561 TValue *rb = k + GETARG_Bx(i);
562 setobj2s(L, ra, rb);
563 )
565 TValue *rb;
567 rb = k + GETARG_Ax(*ci->u.l.savedpc++);
568 setobj2s(L, ra, rb);
569 )
571 setbvalue(ra, GETARG_B(i));
572 if (GETARG_C(i)) ci->u.l.savedpc++; /* skip next instruction (if C) */
573 )
575 int b = GETARG_B(i);
576 do {
577 setnilvalue(ra++);
578 } while (b--);
579 )
581 int b = GETARG_B(i);
582 setobj2s(L, ra, cl->upvals[b]->v);
583 )
585 int b = GETARG_B(i);
586 Protect(luaV_gettable(L, cl->upvals[b]->v, RKC(i), ra));
587 )
589 Protect(luaV_gettable(L, RB(i), RKC(i), ra));
590 )
592 int a = GETARG_A(i);
593 Protect(luaV_settable(L, cl->upvals[a]->v, RKB(i), RKC(i)));
594 )
596 UpVal *uv = cl->upvals[GETARG_B(i)];
597 setobj(L, uv->v, ra);
598 luaC_barrier(L, uv, ra);
599 )
601 Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
602 )
604 int b = GETARG_B(i);
605 int c = GETARG_C(i);
606 Table *t = luaH_new(L);
607 sethvalue(L, ra, t);
608 if (b != 0 || c != 0)
609 luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c));
610 checkGC(L, ra + 1);
611 )
613 StkId rb = RB(i);
614 setobjs2s(L, ra+1, rb);
615 Protect(luaV_gettable(L, rb, RKC(i), ra));
616 )
619 )
622 )
625 )
628 )
631 )
634 )
636 TValue *rb = RB(i);
637 if (ttisnumber(rb)) {
638 lua_Number nb = nvalue(rb);
639 setnvalue(ra, luai_numunm(L, nb));
640 }
641 else {
642 Protect(luaV_arith(L, ra, rb, rb, TM_UNM));
643 }
644 )
646 TValue *rb = RB(i);
647 int res = l_isfalse(rb); /* next assignment may change this value */
648 setbvalue(ra, res);
649 )
651 Protect(luaV_objlen(L, ra, RB(i)));
652 )
654 int b = GETARG_B(i);
655 int c = GETARG_C(i);
656 StkId rb;
657 L->top = base + c + 1; /* mark the end of concat operands */
658 Protect(luaV_concat(L, c - b + 1));
659 ra = RA(i); /* 'luav_concat' may invoke TMs and move the stack */
660 rb = b + base;
661 setobjs2s(L, ra, rb);
662 checkGC(L, (ra >= rb ? ra + 1 : rb));
663 L->top = ci->top; /* restore top */
664 )
666 dojump(ci, i, 0);
667 )
669 TValue *rb = RKB(i);
670 TValue *rc = RKC(i);
671 Protect(
672 if (cast_int(equalobj(L, rb, rc)) != GETARG_A(i))
673 ci->u.l.savedpc++;
674 else
675 donextjump(ci);
676 )
677 )
679 Protect(
680 if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i))
681 ci->u.l.savedpc++;
682 else
683 donextjump(ci);
684 )
685 )
687 Protect(
688 if (luaV_lessequal(L, RKB(i), RKC(i)) != GETARG_A(i))
689 ci->u.l.savedpc++;
690 else
691 donextjump(ci);
692 )
693 )
695 if (GETARG_C(i) ? l_isfalse(ra) : !l_isfalse(ra))
696 ci->u.l.savedpc++;
697 else
698 donextjump(ci);
699 )
701 TValue *rb = RB(i);
702 if (GETARG_C(i) ? l_isfalse(rb) : !l_isfalse(rb))
703 ci->u.l.savedpc++;
704 else {
705 setobjs2s(L, ra, rb);
706 donextjump(ci);
707 }
708 )
710 int b = GETARG_B(i);
711 int nresults = GETARG_C(i) - 1;
712 if (b != 0) L->top = ra+b; /* else previous instruction set top */
713 if (luaD_precall(L, ra, nresults)) { /* C function? */
714 if (nresults >= 0) L->top = ci->top; /* adjust results */
715 base = ci->u.l.base;
716 }
717 else { /* Lua function */
718 ci = L->ci;
720 goto newframe; /* restart luaV_execute over new Lua function */
721 }
722 )
724 int b = GETARG_B(i);
725 if (b != 0) L->top = ra+b; /* else previous instruction set top */
727 if (luaD_precall(L, ra, LUA_MULTRET)) /* C function? */
728 base = ci->u.l.base;
729 else {
730 /* tail call: put called frame (n) in place of caller one (o) */
731 CallInfo *nci = L->ci; /* called frame */
732 CallInfo *oci = nci->previous; /* caller frame */
733 StkId nfunc = nci->func; /* called function */
734 StkId ofunc = oci->func; /* caller function */
735 /* last stack slot filled by 'precall' */
736 StkId lim = nci->u.l.base + getproto(nfunc)->numparams;
737 int aux;
738 /* close all upvalues from previous call */
739 if (cl->p->sizep > 0) luaF_close(L, oci->u.l.base);
740 /* move new frame into old one */
741 for (aux = 0; nfunc + aux < lim; aux++)
742 setobjs2s(L, ofunc + aux, nfunc + aux);
743 oci->u.l.base = ofunc + (nci->u.l.base - nfunc); /* correct base */
744 oci->top = L->top = ofunc + (L->top - nfunc); /* correct top */
745 oci->u.l.savedpc = nci->u.l.savedpc;
746 oci->callstatus |= CIST_TAIL; /* function was tail called */
747 ci = L->ci = oci; /* remove new frame */
748 lua_assert(L->top == oci->u.l.base + getproto(ofunc)->maxstacksize);
749 goto newframe; /* restart luaV_execute over new Lua function */
750 }
751 )
753 int b = GETARG_B(i);
754 if (b != 0) L->top = ra+b-1;
755 if (cl->p->sizep > 0) luaF_close(L, base);
756 b = luaD_poscall(L, ra);
757 if (!(ci->callstatus & CIST_REENTRY)) /* 'ci' still the called one */
758 return; /* external invocation: return */
759 else { /* invocation via reentry: continue execution */
760 ci = L->ci;
761 if (b) L->top = ci->top;
762 lua_assert(isLua(ci));
763 lua_assert(GET_OPCODE(*((ci)->u.l.savedpc - 1)) == OP_CALL);
764 goto newframe; /* restart luaV_execute over new Lua function */
765 }
766 )
768 lua_Number step = nvalue(ra+2);
769 lua_Number idx = luai_numadd(L, nvalue(ra), step); /* increment index */
770 lua_Number limit = nvalue(ra+1);
771 if (luai_numlt(L, 0, step) ? luai_numle(L, idx, limit)
772 : luai_numle(L, limit, idx)) {
773 ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
774 setnvalue(ra, idx); /* update internal index... */
775 setnvalue(ra+3, idx); /* ...and external index */
776 }
777 )
779 const TValue *init = ra;
780 const TValue *plimit = ra+1;
781 const TValue *pstep = ra+2;
782 if (!tonumber(init, ra))
783 luaG_runerror(L, LUA_QL("for") " initial value must be a number");
784 else if (!tonumber(plimit, ra+1))
785 luaG_runerror(L, LUA_QL("for") " limit must be a number");
786 else if (!tonumber(pstep, ra+2))
787 luaG_runerror(L, LUA_QL("for") " step must be a number");
788 setnvalue(ra, luai_numsub(L, nvalue(ra), nvalue(pstep)));
789 ci->u.l.savedpc += GETARG_sBx(i);
790 )
792 StkId cb = ra + 3; /* call base */
793 setobjs2s(L, cb+2, ra+2);
794 setobjs2s(L, cb+1, ra+1);
795 setobjs2s(L, cb, ra);
796 L->top = cb + 3; /* func. + 2 args (state and index) */
797 Protect(luaD_call(L, cb, GETARG_C(i), 1));
798 L->top = ci->top;
799 i = *(ci->u.l.savedpc++); /* go to next instruction */
800 ra = RA(i);
802 goto l_tforloop;
803 )
805 l_tforloop:
806 if (!ttisnil(ra + 1)) { /* continue loop? */
807 setobjs2s(L, ra, ra + 1); /* save control variable */
808 ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
809 }
810 )
812 int n = GETARG_B(i);
813 int c = GETARG_C(i);
814 int last;
815 Table *h;
816 if (n == 0) n = cast_int(L->top - ra) - 1;
817 if (c == 0) {
819 c = GETARG_Ax(*ci->u.l.savedpc++);
820 }
822 h = hvalue(ra);
823 last = ((c-1)*LFIELDS_PER_FLUSH) + n;
824 if (last > h->sizearray) /* needs more space? */
825 luaH_resizearray(L, h, last); /* pre-allocate it at once */
826 for (; n > 0; n--) {
827 TValue *val = ra+n;
828 luaH_setint(L, h, last--, val);
829 luaC_barrierback(L, obj2gco(h), val);
830 }
831 L->top = ci->top; /* correct top (in case of previous open call) */
832 )
834 Proto *p = cl->p->p[GETARG_Bx(i)];
835 Closure *ncl = getcached(p, cl->upvals, base); /* cached closure */
836 if (ncl == NULL) /* no match? */
837 pushclosure(L, p, cl->upvals, base, ra); /* create a new one */
838 else
839 setclLvalue(L, ra, ncl); /* push cashed closure */
840 checkGC(L, ra + 1);
841 )
843 int b = GETARG_B(i) - 1;
844 int j;
845 int n = cast_int(base - ci->func) - cl->p->numparams - 1;
846 if (b < 0) { /* B == 0? */
847 b = n; /* get all var. arguments */
849 ra = RA(i); /* previous call may change the stack */
850 L->top = ra + n;
851 }
852 for (j = 0; j < b; j++) {
853 if (j < n) {
854 setobjs2s(L, ra + j, base - n + j);
855 }
856 else {
857 setnilvalue(ra + j);
858 }
859 }
860 )
862 lua_assert(0);
863 )
864 }
865 }
866}
int luaD_precall(lua_State *L, StkId func, int nresults)
void luaD_call(lua_State *L, StkId func, int nResults)
int luaD_poscall(lua_State *L, StkId firstResult)
#define luaD_checkstack(L, n)
void luaF_close(lua_State *L, StkId level)
#define luaC_barrier(L, p, v)
lu_int32 Instruction
#define cast_int(i)
int luaO_fb2int(int x)
#define setbvalue(obj, x)
#define nvalue(o)
#define setnvalue(obj, x)
#define sethvalue(L, obj, x)
#define setobj(L, obj1, obj2)
#define setnilvalue(obj)
#define LFIELDS_PER_FLUSH
#define GETARG_A(i)
#define GETARG_sBx(i)
#define GETARG_B(i)
#define GET_OPCODE(i)
#define GETARG_Bx(i)
#define GETARG_C(i)
#define obj2gco(v)
#define isLua(ci)
Table * luaH_new(lua_State *L, int narray, int nhash)
void luaH_resizearray(lua_State *L, Table *t, int nasize)
@ TM_MUL
@ TM_UNM
@ TM_POW
@ TM_DIV
@ TM_SUB
@ TM_ADD
@ TM_MOD
#define LUA_MASKCOUNT
#define LUA_MASKLINE
#define LUA_MULTRET
LUA_NUMBER lua_Number
#define LUA_QL(x)
#define equalobj(L, o1, o2)
#define tonumber(o, n)
#define getproto(o)
#define setclLvalue(L, obj, x)
#define clLvalue(o)
#define GETARG_Ax(i)
#define CIST_TAIL
#define CIST_REENTRY
void luaH_resize(lua_State *L, Table *t, int nasize, int nhsize)
void luaH_setint(lua_State *L, Table *t, int key, TValue *value)
int luaV_lessequal(lua_State *L, const TValue *l, const TValue *r)
#define checkGC(L, c)
#define dojump(ci, i, e)
#define RB(i)
#define vmcasenb(l, b)
void luaV_concat(lua_State *L, int total)
void luaV_arith(lua_State *L, StkId ra, const TValue *rb, const TValue *rc, TMS op)
static void pushclosure(lua_State *L, Proto *p, UpVal **encup, StkId base, StkId ra)
#define RKC(i)
#define RA(i)
#define vmcase(l, b)
int luaV_lessthan(lua_State *L, const TValue *l, const TValue *r)
#define arith_op(op, tm)
static void traceexec(lua_State *L)
void luaV_objlen(lua_State *L, StkId ra, const TValue *rb)
#define luai_runtimecheck(L, c)
#define donextjump(ci)
#define RKB(i)
#define Protect(x)
#define vmdispatch(o)
static Closure * getcached(Proto *p, UpVal **encup, StkId base)
#define luai_nummul(L, a, b)
#define luai_numdiv(L, a, b)
#define luai_numpow(L, a, b)
#define luai_numunm(L, a)
#define luai_numsub(L, a, b)
#define luai_nummod(L, a, b, m)
#define luai_numlt(a, b)
#define luai_numadd(L, a, b)
#define luai_numle(a, b)
#define luaV_gettable(L, t, k, v)
#define luaV_settable(L, t, k, v)
struct CallInfo * previous
struct CallInfo::@64::@65 l
const Instruction * savedpc
union CallInfo::@64 u
struct Proto * p
struct Proto ** p

References arith_op, CallInfo::base, CallInfo::callstatus, cast_int, checkGC, chgfltvalue, chgivalue, lua_State::ci, CIST_FRESH, CIST_REENTRY, CIST_TAIL, clLvalue, dojump, donextjump, equalobj, fltvalue, forlimit(), CallInfo::func, GET_OPCODE, GETARG_A, GETARG_Ax, GETARG_B, GETARG_Bx, GETARG_C, GETARG_sBx, getcached(), getcached(), getproto, gettableProtected, lua_State::hookcount, lua_State::hookmask, hvalue, intop, isLua, ivalue, Proto::k, CallInfo::l, l_castS2U, l_isfalse, LFIELDS_PER_FLUSH, lua_assert, LUA_MASKCOUNT, LUA_MASKLINE, LUA_MULTRET, LUA_QL, luaC_barrier, luaC_barrierback, luaC_upvalbarrier, luaD_call(), luaD_checkstack, luaD_poscall(), luaD_precall(), luaF_close(), luaG_runerror(), luaH_getstr(), luaH_new(), luaH_resize(), luaH_resizearray(), luaH_setint(), luai_numadd, luai_numdiv, luai_numidiv, luai_numle, luai_numlt, luai_nummod, luai_nummul, luai_numpow, luai_numsub, luai_numunm, luai_runtimecheck, luaO_fb2int(), luaT_trybinTM(), luaV_arith(), luaV_concat(), luaV_div(), luaV_equalobj(), luaV_fastget, luaV_finishget(), luaV_gettable, luaV_lessequal(), luaV_lessthan(), luaV_mod(), luaV_objlen(), luaV_settable, luaV_shiftl(), NULL, Proto::numparams, nvalue, obj2gco, OP_ADD, OP_BAND, OP_BNOT, OP_BOR, OP_BXOR, OP_CALL, OP_CLOSURE, OP_CONCAT, OP_DIV, OP_EQ, OP_EXTRAARG, OP_FORLOOP, OP_FORPREP, OP_GETTABLE, OP_GETTABUP, OP_GETUPVAL, OP_IDIV, OP_JMP, OP_LE, OP_LEN, OP_LOADBOOL, OP_LOADK, OP_LOADKX, OP_LOADNIL, OP_LT, OP_MOD, OP_MOVE, OP_MUL, OP_NEWTABLE, OP_NOT, OP_POW, OP_RETURN, OP_SELF, OP_SETLIST, OP_SETTABLE, OP_SETTABUP, OP_SETUPVAL, OP_SHL, OP_SHR, OP_SUB, OP_TAILCALL, OP_TEST, OP_TESTSET, OP_TFORCALL, OP_TFORLOOP, OP_UNM, OP_VARARG, Proto::p, LClosure::p, CallInfo::previous, Protect, pushclosure(), pushclosure(), RA, RB, RKB, RKC, CallInfo::savedpc, setbvalue, setclLvalue, setfltvalue, sethvalue, setivalue, setnilvalue, setnvalue, setobj, setobj2s, setobjs2s, settableProtected, Table::sizearray, Proto::sizep, lua_State::stack, lua_State::stacksize, TM_ADD, TM_BAND, TM_BNOT, TM_BOR, TM_BXOR, TM_DIV, TM_IDIV, TM_MOD, TM_MUL, TM_POW, TM_SHL, TM_SHR, TM_SUB, TM_UNM, tointeger, tonumber, CallInfo::top, lua_State::top, traceexec(), tsvalue, ttisinteger, ttisnil, ttisnumber, ttistable, CallInfo::u, LClosure::upvals, UpVal::v, vmbreak, vmcase, vmcasenb, vmdispatch, and vmfetch.

◆ luaV_finishget()

LUAI_FUNC void luaV_finishget ( lua_State * L,
const TValue * t,
TValue * key,
StkId val,
const TValue * slot )

Definition at line 160 of file lua-5.3.6/src/lvm.c.

161 {
162 int loop; /* counter to avoid infinite loops */
163 const TValue *tm; /* metamethod */
164 for (loop = 0; loop < MAXTAGLOOP; loop++) {
165 if (slot == NULL) { /* 't' is not a table? */
167 tm = luaT_gettmbyobj(L, t, TM_INDEX);
168 if (ttisnil(tm))
169 luaG_typeerror(L, t, "index"); /* no metamethod */
170 /* else will try the metamethod */
171 }
172 else { /* 't' is a table */
173 lua_assert(ttisnil(slot));
174 tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */
175 if (tm == NULL) { /* no metamethod? */
176 setnilvalue(val); /* result is nil */
177 return;
178 }
179 /* else will try the metamethod */
180 }
181 if (ttisfunction(tm)) { /* is metamethod a function? */
182 luaT_callTM(L, tm, t, key, val, 1); /* call it */
183 return;
184 }
185 t = tm; /* else try to access 'tm[key]' */
186 if (luaV_fastget(L,t,key,slot,luaH_get)) { /* fast track? */
187 setobj2s(L, val, slot); /* done */
188 return;
189 }
190 /* else repeat (tail call 'luaV_finishget') */
191 }
192 luaG_runerror(L, "'__index' chain too long; possible loop");
193}
void luaG_typeerror(lua_State *L, const TValue *o, const char *op)
#define ttisfunction(o)
const TValue * luaT_gettmbyobj(lua_State *L, const TValue *o, TMS event)
@ TM_INDEX
#define MAXTAGLOOP

◆ luaV_finishOp()

LUAI_FUNC void luaV_finishOp ( lua_State * L)

Definition at line 423 of file lua-5.2.4/src/lvm.c.

423 {
424 CallInfo *ci = L->ci;
425 StkId base = ci->u.l.base;
426 Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */
427 OpCode op = GET_OPCODE(inst);
428 switch (op) { /* finish its execution */
429 case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV:
430 case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN:
431 case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: {
432 setobjs2s(L, base + GETARG_A(inst), --L->top);
433 break;
434 }
435 case OP_LE: case OP_LT: case OP_EQ: {
436 int res = !l_isfalse(L->top - 1);
437 L->top--;
438 /* metamethod should not be called when operand is K */
439 lua_assert(!ISK(GETARG_B(inst)));
440 if (op == OP_LE && /* "<=" using "<" instead? */
441 ttisnil(luaT_gettmbyobj(L, base + GETARG_B(inst), TM_LE)))
442 res = !res; /* invert result */
444 if (res != GETARG_A(inst)) /* condition failed? */
445 ci->u.l.savedpc++; /* skip jump instruction */
446 break;
447 }
448 case OP_CONCAT: {
449 StkId top = L->top - 1; /* top when 'call_binTM' was called */
450 int b = GETARG_B(inst); /* first element to concatenate */
451 int total = cast_int(top - 1 - (base + b)); /* yet to concatenate */
452 setobj2s(L, top - 2, top); /* put TM result in proper position */
453 if (total > 1) { /* are there elements to concat? */
454 L->top = top - 1; /* top is one after last element (at top-2) */
455 luaV_concat(L, total); /* concat them (may yield again) */
456 }
457 /* move final result to final position */
458 setobj2s(L, ci->u.l.base + GETARG_A(inst), L->top - 1);
459 L->top = ci->top; /* restore top */
460 break;
461 }
462 case OP_TFORCALL: {
464 L->top = ci->top; /* correct top */
465 break;
466 }
467 case OP_CALL: {
468 if (GETARG_C(inst) - 1 >= 0) /* nresults >= 0? */
469 L->top = ci->top; /* adjust results */
470 break;
471 }
472 case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE:
473 break;
474 default: lua_assert(0);
475 }
476}
#define ISK(x)
@ TM_LE

◆ luaV_finishset()

LUAI_FUNC void luaV_finishset ( lua_State * L,
const TValue * t,
TValue * key,
StkId val,
const TValue * slot )

Definition at line 203 of file lua-5.3.6/src/lvm.c.

204 {
205 int loop; /* counter to avoid infinite loops */
206 for (loop = 0; loop < MAXTAGLOOP; loop++) {
207 const TValue *tm; /* '__newindex' metamethod */
208 if (slot != NULL) { /* is 't' a table? */
209 Table *h = hvalue(t); /* save 't' table */
210 lua_assert(ttisnil(slot)); /* old value must be nil */
211 tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */
212 if (tm == NULL) { /* no metamethod? */
213 if (slot == luaO_nilobject) /* no previous entry? */
214 slot = luaH_newkey(L, h, key); /* create one */
215 /* no metamethod and (now) there is an entry with given key */
216 setobj2t(L, cast(TValue *, slot), val); /* set its new value */
218 luaC_barrierback(L, h, val);
219 return;
220 }
221 /* else will try the metamethod */
222 }
223 else { /* not a table; check metamethod */
224 if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
225 luaG_typeerror(L, t, "index");
226 }
227 /* try the metamethod */
228 if (ttisfunction(tm)) {
229 luaT_callTM(L, tm, t, key, val, 0);
230 return;
231 }
232 t = tm; /* else repeat assignment over 'tm' */
233 if (luaV_fastset(L, t, key, slot, luaH_get, val))
234 return; /* done */
235 /* else loop */
236 }
237 luaG_runerror(L, "'__newindex' chain too long; possible loop");
238}
#define luaO_nilobject
@ TM_NEWINDEX
TValue * luaH_newkey(lua_State *L, Table *t, const TValue *key)
#define invalidateTMcache(t)
struct Table * metatable

References cast, fasttm, hvalue, invalidateTMcache, lua_assert, luaC_barrierback, luaG_runerror(), luaG_typeerror(), luaH_get(), luaH_newkey(), luaO_nilobject, luaT_callTM(), luaT_gettmbyobj(), luaV_fastset, MAXTAGLOOP, Table::metatable, NULL, setobj2t, TM_NEWINDEX, ttisfunction, and ttisnil.

Referenced by auxsetstr(), auxsetstr(), lua_seti(), and lua_settable().

◆ luaV_lessequal()

LUAI_FUNC int luaV_lessequal ( lua_State * L,
const TValue * l,
const TValue * r )

Definition at line 243 of file lua-5.2.4/src/lvm.c.

243 {
244 int res;
245 if (ttisnumber(l) && ttisnumber(r))
246 return luai_numle(L, nvalue(l), nvalue(r));
247 else if (ttisstring(l) && ttisstring(r))
248 return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
249 else if ((res = call_orderTM(L, l, r, TM_LE)) >= 0) /* first try `le' */
250 return res;
251 else if ((res = call_orderTM(L, r, l, TM_LT)) < 0) /* else try `lt' */
252 luaG_ordererror(L, l, r);
253 return !res;
254}
int luaG_ordererror(lua_State *L, const TValue *p1, const TValue *p2)
#define rawtsvalue(o)
@ TM_LT
static int call_orderTM(lua_State *L, const TValue *p1, const TValue *p2, TMS event)
static int l_strcmp(const TString *ls, const TString *rs)

◆ luaV_lessthan()

LUAI_FUNC int luaV_lessthan ( lua_State * L,
const TValue * l,
const TValue * r )

Definition at line 225 of file lua-5.1.5/src/lvm.c.

225 {
226 int res;
227 if (ttype(l) != ttype(r))
228 return luaG_ordererror(L, l, r);
229 else if (ttisnumber(l))
230 return luai_numlt(nvalue(l), nvalue(r));
231 else if (ttisstring(l))
232 return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
233 else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
234 return res;
235 return luaG_ordererror(L, l, r);
236}
static int call_orderTM(lua_State *L, const TValue *p1, const TValue *p2, TMS event)
static int l_strcmp(const TString *ls, const TString *rs)

◆ luaV_mod()

Definition at line 572 of file lua-5.3.6/src/lvm.c.

572 {
573 if (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */
574 if (n == 0)
575 luaG_runerror(L, "attempt to perform 'n%%0'");
576 return 0; /* m % -1 == 0; avoid overflow with 0x80000...%-1 */
577 }
578 else {
579 lua_Integer r = m % n;
580 if (r != 0 && (m ^ n) < 0) /* 'm/n' would be non-integer negative? */
581 r += n; /* correct result for different rounding */
582 return r;
583 }
584}

◆ luaV_objlen()

LUAI_FUNC void luaV_objlen ( lua_State * L,
StkId ra,
const TValue * rb )

Definition at line 335 of file lua-5.2.4/src/lvm.c.

335 {
336 const TValue *tm;
337 switch (ttypenv(rb)) {
338 case LUA_TTABLE: {
339 Table *h = hvalue(rb);
340 tm = fasttm(L, h->metatable, TM_LEN);
341 if (tm) break; /* metamethod? break switch to call it */
342 setnvalue(ra, cast_num(luaH_getn(h))); /* else primitive len */
343 return;
344 }
345 case LUA_TSTRING: {
346 setnvalue(ra, cast_num(tsvalue(rb)->len));
347 return;
348 }
349 default: { /* try metamethod */
350 tm = luaT_gettmbyobj(L, rb, TM_LEN);
351 if (ttisnil(tm)) /* no metamethod? */
352 luaG_typeerror(L, rb, "get length of");
353 break;
354 }
355 }
356 callTM(L, tm, rb, rb, ra, 1);
357}
#define cast_num(i)
int luaH_getn(Table *t)
@ TM_LEN
#define LUA_TSTRING
#define ttypenv(o)
static void callTM(lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, TValue *p3, int hasres)

◆ luaV_shiftl()

Definition at line 593 of file lua-5.3.6/src/lvm.c.

593 {
594 if (y < 0) { /* shift right? */
595 if (y <= -NBITS) return 0;
596 else return intop(>>, x, -y);
597 }
598 else { /* shift left */
599 if (y >= NBITS) return 0;
600 else return intop(<<, x, y);
601 }
602}
#define NBITS

◆ luaV_tointeger()

LUAI_FUNC int luaV_tointeger ( const TValue * obj,
lua_Integer * p,
int mode )

Definition at line 94 of file lua-5.3.6/src/lvm.c.

94 {
95 TValue v;
96 again:
97 if (ttisfloat(obj)) {
98 lua_Number n = fltvalue(obj);
99 lua_Number f = l_floor(n);
100 if (n != f) { /* not an integral value? */
101 if (mode == 0) return 0; /* fails if mode demands integral value */
102 else if (mode > 1) /* needs ceil? */
103 f += 1; /* convert floor to ceil (remember: n != f) */
104 }
105 return lua_numbertointeger(f, p);
106 }
107 else if (ttisinteger(obj)) {
108 *p = ivalue(obj);
109 return 1;
110 }
111 else if (cvt2num(obj) &&
112 luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {
113 obj = &v;
114 goto again; /* convert result from 'luaO_str2num' to an integer */
115 }
116 return 0; /* conversion failed */
117}
size_t luaO_str2num(const char *s, TValue *o)
#define vslen(o)
#define ttisinteger(o)
#define ttisfloat(o)
#define lua_numbertointeger(n, p)
#define l_floor(x)
#define cvt2num(o)

References cvt2num, fltvalue, ivalue, l_floor, lua_numbertointeger, luaO_str2num(), svalue, ttisfloat, ttisinteger, and vslen.

Referenced by forlimit(), luaH_get(), and luaH_newkey().

◆ luaV_tonumber_()

LUAI_FUNC int luaV_tonumber_ ( const TValue * obj,
lua_Number * n )

Definition at line 72 of file lua-5.3.6/src/lvm.c.

72 {
73 TValue v;
74 if (ttisinteger(obj)) {
75 *n = cast_num(ivalue(obj));
76 return 1;
77 }
78 else if (cvt2num(obj) && /* string convertible to number? */
79 luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {
80 *n = nvalue(&v); /* convert result of 'luaO_str2num' to a float */
81 return 1;
82 }
83 else
84 return 0; /* conversion failed */
85}