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

2.9 KiB

Really Bad Compiler in Haskell

A compiler written in Haskell which can currently perform basic arithmetic. Currently using the megaparsec and llvm-hs-* libraries, but I may reimplement certain libraries myself. Built for the Introduction to Compiler Design class at The University of Texas at Dallas.

Main repo: https://git.sudoer.ch/me/really-bad-compiler-in-haskell

Setup Instructions

  • Install ghcup (for managing Haskell tools) and nix (for managing external dependencies).
  • Clone the repo.
  • Use ghcup to install stack 2.9.3, HLS 2.2.0.0, GHC 9.2.8, and cabal 3.6.2.0.

Run Instructions

  • Use stack run <file> to run the program (for example, stack run example/1.fs).
  • The LLVM will be generated as a.out.ll, and the executable will be generated as a.out.

Language

It is planned to be similar to Forth, unless it turns out that Forth does not have the features I am looking for.

Currently, it supports positive integers, +, -, *, /, and . (pops from stack and outputs to console).

The supported syntax for this compiler aims to be compatible with Gforth.

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.

File structure

  • app - contains the compiler program
  • example - contains example programs that can be compiled

Credits

Learning Resources Used

Tools

  • Language: Haskell
  • Haskell tools: GHCup, Stack, Cabal, GHC 9.2
  • Libraries: megaparsec, parser-combinators, text, process, llvm-hs 15, llvm-hs-pure 15,
  • Dependencies: llvm 15, clang 15
  • IDE: VSCodium
  • Git platform: Forgejo
  • AI: Phind (GPT-4), ollama (codellama)
  • Search: Kagi, Stack Overflow