From 44146341295307df2183c08da469d6ac88edd00a Mon Sep 17 00:00:00 2001 From: dcode Date: Tue, 3 Mar 2020 17:15:55 +0100 Subject: [PATCH 1/2] Modernize source file headers --- cli/asc.d.ts | 5 + cli/asc.js | 7 +- cli/transform.d.ts | 6 +- cli/transform.js | 5 + cli/util/colors.d.ts | 5 + cli/util/colors.js | 5 + cli/util/find.d.ts | 5 + cli/util/find.js | 5 + cli/util/mkdirp.d.ts | 5 + cli/util/mkdirp.js | 48 +-- cli/util/options.d.ts | 5 + cli/util/options.js | 5 + cli/util/utf8.d.ts | 5 + cli/util/utf8.js | 5 + scripts/build-diagnostics.js | 17 +- src/ast.ts | 17 +- src/builtins.ts | 30 +- src/common.ts | 6 +- src/compiler.ts | 6 +- src/definitions.ts | 12 +- src/diagnosticMessages.generated.ts | 6 +- src/diagnostics.ts | 7 +- src/extra/ast.ts | 8 +- src/flow.ts | 22 +- src/glue/binaryen.d.ts | 9 +- src/glue/binaryen.js | 5 + src/glue/js/{mapset.d.ts => collections.d.ts} | 5 + src/glue/js/{mapset.js => collections.js} | 5 + src/glue/js/float.d.ts | 5 +- src/glue/js/float.js | 5 + src/glue/js/i64.d.ts | 5 +- src/glue/js/i64.js | 5 + src/glue/js/index.ts | 9 +- src/glue/js/node.d.ts | 5 +- src/glue/wasm/{mapset.ts => collections.ts} | 5 + src/glue/wasm/float.ts | 5 +- src/glue/wasm/i64.ts | 5 +- src/glue/wasm/index.ts | 9 +- src/index.ts | 36 +- src/module.ts | 11 +- src/parser.ts | 10 +- src/program.ts | 19 +- src/resolver.ts | 14 +- src/tokenizer.ts | 14 +- src/types.ts | 8 +- src/util/binary.ts | 5 +- src/util/bitset.ts | 38 -- src/util/charcode.ts | 378 ----------------- src/util/collections.ts | 5 + src/util/index.ts | 17 +- src/util/math.ts | 9 + src/util/path.ts | 7 +- src/util/text.ts | 382 +++++++++++++++++- webpack.config.js | 42 +- 54 files changed, 777 insertions(+), 547 deletions(-) rename src/glue/js/{mapset.d.ts => collections.d.ts} (64%) rename src/glue/js/{mapset.js => collections.js} (71%) rename src/glue/wasm/{mapset.ts => collections.ts} (80%) delete mode 100644 src/util/bitset.ts delete mode 100644 src/util/charcode.ts create mode 100644 src/util/math.ts diff --git a/cli/asc.d.ts b/cli/asc.d.ts index 0445f60333..49efa374d4 100644 --- a/cli/asc.d.ts +++ b/cli/asc.d.ts @@ -1,3 +1,8 @@ +/** + * @fileoverview Definitions for asc. + * @license Apache-2.0 + */ + import { OptionDescription } from "./util/options"; export { OptionDescription }; diff --git a/cli/asc.js b/cli/asc.js index 7832b2ba32..977eaf31a8 100644 --- a/cli/asc.js +++ b/cli/asc.js @@ -1,6 +1,5 @@ -"use strict"; /** - * Compiler frontend for node.js + * @fileoverview Compiler frontend for node.js * * Uses the low-level API exported from src/index.ts so it works with the compiler compiled to * JavaScript as well as the compiler compiled to WebAssembly (eventually). Runs the sources @@ -9,7 +8,9 @@ * Can also be packaged as a bundle suitable for in-browser use with the standard library injected * in the build step. See dist/asc.js for the bundle and webpack.config.js for building details. * - * @module cli/asc + * @license + * Copyright Daniel Wirtz / The AssemblyScript Authors. + * SPDX-License-Identifier: Apache-2.0 */ // Use "." instead of "/" as cwd in browsers diff --git a/cli/transform.d.ts b/cli/transform.d.ts index e7afdc7ddd..50e8806ce1 100644 --- a/cli/transform.d.ts +++ b/cli/transform.d.ts @@ -1,7 +1,7 @@ /** - * Definitions for custom compiler transforms that can be applied with the `--transform` option. - * @module cli/transform - *//***/ + * @fileoverview Compiler transform interface definitions. + * @license Apache-2.0 + */ import { Program, Parser, Module } from ".."; import { OutputStream } from "./asc"; diff --git a/cli/transform.js b/cli/transform.js index 141277d2b6..5b1e1596c7 100644 --- a/cli/transform.js +++ b/cli/transform.js @@ -1,2 +1,7 @@ +/** + * @fileoverview Compiler transform interface. + * @license Apache-2.0 + */ + // becomes replaced with the actual base by asc exports.Transform = function Transform() {}; diff --git a/cli/util/colors.d.ts b/cli/util/colors.d.ts index e6f2f88191..f2a6463740 100644 --- a/cli/util/colors.d.ts +++ b/cli/util/colors.d.ts @@ -1,3 +1,8 @@ +/** + * @fileoverview Terminal colors utility definitions. + * @license Apache-2.0 + */ + interface Colors { /** Whether terminal colors are supported. */ supported: boolean; diff --git a/cli/util/colors.js b/cli/util/colors.js index f27f0dda7a..798960c7a0 100644 --- a/cli/util/colors.js +++ b/cli/util/colors.js @@ -1,3 +1,8 @@ +/** + * @fileoverview Terminal colors utility. + * @license Apache-2.0 + */ + var proc = typeof process !== "undefined" && process || {}; var isCI = proc.env && "CI" in proc.env; // doesn't work when bundled because 'process' is a mock diff --git a/cli/util/find.d.ts b/cli/util/find.d.ts index 6d5f3cf202..2778f9aa29 100644 --- a/cli/util/find.d.ts +++ b/cli/util/find.d.ts @@ -1,3 +1,8 @@ +/** + * @fileoverview File finding utility definitions. + * @license Apache-2.0 + */ + export function files(dirname: string, filter?: ((name: string) => bool) | RegExp): string[]; export const TS: RegExp; export const TS_EXCEPT_DTS: RegExp; diff --git a/cli/util/find.js b/cli/util/find.js index 4cb68d7377..0541679de5 100644 --- a/cli/util/find.js +++ b/cli/util/find.js @@ -1,3 +1,8 @@ +/** + * @fileoverview File finding utility. + * @license Apache-2.0 + */ + const fs = require("fs"); const path = require("path"); diff --git a/cli/util/mkdirp.d.ts b/cli/util/mkdirp.d.ts index b93735bbdd..7a0658d500 100644 --- a/cli/util/mkdirp.d.ts +++ b/cli/util/mkdirp.d.ts @@ -1,3 +1,8 @@ +/** + * @fileoverview Recursive mkdir definitions. + * @license Apache-2.0 + */ + interface Options { mode?: number; } diff --git a/cli/util/mkdirp.js b/cli/util/mkdirp.js index aad62bc3d0..bc7bffa8bb 100644 --- a/cli/util/mkdirp.js +++ b/cli/util/mkdirp.js @@ -1,26 +1,28 @@ -/* -Copyright 2010 James Halliday (mail@substack.net) - -This project is free software released under the MIT/X11 license: - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ +/** + * @fileoverview Recursive mkdir. + * @license + * Copyright 2010 James Halliday (mail@substack.net) + * + * This project is free software released under the MIT/X11 license: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ var path = require("path"); var fs = require("fs"); diff --git a/cli/util/options.d.ts b/cli/util/options.d.ts index 1126f392f0..5b3601b20a 100644 --- a/cli/util/options.d.ts +++ b/cli/util/options.d.ts @@ -1,3 +1,8 @@ +/** + * @fileoverview Command line options utility definitions. + * @license Apache-2.0 + */ + /** Command line option description. */ export interface OptionDescription { /** Textual description. */ diff --git a/cli/util/options.js b/cli/util/options.js index 89c9c409d6..43416641cf 100644 --- a/cli/util/options.js +++ b/cli/util/options.js @@ -1,3 +1,8 @@ +/** + * @fileoverview Command line options utility. + * @license Apache-2.0 + */ + const colorsUtil = require("./colors"); // type | meaning diff --git a/cli/util/utf8.d.ts b/cli/util/utf8.d.ts index 2f1d0ab1cb..d419c041e3 100644 --- a/cli/util/utf8.d.ts +++ b/cli/util/utf8.d.ts @@ -1,3 +1,8 @@ +/** + * @fileoverview UTF8 utility definitions. + * @license Apache-2.0 + */ + /** * Calculates the UTF8 byte length of a string. * @param {string} string String diff --git a/cli/util/utf8.js b/cli/util/utf8.js index 04b5600e3c..0b37c859b1 100644 --- a/cli/util/utf8.js +++ b/cli/util/utf8.js @@ -1,3 +1,8 @@ +/** + * @fileoverview UTF8 utility. + * @license Apache-2.0 + */ + // @protobufjs/utf8 /** diff --git a/scripts/build-diagnostics.js b/scripts/build-diagnostics.js index 584a696693..e5052654a1 100644 --- a/scripts/build-diagnostics.js +++ b/scripts/build-diagnostics.js @@ -2,13 +2,16 @@ var fs = require("fs"); var messages = require(__dirname + "/../src/diagnosticMessages.json"); -var sb = [ - "/**\n", - " * Generated from diagnosticsMessages.json. Do not edit.\n", - " * @module diagnostics\n", - " *//***/\n\n", - "/* tslint:disable:max-line-length */\n\n" -]; +var header = `/** + * @fileoverview Generated from diagnosticsMessages.json. Do not edit. + * @license Apache-2.0 + */ + +/* tslint:disable:max-line-length */ + +`.replace(/\r\n/g, "\n"); + +var sb = [ header ]; function makeKey(text) { return text.replace(/[^\w]+/g, "_").replace(/_+$/, ""); diff --git a/src/ast.ts b/src/ast.ts index 440fc0efb2..23ffaca27f 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1,7 +1,18 @@ /** - * Abstract syntax tree representing a source file once parsed. - * @module ast - *//***/ + * @fileoverview Abstract syntax tree representing a source file once parsed. + * + * Each node in the AST is represented by an instance of a subclass of `Node`, + * with its `Node#kind` represented by one of the `NodeKind` constants, which + * dependent code typically switches over. The intended way to create a node + * is to use the respective `Node.createX` method instead of its constructor. + * + * Note that the AST does not contain any type information except type names. + * + * @license Apache-2.0 + */ + +// TODO: Make the AST more easily serializable by refactoring `Node#range` so +// it doesn't reference the non-serializable `Source` object. import { CommonFlags, diff --git a/src/builtins.ts b/src/builtins.ts index d6feedaf4a..7be453c14d 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -1,9 +1,29 @@ /** - * Built-in elements providing WebAssembly core functionality. - * @module builtins - *//***/ + * @fileoverview Built-in elements providing core WebAssembly functionality. + * + * Each builtin is linked to its definition in std/assembly/builtins.ts. + * When its prototype is called, the compiler recognizes the `@builtin` + * decorator, looks up the respective handler in the global builtins map + * and executes it, with the handler directly emitting WebAssembly code + * according to context. + * + * Builtins can be categorized into core builtins that typically are generic + * and emit code directly and aliases calling core builtins with overridden + * contexts. The latter is used by inline assembler aliases of WebAssembly + * instructions, like `i64.load8_u` deferring to `load`. + * + * The `contextIsExact` modifier is used to force a specific instruction + * family. A `i32.store8` deferring to `store` for example is + * ambiguous in that the input can still be an i32 or an i64, leading to + * either an `i32.store8` or an `i64.store8`, so `i32` is forced there. + * This behavior is indicated by `from i32/i64` in the comments below. + * + * @license Apache-2.0 + */ + +// TODO: Add builtins for `i32.add` etc. that do not have a core builtin. - import { +import { Compiler, Constraints, RuntimeFeatures @@ -586,7 +606,7 @@ export class BuiltinContext { contextIsExact: bool; } -/** Registered builtins. */ +/** Global builtins map. */ export const builtins = new Map ExpressionRef>(); // === Static type evaluation ================================================================= diff --git a/src/common.ts b/src/common.ts index c50c49cd04..48b1ddc2fe 100644 --- a/src/common.ts +++ b/src/common.ts @@ -1,7 +1,7 @@ /** - * Common constants. - * @module common - *//***/ + * @fileoverview Common constants used by various parts of the compiler. + * @license Apache-2.0 + */ /** Indicates traits of a {@link Node} or {@link Element}. */ export enum CommonFlags { diff --git a/src/compiler.ts b/src/compiler.ts index 197ed9d50d..374aa559f5 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1,7 +1,7 @@ /** - * The AssemblyScript compiler. - * @module compiler - *//***/ + * @fileoverview The AssemblyScript compiler. + * @license Apache-2.0 + */ import { BuiltinNames, diff --git a/src/definitions.ts b/src/definitions.ts index 239cc3c139..95236a9b14 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -1,9 +1,13 @@ /** - * Definition builders for WebIDL and TypeScript. - * @module definitions - *//***/ + * @fileoverview Builders for various definitions describing a module. + * + * - TSDBuilder: Creates a TypeScript definition file (.d.ts) + * - IDLBuilder: Creates a WebIDL interface definition (.webidl) + * + * @license Apache-2.0 + */ - import { +import { CommonFlags } from "./common"; diff --git a/src/diagnosticMessages.generated.ts b/src/diagnosticMessages.generated.ts index a6de0f5569..d674d316c6 100644 --- a/src/diagnosticMessages.generated.ts +++ b/src/diagnosticMessages.generated.ts @@ -1,7 +1,7 @@ /** - * Generated from diagnosticsMessages.json. Do not edit. - * @module diagnostics - *//***/ + * @fileoverview Generated from diagnosticsMessages.json. Do not edit. + * @license Apache-2.0 + */ /* tslint:disable:max-line-length */ diff --git a/src/diagnostics.ts b/src/diagnostics.ts index 2f8054a03a..a43345a542 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -1,8 +1,7 @@ /** - * Shared diagnostic handling inherited by the parser and the compiler. - * @module diagnostics - * @preferred - *//***/ + * @fileoverview Shared diagnostic handling. + * @license Apache-2.0 + */ import { Range diff --git a/src/extra/ast.ts b/src/extra/ast.ts index e3c4300542..7266545123 100644 --- a/src/extra/ast.ts +++ b/src/extra/ast.ts @@ -1,10 +1,10 @@ /** - * Abstract Syntax Tree extras. + * @fileoverview Abstract Syntax Tree extras. * - * Not needed in a standalone compiler but useful for testing the parser. + * Provides serialization of the AssemblyScript AST back to it source form. * - * @module extra/ast - *//***/ + * @license Apache-2.0 + */ import { Node, diff --git a/src/flow.ts b/src/flow.ts index 5a1c8a2417..abd91ab53e 100644 --- a/src/flow.ts +++ b/src/flow.ts @@ -1,7 +1,19 @@ /** - * A control flow analyzer. - * @module flow - *//***/ + * @fileoverview A concurrent code flow analyzer. + * + * Flows keep track of compilation state and can be queried for various + * conditions, like whether the current branch always terminates, whether + * a local is known to be non-null or whether an expression has possibly + * overflown its value range. + * + * To accomplish this, compilation of each function begins with a clean + * flow populated with initial local states etc. While compilation + * progresses, statements and expressions update flow state while control + * constructs fork, potentially add scoped locals and later merge these + * forked branches as necessary. + * + * @license Apache-2.0 + */ import { Type, @@ -21,6 +33,8 @@ import { NativeType, ExpressionId, ExpressionRef, + BinaryOp, + UnaryOp, getExpressionId, getLocalGetIndex, @@ -28,12 +42,10 @@ import { getLocalSetValue, getGlobalGetName, getBinaryOp, - BinaryOp, getBinaryLeft, getConstValueI32, getBinaryRight, getUnaryOp, - UnaryOp, getExpressionType, getConstValueI64Low, getConstValueF32, diff --git a/src/glue/binaryen.d.ts b/src/glue/binaryen.d.ts index 547b31e95b..7376bc2c62 100644 --- a/src/glue/binaryen.d.ts +++ b/src/glue/binaryen.d.ts @@ -1,11 +1,12 @@ /** - * Portable definitions for Binaryen's C-API. tsc uses the .js file next to it, - * while asc makes it a Wasm import. + * @fileoverview Portable definitions for Binaryen's C-API. + * + * tsc uses the .js file next to it, while asc makes it a Wasm import. * * See: https://github.com/WebAssembly/binaryen/blob/master/src/binaryen-c.h * - * @module glue/binaryen - *//***/ + * @license Apache-2.0 + */ export declare function _malloc(size: usize): usize; export declare function _free(ptr: usize): void; diff --git a/src/glue/binaryen.js b/src/glue/binaryen.js index 60f88598d8..0db53bbb64 100644 --- a/src/glue/binaryen.js +++ b/src/glue/binaryen.js @@ -1,3 +1,8 @@ +/** + * @fileoverview Binaryen glue code for JavaScript. + * @license Apache-2.0 + */ + const binaryen = global.Binaryen || (global.Binaryen = require("binaryen")); module.exports = binaryen; diff --git a/src/glue/js/mapset.d.ts b/src/glue/js/collections.d.ts similarity index 64% rename from src/glue/js/mapset.d.ts rename to src/glue/js/collections.d.ts index 7a5e8a5753..73b5e9d167 100644 --- a/src/glue/js/mapset.d.ts +++ b/src/glue/js/collections.d.ts @@ -1,3 +1,8 @@ +/** + * @fileoverview Collections glue code for TypeScript. + * @license Apache-2.0 + */ + declare function Map_keys(map: Map): K[]; declare function Map_values(map: Map): V[]; declare function Set_values(set: Set): V[]; diff --git a/src/glue/js/mapset.js b/src/glue/js/collections.js similarity index 71% rename from src/glue/js/mapset.js rename to src/glue/js/collections.js index 3164caf25e..a94224f0a3 100644 --- a/src/glue/js/mapset.js +++ b/src/glue/js/collections.js @@ -1,3 +1,8 @@ +/** + * @fileoverview Collections glue code for JavaScript. + * @license Apache-2.0 + */ + global.Map_keys = function(map) { return Array.from(map.keys()); }; diff --git a/src/glue/js/float.d.ts b/src/glue/js/float.d.ts index f40a1dd317..8694f03b52 100644 --- a/src/glue/js/float.d.ts +++ b/src/glue/js/float.d.ts @@ -1,4 +1,7 @@ -/** @module glue/js *//***/ +/** + * @fileoverview Floating point glue code for TypeScript. + * @license Apache-2.0 + */ declare function f32_as_i32(value: f32): i32; declare function i32_as_f32(value: i32): f32; diff --git a/src/glue/js/float.js b/src/glue/js/float.js index 1f98c70caf..0ab2809b5b 100644 --- a/src/glue/js/float.js +++ b/src/glue/js/float.js @@ -1,3 +1,8 @@ +/** + * @fileoverview Floating point glue code for JaavaScript. + * @license Apache-2.0 + */ + const F64 = new Float64Array(1); const F32 = new Float32Array(F64.buffer); const I32 = new Int32Array(F64.buffer); diff --git a/src/glue/js/i64.d.ts b/src/glue/js/i64.d.ts index 7bcc0941b2..631d2b8014 100644 --- a/src/glue/js/i64.d.ts +++ b/src/glue/js/i64.d.ts @@ -1,4 +1,7 @@ -/** @module glue/js *//***/ +/** + * @fileoverview 64-bit integer glue code for TypeScript. + * @license Apache-2.0 + */ declare type i64 = { __Long__: true }; // opaque diff --git a/src/glue/js/i64.js b/src/glue/js/i64.js index d685ab75af..123a8c1022 100644 --- a/src/glue/js/i64.js +++ b/src/glue/js/i64.js @@ -1,3 +1,8 @@ +/** + * @fileoverview 64-bit integer glue code for JavaScript. + * @license Apache-2.0 + */ + const Long = global.Long || require("long"); global.i64_zero = Long.ZERO; diff --git a/src/glue/js/index.ts b/src/glue/js/index.ts index fb9f71a11e..6be3f5f161 100644 --- a/src/glue/js/index.ts +++ b/src/glue/js/index.ts @@ -1,11 +1,10 @@ /** - * JavaScript glue code. - * @module glue/js - * @preferred - *//***/ + * @fileoverview JavaScript glue code. + * @license Apache-2.0 + */ import "../../../std/portable/index"; import "../binaryen"; import "./float"; import "./i64"; -import "./mapset"; +import "./collections"; diff --git a/src/glue/js/node.d.ts b/src/glue/js/node.d.ts index e8e3e0f064..eb548b3ab8 100644 --- a/src/glue/js/node.d.ts +++ b/src/glue/js/node.d.ts @@ -1,4 +1,7 @@ -/** @module glue/js *//***/ +/** + * @fileoverview Node.js glue code for TypeScript. + * @license Apache-2.0 + */ declare const global: any; declare function require(name: string): any; diff --git a/src/glue/wasm/mapset.ts b/src/glue/wasm/collections.ts similarity index 80% rename from src/glue/wasm/mapset.ts rename to src/glue/wasm/collections.ts index cd040b37ac..2989a2bc37 100644 --- a/src/glue/wasm/mapset.ts +++ b/src/glue/wasm/collections.ts @@ -1,3 +1,8 @@ +/** + * @fileoverview Collections glue code for WebAssembly. + * @license Apache-2.0 + */ + // @ts-ignore: decorator @global function Map_keys(map: Map): K[] { diff --git a/src/glue/wasm/float.ts b/src/glue/wasm/float.ts index 104994afef..7331fe8e18 100644 --- a/src/glue/wasm/float.ts +++ b/src/glue/wasm/float.ts @@ -1,4 +1,7 @@ -/** @module glue/wasm *//***/ +/** + * @fileoverview Floating point glue code for WebAssembly. + * @license Apache-2.0 + */ // @ts-ignore: decorator @global diff --git a/src/glue/wasm/i64.ts b/src/glue/wasm/i64.ts index 753bd2f0fd..a209e77c6c 100644 --- a/src/glue/wasm/i64.ts +++ b/src/glue/wasm/i64.ts @@ -1,4 +1,7 @@ -/** @module glue/wasm *//***/ +/** + * @fileoverview 64-bit integer glue code for WebAssembly. + * @license Apache-2.0 + */ // @ts-ignore: decorator @global diff --git a/src/glue/wasm/index.ts b/src/glue/wasm/index.ts index 6652e0047d..e366c5bbb2 100644 --- a/src/glue/wasm/index.ts +++ b/src/glue/wasm/index.ts @@ -1,9 +1,8 @@ /** - * WebAssembly glue code. - * @module glue/wasm - * @preferred - *//***/ + * @fileoverview WebAssembly glue code. + * @license Apache-2.0 + */ import "./i64"; import "./float"; -import "./mapset"; +import "./collections"; diff --git a/src/index.ts b/src/index.ts index 23bf8d6074..c09ebf2d5c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,37 @@ /** - * Low-level C-like compiler API. - * @module index - *//***/ + * @license + * Copyright 2020 Daniel Wirtz / The AssemblyScript Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview The C-like and re-exported public compiler interface. + * + * The intended way to consume the compiler sources is to import this + * file, which again exports all relevant functions, classes and constants + * as a flat namespace. + * + * Note though that the compiler sources are written in "portable + * AssemblyScript" that can be compiled to both JavaScript with tsc and + * to WebAssembly with asc, and as such require additional glue code + * depending on the target. + * + * When compiling to JavaScript `glue/js/index.js` must be included. + * When compiling to WebAssembly `glue/wasm/index.ts` must be included. + */ import { Target, Feature } from "./common"; import { Compiler, Options } from "./compiler"; diff --git a/src/module.ts b/src/module.ts index 3553a5b5a0..c6e1e12dd9 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1,7 +1,12 @@ /** - * A thin wrapper around Binaryen's C-API. - * @module module - *//***/ + * @fileoverview A thin wrapper around Binaryen's C-API. + * + * The AssemblyScript compiler utilizes Binaryen's C-API directly. Even + * though it currently imports binaryen.js, none of the JS APIs it + * provides are used. + * + * @license Apache-2.0 + */ import { Target } from "./common"; import * as binaryen from "./glue/binaryen"; diff --git a/src/parser.ts b/src/parser.ts index 7954e1bf0e..3e9bf3b498 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -1,7 +1,11 @@ /** - * A TypeScript parser for the AssemblyScript subset. - * @module parser - *//***/ + * @fileoverview A TypeScript parser for the AssemblyScript subset. + * + * Takes the tokens produced by the `Tokenizer` and builds an abstract + * syntax tree composed of `Node`s wrapped in a `Source` out of it. + * + * @license Apache-2.0 + */ import { CommonFlags, diff --git a/src/program.ts b/src/program.ts index 5b7f48c53e..0157e562bd 100644 --- a/src/program.ts +++ b/src/program.ts @@ -1,7 +1,20 @@ /** - * AssemblyScript's intermediate representation describing a program's elements. - * @module program - *//***/ + * @fileoverview AssemblyScript's intermediate representation. + * + * The compiler uses Binaryen IR, which is fairly low level, as its + * primary intermediate representation, with the following structures + * holding any higher level information that cannot be represented by + * Binaryen IR alone, for example higher level types. + * + * Similar to the AST being composed of `Node`s in `Source`s, the IR is + * composed of `Element`s in a `Program`. Each class or function is + * represented by a "prototype" holding all the relevant information, + * including each's concrete instances. If a class or function is not + * generic, there is exactly one instance, otherwise there is one for + * each concrete set of type arguments. + * + * @license Apache-2.0 + */ import { CommonFlags, diff --git a/src/resolver.ts b/src/resolver.ts index 1843cb9e34..b637202ed0 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -1,7 +1,15 @@ /** - * Resolve infrastructure to obtain types and elements. - * @module resolver - *//***/ + * @fileoverview Resolve infrastructure to obtain types and elements. + * + * Similar to the compiler making instructions of expressions, the resolver + * obtains metadata of expressions. As such, for each `compileX` method in + * the compiler there is one `lookupX` method in the resolver returning the + * respective IR element, respectively one `resolveX` method returning the + * respective type of an expression. It is also able to make new elements, + * like instances of classes given its concrete type arguments. + * + * @license Apache-2.0 + */ import { DiagnosticEmitter, diff --git a/src/tokenizer.ts b/src/tokenizer.ts index fda08e1b52..cce445e1b7 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -1,11 +1,15 @@ /** - * A TypeScript tokenizer modified for AssemblyScript. + * @fileoverview A TypeScript tokenizer modified for AssemblyScript. * - * Skips over trivia and provides a general mark/reset mechanism for the parser to utilize on - * ambiguous tokens. + * The `Tokenizer` scans over a source file and returns one syntactic token + * at a time that the parser will combine to an abstract syntax tree. * - * @module tokenizer - *//***/ + * It skips over trivia like comments and whitespace and provides a general + * mark/reset mechanism for the parser to utilize on ambiguous tokens, with + * one token of lookahead otherwise. + * + * @license Apache-2.0 + */ import { DiagnosticCode, diff --git a/src/types.ts b/src/types.ts index 4afc65cee1..113bf04b9e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,7 @@ /** - * Mappings from AssemblyScript types to WebAssembly types. - * @module types - *//***/ + * @fileoverview Mappings from AssemblyScript types to WebAssembly types. + * @license Apache-2.0 + */ import { Class, @@ -98,8 +98,6 @@ export const enum TypeFlags { HOST = 1 << 11 } -const v128_zero = new Uint8Array(16); - /** Represents a resolved type. */ export class Type { diff --git a/src/util/binary.ts b/src/util/binary.ts index 887759d7fd..b1d080601d 100644 --- a/src/util/binary.ts +++ b/src/util/binary.ts @@ -1,4 +1,7 @@ -/** @module util *//***/ +/** + * @fileoverview Various binary reading and writing utility. + * @license Apache-2.0 + */ /** Reads an 8-bit integer from the specified buffer. */ export function readI8(buffer: Uint8Array, offset: i32): i32 { diff --git a/src/util/bitset.ts b/src/util/bitset.ts deleted file mode 100644 index df36ca293f..0000000000 --- a/src/util/bitset.ts +++ /dev/null @@ -1,38 +0,0 @@ -/** @module util *//***/ - -/** Tests if the bit at the specified index is set within a 64-bit map. */ -export function bitsetIs(map: i64, index: i32): bool { - assert(index >= 0 && index < 64); - return i64_ne( - i64_and( - map, - i64_shl( - i64_one, - i64_new(index) - ) - ), - i64_zero - ); -} - -/** Sets or unsets the bit at the specified index within a 64-bit map and returns the new map. */ -export function bitsetSet(map: i64, index: i32, isSet: bool): i64 { - assert(index >= 0 && index < 64); - return isSet - ? i64_or( - map, - i64_shl( - i64_one, - i64_new(index) - ) - ) - : i64_and( - map, - i64_not( - i64_shl( - i64_one, - i64_new(index) - ) - ) - ); -} diff --git a/src/util/charcode.ts b/src/util/charcode.ts deleted file mode 100644 index 318b571430..0000000000 --- a/src/util/charcode.ts +++ /dev/null @@ -1,378 +0,0 @@ -/** @module util *//***/ - -/** An enum of named character codes. */ -export const enum CharCode { - - NULL = 0, - LINEFEED = 0x0A, - CARRIAGERETURN = 0x0D, - LINESEPARATOR = 0x2028, - PARAGRAPHSEPARATOR = 0x2029, - NEXTLINE = 0x0085, - - SPACE = 0x20, - NONBREAKINGSPACE = 0xA0, - ENQUAD = 0x2000, - EMQUAD = 0x2001, - ENSPACE = 0x2002, - EMSPACE = 0x2003, - THREEPEREMSPACE = 0x2004, - FOURPEREMSPACE = 0x2005, - SIXPEREMSPACE = 0x2006, - FIGURESPACE = 0x2007, - PUNCTUATIONSPACE = 0x2008, - THINSPACE = 0x2009, - HAIRSPACE = 0x200A, - ZEROWIDTHSPACE = 0x200B, - NARROWNOBREAKSPACE = 0x202F, - IDEOGRAPHICSPACE = 0x3000, - MATHEMATICALSPACE = 0x205F, - OGHAM = 0x1680, - - _ = 0x5F, - - _0 = 0x30, - _1 = 0x31, - _2 = 0x32, - _3 = 0x33, - _4 = 0x34, - _5 = 0x35, - _6 = 0x36, - _7 = 0x37, - _8 = 0x38, - _9 = 0x39, - - a = 0x61, - b = 0x62, - c = 0x63, - d = 0x64, - e = 0x65, - f = 0x66, - g = 0x67, - h = 0x68, - i = 0x69, - j = 0x6A, - k = 0x6B, - l = 0x6C, - m = 0x6D, - n = 0x6E, - o = 0x6F, - p = 0x70, - q = 0x71, - r = 0x72, - s = 0x73, - t = 0x74, - u = 0x75, - v = 0x76, - w = 0x77, - x = 0x78, - y = 0x79, - z = 0x7A, - - A = 0x41, - B = 0x42, - C = 0x43, - D = 0x44, - E = 0x45, - F = 0x46, - G = 0x47, - H = 0x48, - I = 0x49, - J = 0x4A, - K = 0x4B, - L = 0x4C, - M = 0x4D, - N = 0x4E, - O = 0x4F, - P = 0x50, - Q = 0x51, - R = 0x52, - S = 0x53, - T = 0x54, - U = 0x55, - V = 0x56, - W = 0x57, - X = 0x58, - Y = 0x59, - Z = 0x5a, - - AMPERSAND = 0x26, - ASTERISK = 0x2A, - AT = 0x40, - BACKSLASH = 0x5C, - BACKTICK = 0x60, - BAR = 0x7C, - CARET = 0x5E, - CLOSEBRACE = 0x7D, - CLOSEBRACKET = 0x5D, - CLOSEPAREN = 0x29, - COLON = 0x3A, - COMMA = 0x2C, - DOLLAR = 0x24, - DOT = 0x2E, - DOUBLEQUOTE = 0x22, - EQUALS = 0x3D, - EXCLAMATION = 0x21, - GREATERTHAN = 0x3E, - HASH = 0x23, - LESSTHAN = 0x3C, - MINUS = 0x2D, - OPENBRACE = 0x7B, - OPENBRACKET = 0x5B, - OPENPAREN = 0x28, - PERCENT = 0x25, - PLUS = 0x2B, - QUESTION = 0x3F, - SEMICOLON = 0x3B, - SINGLEQUOTE = 0x27, - SLASH = 0x2F, - TILDE = 0x7E, - - BACKSPACE = 0x08, - FORMFEED = 0x0C, - BYTEORDERMARK = 0xFEFF, - TAB = 0x09, - VERTICALTAB = 0x0B -} - -/** Tests if the specified character code is some sort of line break. */ -export function isLineBreak(c: CharCode): bool { - switch (c) { - case CharCode.LINEFEED: - case CharCode.CARRIAGERETURN: - case CharCode.LINESEPARATOR: - case CharCode.PARAGRAPHSEPARATOR: { - return true; - } - default: { - return false; - } - } -} - -/** Tests if the specified character code is some sort of white space. */ -export function isWhiteSpace(c: i32): bool { - switch (c) { - case CharCode.SPACE: - case CharCode.TAB: - case CharCode.VERTICALTAB: - case CharCode.FORMFEED: - case CharCode.NONBREAKINGSPACE: - case CharCode.NEXTLINE: - case CharCode.OGHAM: - case CharCode.NARROWNOBREAKSPACE: - case CharCode.MATHEMATICALSPACE: - case CharCode.IDEOGRAPHICSPACE: - case CharCode.BYTEORDERMARK: { - return true; - } - default: { - return c >= CharCode.ENQUAD && c <= CharCode.ZEROWIDTHSPACE; - } - } -} - -/** Tests if the specified character code is a valid decimal digit. */ -export function isDecimalDigit(c: i32): bool { - return c >= CharCode._0 && c <= CharCode._9; -} - -/** Tests if the specified character code is a valid octal digit. */ -export function isOctalDigit(c: i32): bool { - return c >= CharCode._0 && c <= CharCode._7; -} - -/** Tests if the specified character code is a valid start of an identifier. */ -export function isIdentifierStart(c: i32): bool { - const c0 = c | 32; // unify uppercases and lowercases a|A - z|Z - return c0 >= CharCode.a && c0 <= CharCode.z - || c == CharCode._ - || c == CharCode.DOLLAR - || c > 0x7F && isUnicodeIdentifierStart(c); -} - -/** Tests if the specified character code is a valid keyword character. */ -export function isKeywordCharacter(c: i32): bool { - return c >= CharCode.a && c <= CharCode.z; -} - -/** Tests if the specified character code is a valid part of an identifier. */ -export function isIdentifierPart(c: i32): bool { - const c0 = c | 32; // unify uppercases and lowercases a|A - z|Z - return c0 >= CharCode.a && c0 <= CharCode.z - || c >= CharCode._0 && c <= CharCode._9 - || c == CharCode._ - || c == CharCode.DOLLAR - || c > 0x7F && isUnicodeIdentifierPart(c); -} - -// storing as u16 to save memory -const unicodeIdentifierStart: u16[] = [ - 170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, - 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, - 908, 908, 910, 929, 931, - 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, - 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, - 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, - 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, - 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, - 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, - 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, - 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, - 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, - 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, - 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, - 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, - 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, - 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, - 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, - 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, - 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, - 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, - 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, - 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, - 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, - 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, - 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, - 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, - 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, - 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, - 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, - 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, - 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, - 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, - 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, - 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, - 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, - 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, - 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, - 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, - 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, - 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, - 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, - 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, - 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, - 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, - 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, - 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, - 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, - 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, - 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, - 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, - 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, - 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, - 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, - 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, - 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, - 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, - 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, - 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, - 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, - 65479, 65482, 65487, 65490, 65495, 65498, 65500, -]; -const unicodeIdentifierPart: u16[] = [ - 170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, - 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, - 908, 908, 910, 929, 931, - 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, - 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, - 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, - 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, - 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, - 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, - 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, - 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, - 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, - 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, - 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, - 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, - 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, - 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, - 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, - 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, - 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, - 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, - 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, - 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, - 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, - 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, - 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, - 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, - 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, - 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, - 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, - 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, - 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, - 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, - 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, - 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, - 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, - 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, - 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, - 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, - 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, - 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, - 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, - 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, - 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, - 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, - 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, - 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, - 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, - 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, - 8521, 8526, 8526, 8544, 8584, - 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, - 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, - 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, - 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, - 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, - 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, - 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, - 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, - 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, - 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, - 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, - 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, - 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, - 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, - 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, - 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, - 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, - 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, - 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, - 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, -]; - -function lookupInUnicodeMap(code: u16, map: u16[]): bool { - if (code < map[0]) return false; - - var lo = 0; - var hi = map.length; - var mid: i32; - var midVal: u16; - - while (lo + 1 < hi) { - mid = lo + ((hi - lo) >> 1); - mid -= (mid & 1); - midVal = map[mid]; - if (midVal <= code && code <= map[mid + 1]) { - return true; - } - if (code < midVal) { - hi = mid; - } else { - lo = mid + 2; - } - } - return false; -} - -function isUnicodeIdentifierStart(code: i32): bool { - return code < 170 || code > 65500 ? false - : lookupInUnicodeMap(code as u16, unicodeIdentifierStart); -} - -function isUnicodeIdentifierPart(code: i32): bool { - return code < 170 || code > 65500 ? false - : lookupInUnicodeMap(code as u16, unicodeIdentifierPart); -} diff --git a/src/util/collections.ts b/src/util/collections.ts index f1ea2461fb..fc84409560 100644 --- a/src/util/collections.ts +++ b/src/util/collections.ts @@ -1,3 +1,8 @@ +/** + * @fileoverview Various collections utility. + * @license Apache-2.0 + */ + export function makeArray(original: Array | null = null): Array { if (original) { let len = original.length; diff --git a/src/util/index.ts b/src/util/index.ts index 219815d2e2..da61a0069f 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -1,17 +1,10 @@ /** - * Various compiler utilities. - * @module util - * @preferred - *//***/ + * @fileoverview Various utility. + * @license Apache-2.0 + */ -export * from "./bitset"; -export * from "./charcode"; +export * from "./binary"; export * from "./collections"; +export * from "./math"; export * from "./path"; export * from "./text"; -export * from "./binary"; - -/** Tests if `x` is a power of two. */ -export function isPowerOf2(x: i32): bool { - return x != 0 && (x & (x - 1)) == 0; -} diff --git a/src/util/math.ts b/src/util/math.ts new file mode 100644 index 0000000000..592bfe8b6b --- /dev/null +++ b/src/util/math.ts @@ -0,0 +1,9 @@ +/** + * @fileoverview Various math utility. + * @license Apache-2.0 + */ + +/** Tests if `x` is a power of two. */ +export function isPowerOf2(x: i32): bool { + return x != 0 && (x & (x - 1)) == 0; +} diff --git a/src/util/path.ts b/src/util/path.ts index 9fa6110051..a219388972 100644 --- a/src/util/path.ts +++ b/src/util/path.ts @@ -1,8 +1,11 @@ -/** @module util *//***/ +/** + * @fileoverview Various file path utility. + * @license Apache-2.0 + */ import { CharCode -} from "./charcode"; +} from "./text"; import { PATH_DELIMITER diff --git a/src/util/text.ts b/src/util/text.ts index e9a40d4c3a..caa983b625 100644 --- a/src/util/text.ts +++ b/src/util/text.ts @@ -1,4 +1,384 @@ -/** @module util *//***/ +/** + * @fileoverview Various character and text utility. + * @license Apache-2.0 + */ + +/** An enum of named character codes. */ +export const enum CharCode { + + NULL = 0, + LINEFEED = 0x0A, + CARRIAGERETURN = 0x0D, + LINESEPARATOR = 0x2028, + PARAGRAPHSEPARATOR = 0x2029, + NEXTLINE = 0x0085, + + SPACE = 0x20, + NONBREAKINGSPACE = 0xA0, + ENQUAD = 0x2000, + EMQUAD = 0x2001, + ENSPACE = 0x2002, + EMSPACE = 0x2003, + THREEPEREMSPACE = 0x2004, + FOURPEREMSPACE = 0x2005, + SIXPEREMSPACE = 0x2006, + FIGURESPACE = 0x2007, + PUNCTUATIONSPACE = 0x2008, + THINSPACE = 0x2009, + HAIRSPACE = 0x200A, + ZEROWIDTHSPACE = 0x200B, + NARROWNOBREAKSPACE = 0x202F, + IDEOGRAPHICSPACE = 0x3000, + MATHEMATICALSPACE = 0x205F, + OGHAM = 0x1680, + + _ = 0x5F, + + _0 = 0x30, + _1 = 0x31, + _2 = 0x32, + _3 = 0x33, + _4 = 0x34, + _5 = 0x35, + _6 = 0x36, + _7 = 0x37, + _8 = 0x38, + _9 = 0x39, + + a = 0x61, + b = 0x62, + c = 0x63, + d = 0x64, + e = 0x65, + f = 0x66, + g = 0x67, + h = 0x68, + i = 0x69, + j = 0x6A, + k = 0x6B, + l = 0x6C, + m = 0x6D, + n = 0x6E, + o = 0x6F, + p = 0x70, + q = 0x71, + r = 0x72, + s = 0x73, + t = 0x74, + u = 0x75, + v = 0x76, + w = 0x77, + x = 0x78, + y = 0x79, + z = 0x7A, + + A = 0x41, + B = 0x42, + C = 0x43, + D = 0x44, + E = 0x45, + F = 0x46, + G = 0x47, + H = 0x48, + I = 0x49, + J = 0x4A, + K = 0x4B, + L = 0x4C, + M = 0x4D, + N = 0x4E, + O = 0x4F, + P = 0x50, + Q = 0x51, + R = 0x52, + S = 0x53, + T = 0x54, + U = 0x55, + V = 0x56, + W = 0x57, + X = 0x58, + Y = 0x59, + Z = 0x5a, + + AMPERSAND = 0x26, + ASTERISK = 0x2A, + AT = 0x40, + BACKSLASH = 0x5C, + BACKTICK = 0x60, + BAR = 0x7C, + CARET = 0x5E, + CLOSEBRACE = 0x7D, + CLOSEBRACKET = 0x5D, + CLOSEPAREN = 0x29, + COLON = 0x3A, + COMMA = 0x2C, + DOLLAR = 0x24, + DOT = 0x2E, + DOUBLEQUOTE = 0x22, + EQUALS = 0x3D, + EXCLAMATION = 0x21, + GREATERTHAN = 0x3E, + HASH = 0x23, + LESSTHAN = 0x3C, + MINUS = 0x2D, + OPENBRACE = 0x7B, + OPENBRACKET = 0x5B, + OPENPAREN = 0x28, + PERCENT = 0x25, + PLUS = 0x2B, + QUESTION = 0x3F, + SEMICOLON = 0x3B, + SINGLEQUOTE = 0x27, + SLASH = 0x2F, + TILDE = 0x7E, + + BACKSPACE = 0x08, + FORMFEED = 0x0C, + BYTEORDERMARK = 0xFEFF, + TAB = 0x09, + VERTICALTAB = 0x0B +} + +/** Tests if the specified character code is some sort of line break. */ +export function isLineBreak(c: CharCode): bool { + switch (c) { + case CharCode.LINEFEED: + case CharCode.CARRIAGERETURN: + case CharCode.LINESEPARATOR: + case CharCode.PARAGRAPHSEPARATOR: { + return true; + } + default: { + return false; + } + } +} + +/** Tests if the specified character code is some sort of white space. */ +export function isWhiteSpace(c: i32): bool { + switch (c) { + case CharCode.SPACE: + case CharCode.TAB: + case CharCode.VERTICALTAB: + case CharCode.FORMFEED: + case CharCode.NONBREAKINGSPACE: + case CharCode.NEXTLINE: + case CharCode.OGHAM: + case CharCode.NARROWNOBREAKSPACE: + case CharCode.MATHEMATICALSPACE: + case CharCode.IDEOGRAPHICSPACE: + case CharCode.BYTEORDERMARK: { + return true; + } + default: { + return c >= CharCode.ENQUAD && c <= CharCode.ZEROWIDTHSPACE; + } + } +} + +/** Tests if the specified character code is a valid decimal digit. */ +export function isDecimalDigit(c: i32): bool { + return c >= CharCode._0 && c <= CharCode._9; +} + +/** Tests if the specified character code is a valid octal digit. */ +export function isOctalDigit(c: i32): bool { + return c >= CharCode._0 && c <= CharCode._7; +} + +/** Tests if the specified character code is a valid start of an identifier. */ +export function isIdentifierStart(c: i32): bool { + const c0 = c | 32; // unify uppercases and lowercases a|A - z|Z + return c0 >= CharCode.a && c0 <= CharCode.z + || c == CharCode._ + || c == CharCode.DOLLAR + || c > 0x7F && isUnicodeIdentifierStart(c); +} + +/** Tests if the specified character code is a valid keyword character. */ +export function isKeywordCharacter(c: i32): bool { + return c >= CharCode.a && c <= CharCode.z; +} + +/** Tests if the specified character code is a valid part of an identifier. */ +export function isIdentifierPart(c: i32): bool { + const c0 = c | 32; // unify uppercases and lowercases a|A - z|Z + return c0 >= CharCode.a && c0 <= CharCode.z + || c >= CharCode._0 && c <= CharCode._9 + || c == CharCode._ + || c == CharCode.DOLLAR + || c > 0x7F && isUnicodeIdentifierPart(c); +} + +// storing as u16 to save memory +const unicodeIdentifierStart: u16[] = [ + 170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, + 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, + 908, 908, 910, 929, 931, + 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, + 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, + 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, + 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, + 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, + 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, + 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, + 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, + 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, + 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, + 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, + 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, + 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, + 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, + 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, + 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, + 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, + 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, + 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, + 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, + 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, + 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, + 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, + 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, + 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, + 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, + 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, + 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, + 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, + 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, + 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, + 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, + 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, + 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, + 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, + 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, + 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, + 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, + 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, + 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, + 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, + 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, + 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, + 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, + 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, + 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, + 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, + 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, + 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, + 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, + 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, + 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, + 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, + 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, + 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, + 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, + 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, + 65479, 65482, 65487, 65490, 65495, 65498, 65500, +]; +const unicodeIdentifierPart: u16[] = [ + 170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, + 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, + 908, 908, 910, 929, 931, + 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, + 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, + 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, + 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, + 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, + 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, + 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, + 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, + 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, + 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, + 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, + 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, + 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, + 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, + 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, + 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, + 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, + 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, + 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, + 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, + 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, + 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, + 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, + 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, + 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, + 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, + 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, + 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, + 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, + 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, + 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, + 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, + 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, + 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, + 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, + 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, + 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, + 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, + 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, + 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, + 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, + 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, + 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, + 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, + 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, + 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, + 8521, 8526, 8526, 8544, 8584, + 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, + 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, + 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, + 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, + 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, + 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, + 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, + 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, + 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, + 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, + 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, + 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, + 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, + 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, + 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, + 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, + 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, + 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, + 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, + 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, +]; + +function lookupInUnicodeMap(code: u16, map: u16[]): bool { + if (code < map[0]) return false; + + var lo = 0; + var hi = map.length; + var mid: i32; + var midVal: u16; + + while (lo + 1 < hi) { + mid = lo + ((hi - lo) >> 1); + mid -= (mid & 1); + midVal = map[mid]; + if (midVal <= code && code <= map[mid + 1]) { + return true; + } + if (code < midVal) { + hi = mid; + } else { + lo = mid + 2; + } + } + return false; +} + +function isUnicodeIdentifierStart(code: i32): bool { + return code < 170 || code > 65500 ? false + : lookupInUnicodeMap(code as u16, unicodeIdentifierStart); +} + +function isUnicodeIdentifierPart(code: i32): bool { + return code < 170 || code > 65500 ? false + : lookupInUnicodeMap(code as u16, unicodeIdentifierPart); +} const indentX1 = " "; const indentX2 = " "; diff --git a/webpack.config.js b/webpack.config.js index 30d0714812..038f53050f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,18 @@ const path = require("path"); const fs = require("fs"); const webpack = require("webpack"); +const TerserPlugin = require('terser-webpack-plugin'); + +function preamble(name) { + return [ + "/**", + " * @license", + " * " + name, + " * Copyright Daniel Wirtz / The AssemblyScript Authors.", + " * SPDX-License-Identifier: Apache-2.0", + " */" + ].join("\n"); +} // Build the C-like library const lib = { @@ -30,6 +42,20 @@ const lib = { devtool: "source-map", performance: { hints : false + }, + optimization: { + minimize: true, + minimizer: [ + new TerserPlugin({ + terserOptions: { + output: { + comments: false, + preamble: preamble("The AssemblyScript Compiler.") + } + }, + sourceMap: true + }) + ], } }; @@ -76,7 +102,21 @@ const bin = { __dirname: JSON.stringify(".") }), new webpack.IgnorePlugin(/\.\/src|package\.json|^(ts\-node|glob)$/) - ] + ], + optimization: { + minimize: true, + minimizer: [ + new TerserPlugin({ + terserOptions: { + output: { + comments: false, + preamble: preamble("The AssemblyScript Compiler Frontend.") + } + }, + sourceMap: true + }) + ], + } }; function bundleFile(filename) { From 318cc3ffe7287dd9985b3730ec9d11ddfef6ab30 Mon Sep 17 00:00:00 2001 From: dcode Date: Tue, 3 Mar 2020 18:52:55 +0100 Subject: [PATCH 2/2] use full header in asc as well --- cli/asc.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/cli/asc.js b/cli/asc.js index 977eaf31a8..85b1bc5c63 100644 --- a/cli/asc.js +++ b/cli/asc.js @@ -1,3 +1,22 @@ +/** + * @license + * Copyright 2020 Daniel Wirtz / The AssemblyScript Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + /** * @fileoverview Compiler frontend for node.js * @@ -7,10 +26,6 @@ * * Can also be packaged as a bundle suitable for in-browser use with the standard library injected * in the build step. See dist/asc.js for the bundle and webpack.config.js for building details. - * - * @license - * Copyright Daniel Wirtz / The AssemblyScript Authors. - * SPDX-License-Identifier: Apache-2.0 */ // Use "." instead of "/" as cwd in browsers