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 a7efbc6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
6 changes: 6 additions & 0 deletions src/callable/primitive/substitute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ impl Callable for PrimitiveSubstitute {
return internal_err!();
};

// let x = args.try_get_named("expr")?;

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

let Obj::Promise(_, expr, _) = args.try_get_named("expr")? else {
return internal_err!();
};
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
14 changes: 7 additions & 7 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 @@ -109,12 +109,12 @@ pub trait Context: std::fmt::Debug + std::fmt::Display {
Ok(List::from(elem).iter_pairs())
}
(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 k = k.map_or(OptionNA::NA, OptionNA::Some);
Ok(List::from(vec![(k, Obj::Promise(None, v, self.env()))]).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 a7efbc6

Please sign in to comment.