# lua/lvm.c File Reference

`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include "lua.h"`
`#include "ldebug.h"`
`#include "ldo.h"`
`#include "lfunc.h"`
`#include "lgc.h"`
`#include "lobject.h"`
`#include "lopcodes.h"`
`#include "lstate.h"`
`#include "lstring.h"`
`#include "ltable.h"`
`#include "ltm.h"`
`#include "lvm.h"`

Include dependency graph for lvm.c:

Go to the source code of this file.

## Defines
#define | lvm_c
#define | LUA_CORE
#define | MAXTAGLOOP 100
#define | runtime_check(L, c) { if (!(c)) break; }
#define | RA(i) (base+GETARG_A(i))
#define | RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))
#define | RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))
#define | RKB(i)
#define | RKC(i)
#define | KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i))
#define | dojump(L, pc, i) {(pc) += (i); luai_threadyield(L);}
#define | Protect(x) { L->savedpc = pc; {x;}; base = L->base; }
#define | arith_op(op, tm)
## Functions
const TValue * | luaV_tonumber (const TValue *obj, TValue *n)
int | luaV_tostring (lua_State *L, StkId obj)
static void | traceexec (lua_State *L, const Instruction *pc)
static void | callTMres (lua_State *L, StkId res, const TValue *f, const TValue *p1, const TValue *p2)
static void | callTM (lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, const TValue *p3)
void | luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val)
void | luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val)
static int | call_binTM (lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event)
static const TValue * | get_compTM (lua_State *L, Table *mt1, Table *mt2, TMS event)
static int | call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, TMS event)
static int | l_strcmp (const TString *ls, const TString *rs)
int | luaV_lessthan (lua_State *L, const TValue *l, const TValue *r)
static int | lessequal (lua_State *L, const TValue *l, const TValue *r)
int | luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2)
void | luaV_concat (lua_State *L, int total, int last)
static void | Arith (lua_State *L, StkId ra, const TValue *rb, const TValue *rc, TMS op)
void | luaV_execute (lua_State *L, int nexeccalls)

## Define Documentation

#define arith_op | ( | op,
|  | tm |  | ) |

Value:

    { \
            TValue *rb = RKB(i); \
            TValue *rc = RKC(i); \
            if (ttisnumber(rb) && ttisnumber(rc)) { \
              lua_Number nb = nvalue(rb), nc = nvalue(rc); \
              setnvalue(ra, op(nb, nc)); \
            } \
            else \
              Protect(Arith(L, ra, rb, rc, tm)); \
          }

Definition at line 360 of file lvm.c.

Referenced by luaV_execute().

#define dojump | ( | L,
|  | pc,
|  | i |  | ) | {(pc) += (i); luai_threadyield(L);}

Definition at line 354 of file lvm.c.

Referenced by luaV_execute().

#define KBx | ( | i |  | ) | check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i))

Definition at line 351 of file lvm.c.

Referenced by luaV_execute().

#define LUA_CORE

Definition at line 13 of file lvm.c.

#define lvm_c

Definition at line 12 of file lvm.c.

#define MAXTAGLOOP 100

Definition at line 32 of file lvm.c.

Referenced by luaV_gettable(), and luaV_settable().

#define Protect | ( | x |  | ) | { L->savedpc = pc; {x;}; base = L->base; }

Definition at line 357 of file lvm.c.

Referenced by luaV_execute().

#define RA | ( | i |  | ) | (base+GETARG_A(i))

Definition at line 343 of file lvm.c.

Referenced by luaV_execute().

#define RB | ( | i |  | ) | check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))

Definition at line 345 of file lvm.c.

Referenced by luaV_execute().

#define RC | ( | i |  | ) | check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))

Definition at line 346 of file lvm.c.

#define RKB | ( | i |  | ) |

Value:

    check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \
            ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))

Definition at line 347 of file lvm.c.

Referenced by luaV_execute().

#define RKC | ( | i |  | ) |

Value:

    check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \
            ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))

Definition at line 349 of file lvm.c.

Referenced by luaV_execute().

#define runtime_check | ( | L,
|  | c |  | ) | { if (!(c)) break; }

Definition at line 341 of file lvm.c.

Referenced by luaV_execute().

## Function Documentation

static void Arith | ( | lua_State * | L,
|  | StkId | ra,
|  | const TValue * | rb,
|  | const TValue * | rc,
|  | TMS | op |
| ) |  |  | `[static]`

Definition at line 313 of file lvm.c.

References call_binTM(), lua_assert, luaG_aritherror(), luaV_tonumber(), nvalue, setnvalue, TM_ADD, TM_DIV, TM_MOD, TM_MUL, TM_POW, TM_SUB, and TM_UNM.

Referenced by luaV_execute().

static int call_binTM | ( | lua_State * | L,
|  | const TValue * | p1,
|  | const TValue * | p2,
|  | StkId | res,
|  | TMS | event |
| ) |  |  | `[static]`

Definition at line 161 of file lvm.c.

References callTMres(), luaT_gettmbyobj(), and ttisnil.

Referenced by Arith(), luaV_concat(), and luaV_execute().

static int call_orderTM | ( | lua_State * | L,
|  | const TValue * | p1,
|  | const TValue * | p2,
|  | TMS | event |
| ) |  |  | `[static]`

Definition at line 186 of file lvm.c.

References callTMres(), l_isfalse, luaO_rawequalObj(), luaT_gettmbyobj(), lua_State::top, and ttisnil.

Referenced by lessequal(), and luaV_lessthan().

static void callTM | ( | lua_State * | L,
|  | const TValue * | f,
|  | const TValue * | p1,
|  | const TValue * | p2,
|  | const TValue * | p3 |
| ) |  |  | `[static]`

Definition at line 96 of file lvm.c.

References luaD_call(), luaD_checkstack, setobj2s, and lua_State::top.

Referenced by luaV_settable().

static void callTMres | ( | lua_State * | L,
|  | StkId | res,
|  | const TValue * | f,
|  | const TValue * | p1,
|  | const TValue * | p2 |
| ) |  |  | `[static]`

Definition at line 80 of file lvm.c.

References luaD_call(), luaD_checkstack, restorestack, savestack, setobj2s, setobjs2s, and lua_State::top.

Referenced by call_binTM(), call_orderTM(), luaV_equalval(), and luaV_gettable().

static const TValue* get_compTM | ( | lua_State * | L,
|  | Table * | mt1,
|  | Table * | mt2,
|  | TMS | event |
| ) |  |  | `[static]`

Definition at line 172 of file lvm.c.

References fasttm, and luaO_rawequalObj().

Referenced by luaV_equalval().

static int l_strcmp | ( | const TString * | ls,
|  | const TString * | rs |
| ) |  |  | `[static]`

Definition at line 199 of file lvm.c.

References getstr, TString::len, and TString::tsv.

Referenced by lessequal(), and luaV_lessthan().

static int lessequal | ( | lua_State * | L,
|  | const TValue * | l,
|  | const TValue * | r |
| ) |  |  | `[static]`

Definition at line 235 of file lvm.c.

References call_orderTM(), l_strcmp(), luaG_ordererror(), nvalue, rawtsvalue, TM_LE, TM_LT, ttisnumber, ttisstring, and ttype.

Referenced by luaV_execute().

void luaV_concat | ( | lua_State * | L,
|  | int | total,
|  | int | last |
| ) |  |  |

Definition at line 278 of file lvm.c.

References lua_State::base, call_binTM(), G, luaG_concaterror(), luaG_runerror(), luaS_newlstr(), luaZ_openspace(), MAX_SIZET, setsvalue2s, svalue, TM_CONCAT, tostring, tsvalue, ttisnumber, and ttisstring.

Referenced by lua_concat(), luaO_pushvfstring(), and luaV_execute().

int luaV_equalval | ( | lua_State * | L,
|  | const TValue * | t1,
|  | const TValue * | t2 |
| ) |  |  |

Definition at line 251 of file lvm.c.

References bvalue, callTMres(), gcvalue, get_compTM(), hvalue, l_isfalse, lua_assert, nvalue, pvalue, TM_EQ, lua_State::top, ttype, and uvalue.

void luaV_execute | ( | lua_State * | L,
|  | int | nexeccalls |
| ) |  |  |

Definition at line 373 of file lvm.c.

References Arith(), arith_op, CallInfo::base, lua_State::base, call_binTM(), cast_int, cast_num, lua_State::ci, clvalue, dojump, LClosure::env, equalobj, CallInfo::func, GET_OPCODE, GETARG_A, GETARG_B, GETARG_Bx, GETARG_C, GETARG_sBx, lua_State::hookcount, lua_State::hookmask, hvalue, isLua, Proto::k, KBx, Closure::l, l_isfalse, lessequal(), LFIELDS_PER_FLUSH, lua_assert, luaC_barrier, luaC_barriert, luaC_checkGC, luaD_call(), luaD_checkstack, luaD_poscall(), luaD_precall(), luaF_close(), luaF_findupval(), luaF_newLclosure(), luaG_checkopenop(), luaG_runerror(), luaG_typeerror(), luaH_getn(), luaH_new(), luaH_resizearray(), luaH_setnum(), luaO_fb2int(), luaO_nilobject, luaV_concat(), luaV_gettable(), luaV_lessthan(), luaV_settable(), Proto::numparams, Proto::nups, nvalue, OP_ADD, OP_CALL, OP_CLOSE, OP_CLOSURE, OP_CONCAT, OP_DIV, OP_EQ, OP_FORLOOP, OP_FORPREP, OP_GETGLOBAL, OP_GETTABLE, OP_GETUPVAL, OP_JMP, OP_LE, OP_LEN, OP_LOADBOOL, OP_LOADK, OP_LOADNIL, OP_LT, OP_MOD, OP_MOVE, OP_MUL, OP_NEWTABLE, OP_NOT, OP_POW, OP_RETURN, OP_SELF, OP_SETGLOBAL, OP_SETLIST, OP_SETTABLE, OP_SETUPVAL, OP_SUB, OP_TAILCALL, OP_TEST, OP_TESTSET, OP_TFORLOOP, OP_UNM, OP_VARARG, lua_State::openupval, Proto::p, LClosure::p, PCRC, PCRLUA, Protect, RA, RB, RKB, RKC, runtime_check, CallInfo::savedpc, lua_State::savedpc, setbvalue, setclvalue, sethvalue, setnilvalue, setnvalue, setobj, setobj2s, setobj2t, setobjs2s, Table::sizearray, lua_State::stack, lua_State::stacksize, lua_State::status, CallInfo::tailcalls, TM_ADD, TM_DIV, TM_LEN, TM_MOD, TM_MUL, TM_POW, TM_SUB, TM_UNM, tonumber, CallInfo::top, lua_State::top, traceexec(), tsvalue, ttisnil, ttisnumber, ttisstring, ttistable, ttype, LClosure::upvals, and UpVal::v.

Referenced by luaD_call(), and resume().

void luaV_gettable | ( | lua_State * | L,
|  | const TValue * | t,
|  | TValue * | key,
|  | StkId | val |
| ) |  |  |

Definition at line 108 of file lvm.c.

References callTMres(), fasttm, hvalue, luaG_runerror(), luaG_typeerror(), luaH_get(), luaT_gettmbyobj(), MAXTAGLOOP, Table::metatable, setobj2s, TM_INDEX, ttisfunction, ttisnil, and ttistable.

Referenced by lua_getfield(), lua_gettable(), and luaV_execute().

int luaV_lessthan | ( | lua_State * | L,
|  | const TValue * | l,
|  | const TValue * | r |
| ) |  |  |

Definition at line 221 of file lvm.c.

References call_orderTM(), l_strcmp(), luaG_ordererror(), nvalue, rawtsvalue, TM_LT, ttisnumber, ttisstring, and ttype.

Referenced by lua_lessthan(), and luaV_execute().

void luaV_settable | ( | lua_State * | L,
|  | const TValue * | t,
|  | TValue * | key,
|  | StkId | val |
| ) |  |  |

Definition at line 134 of file lvm.c.

References callTM(), fasttm, hvalue, luaC_barriert, luaG_runerror(), luaG_typeerror(), luaH_set(), luaT_gettmbyobj(), MAXTAGLOOP, Table::metatable, setobj2t, TM_NEWINDEX, ttisfunction, ttisnil, and ttistable.

Referenced by lua_setfield(), lua_settable(), and luaV_execute().

const TValue* luaV_tonumber | ( | const TValue * | obj,
|  | TValue * | n |
| ) |  |  |

Definition at line 35 of file lvm.c.

References luaO_str2d(), setnvalue, svalue, ttisnumber, and ttisstring.

Referenced by Arith(), and luaG_aritherror().

int luaV_tostring | ( | lua_State * | L,
|  | StkId | obj |
| ) |  |  |

Definition at line 47 of file lvm.c.

References luaS_new, nvalue, setsvalue2s, and ttisnumber.

Referenced by lua_objlen(), and lua_tolstring().

static void traceexec | ( | lua_State * | L,
|  | const Instruction * | pc |
| ) |  |  | `[static]`

Definition at line 60 of file lvm.c.

References lua_State::ci, ci_func, getline, lua_State::hookcount, lua_State::hookmask, luaD_callhook(), pcRel, resethookcount, and lua_State::savedpc.

Referenced by luaV_execute().