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.
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, andrem - Cranelift object emission for
main(each file is loaded as a seperate main) printuses 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, andgosub - Floats in any way shape or form
- Multifile linkage (likely never supported)
- Rust 2024
cargo buildor
cargo build --releaseCompile a .bsc source file to an object file:
cargo run -- tests/input/print.bscBy default, bcomp writes the object next to the input with an .o extension.
Use -o to choose an output path:
cargo run -- tests/input/print.bsc -o print.oThe generated object currently expects libc symbols such as printf, so link it
with your platform C compiler:
cc print.o -o printInput:
print "HELLO WORLD";Compile:
cargo run -- tests/input/print.bsc -o print.o
cc print.o -o print
./printRun the test suite:
cargo testRun lint checks:
cargo clippy --all-targets --all-featuresThe 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. See LICENSE.