Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
I'm working on a small stack-based programming language. I'm currently at a stage where I'm trying to compile it using Cranelift. Altrough the Cranelift documentation is extensive, I'm lacking a broader picture on how to approach some things like heap-allocations and stack-management. The only example project I found are cranelift-jit-demo and this wonderful post.
So, does someone know how to allocate memory on the heap using Cranelift? I've seen instructions like heap_addr, heap_load and heap_store so there should be some way (altrough I don't understand why we can't use the normal load and store here..). create_heap would be my best guess, but it takes a HeapData which confuses me. Dafuq is an index_type, HeapStyle and offset_guard_size? How do I get a GlobalValue for it? How do I free it? Or maybe I should just use C's malloc/free instead... On the other hand direct support for heaps seems to be removed? Sigh. I'm confused.
And I need heap-allocations anyway for storing larger objects. Thx for the stack2ssa tip, found thisand it seems interesting..