Repository navigation
Conversation
`x op= v` was desugared into `x = x op v`, cloning the named expression, so an array subscript ran twice: `a[i++] += 5` read a[0], stored into a[1] and advanced i by two. POSIX requires the named expression to be "evaluated only once". Keep the operator in a CompoundAssignment node. The interpreter resolves the target to a slot once, reads it before the right side runs (as GNU bc does), and writes the result back to the same slot. The binary operators share one apply_arith. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`i=0; b[i] = (i=2)` evaluated the value first and stored into b[2]; GNU bc stores into b[0], and `b[i] op= v` now resolves its target first too. POSIX leaves the order unspecified; resolve the slot first so both assignment forms agree with each other and with GNU. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Scripts written against GNU bc put a newline between the ')' of an
if, while or for and its body (Allman-style braces), write one-line
definitions such as `define f(x) { return (x*2) }`, and write
`return x`. POSIX's grammar has none of these, and bc rejected them;
on standard input the rejected header was dropped and its body then
ran on its own, unconditionally.
Accept them as GNU bc does: one optional newline before an if/while/
for body and before a definition's '{', a body on the '{' line (auto
list still first), and `return expression`. A blank line still ends
the construct, so an abandoned `if (x)` is reported. Each form is
recorded in NONPOSIX.md.
The tests run each form on standard input and as a file operand,
through a shared program_file helper.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POSIX: quit stops bc "at the point where the statement occurs in the input". `1/0; quit` abandoned its input item at the division, so the quit was never executed and bc read on. The quit has been read all the same; when an item that contains one fails, stop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A file operand was parsed whole and then run: a runtime error dropped the rest of the file, and a syntax error anywhere ran none of it. Standard input went line by line through rustyline even when it was not a terminal, which edited the program text (a backspace deleted the character before it, a carriage return was stripped), panicked on a grapheme cluster over 255 bytes, re-parsed a multi-line construct after every line (a 20,000-line function took 90 seconds), and numbered every diagnostic from the start of its own input item. Files and standard input now share one path. Lines are gathered in a Pending buffer whose one-pass scan of strings, comments, brackets and continuations says when a parse is worth trying; each completed item runs before the next is read. Lines are numbered across the whole input. A runtime error ends only its item, as in GNU bc. A syntax error ends a non-interactive input, so nothing after it runs out of context; a session typed at a terminal reports it and goes on. Non-text input is reported where it stops being text, for files and standard input alike. POSIX makes bc interactive only when standard input and output are both terminals; that now decides the exit status, and line editing is used only then, so a typed session with redirected output gets no prompts in its output. Ctrl-C abandons a half-typed construct instead of ending the session. Output is flushed after each item unless standard input is a regular file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ls quickly NONPOSIX.md promises that an operation building more than a million decimal digits fails with "number too large". Multiplication had no check, so repeated products built a value whose scale passed the limit, and printing it gave a silent 0; a quotient could pass it too when its dividend already had a large scale; and a literal with too many digits was reported as an invalid digit. Check the result scale in mul and in divide_exact, and the digit counts of a literal, so no value exceeds the limit; printing no longer needs a fallback, and computes 10^scale directly. Number::parse returns the reason it failed. A literal was also read digit by digit, quadratic in its length, and num-bigint's own decimal reader is quadratic too: a million digits took seconds. read_digits splits the string in halves and joins them with one multiplication per level. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each line of a runtime error's call trace ended in a newline, and the diagnostic printer added another, leaving a blank line after the trace; a line naming a file also ended in a space. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
break.out, for.out and while.out have no program beside them and no test reads them; break_out_of_loop, for_loop and while_loop are the tests of those statements. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
diag::init_locale restores SIGPIPE, calls setlocale, binds the message catalog and installs a panic hook: all process-wide, and plib's restore_sigpipe documents that it runs before any other thread exists. bc called it on the interpreter thread while main waited in join. Call it in main before spawning, and set only the thread-local diagnostic prefix on the interpreter thread. No behavior changes: a broken pipe still kills bc by SIGPIPE, an inherited SIG_IGN still yields a write error, so there is no failing test to add; the existing write-error tests cover both paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
stdin_is_regular_file duplicated standard input through std::os::fd, which exists only on Unix, so bc no longer built for Windows. Take the duplicate through std::os::windows::io there: a handle to a file has file metadata, while a console handle has none and a pipe is not a regular file, so output is still flushed per item exactly when someone may be waiting on it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.