Skip to content

Commit

Permalink
Fix step 5 call function no args
Browse files Browse the repository at this point in the history
Previously failed on
```
((fn* () 4))

```
due to freeing the list containing the function too early.
  • Loading branch information
bendudson committed Jul 28, 2019
1 parent 075d9c6 commit 76b2506
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions nasm/step5_tco.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ eval:
mov [rax + Cons.typecdr], BYTE content_pointer
mov [r13 + Cons.cdr], rax ; Append to list
mov r14, rax
mov r14, rax ; R14 contains last cons in list
push rax
mov rsi, r15
Expand Down Expand Up @@ -1314,18 +1314,20 @@ eval:
je .list_got_args
; No arguments
push rbx ; Function object
mov rsi, rax ; List with function first
call release_object ; Can be freed now
push rax ; List with function first

; Create an empty list for the arguments
call alloc_cons
mov [rax], BYTE maltype_empty_list
mov rsi, rax ; Argument list into RSI

pop rax ; list, function first
;; Put new empty list onto end of original list
mov [rax + Cons.typecdr], BYTE content_pointer
mov [rax + Cons.cdr], rsi
pop rbx
mov rsi, rax
jmp .list_function_call
.list_got_args:
mov rsi, [rax + Cons.cdr] ; Rest of list
Expand Down

0 comments on commit 76b2506

Please sign in to comment.