mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add no-entry to project/command line. Add "link-args" to project. Add @wasm and @extern attributes. Added $$wasm_memory_size and $$wasm_memory_grow builtins.
This commit is contained in:
committed by
Christoffer Lerno
parent
39801a304d
commit
a95710c93f
@@ -178,4 +178,33 @@ fn void ArenaAllocator.init(ArenaAllocator* this, char[] data)
|
||||
fn void ArenaAllocator.reset(ArenaAllocator* this)
|
||||
{
|
||||
this.used = 0;
|
||||
}
|
||||
|
||||
const usz WASM_BLOCK_SIZE = 65536;
|
||||
|
||||
WasmMemory wasm_memory;
|
||||
|
||||
struct WasmMemory
|
||||
{
|
||||
usz allocation;
|
||||
uptr use;
|
||||
}
|
||||
|
||||
fn void*! WasmMemory.allocate_block(WasmMemory* this, usz bytes)
|
||||
{
|
||||
if (!this.allocation)
|
||||
{
|
||||
this.allocation = $$wasm_memory_size(0) * WASM_BLOCK_SIZE;
|
||||
}
|
||||
isz bytes_required = bytes + this.use - this.allocation;
|
||||
if (bytes_required <= 0)
|
||||
{
|
||||
defer this.use += bytes;
|
||||
return (void*)this.use;
|
||||
}
|
||||
usz blocks_required = (bytes_required + WASM_BLOCK_SIZE + 1) / WASM_BLOCK_SIZE;
|
||||
if (!$$wasm_memory_grow(0, blocks_required)) return AllocationFailure.OUT_OF_MEMORY!;
|
||||
this.allocation = $$wasm_memory_size(0) * WASM_BLOCK_SIZE;
|
||||
defer this.use += bytes;
|
||||
return (void*)this.use;
|
||||
}
|
||||
Reference in New Issue
Block a user