Reduct  v1.0.4-3-gdaf0d70
A functional and immutable language.
Loading...
Searching...
No Matches
intrinsic.h
Go to the documentation of this file.
1#ifndef REDUCT_INTRINSIC_H
2#define REDUCT_INTRINSIC_H 1
3
4#include "defs.h"
5#include "native.h"
6
7struct reduct;
8struct reduct_compiler;
9struct reduct_item;
10struct reduct_expr;
11
12/**
13 * @file intrinsic.h
14 * @brief Intrinsic management.
15 * @defgroup intrinsic Intrinsics
16 *
17 * A intrinsic is an atom recognized by the bytecode compiler as a special form or built-in operator, resulting in it
18 * emitting specific bytecode instructions for each intrinsic.
19 *
20 * This is in contrast to a "native" which will be invoked as a standard function call at runtime.
21 *
22 * @{
23 */
24
25/**
26 * @brief Intrinsic types.
27 */
29
30#define REDUCT_INTRINSIC_NONE 0 ///< None
31#define REDUCT_INTRINSIC_QUOTE 1 ///< Quote
32#define REDUCT_INTRINSIC_LIST 2 ///< List
33#define REDUCT_INTRINSIC_DO 3 ///< Do
34#define REDUCT_INTRINSIC_LAMBDA 4 ///< Lambda
35#define REDUCT_INTRINSIC_THREAD 5 ///< Thread
36#define REDUCT_INTRINSIC_DEF 6 ///< Def
37#define REDUCT_INTRINSIC_IF 7 ///< If
38#define REDUCT_INTRINSIC_COND 8 ///< Cond
39#define REDUCT_INTRINSIC_MATCH 9 ///< Match
40#define REDUCT_INTRINSIC_AND 10 ///< And
41#define REDUCT_INTRINSIC_OR 11 ///< Or
42#define REDUCT_INTRINSIC_NOT 12 ///< Not
43#define REDUCT_INTRINSIC_ADD 13 ///< Add
44#define REDUCT_INTRINSIC_SUB 14 ///< Sub
45#define REDUCT_INTRINSIC_MUL 15 ///< Mul
46#define REDUCT_INTRINSIC_DIV 16 ///< Div
47#define REDUCT_INTRINSIC_MOD 17 ///< Mod
48#define REDUCT_INTRINSIC_INC 18 ///< Inc
49#define REDUCT_INTRINSIC_DEC 19 ///< Dec
50#define REDUCT_INTRINSIC_BAND 20 ///< Bitwise And
51#define REDUCT_INTRINSIC_BOR 21 ///< Bitwise Or
52#define REDUCT_INTRINSIC_BXOR 22 ///< Bitwise Xor
53#define REDUCT_INTRINSIC_BNOT 23 ///< Bitwise Not
54#define REDUCT_INTRINSIC_SHL 24 ///< Bitwise Shift Left
55#define REDUCT_INTRINSIC_SHR 25 ///< Bitwise Shift Right
56#define REDUCT_INTRINSIC_EQ 26 ///< Equal
57#define REDUCT_INTRINSIC_NEQ 27 ///< Not Equal
58#define REDUCT_INTRINSIC_SEQ 28 ///< Strict Equal
59#define REDUCT_INTRINSIC_SNEQ 29 ///< Strict Not Equal
60#define REDUCT_INTRINSIC_LT 30 ///< Less
61#define REDUCT_INTRINSIC_LE 31 ///< Less Equal
62#define REDUCT_INTRINSIC_GT 32 ///< Greater
63#define REDUCT_INTRINSIC_GE 33 ///< Greater Equal
64#define REDUCT_INTRINSIC_MAX 34 ///< The amount of intrinsics
65
66/**
67 * @brief Intrinsic handler function type.
68 */
69typedef void (
70 *reduct_intrinsic_handler_t)(struct reduct_compiler* compiler, struct reduct_item* expr, struct reduct_expr* out);
71
72/**
73 * @brief Intrinsic handler functions array.
74 */
76
77/**
78 * @brief Intrinsic native functions array.
79 */
81
82/**
83 * @brief Intrinsic names array.
84 */
85extern const char* reductIntrinsics[REDUCT_INTRINSIC_MAX];
86
87/**
88 * @brief Registers all Reduct intrinsics with the given Reduct instance.
89 *
90 * @param reduct The Reduct instance to register intrinsics with.
91 */
92REDUCT_API void reduct_intrinsic_register_all(struct reduct* reduct);
93
94/**
95 * @brief Compiles a block of expressions (like a `do` block).
96 *
97 * @param compiler The compiler context.
98 * @param list The list containing the expressions.
99 * @param startIdx The index to start compiling from.
100 * @param out The output expression.
101 */
102void reduct_intrinsic_block_generic(struct reduct_compiler* compiler, struct reduct_item* list,
103 reduct_uint32_t startIdx, struct reduct_expr* out);
104
105#endif
uint32_t reduct_uint32_t
Definition defs.h:95
uint8_t reduct_uint8_t
Definition defs.h:99
#define REDUCT_API
Definition defs.h:7
reduct_intrinsic_handler_t reductIntrinsicHandlers[REDUCT_INTRINSIC_MAX]
Intrinsic handler functions array.
const char * reductIntrinsics[REDUCT_INTRINSIC_MAX]
Intrinsic names array.
#define REDUCT_INTRINSIC_MAX
The amount of intrinsics.
Definition intrinsic.h:64
reduct_native_fn reductIntrinsicNatives[REDUCT_INTRINSIC_MAX]
Intrinsic native functions array.
reduct_uint8_t reduct_intrinsic_t
Intrinsic types.
Definition intrinsic.h:28
REDUCT_API void reduct_intrinsic_register_all(struct reduct *reduct)
Registers all Reduct intrinsics with the given Reduct instance.
void reduct_intrinsic_block_generic(struct reduct_compiler *compiler, struct reduct_item *list, reduct_uint32_t startIdx, struct reduct_expr *out)
Compiles a block of expressions (like a do block).
void(* reduct_intrinsic_handler_t)(struct reduct_compiler *compiler, struct reduct_item *expr, struct reduct_expr *out)
Intrinsic handler function type.
Definition intrinsic.h:70
reduct_handle_t(* reduct_native_fn)(struct reduct *reduct, reduct_size_t argc, reduct_handle_t *argv)
Native function pointer type.
Definition native.h:26
Native function registration.