alloc memory for FUNs
This commit is contained in:
parent
a39e193eb8
commit
d1a4eb56cc
|
@ -5,6 +5,7 @@
|
|||
|
||||
# | fun | arg | -> cont
|
||||
.thunkcode apply1
|
||||
needs_alloc $050
|
||||
thunkto %rsi, $apply1_fini, $3, 030(%rbp), %rbp, %rsi
|
||||
enter 020(%rbp) # evaluate fun
|
||||
|
||||
|
@ -14,6 +15,10 @@
|
|||
# we're certainly going to copy a lot of args.
|
||||
mov 020(%rsi), %r11 # amount of args applied now
|
||||
|
||||
# prepare enough memory for the worst case alloc (make FUN from arg count + 3)
|
||||
lea 030(,%r11,010), %r12
|
||||
needs_alloc %r12
|
||||
|
||||
# the copying code is shared so let's do that first:
|
||||
pushq 020(%rbp) #push the new arg
|
||||
lea 030(%rsi), %rdx # the end (first arg)
|
||||
|
@ -59,6 +64,7 @@ apply1_fini_feed:
|
|||
|
||||
# | fun | arg[1] | arg[2] | ... | arg[args-1] | -> cont
|
||||
.thunkcode apply
|
||||
needs_alloc $040
|
||||
thunkto %rsi, $apply_fini, $2, %rbp, %rsi
|
||||
enter 020(%rbp)
|
||||
|
||||
|
@ -71,13 +77,18 @@ apply1_fini_feed:
|
|||
mov 010(%r10), %r13 # amount of args in the original thunk
|
||||
sub $1, %r13 # amount of args we want to apply (the 1st one is the FUN)
|
||||
|
||||
mov %r11, %r14
|
||||
add %r13, %r14
|
||||
cmp %r12, %r14 # do we have enough arguments?
|
||||
lea (%r11, %r13), %r14 # total amount arguments we have
|
||||
lea 050(%r14), %r15 # how much memory this needs in extreme
|
||||
needs_alloc %r15
|
||||
# worst-case memory is: we make a thunk (2 headers + some args) and a
|
||||
# leftover closure (3 headers + rest of args)
|
||||
|
||||
# Now that we have enough memory, do we have enough arguments to do anything?
|
||||
cmp %r12, %r14
|
||||
ja apply_fini_o
|
||||
|
||||
apply_fini_pt:
|
||||
# not enough args or exactly enough args.
|
||||
# Not enough args or exactly enough args.
|
||||
# Basically make a function or a thunk that is almost the same.
|
||||
|
||||
# first move thunk params
|
||||
|
|
Loading…
Reference in a new issue