Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lcode.c File Reference
#include "lprefix.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)
 

Functions

static int tonumeral (const expdesc *e, TValue *v)
 
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 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)
 
static void dischargejpc (FuncState *fs)
 
void luaK_patchtohere (FuncState *fs, int list)
 
void luaK_patchlist (FuncState *fs, int list, int target)
 
void luaK_patchclose (FuncState *fs, int list, int level)
 
static int luaK_code (FuncState *fs, Instruction i)
 
int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c)
 
int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc)
 
static int codeextraarg (FuncState *fs, int a)
 
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 freeexp (FuncState *fs, expdesc *e)
 
static void freeexps (FuncState *fs, expdesc *e1, expdesc *e2)
 
static int addk (FuncState *fs, TValue *key, TValue *v)
 
int luaK_stringK (FuncState *fs, TString *s)
 
int luaK_intK (FuncState *fs, lua_Integer n)
 
static int luaK_numberK (FuncState *fs, lua_Number r)
 
static int boolK (FuncState *fs, int b)
 
static int nilK (FuncState *fs)
 
void luaK_setreturns (FuncState *fs, expdesc *e, int nresults)
 
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, int b, int jump)
 
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)
 
int luaK_exp2RK (FuncState *fs, expdesc *e)
 
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)
 
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 codebinexpval (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2, int line)
 
static void codecomp (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)
 
void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2, int line)
 
void luaK_fixline (FuncState *fs, int line)
 
void luaK_setlist (FuncState *fs, int base, int nelems, int tostore)
 

Macro Definition Documentation

◆ hasjumps

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

◆ lcode_c

#define lcode_c

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

◆ LUA_CORE

#define LUA_CORE

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

◆ MAXREGS

#define MAXREGS   255

Definition at line 33 of file lua-5.3.6/src/lcode.c.

Referenced by luaK_checkstack().

Function Documentation

◆ addk()

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

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

428 {
429 lua_State *L = fs->ls->L;
430 Proto *f = fs->f;
431 TValue *idx = luaH_set(L, fs->ls->h, key); /* index scanner table */
432 int k, oldsize;
433 if (ttisinteger(idx)) { /* is there an index there? */
434 k = cast_int(ivalue(idx));
435 /* correct value? (warning: must distinguish floats from integers!) */
436 if (k < fs->nk && ttype(&f->k[k]) == ttype(v) &&
437 luaV_rawequalobj(&f->k[k], v))
438 return k; /* reuse index */
439 }
440 /* constant not found; create a new entry */
441 oldsize = f->sizek;
442 k = fs->nk;
443 /* numerical value does not need GC barrier;
444 table has no metatable, so it does not need to invalidate cache */
445 setivalue(idx, k);
446 luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");
447 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
448 setobj(L, &f->k[k], v);
449 fs->nk++;
450 luaC_barrier(L, f, v);
451 return k;
452}
#define luaC_barrier(L, p, v)
#define cast_int(i)
#define luaM_growvector(L, v, nelems, size, t, limit, e)
#define ttype(o)
#define setobj(L, obj1, obj2)
#define setnilvalue(obj)
TValue * luaH_set(lua_State *L, Table *t, const TValue *key)
#define MAXARG_Ax
#define luaV_rawequalobj(o1, o2)
#define ttisinteger(o)
#define ivalue(o)
#define setivalue(obj, x)
struct LexState * ls
struct lua_State * L

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

Referenced by boolK(), luaK_intK(), luaK_numberK(), luaK_stringK(), and nilK().

◆ boolK()

static int boolK ( FuncState * fs,
int b )
static

Definition at line 491 of file lua-5.3.6/src/lcode.c.

491 {
492 TValue o;
493 setbvalue(&o, b);
494 return addk(fs, &o, &o); /* use boolean itself as key */
495}
#define setbvalue(obj, x)
static int addk(FuncState *fs, TValue *key, TValue *v)

References addk(), and setbvalue.

Referenced by luaK_exp2RK().

◆ code_loadbool()

static int code_loadbool ( FuncState * fs,
int A,
int b,
int jump )
static

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

649 {
650 luaK_getlabel(fs); /* those instructions may be jump targets */
651 return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);
652}
int luaK_getlabel(FuncState *fs)
#define luaK_codeABC(fs, o, a, b, c)

References luaK_codeABC, luaK_getlabel(), and OP_LOADBOOL.

Referenced by exp2reg().

◆ codebinexpval()

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

Definition at line 1022 of file lua-5.3.6/src/lcode.c.

1023 {
1024 int rk2 = luaK_exp2RK(fs, e2); /* both operands are "RK" */
1025 int rk1 = luaK_exp2RK(fs, e1);
1026 freeexps(fs, e1, e2);
1027 e1->u.info = luaK_codeABC(fs, op, 0, rk1, rk2); /* generate opcode */
1028 e1->k = VRELOCABLE; /* all those operations are relocatable */
1029 luaK_fixline(fs, line);
1030}
static void freeexps(FuncState *fs, expdesc *e1, expdesc *e2)
int luaK_exp2RK(FuncState *fs, expdesc *e)
void luaK_fixline(FuncState *fs, int line)
union expdesc::@52 u

References freeexps(), expdesc::info, expdesc::k, luaK_codeABC, luaK_exp2RK(), luaK_fixline(), expdesc::u, and VRELOCABLE.

Referenced by luaK_posfix().

◆ codecomp()

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

Definition at line 1037 of file lua-5.3.6/src/lcode.c.

1037 {
1038 int rk1 = (e1->k == VK) ? RKASK(e1->u.info)
1039 : check_exp(e1->k == VNONRELOC, e1->u.info);
1040 int rk2 = luaK_exp2RK(fs, e2);
1041 freeexps(fs, e1, e2);
1042 switch (opr) {
1043 case OPR_NE: { /* '(a ~= b)' ==> 'not (a == b)' */
1044 e1->u.info = condjump(fs, OP_EQ, 0, rk1, rk2);
1045 break;
1046 }
1047 case OPR_GT: case OPR_GE: {
1048 /* '(a > b)' ==> '(b < a)'; '(a >= b)' ==> '(b <= a)' */
1049 OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ);
1050 e1->u.info = condjump(fs, op, 1, rk2, rk1); /* invert operands */
1051 break;
1052 }
1053 default: { /* '==', '<', '<=' use their own opcodes */
1054 OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ);
1055 e1->u.info = condjump(fs, op, 1, rk1, rk2);
1056 break;
1057 }
1058 }
1059 e1->k = VJMP;
1060}
#define cast(t, exp)
#define check_exp(c, e)
#define RKASK(x)
static int condjump(FuncState *fs, OpCode op, int A, int B, int C)

References cast, check_exp, condjump(), freeexps(), expdesc::info, expdesc::k, luaK_exp2RK(), OP_EQ, OPR_EQ, OPR_GE, OPR_GT, OPR_NE, RKASK, expdesc::u, VJMP, VK, and VNONRELOC.

Referenced by luaK_posfix().

◆ codeextraarg()

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

Definition at line 335 of file lua-5.3.6/src/lcode.c.

335 {
337 return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a));
338}
#define lua_assert(c)
#define CREATE_Ax(o, a)
static 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 910 of file lua-5.3.6/src/lcode.c.

910 {
911 luaK_dischargevars(fs, e);
912 switch (e->k) {
913 case VNIL: case VFALSE: {
914 e->k = VTRUE; /* true == not nil == not false */
915 break;
916 }
917 case VK: case VKFLT: case VKINT: case VTRUE: {
918 e->k = VFALSE; /* false == not "x" == not 0.5 == not 1 == not true */
919 break;
920 }
921 case VJMP: {
922 negatecondition(fs, e);
923 break;
924 }
925 case VRELOCABLE:
926 case VNONRELOC: {
927 discharge2anyreg(fs, e);
928 freeexp(fs, e);
929 e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);
930 e->k = VRELOCABLE;
931 break;
932 }
933 default: lua_assert(0); /* cannot happen */
934 }
935 /* interchange true and false lists */
936 { int temp = e->f; e->f = e->t; e->t = temp; }
937 removevalues(fs, e->f); /* values are useless when negated */
938 removevalues(fs, e->t);
939}
static void discharge2anyreg(FuncState *fs, expdesc *e)
static void negatecondition(FuncState *fs, expdesc *e)
static void removevalues(FuncState *fs, int list)
void luaK_dischargevars(FuncState *fs, expdesc *e)
static void freeexp(FuncState *fs, expdesc *e)

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

Referenced by luaK_prefix().

◆ codeunexpval()

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

Definition at line 1004 of file lua-5.3.6/src/lcode.c.

1004 {
1005 int r = luaK_exp2anyreg(fs, e); /* opcodes operate only on registers */
1006 freeexp(fs, e);
1007 e->u.info = luaK_codeABC(fs, op, 0, r, 0); /* generate opcode */
1008 e->k = VRELOCABLE; /* all those operations are relocatable */
1009 luaK_fixline(fs, line);
1010}
int luaK_exp2anyreg(FuncState *fs, expdesc *e)

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

Referenced by luaK_prefix().

◆ condjump()

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

Definition at line 158 of file lua-5.3.6/src/lcode.c.

158 {
159 luaK_codeABC(fs, op, A, B, C);
160 return luaK_jump(fs);
161}
int luaK_jump(FuncState *fs)

References luaK_codeABC, and luaK_jump().

Referenced by codecomp(), and jumponcond().

◆ constfolding()

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

Definition at line 978 of file lua-5.3.6/src/lcode.c.

979 {
980 TValue v1, v2, res;
981 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))
982 return 0; /* non-numeric operands or not safe to fold */
983 luaO_arith(fs->ls->L, op, &v1, &v2, &res); /* does operation */
984 if (ttisinteger(&res)) {
985 e1->k = VKINT;
986 e1->u.ival = ivalue(&res);
987 }
988 else { /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */
989 lua_Number n = fltvalue(&res);
990 if (luai_numisnan(n) || n == 0)
991 return 0;
992 e1->k = VKFLT;
993 e1->u.nval = n;
994 }
995 return 1;
996}
LUA_NUMBER lua_Number
lua_Number luaO_arith(int op, lua_Number v1, lua_Number v2)
static int validop(int op, TValue *v1, TValue *v2)
static int tonumeral(const expdesc *e, TValue *v)
#define luai_numisnan(a)
#define fltvalue(o)
lua_Integer ival
lua_Number nval

References fltvalue, expdesc::ival, ivalue, expdesc::k, LexState::L, FuncState::ls, luai_numisnan, luaO_arith(), 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 641 of file lua-5.3.6/src/lcode.c.

641 {
642 if (e->k != VNONRELOC) { /* no fixed register yet? */
643 luaK_reserveregs(fs, 1); /* get a register */
644 discharge2reg(fs, e, fs->freereg-1); /* put value there */
645 }
646}
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 595 of file lua-5.3.6/src/lcode.c.

595 {
596 luaK_dischargevars(fs, e);
597 switch (e->k) {
598 case VNIL: {
599 luaK_nil(fs, reg, 1);
600 break;
601 }
602 case VFALSE: case VTRUE: {
603 luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);
604 break;
605 }
606 case VK: {
607 luaK_codek(fs, reg, e->u.info);
608 break;
609 }
610 case VKFLT: {
611 luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval));
612 break;
613 }
614 case VKINT: {
615 luaK_codek(fs, reg, luaK_intK(fs, e->u.ival));
616 break;
617 }
618 case VRELOCABLE: {
619 Instruction *pc = &getinstruction(fs, e);
620 SETARG_A(*pc, reg); /* instruction will put result in 'reg' */
621 break;
622 }
623 case VNONRELOC: {
624 if (reg != e->u.info)
625 luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);
626 break;
627 }
628 default: {
629 lua_assert(e->k == VJMP);
630 return; /* nothing to do... */
631 }
632 }
633 e->u.info = reg;
634 e->k = VNONRELOC;
635}
lu_int32 Instruction
#define SETARG_A(i, u)
int luaK_codek(FuncState *fs, int reg, int k)
int luaK_intK(FuncState *fs, lua_Integer n)
void luaK_nil(FuncState *fs, int from, int n)
static int luaK_numberK(FuncState *fs, lua_Number r)
#define getinstruction(fs, e)

References getinstruction, expdesc::info, expdesc::ival, expdesc::k, lua_assert, luaK_codeABC, luaK_codek(), luaK_dischargevars(), luaK_intK(), luaK_nil(), luaK_numberK(), expdesc::nval, OP_LOADBOOL, OP_MOVE, SETARG_A, expdesc::u, VFALSE, VJMP, VK, VKFLT, VKINT, VNIL, VNONRELOC, VRELOCABLE, and VTRUE.

Referenced by discharge2anyreg(), and exp2reg().

◆ dischargejpc()

static void dischargejpc ( FuncState * fs)
static

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

242 {
243 patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);
244 fs->jpc = NO_JUMP;
245}
#define NO_JUMP
#define NO_REG
static void patchlistaux(FuncState *fs, int list, int vtarget, int reg, int dtarget)

References FuncState::jpc, NO_JUMP, NO_REG, patchlistaux(), and FuncState::pc.

Referenced by luaK_code().

◆ exp2reg()

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

Definition at line 675 of file lua-5.3.6/src/lcode.c.

675 {
676 discharge2reg(fs, e, reg);
677 if (e->k == VJMP) /* expression itself is a test? */
678 luaK_concat(fs, &e->t, e->u.info); /* put this jump in 't' list */
679 if (hasjumps(e)) {
680 int final; /* position after whole expression */
681 int p_f = NO_JUMP; /* position of an eventual LOAD false */
682 int p_t = NO_JUMP; /* position of an eventual LOAD true */
683 if (need_value(fs, e->t) || need_value(fs, e->f)) {
684 int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);
685 p_f = code_loadbool(fs, reg, 0, 1);
686 p_t = code_loadbool(fs, reg, 1, 0);
687 luaK_patchtohere(fs, fj);
688 }
689 final = luaK_getlabel(fs);
690 patchlistaux(fs, e->f, final, reg, p_f);
691 patchlistaux(fs, e->t, final, reg, p_t);
692 }
693 e->f = e->t = NO_JUMP;
694 e->u.info = reg;
695 e->k = VNONRELOC;
696}
static int code_loadbool(FuncState *fs, int A, int b, int jump)
void luaK_patchtohere(FuncState *fs, int list)
#define hasjumps(e)
void luaK_concat(FuncState *fs, int *l1, int l2)
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, patchlistaux(), expdesc::t, expdesc::u, VJMP, and VNONRELOC.

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

◆ fixjump()

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

Definition at line 103 of file lua-5.3.6/src/lcode.c.

103 {
104 Instruction *jmp = &fs->f->code[pc];
105 int offset = dest - (pc + 1);
106 lua_assert(dest != NO_JUMP);
107 if (abs(offset) > MAXARG_sBx)
108 luaX_syntaxerror(fs->ls, "control structure too long");
109 SETARG_sBx(*jmp, offset);
110}
void luaX_syntaxerror(LexState *ls, const char *msg)
#define MAXARG_sBx
#define SETARG_sBx(i, b)
Instruction * code

References Proto::code, FuncState::f, FuncState::ls, lua_assert, luaX_syntaxerror(), MAXARG_sBx, NO_JUMP, and SETARG_sBx.

Referenced by luaK_concat(), and patchlistaux().

◆ freeexp()

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

Definition at line 397 of file lua-5.3.6/src/lcode.c.

397 {
398 if (e->k == VNONRELOC)
399 freereg(fs, e->u.info);
400}
static void freereg(FuncState *fs, int reg)

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

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

◆ freeexps()

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

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

407 {
408 int r1 = (e1->k == VNONRELOC) ? e1->u.info : -1;
409 int r2 = (e2->k == VNONRELOC) ? e2->u.info : -1;
410 if (r1 > r2) {
411 freereg(fs, r1);
412 freereg(fs, r2);
413 }
414 else {
415 freereg(fs, r2);
416 freereg(fs, r1);
417 }
418}

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

Referenced by codebinexpval(), and codecomp().

◆ freereg()

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

Definition at line 386 of file lua-5.3.6/src/lcode.c.

386 {
387 if (!ISK(reg) && reg >= fs->nactvar) {
388 fs->freereg--;
389 lua_assert(reg == fs->freereg);
390 }
391}
#define ISK(x)

References FuncState::freereg, ISK, lua_assert, and FuncState::nactvar.

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

◆ getjump()

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

Definition at line 90 of file lua-5.3.6/src/lcode.c.

90 {
91 int offset = GETARG_sBx(fs->f->code[pc]);
92 if (offset == NO_JUMP) /* point to itself represents end of list */
93 return NO_JUMP; /* end of list */
94 else
95 return (pc+1)+offset; /* turn offset into absolute position */
96}
#define GETARG_sBx(i)

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

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

◆ getjumpcontrol()

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

Definition at line 179 of file lua-5.3.6/src/lcode.c.

179 {
180 Instruction *pi = &fs->f->code[pc];
181 if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))
182 return pi-1;
183 else
184 return pi;
185}
#define testTMode(m)
#define GET_OPCODE(i)

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

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

◆ jumponcond()

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

Definition at line 839 of file lua-5.3.6/src/lcode.c.

839 {
840 if (e->k == VRELOCABLE) {
841 Instruction ie = getinstruction(fs, e);
842 if (GET_OPCODE(ie) == OP_NOT) {
843 fs->pc--; /* remove previous OP_NOT */
844 return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);
845 }
846 /* else go through */
847 }
848 discharge2anyreg(fs, e);
849 freeexp(fs, e);
850 return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond);
851}
#define GETARG_B(i)
static int cond(LexState *ls)

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

Referenced by luaK_goiffalse(), and luaK_goiftrue().

◆ luaK_checkstack()

void luaK_checkstack ( FuncState * fs,
int n )

Definition at line 361 of file lua-5.3.6/src/lcode.c.

361 {
362 int newstack = fs->freereg + n;
363 if (newstack > fs->f->maxstacksize) {
364 if (newstack >= MAXREGS)
366 "function or expression needs too many registers");
367 fs->f->maxstacksize = cast_byte(newstack);
368 }
369}
#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()

static int luaK_code ( FuncState * fs,
Instruction i )
static

Definition at line 293 of file lua-5.3.6/src/lcode.c.

293 {
294 Proto *f = fs->f;
295 dischargejpc(fs); /* 'pc' will change */
296 /* put new instruction in code array */
297 luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,
298 MAX_INT, "opcodes");
299 f->code[fs->pc] = i;
300 /* save corresponding line information */
301 luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
302 MAX_INT, "opcodes");
303 f->lineinfo[fs->pc] = fs->ls->lastline;
304 return fs->pc++;
305}
#define MAX_INT
static void dischargejpc(FuncState *fs)

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

Referenced by codeextraarg(), luaK_codeABC(), and luaK_codeABx().

◆ luaK_codeABC()

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

Definition at line 312 of file lua-5.3.6/src/lcode.c.

312 {
314 lua_assert(getBMode(o) != OpArgN || b == 0);
315 lua_assert(getCMode(o) != OpArgN || c == 0);
316 lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C);
317 return luaK_code(fs, CREATE_ABC(o, a, b, c));
318}
#define MAXARG_C
#define CREATE_ABC(o, a, b, c)
#define getCMode(m)
#define MAXARG_A
#define MAXARG_B
#define getBMode(m)
#define getOpMode(m)

References CREATE_ABC, getBMode, getCMode, getOpMode, iABC, lua_assert, luaK_code(), MAXARG_A, MAXARG_B, MAXARG_C, and OpArgN.

◆ luaK_codeABx()

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

Definition at line 324 of file lua-5.3.6/src/lcode.c.

324 {
325 lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);
327 lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx);
328 return luaK_code(fs, CREATE_ABx(o, a, bc));
329}
#define CREATE_ABx(o, a, bc)
#define MAXARG_Bx

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

Referenced by luaK_codek().

◆ luaK_codek()

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

Definition at line 346 of file lua-5.3.6/src/lcode.c.

346 {
347 if (k <= MAXARG_Bx)
348 return luaK_codeABx(fs, OP_LOADK, reg, k);
349 else {
350 int p = luaK_codeABx(fs, OP_LOADKX, reg, 0);
351 codeextraarg(fs, k);
352 return p;
353 }
354}
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_concat()

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

Definition at line 116 of file lua-5.3.6/src/lcode.c.

116 {
117 if (l2 == NO_JUMP) return; /* nothing to concatenate? */
118 else if (*l1 == NO_JUMP) /* no original list? */
119 *l1 = l2; /* 'l1' points to 'l2' */
120 else {
121 int list = *l1;
122 int next;
123 while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */
124 list = next;
125 fixjump(fs, list, l2); /* last element links to 'l2' */
126 }
127}
#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(), luaK_jump(), luaK_patchtohere(), and luaK_posfix().

◆ luaK_dischargevars()

void luaK_dischargevars ( FuncState * fs,
expdesc * e )

Definition at line 556 of file lua-5.3.6/src/lcode.c.

556 {
557 switch (e->k) {
558 case VLOCAL: { /* already in a register */
559 e->k = VNONRELOC; /* becomes a non-relocatable value */
560 break;
561 }
562 case VUPVAL: { /* move value to some (pending) register */
563 e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);
564 e->k = VRELOCABLE;
565 break;
566 }
567 case VINDEXED: {
568 OpCode op;
569 freereg(fs, e->u.ind.idx);
570 if (e->u.ind.vt == VLOCAL) { /* is 't' in a register? */
571 freereg(fs, e->u.ind.t);
572 op = OP_GETTABLE;
573 }
574 else {
575 lua_assert(e->u.ind.vt == VUPVAL);
576 op = OP_GETTABUP; /* 't' is in an upvalue */
577 }
578 e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx);
579 e->k = VRELOCABLE;
580 break;
581 }
582 case VVARARG: case VCALL: {
583 luaK_setoneret(fs, e);
584 break;
585 }
586 default: break; /* there is one value available (somewhere) */
587 }
588}
void luaK_setoneret(FuncState *fs, expdesc *e)
struct expdesc::@61::@62 ind

References freereg(), expdesc::idx, expdesc::ind, expdesc::info, expdesc::k, lua_assert, luaK_codeABC, luaK_setoneret(), OP_GETTABLE, OP_GETTABUP, OP_GETUPVAL, expdesc::t, expdesc::u, VCALL, VINDEXED, VLOCAL, VNONRELOC, VRELOCABLE, expdesc::vt, VUPVAL, and VVARARG.

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

◆ luaK_exp2anyreg()

int luaK_exp2anyreg ( FuncState * fs,
expdesc * e )

Definition at line 715 of file lua-5.3.6/src/lcode.c.

715 {
716 luaK_dischargevars(fs, e);
717 if (e->k == VNONRELOC) { /* expression already has a register? */
718 if (!hasjumps(e)) /* no jumps? */
719 return e->u.info; /* result is already in a register */
720 if (e->u.info >= fs->nactvar) { /* reg. is not a local? */
721 exp2reg(fs, e, e->u.info); /* put final result in it */
722 return e->u.info;
723 }
724 }
725 luaK_exp2nextreg(fs, e); /* otherwise, use next available register */
726 return e->u.info;
727}
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(), FuncState::nactvar, expdesc::u, and VNONRELOC.

Referenced by codeunexpval(), luaK_exp2anyregup(), luaK_exp2RK(), luaK_exp2val(), luaK_self(), and luaK_storevar().

◆ luaK_exp2anyregup()

void luaK_exp2anyregup ( FuncState * fs,
expdesc * e )

Definition at line 734 of file lua-5.3.6/src/lcode.c.

734 {
735 if (e->k != VUPVAL || hasjumps(e))
736 luaK_exp2anyreg(fs, e);
737}

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

◆ luaK_exp2nextreg()

void luaK_exp2nextreg ( FuncState * fs,
expdesc * e )

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

703 {
704 luaK_dischargevars(fs, e);
705 freeexp(fs, e);
706 luaK_reserveregs(fs, 1);
707 exp2reg(fs, e, fs->freereg - 1);
708}

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 758 of file lua-5.3.6/src/lcode.c.

758 {
759 luaK_exp2val(fs, e);
760 switch (e->k) { /* move constants to 'k' */
761 case VTRUE: e->u.info = boolK(fs, 1); goto vk;
762 case VFALSE: e->u.info = boolK(fs, 0); goto vk;
763 case VNIL: e->u.info = nilK(fs); goto vk;
764 case VKINT: e->u.info = luaK_intK(fs, e->u.ival); goto vk;
765 case VKFLT: e->u.info = luaK_numberK(fs, e->u.nval); goto vk;
766 case VK:
767 vk:
768 e->k = VK;
769 if (e->u.info <= MAXINDEXRK) /* constant fits in 'argC'? */
770 return RKASK(e->u.info);
771 else break;
772 default: break;
773 }
774 /* not a constant in the right range: put it in a register */
775 return luaK_exp2anyreg(fs, e);
776}
#define MAXINDEXRK
void luaK_exp2val(FuncState *fs, expdesc *e)
static int nilK(FuncState *fs)
static int boolK(FuncState *fs, int b)

References boolK(), expdesc::info, expdesc::ival, expdesc::k, luaK_exp2anyreg(), luaK_exp2val(), luaK_intK(), luaK_numberK(), MAXINDEXRK, nilK(), expdesc::nval, RKASK, expdesc::u, VFALSE, VK, VKFLT, VKINT, VNIL, and VTRUE.

Referenced by codebinexpval(), codecomp(), luaK_indexed(), luaK_infix(), luaK_self(), and luaK_storevar().

◆ luaK_exp2val()

void luaK_exp2val ( FuncState * fs,
expdesc * e )

Definition at line 744 of file lua-5.3.6/src/lcode.c.

744 {
745 if (hasjumps(e))
746 luaK_exp2anyreg(fs, e);
747 else
748 luaK_dischargevars(fs, e);
749}

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

Referenced by luaK_exp2RK(), and luaK_posfix().

◆ luaK_fixline()

void luaK_fixline ( FuncState * fs,
int line )

Definition at line 1177 of file lua-5.3.6/src/lcode.c.

1177 {
1178 fs->f->lineinfo[fs->pc - 1] = line;
1179}

References FuncState::f, Proto::lineinfo, and FuncState::pc.

Referenced by codebinexpval(), and codeunexpval().

◆ luaK_getlabel()

int luaK_getlabel ( FuncState * fs)

Definition at line 168 of file lua-5.3.6/src/lcode.c.

168 {
169 fs->lasttarget = fs->pc;
170 return fs->pc;
171}

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 884 of file lua-5.3.6/src/lcode.c.

884 {
885 int pc; /* pc of new jump */
886 luaK_dischargevars(fs, e);
887 switch (e->k) {
888 case VJMP: {
889 pc = e->u.info; /* already jump if true */
890 break;
891 }
892 case VNIL: case VFALSE: {
893 pc = NO_JUMP; /* always false; do nothing */
894 break;
895 }
896 default: {
897 pc = jumponcond(fs, e, 1); /* jump if true */
898 break;
899 }
900 }
901 luaK_concat(fs, &e->t, pc); /* insert new jump in 't' list */
902 luaK_patchtohere(fs, e->f); /* false list jumps to here (to go through) */
903 e->f = NO_JUMP;
904}
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 857 of file lua-5.3.6/src/lcode.c.

857 {
858 int pc; /* pc of new jump */
859 luaK_dischargevars(fs, e);
860 switch (e->k) {
861 case VJMP: { /* condition? */
862 negatecondition(fs, e); /* jump when it is false */
863 pc = e->u.info; /* save jump position */
864 break;
865 }
866 case VK: case VKFLT: case VKINT: case VTRUE: {
867 pc = NO_JUMP; /* always true; do nothing */
868 break;
869 }
870 default: {
871 pc = jumponcond(fs, e, 0); /* jump when false */
872 break;
873 }
874 }
875 luaK_concat(fs, &e->f, pc); /* insert new jump in false list */
876 luaK_patchtohere(fs, e->t); /* true list jumps to here (to go through) */
877 e->t = NO_JUMP;
878}

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, and VTRUE.

Referenced by luaK_infix().

◆ luaK_indexed()

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

Definition at line 946 of file lua-5.3.6/src/lcode.c.

946 {
947 lua_assert(!hasjumps(t) && (vkisinreg(t->k) || t->k == VUPVAL));
948 t->u.ind.t = t->u.info; /* register or upvalue index */
949 t->u.ind.idx = luaK_exp2RK(fs, k); /* R/K index for key */
950 t->u.ind.vt = (t->k == VUPVAL) ? VUPVAL : VLOCAL;
951 t->k = VINDEXED;
952}
#define vkisinreg(k)

References hasjumps, expdesc::idx, expdesc::ind, expdesc::info, expdesc::k, lua_assert, luaK_exp2RK(), expdesc::t, expdesc::u, VINDEXED, vkisinreg, VLOCAL, expdesc::vt, and VUPVAL.

◆ luaK_infix()

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

Definition at line 1086 of file lua-5.3.6/src/lcode.c.

1086 {
1087 switch (op) {
1088 case OPR_AND: {
1089 luaK_goiftrue(fs, v); /* go ahead only if 'v' is true */
1090 break;
1091 }
1092 case OPR_OR: {
1093 luaK_goiffalse(fs, v); /* go ahead only if 'v' is false */
1094 break;
1095 }
1096 case OPR_CONCAT: {
1097 luaK_exp2nextreg(fs, v); /* operand must be on the 'stack' */
1098 break;
1099 }
1100 case OPR_ADD: case OPR_SUB:
1101 case OPR_MUL: case OPR_DIV: case OPR_IDIV:
1102 case OPR_MOD: case OPR_POW:
1103 case OPR_BAND: case OPR_BOR: case OPR_BXOR:
1104 case OPR_SHL: case OPR_SHR: {
1105 if (!tonumeral(v, NULL))
1106 luaK_exp2RK(fs, v);
1107 /* else keep numeral, which may be folded with 2nd operand */
1108 break;
1109 }
1110 default: {
1111 luaK_exp2RK(fs, v);
1112 break;
1113 }
1114 }
1115}
#define NULL
Definition gmacros.h:924
@ OPR_CONCAT
void luaK_goiffalse(FuncState *fs, expdesc *e)
void luaK_goiftrue(FuncState *fs, expdesc *e)

References luaK_exp2nextreg(), luaK_exp2RK(), luaK_goiffalse(), luaK_goiftrue(), NULL, OPR_ADD, OPR_AND, OPR_BAND, OPR_BOR, OPR_BXOR, OPR_CONCAT, OPR_DIV, OPR_IDIV, OPR_MOD, OPR_MUL, OPR_OR, OPR_POW, OPR_SHL, OPR_SHR, OPR_SUB, and tonumeral().

◆ luaK_intK()

int luaK_intK ( FuncState * fs,
lua_Integer n )

Definition at line 471 of file lua-5.3.6/src/lcode.c.

471 {
472 TValue k, o;
473 setpvalue(&k, cast(void*, cast(size_t, n)));
474 setivalue(&o, n);
475 return addk(fs, &k, &o);
476}
#define setpvalue(obj, x)

References addk(), cast, setivalue, and setpvalue.

Referenced by discharge2reg(), fornum(), and luaK_exp2RK().

◆ luaK_jump()

int luaK_jump ( FuncState * fs)

Definition at line 136 of file lua-5.3.6/src/lcode.c.

136 {
137 int jpc = fs->jpc; /* save list of jumps to here */
138 int j;
139 fs->jpc = NO_JUMP; /* no more jumps to here */
140 j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);
141 luaK_concat(fs, &j, jpc); /* keep them on hold */
142 return j;
143}
#define luaK_codeAsBx(fs, o, A, sBx)

References FuncState::jpc, luaK_codeAsBx, luaK_concat(), NO_JUMP, and OP_JMP.

Referenced by condjump(), and exp2reg().

◆ luaK_nil()

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

Definition at line 64 of file lua-5.3.6/src/lcode.c.

64 {
65 Instruction *previous;
66 int l = from + n - 1; /* last register to set nil */
67 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
68 previous = &fs->f->code[fs->pc-1];
69 if (GET_OPCODE(*previous) == OP_LOADNIL) { /* previous is LOADNIL? */
70 int pfrom = GETARG_A(*previous); /* get previous range */
71 int pl = pfrom + GETARG_B(*previous);
72 if ((pfrom <= from && from <= pl + 1) ||
73 (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
74 if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
75 if (pl > l) l = pl; /* l = max(l, pl) */
76 SETARG_A(*previous, from);
77 SETARG_B(*previous, l - from);
78 return;
79 }
80 } /* else go through */
81 }
82 luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */
83}
#define GETARG_A(i)
#define SETARG_B(i, b)

References Proto::code, FuncState::f, GET_OPCODE, GETARG_A, GETARG_B, FuncState::lasttarget, luaK_codeABC, OP_LOADNIL, FuncState::pc, SETARG_A, and SETARG_B.

Referenced by discharge2reg().

◆ luaK_numberK()

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

Definition at line 481 of file lua-5.3.6/src/lcode.c.

481 {
482 TValue o;
483 setfltvalue(&o, r);
484 return addk(fs, &o, &o); /* use number itself as key */
485}
#define setfltvalue(obj, x)

References addk(), and setfltvalue.

Referenced by discharge2reg(), and luaK_exp2RK().

◆ luaK_patchclose()

void luaK_patchclose ( FuncState * fs,
int list,
int level )

Definition at line 278 of file lua-5.3.6/src/lcode.c.

278 {
279 level++; /* argument is +1 to reserve 0 as non-op */
280 for (; list != NO_JUMP; list = getjump(fs, list)) {
281 lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP &&
282 (GETARG_A(fs->f->code[list]) == 0 ||
283 GETARG_A(fs->f->code[list]) >= level));
284 SETARG_A(fs->f->code[list], level);
285 }
286}

References Proto::code, FuncState::f, GET_OPCODE, GETARG_A, getjump(), lua_assert, NO_JUMP, OP_JMP, and SETARG_A.

◆ luaK_patchlist()

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

Definition at line 263 of file lua-5.3.6/src/lcode.c.

263 {
264 if (target == fs->pc) /* 'target' is current position? */
265 luaK_patchtohere(fs, list); /* add list to pending jumps */
266 else {
267 lua_assert(target < fs->pc);
268 patchlistaux(fs, list, target, NO_REG, target);
269 }
270}

References lua_assert, luaK_patchtohere(), NO_REG, patchlistaux(), and FuncState::pc.

◆ luaK_patchtohere()

void luaK_patchtohere ( FuncState * fs,
int list )

Definition at line 252 of file lua-5.3.6/src/lcode.c.

252 {
253 luaK_getlabel(fs); /* mark "here" as a jump target */
254 luaK_concat(fs, &fs->jpc, list);
255}

References FuncState::jpc, luaK_concat(), and luaK_getlabel().

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

◆ luaK_posfix()

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

Definition at line 1124 of file lua-5.3.6/src/lcode.c.

1125 {
1126 switch (op) {
1127 case OPR_AND: {
1128 lua_assert(e1->t == NO_JUMP); /* list closed by 'luK_infix' */
1129 luaK_dischargevars(fs, e2);
1130 luaK_concat(fs, &e2->f, e1->f);
1131 *e1 = *e2;
1132 break;
1133 }
1134 case OPR_OR: {
1135 lua_assert(e1->f == NO_JUMP); /* list closed by 'luK_infix' */
1136 luaK_dischargevars(fs, e2);
1137 luaK_concat(fs, &e2->t, e1->t);
1138 *e1 = *e2;
1139 break;
1140 }
1141 case OPR_CONCAT: {
1142 luaK_exp2val(fs, e2);
1143 if (e2->k == VRELOCABLE &&
1144 GET_OPCODE(getinstruction(fs, e2)) == OP_CONCAT) {
1145 lua_assert(e1->u.info == GETARG_B(getinstruction(fs, e2))-1);
1146 freeexp(fs, e1);
1147 SETARG_B(getinstruction(fs, e2), e1->u.info);
1148 e1->k = VRELOCABLE; e1->u.info = e2->u.info;
1149 }
1150 else {
1151 luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */
1152 codebinexpval(fs, OP_CONCAT, e1, e2, line);
1153 }
1154 break;
1155 }
1156 case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
1157 case OPR_IDIV: case OPR_MOD: case OPR_POW:
1158 case OPR_BAND: case OPR_BOR: case OPR_BXOR:
1159 case OPR_SHL: case OPR_SHR: {
1160 if (!constfolding(fs, op + LUA_OPADD, e1, e2))
1161 codebinexpval(fs, cast(OpCode, op + OP_ADD), e1, e2, line);
1162 break;
1163 }
1164 case OPR_EQ: case OPR_LT: case OPR_LE:
1165 case OPR_NE: case OPR_GT: case OPR_GE: {
1166 codecomp(fs, op, e1, e2);
1167 break;
1168 }
1169 default: lua_assert(0);
1170 }
1171}
#define LUA_OPADD
static void codecomp(FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2)
static int constfolding(FuncState *fs, int op, expdesc *e1, const expdesc *e2)
static void codebinexpval(FuncState *fs, OpCode op, expdesc *e1, expdesc *e2, int line)

References cast, codebinexpval(), codecomp(), constfolding(), expdesc::f, freeexp(), GET_OPCODE, GETARG_B, getinstruction, expdesc::info, expdesc::k, lua_assert, LUA_OPADD, luaK_concat(), luaK_dischargevars(), luaK_exp2nextreg(), luaK_exp2val(), NO_JUMP, OP_ADD, OP_CONCAT, 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, SETARG_B, expdesc::t, expdesc::u, and VRELOCABLE.

◆ luaK_prefix()

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

Definition at line 1066 of file lua-5.3.6/src/lcode.c.

1066 {
1067 static const expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP};
1068 switch (op) {
1069 case OPR_MINUS: case OPR_BNOT: /* use 'ef' as fake 2nd operand */
1070 if (constfolding(fs, op + LUA_OPUNM, e, &ef))
1071 break;
1072 /* FALLTHROUGH */
1073 case OPR_LEN:
1074 codeunexpval(fs, cast(OpCode, op + OP_UNM), e, line);
1075 break;
1076 case OPR_NOT: codenot(fs, e); break;
1077 default: lua_assert(0);
1078 }
1079}
@ 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, 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 375 of file lua-5.3.6/src/lcode.c.

375 {
376 luaK_checkstack(fs, n);
377 fs->freereg += n;
378}
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 149 of file lua-5.3.6/src/lcode.c.

149 {
150 luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);
151}

References luaK_codeABC, and OP_RETURN.

◆ luaK_self()

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

Definition at line 809 of file lua-5.3.6/src/lcode.c.

809 {
810 int ereg;
811 luaK_exp2anyreg(fs, e);
812 ereg = e->u.info; /* register where 'e' was placed */
813 freeexp(fs, e);
814 e->u.info = fs->freereg; /* base register for op_self */
815 e->k = VNONRELOC; /* self expression has a fixed register */
816 luaK_reserveregs(fs, 2); /* function and 'self' produced by op_self */
817 luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key));
818 freeexp(fs, key);
819}

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

◆ luaK_setlist()

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

Definition at line 1189 of file lua-5.3.6/src/lcode.c.

1189 {
1190 int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1;
1191 int b = (tostore == LUA_MULTRET) ? 0 : tostore;
1192 lua_assert(tostore != 0 && tostore <= LFIELDS_PER_FLUSH);
1193 if (c <= MAXARG_C)
1194 luaK_codeABC(fs, OP_SETLIST, base, b, c);
1195 else if (c <= MAXARG_Ax) {
1196 luaK_codeABC(fs, OP_SETLIST, base, b, 0);
1197 codeextraarg(fs, c);
1198 }
1199 else
1200 luaX_syntaxerror(fs->ls, "constructor too long");
1201 fs->freereg = base + 1; /* free registers with list values */
1202}
#define LFIELDS_PER_FLUSH
#define LUA_MULTRET

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

◆ luaK_setoneret()

void luaK_setoneret ( FuncState * fs,
expdesc * e )

Definition at line 539 of file lua-5.3.6/src/lcode.c.

539 {
540 if (e->k == VCALL) { /* expression is an open function call? */
541 /* already returns 1 value */
542 lua_assert(GETARG_C(getinstruction(fs, e)) == 2);
543 e->k = VNONRELOC; /* result has fixed position */
544 e->u.info = GETARG_A(getinstruction(fs, e));
545 }
546 else if (e->k == VVARARG) {
547 SETARG_B(getinstruction(fs, e), 2);
548 e->k = VRELOCABLE; /* can relocate its simple result */
549 }
550}
#define GETARG_C(i)

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

Referenced by luaK_dischargevars().

◆ luaK_setreturns()

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

Definition at line 515 of file lua-5.3.6/src/lcode.c.

515 {
516 if (e->k == VCALL) { /* expression is an open function call? */
517 SETARG_C(getinstruction(fs, e), nresults + 1);
518 }
519 else if (e->k == VVARARG) {
520 Instruction *pc = &getinstruction(fs, e);
521 SETARG_B(*pc, nresults + 1);
522 SETARG_A(*pc, fs->freereg);
523 luaK_reserveregs(fs, 1);
524 }
525 else lua_assert(nresults == LUA_MULTRET);
526}
#define SETARG_C(i, b)

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

◆ luaK_storevar()

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

Definition at line 782 of file lua-5.3.6/src/lcode.c.

782 {
783 switch (var->k) {
784 case VLOCAL: {
785 freeexp(fs, ex);
786 exp2reg(fs, ex, var->u.info); /* compute 'ex' into proper place */
787 return;
788 }
789 case VUPVAL: {
790 int e = luaK_exp2anyreg(fs, ex);
791 luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);
792 break;
793 }
794 case VINDEXED: {
795 OpCode op = (var->u.ind.vt == VLOCAL) ? OP_SETTABLE : OP_SETTABUP;
796 int e = luaK_exp2RK(fs, ex);
797 luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e);
798 break;
799 }
800 default: lua_assert(0); /* invalid var kind to store */
801 }
802 freeexp(fs, ex);
803}

References exp2reg(), freeexp(), expdesc::idx, expdesc::ind, expdesc::info, expdesc::k, lua_assert, luaK_codeABC, luaK_exp2anyreg(), luaK_exp2RK(), OP_SETTABLE, OP_SETTABUP, OP_SETUPVAL, expdesc::t, expdesc::u, VINDEXED, VLOCAL, expdesc::vt, and VUPVAL.

◆ luaK_stringK()

int luaK_stringK ( FuncState * fs,
TString * s )

Definition at line 458 of file lua-5.3.6/src/lcode.c.

458 {
459 TValue o;
460 setsvalue(fs->ls->L, &o, s);
461 return addk(fs, &o, &o); /* use string itself as key */
462}
#define setsvalue(L, obj, x)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

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

◆ need_value()

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

Definition at line 659 of file lua-5.3.6/src/lcode.c.

659 {
660 for (; list != NO_JUMP; list = getjump(fs, list)) {
661 Instruction i = *getjumpcontrol(fs, list);
662 if (GET_OPCODE(i) != OP_TESTSET) return 1;
663 }
664 return 0; /* not found */
665}
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 825 of file lua-5.3.6/src/lcode.c.

825 {
826 Instruction *pc = getjumpcontrol(fs, e->u.info);
828 GET_OPCODE(*pc) != OP_TEST);
829 SETARG_A(*pc, !(GETARG_A(*pc)));
830}

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

Referenced by codenot(), and luaK_goiftrue().

◆ nilK()

static int nilK ( FuncState * fs)
static

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

501 {
502 TValue k, v;
503 setnilvalue(&v);
504 /* cannot use nil as key; instead use table itself to represent nil */
505 sethvalue(fs->ls->L, &k, fs->ls->h);
506 return addk(fs, &k, &v);
507}
#define sethvalue(L, obj, x)

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

Referenced by luaK_exp2RK().

◆ patchlistaux()

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

Definition at line 224 of file lua-5.3.6/src/lcode.c.

225 {
226 while (list != NO_JUMP) {
227 int next = getjump(fs, list);
228 if (patchtestreg(fs, list, reg))
229 fixjump(fs, list, vtarget);
230 else
231 fixjump(fs, list, dtarget); /* jump to default target */
232 list = next;
233 }
234}
static int patchtestreg(FuncState *fs, int node, int reg)

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

Referenced by dischargejpc(), exp2reg(), and luaK_patchlist().

◆ patchtestreg()

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

Definition at line 195 of file lua-5.3.6/src/lcode.c.

195 {
196 Instruction *i = getjumpcontrol(fs, node);
197 if (GET_OPCODE(*i) != OP_TESTSET)
198 return 0; /* cannot patch other instructions */
199 if (reg != NO_REG && reg != GETARG_B(*i))
200 SETARG_A(*i, reg);
201 else {
202 /* no register to put value or register already has the value;
203 change instruction to simple test */
204 *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));
205 }
206 return 1;
207}

References CREATE_ABC, GET_OPCODE, GETARG_B, GETARG_C, getjumpcontrol(), NO_REG, OP_TEST, OP_TESTSET, and SETARG_A.

Referenced by patchlistaux(), and removevalues().

◆ removevalues()

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

Definition at line 213 of file lua-5.3.6/src/lcode.c.

213 {
214 for (; list != NO_JUMP; list = getjump(fs, list))
215 patchtestreg(fs, list, NO_REG);
216}

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

Referenced by codenot().

◆ tonumeral()

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

Definition at line 43 of file lua-5.3.6/src/lcode.c.

43 {
44 if (hasjumps(e))
45 return 0; /* not a numeral */
46 switch (e->k) {
47 case VKINT:
48 if (v) setivalue(v, e->u.ival);
49 return 1;
50 case VKFLT:
51 if (v) setfltvalue(v, e->u.nval);
52 return 1;
53 default: return 0;
54 }
55}

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

Referenced by constfolding(), and luaK_infix().

◆ validop()

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

Definition at line 960 of file lua-5.3.6/src/lcode.c.

960 {
961 switch (op) {
962 case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:
963 case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: { /* conversion errors */
964 lua_Integer i;
965 return (tointeger(v1, &i) && tointeger(v2, &i));
966 }
967 case LUA_OPDIV: case LUA_OPIDIV: case LUA_OPMOD: /* division by 0 */
968 return (nvalue(v2) != 0);
969 default: return 1; /* everything else is valid */
970 }
971}
#define nvalue(o)
LUA_INTEGER lua_Integer
#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 tointeger(o, i)

References LUA_OPBAND, LUA_OPBNOT, LUA_OPBOR, LUA_OPBXOR, LUA_OPDIV, LUA_OPIDIV, LUA_OPMOD, LUA_OPSHL, LUA_OPSHR, nvalue, and tointeger.

Referenced by constfolding().