vm.h (78bc019d220e05abb5b12f678f9b4a847019bbcc) vm.h (d101cdd6edd782f6ec56eef63ed91abd77a8b317)
1/*
2 * *****************************************************************************
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 *
1/*
2 * *****************************************************************************
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 *
6 * Copyright (c) 2018-2021 Gavin D. Howard and contributors.
6 * Copyright (c) 2018-2023 Gavin D. Howard and contributors.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * * Redistributions of source code must retain the above copyright notice, this
12 * list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above copyright notice,

--- 58 unchanged lines hidden (view full) ---

73
74// CHAR_BIT must be at least 6, for various reasons. I might want to bump this
75// to 8 in the future.
76#if CHAR_BIT < 6
77#error CHAR_BIT must be at least 6.
78#endif
79
80// Set defaults.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * * Redistributions of source code must retain the above copyright notice, this
12 * list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above copyright notice,

--- 58 unchanged lines hidden (view full) ---

73
74// CHAR_BIT must be at least 6, for various reasons. I might want to bump this
75// to 8 in the future.
76#if CHAR_BIT < 6
77#error CHAR_BIT must be at least 6.
78#endif
79
80// Set defaults.
81//
82#ifndef BC_ENABLE_NLS
83#define BC_ENABLE_NLS (0)
84#endif // BC_ENABLE_NLS
85
86#ifndef MAINEXEC
87#define MAINEXEC bc
88#endif // MAINEXEC
89
90#ifndef _WIN32
91#ifndef EXECPREFIX
92#define EXECPREFIX

--- 81 unchanged lines hidden (view full) ---

174#define BC_FLAG_TTY (UINTMAX_C(1) << 11)
175
176/// The flag for reset on SIGINT.
177#define BC_FLAG_SIGINT (UINTMAX_C(1) << 12)
178
179/// The flag for exiting with expressions.
180#define BC_FLAG_EXPR_EXIT (UINTMAX_C(1) << 13)
181
81
82#ifndef MAINEXEC
83#define MAINEXEC bc
84#endif // MAINEXEC
85
86#ifndef _WIN32
87#ifndef EXECPREFIX
88#define EXECPREFIX

--- 81 unchanged lines hidden (view full) ---

170#define BC_FLAG_TTY (UINTMAX_C(1) << 11)
171
172/// The flag for reset on SIGINT.
173#define BC_FLAG_SIGINT (UINTMAX_C(1) << 12)
174
175/// The flag for exiting with expressions.
176#define BC_FLAG_EXPR_EXIT (UINTMAX_C(1) << 13)
177
178/// The flag for digit clamping.
179#define BC_FLAG_DIGIT_CLAMP (UINTMAX_C(1) << 14)
180
182/// A convenience macro for getting the TTYIN flag.
181/// A convenience macro for getting the TTYIN flag.
183#define BC_TTYIN (vm.flags & BC_FLAG_TTYIN)
182#define BC_TTYIN (vm->flags & BC_FLAG_TTYIN)
184
185/// A convenience macro for getting the TTY flag.
183
184/// A convenience macro for getting the TTY flag.
186#define BC_TTY (vm.flags & BC_FLAG_TTY)
185#define BC_TTY (vm->flags & BC_FLAG_TTY)
187
188/// A convenience macro for getting the SIGINT flag.
186
187/// A convenience macro for getting the SIGINT flag.
189#define BC_SIGINT (vm.flags & BC_FLAG_SIGINT)
188#define BC_SIGINT (vm->flags & BC_FLAG_SIGINT)
190
191#if BC_ENABLED
192
193/// A convenience macro for getting the POSIX error flag.
189
190#if BC_ENABLED
191
192/// A convenience macro for getting the POSIX error flag.
194#define BC_S (vm.flags & BC_FLAG_S)
193#define BC_S (vm->flags & BC_FLAG_S)
195
196/// A convenience macro for getting the POSIX warning flag.
194
195/// A convenience macro for getting the POSIX warning flag.
197#define BC_W (vm.flags & BC_FLAG_W)
196#define BC_W (vm->flags & BC_FLAG_W)
198
199/// A convenience macro for getting the math library flag.
197
198/// A convenience macro for getting the math library flag.
200#define BC_L (vm.flags & BC_FLAG_L)
199#define BC_L (vm->flags & BC_FLAG_L)
201
202/// A convenience macro for getting the global stacks flag.
200
201/// A convenience macro for getting the global stacks flag.
203#define BC_G (vm.flags & BC_FLAG_G)
202#define BC_G (vm->flags & BC_FLAG_G)
204
205#endif // BC_ENABLED
206
207#if DC_ENABLED
208
209/// A convenience macro for getting the extended register flag.
203
204#endif // BC_ENABLED
205
206#if DC_ENABLED
207
208/// A convenience macro for getting the extended register flag.
210#define DC_X (vm.flags & DC_FLAG_X)
209#define DC_X (vm->flags & DC_FLAG_X)
211
212#endif // DC_ENABLED
213
214/// A convenience macro for getting the interactive flag.
210
211#endif // DC_ENABLED
212
213/// A convenience macro for getting the interactive flag.
215#define BC_I (vm.flags & BC_FLAG_I)
214#define BC_I (vm->flags & BC_FLAG_I)
216
217/// A convenience macro for getting the prompt flag.
215
216/// A convenience macro for getting the prompt flag.
218#define BC_P (vm.flags & BC_FLAG_P)
217#define BC_P (vm->flags & BC_FLAG_P)
219
220/// A convenience macro for getting the read prompt flag.
218
219/// A convenience macro for getting the read prompt flag.
221#define BC_R (vm.flags & BC_FLAG_R)
220#define BC_R (vm->flags & BC_FLAG_R)
222
223/// A convenience macro for getting the leading zero flag.
221
222/// A convenience macro for getting the leading zero flag.
224#define BC_Z (vm.flags & BC_FLAG_Z)
223#define BC_Z (vm->flags & BC_FLAG_Z)
225
226/// A convenience macro for getting the expression exit flag.
224
225/// A convenience macro for getting the expression exit flag.
227#define BC_EXPR_EXIT (vm.flags & BC_FLAG_EXPR_EXIT)
226#define BC_EXPR_EXIT (vm->flags & BC_FLAG_EXPR_EXIT)
228
227
228/// A convenience macro for getting the digit clamp flag.
229#define BC_DIGIT_CLAMP (vm->flags & BC_FLAG_DIGIT_CLAMP)
230
229#if BC_ENABLED
230
231/// A convenience macro for checking if bc is in POSIX mode.
232#define BC_IS_POSIX (BC_S || BC_W)
233
234#if DC_ENABLED
235
236/// Returns true if bc is running.
231#if BC_ENABLED
232
233/// A convenience macro for checking if bc is in POSIX mode.
234#define BC_IS_POSIX (BC_S || BC_W)
235
236#if DC_ENABLED
237
238/// Returns true if bc is running.
237#define BC_IS_BC (vm.name[0] != 'd')
239#define BC_IS_BC (vm->name[0] != 'd')
238
239/// Returns true if dc is running.
240
241/// Returns true if dc is running.
240#define BC_IS_DC (vm.name[0] == 'd')
242#define BC_IS_DC (vm->name[0] == 'd')
241
243
244/// Returns the correct read prompt.
245#define BC_VM_READ_PROMPT (BC_IS_BC ? "read> " : "?> ")
246
247/// Returns the string for the line length environment variable.
248#define BC_VM_LINE_LENGTH_STR (BC_IS_BC ? "BC_LINE_LENGTH" : "DC_LINE_LENGTH")
249
250/// Returns the string for the environment args environment variable.
251#define BC_VM_ENV_ARGS_STR (BC_IS_BC ? "BC_ENV_ARGS" : "DC_ENV_ARGS")
252
253/// Returns the string for the expression exit environment variable.
254#define BC_VM_EXPR_EXIT_STR (BC_IS_BC ? "BC_EXPR_EXIT" : "DC_EXPR_EXIT")
255
256/// Returns the default for the expression exit environment variable.
257#define BC_VM_EXPR_EXIT_DEF \
258 (BC_IS_BC ? BC_DEFAULT_EXPR_EXIT : DC_DEFAULT_EXPR_EXIT)
259
260/// Returns the string for the digit clamp environment variable.
261#define BC_VM_DIGIT_CLAMP_STR (BC_IS_BC ? "BC_DIGIT_CLAMP" : "DC_DIGIT_CLAMP")
262
263/// Returns the default for the digit clamp environment variable.
264#define BC_VM_DIGIT_CLAMP_DEF \
265 (BC_IS_BC ? BC_DEFAULT_DIGIT_CLAMP : DC_DEFAULT_DIGIT_CLAMP)
266
267/// Returns the string for the TTY mode environment variable.
268#define BC_VM_TTY_MODE_STR (BC_IS_BC ? "BC_TTY_MODE" : "DC_TTY_MODE")
269
270/// Returns the default for the TTY mode environment variable.
271#define BC_VM_TTY_MODE_DEF \
272 (BC_IS_BC ? BC_DEFAULT_TTY_MODE : DC_DEFAULT_TTY_MODE)
273
274/// Returns the string for the prompt environment variable.
275#define BC_VM_PROMPT_STR (BC_IS_BC ? "BC_PROMPT" : "DC_PROMPT")
276
277/// Returns the default for the prompt environment variable.
278#define BC_VM_PROMPT_DEF (BC_IS_BC ? BC_DEFAULT_PROMPT : DC_DEFAULT_PROMPT)
279
280/// Returns the string for the SIGINT reset environment variable.
281#define BC_VM_SIGINT_RESET_STR \
282 (BC_IS_BC ? "BC_SIGINT_RESET" : "DC_SIGINT_RESET")
283
284/// Returns the string for the SIGINT reset environment variable.
285#define BC_VM_SIGINT_RESET_DEF \
286 (BC_IS_BC ? BC_DEFAULT_SIGINT_RESET : DC_DEFAULT_SIGINT_RESET)
287
288/// Returns true if the calculator should run stdin.
289#define BC_VM_RUN_STDIN(has_file) (BC_IS_BC || !(has_file))
290
242#else // DC_ENABLED
243
244/// Returns true if bc is running.
245#define BC_IS_BC (1)
246
247/// Returns true if dc is running.
248#define BC_IS_DC (0)
249
291#else // DC_ENABLED
292
293/// Returns true if bc is running.
294#define BC_IS_BC (1)
295
296/// Returns true if dc is running.
297#define BC_IS_DC (0)
298
299/// Returns the correct read prompt.
300#define BC_VM_READ_PROMPT ("read> ")
301
302/// Returns the string for the line length environment variable.
303#define BC_VM_LINE_LENGTH_STR ("BC_LINE_LENGTH")
304
305/// Returns the string for the environment args environment variable.
306#define BC_VM_ENV_ARGS_STR ("BC_ENV_ARGS")
307
308/// Returns the string for the expression exit environment variable.
309#define BC_VM_EXPR_EXIT_STR ("BC_EXPR_EXIT")
310
311/// Returns the default for the expression exit environment variable.
312#define BC_VM_EXPR_EXIT_DEF (BC_DEFAULT_EXPR_EXIT)
313
314/// Returns the string for the digit clamp environment variable.
315#define BC_VM_DIGIT_CLAMP_STR ("BC_DIGIT_CLAMP")
316
317/// Returns the default for the digit clamp environment variable.
318#define BC_VM_DIGIT_CLAMP_DEF (BC_DEFAULT_DIGIT_CLAMP)
319
320/// Returns the string for the TTY mode environment variable.
321#define BC_VM_TTY_MODE_STR ("BC_TTY_MODE")
322
323/// Returns the default for the TTY mode environment variable.
324#define BC_VM_TTY_MODE_DEF (BC_DEFAULT_TTY_MODE)
325
326/// Returns the string for the prompt environment variable.
327#define BC_VM_PROMPT_STR ("BC_PROMPT")
328
329/// Returns the default for the SIGINT reset environment variable.
330#define BC_VM_PROMPT_DEF (BC_DEFAULT_PROMPT)
331
332/// Returns the string for the SIGINT reset environment variable.
333#define BC_VM_SIGINT_RESET_STR ("BC_SIGINT_RESET")
334
335/// Returns the string for the SIGINT reset environment variable.
336#define BC_VM_SIGINT_RESET_DEF (BC_DEFAULT_SIGINT_RESET)
337
338/// Returns true if the calculator should run stdin.
339#define BC_VM_RUN_STDIN(has_file) (BC_IS_BC)
340
250#endif // DC_ENABLED
251
252#else // BC_ENABLED
253
254/// A convenience macro for checking if bc is in POSIX mode.
255#define BC_IS_POSIX (0)
256
257/// Returns true if bc is running.
258#define BC_IS_BC (0)
259
260/// Returns true if dc is running.
261#define BC_IS_DC (1)
262
341#endif // DC_ENABLED
342
343#else // BC_ENABLED
344
345/// A convenience macro for checking if bc is in POSIX mode.
346#define BC_IS_POSIX (0)
347
348/// Returns true if bc is running.
349#define BC_IS_BC (0)
350
351/// Returns true if dc is running.
352#define BC_IS_DC (1)
353
354/// Returns the correct read prompt.
355#define BC_VM_READ_PROMPT ("?> ")
356
357/// Returns the string for the line length environment variable.
358#define BC_VM_LINE_LENGTH_STR ("DC_LINE_LENGTH")
359
360/// Returns the string for the environment args environment variable.
361#define BC_VM_ENV_ARGS_STR ("DC_ENV_ARGS")
362
363/// Returns the string for the expression exit environment variable.
364#define BC_VM_EXPR_EXIT_STR ("DC_EXPR_EXIT")
365
366/// Returns the default for the expression exit environment variable.
367#define BC_VM_EXPR_EXIT_DEF (DC_DEFAULT_EXPR_EXIT)
368
369/// Returns the string for the digit clamp environment variable.
370#define BC_VM_DIGIT_CLAMP_STR ("DC_DIGIT_CLAMP")
371
372/// Returns the default for the digit clamp environment variable.
373#define BC_VM_DIGIT_CLAMP_DEF (DC_DEFAULT_DIGIT_CLAMP)
374
375/// Returns the string for the TTY mode environment variable.
376#define BC_VM_TTY_MODE_STR ("DC_TTY_MODE")
377
378/// Returns the default for the TTY mode environment variable.
379#define BC_VM_TTY_MODE_DEF (DC_DEFAULT_TTY_MODE)
380
381/// Returns the string for the prompt environment variable.
382#define BC_VM_PROMPT_STR ("DC_PROMPT")
383
384/// Returns the default for the SIGINT reset environment variable.
385#define BC_VM_PROMPT_DEF (DC_DEFAULT_PROMPT)
386
387/// Returns the string for the SIGINT reset environment variable.
388#define BC_VM_SIGINT_RESET_STR ("DC_SIGINT_RESET")
389
390/// Returns the string for the SIGINT reset environment variable.
391#define BC_VM_SIGINT_RESET_DEF (DC_DEFAULT_SIGINT_RESET)
392
393/// Returns true if the calculator should run stdin.
394#define BC_VM_RUN_STDIN(has_file) (!(has_file))
395
263#endif // BC_ENABLED
264
265/// A convenience macro for checking if the prompt is enabled.
266#define BC_PROMPT (BC_P)
267
268#else // !BC_ENABLE_LIBRARY
269
396#endif // BC_ENABLED
397
398/// A convenience macro for checking if the prompt is enabled.
399#define BC_PROMPT (BC_P)
400
401#else // !BC_ENABLE_LIBRARY
402
270#define BC_Z (vm.leading_zeroes)
403#define BC_Z (vm->leading_zeroes)
271
404
405#define BC_DIGIT_CLAMP (vm->digit_clamp)
406
272#endif // !BC_ENABLE_LIBRARY
273
274/**
275 * Returns the max of its two arguments. This evaluates arguments twice, so be
276 * careful what args you give it.
277 * @param a The first argument.
278 * @param b The second argument.
279 * @return The max of the two arguments.

--- 152 unchanged lines hidden (view full) ---

432 BclError err;
433
434 /// Whether or not bcl should abort on fatal errors.
435 bool abrt;
436
437 /// Whether or not to print leading zeros.
438 bool leading_zeroes;
439
407#endif // !BC_ENABLE_LIBRARY
408
409/**
410 * Returns the max of its two arguments. This evaluates arguments twice, so be
411 * careful what args you give it.
412 * @param a The first argument.
413 * @param b The second argument.
414 * @return The max of the two arguments.

--- 152 unchanged lines hidden (view full) ---

567 BclError err;
568
569 /// Whether or not bcl should abort on fatal errors.
570 bool abrt;
571
572 /// Whether or not to print leading zeros.
573 bool leading_zeroes;
574
575 /// Whether or not to clamp digits that are greater than or equal to the
576 /// current ibase.
577 bool digit_clamp;
578
440 /// The number of "references," or times that the library was initialized.
441 unsigned int refs;
442
579 /// The number of "references," or times that the library was initialized.
580 unsigned int refs;
581
443 /// Non-zero if bcl is running. This is volatile sig_atomic_t because it is
444 /// also used in the signal handler. See the development manual
445 /// (manuals/development.md#async-signal-safe-signal-handling) for more
446 /// information.
447 volatile sig_atomic_t running;
582#else // BC_ENABLE_LIBRARY
448
583
449#endif // BC_ENABLE_LIBRARY
450
451#if !BC_ENABLE_LIBRARY
452
453 /// A pointer to the filename of the current file. This is not owned by the
454 /// BcVm struct.
455 const char* file;
456
457 /// The message printed when SIGINT happens.
458 const char* sigmsg;
459
584 /// A pointer to the filename of the current file. This is not owned by the
585 /// BcVm struct.
586 const char* file;
587
588 /// The message printed when SIGINT happens.
589 const char* sigmsg;
590
460#endif // !BC_ENABLE_LIBRARY
461
462 /// Non-zero when signals are "locked." This is volatile sig_atomic_t
463 /// because it is also used in the signal handler. See the development
464 /// manual (manuals/development.md#async-signal-safe-signal-handling) for
465 /// more information.
466 volatile sig_atomic_t sig_lock;
467
468 /// Non-zero when a signal has been received, but not acted on. This is
469 /// volatile sig_atomic_t because it is also used in the signal handler. See
470 /// the development manual
471 /// (manuals/development.md#async-signal-safe-signal-handling) for more
472 /// information.
473 volatile sig_atomic_t sig;
474
591 /// Non-zero when signals are "locked." This is volatile sig_atomic_t
592 /// because it is also used in the signal handler. See the development
593 /// manual (manuals/development.md#async-signal-safe-signal-handling) for
594 /// more information.
595 volatile sig_atomic_t sig_lock;
596
597 /// Non-zero when a signal has been received, but not acted on. This is
598 /// volatile sig_atomic_t because it is also used in the signal handler. See
599 /// the development manual
600 /// (manuals/development.md#async-signal-safe-signal-handling) for more
601 /// information.
602 volatile sig_atomic_t sig;
603
475#if !BC_ENABLE_LIBRARY
476
477 /// The length of sigmsg.
478 uchar siglen;
479
480 /// The instruction used for returning from a read() call.
481 uchar read_ret;
482
483 /// The flags field used by most macros above.
484 uint16_t flags;

--- 11 unchanged lines hidden (view full) ---

496 bool no_exprs;
497
498 /// True if bc should exit if expresions are encountered.
499 bool exit_exprs;
500
501 /// True if EOF was encountered.
502 bool eof;
503
604 /// The length of sigmsg.
605 uchar siglen;
606
607 /// The instruction used for returning from a read() call.
608 uchar read_ret;
609
610 /// The flags field used by most macros above.
611 uint16_t flags;

--- 11 unchanged lines hidden (view full) ---

623 bool no_exprs;
624
625 /// True if bc should exit if expresions are encountered.
626 bool exit_exprs;
627
628 /// True if EOF was encountered.
629 bool eof;
630
504 /// True if bc is currently reading from stdin.
505 bool is_stdin;
631 /// The mode that the program is in.
632 uchar mode;
506
507#if BC_ENABLED
508
509 /// True if keywords should not be redefined. This is only true for the
510 /// builtin math libraries for bc.
511 bool no_redefine;
512
513#endif // BC_ENABLED
514
633
634#if BC_ENABLED
635
636 /// True if keywords should not be redefined. This is only true for the
637 /// builtin math libraries for bc.
638 bool no_redefine;
639
640#endif // BC_ENABLED
641
515#endif // !BC_ENABLE_LIBRARY
516
517 /// An array of maxes for the globals.
518 BcBigDig maxes[BC_PROG_GLOBALS_LEN + BC_ENABLE_EXTRA_MATH];
519
520#if !BC_ENABLE_LIBRARY
521
522 /// A vector of filenames to process.
523 BcVec files;
524
525 /// A vector of expressions to process.
526 BcVec exprs;
527
528 /// The name of the calculator under use. This is used by BC_IS_BC and
529 /// BC_IS_DC.

--- 13 unchanged lines hidden (view full) ---

543 BcLexNext next;
544
545 /// The function to call to parse.
546 BcParseParse parse;
547
548 /// The function to call to parse expressions.
549 BcParseExpr expr;
550
642 /// A vector of filenames to process.
643 BcVec files;
644
645 /// A vector of expressions to process.
646 BcVec exprs;
647
648 /// The name of the calculator under use. This is used by BC_IS_BC and
649 /// BC_IS_DC.

--- 13 unchanged lines hidden (view full) ---

663 BcLexNext next;
664
665 /// The function to call to parse.
666 BcParseParse parse;
667
668 /// The function to call to parse expressions.
669 BcParseExpr expr;
670
551 /// The text to display to label functions in error messages.
552 const char* func_header;
553
554 /// The names of the categories of errors.
555 const char* err_ids[BC_ERR_IDX_NELEMS + BC_ENABLED];
556
557 /// The messages for each error.
558 const char* err_msgs[BC_ERR_NELEMS];
559
560#if BC_ENABLE_NLS
561 /// The locale.
562 const char* locale;
563#endif // BC_ENABLE_NLS
564
671 /// The names of the categories of errors.
672 const char* err_ids[BC_ERR_IDX_NELEMS + BC_ENABLED];
673
674 /// The messages for each error.
675 const char* err_msgs[BC_ERR_NELEMS];
676
677#if BC_ENABLE_NLS
678 /// The locale.
679 const char* locale;
680#endif // BC_ENABLE_NLS
681
565#endif // !BC_ENABLE_LIBRARY
682#endif // BC_ENABLE_LIBRARY
566
683
684 /// An array of maxes for the globals.
685 BcBigDig maxes[BC_PROG_GLOBALS_LEN + BC_ENABLE_EXTRA_MATH];
686
567 /// The last base used to parse.
568 BcBigDig last_base;
569
570 /// The last power of last_base used to parse.
571 BcBigDig last_pow;
572
573 /// The last exponent of base that equals last_pow.
574 BcBigDig last_exp;

--- 52 unchanged lines hidden (view full) ---

627#endif // BC_ENABLE_NLS
628
629 /// A pointer to the stdin buffer.
630 char* buf;
631
632 /// The number of items in the input buffer.
633 size_t buf_len;
634
687 /// The last base used to parse.
688 BcBigDig last_base;
689
690 /// The last power of last_base used to parse.
691 BcBigDig last_pow;
692
693 /// The last exponent of base that equals last_pow.
694 BcBigDig last_exp;

--- 52 unchanged lines hidden (view full) ---

747#endif // BC_ENABLE_NLS
748
749 /// A pointer to the stdin buffer.
750 char* buf;
751
752 /// The number of items in the input buffer.
753 size_t buf_len;
754
635 /// The slab for constants in the main function. This is separate for
636 /// garbage collection reasons.
637 BcVec main_const_slab;
755 /// The slabs vector for constants, strings, function names, and other
756 /// string-like things.
757 BcVec slabs;
638
758
639 //// The slab for all other strings for the main function.
640 BcVec main_slabs;
641
642 /// The slab for function names, strings in other functions, and constants
643 /// in other functions.
644 BcVec other_slabs;
645
646#if BC_ENABLED
647
648 /// An array of booleans for which bc keywords have been redefined if
649 /// BC_REDEFINE_KEYWORDS is non-zero.
650 bool redefined_kws[BC_LEX_NKWS];
651
652#endif // BC_ENABLED
653#endif // !BC_ENABLE_LIBRARY
654
759#if BC_ENABLED
760
761 /// An array of booleans for which bc keywords have been redefined if
762 /// BC_REDEFINE_KEYWORDS is non-zero.
763 bool redefined_kws[BC_LEX_NKWS];
764
765#endif // BC_ENABLED
766#endif // !BC_ENABLE_LIBRARY
767
768 BcDig* temps_buf[BC_VM_MAX_TEMPS];
769
655#if BC_DEBUG_CODE
656
657 /// The depth for BC_FUNC_ENTER and BC_FUNC_EXIT.
658 size_t func_depth;
659
660#endif // BC_DEBUG_CODE
661
662} BcVm;

--- 29 unchanged lines hidden (view full) ---

692/**
693 * Add a temp to the temp array.
694 * @param num The BcDig array to add to the temp array.
695 */
696void
697bc_vm_addTemp(BcDig* num);
698
699/**
770#if BC_DEBUG_CODE
771
772 /// The depth for BC_FUNC_ENTER and BC_FUNC_EXIT.
773 size_t func_depth;
774
775#endif // BC_DEBUG_CODE
776
777} BcVm;

--- 29 unchanged lines hidden (view full) ---

807/**
808 * Add a temp to the temp array.
809 * @param num The BcDig array to add to the temp array.
810 */
811void
812bc_vm_addTemp(BcDig* num);
813
814/**
700 * Dish out a temp, or NULL if there are none.
815 * Return the temp on the top of the temp stack, or NULL if there are none.
701 * @return A temp, or NULL if none exist.
702 */
703BcDig*
704bc_vm_takeTemp(void);
705
706/**
816 * @return A temp, or NULL if none exist.
817 */
818BcDig*
819bc_vm_takeTemp(void);
820
821/**
822 * Gets the top temp of the temp stack. This is separate from bc_vm_takeTemp()
823 * to quiet a GCC warning about longjmp() clobbering in bc_num_init().
824 * @return A temp, or NULL if none exist.
825 */
826BcDig*
827bc_vm_getTemp(void);
828
829/**
707 * Frees all temporaries.
708 */
709void
710bc_vm_freeTemps(void);
711
830 * Frees all temporaries.
831 */
832void
833bc_vm_freeTemps(void);
834
712#if !BC_ENABLE_HISTORY || BC_ENABLE_LINE_LIB
835#if !BC_ENABLE_HISTORY || BC_ENABLE_LINE_LIB || BC_ENABLE_LIBRARY
713
714/**
715 * Erases the flush argument if history does not exist because it does not
716 * matter if history does not exist.
717 */
836
837/**
838 * Erases the flush argument if history does not exist because it does not
839 * matter if history does not exist.
840 */
718#define bc_vm_putchar(c, t) bc_vm_putchar(c)
841#define bc_vm_putchar(c, t) bc_vm_putchar_impl(c)
719
842
720#endif // !BC_ENABLE_HISTORY || BC_ENABLE_LINE_LIB
843#else // !BC_ENABLE_HISTORY || BC_ENABLE_LINE_LIB || BC_ENABLE_LIBRARY
721
844
845// This is here to satisfy a clang warning about recursive macros.
846#define bc_vm_putchar(c, t) bc_vm_putchar_impl(c, t)
847
848#endif // !BC_ENABLE_HISTORY || BC_ENABLE_LINE_LIB || BC_ENABLE_LIBRARY
849
722/**
723 * Print to stdout with limited formating.
724 * @param fmt The format string.
725 */
726void
727bc_vm_printf(const char* fmt, ...);
728
729/**

--- 91 unchanged lines hidden (view full) ---

821#if BC_DEBUG_CODE
822
823/**
824 * Start executing a jump series.
825 * @param f The name of the function that started the jump series.
826 */
827void
828bc_vm_jmp(const char* f);
850/**
851 * Print to stdout with limited formating.
852 * @param fmt The format string.
853 */
854void
855bc_vm_printf(const char* fmt, ...);
856
857/**

--- 91 unchanged lines hidden (view full) ---

949#if BC_DEBUG_CODE
950
951/**
952 * Start executing a jump series.
953 * @param f The name of the function that started the jump series.
954 */
955void
956bc_vm_jmp(const char* f);
957
829#else // BC_DEBUG_CODE
830
831/**
832 * Start executing a jump series.
833 */
834void
835bc_vm_jmp(void);
836

--- 21 unchanged lines hidden (view full) ---

858 * A function to call at exit.
859 */
860void
861bc_vm_atexit(void);
862
863#else // BC_ENABLE_LIBRARY
864
865/**
958#else // BC_DEBUG_CODE
959
960/**
961 * Start executing a jump series.
962 */
963void
964bc_vm_jmp(void);
965

--- 21 unchanged lines hidden (view full) ---

987 * A function to call at exit.
988 */
989void
990bc_vm_atexit(void);
991
992#else // BC_ENABLE_LIBRARY
993
994/**
995 * Calculates the number of decimal digits in the argument.
996 * @param val The value to calculate the number of decimal digits in.
997 * @return The number of decimal digits in @a val.
998 */
999size_t
1000bc_vm_numDigits(size_t val);
1001
1002#ifndef NDEBUG
1003
1004/**
866 * Handle an error. This is the true error handler. It will start a jump series
867 * if an error occurred. POSIX errors will not cause jumps when warnings are on
868 * or no POSIX errors are enabled.
1005 * Handle an error. This is the true error handler. It will start a jump series
1006 * if an error occurred. POSIX errors will not cause jumps when warnings are on
1007 * or no POSIX errors are enabled.
1008 * @param e The error.
1009 * @param file The source file where the error occurred.
1010 * @param fline The line in the source file where the error occurred.
1011 * @param line The bc source line where the error occurred.
1012 */
1013void
1014bc_vm_handleError(BcErr e, const char* file, int fline, size_t line, ...);
1015
1016#else // NDEBUG
1017
1018/**
1019 * Handle an error. This is the true error handler. It will start a jump series
1020 * if an error occurred. POSIX errors will not cause jumps when warnings are on
1021 * or no POSIX errors are enabled.
869 * @param e The error.
1022 * @param e The error.
870 * @param line The source line where the error occurred.
1023 * @param line The bc source line where the error occurred.
871 */
872void
873bc_vm_handleError(BcErr e, size_t line, ...);
874
1024 */
1025void
1026bc_vm_handleError(BcErr e, size_t line, ...);
1027
1028#endif // NDEBUG
1029
875/**
876 * Handle a fatal error.
877 * @param e The error.
878 */
879#if !BC_ENABLE_MEMCHECK
880BC_NORETURN
881#endif // !BC_ENABLE_MEMCHECK
882void

--- 5 unchanged lines hidden (view full) ---

888 */
889int
890bc_vm_atexit(int status);
891#endif // BC_ENABLE_LIBRARY
892
893/// A reference to the copyright header.
894extern const char bc_copyright[];
895
1030/**
1031 * Handle a fatal error.
1032 * @param e The error.
1033 */
1034#if !BC_ENABLE_MEMCHECK
1035BC_NORETURN
1036#endif // !BC_ENABLE_MEMCHECK
1037void

--- 5 unchanged lines hidden (view full) ---

1043 */
1044int
1045bc_vm_atexit(int status);
1046#endif // BC_ENABLE_LIBRARY
1047
1048/// A reference to the copyright header.
1049extern const char bc_copyright[];
1050
896/// A reference to the format string for source code line printing.
897extern const char* const bc_err_line;
898
899/// A reference to the format string for source code function printing.
900extern const char* const bc_err_func_header;
901
902/// A reference to the array of default error category names.
903extern const char* bc_errs[];
904
905/// A reference to the array of error category indices for each error.
906extern const uchar bc_err_ids[];
907
908/// A reference to the array of default error messages.
909extern const char* const bc_err_msgs[];

--- 6 unchanged lines hidden (view full) ---

916/// A reference to the end pledge() promises when using history.
917extern const char bc_pledge_end_history[];
918
919#endif // BC_ENABLE_HISTORY
920
921/// A reference to the end pledge() promises when *not* using history.
922extern const char bc_pledge_end[];
923
1051/// A reference to the array of default error category names.
1052extern const char* bc_errs[];
1053
1054/// A reference to the array of error category indices for each error.
1055extern const uchar bc_err_ids[];
1056
1057/// A reference to the array of default error messages.
1058extern const char* const bc_err_msgs[];

--- 6 unchanged lines hidden (view full) ---

1065/// A reference to the end pledge() promises when using history.
1066extern const char bc_pledge_end_history[];
1067
1068#endif // BC_ENABLE_HISTORY
1069
1070/// A reference to the end pledge() promises when *not* using history.
1071extern const char bc_pledge_end[];
1072
1073#if !BC_ENABLE_LIBRARY
1074
924/// A reference to the global data.
1075/// A reference to the global data.
925extern BcVm vm;
1076extern BcVm* vm;
926
1077
1078/// The global data.
1079extern BcVm vm_data;
1080
927/// A reference to the global output buffers.
928extern char output_bufs[BC_VM_BUF_SIZE];
929
1081/// A reference to the global output buffers.
1082extern char output_bufs[BC_VM_BUF_SIZE];
1083
1084#endif // !BC_ENABLE_LIBRARY
1085
930#endif // BC_VM_H
1086#endif // BC_VM_H