diff options
Diffstat (limited to 'src/lj_lib.h')
-rw-r--r-- | src/lj_lib.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/lj_lib.h b/src/lj_lib.h new file mode 100644 index 00000000..1cba3778 --- /dev/null +++ b/src/lj_lib.h | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | ** Library function support. | ||
3 | ** Copyright (C) 2005-2009 Mike Pall. See Copyright Notice in luajit.h | ||
4 | */ | ||
5 | |||
6 | #ifndef _LJ_LIB_H | ||
7 | #define _LJ_LIB_H | ||
8 | |||
9 | #include "lj_obj.h" | ||
10 | |||
11 | /* | ||
12 | ** A fallback handler is called by the assembler VM if the fast path fails: | ||
13 | ** | ||
14 | ** - too few arguments: unrecoverable. | ||
15 | ** - wrong argument type: recoverable, if coercion succeeds. | ||
16 | ** - bad argument value: unrecoverable. | ||
17 | ** - stack overflow: recoverable, if stack reallocation succeeds. | ||
18 | ** - extra handling: recoverable. | ||
19 | ** | ||
20 | ** The unrecoverable cases throw an error with lj_err_arg(), lj_err_argtype(), | ||
21 | ** lj_err_caller() or lj_err_callermsg(). | ||
22 | ** The recoverable cases return 0 or the number of results + 1. | ||
23 | ** The assembler VM retries the fast path only if 0 is returned. | ||
24 | ** This time the fallback must not be called again or it gets stuck in a loop. | ||
25 | */ | ||
26 | |||
27 | /* Return values from fallback handler. */ | ||
28 | #define FFH_RETRY 0 | ||
29 | #define FFH_UNREACHABLE FFH_RETRY | ||
30 | #define FFH_RES(n) ((n)+1) | ||
31 | |||
32 | LJ_FUNC TValue *lj_lib_checkany(lua_State *L, int narg); | ||
33 | LJ_FUNC GCstr *lj_lib_checkstr(lua_State *L, int narg); | ||
34 | LJ_FUNC GCstr *lj_lib_optstr(lua_State *L, int narg); | ||
35 | LJ_FUNC lua_Number lj_lib_checknum(lua_State *L, int narg); | ||
36 | LJ_FUNC int32_t lj_lib_checkint(lua_State *L, int narg); | ||
37 | LJ_FUNC int32_t lj_lib_optint(lua_State *L, int narg, int32_t def); | ||
38 | LJ_FUNC GCfunc *lj_lib_checkfunc(lua_State *L, int narg); | ||
39 | LJ_FUNC GCtab *lj_lib_checktab(lua_State *L, int narg); | ||
40 | LJ_FUNC GCtab *lj_lib_checktabornil(lua_State *L, int narg); | ||
41 | LJ_FUNC int lj_lib_checkopt(lua_State *L, int narg, int def, const char *lst); | ||
42 | |||
43 | #define lj_lib_opt(L, narg, gotarg, noarg) \ | ||
44 | { TValue *_o = L->base + (narg)-1; \ | ||
45 | if (_o < L->top && !tvisnil(_o)) { gotarg } else { noarg } } | ||
46 | |||
47 | /* Avoid including lj_frame.h. */ | ||
48 | #define lj_lib_upvalue(L, n) \ | ||
49 | (&gcref((L->base-1)->fr.func)->fn.c.upvalue[(n)-1]) | ||
50 | |||
51 | /* Library function declarations. Scanned by buildvm. */ | ||
52 | #define LJLIB_CF(name) static int lj_cf_##name(lua_State *L) | ||
53 | #define LJLIB_ASM(name) static int lj_ffh_##name(lua_State *L) | ||
54 | #define LJLIB_ASM_(name) | ||
55 | #define LJLIB_SET(name) | ||
56 | #define LJLIB_PUSH(arg) | ||
57 | #define LJLIB_REC(handler) | ||
58 | #define LJLIB_NOREGUV | ||
59 | #define LJLIB_NOREG | ||
60 | |||
61 | #define LJ_LIB_REG(L, name) \ | ||
62 | lj_lib_register(L, #name, lj_lib_init_##name, lj_lib_cf_##name) | ||
63 | #define LJ_LIB_REG_(L, regname, name) \ | ||
64 | lj_lib_register(L, regname, lj_lib_init_##name, lj_lib_cf_##name) | ||
65 | |||
66 | LJ_FUNC void lj_lib_register(lua_State *L, const char *libname, | ||
67 | const uint8_t *init, const lua_CFunction *cf); | ||
68 | |||
69 | /* Library init data tags. */ | ||
70 | #define LIBINIT_LENMASK 0x3f | ||
71 | #define LIBINIT_TAGMASK 0xc0 | ||
72 | #define LIBINIT_CF 0x00 | ||
73 | #define LIBINIT_ASM 0x40 | ||
74 | #define LIBINIT_ASM_ 0x80 | ||
75 | #define LIBINIT_STRING 0xc0 | ||
76 | #define LIBINIT_MAXSTR 0x39 | ||
77 | #define LIBINIT_SET 0xfa | ||
78 | #define LIBINIT_NUMBER 0xfb | ||
79 | #define LIBINIT_COPY 0xfc | ||
80 | #define LIBINIT_LASTCL 0xfd | ||
81 | #define LIBINIT_FFID 0xfe | ||
82 | #define LIBINIT_END 0xff | ||
83 | |||
84 | #endif | ||