This repository holds the source code for the Fly compiler
The fly compiler processes a .fly file provided in the program arguments, or reads a fly program through stdin if no file is provided.
By default, the fly compiler produces a fly.out executable from the given program.
However, that behaviour is changed with the following flags:
--tokens: prints the program's tokens to stdout--ast: prints the program's ast to stdout--ir: prints the program's llvm IR to stdout
❯ ./fly --help
Usage: ./fly <filename>.fly
--tokens Print Tokens to stdout
--ast Print Ast to stdout
--ir Print IR to stdout
-help Display this list of options
--help Display this list of options
# produce a "fly.out" executable from the program
❯ ./fly main.fly
# produce the program's tokens to stdout
❯ ./fly --tokens main.fly
# produce the program's ast to stdout
❯ ./fly --ast main.fly
# produce the program's llvm IR to stdout
❯ ./fly --ir main.flyThis project is built using opam.
If you don't have opam, we recommend installing it through homebrew (Mac).
Mac (homebrew):
❯ brew install opamAlso, the project requires llvm@14 on your machine.
You don't have to set it up as a default or anything.
As long as it's installed, you're good.
Mac (homebrew):
❯ brew install llvm@14
...
❯ ls /opt/homebrew/Cellar/llvm@14
14.0.6Also, you'll have to use ocaml v4 to be able to use the llvm@14 bindings.
If you're already using version 4, you should be good. If you're using v5, follow these steps:
# create a new "switch", basically a virtual environment,
# called "ocaml4.14.4" using the v4.14.2 ocaml compiler
❯ opam switch create ocaml4.14.2 ocaml-base-compiler.4.14.2
# ensure we've successfully moved switches
❯ opam switch list
# switch compiler description
default ocaml-base-compiler.5.3.0,ocaml-options-vanilla.1 ocaml >= 4.05.0
→ ocaml4.14.2 ocaml-base-compiler.4.14.2,ocaml-options-vanilla.1 ocaml-base-compiler = 4.14.2
# do this in every shell that existed prior to the opam switch
# to update your opam environment (or just create a new shell)
❯ eval $(opam env)In some cases, this make still fail. If so, delete opam from your machine and reinstall. Then re-run the commands above. This should be fine, as you likely have no important stuff in your opam files:
Mac (homebrew):
❯ brew uninstall opam --force
❯ rm -rf ~/.opam
❯ brew install opamTo install all dependencies:
❯ opam install . --deps-only -yThis project is built using dune v3.17.
You should have installed dune as a project dependency in the opam install script above.
To build the compiler:
dune buildThis will create the compiler executable in ./_build/default/src/ as fly.exe
You can also run the compiler using dune:
./_build/default/src/fly.exe
# or
dune exec flyTo pass program arguments to the executable through dune:
dune exec fly -- [<flags>] <filename>To run all tests on the compiler:
dune runtest #runs all test filesTo run all tests in a specific file:
dune exec test/scanner/test_and.exe # Tests if the scanner correctly parses the AND operator