Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(substitute): literals and function definitions #210

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading