Skip to content

Commit

Permalink
Split Op enum into separate types (#8)
Browse files Browse the repository at this point in the history
* Split Op enum

* Make AstNode generic

* Fix op.rs and node.rs

* Resolve errors

* Complete op-split refactor

* cargo fmt

---------

Co-authored-by: Kevin Phoenix <[email protected]>
  • Loading branch information
spshah1701 and twizmwazin authored Oct 28, 2024
1 parent 48d34f5 commit a366e66
Show file tree
Hide file tree
Showing 23 changed files with 1,595 additions and 1,567 deletions.
440 changes: 12 additions & 428 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[workspace]
members = ["crates/*"]
members = [
"crates/clarirs_num",
"crates/clarirs_core",
]
resolver = "2"

[workspace.package]
Expand Down
1 change: 1 addition & 0 deletions crates/clarirs_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ahash = "0.8.11"
anyhow = "1.0.86"
clarirs_num = { path = "../clarirs_num" }
num-bigint = { version = "0.4.6", features = ["serde"] }
paste = "1.0.15"
petgraph = "0.6.5"
rand = { version = "0.8.5", features = [ "small_rng"] }
serde = { version = "1.0.209", features = ["derive", "rc"] }
Expand Down
18 changes: 9 additions & 9 deletions crates/clarirs_core/src/algorithms/join.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use crate::prelude::*;

pub trait Join<'c> {
fn and_join(self, ctx: &'c Context<'c>) -> Result<AstRef<'c>, ClarirsError>;
fn or_join(self, ctx: &'c Context<'c>) -> Result<AstRef<'c>, ClarirsError>;
fn and_join(self, ctx: &'c Context<'c>) -> Result<BoolAst<'c>, ClarirsError>;
fn or_join(self, ctx: &'c Context<'c>) -> Result<BoolAst<'c>, ClarirsError>;
}

impl<'c, T: IntoIterator<Item = AstRef<'c>>> Join<'c> for T {
fn and_join(self, ctx: &'c Context<'c>) -> Result<AstRef<'c>, ClarirsError> {
impl<'c, T: IntoIterator<Item = BoolAst<'c>>> Join<'c> for T {
fn and_join(self, ctx: &'c Context<'c>) -> Result<BoolAst<'c>, ClarirsError> {
and_join(ctx, self)
}

fn or_join(self, ctx: &'c Context<'c>) -> Result<AstRef<'c>, ClarirsError> {
fn or_join(self, ctx: &'c Context<'c>) -> Result<BoolAst<'c>, ClarirsError> {
or_join(ctx, self)
}
}

pub fn and_join<'c, I>(ctx: &'c Context<'c>, asts: I) -> Result<AstRef<'c>, ClarirsError>
pub fn and_join<'c, I>(ctx: &'c Context<'c>, asts: I) -> Result<BoolAst<'c>, ClarirsError>
where
I: IntoIterator<Item = AstRef<'c>>,
I: IntoIterator<Item = BoolAst<'c>>,
{
let mut result = ctx.true_()?;
for ast in asts.into_iter() {
Expand All @@ -29,9 +29,9 @@ where
Ok(result)
}

pub fn or_join<'c, I>(ctx: &'c Context<'c>, asts: I) -> Result<AstRef<'c>, ClarirsError>
pub fn or_join<'c, I>(ctx: &'c Context<'c>, asts: I) -> Result<BoolAst<'c>, ClarirsError>
where
I: IntoIterator<Item = AstRef<'c>>,
I: IntoIterator<Item = BoolAst<'c>>,
{
let mut result = ctx.false_()?;
for ast in asts.into_iter() {
Expand Down
Loading

0 comments on commit a366e66

Please sign in to comment.