Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

malloc/free implementation #659

Merged
merged 3 commits into from
May 19, 2020
Merged

malloc/free implementation #659

merged 3 commits into from
May 19, 2020

Conversation

TerrorJack
Copy link
Member

Closes #654.

This should suffice to get stuff working before #658 lands. This implementation allocates one pinned ByteArray# for each malloc call, sets up a StablePtr# for the ByteArray# closure, and store the StablePtr# in the payload's first word. Starting from the second word of the payload is available space as the result of malloc. free would simply fetch the StablePtr# and free it, so later the garbage collector would be able to recycle the space taken by ByteArray#.

@TerrorJack TerrorJack added P1 critical: next release type: bug labels May 19, 2020
@TerrorJack TerrorJack requested a review from gkaracha May 19, 2020 15:08
@TerrorJack TerrorJack self-assigned this May 19, 2020
Copy link
Member

@gkaracha gkaracha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #654 is fixed indeed, I tried it locally 👍 I left a couple of minor comments to fix but otherwise it LGTM.

asterius/src/Asterius/Builtins/Malloc.hs Show resolved Hide resolved
p <- param I64
call "freeStablePtr" [loadI64 (p `subInt64` constI64 8) 0]

roundup_bytes_to_words_expr :: Expression -> Expression
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that roundup_bytes_to_words_expr is not exported, but by convention I'd use camelCase anyway (roundupBytesToWordsExpr), since it's a top-level function .

@TerrorJack TerrorJack merged commit cb5fdd6 into master May 19, 2020
@TerrorJack TerrorJack deleted the wip-wtf-malloc branch May 19, 2020 19:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P1 critical: next release type: bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implementation of malloc is missing
2 participants