2 * *****************************************************************************
4 * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright (c) 2018-2020 Gavin D. Howard and contributors.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * * Redistributions of source code must retain the above copyright notice, this
12 * list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * *****************************************************************************
32 * Definitions for program data.
46 #define BC_INST_IS_ASSIGN(i) \
47 ((i) == BC_INST_ASSIGN || (i) == BC_INST_ASSIGN_NO_VAL)
48 #define BC_INST_USE_VAL(i) ((i) <= BC_INST_ASSIGN)
50 #define BC_INST_IS_ASSIGN(i) ((i) == BC_INST_ASSIGN_NO_VAL)
51 #define BC_INST_USE_VAL(i) (false)
55 #define BC_ENABLE_FUNC_FREE (1)
57 #define BC_ENABLE_FUNC_FREE DC_ENABLED
69 #if BC_ENABLE_EXTRA_MATH
71 #endif // BC_ENABLE_EXTRA_MATH
80 #if BC_ENABLE_EXTRA_MATH
85 #endif // BC_ENABLE_EXTRA_MATH
99 BC_INST_ASSIGN_MULTIPLY,
100 BC_INST_ASSIGN_DIVIDE,
101 BC_INST_ASSIGN_MODULUS,
103 BC_INST_ASSIGN_MINUS,
104 #if BC_ENABLE_EXTRA_MATH
105 BC_INST_ASSIGN_PLACES,
106 BC_INST_ASSIGN_LSHIFT,
107 BC_INST_ASSIGN_RSHIFT,
108 #endif // BC_ENABLE_EXTRA_MATH
111 BC_INST_ASSIGN_POWER_NO_VAL,
112 BC_INST_ASSIGN_MULTIPLY_NO_VAL,
113 BC_INST_ASSIGN_DIVIDE_NO_VAL,
114 BC_INST_ASSIGN_MODULUS_NO_VAL,
115 BC_INST_ASSIGN_PLUS_NO_VAL,
116 BC_INST_ASSIGN_MINUS_NO_VAL,
117 #if BC_ENABLE_EXTRA_MATH
118 BC_INST_ASSIGN_PLACES_NO_VAL,
119 BC_INST_ASSIGN_LSHIFT_NO_VAL,
120 BC_INST_ASSIGN_RSHIFT_NO_VAL,
121 #endif // BC_ENABLE_EXTRA_MATH
123 BC_INST_ASSIGN_NO_VAL,
141 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
143 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
148 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
150 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
152 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
154 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
158 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
160 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
191 BC_INST_PRINT_STREAM,
207 BC_INST_INVALID = UCHAR_MAX,
211 typedef struct BcId {
216 typedef struct BcLoc {
221 typedef struct BcConst {
227 typedef struct BcFunc {
246 typedef enum BcResultType {
249 BC_RESULT_ARRAY_ELEM,
268 #if BC_ENABLE_EXTRA_MATH
270 #endif // BC_ENABLE_EXTRA_MATH
274 typedef union BcResultData {
280 typedef struct BcResult {
285 typedef struct BcInstPtr {
291 typedef enum BcType {
301 void bc_func_init(BcFunc *f, const char* name);
302 void bc_func_insert(BcFunc *f, struct BcProgram* p, char* name,
303 BcType type, size_t line);
304 void bc_func_reset(BcFunc *f);
305 void bc_func_free(void *func);
307 void bc_array_init(BcVec *a, bool nums);
308 void bc_array_copy(BcVec *d, const BcVec *s);
310 void bc_string_free(void *string);
311 void bc_const_free(void *constant);
312 void bc_id_free(void *id);
313 void bc_result_clear(BcResult *r);
314 void bc_result_copy(BcResult *d, BcResult *src);
315 void bc_result_free(void *result);
317 void bc_array_expand(BcVec *a, size_t len);
318 int bc_id_cmp(const BcId *e1, const BcId *e2);
321 extern const char* bc_inst_names[];
322 #endif // BC_DEBUG_CODE
324 extern const char bc_func_main[];
325 extern const char bc_func_read[];