xref: /netbsd/external/mit/lua/dist/src/ltm.h (revision f13f21ab)
1 /*	$NetBSD: ltm.h,v 1.10 2023/06/08 21:12:08 nikita Exp $	*/
2 
3 /*
4 ** Id: ltm.h
5 ** Tag methods
6 ** See Copyright Notice in lua.h
7 */
8 
9 #ifndef ltm_h
10 #define ltm_h
11 
12 
13 #include "lobject.h"
14 #include "lstate.h"
15 
16 
17 /*
18 * WARNING: if you change the order of this enumeration,
19 * grep "ORDER TM" and "ORDER OP"
20 */
21 typedef enum {
22   TM_INDEX,
23   TM_NEWINDEX,
24   TM_GC,
25   TM_MODE,
26   TM_LEN,
27   TM_EQ,  /* last tag method with fast access */
28   TM_ADD,
29   TM_SUB,
30   TM_MUL,
31   TM_MOD,
32 #ifndef _KERNEL
33   TM_POW,
34   TM_DIV,
35 #endif /* _KERNEL */
36   TM_IDIV,
37   TM_BAND,
38   TM_BOR,
39   TM_BXOR,
40   TM_SHL,
41   TM_SHR,
42   TM_UNM,
43   TM_BNOT,
44   TM_LT,
45   TM_LE,
46   TM_CONCAT,
47   TM_CALL,
48   TM_CLOSE,
49   TM_N		/* number of elements in the enum */
50 } TMS;
51 
52 
53 /*
54 ** Mask with 1 in all fast-access methods. A 1 in any of these bits
55 ** in the flag of a (meta)table means the metatable does not have the
56 ** corresponding metamethod field. (Bit 7 of the flag is used for
57 ** 'isrealasize'.)
58 */
59 #define maskflags	(~(~0u << (TM_EQ + 1)))
60 
61 
62 /*
63 ** Test whether there is no tagmethod.
64 ** (Because tagmethods use raw accesses, the result may be an "empty" nil.)
65 */
66 #define notm(tm)	ttisnil(tm)
67 
68 
69 #define gfasttm(g,et,e) ((et) == NULL ? NULL : \
70   ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))
71 
72 #define fasttm(l,et,e)	gfasttm(G(l), et, e)
73 
74 #define ttypename(x)	luaT_typenames_[(x) + 1]
75 
76 LUAI_DDEC(const char *const luaT_typenames_[LUA_TOTALTYPES];)
77 
78 
79 LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o);
80 
81 LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);
82 LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,
83                                                        TMS event);
84 LUAI_FUNC void luaT_init (lua_State *L);
85 
86 LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,
87                             const TValue *p2, const TValue *p3);
88 LUAI_FUNC void luaT_callTMres (lua_State *L, const TValue *f,
89                             const TValue *p1, const TValue *p2, StkId p3);
90 LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,
91                               StkId res, TMS event);
92 LUAI_FUNC void luaT_tryconcatTM (lua_State *L);
93 LUAI_FUNC void luaT_trybinassocTM (lua_State *L, const TValue *p1,
94        const TValue *p2, int inv, StkId res, TMS event);
95 LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2,
96                                int inv, StkId res, TMS event);
97 LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1,
98                                 const TValue *p2, TMS event);
99 LUAI_FUNC int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2,
100                                  int inv, int isfloat, TMS event);
101 
102 LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams,
103                                    CallInfo *ci, const Proto *p);
104 LUAI_FUNC void luaT_getvarargs (lua_State *L, CallInfo *ci,
105                                               StkId where, int wanted);
106 
107 
108 #endif
109