mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-05-02 10:22:15 +00:00
more
This commit is contained in:
parent
37d361bafd
commit
707f2dae9a
@ -1330,7 +1330,7 @@ export class Program extends DiagnosticEmitter {
|
||||
property,
|
||||
declaration,
|
||||
this.checkDecorators(declaration.decorators,
|
||||
DecoratorFlags.INLINE
|
||||
DecoratorFlags.INLINE | DecoratorFlags.UNSAFE
|
||||
)
|
||||
);
|
||||
if (isGetter) {
|
||||
|
@ -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;
|
||||
|
@ -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 << <usize>SL_BITS;
|
||||
|
@ -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<T> extends ArrayBufferView {
|
||||
private length_: i32;
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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<K,V> {
|
||||
|
||||
private find(key: K, hashCode: u32): MapEntry<K,V> | null {
|
||||
var entry = load<MapEntry<K,V>>(
|
||||
changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE,
|
||||
HEADER_SIZE_AB
|
||||
changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE
|
||||
);
|
||||
while (entry) {
|
||||
if (!(entry.taggedNext & EMPTY) && entry.key == key) return entry;
|
||||
@ -105,17 +99,17 @@ export class Map<K,V> {
|
||||
// append new entry
|
||||
let entries = this.entries;
|
||||
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.value = value;
|
||||
++this.entriesCount;
|
||||
// link with previous entry in bucket
|
||||
let bucketPtrBase = changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE;
|
||||
entry.taggedNext = load<usize>(bucketPtrBase, HEADER_SIZE_AB);
|
||||
store<usize>(bucketPtrBase, changetype<usize>(entry), HEADER_SIZE_AB);
|
||||
if (isManaged<K>()) __gc_link(changetype<usize>(this), changetype<usize>(key)); // tslint:disable-line
|
||||
if (isManaged<V>()) __gc_link(changetype<usize>(this), changetype<usize>(value)); // tslint:disable-line
|
||||
entry.taggedNext = load<usize>(bucketPtrBase);
|
||||
store<usize>(bucketPtrBase, changetype<usize>(entry));
|
||||
if (isManaged<K>()) LINK(changetype<usize>(key), changetype<usize>(this));
|
||||
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);
|
||||
|
||||
// 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 newPtr = changetype<usize>(newEntries) + HEADER_SIZE_AB;
|
||||
var newPtr = changetype<usize>(newEntries);
|
||||
while (oldPtr != oldEnd) {
|
||||
let oldEntry = changetype<MapEntry<K,V>>(oldPtr);
|
||||
if (!(oldEntry.taggedNext & EMPTY)) {
|
||||
@ -151,8 +145,8 @@ export class Map<K,V> {
|
||||
newEntry.value = oldEntry.value;
|
||||
let newBucketIndex = HASH<K>(oldEntry.key) & newBucketsMask;
|
||||
let newBucketPtrBase = changetype<usize>(newBuckets) + <usize>newBucketIndex * BUCKET_SIZE;
|
||||
newEntry.taggedNext = load<usize>(newBucketPtrBase, HEADER_SIZE_AB);
|
||||
store<usize>(newBucketPtrBase, newPtr, HEADER_SIZE_AB);
|
||||
newEntry.taggedNext = load<usize>(newBucketPtrBase);
|
||||
store<usize>(newBucketPtrBase, newPtr);
|
||||
newPtr += ENTRY_SIZE<K,V>();
|
||||
}
|
||||
oldPtr += ENTRY_SIZE<K,V>();
|
||||
@ -169,23 +163,23 @@ export class Map<K,V> {
|
||||
return "[object Map]";
|
||||
}
|
||||
|
||||
private __gc(): void {
|
||||
__gc_mark(changetype<usize>(this.buckets)); // tslint:disable-line
|
||||
var entries = this.entries;
|
||||
__gc_mark(changetype<usize>(entries)); // tslint:disable-line
|
||||
if (isManaged<K>() || isManaged<V>()) {
|
||||
let offset: usize = 0;
|
||||
let end: usize = this.entriesOffset * ENTRY_SIZE<K,V>();
|
||||
while (offset < end) {
|
||||
let entry = changetype<MapEntry<K,V>>(
|
||||
changetype<usize>(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE<K,V>()
|
||||
);
|
||||
if (!(entry.taggedNext & EMPTY)) {
|
||||
if (isManaged<K>()) __gc_mark(changetype<usize>(entry.key)); // tslint:disable-line
|
||||
if (isManaged<V>()) __gc_mark(changetype<usize>(entry.value)); // tslint:disable-line
|
||||
}
|
||||
offset += ENTRY_SIZE<K,V>();
|
||||
}
|
||||
}
|
||||
}
|
||||
// private __gc(): void {
|
||||
// __gc_mark(changetype<usize>(this.buckets)); // tslint:disable-line
|
||||
// var entries = this.entries;
|
||||
// __gc_mark(changetype<usize>(entries)); // tslint:disable-line
|
||||
// if (isManaged<K>() || isManaged<V>()) {
|
||||
// let offset: usize = 0;
|
||||
// let end: usize = this.entriesOffset * ENTRY_SIZE<K,V>();
|
||||
// while (offset < end) {
|
||||
// let entry = changetype<MapEntry<K,V>>(
|
||||
// changetype<usize>(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE<K,V>()
|
||||
// );
|
||||
// if (!(entry.taggedNext & EMPTY)) {
|
||||
// if (isManaged<K>()) __gc_mark(changetype<usize>(entry.key)); // tslint:disable-line
|
||||
// if (isManaged<V>()) __gc_mark(changetype<usize>(entry.value)); // tslint:disable-line
|
||||
// }
|
||||
// offset += ENTRY_SIZE<K,V>();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<K> {
|
||||
|
||||
private find(key: K, hashCode: u32): SetEntry<K> | null {
|
||||
var entry = load<SetEntry<K>>(
|
||||
changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE,
|
||||
HEADER_SIZE_AB
|
||||
changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE
|
||||
);
|
||||
while (entry) {
|
||||
if (!(entry.taggedNext & EMPTY) && entry.key == key) return entry;
|
||||
@ -96,15 +90,15 @@ export class Set<K> {
|
||||
// append new entry
|
||||
let entries = this.entries;
|
||||
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;
|
||||
++this.entriesCount;
|
||||
// link with previous entry in bucket
|
||||
let bucketPtrBase = changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE;
|
||||
entry.taggedNext = load<usize>(bucketPtrBase, HEADER_SIZE_AB);
|
||||
store<usize>(bucketPtrBase, changetype<usize>(entry), HEADER_SIZE_AB);
|
||||
if (isManaged<K>()) __gc_link(changetype<usize>(this), changetype<usize>(key)); // tslint:disable-line
|
||||
entry.taggedNext = load<usize>(bucketPtrBase);
|
||||
store<usize>(bucketPtrBase, changetype<usize>(entry));
|
||||
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);
|
||||
|
||||
// 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 newPtr = changetype<usize>(newEntries) + HEADER_SIZE_AB;
|
||||
var newPtr = changetype<usize>(newEntries);
|
||||
while (oldPtr != oldEnd) {
|
||||
let oldEntry = changetype<SetEntry<K>>(oldPtr);
|
||||
if (!(oldEntry.taggedNext & EMPTY)) {
|
||||
@ -139,8 +133,8 @@ export class Set<K> {
|
||||
newEntry.key = oldEntry.key;
|
||||
let newBucketIndex = HASH<K>(oldEntry.key) & newBucketsMask;
|
||||
let newBucketPtrBase = changetype<usize>(newBuckets) + <usize>newBucketIndex * BUCKET_SIZE;
|
||||
newEntry.taggedNext = load<usize>(newBucketPtrBase, HEADER_SIZE_AB);
|
||||
store<usize>(newBucketPtrBase, newPtr, HEADER_SIZE_AB);
|
||||
newEntry.taggedNext = load<usize>(newBucketPtrBase);
|
||||
store<usize>(newBucketPtrBase, newPtr);
|
||||
newPtr += ENTRY_SIZE<K>();
|
||||
}
|
||||
oldPtr += ENTRY_SIZE<K>();
|
||||
@ -157,20 +151,20 @@ export class Set<K> {
|
||||
return "[object Set]";
|
||||
}
|
||||
|
||||
private __gc(): void {
|
||||
__gc_mark(changetype<usize>(this.buckets)); // tslint:disable-line
|
||||
var entries = this.entries;
|
||||
__gc_mark(changetype<usize>(entries)); // tslint:disable-line
|
||||
if (isManaged<K>()) {
|
||||
let offset: usize = 0;
|
||||
let end: usize = this.entriesOffset * ENTRY_SIZE<K>();
|
||||
while (offset < end) {
|
||||
let entry = changetype<SetEntry<K>>(
|
||||
changetype<usize>(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE<K>()
|
||||
);
|
||||
if (!(entry.taggedNext & EMPTY)) __gc_mark(changetype<usize>(entry.key)); // tslint:disable-line
|
||||
offset += ENTRY_SIZE<K>();
|
||||
}
|
||||
}
|
||||
}
|
||||
// private __gc(): void {
|
||||
// __gc_mark(changetype<usize>(this.buckets)); // tslint:disable-line
|
||||
// var entries = this.entries;
|
||||
// __gc_mark(changetype<usize>(entries)); // tslint:disable-line
|
||||
// if (isManaged<K>()) {
|
||||
// let offset: usize = 0;
|
||||
// let end: usize = this.entriesOffset * ENTRY_SIZE<K>();
|
||||
// while (offset < end) {
|
||||
// let entry = changetype<SetEntry<K>>(
|
||||
// changetype<usize>(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE<K>()
|
||||
// );
|
||||
// if (!(entry.taggedNext & EMPTY)) __gc_mark(changetype<usize>(entry.key)); // tslint:disable-line
|
||||
// offset += ENTRY_SIZE<K>();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user