LispBM
extensions.h
Go to the documentation of this file.
1 
2 /*
3  Copyright 2019, 2022, 2024 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 "heap.h"
24 #include "lbm_types.h"
25 #include "lbm_constants.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
37 
40 typedef struct {
42  char *name;
44 
45 
47 
48 #define LBM_EXTENSION(name, argv, argn) \
49  __attribute__((aligned(LBM_STORABLE_ADDRESS_ALIGNMENT))) lbm_value name(lbm_value *(argv), lbm_uint (argn))
50 
56  int lbm_extensions_init(lbm_extension_t *extension_storage, lbm_uint extension_storage_size);
70 bool lbm_lookup_extension_id(char *sym_str, lbm_uint *ix);
84 bool lbm_clr_extension(lbm_uint sym_id);
90 bool lbm_add_extension(char *sym_str, extension_fptr ext);
91 
96 static inline bool lbm_is_extension(lbm_value exp) {
97  return ((lbm_type_of(exp) == LBM_TYPE_SYMBOL) &&
98  (lbm_get_extension(lbm_dec_sym(exp)) != NULL));
99 }
100 
101 
112 bool lbm_check_number_all(lbm_value *args, lbm_uint argn);
118 bool lbm_check_argn(lbm_uint argn, lbm_uint n);
125 bool lbm_check_argn_number(lbm_value *args, lbm_uint argn, lbm_uint n);
126 
127 #define LBM_CHECK_NUMBER_ALL() if (!lbm_check_number_all(args, argn)) {return ENC_SYM_EERROR;}
128 #define LBM_CHECK_ARGN(n) if (!lbm_check_argn(argn, n)) {return ENC_SYM_EERROR;}
129 #define LBM_CHECK_ARGN_NUMBER(n) if (!lbm_check_argn_number(args, argn, n)) {return ENC_SYM_EERROR;}
130 
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 #endif
lbm_constants.h
lbm_uint
uint32_t lbm_uint
Definition: lbm_types.h:48
lbm_dec_sym
static lbm_uint lbm_dec_sym(lbm_value x)
Definition: heap.h:762
lbm_clr_extension
bool lbm_clr_extension(lbm_uint sym_id)
Definition: extensions.c:74
LBM_TYPE_SYMBOL
#define LBM_TYPE_SYMBOL
Definition: lbm_defines.h:76
lbm_extension_t::fptr
extension_fptr fptr
Definition: extensions.h:41
lbm_get_extension
extension_fptr lbm_get_extension(lbm_uint sym)
Definition: extensions.c:66
lbm_get_max_extensions
lbm_uint lbm_get_max_extensions(void)
Definition: extensions.c:58
lbm_check_number_all
bool lbm_check_number_all(lbm_value *args, lbm_uint argn)
Definition: extensions.c:139
lbm_extensions_default
lbm_value lbm_extensions_default(lbm_value *args, lbm_uint argn)
Definition: extensions.c:35
lbm_extension_t::name
char * name
Definition: extensions.h:42
lbm_check_true_false
bool lbm_check_true_false(lbm_value v)
Definition: extensions.c:133
lbm_check_argn
bool lbm_check_argn(lbm_uint argn, lbm_uint n)
Definition: extensions.c:147
lbm_get_num_extensions
lbm_uint lbm_get_num_extensions(void)
Definition: extensions.c:62
lbm_types.h
extension_fptr
lbm_value(* extension_fptr)(lbm_value *, lbm_uint)
Definition: extensions.h:36
lbm_extension_t
Definition: extensions.h:40
lbm_type_of
static lbm_type lbm_type_of(lbm_value x)
Definition: heap.h:663
lbm_add_extension
bool lbm_add_extension(char *sym_str, extension_fptr ext)
Definition: extensions.c:96
lbm_value
uint32_t lbm_value
Definition: lbm_types.h:44
lbm_is_extension
static bool lbm_is_extension(lbm_value exp)
Definition: extensions.h:96
lbm_check_argn_number
bool lbm_check_argn_number(lbm_value *args, lbm_uint argn, lbm_uint n)
Definition: extensions.c:156
extension_table
lbm_extension_t * extension_table
Definition: extensions.c:33
lbm_lookup_extension_id
bool lbm_lookup_extension_id(char *sym_str, lbm_uint *ix)
Definition: extensions.c:84
lbm_extensions_init
int lbm_extensions_init(lbm_extension_t *extension_storage, lbm_uint extension_storage_size)
Definition: extensions.c:41
heap.h