-
Notifications
You must be signed in to change notification settings - Fork 0
Codegen fixes #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9a7ec5f
Add CLAUDE.md and rename design spec
jgarzik bc67eec
Fix x86-64 assembly codegen bugs and CI cleanup
jgarzik ef580bb
parser: use ArrayAccess for declared arrays instead of FnCall
jgarzik 565c6e4
codegen: fix misleading string variable layout comment
jgarzik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Build and Test Commands | ||
|
|
||
| ```bash | ||
| # Build | ||
| cargo build --release | ||
|
|
||
| # Run all tests | ||
| cargo test | ||
|
|
||
| # Run a single test by name | ||
| cargo test test_name | ||
|
|
||
| # Run tests in a specific module | ||
| cargo test arithmetic:: | ||
| cargo test control:: | ||
| cargo test strings:: | ||
|
|
||
| # Compile a BASIC program | ||
| cargo run -- program.bas # Output: ./program | ||
| cargo run -- program.bas -o out # Custom output name | ||
| cargo run -- -S program.bas # Emit assembly only (no linking) | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| xbasic64 is a BASIC-to-x86_64 native code compiler with a direct AST-to-assembly pipeline (no IR): | ||
|
|
||
| ``` | ||
| Source → Lexer → Parser → CodeGen → Assembly → Executable | ||
| (tokens) (AST) (x86-64) | ||
| ``` | ||
|
|
||
| ### Source Files (`src/`) | ||
|
|
||
| - **lexer.rs** - Tokenizer handling case-insensitive keywords, line numbers, type suffixes (`%`, `&`, `!`, `#`, `$`), and BASIC literals | ||
| - **parser.rs** - Recursive descent parser producing an AST; handles expression precedence via Pratt parsing | ||
| - **codegen.rs** - Direct AST-to-x86-64 assembly translation using System V AMD64 ABI | ||
| - **runtime.rs** - Hand-written x86-64 assembly runtime library (I/O, strings, math) using libc | ||
| - **main.rs** - CLI driver: reads source, runs pipeline, shells out to `as` and `cc` for linking | ||
|
|
||
| ### Test Structure (`tests/`) | ||
|
|
||
| Integration tests organized by feature area: | ||
| - `common/mod.rs` - Test harness with `compile_and_run()` helper that compiles BASIC source and captures output | ||
| - Feature modules: `arithmetic/`, `arrays/`, `control/`, `data/`, `file_io/`, `input/`, `math/`, `print/`, `procedures/`, `strings/`, `types/`, `variables/` | ||
|
|
||
| ### Key Design Decisions | ||
|
|
||
| - **No IR**: AST compiles directly to assembly for simplicity | ||
| - **System V AMD64 ABI**: Enables libc interoperability for I/O and math | ||
| - **GW-BASIC semantics**: Division (`/`) always returns Double; integer division uses `\` | ||
| - **Default type is Double**: Unsuffixed numeric variables are `#` (Double), not Single | ||
| - **Boolean -1/0**: Comparisons return -1 (true) or 0 (false) for bitwise compatibility | ||
|
|
||
| ## Language Reference | ||
|
|
||
| See [LANGREF.md](LANGREF.md) for the supported BASIC dialect. Key points: | ||
| - Types: INTEGER (`%`), LONG (`&`), SINGLE (`!`), DOUBLE (`#`), STRING (`$`) | ||
| - Control flow: IF/THEN/ELSE, FOR/NEXT, WHILE/WEND, DO/LOOP, SELECT CASE, GOTO/GOSUB | ||
| - Procedures: SUB and FUNCTION with recursion (parameters are by-value only) | ||
| - File I/O: OPEN FOR INPUT/OUTPUT/APPEND, PRINT #, INPUT #, LINE INPUT #, CLOSE | ||
| - String indexing is 1-based (MID$, INSTR); array indexing is 0-based |
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
File renamed without changes.
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.