1 /*************************************************************************
2 * Copyright (C) 2024 Francesco Palumbo <phranz.dev@gmail.com>, Naples (Italy)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 *************************************************************************/
21 #define EV_QUITCALLED 1
22 #define EV_BREAK (1 << 1)
23 #define EV_RETURN (1 << 2)
25 #define err(S, L, M, ...) \
27 debug("-- ERROR --"); \
28 if (strace->count) { \
29 fprintf(stderr, "<<<< stack trace >>>:\n"); \
32 fprintf(stderr, " '%s(...)' at '%lu'\n", trace->key, trace->val); \
37 fprintf(stderr, M, ## __VA_ARGS__); \
41 #define warn(S, L, M, ...) \
45 fprintf(stderr, M, ## __VA_ARGS__); \
48 #define assert_block(A, I, F) if (A->type != T_BLOCK) err(A->source, A->lineno, "error, '%s' %s argument must be a block!\n", F, I)
49 #define assert_notblock(A, I, F) if (A->type == T_BLOCK) err(A->source, A->lineno, "error, '%s' %s argument cannot be a block!\n", F, I)
51 typedef struct token_t token_t
;
52 typedef struct vec_token_t phrase_t
;
53 typedef struct vec_str_t vec_str_t
;
54 typedef struct vec_strline_t vec_strlint_t
;
56 typedef struct map_strstr_t map_strstr_t
;
57 typedef struct map_strint_t map_strint_t
;
59 typedef struct scope_t
{
60 map_strtoken_t
* memos
;
61 void (*free
)(struct scope_t
*);
64 typedef struct block_t
{
67 void (*free
)(struct block_t
*);
70 scope_t
* scope_t_init();
71 scope_t
* copy_scope(scope_t
*);
73 block_t
* block_t_init();
74 block_t
* copy_block(block_t
*);
76 void evaluator_init();
77 void evaluator_free();
79 vec_token_t
* parse(phrase_t
*);
80 size_t eval_expressions(vec_token_t
*, vec_token_t
*);
81 size_t eval_statements(vec_token_t
*, vec_token_t
*);
82 token_t
* repr(token_t
*, int);
83 long tolong(token_t
*);
84 void define(token_t
*, token_t
*, scope_t
*, vec_token_t
*);
86 int trigger(unsigned long, int);