Repository navigation
Peephole cleanup - #129
Merged
Merged
Peephole cleanup#129
Conversation
Functions called from within a PRINT expression must only compute and return a value; nested output or I/O-channel changes invalidate the statement-local print state. Aided by Opencode / DeepSeek V4.1 Flash 1017
A label may be reached by a jump, so the tracked print color from the previous linear block is no longer valid. Reset it together with the top-of-stack tracking when a label is seen. Aided by Opencode / DeepSeek V4.1 Flash 1017
Add a reusable token-pattern matcher with typed captures and replacement templates. Rules are compiled once into tables and dispatched by their first token. FASTBASIC_PEEPHOLE_DEBUG=1 prints parsed rules, matches and captures. Aided by Opencode / DeepSeek V4.1 Flash 1017
Replace the arithmetic, memory, I/O, POKE, constant, variable, update, boolean, branch and print-join checks with entries in the compiled rule table. Structural passes that need to inspect whole ranges still run procedurally. Aided by Opencode / DeepSeek V4.1 Flash 1017
Move number normalization, PUSH expansion and folding, SADDR folding, label-target rewriting, short print strings and I/O channel tracking to compiled rule tables. This removes the remaining procedural matchers and simplifies the optimizer loop. Aided by Opencode / DeepSeek V4.1 Flash 1017
Use an expression span to handle any value expression after a constant byte POKE address. Reject spans that cross source lines, labels, or statement terminators so same-line statements and DPOKE sequences stay separate. The generic rule replaces the two redundant simple numeric-address POKE rules. Add a complex-value regression test, including same-line and DPOKE boundary cases. Aided by Opencode / DeepSeek V4.1 Flash 1017
Use the expression-span rule for constant word addresses, emitting NUM_POKE with the value expression. Remove the redundant simple word-address POKE rules and cover word-address values and statement boundaries in the regression test. Aided by Opencode / DeepSeek V4.1 Flash 1017
Generalize symbolic byte-address POKE to match arbitrary value expressions, replacing the two simple-value rules. Add a cross-only regression test for the imported byte symbol. Aided by Opencode / DeepSeek V4.1 Flash 1017
Fold the address/SADDR sequence around INPUT into a variable store. This removes the DPOKE address setup when the INPUT target is a word variable. Aided by Opencode / DeepSeek V4.1 Flash 1017
Add arithmetic, boolean, conditional-return, address increment and byte-symbol PUT tests, and extend the boolean test to cover comparison normalization. Each test checks the optimized program's output, not only that the compiler accepts it. Aided by Opencode / DeepSeek V4.1 Flash 1017
Tag the optimizer debug output with the phase and rule number, and add a development target that compiles the test sources with both targets and fails if any peephole rule is not reached. The check uses test sources only, so an uncovered rule cannot be hidden by the compiler or IDE. Remove the rules that the coverage report proved unreachable, and keep the generated coverage files under build/ so make clean and make distclean remove them. Aided by Opencode / DeepSeek V4.1 Flash 1017
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.
This rewrites the peephole pass using simpler pattern matching rules instead of the explicit code.