summaryrefslogtreecommitdiff
path: root/src/lj_frame.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lj_frame.h84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/lj_frame.h b/src/lj_frame.h
new file mode 100644
index 00000000..1c03e3e1
--- /dev/null
+++ b/src/lj_frame.h
@@ -0,0 +1,84 @@
1/*
2** Stack frames.
3** Copyright (C) 2005-2009 Mike Pall. See Copyright Notice in luajit.h
4*/
5
6#ifndef _LJ_FRAME_H
7#define _LJ_FRAME_H
8
9#include "lj_obj.h"
10#include "lj_bc.h"
11
12/* -- Lua stack frame ----------------------------------------------------- */
13
14/* Frame type markers in callee function slot (callee base-1). */
15enum {
16 FRAME_LUA, FRAME_C, FRAME_CONT, FRAME_VARG,
17 FRAME_LUAP, FRAME_CP, FRAME_PCALL, FRAME_PCALLH
18};
19#define FRAME_TYPE 3
20#define FRAME_P 4
21#define FRAME_TYPEP (FRAME_TYPE|FRAME_P)
22
23/* Macros to access and modify Lua frames. */
24#define frame_gc(f) (gcref((f)->fr.func))
25#define frame_func(f) (&frame_gc(f)->fn)
26#define frame_ftsz(f) ((f)->fr.tp.ftsz)
27
28#define frame_type(f) (frame_ftsz(f) & FRAME_TYPE)
29#define frame_typep(f) (frame_ftsz(f) & FRAME_TYPEP)
30#define frame_islua(f) (frame_type(f) == FRAME_LUA)
31#define frame_isc(f) (frame_type(f) == FRAME_C)
32#define frame_iscont(f) (frame_typep(f) == FRAME_CONT)
33#define frame_isvarg(f) (frame_typep(f) == FRAME_VARG)
34#define frame_ispcall(f) ((frame_ftsz(f) & 6) == FRAME_PCALL)
35
36#define frame_pc(f) (mref((f)->fr.tp.pcr, const BCIns))
37#define frame_contpc(f) (frame_pc((f)-1))
38#if LJ_64
39#define frame_contf(f) \
40 ((ASMFunction)(void *)((intptr_t)lj_vm_asm_begin+(((f)-1)->u64 & 0xffffffff)))
41#else
42#define frame_contf(f) ((ASMFunction)gcrefp(((f)-1)->gcr, void))
43#endif
44#define frame_delta(f) (frame_ftsz(f) >> 3)
45#define frame_sized(f) (frame_ftsz(f) & ~FRAME_TYPEP)
46
47#define frame_prevl(f) ((f) - (1+bc_a(frame_pc(f)[-1])))
48#define frame_prevd(f) ((TValue *)((char *)(f) - frame_sized(f)))
49#define frame_prev(f) (frame_islua(f)?frame_prevl(f):frame_prevd(f))
50/* Note: this macro does not skip over FRAME_VARG. */
51
52#define setframe_pc(f, pc) (setmref((f)->fr.tp.pcr, (pc)))
53#define setframe_gc(f, p) (setgcref((f)->fr.func, (p)))
54
55/* -- C stack frame ------------------------------------------------------- */
56
57/* Macros to access and modify the C stack frame chain. */
58
59/* These definitions must match with the arch-specific *.dasc files. */
60#if LJ_TARGET_X86
61#define CFRAME_OFS_ERRF (15*sizeof(void *))
62#define CFRAME_OFS_NRES (14*sizeof(void *))
63#define CFRAME_OFS_PREV (13*sizeof(void *))
64#define CFRAME_OFS_L (12*sizeof(void *))
65#define CFRAME_OFS_PC (6*sizeof(void *))
66#define CFRAME_SIZE (12*sizeof(void *))
67#else
68#error "Missing CFRAME_* definitions for this architecture"
69#endif
70
71#define CFRAME_RESUME 1
72#define CFRAME_CANYIELD ((intptr_t)(CFRAME_RESUME))
73#define CFRAME_RAWMASK (~CFRAME_CANYIELD)
74
75#define cframe_errfunc(cf) (*(ptrdiff_t *)(((char *)cf)+CFRAME_OFS_ERRF))
76#define cframe_nres(cf) (*(ptrdiff_t *)(((char *)cf)+CFRAME_OFS_NRES))
77#define cframe_prev(cf) (*(void **)(((char *)cf)+CFRAME_OFS_PREV))
78#define cframe_L(cf) (*(lua_State **)(((char *)cf)+CFRAME_OFS_L))
79#define cframe_pc(cf) (*(const BCIns **)(((char *)cf)+CFRAME_OFS_PC))
80#define cframe_canyield(cf) ((intptr_t)(cf) & CFRAME_CANYIELD)
81#define cframe_raw(cf) ((void *)((intptr_t)(cf) & CFRAME_RAWMASK))
82#define cframe_Lpc(L) cframe_pc(cframe_raw(L->cframe))
83
84#endif