Skip to content

Commit dd032cd

Browse files
committed
Initial check in
0 parents  commit dd032cd

32 files changed

+1961
-0
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target
2+
**/*.rs.bk
3+
Cargo.lock

.rustfmt.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
wrap_comments = true
2+
max_width = 100

Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[workspace]
2+
members = [
3+
"crates/sml-core",
4+
"crates/sml-frontend",
5+
"crates/sml-util",
6+
]

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019-2020 Michael Lazear
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SimpleML
2+
3+
SimpleML is a toy Standard ML compiler

book/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
book

book/book.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[book]
2+
authors = ["Michael Lazear"]
3+
language = "en"
4+
multilingual = false
5+
src = "src"
6+
title = "SimpleML"

book/src/SUMMARY.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Summary
2+
3+
- [Chapter 1](./chapter_1.md)

book/src/chapter_1.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Chapter 1

crates/sml-core/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
Cargo.lock

crates/sml-core/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "sml-core"
3+
version = "0.1.0"
4+
authors = ["Michael Lazear <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]

crates/sml-core/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[cfg(test)]
2+
mod tests {
3+
#[test]
4+
fn it_works() {
5+
assert_eq!(2 + 2, 4);
6+
}
7+
}

crates/sml-frontend/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
Cargo.lock

crates/sml-frontend/Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "sml-frontend"
3+
version = "0.1.0"
4+
authors = ["Michael Lazear <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
sml-util = {path = "../sml-util"}

crates/sml-frontend/src/ast.rs

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
use sml_util::interner::Symbol;
2+
use sml_util::span::{Span, Spanned};
3+
4+
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
5+
pub enum Literal {
6+
Unit,
7+
Int(usize),
8+
Char(char),
9+
String(Symbol),
10+
}
11+
12+
#[derive(Clone, Debug, PartialEq, PartialOrd)]
13+
pub enum DeclKind {
14+
Datatype(Symbol, Vec<Symbol>, Spanned<Vec<Variant>>),
15+
Type(Symbol, Vec<Symbol>, Type),
16+
Function(Symbol, Function),
17+
Value(Pat, Expr),
18+
Infix(u8, Symbol),
19+
Infixr(u8, Symbol),
20+
}
21+
22+
#[derive(Clone, Debug, PartialEq, PartialOrd)]
23+
pub enum TypeKind {
24+
/// Type variable
25+
Var(Symbol),
26+
/// Constructor, with applied arguments
27+
Con(Symbol, Vec<Type>),
28+
/// Tuple type
29+
Product(Vec<Type>),
30+
/// Record type
31+
Record(Vec<Row>),
32+
/// Universally quantified type
33+
Univ(Symbol, Box<Type>),
34+
}
35+
36+
#[derive(Clone, Debug, PartialEq, PartialOrd)]
37+
pub enum ExprKind {
38+
Lit(Literal),
39+
Var(Symbol),
40+
Abs(Box<Pat>, Box<Expr>),
41+
App(Box<Expr>, Box<Expr>),
42+
FlatApp(Vec<Expr>),
43+
Ann(Box<Expr>, Box<Type>),
44+
Record(Vec<Field>),
45+
Tuple(Vec<Expr>),
46+
Projection(Box<Expr>, Box<Expr>),
47+
Case(Box<Expr>, Vec<Arm>),
48+
Let(Vec<Decl>, Box<Expr>),
49+
}
50+
51+
#[derive(Clone, Debug, PartialEq, PartialOrd)]
52+
pub enum PatKind {
53+
/// Wildcard
54+
Any,
55+
/// Literal
56+
Lit(Literal),
57+
/// Type ascription
58+
Ascribe(Box<Pat>, Box<Type>),
59+
/// Variable binding
60+
Variable(Symbol),
61+
/// Tuple of pattern bindings (_, x)
62+
Product(Vec<Pat>),
63+
/// Record pattern { label1, label2 }
64+
Record(Vec<Pat>),
65+
/// A collection of pat applications, possibly including infix constructors
66+
FlatApp(Vec<Pat>),
67+
/// Algebraic datatype constructor, along with binding pattern
68+
App(Box<Pat>, Box<Pat>),
69+
}
70+
71+
#[derive(Clone, Debug, PartialEq, PartialOrd)]
72+
pub struct Function {
73+
pub ty: Option<Type>,
74+
pub body: Vec<FnBinding>,
75+
pub span: Span,
76+
}
77+
78+
#[derive(Clone, Debug, PartialEq, PartialOrd)]
79+
pub struct FnBinding {
80+
pub pats: Vec<Pat>,
81+
pub expr: Expr,
82+
}
83+
84+
/// Arm of a case expression
85+
#[derive(Clone, Debug, PartialEq, PartialOrd)]
86+
pub struct Arm {
87+
pub pat: Pat,
88+
pub expr: Expr,
89+
pub span: Span,
90+
}
91+
92+
#[derive(Clone, Debug, PartialEq, PartialOrd)]
93+
pub struct Field {
94+
pub label: Symbol,
95+
pub expr: Expr,
96+
pub span: Span,
97+
}
98+
99+
#[derive(Clone, Debug, PartialEq, PartialOrd)]
100+
pub struct Variant {
101+
pub label: Symbol,
102+
pub ty: Vec<Type>,
103+
pub span: Span,
104+
}
105+
106+
#[derive(Clone, Debug, PartialEq, PartialOrd)]
107+
pub struct Row {
108+
pub label: Symbol,
109+
pub ty: Type,
110+
pub span: Span,
111+
}
112+
113+
pub type Decl = Spanned<DeclKind>;
114+
pub type Type = Spanned<TypeKind>;
115+
pub type Expr = Spanned<ExprKind>;
116+
pub type Pat = Spanned<PatKind>;

0 commit comments

Comments
 (0)