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 "ltable.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)
 
void luaK_patchtohere (FuncState *fs, int list)
 
void luaK_concat (FuncState *fs, int *l1, int l2)
 
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 *k, 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_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)
 
static 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)
 
static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, expdesc *e2)
 
void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e)
 
void luaK_infix (FuncState *fs, BinOpr op, expdesc *v)
 
void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2)
 
void luaK_fixline (FuncState *fs, int line)
 
static int luaK_code (FuncState *fs, Instruction i, int line)
 
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)
 
void luaK_setlist (FuncState *fs, int base, int nelems, int tostore)
 

Macro Definition Documentation

◆ hasjumps

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

Definition at line 27 of file lua-5.1.5/src/lcode.c.

Referenced by exp2reg(), luaK_exp2anyreg(), and luaK_exp2val().

◆ lcode_c

#define lcode_c

Definition at line 10 of file lua-5.1.5/src/lcode.c.

◆ LUA_CORE

#define LUA_CORE

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

Function Documentation

◆ addk()

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

Definition at line 229 of file lua-5.1.5/src/lcode.c.

229 {
230 lua_State *L = fs->L;
231 TValue *idx = luaH_set(L, fs->h, k);
232 Proto *f = fs->f;
233 int oldsize = f->sizek;
234 if (ttisnumber(idx)) {
235 lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v));
236 return cast_int(nvalue(idx));
237 }
238 else { /* constant not found; create a new entry */
239 setnvalue(idx, cast_num(fs->nk));
240 luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
241 MAXARG_Bx, "constant table overflow");
242 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
243 setobj(L, &f->k[fs->nk], v);
244 luaC_barrier(L, f, v);
245 return fs->nk++;
246 }
247}
#define luaC_barrier(L, p, v)
#define cast_int(i)
#define lua_assert(c)
#define cast_num(i)
#define luaM_growvector(L, v, nelems, size, t, limit, e)
int luaO_rawequalObj(const TValue *t1, const TValue *t2)
#define nvalue(o)
#define setnvalue(obj, x)
#define ttisnumber(o)
#define setobj(L, obj1, obj2)
#define setnilvalue(obj)
#define MAXARG_Bx
TValue * luaH_set(lua_State *L, Table *t, const TValue *key)
struct lua_State * L

References cast_int, cast_num, FuncState::f, FuncState::h, Proto::k, FuncState::L, lua_assert, luaC_barrier, luaH_set(), luaM_growvector, luaO_rawequalObj(), MAXARG_Bx, 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 264 of file lua-5.1.5/src/lcode.c.

264 {
265 TValue o;
266 setbvalue(&o, b);
267 return addk(fs, &o, &o);
268}
static int addk(FuncState *fs, TValue *k, TValue *v)
#define setbvalue(obj, x)

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

337 {
338 luaK_getlabel(fs); /* those instructions may be jump targets */
339 return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);
340}
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 )
static

Definition at line 653 of file lua-5.1.5/src/lcode.c.

653 {
654 if (constfolding(op, e1, e2))
655 return;
656 else {
657 int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
658 int o1 = luaK_exp2RK(fs, e1);
659 if (o1 > o2) {
660 freeexp(fs, e1);
661 freeexp(fs, e2);
662 }
663 else {
664 freeexp(fs, e2);
665 freeexp(fs, e1);
666 }
667 e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
668 e1->k = VRELOCABLE;
669 }
670}
int luaK_exp2RK(FuncState *fs, expdesc *e)
static void freeexp(FuncState *fs, expdesc *e)
static int constfolding(OpCode op, expdesc *e1, expdesc *e2)
struct expdesc::@52::@53 s
union expdesc::@52 u

References constfolding(), freeexp(), expdesc::info, expdesc::k, luaK_codeABC, luaK_exp2RK(), OP_LEN, OP_UNM, expdesc::s, 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 673 of file lua-5.1.5/src/lcode.c.

674 {
675 int o1 = luaK_exp2RK(fs, e1);
676 int o2 = luaK_exp2RK(fs, e2);
677 freeexp(fs, e2);
678 freeexp(fs, e1);
679 if (cond == 0 && op != OP_EQ) {
680 int temp; /* exchange args to replace by `<' or `<=' */
681 temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */
682 cond = 1;
683 }
684 e1->u.s.info = condjump(fs, op, cond, o1, o2);
685 e1->k = VJMP;
686}
static int condjump(FuncState *fs, OpCode op, int A, int B, int C)
static int cond(LexState *ls)

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

Referenced by luaK_posfix().

◆ codenot()

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

Definition at line 586 of file lua-5.1.5/src/lcode.c.

586 {
587 luaK_dischargevars(fs, e);
588 switch (e->k) {
589 case VNIL: case VFALSE: {
590 e->k = VTRUE;
591 break;
592 }
593 case VK: case VKNUM: case VTRUE: {
594 e->k = VFALSE;
595 break;
596 }
597 case VJMP: {
598 invertjump(fs, e);
599 break;
600 }
601 case VRELOCABLE:
602 case VNONRELOC: {
603 discharge2anyreg(fs, e);
604 freeexp(fs, e);
605 e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0);
606 e->k = VRELOCABLE;
607 break;
608 }
609 default: {
610 lua_assert(0); /* cannot happen */
611 break;
612 }
613 }
614 /* interchange true and false lists */
615 { int temp = e->f; e->f = e->t; e->t = temp; }
616 removevalues(fs, e->f);
617 removevalues(fs, e->t);
618}
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::s, 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.1.5/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 627 of file lua-5.1.5/src/lcode.c.

627 {
628 lua_Number v1, v2, r;
629 if (!isnumeral(e1) || !isnumeral(e2)) return 0;
630 v1 = e1->u.nval;
631 v2 = e2->u.nval;
632 switch (op) {
633 case OP_ADD: r = luai_numadd(v1, v2); break;
634 case OP_SUB: r = luai_numsub(v1, v2); break;
635 case OP_MUL: r = luai_nummul(v1, v2); break;
636 case OP_DIV:
637 if (v2 == 0) return 0; /* do not attempt to divide by 0 */
638 r = luai_numdiv(v1, v2); break;
639 case OP_MOD:
640 if (v2 == 0) return 0; /* do not attempt to divide by 0 */
641 r = luai_nummod(v1, v2); break;
642 case OP_POW: r = luai_numpow(v1, v2); break;
643 case OP_UNM: r = luai_numunm(v1); break;
644 case OP_LEN: return 0; /* no constant folding for 'len' */
645 default: lua_assert(0); r = 0; break;
646 }
647 if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */
648 e1->u.nval = r;
649 return 1;
650}
static int isnumeral(expdesc *e)
LUA_NUMBER lua_Number
#define luai_nummul(L, a, b)
#define luai_numdiv(L, a, b)
#define luai_numpow(L, a, b)
#define luai_numisnan(a)
#define luai_numunm(L, a)
#define luai_numsub(L, a, b)
#define luai_nummod(L, a, b, m)
#define luai_numadd(L, a, b)
lua_Number nval

References isnumeral(), lua_assert, luai_numadd, luai_numdiv, luai_numisnan, luai_nummod, luai_nummul, luai_numpow, luai_numsub, luai_numunm, expdesc::nval, OP_ADD, OP_DIV, OP_LEN, OP_MOD, OP_MUL, OP_POW, OP_SUB, OP_UNM, and expdesc::u.

Referenced by codearith().

◆ discharge2anyreg()

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

Definition at line 382 of file lua-5.1.5/src/lcode.c.

382 {
383 if (e->k != VNONRELOC) {
384 luaK_reserveregs(fs, 1);
385 discharge2reg(fs, e, fs->freereg-1);
386 }
387}
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 343 of file lua-5.1.5/src/lcode.c.

343 {
344 luaK_dischargevars(fs, e);
345 switch (e->k) {
346 case VNIL: {
347 luaK_nil(fs, reg, 1);
348 break;
349 }
350 case VFALSE: case VTRUE: {
351 luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);
352 break;
353 }
354 case VK: {
355 luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info);
356 break;
357 }
358 case VKNUM: {
359 luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval));
360 break;
361 }
362 case VRELOCABLE: {
363 Instruction *pc = &getcode(fs, e);
364 SETARG_A(*pc, reg);
365 break;
366 }
367 case VNONRELOC: {
368 if (reg != e->u.s.info)
369 luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0);
370 break;
371 }
372 default: {
373 lua_assert(e->k == VVOID || e->k == VJMP);
374 return; /* nothing to do... */
375 }
376 }
377 e->u.s.info = reg;
378 e->k = VNONRELOC;
379}
int luaK_numberK(FuncState *fs, lua_Number r)
int luaK_codeABx(FuncState *fs, OpCode o, int a, unsigned int bc)
void luaK_nil(FuncState *fs, int from, int n)
#define getcode(fs, e)
lu_int32 Instruction
#define SETARG_A(i, u)

References getcode, expdesc::info, expdesc::k, lua_assert, luaK_codeABC, luaK_codeABx(), luaK_dischargevars(), luaK_nil(), luaK_numberK(), expdesc::nval, OP_LOADBOOL, OP_LOADK, OP_MOVE, expdesc::s, 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.1.5/src/lcode.c.

163 {
164 patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);
165 fs->jpc = NO_JUMP;
166}
static void patchlistaux(FuncState *fs, int list, int vtarget, int reg, int dtarget)
#define NO_JUMP
#define NO_REG

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

390 {
391 discharge2reg(fs, e, reg);
392 if (e->k == VJMP)
393 luaK_concat(fs, &e->t, e->u.s.info); /* put this jump in `t' list */
394 if (hasjumps(e)) {
395 int final; /* position after whole expression */
396 int p_f = NO_JUMP; /* position of an eventual LOAD false */
397 int p_t = NO_JUMP; /* position of an eventual LOAD true */
398 if (need_value(fs, e->t) || need_value(fs, e->f)) {
399 int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);
400 p_f = code_label(fs, reg, 0, 1);
401 p_t = code_label(fs, reg, 1, 0);
402 luaK_patchtohere(fs, fj);
403 }
404 final = luaK_getlabel(fs);
405 patchlistaux(fs, e->f, final, reg, p_f);
406 patchlistaux(fs, e->t, final, reg, p_t);
407 }
408 e->f = e->t = NO_JUMP;
409 e->u.s.info = reg;
410 e->k = VNONRELOC;
411}
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::s, 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.1.5/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)
struct LexState * ls
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 223 of file lua-5.1.5/src/lcode.c.

223 {
224 if (e->k == VNONRELOC)
225 freereg(fs, e->u.s.info);
226}
static void freereg(FuncState *fs, int reg)

References freereg(), expdesc::info, expdesc::k, expdesc::s, 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 215 of file lua-5.1.5/src/lcode.c.

215 {
216 if (!ISK(reg) && reg >= fs->nactvar) {
217 fs->freereg--;
218 lua_assert(reg == fs->freereg);
219 }
220}
#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.1.5/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(), need_value(), patchlistaux(), and removevalues().

◆ getjumpcontrol()

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

Definition at line 109 of file lua-5.1.5/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 516 of file lua-5.1.5/src/lcode.c.

516 {
517 Instruction *pc = getjumpcontrol(fs, e->u.s.info);
519 GET_OPCODE(*pc) != OP_TEST);
520 SETARG_A(*pc, !(GETARG_A(*pc)));
521}
static Instruction * getjumpcontrol(FuncState *fs, int pc)
#define GETARG_A(i)

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

Referenced by codenot(), and luaK_goiftrue().

◆ isnumeral()

static int isnumeral ( expdesc * e)
static

Definition at line 30 of file lua-5.1.5/src/lcode.c.

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

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

524 {
525 if (e->k == VRELOCABLE) {
526 Instruction ie = getcode(fs, e);
527 if (GET_OPCODE(ie) == OP_NOT) {
528 fs->pc--; /* remove previous OP_NOT */
529 return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);
530 }
531 /* else go through */
532 }
533 discharge2anyreg(fs, e);
534 freeexp(fs, e);
535 return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond);
536}
#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::s, expdesc::u, and VRELOCABLE.

Referenced by luaK_goiffalse(), and luaK_goiftrue().

◆ luaK_checkstack()

void luaK_checkstack ( FuncState * fs,
int n )

Definition at line 199 of file lua-5.1.5/src/lcode.c.

199 {
200 int newstack = fs->freereg + n;
201 if (newstack > fs->f->maxstacksize) {
202 if (newstack >= MAXSTACK)
203 luaX_syntaxerror(fs->ls, "function or expression too complex");
204 fs->f->maxstacksize = cast_byte(newstack);
205 }
206}
#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 forlist(), forlist(), forlist(), forlist(), and luaK_reserveregs().

◆ luaK_code()

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

Definition at line 789 of file lua-5.1.5/src/lcode.c.

789 {
790 Proto *f = fs->f;
791 dischargejpc(fs); /* `pc' will change */
792 /* put new instruction in code array */
793 luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction,
794 MAX_INT, "code size overflow");
795 f->code[fs->pc] = i;
796 /* save corresponding line information */
797 luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
798 MAX_INT, "code size overflow");
799 f->lineinfo[fs->pc] = line;
800 return fs->pc++;
801}
static void dischargejpc(FuncState *fs)
#define MAX_INT

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

Referenced by constructor(), luaK_codeABC(), luaK_codeABx(), and luaK_setlist().

◆ luaK_codeABC()

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

Definition at line 804 of file lua-5.1.5/src/lcode.c.

804 {
806 lua_assert(getBMode(o) != OpArgN || b == 0);
807 lua_assert(getCMode(o) != OpArgN || c == 0);
808 return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline);
809}
static int luaK_code(FuncState *fs, Instruction i, int line)
#define CREATE_ABC(o, a, b, c)
#define getCMode(m)
#define getBMode(m)
#define getOpMode(m)

References CREATE_ABC, getBMode, getCMode, getOpMode, iABC, LexState::lastline, FuncState::ls, lua_assert, luaK_code(), and OpArgN.

◆ luaK_codeABx()

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

◆ luaK_concat()

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

Definition at line 185 of file lua-5.1.5/src/lcode.c.

185 {
186 if (l2 == NO_JUMP) return;
187 else if (*l1 == NO_JUMP)
188 *l1 = l2;
189 else {
190 int list = *l1;
191 int next;
192 while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */
193 list = next;
194 fixjump(fs, list, l2);
195 }
196}
static void fixjump(FuncState *fs, int pc, int dest)
static int getjump(FuncState *fs, int pc)
#define next(ls)

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

Referenced by breakstat(), exp2reg(), ifstat(), luaK_goiffalse(), luaK_goiftrue(), luaK_jump(), luaK_patchtohere(), luaK_posfix(), test_then_block(), test_then_block(), and test_then_block().

◆ luaK_dischargevars()

void luaK_dischargevars ( FuncState * fs,
expdesc * e )

Definition at line 304 of file lua-5.1.5/src/lcode.c.

304 {
305 switch (e->k) {
306 case VLOCAL: {
307 e->k = VNONRELOC;
308 break;
309 }
310 case VUPVAL: {
311 e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0);
312 e->k = VRELOCABLE;
313 break;
314 }
315 case VGLOBAL: {
316 e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info);
317 e->k = VRELOCABLE;
318 break;
319 }
320 case VINDEXED: {
321 freereg(fs, e->u.s.aux);
322 freereg(fs, e->u.s.info);
323 e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux);
324 e->k = VRELOCABLE;
325 break;
326 }
327 case VVARARG:
328 case VCALL: {
329 luaK_setoneret(fs, e);
330 break;
331 }
332 default: break; /* there is one value available (somewhere) */
333 }
334}
void luaK_setoneret(FuncState *fs, expdesc *e)

References expdesc::aux, freereg(), expdesc::info, expdesc::k, luaK_codeABC, luaK_codeABx(), luaK_setoneret(), OP_GETGLOBAL, OP_GETTABLE, OP_GETUPVAL, expdesc::s, expdesc::u, VCALL, VGLOBAL, VINDEXED, VLOCAL, VNONRELOC, VRELOCABLE, VUPVAL, and VVARARG.

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

◆ luaK_exp2anyreg()

int luaK_exp2anyreg ( FuncState * fs,
expdesc * e )

Definition at line 422 of file lua-5.1.5/src/lcode.c.

422 {
423 luaK_dischargevars(fs, e);
424 if (e->k == VNONRELOC) {
425 if (!hasjumps(e)) return e->u.s.info; /* exp is already in a register */
426 if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */
427 exp2reg(fs, e, e->u.s.info); /* put value on it */
428 return e->u.s.info;
429 }
430 }
431 luaK_exp2nextreg(fs, e); /* default */
432 return e->u.s.info;
433}
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::s, expdesc::u, and VNONRELOC.

Referenced by field(), luaK_exp2RK(), luaK_exp2val(), luaK_prefix(), luaK_self(), luaK_storevar(), primaryexp(), retstat(), retstat(), retstat(), and retstat().

◆ luaK_exp2nextreg()

◆ luaK_exp2RK()

int luaK_exp2RK ( FuncState * fs,
expdesc * e )

Definition at line 444 of file lua-5.1.5/src/lcode.c.

444 {
445 luaK_exp2val(fs, e);
446 switch (e->k) {
447 case VKNUM:
448 case VTRUE:
449 case VFALSE:
450 case VNIL: {
451 if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */
452 e->u.s.info = (e->k == VNIL) ? nilK(fs) :
453 (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) :
454 boolK(fs, (e->k == VTRUE));
455 e->k = VK;
456 return RKASK(e->u.s.info);
457 }
458 else break;
459 }
460 case VK: {
461 if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */
462 return RKASK(e->u.s.info);
463 else break;
464 }
465 default: break;
466 }
467 /* not a constant in the right range: put it in a register */
468 return luaK_exp2anyreg(fs, e);
469}
void luaK_exp2val(FuncState *fs, expdesc *e)
static int nilK(FuncState *fs)
int luaK_exp2anyreg(FuncState *fs, expdesc *e)
static int boolK(FuncState *fs, int b)
#define RKASK(x)
#define MAXINDEXRK

References boolK(), expdesc::info, expdesc::k, luaK_exp2anyreg(), luaK_exp2val(), luaK_numberK(), MAXINDEXRK, nilK(), FuncState::nk, expdesc::nval, RKASK, expdesc::s, expdesc::u, VFALSE, VK, VKNUM, VNIL, and VTRUE.

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

◆ luaK_exp2val()

void luaK_exp2val ( FuncState * fs,
expdesc * e )

Definition at line 436 of file lua-5.1.5/src/lcode.c.

436 {
437 if (hasjumps(e))
438 luaK_exp2anyreg(fs, e);
439 else
440 luaK_dischargevars(fs, e);
441}

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

Referenced by luaK_exp2RK(), luaK_posfix(), yindex(), yindex(), yindex(), and yindex().

◆ luaK_fixline()

void luaK_fixline ( FuncState * fs,
int line )

Definition at line 784 of file lua-5.1.5/src/lcode.c.

784 {
785 fs->f->lineinfo[fs->pc - 1] = line;
786}

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

Referenced by forbody(), forbody(), forbody(), forbody(), funcargs(), funcargs(), funcargs(), funcargs(), funcstat(), funcstat(), funcstat(), and funcstat().

◆ luaK_getlabel()

◆ luaK_goiffalse()

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

Definition at line 563 of file lua-5.1.5/src/lcode.c.

563 {
564 int pc; /* pc of last jump */
565 luaK_dischargevars(fs, e);
566 switch (e->k) {
567 case VNIL: case VFALSE: {
568 pc = NO_JUMP; /* always false; do nothing */
569 break;
570 }
571 case VJMP: {
572 pc = e->u.s.info;
573 break;
574 }
575 default: {
576 pc = jumponcond(fs, e, 1);
577 break;
578 }
579 }
580 luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */
581 luaK_patchtohere(fs, e->f);
582 e->f = NO_JUMP;
583}
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::s, expdesc::t, expdesc::u, VFALSE, VJMP, and VNIL.

Referenced by luaK_infix(), test_then_block(), test_then_block(), and test_then_block().

◆ luaK_goiftrue()

void luaK_goiftrue ( FuncState * fs,
expdesc * e )

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

539 {
540 int pc; /* pc of last jump */
541 luaK_dischargevars(fs, e);
542 switch (e->k) {
543 case VK: case VKNUM: case VTRUE: {
544 pc = NO_JUMP; /* always true; do nothing */
545 break;
546 }
547 case VJMP: {
548 invertjump(fs, e);
549 pc = e->u.s.info;
550 break;
551 }
552 default: {
553 pc = jumponcond(fs, e, 0);
554 break;
555 }
556 }
557 luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */
558 luaK_patchtohere(fs, e->t);
559 e->t = NO_JUMP;
560}

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

Referenced by cond(), cond(), cond(), cond(), luaK_infix(), test_then_block(), test_then_block(), and test_then_block().

◆ luaK_indexed()

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

◆ luaK_infix()

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

Definition at line 710 of file lua-5.1.5/src/lcode.c.

710 {
711 switch (op) {
712 case OPR_AND: {
713 luaK_goiftrue(fs, v);
714 break;
715 }
716 case OPR_OR: {
717 luaK_goiffalse(fs, v);
718 break;
719 }
720 case OPR_CONCAT: {
721 luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
722 break;
723 }
724 case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
725 case OPR_MOD: case OPR_POW: {
726 if (!isnumeral(v)) luaK_exp2RK(fs, v);
727 break;
728 }
729 default: {
730 luaK_exp2RK(fs, v);
731 break;
732 }
733 }
734}
static void luaK_goiffalse(FuncState *fs, expdesc *e)
void luaK_goiftrue(FuncState *fs, expdesc *e)
@ OPR_CONCAT

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.

Referenced by subexpr(), subexpr(), subexpr(), and subexpr().

◆ luaK_jump()

int luaK_jump ( FuncState * fs)

Definition at line 59 of file lua-5.1.5/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 breakstat(), breakstat(), condjump(), exp2reg(), forbody(), forbody(), forbody(), gotostat(), ifstat(), leaveblock(), leaveblock(), repeatstat(), repeatstat(), statement(), statement(), test_then_block(), test_then_block(), test_then_block(), and whilestat().

◆ luaK_nil()

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

Definition at line 35 of file lua-5.1.5/src/lcode.c.

35 {
36 Instruction *previous;
37 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
38 if (fs->pc == 0) { /* function start? */
39 if (from >= fs->nactvar)
40 return; /* positions are already clean */
41 }
42 else {
43 previous = &fs->f->code[fs->pc-1];
44 if (GET_OPCODE(*previous) == OP_LOADNIL) {
45 int pfrom = GETARG_A(*previous);
46 int pto = GETARG_B(*previous);
47 if (pfrom <= from && from <= pto+1) { /* can connect both? */
48 if (from+n-1 > pto)
49 SETARG_B(*previous, from+n-1);
50 return;
51 }
52 }
53 }
54 }
55 luaK_codeABC(fs, OP_LOADNIL, from, 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, FuncState::nactvar, OP_LOADNIL, FuncState::pc, and SETARG_B.

Referenced by adjust_assign(), adjust_assign(), adjust_assign(), adjust_assign(), and discharge2reg().

◆ luaK_numberK()

int luaK_numberK ( FuncState * fs,
lua_Number r )

Definition at line 257 of file lua-5.1.5/src/lcode.c.

257 {
258 TValue o;
259 setnvalue(&o, r);
260 return addk(fs, &o, &o);
261}

References addk(), and setnvalue.

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

◆ luaK_patchlist()

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

Definition at line 169 of file lua-5.1.5/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.

Referenced by closegoto(), closegoto(), forbody(), forbody(), forbody(), gotostat(), repeatstat(), repeatstat(), repeatstat(), repeatstat(), solvegoto(), and whilestat().

◆ luaK_patchtohere()

◆ luaK_posfix()

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

Definition at line 737 of file lua-5.1.5/src/lcode.c.

737 {
738 switch (op) {
739 case OPR_AND: {
740 lua_assert(e1->t == NO_JUMP); /* list must be closed */
741 luaK_dischargevars(fs, e2);
742 luaK_concat(fs, &e2->f, e1->f);
743 *e1 = *e2;
744 break;
745 }
746 case OPR_OR: {
747 lua_assert(e1->f == NO_JUMP); /* list must be closed */
748 luaK_dischargevars(fs, e2);
749 luaK_concat(fs, &e2->t, e1->t);
750 *e1 = *e2;
751 break;
752 }
753 case OPR_CONCAT: {
754 luaK_exp2val(fs, e2);
755 if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {
756 lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1);
757 freeexp(fs, e1);
758 SETARG_B(getcode(fs, e2), e1->u.s.info);
759 e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info;
760 }
761 else {
762 luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */
763 codearith(fs, OP_CONCAT, e1, e2);
764 }
765 break;
766 }
767 case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break;
768 case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break;
769 case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break;
770 case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break;
771 case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break;
772 case OPR_POW: codearith(fs, OP_POW, e1, e2); break;
773 case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break;
774 case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break;
775 case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break;
776 case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break;
777 case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break;
778 case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break;
779 default: lua_assert(0);
780 }
781}
static void codecomp(FuncState *fs, OpCode op, int cond, expdesc *e1, expdesc *e2)
static void codearith(FuncState *fs, OpCode op, expdesc *e1, expdesc *e2)

References 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_DIV, OP_EQ, OP_LE, OP_LT, OP_MOD, OP_MUL, OP_POW, OP_SUB, 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, expdesc::s, SETARG_B, expdesc::t, expdesc::u, and VRELOCABLE.

Referenced by subexpr(), subexpr(), subexpr(), and subexpr().

◆ luaK_prefix()

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

Definition at line 689 of file lua-5.1.5/src/lcode.c.

689 {
690 expdesc e2;
691 e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
692 switch (op) {
693 case OPR_MINUS: {
694 if (!isnumeral(e))
695 luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */
696 codearith(fs, OP_UNM, e, &e2);
697 break;
698 }
699 case OPR_NOT: codenot(fs, e); break;
700 case OPR_LEN: {
701 luaK_exp2anyreg(fs, e); /* cannot operate on constants */
702 codearith(fs, OP_LEN, e, &e2);
703 break;
704 }
705 default: lua_assert(0);
706 }
707}
static void codenot(FuncState *fs, expdesc *e)
@ OPR_MINUS

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

Referenced by subexpr(), subexpr(), subexpr(), and subexpr().

◆ luaK_reserveregs()

◆ luaK_ret()

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

Definition at line 69 of file lua-5.1.5/src/lcode.c.

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

References luaK_codeABC, and OP_RETURN.

Referenced by close_func(), close_func(), close_func(), close_func(), retstat(), retstat(), retstat(), and retstat().

◆ luaK_self()

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

Definition at line 503 of file lua-5.1.5/src/lcode.c.

503 {
504 int func;
505 luaK_exp2anyreg(fs, e);
506 freeexp(fs, e);
507 func = fs->freereg;
508 luaK_reserveregs(fs, 2);
509 luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key));
510 freeexp(fs, key);
511 e->u.s.info = func;
512 e->k = VNONRELOC;
513}

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

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

◆ luaK_setlist()

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

Definition at line 819 of file lua-5.1.5/src/lcode.c.

819 {
820 int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1;
821 int b = (tostore == LUA_MULTRET) ? 0 : tostore;
822 lua_assert(tostore != 0);
823 if (c <= MAXARG_C)
824 luaK_codeABC(fs, OP_SETLIST, base, b, c);
825 else {
826 luaK_codeABC(fs, OP_SETLIST, base, b, 0);
827 luaK_code(fs, cast(Instruction, c), fs->ls->lastline);
828 }
829 fs->freereg = base + 1; /* free registers with list values */
830}
#define cast(t, exp)
#define LFIELDS_PER_FLUSH
#define MAXARG_C
#define LUA_MULTRET

References cast, FuncState::freereg, LexState::lastline, LFIELDS_PER_FLUSH, FuncState::ls, lua_assert, LUA_MULTRET, luaK_code(), luaK_codeABC, MAXARG_C, and OP_SETLIST.

Referenced by closelistfield(), closelistfield(), closelistfield(), closelistfield(), lastlistfield(), lastlistfield(), lastlistfield(), and lastlistfield().

◆ luaK_setoneret()

void luaK_setoneret ( FuncState * fs,
expdesc * e )

Definition at line 292 of file lua-5.1.5/src/lcode.c.

292 {
293 if (e->k == VCALL) { /* expression is an open function call? */
294 e->k = VNONRELOC;
295 e->u.s.info = GETARG_A(getcode(fs, e));
296 }
297 else if (e->k == VVARARG) {
298 SETARG_B(getcode(fs, e), 2);
299 e->k = VRELOCABLE; /* can relocate its simple result */
300 }
301}

References GETARG_A, getcode, expdesc::info, expdesc::k, expdesc::s, SETARG_B, expdesc::u, VCALL, VNONRELOC, VRELOCABLE, and VVARARG.

Referenced by assignment(), assignment(), assignment(), luaK_dischargevars(), and restassign().

◆ luaK_setreturns()

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

Definition at line 280 of file lua-5.1.5/src/lcode.c.

280 {
281 if (e->k == VCALL) { /* expression is an open function call? */
282 SETARG_C(getcode(fs, e), nresults+1);
283 }
284 else if (e->k == VVARARG) {
285 SETARG_B(getcode(fs, e), nresults+1);
286 SETARG_A(getcode(fs, e), fs->freereg);
287 luaK_reserveregs(fs, 1);
288 }
289}
#define SETARG_C(i, b)

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

Referenced by adjust_assign(), adjust_assign(), adjust_assign(), and adjust_assign().

◆ luaK_storevar()

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

Definition at line 472 of file lua-5.1.5/src/lcode.c.

472 {
473 switch (var->k) {
474 case VLOCAL: {
475 freeexp(fs, ex);
476 exp2reg(fs, ex, var->u.s.info);
477 return;
478 }
479 case VUPVAL: {
480 int e = luaK_exp2anyreg(fs, ex);
481 luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0);
482 break;
483 }
484 case VGLOBAL: {
485 int e = luaK_exp2anyreg(fs, ex);
486 luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info);
487 break;
488 }
489 case VINDEXED: {
490 int e = luaK_exp2RK(fs, ex);
491 luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e);
492 break;
493 }
494 default: {
495 lua_assert(0); /* invalid var kind to store */
496 break;
497 }
498 }
499 freeexp(fs, ex);
500}

References expdesc::aux, exp2reg(), freeexp(), expdesc::info, expdesc::k, lua_assert, luaK_codeABC, luaK_codeABx(), luaK_exp2anyreg(), luaK_exp2RK(), OP_SETGLOBAL, OP_SETTABLE, OP_SETUPVAL, expdesc::s, expdesc::u, VGLOBAL, VINDEXED, VLOCAL, and VUPVAL.

Referenced by assignment(), assignment(), assignment(), funcstat(), funcstat(), funcstat(), funcstat(), localfunc(), recfield(), and restassign().

◆ luaK_stringK()

int luaK_stringK ( FuncState * fs,
TString * s )

Definition at line 250 of file lua-5.1.5/src/lcode.c.

250 {
251 TValue o;
252 setsvalue(fs->L, &o, s);
253 return addk(fs, &o, &o);
254}
#define setsvalue(L, obj, x)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

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

Referenced by codestring(), codestring(), codestring(), and singlevar().

◆ need_value()

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

Definition at line 122 of file lua-5.1.5/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 271 of file lua-5.1.5/src/lcode.c.

271 {
272 TValue k, v;
273 setnilvalue(&v);
274 /* cannot use nil as key; instead use table itself to represent nil */
275 sethvalue(fs->L, &k, fs->h);
276 return addk(fs, &k, &v);
277}
#define sethvalue(L, obj, x)

References addk(), FuncState::h, FuncState::L, 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.1.5/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.1.5/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.1.5/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().