Reduct  v1.0.4-3-gdaf0d70
A functional and immutable language.
Loading...
Searching...
No Matches
native_impl.h
Go to the documentation of this file.
1#ifndef REDUCT_NATIVE_IMPL_H
2#define REDUCT_NATIVE_IMPL_H 1
3
4#include "atom.h"
5#include "core.h"
6#include "gc.h"
7#include "item.h"
8#include "native.h"
9
11{
12 REDUCT_ASSERT(reduct != REDUCT_NULL);
13 REDUCT_ASSERT(array != REDUCT_NULL || count == 0);
14
15 for (reduct_size_t i = 0; i < count; i++)
16 {
17 reduct_native_t* native = &array[i];
18
19 reduct_size_t len = REDUCT_STRLEN(native->name);
20 reduct_atom_t* atom = reduct_atom_lookup(reduct, native->name, len, REDUCT_ATOM_LOOKUP_NONE);
22
24 atom->native = native->fn;
25
26 REDUCT_GC_RETAIN_ITEM(reduct, item);
27 }
28}
29
30#endif
Atom representation and operations.
Core definitions and structures.
#define REDUCT_STRLEN(s)
Definition defs.h:38
size_t reduct_size_t
Definition defs.h:100
#define REDUCT_CONTAINER_OF(_ptr, _type, _member)
Container of macro.
Definition defs.h:184
#define REDUCT_ASSERT(_cond)
Definition defs.h:25
#define REDUCT_API
Definition defs.h:7
#define REDUCT_NULL
Definition defs.h:23
Garbage collection.
REDUCT_API reduct_atom_t * reduct_atom_lookup(struct reduct *reduct, const char *str, reduct_size_t len, reduct_atom_lookup_flags_t flags)
Lookup an atom in the Reduct structure.
@ REDUCT_ATOM_LOOKUP_NONE
No flags.
Definition atom.h:39
#define REDUCT_GC_RETAIN_ITEM(_reduct, _item)
Retain a item, preventing it from being collected by the GC.
Definition gc.h:56
#define REDUCT_ITEM_FLAG_NATIVE
Item is an atom and a native function.
Definition item.h:42
Item management.
Native function registration.
REDUCT_API void reduct_native_register(reduct_t *reduct, reduct_native_t *array, reduct_size_t count)
Definition native_impl.h:10
Atom structure.
Definition atom.h:48
reduct_native_fn native
Native function, item must have REDUCT_ITEM_FLAG_NATIVE.
Definition atom.h:57
Item structure.
Definition item.h:57
reduct_item_flags_t flags
Flags for the item.
Definition item.h:60
Native function definition structure.
Definition native.h:32
const char * name
Definition native.h:33
reduct_native_fn fn
Definition native.h:34
State structure.
Definition core.h:61