1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/*
* Copyright (C) 2020 Jo-Philipp Wich <jo@mein.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef __MODULE_H_
#define __MODULE_H_
#include "ast.h"
#include "lib.h"
struct uc_ops {
bool (*register_function)(struct uc_state *, struct json_object *, const char *, uc_c_fn *);
bool (*register_type)(const char *, struct json_object *, void (*)(void *));
struct json_object *(*set_type)(struct json_object *, const char *, void *);
void **(*get_type)(struct json_object *, const char *);
struct json_object *(*new_object)(struct json_object *);
struct json_object *(*new_double)(double);
struct json_object *(*invoke)(struct uc_state *, uint32_t, struct json_object *, struct json_object *, struct json_object *);
enum json_type (*cast_number)(struct json_object *, int64_t *, double *);
};
extern const struct uc_ops ut;
#define register_functions(state, ops, functions, scope) \
if (scope) \
for (int i = 0; i < ARRAY_SIZE(functions); i++) \
ops->register_function(state, scope, functions[i].name, functions[i].func)
void uc_module_init(const struct uc_ops *, struct uc_state *, struct json_object *);
#endif /* __MODULE_H_ */
|