Backends

Juvix supports backends for generating code for different targets (Michelson, LLVM etc.). Juvix programs are written in terms of primitives, i.e. values and types that are directly available in the target language. This allows is us to abstract away from target-specific code by replacing these primitives with ones from other targets, but at the same time give enough flexibility to execute target-specific operations if necessary.

Connection with pipeline

The backend implements several datatypes and class-instances that connect to the pipeline of Juvix.

Main backend instance

An instance of HasBackend, that implements the main connection to the pipeline:

  • The datatype used for types, values and errors (Ty, Val, Err

respectively);

  • stdlib, the Juvix source file(s) that make up the standard library for

this backend;

  • Optionally an implementation for the parse function;

  • Optionally an implementation for the typecheck function;

  • An implementation for the compile function.

Parameterisation

We need to inform the Juvix compiler of some basic information about our backend, such as:

  • A function for typechecking primitives: hasType.

  • Lists of builtin values and types: builtinTypes and builtinValues.

  • Functions for creating primitives based on a literal integers, floats or strings: stringVal, intVal and floatVal.

Substitution and weakening

For compilation, the backend takes a representation of the input program that is very close to a primitive-extended lambda calculus with multi-argument lambda's. As the primitives of the target language themselves can be functions, for example basic arithmetic operators, we can normalize these terms as well. For this we need to instantiate two classes for the primitives:

  • HasSubstV: For substitution of term.

  • HasWeak: For weakening of terms (accounting for removal of a lambda abstraction).

  • HasPatSubstTerm: Substitution of patterns.

Each of these are documented in more detail at the evaluator page.

Additionally, to make applying terms possible during substitution, the CanApply class needs to be instantiated for primitive terms and types.

Last modified August 3, 2021 : General backend documentation (#18) (7073b18)