-
Notifications
You must be signed in to change notification settings - Fork 11
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
3 changed files
with
89 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,21 @@ | ||
pub mod expr; | ||
|
||
pub type Result = std::result::Result<(), egglog::Error>; | ||
|
||
pub fn run_test(build: &str, check: &str, progs: Vec<Program>) -> Result { | ||
let program = format!( | ||
"{}\n{build}\n{}\n{check}\n", | ||
[include_str!("schema.egg"),].join("\n"), | ||
include_str!("schedule.egg"), | ||
); | ||
|
||
println!("{}", program); | ||
|
||
egglog::EGraph::default() | ||
.parse_and_run_program(&program) | ||
.map(|lines| { | ||
for line in lines { | ||
println!("{}", line); | ||
} | ||
}) | ||
} |
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,5 @@ | ||
(run-schedule | ||
(repeat 6 | ||
(saturate always-run) | ||
(saturate error-checking) | ||
)) |
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,63 @@ | ||
//! This module mirrors `schema.egg`. | ||
//! No implementation or conversion should | ||
//! be implemented in this file. | ||
|
||
use std::rc::Rc; | ||
|
||
struct Program { | ||
entry: Expr, // must be a function | ||
functions: Vec<Expr>, // a list of other functions | ||
} | ||
|
||
enum Ctx { | ||
Global, | ||
} | ||
|
||
enum Type { | ||
IntT, | ||
BoolT, | ||
FuncT(Rc<Type>, Rc<Type>), | ||
TupleT(Vec<Rc<Type>>), | ||
} | ||
|
||
enum BinaryOp { | ||
Add, | ||
Sub, | ||
Mul, | ||
LessThan, | ||
And, | ||
Or, | ||
Write, | ||
} | ||
|
||
enum UnaryOp { | ||
Not, | ||
Print, | ||
} | ||
|
||
enum Constant { | ||
Int(i64), | ||
Bool(bool), | ||
} | ||
|
||
enum Order { | ||
Parallel, | ||
Sequential, | ||
} | ||
|
||
enum Expr { | ||
Const(Ctx, Constant), | ||
Bop(BinaryOp, Rc<Expr>, Rc<Expr>), | ||
Uop(UnaryOp, Rc<Expr>), | ||
Get(Rc<Expr>, i64), | ||
Read(Rc<Expr>, Type), | ||
Call(String, Rc<Expr>), | ||
All(Ctx, Order, Vec<Rc<Expr>>), | ||
Switch(Rc<Expr>, Vec<Rc<Expr>>), | ||
If(Rc<Expr>, Rc<Expr>, Rc<Expr>), | ||
Input(Rc<Expr>), | ||
Arg(Type), | ||
Let(Rc<Expr>), | ||
DoWhile(Rc<Expr>, Rc<Expr>, Rc<Expr>), | ||
Function(String, Type, Type, Rc<Expr>), | ||
} |