This commit is contained in:
dcode 2019-03-13 03:47:35 +01:00
parent 37d361bafd
commit 707f2dae9a
8 changed files with 82 additions and 164 deletions

View File

@ -1330,7 +1330,7 @@ export class Program extends DiagnosticEmitter {
property, property,
declaration, declaration,
this.checkDecorators(declaration.decorators, this.checkDecorators(declaration.decorators,
DecoratorFlags.INLINE DecoratorFlags.INLINE | DecoratorFlags.UNSAFE
) )
); );
if (isGetter) { if (isGetter) {

View File

@ -7,7 +7,7 @@
* @module std/assembly/allocator/arena * @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 startOffset: usize = (HEAP_BASE + AL_MASK) & ~AL_MASK;
var offset: usize = startOffset; var offset: usize = startOffset;

View File

@ -15,11 +15,7 @@
// └───────────────────────────────────────────────┴─────────╨─────┘ // └───────────────────────────────────────────────┴─────────╨─────┘
// FL: first level, SL: second level, AL: alignment, SB: small block // FL: first level, SL: second level, AL: alignment, SB: small block
import { import { AL_BITS, AL_SIZE, AL_MASK } from "../util/allocator";
AL_BITS,
AL_SIZE,
AL_MASK
} from "../internal/allocator";
const SL_BITS: u32 = 5; const SL_BITS: u32 = 5;
const SL_SIZE: usize = 1 << <usize>SL_BITS; const SL_SIZE: usize = 1 << <usize>SL_BITS;

View File

@ -1,32 +1,8 @@
import { import { ALLOC, REALLOC, REGISTER, LINK, FREE, ArrayBufferView } from "./runtime";
ALLOC, import { ArrayBuffer } from "./arraybuffer";
REALLOC, import { COMPARATOR, SORT } from "./util/sort";
REGISTER, import { itoa, dtoa, itoa_stream, dtoa_stream, MAX_DOUBLE_LENGTH } from "./util/number";
LINK, import { isArray as builtin_isArray } from "./builtins";
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";
export class Array<T> extends ArrayBufferView { export class Array<T> extends ArrayBufferView {
private length_: i32; private length_: i32;

View File

@ -1,26 +1,4 @@
import { import { ALLOC_RAW, REGISTER, ArrayBufferBase } from "./runtime";
ALLOC_RAW,
REGISTER,
ArrayBufferBase
} from "./runtime";
import {
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Int64Array,
Uint64Array,
Float32Array,
Float64Array
} from "./typedarray";
import {
DataView
} from "./dataview";
@sealed export class ArrayBuffer extends ArrayBufferBase { @sealed export class ArrayBuffer extends ArrayBufferBase {

View File

@ -1,10 +1,5 @@
import { import { LINK } from "./runtime";
HEADER_SIZE as HEADER_SIZE_AB import { HASH } from "./util/hash";
} from "./internal/arraybuffer";
import {
HASH
} from "./internal/hash";
// A deterministic hash map based on CloseTable from https://github.com/jorendorff/dht // A deterministic hash map based on CloseTable from https://github.com/jorendorff/dht
@ -69,8 +64,7 @@ export class Map<K,V> {
private find(key: K, hashCode: u32): MapEntry<K,V> | null { private find(key: K, hashCode: u32): MapEntry<K,V> | null {
var entry = load<MapEntry<K,V>>( var entry = load<MapEntry<K,V>>(
changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE, changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE
HEADER_SIZE_AB
); );
while (entry) { while (entry) {
if (!(entry.taggedNext & EMPTY) && entry.key == key) return entry; if (!(entry.taggedNext & EMPTY) && entry.key == key) return entry;
@ -105,17 +99,17 @@ export class Map<K,V> {
// append new entry // append new entry
let entries = this.entries; let entries = this.entries;
entry = changetype<MapEntry<K,V>>( entry = changetype<MapEntry<K,V>>(
changetype<usize>(entries) + HEADER_SIZE_AB + this.entriesOffset++ * ENTRY_SIZE<K,V>() changetype<usize>(entries) + this.entriesOffset++ * ENTRY_SIZE<K,V>()
); );
entry.key = key; entry.key = key;
entry.value = value; entry.value = value;
++this.entriesCount; ++this.entriesCount;
// link with previous entry in bucket // link with previous entry in bucket
let bucketPtrBase = changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE; let bucketPtrBase = changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE;
entry.taggedNext = load<usize>(bucketPtrBase, HEADER_SIZE_AB); entry.taggedNext = load<usize>(bucketPtrBase);
store<usize>(bucketPtrBase, changetype<usize>(entry), HEADER_SIZE_AB); store<usize>(bucketPtrBase, changetype<usize>(entry));
if (isManaged<K>()) __gc_link(changetype<usize>(this), changetype<usize>(key)); // tslint:disable-line if (isManaged<K>()) LINK(changetype<usize>(key), changetype<usize>(this));
if (isManaged<V>()) __gc_link(changetype<usize>(this), changetype<usize>(value)); // tslint:disable-line if (isManaged<V>()) LINK(changetype<usize>(value), changetype<usize>(this));
} }
} }
@ -140,9 +134,9 @@ export class Map<K,V> {
var newEntries = new ArrayBuffer(newEntriesCapacity * <i32>ENTRY_SIZE<K,V>(), true); var newEntries = new ArrayBuffer(newEntriesCapacity * <i32>ENTRY_SIZE<K,V>(), true);
// copy old entries to new entries // copy old entries to new entries
var oldPtr = changetype<usize>(this.entries) + HEADER_SIZE_AB; var oldPtr = changetype<usize>(this.entries);
var oldEnd = oldPtr + <usize>this.entriesOffset * ENTRY_SIZE<K,V>(); var oldEnd = oldPtr + <usize>this.entriesOffset * ENTRY_SIZE<K,V>();
var newPtr = changetype<usize>(newEntries) + HEADER_SIZE_AB; var newPtr = changetype<usize>(newEntries);
while (oldPtr != oldEnd) { while (oldPtr != oldEnd) {
let oldEntry = changetype<MapEntry<K,V>>(oldPtr); let oldEntry = changetype<MapEntry<K,V>>(oldPtr);
if (!(oldEntry.taggedNext & EMPTY)) { if (!(oldEntry.taggedNext & EMPTY)) {
@ -151,8 +145,8 @@ export class Map<K,V> {
newEntry.value = oldEntry.value; newEntry.value = oldEntry.value;
let newBucketIndex = HASH<K>(oldEntry.key) & newBucketsMask; let newBucketIndex = HASH<K>(oldEntry.key) & newBucketsMask;
let newBucketPtrBase = changetype<usize>(newBuckets) + <usize>newBucketIndex * BUCKET_SIZE; let newBucketPtrBase = changetype<usize>(newBuckets) + <usize>newBucketIndex * BUCKET_SIZE;
newEntry.taggedNext = load<usize>(newBucketPtrBase, HEADER_SIZE_AB); newEntry.taggedNext = load<usize>(newBucketPtrBase);
store<usize>(newBucketPtrBase, newPtr, HEADER_SIZE_AB); store<usize>(newBucketPtrBase, newPtr);
newPtr += ENTRY_SIZE<K,V>(); newPtr += ENTRY_SIZE<K,V>();
} }
oldPtr += ENTRY_SIZE<K,V>(); oldPtr += ENTRY_SIZE<K,V>();
@ -169,23 +163,23 @@ export class Map<K,V> {
return "[object Map]"; return "[object Map]";
} }
private __gc(): void { // private __gc(): void {
__gc_mark(changetype<usize>(this.buckets)); // tslint:disable-line // __gc_mark(changetype<usize>(this.buckets)); // tslint:disable-line
var entries = this.entries; // var entries = this.entries;
__gc_mark(changetype<usize>(entries)); // tslint:disable-line // __gc_mark(changetype<usize>(entries)); // tslint:disable-line
if (isManaged<K>() || isManaged<V>()) { // if (isManaged<K>() || isManaged<V>()) {
let offset: usize = 0; // let offset: usize = 0;
let end: usize = this.entriesOffset * ENTRY_SIZE<K,V>(); // let end: usize = this.entriesOffset * ENTRY_SIZE<K,V>();
while (offset < end) { // while (offset < end) {
let entry = changetype<MapEntry<K,V>>( // let entry = changetype<MapEntry<K,V>>(
changetype<usize>(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE<K,V>() // changetype<usize>(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE<K,V>()
); // );
if (!(entry.taggedNext & EMPTY)) { // if (!(entry.taggedNext & EMPTY)) {
if (isManaged<K>()) __gc_mark(changetype<usize>(entry.key)); // tslint:disable-line // if (isManaged<K>()) __gc_mark(changetype<usize>(entry.key)); // tslint:disable-line
if (isManaged<V>()) __gc_mark(changetype<usize>(entry.value)); // tslint:disable-line // if (isManaged<V>()) __gc_mark(changetype<usize>(entry.value)); // tslint:disable-line
} // }
offset += ENTRY_SIZE<K,V>(); // offset += ENTRY_SIZE<K,V>();
} // }
} // }
} // }
} }

View File

@ -1,15 +1,7 @@
import { import { itoa, dtoa } from "./util/number";
itoa, import { isNaN as builtin_isNaN, isFinite as builtin_isFinite } from "./builtins";
dtoa
} from "./internal/number";
import { @sealed export abstract class I8 {
isNaN as builtin_isNaN,
isFinite as builtin_isFinite
} from "./builtins";
@sealed
export abstract class I8 {
@lazy static readonly MIN_VALUE: i8 = i8.MIN_VALUE; @lazy static readonly MIN_VALUE: i8 = i8.MIN_VALUE;
@lazy static readonly MAX_VALUE: i8 = i8.MAX_VALUE; @lazy static readonly MAX_VALUE: i8 = i8.MAX_VALUE;
@ -24,8 +16,7 @@ export abstract class I8 {
} }
} }
@sealed @sealed export abstract class I16 {
export abstract class I16 {
@lazy static readonly MIN_VALUE: i16 = i16.MIN_VALUE; @lazy static readonly MIN_VALUE: i16 = i16.MIN_VALUE;
@lazy static readonly MAX_VALUE: i16 = i16.MAX_VALUE; @lazy static readonly MAX_VALUE: i16 = i16.MAX_VALUE;
@ -40,8 +31,7 @@ export abstract class I16 {
} }
} }
@sealed @sealed export abstract class I32 {
export abstract class I32 {
@lazy static readonly MIN_VALUE: i32 = i32.MIN_VALUE; @lazy static readonly MIN_VALUE: i32 = i32.MIN_VALUE;
@lazy static readonly MAX_VALUE: i32 = i32.MAX_VALUE; @lazy static readonly MAX_VALUE: i32 = i32.MAX_VALUE;
@ -56,8 +46,7 @@ export abstract class I32 {
} }
} }
@sealed @sealed export abstract class I64 {
export abstract class I64 {
@lazy static readonly MIN_VALUE: i64 = i64.MIN_VALUE; @lazy static readonly MIN_VALUE: i64 = i64.MIN_VALUE;
@lazy static readonly MAX_VALUE: i64 = i64.MAX_VALUE; @lazy static readonly MAX_VALUE: i64 = i64.MAX_VALUE;
@ -72,8 +61,7 @@ export abstract class I64 {
} }
} }
@sealed @sealed export abstract class Isize {
export abstract class Isize {
@lazy static readonly MIN_VALUE: isize = isize.MIN_VALUE; @lazy static readonly MIN_VALUE: isize = isize.MIN_VALUE;
@lazy static readonly MAX_VALUE: isize = isize.MAX_VALUE; @lazy static readonly MAX_VALUE: isize = isize.MAX_VALUE;
@ -88,8 +76,7 @@ export abstract class Isize {
} }
} }
@sealed @sealed export abstract class U8 {
export abstract class U8 {
@lazy static readonly MIN_VALUE: u8 = u8.MIN_VALUE; @lazy static readonly MIN_VALUE: u8 = u8.MIN_VALUE;
@lazy static readonly MAX_VALUE: u8 = u8.MAX_VALUE; @lazy static readonly MAX_VALUE: u8 = u8.MAX_VALUE;
@ -104,8 +91,7 @@ export abstract class U8 {
} }
} }
@sealed @sealed export abstract class U16 {
export abstract class U16 {
@lazy static readonly MIN_VALUE: u16 = u16.MIN_VALUE; @lazy static readonly MIN_VALUE: u16 = u16.MIN_VALUE;
@lazy static readonly MAX_VALUE: u16 = u16.MAX_VALUE; @lazy static readonly MAX_VALUE: u16 = u16.MAX_VALUE;
@ -120,8 +106,7 @@ export abstract class U16 {
} }
} }
@sealed @sealed export abstract class U32 {
export abstract class U32 {
@lazy static readonly MIN_VALUE: u32 = u32.MIN_VALUE; @lazy static readonly MIN_VALUE: u32 = u32.MIN_VALUE;
@lazy static readonly MAX_VALUE: u32 = u32.MAX_VALUE; @lazy static readonly MAX_VALUE: u32 = u32.MAX_VALUE;
@ -136,8 +121,7 @@ export abstract class U32 {
} }
} }
@sealed @sealed export abstract class U64 {
export abstract class U64 {
@lazy static readonly MIN_VALUE: u64 = u64.MIN_VALUE; @lazy static readonly MIN_VALUE: u64 = u64.MIN_VALUE;
@lazy static readonly MAX_VALUE: u64 = u64.MAX_VALUE; @lazy static readonly MAX_VALUE: u64 = u64.MAX_VALUE;
@ -152,8 +136,7 @@ export abstract class U64 {
} }
} }
@sealed @sealed export abstract class Usize {
export abstract class Usize {
@lazy static readonly MIN_VALUE: usize = usize.MIN_VALUE; @lazy static readonly MIN_VALUE: usize = usize.MIN_VALUE;
@lazy static readonly MAX_VALUE: usize = usize.MAX_VALUE; @lazy static readonly MAX_VALUE: usize = usize.MAX_VALUE;
@ -168,8 +151,7 @@ export abstract class Usize {
} }
} }
@sealed @sealed export abstract class Bool {
export abstract class Bool {
@lazy static readonly MIN_VALUE: bool = bool.MIN_VALUE; @lazy static readonly MIN_VALUE: bool = bool.MIN_VALUE;
@lazy static readonly MAX_VALUE: bool = bool.MAX_VALUE; @lazy static readonly MAX_VALUE: bool = bool.MAX_VALUE;
@ -182,8 +164,7 @@ export abstract class Bool {
export { Bool as Boolean }; export { Bool as Boolean };
@sealed @sealed export abstract class F32 {
export abstract class F32 {
@lazy static readonly EPSILON: f32 = f32.EPSILON; @lazy static readonly EPSILON: f32 = f32.EPSILON;
@lazy static readonly MIN_VALUE: f32 = f32.MIN_VALUE; @lazy static readonly MIN_VALUE: f32 = f32.MIN_VALUE;
@ -224,8 +205,7 @@ export abstract class F32 {
} }
} }
@sealed @sealed export abstract class F64 {
export abstract class F64 {
@lazy static readonly EPSILON: f64 = f64.EPSILON; @lazy static readonly EPSILON: f64 = f64.EPSILON;
@lazy static readonly MIN_VALUE: f64 = f64.MIN_VALUE; @lazy static readonly MIN_VALUE: f64 = f64.MIN_VALUE;

View File

@ -1,10 +1,5 @@
import { import { LINK } from "./runtime";
HEADER_SIZE as HEADER_SIZE_AB import { HASH } from "./util/hash";
} from "./internal/arraybuffer";
import {
HASH
} from "./internal/hash";
// A deterministic hash set based on CloseTable from https://github.com/jorendorff/dht // A deterministic hash set based on CloseTable from https://github.com/jorendorff/dht
@ -67,8 +62,7 @@ export class Set<K> {
private find(key: K, hashCode: u32): SetEntry<K> | null { private find(key: K, hashCode: u32): SetEntry<K> | null {
var entry = load<SetEntry<K>>( var entry = load<SetEntry<K>>(
changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE, changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE
HEADER_SIZE_AB
); );
while (entry) { while (entry) {
if (!(entry.taggedNext & EMPTY) && entry.key == key) return entry; if (!(entry.taggedNext & EMPTY) && entry.key == key) return entry;
@ -96,15 +90,15 @@ export class Set<K> {
// append new entry // append new entry
let entries = this.entries; let entries = this.entries;
entry = changetype<SetEntry<K>>( entry = changetype<SetEntry<K>>(
changetype<usize>(entries) + HEADER_SIZE_AB + this.entriesOffset++ * ENTRY_SIZE<K>() changetype<usize>(entries) + this.entriesOffset++ * ENTRY_SIZE<K>()
); );
entry.key = key; entry.key = key;
++this.entriesCount; ++this.entriesCount;
// link with previous entry in bucket // link with previous entry in bucket
let bucketPtrBase = changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE; let bucketPtrBase = changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE;
entry.taggedNext = load<usize>(bucketPtrBase, HEADER_SIZE_AB); entry.taggedNext = load<usize>(bucketPtrBase);
store<usize>(bucketPtrBase, changetype<usize>(entry), HEADER_SIZE_AB); store<usize>(bucketPtrBase, changetype<usize>(entry));
if (isManaged<K>()) __gc_link(changetype<usize>(this), changetype<usize>(key)); // tslint:disable-line if (isManaged<K>()) LINK(changetype<usize>(key), changetype<usize>(this)); // tslint:disable-line
} }
} }
@ -129,9 +123,9 @@ export class Set<K> {
var newEntries = new ArrayBuffer(newEntriesCapacity * <i32>ENTRY_SIZE<K>(), true); var newEntries = new ArrayBuffer(newEntriesCapacity * <i32>ENTRY_SIZE<K>(), true);
// copy old entries to new entries // copy old entries to new entries
var oldPtr = changetype<usize>(this.entries) + HEADER_SIZE_AB; var oldPtr = changetype<usize>(this.entries);
var oldEnd = oldPtr + <usize>this.entriesOffset * ENTRY_SIZE<K>(); var oldEnd = oldPtr + <usize>this.entriesOffset * ENTRY_SIZE<K>();
var newPtr = changetype<usize>(newEntries) + HEADER_SIZE_AB; var newPtr = changetype<usize>(newEntries);
while (oldPtr != oldEnd) { while (oldPtr != oldEnd) {
let oldEntry = changetype<SetEntry<K>>(oldPtr); let oldEntry = changetype<SetEntry<K>>(oldPtr);
if (!(oldEntry.taggedNext & EMPTY)) { if (!(oldEntry.taggedNext & EMPTY)) {
@ -139,8 +133,8 @@ export class Set<K> {
newEntry.key = oldEntry.key; newEntry.key = oldEntry.key;
let newBucketIndex = HASH<K>(oldEntry.key) & newBucketsMask; let newBucketIndex = HASH<K>(oldEntry.key) & newBucketsMask;
let newBucketPtrBase = changetype<usize>(newBuckets) + <usize>newBucketIndex * BUCKET_SIZE; let newBucketPtrBase = changetype<usize>(newBuckets) + <usize>newBucketIndex * BUCKET_SIZE;
newEntry.taggedNext = load<usize>(newBucketPtrBase, HEADER_SIZE_AB); newEntry.taggedNext = load<usize>(newBucketPtrBase);
store<usize>(newBucketPtrBase, newPtr, HEADER_SIZE_AB); store<usize>(newBucketPtrBase, newPtr);
newPtr += ENTRY_SIZE<K>(); newPtr += ENTRY_SIZE<K>();
} }
oldPtr += ENTRY_SIZE<K>(); oldPtr += ENTRY_SIZE<K>();
@ -157,20 +151,20 @@ export class Set<K> {
return "[object Set]"; return "[object Set]";
} }
private __gc(): void { // private __gc(): void {
__gc_mark(changetype<usize>(this.buckets)); // tslint:disable-line // __gc_mark(changetype<usize>(this.buckets)); // tslint:disable-line
var entries = this.entries; // var entries = this.entries;
__gc_mark(changetype<usize>(entries)); // tslint:disable-line // __gc_mark(changetype<usize>(entries)); // tslint:disable-line
if (isManaged<K>()) { // if (isManaged<K>()) {
let offset: usize = 0; // let offset: usize = 0;
let end: usize = this.entriesOffset * ENTRY_SIZE<K>(); // let end: usize = this.entriesOffset * ENTRY_SIZE<K>();
while (offset < end) { // while (offset < end) {
let entry = changetype<SetEntry<K>>( // let entry = changetype<SetEntry<K>>(
changetype<usize>(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE<K>() // changetype<usize>(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE<K>()
); // );
if (!(entry.taggedNext & EMPTY)) __gc_mark(changetype<usize>(entry.key)); // tslint:disable-line // if (!(entry.taggedNext & EMPTY)) __gc_mark(changetype<usize>(entry.key)); // tslint:disable-line
offset += ENTRY_SIZE<K>(); // offset += ENTRY_SIZE<K>();
} // }
} // }
} // }
} }