Rework resolver (#489)

* Rework IR and resolver to use nested lookup tables
* Integrate types into IR
* Make components prefer IR, slimmed down AST
* Implement `export *`
* Add `@lazy` annotation and remove `--noTreeShaking`
* Add `@start` annotation and remove magic `main`
* Related refactoring, cleanup and docs
This commit is contained in:
Daniel Wirtz
2019-02-21 00:11:22 +01:00
committed by GitHub
parent e623786b42
commit 0c64f21250
234 changed files with 16949 additions and 37871 deletions

View File

@ -59,20 +59,20 @@ export namespace atomic {
@builtin export declare function i8(value: void): i8;
export namespace i8 {
export const MIN_VALUE: i8 = -128;
export const MAX_VALUE: i8 = 127;
@lazy export const MIN_VALUE: i8 = -128;
@lazy export const MAX_VALUE: i8 = 127;
}
@builtin export declare function i16(value: void): i16;
export namespace i16 {
export const MIN_VALUE: i16 = -32768;
export const MAX_VALUE: i16 = 32767;
@lazy export const MIN_VALUE: i16 = -32768;
@lazy export const MAX_VALUE: i16 = 32767;
}
@builtin export declare function i32(value: void): i32;
export namespace i32 {
export const MIN_VALUE: i32 = -2147483648;
export const MAX_VALUE: i32 = 2147483647;
@lazy export const MIN_VALUE: i32 = -2147483648;
@lazy export const MAX_VALUE: i32 = 2147483647;
@builtin export declare function clz(value: i32): i32;
@builtin export declare function ctz(value: i32): i32;
@builtin export declare function popcnt(value: i32): i32;
@ -134,8 +134,8 @@ export namespace i32 {
@builtin export declare function i64(value: void): i64;
export namespace i64 {
export const MIN_VALUE: i64 = -9223372036854775808;
export const MAX_VALUE: i64 = 9223372036854775807;
@lazy export const MIN_VALUE: i64 = -9223372036854775808;
@lazy export const MAX_VALUE: i64 = 9223372036854775807;
@builtin export declare function clz(value: i64): i64;
@builtin export declare function ctz(value: i64): i64;
@builtin export declare function load8_s(offset: usize, constantOffset?: usize): i64;
@ -210,60 +210,60 @@ export namespace i64 {
@builtin export declare function isize(value: void): isize;
export namespace isize {
export const MIN_VALUE: isize = sizeof<i32>() == sizeof<isize>()
@lazy export const MIN_VALUE: isize = sizeof<i32>() == sizeof<isize>()
? -2147483648
: <isize>-9223372036854775808;
export const MAX_VALUE: isize = sizeof<i32>() == sizeof<isize>()
@lazy export const MAX_VALUE: isize = sizeof<i32>() == sizeof<isize>()
? 2147483647
: <isize>9223372036854775807;
}
@builtin export declare function u8(value: void): u8;
export namespace u8 {
export const MIN_VALUE: u8 = 0;
export const MAX_VALUE: u8 = 255;
@lazy export const MIN_VALUE: u8 = 0;
@lazy export const MAX_VALUE: u8 = 255;
}
@builtin export declare function u16(value: void): u16;
export namespace u16 {
export const MIN_VALUE: u16 = 0;
export const MAX_VALUE: u16 = 65535;
@lazy export const MIN_VALUE: u16 = 0;
@lazy export const MAX_VALUE: u16 = 65535;
}
@builtin export declare function u32(value: void): u32;
export namespace u32 {
export const MIN_VALUE: u32 = 0;
export const MAX_VALUE: u32 = 4294967295;
@lazy export const MIN_VALUE: u32 = 0;
@lazy export const MAX_VALUE: u32 = 4294967295;
}
@builtin export declare function u64(value: void): u64;
export namespace u64 {
export const MIN_VALUE: u64 = 0;
export const MAX_VALUE: u64 = 18446744073709551615;
@lazy export const MIN_VALUE: u64 = 0;
@lazy export const MAX_VALUE: u64 = 18446744073709551615;
}
@builtin export declare function usize(value: void): usize;
export namespace usize {
export const MIN_VALUE: usize = 0;
export const MAX_VALUE: usize = sizeof<u32>() == sizeof<usize>()
@lazy export const MIN_VALUE: usize = 0;
@lazy export const MAX_VALUE: usize = sizeof<u32>() == sizeof<usize>()
? 4294967295
: <usize>18446744073709551615;
}
@builtin export declare function bool(value: void): bool;
export namespace bool {
export const MIN_VALUE: bool = false;
export const MAX_VALUE: bool = true;
@lazy export const MIN_VALUE: bool = false;
@lazy export const MAX_VALUE: bool = true;
}
@builtin export declare function f32(value: void): f32;
export namespace f32 {
export const EPSILON = reinterpret<f32>(0x34000000); // 0x1p-23f
export const MIN_VALUE = reinterpret<f32>(0x00000001); // 0x0.000001p+0f
export const MAX_VALUE = reinterpret<f32>(0x7F7FFFFF); // 0x1.fffffep+127f
export const MIN_NORMAL_VALUE = reinterpret<f32>(0x00800000); // 0x1p-126f
export const MIN_SAFE_INTEGER: f32 = -16777215;
export const MAX_SAFE_INTEGER: f32 = 16777215;
@lazy export const EPSILON = reinterpret<f32>(0x34000000); // 0x1p-23f
@lazy export const MIN_VALUE = reinterpret<f32>(0x00000001); // 0x0.000001p+0f
@lazy export const MAX_VALUE = reinterpret<f32>(0x7F7FFFFF); // 0x1.fffffep+127f
@lazy export const MIN_NORMAL_VALUE = reinterpret<f32>(0x00800000); // 0x1p-126f
@lazy export const MIN_SAFE_INTEGER: f32 = -16777215;
@lazy export const MAX_SAFE_INTEGER: f32 = 16777215;
@builtin export declare function abs(value: f32): f32;
@builtin export declare function ceil(value: f32): f32;
@builtin export declare function copysign(x: f32, y: f32): f32;
@ -280,12 +280,12 @@ export namespace f32 {
@builtin export declare function f64(value: void): f64;
export namespace f64 {
export const EPSILON = reinterpret<f64>(0x3CB0000000000000); // 0x1p-52
export const MIN_VALUE = reinterpret<f64>(0x0000000000000001); // 0x0.0000000000001p+0
export const MAX_VALUE = reinterpret<f64>(0x7FEFFFFFFFFFFFFF); // 0x1.fffffffffffffp+1023
export const MIN_NORMAL_VALUE = reinterpret<f64>(0x0010000000000000); // 0x1p-1022
export const MIN_SAFE_INTEGER: f64 = -9007199254740991;
export const MAX_SAFE_INTEGER: f64 = 9007199254740991;
@lazy export const EPSILON = reinterpret<f64>(0x3CB0000000000000); // 0x1p-52
@lazy export const MIN_VALUE = reinterpret<f64>(0x0000000000000001); // 0x0.0000000000001p+0
@lazy export const MAX_VALUE = reinterpret<f64>(0x7FEFFFFFFFFFFFFF); // 0x1.fffffffffffffp+1023
@lazy export const MIN_NORMAL_VALUE = reinterpret<f64>(0x0010000000000000); // 0x1p-1022
@lazy export const MIN_SAFE_INTEGER: f64 = -9007199254740991;
@lazy export const MAX_SAFE_INTEGER: f64 = 9007199254740991;
@builtin export declare function abs(value: f64): f64;
@builtin export declare function ceil(value: f64): f64;
@builtin export declare function copysign(x: f64, y: f64): f64;
@ -301,5 +301,3 @@ export namespace f64 {
}
@builtin export declare function start(): void;
@builtin export function NATIVE_CODE(): void { unreachable(); }

View File

@ -6,10 +6,10 @@
// Largely based on Bach Le's μgc, see: https://github.com/bullno1/ugc
const TRACE = false;
@inline const TRACE = false;
/** Size of a managed object header. */
export const HEADER_SIZE: usize = (offsetof<ManagedObject>() + AL_MASK) & ~AL_MASK;
@inline export const HEADER_SIZE: usize = (offsetof<ManagedObject>() + AL_MASK) & ~AL_MASK;
import { AL_MASK, MAX_SIZE_32 } from "../internal/allocator";
import { iterateRoots } from "../gc";

View File

@ -38,8 +38,6 @@ declare type f64 = number;
/** Compiler target. 0 = JS, 1 = WASM32, 2 = WASM64. */
declare const ASC_TARGET: i32;
/** Provided noTreeshaking option. */
declare const ASC_NO_TREESHAKING: bool;
/** Provided noAssert option. */
declare const ASC_NO_ASSERT: bool;
/** Provided memoryBase option. */
@ -354,7 +352,7 @@ declare namespace f64 {
export function store(offset: usize, value: f64, constantOffset?: usize): void;
}
/** Macro type evaluating to the underlying native WebAssembly type. */
declare type NATIVE<T> = T;
declare type native<T> = T;
/** Pseudo-class representing the backing class of integer types. */
declare class _Integer {
@ -966,7 +964,7 @@ declare function unmanaged(constructor: Function): void;
/** Annotates a class as being sealed / non-derivable. */
declare function sealed(constructor: Function): void;
/** Annotates a method or function as always inlined. */
/** Annotates a method, function or constant global as always inlined. */
declare function inline(
target: any,
propertyKey: string,
@ -979,3 +977,17 @@ declare function external(namespace: string, name: string): (
propertyKey: string,
descriptor: TypedPropertyDescriptor<any>
) => TypedPropertyDescriptor<any> | void;
/** Annotates a global for lazy compilation. */
declare function lazy(
target: any,
propertyKey: string,
descriptor: TypedPropertyDescriptor<any>
): TypedPropertyDescriptor<any> | void;
/** Annotates a function as the explicit start function. */
declare function start(
target: any,
propertyKey: string,
descriptor: TypedPropertyDescriptor<any>
): TypedPropertyDescriptor<any> | void;

View File

@ -1,8 +1,8 @@
/** Number of alignment bits. */
export const AL_BITS: u32 = 3;
@inline export const AL_BITS: u32 = 3;
/** Number of possible alignment values. */
export const AL_SIZE: usize = 1 << <usize>AL_BITS;
@inline export const AL_SIZE: usize = 1 << <usize>AL_BITS;
/** Mask to obtain just the alignment bits. */
export const AL_MASK: usize = AL_SIZE - 1;
@inline export const AL_MASK: usize = AL_SIZE - 1;
/** Maximum 32-bit allocation size. */
export const MAX_SIZE_32: usize = 1 << 30; // 1GB
@inline export const MAX_SIZE_32: usize = 1 << 30; // 1GB

View File

@ -4,9 +4,9 @@ import {
} from "./allocator";
/** Size of an ArrayBuffer header. */
export const HEADER_SIZE: usize = (offsetof<ArrayBuffer>() + AL_MASK) & ~AL_MASK;
@inline export const HEADER_SIZE: usize = (offsetof<ArrayBuffer>() + AL_MASK) & ~AL_MASK;
/** Maximum byte length of an ArrayBuffer. */
export const MAX_BLENGTH: i32 = <i32>MAX_SIZE_32 - HEADER_SIZE;
@inline export const MAX_BLENGTH: i32 = <i32>MAX_SIZE_32 - HEADER_SIZE;
function computeSize(byteLength: i32): usize {
// round up to power of 2, with HEADER_SIZE=8:

View File

@ -25,8 +25,8 @@ export function HASH<T>(key: T): u32 {
// FNV-1a 32-bit as a starting point, see: http://isthe.com/chongo/tech/comp/fnv/
const FNV_OFFSET: u32 = 2166136261;
const FNV_PRIME: u32 = 16777619;
@inline const FNV_OFFSET: u32 = 2166136261;
@inline const FNV_PRIME: u32 = 16777619;
function hash8(key: u32): u32 {
return (FNV_OFFSET ^ key) * FNV_PRIME;

View File

@ -1,4 +1,3 @@
import {
CharCode,
allocateUnsafe as allocateUnsafeString,
@ -10,7 +9,7 @@ import {
LOAD
} from "./arraybuffer";
export const MAX_DOUBLE_LENGTH = 28;
@lazy export const MAX_DOUBLE_LENGTH = 28;
@inline
export function POWERS10(): u32[] {
@ -359,16 +358,13 @@ export function itoa<T>(value: T): String {
}
}
var _K: i32 = 0;
var _frc: u64 = 0;
var _exp: i32 = 0;
var _frc_minus: u64 = 0;
var _frc_plus: u64 = 0;
var _frc_pow: u64 = 0;
var _exp_pow: i32 = 0;
@lazy var _K: i32 = 0;
// @lazy var _frc: u64 = 0;
@lazy var _exp: i32 = 0;
@lazy var _frc_minus: u64 = 0;
@lazy var _frc_plus: u64 = 0;
@lazy var _frc_pow: u64 = 0;
@lazy var _exp_pow: i32 = 0;
@inline
function umul64f(u: u64, v: u64): u64 {

View File

@ -2,9 +2,9 @@ import { MAX_SIZE_32 } from "./allocator";
import { String } from "../string";
/** Size of a String header. */
export const HEADER_SIZE = (offsetof<String>() + 1) & ~1; // 2 byte aligned
@inline export const HEADER_SIZE = (offsetof<String>() + 1) & ~1; // 2 byte aligned
/** Maximum length of a String. */
export const MAX_LENGTH = (<i32>MAX_SIZE_32 - HEADER_SIZE) >>> 1;
@inline export const MAX_LENGTH = (<i32>MAX_SIZE_32 - HEADER_SIZE) >>> 1;
// Low-level utility

View File

@ -46,14 +46,14 @@ export abstract class TypedArray<T> {
}
@operator("[]=")
protected __set(index: i32, value: NATIVE<T>): void {
protected __set(index: i32, value: native<T>): void {
if (<u32>index >= <u32>(this.byteLength >>> alignof<T>())) throw new Error("Index out of bounds");
STORE<T,NATIVE<T>>(this.buffer, index, value, this.byteOffset);
STORE<T,native<T>>(this.buffer, index, value, this.byteOffset);
}
@inline @operator("{}=")
protected __unchecked_set(index: i32, value: NATIVE<T>): void {
STORE<T,NATIVE<T>>(this.buffer, index, value, this.byteOffset);
protected __unchecked_set(index: i32, value: native<T>): void {
STORE<T,native<T>>(this.buffer, index, value, this.byteOffset);
}
// copyWithin(target: i32, start: i32, end: i32 = this.length): this
@ -62,7 +62,7 @@ export abstract class TypedArray<T> {
@inline
export function FILL<TArray extends TypedArray<T>, T extends number>(
array: TArray,
value: NATIVE<T>,
value: native<T>,
start: i32,
end: i32
): TArray {
@ -81,7 +81,7 @@ export function FILL<TArray extends TypedArray<T>, T extends number>(
}
} else {
for (; start < end; ++start) {
STORE<T,NATIVE<T>>(buffer, start, value, byteOffset);
STORE<T,native<T>>(buffer, start, value, byteOffset);
}
}
return array;
@ -177,7 +177,7 @@ export function MAP<TArray extends TypedArray<T>, T>(
var result = instantiate<TArray>(length);
var resultBuffer = result.buffer;
for (let i = 0; i < length; i++) {
STORE<T, NATIVE<T>>(resultBuffer, i, <NATIVE<T>>callbackfn(LOAD<T>(buffer, i, byteOffset), i, array));
STORE<T, native<T>>(resultBuffer, i, <native<T>>callbackfn(LOAD<T>(buffer, i, byteOffset), i, array));
}
return result;

View File

@ -8,9 +8,9 @@ import {
// A deterministic hash map based on CloseTable from https://github.com/jorendorff/dht
const INITIAL_CAPACITY = 4;
const FILL_FACTOR: f64 = 8 / 3;
const FREE_FACTOR: f64 = 3 / 4;
@inline const INITIAL_CAPACITY = 4;
@inline const FILL_FACTOR: f64 = 8 / 3;
@inline const FREE_FACTOR: f64 = 3 / 4;
/** Structure of a map entry. */
@unmanaged class MapEntry<K,V> {
@ -20,10 +20,10 @@ const FREE_FACTOR: f64 = 3 / 4;
}
/** Empty bit. */
const EMPTY: usize = 1 << 0;
@inline const EMPTY: usize = 1 << 0;
/** Size of a bucket. */
const BUCKET_SIZE = sizeof<usize>();
@inline const BUCKET_SIZE = sizeof<usize>();
/** Computes the alignment of an entry. */
@inline function ENTRY_ALIGN<K,V>(): usize {

View File

@ -24,7 +24,6 @@ import {
// TODO: sin, cos, tan
/** @internal */
function R(z: f64): f64 { // Rational approximation of (asin(x)-x)/x^3
const // see: musl/src/math/asin.c and SUN COPYRIGHT NOTICE above
pS0 = reinterpret<f64>(0x3FC5555555555555), // 1.66666666666666657415e-01
@ -42,8 +41,7 @@ function R(z: f64): f64 { // Rational approximation of (asin(x)-x)/x^3
return p / q;
}
@inline /** @internal */
function expo2(x: f64): f64 { // exp(x)/2 for x >= log(DBL_MAX)
@inline function expo2(x: f64): f64 { // exp(x)/2 for x >= log(DBL_MAX)
const // see: musl/src/math/__expo2.c
k = <u32>2043,
kln2 = reinterpret<f64>(0x40962066151ADD8B); // 0x1.62066151add8bp+10
@ -51,13 +49,12 @@ function expo2(x: f64): f64 { // exp(x)/2 for x >= log(DBL_MAX)
return NativeMath.exp(x - kln2) * scale * scale;
}
var random_seeded = false;
var random_state0_64: u64;
var random_state1_64: u64;
var random_state0_32: u32;
var random_state1_32: u32;
@lazy var random_seeded = false;
@lazy var random_state0_64: u64;
@lazy var random_state1_64: u64;
@lazy var random_state0_32: u32;
@lazy var random_state1_32: u32;
/** @internal */
function murmurHash3(h: u64): u64 { // Force all bits of a hash block to avalanche
h ^= h >> 33; // see: https://github.com/aappleby/smhasher
h *= 0xFF51AFD7ED558CCD;
@ -67,7 +64,6 @@ function murmurHash3(h: u64): u64 { // Force all bits of a hash block to avalanc
return h;
}
/** @internal */
function splitMix32(h: u32): u32 {
h += 0x6D2B79F5;
h = (h ^ (h >> 15)) * (h | 1);
@ -77,14 +73,14 @@ function splitMix32(h: u32): u32 {
export namespace NativeMath {
export const E = reinterpret<f64>(0x4005BF0A8B145769); // 2.7182818284590452354
export const LN2 = reinterpret<f64>(0x3FE62E42FEFA39EF); // 0.69314718055994530942
export const LN10 = reinterpret<f64>(0x40026BB1BBB55516); // 2.30258509299404568402
export const LOG2E = reinterpret<f64>(0x3FF71547652B82FE); // 1.4426950408889634074
export const LOG10E = reinterpret<f64>(0x3FDBCB7B1526E50E); // 0.43429448190325182765
export const PI = reinterpret<f64>(0x400921FB54442D18); // 3.14159265358979323846
export const SQRT1_2 = reinterpret<f64>(0x3FE6A09E667F3BCD); // 0.70710678118654752440
export const SQRT2 = reinterpret<f64>(0x3FF6A09E667F3BCD); // 1.41421356237309504880
@lazy export const E = reinterpret<f64>(0x4005BF0A8B145769); // 2.7182818284590452354
@lazy export const LN2 = reinterpret<f64>(0x3FE62E42FEFA39EF); // 0.69314718055994530942
@lazy export const LN10 = reinterpret<f64>(0x40026BB1BBB55516); // 2.30258509299404568402
@lazy export const LOG2E = reinterpret<f64>(0x3FF71547652B82FE); // 1.4426950408889634074
@lazy export const LOG10E = reinterpret<f64>(0x3FDBCB7B1526E50E); // 0.43429448190325182765
@lazy export const PI = reinterpret<f64>(0x400921FB54442D18); // 3.14159265358979323846
@lazy export const SQRT1_2 = reinterpret<f64>(0x3FE6A09E667F3BCD); // 0.70710678118654752440
@lazy export const SQRT2 = reinterpret<f64>(0x3FF6A09E667F3BCD); // 1.41421356237309504880
@inline
export function abs(x: f64): f64 {
@ -1073,7 +1069,6 @@ export namespace NativeMath {
return builtin_trunc<f64>(x);
}
/** @internal */
export function scalbn(x: f64, n: i32): f64 { // see: https://git.musl-libc.org/cgit/musl/tree/src/math/scalbn.c
const
Ox1p53 = reinterpret<f64>(0x4340000000000000),
@ -1227,7 +1222,6 @@ export namespace NativeMath {
}
}
/** @internal */
function Rf(z: f32): f32 { // Rational approximation of (asin(x)-x)/x^3
const // see: musl/src/math/asinf.c and SUN COPYRIGHT NOTICE above
pS0 = reinterpret<f32>(0x3E2AAA75), // 1.6666586697e-01f
@ -1239,8 +1233,7 @@ function Rf(z: f32): f32 { // Rational approximation of (asin(x)-x)/x^3
return p / q;
}
@inline /** @internal */
function expo2f(x: f32): f32 { // exp(x)/2 for x >= log(DBL_MAX)
@inline function expo2f(x: f32): f32 { // exp(x)/2 for x >= log(DBL_MAX)
const // see: musl/src/math/__expo2f.c
k = <u32>235,
kln2 = reinterpret<f32>(0x4322E3BC); // 0x1.45c778p+7f
@ -1250,14 +1243,14 @@ function expo2f(x: f32): f32 { // exp(x)/2 for x >= log(DBL_MAX)
export namespace NativeMathf {
export const E = <f32>NativeMath.E;
export const LN2 = <f32>NativeMath.LN2;
export const LN10 = <f32>NativeMath.LN10;
export const LOG2E = <f32>NativeMath.LOG2E;
export const LOG10E = <f32>NativeMath.LOG10E;
export const PI = <f32>NativeMath.PI;
export const SQRT1_2 = <f32>NativeMath.SQRT1_2;
export const SQRT2 = <f32>NativeMath.SQRT2;
@lazy export const E = <f32>NativeMath.E;
@lazy export const LN2 = <f32>NativeMath.LN2;
@lazy export const LN10 = <f32>NativeMath.LN10;
@lazy export const LOG2E = <f32>NativeMath.LOG2E;
@lazy export const LOG10E = <f32>NativeMath.LOG10E;
@lazy export const PI = <f32>NativeMath.PI;
@lazy export const SQRT1_2 = <f32>NativeMath.SQRT1_2;
@lazy export const SQRT2 = <f32>NativeMath.SQRT2;
@inline
export function abs(x: f32): f32 {
@ -2138,7 +2131,6 @@ export namespace NativeMathf {
return builtin_trunc<f32>(x);
}
/** @internal */
export function scalbn(x: f32, n: i32): f32 { // see: https://git.musl-libc.org/cgit/musl/tree/src/math/scalbnf.c
const
Ox1p24f = reinterpret<f32>(0x4B800000),

View File

@ -11,8 +11,8 @@ import {
@sealed
export abstract class I8 {
static readonly MIN_VALUE: i8 = i8.MIN_VALUE;
static readonly MAX_VALUE: i8 = i8.MAX_VALUE;
@lazy static readonly MIN_VALUE: i8 = i8.MIN_VALUE;
@lazy static readonly MAX_VALUE: i8 = i8.MAX_VALUE;
static parseInt(value: string, radix: i32 = 0): i8 {
return <i8>parseI32(value, radix);
@ -27,8 +27,8 @@ export abstract class I8 {
@sealed
export abstract class I16 {
static readonly MIN_VALUE: i16 = i16.MIN_VALUE;
static readonly MAX_VALUE: i16 = i16.MAX_VALUE;
@lazy static readonly MIN_VALUE: i16 = i16.MIN_VALUE;
@lazy static readonly MAX_VALUE: i16 = i16.MAX_VALUE;
static parseInt(value: string, radix: i32 = 0): i16 {
return <i16>parseI32(value, radix);
@ -43,8 +43,8 @@ export abstract class I16 {
@sealed
export abstract class I32 {
static readonly MIN_VALUE: i32 = i32.MIN_VALUE;
static readonly MAX_VALUE: i32 = i32.MAX_VALUE;
@lazy static readonly MIN_VALUE: i32 = i32.MIN_VALUE;
@lazy static readonly MAX_VALUE: i32 = i32.MAX_VALUE;
static parseInt(value: string, radix: i32 = 0): i32 {
return <i32>parseI32(value, radix);
@ -59,8 +59,8 @@ export abstract class I32 {
@sealed
export abstract class I64 {
static readonly MIN_VALUE: i64 = i64.MIN_VALUE;
static readonly MAX_VALUE: i64 = i64.MAX_VALUE;
@lazy static readonly MIN_VALUE: i64 = i64.MIN_VALUE;
@lazy static readonly MAX_VALUE: i64 = i64.MAX_VALUE;
static parseInt(value: string, radix: i32 = 0): i64 {
return <i64>parseI64(value, radix);
@ -75,8 +75,8 @@ export abstract class I64 {
@sealed
export abstract class Isize {
static readonly MIN_VALUE: isize = isize.MIN_VALUE;
static readonly MAX_VALUE: isize = isize.MAX_VALUE;
@lazy static readonly MIN_VALUE: isize = isize.MIN_VALUE;
@lazy static readonly MAX_VALUE: isize = isize.MAX_VALUE;
static parseInt(value: string, radix: i32 = 0): isize {
return <isize>parseI64(value, radix);
@ -91,8 +91,8 @@ export abstract class Isize {
@sealed
export abstract class U8 {
static readonly MIN_VALUE: u8 = u8.MIN_VALUE;
static readonly MAX_VALUE: u8 = u8.MAX_VALUE;
@lazy static readonly MIN_VALUE: u8 = u8.MIN_VALUE;
@lazy static readonly MAX_VALUE: u8 = u8.MAX_VALUE;
static parseInt(value: string, radix: i32 = 0): u8 {
return <u8>parseI32(value, radix);
@ -107,8 +107,8 @@ export abstract class U8 {
@sealed
export abstract class U16 {
static readonly MIN_VALUE: u16 = u16.MIN_VALUE;
static readonly MAX_VALUE: u16 = u16.MAX_VALUE;
@lazy static readonly MIN_VALUE: u16 = u16.MIN_VALUE;
@lazy static readonly MAX_VALUE: u16 = u16.MAX_VALUE;
static parseInt(value: string, radix: i32 = 0): u16 {
return <u16>parseI32(value, radix);
@ -123,8 +123,8 @@ export abstract class U16 {
@sealed
export abstract class U32 {
static readonly MIN_VALUE: u32 = u32.MIN_VALUE;
static readonly MAX_VALUE: u32 = u32.MAX_VALUE;
@lazy static readonly MIN_VALUE: u32 = u32.MIN_VALUE;
@lazy static readonly MAX_VALUE: u32 = u32.MAX_VALUE;
static parseInt(value: string, radix: i32 = 0): u32 {
return <u32>parseI32(value, radix);
@ -139,8 +139,8 @@ export abstract class U32 {
@sealed
export abstract class U64 {
static readonly MIN_VALUE: u64 = u64.MIN_VALUE;
static readonly MAX_VALUE: u64 = u64.MAX_VALUE;
@lazy static readonly MIN_VALUE: u64 = u64.MIN_VALUE;
@lazy static readonly MAX_VALUE: u64 = u64.MAX_VALUE;
static parseInt(value: string, radix: i32 = 0): u64 {
return <u64>parseI64(value, radix);
@ -155,8 +155,8 @@ export abstract class U64 {
@sealed
export abstract class Usize {
static readonly MIN_VALUE: usize = usize.MIN_VALUE;
static readonly MAX_VALUE: usize = usize.MAX_VALUE;
@lazy static readonly MIN_VALUE: usize = usize.MIN_VALUE;
@lazy static readonly MAX_VALUE: usize = usize.MAX_VALUE;
static parseInt(value: string, radix: i32 = 0): usize {
return <usize>parseI64(value, radix);
@ -171,8 +171,8 @@ export abstract class Usize {
@sealed
export abstract class Bool {
static readonly MIN_VALUE: bool = bool.MIN_VALUE;
static readonly MAX_VALUE: bool = bool.MAX_VALUE;
@lazy static readonly MIN_VALUE: bool = bool.MIN_VALUE;
@lazy static readonly MAX_VALUE: bool = bool.MAX_VALUE;
toString(this: bool): String {
// TODO: radix?
@ -180,20 +180,19 @@ export abstract class Bool {
}
}
@sealed
export abstract class Boolean extends Bool {}
export { Bool as Boolean };
@sealed
export abstract class F32 {
static readonly EPSILON: f32 = f32.EPSILON;
static readonly MIN_VALUE: f32 = f32.MIN_VALUE;
static readonly MAX_VALUE: f32 = f32.MAX_VALUE;
static readonly MIN_SAFE_INTEGER: f32 = f32.MIN_SAFE_INTEGER;
static readonly MAX_SAFE_INTEGER: f32 = f32.MAX_SAFE_INTEGER;
static readonly POSITIVE_INFINITY: f32 = Infinity;
static readonly NEGATIVE_INFINITY: f32 = -Infinity;
static readonly NaN: f32 = NaN;
@lazy static readonly EPSILON: f32 = f32.EPSILON;
@lazy static readonly MIN_VALUE: f32 = f32.MIN_VALUE;
@lazy static readonly MAX_VALUE: f32 = f32.MAX_VALUE;
@lazy static readonly MIN_SAFE_INTEGER: f32 = f32.MIN_SAFE_INTEGER;
@lazy static readonly MAX_SAFE_INTEGER: f32 = f32.MAX_SAFE_INTEGER;
@lazy static readonly POSITIVE_INFINITY: f32 = Infinity;
@lazy static readonly NEGATIVE_INFINITY: f32 = -Infinity;
@lazy static readonly NaN: f32 = NaN;
static isNaN(value: f32): bool {
return isNaN<f32>(value);
@ -228,14 +227,14 @@ export abstract class F32 {
@sealed
export abstract class F64 {
static readonly EPSILON: f64 = f64.EPSILON;
static readonly MIN_VALUE: f64 = f64.MIN_VALUE;
static readonly MAX_VALUE: f64 = f64.MAX_VALUE;
static readonly MIN_SAFE_INTEGER: f64 = f64.MIN_SAFE_INTEGER;
static readonly MAX_SAFE_INTEGER: f64 = f64.MAX_SAFE_INTEGER;
static readonly POSITIVE_INFINITY: f64 = Infinity;
static readonly NEGATIVE_INFINITY: f64 = -Infinity;
static readonly NaN: f64 = NaN;
@lazy static readonly EPSILON: f64 = f64.EPSILON;
@lazy static readonly MIN_VALUE: f64 = f64.MIN_VALUE;
@lazy static readonly MAX_VALUE: f64 = f64.MAX_VALUE;
@lazy static readonly MIN_SAFE_INTEGER: f64 = f64.MIN_SAFE_INTEGER;
@lazy static readonly MAX_SAFE_INTEGER: f64 = f64.MAX_SAFE_INTEGER;
@lazy static readonly POSITIVE_INFINITY: f64 = Infinity;
@lazy static readonly NEGATIVE_INFINITY: f64 = -Infinity;
@lazy static readonly NaN: f64 = NaN;
static isNaN(value: f64): bool {
return builtin_isNaN<f64>(value);
@ -267,5 +266,4 @@ export abstract class F64 {
}
}
@sealed
export abstract class Number extends F64 {}
export { F64 as Number };

View File

@ -8,9 +8,9 @@ import {
// A deterministic hash set based on CloseTable from https://github.com/jorendorff/dht
const INITIAL_CAPACITY = 4;
const FILL_FACTOR: f64 = 8 / 3;
const FREE_FACTOR: f64 = 3 / 4;
@inline const INITIAL_CAPACITY = 4;
@inline const FILL_FACTOR: f64 = 8 / 3;
@inline const FREE_FACTOR: f64 = 3 / 4;
/** Structure of a set entry. */
@unmanaged class SetEntry<K> {
@ -19,10 +19,10 @@ const FREE_FACTOR: f64 = 3 / 4;
}
/** Empty bit. */
const EMPTY: usize = 1 << 0;
@inline const EMPTY: usize = 1 << 0;
/** Size of a bucket. */
const BUCKET_SIZE = sizeof<usize>();
@inline const BUCKET_SIZE = sizeof<usize>();
/** Computes the alignment of an entry. */
@inline function ENTRY_ALIGN<K>(): usize {

View File

@ -596,6 +596,8 @@ export class String {
}
}
export type string = String;
export function parseInt(str: String, radix: i32 = 0): f64 {
return parse<f64>(str, radix);
}

View File

@ -1,8 +1,8 @@
import { Map } from "./map";
var stringToId: Map<string, usize>;
var idToString: Map<usize, string>;
var nextId: usize = 12; // Symbol.unscopables + 1
@lazy var stringToId: Map<string, usize>;
@lazy var idToString: Map<usize, string>;
@lazy var nextId: usize = 12; // Symbol.unscopables + 1
@unmanaged export class symbol {
toString(): string {
@ -29,8 +29,6 @@ var nextId: usize = 12; // Symbol.unscopables + 1
}
}
type Symbol = symbol;
export function Symbol(description: string | null = null): symbol {
var id = nextId++;
if (!id) unreachable(); // out of ids
@ -40,18 +38,18 @@ export function Symbol(description: string | null = null): symbol {
export namespace Symbol {
// well-known symbols
export const hasInstance = changetype<symbol>(1);
export const isConcatSpreadable = changetype<symbol>(2);
export const isRegExp = changetype<symbol>(3);
export const iterator = changetype<symbol>(3);
export const match = changetype<symbol>(4);
export const replace = changetype<symbol>(5);
export const search = changetype<symbol>(6);
export const species = changetype<symbol>(7);
export const split = changetype<symbol>(8);
export const toPrimitive = changetype<symbol>(9);
export const toStringTag = changetype<symbol>(10);
export const unscopables = changetype<symbol>(11);
@lazy export const hasInstance = changetype<symbol>(1);
@lazy export const isConcatSpreadable = changetype<symbol>(2);
@lazy export const isRegExp = changetype<symbol>(3);
@lazy export const iterator = changetype<symbol>(3);
@lazy export const match = changetype<symbol>(4);
@lazy export const replace = changetype<symbol>(5);
@lazy export const search = changetype<symbol>(6);
@lazy export const species = changetype<symbol>(7);
@lazy export const split = changetype<symbol>(8);
@lazy export const toPrimitive = changetype<symbol>(9);
@lazy export const toStringTag = changetype<symbol>(10);
@lazy export const unscopables = changetype<symbol>(11);
/* tslint:disable */// not valid TS
export function for(key: string): symbol {

View File

@ -16,7 +16,7 @@ import {
} from "./internal/sort";
export class Int8Array extends TypedArray<i8> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<i8>();
@lazy static readonly BYTES_PER_ELEMENT: usize = sizeof<i8>();
fill(value: i32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Int8Array {
return FILL<Int8Array, i8>(this, value, start, end);
@ -62,7 +62,7 @@ export class Int8Array extends TypedArray<i8> {
}
export class Uint8Array extends TypedArray<u8> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<u8>();
@lazy static readonly BYTES_PER_ELEMENT: usize = sizeof<u8>();
fill(value: u32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Uint8Array {
return FILL<Uint8Array, u8>(this, value, start, end);
@ -108,7 +108,7 @@ export class Uint8Array extends TypedArray<u8> {
}
export class Uint8ClampedArray extends Uint8Array {
static readonly BYTES_PER_ELEMENT: usize = sizeof<u8>();
@lazy static readonly BYTES_PER_ELEMENT: usize = sizeof<u8>();
@inline @operator("[]=")
protected __set(index: i32, value: i32): void {
@ -150,7 +150,7 @@ export class Uint8ClampedArray extends Uint8Array {
}
export class Int16Array extends TypedArray<i16> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<i16>();
@lazy static readonly BYTES_PER_ELEMENT: usize = sizeof<i16>();
fill(value: i32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Int16Array {
return FILL<Int16Array, i16>(this, value, start, end);
@ -196,7 +196,7 @@ export class Int16Array extends TypedArray<i16> {
}
export class Uint16Array extends TypedArray<u16> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<u16>();
@lazy static readonly BYTES_PER_ELEMENT: usize = sizeof<u16>();
fill(value: u32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Uint16Array {
return FILL<Uint16Array, u16>(this, value, start, end);
@ -242,7 +242,7 @@ export class Uint16Array extends TypedArray<u16> {
}
export class Int32Array extends TypedArray<i32> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<i32>();
@lazy static readonly BYTES_PER_ELEMENT: usize = sizeof<i32>();
fill(value: i32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Int32Array {
return FILL<Int32Array, i32>(this, value, start, end);
@ -288,7 +288,7 @@ export class Int32Array extends TypedArray<i32> {
}
export class Uint32Array extends TypedArray<u32> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<u32>();
@lazy static readonly BYTES_PER_ELEMENT: usize = sizeof<u32>();
fill(value: u32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Uint32Array {
return FILL<Uint32Array, u32>(this, value, start, end);
@ -334,7 +334,7 @@ export class Uint32Array extends TypedArray<u32> {
}
export class Int64Array extends TypedArray<i64> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<i64>();
@lazy static readonly BYTES_PER_ELEMENT: usize = sizeof<i64>();
fill(value: i64, start: i32 = 0, end: i32 = i32.MAX_VALUE): Int64Array {
return FILL<Int64Array, i64>(this, value, start, end);
@ -380,7 +380,7 @@ export class Int64Array extends TypedArray<i64> {
}
export class Uint64Array extends TypedArray<u64> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<u64>();
@lazy static readonly BYTES_PER_ELEMENT: usize = sizeof<u64>();
fill(value: u64, start: i32 = 0, end: i32 = i32.MAX_VALUE): Uint64Array {
return FILL<Uint64Array, u64>(this, value, start, end);
@ -426,7 +426,7 @@ export class Uint64Array extends TypedArray<u64> {
}
export class Float32Array extends TypedArray<f32> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<f32>();
@lazy static readonly BYTES_PER_ELEMENT: usize = sizeof<f32>();
fill(value: f32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Float32Array {
return FILL<Float32Array, f32>(this, value, start, end);
@ -472,7 +472,7 @@ export class Float32Array extends TypedArray<f32> {
}
export class Float64Array extends TypedArray<f64> {
static readonly BYTES_PER_ELEMENT: usize = sizeof<f64>();
@lazy static readonly BYTES_PER_ELEMENT: usize = sizeof<f64>();
fill(value: f64, start: i32 = 0, end: i32 = i32.MAX_VALUE): Float64Array {
return FILL<Float64Array, f64>(this, value, start, end);