xref: /freebsd/contrib/lua/src/lcode.h (revision 0495ed398c4f64013bab2327eb13a303e1f90c13)
18e3e3a7aSWarner Losh /*
2*0495ed39SKyle Evans ** $Id: lcode.h $
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 {
27*0495ed39SKyle Evans   /* arithmetic operators */
288e3e3a7aSWarner Losh   OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW,
29*0495ed39SKyle Evans   OPR_DIV, OPR_IDIV,
30*0495ed39SKyle Evans   /* bitwise operators */
318e3e3a7aSWarner Losh   OPR_BAND, OPR_BOR, OPR_BXOR,
328e3e3a7aSWarner Losh   OPR_SHL, OPR_SHR,
33*0495ed39SKyle Evans   /* string operator */
348e3e3a7aSWarner Losh   OPR_CONCAT,
35*0495ed39SKyle Evans   /* comparison operators */
368e3e3a7aSWarner Losh   OPR_EQ, OPR_LT, OPR_LE,
378e3e3a7aSWarner Losh   OPR_NE, OPR_GT, OPR_GE,
38*0495ed39SKyle Evans   /* logical operators */
398e3e3a7aSWarner Losh   OPR_AND, OPR_OR,
408e3e3a7aSWarner Losh   OPR_NOBINOPR
418e3e3a7aSWarner Losh } BinOpr;
428e3e3a7aSWarner Losh 
438e3e3a7aSWarner Losh 
44*0495ed39SKyle Evans /* true if operation is foldable (that is, it is arithmetic or bitwise) */
45*0495ed39SKyle Evans #define foldbinop(op)	((op) <= OPR_SHR)
46*0495ed39SKyle Evans 
47*0495ed39SKyle Evans 
48*0495ed39SKyle Evans #define luaK_codeABC(fs,o,a,b,c)	luaK_codeABCk(fs,o,a,b,c,0)
49*0495ed39SKyle Evans 
50*0495ed39SKyle Evans 
518e3e3a7aSWarner Losh typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
528e3e3a7aSWarner Losh 
538e3e3a7aSWarner Losh 
548e3e3a7aSWarner Losh /* get (pointer to) instruction of given 'expdesc' */
558e3e3a7aSWarner Losh #define getinstruction(fs,e)	((fs)->f->code[(e)->u.info])
568e3e3a7aSWarner Losh 
578e3e3a7aSWarner Losh 
588e3e3a7aSWarner Losh #define luaK_setmultret(fs,e)	luaK_setreturns(fs, e, LUA_MULTRET)
598e3e3a7aSWarner Losh 
608e3e3a7aSWarner Losh #define luaK_jumpto(fs,t)	luaK_patchlist(fs, luaK_jump(fs), t)
618e3e3a7aSWarner Losh 
62*0495ed39SKyle Evans LUAI_FUNC int luaK_code (FuncState *fs, Instruction i);
638e3e3a7aSWarner Losh LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
64*0495ed39SKyle Evans LUAI_FUNC int luaK_codeAsBx (FuncState *fs, OpCode o, int A, int Bx);
65*0495ed39SKyle Evans LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A,
66*0495ed39SKyle Evans                                             int B, int C, int k);
67*0495ed39SKyle Evans LUAI_FUNC int luaK_isKint (expdesc *e);
68*0495ed39SKyle Evans LUAI_FUNC int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v);
698e3e3a7aSWarner Losh LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
708e3e3a7aSWarner Losh LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);
718e3e3a7aSWarner Losh LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);
728e3e3a7aSWarner Losh LUAI_FUNC void luaK_checkstack (FuncState *fs, int n);
73*0495ed39SKyle Evans LUAI_FUNC void luaK_int (FuncState *fs, int reg, lua_Integer n);
748e3e3a7aSWarner Losh LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);
758e3e3a7aSWarner Losh LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);
768e3e3a7aSWarner Losh LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e);
778e3e3a7aSWarner Losh LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);
788e3e3a7aSWarner Losh LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);
798e3e3a7aSWarner Losh LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);
808e3e3a7aSWarner Losh LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
818e3e3a7aSWarner Losh LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
828e3e3a7aSWarner Losh LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
838e3e3a7aSWarner Losh LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);
848e3e3a7aSWarner Losh LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
858e3e3a7aSWarner Losh LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);
868e3e3a7aSWarner Losh LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);
878e3e3a7aSWarner Losh LUAI_FUNC int luaK_jump (FuncState *fs);
888e3e3a7aSWarner Losh LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);
898e3e3a7aSWarner Losh LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);
908e3e3a7aSWarner Losh LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);
918e3e3a7aSWarner Losh LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);
928e3e3a7aSWarner Losh LUAI_FUNC int luaK_getlabel (FuncState *fs);
938e3e3a7aSWarner Losh LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line);
948e3e3a7aSWarner Losh LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);
958e3e3a7aSWarner Losh LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1,
968e3e3a7aSWarner Losh                             expdesc *v2, int line);
97*0495ed39SKyle Evans LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc,
98*0495ed39SKyle Evans                                   int ra, int asize, int hsize);
998e3e3a7aSWarner Losh LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
100*0495ed39SKyle Evans LUAI_FUNC void luaK_finish (FuncState *fs);
101*0495ed39SKyle Evans LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg);
1028e3e3a7aSWarner Losh 
1038e3e3a7aSWarner Losh 
1048e3e3a7aSWarner Losh #endif
105