aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2023-10-31 22:33:26 +0100
committerMirek Kratochvil <exa.exa@gmail.com>2023-10-31 22:33:26 +0100
commitd1a4eb56ccf39974dd93eeb0434721acc69bbc7c (patch)
treeab19a217b9fbc7004ff19acd34d605afc5185d48
parenta39e193eb8760b5acd5a9abd5017f3f1cfb703ac (diff)
downloaduskel-gc-attempt-1.tar.gz
uskel-gc-attempt-1.tar.bz2
alloc memory for FUNsgc-attempt-1
-rw-r--r--include/apply.s19
1 files changed, 15 insertions, 4 deletions
diff --git a/include/apply.s b/include/apply.s
index 82465bc..7c5d366 100644
--- a/include/apply.s
+++ b/include/apply.s
@@ -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