Skip to content

Commit c54b68f

Browse files
committed
Begin anf and cc modules
1 parent e6f7e9d commit c54b68f

File tree

3 files changed

+102
-2
lines changed

3 files changed

+102
-2
lines changed

pikelet/src/lang.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
//! Intermediate representations of Pikelet.
1+
//! Intermediate languages of the Pikelet compiler.
22
3-
pub mod core;
43
pub mod surface;
4+
// 🠃
5+
pub mod core;
6+
// 🠃
7+
pub mod anf;
8+
// 🠃
9+
pub mod cc;
10+
// 🠃
11+
// ...

pikelet/src/lang/anf.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//! The A-normal form language, with types preserved.
2+
//!
3+
//! This language makes an explicit distinction between _computations_ and
4+
//! _values_, and makes the evaluation indifferent to the order in which
5+
//! computations are executed (somewhat like [applicative functors in
6+
//! Haskell][applicative-functors]). It does this through alterations to the
7+
//! syntactic structure of the [core language][crate::lang::core], while
8+
//! avoiding making many significant changes to the type structure which
9+
//! would make type preservation more challenging.
10+
//!
11+
//! The main inspiration for this language is William Bowman's dissertation,
12+
//! [Compiling with Dependent Types][wjb-dissertation].
13+
//!
14+
//! Note: the 'A' in 'A-Normal Form' does not stand for anything, at least
15+
//! [according to one of the original authors, Matthias Felleisen][just-a].
16+
//! I really wish there was a better name for this language.
17+
//!
18+
//! [applicative-functors]: https://wiki.haskell.org/Applicative_functor
19+
//! [wjb-dissertation]: https://www.williamjbowman.com/resources/wjb-dissertation.pdf
20+
//! [just-a]: https://vimeo.com/387739817
21+
22+
pub use crate::lang::core::{Constant, LocalIndex, UniverseLevel, UniverseOffset};
23+
24+
/// Values are terms that do not reduce.
25+
pub enum Value {
26+
/// Global variables.
27+
Global(String),
28+
/// Local variables.
29+
Local(LocalIndex),
30+
31+
/// Annotated values
32+
Ann(Box<Value>, Box<Configuration>),
33+
34+
/// The type of types.
35+
Universe(UniverseLevel),
36+
/// Lift a value by the given number of universe levels.
37+
Lift(Box<Value>, UniverseOffset),
38+
39+
/// Function types.
40+
///
41+
/// Also known as: pi type, dependent product type.
42+
FunctionType(Option<String>, Box<Configuration>, Box<Configuration>),
43+
/// Function terms.
44+
///
45+
/// Also known as: lambda abstraction, anonymous function.
46+
FunctionTerm(String, Box<Configuration>),
47+
48+
/// Record types.
49+
RecordType(Vec<(String, Box<Configuration>)>),
50+
/// Record terms.
51+
RecordTerm(Vec<(String, Box<Value>)>),
52+
53+
/// Constants.
54+
Constant(Constant),
55+
56+
/// Error sentinel.
57+
Error,
58+
}
59+
60+
/// Computations eliminate values.
61+
pub enum Computation {
62+
/// Values.
63+
Value(Box<Value>),
64+
/// Function eliminations.
65+
///
66+
/// Also known as: function application.
67+
FunctionElim(Box<Value>, Box<Value>),
68+
/// Record eliminations.
69+
///
70+
/// Also known as: record projection, field lookup.
71+
RecordElim(Box<Value>, String),
72+
}
73+
74+
/// Programs that are ready to be executed.
75+
pub struct Configuration {
76+
/// A list of computations to be used when we execute this program.
77+
pub bindings: Vec<Computation>,
78+
/// The final output of the program.
79+
pub output: Computation,
80+
}

pikelet/src/lang/cc.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! The closure converted language, with types preserved.
2+
//!
3+
//! This language makes an explicit distinction between the _use_ of a
4+
//! computation and the _definition_ of a computation. In doing this we make
5+
//! implicit environment capture explicit through the use of an explicit
6+
//! closure object, which holds the closed code and the local environment.
7+
//!
8+
//! The main inspiration for this language is William Bowman's dissertation,
9+
//! [Compiling with Dependent Types][wjb-dissertation].
10+
//!
11+
//! [wjb-dissertation](https://www.williamjbowman.com/resources/wjb-dissertation.pdf)
12+
13+
// TODO: Define syntax

0 commit comments

Comments
 (0)