diff options
| author | Stefan Eßer <se@FreeBSD.org> | 2023-01-28 20:02:27 +0000 |
|---|---|---|
| committer | Stefan Eßer <se@FreeBSD.org> | 2023-01-28 20:02:27 +0000 |
| commit | e7017237c9d842b4cebdcfb13526cd71a2b2836a (patch) | |
| tree | 9b947d28ee94ab6b413bebb96a7d040873038c0d /include | |
| parent | 0b671e8cf134e605567a6b8091958c1f1dfc5140 (diff) | |
Diffstat (limited to 'include')
| -rw-r--r-- | include/args.h | 2 | ||||
| -rw-r--r-- | include/bc.h | 2 | ||||
| -rw-r--r-- | include/bcl.h | 2 | ||||
| -rw-r--r-- | include/dc.h | 2 | ||||
| -rw-r--r-- | include/file.h | 2 | ||||
| -rw-r--r-- | include/history.h | 2 | ||||
| -rw-r--r-- | include/lang.h | 2 | ||||
| -rw-r--r-- | include/lex.h | 26 | ||||
| -rw-r--r-- | include/library.h | 2 | ||||
| -rw-r--r-- | include/num.h | 2 | ||||
| -rw-r--r-- | include/opt.h | 2 | ||||
| -rw-r--r-- | include/parse.h | 16 | ||||
| -rw-r--r-- | include/program.h | 9 | ||||
| -rw-r--r-- | include/rand.h | 2 | ||||
| -rw-r--r-- | include/read.h | 2 | ||||
| -rw-r--r-- | include/status.h | 32 | ||||
| -rw-r--r-- | include/vector.h | 2 | ||||
| -rw-r--r-- | include/version.h | 4 | ||||
| -rw-r--r-- | include/vm.h | 40 |
19 files changed, 115 insertions, 38 deletions
diff --git a/include/args.h b/include/args.h index 515e53b1e891..3174ba267590 100644 --- a/include/args.h +++ b/include/args.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/include/bc.h b/include/bc.h index 5e879e83a987..73a85aa406a0 100644 --- a/include/bc.h +++ b/include/bc.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/include/bcl.h b/include/bcl.h index 0a6f43700797..234fe475f00e 100644 --- a/include/bcl.h +++ b/include/bcl.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/include/dc.h b/include/dc.h index 42cd842b57ce..9a603c26d1a5 100644 --- a/include/dc.h +++ b/include/dc.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/include/file.h b/include/file.h index d6b7c4e56f85..95cfa861a734 100644 --- a/include/file.h +++ b/include/file.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/include/history.h b/include/history.h index 495b315cc311..19c5a0fe27f7 100644 --- a/include/history.h +++ b/include/history.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/include/lang.h b/include/lang.h index 396fc8a4b34c..4ad6df88f5ed 100644 --- a/include/lang.h +++ b/include/lang.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/include/lex.h b/include/lex.h index 160c0f114855..54d704f8b447 100644 --- a/include/lex.h +++ b/include/lex.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -43,10 +43,30 @@ #include <vector.h> #include <lang.h> -// Two convencience macros for throwing errors in lex code. They take care of -// plumbing like passing in the current line the lexer is on. +/** + * A convenience macro for throwing errors in lex code. This takes care of + * plumbing like passing in the current line the lexer is on. + * @param l The lexer. + * @param e The error. + */ +#ifndef NDEBUG +#define bc_lex_err(l, e) (bc_vm_handleError((e), __FILE__, __LINE__, (l)->line)) +#else // NDEBUG #define bc_lex_err(l, e) (bc_vm_handleError((e), (l)->line)) +#endif // NDEBUG + +/** + * A convenience macro for throwing errors in lex code. This takes care of + * plumbing like passing in the current line the lexer is on. + * @param l The lexer. + * @param e The error. + */ +#ifndef NDEBUG +#define bc_lex_verr(l, e, ...) \ + (bc_vm_handleError((e), __FILE__, __LINE__, (l)->line, __VA_ARGS__)) +#else // NDEBUG #define bc_lex_verr(l, e, ...) (bc_vm_handleError((e), (l)->line, __VA_ARGS__)) +#endif // NDEBUG // BC_LEX_NEG_CHAR returns the char that corresponds to negative for the // current calculator. diff --git a/include/library.h b/include/library.h index 2984de29d208..76df91392da1 100644 --- a/include/library.h +++ b/include/library.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/include/num.h b/include/num.h index 835dd8e97478..8078809250f8 100644 --- a/include/num.h +++ b/include/num.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/include/opt.h b/include/opt.h index 3c465c80fbf6..28d9d99a7856 100644 --- a/include/opt.h +++ b/include/opt.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/include/parse.h b/include/parse.h index ebf234c5f7f9..2527aeb824f8 100644 --- a/include/parse.h +++ b/include/parse.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -105,22 +105,32 @@ #define bc_parse_pushIndex(p, idx) (bc_vec_pushIndex(&(p)->func->code, (idx))) /** - * A convenience macro for throwing errors in parse code. They take care of + * A convenience macro for throwing errors in parse code. This takes care of * plumbing like passing in the current line the lexer is on. * @param p The parser. * @param e The error. */ +#ifndef NDEBUG +#define bc_parse_err(p, e) \ + (bc_vm_handleError((e), __FILE__, __LINE__, (p)->l.line)) +#else // NDEBUG #define bc_parse_err(p, e) (bc_vm_handleError((e), (p)->l.line)) +#endif // NDEBUG /** - * A convenience macro for throwing errors in parse code. They take care of + * A convenience macro for throwing errors in parse code. This takes care of * plumbing like passing in the current line the lexer is on. * @param p The parser. * @param e The error. * @param ... The varags that are needed. */ +#ifndef NDEBUG +#define bc_parse_verr(p, e, ...) \ + (bc_vm_handleError((e), __FILE__, __LINE__, (p)->l.line, __VA_ARGS__)) +#else // NDEBUG #define bc_parse_verr(p, e, ...) \ (bc_vm_handleError((e), (p)->l.line, __VA_ARGS__)) +#endif // NDEBUG // Forward declarations. struct BcParse; diff --git a/include/program.h b/include/program.h index 62e867eb7fb8..3acd5157b127 100644 --- a/include/program.h +++ b/include/program.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -320,6 +320,13 @@ bc_program_free(BcProgram* p); #endif // NDEBUG +/** + * Prints a stack trace of the bc functions or dc strings currently executing. + * @param p The program. + */ +void +bc_program_printStackTrace(BcProgram* p); + #if BC_DEBUG_CODE #if BC_ENABLED && DC_ENABLED diff --git a/include/rand.h b/include/rand.h index 7546891dbd64..7db0ee90af1f 100644 --- a/include/rand.h +++ b/include/rand.h @@ -13,7 +13,7 @@ * This code is under the following license: * * Copyright (c) 2014-2017 Melissa O'Neill and PCG Project contributors - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/include/read.h b/include/read.h index 0e824d941b50..867dcd7433a3 100644 --- a/include/read.h +++ b/include/read.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/include/status.h b/include/status.h index ce6251ab0c1d..9962d58d0be0 100644 --- a/include/status.h +++ b/include/status.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -687,11 +687,18 @@ typedef enum BcMode /// Returns true if an exception is in flight, false otherwise. #define BC_SIG_EXC(vm) \ - BC_UNLIKELY(vm->status != (sig_atomic_t) BC_STATUS_SUCCESS || vm->sig) + BC_UNLIKELY((vm)->status != (sig_atomic_t) BC_STATUS_SUCCESS || (vm)->sig) /// Returns true if there is *no* exception in flight, false otherwise. #define BC_NO_SIG_EXC(vm) \ - BC_LIKELY(vm->status == (sig_atomic_t) BC_STATUS_SUCCESS && !vm->sig) + BC_LIKELY((vm)->status == (sig_atomic_t) BC_STATUS_SUCCESS && !(vm)->sig) + +#ifndef _WIN32 +#define BC_SIG_INTERRUPT(vm) \ + BC_UNLIKELY((vm)->sig != 0 && (vm)->sig != SIGWINCH) +#else // _WIN32 +#define BC_SIG_INTERRUPT(vm) BC_UNLIKELY((vm)->sig != 0) +#endif // _WIN32 #ifndef NDEBUG @@ -773,7 +780,7 @@ typedef enum BcMode } \ while (0) -/* +/** * Locks signals, but stores the old lock state, to be restored later by * BC_SIG_TRYUNLOCK. * @param v The variable to store the old lock state to. @@ -786,7 +793,8 @@ typedef enum BcMode } \ while (0) -/* Restores the previous state of a signal lock, and if it is now unlocked, +/** + * Restores the previous state of a signal lock, and if it is now unlocked, * initiates an exception/jump. * @param v The old lock state. */ @@ -949,19 +957,33 @@ typedef enum BcMode * @param l The line of the script that the error happened. * @param ... Extra arguments for error messages as necessary. */ +#ifndef NDEBUG +#define bc_error(e, l, ...) \ + (bc_vm_handleError((e), __FILE__, __LINE__, (l), __VA_ARGS__)) +#else // NDEBUG #define bc_error(e, l, ...) (bc_vm_handleError((e), (l), __VA_ARGS__)) +#endif // NDEBUG /** * Call bc's error handling routine. * @param e The error. */ +#ifndef NDEBUG +#define bc_err(e) (bc_vm_handleError((e), __FILE__, __LINE__, 0)) +#else // NDEBUG #define bc_err(e) (bc_vm_handleError((e), 0)) +#endif // NDEBUG /** * Call bc's error handling routine. * @param e The error. */ +#ifndef NDEBUG +#define bc_verr(e, ...) \ + (bc_vm_handleError((e), __FILE__, __LINE__, 0, __VA_ARGS__)) +#else // NDEBUG #define bc_verr(e, ...) (bc_vm_handleError((e), 0, __VA_ARGS__)) +#endif // NDEBUG #endif // BC_ENABLE_LIBRARY diff --git a/include/vector.h b/include/vector.h index bf79d30c36dd..51c5e8b95293 100644 --- a/include/vector.h +++ b/include/vector.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/include/version.h b/include/version.h index 2a3e6aa0f34c..d7f8ef5bcc18 100644 --- a/include/version.h +++ b/include/version.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -37,6 +37,6 @@ #define BC_VERSION_H /// The current version. -#define VERSION 6.1.0 +#define VERSION 6.2.0 #endif // BC_VERSION_H diff --git a/include/vm.h b/include/vm.h index 44212eb03598..1c303add2de0 100644 --- a/include/vm.h +++ b/include/vm.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2021 Gavin D. Howard and contributors. + * Copyright (c) 2018-2023 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -668,9 +668,6 @@ typedef struct BcVm /// The function to call to parse expressions. BcParseExpr expr; - /// The text to display to label functions in error messages. - const char* func_header; - /// The names of the categories of errors. const char* err_ids[BC_ERR_IDX_NELEMS + BC_ENABLED]; @@ -957,6 +954,7 @@ bc_vm_getenvFree(char* val); */ void bc_vm_jmp(const char* f); + #else // BC_DEBUG_CODE /** @@ -994,15 +992,41 @@ bc_vm_atexit(void); #else // BC_ENABLE_LIBRARY /** + * Calculates the number of decimal digits in the argument. + * @param val The value to calculate the number of decimal digits in. + * @return The number of decimal digits in @a val. + */ +size_t +bc_vm_numDigits(size_t val); + +#ifndef NDEBUG + +/** + * Handle an error. This is the true error handler. It will start a jump series + * if an error occurred. POSIX errors will not cause jumps when warnings are on + * or no POSIX errors are enabled. + * @param e The error. + * @param file The source file where the error occurred. + * @param fline The line in the source file where the error occurred. + * @param line The bc source line where the error occurred. + */ +void +bc_vm_handleError(BcErr e, const char* file, int fline, size_t line, ...); + +#else // NDEBUG + +/** * Handle an error. This is the true error handler. It will start a jump series * if an error occurred. POSIX errors will not cause jumps when warnings are on * or no POSIX errors are enabled. * @param e The error. - * @param line The source line where the error occurred. + * @param line The bc source line where the error occurred. */ void bc_vm_handleError(BcErr e, size_t line, ...); +#endif // NDEBUG + /** * Handle a fatal error. * @param e The error. @@ -1024,12 +1048,6 @@ bc_vm_atexit(int status); /// A reference to the copyright header. extern const char bc_copyright[]; -/// A reference to the format string for source code line printing. -extern const char* const bc_err_line; - -/// A reference to the format string for source code function printing. -extern const char* const bc_err_func_header; - /// A reference to the array of default error category names. extern const char* bc_errs[]; |
