Skip to content

Commit 5a6bd88

Browse files
committed
...
1 parent 951f5e9 commit 5a6bd88

File tree

6 files changed

+31
-25
lines changed

6 files changed

+31
-25
lines changed

src/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@
1414
* The `typeof()` primitive was added
1515
* Type stability for numeric operations (@69)
1616

17+
## Noteable Bugs Addressed:
18+
19+
* `substitute()` now works on datatypes such as literals or calls.
20+
1721
## Internals
1822

1923
* The `List` is now represented as a `Rep<Obj>`, unifying heterogenous and atomic vectors.
2024
This included a considerable refactor.
2125
* Iterating over references of a `Rep<T>` was made much simpler and new methods were added
2226
and unused ones removed.
2327
* The `RepType` struct that was introduced in 0.4.0 was removed again (#189).
28+
* `eval_list_eager()` was removed from the `Context` trait and added as a member method for `CallStack`.
29+
* `eval_list_lazy()` now boxes all expressions in promises (including literals)
30+
This is necessary to box `..a`-style ellipsis arguments in a list-call promise, which requires
31+
access to the underlying expression.
2432

2533
## Notable Bugs Addressed
2634

src/callable/core.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ pub trait CallableFormals {
3838
pub trait Callable: CallableFormals {
3939
fn match_args(&self, args: List, stack: &mut CallStack) -> Result<(List, List), Signal> {
4040
let mut formals = self.formals();
41-
// instead of using a List for ellipsis I want an ExprList
4241

42+
// this collects the expressions
4343
let mut expr_ellipsis: ExprList = ExprList::new();
44-
4544
let mut ellipsis: List = List::new();
4645
let mut matched_args: List = List::new();
4746

src/callable/primitive/list.rs

-11
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,6 @@ formals!(PrimitiveList, "(...)");
5858

5959
impl Callable for PrimitiveList {
6060
fn call(&self, args: ExprList, stack: &mut CallStack) -> EvalResult {
61-
for (name, arg) in args.clone() {
62-
dbg!(&name);
63-
dbg!(&arg);
64-
//dbg!(stack.eval(arg)?);
65-
}
66-
// args.iter_pairs()
67-
// .map(|(k, v)| match (k, v.force(stack)) {
68-
// (k, Ok(v)) => Ok((k, v)),
69-
// (_, Err(e)) => Err(e),
70-
// })
71-
// .collect()
7261
stack.eval_list_eager(args)
7362
}
7463

src/callable/primitive/substitute.rs

+7
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,11 @@ mod test {
199199
r_expect!(substitute(true) == true);
200200
r_expect!(substitute(1L) == 1L);
201201
}
202+
203+
#[test]
204+
fn calls_work() {
205+
r_expect! {{"
206+
eval(substitute(fn(x) x))(1) == 1
207+
"}}
208+
}
202209
}

src/lang.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ impl CallStack {
663663
Obj::Promise(_, expr, _) => {
664664
Ok((k, self.eval_and_finalize(expr)?))
665665
}
666-
// todo: evaluated promise(?)
667666
_ => Ok((k, v)),
668667
})
669668
.collect::<Result<Vec<(Character, Obj)>, Signal>>()?;
@@ -1270,16 +1269,6 @@ mod test {
12701269

12711270
#[test]
12721271
fn fn_rest_arg_ellipsis() {
1273-
let x = CallStack::default()
1274-
.map_session(|s| s.with_experiments(vec![Experiment::RestArgs]))
1275-
.parse_and_eval(
1276-
"
1277-
f <- fn(...) { . }
1278-
f(1, 2, 3)
1279-
",
1280-
);
1281-
println!("{:?}", x);
1282-
// dbg!(&x);
12831272
assert_eq!(
12841273
CallStack::default()
12851274
.map_session(|s| s.with_experiments(vec![Experiment::RestArgs]))
@@ -1293,6 +1282,21 @@ mod test {
12931282
)
12941283
}
12951284

1285+
#[test]
1286+
fn accessing_ellipsis_forces_evaluation() {
1287+
assert_eq!(
1288+
CallStack::default()
1289+
.map_session(|s| s.with_experiments(vec![Experiment::RestArgs]))
1290+
.parse_and_eval(
1291+
"
1292+
f = fn(...) { . }
1293+
f(sum(1))
1294+
",
1295+
),
1296+
r! { list(1) }
1297+
)
1298+
}
1299+
12961300
#[test]
12971301
fn fn_duplicated_parameters() {
12981302
assert_eq!(

src/object/ast.rs

-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ impl ExprList {
107107
}
108108
}
109109

110-
111110
impl fmt::Display for ExprList {
112111
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
113112
let pairs: Vec<String> = self

0 commit comments

Comments
 (0)