8 releases
0.1.18 | Jan 7, 2024 |
---|---|
0.1.17 | Nov 17, 2023 |
0.1.15 | Oct 22, 2023 |
#224 in Programming languages
27 downloads per month
155KB
4K
SLoC
Contains (Mach-o exe, 34KB) bin/main
Cyclang
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
!
WebAssembly (WASM)
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.
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.
Installing and Running
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.
Dependencies
~6–17MB
~198K SLoC