Skip to content

jlscheerer/val

 
 

Repository files navigation

Val

Val is a research programming language to explore the concepts of mutable value semantics and generic programming for high-level systems programming.

This repository contains the sources of the reference implementation of Val. Please visit our website to get more information about the language itself.

Installation

This project is written in Swift and distributed in the form of a package, built with Swift Package Manager. You will need Swift 5.7 or higher to build the compiler from sources.

Note to Windows users: although this project is not Unix-specific, Windows support is not guaranteed due to the instability of continuous integration (see hylo-lang#252).

Prerequisites

You can skip this step if you're doing development exlusively in a devcontainer. Otherwise:

  1. Install LLVM 15 or later on your system (e.g. brew install llvm)
  2. Have the above installation's llvm-config in your PATH (homebrew doesn't do that automatically; you'd need export PATH="$HOMEBREW_PREFIX/opt/llvm/bin:$PATH"). Then, in this project's root directory.
  3. swift package resolve to get the tool for step 3.
  4. .build/checkouts/Swifty-LLVM/Tools/make-pkgconfig.sh llvm.pc to generate LLVM's library description.
  5. Either
    1. sudo mkdir -p /usr/local/lib/pkgconfig && sudo mv llvm.pc /usr/local/lib/pkgconfig/ (if you want to use Xcode), or
    2. export PKG_CONFIG_PATH=$PWD in any shell where you want to work on this project

Building the compiler

You may compile Val's compiler with the following commands:

swift build -c release

That command will create an executable named valc in .build/release. That's Val compiler!

Running the tests

To test your compiler,

swift test -c release --parallel

Building Val Devcontainer with VSCode

While Val supports Linux natively, it also provides a Devcontainer specification to develop for Linux on other platforms through a Docker container. Our Linux CI uses this specification; this makes it possible to run Linux CI locally on other operating systems like macOS. While this specification should work for any IDE that supports devcontainers, keep in mind this team only uses VSCode.

When opening the Val project in VSCode for the first time, you should be prompted to install the extension recommendations in .vscode/extensions.json. If you are not prompted, manually install the extensions by searching for the extension identifiers in the Extensions Marketplace.

Then, build the Devcontainer with the VSCode command: > Dev Containers: Rebuild and Reopen in Container.

Finally, open a new integrated terminal in VSCode and confirm that the shell user is vscode. You can run whoami to check this.

That integrated terminal is connected to the Devcontainer, as if by ssh. You can now run swift test -c release to build and test for Linux.

The Val repository files are mounted into the container, so any changes made locally (in VSCode or in other editors) will be automatically propagated into the Devcontainer. However, if you need to modifiy any of the files in the .devcontainer directory, you will need to rebuild the container with > Dev Containers: Rebuild and Reopen in Container.

Implementation status

This project is under active development; expect things to break and APIs to change.

The compiler pipeline is organized as below. Incidentally, early stages of this pipeline are more stable than later ones. (Note: completion percentages are very rough estimations.)

  1. Parsing (100%)
  2. Type checking (50%)
  3. IR lowering (30%)
  4. IR analysis and transformations (30%)
  5. Machine code generation (20%)

You can select how deep the compiler should go through the pipeline with the following options:

  • --emit raw-ast: Only parse the input files and output an untyped AST as a JSON file.
  • --typecheck: Run the type checker on the input.
  • --emit raw-ir: Lower the typed AST into Val IR and output the result in a file.
  • --emit ir: Run mandatory IR passes and output the result in a file.
  • --emit llvm: Transpile the program to LLVM and output LLVM IR.
  • --emit binary (default): Produce an executable.

For example, valc --emit raw-ast -o main.json main.val will parse main.val, write the untyped AST in main.json, and exit the pipeline.

A more detailed description of the current implementation status is available on our roadmap page.

Related video and audio

Lightning Talk: An Object Model for Safety and Efficiency by Definition - Dave Abrahams CppNorth 22

Keynote: A Future of Value Semantics and Generic Programming Part 1 - Dave Abrahams - CppNow 2022

Keynote: A Future of Value Semantics and Generic Programming Part 2 - Dave Abrahams & Dimi Racordon - CppNow 2022

Value Semantics: Safety, Independence, Projection, & Future of Programming - Dave Abrahams CppCon 22

Val and Mutable Value Semantics - Dimi Racordon

Val: A Safe Language to Interoperate with C++ - Dimi Racordon - CppCon 2022

Contributing

We welcome contributions to Val. Please read through CONTRIBUTING.md for details on how to get started.

License

Val is distributed under the terms of the Apache-2.0 license. See LICENSE for details.

Releases

No releases published

Packages

No packages published

Languages

  • Swift 99.8%
  • Other 0.2%