Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lvm.c File Reference
#include "lprefix.h"
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lua.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lgc.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
#include "lvm.h"

Go to the source code of this file.

Macros

#define lvm_c
 
#define LUA_CORE
 
#define LUA_USE_JUMPTABLE   0
 
#define MAXTAGLOOP   2000
 
#define NBM   (l_floatatt(MANT_DIG))
 
#define l_intfitsf(i)   1
 
#define tostring(L, o)    (ttisstring(o) || (cvt2str(o) && (luaO_tostring(L, o), 1)))
 
#define isemptystr(o)   (ttisshrstring(o) && tsvalue(o)->shrlen == 0)
 
#define NBITS   cast_int(sizeof(lua_Integer) * CHAR_BIT)
 
#define luaV_shiftr(x, y)   luaV_shiftl(x,-(y))
 
#define l_addi(L, a, b)   intop(+, a, b)
 
#define l_subi(L, a, b)   intop(-, a, b)
 
#define l_muli(L, a, b)   intop(*, a, b)
 
#define l_band(a, b)   intop(&, a, b)
 
#define l_bor(a, b)   intop(|, a, b)
 
#define l_bxor(a, b)   intop(^, a, b)
 
#define l_lti(a, b)   (a < b)
 
#define l_lei(a, b)   (a <= b)
 
#define l_gti(a, b)   (a > b)
 
#define l_gei(a, b)   (a >= b)
 
#define op_arithI(L, iop, fop)
 
#define op_arithf_aux(L, v1, v2, fop)
 
#define op_arithf(L, fop)
 
#define op_arithfK(L, fop)
 
#define op_arith_aux(L, v1, v2, iop, fop)
 
#define op_arith(L, iop, fop)
 
#define op_arithK(L, iop, fop)
 
#define op_bitwiseK(L, op)
 
#define op_bitwise(L, op)
 
#define op_order(L, opi, opn, other)
 
#define op_orderI(L, opi, opf, inv, tm)
 
#define RA(i)   (base+GETARG_A(i))
 
#define RB(i)   (base+GETARG_B(i))
 
#define vRB(i)   s2v(RB(i))
 
#define KB(i)   (k+GETARG_B(i))
 
#define RC(i)   (base+GETARG_C(i))
 
#define vRC(i)   s2v(RC(i))
 
#define KC(i)   (k+GETARG_C(i))
 
#define RKC(i)   ((TESTARG_k(i)) ? k + GETARG_C(i) : s2v(base + GETARG_C(i)))
 
#define updatetrap(ci)   (trap = ci->u.l.trap)
 
#define updatebase(ci)   (base = ci->func + 1)
 
#define updatestack(ci)    { if (l_unlikely(trap)) { updatebase(ci); ra = RA(i); } }
 
#define dojump(ci, i, e)   { pc += GETARG_sJ(i) + e; updatetrap(ci); }
 
#define donextjump(ci)   { Instruction ni = *pc; dojump(ci, ni, 1); }
 
#define docondjump()   if (cond != GETARG_k(i)) pc++; else donextjump(ci);
 
#define savepc(L)   (ci->u.l.savedpc = pc)
 
#define savestate(L, ci)   (savepc(L), L->top = ci->top)
 
#define Protect(exp)   (savestate(L,ci), (exp), updatetrap(ci))
 
#define ProtectNT(exp)   (savepc(L), (exp), updatetrap(ci))
 
#define halfProtect(exp)   (savestate(L,ci), (exp))
 
#define checkGC(L, c)
 
#define vmfetch()
 
#define vmdispatch(o)   switch(o)
 
#define vmcase(l)   case l:
 
#define vmbreak   break
 

Functions

static int l_strton (const TValue *obj, TValue *result)
 
int luaV_tonumber_ (const TValue *obj, lua_Number *n)
 
int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode)
 
int luaV_tointegerns (const TValue *obj, lua_Integer *p, F2Imod mode)
 
int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode)
 
static int forlimit (lua_State *L, lua_Integer init, const TValue *lim, lua_Integer *p, lua_Integer step)
 
static int forprep (lua_State *L, StkId ra)
 
static int floatforloop (StkId ra)
 
void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, const TValue *slot)
 
void luaV_finishset (lua_State *L, const TValue *t, TValue *key, TValue *val, const TValue *slot)
 
static int l_strcmp (const TString *ls, const TString *rs)
 
static int LTintfloat (lua_Integer i, lua_Number f)
 
static int LEintfloat (lua_Integer i, lua_Number f)
 
static int LTfloatint (lua_Number f, lua_Integer i)
 
static int LEfloatint (lua_Number f, lua_Integer i)
 
static int LTnum (const TValue *l, const TValue *r)
 
static int LEnum (const TValue *l, const TValue *r)
 
static int lessthanothers (lua_State *L, const TValue *l, const TValue *r)
 
int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r)
 
static int lessequalothers (lua_State *L, const TValue *l, const TValue *r)
 
int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r)
 
int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2)
 
static void copy2buff (StkId top, int n, char *buff)
 
void luaV_concat (lua_State *L, int total)
 
void luaV_objlen (lua_State *L, StkId ra, const TValue *rb)
 
lua_Integer luaV_idiv (lua_State *L, lua_Integer m, lua_Integer n)
 
lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n)
 
lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n)
 
lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y)
 
static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base, StkId ra)
 
void luaV_finishOp (lua_State *L)
 
void luaV_execute (lua_State *L, CallInfo *ci)
 

Macro Definition Documentation

◆ checkGC

#define checkGC ( L,
c )
Value:
{ luaC_condGC(L, (savepc(L), L->top = (c)), \
updatetrap(ci)); \
luai_threadyield(L); }
#define luaC_condGC(L, c)
#define updatetrap(ci)
#define savepc(L)

Definition at line 1108 of file lua-5.4.3/src/lvm.c.

1108#define checkGC(L,c) \
1109 { luaC_condGC(L, (savepc(L), L->top = (c)), \
1110 updatetrap(ci)); \
1111 luai_threadyield(L); }

Referenced by luaV_execute().

◆ docondjump

#define docondjump ( )    if (cond != GETARG_k(i)) pc++; else donextjump(ci);

Definition at line 1076 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ dojump

#define dojump ( ci,
i,
e )   { pc += GETARG_sJ(i) + e; updatetrap(ci); }

Definition at line 1065 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ donextjump

#define donextjump ( ci)    { Instruction ni = *pc; dojump(ci, ni, 1); }

Definition at line 1069 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ halfProtect

#define halfProtect ( exp)    (savestate(L,ci), (exp))

Definition at line 1105 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ isemptystr

#define isemptystr ( o)    (ttisshrstring(o) && tsvalue(o)->shrlen == 0)

Definition at line 621 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_concat().

◆ KB

#define KB ( i)    (k+GETARG_B(i))

Definition at line 1044 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ KC

#define KC ( i)    (k+GETARG_C(i))

Definition at line 1047 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ l_addi

#define l_addi ( L,
a,
b )   intop(+, a, b)

Definition at line 873 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ l_band

#define l_band ( a,
b )   intop(&, a, b)

Definition at line 876 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ l_bor

#define l_bor ( a,
b )   intop(|, a, b)

Definition at line 877 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ l_bxor

#define l_bxor ( a,
b )   intop(^, a, b)

Definition at line 878 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ l_gei

#define l_gei ( a,
b )   (a >= b)

Definition at line 883 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ l_gti

#define l_gti ( a,
b )   (a > b)

Definition at line 882 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ l_intfitsf

#define l_intfitsf ( i)    1

◆ l_lei

#define l_lei ( a,
b )   (a <= b)

Definition at line 881 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ l_lti

#define l_lti ( a,
b )   (a < b)

Definition at line 880 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ l_muli

#define l_muli ( L,
a,
b )   intop(*, a, b)

Definition at line 875 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ l_subi

#define l_subi ( L,
a,
b )   intop(-, a, b)

Definition at line 874 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ LUA_CORE

#define LUA_CORE

Definition at line 8 of file lua-5.4.3/src/lvm.c.

◆ LUA_USE_JUMPTABLE

#define LUA_USE_JUMPTABLE   0

Definition at line 42 of file lua-5.4.3/src/lvm.c.

◆ luaV_shiftr

#define luaV_shiftr ( x,
y )   luaV_shiftl(x,-(y))

Definition at line 769 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ lvm_c

#define lvm_c

Definition at line 7 of file lua-5.4.3/src/lvm.c.

◆ MAXTAGLOOP

#define MAXTAGLOOP   2000

Definition at line 49 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_finishget(), and luaV_finishset().

◆ NBITS

#define NBITS   cast_int(sizeof(lua_Integer) * CHAR_BIT)

Definition at line 764 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_shiftl().

◆ NBM

#define NBM   (l_floatatt(MANT_DIG))

Definition at line 58 of file lua-5.4.3/src/lvm.c.

◆ op_arith

#define op_arith ( L,
iop,
fop )
Value:
{ \
TValue *v1 = vRB(i); \
TValue *v2 = vRC(i); \
op_arith_aux(L, v1, v2, iop, fop); }
#define vRC(i)
#define vRB(i)

Definition at line 947 of file lua-5.4.3/src/lvm.c.

947#define op_arith(L,iop,fop) { \
948 TValue *v1 = vRB(i); \
949 TValue *v2 = vRC(i); \
950 op_arith_aux(L, v1, v2, iop, fop); }

Referenced by luaV_execute().

◆ op_arith_aux

#define op_arith_aux ( L,
v1,
v2,
iop,
fop )
Value:
{ \
if (ttisinteger(v1) && ttisinteger(v2)) { \
lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2); \
pc++; setivalue(s2v(ra), iop(L, i1, i2)); \
} \
else op_arithf_aux(L, v1, v2, fop); }
LUA_INTEGER lua_Integer
#define ttisinteger(o)
#define ivalue(o)
#define setivalue(obj, x)
#define s2v(o)
#define op_arithf_aux(L, v1, v2, fop)

Definition at line 936 of file lua-5.4.3/src/lvm.c.

936#define op_arith_aux(L,v1,v2,iop,fop) { \
937 if (ttisinteger(v1) && ttisinteger(v2)) { \
938 lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2); \
939 pc++; setivalue(s2v(ra), iop(L, i1, i2)); \
940 } \
941 else op_arithf_aux(L, v1, v2, fop); }

◆ op_arithf

#define op_arithf ( L,
fop )
Value:
{ \
TValue *v1 = vRB(i); \
TValue *v2 = vRC(i); \
op_arithf_aux(L, v1, v2, fop); }

Definition at line 918 of file lua-5.4.3/src/lvm.c.

918#define op_arithf(L,fop) { \
919 TValue *v1 = vRB(i); \
920 TValue *v2 = vRC(i); \
921 op_arithf_aux(L, v1, v2, fop); }

Referenced by luaV_execute().

◆ op_arithf_aux

#define op_arithf_aux ( L,
v1,
v2,
fop )
Value:
{ \
if (tonumberns(v1, n1) && tonumberns(v2, n2)) { \
pc++; setfltvalue(s2v(ra), fop(L, n1, n2)); \
}}
LUA_NUMBER lua_Number
#define setfltvalue(obj, x)
#define tonumberns(o, n)

Definition at line 908 of file lua-5.4.3/src/lvm.c.

908#define op_arithf_aux(L,v1,v2,fop) { \
909 lua_Number n1; lua_Number n2; \
910 if (tonumberns(v1, n1) && tonumberns(v2, n2)) { \
911 pc++; setfltvalue(s2v(ra), fop(L, n1, n2)); \
912 }}

◆ op_arithfK

#define op_arithfK ( L,
fop )
Value:
{ \
TValue *v1 = vRB(i); \
TValue *v2 = KC(i); lua_assert(ttisnumber(v2)); \
op_arithf_aux(L, v1, v2, fop); }
#define lua_assert(c)
#define ttisnumber(o)
#define KC(i)

Definition at line 927 of file lua-5.4.3/src/lvm.c.

927#define op_arithfK(L,fop) { \
928 TValue *v1 = vRB(i); \
929 TValue *v2 = KC(i); lua_assert(ttisnumber(v2)); \
930 op_arithf_aux(L, v1, v2, fop); }

Referenced by luaV_execute().

◆ op_arithI

#define op_arithI ( L,
iop,
fop )
Value:
{ \
TValue *v1 = vRB(i); \
int imm = GETARG_sC(i); \
if (ttisinteger(v1)) { \
lua_Integer iv1 = ivalue(v1); \
pc++; setivalue(s2v(ra), iop(L, iv1, imm)); \
} \
else if (ttisfloat(v1)) { \
lua_Number nb = fltvalue(v1); \
lua_Number fimm = cast_num(imm); \
pc++; setfltvalue(s2v(ra), fop(L, nb, fimm)); \
}}
#define cast_num(i)
#define fltvalue(o)
#define ttisfloat(o)
#define GETARG_sC(i)

Definition at line 890 of file lua-5.4.3/src/lvm.c.

890#define op_arithI(L,iop,fop) { \
891 TValue *v1 = vRB(i); \
892 int imm = GETARG_sC(i); \
893 if (ttisinteger(v1)) { \
894 lua_Integer iv1 = ivalue(v1); \
895 pc++; setivalue(s2v(ra), iop(L, iv1, imm)); \
896 } \
897 else if (ttisfloat(v1)) { \
898 lua_Number nb = fltvalue(v1); \
899 lua_Number fimm = cast_num(imm); \
900 pc++; setfltvalue(s2v(ra), fop(L, nb, fimm)); \
901 }}

Referenced by luaV_execute().

◆ op_arithK

#define op_arithK ( L,
iop,
fop )
Value:
{ \
TValue *v1 = vRB(i); \
TValue *v2 = KC(i); lua_assert(ttisnumber(v2)); \
op_arith_aux(L, v1, v2, iop, fop); }

Definition at line 956 of file lua-5.4.3/src/lvm.c.

956#define op_arithK(L,iop,fop) { \
957 TValue *v1 = vRB(i); \
958 TValue *v2 = KC(i); lua_assert(ttisnumber(v2)); \
959 op_arith_aux(L, v1, v2, iop, fop); }

Referenced by luaV_execute().

◆ op_bitwise

#define op_bitwise ( L,
op )
Value:
{ \
TValue *v1 = vRB(i); \
TValue *v2 = vRC(i); \
if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) { \
pc++; setivalue(s2v(ra), op(i1, i2)); \
}}
#define tointegerns(o, i)

Definition at line 978 of file lua-5.4.3/src/lvm.c.

978#define op_bitwise(L,op) { \
979 TValue *v1 = vRB(i); \
980 TValue *v2 = vRC(i); \
981 lua_Integer i1; lua_Integer i2; \
982 if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) { \
983 pc++; setivalue(s2v(ra), op(i1, i2)); \
984 }}

Referenced by luaV_execute().

◆ op_bitwiseK

#define op_bitwiseK ( L,
op )
Value:
{ \
TValue *v1 = vRB(i); \
TValue *v2 = KC(i); \
lua_Integer i2 = ivalue(v2); \
if (tointegerns(v1, &i1)) { \
pc++; setivalue(s2v(ra), op(i1, i2)); \
}}

Definition at line 965 of file lua-5.4.3/src/lvm.c.

965#define op_bitwiseK(L,op) { \
966 TValue *v1 = vRB(i); \
967 TValue *v2 = KC(i); \
968 lua_Integer i1; \
969 lua_Integer i2 = ivalue(v2); \
970 if (tointegerns(v1, &i1)) { \
971 pc++; setivalue(s2v(ra), op(i1, i2)); \
972 }}

Referenced by luaV_execute().

◆ op_order

#define op_order ( L,
opi,
opn,
other )
Value:
{ \
int cond; \
TValue *rb = vRB(i); \
if (ttisinteger(s2v(ra)) && ttisinteger(rb)) { \
lua_Integer ia = ivalue(s2v(ra)); \
lua_Integer ib = ivalue(rb); \
cond = opi(ia, ib); \
} \
else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) \
cond = opn(s2v(ra), rb); \
else \
Protect(cond = other(L, s2v(ra), rb)); \
docondjump(); }
static int cond(LexState *ls)

Definition at line 992 of file lua-5.4.3/src/lvm.c.

992#define op_order(L,opi,opn,other) { \
993 int cond; \
994 TValue *rb = vRB(i); \
995 if (ttisinteger(s2v(ra)) && ttisinteger(rb)) { \
996 lua_Integer ia = ivalue(s2v(ra)); \
997 lua_Integer ib = ivalue(rb); \
998 cond = opi(ia, ib); \
999 } \
1000 else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) \
1001 cond = opn(s2v(ra), rb); \
1002 else \
1003 Protect(cond = other(L, s2v(ra), rb)); \
1004 docondjump(); }

Referenced by luaV_execute().

◆ op_orderI

#define op_orderI ( L,
opi,
opf,
inv,
tm )
Value:
{ \
int cond; \
int im = GETARG_sB(i); \
if (ttisinteger(s2v(ra))) \
cond = opi(ivalue(s2v(ra)), im); \
else if (ttisfloat(s2v(ra))) { \
lua_Number fa = fltvalue(s2v(ra)); \
lua_Number fim = cast_num(im); \
cond = opf(fa, fim); \
} \
else { \
int isf = GETARG_C(i); \
Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm)); \
} \
docondjump(); }
#define GETARG_C(i)
#define GETARG_sB(i)
int luaT_callorderiTM(lua_State *L, const TValue *p1, int v2, int flip, int isfloat, TMS event)

Definition at line 1011 of file lua-5.4.3/src/lvm.c.

1011#define op_orderI(L,opi,opf,inv,tm) { \
1012 int cond; \
1013 int im = GETARG_sB(i); \
1014 if (ttisinteger(s2v(ra))) \
1015 cond = opi(ivalue(s2v(ra)), im); \
1016 else if (ttisfloat(s2v(ra))) { \
1017 lua_Number fa = fltvalue(s2v(ra)); \
1018 lua_Number fim = cast_num(im); \
1019 cond = opf(fa, fim); \
1020 } \
1021 else { \
1022 int isf = GETARG_C(i); \
1023 Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm)); \
1024 } \
1025 docondjump(); }

Referenced by luaV_execute().

◆ Protect

#define Protect ( exp)    (savestate(L,ci), (exp), updatetrap(ci))

Definition at line 1096 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ ProtectNT

#define ProtectNT ( exp)    (savepc(L), (exp), updatetrap(ci))

Definition at line 1099 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ RA

#define RA ( i)    (base+GETARG_A(i))

Definition at line 1041 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ RB

#define RB ( i)    (base+GETARG_B(i))

Definition at line 1042 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ RC

#define RC ( i)    (base+GETARG_C(i))

Definition at line 1045 of file lua-5.4.3/src/lvm.c.

◆ RKC

#define RKC ( i)    ((TESTARG_k(i)) ? k + GETARG_C(i) : s2v(base + GETARG_C(i)))

Definition at line 1048 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ savepc

#define savepc ( L)    (ci->u.l.savedpc = pc)

Definition at line 1082 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ savestate

#define savestate ( L,
ci )   (savepc(L), L->top = ci->top)

Definition at line 1089 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ tostring

#define tostring ( L,
o )    (ttisstring(o) || (cvt2str(o) && (luaO_tostring(L, o), 1)))

Definition at line 618 of file lua-5.4.3/src/lvm.c.

618#define tostring(L,o) \
619 (ttisstring(o) || (cvt2str(o) && (luaO_tostring(L, o), 1)))

Referenced by luaV_concat().

◆ updatebase

#define updatebase ( ci)    (base = ci->func + 1)

Definition at line 1054 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ updatestack

#define updatestack ( ci)     { if (l_unlikely(trap)) { updatebase(ci); ra = RA(i); } }

Definition at line 1057 of file lua-5.4.3/src/lvm.c.

1057#define updatestack(ci) \
1058 { if (l_unlikely(trap)) { updatebase(ci); ra = RA(i); } }

Referenced by luaV_execute().

◆ updatetrap

#define updatetrap ( ci)    (trap = ci->u.l.trap)

Definition at line 1052 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ vmbreak

#define vmbreak   break

Definition at line 1126 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ vmcase

#define vmcase ( l)    case l:

Definition at line 1125 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ vmdispatch

#define vmdispatch ( o)    switch(o)

Definition at line 1124 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ vmfetch

#define vmfetch ( )
Value:
{ \
if (l_unlikely(trap)) { /* stack reallocation or hooks? */ \
trap = luaG_traceexec(L, pc); /* handle hooks */ \
updatebase(ci); /* correct stack */ \
} \
i = *(pc++); \
ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \
}
void luaG_traceexec(lua_State *L)
#define RA(i)

Definition at line 1115 of file lua-5.4.3/src/lvm.c.

1115#define vmfetch() { \
1116 if (l_unlikely(trap)) { /* stack reallocation or hooks? */ \
1117 trap = luaG_traceexec(L, pc); /* handle hooks */ \
1118 updatebase(ci); /* correct stack */ \
1119 } \
1120 i = *(pc++); \
1121 ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \
1122}

Referenced by luaV_execute().

◆ vRB

#define vRB ( i)    s2v(RB(i))

Definition at line 1043 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

◆ vRC

#define vRC ( i)    s2v(RC(i))

Definition at line 1046 of file lua-5.4.3/src/lvm.c.

Referenced by luaV_execute().

Function Documentation

◆ copy2buff()

static void copy2buff ( StkId top,
int n,
char * buff )
static

Definition at line 624 of file lua-5.4.3/src/lvm.c.

624 {
625 size_t tl = 0; /* size already copied */
626 do {
627 size_t l = vslen(s2v(top - n)); /* length of string being copied */
628 memcpy(buff + tl, svalue(s2v(top - n)), l * sizeof(char));
629 tl += l;
630 } while (--n > 0);
631}
#define svalue(o)
#define vslen(o)

References s2v, svalue, and vslen.

Referenced by luaV_concat().

◆ floatforloop()

static int floatforloop ( StkId ra)
static

Definition at line 266 of file lua-5.4.3/src/lvm.c.

266 {
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}
#define luai_numlt(a, b)
#define luai_numadd(L, a, b)
#define luai_numle(a, b)
#define chgfltvalue(obj, x)

References chgfltvalue, fltvalue, luai_numadd, luai_numle, luai_numlt, s2v, and setfltvalue.

Referenced by luaV_execute().

◆ forlimit()

static int forlimit ( lua_State * L,
lua_Integer init,
const TValue * lim,
lua_Integer * p,
lua_Integer step )
static

Definition at line 176 of file lua-5.4.3/src/lvm.c.

177 {
178 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 return (step > 0 ? init > *p : init < *p); /* not to run? */
194}
#define tonumber(o, n)
l_noret luaG_forerror(lua_State *L, const TValue *o, const char *what)
int luaV_tointeger(const TValue *obj, lua_Integer *p, F2Imod mode)
@ F2Ifloor
@ F2Iceil

References F2Iceil, F2Ifloor, luaG_forerror(), luai_numlt, luaV_tointeger(), and tonumber.

Referenced by forprep().

◆ forprep()

static int forprep ( lua_State * L,
StkId ra )
static

Definition at line 206 of file lua-5.4.3/src/lvm.c.

206 {
207 TValue *pinit = s2v(ra);
208 TValue *plimit = s2v(ra + 1);
209 TValue *pstep = s2v(ra + 2);
210 if (ttisinteger(pinit) && ttisinteger(pstep)) { /* integer loop? */
211 lua_Integer init = ivalue(pinit);
212 lua_Integer step = ivalue(pstep);
213 lua_Integer limit;
214 if (step == 0)
215 luaG_runerror(L, "'for' step is zero");
216 setivalue(s2v(ra + 3), init); /* control variable */
217 if (forlimit(L, init, plimit, &limit, step))
218 return 1; /* skip the loop */
219 else { /* prepare loop counter */
220 lua_Unsigned count;
221 if (step > 0) { /* ascending loop? */
222 count = l_castS2U(limit) - l_castS2U(init);
223 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 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 return 0;
258}
void luaG_runerror(lua_State *L, const char *fmt,...)
LUA_UNSIGNED lua_Unsigned
#define l_castS2U(i)
#define l_castU2S(i)
static int forlimit(lua_State *L, lua_Integer init, const TValue *lim, lua_Integer *p, lua_Integer step)

References forlimit(), ivalue, l_castS2U, l_castU2S, luaG_forerror(), luaG_runerror(), luai_numlt, s2v, setfltvalue, setivalue, tonumber, and ttisinteger.

Referenced by forbody(), and luaV_execute().

◆ l_strcmp()

static int l_strcmp ( const TString * ls,
const TString * rs )
static

Definition at line 375 of file lua-5.4.3/src/lvm.c.

375 {
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}
#define getstr(ts)
#define tsslen(s)

References getstr, and tsslen.

Referenced by lessequalothers(), and lessthanothers().

◆ l_strton()

static int l_strton ( const TValue * obj,
TValue * result )
static

Definition at line 90 of file lua-5.4.3/src/lvm.c.

90 {
91 lua_assert(obj != result);
92 if (!cvt2num(obj)) /* is object not a string? */
93 return 0;
94 else
95 return (luaO_str2num(svalue(obj), result) == vslen(obj) + 1);
96}
size_t luaO_str2num(const char *s, TValue *o)
#define cvt2num(o)

References cvt2num, lua_assert, luaO_str2num(), svalue, and vslen.

Referenced by luaV_tointeger(), and luaV_tonumber_().

◆ LEfloatint()

static int LEfloatint ( lua_Number f,
lua_Integer i )
static

Definition at line 460 of file lua-5.4.3/src/lvm.c.

460 {
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}
int luaV_flttointeger(lua_Number n, lua_Integer *p, F2Imod mode)
#define l_intfitsf(i)

References cast_num, F2Iceil, l_intfitsf, luai_numle, and luaV_flttointeger().

Referenced by LEnum().

◆ LEintfloat()

static int LEintfloat ( lua_Integer i,
lua_Number f )
static

Definition at line 426 of file lua-5.4.3/src/lvm.c.

426 {
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}

References cast_num, F2Ifloor, l_intfitsf, luai_numle, and luaV_flttointeger().

Referenced by LEnum().

◆ LEnum()

static int LEnum ( const TValue * l,
const TValue * r )
static

Definition at line 498 of file lua-5.4.3/src/lvm.c.

498 {
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}
static int LEfloatint(lua_Number f, lua_Integer i)
static int LEintfloat(lua_Integer i, lua_Number f)

References fltvalue, ivalue, LEfloatint(), LEintfloat(), lua_assert, luai_numle, ttisfloat, ttisinteger, and ttisnumber.

Referenced by luaV_execute(), and luaV_lessequal().

◆ lessequalothers()

static int lessequalothers ( lua_State * L,
const TValue * l,
const TValue * r )
static

Definition at line 542 of file lua-5.4.3/src/lvm.c.

542 {
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}
#define tsvalue(o)
#define ttisstring(o)
@ TM_LE
int luaT_callorderTM(lua_State *L, const TValue *p1, const TValue *p2, TMS event)
static int l_strcmp(const TString *ls, const TString *rs)

References l_strcmp(), lua_assert, luaT_callorderTM(), TM_LE, tsvalue, ttisnumber, and ttisstring.

Referenced by luaV_execute(), and luaV_lessequal().

◆ lessthanothers()

static int lessthanothers ( lua_State * L,
const TValue * l,
const TValue * r )
static

Definition at line 520 of file lua-5.4.3/src/lvm.c.

520 {
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}
@ TM_LT

References l_strcmp(), lua_assert, luaT_callorderTM(), TM_LT, tsvalue, ttisnumber, and ttisstring.

Referenced by luaV_execute(), and luaV_lessthan().

◆ LTfloatint()

static int LTfloatint ( lua_Number f,
lua_Integer i )
static

Definition at line 443 of file lua-5.4.3/src/lvm.c.

443 {
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}

References cast_num, F2Ifloor, l_intfitsf, luai_numlt, and luaV_flttointeger().

Referenced by LTnum().

◆ LTintfloat()

static int LTintfloat ( lua_Integer i,
lua_Number f )
static

Definition at line 409 of file lua-5.4.3/src/lvm.c.

409 {
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}

References cast_num, F2Iceil, l_intfitsf, luai_numlt, and luaV_flttointeger().

Referenced by LTnum().

◆ LTnum()

static int LTnum ( const TValue * l,
const TValue * r )
static

Definition at line 476 of file lua-5.4.3/src/lvm.c.

476 {
478 if (ttisinteger(l)) {
479 lua_Integer li = ivalue(l);
480 if (ttisinteger(r))
481 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}
static int LTfloatint(lua_Number f, lua_Integer i)
static int LTintfloat(lua_Integer i, lua_Number f)

References fltvalue, ivalue, LTfloatint(), LTintfloat(), lua_assert, luai_numlt, ttisfloat, ttisinteger, and ttisnumber.

Referenced by luaV_execute(), and luaV_lessthan().

◆ luaV_concat()

void luaV_concat ( lua_State * L,
int total )

Definition at line 638 of file lua-5.4.3/src/lvm.c.

638 {
639 if (total == 1)
640 return; /* "all" values already concatenated */
641 do {
642 StkId top = L->top;
643 int n = 2; /* number of elements handled in this pass (at least 2) */
644 if (!(ttisstring(s2v(top - 2)) || cvt2str(s2v(top - 2))) ||
645 !tostring(L, s2v(top - 1)))
647 else if (isemptystr(s2v(top - 1))) /* second operand is empty? */
648 cast_void(tostring(L, s2v(top - 2))); /* result is first operand */
649 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 size_t tl = vslen(s2v(top - 1));
655 TString *ts;
656 /* collect total length and number of strings */
657 for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) {
658 size_t l = vslen(s2v(top - n - 1));
659 if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl))
660 luaG_runerror(L, "string length overflow");
661 tl += l;
662 }
663 if (tl <= LUAI_MAXSHORTLEN) { /* is result a short string? */
664 char buff[LUAI_MAXSHORTLEN];
665 copy2buff(top, n, buff); /* copy strings to buffer */
666 ts = luaS_newlstr(L, buff, tl);
667 }
668 else { /* long string; copy strings directly to final result */
669 ts = luaS_createlngstrobj(L, tl);
670 copy2buff(top, n, getstr(ts));
671 }
672 setsvalue2s(L, top - n, ts); /* create result */
673 }
674 total -= n-1; /* got 'n' strings to create 1 new */
675 L->top -= n-1; /* popped 'n' strings and pushed one */
676 } while (total > 1); /* repeat until only 1 result left */
677}
#define setsvalue2s
#define setobjs2s
TString * luaS_newlstr(lua_State *L, const char *str, size_t l)
#define LUAI_MAXSHORTLEN
#define MAX_SIZE
#define cast_void(i)
TString * luaS_createlngstrobj(lua_State *L, size_t l)
#define cvt2str(o)
void luaT_tryconcatTM(lua_State *L)
static void copy2buff(StkId top, int n, char *buff)
#define tostring(L, o)
#define isemptystr(o)

References cast_void, copy2buff(), cvt2str, getstr, isemptystr, luaG_runerror(), LUAI_MAXSHORTLEN, luaS_createlngstrobj(), luaS_newlstr(), luaT_tryconcatTM(), MAX_SIZE, s2v, setobjs2s, setsvalue2s, lua_State::top, tostring, ttisstring, and vslen.

Referenced by luaV_execute(), and luaV_finishOp().

◆ luaV_equalobj()

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

Definition at line 565 of file lua-5.4.3/src/lvm.c.

565 {
566 const TValue *tm;
567 if (ttypetag(t1) != ttypetag(t2)) { /* not the same variant? */
568 if (ttype(t1) != ttype(t2) || ttype(t1) != LUA_TNUMBER)
569 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 switch (ttypetag(t1)) {
582 case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: return 1;
583 case LUA_VNUMINT: return (ivalue(t1) == ivalue(t2));
584 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 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 case LUA_VTABLE: {
598 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); /* call TM */
612 return !l_isfalse(s2v(L->top));
613 }
614}
#define NULL
Definition gmacros.h:924
#define gcvalue(o)
#define pvalue(o)
#define l_isfalse(o)
#define uvalue(o)
#define hvalue(o)
#define ttype(o)
#define fasttm(l, et, e)
@ TM_EQ
#define LUA_TNUMBER
#define fvalue(o)
int luaS_eqlngstr(TString *a, TString *b)
#define eqshrstr(a, b)
#define luai_numeq(a, b)
#define ttypetag(o)
#define LUA_VLIGHTUSERDATA
#define LUA_VNUMFLT
#define LUA_VLNGSTR
#define LUA_VNUMINT
#define LUA_VSHRSTR
#define LUA_VFALSE
#define LUA_VLCF
#define LUA_VNIL
#define LUA_VTRUE
#define LUA_VUSERDATA
#define LUA_VTABLE
void luaT_callTMres(lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, StkId res)
int luaV_tointegerns(const TValue *obj, lua_Integer *p, F2Imod mode)
@ F2Ieq

References eqshrstr, F2Ieq, fasttm, fltvalue, fvalue, gcvalue, hvalue, ivalue, l_isfalse, LUA_TNUMBER, LUA_VFALSE, LUA_VLCF, LUA_VLIGHTUSERDATA, LUA_VLNGSTR, LUA_VNIL, LUA_VNUMFLT, LUA_VNUMINT, LUA_VSHRSTR, LUA_VTABLE, LUA_VTRUE, LUA_VUSERDATA, luai_numeq, luaS_eqlngstr(), luaT_callTMres(), luaV_tointegerns(), NULL, pvalue, s2v, TM_EQ, lua_State::top, tsvalue, ttype, ttypetag, and uvalue.

Referenced by luaV_execute().

◆ luaV_execute()

void luaV_execute ( lua_State * L,
CallInfo * ci )

Definition at line 1129 of file lua-5.4.3/src/lvm.c.

1129 {
1130 LClosure *cl;
1131 TValue *k;
1132 StkId base;
1133 const Instruction *pc;
1134 int trap;
1135#if LUA_USE_JUMPTABLE
1136#include "ljumptab.h"
1137#endif
1138 startfunc:
1139 trap = L->hookmask;
1140 returning: /* trap already set */
1141 cl = clLvalue(s2v(ci->func));
1142 k = cl->p->k;
1143 pc = ci->u.l.savedpc;
1144 if (l_unlikely(trap)) {
1145 if (pc == cl->p->code) { /* first instruction (not resuming)? */
1146 if (cl->p->is_vararg)
1147 trap = 0; /* hooks will start after VARARGPREP instruction */
1148 else /* check 'call' hook */
1149 luaD_hookcall(L, ci);
1150 }
1151 ci->u.l.trap = 1; /* assume trap is on, for now */
1152 }
1153 base = ci->func + 1;
1154 /* main loop of interpreter */
1155 for (;;) {
1156 Instruction i; /* instruction being executed */
1157 StkId ra; /* instruction's A register */
1158 vmfetch();
1159// low-level line tracing for debugging Lua
1160// printf("line: %d\n", luaG_getfuncline(cl->p, pcRel(pc, cl->p)));
1161 lua_assert(base == ci->func + 1);
1162 lua_assert(base <= L->top && L->top < L->stack_last);
1163 /* invalidate top for instructions not expecting it */
1164 lua_assert(isIT(i) || (cast_void(L->top = base), 1));
1165 vmdispatch (GET_OPCODE(i)) {
1166 vmcase(OP_MOVE) {
1167 setobjs2s(L, ra, RB(i));
1168 vmbreak;
1169 }
1170 vmcase(OP_LOADI) {
1171 lua_Integer b = GETARG_sBx(i);
1172 setivalue(s2v(ra), b);
1173 vmbreak;
1174 }
1175 vmcase(OP_LOADF) {
1176 int b = GETARG_sBx(i);
1177 setfltvalue(s2v(ra), cast_num(b));
1178 vmbreak;
1179 }
1180 vmcase(OP_LOADK) {
1181 TValue *rb = k + GETARG_Bx(i);
1182 setobj2s(L, ra, rb);
1183 vmbreak;
1184 }
1185 vmcase(OP_LOADKX) {
1186 TValue *rb;
1187 rb = k + GETARG_Ax(*pc); pc++;
1188 setobj2s(L, ra, rb);
1189 vmbreak;
1190 }
1192 setbfvalue(s2v(ra));
1193 vmbreak;
1194 }
1196 setbfvalue(s2v(ra));
1197 pc++; /* skip next instruction */
1198 vmbreak;
1199 }
1201 setbtvalue(s2v(ra));
1202 vmbreak;
1203 }
1205 int b = GETARG_B(i);
1206 do {
1207 setnilvalue(s2v(ra++));
1208 } while (b--);
1209 vmbreak;
1210 }
1212 int b = GETARG_B(i);
1213 setobj2s(L, ra, cl->upvals[b]->v);
1214 vmbreak;
1215 }
1217 UpVal *uv = cl->upvals[GETARG_B(i)];
1218 setobj(L, uv->v, s2v(ra));
1219 luaC_barrier(L, uv, s2v(ra));
1220 vmbreak;
1221 }
1223 const TValue *slot;
1224 TValue *upval = cl->upvals[GETARG_B(i)]->v;
1225 TValue *rc = KC(i);
1226 TString *key = tsvalue(rc); /* key must be a string */
1227 if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {
1228 setobj2s(L, ra, slot);
1229 }
1230 else
1231 Protect(luaV_finishget(L, upval, rc, ra, slot));
1232 vmbreak;
1233 }
1235 const TValue *slot;
1236 TValue *rb = vRB(i);
1237 TValue *rc = vRC(i);
1238 lua_Unsigned n;
1239 if (ttisinteger(rc) /* fast track for integers? */
1240 ? (cast_void(n = ivalue(rc)), luaV_fastgeti(L, rb, n, slot))
1241 : luaV_fastget(L, rb, rc, slot, luaH_get)) {
1242 setobj2s(L, ra, slot);
1243 }
1244 else
1245 Protect(luaV_finishget(L, rb, rc, ra, slot));
1246 vmbreak;
1247 }
1248 vmcase(OP_GETI) {
1249 const TValue *slot;
1250 TValue *rb = vRB(i);
1251 int c = GETARG_C(i);
1252 if (luaV_fastgeti(L, rb, c, slot)) {
1253 setobj2s(L, ra, slot);
1254 }
1255 else {
1256 TValue key;
1257 setivalue(&key, c);
1258 Protect(luaV_finishget(L, rb, &key, ra, slot));
1259 }
1260 vmbreak;
1261 }
1263 const TValue *slot;
1264 TValue *rb = vRB(i);
1265 TValue *rc = KC(i);
1266 TString *key = tsvalue(rc); /* key must be a string */
1267 if (luaV_fastget(L, rb, key, slot, luaH_getshortstr)) {
1268 setobj2s(L, ra, slot);
1269 }
1270 else
1271 Protect(luaV_finishget(L, rb, rc, ra, slot));
1272 vmbreak;
1273 }
1275 const TValue *slot;
1276 TValue *upval = cl->upvals[GETARG_A(i)]->v;
1277 TValue *rb = KB(i);
1278 TValue *rc = RKC(i);
1279 TString *key = tsvalue(rb); /* key must be a string */
1280 if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {
1281 luaV_finishfastset(L, upval, slot, rc);
1282 }
1283 else
1284 Protect(luaV_finishset(L, upval, rb, rc, slot));
1285 vmbreak;
1286 }
1288 const TValue *slot;
1289 TValue *rb = vRB(i); /* key (table is in 'ra') */
1290 TValue *rc = RKC(i); /* value */
1291 lua_Unsigned n;
1292 if (ttisinteger(rb) /* fast track for integers? */
1293 ? (cast_void(n = ivalue(rb)), luaV_fastgeti(L, s2v(ra), n, slot))
1294 : luaV_fastget(L, s2v(ra), rb, slot, luaH_get)) {
1295 luaV_finishfastset(L, s2v(ra), slot, rc);
1296 }
1297 else
1298 Protect(luaV_finishset(L, s2v(ra), rb, rc, slot));
1299 vmbreak;
1300 }
1301 vmcase(OP_SETI) {
1302 const TValue *slot;
1303 int c = GETARG_B(i);
1304 TValue *rc = RKC(i);
1305 if (luaV_fastgeti(L, s2v(ra), c, slot)) {
1306 luaV_finishfastset(L, s2v(ra), slot, rc);
1307 }
1308 else {
1309 TValue key;
1310 setivalue(&key, c);
1311 Protect(luaV_finishset(L, s2v(ra), &key, rc, slot));
1312 }
1313 vmbreak;
1314 }
1316 const TValue *slot;
1317 TValue *rb = KB(i);
1318 TValue *rc = RKC(i);
1319 TString *key = tsvalue(rb); /* key must be a string */
1320 if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) {
1321 luaV_finishfastset(L, s2v(ra), slot, rc);
1322 }
1323 else
1324 Protect(luaV_finishset(L, s2v(ra), rb, rc, slot));
1325 vmbreak;
1326 }
1328 int b = GETARG_B(i); /* log2(hash size) + 1 */
1329 int c = GETARG_C(i); /* array size */
1330 Table *t;
1331 if (b > 0)
1332 b = 1 << (b - 1); /* size is 2^(b - 1) */
1333 lua_assert((!TESTARG_k(i)) == (GETARG_Ax(*pc) == 0));
1334 if (TESTARG_k(i)) /* non-zero extra argument? */
1335 c += GETARG_Ax(*pc) * (MAXARG_C + 1); /* add it to size */
1336 pc++; /* skip extra argument */
1337 L->top = ra + 1; /* correct top in case of emergency GC */
1338 t = luaH_new(L); /* memory allocation */
1339 sethvalue2s(L, ra, t);
1340 if (b != 0 || c != 0)
1341 luaH_resize(L, t, c, b); /* idem */
1342 checkGC(L, ra + 1);
1343 vmbreak;
1344 }
1345 vmcase(OP_SELF) {
1346 const TValue *slot;
1347 TValue *rb = vRB(i);
1348 TValue *rc = RKC(i);
1349 TString *key = tsvalue(rc); /* key must be a string */
1350 setobj2s(L, ra + 1, rb);
1351 if (luaV_fastget(L, rb, key, slot, luaH_getstr)) {
1352 setobj2s(L, ra, slot);
1353 }
1354 else
1355 Protect(luaV_finishget(L, rb, rc, ra, slot));
1356 vmbreak;
1357 }
1358 vmcase(OP_ADDI) {
1360 vmbreak;
1361 }
1362 vmcase(OP_ADDK) {
1364 vmbreak;
1365 }
1366 vmcase(OP_SUBK) {
1368 vmbreak;
1369 }
1370 vmcase(OP_MULK) {
1372 vmbreak;
1373 }
1374 vmcase(OP_MODK) {
1376 vmbreak;
1377 }
1378 vmcase(OP_POWK) {
1380 vmbreak;
1381 }
1382 vmcase(OP_DIVK) {
1384 vmbreak;
1385 }
1386 vmcase(OP_IDIVK) {
1388 vmbreak;
1389 }
1390 vmcase(OP_BANDK) {
1391 op_bitwiseK(L, l_band);
1392 vmbreak;
1393 }
1394 vmcase(OP_BORK) {
1395 op_bitwiseK(L, l_bor);
1396 vmbreak;
1397 }
1398 vmcase(OP_BXORK) {
1399 op_bitwiseK(L, l_bxor);
1400 vmbreak;
1401 }
1402 vmcase(OP_SHRI) {
1403 TValue *rb = vRB(i);
1404 int ic = GETARG_sC(i);
1405 lua_Integer ib;
1406 if (tointegerns(rb, &ib)) {
1407 pc++; setivalue(s2v(ra), luaV_shiftl(ib, -ic));
1408 }
1409 vmbreak;
1410 }
1411 vmcase(OP_SHLI) {
1412 TValue *rb = vRB(i);
1413 int ic = GETARG_sC(i);
1414 lua_Integer ib;
1415 if (tointegerns(rb, &ib)) {
1416 pc++; setivalue(s2v(ra), luaV_shiftl(ic, ib));
1417 }
1418 vmbreak;
1419 }
1420 vmcase(OP_ADD) {
1422 vmbreak;
1423 }
1424 vmcase(OP_SUB) {
1426 vmbreak;
1427 }
1428 vmcase(OP_MUL) {
1430 vmbreak;
1431 }
1432 vmcase(OP_MOD) {
1434 vmbreak;
1435 }
1436 vmcase(OP_POW) {
1438 vmbreak;
1439 }
1440 vmcase(OP_DIV) { /* float division (always with floats) */
1442 vmbreak;
1443 }
1444 vmcase(OP_IDIV) { /* floor division */
1446 vmbreak;
1447 }
1448 vmcase(OP_BAND) {
1449 op_bitwise(L, l_band);
1450 vmbreak;
1451 }
1452 vmcase(OP_BOR) {
1453 op_bitwise(L, l_bor);
1454 vmbreak;
1455 }
1456 vmcase(OP_BXOR) {
1457 op_bitwise(L, l_bxor);
1458 vmbreak;
1459 }
1460 vmcase(OP_SHR) {
1462 vmbreak;
1463 }
1464 vmcase(OP_SHL) {
1466 vmbreak;
1467 }
1468 vmcase(OP_MMBIN) {
1469 Instruction pi = *(pc - 2); /* original arith. expression */
1470 TValue *rb = vRB(i);
1471 TMS tm = (TMS)GETARG_C(i);
1472 StkId result = RA(pi);
1473 lua_assert(OP_ADD <= GET_OPCODE(pi) && GET_OPCODE(pi) <= OP_SHR);
1474 Protect(luaT_trybinTM(L, s2v(ra), rb, result, tm));
1475 vmbreak;
1476 }
1477 vmcase(OP_MMBINI) {
1478 Instruction pi = *(pc - 2); /* original arith. expression */
1479 int imm = GETARG_sB(i);
1480 TMS tm = (TMS)GETARG_C(i);
1481 int flip = GETARG_k(i);
1482 StkId result = RA(pi);
1483 Protect(luaT_trybiniTM(L, s2v(ra), imm, flip, result, tm));
1484 vmbreak;
1485 }
1486 vmcase(OP_MMBINK) {
1487 Instruction pi = *(pc - 2); /* original arith. expression */
1488 TValue *imm = KB(i);
1489 TMS tm = (TMS)GETARG_C(i);
1490 int flip = GETARG_k(i);
1491 StkId result = RA(pi);
1492 Protect(luaT_trybinassocTM(L, s2v(ra), imm, flip, result, tm));
1493 vmbreak;
1494 }
1495 vmcase(OP_UNM) {
1496 TValue *rb = vRB(i);
1497 lua_Number nb;
1498 if (ttisinteger(rb)) {
1499 lua_Integer ib = ivalue(rb);
1500 setivalue(s2v(ra), intop(-, 0, ib));
1501 }
1502 else if (tonumberns(rb, nb)) {
1503 setfltvalue(s2v(ra), luai_numunm(L, nb));
1504 }
1505 else
1506 Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM));
1507 vmbreak;
1508 }
1509 vmcase(OP_BNOT) {
1510 TValue *rb = vRB(i);
1511 lua_Integer ib;
1512 if (tointegerns(rb, &ib)) {
1513 setivalue(s2v(ra), intop(^, ~l_castS2U(0), ib));
1514 }
1515 else
1516 Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));
1517 vmbreak;
1518 }
1519 vmcase(OP_NOT) {
1520 TValue *rb = vRB(i);
1521 if (l_isfalse(rb))
1522 setbtvalue(s2v(ra));
1523 else
1524 setbfvalue(s2v(ra));
1525 vmbreak;
1526 }
1527 vmcase(OP_LEN) {
1528 Protect(luaV_objlen(L, ra, vRB(i)));
1529 vmbreak;
1530 }
1531 vmcase(OP_CONCAT) {
1532 int n = GETARG_B(i); /* number of elements to concatenate */
1533 L->top = ra + n; /* mark the end of concat operands */
1534 ProtectNT(luaV_concat(L, n));
1535 checkGC(L, L->top); /* 'luaV_concat' ensures correct top */
1536 vmbreak;
1537 }
1538 vmcase(OP_CLOSE) {
1539 Protect(luaF_close(L, ra, LUA_OK, 1));
1540 vmbreak;
1541 }
1542 vmcase(OP_TBC) {
1543 /* create new to-be-closed upvalue */
1545 vmbreak;
1546 }
1547 vmcase(OP_JMP) {
1548 dojump(ci, i, 0);
1549 vmbreak;
1550 }
1551 vmcase(OP_EQ) {
1552 int cond;
1553 TValue *rb = vRB(i);
1554 Protect(cond = luaV_equalobj(L, s2v(ra), rb));
1555 docondjump();
1556 vmbreak;
1557 }
1558 vmcase(OP_LT) {
1560 vmbreak;
1561 }
1562 vmcase(OP_LE) {
1564 vmbreak;
1565 }
1566 vmcase(OP_EQK) {
1567 TValue *rb = KB(i);
1568 /* basic types do not use '__eq'; we can use raw equality */
1569 int cond = luaV_rawequalobj(s2v(ra), rb);
1570 docondjump();
1571 vmbreak;
1572 }
1573 vmcase(OP_EQI) {
1574 int cond;
1575 int im = GETARG_sB(i);
1576 if (ttisinteger(s2v(ra)))
1577 cond = (ivalue(s2v(ra)) == im);
1578 else if (ttisfloat(s2v(ra)))
1579 cond = luai_numeq(fltvalue(s2v(ra)), cast_num(im));
1580 else
1581 cond = 0; /* other types cannot be equal to a number */
1582 docondjump();
1583 vmbreak;
1584 }
1585 vmcase(OP_LTI) {
1587 vmbreak;
1588 }
1589 vmcase(OP_LEI) {
1591 vmbreak;
1592 }
1593 vmcase(OP_GTI) {
1595 vmbreak;
1596 }
1597 vmcase(OP_GEI) {
1599 vmbreak;
1600 }
1601 vmcase(OP_TEST) {
1602 int cond = !l_isfalse(s2v(ra));
1603 docondjump();
1604 vmbreak;
1605 }
1607 TValue *rb = vRB(i);
1608 if (l_isfalse(rb) == GETARG_k(i))
1609 pc++;
1610 else {
1611 setobj2s(L, ra, rb);
1612 donextjump(ci);
1613 }
1614 vmbreak;
1615 }
1616 vmcase(OP_CALL) {
1617 CallInfo *newci;
1618 int b = GETARG_B(i);
1619 int nresults = GETARG_C(i) - 1;
1620 if (b != 0) /* fixed number of arguments? */
1621 L->top = ra + b; /* top signals number of arguments */
1622 /* else previous instruction set top */
1623 savepc(L); /* in case of errors */
1624 if ((newci = luaD_precall(L, ra, nresults)) == NULL)
1625 updatetrap(ci); /* C call; nothing else to be done */
1626 else { /* Lua call: run function in this same C frame */
1627 ci = newci;
1628 ci->callstatus = 0; /* call re-uses 'luaV_execute' */
1629 goto startfunc;
1630 }
1631 vmbreak;
1632 }
1634 int b = GETARG_B(i); /* number of arguments + 1 (function) */
1635 int nparams1 = GETARG_C(i);
1636 /* delta is virtual 'func' - real 'func' (vararg functions) */
1637 int delta = (nparams1) ? ci->u.l.nextraargs + nparams1 : 0;
1638 if (b != 0)
1639 L->top = ra + b;
1640 else /* previous instruction set top */
1641 b = cast_int(L->top - ra);
1642 savepc(ci); /* several calls here can raise errors */
1643 if (TESTARG_k(i)) {
1644 luaF_closeupval(L, base); /* close upvalues from current call */
1645 lua_assert(L->tbclist < base); /* no pending tbc variables */
1646 lua_assert(base == ci->func + 1);
1647 }
1648 while (!ttisfunction(s2v(ra))) { /* not a function? */
1649 luaD_tryfuncTM(L, ra); /* try '__call' metamethod */
1650 b++; /* there is now one extra argument */
1651 checkstackGCp(L, 1, ra);
1652 }
1653 if (!ttisLclosure(s2v(ra))) { /* C function? */
1654 luaD_precall(L, ra, LUA_MULTRET); /* call it */
1655 updatetrap(ci);
1656 updatestack(ci); /* stack may have been relocated */
1657 ci->func -= delta; /* restore 'func' (if vararg) */
1658 luaD_poscall(L, ci, cast_int(L->top - ra)); /* finish caller */
1659 updatetrap(ci); /* 'luaD_poscall' can change hooks */
1660 goto ret; /* caller returns after the tail call */
1661 }
1662 ci->func -= delta; /* restore 'func' (if vararg) */
1663 luaD_pretailcall(L, ci, ra, b); /* prepare call frame */
1664 goto startfunc; /* execute the callee */
1665 }
1666 vmcase(OP_RETURN) {
1667 int n = GETARG_B(i) - 1; /* number of results */
1668 int nparams1 = GETARG_C(i);
1669 if (n < 0) /* not fixed? */
1670 n = cast_int(L->top - ra); /* get what is available */
1671 savepc(ci);
1672 if (TESTARG_k(i)) { /* may there be open upvalues? */
1673 if (L->top < ci->top)
1674 L->top = ci->top;
1675 luaF_close(L, base, CLOSEKTOP, 1);
1676 updatetrap(ci);
1677 updatestack(ci);
1678 }
1679 if (nparams1) /* vararg function? */
1680 ci->func -= ci->u.l.nextraargs + nparams1;
1681 L->top = ra + n; /* set call for 'luaD_poscall' */
1682 luaD_poscall(L, ci, n);
1683 updatetrap(ci); /* 'luaD_poscall' can change hooks */
1684 goto ret;
1685 }
1687 if (l_unlikely(L->hookmask)) {
1688 L->top = ra;
1689 savepc(ci);
1690 luaD_poscall(L, ci, 0); /* no hurry... */
1691 trap = 1;
1692 }
1693 else { /* do the 'poscall' here */
1694 int nres;
1695 L->ci = ci->previous; /* back to caller */
1696 L->top = base - 1;
1697 for (nres = ci->nresults; l_unlikely(nres > 0); nres--)
1698 setnilvalue(s2v(L->top++)); /* all results are nil */
1699 }
1700 goto ret;
1701 }
1703 if (l_unlikely(L->hookmask)) {
1704 L->top = ra + 1;
1705 savepc(ci);
1706 luaD_poscall(L, ci, 1); /* no hurry... */
1707 trap = 1;
1708 }
1709 else { /* do the 'poscall' here */
1710 int nres = ci->nresults;
1711 L->ci = ci->previous; /* back to caller */
1712 if (nres == 0)
1713 L->top = base - 1; /* asked for no results */
1714 else {
1715 setobjs2s(L, base - 1, ra); /* at least this result */
1716 L->top = base;
1717 for (; l_unlikely(nres > 1); nres--)
1718 setnilvalue(s2v(L->top++)); /* complete missing results */
1719 }
1720 }
1721 ret: /* return from a Lua function */
1722 if (ci->callstatus & CIST_FRESH)
1723 return; /* end this frame */
1724 else {
1725 ci = ci->previous;
1726 goto returning; /* continue running caller in this frame */
1727 }
1728 }
1730 if (ttisinteger(s2v(ra + 2))) { /* integer loop? */
1731 lua_Unsigned count = l_castS2U(ivalue(s2v(ra + 1)));
1732 if (count > 0) { /* still more iterations? */
1733 lua_Integer step = ivalue(s2v(ra + 2));
1734 lua_Integer idx = ivalue(s2v(ra)); /* internal index */
1735 chgivalue(s2v(ra + 1), count - 1); /* update counter */
1736 idx = intop(+, idx, step); /* add step to index */
1737 chgivalue(s2v(ra), idx); /* update internal index */
1738 setivalue(s2v(ra + 3), idx); /* and control variable */
1739 pc -= GETARG_Bx(i); /* jump back */
1740 }
1741 }
1742 else if (floatforloop(ra)) /* float loop */
1743 pc -= GETARG_Bx(i); /* jump back */
1744 updatetrap(ci); /* allows a signal to break the loop */
1745 vmbreak;
1746 }
1748 savestate(L, ci); /* in case of errors */
1749 if (forprep(L, ra))
1750 pc += GETARG_Bx(i) + 1; /* skip the loop */
1751 vmbreak;
1752 }
1754 /* create to-be-closed upvalue (if needed) */
1755 halfProtect(luaF_newtbcupval(L, ra + 3));
1756 pc += GETARG_Bx(i);
1757 i = *(pc++); /* go to next instruction */
1758 lua_assert(GET_OPCODE(i) == OP_TFORCALL && ra == RA(i));
1759 goto l_tforcall;
1760 }
1762 l_tforcall:
1763 /* 'ra' has the iterator function, 'ra + 1' has the state,
1764 'ra + 2' has the control variable, and 'ra + 3' has the
1765 to-be-closed variable. The call will use the stack after
1766 these values (starting at 'ra + 4')
1767 */
1768 /* push function, state, and control variable */
1769 memcpy(ra + 4, ra, 3 * sizeof(*ra));
1770 L->top = ra + 4 + 3;
1771 ProtectNT(luaD_call(L, ra + 4, GETARG_C(i))); /* do the call */
1772 updatestack(ci); /* stack may have changed */
1773 i = *(pc++); /* go to next instruction */
1774 lua_assert(GET_OPCODE(i) == OP_TFORLOOP && ra == RA(i));
1775 goto l_tforloop;
1776 }
1778 l_tforloop:
1779 if (!ttisnil(s2v(ra + 4))) { /* continue loop? */
1780 setobjs2s(L, ra + 2, ra + 4); /* save control variable */
1781 pc -= GETARG_Bx(i); /* jump back */
1782 }
1783 vmbreak;
1784 }
1786 int n = GETARG_B(i);
1787 unsigned int last = GETARG_C(i);
1788 Table *h = hvalue(s2v(ra));
1789 if (n == 0)
1790 n = cast_int(L->top - ra) - 1; /* get up to the top */
1791 else
1792 L->top = ci->top; /* correct top in case of emergency GC */
1793 last += n;
1794 if (TESTARG_k(i)) {
1795 last += GETARG_Ax(*pc) * (MAXARG_C + 1);
1796 pc++;
1797 }
1798 if (last > luaH_realasize(h)) /* needs more space? */
1799 luaH_resizearray(L, h, last); /* preallocate it at once */
1800 for (; n > 0; n--) {
1801 TValue *val = s2v(ra + n);
1802 setobj2t(L, &h->array[last - 1], val);
1803 last--;
1804 luaC_barrierback(L, obj2gco(h), val);
1805 }
1806 vmbreak;
1807 }
1809 Proto *p = cl->p->p[GETARG_Bx(i)];
1810 halfProtect(pushclosure(L, p, cl->upvals, base, ra));
1811 checkGC(L, ra + 1);
1812 vmbreak;
1813 }
1814 vmcase(OP_VARARG) {
1815 int n = GETARG_C(i) - 1; /* required results */
1816 Protect(luaT_getvarargs(L, ci, ra, n));
1817 vmbreak;
1818 }
1820 ProtectNT(luaT_adjustvarargs(L, GETARG_A(i), ci, cl->p));
1821 if (l_unlikely(trap)) { /* previous "Protect" updated trap */
1822 luaD_hookcall(L, ci);
1823 L->oldpc = 1; /* next opcode will be seen as a "new" line */
1824 }
1825 updatebase(ci); /* function has new base after adjustment */
1826 vmbreak;
1827 }
1829 lua_assert(0);
1830 vmbreak;
1831 }
1832 }
1833 }
1834}
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)
void luaF_close(lua_State *L, StkId level)
#define luaC_barrier(L, p, v)
lu_int32 Instruction
#define cast_int(i)
#define setobj2s
#define sethvalue2s
#define ttisfunction(o)
#define ttisnil(o)
#define setobj(L, obj1, obj2)
#define setnilvalue(obj)
#define setobj2t
#define MAXARG_C
#define GETARG_A(i)
#define GETARG_sBx(i)
#define GETARG_B(i)
#define GET_OPCODE(i)
#define GETARG_Bx(i)
#define obj2gco(v)
const TValue * luaH_get(Table *t, const TValue *key)
Table * luaH_new(lua_State *L, int narray, int nhash)
const TValue * luaH_getstr(Table *t, TString *key)
void luaH_resizearray(lua_State *L, Table *t, int nasize)
@ TM_UNM
#define LUA_MULTRET
#define luaC_barrierback(L, p, v)
#define ttisLclosure(o)
#define clLvalue(o)
#define GETARG_Ax(i)
void luaH_resize(lua_State *L, Table *t, int nasize, int nhsize)
#define LUA_OK
#define luaV_rawequalobj(o1, o2)
#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_numidiv(L, a, b)
#define chgivalue(obj, x)
#define CIST_FRESH
const TValue * luaH_getshortstr(Table *t, TString *key)
void luaT_trybinTM(lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event)
@ TM_BNOT
#define luaV_fastget(L, t, k, slot, f)
#define intop(op, v1, v2)
void luaD_pretailcall(lua_State *L, CallInfo *ci, StkId func, int narg1)
void luaD_hookcall(lua_State *L, CallInfo *ci)
void luaD_tryfuncTM(lua_State *L, StkId func)
#define checkstackGCp(L, n, p)
void luaF_newtbcupval(lua_State *L, StkId level)
void luaF_closeupval(lua_State *L, StkId level)
#define CLOSEKTOP
#define luai_numgt(a, b)
#define luai_numge(a, b)
#define setbtvalue(obj)
#define setbfvalue(obj)
#define TESTARG_k(i)
#define GETARG_k(i)
#define isIT(i)
LUAI_FUNC unsigned int luaH_realasize(const Table *t)
void luaT_adjustvarargs(lua_State *L, int nfixparams, CallInfo *ci, const Proto *p)
void luaT_trybiniTM(lua_State *L, const TValue *p1, lua_Integer i2, int flip, StkId res, TMS event)
void luaT_trybinassocTM(lua_State *L, const TValue *p1, const TValue *p2, int flip, StkId res, TMS event)
void luaT_getvarargs(lua_State *L, CallInfo *ci, StkId where, int wanted)
#define checkGC(L, c)
#define KB(i)
static int lessthanothers(lua_State *L, const TValue *l, const TValue *r)
#define dojump(ci, i, e)
#define luaV_shiftr(x, y)
#define l_bxor(a, b)
void luaV_finishset(lua_State *L, const TValue *t, TValue *key, TValue *val, const TValue *slot)
static int LTnum(const TValue *l, const TValue *r)
#define ProtectNT(exp)
#define RB(i)
#define l_band(a, b)
#define op_arithfK(L, fop)
#define l_bor(a, b)
void luaV_concat(lua_State *L, int total)
#define vmbreak
#define l_gei(a, b)
#define op_arithf(L, fop)
#define op_order(L, opi, opn, other)
void luaV_finishget(lua_State *L, const TValue *t, TValue *key, StkId val, const TValue *slot)
int luaV_equalobj(lua_State *L, const TValue *t1, const TValue *t2)
static void pushclosure(lua_State *L, Proto *p, UpVal **encup, StkId base, StkId ra)
#define l_lti(a, b)
#define op_bitwiseK(L, op)
#define savestate(L, ci)
#define RKC(i)
#define vmcase(l)
#define op_arithI(L, iop, fop)
#define op_bitwise(L, op)
#define l_muli(L, a, b)
lua_Integer luaV_idiv(lua_State *L, lua_Integer m, lua_Integer n)
#define halfProtect(exp)
static int forprep(lua_State *L, StkId ra)
#define updatebase(ci)
#define l_gti(a, b)
static int lessequalothers(lua_State *L, const TValue *l, const TValue *r)
#define updatestack(ci)
static int LEnum(const TValue *l, const TValue *r)
void luaV_objlen(lua_State *L, StkId ra, const TValue *rb)
#define donextjump(ci)
lua_Number luaV_modf(lua_State *L, lua_Number m, lua_Number n)
#define op_orderI(L, opi, opf, inv, tm)
#define op_arith(L, iop, fop)
#define l_addi(L, a, b)
#define l_subi(L, a, b)
lua_Integer luaV_shiftl(lua_Integer x, lua_Integer y)
static int floatforloop(StkId ra)
#define Protect(exp)
#define vmfetch()
#define vmdispatch(o)
#define l_lei(a, b)
lua_Integer luaV_mod(lua_State *L, lua_Integer m, lua_Integer n)
#define docondjump()
#define op_arithK(L, iop, fop)
#define luaV_fastgeti(L, t, k, slot)
#define luaV_finishfastset(L, t, slot, v)
volatile l_signalT trap
struct CallInfo * previous
struct CallInfo::@64::@65 l
const Instruction * savedpc
union CallInfo::@64 u
struct Proto * p
Instruction * code
struct Proto ** p
const Instruction * oldpc

References Table::array, CallInfo::callstatus, cast_int, cast_num, cast_void, checkGC, checkstackGCp, chgivalue, lua_State::ci, CIST_FRESH, clLvalue, CLOSEKTOP, Proto::code, cond(), docondjump, dojump, donextjump, floatforloop(), fltvalue, forprep(), CallInfo::func, GET_OPCODE, GETARG_A, GETARG_Ax, GETARG_B, GETARG_Bx, GETARG_C, GETARG_k, GETARG_sB, GETARG_sBx, GETARG_sC, halfProtect, lua_State::hookmask, hvalue, intop, Proto::is_vararg, isIT, ivalue, Proto::k, KB, KC, CallInfo::l, l_addi, l_band, l_bor, l_bxor, l_castS2U, l_gei, l_gti, l_isfalse, l_lei, l_lti, l_muli, l_subi, LEnum(), lessequalothers(), lessthanothers(), LTnum(), lua_assert, LUA_MULTRET, LUA_OK, luaC_barrier, luaC_barrierback, luaD_call(), luaD_hookcall(), luaD_poscall(), luaD_precall(), luaD_pretailcall(), luaD_tryfuncTM(), luaF_close(), luaF_closeupval(), luaF_newtbcupval(), luaH_get(), luaH_getshortstr(), luaH_getstr(), luaH_new(), luaH_realasize(), luaH_resize(), luaH_resizearray(), luai_numadd, luai_numdiv, luai_numeq, luai_numge, luai_numgt, luai_numidiv, luai_numle, luai_numlt, luai_nummul, luai_numpow, luai_numsub, luai_numunm, luaT_adjustvarargs(), luaT_getvarargs(), luaT_trybinassocTM(), luaT_trybiniTM(), luaT_trybinTM(), luaV_concat(), luaV_equalobj(), luaV_fastget, luaV_fastgeti, luaV_finishfastset, luaV_finishget(), luaV_finishset(), luaV_idiv(), luaV_mod(), luaV_modf(), luaV_objlen(), luaV_rawequalobj, luaV_shiftl(), luaV_shiftr, MAXARG_C, CallInfo::nextraargs, CallInfo::nresults, NULL, obj2gco, lua_State::oldpc, OP_ADD, OP_ADDI, OP_ADDK, op_arith, op_arithf, op_arithfK, op_arithI, op_arithK, OP_BAND, OP_BANDK, op_bitwise, op_bitwiseK, OP_BNOT, OP_BOR, OP_BORK, OP_BXOR, OP_BXORK, OP_CALL, OP_CLOSE, OP_CLOSURE, OP_CONCAT, OP_DIV, OP_DIVK, OP_EQ, OP_EQI, OP_EQK, OP_EXTRAARG, OP_FORLOOP, OP_FORPREP, OP_GEI, OP_GETFIELD, OP_GETI, OP_GETTABLE, OP_GETTABUP, OP_GETUPVAL, OP_GTI, OP_IDIV, OP_IDIVK, OP_JMP, OP_LE, OP_LEI, OP_LEN, OP_LFALSESKIP, OP_LOADF, OP_LOADFALSE, OP_LOADI, OP_LOADK, OP_LOADKX, OP_LOADNIL, OP_LOADTRUE, OP_LT, OP_LTI, OP_MMBIN, OP_MMBINI, OP_MMBINK, OP_MOD, OP_MODK, OP_MOVE, OP_MUL, OP_MULK, OP_NEWTABLE, OP_NOT, op_order, op_orderI, OP_POW, OP_POWK, OP_RETURN, OP_RETURN0, OP_RETURN1, OP_SELF, OP_SETFIELD, OP_SETI, OP_SETLIST, OP_SETTABLE, OP_SETTABUP, OP_SETUPVAL, OP_SHL, OP_SHLI, OP_SHR, OP_SHRI, OP_SUB, OP_SUBK, OP_TAILCALL, OP_TBC, OP_TEST, OP_TESTSET, OP_TFORCALL, OP_TFORLOOP, OP_TFORPREP, OP_UNM, OP_VARARG, OP_VARARGPREP, Proto::p, LClosure::p, CallInfo::previous, Protect, ProtectNT, pushclosure(), RA, RB, RKC, s2v, CallInfo::savedpc, savepc, savestate, setbfvalue, setbtvalue, setfltvalue, sethvalue2s, setivalue, setnilvalue, setobj, setobj2s, setobj2t, setobjs2s, lua_State::stack_last, lua_State::tbclist, TESTARG_k, TM_BNOT, TM_LE, TM_LT, TM_UNM, tointegerns, tonumberns, CallInfo::top, lua_State::top, CallInfo::trap, tsvalue, ttisfloat, ttisfunction, ttisinteger, ttisLclosure, ttisnil, CallInfo::u, updatebase, updatestack, updatetrap, LClosure::upvals, UpVal::v, vmbreak, vmcase, vmdispatch, vmfetch, vRB, and vRC.

◆ luaV_finishget()

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

Definition at line 287 of file lua-5.4.3/src/lvm.c.

288 {
289 int loop; /* counter to avoid infinite loops */
290 const TValue *tm; /* metamethod */
291 for (loop = 0; loop < MAXTAGLOOP; loop++) {
292 if (slot == NULL) { /* 't' is not a table? */
294 tm = luaT_gettmbyobj(L, t, TM_INDEX);
295 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 tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */
302 if (tm == NULL) { /* no metamethod? */
303 setnilvalue(s2v(val)); /* result is nil */
304 return;
305 }
306 /* else will try the metamethod */
307 }
308 if (ttisfunction(tm)) { /* is metamethod a function? */
309 luaT_callTMres(L, tm, t, key, val); /* call it */
310 return;
311 }
312 t = tm; /* else try to access 'tm[key]' */
313 if (luaV_fastget(L, t, key, slot, luaH_get)) { /* fast track? */
314 setobj2s(L, val, slot); /* done */
315 return;
316 }
317 /* else repeat (tail call 'luaV_finishget') */
318 }
319 luaG_runerror(L, "'__index' chain too long; possible loop");
320}
void luaG_typeerror(lua_State *L, const TValue *o, const char *op)
#define ttistable(o)
const TValue * luaT_gettmbyobj(lua_State *L, const TValue *o, TMS event)
@ TM_INDEX
#define isempty(v)
#define notm(tm)
#define MAXTAGLOOP

References fasttm, hvalue, isempty, lua_assert, luaG_runerror(), luaG_typeerror(), luaH_get(), luaT_callTMres(), luaT_gettmbyobj(), luaV_fastget, MAXTAGLOOP, notm, NULL, s2v, setnilvalue, setobj2s, TM_INDEX, ttisfunction, and ttistable.

Referenced by luaV_execute().

◆ luaV_finishOp()

void luaV_finishOp ( lua_State * L)

Definition at line 808 of file lua-5.4.3/src/lvm.c.

808 {
809 CallInfo *ci = L->ci;
810 StkId base = ci->func + 1;
811 Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */
812 OpCode op = GET_OPCODE(inst);
813 switch (op) { /* finish its execution */
814 case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: {
815 setobjs2s(L, base + GETARG_A(*(ci->u.l.savedpc - 2)), --L->top);
816 break;
817 }
818 case OP_UNM: case OP_BNOT: case OP_LEN:
819 case OP_GETTABUP: case OP_GETTABLE: case OP_GETI:
820 case OP_GETFIELD: case OP_SELF: {
821 setobjs2s(L, base + GETARG_A(inst), --L->top);
822 break;
823 }
824 case OP_LT: case OP_LE:
825 case OP_LTI: case OP_LEI:
826 case OP_GTI: case OP_GEI:
827 case OP_EQ: { /* note that 'OP_EQI'/'OP_EQK' cannot yield */
828 int res = !l_isfalse(s2v(L->top - 1));
829 L->top--;
830#if defined(LUA_COMPAT_LT_LE)
831 if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */
832 ci->callstatus ^= CIST_LEQ; /* clear mark */
833 res = !res; /* negate result */
834 }
835#endif
837 if (res != GETARG_k(inst)) /* condition failed? */
838 ci->u.l.savedpc++; /* skip jump instruction */
839 break;
840 }
841 case OP_CONCAT: {
842 StkId top = L->top - 1; /* top when 'luaT_tryconcatTM' was called */
843 int a = GETARG_A(inst); /* first element to concatenate */
844 int total = cast_int(top - 1 - (base + a)); /* yet to concatenate */
845 setobjs2s(L, top - 2, top); /* put TM result in proper position */
846 L->top = top - 1; /* top is one after last element (at top-2) */
847 luaV_concat(L, total); /* concat them (may yield again) */
848 break;
849 }
850 case OP_CLOSE: case OP_RETURN: { /* yielded closing variables */
851 ci->u.l.savedpc--; /* repeat instruction to close other vars. */
852 break;
853 }
854 default: {
855 /* only these other opcodes can yield */
856 lua_assert(op == OP_TFORCALL || op == OP_CALL ||
857 op == OP_TAILCALL || op == OP_SETTABUP || op == OP_SETTABLE ||
858 op == OP_SETI || op == OP_SETFIELD);
859 break;
860 }
861 }
862}
#define CIST_LEQ

References CallInfo::callstatus, cast_int, lua_State::ci, CIST_LEQ, CallInfo::func, GET_OPCODE, GETARG_A, GETARG_k, CallInfo::l, l_isfalse, lua_assert, luaV_concat(), OP_BNOT, OP_CALL, OP_CLOSE, OP_CONCAT, OP_EQ, OP_GEI, OP_GETFIELD, OP_GETI, OP_GETTABLE, OP_GETTABUP, OP_GTI, OP_JMP, OP_LE, OP_LEI, OP_LEN, OP_LT, OP_LTI, OP_MMBIN, OP_MMBINI, OP_MMBINK, OP_RETURN, OP_SELF, OP_SETFIELD, OP_SETI, OP_SETTABLE, OP_SETTABUP, OP_TAILCALL, OP_TFORCALL, OP_UNM, s2v, CallInfo::savedpc, setobjs2s, lua_State::top, and CallInfo::u.

◆ luaV_finishset()

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

Definition at line 330 of file lua-5.4.3/src/lvm.c.

331 {
332 int loop; /* counter to avoid infinite loops */
333 for (loop = 0; loop < MAXTAGLOOP; loop++) {
334 const TValue *tm; /* '__newindex' metamethod */
335 if (slot != NULL) { /* is 't' a table? */
336 Table *h = hvalue(t); /* save 't' table */
337 lua_assert(isempty(slot)); /* slot must be empty */
338 tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */
339 if (tm == NULL) { /* no metamethod? */
340 luaH_finishset(L, h, key, slot, val); /* set new value */
342 luaC_barrierback(L, obj2gco(h), val);
343 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}
@ TM_NEWINDEX
#define invalidateTMcache(t)
void luaT_callTM(lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, TValue *p3, int hasres)
void luaH_finishset(lua_State *L, Table *t, const TValue *key, const TValue *slot, TValue *value)
struct Table * metatable

References fasttm, hvalue, invalidateTMcache, isempty, lua_assert, luaC_barrierback, luaG_runerror(), luaG_typeerror(), luaH_finishset(), luaH_get(), luaT_callTM(), luaT_gettmbyobj(), luaV_fastget, luaV_finishfastset, MAXTAGLOOP, Table::metatable, notm, NULL, obj2gco, TM_NEWINDEX, and ttisfunction.

Referenced by luaV_execute().

◆ luaV_flttointeger()

int luaV_flttointeger ( lua_Number n,
lua_Integer * p,
F2Imod mode )

Definition at line 121 of file lua-5.4.3/src/lvm.c.

121 {
122 lua_Number f = l_floor(n);
123 if (n != f) { /* not an integral value? */
124 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 return lua_numbertointeger(f, p);
129}
#define lua_numbertointeger(n, p)
#define l_floor(x)

References F2Iceil, F2Ieq, l_floor, and lua_numbertointeger.

Referenced by isSCnumber(), LEfloatint(), LEintfloat(), LTfloatint(), LTintfloat(), luaH_get(), luaH_newkey(), luaK_float(), and luaV_tointegerns().

◆ luaV_idiv()

lua_Integer luaV_idiv ( lua_State * L,
lua_Integer m,
lua_Integer n )

Definition at line 718 of file lua-5.4.3/src/lvm.c.

718 {
719 if (l_unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */
720 if (n == 0)
721 luaG_runerror(L, "attempt to divide by zero");
722 return intop(-, 0, m); /* n==-1; avoid overflow with 0x80000...//-1 */
723 }
724 else {
725 lua_Integer q = m / n; /* perform C division */
726 if ((m ^ n) < 0 && m % n != 0) /* 'm/n' would be negative non-integer? */
727 q -= 1; /* correct result for different rounding */
728 return q;
729 }
730}

References intop, l_castS2U, and luaG_runerror().

Referenced by intarith(), and luaV_execute().

◆ luaV_lessequal()

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

Definition at line 554 of file lua-5.4.3/src/lvm.c.

554 {
555 if (ttisnumber(l) && ttisnumber(r)) /* both operands are numbers? */
556 return LEnum(l, r);
557 else return lessequalothers(L, l, r);
558}

References LEnum(), lessequalothers(), and ttisnumber.

◆ luaV_lessthan()

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

Definition at line 532 of file lua-5.4.3/src/lvm.c.

532 {
533 if (ttisnumber(l) && ttisnumber(r)) /* both operands are numbers? */
534 return LTnum(l, r);
535 else return lessthanothers(L, l, r);
536}

References lessthanothers(), LTnum(), and ttisnumber.

◆ luaV_mod()

lua_Integer luaV_mod ( lua_State * L,
lua_Integer m,
lua_Integer n )

Definition at line 738 of file lua-5.4.3/src/lvm.c.

738 {
739 if (l_unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */
740 if (n == 0)
741 luaG_runerror(L, "attempt to perform 'n%%0'");
742 return 0; /* m % -1 == 0; avoid overflow with 0x80000...%-1 */
743 }
744 else {
745 lua_Integer r = m % n;
746 if (r != 0 && (r ^ n) < 0) /* 'm/n' would be non-integer negative? */
747 r += n; /* correct result for different rounding */
748 return r;
749 }
750}

References l_castS2U, and luaG_runerror().

Referenced by luaV_execute().

◆ luaV_modf()

lua_Number luaV_modf ( lua_State * L,
lua_Number m,
lua_Number n )

Definition at line 756 of file lua-5.4.3/src/lvm.c.

756 {
757 lua_Number r;
758 luai_nummod(L, m, n, r);
759 return r;
760}
#define luai_nummod(L, a, b, m)

References luai_nummod.

Referenced by luaV_execute(), and numarith().

◆ luaV_objlen()

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

Definition at line 683 of file lua-5.4.3/src/lvm.c.

683 {
684 const TValue *tm;
685 switch (ttypetag(rb)) {
686 case LUA_VTABLE: {
687 Table *h = hvalue(rb);
688 tm = fasttm(L, h->metatable, TM_LEN);
689 if (tm) break; /* metamethod? break switch to call it */
690 setivalue(s2v(ra), luaH_getn(h)); /* else primitive len */
691 return;
692 }
693 case LUA_VSHRSTR: {
694 setivalue(s2v(ra), tsvalue(rb)->shrlen);
695 return;
696 }
697 case LUA_VLNGSTR: {
698 setivalue(s2v(ra), tsvalue(rb)->u.lnglen);
699 return;
700 }
701 default: { /* try metamethod */
702 tm = luaT_gettmbyobj(L, rb, TM_LEN);
703 if (l_unlikely(notm(tm))) /* no metamethod? */
704 luaG_typeerror(L, rb, "get length of");
705 break;
706 }
707 }
708 luaT_callTMres(L, tm, rb, rb, ra);
709}
int luaH_getn(Table *t)
@ TM_LEN

References fasttm, hvalue, LUA_VLNGSTR, LUA_VSHRSTR, LUA_VTABLE, luaG_typeerror(), luaH_getn(), luaT_callTMres(), luaT_gettmbyobj(), Table::metatable, notm, s2v, setivalue, TM_LEN, tsvalue, and ttypetag.

Referenced by luaV_execute().

◆ luaV_shiftl()

lua_Integer luaV_shiftl ( lua_Integer x,
lua_Integer y )

Definition at line 771 of file lua-5.4.3/src/lvm.c.

771 {
772 if (y < 0) { /* shift right? */
773 if (y <= -NBITS) return 0;
774 else return intop(>>, x, -y);
775 }
776 else { /* shift left */
777 if (y >= NBITS) return 0;
778 else return intop(<<, x, y);
779 }
780}
#define NBITS

References intop, and NBITS.

Referenced by luaV_execute().

◆ luaV_tointeger()

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

Definition at line 152 of file lua-5.4.3/src/lvm.c.

152 {
153 TValue v;
154 if (l_strton(obj, &v)) /* does 'obj' point to a numerical string? */
155 obj = &v; /* change it to point to its corresponding number */
156 return luaV_tointegerns(obj, p, mode);
157}
static int l_strton(const TValue *obj, TValue *result)

References l_strton(), and luaV_tointegerns().

Referenced by forlimit().

◆ luaV_tointegerns()

int luaV_tointegerns ( const TValue * obj,
lua_Integer * p,
F2Imod mode )

Definition at line 137 of file lua-5.4.3/src/lvm.c.

137 {
138 if (ttisfloat(obj))
139 return luaV_flttointeger(fltvalue(obj), p, mode);
140 else if (ttisinteger(obj)) {
141 *p = ivalue(obj);
142 return 1;
143 }
144 else
145 return 0;
146}

References fltvalue, ivalue, luaV_flttointeger(), ttisfloat, and ttisinteger.

Referenced by luaG_tointerror(), luaV_equalobj(), luaV_tointeger(), and validop().

◆ luaV_tonumber_()

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

Definition at line 103 of file lua-5.4.3/src/lvm.c.

103 {
104 TValue v;
105 if (ttisinteger(obj)) {
106 *n = cast_num(ivalue(obj));
107 return 1;
108 }
109 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 return 0; /* conversion failed */
115}
#define nvalue(o)

References cast_num, ivalue, l_strton(), nvalue, and ttisinteger.

◆ pushclosure()

static void pushclosure ( lua_State * L,
Proto * p,
UpVal ** encup,
StkId base,
StkId ra )
static

Definition at line 787 of file lua-5.4.3/src/lvm.c.

788 {
789 int nup = p->sizeupvalues;
790 Upvaldesc *uv = p->upvalues;
791 int i;
792 LClosure *ncl = luaF_newLclosure(L, nup);
793 ncl->p = p;
794 setclLvalue2s(L, ra, ncl); /* anchor new closure in stack */
795 for (i = 0; i < nup; i++) { /* fill in its upvalues */
796 if (uv[i].instack) /* upvalue refers to local variable? */
797 ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx);
798 else /* get upvalue from enclosing function */
799 ncl->upvals[i] = encup[uv[i].idx];
800 luaC_objbarrier(L, ncl, ncl->upvals[i]);
801 }
802}
Closure * luaF_newLclosure(lua_State *L, int nelems, Table *e)
UpVal * luaF_findupval(lua_State *L, StkId level)
#define luaC_objbarrier(L, p, o)
#define setclLvalue2s(L, o, cl)
TString ** upvalues

References Upvaldesc::idx, luaC_objbarrier, luaF_findupval(), luaF_newLclosure(), LClosure::p, setclLvalue2s, Proto::sizeupvalues, LClosure::upvals, and Proto::upvalues.

Referenced by luaV_execute().