LispBM
extensions.h
Go to the documentation of this file.
1 
2 /*
3  Copyright 2019, 2022 Joel Svensson svenssonjoel@yahoo.se
4  2022 Benjamin Vedder
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef EXTENSIONS_H_
21 #define EXTENSIONS_H_
22 
23 #include "symrepr.h"
24 #include "heap.h"
25 #include "lbm_types.h"
26 #include "lbm_constants.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #define LBM_EXTENSION(name, argv, argn) \
33  __attribute__((aligned(LBM_STORABLE_ADDRESS_ALIGNMENT))) lbm_value name(lbm_value *(argv), lbm_uint (argn))
34 
40 typedef lbm_value (*extension_fptr)(lbm_value*,lbm_uint);
41 
48 int lbm_extensions_init(extension_fptr *extension_storage, int extension_storage_size);
52 lbm_uint lbm_get_max_extensions(void);
56 lbm_uint lbm_get_num_extensions(void);
70 bool lbm_clr_extension(lbm_uint sym_id);
76 bool lbm_add_extension(char *sym_str, extension_fptr ext);
77 
82 static inline bool lbm_is_extension(lbm_value exp) {
83  return ((lbm_type_of(exp) == LBM_TYPE_SYMBOL) &&
84  (lbm_get_extension(lbm_dec_sym(exp)) != NULL));
85 }
86 
87 
98 bool lbm_check_number_all(lbm_value *args, lbm_uint argn);
104 bool lbm_check_argn(lbm_uint argn, lbm_uint n);
111 bool lbm_check_argn_number(lbm_value *args, lbm_uint argn, lbm_uint n);
112 
113 #define LBM_CHECK_NUMBER_ALL() if (!lbm_check_number_all(args, argn)) {return ENC_SYM_EERROR;}
114 #define LBM_CHECK_ARGN(n) if (!lbm_check_argn(argn, n)) {return ENC_SYM_EERROR;}
115 #define LBM_CHECK_ARGN_NUMBER(n) if (!lbm_check_argn_number(args, argn, n)) {return ENC_SYM_EERROR;}
116 
117 #ifdef __cplusplus
118 }
119 #endif
120 #endif
bool lbm_check_argn(lbm_uint argn, lbm_uint n)
static bool lbm_is_extension(lbm_value exp)
Definition: extensions.h:82
lbm_uint lbm_get_max_extensions(void)
bool lbm_check_true_false(lbm_value v)
extension_fptr lbm_get_extension(lbm_uint sym)
lbm_value(* extension_fptr)(lbm_value *, lbm_uint)
Definition: extensions.h:40
bool lbm_check_number_all(lbm_value *args, lbm_uint argn)
bool lbm_check_argn_number(lbm_value *args, lbm_uint argn, lbm_uint n)
bool lbm_add_extension(char *sym_str, extension_fptr ext)
lbm_uint lbm_get_num_extensions(void)
int lbm_extensions_init(extension_fptr *extension_storage, int extension_storage_size)
bool lbm_clr_extension(lbm_uint sym_id)
static lbm_type lbm_type_of(lbm_value x)
Definition: heap.h:657
uint32_t lbm_value
Definition: lbm_types.h:43