More stdlib setup

This commit is contained in:
dcodeIO
2017-12-16 17:54:53 +01:00
parent 85a9fb1eb5
commit 2720515982
47 changed files with 875 additions and 733 deletions

View File

@ -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() {}
}