bcomp 0.1.0

A compiler for a subset of the BASIC language
# bcomp

`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.

## Current Status

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 2024

## Build

```sh
cargo build
```

or

```sh
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
cargo run -- tests/input/print.bsc -o print.o
```

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

Input:

```basic
print "HELLO WORLD";
```

Compile:

```sh
cargo run -- tests/input/print.bsc -o print.o
cc print.o -o print
./print
```

## Development

Run the test suite:

```sh
cargo test
```

Run lint checks:

```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.

## References

- [Let's make a Teeny Tiny compiler]https://austinhenley.com/blog/teenytinycompiler1.html
- [Cranelift documentation]https://github.com/bytecodealliance/wasmtime/tree/main/cranelift

## License

MIT. See [LICENSE](LICENSE).