Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vkobinski committed Jun 29, 2024
1 parent 636fa25 commit 75375c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
4 changes: 2 additions & 2 deletions crates/benda/src/types/fan.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bend::fun::Term;
use pyo3::types::{PyString, PyTuple, PyTupleMethods};
use pyo3::{pyclass, pymethods, Bound, Py, PyAny};
use pyo3::types::{PyTuple, PyTupleMethods};
use pyo3::{pyclass, pymethods, Bound};

use crate::types::extract_type_raw;

Expand Down
1 change: 1 addition & 0 deletions crates/benda/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pub fn extract_type_expr(call: ExprCall) -> Option<imp::Expr> {
pub enum BuiltinType {
U24,
F32,
#[allow(dead_code)]
I32,
Tree,
Leaf,
Expand Down
34 changes: 9 additions & 25 deletions crates/benda/src/types/user_adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,15 @@ pub fn from_term_into_adt(term: &BTerm, def_adts: &Ctrs) -> Option<TermParse> {
if let (BTerm::Var { nam: _ }, BTerm::Num { val }) =
(fun.as_ref(), arg.as_ref())
{
let mut constructor: Option<Box<dyn BendCtr>> = None;
match num_to_i32(val) {
0 => {
constructor =
Some(Box::new(def_adts.first.clone().unwrap()));
}
1 => {
constructor =
Some(Box::new(def_adts.second.clone().unwrap()));
}
2 => {
constructor =
Some(Box::new(def_adts.third.clone().unwrap()));
}
3 => {
constructor =
Some(Box::new(def_adts.fourth.clone().unwrap()));
}
4 => {
constructor =
Some(Box::new(def_adts.fifth.clone().unwrap()));
}

_ => panic!("ADT has more than 5 Ctrs"),
};
let constructor: Option<Box<dyn BendCtr>> =
match num_to_i32(val) {
0 => Some(Box::new(def_adts.first.clone().unwrap())),
1 => Some(Box::new(def_adts.second.clone().unwrap())),
2 => Some(Box::new(def_adts.third.clone().unwrap())),
3 => Some(Box::new(def_adts.fourth.clone().unwrap())),
4 => Some(Box::new(def_adts.fifth.clone().unwrap())),
_ => panic!("ADT has more than 5 Ctrs"),
};

return Some(TermParse::Ctr(constructor.unwrap()));
}
Expand Down

0 comments on commit 75375c0

Please sign in to comment.