Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
sebffischer committed Oct 17, 2024
1 parent 6c5e304 commit 8fc8b2e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 23 deletions.
15 changes: 13 additions & 2 deletions src/callable/primitive/substitute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,20 @@ impl Callable for PrimitiveSubstitute {
return internal_err!();
};

let Obj::Promise(_, expr, _) = args.try_get_named("expr")? else {
return internal_err!();
let x = args.try_get_named("expr")?;

let Obj::Promise(_, expr, _) = x else {
return Ok(x);
};
// match x {
// Obj::Promise(_, e)
// }
// if let Obj::Promise()

// let Obj::Promise(_, expr, _) = args.try_get_named("expr")? else {
// return internal_err!();
// } else {
// }

fn recurse(exprs: ExprList, env: &Environment, paren: bool) -> ExprList {
exprs
Expand Down
16 changes: 1 addition & 15 deletions src/callable/primitive/type_reflection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,7 @@ impl Callable for PrimitiveTypeOf {
let mut args = Obj::List(args);
let x = args.try_get_named("x")?.force(stack)?;

let t = match x {
Obj::Null => "null",
Obj::Vector(v) => match v {
Vector::Character(_) => "character",
Vector::Integer(_) => "integer",
Vector::Double(_) => "double",
Vector::Logical(_) => "logical",
},
Obj::List(_) => "list",
Obj::Expr(_) => "expression",
Obj::Promise(..) => "promise",
Obj::Function(..) => "function",
Obj::Environment(..) => "environment",
};
EvalResult::Ok(Obj::Vector(Vector::Character(vec![t.to_string()].into())))
EvalResult::Ok(Obj::Vector(Vector::Character(vec![x.type_of()].into())))
}
}

Expand Down
26 changes: 20 additions & 6 deletions src/context/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub trait Context: std::fmt::Debug + std::fmt::Display {
internal_err!()
}
}
// Avoid creating a new closure just to point to another, just reuse it
// Avoid creating a new promise just to point to another, just reuse it
(k, Expr::Symbol(s)) => match self.env().get(s.clone()) {
Ok(c @ Obj::Promise(..)) => {
let k = k.map_or(OptionNA::NA, OptionNA::Some);
Expand All @@ -110,11 +110,25 @@ pub trait Context: std::fmt::Debug + std::fmt::Display {
}
(k, v) => {
let k = k.map_or(OptionNA::NA, OptionNA::Some);
if let Ok(elem) = self.eval(v) {
Ok(List::from(vec![(k, elem)]).iter_pairs())
} else {
internal_err!()
}
let x = match v {
Expr::Bool(x) => Obj::Vector(vec![x].into()),
Expr::Integer(x) => Obj::Vector(vec![x].into()),
Expr::Number(x) => Obj::Vector(vec![x].into()),
Expr::String(x) => Obj::Vector(vec![x].into()),
_ => {
if let Ok(elem) = self.eval(v) {
elem
} else {
return internal_err!();
}
}
};
Ok(List::from(vec![(k, x)]).iter_pairs())

// if let Ok(elem) = self.eval(v) {
// } else {
// internal_err!()
// }
}
})
.collect::<Result<Vec<_>, _>>()?
Expand Down
17 changes: 17 additions & 0 deletions src/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ impl ViewMut for Obj {
}

impl Obj {
pub fn type_of(&self) -> String {
match self {
Obj::Null => "null",
Obj::Vector(v) => match v {
Vector::Character(_) => "character",
Vector::Integer(_) => "integer",
Vector::Double(_) => "double",
Vector::Logical(_) => "logical",
},
Obj::List(_) => "list",
Obj::Expr(_) => "expression",
Obj::Promise(..) => "promise",
Obj::Function(..) => "function",
Obj::Environment(..) => "environment",
}
.to_string()
}
pub fn with_visibility(self, visibility: bool) -> EvalResult {
Signal::Return(self, visibility).into()
}
Expand Down

0 comments on commit 8fc8b2e

Please sign in to comment.