The Valhalla Compiler
This is the parser and compiler for Valhalla, which excludes the virtual machine that the compiled bytecode runs on, which is, Brokkr VM.
[!!]
Planning a complete rewrite, and balancing work.
What's been done so far on the front-end:
- Parser
- Lexical analysis, full UTF-8 support, handling: identifiers, symbols, numbers, strings (utf-8 with a good number of escapes), all sorts of braces for: vectors, sets and grouping, etc.
- Infix, prefix and suffix notation.
- Correct parsing of precedence, arity and associativity.
- The base operators for the language.
- Proper function calls, Currying / partial application of functions is properly implemented (Haskell-like functions).
- Error messages, with fancy line and column number and read-out of the source line.
- Constant folding optimisations on trivially deducible numeric computations at compile time.
- Implicit compile-time type-casting in specific situations.
- Macros (including macro definitions and macro application).
- User-defined binary operators as aliases to functions.
- Compiler (generating bytecode to assemble an executable file).
- Table of constants and locals with basic PUSH & POP instructions as well as basic arithmetic.
- Access, assignment and retrieval of local variables within code-block scope.
- Generating curried functions.
- Optimise functions to not curry when currying is not neccesary (by tracking arity of function's definition and function's call).
- Optimise functions to not search globally for variables when they come from nested closures (nested closures implement currying).
- Optimise functions for tail calls.
- Track variable and function types.
- Marshaling, i.e. serialising the bytecode and storing it in a file for future interpretation and execution by the virtual machine.
- ...
The VM, i.e. the backend for the language, is being developed separately and will progress semi-independently.
In your shell, in the root of this repository, you may write:
cargo run [source-file-to-compile.vh] [-o out-file] [-v]
or, have the compiler print out debug information like token streams, syntax trees, symbol tables, bytecode instructions, &ct., use --features=debug
:
cargo run --features=debug [source-file.vh]
For example, you can run.
cargo run test_source.vh -v # For verbose output.
to demonstrate compilation with the included test-file (test_source.vh
).
The argument of a source-file to compile is, of course, necessary.
This repository contains the front-end (parser and bytecode compilation) which processes the syntax and semantics of the source code. The generated AST is then compiled to Brokkr VM bytecode. The execution of the subsequent bytecode is handled by the language's VM (virtual machine) called Brokkr, which exists separately from this repository.
Valhalla is a set-theoretic programming language. That's to say, it's based on principles from set theory, in a way that all types are just sets, and hence everything is just an element of a set. The language is meant to give a new way to interact with types, and provides an intuitive way to think about them. A goal is that it may also be used to verify proofs and such in and around set theory.
The language is a general purpose, but instead of being totally object-oriented, or functional, etc., it's just set theory based. From what I've gathered, it's not a very popular paradigm... Likely for good reason, but hey, it might be interesting.
To be significantly reduced.