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

[sc-495][sc-494] Update for new hvmc num ops and pre_reduce #222

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/hvmc_net/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pub mod pre_reduce;
pub mod prune;
71 changes: 0 additions & 71 deletions src/hvmc_net/pre_reduce.rs

This file was deleted.

5 changes: 1 addition & 4 deletions src/hvmc_net/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ fn used_defs_in_tree(tree: &Tree, used_defs: &mut HashSet<String>, to_visit: &mu
to_visit.push(nam.clone());
}
}
Tree::Ctr { lft, rgt, .. } | Tree::Op2 { lft, rgt, .. } | Tree::Mat { sel: lft, ret: rgt } => {
Tree::Ctr { lft, rgt, .. } | Tree::Op { rhs: lft, out: rgt, .. } | Tree::Mat { sel: lft, ret: rgt } => {
used_defs_in_tree(lft, used_defs, to_visit);
used_defs_in_tree(rgt, used_defs, to_visit);
}
Tree::Op1 { rgt, .. } => {
used_defs_in_tree(rgt, used_defs, to_visit);
}
Tree::Var { .. } | Tree::Num { .. } | Tree::Era => (),
}
}
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use hvmc::{
run::{DynNet, Heap, Rewrites},
stdlib::LogDef,
};
use hvmc_net::{pre_reduce::pre_reduce_book, prune::prune_defs};
use hvmc_net::prune::prune_defs;
use net::{hvmc_to_net::hvmc_to_net, net_to_hvmc::nets_to_hvmc};
use std::{
str::FromStr,
Expand Down Expand Up @@ -99,7 +99,7 @@ pub fn compile_book(

let mut core_book = nets_to_hvmc(nets)?;
if opts.pre_reduce {
pre_reduce_book(&mut core_book, book.hvmc_entrypoint())?;
core_book.pre_reduce(&|x| x == book.hvmc_entrypoint(), 1 << 24, 100_000)?;
}
if opts.prune {
prune_defs(&mut core_book, book.hvmc_entrypoint().to_string());
Expand Down Expand Up @@ -220,14 +220,15 @@ pub fn count_nodes<'l>(net: &'l hvmc::ast::Net) -> usize {
}
while let Some(tree) = visit.pop() {
match tree {
ast::Tree::Ctr { lft, rgt, .. } | ast::Tree::Op2 { lft, rgt, .. } => {
ast::Tree::Ctr { lft, rgt, .. } => {
count += 1;
visit.push(lft);
visit.push(rgt);
}
ast::Tree::Op1 { rgt, .. } => {
ast::Tree::Op { rhs, out, .. } => {
count += 1;
visit.push(rgt);
visit.push(rhs);
visit.push(out);
}
ast::Tree::Mat { sel, ret } => {
count += 1;
Expand Down
20 changes: 5 additions & 15 deletions src/net/hvmc_to_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,11 @@ fn tree_to_inodes(tree: &Tree, tree_root: String, net_root: &str, n_vars: &mut N
let var = new_var(n_vars);
inodes.push(INode { kind, ports: [subtree_root, var.clone(), var] });
}
Tree::Op1 { opr, lft, rgt } => {
// Add port 1 as a new Num node.
let lft_name = new_var(n_vars);
let num_name = new_var(n_vars);
inodes.push(INode { kind: Num { val: *lft }, ports: [lft_name.clone(), num_name.clone(), num_name] });
// Swap ports 0 and 1 and transform into OP2.
let kind = Op2 { opr: *opr };
let rgt = process_node_subtree(rgt, net_root, &mut subtrees, n_vars);
inodes.push(INode { kind, ports: [lft_name, subtree_root, rgt] });
}
Tree::Op2 { opr, lft, rgt } => {
let kind = Op2 { opr: *opr };
let lft = process_node_subtree(lft, net_root, &mut subtrees, n_vars);
let rgt = process_node_subtree(rgt, net_root, &mut subtrees, n_vars);
inodes.push(INode { kind, ports: [subtree_root, lft, rgt] });
Tree::Op { op, rhs, out } => {
let kind = Op2 { opr: *op };
let rhs = process_node_subtree(rhs, net_root, &mut subtrees, n_vars);
let out = process_node_subtree(out, net_root, &mut subtrees, n_vars);
inodes.push(INode { kind, ports: [subtree_root, rhs, out] });
}
Tree::Mat { sel, ret } => {
let kind = Mat;
Expand Down
8 changes: 4 additions & 4 deletions src/net/net_to_hvmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ fn net_tree_to_hvmc_tree(inet: &INet, tree_root: NodeId, port_to_var_id: &mut Ha
},
NodeKind::Ref { def_name } => Tree::Ref { nam: def_name.to_string() },
NodeKind::Num { val } => Tree::Num { val: *val },
NodeKind::Op2 { opr } => Tree::Op2 {
opr: *opr,
lft: Box::new(var_or_subtree(inet, Port(tree_root, 1), port_to_var_id)),
rgt: Box::new(var_or_subtree(inet, Port(tree_root, 2), port_to_var_id)),
NodeKind::Op2 { opr } => Tree::Op {
op: *opr,
rhs: Box::new(var_or_subtree(inet, Port(tree_root, 1), port_to_var_id)),
out: Box::new(var_or_subtree(inet, Port(tree_root, 2), port_to_var_id)),
},
NodeKind::Mat => Tree::Mat {
sel: Box::new(var_or_subtree(inet, Port(tree_root, 1), port_to_var_id)),
Expand Down
33 changes: 16 additions & 17 deletions src/term/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,22 @@ impl fmt::Display for NumCtr {
impl fmt::Display for Op {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Op::ADD => write!(f, "+"),
Op::SUB => write!(f, "-"),
Op::MUL => write!(f, "*"),
Op::DIV => write!(f, "/"),
Op::MOD => write!(f, "%"),
Op::EQ => write!(f, "=="),
Op::NE => write!(f, "!="),
Op::LT => write!(f, "<"),
Op::GT => write!(f, ">"),
Op::LTE => write!(f, "<="),
Op::GTE => write!(f, ">="),
Op::AND => write!(f, "&"),
Op::OR => write!(f, "|"),
Op::XOR => write!(f, "^"),
Op::LSH => write!(f, "<<"),
Op::RSH => write!(f, ">>"),
Op::NOT => write!(f, "~"),
Op::Add => write!(f, "+"),
Op::Sub => write!(f, "-"),
Op::Mul => write!(f, "*"),
Op::Div => write!(f, "/"),
Op::Mod => write!(f, "%"),
Op::Eq => write!(f, "=="),
Op::Ne => write!(f, "!="),
Op::Lt => write!(f, "<"),
Op::Gt => write!(f, ">"),
Op::Lte => write!(f, "<="),
Op::Gte => write!(f, ">="),
Op::And => write!(f, "&"),
Op::Or => write!(f, "|"),
Op::Xor => write!(f, "^"),
Op::Shl => write!(f, "<<"),
Op::Shr => write!(f, ">>"),
}
}
}
Expand Down
37 changes: 18 additions & 19 deletions src/term/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,22 @@ pub enum Tag {

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Op {
ADD,
SUB,
MUL,
DIV,
MOD,
EQ,
NE,
LT,
GT,
LTE,
GTE,
AND,
OR,
XOR,
LSH,
RSH,
NOT,
Add,
Sub,
Mul,
Div,
Mod,
Eq,
Ne,
Lt,
Gt,
Lte,
Gte,
And,
Or,
Xor,
Shl,
Shr,
}

/// Pattern types.
Expand Down Expand Up @@ -387,15 +386,15 @@ impl Term {
if val == 0 {
arg
} else {
Term::Opx { op: Op::SUB, fst: Box::new(arg), snd: Box::new(Term::Num { val }) }
Term::Opx { op: Op::Sub, fst: Box::new(arg), snd: Box::new(Term::Num { val }) }
}
}

pub fn add_num(arg: Term, val: u64) -> Term {
if val == 0 {
arg
} else {
Term::Opx { op: Op::ADD, fst: Box::new(arg), snd: Box::new(Term::Num { val }) }
Term::Opx { op: Op::Add, fst: Box::new(arg), snd: Box::new(Term::Num { val }) }
}
}

Expand Down
Loading
Loading