Skip to content

Commit

Permalink
adding rust schema
Browse files Browse the repository at this point in the history
  • Loading branch information
oflatt committed Feb 2, 2024
1 parent acaf5f0 commit 185be05
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tree_inputs/src/lib.rs
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);
}
})
}
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)
))
63 changes: 63 additions & 0 deletions tree_inputs/src/schema.rs
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>),
}

0 comments on commit 185be05

Please sign in to comment.