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