Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assume schema rust definition #316

Closed
wants to merge 13 commits into from
23 changes: 23 additions & 0 deletions tree_inputs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use schema::Program;

pub mod schema;

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);
}
})
}
5 changes: 5 additions & 0 deletions tree_inputs/src/schedule.egg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(run-schedule
(repeat 6
(saturate always-run)
(saturate error-checking)
))
71 changes: 71 additions & 0 deletions tree_inputs/src/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//! This module mirrors `schema.egg`.
//! No implementation or conversion should
//! be implemented in this file.

use std::rc::Rc;

pub enum Type {
IntT,
BoolT,
UnitT,
/// Nested tuple types are not allowed.
TupleT(Vec<Rc<Type>>),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If nested tuples aren't allowed, can we make them unrepresentable, as in:

pub enum BaseType { Int, Bool, Unit }
pub enum Type { Prim(BaseType), Tuple(Vec<BaseType>) }

This way we also get to avoid boxing the tuple elements.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea

}

pub enum BinaryOp {
Add,
Sub,
Mul,
LessThan,
And,
Or,
Write,
}

pub enum UnaryOp {
Not,
Print,
}

pub enum Constant {
Int(i64),
Bool(bool),
Unit,
}

pub enum Order {
Parallel,
Sequential,
}

pub type RcExpr = Rc<Expr>;

pub enum Assumption {
InLet(RcExpr),
InLoop(RcExpr, RcExpr),
}

pub enum Expr {
Const(Constant),
Bop(BinaryOp, RcExpr, RcExpr),
Uop(UnaryOp, RcExpr),
Get(RcExpr, i64),
Read(RcExpr, Type),
Call(String, RcExpr),
Empty(),
Push(Order, RcExpr, RcExpr),
Switch(RcExpr, Vec<RcExpr>),
If(RcExpr, RcExpr, RcExpr),
Let(RcExpr, RcExpr),
DoWhile(RcExpr, RcExpr),
Arg(Type),
Assume(Assumption, RcExpr),
Function(String, Type, Type, RcExpr),
}

pub struct Program {
/// must be a function
pub entry: Expr,
/// a list of other functions
pub functions: Vec<Expr>,
}
Loading