A programming language I built in Rust - mainly for fun and my own learning! Uses PEG Parser in Rust for parsing and LLVM (llvm-sys) as the backend to compile to machine code binary. Check the user guide for a detailed overview of the language.
Try the Fibonacci example in /examples/fib.cyc
fn fib(i32 n) -> i32 {
if (n < 2) {
return n;
}
return fib(n - 1) + fib(n - 2);
}
print(fib(20));
You will need Rust installed to run the below command.
cyclang --file ./examples/fib.cyc
This should output 6765
!
To run the WASM example that compares Cyclang output (and an optimised version of the IR) against JS use the following command:
make fib-wasm
Below is a comparison of times in Node, Cyclang (unoptimized) WASM and Cyclang optimized WASM for a simple Fibonacci example.
![Screenshot 2023-11-17 at 18 08 23](https://private-user-images.githubusercontent.com/20296911/283891214-646f04d6-cc16-4045-b9b7-6e9438e810f6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAzNTgyMjAsIm5iZiI6MTcyMDM1NzkyMCwicGF0aCI6Ii8yMDI5NjkxMS8yODM4OTEyMTQtNjQ2ZjA0ZDYtY2MxNi00MDQ1LWI5YjctNmU5NDM4ZTgxMGY2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA3VDEzMTIwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU4ODgzMzY3OTE0ZWU4MTQwZGJiZmRmM2JhNDZjOWE5YWNjMWM0NzU3ODJlYTQ1ODU1NjJmMDkyNzNkNjQ5MGEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.aWXX8R9WXyW4TxXDqBCSnx-lIC2U5HzMcDNWJQlXIEg)
Ensure you have wasm-ld
installed to convert LLVM object IR to a .wasm
file. This should come with the LLVM 17 installation - instructions below.
You will need LLVM 17 installed before you install cyclang,
For MacOS run the following command
brew install llvm@17
For Ubuntu install the following packages
llvm-17
llvm-17-tools
llvm-17-dev
clang-17
libpolly-17-dev
And run make set-llvm-sys-ffi-workaround
Then the easiest way to install the binary currently is through the Rust package manager Cargo - see Install Rust. Once the step above is done, then run
cargo install cyclang
See the book for a more detailed guide on setup.