Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lcode.c File Reference
#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 hasjumps(e)   ((e)->t != (e)->f)
 

Functions

static int isnumeral (expdesc *e)
 
void luaK_nil (FuncState *fs, int from, int n)
 
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)
 
static void fixjump (FuncState *fs, int pc, int dest)
 
int luaK_getlabel (FuncState *fs)
 
static int getjump (FuncState *fs, int pc)
 
static Instructiongetjumpcontrol (FuncState *fs, int pc)
 
static int need_value (FuncState *fs, int list)
 
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_patchlist (FuncState *fs, int list, int target)
 
LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level)
 
void luaK_patchtohere (FuncState *fs, int list)
 
void luaK_concat (FuncState *fs, int *l1, int l2)
 
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 int addk (FuncState *fs, TValue *key, TValue *v)
 
int luaK_stringK (FuncState *fs, TString *s)
 
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 int code_label (FuncState *fs, int A, int b, int jump)
 
static void discharge2reg (FuncState *fs, expdesc *e, int reg)
 
static void discharge2anyreg (FuncState *fs, expdesc *e)
 
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 invertjump (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 constfolding (OpCode op, expdesc *e1, expdesc *e2)
 
static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2, int line)
 
static void codecomp (FuncState *fs, OpCode op, int cond, 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 10 of file lua-5.2.4/src/lcode.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 11 of file lua-5.2.4/src/lcode.c.

Function Documentation

◆ addk()

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

Definition at line 291 of file lua-5.2.4/src/lcode.c.

291 {
292 lua_State *L = fs->ls->L;
293 TValue *idx = luaH_set(L, fs->h, key);
294 Proto *f = fs->f;
295 int k, oldsize;
296 if (ttisnumber(idx)) {
297 lua_Number n = nvalue(idx);
298 lua_number2int(k, n);
299 if (luaV_rawequalobj(&f->k[k], v))
300 return k;
301 /* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0");
302 go through and create a new entry for this value */
303 }
304 /* constant not found; create a new entry */
305 oldsize = f->sizek;
306 k = fs->nk;
307 /* numerical value does not need GC barrier;
308 table has no metatable, so it does not need to invalidate cache */
309 setnvalue(idx, cast_num(k));
310 luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");
311 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
312 setobj(L, &f->k[k], v);
313 fs->nk++;
314 luaC_barrier(L, f, v);
315 return k;
316}
#define luaC_barrier(L, p, v)
#define cast_num(i)
#define luaM_growvector(L, v, nelems, size, t, limit, e)
#define nvalue(o)
#define setnvalue(obj, x)
#define ttisnumber(o)
#define setobj(L, obj1, obj2)
#define setnilvalue(obj)
TValue * luaH_set(lua_State *L, Table *t, const TValue *key)
LUA_NUMBER lua_Number
#define lua_number2int(i, d)
#define MAXARG_Ax
#define luaV_rawequalobj(o1, o2)
struct LexState * ls
struct lua_State * L

References cast_num, FuncState::f, FuncState::h, Proto::k, LexState::L, FuncState::ls, lua_number2int, luaC_barrier, luaH_set(), luaM_growvector, luaV_rawequalobj, MAXARG_Ax, FuncState::nk, nvalue, setnilvalue, setnvalue, setobj, Proto::sizek, and ttisnumber.

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

◆ boolK()

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

Definition at line 343 of file lua-5.2.4/src/lcode.c.

343 {
344 TValue o;
345 setbvalue(&o, b);
346 return addk(fs, &o, &o);
347}
#define setbvalue(obj, x)
static int addk(FuncState *fs, TValue *key, TValue *v)

References addk(), and setbvalue.

Referenced by luaK_exp2RK().

◆ code_label()

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

Definition at line 415 of file lua-5.2.4/src/lcode.c.

415 {
416 luaK_getlabel(fs); /* those instructions may be jump targets */
417 return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);
418}
int luaK_getlabel(FuncState *fs)
#define luaK_codeABC(fs, o, a, b, c)

References luaK_codeABC, luaK_getlabel(), and OP_LOADBOOL.

Referenced by exp2reg().

◆ codearith()

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

Definition at line 724 of file lua-5.2.4/src/lcode.c.

725 {
726 if (constfolding(op, e1, e2))
727 return;
728 else {
729 int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
730 int o1 = luaK_exp2RK(fs, e1);
731 if (o1 > o2) {
732 freeexp(fs, e1);
733 freeexp(fs, e2);
734 }
735 else {
736 freeexp(fs, e2);
737 freeexp(fs, e1);
738 }
739 e1->u.info = luaK_codeABC(fs, op, 0, o1, o2);
740 e1->k = VRELOCABLE;
741 luaK_fixline(fs, line);
742 }
743}
int luaK_exp2RK(FuncState *fs, expdesc *e)
static void freeexp(FuncState *fs, expdesc *e)
void luaK_fixline(FuncState *fs, int line)
static int constfolding(OpCode op, expdesc *e1, expdesc *e2)
union expdesc::@52 u

References constfolding(), freeexp(), expdesc::info, expdesc::k, luaK_codeABC, luaK_exp2RK(), luaK_fixline(), OP_LEN, OP_UNM, expdesc::u, and VRELOCABLE.

Referenced by luaK_posfix(), and luaK_prefix().

◆ codecomp()

static void codecomp ( FuncState * fs,
OpCode op,
int cond,
expdesc * e1,
expdesc * e2 )
static

Definition at line 746 of file lua-5.2.4/src/lcode.c.

747 {
748 int o1 = luaK_exp2RK(fs, e1);
749 int o2 = luaK_exp2RK(fs, e2);
750 freeexp(fs, e2);
751 freeexp(fs, e1);
752 if (cond == 0 && op != OP_EQ) {
753 int temp; /* exchange args to replace by `<' or `<=' */
754 temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */
755 cond = 1;
756 }
757 e1->u.info = condjump(fs, op, cond, o1, o2);
758 e1->k = VJMP;
759}
static int cond(LexState *ls)
static int condjump(FuncState *fs, OpCode op, int A, int B, int C)

References cond(), condjump(), freeexp(), expdesc::info, expdesc::k, luaK_exp2RK(), OP_EQ, expdesc::u, and VJMP.

Referenced by luaK_posfix().

◆ codeextraarg()

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

Definition at line 244 of file lua-5.2.4/src/lcode.c.

244 {
246 return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a));
247}
#define lua_assert(c)
static int luaK_code(FuncState *fs, Instruction i)
#define CREATE_Ax(o, a)

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

668 {
669 luaK_dischargevars(fs, e);
670 switch (e->k) {
671 case VNIL: case VFALSE: {
672 e->k = VTRUE;
673 break;
674 }
675 case VK: case VKNUM: case VTRUE: {
676 e->k = VFALSE;
677 break;
678 }
679 case VJMP: {
680 invertjump(fs, e);
681 break;
682 }
683 case VRELOCABLE:
684 case VNONRELOC: {
685 discharge2anyreg(fs, e);
686 freeexp(fs, e);
687 e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);
688 e->k = VRELOCABLE;
689 break;
690 }
691 default: {
692 lua_assert(0); /* cannot happen */
693 break;
694 }
695 }
696 /* interchange true and false lists */
697 { int temp = e->f; e->f = e->t; e->t = temp; }
698 removevalues(fs, e->f);
699 removevalues(fs, e->t);
700}
static void discharge2anyreg(FuncState *fs, expdesc *e)
static void removevalues(FuncState *fs, int list)
static void invertjump(FuncState *fs, expdesc *e)
void luaK_dischargevars(FuncState *fs, expdesc *e)

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

Referenced by luaK_prefix().

◆ condjump()

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

Definition at line 74 of file lua-5.2.4/src/lcode.c.

74 {
75 luaK_codeABC(fs, op, A, B, C);
76 return luaK_jump(fs);
77}
int luaK_jump(FuncState *fs)

References luaK_codeABC, and luaK_jump().

Referenced by codecomp(), and jumponcond().

◆ constfolding()

static int constfolding ( OpCode op,
expdesc * e1,
expdesc * e2 )
static

Definition at line 713 of file lua-5.2.4/src/lcode.c.

713 {
714 lua_Number r;
715 if (!isnumeral(e1) || !isnumeral(e2)) return 0;
716 if ((op == OP_DIV || op == OP_MOD) && e2->u.nval == 0)
717 return 0; /* do not attempt to divide by 0 */
718 r = luaO_arith(op - OP_ADD + LUA_OPADD, e1->u.nval, e2->u.nval);
719 e1->u.nval = r;
720 return 1;
721}
static int isnumeral(expdesc *e)
lua_Number luaO_arith(int op, lua_Number v1, lua_Number v2)
#define LUA_OPADD
lua_Number nval

References isnumeral(), LUA_OPADD, luaO_arith(), expdesc::nval, OP_ADD, OP_DIV, OP_MOD, and expdesc::u.

Referenced by codearith().

◆ discharge2anyreg()

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

Definition at line 460 of file lua-5.2.4/src/lcode.c.

460 {
461 if (e->k != VNONRELOC) {
462 luaK_reserveregs(fs, 1);
463 discharge2reg(fs, e, fs->freereg-1);
464 }
465}
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 421 of file lua-5.2.4/src/lcode.c.

421 {
422 luaK_dischargevars(fs, e);
423 switch (e->k) {
424 case VNIL: {
425 luaK_nil(fs, reg, 1);
426 break;
427 }
428 case VFALSE: case VTRUE: {
429 luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);
430 break;
431 }
432 case VK: {
433 luaK_codek(fs, reg, e->u.info);
434 break;
435 }
436 case VKNUM: {
437 luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval));
438 break;
439 }
440 case VRELOCABLE: {
441 Instruction *pc = &getcode(fs, e);
442 SETARG_A(*pc, reg);
443 break;
444 }
445 case VNONRELOC: {
446 if (reg != e->u.info)
447 luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);
448 break;
449 }
450 default: {
451 lua_assert(e->k == VVOID || e->k == VJMP);
452 return; /* nothing to do... */
453 }
454 }
455 e->u.info = reg;
456 e->k = VNONRELOC;
457}
#define getcode(fs, e)
lu_int32 Instruction
#define SETARG_A(i, u)
int luaK_codek(FuncState *fs, int reg, int k)
int luaK_numberK(FuncState *fs, lua_Number r)
void luaK_nil(FuncState *fs, int from, int n)

References getcode, expdesc::info, expdesc::k, lua_assert, luaK_codeABC, luaK_codek(), luaK_dischargevars(), luaK_nil(), luaK_numberK(), expdesc::nval, OP_LOADBOOL, OP_MOVE, SETARG_A, expdesc::u, VFALSE, VJMP, VK, VKNUM, VNIL, VNONRELOC, VRELOCABLE, VTRUE, and VVOID.

Referenced by discharge2anyreg(), and exp2reg().

◆ dischargejpc()

static void dischargejpc ( FuncState * fs)
static

Definition at line 163 of file lua-5.2.4/src/lcode.c.

163 {
164 patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);
165 fs->jpc = NO_JUMP;
166}
#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 468 of file lua-5.2.4/src/lcode.c.

468 {
469 discharge2reg(fs, e, reg);
470 if (e->k == VJMP)
471 luaK_concat(fs, &e->t, e->u.info); /* put this jump in `t' list */
472 if (hasjumps(e)) {
473 int final; /* position after whole expression */
474 int p_f = NO_JUMP; /* position of an eventual LOAD false */
475 int p_t = NO_JUMP; /* position of an eventual LOAD true */
476 if (need_value(fs, e->t) || need_value(fs, e->f)) {
477 int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);
478 p_f = code_label(fs, reg, 0, 1);
479 p_t = code_label(fs, reg, 1, 0);
480 luaK_patchtohere(fs, fj);
481 }
482 final = luaK_getlabel(fs);
483 patchlistaux(fs, e->f, final, reg, p_f);
484 patchlistaux(fs, e->t, final, reg, p_t);
485 }
486 e->f = e->t = NO_JUMP;
487 e->u.info = reg;
488 e->k = VNONRELOC;
489}
static int code_label(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_label(), 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 80 of file lua-5.2.4/src/lcode.c.

80 {
81 Instruction *jmp = &fs->f->code[pc];
82 int offset = dest-(pc+1);
83 lua_assert(dest != NO_JUMP);
84 if (abs(offset) > MAXARG_sBx)
85 luaX_syntaxerror(fs->ls, "control structure too long");
86 SETARG_sBx(*jmp, offset);
87}
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 285 of file lua-5.2.4/src/lcode.c.

285 {
286 if (e->k == VNONRELOC)
287 freereg(fs, e->u.info);
288}
static void freereg(FuncState *fs, int reg)

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

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

◆ freereg()

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

Definition at line 277 of file lua-5.2.4/src/lcode.c.

277 {
278 if (!ISK(reg) && reg >= fs->nactvar) {
279 fs->freereg--;
280 lua_assert(reg == fs->freereg);
281 }
282}
#define ISK(x)

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

Referenced by freeexp(), and luaK_dischargevars().

◆ getjump()

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

Definition at line 100 of file lua-5.2.4/src/lcode.c.

100 {
101 int offset = GETARG_sBx(fs->f->code[pc]);
102 if (offset == NO_JUMP) /* point to itself represents end of list */
103 return NO_JUMP; /* end of list */
104 else
105 return (pc+1)+offset; /* turn offset into absolute position */
106}
#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 109 of file lua-5.2.4/src/lcode.c.

109 {
110 Instruction *pi = &fs->f->code[pc];
111 if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))
112 return pi-1;
113 else
114 return pi;
115}
#define testTMode(m)
#define GET_OPCODE(i)

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

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

◆ invertjump()

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

Definition at line 598 of file lua-5.2.4/src/lcode.c.

598 {
599 Instruction *pc = getjumpcontrol(fs, e->u.info);
601 GET_OPCODE(*pc) != OP_TEST);
602 SETARG_A(*pc, !(GETARG_A(*pc)));
603}
#define GETARG_A(i)
static Instruction * getjumpcontrol(FuncState *fs, int pc)

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().

◆ isnumeral()

static int isnumeral ( expdesc * e)
static

Definition at line 32 of file lua-5.2.4/src/lcode.c.

32 {
33 return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP);
34}

References expdesc::f, expdesc::k, NO_JUMP, expdesc::t, and VKNUM.

Referenced by constfolding(), luaK_infix(), and luaK_prefix().

◆ jumponcond()

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

Definition at line 606 of file lua-5.2.4/src/lcode.c.

606 {
607 if (e->k == VRELOCABLE) {
608 Instruction ie = getcode(fs, e);
609 if (GET_OPCODE(ie) == OP_NOT) {
610 fs->pc--; /* remove previous OP_NOT */
611 return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);
612 }
613 /* else go through */
614 }
615 discharge2anyreg(fs, e);
616 freeexp(fs, e);
617 return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond);
618}
#define GETARG_B(i)

References cond(), condjump(), discharge2anyreg(), freeexp(), GET_OPCODE, GETARG_B, getcode, 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 261 of file lua-5.2.4/src/lcode.c.

261 {
262 int newstack = fs->freereg + n;
263 if (newstack > fs->f->maxstacksize) {
264 if (newstack >= MAXSTACK)
265 luaX_syntaxerror(fs->ls, "function or expression too complex");
266 fs->f->maxstacksize = cast_byte(newstack);
267 }
268}
#define cast_byte(i)
#define MAXSTACK
lu_byte maxstacksize

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

Referenced by luaK_reserveregs().

◆ luaK_code()

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

Definition at line 212 of file lua-5.2.4/src/lcode.c.

212 {
213 Proto *f = fs->f;
214 dischargejpc(fs); /* `pc' will change */
215 /* put new instruction in code array */
216 luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,
217 MAX_INT, "opcodes");
218 f->code[fs->pc] = i;
219 /* save corresponding line information */
220 luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
221 MAX_INT, "opcodes");
222 f->lineinfo[fs->pc] = fs->ls->lastline;
223 return fs->pc++;
224}
#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 227 of file lua-5.2.4/src/lcode.c.

227 {
229 lua_assert(getBMode(o) != OpArgN || b == 0);
230 lua_assert(getCMode(o) != OpArgN || c == 0);
231 lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C);
232 return luaK_code(fs, CREATE_ABC(o, a, b, c));
233}
#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 236 of file lua-5.2.4/src/lcode.c.

236 {
237 lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);
239 lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx);
240 return luaK_code(fs, CREATE_ABx(o, a, bc));
241}
#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 250 of file lua-5.2.4/src/lcode.c.

250 {
251 if (k <= MAXARG_Bx)
252 return luaK_codeABx(fs, OP_LOADK, reg, k);
253 else {
254 int p = luaK_codeABx(fs, OP_LOADKX, reg, 0);
255 codeextraarg(fs, k);
256 return p;
257 }
258}
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(), fornum(), and fornum().

◆ luaK_concat()

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

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

198 {
199 if (l2 == NO_JUMP) return;
200 else if (*l1 == NO_JUMP)
201 *l1 = l2;
202 else {
203 int list = *l1;
204 int next;
205 while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */
206 list = next;
207 fixjump(fs, list, l2);
208 }
209}
#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 383 of file lua-5.2.4/src/lcode.c.

383 {
384 switch (e->k) {
385 case VLOCAL: {
386 e->k = VNONRELOC;
387 break;
388 }
389 case VUPVAL: {
390 e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);
391 e->k = VRELOCABLE;
392 break;
393 }
394 case VINDEXED: {
395 OpCode op = OP_GETTABUP; /* assume 't' is in an upvalue */
396 freereg(fs, e->u.ind.idx);
397 if (e->u.ind.vt == VLOCAL) { /* 't' is in a register? */
398 freereg(fs, e->u.ind.t);
399 op = OP_GETTABLE;
400 }
401 e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx);
402 e->k = VRELOCABLE;
403 break;
404 }
405 case VVARARG:
406 case VCALL: {
407 luaK_setoneret(fs, e);
408 break;
409 }
410 default: break; /* there is one value available (somewhere) */
411 }
412}
void luaK_setoneret(FuncState *fs, expdesc *e)
struct expdesc::@61::@62 ind

References freereg(), expdesc::idx, expdesc::ind, expdesc::info, expdesc::k, 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 500 of file lua-5.2.4/src/lcode.c.

500 {
501 luaK_dischargevars(fs, e);
502 if (e->k == VNONRELOC) {
503 if (!hasjumps(e)) return e->u.info; /* exp is already in a register */
504 if (e->u.info >= fs->nactvar) { /* reg. is not a local? */
505 exp2reg(fs, e, e->u.info); /* put value on it */
506 return e->u.info;
507 }
508 }
509 luaK_exp2nextreg(fs, e); /* default */
510 return e->u.info;
511}
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 luaK_exp2anyregup(), luaK_exp2RK(), luaK_exp2val(), luaK_prefix(), luaK_self(), and luaK_storevar().

◆ luaK_exp2anyregup()

void luaK_exp2anyregup ( FuncState * fs,
expdesc * e )

Definition at line 514 of file lua-5.2.4/src/lcode.c.

514 {
515 if (e->k != VUPVAL || hasjumps(e))
516 luaK_exp2anyreg(fs, e);
517}
int luaK_exp2anyreg(FuncState *fs, expdesc *e)

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

Referenced by fieldsel(), fieldsel(), fieldsel(), suffixedexp(), suffixedexp(), and suffixedexp().

◆ luaK_exp2nextreg()

void luaK_exp2nextreg ( FuncState * fs,
expdesc * e )

Definition at line 492 of file lua-5.2.4/src/lcode.c.

492 {
493 luaK_dischargevars(fs, e);
494 freeexp(fs, e);
495 luaK_reserveregs(fs, 1);
496 exp2reg(fs, e, fs->freereg - 1);
497}

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

528 {
529 luaK_exp2val(fs, e);
530 switch (e->k) {
531 case VTRUE:
532 case VFALSE:
533 case VNIL: {
534 if (fs->nk <= MAXINDEXRK) { /* constant fits in RK operand? */
535 e->u.info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE));
536 e->k = VK;
537 return RKASK(e->u.info);
538 }
539 else break;
540 }
541 case VKNUM: {
542 e->u.info = luaK_numberK(fs, e->u.nval);
543 e->k = VK;
544 /* go through */
545 }
546 case VK: {
547 if (e->u.info <= MAXINDEXRK) /* constant fits in argC? */
548 return RKASK(e->u.info);
549 else break;
550 }
551 default: break;
552 }
553 /* not a constant in the right range: put it in a register */
554 return luaK_exp2anyreg(fs, e);
555}
#define RKASK(x)
#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::k, luaK_exp2anyreg(), luaK_exp2val(), luaK_numberK(), MAXINDEXRK, nilK(), FuncState::nk, expdesc::nval, RKASK, expdesc::u, VFALSE, VK, VKNUM, VNIL, and VTRUE.

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

◆ luaK_exp2val()

void luaK_exp2val ( FuncState * fs,
expdesc * e )

Definition at line 520 of file lua-5.2.4/src/lcode.c.

520 {
521 if (hasjumps(e))
522 luaK_exp2anyreg(fs, e);
523 else
524 luaK_dischargevars(fs, e);
525}

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

862 {
863 fs->f->lineinfo[fs->pc - 1] = line;
864}

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

Referenced by codearith().

◆ luaK_getlabel()

int luaK_getlabel ( FuncState * fs)

Definition at line 94 of file lua-5.2.4/src/lcode.c.

94 {
95 fs->lasttarget = fs->pc;
96 return fs->pc;
97}

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

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

◆ luaK_goiffalse()

void luaK_goiffalse ( FuncState * fs,
expdesc * e )

Definition at line 645 of file lua-5.2.4/src/lcode.c.

645 {
646 int pc; /* pc of last jump */
647 luaK_dischargevars(fs, e);
648 switch (e->k) {
649 case VJMP: {
650 pc = e->u.info;
651 break;
652 }
653 case VNIL: case VFALSE: {
654 pc = NO_JUMP; /* always false; do nothing */
655 break;
656 }
657 default: {
658 pc = jumponcond(fs, e, 1);
659 break;
660 }
661 }
662 luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */
663 luaK_patchtohere(fs, e->f);
664 e->f = NO_JUMP;
665}
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 621 of file lua-5.2.4/src/lcode.c.

621 {
622 int pc; /* pc of last jump */
623 luaK_dischargevars(fs, e);
624 switch (e->k) {
625 case VJMP: {
626 invertjump(fs, e);
627 pc = e->u.info;
628 break;
629 }
630 case VK: case VKNUM: case VTRUE: {
631 pc = NO_JUMP; /* always true; do nothing */
632 break;
633 }
634 default: {
635 pc = jumponcond(fs, e, 0);
636 break;
637 }
638 }
639 luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */
640 luaK_patchtohere(fs, e->t);
641 e->t = NO_JUMP;
642}

References expdesc::f, expdesc::info, invertjump(), jumponcond(), expdesc::k, luaK_concat(), luaK_dischargevars(), luaK_patchtohere(), NO_JUMP, expdesc::t, expdesc::u, VJMP, VK, VKNUM, and VTRUE.

Referenced by luaK_infix().

◆ luaK_indexed()

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

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

703 {
704 lua_assert(!hasjumps(t));
705 t->u.ind.t = t->u.info;
706 t->u.ind.idx = luaK_exp2RK(fs, k);
707 t->u.ind.vt = (t->k == VUPVAL) ? VUPVAL
708 : check_exp(vkisinreg(t->k), VLOCAL);
709 t->k = VINDEXED;
710}
#define check_exp(c, e)
#define vkisinreg(k)

References check_exp, 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 786 of file lua-5.2.4/src/lcode.c.

786 {
787 switch (op) {
788 case OPR_AND: {
789 luaK_goiftrue(fs, v);
790 break;
791 }
792 case OPR_OR: {
793 luaK_goiffalse(fs, v);
794 break;
795 }
796 case OPR_CONCAT: {
797 luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
798 break;
799 }
800 case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
801 case OPR_MOD: case OPR_POW: {
802 if (!isnumeral(v)) luaK_exp2RK(fs, v);
803 break;
804 }
805 default: {
806 luaK_exp2RK(fs, v);
807 break;
808 }
809 }
810}
@ OPR_CONCAT
void luaK_goiffalse(FuncState *fs, expdesc *e)
void luaK_goiftrue(FuncState *fs, expdesc *e)

References isnumeral(), luaK_exp2nextreg(), luaK_exp2RK(), luaK_goiffalse(), luaK_goiftrue(), OPR_ADD, OPR_AND, OPR_CONCAT, OPR_DIV, OPR_MOD, OPR_MUL, OPR_OR, OPR_POW, and OPR_SUB.

◆ luaK_jump()

int luaK_jump ( FuncState * fs)

Definition at line 59 of file lua-5.2.4/src/lcode.c.

59 {
60 int jpc = fs->jpc; /* save list of jumps to here */
61 int j;
62 fs->jpc = NO_JUMP;
63 j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);
64 luaK_concat(fs, &j, jpc); /* keep them on hold */
65 return j;
66}
#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 37 of file lua-5.2.4/src/lcode.c.

37 {
38 Instruction *previous;
39 int l = from + n - 1; /* last register to set nil */
40 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
41 previous = &fs->f->code[fs->pc-1];
42 if (GET_OPCODE(*previous) == OP_LOADNIL) {
43 int pfrom = GETARG_A(*previous);
44 int pl = pfrom + GETARG_B(*previous);
45 if ((pfrom <= from && from <= pl + 1) ||
46 (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
47 if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
48 if (pl > l) l = pl; /* l = max(l, pl) */
49 SETARG_A(*previous, from);
50 SETARG_B(*previous, l - from);
51 return;
52 }
53 } /* else go through */
54 }
55 luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */
56}
#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()

int luaK_numberK ( FuncState * fs,
lua_Number r )

Definition at line 326 of file lua-5.2.4/src/lcode.c.

326 {
327 int n;
328 lua_State *L = fs->ls->L;
329 TValue o;
330 setnvalue(&o, r);
331 if (r == 0 || luai_numisnan(NULL, r)) { /* handle -0 and NaN */
332 /* use raw representation as key to avoid numeric problems */
333 setsvalue(L, L->top++, luaS_newlstr(L, (char *)&r, sizeof(r)));
334 n = addk(fs, L->top - 1, &o);
335 L->top--;
336 }
337 else
338 n = addk(fs, &o, &o); /* regular case */
339 return n;
340}
#define NULL
Definition gmacros.h:924
#define setsvalue(L, obj, x)
TString * luaS_newlstr(lua_State *L, const char *str, size_t l)
#define luai_numisnan(a)

References addk(), LexState::L, FuncState::ls, luai_numisnan, luaS_newlstr(), NULL, setnvalue, setsvalue, and lua_State::top.

Referenced by discharge2reg(), and luaK_exp2RK().

◆ luaK_patchclose()

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

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

179 {
180 level++; /* argument is +1 to reserve 0 as non-op */
181 while (list != NO_JUMP) {
182 int next = getjump(fs, list);
183 lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP &&
184 (GETARG_A(fs->f->code[list]) == 0 ||
185 GETARG_A(fs->f->code[list]) >= level));
186 SETARG_A(fs->f->code[list], level);
187 list = next;
188 }
189}

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

Referenced by findlabel(), findlabel(), leaveblock(), leaveblock(), movegotosout(), movegotosout(), repeatstat(), and repeatstat().

◆ luaK_patchlist()

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

Definition at line 169 of file lua-5.2.4/src/lcode.c.

169 {
170 if (target == fs->pc)
171 luaK_patchtohere(fs, list);
172 else {
173 lua_assert(target < fs->pc);
174 patchlistaux(fs, list, target, NO_REG, target);
175 }
176}

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

◆ luaK_patchtohere()

void luaK_patchtohere ( FuncState * fs,
int list )

Definition at line 192 of file lua-5.2.4/src/lcode.c.

192 {
193 luaK_getlabel(fs);
194 luaK_concat(fs, &fs->jpc, list);
195}

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

814 {
815 switch (op) {
816 case OPR_AND: {
817 lua_assert(e1->t == NO_JUMP); /* list must be closed */
818 luaK_dischargevars(fs, e2);
819 luaK_concat(fs, &e2->f, e1->f);
820 *e1 = *e2;
821 break;
822 }
823 case OPR_OR: {
824 lua_assert(e1->f == NO_JUMP); /* list must be closed */
825 luaK_dischargevars(fs, e2);
826 luaK_concat(fs, &e2->t, e1->t);
827 *e1 = *e2;
828 break;
829 }
830 case OPR_CONCAT: {
831 luaK_exp2val(fs, e2);
832 if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {
833 lua_assert(e1->u.info == GETARG_B(getcode(fs, e2))-1);
834 freeexp(fs, e1);
835 SETARG_B(getcode(fs, e2), e1->u.info);
836 e1->k = VRELOCABLE; e1->u.info = e2->u.info;
837 }
838 else {
839 luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */
840 codearith(fs, OP_CONCAT, e1, e2, line);
841 }
842 break;
843 }
844 case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
845 case OPR_MOD: case OPR_POW: {
846 codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line);
847 break;
848 }
849 case OPR_EQ: case OPR_LT: case OPR_LE: {
850 codecomp(fs, cast(OpCode, op - OPR_EQ + OP_EQ), 1, e1, e2);
851 break;
852 }
853 case OPR_NE: case OPR_GT: case OPR_GE: {
854 codecomp(fs, cast(OpCode, op - OPR_NE + OP_EQ), 0, e1, e2);
855 break;
856 }
857 default: lua_assert(0);
858 }
859}
#define cast(t, exp)
static void codecomp(FuncState *fs, OpCode op, int cond, expdesc *e1, expdesc *e2)
static void codearith(FuncState *fs, OpCode op, expdesc *e1, expdesc *e2, int line)

References cast, codearith(), codecomp(), expdesc::f, freeexp(), GET_OPCODE, GETARG_B, getcode, expdesc::info, expdesc::k, lua_assert, luaK_concat(), luaK_dischargevars(), luaK_exp2nextreg(), luaK_exp2val(), NO_JUMP, OP_ADD, OP_CONCAT, OP_EQ, OPR_ADD, OPR_AND, OPR_CONCAT, OPR_DIV, OPR_EQ, OPR_GE, OPR_GT, OPR_LE, OPR_LT, OPR_MOD, OPR_MUL, OPR_NE, OPR_OR, OPR_POW, 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 762 of file lua-5.2.4/src/lcode.c.

762 {
763 expdesc e2;
764 e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
765 switch (op) {
766 case OPR_MINUS: {
767 if (isnumeral(e)) /* minus constant? */
768 e->u.nval = luai_numunm(NULL, e->u.nval); /* fold it */
769 else {
770 luaK_exp2anyreg(fs, e);
771 codearith(fs, OP_UNM, e, &e2, line);
772 }
773 break;
774 }
775 case OPR_NOT: codenot(fs, e); break;
776 case OPR_LEN: {
777 luaK_exp2anyreg(fs, e); /* cannot operate on constants */
778 codearith(fs, OP_LEN, e, &e2, line);
779 break;
780 }
781 default: lua_assert(0);
782 }
783}
@ OPR_MINUS
static void codenot(FuncState *fs, expdesc *e)
#define luai_numunm(L, a)

References codearith(), codenot(), expdesc::f, isnumeral(), expdesc::k, lua_assert, luai_numunm, luaK_exp2anyreg(), NO_JUMP, NULL, expdesc::nval, OP_LEN, OP_UNM, OPR_LEN, OPR_MINUS, OPR_NOT, expdesc::t, expdesc::u, and VKNUM.

◆ luaK_reserveregs()

void luaK_reserveregs ( FuncState * fs,
int n )

Definition at line 271 of file lua-5.2.4/src/lcode.c.

271 {
272 luaK_checkstack(fs, n);
273 fs->freereg += n;
274}
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 69 of file lua-5.2.4/src/lcode.c.

69 {
70 luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);
71}

References luaK_codeABC, and OP_RETURN.

◆ luaK_self()

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

Definition at line 585 of file lua-5.2.4/src/lcode.c.

585 {
586 int ereg;
587 luaK_exp2anyreg(fs, e);
588 ereg = e->u.info; /* register where 'e' was placed */
589 freeexp(fs, e);
590 e->u.info = fs->freereg; /* base register for op_self */
591 e->k = VNONRELOC;
592 luaK_reserveregs(fs, 2); /* function and 'self' produced by op_self */
593 luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key));
594 freeexp(fs, key);
595}

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

867 {
868 int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1;
869 int b = (tostore == LUA_MULTRET) ? 0 : tostore;
870 lua_assert(tostore != 0);
871 if (c <= MAXARG_C)
872 luaK_codeABC(fs, OP_SETLIST, base, b, c);
873 else if (c <= MAXARG_Ax) {
874 luaK_codeABC(fs, OP_SETLIST, base, b, 0);
875 codeextraarg(fs, c);
876 }
877 else
878 luaX_syntaxerror(fs->ls, "constructor too long");
879 fs->freereg = base + 1; /* free registers with list values */
880}
#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 371 of file lua-5.2.4/src/lcode.c.

371 {
372 if (e->k == VCALL) { /* expression is an open function call? */
373 e->k = VNONRELOC;
374 e->u.info = GETARG_A(getcode(fs, e));
375 }
376 else if (e->k == VVARARG) {
377 SETARG_B(getcode(fs, e), 2);
378 e->k = VRELOCABLE; /* can relocate its simple result */
379 }
380}

References GETARG_A, getcode, expdesc::info, expdesc::k, 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 359 of file lua-5.2.4/src/lcode.c.

359 {
360 if (e->k == VCALL) { /* expression is an open function call? */
361 SETARG_C(getcode(fs, e), nresults+1);
362 }
363 else if (e->k == VVARARG) {
364 SETARG_B(getcode(fs, e), nresults+1);
365 SETARG_A(getcode(fs, e), fs->freereg);
366 luaK_reserveregs(fs, 1);
367 }
368}
#define SETARG_C(i, b)

References FuncState::freereg, getcode, expdesc::k, 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 558 of file lua-5.2.4/src/lcode.c.

558 {
559 switch (var->k) {
560 case VLOCAL: {
561 freeexp(fs, ex);
562 exp2reg(fs, ex, var->u.info);
563 return;
564 }
565 case VUPVAL: {
566 int e = luaK_exp2anyreg(fs, ex);
567 luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);
568 break;
569 }
570 case VINDEXED: {
571 OpCode op = (var->u.ind.vt == VLOCAL) ? OP_SETTABLE : OP_SETTABUP;
572 int e = luaK_exp2RK(fs, ex);
573 luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e);
574 break;
575 }
576 default: {
577 lua_assert(0); /* invalid var kind to store */
578 break;
579 }
580 }
581 freeexp(fs, ex);
582}

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

319 {
320 TValue o;
321 setsvalue(fs->ls->L, &o, s);
322 return addk(fs, &o, &o);
323}
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 122 of file lua-5.2.4/src/lcode.c.

122 {
123 for (; list != NO_JUMP; list = getjump(fs, list)) {
124 Instruction i = *getjumpcontrol(fs, list);
125 if (GET_OPCODE(i) != OP_TESTSET) return 1;
126 }
127 return 0; /* not found */
128}

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

Referenced by exp2reg().

◆ nilK()

static int nilK ( FuncState * fs)
static

Definition at line 350 of file lua-5.2.4/src/lcode.c.

350 {
351 TValue k, v;
352 setnilvalue(&v);
353 /* cannot use nil as key; instead use table itself to represent nil */
354 sethvalue(fs->ls->L, &k, fs->h);
355 return addk(fs, &k, &v);
356}
#define sethvalue(L, obj, x)

References addk(), FuncState::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 150 of file lua-5.2.4/src/lcode.c.

151 {
152 while (list != NO_JUMP) {
153 int next = getjump(fs, list);
154 if (patchtestreg(fs, list, reg))
155 fixjump(fs, list, vtarget);
156 else
157 fixjump(fs, list, dtarget); /* jump to default target */
158 list = next;
159 }
160}
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 131 of file lua-5.2.4/src/lcode.c.

131 {
132 Instruction *i = getjumpcontrol(fs, node);
133 if (GET_OPCODE(*i) != OP_TESTSET)
134 return 0; /* cannot patch other instructions */
135 if (reg != NO_REG && reg != GETARG_B(*i))
136 SETARG_A(*i, reg);
137 else /* no register to put value or register already has the value */
138 *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));
139
140 return 1;
141}
#define GETARG_C(i)

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

144 {
145 for (; list != NO_JUMP; list = getjump(fs, list))
146 patchtestreg(fs, list, NO_REG);
147}

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

Referenced by codenot().