Skip to content

ngraf3255/bcomp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

cargo build

or

cargo build --release

Usage

Compile a .bsc source file to an object file:

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:

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:

cc print.o -o print

Example

Input:

print "HELLO WORLD";

Compile:

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

Development

Run the test suite:

cargo test

Run lint checks:

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

License

MIT. See LICENSE.

About

A BASIC compiler

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages