2017-12-03 23:04:33 +01:00
|
|
|
/// <reference path="../../assembly.d.ts" />
|
2017-10-19 18:55:27 +02:00
|
|
|
|
2017-12-07 04:37:14 +01:00
|
|
|
const MEMORY_ALIGN_LOG2: usize = 3;
|
|
|
|
const MEMORY_ALIGN_SIZE: usize = 1 << MEMORY_ALIGN_LOG2;
|
|
|
|
const MEMORY_ALIGN_MASK: usize = MEMORY_ALIGN_SIZE - 1;
|
|
|
|
|
2017-10-19 18:55:27 +02:00
|
|
|
@global()
|
|
|
|
class Memory {
|
|
|
|
|
|
|
|
static allocate(size: usize): usize {
|
2017-12-07 04:37:14 +01:00
|
|
|
const ptr: usize = HEAP_OFFSET;
|
|
|
|
HEAP_OFFSET += size;
|
|
|
|
if ((HEAP_OFFSET & MEMORY_ALIGN_MASK) != 0)
|
|
|
|
HEAP_OFFSET = (HEAP_OFFSET | MEMORY_ALIGN_MASK) + 1;
|
2017-10-19 18:55:27 +02:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2017-12-07 04:37:14 +01:00
|
|
|
static dispose(ptr: usize): void {
|
|
|
|
// just a big chunk of non-disposable memory for now
|
2017-10-19 18:55:27 +02:00
|
|
|
}
|
|
|
|
}
|