Warn on constant locals not being actual constants; Simplify changetype

This commit is contained in:
dcodeIO
2017-12-28 17:16:37 +01:00
parent 2f12c7fa50
commit 4207f6460d
14 changed files with 90 additions and 74 deletions

View File

@ -2,7 +2,7 @@ const ALIGN_LOG2: usize = 3;
const ALIGN_SIZE: usize = 1 << ALIGN_LOG2;
const ALIGN_MASK: usize = ALIGN_SIZE - 1;
let HEAP_OFFSET: usize = HEAP_BASE; // HEAP_BASE is a constant generated by the compiler
var HEAP_OFFSET: usize = HEAP_BASE; // HEAP_BASE is a constant generated by the compiler
// TODO: maybe tlsf
@ -15,11 +15,11 @@ export class Heap {
static allocate(size: usize): usize {
if (!size) return 0;
const len: i32 = current_memory();
var len: i32 = current_memory();
if (HEAP_OFFSET + size > <usize>len << 16)
if(grow_memory(max<i32>(<i32>ceil<f64>(<f64>size / 65536), len * 2 - len)) < 0)
unreachable();
const ptr: usize = HEAP_OFFSET;
var ptr: usize = HEAP_OFFSET;
if ((HEAP_OFFSET += size) & ALIGN_MASK) // align next offset
HEAP_OFFSET = (HEAP_OFFSET | ALIGN_MASK) + 1;
return ptr;
@ -33,8 +33,8 @@ export class Heap {
assert(dest >= HEAP_BASE);
// the following is based on musl's implementation of memcpy
let dst: usize = dest;
let w: u32, x: u32;
var dst: usize = dest;
var w: u32, x: u32;
// copy 1 byte each until src is aligned to 4 bytes
while (n && src % 4) {
@ -180,7 +180,7 @@ export class Heap {
// the following is based on musl's implementation of memset
if (!n) return dest;
let s: usize = dest;
var s: usize = dest;
// Fill head and tail with minimal branching
store<u8>(s, c); store<u8>(s + n - 1, c);
@ -192,12 +192,12 @@ export class Heap {
if (n <= 8) return dest;
// Align to 4 bytes
let k: usize = -s & 3;
var k: usize = -s & 3;
s += k;
n -= k;
n &= -4;
let c32: u32 = -1 / 255 * c;
var c32: u32 = -1 / 255 * c;
// Fill head and tail in preparation of setting 32 bytes at a time
store<u32>(s, c32);
@ -223,7 +223,7 @@ export class Heap {
n -= k;
// Set 32 bytes at a time
let c64: u64 = <u64>c32 | (<u64>c32 << 32);
var c64: u64 = <u64>c32 | (<u64>c32 << 32);
while (n >= 32) {
store<u64>(s, c64);
store<u64>(s + 8, c64);