Rename memory instructions; Rework constant handling (#177)

* Rename memory instructions as proposed by the bulk-memory-operations spec.
* Rename memory manager functions to memory.* as well
* Remove automatic inlining of constant globals (Binaryen does this now)
* Improve 'const' enum compatibility
* Improve module-level export generation
* Enable the inline decorator for constant variables
* Add ERROR, WARNING and INFO macros that emit a user-defined diagnostic
* Reintroduce builtin decorator so these can appear anywhere in stdlib again
* Inline isNaN and isFinite by default
* Make an interface around gc.* similar to memory.*
* Emit an error when trying to inline a mutable variable
* Slim down CI stages
* Add a more convenient tracing utility for debugging
* Implement some prequesites for an eventual bundled GC
This commit is contained in:
Daniel Wirtz
2018-07-20 22:53:33 +02:00
committed by GitHub
parent 34e8facfdc
commit 39b489bee2
196 changed files with 28714 additions and 6674 deletions

View File

@ -1,7 +1,7 @@
/**
* Arena Memory Allocator
*
* Provides a `reset_memory` function to reset the heap to its initial state. A user has to make
* Provides a `memory.reset` function to reset the heap to its initial state. A user has to make
* sure that there are no more references to cleared memory afterwards. Always aligns to 8 bytes.
*
* @module std/assembly/allocator/arena
@ -12,18 +12,19 @@ import { AL_MASK, MAX_SIZE_32 } from "../internal/allocator";
var startOffset: usize = (HEAP_BASE + AL_MASK) & ~AL_MASK;
var offset: usize = startOffset;
@global
export function allocate_memory(size: usize): usize {
// Memory allocator interface
@global export function __memory_allocate(size: usize): usize {
if (size) {
if (size > MAX_SIZE_32) unreachable();
let ptr = offset;
let newPtr = (ptr + size + AL_MASK) & ~AL_MASK;
let pagesBefore = current_memory();
let pagesBefore = memory.size();
if (newPtr > <usize>pagesBefore << 16) {
let pagesNeeded = ((newPtr - ptr + 0xffff) & ~0xffff) >>> 16;
let pagesWanted = max(pagesBefore, pagesNeeded); // double memory
if (grow_memory(pagesWanted) < 0) {
if (grow_memory(pagesNeeded) < 0) {
if (memory.grow(pagesWanted) < 0) {
if (memory.grow(pagesNeeded) < 0) {
unreachable(); // out of memory
}
}
@ -34,12 +35,8 @@ export function allocate_memory(size: usize): usize {
return 0;
}
@global
export function free_memory(ptr: usize): void {
// nop
}
@global export function __memory_free(ptr: usize): void { /* nop */ }
@global
export function reset_memory(): void {
@global export function __memory_reset(): void {
offset = startOffset;
}