Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vkobinski committed Jun 26, 2024
1 parent b4f6a9d commit 834c50f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
12 changes: 1 addition & 11 deletions crates/benda/src/types/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::panic;
use std::cell::RefCell;
use std::vec;

use bend::fun::{self, Book as BendBook, CtrField, Name, Rule};
use bend::fun::{self, Book as BendBook, Name, Rule};
use bend::imp::{self, Expr, Stmt};
use indexmap::IndexMap;
use num_traits::ToPrimitive;
Expand Down Expand Up @@ -114,12 +114,6 @@ macro_rules! generate_structs {
fields: IndexMap<String, Option<Py<PyAny>>>,
}

impl InsertField for $iden {
fn insert_field(&mut self, field: &CtrField) {
self.fields.insert(field.nam.to_string(), None);
}
}

impl BendCtr for $iden {
fn to_py(&self, py: &Python) -> Py<PyAny> {
Py::new(*py, self.clone()).unwrap().as_any().clone()
Expand Down Expand Up @@ -245,10 +239,6 @@ impl Ctrs {
}
}

trait InsertField {
fn insert_field(&mut self, field: &CtrField);
}

#[pymethods]
impl Ctrs {
fn __getattr__(&self, object: Bound<PyAny>) -> PyResult<pyo3::PyObject> {
Expand Down
18 changes: 10 additions & 8 deletions crates/benda/src/types/user_adt.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::vec;

use bend::fun::{Adt as BAdt, Adts, Book, Name, Num, Term as BTerm};
use bend::fun::{Adt as BAdt, Book, Name, Num, Term as BTerm};
use bend::imp::{self};
use indexmap::IndexMap;
use num_traits::ToPrimitive;
use pyo3::types::{PyAnyMethods, PyString, PyTuple};
use pyo3::{Bound, IntoPy, Py, PyAny, PyErr, PyObject, PyResult, Python};
Expand Down Expand Up @@ -35,7 +34,11 @@ pub(crate) trait BendCtr: std::fmt::Debug {

pub fn from_term_into_adt(term: &BTerm, def_adts: &Ctrs) -> Option<TermParse> {
match term {
BTerm::Lam { tag, pat, bod } => {
BTerm::Lam {
tag: _,
pat: _,
bod,
} => {
let mut args: Vec<Py<PyAny>> = vec![];

let lam_body = from_term_into_adt(bod.as_ref(), def_adts);
Expand Down Expand Up @@ -72,19 +75,18 @@ pub fn from_term_into_adt(term: &BTerm, def_adts: &Ctrs) -> Option<TermParse> {
));
});
}
TermParse::Args(args) => {
TermParse::Args(_) => {
todo!()
}
};
}
todo!()
}
BTerm::App { tag, fun, arg } => {
let mut constructor: Option<Box<dyn BendCtr>> = None;

if let (BTerm::Var { nam }, BTerm::Num { val }) =
BTerm::App { tag: _, fun, arg } => {
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 =
Expand Down

0 comments on commit 834c50f

Please sign in to comment.