-
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
4 changed files
with
575 additions
and
1 deletion.
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,37 @@ | ||
#[derive(Debug, Clone)] | ||
pub struct Program { | ||
pub functions: Vec<Function>, | ||
pub main: Expr, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Function { | ||
pub name: String, | ||
pub args: Vec<Arg>, | ||
pub return_type: Option<Type>, | ||
pub body: Expr, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Arg { | ||
pub name: String, | ||
pub type_ann: Option<Type>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub enum Type { | ||
IntT, | ||
BoolT, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub enum Expr { | ||
IntLit(u64), | ||
BoolLit(bool), | ||
Ident(String), | ||
Plus(Box<Expr>, Box<Expr>), | ||
Lt(Box<Expr>, Box<Expr>), | ||
IfThenElse(Box<Expr>, Box<Expr>, Box<Expr>), | ||
FunCall(String, Vec<Expr>), | ||
Ascribe(Box<Expr>, Type), | ||
} |
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 |
---|---|---|
@@ -1,3 +1,44 @@ | ||
#![allow(unused)] | ||
|
||
use crate::ast::*; | ||
use crate::parse::parse; | ||
|
||
mod ast; | ||
mod parse; | ||
mod union_find; | ||
|
||
pub fn main() { | ||
println!("Hello from overload example!") | ||
let program = " | ||
fun tt() = true; | ||
fun not(b) = if b { false } else { true }; | ||
fun and(b1: bool, b2): bool = | ||
if b1 { | ||
if b2 { | ||
true | ||
} else { | ||
false | ||
} | ||
} else { | ||
false | ||
}; | ||
$ and(not(false), tt()) | ||
"; | ||
|
||
assert!(parse(program).is_ok()) | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub enum PartialType { | ||
// Types are not recursive, so no need to have separate constructors for each variant | ||
Type(Type), | ||
Variable(TypeVar), | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct TypeVar(usize); | ||
|
||
pub struct FunType { | ||
return_type: PartialType, | ||
arg_types: Vec<(String, PartialType)>, | ||
} |
Oops, something went wrong.