-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Tianyu Geng | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
documentation files (the “Software”), to deal in the Software without restriction, including without limitation the | ||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit | ||
persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the | ||
Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Archon VM | ||
|
||
Low level IR and runtime for [Archon](https://github.com/tgeng/archon). | ||
|
||
## What is this? | ||
|
||
Archon is a work-in-progress experimental language that combines dependent types, algebraic effects and handlers, and | ||
quantitative types. Since Archon has algebraic effects and handlers, which supports multi-shot continuations, compiling | ||
it to machine code is not straightforward. The low level IR in this project is close enough to the core type theory of | ||
Archon so that compiling Archon to this low level IR should be straightforward: basically just erase unneeded | ||
information. | ||
|
||
## Some Design Choices | ||
|
||
* **Selective CPS transformation** Functions with complex effects (e.g. effects whose handlers may capture the | ||
continuation and manipulate it) are compiled into state machines with CPS transformation. Delimited continuation is | ||
then represented as a singly linked list of continuation objects. Functions that only performs simple effects (e.g. | ||
`State`, `IO`, non-resumable exception) are not CPS-transformed and hence can run as fast as normal functions with | ||
little additional overhead. | ||
* **Uniform value representation** All values have a uniform representation so that everything has the same size. That | ||
is, larger values that cannot fit 8 bytes are represented as pointers. Pointers are 4 byte-aligned and the lowest two | ||
bits are used to tag the value. Native integer is 63-bit because the last bit is used to tag the value as integer. | ||
* **Conservative GC** A conservative GC is used for simplicity of implementation and also flexibility of calling foreign | ||
functions. | ||
* **Typeless** The low level IR has no type information and no type checking is done on it. This is because Archon is | ||
already type-checked and there is no need to do type checking in low level IR again. In fact, adding type checking to | ||
the low level IR is not trivial because Archon supports dependent types, which means one can easily create a function | ||
whose argument can have any types. | ||
|
||
## Getting Started | ||
|
||
`cargo build` to build the project. `cargo test` to run tests. | ||
|
||
See `src/ast/term.rs` and `src/ast/signature.rs` for the low level IR. One can create a `Signature` and then compile it | ||
with `src/backend/compiler.rs` to machine code. Currently only ARM64 macOS is supported. Also, there is no plan to | ||
support 32-bit architectures. | ||
|
||
A simpler frontend IR and parser is also provided in `src/frontend/f_term.rs` and it's used in tests. | ||
See `resources/frontend/transpiler_tests/*.input.txt` for examples. | ||
|
||
## TODOs | ||
|
||
* Integrate Boehm's GC for memory management. | ||
* Support more OS/architectures. | ||
* Add some FFI support. | ||
* Add more built-in types in addition to 63-bit integers. | ||
* Add more built-in functions for primitive manipulations. |