The Battle for Wesnoth  1.15.2+dev
Macros | Functions
lcode.cpp 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"
Include dependency graph for lcode.cpp:

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 lcode.cpp.

◆ LUA_CORE

#define LUA_CORE

Definition at line 8 of file lcode.cpp.

◆ MAXREGS

#define MAXREGS   255

Definition at line 33 of file lcode.cpp.

Referenced by luaK_checkstack().

Function Documentation

◆ addk()

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

◆ boolK()

static int boolK ( FuncState fs,
int  b 
)
static

Definition at line 491 of file lcode.cpp.

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 lcode.cpp.

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

◆ codecomp()

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

◆ codeextraarg()

static int codeextraarg ( FuncState fs,
int  a 
)
static

Definition at line 335 of file lcode.cpp.

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

◆ codeunexpval()

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

◆ condjump()

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

Definition at line 158 of file lcode.cpp.

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

◆ discharge2anyreg()

static void discharge2anyreg ( FuncState fs,
expdesc e 
)
static

Definition at line 641 of file lcode.cpp.

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

◆ dischargejpc()

static void dischargejpc ( FuncState fs)
static

Definition at line 242 of file lcode.cpp.

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

◆ fixjump()

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

◆ freeexp()

static void freeexp ( FuncState fs,
expdesc e 
)
static

◆ freeexps()

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

Definition at line 407 of file lcode.cpp.

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 lcode.cpp.

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 lcode.cpp.

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 lcode.cpp.

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

◆ luaK_checkstack()

void luaK_checkstack ( FuncState fs,
int  n 
)

◆ luaK_code()

static int luaK_code ( FuncState fs,
Instruction  i 
)
static

◆ luaK_codeABC()

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

◆ luaK_codeABx()

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

Definition at line 324 of file lcode.cpp.

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

Referenced by codeclosure(), and luaK_codek().

◆ luaK_codek()

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

Definition at line 346 of file lcode.cpp.

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

Referenced by discharge2reg(), and fornum().

◆ luaK_concat()

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

◆ luaK_dischargevars()

void luaK_dischargevars ( FuncState fs,
expdesc e 
)

◆ luaK_exp2anyreg()

int luaK_exp2anyreg ( FuncState fs,
expdesc e 
)

◆ luaK_exp2anyregup()

void luaK_exp2anyregup ( FuncState fs,
expdesc e 
)

Definition at line 734 of file lcode.cpp.

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

Referenced by fieldsel(), and suffixedexp().

◆ luaK_exp2nextreg()

void luaK_exp2nextreg ( FuncState fs,
expdesc e 
)

◆ luaK_exp2RK()

int luaK_exp2RK ( FuncState fs,
expdesc e 
)

◆ luaK_exp2val()

void luaK_exp2val ( FuncState fs,
expdesc e 
)

Definition at line 744 of file lcode.cpp.

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

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

◆ luaK_fixline()

void luaK_fixline ( FuncState fs,
int  line 
)

Definition at line 1177 of file lcode.cpp.

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

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

◆ luaK_getlabel()

int luaK_getlabel ( FuncState fs)

◆ luaK_goiffalse()

void luaK_goiffalse ( FuncState fs,
expdesc e 
)

◆ luaK_goiftrue()

void luaK_goiftrue ( FuncState fs,
expdesc e 
)

◆ luaK_indexed()

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

◆ luaK_infix()

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

◆ luaK_intK()

int luaK_intK ( FuncState fs,
lua_Integer  n 
)

Definition at line 471 of file lcode.cpp.

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

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

◆ luaK_jump()

int luaK_jump ( FuncState fs)

◆ luaK_nil()

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

◆ luaK_numberK()

static int luaK_numberK ( FuncState fs,
lua_Number  r 
)
static

Definition at line 481 of file lcode.cpp.

References addk(), and setfltvalue.

Referenced by discharge2reg(), and luaK_exp2RK().

◆ luaK_patchclose()

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

◆ luaK_patchlist()

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

Definition at line 263 of file lcode.cpp.

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

Referenced by closegoto(), forbody(), and repeatstat().

◆ luaK_patchtohere()

void luaK_patchtohere ( FuncState fs,
int  list 
)

◆ luaK_posfix()

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

◆ luaK_prefix()

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

Definition at line 1066 of file lcode.cpp.

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

Referenced by subexpr().

◆ luaK_reserveregs()

void luaK_reserveregs ( FuncState fs,
int  n 
)

◆ luaK_ret()

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

Definition at line 149 of file lcode.cpp.

References luaK_codeABC(), and OP_RETURN.

Referenced by close_func(), and retstat().

◆ luaK_self()

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

◆ luaK_setlist()

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

◆ luaK_setoneret()

void luaK_setoneret ( FuncState fs,
expdesc e 
)

◆ luaK_setreturns()

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

◆ luaK_storevar()

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

◆ luaK_stringK()

int luaK_stringK ( FuncState fs,
TString s 
)

Definition at line 458 of file lcode.cpp.

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

Referenced by codestring().

◆ need_value()

static int need_value ( FuncState fs,
int  list 
)
static

Definition at line 659 of file lcode.cpp.

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

Referenced by exp2reg().

◆ negatecondition()

static void negatecondition ( FuncState fs,
expdesc e 
)
static

◆ nilK()

static int nilK ( FuncState fs)
static

Definition at line 501 of file lcode.cpp.

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 lcode.cpp.

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 lcode.cpp.

References CREATE_ABC, GET_OPCODE, GETARG_B, GETARG_C, getjumpcontrol(), i, 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 lcode.cpp.

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 lcode.cpp.

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 lcode.cpp.

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

Referenced by constfolding().