Skip to content

Commit 2e2efd5

Browse files
committed
[Heavy] Fix apply function to accept list
1 parent 2a7964c commit 2e2efd5

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

heavy/lib/Builtins.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -906,11 +906,23 @@ void is_source_value(Context& C, ValueRefs Args) {
906906
}
907907

908908
void apply(Context& C, ValueRefs Args) {
909-
if (Args.size() < 1)
909+
llvm::SmallVector<heavy::Value, 8> NewArgs;
910+
911+
if (Args.size() == 1)
912+
return C.Apply(Args[0], NewArgs);
913+
if (Args.size() < 2)
910914
return C.RaiseError("invalid arity");
911-
Value Fn = Args[0];
912-
Args = Args.drop_front();
913-
C.Apply(Fn, Args);
915+
916+
Value Fn = Args.front();
917+
Value LastArg = Args.back();
918+
Args = Args.drop_front().drop_back();
919+
920+
for (heavy::Value Arg : Args)
921+
NewArgs.push_back(Arg);
922+
for (heavy::Value Arg : LastArg)
923+
NewArgs.push_back(Arg);
924+
925+
C.Apply(Fn, NewArgs);
914926
}
915927

916928
void make_syntactic_closure(Context& C, ValueRefs Args) {

heavy/test/Evaluate/apply.scm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@
1515
(apply check-list 1 2 3)
1616
; CHECK: (1 2 3 4 5)
1717
(apply check-list 1 2 3 4 5)
18+
; CHECK: (1 2 3 4 5)
19+
(apply check-list 1 2 3 '(4 5))
20+
; CHECK: (1 2 3 4 5)
21+
(apply check-list 1 2 3 '(4 . 5))

0 commit comments

Comments
 (0)