18e3e3a7aSWarner Losh /* 2*e112e9d2SKyle Evans ** $Id: lcode.h,v 1.64.1.1 2017/04/19 17:20:42 roberto Exp $ 38e3e3a7aSWarner Losh ** Code generator for Lua 48e3e3a7aSWarner Losh ** See Copyright Notice in lua.h 58e3e3a7aSWarner Losh */ 68e3e3a7aSWarner Losh 78e3e3a7aSWarner Losh #ifndef lcode_h 88e3e3a7aSWarner Losh #define lcode_h 98e3e3a7aSWarner Losh 108e3e3a7aSWarner Losh #include "llex.h" 118e3e3a7aSWarner Losh #include "lobject.h" 128e3e3a7aSWarner Losh #include "lopcodes.h" 138e3e3a7aSWarner Losh #include "lparser.h" 148e3e3a7aSWarner Losh 158e3e3a7aSWarner Losh 168e3e3a7aSWarner Losh /* 178e3e3a7aSWarner Losh ** Marks the end of a patch list. It is an invalid value both as an absolute 188e3e3a7aSWarner Losh ** address, and as a list link (would link an element to itself). 198e3e3a7aSWarner Losh */ 208e3e3a7aSWarner Losh #define NO_JUMP (-1) 218e3e3a7aSWarner Losh 228e3e3a7aSWarner Losh 238e3e3a7aSWarner Losh /* 248e3e3a7aSWarner Losh ** grep "ORDER OPR" if you change these enums (ORDER OP) 258e3e3a7aSWarner Losh */ 268e3e3a7aSWarner Losh typedef enum BinOpr { 278e3e3a7aSWarner Losh OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW, 288e3e3a7aSWarner Losh OPR_DIV, 298e3e3a7aSWarner Losh OPR_IDIV, 308e3e3a7aSWarner Losh OPR_BAND, OPR_BOR, OPR_BXOR, 318e3e3a7aSWarner Losh OPR_SHL, OPR_SHR, 328e3e3a7aSWarner Losh OPR_CONCAT, 338e3e3a7aSWarner Losh OPR_EQ, OPR_LT, OPR_LE, 348e3e3a7aSWarner Losh OPR_NE, OPR_GT, OPR_GE, 358e3e3a7aSWarner Losh OPR_AND, OPR_OR, 368e3e3a7aSWarner Losh OPR_NOBINOPR 378e3e3a7aSWarner Losh } BinOpr; 388e3e3a7aSWarner Losh 398e3e3a7aSWarner Losh 408e3e3a7aSWarner Losh typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 418e3e3a7aSWarner Losh 428e3e3a7aSWarner Losh 438e3e3a7aSWarner Losh /* get (pointer to) instruction of given 'expdesc' */ 448e3e3a7aSWarner Losh #define getinstruction(fs,e) ((fs)->f->code[(e)->u.info]) 458e3e3a7aSWarner Losh 468e3e3a7aSWarner Losh #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 478e3e3a7aSWarner Losh 488e3e3a7aSWarner Losh #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 498e3e3a7aSWarner Losh 508e3e3a7aSWarner Losh #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) 518e3e3a7aSWarner Losh 528e3e3a7aSWarner Losh LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 538e3e3a7aSWarner Losh LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 548e3e3a7aSWarner Losh LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k); 558e3e3a7aSWarner Losh LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 568e3e3a7aSWarner Losh LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 578e3e3a7aSWarner Losh LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 588e3e3a7aSWarner Losh LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 598e3e3a7aSWarner Losh LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 608e3e3a7aSWarner Losh LUAI_FUNC int luaK_intK (FuncState *fs, lua_Integer n); 618e3e3a7aSWarner Losh LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 628e3e3a7aSWarner Losh LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 638e3e3a7aSWarner Losh LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 648e3e3a7aSWarner Losh LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 658e3e3a7aSWarner Losh LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 668e3e3a7aSWarner Losh LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 678e3e3a7aSWarner Losh LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 688e3e3a7aSWarner Losh LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 698e3e3a7aSWarner Losh LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 708e3e3a7aSWarner Losh LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); 718e3e3a7aSWarner Losh LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 728e3e3a7aSWarner Losh LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 738e3e3a7aSWarner Losh LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 748e3e3a7aSWarner Losh LUAI_FUNC int luaK_jump (FuncState *fs); 758e3e3a7aSWarner Losh LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 768e3e3a7aSWarner Losh LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 778e3e3a7aSWarner Losh LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 788e3e3a7aSWarner Losh LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level); 798e3e3a7aSWarner Losh LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 808e3e3a7aSWarner Losh LUAI_FUNC int luaK_getlabel (FuncState *fs); 818e3e3a7aSWarner Losh LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); 828e3e3a7aSWarner Losh LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 838e3e3a7aSWarner Losh LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, 848e3e3a7aSWarner Losh expdesc *v2, int line); 858e3e3a7aSWarner Losh LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 868e3e3a7aSWarner Losh 878e3e3a7aSWarner Losh 888e3e3a7aSWarner Losh #endif 89