Skip to content

Speedup tokenizer & parser #2161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 134 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
60f14a8
init
MaxGraey Nov 14, 2021
bd5ef03
advance pos for readInteger
MaxGraey Nov 14, 2021
3072664
fix
MaxGraey Nov 14, 2021
fcb4200
comments
MaxGraey Nov 14, 2021
26ab535
better
MaxGraey Nov 14, 2021
72a6203
Guarantee skip upper cased tokens as keywords
MaxGraey Nov 14, 2021
4c4c4c9
add keyword length limit
MaxGraey Nov 14, 2021
6159cd8
better
MaxGraey Nov 14, 2021
35fb736
revert
MaxGraey Nov 14, 2021
182eb41
improve token skip
MaxGraey Nov 15, 2021
1b91de3
add isKeyword helper
MaxGraey Nov 15, 2021
1c22bc5
refactor
MaxGraey Nov 15, 2021
207b7d9
add skipKeyword
MaxGraey Nov 15, 2021
7c1fa02
clean
MaxGraey Nov 15, 2021
133892b
allow "of" as identifier
MaxGraey Nov 15, 2021
7cfb3a3
fix
MaxGraey Nov 15, 2021
b12bb19
better
MaxGraey Nov 15, 2021
6721afc
use const enums
MaxGraey Nov 15, 2021
43be895
improve ts emit
MaxGraey Nov 15, 2021
c8ed972
fix
MaxGraey Nov 15, 2021
4dcbce4
Merge branch 'main' into speedup-tokenizer
MaxGraey Nov 15, 2021
0729ee3
refactor
MaxGraey Nov 15, 2021
52e5b56
Merge branch 'main' into speedup-tokenizer
MaxGraey Nov 16, 2021
ad65d6a
add MIN_KEYWORD_LENGTH
MaxGraey Nov 16, 2021
4dbebdb
more
MaxGraey Nov 16, 2021
dc19d6e
simplify tokenFromKeyword
MaxGraey Nov 16, 2021
2e1d68a
disable preserveConstEnums
MaxGraey Nov 16, 2021
37610b2
refactor compilerOptions
MaxGraey Nov 16, 2021
42e674d
improve line break for single comments
MaxGraey Nov 16, 2021
2637ffc
add TODO
MaxGraey Nov 16, 2021
79480c4
refactor
MaxGraey Nov 16, 2021
1d2f631
add comment
MaxGraey Nov 16, 2021
aef8da8
add TODO
MaxGraey Nov 16, 2021
5d861b6
handle ||= and &&=
MaxGraey Nov 16, 2021
27b2259
refactor
MaxGraey Nov 16, 2021
39937b2
typo
MaxGraey Nov 16, 2021
9d77b36
better
MaxGraey Nov 16, 2021
dae3462
refactor
MaxGraey Nov 16, 2021
4a4b8f4
add ?? and ??= for tokenizer
MaxGraey Nov 17, 2021
2554518
Merge branch 'main' into speedup-tokenizer
MaxGraey Nov 17, 2021
3ee3dac
Merge branch 'main' into speedup-tokenizer
MaxGraey Nov 17, 2021
c1a267c
refactor range
MaxGraey Nov 17, 2021
3f34f97
Merge branch 'main' into speedup-tokenizer
MaxGraey Nov 18, 2021
3ca80dd
Merge branch 'main' into speedup-tokenizer
MaxGraey Nov 18, 2021
d9e08a7
better probeKeywordToken
MaxGraey Nov 18, 2021
d12d5ff
faster isIllegalVariableIdentifier
MaxGraey Nov 18, 2021
ab3b858
better readHexInteger
MaxGraey Nov 18, 2021
bc4ec02
better
MaxGraey Nov 18, 2021
e4986e3
better octal
MaxGraey Nov 18, 2021
b57e5c6
optimize read hex, octal and binary by skipping seq zeros
MaxGraey Nov 18, 2021
5d960a9
refactor
MaxGraey Nov 18, 2021
9d5d0ff
more
MaxGraey Nov 18, 2021
3df8ce8
add fast pathes for readDecimalFloat
MaxGraey Nov 18, 2021
92dd92a
simplify readDecimalFloatPartial
MaxGraey Nov 18, 2021
d693f7b
refactor
MaxGraey Nov 18, 2021
1f80377
more
MaxGraey Nov 18, 2021
f7d3a90
better
MaxGraey Nov 18, 2021
ee8dba9
add await operator for operatorTokenToString
MaxGraey Nov 19, 2021
82ae5c8
refactor
MaxGraey Nov 19, 2021
e2e86ca
refactor readInteger
MaxGraey Nov 19, 2021
4399ab7
refactor
MaxGraey Nov 19, 2021
0cba78a
better
MaxGraey Nov 19, 2021
1e9ea69
refactor
MaxGraey Nov 19, 2021
51e9197
again
MaxGraey Nov 19, 2021
87557ee
ENDOFFILE => EOF
MaxGraey Nov 19, 2021
f326524
simplify parseExpression
MaxGraey Nov 19, 2021
43b41b0
add comment for parse new operator
MaxGraey Nov 22, 2021
e38fe0d
more
MaxGraey Nov 22, 2021
f4179f3
add regexp case for parser's skipStatement
MaxGraey Nov 22, 2021
33617ce
more
MaxGraey Nov 22, 2021
7db95f8
add ||=, &&=, ??= and ?? for determinePrecedence
MaxGraey Nov 22, 2021
34c8f9e
refactor determinePrecedence
MaxGraey Nov 22, 2021
8d1e2c8
refactor
MaxGraey Nov 22, 2021
343c161
refactor
MaxGraey Nov 22, 2021
651cf1f
Merge branch 'main' into speedup-tokenizer
MaxGraey Nov 23, 2021
5b97b00
refactor
MaxGraey Nov 25, 2021
396dd23
better
MaxGraey Nov 25, 2021
d0921a0
add tests
MaxGraey Nov 25, 2021
264d7d2
simplify isIllegalVariableIdentifier
MaxGraey Nov 25, 2021
23632a6
comment
MaxGraey Nov 25, 2021
6f3cb12
simplify
MaxGraey Nov 25, 2021
79c2a86
better
MaxGraey Nov 25, 2021
efcadb6
simplify
MaxGraey Nov 26, 2021
8d8251e
refactor
MaxGraey Nov 26, 2021
437ce5a
refactor configs
MaxGraey Nov 26, 2021
1c5f75d
Merge branch 'main' into speedup-tokenizer
MaxGraey Nov 26, 2021
163ec99
refactor peek
MaxGraey Nov 28, 2021
6d43043
opt readIdentifier
MaxGraey Nov 28, 2021
590181f
simplify comment
MaxGraey Nov 28, 2021
d95b5d5
more
MaxGraey Nov 28, 2021
3840256
use index intead charAt
MaxGraey Nov 29, 2021
cd6a125
Merge branch 'main' into speedup-tokenizer
MaxGraey Dec 2, 2021
bb7ec82
revert some changes in test after resolve conflicts
MaxGraey Dec 2, 2021
ced5015
refactor
MaxGraey Dec 5, 2021
c61f41b
remove preserveCostEnum
MaxGraey Dec 5, 2021
eec4d88
add lookup token table
MaxGraey Dec 5, 2021
3d0daa9
use this table for speedup & simplify tokenization
MaxGraey Dec 5, 2021
bf8c66d
refactor
MaxGraey Dec 5, 2021
233a013
rearrange
MaxGraey Dec 5, 2021
60a3d36
Merge branch 'main' into speedup-tokenizer
MaxGraey Dec 5, 2021
af33cd5
simplify
MaxGraey Dec 6, 2021
a13414a
more
MaxGraey Dec 6, 2021
e06fa9e
refactor
MaxGraey Dec 6, 2021
057840e
simplify
MaxGraey Dec 6, 2021
02250c9
refactor
MaxGraey Dec 6, 2021
cb32321
fix
MaxGraey Dec 6, 2021
33bcf1f
simplify integerOrFloatToken
MaxGraey Dec 6, 2021
6bee4dc
refactor
MaxGraey Dec 6, 2021
273dc43
refactor. Simplify names
MaxGraey Dec 6, 2021
114ac1e
refactor
MaxGraey Dec 6, 2021
25991a8
refactor skipLineComment
MaxGraey Dec 6, 2021
e1de806
refactor skipBlockComment
MaxGraey Dec 6, 2021
1e52754
let -> var
MaxGraey Dec 6, 2021
f3f309e
refactor scanKeyword
MaxGraey Dec 6, 2021
2a18ccc
refactor scanKeyword
MaxGraey Dec 6, 2021
23d6ad8
simplify
MaxGraey Dec 6, 2021
9fab45e
fix
MaxGraey Dec 6, 2021
d25c23b
refactor
MaxGraey Dec 6, 2021
2443123
remove assert in scanKeyword
MaxGraey Dec 6, 2021
745e615
refactor
MaxGraey Dec 6, 2021
02b02f3
more
MaxGraey Dec 6, 2021
1260341
more
MaxGraey Dec 6, 2021
abc9d12
refactor
MaxGraey Dec 6, 2021
009e7c0
refactor
MaxGraey Dec 6, 2021
8b5c101
better
MaxGraey Dec 6, 2021
c86dd79
fix
MaxGraey Dec 6, 2021
56cd089
better
MaxGraey Dec 6, 2021
de390ac
refactor
MaxGraey Dec 6, 2021
ec0e9b8
add COMMENT_OR_OPERATOR pseudo token
MaxGraey Dec 6, 2021
f6cb7e3
move Range to diagnostics
MaxGraey Dec 6, 2021
f7a74f0
refactor comment
MaxGraey Dec 6, 2021
e9603bb
unchecked
MaxGraey Dec 6, 2021
f131f29
refactoring
MaxGraey Dec 8, 2021
ab507d5
MAYBE_KEYWORD -> IDENTIFIER_OR_KEYWORD
MaxGraey Dec 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import {
} from "./common";

import {
Token,
Range
} from "./diagnostics";

import {
Token
} from "./tokenizer";

import {
Expand All @@ -42,7 +45,7 @@ import {
} from "./types";

/** Indicates the kind of a node. */
export enum NodeKind {
export const enum NodeKind {

SOURCE,

Expand Down Expand Up @@ -923,7 +926,7 @@ export class TypeParameterNode extends Node {
}

/** Represents the kind of a parameter. */
export enum ParameterKind {
export const enum ParameterKind {
/** No specific flags. */
DEFAULT,
/** Is an optional parameter. */
Expand Down Expand Up @@ -1067,7 +1070,7 @@ export class DecoratorNode extends Node {
}

/** Comment kinds. */
export enum CommentKind {
export const enum CommentKind {
/** Line comment. */
LINE,
/** Triple-slash line comment. */
Expand Down Expand Up @@ -1110,7 +1113,7 @@ export class IdentifierExpression extends Expression {
}

/** Indicates the kind of a literal. */
export enum LiteralKind {
export const enum LiteralKind {
FLOAT,
INTEGER,
STRING,
Expand Down Expand Up @@ -1145,7 +1148,7 @@ export class ArrayLiteralExpression extends LiteralExpression {
}

/** Indicates the kind of an assertion. */
export enum AssertionKind {
export const enum AssertionKind {
/** A prefix assertion, i.e. `<T>expr`. */
PREFIX,
/** An as assertion, i.e. `expr as T`. */
Expand Down Expand Up @@ -1586,7 +1589,7 @@ export class CompiledExpression extends Expression {
export abstract class Statement extends Node { }

/** Indicates the specific kind of a source. */
export enum SourceKind {
export const enum SourceKind {
/** User-provided file. */
USER = 0,
/** User-provided entry file. */
Expand Down
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/** Indicates traits of a {@link Node} or {@link Element}. */
export enum CommonFlags {
export const enum CommonFlags {
/** No flags set. */
NONE = 0,

Expand Down
2 changes: 1 addition & 1 deletion src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "./builtins";

import {
Range,
DiagnosticCode,
DiagnosticEmitter
} from "./diagnostics";
Expand Down Expand Up @@ -108,7 +109,6 @@ import {

import {
Token,
Range,
operatorTokenToString
} from "./tokenizer";

Expand Down
48 changes: 43 additions & 5 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
* @license Apache-2.0
*/

import {
Range
} from "./tokenizer";

import {
Source
} from "./ast";
Expand All @@ -33,7 +29,7 @@ export {
} from "./diagnosticMessages.generated";

/** Indicates the category of a {@link DiagnosticMessage}. */
export enum DiagnosticCategory {
export const enum DiagnosticCategory {
/** Overly pedantic message. */
PEDANTIC,
/** Informatory message. */
Expand All @@ -44,6 +40,48 @@ export enum DiagnosticCategory {
ERROR
}

export class Range {

source!: Source;
debugInfoRef: usize = 0;

constructor(public start: i32, public end: i32) {}

static join(a: Range, b: Range): Range {
if (a.source != b.source) throw new Error("source mismatch");
let range = new Range(
a.start < b.start ? a.start : b.start,
a.end > b.end ? a.end : b.end
);
range.source = a.source;
return range;
}

equals(other: Range): bool {
return (
this.source == other.source &&
this.start == other.start &&
this.end == other.end
);
}

get atStart(): Range {
let range = new Range(this.start, this.start);
range.source = this.source;
return range;
}

get atEnd(): Range {
let range = new Range(this.end, this.end);
range.source = this.source;
return range;
}

toString(): string {
return this.source.text.substring(this.start, this.end);
}
}

/** Returns the string representation of the specified diagnostic category. */
export function diagnosticCategoryToString(category: DiagnosticCategory): string {
switch (category) {
Expand Down
4 changes: 2 additions & 2 deletions src/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const enum FlowFlags {
}

/** Flags indicating the current state of a local. */
export enum LocalFlags {
export const enum LocalFlags {
/** No specific conditions. */
NONE = 0,

Expand All @@ -169,7 +169,7 @@ export enum LocalFlags {
}

/** Flags indicating the current state of a field. */
export enum FieldFlags {
export const enum FieldFlags {
NONE = 0,
INITIALIZED = 1 << 0
}
Expand Down
34 changes: 17 additions & 17 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export namespace TypeRef {
}

/** Binaryen feature constants. */
export enum FeatureFlags {
export const enum FeatureFlags {
MVP = 0 /* _BinaryenFeatureMVP */,
Atomics = 1 /* _BinaryenFeatureAtomics */,
MutableGloabls = 2 /* _BinaryenFeatureMutableGlobals */,
Expand All @@ -88,7 +88,7 @@ export enum FeatureFlags {
}

/** Binaryen expression id constants. */
export enum ExpressionId {
export const enum ExpressionId {
Invalid = 0 /* _BinaryenInvalidId */,
Block = 1 /* _BinaryenBlockId */,
If = 2 /* _BinaryenIfId */,
Expand Down Expand Up @@ -164,7 +164,7 @@ export enum ExpressionId {
}

/** Binaryen external kind constants. */
export enum ExternalKind {
export const enum ExternalKind {
Function = 0 /* _BinaryenExternalFunction */,
Table = 1 /* _BinaryenExternalTable */,
Memory = 2 /* _BinaryenExternalMemory */,
Expand All @@ -173,7 +173,7 @@ export enum ExternalKind {
}

/** Binaryen unary operation constants. */
export enum UnaryOp {
export const enum UnaryOp {
/** i32.clz */
ClzI32 = 0 /* _BinaryenClzInt32 */,
/** i64.clz */
Expand Down Expand Up @@ -449,7 +449,7 @@ export enum UnaryOp {
}

/** Binaryen binary operation constants. */
export enum BinaryOp {
export const enum BinaryOp {
/** i32.add */
AddI32 = 0 /* _BinaryenAddInt32 */,
/** i32.sub */
Expand Down Expand Up @@ -903,7 +903,7 @@ export enum BinaryOp {
}

/** Binaryen atomic read-modify-write operation constants. */
export enum AtomicRMWOp {
export const enum AtomicRMWOp {
/** i32.atomic.rmw.add, i32.atomic.rmw8.add_u, i32.atomic.rmw16.add_u, i64.atomic.rmw.add, i64.atomic.rmw8.add_u, i64.atomic.rmw16.add_u, i64.atomic.rmw32.add_u */
Add = 0 /* _BinaryenAtomicRMWAdd */,
/** i32.atomic.rmw.sub, i32.atomic.rmw8.sub_u, i32.atomic.rmw16.sub_u, i64.atomic.rmw.sub, i64.atomic.rmw8.sub_u, i64.atomic.rmw16.sub_u, i64.atomic.rmw32.sub_u */
Expand All @@ -919,7 +919,7 @@ export enum AtomicRMWOp {
}

/** Binaryen SIMD extract operation constants. */
export enum SIMDExtractOp {
export const enum SIMDExtractOp {
/** i8x16.extract_lane_s */
ExtractLaneI8x16 = 0 /* _BinaryenExtractLaneSVecI8x16 */,
/** i8x16.extract_lane_u */
Expand All @@ -939,7 +939,7 @@ export enum SIMDExtractOp {
}

/** Binaryen SIMD replace operation constants. */
export enum SIMDReplaceOp {
export const enum SIMDReplaceOp {
/** i8x16.replace_lane */
ReplaceLaneI8x16 = 0 /* _BinaryenReplaceLaneVecI8x16 */,
/** i16x8.replace_lane */
Expand All @@ -955,7 +955,7 @@ export enum SIMDReplaceOp {
}

/** Binaryen SIMD shift operation constants. */
export enum SIMDShiftOp {
export const enum SIMDShiftOp {
/** i8x16.shl */
ShlI8x16 = 0 /* _BinaryenShlVecI8x16 */,
/** i8x16.shr_s */
Expand Down Expand Up @@ -983,7 +983,7 @@ export enum SIMDShiftOp {
}

/** Binaryen SIMD load operation constants. */
export enum SIMDLoadOp {
export const enum SIMDLoadOp {
/** v128.load8_splat */
Load8Splat = 0 /* _BinaryenLoad8SplatVec128 */,
/** v128.load16_splat */
Expand Down Expand Up @@ -1011,7 +1011,7 @@ export enum SIMDLoadOp {
}

/** Binaryen SIMD load/store lane operation constants. */
export enum SIMDLoadStoreLaneOp {
export const enum SIMDLoadStoreLaneOp {
/** v128.load8_lane */
Load8Lane = 0 /* _BinaryenLoad8LaneVec128 */,
/** v128.load16_lane */
Expand All @@ -1031,13 +1031,13 @@ export enum SIMDLoadStoreLaneOp {
}

/** Binaryen SIMD ternary operation constants. */
export enum SIMDTernaryOp {
export const enum SIMDTernaryOp {
/** v128.bitselect */
Bitselect = 0 /* _BinaryenBitselectVec128 */
}

/** Binaryen RefIs operation constants. */
export enum RefIsOp {
export const enum RefIsOp {
/** ref.is_null */
RefIsNull = 0 /* _BinaryenRefIsNull */,
/** ref.is_func */
Expand All @@ -1049,7 +1049,7 @@ export enum RefIsOp {
}

/** Binaryen RefAs operation constants. */
export enum RefAsOp {
export const enum RefAsOp {
/** ref.as_non_null */
RefAsNonNull = 0 /* _BinaryenRefAsNonNull */,
/** ref.as_func */
Expand All @@ -1061,7 +1061,7 @@ export enum RefAsOp {
}

/** Binaryen BrOn operation constants. */
export enum BrOnOp {
export const enum BrOnOp {
/** br_on_null */
BrOnNull = 0 /* TODO_BinaryenBrOnNull */,
/** br_on_cast */
Expand All @@ -1075,7 +1075,7 @@ export enum BrOnOp {
}

/** Binaryen expression runner flags. */
export enum ExpressionRunnerFlags {
export const enum ExpressionRunnerFlags {
Default = 0 /* _ExpressionRunnerFlagsDefault */,
PreserveSideeffects = 1 /* _ExpressionRunnerFlagsPreserveSideeffects */,
TraverseCalls = 2 /* _ExpressionRunnerFlagsTraverseCalls */
Expand Down Expand Up @@ -3016,7 +3016,7 @@ export class SwitchBuilder {
}
}

export enum SideEffects {
export const enum SideEffects {
None = 0 /* _BinaryenSideEffectNone */,
Branches = 1 /* _BinaryenSideEffectBranches */,
Calls = 2 /* _BinaryenSideEffectCalls */,
Expand Down
Loading