From d31d550a852fb52195dbaebbd699cc2e6d696a8b Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 15 Aug 2023 11:07:06 +0200 Subject: [PATCH] fix apply-over --- include/apply.s | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include/apply.s b/include/apply.s index 0a0457d..82465bc 100644 --- a/include/apply.s +++ b/include/apply.s @@ -105,7 +105,7 @@ apply_fini_pt: # make a thunk thunk 010(%rsi), %r14 cmp %r12, %r14 # are we precisely at the right amount of arguments for a thunk? - je apply_fini_pt_thunk # if not wrap a closure + je apply_fini_pt_thunk # if not, wrap a closure apply_fini_pt_closure: thunkto %rsi, %r9 @@ -128,19 +128,25 @@ apply_fini_o: #TODO needs to be tested # first move just the right amount of args off the thunk mov %r12, %rcx sub %r11, %rcx + cmp $0, %rcx + jz apply_fini_o_tc_skip lea 030(%r10, %rcx, 010), %rdx apply_fini_o_tc_copy: sub $010, %rdx pushq (%rdx) loop apply_fini_o_tc_copy + apply_fini_o_tc_skip: # move all args from the closure mov %r11, %rcx + cmp $0, %rcx + jz apply_fini_o_fun_skip lea 030(%rsi, %r11, 010), %rdx apply_fini_o_fun_copy: sub $010, %rdx pushq (%rdx) loop apply_fini_o_fun_copy + apply_fini_o_fun_skip: # make the thunk for the application that can be evaluated later thunkto %r15, 010(%rsi), %r14 @@ -148,12 +154,15 @@ apply_fini_o: #TODO needs to be tested # now make a thunk with the rest of the stuff mov %r14, %rcx sub %r12, %rcx - mov %rcx, %r14 #backup leftover count for later + mov %rcx, %r14 # backup leftover count for later + cmp $0, %rcx + jz apply_fini_o_tt_skip lea 030(%r10, %r13, 010), %rdx apply_fini_o_tt_copy: sub $010, %rdx pushq (%rdx) loop apply_fini_o_tt_copy + apply_fini_o_tt_skip: # finish the leftovers thunk add $1, %r14 # (1 fun to apply to + args)