diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/args.c | 2 | ||||
| -rw-r--r-- | src/bc.c | 2 | ||||
| -rw-r--r-- | src/bc_fuzzer.c | 3 | ||||
| -rw-r--r-- | src/bc_lex.c | 2 | ||||
| -rw-r--r-- | src/bc_parse.c | 2 | ||||
| -rw-r--r-- | src/data.c | 142 | ||||
| -rw-r--r-- | src/dc.c | 2 | ||||
| -rw-r--r-- | src/dc_fuzzer.c | 3 | ||||
| -rw-r--r-- | src/dc_lex.c | 2 | ||||
| -rw-r--r-- | src/dc_parse.c | 2 | ||||
| -rw-r--r-- | src/file.c | 2 | ||||
| -rw-r--r-- | src/history.c | 16 | ||||
| -rw-r--r-- | src/lang.c | 7 | ||||
| -rw-r--r-- | src/lex.c | 2 | ||||
| -rw-r--r-- | src/library.c | 2 | ||||
| -rw-r--r-- | src/main.c | 3 | ||||
| -rw-r--r-- | src/num.c | 3 | ||||
| -rw-r--r-- | src/opt.c | 2 | ||||
| -rw-r--r-- | src/parse.c | 2 | ||||
| -rw-r--r-- | src/program.c | 55 | ||||
| -rw-r--r-- | src/rand.c | 2 | ||||
| -rw-r--r-- | src/read.c | 23 | ||||
| -rw-r--r-- | src/vector.c | 2 | ||||
| -rw-r--r-- | src/vm.c | 32 |
24 files changed, 151 insertions, 164 deletions
diff --git a/src/args.c b/src/args.c index 6eba802d34ac..71a340bce1d9 100644 --- a/src/args.c +++ b/src/args.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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: @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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/src/bc_fuzzer.c b/src/bc_fuzzer.c index 7d7b3292b727..9c68d6acbd10 100644 --- a/src/bc_fuzzer.c +++ b/src/bc_fuzzer.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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: @@ -36,7 +36,6 @@ #include <setjmp.h> #include <string.h> -#include <version.h> #include <status.h> #include <ossfuzz.h> #include <vm.h> diff --git a/src/bc_lex.c b/src/bc_lex.c index f83eaf731622..c53d583a0183 100644 --- a/src/bc_lex.c +++ b/src/bc_lex.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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/src/bc_parse.c b/src/bc_parse.c index cf4398709e58..f66e392a9e99 100644 --- a/src/bc_parse.c +++ b/src/bc_parse.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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/src/data.c b/src/data.c index bb1a6796f752..00f692a4599c 100644 --- a/src/data.c +++ b/src/data.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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: @@ -70,8 +70,8 @@ const uchar dc_sig_msg_len = (uchar) (sizeof(dc_sig_msg) - 1); /// The copyright banner. const char bc_copyright[] = - "Copyright (c) 2018-2024 Gavin D. Howard and contributors\n" - "Report bugs at: https://git.gavinhoward.com/gavin/bc\n\n" + "Copyright (c) 2018-2025 Gavin D. Howard and contributors\n" + "Report bugs at: https://github.com/gavinhoward/bc\n\n" "This is free software with ABSOLUTELY NO WARRANTY.\n"; // clang-format on @@ -850,51 +850,51 @@ const char bc_parse_one[2] = "1"; /// A list of keywords for bc. This needs to be updated if keywords change. const BcLexKeyword bc_lex_kws[] = { - BC_LEX_KW_ENTRY("auto", 4, true), - BC_LEX_KW_ENTRY("break", 5, true), - BC_LEX_KW_ENTRY("continue", 8, false), - BC_LEX_KW_ENTRY("define", 6, true), - BC_LEX_KW_ENTRY("for", 3, true), - BC_LEX_KW_ENTRY("if", 2, true), - BC_LEX_KW_ENTRY("limits", 6, false), - BC_LEX_KW_ENTRY("return", 6, true), - BC_LEX_KW_ENTRY("while", 5, true), - BC_LEX_KW_ENTRY("halt", 4, false), - BC_LEX_KW_ENTRY("last", 4, false), - BC_LEX_KW_ENTRY("ibase", 5, true), - BC_LEX_KW_ENTRY("obase", 5, true), - BC_LEX_KW_ENTRY("scale", 5, true), + BC_LEX_KW_ENTRY("auto", 4, 1), + BC_LEX_KW_ENTRY("break", 5, 1), + BC_LEX_KW_ENTRY("continue", 8, 0), + BC_LEX_KW_ENTRY("define", 6, 1), + BC_LEX_KW_ENTRY("for", 3, 1), + BC_LEX_KW_ENTRY("if", 2, 1), + BC_LEX_KW_ENTRY("limits", 6, 0), + BC_LEX_KW_ENTRY("return", 6, 1), + BC_LEX_KW_ENTRY("while", 5, 1), + BC_LEX_KW_ENTRY("halt", 4, 0), + BC_LEX_KW_ENTRY("last", 4, 0), + BC_LEX_KW_ENTRY("ibase", 5, 1), + BC_LEX_KW_ENTRY("obase", 5, 1), + BC_LEX_KW_ENTRY("scale", 5, 1), #if BC_ENABLE_EXTRA_MATH - BC_LEX_KW_ENTRY("seed", 4, false), + BC_LEX_KW_ENTRY("seed", 4, 0), #endif // BC_ENABLE_EXTRA_MATH - BC_LEX_KW_ENTRY("length", 6, true), - BC_LEX_KW_ENTRY("print", 5, false), - BC_LEX_KW_ENTRY("sqrt", 4, true), - BC_LEX_KW_ENTRY("abs", 3, false), - BC_LEX_KW_ENTRY("is_number", 9, false), - BC_LEX_KW_ENTRY("is_string", 9, false), + BC_LEX_KW_ENTRY("length", 6, 1), + BC_LEX_KW_ENTRY("print", 5, 0), + BC_LEX_KW_ENTRY("sqrt", 4, 1), + BC_LEX_KW_ENTRY("abs", 3, 0), + BC_LEX_KW_ENTRY("is_number", 9, 0), + BC_LEX_KW_ENTRY("is_string", 9, 0), #if BC_ENABLE_EXTRA_MATH - BC_LEX_KW_ENTRY("irand", 5, false), + BC_LEX_KW_ENTRY("irand", 5, 0), #endif // BC_ENABLE_EXTRA_MATH - BC_LEX_KW_ENTRY("asciify", 7, false), - BC_LEX_KW_ENTRY("modexp", 6, false), - BC_LEX_KW_ENTRY("divmod", 6, false), - BC_LEX_KW_ENTRY("quit", 4, true), - BC_LEX_KW_ENTRY("read", 4, false), + BC_LEX_KW_ENTRY("asciify", 7, 0), + BC_LEX_KW_ENTRY("modexp", 6, 0), + BC_LEX_KW_ENTRY("divmod", 6, 0), + BC_LEX_KW_ENTRY("quit", 4, 1), + BC_LEX_KW_ENTRY("read", 4, 0), #if BC_ENABLE_EXTRA_MATH - BC_LEX_KW_ENTRY("rand", 4, false), + BC_LEX_KW_ENTRY("rand", 4, 0), #endif // BC_ENABLE_EXTRA_MATH - BC_LEX_KW_ENTRY("maxibase", 8, false), - BC_LEX_KW_ENTRY("maxobase", 8, false), - BC_LEX_KW_ENTRY("maxscale", 8, false), + BC_LEX_KW_ENTRY("maxibase", 8, 0), + BC_LEX_KW_ENTRY("maxobase", 8, 0), + BC_LEX_KW_ENTRY("maxscale", 8, 0), #if BC_ENABLE_EXTRA_MATH - BC_LEX_KW_ENTRY("maxrand", 7, false), + BC_LEX_KW_ENTRY("maxrand", 7, 0), #endif // BC_ENABLE_EXTRA_MATH - BC_LEX_KW_ENTRY("line_length", 11, false), - BC_LEX_KW_ENTRY("global_stacks", 13, false), - BC_LEX_KW_ENTRY("leading_zero", 12, false), - BC_LEX_KW_ENTRY("stream", 6, false), - BC_LEX_KW_ENTRY("else", 4, false), + BC_LEX_KW_ENTRY("line_length", 11, 0), + BC_LEX_KW_ENTRY("global_stacks", 13, 0), + BC_LEX_KW_ENTRY("leading_zero", 12, 0), + BC_LEX_KW_ENTRY("stream", 6, 0), + BC_LEX_KW_ENTRY("else", 4, 0), }; /// The length of the list of bc keywords. @@ -917,64 +917,64 @@ _Static_assert(sizeof(bc_lex_kws) / sizeof(BcLexKeyword) == BC_LEX_NKWS, const uint8_t bc_parse_exprs[] = { // Starts with BC_LEX_EOF. - BC_PARSE_EXPR_ENTRY(false, false, true, true, true, true, true, true), + BC_PARSE_EXPR_ENTRY(0, 0, 1, 1, 1, 1, 1, 1), // Starts with BC_LEX_OP_MULTIPLY if extra math is enabled, BC_LEX_OP_DIVIDE // otherwise. - BC_PARSE_EXPR_ENTRY(true, true, true, true, true, true, true, true), + BC_PARSE_EXPR_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), // Starts with BC_LEX_OP_REL_EQ if extra math is enabled, BC_LEX_OP_REL_LT // otherwise. - BC_PARSE_EXPR_ENTRY(true, true, true, true, true, true, true, true), + BC_PARSE_EXPR_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), #if BC_ENABLE_EXTRA_MATH // Starts with BC_LEX_OP_ASSIGN_POWER. - BC_PARSE_EXPR_ENTRY(true, true, true, true, true, true, true, true), + BC_PARSE_EXPR_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), // Starts with BC_LEX_OP_ASSIGN_RSHIFT. - BC_PARSE_EXPR_ENTRY(true, true, false, false, true, true, false, false), + BC_PARSE_EXPR_ENTRY(1, 1, 0, 0, 1, 1, 0, 0), // Starts with BC_LEX_RBRACKET. - BC_PARSE_EXPR_ENTRY(false, false, false, false, true, true, true, false), + BC_PARSE_EXPR_ENTRY(0, 0, 0, 0, 1, 1, 1, 0), // Starts with BC_LEX_KW_BREAK. - BC_PARSE_EXPR_ENTRY(false, false, false, false, false, false, false, false), + BC_PARSE_EXPR_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), // Starts with BC_LEX_KW_HALT. - BC_PARSE_EXPR_ENTRY(false, true, true, true, true, true, true, false), + BC_PARSE_EXPR_ENTRY(0, 1, 1, 1, 1, 1, 1, 0), // Starts with BC_LEX_KW_SQRT. - BC_PARSE_EXPR_ENTRY(true, true, true, true, true, true, true, true), + BC_PARSE_EXPR_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), // Starts with BC_LEX_KW_QUIT. - BC_PARSE_EXPR_ENTRY(false, true, true, true, true, true, true, true), + BC_PARSE_EXPR_ENTRY(0, 1, 1, 1, 1, 1, 1, 1), // Starts with BC_LEX_KW_GLOBAL_STACKS. - BC_PARSE_EXPR_ENTRY(true, true, false, false, 0, 0, 0, 0) + BC_PARSE_EXPR_ENTRY(1, 1, 0, 0, 0, 0, 0, 0) #else // BC_ENABLE_EXTRA_MATH // Starts with BC_LEX_OP_ASSIGN_PLUS. - BC_PARSE_EXPR_ENTRY(true, true, true, false, false, true, true, false), + BC_PARSE_EXPR_ENTRY(1, 1, 1, 0, 0, 1, 1, 0), // Starts with BC_LEX_COMMA. - BC_PARSE_EXPR_ENTRY(false, false, false, false, false, true, true, true), + BC_PARSE_EXPR_ENTRY(0, 0, 0, 0, 0, 1, 1, 1), // Starts with BC_LEX_KW_AUTO. - BC_PARSE_EXPR_ENTRY(false, false, false, false, false, false, false, false), + BC_PARSE_EXPR_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), // Starts with BC_LEX_KW_WHILE. - BC_PARSE_EXPR_ENTRY(false, false, true, true, true, true, true, false), + BC_PARSE_EXPR_ENTRY(0, 0, 1, 1, 1, 1, 1, 0), // Starts with BC_LEX_KW_SQRT. - BC_PARSE_EXPR_ENTRY(true, true, true, true, true, true, true, false), + BC_PARSE_EXPR_ENTRY(1, 1, 1, 1, 1, 1, 1, 0), // Starts with BC_LEX_KW_MAXIBASE. - BC_PARSE_EXPR_ENTRY(true, true, true, true, true, true, true, false), + BC_PARSE_EXPR_ENTRY(1, 1, 1, 1, 1, 1, 1, 0), // Starts with BC_LEX_KW_ELSE. - BC_PARSE_EXPR_ENTRY(false, 0, 0, 0, 0, 0, 0, 0) + BC_PARSE_EXPR_ENTRY(0, 0, 0, 0, 0, 0, 0, 0) #endif // BC_ENABLE_EXTRA_MATH }; @@ -982,25 +982,25 @@ const uint8_t bc_parse_exprs[] = { /// An array of data for operators that correspond to token types. Note that a /// lower precedence *value* means a higher precedence. const uchar bc_parse_ops[] = { - BC_PARSE_OP(0, false), BC_PARSE_OP(0, false), BC_PARSE_OP(1, false), - BC_PARSE_OP(1, false), + BC_PARSE_OP(0, 0), BC_PARSE_OP(0, 0), BC_PARSE_OP(1, 0), + BC_PARSE_OP(1, 0), #if BC_ENABLE_EXTRA_MATH - BC_PARSE_OP(2, false), + BC_PARSE_OP(2, 0), #endif // BC_ENABLE_EXTRA_MATH - BC_PARSE_OP(4, false), BC_PARSE_OP(5, true), BC_PARSE_OP(5, true), - BC_PARSE_OP(5, true), BC_PARSE_OP(6, true), BC_PARSE_OP(6, true), + BC_PARSE_OP(4, 0), BC_PARSE_OP(5, 1), BC_PARSE_OP(5, 1), + BC_PARSE_OP(5, 1), BC_PARSE_OP(6, 1), BC_PARSE_OP(6, 1), #if BC_ENABLE_EXTRA_MATH - BC_PARSE_OP(3, false), BC_PARSE_OP(7, true), BC_PARSE_OP(7, true), + BC_PARSE_OP(3, 0), BC_PARSE_OP(7, 1), BC_PARSE_OP(7, 1), #endif // BC_ENABLE_EXTRA_MATH - BC_PARSE_OP(9, true), BC_PARSE_OP(9, true), BC_PARSE_OP(9, true), - BC_PARSE_OP(9, true), BC_PARSE_OP(9, true), BC_PARSE_OP(9, true), - BC_PARSE_OP(11, true), BC_PARSE_OP(10, true), BC_PARSE_OP(8, false), - BC_PARSE_OP(8, false), BC_PARSE_OP(8, false), BC_PARSE_OP(8, false), - BC_PARSE_OP(8, false), BC_PARSE_OP(8, false), + BC_PARSE_OP(9, 1), BC_PARSE_OP(9, 1), BC_PARSE_OP(9, 1), + BC_PARSE_OP(9, 1), BC_PARSE_OP(9, 1), BC_PARSE_OP(9, 1), + BC_PARSE_OP(11, 1), BC_PARSE_OP(10, 1), BC_PARSE_OP(8, 0), + BC_PARSE_OP(8, 0), BC_PARSE_OP(8, 0), BC_PARSE_OP(8, 0), + BC_PARSE_OP(8, 0), BC_PARSE_OP(8, 0), #if BC_ENABLE_EXTRA_MATH - BC_PARSE_OP(8, false), BC_PARSE_OP(8, false), BC_PARSE_OP(8, false), + BC_PARSE_OP(8, 0), BC_PARSE_OP(8, 0), BC_PARSE_OP(8, 0), #endif // BC_ENABLE_EXTRA_MATH - BC_PARSE_OP(8, false), + BC_PARSE_OP(8, 0), }; // These identify what tokens can come after expressions in certain cases. @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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/src/dc_fuzzer.c b/src/dc_fuzzer.c index adaf486a668c..0cb12e4fdf4c 100644 --- a/src/dc_fuzzer.c +++ b/src/dc_fuzzer.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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: @@ -36,7 +36,6 @@ #include <setjmp.h> #include <string.h> -#include <version.h> #include <status.h> #include <ossfuzz.h> #include <vm.h> diff --git a/src/dc_lex.c b/src/dc_lex.c index d5131b45331d..763957edc2ee 100644 --- a/src/dc_lex.c +++ b/src/dc_lex.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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/src/dc_parse.c b/src/dc_parse.c index 1996120461a8..b607bfd4c39f 100644 --- a/src/dc_parse.c +++ b/src/dc_parse.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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/src/file.c b/src/file.c index 697fca8cf29d..bc8097c5b8ce 100644 --- a/src/file.c +++ b/src/file.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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/src/history.c b/src/history.c index 32a19f71d777..594cc4eb46de 100644 --- a/src/history.c +++ b/src/history.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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: @@ -199,6 +199,7 @@ bc_history_init(BcHistory* h) h->el = el_init(vm->name, stdin, stdout, stderr); if (BC_ERR(h->el == NULL)) bc_vm_fatalError(BC_ERR_FATAL_ALLOC_ERR); + el_set(h->el, EL_SIGNAL, 1); // I want history and a prompt. history(h->hist, &bc_history_event, H_SETSIZE, 100); @@ -264,18 +265,7 @@ bc_history_line(BcHistory* h, BcVec* vec, const char* prompt) errno = EINTR; // Get the line. - // - // XXX: Why have a macro here? Because macOS needs to be special. Honestly, - // it's starting to feel special like Windows at this point. Anyway, the - // second SIGWINCH signal of multiple will return a valid line length on - // macOS, so we need to allow for that on macOS. However, FreeBSD's editline - // is different and will mess up the terminal if we do it that way. - // - // There is one limitation with this, however: Ctrl+D won't work on macOS. - // But it's because of macOS that this problem exists, and I can't really do - // anything about it. So macOS should fix their broken editline; once they - // do, I'll fix Ctrl+D on macOS. - while (BC_HISTORY_INVALID_LINE(line, len)) + while (line == NULL && len == -1 && errno == EINTR) { line = el_gets(h->el, &len); bc_history_use_prompt = false; diff --git a/src/lang.c b/src/lang.c index 7968bcbd9dfd..2a62509c98b0 100644 --- a/src/lang.c +++ b/src/lang.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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: @@ -73,9 +73,10 @@ bc_func_insert(BcFunc* f, BcProgram* p, char* name, BcType type, size_t line) BcAuto* aptr = bc_vec_item(&f->autos, i); // If they match, barf. - if (BC_ERR(idx == aptr->idx && type == aptr->type)) + if (BC_ERR(idx == aptr->idx && + BC_IS_ARRAY(type) == BC_IS_ARRAY(aptr->type))) { - const char* array = type == BC_TYPE_ARRAY ? "[]" : ""; + const char* array = BC_IS_ARRAY(type) ? "[]" : ""; bc_error(BC_ERR_PARSE_DUP_LOCAL, line, name, array); } diff --git a/src/lex.c b/src/lex.c index 37e52c33fffd..6b639a65b6a8 100644 --- a/src/lex.c +++ b/src/lex.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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/src/library.c b/src/library.c index 5451e91684a2..282dddff27d2 100644 --- a/src/library.c +++ b/src/library.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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/src/main.c b/src/main.c index da4c27156029..749248048e78 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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: @@ -47,7 +47,6 @@ #include <setjmp.h> -#include <version.h> #include <status.h> #include <vm.h> #include <bc.h> diff --git a/src/num.c b/src/num.c index 83f84edb91fc..2cdc6eea0087 100644 --- a/src/num.c +++ b/src/num.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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: @@ -1093,6 +1093,7 @@ bc_num_as(BcNum* a, BcNum* b, BcNum* restrict c, size_t sub) max_len = max_int + max_rdx; + // Figure out the max length and also if we need to reverse the operation. if (do_sub) { // Check whether b has to be subtracted from a or a from b. diff --git a/src/opt.c b/src/opt.c index a1c8e813b1ea..6a24291ac401 100644 --- a/src/opt.c +++ b/src/opt.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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/src/parse.c b/src/parse.c index 0107d4cdef0d..026607994984 100644 --- a/src/parse.c +++ b/src/parse.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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/src/program.c b/src/program.c index 469835d321b9..af032c5f1e86 100644 --- a/src/program.c +++ b/src/program.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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: @@ -623,6 +623,9 @@ bc_program_prepResult(BcProgram* p) { BcResult* res = bc_vec_pushEmpty(&p->results); + // Mark a result as not retired. + p->nresults += 1; + bc_result_clear(res); return res; @@ -646,6 +649,8 @@ bc_program_const(BcProgram* p, const char* code, size_t* bgn) BcConst* c = bc_vec_item(&p->consts, bc_program_index(code, bgn)); BcBigDig base = BC_PROG_IBASE(p); + assert(p->nresults == 1); + // Only reparse if the base changed. if (c->base != base) { @@ -673,6 +678,9 @@ bc_program_const(BcProgram* p, const char* code, size_t* bgn) bc_num_createCopy(&r->d.n, &c->num); BC_SIG_UNLOCK; + + // XXX: Make sure to clear the number of results. + p->nresults -= 1; } /** @@ -692,6 +700,8 @@ bc_program_op(BcProgram* p, uchar inst) res = bc_program_prepResult(p); + assert(p->nresults == 1); + bc_program_binOpPrep(p, &opd1, &n1, &opd2, &n2, 1); BC_SIG_LOCK; @@ -709,7 +719,7 @@ bc_program_op(BcProgram* p, uchar inst) // Run the operation. This also executes an item of an array. bc_program_ops[idx](n1, n2, &res->d.n, BC_PROG_SCALE(p)); - bc_program_retire(p, 1, 2); + bc_program_retire(p, 2); } /** @@ -1060,6 +1070,8 @@ bc_program_unary(BcProgram* p, uchar inst) res = bc_program_prepResult(p); + assert(p->nresults == 1); + bc_program_prep(p, &ptr, &num, 1); BC_SIG_LOCK; @@ -1070,7 +1082,7 @@ bc_program_unary(BcProgram* p, uchar inst) // This calls a function that is in an array. bc_program_unarys[inst - BC_INST_NEG](res, num); - bc_program_retire(p, 1, 1); + bc_program_retire(p, 1); } /** @@ -1091,6 +1103,8 @@ bc_program_logical(BcProgram* p, uchar inst) res = bc_program_prepResult(p); + assert(p->nresults == 1); + // All logical operators (except boolean not, which is taken care of by // bc_program_unary()), are binary operators. bc_program_binOpPrep(p, &opd1, &n1, &opd2, &n2, 1); @@ -1165,7 +1179,7 @@ bc_program_logical(BcProgram* p, uchar inst) if (cond) bc_num_one(&res->d.n); - bc_program_retire(p, 1, 2); + bc_program_retire(p, 2); } /** @@ -1880,6 +1894,8 @@ bc_program_return(BcProgram* p, uchar inst) res = bc_program_prepResult(p); + assert(p->nresults == 1); + // If we are returning normally... if (inst == BC_INST_RET) { @@ -1930,7 +1946,7 @@ bc_program_return(BcProgram* p, uchar inst) BC_SIG_LOCK; // When we retire, pop all of the unused results. - bc_program_retire(p, 1, nresults); + bc_program_retire(p, nresults); // Pop the globals, if necessary. if (BC_G) bc_program_popGlobals(p, false); @@ -1974,6 +1990,8 @@ bc_program_builtin(BcProgram* p, uchar inst) res = bc_program_prepResult(p); + assert(p->nresults == 1); + bc_program_operand(p, &opd, &num, 1); assert(num != NULL); @@ -2102,7 +2120,7 @@ bc_program_builtin(BcProgram* p, uchar inst) BC_SIG_UNLOCK; } - bc_program_retire(p, 1, 1); + bc_program_retire(p, 1); } /** @@ -2127,6 +2145,7 @@ bc_program_divmod(BcProgram* p) // the capacity is enough due to the line above. res2 = bc_program_prepResult(p); res = bc_program_prepResult(p); + assert(p->nresults == 2); // Prepare the operands. bc_program_binOpPrep(p, &opd1, &n1, &opd2, &n2, 2); @@ -2144,7 +2163,7 @@ bc_program_divmod(BcProgram* p) // Execute. bc_num_divmod(n1, n2, &res2->d.n, &res->d.n, BC_PROG_SCALE(p)); - bc_program_retire(p, 2, 2); + bc_program_retire(p, 2); } /** @@ -2176,6 +2195,8 @@ bc_program_modexp(BcProgram* p) res = bc_program_prepResult(p); + assert(p->nresults == 1); + // Get the first operand and typecheck. bc_program_operand(p, &r1, &n1, 3); bc_program_type_num(r1, n1); @@ -2198,7 +2219,7 @@ bc_program_modexp(BcProgram* p) bc_num_modexp(n1, n2, n3, &res->d.n); - bc_program_retire(p, 1, 3); + bc_program_retire(p, 3); } /** @@ -2737,6 +2758,9 @@ bc_program_pushSeed(BcProgram* p) BcResult* res; res = bc_program_prepResult(p); + + assert(p->nresults == 1); + res->t = BC_RESULT_SEED; BC_SIG_LOCK; @@ -2747,6 +2771,9 @@ bc_program_pushSeed(BcProgram* p) BC_SIG_UNLOCK; bc_num_createFromRNG(&res->d.n, &p->rng); + + // XXX: Clear the number of results. + p->nresults = 0; } #endif // BC_ENABLE_EXTRA_MATH @@ -2932,6 +2959,9 @@ bc_program_init(BcProgram* p) bc_map_init(&p->const_map); bc_vec_init(&p->strs, sizeof(char*), BC_DTOR_NONE); bc_map_init(&p->str_map); + + // XXX: Clear the number of results. + p->nresults = 0; } void @@ -2985,13 +3015,18 @@ bc_program_reset(BcProgram* p) if (BC_IS_DC) bc_vec_npop(&p->tail_calls, p->tail_calls.len - 1); #endif // DC_ENABLED -#if BC_ENABLED // Clear the stack if we are in bc. We have to do this in bc because bc's // stack is implicit. // // XXX: We don't do this in dc because other dc implementations don't. - if (BC_IS_BC || !BC_I) bc_vec_popAll(&p->results); + // However, we *MUST* pop the items for results that are not retired yet. + if (BC_IS_DC && BC_I) bc_vec_npop(&p->results, p->nresults); + else bc_vec_popAll(&p->results); + // Now clear how many results there are. + p->nresults = 0; + +#if BC_ENABLED // Clear the globals' stacks. if (BC_G) bc_program_popGlobals(p, true); #endif // BC_ENABLED diff --git a/src/rand.c b/src/rand.c index 0f9950788f7c..3aaf905f8520 100644 --- a/src/rand.c +++ b/src/rand.c @@ -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-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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/src/read.c b/src/read.c index 01d804848945..650c2813bd1e 100644 --- a/src/read.c +++ b/src/read.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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: @@ -171,34 +171,23 @@ bc_read_chars(BcVec* vec, const char* prompt) // If interupted... if (errno == EINTR) { - int sig; - // Jump out if we are supposed to quit, which certain signals // will require. if (vm->status == (sig_atomic_t) BC_STATUS_QUIT) BC_JMP; assert(vm->sig != 0); - sig = (int) vm->sig; - // Clear the signal and status. vm->sig = 0; vm->status = (sig_atomic_t) BC_STATUS_SUCCESS; -#ifndef _WIN32 - // We don't want to print anything on a SIGWINCH. - if (sig != SIGWINCH) -#endif // _WIN32 + // Print the ready message and prompt again. + bc_file_puts(&vm->fout, bc_flush_none, bc_program_ready_msg); + if (BC_PROMPT) { - // Print the ready message and prompt again. - bc_file_puts(&vm->fout, bc_flush_none, - bc_program_ready_msg); - if (BC_PROMPT) - { - bc_file_puts(&vm->fout, bc_flush_none, prompt); - } - bc_file_flush(&vm->fout, bc_flush_none); + bc_file_puts(&vm->fout, bc_flush_none, prompt); } + bc_file_flush(&vm->fout, bc_flush_none); BC_SIG_UNLOCK; diff --git a/src/vector.c b/src/vector.c index 4b49e61968df..7d5c0bc7376f 100644 --- a/src/vector.c +++ b/src/vector.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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: @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 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: @@ -124,27 +124,6 @@ bc_vm_jmp(void) static void bc_vm_sig(int sig) { -#if BC_ENABLE_EDITLINE - // Editline needs this to resize the terminal. This also needs to come first - // because a resize always needs to happen. - if (sig == SIGWINCH) - { - if (BC_TTY) - { - el_resize(vm->history.el); - - // If the signal was a SIGWINCH, clear it because we don't need to - // print a stack trace in that case. - if (vm->sig == SIGWINCH) - { - vm->sig = 0; - } - } - - return; - } -#endif // BC_ENABLE_EDITLINE - // There is already a signal in flight if this is true. if (vm->status == (sig_atomic_t) BC_STATUS_QUIT || vm->sig != 0) { @@ -217,7 +196,7 @@ bc_vm_sigaction(void) struct sigaction sa; sigemptyset(&sa.sa_mask); - sa.sa_flags = BC_ENABLE_EDITLINE ? 0 : SA_NODEFER; + sa.sa_flags = SA_NODEFER; // This mess is to silence a warning on Clang with regards to glibc's // sigaction handler, which activates the warning here. @@ -234,11 +213,6 @@ bc_vm_sigaction(void) sigaction(SIGQUIT, &sa, NULL); sigaction(SIGINT, &sa, NULL); -#if BC_ENABLE_EDITLINE - // Editline needs this to resize the terminal. - if (BC_TTY) sigaction(SIGWINCH, &sa, NULL); -#endif // BC_ENABLE_EDITLINE - #if BC_ENABLE_HISTORY if (BC_TTY) sigaction(SIGHUP, &sa, NULL); #endif // BC_ENABLE_HISTORY @@ -545,7 +519,7 @@ bc_vm_envArgs(const char* const env_args_name, BcBigDig* scale, BcBigDig* ibase, if (env_args == NULL) return; - // Windows already allocates, so we don't need to. + // Windows already allocates, so we don't need to. #ifndef _WIN32 start = buf = vm->env_args_buffer = bc_vm_strdup(env_args); #else // _WIN32 |
