Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lcode.c File Reference
#include "lprefix.h"
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include "lua.h"
#include "lcode.h"
#include "ldebug.h"
#include "ldo.h"
#include "lgc.h"
#include "llex.h"
#include "lmem.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lparser.h"
#include "lstring.h"
#include "ltable.h"
#include "lvm.h"

Go to the source code of this file.

Macros

#define lcode_c
 
#define LUA_CORE
 
#define MAXREGS   255
 
#define hasjumps(e)   ((e)->t != (e)->f)
 
#define LIMLINEDIFF   0x80
 

Functions

static int codesJ (FuncState *fs, OpCode o, int sj, int k)
 
l_noret luaK_semerror (LexState *ls, const char *msg)
 
static int tonumeral (const expdesc *e, TValue *v)
 
static TValueconst2val (FuncState *fs, const expdesc *e)
 
int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v)
 
static Instructionpreviousinstruction (FuncState *fs)
 
void luaK_nil (FuncState *fs, int from, int n)
 
static int getjump (FuncState *fs, int pc)
 
static void fixjump (FuncState *fs, int pc, int dest)
 
void luaK_concat (FuncState *fs, int *l1, int l2)
 
int luaK_jump (FuncState *fs)
 
void luaK_ret (FuncState *fs, int first, int nret)
 
static int condjump (FuncState *fs, OpCode op, int A, int B, int C, int k)
 
int luaK_getlabel (FuncState *fs)
 
static Instructiongetjumpcontrol (FuncState *fs, int pc)
 
static int patchtestreg (FuncState *fs, int node, int reg)
 
static void removevalues (FuncState *fs, int list)
 
static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, int dtarget)
 
void luaK_patchlist (FuncState *fs, int list, int target)
 
void luaK_patchtohere (FuncState *fs, int list)
 
static void savelineinfo (FuncState *fs, Proto *f, int line)
 
static void removelastlineinfo (FuncState *fs)
 
static void removelastinstruction (FuncState *fs)
 
int luaK_code (FuncState *fs, Instruction i)
 
int luaK_codeABCk (FuncState *fs, OpCode o, int a, int b, int c, int k)
 
int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc)
 
int luaK_codeAsBx (FuncState *fs, OpCode o, int a, int bc)
 
static int codeextraarg (FuncState *fs, int a)
 
static int luaK_codek (FuncState *fs, int reg, int k)
 
void luaK_checkstack (FuncState *fs, int n)
 
void luaK_reserveregs (FuncState *fs, int n)
 
static void freereg (FuncState *fs, int reg)
 
static void freeregs (FuncState *fs, int r1, int r2)
 
static void freeexp (FuncState *fs, expdesc *e)
 
static void freeexps (FuncState *fs, expdesc *e1, expdesc *e2)
 
static int addk (FuncState *fs, TValue *key, TValue *v)
 
static int stringK (FuncState *fs, TString *s)
 
static int luaK_intK (FuncState *fs, lua_Integer n)
 
static int luaK_numberK (FuncState *fs, lua_Number r)
 
static int boolF (FuncState *fs)
 
static int boolT (FuncState *fs)
 
static int nilK (FuncState *fs)
 
static int fitsC (lua_Integer i)
 
static int fitsBx (lua_Integer i)
 
void luaK_int (FuncState *fs, int reg, lua_Integer i)
 
static void luaK_float (FuncState *fs, int reg, lua_Number f)
 
static void const2exp (TValue *v, expdesc *e)
 
void luaK_setreturns (FuncState *fs, expdesc *e, int nresults)
 
static void str2K (FuncState *fs, expdesc *e)
 
void luaK_setoneret (FuncState *fs, expdesc *e)
 
void luaK_dischargevars (FuncState *fs, expdesc *e)
 
static void discharge2reg (FuncState *fs, expdesc *e, int reg)
 
static void discharge2anyreg (FuncState *fs, expdesc *e)
 
static int code_loadbool (FuncState *fs, int A, OpCode op)
 
static int need_value (FuncState *fs, int list)
 
static void exp2reg (FuncState *fs, expdesc *e, int reg)
 
void luaK_exp2nextreg (FuncState *fs, expdesc *e)
 
int luaK_exp2anyreg (FuncState *fs, expdesc *e)
 
void luaK_exp2anyregup (FuncState *fs, expdesc *e)
 
void luaK_exp2val (FuncState *fs, expdesc *e)
 
static int luaK_exp2K (FuncState *fs, expdesc *e)
 
int luaK_exp2RK (FuncState *fs, expdesc *e)
 
static void codeABRK (FuncState *fs, OpCode o, int a, int b, expdesc *ec)
 
void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex)
 
void luaK_self (FuncState *fs, expdesc *e, expdesc *key)
 
static void negatecondition (FuncState *fs, expdesc *e)
 
static int jumponcond (FuncState *fs, expdesc *e, int cond)
 
void luaK_goiftrue (FuncState *fs, expdesc *e)
 
void luaK_goiffalse (FuncState *fs, expdesc *e)
 
static void codenot (FuncState *fs, expdesc *e)
 
static int isKstr (FuncState *fs, expdesc *e)
 
int luaK_isKint (expdesc *e)
 
static int isCint (expdesc *e)
 
static int isSCint (expdesc *e)
 
static int isSCnumber (expdesc *e, int *pi, int *isfloat)
 
void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k)
 
static int validop (int op, TValue *v1, TValue *v2)
 
static int constfolding (FuncState *fs, int op, expdesc *e1, const expdesc *e2)
 
static void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line)
 
static void finishbinexpval (FuncState *fs, expdesc *e1, expdesc *e2, OpCode op, int v2, int flip, int line, OpCode mmop, TMS event)
 
static void codebinexpval (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2, int line)
 
static void codebini (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2, int flip, int line, TMS event)
 
static int finishbinexpneg (FuncState *fs, expdesc *e1, expdesc *e2, OpCode op, int line, TMS event)
 
static void swapexps (expdesc *e1, expdesc *e2)
 
static void codearith (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2, int flip, int line)
 
static void codecommutative (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2, int line)
 
static void codebitwise (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2, int line)
 
static void codeorder (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2)
 
static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2)
 
void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line)
 
void luaK_infix (FuncState *fs, BinOpr op, expdesc *v)
 
static void codeconcat (FuncState *fs, expdesc *e1, expdesc *e2, int line)
 
void luaK_posfix (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2, int line)
 
void luaK_fixline (FuncState *fs, int line)
 
void luaK_settablesize (FuncState *fs, int pc, int ra, int asize, int hsize)
 
void luaK_setlist (FuncState *fs, int base, int nelems, int tostore)
 
static int finaltarget (Instruction *code, int i)
 
void luaK_finish (FuncState *fs)
 

Macro Definition Documentation

◆ hasjumps

#define hasjumps ( e)    ((e)->t != (e)->f)

◆ lcode_c

#define lcode_c

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

◆ LIMLINEDIFF

#define LIMLINEDIFF   0x80

Definition at line 318 of file lua-5.4.3/src/lcode.c.

Referenced by savelineinfo().

◆ LUA_CORE

#define LUA_CORE

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

◆ MAXREGS

#define MAXREGS   255

Definition at line 34 of file lua-5.4.3/src/lcode.c.

Referenced by luaK_checkstack().

Function Documentation

◆ addk()

static int addk ( FuncState * fs,
TValue * key,
TValue * v )
static

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

542 {
543 TValue val;
544 lua_State *L = fs->ls->L;
545 Proto *f = fs->f;
546 const TValue *idx = luaH_get(fs->ls->h, key); /* query scanner table */
547 int k, oldsize;
548 if (ttisinteger(idx)) { /* is there an index there? */
549 k = cast_int(ivalue(idx));
550 /* correct value? (warning: must distinguish floats from integers!) */
551 if (k < fs->nk && ttypetag(&f->k[k]) == ttypetag(v) &&
552 luaV_rawequalobj(&f->k[k], v))
553 return k; /* reuse index */
554 }
555 /* constant not found; create a new entry */
556 oldsize = f->sizek;
557 k = fs->nk;
558 /* numerical value does not need GC barrier;
559 table has no metatable, so it does not need to invalidate cache */
560 setivalue(&val, k);
561 luaH_finishset(L, fs->ls->h, key, idx, &val);
562 luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");
563 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
564 setobj(L, &f->k[k], v);
565 fs->nk++;
566 luaC_barrier(L, f, v);
567 return k;
568}
#define luaC_barrier(L, p, v)
#define cast_int(i)
#define luaM_growvector(L, v, nelems, size, t, limit, e)
#define setobj(L, obj1, obj2)
#define setnilvalue(obj)
const TValue * luaH_get(Table *t, const TValue *key)
#define MAXARG_Ax
#define luaV_rawequalobj(o1, o2)
#define ttisinteger(o)
#define ivalue(o)
#define setivalue(obj, x)
#define ttypetag(o)
void luaH_finishset(lua_State *L, Table *t, const TValue *key, const TValue *slot, TValue *value)
struct LexState * ls
struct lua_State * L

References cast_int, FuncState::f, LexState::h, ivalue, Proto::k, LexState::L, FuncState::ls, luaC_barrier, luaH_finishset(), luaH_get(), luaM_growvector, luaV_rawequalobj, MAXARG_Ax, FuncState::nk, setivalue, setnilvalue, setobj, Proto::sizek, ttisinteger, and ttypetag.

Referenced by boolF(), boolT(), luaK_intK(), luaK_numberK(), nilK(), and stringK().

◆ boolF()

static int boolF ( FuncState * fs)
static

Definition at line 607 of file lua-5.4.3/src/lcode.c.

607 {
608 TValue o;
609 setbfvalue(&o);
610 return addk(fs, &o, &o); /* use boolean itself as key */
611}
static int addk(FuncState *fs, TValue *key, TValue *v)
#define setbfvalue(obj)

References addk(), and setbfvalue.

Referenced by luaK_exp2K().

◆ boolT()

static int boolT ( FuncState * fs)
static

Definition at line 617 of file lua-5.4.3/src/lcode.c.

617 {
618 TValue o;
619 setbtvalue(&o);
620 return addk(fs, &o, &o); /* use boolean itself as key */
621}
#define setbtvalue(obj)

References addk(), and setbtvalue.

Referenced by luaK_exp2K().

◆ code_loadbool()

static int code_loadbool ( FuncState * fs,
int A,
OpCode op )
static

Definition at line 870 of file lua-5.4.3/src/lcode.c.

870 {
871 luaK_getlabel(fs); /* those instructions may be jump targets */
872 return luaK_codeABC(fs, op, A, 0, 0);
873}
int luaK_getlabel(FuncState *fs)
#define luaK_codeABC(fs, o, a, b, c)

References luaK_codeABC, and luaK_getlabel().

Referenced by exp2reg().

◆ codeABRK()

static void codeABRK ( FuncState * fs,
OpCode o,
int a,
int b,
expdesc * ec )
static

Definition at line 1020 of file lua-5.4.3/src/lcode.c.

1021 {
1022 int k = luaK_exp2RK(fs, ec);
1023 luaK_codeABCk(fs, o, a, b, ec->u.info, k);
1024}
int luaK_codeABCk(FuncState *fs, OpCode o, int a, int b, int c, int k)
int luaK_exp2RK(FuncState *fs, expdesc *e)
union expdesc::@52 u

References expdesc::info, luaK_codeABCk(), luaK_exp2RK(), and expdesc::u.

Referenced by luaK_self(), and luaK_storevar().

◆ codearith()

static void codearith ( FuncState * fs,
BinOpr opr,
expdesc * e1,
expdesc * e2,
int flip,
int line )
static

Definition at line 1426 of file lua-5.4.3/src/lcode.c.

1427 {
1428 TMS event = cast(TMS, opr + TM_ADD);
1429 if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) { /* K operand? */
1430 int v2 = e2->u.info; /* K index */
1431 OpCode op = cast(OpCode, opr + OP_ADDK);
1432 finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event);
1433 }
1434 else { /* 'e2' is neither an immediate nor a K operand */
1435 OpCode op = cast(OpCode, opr + OP_ADD);
1436 if (flip)
1437 swapexps(e1, e2); /* back to original order */
1438 codebinexpval(fs, op, e1, e2, line); /* use standard operators */
1439 }
1440}
#define NULL
Definition gmacros.h:924
#define cast(t, exp)
@ TM_ADD
static void finishbinexpval(FuncState *fs, expdesc *e1, expdesc *e2, OpCode op, int v2, int flip, int line, OpCode mmop, TMS event)
static int luaK_exp2K(FuncState *fs, expdesc *e)
static void swapexps(expdesc *e1, expdesc *e2)
static void codebinexpval(FuncState *fs, OpCode op, expdesc *e1, expdesc *e2, int line)
static int tonumeral(const expdesc *e, TValue *v)

References cast, codebinexpval(), finishbinexpval(), expdesc::info, luaK_exp2K(), NULL, OP_ADD, OP_ADDK, OP_MMBINK, swapexps(), TM_ADD, tonumeral(), and expdesc::u.

Referenced by codecommutative(), and luaK_posfix().

◆ codebinexpval()

static void codebinexpval ( FuncState * fs,
OpCode op,
expdesc * e1,
expdesc * e2,
int line )
static

Definition at line 1374 of file lua-5.4.3/src/lcode.c.

1375 {
1376 int v2 = luaK_exp2anyreg(fs, e2); /* both operands are in registers */
1377 lua_assert(OP_ADD <= op && op <= OP_SHR);
1378 finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN,
1379 cast(TMS, (op - OP_ADD) + TM_ADD));
1380}
#define lua_assert(c)
int luaK_exp2anyreg(FuncState *fs, expdesc *e)

References cast, finishbinexpval(), lua_assert, luaK_exp2anyreg(), OP_ADD, OP_MMBIN, OP_SHR, and TM_ADD.

Referenced by codearith(), codebitwise(), and luaK_posfix().

◆ codebini()

static void codebini ( FuncState * fs,
OpCode op,
expdesc * e1,
expdesc * e2,
int flip,
int line,
TMS event )
static

Definition at line 1386 of file lua-5.4.3/src/lcode.c.

1388 {
1389 int v2 = int2sC(cast_int(e2->u.ival)); /* immediate operand */
1390 lua_assert(e2->k == VKINT);
1391 finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINI, event);
1392}
#define int2sC(i)
lua_Integer ival

References cast_int, finishbinexpval(), int2sC, expdesc::ival, expdesc::k, lua_assert, OP_MMBINI, expdesc::u, and VKINT.

Referenced by codecommutative(), and luaK_posfix().

◆ codebitwise()

static void codebitwise ( FuncState * fs,
BinOpr opr,
expdesc * e1,
expdesc * e2,
int line )
static

Definition at line 1466 of file lua-5.4.3/src/lcode.c.

1467 {
1468 int flip = 0;
1469 int v2;
1470 OpCode op;
1471 if (e1->k == VKINT && luaK_exp2RK(fs, e1)) {
1472 swapexps(e1, e2); /* 'e2' will be the constant operand */
1473 flip = 1;
1474 }
1475 else if (!(e2->k == VKINT && luaK_exp2RK(fs, e2))) { /* no constants? */
1476 op = cast(OpCode, opr + OP_ADD);
1477 codebinexpval(fs, op, e1, e2, line); /* all-register opcodes */
1478 return;
1479 }
1480 v2 = e2->u.info; /* index in K array */
1481 op = cast(OpCode, opr + OP_ADDK);
1482 lua_assert(ttisinteger(&fs->f->k[v2]));
1483 finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK,
1484 cast(TMS, opr + TM_ADD));
1485}

References cast, codebinexpval(), FuncState::f, finishbinexpval(), expdesc::info, Proto::k, expdesc::k, lua_assert, luaK_exp2RK(), OP_ADD, OP_ADDK, OP_MMBINK, swapexps(), TM_ADD, ttisinteger, expdesc::u, and VKINT.

Referenced by luaK_posfix().

◆ codecommutative()

static void codecommutative ( FuncState * fs,
BinOpr op,
expdesc * e1,
expdesc * e2,
int line )
static

Definition at line 1448 of file lua-5.4.3/src/lcode.c.

1449 {
1450 int flip = 0;
1451 if (tonumeral(e1, NULL)) { /* is first operand a numeric constant? */
1452 swapexps(e1, e2); /* change order */
1453 flip = 1;
1454 }
1455 if (op == OPR_ADD && isSCint(e2)) /* immediate operand? */
1456 codebini(fs, cast(OpCode, OP_ADDI), e1, e2, flip, line, TM_ADD);
1457 else
1458 codearith(fs, op, e1, e2, flip, line);
1459}
static int isSCint(expdesc *e)
static void codebini(FuncState *fs, OpCode op, expdesc *e1, expdesc *e2, int flip, int line, TMS event)
static void codearith(FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2, int flip, int line)

References cast, codearith(), codebini(), isSCint(), NULL, OP_ADDI, OPR_ADD, swapexps(), TM_ADD, and tonumeral().

Referenced by luaK_posfix().

◆ codeconcat()

static void codeconcat ( FuncState * fs,
expdesc * e1,
expdesc * e2,
int line )
static

Definition at line 1622 of file lua-5.4.3/src/lcode.c.

1622 {
1624 if (GET_OPCODE(*ie2) == OP_CONCAT) { /* is 'e2' a concatenation? */
1625 int n = GETARG_B(*ie2); /* # of elements concatenated in 'e2' */
1626 lua_assert(e1->u.info + 1 == GETARG_A(*ie2));
1627 freeexp(fs, e2);
1628 SETARG_A(*ie2, e1->u.info); /* correct first element ('e1') */
1629 SETARG_B(*ie2, n + 1); /* will concatenate one more element */
1630 }
1631 else { /* 'e2' is not a concatenation */
1632 luaK_codeABC(fs, OP_CONCAT, e1->u.info, 2, 0); /* new concat opcode */
1633 freeexp(fs, e2);
1634 luaK_fixline(fs, line);
1635 }
1636}
lu_int32 Instruction
#define GETARG_A(i)
#define GETARG_B(i)
#define GET_OPCODE(i)
#define SETARG_B(i, b)
#define SETARG_A(i, u)
static Instruction * previousinstruction(FuncState *fs)
static void freeexp(FuncState *fs, expdesc *e)
void luaK_fixline(FuncState *fs, int line)

References freeexp(), GET_OPCODE, GETARG_A, GETARG_B, expdesc::info, lua_assert, luaK_codeABC, luaK_fixline(), OP_CONCAT, previousinstruction(), SETARG_A, SETARG_B, and expdesc::u.

Referenced by luaK_posfix().

◆ codeeq()

static void codeeq ( FuncState * fs,
BinOpr opr,
expdesc * e1,
expdesc * e2 )
static

Definition at line 1522 of file lua-5.4.3/src/lcode.c.

1522 {
1523 int r1, r2;
1524 int im;
1525 int isfloat = 0; /* not needed here, but kept for symmetry */
1526 OpCode op;
1527 if (e1->k != VNONRELOC) {
1528 lua_assert(e1->k == VK || e1->k == VKINT || e1->k == VKFLT);
1529 swapexps(e1, e2);
1530 }
1531 r1 = luaK_exp2anyreg(fs, e1); /* 1st expression must be in register */
1532 if (isSCnumber(e2, &im, &isfloat)) {
1533 op = OP_EQI;
1534 r2 = im; /* immediate operand */
1535 }
1536 else if (luaK_exp2RK(fs, e2)) { /* 1st expression is constant? */
1537 op = OP_EQK;
1538 r2 = e2->u.info; /* constant index */
1539 }
1540 else {
1541 op = OP_EQ; /* will compare two registers */
1542 r2 = luaK_exp2anyreg(fs, e2);
1543 }
1544 freeexps(fs, e1, e2);
1545 e1->u.info = condjump(fs, op, r1, r2, isfloat, (opr == OPR_EQ));
1546 e1->k = VJMP;
1547}
static void freeexps(FuncState *fs, expdesc *e1, expdesc *e2)
static int condjump(FuncState *fs, OpCode op, int A, int B, int C, int k)
static int isSCnumber(expdesc *e, int *pi, int *isfloat)

References condjump(), freeexps(), expdesc::info, isSCnumber(), expdesc::k, lua_assert, luaK_exp2anyreg(), luaK_exp2RK(), OP_EQ, OP_EQI, OP_EQK, OPR_EQ, swapexps(), expdesc::u, VJMP, VK, VKFLT, VKINT, and VNONRELOC.

Referenced by luaK_posfix().

◆ codeextraarg()

static int codeextraarg ( FuncState * fs,
int a )
static

Definition at line 439 of file lua-5.4.3/src/lcode.c.

439 {
441 return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a));
442}
#define CREATE_Ax(o, a)
int luaK_code(FuncState *fs, Instruction i)

References CREATE_Ax, lua_assert, luaK_code(), MAXARG_Ax, and OP_EXTRAARG.

Referenced by luaK_codek(), and luaK_setlist().

◆ codenot()

static void codenot ( FuncState * fs,
expdesc * e )
static

Definition at line 1168 of file lua-5.4.3/src/lcode.c.

1168 {
1169 switch (e->k) {
1170 case VNIL: case VFALSE: {
1171 e->k = VTRUE; /* true == not nil == not false */
1172 break;
1173 }
1174 case VK: case VKFLT: case VKINT: case VKSTR: case VTRUE: {
1175 e->k = VFALSE; /* false == not "x" == not 0.5 == not 1 == not true */
1176 break;
1177 }
1178 case VJMP: {
1179 negatecondition(fs, e);
1180 break;
1181 }
1182 case VRELOC:
1183 case VNONRELOC: {
1184 discharge2anyreg(fs, e);
1185 freeexp(fs, e);
1186 e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);
1187 e->k = VRELOC;
1188 break;
1189 }
1190 default: lua_assert(0); /* cannot happen */
1191 }
1192 /* interchange true and false lists */
1193 { int temp = e->f; e->f = e->t; e->t = temp; }
1194 removevalues(fs, e->f); /* values are useless when negated */
1195 removevalues(fs, e->t);
1196}
static void discharge2anyreg(FuncState *fs, expdesc *e)
static void negatecondition(FuncState *fs, expdesc *e)
static void removevalues(FuncState *fs, int list)

References discharge2anyreg(), expdesc::f, freeexp(), expdesc::info, expdesc::k, lua_assert, luaK_codeABC, negatecondition(), OP_NOT, removevalues(), expdesc::t, expdesc::u, VFALSE, VJMP, VK, VKFLT, VKINT, VKSTR, VNIL, VNONRELOC, VRELOC, and VTRUE.

Referenced by luaK_prefix().

◆ codeorder()

static void codeorder ( FuncState * fs,
OpCode op,
expdesc * e1,
expdesc * e2 )
static

Definition at line 1492 of file lua-5.4.3/src/lcode.c.

1492 {
1493 int r1, r2;
1494 int im;
1495 int isfloat = 0;
1496 if (isSCnumber(e2, &im, &isfloat)) {
1497 /* use immediate operand */
1498 r1 = luaK_exp2anyreg(fs, e1);
1499 r2 = im;
1500 op = cast(OpCode, (op - OP_LT) + OP_LTI);
1501 }
1502 else if (isSCnumber(e1, &im, &isfloat)) {
1503 /* transform (A < B) to (B > A) and (A <= B) to (B >= A) */
1504 r1 = luaK_exp2anyreg(fs, e2);
1505 r2 = im;
1506 op = (op == OP_LT) ? OP_GTI : OP_GEI;
1507 }
1508 else { /* regular case, compare two registers */
1509 r1 = luaK_exp2anyreg(fs, e1);
1510 r2 = luaK_exp2anyreg(fs, e2);
1511 }
1512 freeexps(fs, e1, e2);
1513 e1->u.info = condjump(fs, op, r1, r2, isfloat, 1);
1514 e1->k = VJMP;
1515}

References cast, condjump(), freeexps(), expdesc::info, isSCnumber(), expdesc::k, luaK_exp2anyreg(), OP_GEI, OP_GTI, OP_LT, OP_LTI, expdesc::u, and VJMP.

Referenced by luaK_posfix().

◆ codesJ()

static int codesJ ( FuncState * fs,
OpCode o,
int sj,
int k )
static

Definition at line 428 of file lua-5.4.3/src/lcode.c.

428 {
429 unsigned int j = sj + OFFSET_sJ;
430 lua_assert(getOpMode(o) == isJ);
431 lua_assert(j <= MAXARG_sJ && (k & ~1) == 0);
432 return luaK_code(fs, CREATE_sJ(o, j, k));
433}
#define getOpMode(m)
#define OFFSET_sJ
#define MAXARG_sJ
#define CREATE_sJ(o, j, k)

References CREATE_sJ, getOpMode, isJ, lua_assert, luaK_code(), MAXARG_sJ, and OFFSET_sJ.

Referenced by luaK_jump().

◆ codeunexpval()

static void codeunexpval ( FuncState * fs,
OpCode op,
expdesc * e,
int line )
static

Definition at line 1341 of file lua-5.4.3/src/lcode.c.

1341 {
1342 int r = luaK_exp2anyreg(fs, e); /* opcodes operate only on registers */
1343 freeexp(fs, e);
1344 e->u.info = luaK_codeABC(fs, op, 0, r, 0); /* generate opcode */
1345 e->k = VRELOC; /* all those operations are relocatable */
1346 luaK_fixline(fs, line);
1347}

References freeexp(), expdesc::info, expdesc::k, luaK_codeABC, luaK_exp2anyreg(), luaK_fixline(), expdesc::u, and VRELOC.

Referenced by luaK_prefix().

◆ condjump()

static int condjump ( FuncState * fs,
OpCode op,
int A,
int B,
int C,
int k )
static

Definition at line 221 of file lua-5.4.3/src/lcode.c.

221 {
222 luaK_codeABCk(fs, op, A, B, C, k);
223 return luaK_jump(fs);
224}
int luaK_jump(FuncState *fs)

References luaK_codeABCk(), and luaK_jump().

Referenced by codeeq(), codeorder(), and jumponcond().

◆ const2exp()

static void const2exp ( TValue * v,
expdesc * e )
static

Definition at line 674 of file lua-5.4.3/src/lcode.c.

674 {
675 switch (ttypetag(v)) {
676 case LUA_VNUMINT:
677 e->k = VKINT; e->u.ival = ivalue(v);
678 break;
679 case LUA_VNUMFLT:
680 e->k = VKFLT; e->u.nval = fltvalue(v);
681 break;
682 case LUA_VFALSE:
683 e->k = VFALSE;
684 break;
685 case LUA_VTRUE:
686 e->k = VTRUE;
687 break;
688 case LUA_VNIL:
689 e->k = VNIL;
690 break;
691 case LUA_VSHRSTR: case LUA_VLNGSTR:
692 e->k = VKSTR; e->u.strval = tsvalue(v);
693 break;
694 default: lua_assert(0);
695 }
696}
#define tsvalue(o)
#define fltvalue(o)
#define LUA_VNUMFLT
#define LUA_VLNGSTR
#define LUA_VNUMINT
#define LUA_VSHRSTR
#define LUA_VFALSE
#define LUA_VNIL
#define LUA_VTRUE
lua_Number nval

References fltvalue, expdesc::ival, ivalue, expdesc::k, lua_assert, LUA_VFALSE, LUA_VLNGSTR, LUA_VNIL, LUA_VNUMFLT, LUA_VNUMINT, LUA_VSHRSTR, LUA_VTRUE, expdesc::nval, expdesc::strval, tsvalue, ttypetag, expdesc::u, VFALSE, VKFLT, VKINT, VKSTR, VNIL, and VTRUE.

Referenced by luaK_dischargevars().

◆ const2val()

static TValue * const2val ( FuncState * fs,
const expdesc * e )
static

Definition at line 73 of file lua-5.4.3/src/lcode.c.

73 {
74 lua_assert(e->k == VCONST);
75 return &fs->ls->dyd->actvar.arr[e->u.info].k;
76}
struct Dyndata::@63 actvar
struct Dyndata * dyd

References Dyndata::actvar, Dyndata::arr, LexState::dyd, expdesc::info, expdesc::k, Vardesc::k, FuncState::ls, lua_assert, expdesc::u, and VCONST.

Referenced by luaK_dischargevars(), and luaK_exp2const().

◆ constfolding()

static int constfolding ( FuncState * fs,
int op,
expdesc * e1,
const expdesc * e2 )
static

Definition at line 1315 of file lua-5.4.3/src/lcode.c.

1316 {
1317 TValue v1, v2, res;
1318 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))
1319 return 0; /* non-numeric operands or not safe to fold */
1320 luaO_rawarith(fs->ls->L, op, &v1, &v2, &res); /* does operation */
1321 if (ttisinteger(&res)) {
1322 e1->k = VKINT;
1323 e1->u.ival = ivalue(&res);
1324 }
1325 else { /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */
1326 lua_Number n = fltvalue(&res);
1327 if (luai_numisnan(n) || n == 0)
1328 return 0;
1329 e1->k = VKFLT;
1330 e1->u.nval = n;
1331 }
1332 return 1;
1333}
LUA_NUMBER lua_Number
#define luai_numisnan(a)
static int validop(int op, TValue *v1, TValue *v2)
int luaO_rawarith(lua_State *L, int op, const TValue *p1, const TValue *p2, TValue *res)

References fltvalue, expdesc::ival, ivalue, expdesc::k, LexState::L, FuncState::ls, luai_numisnan, luaO_rawarith(), expdesc::nval, tonumeral(), ttisinteger, expdesc::u, validop(), VKFLT, and VKINT.

Referenced by luaK_posfix(), and luaK_prefix().

◆ discharge2anyreg()

static void discharge2anyreg ( FuncState * fs,
expdesc * e )
static

Definition at line 862 of file lua-5.4.3/src/lcode.c.

862 {
863 if (e->k != VNONRELOC) { /* no fixed register yet? */
864 luaK_reserveregs(fs, 1); /* get a register */
865 discharge2reg(fs, e, fs->freereg-1); /* put value there */
866 }
867}
static void discharge2reg(FuncState *fs, expdesc *e, int reg)
void luaK_reserveregs(FuncState *fs, int n)

References discharge2reg(), FuncState::freereg, expdesc::k, luaK_reserveregs(), and VNONRELOC.

Referenced by codenot(), and jumponcond().

◆ discharge2reg()

static void discharge2reg ( FuncState * fs,
expdesc * e,
int reg )
static

Definition at line 807 of file lua-5.4.3/src/lcode.c.

807 {
808 luaK_dischargevars(fs, e);
809 switch (e->k) {
810 case VNIL: {
811 luaK_nil(fs, reg, 1);
812 break;
813 }
814 case VFALSE: {
815 luaK_codeABC(fs, OP_LOADFALSE, reg, 0, 0);
816 break;
817 }
818 case VTRUE: {
819 luaK_codeABC(fs, OP_LOADTRUE, reg, 0, 0);
820 break;
821 }
822 case VKSTR: {
823 str2K(fs, e);
824 } /* FALLTHROUGH */
825 case VK: {
826 luaK_codek(fs, reg, e->u.info);
827 break;
828 }
829 case VKFLT: {
830 luaK_float(fs, reg, e->u.nval);
831 break;
832 }
833 case VKINT: {
834 luaK_int(fs, reg, e->u.ival);
835 break;
836 }
837 case VRELOC: {
838 Instruction *pc = &getinstruction(fs, e);
839 SETARG_A(*pc, reg); /* instruction will put result in 'reg' */
840 break;
841 }
842 case VNONRELOC: {
843 if (reg != e->u.info)
844 luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);
845 break;
846 }
847 default: {
848 lua_assert(e->k == VJMP);
849 return; /* nothing to do... */
850 }
851 }
852 e->u.info = reg;
853 e->k = VNONRELOC;
854}
#define getinstruction(fs, e)
void luaK_int(FuncState *fs, int reg, lua_Integer i)
static void luaK_float(FuncState *fs, int reg, lua_Number f)
void luaK_nil(FuncState *fs, int from, int n)
static int luaK_codek(FuncState *fs, int reg, int k)
void luaK_dischargevars(FuncState *fs, expdesc *e)
static void str2K(FuncState *fs, expdesc *e)

References getinstruction, expdesc::info, expdesc::ival, expdesc::k, lua_assert, luaK_codeABC, luaK_codek(), luaK_dischargevars(), luaK_float(), luaK_int(), luaK_nil(), expdesc::nval, OP_LOADFALSE, OP_LOADTRUE, OP_MOVE, SETARG_A, str2K(), expdesc::u, VFALSE, VJMP, VK, VKFLT, VKINT, VKSTR, VNIL, VNONRELOC, VRELOC, and VTRUE.

Referenced by discharge2anyreg(), and exp2reg().

◆ exp2reg()

static void exp2reg ( FuncState * fs,
expdesc * e,
int reg )
static

Definition at line 896 of file lua-5.4.3/src/lcode.c.

896 {
897 discharge2reg(fs, e, reg);
898 if (e->k == VJMP) /* expression itself is a test? */
899 luaK_concat(fs, &e->t, e->u.info); /* put this jump in 't' list */
900 if (hasjumps(e)) {
901 int final; /* position after whole expression */
902 int p_f = NO_JUMP; /* position of an eventual LOAD false */
903 int p_t = NO_JUMP; /* position of an eventual LOAD true */
904 if (need_value(fs, e->t) || need_value(fs, e->f)) {
905 int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);
906 p_f = code_loadbool(fs, reg, OP_LFALSESKIP); /* skip next inst. */
907 p_t = code_loadbool(fs, reg, OP_LOADTRUE);
908 /* jump around these booleans if 'e' is not a test */
909 luaK_patchtohere(fs, fj);
910 }
911 final = luaK_getlabel(fs);
912 patchlistaux(fs, e->f, final, reg, p_f);
913 patchlistaux(fs, e->t, final, reg, p_t);
914 }
915 e->f = e->t = NO_JUMP;
916 e->u.info = reg;
917 e->k = VNONRELOC;
918}
#define NO_JUMP
void luaK_patchtohere(FuncState *fs, int list)
#define hasjumps(e)
static void patchlistaux(FuncState *fs, int list, int vtarget, int reg, int dtarget)
void luaK_concat(FuncState *fs, int *l1, int l2)
static int code_loadbool(FuncState *fs, int A, OpCode op)
static int need_value(FuncState *fs, int list)

References code_loadbool(), discharge2reg(), expdesc::f, hasjumps, expdesc::info, expdesc::k, luaK_concat(), luaK_getlabel(), luaK_jump(), luaK_patchtohere(), need_value(), NO_JUMP, OP_LFALSESKIP, OP_LOADTRUE, patchlistaux(), expdesc::t, expdesc::u, VJMP, and VNONRELOC.

Referenced by luaK_exp2anyreg(), luaK_exp2nextreg(), and luaK_storevar().

◆ finaltarget()

static int finaltarget ( Instruction * code,
int i )
static

Definition at line 1769 of file lua-5.4.3/src/lcode.c.

1769 {
1770 int count;
1771 for (count = 0; count < 100; count++) { /* avoid infinite loops */
1772 Instruction pc = code[i];
1773 if (GET_OPCODE(pc) != OP_JMP)
1774 break;
1775 else
1776 i += GETARG_sJ(pc) + 1;
1777 }
1778 return i;
1779}
#define GETARG_sJ(i)

References GET_OPCODE, GETARG_sJ, and OP_JMP.

Referenced by luaK_finish().

◆ finishbinexpneg()

static int finishbinexpneg ( FuncState * fs,
expdesc * e1,
expdesc * e2,
OpCode op,
int line,
TMS event )
static

Definition at line 1398 of file lua-5.4.3/src/lcode.c.

1399 {
1400 if (!luaK_isKint(e2))
1401 return 0; /* not an integer constant */
1402 else {
1403 lua_Integer i2 = e2->u.ival;
1404 if (!(fitsC(i2) && fitsC(-i2)))
1405 return 0; /* not in the proper range */
1406 else { /* operating a small integer constant */
1407 int v2 = cast_int(i2);
1408 finishbinexpval(fs, e1, e2, op, int2sC(-v2), 0, line, OP_MMBINI, event);
1409 /* correct metamethod argument */
1410 SETARG_B(fs->f->code[fs->pc - 1], int2sC(v2));
1411 return 1; /* successfully coded */
1412 }
1413 }
1414}
LUA_INTEGER lua_Integer
static int fitsC(lua_Integer i)
int luaK_isKint(expdesc *e)
Instruction * code

References cast_int, Proto::code, FuncState::f, finishbinexpval(), fitsC(), int2sC, expdesc::ival, luaK_isKint(), OP_MMBINI, FuncState::pc, SETARG_B, and expdesc::u.

Referenced by luaK_posfix().

◆ finishbinexpval()

static void finishbinexpval ( FuncState * fs,
expdesc * e1,
expdesc * e2,
OpCode op,
int v2,
int flip,
int line,
OpCode mmop,
TMS event )
static

Definition at line 1356 of file lua-5.4.3/src/lcode.c.

1358 {
1359 int v1 = luaK_exp2anyreg(fs, e1);
1360 int pc = luaK_codeABCk(fs, op, 0, v1, v2, 0);
1361 freeexps(fs, e1, e2);
1362 e1->u.info = pc;
1363 e1->k = VRELOC; /* all those operations are relocatable */
1364 luaK_fixline(fs, line);
1365 luaK_codeABCk(fs, mmop, v1, v2, event, flip); /* to call metamethod */
1366 luaK_fixline(fs, line);
1367}

References freeexps(), expdesc::info, expdesc::k, luaK_codeABCk(), luaK_exp2anyreg(), luaK_fixline(), expdesc::u, and VRELOC.

Referenced by codearith(), codebinexpval(), codebini(), codebitwise(), and finishbinexpneg().

◆ fitsBx()

static int fitsBx ( lua_Integer i)
static

Definition at line 649 of file lua-5.4.3/src/lcode.c.

649 {
650 return (-OFFSET_sBx <= i && i <= MAXARG_Bx - OFFSET_sBx);
651}
#define MAXARG_Bx
#define OFFSET_sBx

References MAXARG_Bx, and OFFSET_sBx.

Referenced by luaK_float(), and luaK_int().

◆ fitsC()

static int fitsC ( lua_Integer i)
static

Definition at line 641 of file lua-5.4.3/src/lcode.c.

641 {
642 return (l_castS2U(i) + OFFSET_sC <= cast_uint(MAXARG_C));
643}
#define MAXARG_C
#define l_castS2U(i)
#define cast_uint(i)
#define OFFSET_sC

References cast_uint, l_castS2U, MAXARG_C, and OFFSET_sC.

Referenced by finishbinexpneg(), isSCint(), and isSCnumber().

◆ fixjump()

static void fixjump ( FuncState * fs,
int pc,
int dest )
static

Definition at line 166 of file lua-5.4.3/src/lcode.c.

166 {
167 Instruction *jmp = &fs->f->code[pc];
168 int offset = dest - (pc + 1);
169 lua_assert(dest != NO_JUMP);
170 if (!(-OFFSET_sJ <= offset && offset <= MAXARG_sJ - OFFSET_sJ))
171 luaX_syntaxerror(fs->ls, "control structure too long");
172 lua_assert(GET_OPCODE(*jmp) == OP_JMP);
173 SETARG_sJ(*jmp, offset);
174}
void luaX_syntaxerror(LexState *ls, const char *msg)
#define SETARG_sJ(i, j)

References Proto::code, FuncState::f, GET_OPCODE, FuncState::ls, lua_assert, luaX_syntaxerror(), MAXARG_sJ, NO_JUMP, OFFSET_sJ, OP_JMP, and SETARG_sJ.

Referenced by luaK_concat(), luaK_finish(), and patchlistaux().

◆ freeexp()

static void freeexp ( FuncState * fs,
expdesc * e )
static

Definition at line 516 of file lua-5.4.3/src/lcode.c.

516 {
517 if (e->k == VNONRELOC)
518 freereg(fs, e->u.info);
519}
static void freereg(FuncState *fs, int reg)

References freereg(), expdesc::info, expdesc::k, expdesc::u, and VNONRELOC.

Referenced by codeconcat(), codenot(), codeunexpval(), jumponcond(), luaK_exp2nextreg(), luaK_self(), and luaK_storevar().

◆ freeexps()

static void freeexps ( FuncState * fs,
expdesc * e1,
expdesc * e2 )
static

Definition at line 526 of file lua-5.4.3/src/lcode.c.

526 {
527 int r1 = (e1->k == VNONRELOC) ? e1->u.info : -1;
528 int r2 = (e2->k == VNONRELOC) ? e2->u.info : -1;
529 freeregs(fs, r1, r2);
530}
static void freeregs(FuncState *fs, int r1, int r2)

References freeregs(), expdesc::info, expdesc::k, expdesc::u, and VNONRELOC.

Referenced by codeeq(), codeorder(), and finishbinexpval().

◆ freereg()

static void freereg ( FuncState * fs,
int reg )
static

Definition at line 490 of file lua-5.4.3/src/lcode.c.

490 {
491 if (reg >= luaY_nvarstack(fs)) {
492 fs->freereg--;
493 lua_assert(reg == fs->freereg);
494 }
495}
int luaY_nvarstack(FuncState *fs)

References FuncState::freereg, lua_assert, and luaY_nvarstack().

Referenced by freeexp(), freeregs(), and luaK_dischargevars().

◆ freeregs()

static void freeregs ( FuncState * fs,
int r1,
int r2 )
static

Definition at line 501 of file lua-5.4.3/src/lcode.c.

501 {
502 if (r1 > r2) {
503 freereg(fs, r1);
504 freereg(fs, r2);
505 }
506 else {
507 freereg(fs, r2);
508 freereg(fs, r1);
509 }
510}

References freereg().

Referenced by freeexps(), and luaK_dischargevars().

◆ getjump()

static int getjump ( FuncState * fs,
int pc )
static

Definition at line 153 of file lua-5.4.3/src/lcode.c.

153 {
154 int offset = GETARG_sJ(fs->f->code[pc]);
155 if (offset == NO_JUMP) /* point to itself represents end of list */
156 return NO_JUMP; /* end of list */
157 else
158 return (pc+1)+offset; /* turn offset into absolute position */
159}

References Proto::code, FuncState::f, GETARG_sJ, and NO_JUMP.

Referenced by luaK_concat(), need_value(), patchlistaux(), and removevalues().

◆ getjumpcontrol()

static Instruction * getjumpcontrol ( FuncState * fs,
int pc )
static

Definition at line 242 of file lua-5.4.3/src/lcode.c.

242 {
243 Instruction *pi = &fs->f->code[pc];
244 if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))
245 return pi-1;
246 else
247 return pi;
248}
#define testTMode(m)

References Proto::code, FuncState::f, GET_OPCODE, and testTMode.

Referenced by need_value(), negatecondition(), and patchtestreg().

◆ isCint()

static int isCint ( expdesc * e)
static

Definition at line 1219 of file lua-5.4.3/src/lcode.c.

1219 {
1220 return luaK_isKint(e) && (l_castS2U(e->u.ival) <= l_castS2U(MAXARG_C));
1221}

References expdesc::ival, l_castS2U, luaK_isKint(), MAXARG_C, and expdesc::u.

Referenced by luaK_indexed().

◆ isKstr()

static int isKstr ( FuncState * fs,
expdesc * e )
static

Definition at line 1202 of file lua-5.4.3/src/lcode.c.

1202 {
1203 return (e->k == VK && !hasjumps(e) && e->u.info <= MAXARG_B &&
1204 ttisshrstring(&fs->f->k[e->u.info]));
1205}
#define MAXARG_B
#define ttisshrstring(o)

References FuncState::f, hasjumps, expdesc::info, Proto::k, expdesc::k, MAXARG_B, ttisshrstring, expdesc::u, and VK.

Referenced by luaK_indexed().

◆ isSCint()

static int isSCint ( expdesc * e)
static

Definition at line 1228 of file lua-5.4.3/src/lcode.c.

1228 {
1229 return luaK_isKint(e) && fitsC(e->u.ival);
1230}

References fitsC(), expdesc::ival, luaK_isKint(), and expdesc::u.

Referenced by codecommutative(), and luaK_posfix().

◆ isSCnumber()

static int isSCnumber ( expdesc * e,
int * pi,
int * isfloat )
static

Definition at line 1237 of file lua-5.4.3/src/lcode.c.

1237 {
1238 lua_Integer i;
1239 if (e->k == VKINT)
1240 i = e->u.ival;
1241 else if (e->k == VKFLT && luaV_flttointeger(e->u.nval, &i, F2Ieq))
1242 *isfloat = 1;
1243 else
1244 return 0; /* not a number */
1245 if (!hasjumps(e) && fitsC(i)) {
1246 *pi = int2sC(cast_int(i));
1247 return 1;
1248 }
1249 else
1250 return 0;
1251}
int luaV_flttointeger(lua_Number n, lua_Integer *p, F2Imod mode)
@ F2Ieq

References cast_int, F2Ieq, fitsC(), hasjumps, int2sC, expdesc::ival, expdesc::k, luaV_flttointeger(), expdesc::nval, expdesc::u, VKFLT, and VKINT.

Referenced by codeeq(), codeorder(), and luaK_infix().

◆ jumponcond()

static int jumponcond ( FuncState * fs,
expdesc * e,
int cond )
static

Definition at line 1097 of file lua-5.4.3/src/lcode.c.

1097 {
1098 if (e->k == VRELOC) {
1099 Instruction ie = getinstruction(fs, e);
1100 if (GET_OPCODE(ie) == OP_NOT) {
1101 removelastinstruction(fs); /* remove previous OP_NOT */
1102 return condjump(fs, OP_TEST, GETARG_B(ie), 0, 0, !cond);
1103 }
1104 /* else go through */
1105 }
1106 discharge2anyreg(fs, e);
1107 freeexp(fs, e);
1108 return condjump(fs, OP_TESTSET, NO_REG, e->u.info, 0, cond);
1109}
#define NO_REG
static int cond(LexState *ls)
static void removelastinstruction(FuncState *fs)

References cond(), condjump(), discharge2anyreg(), freeexp(), GET_OPCODE, GETARG_B, getinstruction, expdesc::info, expdesc::k, NO_REG, OP_NOT, OP_TEST, OP_TESTSET, removelastinstruction(), expdesc::u, and VRELOC.

Referenced by luaK_goiffalse(), and luaK_goiftrue().

◆ luaK_checkstack()

void luaK_checkstack ( FuncState * fs,
int n )

Definition at line 465 of file lua-5.4.3/src/lcode.c.

465 {
466 int newstack = fs->freereg + n;
467 if (newstack > fs->f->maxstacksize) {
468 if (newstack >= MAXREGS)
470 "function or expression needs too many registers");
471 fs->f->maxstacksize = cast_byte(newstack);
472 }
473}
#define cast_byte(i)
#define MAXREGS
lu_byte maxstacksize

References cast_byte, FuncState::f, FuncState::freereg, FuncState::ls, luaX_syntaxerror(), MAXREGS, and Proto::maxstacksize.

Referenced by luaK_reserveregs().

◆ luaK_code()

int luaK_code ( FuncState * fs,
Instruction i )

Definition at line 381 of file lua-5.4.3/src/lcode.c.

381 {
382 Proto *f = fs->f;
383 /* put new instruction in code array */
384 luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,
385 MAX_INT, "opcodes");
386 f->code[fs->pc++] = i;
387 savelineinfo(fs, f, fs->ls->lastline);
388 return fs->pc - 1; /* index of new instruction */
389}
#define MAX_INT
static void savelineinfo(FuncState *fs, Proto *f, int line)

References Proto::code, FuncState::f, LexState::L, LexState::lastline, FuncState::ls, luaM_growvector, MAX_INT, FuncState::pc, savelineinfo(), and Proto::sizecode.

Referenced by codeextraarg(), codesJ(), luaK_codeABCk(), luaK_codeABx(), and luaK_codeAsBx().

◆ luaK_codeABCk()

int luaK_codeABCk ( FuncState * fs,
OpCode o,
int a,
int b,
int c,
int k )

Definition at line 396 of file lua-5.4.3/src/lcode.c.

396 {
398 lua_assert(a <= MAXARG_A && b <= MAXARG_B &&
399 c <= MAXARG_C && (k & ~1) == 0);
400 return luaK_code(fs, CREATE_ABCk(o, a, b, c, k));
401}
#define MAXARG_A
#define CREATE_ABCk(o, a, b, c, k)

References CREATE_ABCk, getOpMode, iABC, lua_assert, luaK_code(), MAXARG_A, MAXARG_B, and MAXARG_C.

Referenced by codeABRK(), condjump(), finishbinexpval(), and luaK_setlist().

◆ luaK_codeABx()

int luaK_codeABx ( FuncState * fs,
OpCode o,
int a,
unsigned int bc )

Definition at line 407 of file lua-5.4.3/src/lcode.c.

407 {
409 lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx);
410 return luaK_code(fs, CREATE_ABx(o, a, bc));
411}
#define CREATE_ABx(o, a, bc)

References CREATE_ABx, getOpMode, iABx, lua_assert, luaK_code(), MAXARG_A, and MAXARG_Bx.

Referenced by luaK_codek().

◆ luaK_codeAsBx()

int luaK_codeAsBx ( FuncState * fs,
OpCode o,
int a,
int bc )

Definition at line 417 of file lua-5.4.3/src/lcode.c.

417 {
418 unsigned int b = bc + OFFSET_sBx;
420 lua_assert(a <= MAXARG_A && b <= MAXARG_Bx);
421 return luaK_code(fs, CREATE_ABx(o, a, b));
422}

References CREATE_ABx, getOpMode, iAsBx, lua_assert, luaK_code(), MAXARG_A, MAXARG_Bx, and OFFSET_sBx.

◆ luaK_codek()

static int luaK_codek ( FuncState * fs,
int reg,
int k )
static

Definition at line 450 of file lua-5.4.3/src/lcode.c.

450 {
451 if (k <= MAXARG_Bx)
452 return luaK_codeABx(fs, OP_LOADK, reg, k);
453 else {
454 int p = luaK_codeABx(fs, OP_LOADKX, reg, 0);
455 codeextraarg(fs, k);
456 return p;
457 }
458}
int luaK_codeABx(FuncState *fs, OpCode o, int a, unsigned int bc)
static int codeextraarg(FuncState *fs, int a)

References codeextraarg(), luaK_codeABx(), MAXARG_Bx, OP_LOADK, and OP_LOADKX.

Referenced by discharge2reg(), luaK_float(), and luaK_int().

◆ luaK_concat()

void luaK_concat ( FuncState * fs,
int * l1,
int l2 )

Definition at line 180 of file lua-5.4.3/src/lcode.c.

180 {
181 if (l2 == NO_JUMP) return; /* nothing to concatenate? */
182 else if (*l1 == NO_JUMP) /* no original list? */
183 *l1 = l2; /* 'l1' points to 'l2' */
184 else {
185 int list = *l1;
186 int next;
187 while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */
188 list = next;
189 fixjump(fs, list, l2); /* last element links to 'l2' */
190 }
191}
#define next(ls)
static void fixjump(FuncState *fs, int pc, int dest)
static int getjump(FuncState *fs, int pc)

References fixjump(), getjump(), next, and NO_JUMP.

Referenced by exp2reg(), luaK_goiffalse(), luaK_goiftrue(), and luaK_posfix().

◆ luaK_dischargevars()

void luaK_dischargevars ( FuncState * fs,
expdesc * e )

Definition at line 754 of file lua-5.4.3/src/lcode.c.

754 {
755 switch (e->k) {
756 case VCONST: {
757 const2exp(const2val(fs, e), e);
758 break;
759 }
760 case VLOCAL: { /* already in a register */
761 e->u.info = e->u.var.ridx;
762 e->k = VNONRELOC; /* becomes a non-relocatable value */
763 break;
764 }
765 case VUPVAL: { /* move value to some (pending) register */
766 e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);
767 e->k = VRELOC;
768 break;
769 }
770 case VINDEXUP: {
771 e->u.info = luaK_codeABC(fs, OP_GETTABUP, 0, e->u.ind.t, e->u.ind.idx);
772 e->k = VRELOC;
773 break;
774 }
775 case VINDEXI: {
776 freereg(fs, e->u.ind.t);
777 e->u.info = luaK_codeABC(fs, OP_GETI, 0, e->u.ind.t, e->u.ind.idx);
778 e->k = VRELOC;
779 break;
780 }
781 case VINDEXSTR: {
782 freereg(fs, e->u.ind.t);
783 e->u.info = luaK_codeABC(fs, OP_GETFIELD, 0, e->u.ind.t, e->u.ind.idx);
784 e->k = VRELOC;
785 break;
786 }
787 case VINDEXED: {
788 freeregs(fs, e->u.ind.t, e->u.ind.idx);
789 e->u.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.ind.t, e->u.ind.idx);
790 e->k = VRELOC;
791 break;
792 }
793 case VVARARG: case VCALL: {
794 luaK_setoneret(fs, e);
795 break;
796 }
797 default: break; /* there is one value available (somewhere) */
798 }
799}
static TValue * const2val(FuncState *fs, const expdesc *e)
void luaK_setoneret(FuncState *fs, expdesc *e)
static void const2exp(TValue *v, expdesc *e)
struct expdesc::@89::@91 var
struct expdesc::@61::@62 ind

References const2exp(), const2val(), freereg(), freeregs(), expdesc::idx, expdesc::ind, expdesc::info, expdesc::k, luaK_codeABC, luaK_setoneret(), OP_GETFIELD, OP_GETI, OP_GETTABLE, OP_GETTABUP, OP_GETUPVAL, expdesc::ridx, expdesc::t, expdesc::u, expdesc::var, VCALL, VCONST, VINDEXED, VINDEXI, VINDEXSTR, VINDEXUP, VLOCAL, VNONRELOC, VRELOC, VUPVAL, and VVARARG.

Referenced by discharge2reg(), luaK_exp2anyreg(), luaK_exp2nextreg(), luaK_exp2val(), luaK_goiffalse(), luaK_goiftrue(), luaK_infix(), luaK_posfix(), and luaK_prefix().

◆ luaK_exp2anyreg()

int luaK_exp2anyreg ( FuncState * fs,
expdesc * e )

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

936 {
937 luaK_dischargevars(fs, e);
938 if (e->k == VNONRELOC) { /* expression already has a register? */
939 if (!hasjumps(e)) /* no jumps? */
940 return e->u.info; /* result is already in a register */
941 if (e->u.info >= luaY_nvarstack(fs)) { /* reg. is not a local? */
942 exp2reg(fs, e, e->u.info); /* put final result in it */
943 return e->u.info;
944 }
945 /* else expression has jumps and cannot change its register
946 to hold the jump values, because it is a local variable.
947 Go through to the default case. */
948 }
949 luaK_exp2nextreg(fs, e); /* default: use next available register */
950 return e->u.info;
951}
void luaK_exp2nextreg(FuncState *fs, expdesc *e)
static void exp2reg(FuncState *fs, expdesc *e, int reg)

References exp2reg(), hasjumps, expdesc::info, expdesc::k, luaK_dischargevars(), luaK_exp2nextreg(), luaY_nvarstack(), expdesc::u, and VNONRELOC.

Referenced by codebinexpval(), codeeq(), codeorder(), codeunexpval(), finishbinexpval(), luaK_exp2anyregup(), luaK_exp2RK(), luaK_exp2val(), luaK_indexed(), luaK_infix(), luaK_self(), and luaK_storevar().

◆ luaK_exp2anyregup()

void luaK_exp2anyregup ( FuncState * fs,
expdesc * e )

Definition at line 958 of file lua-5.4.3/src/lcode.c.

958 {
959 if (e->k != VUPVAL || hasjumps(e))
960 luaK_exp2anyreg(fs, e);
961}

References hasjumps, expdesc::k, luaK_exp2anyreg(), and VUPVAL.

◆ luaK_exp2const()

int luaK_exp2const ( FuncState * fs,
const expdesc * e,
TValue * v )

Definition at line 83 of file lua-5.4.3/src/lcode.c.

83 {
84 if (hasjumps(e))
85 return 0; /* not a constant */
86 switch (e->k) {
87 case VFALSE:
88 setbfvalue(v);
89 return 1;
90 case VTRUE:
91 setbtvalue(v);
92 return 1;
93 case VNIL:
94 setnilvalue(v);
95 return 1;
96 case VKSTR: {
97 setsvalue(fs->ls->L, v, e->u.strval);
98 return 1;
99 }
100 case VCONST: {
101 setobj(fs->ls->L, v, const2val(fs, e));
102 return 1;
103 }
104 default: return tonumeral(e, v);
105 }
106}
#define setsvalue(L, obj, x)

References const2val(), hasjumps, expdesc::k, LexState::L, FuncState::ls, setbfvalue, setbtvalue, setnilvalue, setobj, setsvalue, expdesc::strval, tonumeral(), expdesc::u, VCONST, VFALSE, VKSTR, VNIL, and VTRUE.

Referenced by localstat().

◆ luaK_exp2K()

static int luaK_exp2K ( FuncState * fs,
expdesc * e )
static

Definition at line 980 of file lua-5.4.3/src/lcode.c.

980 {
981 if (!hasjumps(e)) {
982 int info;
983 switch (e->k) { /* move constants to 'k' */
984 case VTRUE: info = boolT(fs); break;
985 case VFALSE: info = boolF(fs); break;
986 case VNIL: info = nilK(fs); break;
987 case VKINT: info = luaK_intK(fs, e->u.ival); break;
988 case VKFLT: info = luaK_numberK(fs, e->u.nval); break;
989 case VKSTR: info = stringK(fs, e->u.strval); break;
990 case VK: info = e->u.info; break;
991 default: return 0; /* not a constant */
992 }
993 if (info <= MAXINDEXRK) { /* does constant fit in 'argC'? */
994 e->k = VK; /* make expression a 'K' expression */
995 e->u.info = info;
996 return 1;
997 }
998 }
999 /* else, expression doesn't fit; leave it unchanged */
1000 return 0;
1001}
#define MAXINDEXRK
static int boolT(FuncState *fs)
static int luaK_intK(FuncState *fs, lua_Integer n)
static int boolF(FuncState *fs)
static int stringK(FuncState *fs, TString *s)
static int nilK(FuncState *fs)
static int luaK_numberK(FuncState *fs, lua_Number r)

References boolF(), boolT(), hasjumps, expdesc::info, expdesc::ival, expdesc::k, luaK_intK(), luaK_numberK(), MAXINDEXRK, nilK(), expdesc::nval, stringK(), expdesc::strval, expdesc::u, VFALSE, VK, VKFLT, VKINT, VKSTR, VNIL, and VTRUE.

Referenced by codearith(), and luaK_exp2RK().

◆ luaK_exp2nextreg()

void luaK_exp2nextreg ( FuncState * fs,
expdesc * e )

Definition at line 924 of file lua-5.4.3/src/lcode.c.

924 {
925 luaK_dischargevars(fs, e);
926 freeexp(fs, e);
927 luaK_reserveregs(fs, 1);
928 exp2reg(fs, e, fs->freereg - 1);
929}

References exp2reg(), freeexp(), FuncState::freereg, luaK_dischargevars(), and luaK_reserveregs().

Referenced by luaK_exp2anyreg(), luaK_infix(), and luaK_posfix().

◆ luaK_exp2RK()

int luaK_exp2RK ( FuncState * fs,
expdesc * e )

Definition at line 1010 of file lua-5.4.3/src/lcode.c.

1010 {
1011 if (luaK_exp2K(fs, e))
1012 return 1;
1013 else { /* not a constant in the right range: put it in a register */
1014 luaK_exp2anyreg(fs, e);
1015 return 0;
1016 }
1017}

References luaK_exp2anyreg(), and luaK_exp2K().

Referenced by codeABRK(), codebitwise(), codeeq(), and luaK_infix().

◆ luaK_exp2val()

void luaK_exp2val ( FuncState * fs,
expdesc * e )

Definition at line 968 of file lua-5.4.3/src/lcode.c.

968 {
969 if (hasjumps(e))
970 luaK_exp2anyreg(fs, e);
971 else
972 luaK_dischargevars(fs, e);
973}

References hasjumps, luaK_dischargevars(), and luaK_exp2anyreg().

◆ luaK_finish()

void luaK_finish ( FuncState * fs)

Definition at line 1786 of file lua-5.4.3/src/lcode.c.

1786 {
1787 int i;
1788 Proto *p = fs->f;
1789 for (i = 0; i < fs->pc; i++) {
1790 Instruction *pc = &p->code[i];
1791 lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc));
1792 switch (GET_OPCODE(*pc)) {
1793 case OP_RETURN0: case OP_RETURN1: {
1794 if (!(fs->needclose || p->is_vararg))
1795 break; /* no extra work */
1796 /* else use OP_RETURN to do the extra work */
1797 SET_OPCODE(*pc, OP_RETURN);
1798 } /* FALLTHROUGH */
1799 case OP_RETURN: case OP_TAILCALL: {
1800 if (fs->needclose)
1801 SETARG_k(*pc, 1); /* signal that it needs to close */
1802 if (p->is_vararg)
1803 SETARG_C(*pc, p->numparams + 1); /* signal that it is vararg */
1804 break;
1805 }
1806 case OP_JMP: {
1807 int target = finaltarget(p->code, i);
1808 fixjump(fs, i, target);
1809 break;
1810 }
1811 default: break;
1812 }
1813 }
1814}
#define SET_OPCODE(i, o)
#define SETARG_C(i, b)
static int finaltarget(Instruction *code, int i)
#define isOT(i)
#define SETARG_k(i, v)
#define isIT(i)

References Proto::code, FuncState::f, finaltarget(), fixjump(), GET_OPCODE, Proto::is_vararg, isIT, isOT, lua_assert, FuncState::needclose, Proto::numparams, OP_JMP, OP_RETURN, OP_RETURN0, OP_RETURN1, OP_TAILCALL, FuncState::pc, SET_OPCODE, SETARG_C, and SETARG_k.

Referenced by close_func().

◆ luaK_fixline()

void luaK_fixline ( FuncState * fs,
int line )

Definition at line 1726 of file lua-5.4.3/src/lcode.c.

1726 {
1728 savelineinfo(fs, fs->f, line);
1729}
static void removelastlineinfo(FuncState *fs)

References FuncState::f, removelastlineinfo(), and savelineinfo().

Referenced by codeconcat(), codeunexpval(), and finishbinexpval().

◆ luaK_float()

static void luaK_float ( FuncState * fs,
int reg,
lua_Number f )
static

Definition at line 662 of file lua-5.4.3/src/lcode.c.

662 {
663 lua_Integer fi;
664 if (luaV_flttointeger(f, &fi, F2Ieq) && fitsBx(fi))
665 luaK_codeAsBx(fs, OP_LOADF, reg, cast_int(fi));
666 else
667 luaK_codek(fs, reg, luaK_numberK(fs, f));
668}
#define luaK_codeAsBx(fs, o, A, sBx)
static int fitsBx(lua_Integer i)

References cast_int, F2Ieq, fitsBx(), luaK_codeAsBx, luaK_codek(), luaK_numberK(), luaV_flttointeger(), and OP_LOADF.

Referenced by discharge2reg().

◆ luaK_getlabel()

int luaK_getlabel ( FuncState * fs)

Definition at line 231 of file lua-5.4.3/src/lcode.c.

231 {
232 fs->lasttarget = fs->pc;
233 return fs->pc;
234}

References FuncState::lasttarget, and FuncState::pc.

Referenced by code_loadbool(), exp2reg(), and luaK_patchtohere().

◆ luaK_goiffalse()

void luaK_goiffalse ( FuncState * fs,
expdesc * e )

Definition at line 1142 of file lua-5.4.3/src/lcode.c.

1142 {
1143 int pc; /* pc of new jump */
1144 luaK_dischargevars(fs, e);
1145 switch (e->k) {
1146 case VJMP: {
1147 pc = e->u.info; /* already jump if true */
1148 break;
1149 }
1150 case VNIL: case VFALSE: {
1151 pc = NO_JUMP; /* always false; do nothing */
1152 break;
1153 }
1154 default: {
1155 pc = jumponcond(fs, e, 1); /* jump if true */
1156 break;
1157 }
1158 }
1159 luaK_concat(fs, &e->t, pc); /* insert new jump in 't' list */
1160 luaK_patchtohere(fs, e->f); /* false list jumps to here (to go through) */
1161 e->f = NO_JUMP;
1162}
static int jumponcond(FuncState *fs, expdesc *e, int cond)

References expdesc::f, expdesc::info, jumponcond(), expdesc::k, luaK_concat(), luaK_dischargevars(), luaK_patchtohere(), NO_JUMP, expdesc::t, expdesc::u, VFALSE, VJMP, and VNIL.

Referenced by luaK_infix().

◆ luaK_goiftrue()

void luaK_goiftrue ( FuncState * fs,
expdesc * e )

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

1115 {
1116 int pc; /* pc of new jump */
1117 luaK_dischargevars(fs, e);
1118 switch (e->k) {
1119 case VJMP: { /* condition? */
1120 negatecondition(fs, e); /* jump when it is false */
1121 pc = e->u.info; /* save jump position */
1122 break;
1123 }
1124 case VK: case VKFLT: case VKINT: case VKSTR: case VTRUE: {
1125 pc = NO_JUMP; /* always true; do nothing */
1126 break;
1127 }
1128 default: {
1129 pc = jumponcond(fs, e, 0); /* jump when false */
1130 break;
1131 }
1132 }
1133 luaK_concat(fs, &e->f, pc); /* insert new jump in false list */
1134 luaK_patchtohere(fs, e->t); /* true list jumps to here (to go through) */
1135 e->t = NO_JUMP;
1136}

References expdesc::f, expdesc::info, jumponcond(), expdesc::k, luaK_concat(), luaK_dischargevars(), luaK_patchtohere(), negatecondition(), NO_JUMP, expdesc::t, expdesc::u, VJMP, VK, VKFLT, VKINT, VKSTR, and VTRUE.

Referenced by luaK_infix().

◆ luaK_indexed()

void luaK_indexed ( FuncState * fs,
expdesc * t,
expdesc * k )

Definition at line 1260 of file lua-5.4.3/src/lcode.c.

1260 {
1261 if (k->k == VKSTR)
1262 str2K(fs, k);
1263 lua_assert(!hasjumps(t) &&
1264 (t->k == VLOCAL || t->k == VNONRELOC || t->k == VUPVAL));
1265 if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non 'Kstr'? */
1266 luaK_exp2anyreg(fs, t); /* put it in a register */
1267 if (t->k == VUPVAL) {
1268 t->u.ind.t = t->u.info; /* upvalue index */
1269 t->u.ind.idx = k->u.info; /* literal string */
1270 t->k = VINDEXUP;
1271 }
1272 else {
1273 /* register index of the table */
1274 t->u.ind.t = (t->k == VLOCAL) ? t->u.var.ridx: t->u.info;
1275 if (isKstr(fs, k)) {
1276 t->u.ind.idx = k->u.info; /* literal string */
1277 t->k = VINDEXSTR;
1278 }
1279 else if (isCint(k)) {
1280 t->u.ind.idx = cast_int(k->u.ival); /* int. constant in proper range */
1281 t->k = VINDEXI;
1282 }
1283 else {
1284 t->u.ind.idx = luaK_exp2anyreg(fs, k); /* register */
1285 t->k = VINDEXED;
1286 }
1287 }
1288}
static int isKstr(FuncState *fs, expdesc *e)
static int isCint(expdesc *e)

References cast_int, hasjumps, expdesc::idx, expdesc::ind, expdesc::info, isCint(), isKstr(), expdesc::ival, expdesc::k, lua_assert, luaK_exp2anyreg(), expdesc::ridx, str2K(), expdesc::t, expdesc::u, expdesc::var, VINDEXED, VINDEXI, VINDEXSTR, VINDEXUP, VKSTR, VLOCAL, VNONRELOC, and VUPVAL.

◆ luaK_infix()

void luaK_infix ( FuncState * fs,
BinOpr op,
expdesc * v )

Definition at line 1574 of file lua-5.4.3/src/lcode.c.

1574 {
1575 luaK_dischargevars(fs, v);
1576 switch (op) {
1577 case OPR_AND: {
1578 luaK_goiftrue(fs, v); /* go ahead only if 'v' is true */
1579 break;
1580 }
1581 case OPR_OR: {
1582 luaK_goiffalse(fs, v); /* go ahead only if 'v' is false */
1583 break;
1584 }
1585 case OPR_CONCAT: {
1586 luaK_exp2nextreg(fs, v); /* operand must be on the stack */
1587 break;
1588 }
1589 case OPR_ADD: case OPR_SUB:
1590 case OPR_MUL: case OPR_DIV: case OPR_IDIV:
1591 case OPR_MOD: case OPR_POW:
1592 case OPR_BAND: case OPR_BOR: case OPR_BXOR:
1593 case OPR_SHL: case OPR_SHR: {
1594 if (!tonumeral(v, NULL))
1595 luaK_exp2anyreg(fs, v);
1596 /* else keep numeral, which may be folded with 2nd operand */
1597 break;
1598 }
1599 case OPR_EQ: case OPR_NE: {
1600 if (!tonumeral(v, NULL))
1601 luaK_exp2RK(fs, v);
1602 /* else keep numeral, which may be an immediate operand */
1603 break;
1604 }
1605 case OPR_LT: case OPR_LE:
1606 case OPR_GT: case OPR_GE: {
1607 int dummy, dummy2;
1608 if (!isSCnumber(v, &dummy, &dummy2))
1609 luaK_exp2anyreg(fs, v);
1610 /* else keep numeral, which may be an immediate operand */
1611 break;
1612 }
1613 default: lua_assert(0);
1614 }
1615}
@ OPR_CONCAT
void luaK_goiffalse(FuncState *fs, expdesc *e)
void luaK_goiftrue(FuncState *fs, expdesc *e)

References dummy, isSCnumber(), lua_assert, luaK_dischargevars(), luaK_exp2anyreg(), luaK_exp2nextreg(), luaK_exp2RK(), luaK_goiffalse(), luaK_goiftrue(), NULL, OPR_ADD, OPR_AND, OPR_BAND, OPR_BOR, OPR_BXOR, OPR_CONCAT, OPR_DIV, OPR_EQ, OPR_GE, OPR_GT, OPR_IDIV, OPR_LE, OPR_LT, OPR_MOD, OPR_MUL, OPR_NE, OPR_OR, OPR_POW, OPR_SHL, OPR_SHR, OPR_SUB, and tonumeral().

◆ luaK_int()

void luaK_int ( FuncState * fs,
int reg,
lua_Integer i )

Definition at line 654 of file lua-5.4.3/src/lcode.c.

654 {
655 if (fitsBx(i))
656 luaK_codeAsBx(fs, OP_LOADI, reg, cast_int(i));
657 else
658 luaK_codek(fs, reg, luaK_intK(fs, i));
659}

References cast_int, fitsBx(), luaK_codeAsBx, luaK_codek(), luaK_intK(), and OP_LOADI.

Referenced by discharge2reg(), and fornum().

◆ luaK_intK()

static int luaK_intK ( FuncState * fs,
lua_Integer n )
static

Definition at line 587 of file lua-5.4.3/src/lcode.c.

587 {
588 TValue k, o;
590 setivalue(&o, n);
591 return addk(fs, &k, &o);
592}
#define setpvalue(obj, x)
#define cast_sizet(i)
#define cast_voidp(i)

References addk(), cast_sizet, cast_voidp, setivalue, and setpvalue.

Referenced by luaK_exp2K(), and luaK_int().

◆ luaK_isKint()

int luaK_isKint ( expdesc * e)

Definition at line 1210 of file lua-5.4.3/src/lcode.c.

1210 {
1211 return (e->k == VKINT && !hasjumps(e));
1212}

References hasjumps, expdesc::k, and VKINT.

Referenced by finishbinexpneg(), isCint(), and isSCint().

◆ luaK_jump()

int luaK_jump ( FuncState * fs)

Definition at line 198 of file lua-5.4.3/src/lcode.c.

198 {
199 return codesJ(fs, OP_JMP, NO_JUMP, 0);
200}
static int codesJ(FuncState *fs, OpCode o, int sj, int k)

References codesJ(), NO_JUMP, and OP_JMP.

Referenced by condjump(), and exp2reg().

◆ luaK_nil()

void luaK_nil ( FuncState * fs,
int from,
int n )

Definition at line 130 of file lua-5.4.3/src/lcode.c.

130 {
131 int l = from + n - 1; /* last register to set nil */
132 Instruction *previous = previousinstruction(fs);
133 if (GET_OPCODE(*previous) == OP_LOADNIL) { /* previous is LOADNIL? */
134 int pfrom = GETARG_A(*previous); /* get previous range */
135 int pl = pfrom + GETARG_B(*previous);
136 if ((pfrom <= from && from <= pl + 1) ||
137 (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
138 if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
139 if (pl > l) l = pl; /* l = max(l, pl) */
140 SETARG_A(*previous, from);
141 SETARG_B(*previous, l - from);
142 return;
143 } /* else go through */
144 }
145 luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */
146}

References GET_OPCODE, GETARG_A, GETARG_B, luaK_codeABC, OP_LOADNIL, previousinstruction(), SETARG_A, and SETARG_B.

Referenced by discharge2reg().

◆ luaK_numberK()

static int luaK_numberK ( FuncState * fs,
lua_Number r )
static

Definition at line 597 of file lua-5.4.3/src/lcode.c.

597 {
598 TValue o;
599 setfltvalue(&o, r);
600 return addk(fs, &o, &o); /* use number itself as key */
601}
#define setfltvalue(obj, x)

References addk(), and setfltvalue.

Referenced by luaK_exp2K(), and luaK_float().

◆ luaK_patchlist()

void luaK_patchlist ( FuncState * fs,
int list,
int target )

Definition at line 305 of file lua-5.4.3/src/lcode.c.

305 {
306 lua_assert(target <= fs->pc);
307 patchlistaux(fs, list, target, NO_REG, target);
308}

References lua_assert, NO_REG, and patchlistaux().

Referenced by luaK_patchtohere().

◆ luaK_patchtohere()

void luaK_patchtohere ( FuncState * fs,
int list )

Definition at line 311 of file lua-5.4.3/src/lcode.c.

311 {
312 int hr = luaK_getlabel(fs); /* mark "here" as a jump target */
313 luaK_patchlist(fs, list, hr);
314}
void luaK_patchlist(FuncState *fs, int list, int target)

References luaK_getlabel(), and luaK_patchlist().

Referenced by exp2reg(), luaK_goiffalse(), and luaK_goiftrue().

◆ luaK_posfix()

void luaK_posfix ( FuncState * fs,
BinOpr opr,
expdesc * e1,
expdesc * e2,
int line )

Definition at line 1642 of file lua-5.4.3/src/lcode.c.

1643 {
1644 luaK_dischargevars(fs, e2);
1645 if (foldbinop(opr) && constfolding(fs, opr + LUA_OPADD, e1, e2))
1646 return; /* done by folding */
1647 switch (opr) {
1648 case OPR_AND: {
1649 lua_assert(e1->t == NO_JUMP); /* list closed by 'luaK_infix' */
1650 luaK_concat(fs, &e2->f, e1->f);
1651 *e1 = *e2;
1652 break;
1653 }
1654 case OPR_OR: {
1655 lua_assert(e1->f == NO_JUMP); /* list closed by 'luaK_infix' */
1656 luaK_concat(fs, &e2->t, e1->t);
1657 *e1 = *e2;
1658 break;
1659 }
1660 case OPR_CONCAT: { /* e1 .. e2 */
1661 luaK_exp2nextreg(fs, e2);
1662 codeconcat(fs, e1, e2, line);
1663 break;
1664 }
1665 case OPR_ADD: case OPR_MUL: {
1666 codecommutative(fs, opr, e1, e2, line);
1667 break;
1668 }
1669 case OPR_SUB: {
1670 if (finishbinexpneg(fs, e1, e2, OP_ADDI, line, TM_SUB))
1671 break; /* coded as (r1 + -I) */
1672 /* ELSE */
1673 } /* FALLTHROUGH */
1674 case OPR_DIV: case OPR_IDIV: case OPR_MOD: case OPR_POW: {
1675 codearith(fs, opr, e1, e2, 0, line);
1676 break;
1677 }
1678 case OPR_BAND: case OPR_BOR: case OPR_BXOR: {
1679 codebitwise(fs, opr, e1, e2, line);
1680 break;
1681 }
1682 case OPR_SHL: {
1683 if (isSCint(e1)) {
1684 swapexps(e1, e2);
1685 codebini(fs, OP_SHLI, e1, e2, 1, line, TM_SHL); /* I << r2 */
1686 }
1687 else if (finishbinexpneg(fs, e1, e2, OP_SHRI, line, TM_SHL)) {
1688 /* coded as (r1 >> -I) */;
1689 }
1690 else /* regular case (two registers) */
1691 codebinexpval(fs, OP_SHL, e1, e2, line);
1692 break;
1693 }
1694 case OPR_SHR: {
1695 if (isSCint(e2))
1696 codebini(fs, OP_SHRI, e1, e2, 0, line, TM_SHR); /* r1 >> I */
1697 else /* regular case (two registers) */
1698 codebinexpval(fs, OP_SHR, e1, e2, line);
1699 break;
1700 }
1701 case OPR_EQ: case OPR_NE: {
1702 codeeq(fs, opr, e1, e2);
1703 break;
1704 }
1705 case OPR_LT: case OPR_LE: {
1706 OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ);
1707 codeorder(fs, op, e1, e2);
1708 break;
1709 }
1710 case OPR_GT: case OPR_GE: {
1711 /* '(a > b)' <=> '(b < a)'; '(a >= b)' <=> '(b <= a)' */
1712 OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ);
1713 swapexps(e1, e2);
1714 codeorder(fs, op, e1, e2);
1715 break;
1716 }
1717 default: lua_assert(0);
1718 }
1719}
@ TM_SUB
#define LUA_OPADD
@ TM_SHR
@ TM_SHL
static void codecommutative(FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2, int line)
static int finishbinexpneg(FuncState *fs, expdesc *e1, expdesc *e2, OpCode op, int line, TMS event)
static void codeconcat(FuncState *fs, expdesc *e1, expdesc *e2, int line)
static int constfolding(FuncState *fs, int op, expdesc *e1, const expdesc *e2)
static void codebitwise(FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2, int line)
static void codeorder(FuncState *fs, OpCode op, expdesc *e1, expdesc *e2)
static void codeeq(FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2)
#define foldbinop(op)

References cast, codearith(), codebinexpval(), codebini(), codebitwise(), codecommutative(), codeconcat(), codeeq(), codeorder(), constfolding(), expdesc::f, finishbinexpneg(), foldbinop, isSCint(), lua_assert, LUA_OPADD, luaK_concat(), luaK_dischargevars(), luaK_exp2nextreg(), NO_JUMP, OP_ADDI, OP_EQ, OP_SHL, OP_SHLI, OP_SHR, OP_SHRI, OPR_ADD, OPR_AND, OPR_BAND, OPR_BOR, OPR_BXOR, OPR_CONCAT, OPR_DIV, OPR_EQ, OPR_GE, OPR_GT, OPR_IDIV, OPR_LE, OPR_LT, OPR_MOD, OPR_MUL, OPR_NE, OPR_OR, OPR_POW, OPR_SHL, OPR_SHR, OPR_SUB, swapexps(), expdesc::t, TM_SHL, TM_SHR, and TM_SUB.

◆ luaK_prefix()

void luaK_prefix ( FuncState * fs,
UnOpr op,
expdesc * e,
int line )

Definition at line 1553 of file lua-5.4.3/src/lcode.c.

1553 {
1554 static const expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP};
1555 luaK_dischargevars(fs, e);
1556 switch (op) {
1557 case OPR_MINUS: case OPR_BNOT: /* use 'ef' as fake 2nd operand */
1558 if (constfolding(fs, op + LUA_OPUNM, e, &ef))
1559 break;
1560 /* else */ /* FALLTHROUGH */
1561 case OPR_LEN:
1562 codeunexpval(fs, cast(OpCode, op + OP_UNM), e, line);
1563 break;
1564 case OPR_NOT: codenot(fs, e); break;
1565 default: lua_assert(0);
1566 }
1567}
@ OPR_MINUS
#define LUA_OPUNM
static void codenot(FuncState *fs, expdesc *e)
static void codeunexpval(FuncState *fs, OpCode op, expdesc *e, int line)

References cast, codenot(), codeunexpval(), constfolding(), lua_assert, LUA_OPUNM, luaK_dischargevars(), NO_JUMP, OP_UNM, OPR_BNOT, OPR_LEN, OPR_MINUS, OPR_NOT, and VKINT.

◆ luaK_reserveregs()

void luaK_reserveregs ( FuncState * fs,
int n )

Definition at line 479 of file lua-5.4.3/src/lcode.c.

479 {
480 luaK_checkstack(fs, n);
481 fs->freereg += n;
482}
void luaK_checkstack(FuncState *fs, int n)

References FuncState::freereg, and luaK_checkstack().

Referenced by discharge2anyreg(), luaK_exp2nextreg(), luaK_self(), and luaK_setreturns().

◆ luaK_ret()

void luaK_ret ( FuncState * fs,
int first,
int nret )

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

206 {
207 OpCode op;
208 switch (nret) {
209 case 0: op = OP_RETURN0; break;
210 case 1: op = OP_RETURN1; break;
211 default: op = OP_RETURN; break;
212 }
213 luaK_codeABC(fs, op, first, nret + 1, 0);
214}

References luaK_codeABC, OP_RETURN, OP_RETURN0, and OP_RETURN1.

◆ luaK_self()

void luaK_self ( FuncState * fs,
expdesc * e,
expdesc * key )

Definition at line 1067 of file lua-5.4.3/src/lcode.c.

1067 {
1068 int ereg;
1069 luaK_exp2anyreg(fs, e);
1070 ereg = e->u.info; /* register where 'e' was placed */
1071 freeexp(fs, e);
1072 e->u.info = fs->freereg; /* base register for op_self */
1073 e->k = VNONRELOC; /* self expression has a fixed register */
1074 luaK_reserveregs(fs, 2); /* function and 'self' produced by op_self */
1075 codeABRK(fs, OP_SELF, e->u.info, ereg, key);
1076 freeexp(fs, key);
1077}
static void codeABRK(FuncState *fs, OpCode o, int a, int b, expdesc *ec)

References codeABRK(), freeexp(), FuncState::freereg, expdesc::info, expdesc::k, luaK_exp2anyreg(), luaK_reserveregs(), OP_SELF, expdesc::u, and VNONRELOC.

◆ luaK_semerror()

l_noret luaK_semerror ( LexState * ls,
const char * msg )

Definition at line 45 of file lua-5.4.3/src/lcode.c.

45 {
46 ls->t.token = 0; /* remove "near <token>" from final message */
47 luaX_syntaxerror(ls, msg);
48}

References luaX_syntaxerror(), LexState::t, and Token::token.

Referenced by check_readonly(), checkrepeated(), getlocalattribute(), jumpscopeerror(), localstat(), and undefgoto().

◆ luaK_setlist()

void luaK_setlist ( FuncState * fs,
int base,
int nelems,
int tostore )

Definition at line 1750 of file lua-5.4.3/src/lcode.c.

1750 {
1751 lua_assert(tostore != 0 && tostore <= LFIELDS_PER_FLUSH);
1752 if (tostore == LUA_MULTRET)
1753 tostore = 0;
1754 if (nelems <= MAXARG_C)
1755 luaK_codeABC(fs, OP_SETLIST, base, tostore, nelems);
1756 else {
1757 int extra = nelems / (MAXARG_C + 1);
1758 nelems %= (MAXARG_C + 1);
1759 luaK_codeABCk(fs, OP_SETLIST, base, tostore, nelems, 1);
1760 codeextraarg(fs, extra);
1761 }
1762 fs->freereg = base + 1; /* free registers with list values */
1763}
#define LFIELDS_PER_FLUSH
#define LUA_MULTRET

References codeextraarg(), FuncState::freereg, LFIELDS_PER_FLUSH, lua_assert, LUA_MULTRET, luaK_codeABC, luaK_codeABCk(), MAXARG_C, and OP_SETLIST.

◆ luaK_setoneret()

void luaK_setoneret ( FuncState * fs,
expdesc * e )

Definition at line 736 of file lua-5.4.3/src/lcode.c.

736 {
737 if (e->k == VCALL) { /* expression is an open function call? */
738 /* already returns 1 value */
739 lua_assert(GETARG_C(getinstruction(fs, e)) == 2);
740 e->k = VNONRELOC; /* result has fixed position */
741 e->u.info = GETARG_A(getinstruction(fs, e));
742 }
743 else if (e->k == VVARARG) {
744 SETARG_C(getinstruction(fs, e), 2);
745 e->k = VRELOC; /* can relocate its simple result */
746 }
747}
#define GETARG_C(i)

References GETARG_A, GETARG_C, getinstruction, expdesc::info, expdesc::k, lua_assert, SETARG_C, expdesc::u, VCALL, VNONRELOC, VRELOC, and VVARARG.

Referenced by luaK_dischargevars().

◆ luaK_setreturns()

void luaK_setreturns ( FuncState * fs,
expdesc * e,
int nresults )

Definition at line 703 of file lua-5.4.3/src/lcode.c.

703 {
704 Instruction *pc = &getinstruction(fs, e);
705 if (e->k == VCALL) /* expression is an open function call? */
706 SETARG_C(*pc, nresults + 1);
707 else {
708 lua_assert(e->k == VVARARG);
709 SETARG_C(*pc, nresults + 1);
710 SETARG_A(*pc, fs->freereg);
711 luaK_reserveregs(fs, 1);
712 }
713}

References FuncState::freereg, getinstruction, expdesc::k, lua_assert, luaK_reserveregs(), SETARG_A, SETARG_C, VCALL, and VVARARG.

◆ luaK_settablesize()

void luaK_settablesize ( FuncState * fs,
int pc,
int ra,
int asize,
int hsize )

Definition at line 1732 of file lua-5.4.3/src/lcode.c.

1732 {
1733 Instruction *inst = &fs->f->code[pc];
1734 int rb = (hsize != 0) ? luaO_ceillog2(hsize) + 1 : 0; /* hash size */
1735 int extra = asize / (MAXARG_C + 1); /* higher bits of array size */
1736 int rc = asize % (MAXARG_C + 1); /* lower bits of array size */
1737 int k = (extra > 0); /* true iff needs extra argument */
1738 *inst = CREATE_ABCk(OP_NEWTABLE, ra, rb, rc, k);
1739 *(inst + 1) = CREATE_Ax(OP_EXTRAARG, extra);
1740}
int luaO_ceillog2(unsigned int x)

References Proto::code, CREATE_ABCk, CREATE_Ax, FuncState::f, luaO_ceillog2(), MAXARG_C, OP_EXTRAARG, and OP_NEWTABLE.

Referenced by constructor().

◆ luaK_storevar()

void luaK_storevar ( FuncState * fs,
expdesc * var,
expdesc * ex )

Definition at line 1030 of file lua-5.4.3/src/lcode.c.

1030 {
1031 switch (var->k) {
1032 case VLOCAL: {
1033 freeexp(fs, ex);
1034 exp2reg(fs, ex, var->u.var.ridx); /* compute 'ex' into proper place */
1035 return;
1036 }
1037 case VUPVAL: {
1038 int e = luaK_exp2anyreg(fs, ex);
1039 luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);
1040 break;
1041 }
1042 case VINDEXUP: {
1043 codeABRK(fs, OP_SETTABUP, var->u.ind.t, var->u.ind.idx, ex);
1044 break;
1045 }
1046 case VINDEXI: {
1047 codeABRK(fs, OP_SETI, var->u.ind.t, var->u.ind.idx, ex);
1048 break;
1049 }
1050 case VINDEXSTR: {
1051 codeABRK(fs, OP_SETFIELD, var->u.ind.t, var->u.ind.idx, ex);
1052 break;
1053 }
1054 case VINDEXED: {
1055 codeABRK(fs, OP_SETTABLE, var->u.ind.t, var->u.ind.idx, ex);
1056 break;
1057 }
1058 default: lua_assert(0); /* invalid var kind to store */
1059 }
1060 freeexp(fs, ex);
1061}

References codeABRK(), exp2reg(), freeexp(), expdesc::idx, expdesc::ind, expdesc::info, expdesc::k, lua_assert, luaK_codeABC, luaK_exp2anyreg(), OP_SETFIELD, OP_SETI, OP_SETTABLE, OP_SETTABUP, OP_SETUPVAL, expdesc::ridx, expdesc::t, expdesc::u, expdesc::var, VINDEXED, VINDEXI, VINDEXSTR, VINDEXUP, VLOCAL, and VUPVAL.

◆ need_value()

static int need_value ( FuncState * fs,
int list )
static

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

880 {
881 for (; list != NO_JUMP; list = getjump(fs, list)) {
882 Instruction i = *getjumpcontrol(fs, list);
883 if (GET_OPCODE(i) != OP_TESTSET) return 1;
884 }
885 return 0; /* not found */
886}
static Instruction * getjumpcontrol(FuncState *fs, int pc)

References GET_OPCODE, getjump(), getjumpcontrol(), NO_JUMP, and OP_TESTSET.

Referenced by exp2reg().

◆ negatecondition()

static void negatecondition ( FuncState * fs,
expdesc * e )
static

Definition at line 1083 of file lua-5.4.3/src/lcode.c.

1083 {
1084 Instruction *pc = getjumpcontrol(fs, e->u.info);
1086 GET_OPCODE(*pc) != OP_TEST);
1087 SETARG_k(*pc, (GETARG_k(*pc) ^ 1));
1088}
#define GETARG_k(i)

References GET_OPCODE, GETARG_k, getjumpcontrol(), expdesc::info, lua_assert, OP_TEST, OP_TESTSET, SETARG_k, testTMode, and expdesc::u.

Referenced by codenot(), and luaK_goiftrue().

◆ nilK()

static int nilK ( FuncState * fs)
static

Definition at line 627 of file lua-5.4.3/src/lcode.c.

627 {
628 TValue k, v;
629 setnilvalue(&v);
630 /* cannot use nil as key; instead use table itself to represent nil */
631 sethvalue(fs->ls->L, &k, fs->ls->h);
632 return addk(fs, &k, &v);
633}
#define sethvalue(L, obj, x)

References addk(), LexState::h, LexState::L, FuncState::ls, sethvalue, and setnilvalue.

Referenced by luaK_exp2K().

◆ patchlistaux()

static void patchlistaux ( FuncState * fs,
int list,
int vtarget,
int reg,
int dtarget )
static

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

288 {
289 while (list != NO_JUMP) {
290 int next = getjump(fs, list);
291 if (patchtestreg(fs, list, reg))
292 fixjump(fs, list, vtarget);
293 else
294 fixjump(fs, list, dtarget); /* jump to default target */
295 list = next;
296 }
297}
static int patchtestreg(FuncState *fs, int node, int reg)

References fixjump(), getjump(), next, NO_JUMP, and patchtestreg().

Referenced by exp2reg(), and luaK_patchlist().

◆ patchtestreg()

static int patchtestreg ( FuncState * fs,
int node,
int reg )
static

Definition at line 258 of file lua-5.4.3/src/lcode.c.

258 {
259 Instruction *i = getjumpcontrol(fs, node);
260 if (GET_OPCODE(*i) != OP_TESTSET)
261 return 0; /* cannot patch other instructions */
262 if (reg != NO_REG && reg != GETARG_B(*i))
263 SETARG_A(*i, reg);
264 else {
265 /* no register to put value or register already has the value;
266 change instruction to simple test */
267 *i = CREATE_ABCk(OP_TEST, GETARG_B(*i), 0, 0, GETARG_k(*i));
268 }
269 return 1;
270}

References CREATE_ABCk, GET_OPCODE, GETARG_B, GETARG_k, getjumpcontrol(), NO_REG, OP_TEST, OP_TESTSET, and SETARG_A.

Referenced by patchlistaux(), and removevalues().

◆ previousinstruction()

static Instruction * previousinstruction ( FuncState * fs)
static

Definition at line 115 of file lua-5.4.3/src/lcode.c.

115 {
116 static const Instruction invalidinstruction = ~(Instruction)0;
117 if (fs->pc > fs->lasttarget)
118 return &fs->f->code[fs->pc - 1]; /* previous instruction */
119 else
120 return cast(Instruction*, &invalidinstruction);
121}

References cast, Proto::code, FuncState::f, FuncState::lasttarget, and FuncState::pc.

Referenced by codeconcat(), and luaK_nil().

◆ removelastinstruction()

static void removelastinstruction ( FuncState * fs)
static

Definition at line 371 of file lua-5.4.3/src/lcode.c.

371 {
373 fs->pc--;
374}

References FuncState::pc, and removelastlineinfo().

Referenced by jumponcond().

◆ removelastlineinfo()

static void removelastlineinfo ( FuncState * fs)
static

Definition at line 352 of file lua-5.4.3/src/lcode.c.

352 {
353 Proto *f = fs->f;
354 int pc = fs->pc - 1; /* last instruction coded */
355 if (f->lineinfo[pc] != ABSLINEINFO) { /* relative line info? */
356 fs->previousline -= f->lineinfo[pc]; /* correct last line saved */
357 fs->iwthabs--; /* undo previous increment */
358 }
359 else { /* absolute line information */
360 lua_assert(f->abslineinfo[fs->nabslineinfo - 1].pc == pc);
361 fs->nabslineinfo--; /* remove it */
362 fs->iwthabs = MAXIWTHABS + 1; /* force next line info to be absolute */
363 }
364}
#define ABSLINEINFO
#define MAXIWTHABS
AbsLineInfo * abslineinfo

References ABSLINEINFO, Proto::abslineinfo, FuncState::f, FuncState::iwthabs, Proto::lineinfo, lua_assert, MAXIWTHABS, FuncState::nabslineinfo, FuncState::pc, AbsLineInfo::pc, and FuncState::previousline.

Referenced by luaK_fixline(), and removelastinstruction().

◆ removevalues()

static void removevalues ( FuncState * fs,
int list )
static

Definition at line 276 of file lua-5.4.3/src/lcode.c.

276 {
277 for (; list != NO_JUMP; list = getjump(fs, list))
278 patchtestreg(fs, list, NO_REG);
279}

References getjump(), NO_JUMP, NO_REG, and patchtestreg().

Referenced by codenot().

◆ savelineinfo()

static void savelineinfo ( FuncState * fs,
Proto * f,
int line )
static

Definition at line 328 of file lua-5.4.3/src/lcode.c.

328 {
329 int linedif = line - fs->previousline;
330 int pc = fs->pc - 1; /* last instruction coded */
331 if (abs(linedif) >= LIMLINEDIFF || fs->iwthabs++ >= MAXIWTHABS) {
333 f->sizeabslineinfo, AbsLineInfo, MAX_INT, "lines");
334 f->abslineinfo[fs->nabslineinfo].pc = pc;
335 f->abslineinfo[fs->nabslineinfo++].line = line;
336 linedif = ABSLINEINFO; /* signal that there is absolute information */
337 fs->iwthabs = 1; /* restart counter */
338 }
340 MAX_INT, "opcodes");
341 f->lineinfo[pc] = linedif;
342 fs->previousline = line; /* last line saved */
343}
#define LIMLINEDIFF
signed char ls_byte

References ABSLINEINFO, Proto::abslineinfo, FuncState::iwthabs, LexState::L, LIMLINEDIFF, AbsLineInfo::line, Proto::lineinfo, FuncState::ls, luaM_growvector, MAX_INT, MAXIWTHABS, FuncState::nabslineinfo, FuncState::pc, AbsLineInfo::pc, FuncState::previousline, Proto::sizeabslineinfo, and Proto::sizelineinfo.

Referenced by luaK_code(), and luaK_fixline().

◆ str2K()

static void str2K ( FuncState * fs,
expdesc * e )
static

Definition at line 719 of file lua-5.4.3/src/lcode.c.

719 {
720 lua_assert(e->k == VKSTR);
721 e->u.info = stringK(fs, e->u.strval);
722 e->k = VK;
723}

References expdesc::info, expdesc::k, lua_assert, stringK(), expdesc::strval, expdesc::u, VK, and VKSTR.

Referenced by discharge2reg(), and luaK_indexed().

◆ stringK()

static int stringK ( FuncState * fs,
TString * s )
static

Definition at line 574 of file lua-5.4.3/src/lcode.c.

574 {
575 TValue o;
576 setsvalue(fs->ls->L, &o, s);
577 return addk(fs, &o, &o); /* use string itself as key */
578}
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References addk(), LexState::L, FuncState::ls, s, and setsvalue.

Referenced by luaK_exp2K(), and str2K().

◆ swapexps()

static void swapexps ( expdesc * e1,
expdesc * e2 )
static

Definition at line 1417 of file lua-5.4.3/src/lcode.c.

1417 {
1418 expdesc temp = *e1; *e1 = *e2; *e2 = temp; /* swap 'e1' and 'e2' */
1419}

Referenced by codearith(), codebitwise(), codecommutative(), codeeq(), and luaK_posfix().

◆ tonumeral()

static int tonumeral ( const expdesc * e,
TValue * v )
static

Definition at line 55 of file lua-5.4.3/src/lcode.c.

55 {
56 if (hasjumps(e))
57 return 0; /* not a numeral */
58 switch (e->k) {
59 case VKINT:
60 if (v) setivalue(v, e->u.ival);
61 return 1;
62 case VKFLT:
63 if (v) setfltvalue(v, e->u.nval);
64 return 1;
65 default: return 0;
66 }
67}

References hasjumps, expdesc::ival, expdesc::k, expdesc::nval, setfltvalue, setivalue, expdesc::u, VKFLT, and VKINT.

Referenced by codearith(), codecommutative(), constfolding(), luaK_exp2const(), and luaK_infix().

◆ validop()

static int validop ( int op,
TValue * v1,
TValue * v2 )
static

Definition at line 1296 of file lua-5.4.3/src/lcode.c.

1296 {
1297 switch (op) {
1298 case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:
1299 case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: { /* conversion errors */
1300 lua_Integer i;
1301 return (luaV_tointegerns(v1, &i, LUA_FLOORN2I) &&
1303 }
1304 case LUA_OPDIV: case LUA_OPIDIV: case LUA_OPMOD: /* division by 0 */
1305 return (nvalue(v2) != 0);
1306 default: return 1; /* everything else is valid */
1307 }
1308}
#define nvalue(o)
#define LUA_OPMOD
#define LUA_OPDIV
#define LUA_OPBXOR
#define LUA_OPSHL
#define LUA_OPBOR
#define LUA_OPSHR
#define LUA_OPBNOT
#define LUA_OPBAND
#define LUA_OPIDIV
#define LUA_FLOORN2I
int luaV_tointegerns(const TValue *obj, lua_Integer *p, F2Imod mode)

References LUA_FLOORN2I, LUA_OPBAND, LUA_OPBNOT, LUA_OPBOR, LUA_OPBXOR, LUA_OPDIV, LUA_OPIDIV, LUA_OPMOD, LUA_OPSHL, LUA_OPSHR, luaV_tointegerns(), and nvalue.

Referenced by constfolding().