Created
February 21, 2018 16:57
-
-
Save ebb/ffc40965027bed3cf3464f1e2b45e206 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Define (heap_alloc align size) | |
Begin { | |
Let start | |
Let start (Fetch uint32 heap_top) | |
In | |
Cond { | |
| [align > 4] | |
Let c [[align / 4] - 1] | |
In | |
(and [start + c] (complement c)) | |
| True | |
start | |
} | |
In | |
Begin { | |
Let limit (Fetch uint32 heap_limit) | |
In | |
When Or [start > limit] [size > [4 * [limit - start]]] { | |
(die "Failed to allocate memory.") | |
} | |
} | |
(Store uint32 heap_top [start + [[size + 3] / 4]]) | |
start | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment