Flipper Zero Firmware
Loading...
Searching...
No Matches
ffi.h
1/*
2 * Copyright (c) 2016 Cesanta Software Limited
3 * All rights reserved
4 */
5
6#ifndef MJS_FFI_FFI_H_
7#define MJS_FFI_FFI_H_
8
9#include "../common/platform.h"
10
11#if defined(__cplusplus)
12extern "C" {
13#endif /* __cplusplus */
14
15/*
16 * Maximum number of word-sized args to ffi-ed function. If at least one
17 * of the args is double, only 2 args are allowed.
18 */
19#define FFI_MAX_ARGS_CNT 6
20
21typedef void(ffi_fn_t)(void);
22
23typedef intptr_t ffi_word_t;
24
25enum ffi_ctype {
26 FFI_CTYPE_WORD,
27 FFI_CTYPE_BOOL,
28 FFI_CTYPE_FLOAT,
29 FFI_CTYPE_DOUBLE,
30};
31
32struct ffi_arg {
33 enum ffi_ctype ctype;
34 union {
35 uint64_t i;
36 double d;
37 float f;
38 } v;
39};
40
41int ffi_call_mjs(ffi_fn_t* func, int nargs, struct ffi_arg* res, struct ffi_arg* args);
42
43void ffi_set_word(struct ffi_arg* arg, ffi_word_t v);
44void ffi_set_bool(struct ffi_arg* arg, bool v);
45void ffi_set_ptr(struct ffi_arg* arg, void* v);
46void ffi_set_double(struct ffi_arg* arg, double v);
47void ffi_set_float(struct ffi_arg* arg, float v);
48
49#if defined(__cplusplus)
50}
51#endif /* __cplusplus */
52
53#endif /* MJS_FFI_FFI_H_ */
Definition ffi.h:32