This repository has been archived on 2024-04-05. You can view files and clone it, but cannot push or open issues/pull-requests.
really-bad-compiler-in-haskell/README.md

68 lines
2.9 KiB
Markdown
Raw Normal View History

2023-10-02 16:41:21 +00:00
# HEAR Compiler in Haskell
2023-09-07 20:46:17 +00:00
2023-10-02 16:41:21 +00:00
A compiler for HEAR, a language for when you cannot C.
2023-09-30 08:57:03 +00:00
Written in Haskell, and currently using the megaparsec and llvm-hs-\* libraries, but I plan to eventually rewrite the lexar/parser from scratch. Built for the Introduction to Compiler Design class at The University of Texas at Dallas.
2023-09-07 20:57:58 +00:00
2023-09-07 22:15:02 +00:00
Main repo: https://git.sudoer.ch/me/really-bad-compiler-in-haskell
2023-09-29 10:21:50 +00:00
## Setup Instructions
2023-09-07 20:57:58 +00:00
2023-09-15 06:57:17 +00:00
- Install `ghcup` (for managing Haskell tools) and `nix` (for managing external dependencies).
2023-09-08 03:57:12 +00:00
- Clone the repo.
2023-10-06 05:29:36 +00:00
- Use `ghcup` to install `stack 2.11.1`, `HLS 2.3.0.0`, and `cabal 3.8.1.0`.
2023-09-29 10:21:50 +00:00
## Run Instructions
2023-09-30 08:57:03 +00:00
- Use `stack run <file>` to run the program (for example, `stack run example/1.hear`).
2023-09-29 10:21:50 +00:00
- The LLVM will be generated as `a.out.ll`, and the executable will be generated as `a.out`.
2023-09-07 20:57:58 +00:00
2023-10-07 04:32:00 +00:00
## Currently Supported functionality
- Arithmetic
- Parenthesis
- print() statement
## To edit
I recommend using VSCodium, which is preconfigured to have syntax highlighting and (currently broken) debugging features and will automatically suggest the Haskell extensions to install.
## Known bugs
### Building
- If llvm_16 is in the nix store, stack will use it for some reason and the build will fail. Currently, you may need to run `nix-store --delete /nix/store/<llvm16devdirectory>` to build it.
2023-09-11 17:05:44 +00:00
## File structure
- `src` - contains the compiler program
2023-09-11 17:05:44 +00:00
- `example` - contains example programs that can be compiled
2023-09-07 20:57:58 +00:00
## Credits
2023-09-08 03:57:12 +00:00
### Learning Resources Used
2023-09-07 22:15:02 +00:00
2023-09-07 20:57:58 +00:00
- Introduction to Compiler Design class at The University of Texas at Dallas, taught by Charles Averill
- https://learnyouahaskell.com (for learning Haskell basics)
2023-09-08 03:57:12 +00:00
- https://akashagrawal.me/2017/01/19/beginners-guide-to-megaparsec.html
- https://markkarpov.com/tutorial/megaparsec.html (for help writing a Haskell equation parser using megaparsec)
- https://www.forth.com/starting-forth/1-forth-stacks-dictionary/ (for learning Forth)
- https://blog.josephmorag.com/posts/mcc0/ (Haskell compiler tutorial with megaparsec, llvm-hs, and nix)
- https://gh.sudoer.ch/llvm-hs/llvm-hs-examples (for help writing an llvm code generator using llvm-hs)
- https://danieljharvey.github.io/posts/2023-02-08-llvm-compiler-part-1.html (for help using llvm-hs-pure)
- https://gh.sudoer.ch/danieljharvey/mimsa/blob/trunk/llvm-calc/src/Calc/Compile/ToLLVM.hs (source code for above resource)
- https://9to5tutorial.com/homebrew-compiler-made-with-haskell-llvm-configuration (for help using llvm-hs-pure)
2023-10-07 04:55:57 +00:00
- https://blog.ocharles.org.uk/blog/posts/2012-12-17-24-days-of-hackage-optparse-applicative.html (for help parsing command line arguments with optparse-applicative)
2023-10-08 03:46:37 +00:00
- http://learnyouahaskell.com/making-our-own-types-and-typeclasses (for help defining types)
2023-09-07 22:15:02 +00:00
### Tools
- Language: Haskell
2023-10-07 04:55:57 +00:00
- Haskell/management tools: GHCup, Stack, Cabal, GHC 9.2, Nix
- Libraries: See `package.yaml`
- Dependencies: llvm 15, clang 15
2023-09-07 22:15:02 +00:00
- IDE: VSCodium
2023-09-08 03:57:12 +00:00
- Git platform: Forgejo
- AI: Phind (GPT-4), ollama (codellama)
2023-09-08 05:53:11 +00:00
- Search: Kagi, Stack Overflow