diff --git a/src/program.ts b/src/program.ts index 0d610f8b..7cf086dd 100644 --- a/src/program.ts +++ b/src/program.ts @@ -1330,7 +1330,7 @@ export class Program extends DiagnosticEmitter { property, declaration, this.checkDecorators(declaration.decorators, - DecoratorFlags.INLINE + DecoratorFlags.INLINE | DecoratorFlags.UNSAFE ) ); if (isGetter) { diff --git a/std/assembly/allocator/arena.ts b/std/assembly/allocator/arena.ts index 7a5b0364..dfe694d7 100644 --- a/std/assembly/allocator/arena.ts +++ b/std/assembly/allocator/arena.ts @@ -7,7 +7,7 @@ * @module std/assembly/allocator/arena *//***/ -import { AL_MASK, MAX_SIZE_32 } from "../internal/allocator"; +import { AL_MASK, MAX_SIZE_32 } from "../util/allocator"; var startOffset: usize = (HEAP_BASE + AL_MASK) & ~AL_MASK; var offset: usize = startOffset; diff --git a/std/assembly/allocator/tlsf.ts b/std/assembly/allocator/tlsf.ts index ad625041..4d2b9faf 100644 --- a/std/assembly/allocator/tlsf.ts +++ b/std/assembly/allocator/tlsf.ts @@ -15,11 +15,7 @@ // └───────────────────────────────────────────────┴─────────╨─────┘ // FL: first level, SL: second level, AL: alignment, SB: small block -import { - AL_BITS, - AL_SIZE, - AL_MASK -} from "../internal/allocator"; +import { AL_BITS, AL_SIZE, AL_MASK } from "../util/allocator"; const SL_BITS: u32 = 5; const SL_SIZE: usize = 1 << SL_BITS; diff --git a/std/assembly/array.ts b/std/assembly/array.ts index 22f9d236..a2100858 100644 --- a/std/assembly/array.ts +++ b/std/assembly/array.ts @@ -1,32 +1,8 @@ -import { - ALLOC, - REALLOC, - REGISTER, - LINK, - ArrayBufferView, - FREE -} from "./runtime"; - -import { - ArrayBuffer -} from "./arraybuffer"; - -import { - COMPARATOR, - SORT -} from "./util/sort"; - -import { - itoa, - dtoa, - itoa_stream, - dtoa_stream, - MAX_DOUBLE_LENGTH -} from "./util/number"; - -import { - isArray as builtin_isArray -} from "./builtins"; +import { ALLOC, REALLOC, REGISTER, LINK, FREE, ArrayBufferView } from "./runtime"; +import { ArrayBuffer } from "./arraybuffer"; +import { COMPARATOR, SORT } from "./util/sort"; +import { itoa, dtoa, itoa_stream, dtoa_stream, MAX_DOUBLE_LENGTH } from "./util/number"; +import { isArray as builtin_isArray } from "./builtins"; export class Array extends ArrayBufferView { private length_: i32; diff --git a/std/assembly/arraybuffer.ts b/std/assembly/arraybuffer.ts index 1d274aa9..2baa2bf3 100644 --- a/std/assembly/arraybuffer.ts +++ b/std/assembly/arraybuffer.ts @@ -1,26 +1,4 @@ -import { - ALLOC_RAW, - REGISTER, - ArrayBufferBase -} from "./runtime"; - -import { - Int8Array, - Uint8Array, - Uint8ClampedArray, - Int16Array, - Uint16Array, - Int32Array, - Uint32Array, - Int64Array, - Uint64Array, - Float32Array, - Float64Array -} from "./typedarray"; - -import { - DataView -} from "./dataview"; +import { ALLOC_RAW, REGISTER, ArrayBufferBase } from "./runtime"; @sealed export class ArrayBuffer extends ArrayBufferBase { diff --git a/std/assembly/map.ts b/std/assembly/map.ts index 076962bf..7c549124 100644 --- a/std/assembly/map.ts +++ b/std/assembly/map.ts @@ -1,10 +1,5 @@ -import { - HEADER_SIZE as HEADER_SIZE_AB -} from "./internal/arraybuffer"; - -import { - HASH -} from "./internal/hash"; +import { LINK } from "./runtime"; +import { HASH } from "./util/hash"; // A deterministic hash map based on CloseTable from https://github.com/jorendorff/dht @@ -69,8 +64,7 @@ export class Map { private find(key: K, hashCode: u32): MapEntry | null { var entry = load>( - changetype(this.buckets) + (hashCode & this.bucketsMask) * BUCKET_SIZE, - HEADER_SIZE_AB + changetype(this.buckets) + (hashCode & this.bucketsMask) * BUCKET_SIZE ); while (entry) { if (!(entry.taggedNext & EMPTY) && entry.key == key) return entry; @@ -105,17 +99,17 @@ export class Map { // append new entry let entries = this.entries; entry = changetype>( - changetype(entries) + HEADER_SIZE_AB + this.entriesOffset++ * ENTRY_SIZE() + changetype(entries) + this.entriesOffset++ * ENTRY_SIZE() ); entry.key = key; entry.value = value; ++this.entriesCount; // link with previous entry in bucket let bucketPtrBase = changetype(this.buckets) + (hashCode & this.bucketsMask) * BUCKET_SIZE; - entry.taggedNext = load(bucketPtrBase, HEADER_SIZE_AB); - store(bucketPtrBase, changetype(entry), HEADER_SIZE_AB); - if (isManaged()) __gc_link(changetype(this), changetype(key)); // tslint:disable-line - if (isManaged()) __gc_link(changetype(this), changetype(value)); // tslint:disable-line + entry.taggedNext = load(bucketPtrBase); + store(bucketPtrBase, changetype(entry)); + if (isManaged()) LINK(changetype(key), changetype(this)); + if (isManaged()) LINK(changetype(value), changetype(this)); } } @@ -140,9 +134,9 @@ export class Map { var newEntries = new ArrayBuffer(newEntriesCapacity * ENTRY_SIZE(), true); // copy old entries to new entries - var oldPtr = changetype(this.entries) + HEADER_SIZE_AB; + var oldPtr = changetype(this.entries); var oldEnd = oldPtr + this.entriesOffset * ENTRY_SIZE(); - var newPtr = changetype(newEntries) + HEADER_SIZE_AB; + var newPtr = changetype(newEntries); while (oldPtr != oldEnd) { let oldEntry = changetype>(oldPtr); if (!(oldEntry.taggedNext & EMPTY)) { @@ -151,8 +145,8 @@ export class Map { newEntry.value = oldEntry.value; let newBucketIndex = HASH(oldEntry.key) & newBucketsMask; let newBucketPtrBase = changetype(newBuckets) + newBucketIndex * BUCKET_SIZE; - newEntry.taggedNext = load(newBucketPtrBase, HEADER_SIZE_AB); - store(newBucketPtrBase, newPtr, HEADER_SIZE_AB); + newEntry.taggedNext = load(newBucketPtrBase); + store(newBucketPtrBase, newPtr); newPtr += ENTRY_SIZE(); } oldPtr += ENTRY_SIZE(); @@ -169,23 +163,23 @@ export class Map { return "[object Map]"; } - private __gc(): void { - __gc_mark(changetype(this.buckets)); // tslint:disable-line - var entries = this.entries; - __gc_mark(changetype(entries)); // tslint:disable-line - if (isManaged() || isManaged()) { - let offset: usize = 0; - let end: usize = this.entriesOffset * ENTRY_SIZE(); - while (offset < end) { - let entry = changetype>( - changetype(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE() - ); - if (!(entry.taggedNext & EMPTY)) { - if (isManaged()) __gc_mark(changetype(entry.key)); // tslint:disable-line - if (isManaged()) __gc_mark(changetype(entry.value)); // tslint:disable-line - } - offset += ENTRY_SIZE(); - } - } - } + // private __gc(): void { + // __gc_mark(changetype(this.buckets)); // tslint:disable-line + // var entries = this.entries; + // __gc_mark(changetype(entries)); // tslint:disable-line + // if (isManaged() || isManaged()) { + // let offset: usize = 0; + // let end: usize = this.entriesOffset * ENTRY_SIZE(); + // while (offset < end) { + // let entry = changetype>( + // changetype(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE() + // ); + // if (!(entry.taggedNext & EMPTY)) { + // if (isManaged()) __gc_mark(changetype(entry.key)); // tslint:disable-line + // if (isManaged()) __gc_mark(changetype(entry.value)); // tslint:disable-line + // } + // offset += ENTRY_SIZE(); + // } + // } + // } } diff --git a/std/assembly/number.ts b/std/assembly/number.ts index 20288e19..e562b58a 100644 --- a/std/assembly/number.ts +++ b/std/assembly/number.ts @@ -1,15 +1,7 @@ -import { - itoa, - dtoa -} from "./internal/number"; +import { itoa, dtoa } from "./util/number"; +import { isNaN as builtin_isNaN, isFinite as builtin_isFinite } from "./builtins"; -import { - isNaN as builtin_isNaN, - isFinite as builtin_isFinite -} from "./builtins"; - -@sealed -export abstract class I8 { +@sealed export abstract class I8 { @lazy static readonly MIN_VALUE: i8 = i8.MIN_VALUE; @lazy static readonly MAX_VALUE: i8 = i8.MAX_VALUE; @@ -24,8 +16,7 @@ export abstract class I8 { } } -@sealed -export abstract class I16 { +@sealed export abstract class I16 { @lazy static readonly MIN_VALUE: i16 = i16.MIN_VALUE; @lazy static readonly MAX_VALUE: i16 = i16.MAX_VALUE; @@ -40,8 +31,7 @@ export abstract class I16 { } } -@sealed -export abstract class I32 { +@sealed export abstract class I32 { @lazy static readonly MIN_VALUE: i32 = i32.MIN_VALUE; @lazy static readonly MAX_VALUE: i32 = i32.MAX_VALUE; @@ -56,8 +46,7 @@ export abstract class I32 { } } -@sealed -export abstract class I64 { +@sealed export abstract class I64 { @lazy static readonly MIN_VALUE: i64 = i64.MIN_VALUE; @lazy static readonly MAX_VALUE: i64 = i64.MAX_VALUE; @@ -72,8 +61,7 @@ export abstract class I64 { } } -@sealed -export abstract class Isize { +@sealed export abstract class Isize { @lazy static readonly MIN_VALUE: isize = isize.MIN_VALUE; @lazy static readonly MAX_VALUE: isize = isize.MAX_VALUE; @@ -88,8 +76,7 @@ export abstract class Isize { } } -@sealed -export abstract class U8 { +@sealed export abstract class U8 { @lazy static readonly MIN_VALUE: u8 = u8.MIN_VALUE; @lazy static readonly MAX_VALUE: u8 = u8.MAX_VALUE; @@ -104,8 +91,7 @@ export abstract class U8 { } } -@sealed -export abstract class U16 { +@sealed export abstract class U16 { @lazy static readonly MIN_VALUE: u16 = u16.MIN_VALUE; @lazy static readonly MAX_VALUE: u16 = u16.MAX_VALUE; @@ -120,8 +106,7 @@ export abstract class U16 { } } -@sealed -export abstract class U32 { +@sealed export abstract class U32 { @lazy static readonly MIN_VALUE: u32 = u32.MIN_VALUE; @lazy static readonly MAX_VALUE: u32 = u32.MAX_VALUE; @@ -136,8 +121,7 @@ export abstract class U32 { } } -@sealed -export abstract class U64 { +@sealed export abstract class U64 { @lazy static readonly MIN_VALUE: u64 = u64.MIN_VALUE; @lazy static readonly MAX_VALUE: u64 = u64.MAX_VALUE; @@ -152,8 +136,7 @@ export abstract class U64 { } } -@sealed -export abstract class Usize { +@sealed export abstract class Usize { @lazy static readonly MIN_VALUE: usize = usize.MIN_VALUE; @lazy static readonly MAX_VALUE: usize = usize.MAX_VALUE; @@ -168,8 +151,7 @@ export abstract class Usize { } } -@sealed -export abstract class Bool { +@sealed export abstract class Bool { @lazy static readonly MIN_VALUE: bool = bool.MIN_VALUE; @lazy static readonly MAX_VALUE: bool = bool.MAX_VALUE; @@ -182,8 +164,7 @@ export abstract class Bool { export { Bool as Boolean }; -@sealed -export abstract class F32 { +@sealed export abstract class F32 { @lazy static readonly EPSILON: f32 = f32.EPSILON; @lazy static readonly MIN_VALUE: f32 = f32.MIN_VALUE; @@ -224,8 +205,7 @@ export abstract class F32 { } } -@sealed -export abstract class F64 { +@sealed export abstract class F64 { @lazy static readonly EPSILON: f64 = f64.EPSILON; @lazy static readonly MIN_VALUE: f64 = f64.MIN_VALUE; diff --git a/std/assembly/set.ts b/std/assembly/set.ts index e7f527ef..09e5da5f 100644 --- a/std/assembly/set.ts +++ b/std/assembly/set.ts @@ -1,10 +1,5 @@ -import { - HEADER_SIZE as HEADER_SIZE_AB -} from "./internal/arraybuffer"; - -import { - HASH -} from "./internal/hash"; +import { LINK } from "./runtime"; +import { HASH } from "./util/hash"; // A deterministic hash set based on CloseTable from https://github.com/jorendorff/dht @@ -67,8 +62,7 @@ export class Set { private find(key: K, hashCode: u32): SetEntry | null { var entry = load>( - changetype(this.buckets) + (hashCode & this.bucketsMask) * BUCKET_SIZE, - HEADER_SIZE_AB + changetype(this.buckets) + (hashCode & this.bucketsMask) * BUCKET_SIZE ); while (entry) { if (!(entry.taggedNext & EMPTY) && entry.key == key) return entry; @@ -96,15 +90,15 @@ export class Set { // append new entry let entries = this.entries; entry = changetype>( - changetype(entries) + HEADER_SIZE_AB + this.entriesOffset++ * ENTRY_SIZE() + changetype(entries) + this.entriesOffset++ * ENTRY_SIZE() ); entry.key = key; ++this.entriesCount; // link with previous entry in bucket let bucketPtrBase = changetype(this.buckets) + (hashCode & this.bucketsMask) * BUCKET_SIZE; - entry.taggedNext = load(bucketPtrBase, HEADER_SIZE_AB); - store(bucketPtrBase, changetype(entry), HEADER_SIZE_AB); - if (isManaged()) __gc_link(changetype(this), changetype(key)); // tslint:disable-line + entry.taggedNext = load(bucketPtrBase); + store(bucketPtrBase, changetype(entry)); + if (isManaged()) LINK(changetype(key), changetype(this)); // tslint:disable-line } } @@ -129,9 +123,9 @@ export class Set { var newEntries = new ArrayBuffer(newEntriesCapacity * ENTRY_SIZE(), true); // copy old entries to new entries - var oldPtr = changetype(this.entries) + HEADER_SIZE_AB; + var oldPtr = changetype(this.entries); var oldEnd = oldPtr + this.entriesOffset * ENTRY_SIZE(); - var newPtr = changetype(newEntries) + HEADER_SIZE_AB; + var newPtr = changetype(newEntries); while (oldPtr != oldEnd) { let oldEntry = changetype>(oldPtr); if (!(oldEntry.taggedNext & EMPTY)) { @@ -139,8 +133,8 @@ export class Set { newEntry.key = oldEntry.key; let newBucketIndex = HASH(oldEntry.key) & newBucketsMask; let newBucketPtrBase = changetype(newBuckets) + newBucketIndex * BUCKET_SIZE; - newEntry.taggedNext = load(newBucketPtrBase, HEADER_SIZE_AB); - store(newBucketPtrBase, newPtr, HEADER_SIZE_AB); + newEntry.taggedNext = load(newBucketPtrBase); + store(newBucketPtrBase, newPtr); newPtr += ENTRY_SIZE(); } oldPtr += ENTRY_SIZE(); @@ -157,20 +151,20 @@ export class Set { return "[object Set]"; } - private __gc(): void { - __gc_mark(changetype(this.buckets)); // tslint:disable-line - var entries = this.entries; - __gc_mark(changetype(entries)); // tslint:disable-line - if (isManaged()) { - let offset: usize = 0; - let end: usize = this.entriesOffset * ENTRY_SIZE(); - while (offset < end) { - let entry = changetype>( - changetype(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE() - ); - if (!(entry.taggedNext & EMPTY)) __gc_mark(changetype(entry.key)); // tslint:disable-line - offset += ENTRY_SIZE(); - } - } - } + // private __gc(): void { + // __gc_mark(changetype(this.buckets)); // tslint:disable-line + // var entries = this.entries; + // __gc_mark(changetype(entries)); // tslint:disable-line + // if (isManaged()) { + // let offset: usize = 0; + // let end: usize = this.entriesOffset * ENTRY_SIZE(); + // while (offset < end) { + // let entry = changetype>( + // changetype(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE() + // ); + // if (!(entry.taggedNext & EMPTY)) __gc_mark(changetype(entry.key)); // tslint:disable-line + // offset += ENTRY_SIZE(); + // } + // } + // } }