1*eda14cbcSMatt Macy /* 2*eda14cbcSMatt Macy ** $Id: lcode.h,v 1.58.1.1 2013/04/12 18:48:47 roberto Exp $ 3*eda14cbcSMatt Macy ** Code generator for Lua 4*eda14cbcSMatt Macy ** See Copyright Notice in lua.h 5*eda14cbcSMatt Macy */ 6*eda14cbcSMatt Macy 7*eda14cbcSMatt Macy #ifndef lcode_h 8*eda14cbcSMatt Macy #define lcode_h 9*eda14cbcSMatt Macy 10*eda14cbcSMatt Macy #include "llex.h" 11*eda14cbcSMatt Macy #include "lobject.h" 12*eda14cbcSMatt Macy #include "lopcodes.h" 13*eda14cbcSMatt Macy #include "lparser.h" 14*eda14cbcSMatt Macy 15*eda14cbcSMatt Macy 16*eda14cbcSMatt Macy /* 17*eda14cbcSMatt Macy ** Marks the end of a patch list. It is an invalid value both as an absolute 18*eda14cbcSMatt Macy ** address, and as a list link (would link an element to itself). 19*eda14cbcSMatt Macy */ 20*eda14cbcSMatt Macy #define NO_JUMP (-1) 21*eda14cbcSMatt Macy 22*eda14cbcSMatt Macy 23*eda14cbcSMatt Macy /* 24*eda14cbcSMatt Macy ** grep "ORDER OPR" if you change these enums (ORDER OP) 25*eda14cbcSMatt Macy */ 26*eda14cbcSMatt Macy typedef enum BinOpr { 27*eda14cbcSMatt Macy OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, 28*eda14cbcSMatt Macy OPR_CONCAT, 29*eda14cbcSMatt Macy OPR_EQ, OPR_LT, OPR_LE, 30*eda14cbcSMatt Macy OPR_NE, OPR_GT, OPR_GE, 31*eda14cbcSMatt Macy OPR_AND, OPR_OR, 32*eda14cbcSMatt Macy OPR_NOBINOPR 33*eda14cbcSMatt Macy } BinOpr; 34*eda14cbcSMatt Macy 35*eda14cbcSMatt Macy 36*eda14cbcSMatt Macy typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 37*eda14cbcSMatt Macy 38*eda14cbcSMatt Macy 39*eda14cbcSMatt Macy #define getcode(fs,e) ((fs)->f->code[(e)->u.info]) 40*eda14cbcSMatt Macy 41*eda14cbcSMatt Macy #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 42*eda14cbcSMatt Macy 43*eda14cbcSMatt Macy #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 44*eda14cbcSMatt Macy 45*eda14cbcSMatt Macy #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) 46*eda14cbcSMatt Macy 47*eda14cbcSMatt Macy LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 48*eda14cbcSMatt Macy LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 49*eda14cbcSMatt Macy LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k); 50*eda14cbcSMatt Macy LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 51*eda14cbcSMatt Macy LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 52*eda14cbcSMatt Macy LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 53*eda14cbcSMatt Macy LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 54*eda14cbcSMatt Macy LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 55*eda14cbcSMatt Macy LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); 56*eda14cbcSMatt Macy LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 57*eda14cbcSMatt Macy LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 58*eda14cbcSMatt Macy LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 59*eda14cbcSMatt Macy LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 60*eda14cbcSMatt Macy LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 61*eda14cbcSMatt Macy LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 62*eda14cbcSMatt Macy LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 63*eda14cbcSMatt Macy LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 64*eda14cbcSMatt Macy LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 65*eda14cbcSMatt Macy LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); 66*eda14cbcSMatt Macy LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 67*eda14cbcSMatt Macy LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 68*eda14cbcSMatt Macy LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 69*eda14cbcSMatt Macy LUAI_FUNC int luaK_jump (FuncState *fs); 70*eda14cbcSMatt Macy LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 71*eda14cbcSMatt Macy LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 72*eda14cbcSMatt Macy LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 73*eda14cbcSMatt Macy LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level); 74*eda14cbcSMatt Macy LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 75*eda14cbcSMatt Macy LUAI_FUNC int luaK_getlabel (FuncState *fs); 76*eda14cbcSMatt Macy LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); 77*eda14cbcSMatt Macy LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 78*eda14cbcSMatt Macy LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, 79*eda14cbcSMatt Macy expdesc *v2, int line); 80*eda14cbcSMatt Macy LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 81*eda14cbcSMatt Macy 82*eda14cbcSMatt Macy 83*eda14cbcSMatt Macy #endif 84