A ChocoPy compiler written in Go
ChoGoPy is a compiler for the ChocoPy language written purely in Go as a fun way to learn more about compilers and get better at Go. It includes multiple analysis passes that perform type checking, variable scope analysis, and more, and compiles down to LLVM IR for flexibility and platform support.
- Clone the repository.
git clone https://github.com/ashiven/chogopy.git- Install LLVM according to this guide.
echo 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main' | sudo tee /etc/apt/sources.list.d/llvm.list
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install clang-18 llvm-18-dev lld-18 libclang-18-dev- Compile the compiler.
go build -tags=llvm18 -o cgpBy default ChoGoPy will run every analysis and transformation pass available to it. You are, however, able to specify the exact stages that the compiler should go through by using the following command line flags:
-lto emit only the tokens generated by the lexer.-pto parse the given source code and print the resulting AST.-tto parse the given source code and perform static type checking on it.-nto parse the given source code and perform name scope analysis on it.-cto generate LLVM IR from the given source code.
An exemplary command would look as follows:
./cgp -p test.chocPlease feel free to submit a pull request or open an issue.
- Fork the repository
- Create a new branch:
git checkout -b feature-name. - Make your changes
- Push your branch:
git push origin feature-name. - Submit a PR
This project is licensed under the MIT License.