diff options
author | Mike Pall <mike> | 2010-12-05 00:18:07 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2010-12-05 00:18:07 +0100 |
commit | 526e087e63daaaeab517932351c8941f678e071c (patch) | |
tree | e7a1460ba4c120b1cc464a3702fb915de9388fe9 /src/lj_cconv.h | |
parent | 05973ee44075698e6c578cfb0fa72cfccdf7b742 (diff) | |
download | luajit-526e087e63daaaeab517932351c8941f678e071c.tar.gz luajit-526e087e63daaaeab517932351c8941f678e071c.tar.bz2 luajit-526e087e63daaaeab517932351c8941f678e071c.zip |
FFI: Add C data handling and C type conversions.
Diffstat (limited to 'src/lj_cconv.h')
-rw-r--r-- | src/lj_cconv.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/lj_cconv.h b/src/lj_cconv.h new file mode 100644 index 00000000..45afe718 --- /dev/null +++ b/src/lj_cconv.h | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | ** C type conversions. | ||
3 | ** Copyright (C) 2005-2010 Mike Pall. See Copyright Notice in luajit.h | ||
4 | */ | ||
5 | |||
6 | #ifndef _LJ_CCONV_H | ||
7 | #define _LJ_CCONV_H | ||
8 | |||
9 | #include "lj_obj.h" | ||
10 | #include "lj_ctype.h" | ||
11 | |||
12 | #if LJ_HASFFI | ||
13 | |||
14 | /* Compressed C type index. ORDER CCX. */ | ||
15 | enum { | ||
16 | CCX_B, /* Bool. */ | ||
17 | CCX_I, /* Integer. */ | ||
18 | CCX_F, /* Floating-point number. */ | ||
19 | CCX_C, /* Complex. */ | ||
20 | CCX_V, /* Vector. */ | ||
21 | CCX_P, /* Pointer. */ | ||
22 | CCX_A, /* Refarray. */ | ||
23 | CCX_S /* Struct/union. */ | ||
24 | }; | ||
25 | |||
26 | /* Convert C type info to compressed C type index. ORDER CT. ORDER CCX. */ | ||
27 | static LJ_AINLINE uint32_t cconv_idx(CTInfo info) | ||
28 | { | ||
29 | uint32_t idx = ((info >> 26) & 15u); /* Dispatch bits. */ | ||
30 | lua_assert(ctype_type(info) <= CT_MAYCONVERT); | ||
31 | #if LJ_64 | ||
32 | idx = ((U64x(f436fff5,fff7f021) >> 4*idx) & 15u); | ||
33 | #else | ||
34 | idx = (((idx < 8 ? 0xfff7f021u : 0xf436fff5) >> 4*(idx & 7u)) & 15u); | ||
35 | #endif | ||
36 | lua_assert(idx < 8); | ||
37 | return idx; | ||
38 | } | ||
39 | |||
40 | #define cconv_idx2(dinfo, sinfo) \ | ||
41 | ((cconv_idx((dinfo)) << 3) + cconv_idx((sinfo))) | ||
42 | |||
43 | #define CCX(dst, src) ((CCX_##dst << 3) + CCX_##src) | ||
44 | |||
45 | /* Conversion flags. */ | ||
46 | #define CCF_CAST 0x00000001u | ||
47 | #define CCF_FROMTV 0x00000002u | ||
48 | #define CCF_SAME 0x00000004u | ||
49 | |||
50 | |||
51 | LJ_FUNC void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s, | ||
52 | uint8_t *dp, uint8_t *sp, CTInfo flags); | ||
53 | LJ_FUNC void lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid, | ||
54 | TValue *o, uint8_t *sp); | ||
55 | LJ_FUNC void lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp); | ||
56 | LJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d, | ||
57 | uint8_t *dp, TValue *o, CTInfo flags); | ||
58 | LJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o); | ||
59 | LJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz, | ||
60 | uint8_t *dp, TValue *o, MSize len); | ||
61 | |||
62 | #endif | ||
63 | |||
64 | #endif | ||