From f2ee3fa43c7d36eb7baeca0bb72cc4d97f293585 Mon Sep 17 00:00:00 2001 From: Noah Graf Date: Sun, 26 Apr 2026 06:14:51 +0000 Subject: [PATCH] Updated the README --- README.md | 96 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 69 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index c9223f4..5f7c765 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,104 @@ -# BASIC Compiler (bcomp) +# bcomp -`bcomp` is a compiler for the BASIC programming language that generates LLVM Intermediate Representation (IR). This allows BASIC programs to be compiled and optimized using the LLVM toolchain, enabling high performance and portability. +`bcomp` is a small BASIC compiler written in Rust. It lexes and parses +a subset of pretty BASIC-like syntax, and then uses cranelift to lower it into real assembly. -## Features +## Current Status -- Parses a subset of the BASIC language -- Generates LLVM IR for further compilation or optimization -- Command-line interface for compiling `.bsc` files -- Easily extensible for more BASIC features +Heres what actually work right now if you ran this program: + +- BASIC Expressions, which include: identifiers, numbers, strings, chars, + separators, arithmetic operators, and comparison operators +- Statement lists (each line is a statement), `print`, `return`, `end`, and `rem` +- Cranelift object emission for `main` (each file is loaded as a seperate main) +- `print` uses libc calls for strings, chars, and numeric + expressions +- Tiny program CLI that uses `clap` + +Not implemented yet: + +- Variables and assignment lowering +- Control-flow expressions and keywords like `if`, `goto`, `for`, `next`, and `gosub` +- Floats in any way shape or form +- Multifile linkage (likely never supported) ## Requirements -- Rust (for building the compiler) -- LLVM (for assembling and optimizing IR) +- Rust 2024 + +## Build + +```sh +cargo build +``` -## Installation +or ```sh -git clone https://github.com/Hyphen325/bcomp.git -cd bcomp cargo build --release ``` ## Usage +Compile a `.bsc` source file to an object file: + +```sh +cargo run -- tests/input/print.bsc +``` + +By default, `bcomp` writes the object next to the input with an `.o` extension. +Use `-o` to choose an output path: + ```sh -./target/release/bcomp input.bsc -o output.ll +cargo run -- tests/input/print.bsc -o print.o ``` -- `input.bsc`: Your BASIC source file -- `output.ll`: Generated LLVM IR file +The generated object currently expects libc symbols such as `printf`, so link it +with your platform C compiler: + +```sh +cc print.o -o print +``` ## Example -Given a BASIC file `hello.bas`: +Input: ```basic -10 PRINT "Hello, world!" -20 END +print "HELLO WORLD"; ``` -Compile to LLVM IR: +Compile: ```sh -./bcomp hello.bsc -o hello.ll +cargo run -- tests/input/print.bsc -o print.o +cc print.o -o print +./print ``` -## Reference +## Development -This project references: +Run the test suite: -- [Lets make a Teeny Tiny compiler](https://austinhenley.com/blog/teenytinycompiler1.html) +```sh +cargo test +``` +Run lint checks: -## License +```sh +cargo clippy --all-targets --all-features +``` + +The crate currently denies warnings and Clippy's `all` and `pedantic` groups, so +small changes may still need a formatting or lint pass before they compile +cleanly. -MIT License +## References -## Contributing +- [Let's make a Teeny Tiny compiler](https://austinhenley.com/blog/teenytinycompiler1.html) +- [Cranelift documentation](https://github.com/bytecodealliance/wasmtime/tree/main/cranelift) + +## License -Contributions are welcome! Please open issues or pull requests after reading CONTRIBUTING.md +MIT. See [LICENSE](LICENSE).