Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge up from base backport
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed Aug 1, 2023
2 parents a049e6b + 2054191 commit fcd9e19
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/compiler/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,11 +1129,12 @@ pub fn hoist_body_let_binding(
let mut vres = Vec::new();
let mut new_call_list = vec![list[0].clone()];
for i in list.iter().skip(1) {
let (new_helper, new_arg) =
let (mut new_helpers, new_arg) =
hoist_body_let_binding(outer_context.clone(), args.clone(), i.clone())?;
new_call_list.push(new_arg);
vres.append(&mut new_helper.clone());
vres.append(&mut new_helpers);
}

let new_tail = if let Some(t) = tail.as_ref() {
let (mut new_helper, new_tail_elt) =
hoist_body_let_binding(outer_context, args, t.clone())?;
Expand Down
47 changes: 47 additions & 0 deletions src/tests/compiler/restargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,3 +941,50 @@ fn test_rest_type_bad() {
eprintln!("tc {typecheck_result:?}");
assert!(typecheck_result.is_err());
}

#[test]
fn test_compiler_tail_let_inline() {
let prog = indoc! {"
(mod (X Y)
(include *standard-cl-21*)
(defun F (A B C) (list A B C))
(defun-inline G (X Y) (F X &rest (let ((Q (+ Y 1))) (list Y Q))))
(G X Y)
)"}
.to_string();
let res = run_string(&prog, &"(5 7)".to_string()).expect("should compile and run");
assert_eq!(res.to_string(), "(5 7 8)");
}

#[test]
fn test_compiler_tail_let_ni() {
let prog = indoc! {"
(mod (X Y)
(include *standard-cl-21*)
(defun F (A B C) (list A B C))
(defun G (X Y) (F X &rest (let ((Q (+ Y 1))) (list Y Q))))
(G X Y)
)"}
.to_string();
let res = run_string(&prog, &"(5 7)".to_string()).expect("should compile and run");
assert_eq!(res.to_string(), "(5 7 8)");
}

#[test]
fn test_repl_tail_let() {
assert_eq!(
test_repl_outcome(vec![
"(defun F (A B C D) (list A B C D))",
"(F 5 7 &rest (let ((Q (list 101 103))) (c 99 Q)))"
])
.unwrap()
.unwrap(),
"(q 5 7 99 101)"
);
}

0 comments on commit fcd9e19

Please sign in to comment.