mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-18 09:21:35 +00:00
More stdlib setup
This commit is contained in:
@ -2,10 +2,16 @@ const ALIGN_LOG2: usize = 3;
|
||||
const ALIGN_SIZE: usize = 1 << ALIGN_LOG2;
|
||||
const ALIGN_MASK: usize = ALIGN_SIZE - 1;
|
||||
|
||||
let HEAP_OFFSET: usize = HEAP_START; // HEAP_START is a constant generated by the compiler
|
||||
let HEAP_OFFSET: usize = HEAP_BASE; // HEAP_BASE is a constant generated by the compiler
|
||||
|
||||
// TODO: maybe tlsf
|
||||
|
||||
@global()
|
||||
class Heap {
|
||||
export class Heap {
|
||||
|
||||
static get used(): usize { return HEAP_OFFSET - HEAP_BASE; }
|
||||
static get free(): usize { return (<usize>current_memory() << 16) - HEAP_OFFSET; }
|
||||
static get size(): usize { return (<usize>current_memory() << 16) - HEAP_BASE; }
|
||||
|
||||
static allocate(size: usize): usize {
|
||||
if (!size) return 0;
|
||||
@ -23,20 +29,8 @@ class Heap {
|
||||
// just a big chunk of non-disposable memory for now
|
||||
}
|
||||
|
||||
static get used(): usize {
|
||||
return HEAP_OFFSET - HEAP_START;
|
||||
}
|
||||
|
||||
static get free(): usize {
|
||||
return (<usize>current_memory() << 16) - HEAP_OFFSET;
|
||||
}
|
||||
|
||||
static get size(): usize {
|
||||
return (<usize>current_memory() << 16) - HEAP_START;
|
||||
}
|
||||
|
||||
static copy(dest: usize, src: usize, n: usize): usize {
|
||||
assert(dest >= HEAP_START);
|
||||
assert(dest >= HEAP_BASE);
|
||||
|
||||
// the following is based on musl's implementation of memcpy
|
||||
let dst: usize = dest;
|
||||
@ -179,4 +173,6 @@ class Heap {
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
private constructor() {}
|
||||
}
|
||||
|
Reference in New Issue
Block a user