mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-23 11:41:45 +00:00
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:
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user