-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.h
92 lines (70 loc) · 1.67 KB
/
function.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#pragma once
#include "header.h"
#include "llist.h"
#include "sfmem.h"
#include "sfstr.h"
struct _mod_s;
typedef llnode_t *(*fnret_t) (struct _mod_s *);
#define SF_FUN_ARG_LIMIT 256
enum
{
SF_FUN_NATIVE = 0,
SF_FUN_CODED = 1,
};
struct _sf_fun_s
{
char *name;
int type;
struct _mod_s *mod;
char **args;
size_t argc;
struct
{
fnret_t routine;
} native;
struct
{
size_t id;
int has_id;
} meta;
// .mod can store function body itself
// no struct required for coded functions
};
typedef struct _sf_fun_s fun_t;
#define SF_FUN_CACHE_SIZE 32
#ifdef __cplusplus
extern "C"
{
#endif
/**
* @brief Initializes the sunflower function.
*
* This function initializes the sunflower function utility by performing any
* necessary setup or initialization steps.
*/
SF_API void sf_fun_init (void);
/**
* Creates a new function object.
*
* @param _Name Name of function
* @param _Type The type of the function.
* @param _Mod The module associated with the function.
* @param _RoutineIfNative The native routine if the function is
* native. (pass null if function is coded)
* @return The newly created function object.
*/
SF_API fun_t *sf_fun_new (char *_Name, int _Type, struct _mod_s *_Mod,
void *_RoutineIfNative);
SF_API void sf_fun_addarg (fun_t *_Fun, char *_ArgName);
/**
* Adds a function to the sunflower library.
*
* @param _Fun The function to be added.
* @return A pointer to the added function.
*/
SF_API fun_t *sf_fun_add (fun_t *_Fun);
SF_API fun_t ***sf_fun_getStack (void);
SF_API void sf_fun_free (fun_t *_Fun);
#ifdef __cplusplus
}
#endif