From 884be8f9ecb7afe1943cd6ba4eaafde9ab98543a Mon Sep 17 00:00:00 2001 From: Sam Vervaeck Date: Thu, 28 May 2020 14:08:49 +0200 Subject: [PATCH] Small fixes and major enhancements to TypeChecker --- Makefile | 2 +- src/ast-spec.txt | 122 ++-- src/ast.d.ts | 1132 ++++++++++++++++++++++------------ src/bin/bolt.ts | 102 ++- src/checks.ts | 13 +- src/common.ts | 23 +- src/constants.ts | 5 + src/diagnostics.ts | 22 +- src/emitter.ts | 4 - src/frontend.ts | 10 +- src/parser.ts | 5 +- src/program.ts | 22 +- src/renamer.ts | 3 - src/resolver.ts | 27 +- src/treegen/ast-template.js | 12 +- src/treegen/ast.dts.template | 3 +- src/treegen/index.ts | 33 +- src/types.ts | 626 ++++++++++++++++--- src/util.ts | 66 +- stdlib/Boltfile | 4 +- stdlib/io.bolt | 10 +- stdlib/lib.bolt | 1 + stdlib/math.bolt | 2 + 23 files changed, 1614 insertions(+), 635 deletions(-) delete mode 100644 src/renamer.ts diff --git a/Makefile b/Makefile index 520b4cc20..fef9e0335 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -TREEGEN_FILES = src/ast-spec.txt lib/bin/bolt-treegen.js lib/treegen/parser.js lib/treegen/index.js lib/treegen/util.js src/treegen/ast-template.js +TREEGEN_FILES = src/treegen/ast.dts.template src/ast-spec.txt lib/bin/bolt-treegen.js lib/treegen/parser.js lib/treegen/index.js lib/treegen/util.js src/treegen/ast-template.js all: lib/ast.js bolt check stdlib diff --git a/src/ast-spec.txt b/src/ast-spec.txt index abc81dfab..6691e3449 100644 --- a/src/ast-spec.txt +++ b/src/ast-spec.txt @@ -1,18 +1,14 @@ -@language Bolt; -@language JS; - node EndOfFile > BoltToken, JSToken; node Token; node SourceFile; +node FunctionBody; // Bolt language AST definitions -type BoltValue = Integer | bool | String; +node BoltSyntax; -node FunctionBody; - -node BoltToken > Token; +node BoltToken > Token, BoltSyntax; node BoltStringLiteral > BoltToken { value: String, @@ -85,23 +81,22 @@ node BoltParenthesized > BoltPunctuated; node BoltBraced > BoltPunctuated; node BoltBracketed > BoltPunctuated; -node BoltSourceFile > SourceFile { +node BoltSourceFile > BoltSyntax, SourceFile { elements: Vec, package: Package, } -node BoltQualName { +node BoltQualName > BoltSyntax { isAbsolute: bool, modulePath: Vec, name: BoltSymbol, } -node BoltModulePath { - isAbsolute: bool, - elements: Vec, -} +node BoltTypeExpression > BoltSyntax; -node BoltTypeExpression; +node BoltTypeOfExpression > BoltTypeExpression { + expression: BoltExpression, +} node BoltReferenceTypeExpression > BoltTypeExpression { name: BoltQualName, @@ -117,14 +112,14 @@ node BoltLiftedTypeExpression > BoltTypeExpression { expression: BoltExpression, } -node BoltTypeParameter { +node BoltTypeParameter > BoltSyntax { index: usize, name: BoltIdentifier, typeExpr: Option, defaultType: Option, } -node BoltPattern; +node BoltPattern > BoltSyntax; node BoltBindPattern > BoltPattern { name: BoltIdentifier, @@ -139,7 +134,7 @@ node BoltExpressionPattern > BoltPattern { expression: BoltExpression, } -node BoltTuplePatternElement { +node BoltTuplePatternElement > BoltSyntax { index: usize, pattern: BoltPattern, } @@ -148,7 +143,7 @@ node BoltTuplePattern > BoltPattern { elements: Vec, } -node BoltRecordFieldPattern { +node BoltRecordFieldPattern > BoltSyntax { isRest: bool, name: Option, pattern: Option, @@ -159,7 +154,7 @@ node BoltRecordPattern > BoltPattern { fields: Vec, } -node BoltExpression; +node BoltExpression > BoltSyntax; node BoltQuoteExpression > BoltExpression { tokens: Vec, @@ -193,7 +188,7 @@ node BoltYieldExpression > BoltExpression { value: BoltExpression, } -node BoltMatchArm { +node BoltMatchArm > BoltSyntax { pattern: BoltPattern, body: BoltExpression, } @@ -203,7 +198,7 @@ node BoltMatchExpression > BoltExpression { arms: Vec, } -node BoltCase { +node BoltCase > BoltSyntax { test: BoltExpression, result: BoltExpression, } @@ -220,13 +215,13 @@ node BoltConstantExpression > BoltExpression { value: BoltValue, } -node BoltStatement > BoltFunctionBodyElement, BoltSourceElement; +node BoltStatement > BoltSyntax, BoltFunctionBodyElement, BoltSourceElement; node BoltReturnStatement > BoltStatement { value: Option, } -node BoltConditionalCase { +node BoltConditionalCase > BoltSyntax { test: Option, body: Vec, } @@ -243,31 +238,33 @@ node BoltExpressionStatement > BoltStatement { expression: BoltExpression, } -node BoltParameter { +node BoltParameter > BoltSyntax { index: usize, bindings: BoltPattern, typeExpr: Option, defaultValue: Option, } -node BoltDeclaration > BoltSourceElement; +node BoltDeclaration > BoltSyntax, BoltSourceElement; -node BoltTypeDeclaration > BoltSourceElement; +node BoltTypeDeclaration > BoltSyntax, BoltSourceElement; enum BoltModifiers { IsMutable = 0x1, IsPublic = 0x2, } -node BoltModule > BoltSourceElement { +node BoltModule > BoltSyntax, BoltSourceElement { modifiers: BoltModifiers, name: Vec, elements: Vec, } +node BoltDeclarationLike; + node BoltFunctionBodyElement; -node BoltFunctionDeclaration > BoltFunctionBodyElement, BoltDeclaration { +node BoltFunctionDeclaration > BoltFunctionBodyElement, BoltDeclaration, BoltDeclarationLike { modifiers: BoltModifiers, target: String, name: BoltSymbol, @@ -277,14 +274,14 @@ node BoltFunctionDeclaration > BoltFunctionBodyElement, BoltDeclaration { body: Vec, } -node BoltVariableDeclaration > BoltFunctionBodyElement, BoltDeclaration { +node BoltVariableDeclaration > BoltFunctionBodyElement, BoltDeclaration, BoltDeclarationLike { modifiers: BoltModifiers, bindings: BoltPattern, typeExpr: Option, value: Option, } -node BoltImportSymbol; +node BoltImportSymbol > BoltSyntax; node BoltPlainImportSymbol > BoltImportSymbol { remote: BoltQualName, @@ -294,10 +291,10 @@ node BoltPlainImportSymbol > BoltImportSymbol { node BoltImportDirective > BoltSourceElement { modifiers: BoltModifiers, file: BoltStringLiteral, - symbols: Vec, + symbols: Option>, } -node BoltExportSymbol; +node BoltExportSymbol > BoltSyntax; node BoltPlainExportSymbol { local: BoltQualName, @@ -309,14 +306,14 @@ node BoltExportDirective > BoltSourceElement { symbols: Option>, } -node BoltTraitDeclaration > BoltDeclaration, BoltTypeDeclaration { +node BoltTraitDeclaration > BoltDeclarationLike, BoltTypeDeclaration { modifiers: BoltModifiers, name: BoltIdentifier, typeParams: Option>, elements: Vec, } -node BoltImplDeclaration > BoltDeclaration { +node BoltImplDeclaration > BoltTypeDeclaration, BoltDeclarationLike { modifiers: BoltModifiers, name: BoltIdentifier, trait: BoltTypeExpression, @@ -324,21 +321,21 @@ node BoltImplDeclaration > BoltDeclaration { elements: Vec, } -node BoltTypeAliasDeclaration > BoltDeclaration, BoltTypeDeclaration { +node BoltTypeAliasDeclaration > BoltDeclarationLike, BoltTypeDeclaration { modifiers: BoltModifiers, name: BoltIdentifier, typeParams: Option>, typeExpr: BoltTypeExpression, } -node BoltRecordMember; +node BoltRecordMember > BoltSyntax; node BoltRecordField > BoltRecordMember { name: BoltIdentifier, typeExpr: BoltTypeExpression, } -node BoltRecordDeclaration > BoltDeclaration, BoltTypeDeclaration { +node BoltRecordDeclaration > BoltDeclaration, BoltTypeDeclaration, BoltDeclarationLike { modifiers: BoltModifiers, name: BoltIdentifier, typeParms: Option>, @@ -354,9 +351,9 @@ node BoltMacroCall > BoltRecordMember, BoltStatement, BoltDeclaration, BoltExpre // JavaScript AST definitions -type JSValue = Int | String | Bool | Void; +node JSSyntax; -node JSToken > Token; +node JSToken > JSSyntax, Token; node JSOperator > JSToken { text: String, @@ -388,6 +385,8 @@ node JSFunctionKeyword > JSToken; node JSWhileKeyword > JSToken; node JSForKeyword > JSToken; +node JSOperator; + node JSCloseBrace > JSToken; node JSCloseBracket > JSToken; node JSCloseParen > JSToken; @@ -398,25 +397,25 @@ node JSSemi > JSToken; node JSComma > JSToken; node JSDot > JSToken; node JSDotDotDot > JSToken; -node JSMulOp > JSToken; -node JSAddOp > JSToken; -node JSDivOp > JSToken; -node JSSubOp > JSToken; -node JSLtOp > JSToken; -node JSGtOp > JSToken; -node JSBOrOp > JSToken; -node JSBXorOp > JSToken; -node JSBAndOp > JSToken; -node JSBNotOp > JSToken; -node JSNotOp > JSToken; +node JSMulOp > JSToken, JSOperator; +node JSAddOp > JSToken, JSOperator; +node JSDivOp > JSToken, JSOperator; +node JSSubOp > JSToken, JSOperator; +node JSLtOp > JSToken, JSOperator; +node JSGtOp > JSToken, JSOperator; +node JSBOrOp > JSToken, JSOperator; +node JSBXorOp > JSToken, JSOperator; +node JSBAndOp > JSToken, JSOperator; +node JSBNotOp > JSToken, JSOperator; +node JSNotOp > JSToken, JSOperator; -node JSPattern; +node JSPattern > JSSyntax; node JSBindPattern > JSPattern { name: JSIdentifier, } -node JSExpression; +node JSExpression > JSSyntax; node JSConstantExpression > JSExpression { value: BoltValue, @@ -458,8 +457,6 @@ node JSConditionalExpression > JSExpression { alternate: JSExpression, } -type JSValue = Int - node JSLiteralExpression > JSExpression { value: JSValue, } @@ -474,12 +471,12 @@ node JSFunctionBodyElement; node JSStatement > JSSourceElement, JSFunctionBodyElement; -node JSCatchBlock { +node JSCatchBlock > JSSyntax { bindings: Option, elements: Vec, } -node JSTryCatchStatement { +node JSTryCatchStatement > JSSyntax { tryBlock: Vec, catchBlock: Option, finalBlock: Option>, @@ -489,7 +486,7 @@ node JSExpressionStatement > JSStatement { expression: JSExpression, } -node JSConditionalCase { +node JSConditionalCase > JSSyntax { test: Option, body: Vec, } @@ -502,19 +499,19 @@ node JSReturnStatement > JSStatement { value: Option, } -node JSParameter { +node JSParameter > JSSyntax { index: usize, bindings: JSPattern, defaultValue: Option, } -node JSDeclaration > JSSourceElement; +node JSDeclaration > JSSyntax, JSSourceElement; enum JSDeclarationModifiers { IsExported = 0x1, } -node JSImportBinding; +node JSImportBinding > JSSyntax; node JSImportStarBinding > JSImportBinding { local: JSIdentifier, @@ -548,7 +545,6 @@ node JSLetDeclaration > JSDeclaration, JSFunctionBodyElement { value: Option, } -node JSSourceFile > SourceFile { +node JSSourceFile > JSSyntax, SourceFile { elements: Vec, -} - +} \ No newline at end of file diff --git a/src/ast.d.ts b/src/ast.d.ts index 09284b669..6c636a2e8 100644 --- a/src/ast.d.ts +++ b/src/ast.d.ts @@ -1,5 +1,6 @@ import { Type } from "./types" +import { Diagnostic } from "./diagnostics" import { Package } from "./common" import { TextSpan } from "./text" @@ -13,7 +14,7 @@ interface SyntaxBase { id: number; kind: SyntaxKind; type?: Type; - errors: CompileError[] + errors: Diagnostic[] parentNode: Syntax | null; span: TextSpan | null; visit(visitors: NodeVisitor[]): void; @@ -74,7 +75,7 @@ export class NodeVisitor { protected visitBoltBracketed?(node: BoltBracketed): void; protected visitBoltSourceFile?(node: BoltSourceFile): void; protected visitBoltQualName?(node: BoltQualName): void; - protected visitBoltModulePath?(node: BoltModulePath): void; + protected visitBoltTypeOfExpression?(node: BoltTypeOfExpression): void; protected visitBoltReferenceTypeExpression?(node: BoltReferenceTypeExpression): void; protected visitBoltFunctionTypeExpression?(node: BoltFunctionTypeExpression): void; protected visitBoltLiftedTypeExpression?(node: BoltLiftedTypeExpression): void; @@ -119,7 +120,6 @@ export class NodeVisitor { protected visitBoltRecordField?(node: BoltRecordField): void; protected visitBoltRecordDeclaration?(node: BoltRecordDeclaration): void; protected visitBoltMacroCall?(node: BoltMacroCall): void; - protected visitJSOperator?(node: JSOperator): void; protected visitJSIdentifier?(node: JSIdentifier): void; protected visitJSString?(node: JSString): void; protected visitJSInteger?(node: JSInteger): void; @@ -186,114 +186,113 @@ export class NodeVisitor { export const enum SyntaxKind { - EndOfFile = 2, - FunctionBody = 6, - BoltStringLiteral = 8, - BoltIntegerLiteral = 9, - BoltIdentifier = 11, - BoltOperator = 13, - BoltAssignment = 14, - BoltComma = 15, - BoltSemi = 16, - BoltColon = 17, - BoltColonColon = 18, - BoltDot = 19, - BoltDotDot = 20, - BoltRArrow = 21, - BoltRArrowAlt = 22, - BoltLArrow = 23, - BoltEqSign = 24, - BoltGtSign = 25, - BoltExMark = 26, - BoltLtSign = 27, - BoltVBar = 28, - BoltWhereKeyword = 30, - BoltQuoteKeyword = 31, - BoltFnKeyword = 32, - BoltForeignKeyword = 33, - BoltForKeyword = 34, - BoltLetKeyword = 35, - BoltReturnKeyword = 36, - BoltLoopKeyword = 37, - BoltYieldKeyword = 38, - BoltMatchKeyword = 39, - BoltImportKeyword = 40, - BoltExportKeyword = 41, - BoltPubKeyword = 42, - BoltModKeyword = 43, - BoltMutKeyword = 44, - BoltEnumKeyword = 45, - BoltStructKeyword = 46, - BoltTypeKeyword = 47, - BoltTraitKeyword = 48, - BoltImplKeyword = 49, - BoltParenthesized = 51, - BoltBraced = 52, - BoltBracketed = 53, - BoltSourceFile = 54, - BoltQualName = 55, - BoltModulePath = 56, - BoltReferenceTypeExpression = 58, - BoltFunctionTypeExpression = 59, - BoltLiftedTypeExpression = 60, - BoltTypeParameter = 61, - BoltBindPattern = 63, - BoltTypePattern = 64, - BoltExpressionPattern = 65, - BoltTuplePatternElement = 66, - BoltTuplePattern = 67, - BoltRecordFieldPattern = 68, - BoltRecordPattern = 69, - BoltQuoteExpression = 71, - BoltTupleExpression = 72, - BoltReferenceExpression = 73, - BoltMemberExpression = 74, - BoltFunctionExpression = 75, - BoltCallExpression = 76, - BoltYieldExpression = 77, - BoltMatchArm = 78, - BoltMatchExpression = 79, - BoltCase = 80, - BoltCaseExpression = 81, - BoltBlockExpression = 82, - BoltConstantExpression = 83, - BoltReturnStatement = 85, - BoltConditionalCase = 86, - BoltConditionalStatement = 87, - BoltResumeStatement = 88, - BoltExpressionStatement = 89, - BoltParameter = 90, - BoltModule = 94, - BoltFunctionDeclaration = 96, - BoltVariableDeclaration = 97, - BoltPlainImportSymbol = 99, - BoltImportDirective = 100, - BoltExportSymbol = 101, - BoltPlainExportSymbol = 102, - BoltExportDirective = 103, - BoltTraitDeclaration = 104, - BoltImplDeclaration = 105, - BoltTypeAliasDeclaration = 106, - BoltRecordField = 108, - BoltRecordDeclaration = 109, - BoltMacroCall = 111, - JSOperator = 114, - JSIdentifier = 115, - JSString = 116, - JSInteger = 117, - JSFromKeyword = 118, - JSReturnKeyword = 119, - JSTryKeyword = 120, - JSFinallyKeyword = 121, - JSCatchKeyword = 122, - JSImportKeyword = 123, - JSAsKeyword = 124, - JSConstKeyword = 125, - JSLetKeyword = 126, - JSExportKeyword = 127, - JSFunctionKeyword = 128, - JSWhileKeyword = 129, - JSForKeyword = 130, + EndOfFile = 0, + FunctionBody = 3, + BoltStringLiteral = 6, + BoltIntegerLiteral = 7, + BoltIdentifier = 9, + BoltOperator = 11, + BoltAssignment = 12, + BoltComma = 13, + BoltSemi = 14, + BoltColon = 15, + BoltColonColon = 16, + BoltDot = 17, + BoltDotDot = 18, + BoltRArrow = 19, + BoltRArrowAlt = 20, + BoltLArrow = 21, + BoltEqSign = 22, + BoltGtSign = 23, + BoltExMark = 24, + BoltLtSign = 25, + BoltVBar = 26, + BoltWhereKeyword = 28, + BoltQuoteKeyword = 29, + BoltFnKeyword = 30, + BoltForeignKeyword = 31, + BoltForKeyword = 32, + BoltLetKeyword = 33, + BoltReturnKeyword = 34, + BoltLoopKeyword = 35, + BoltYieldKeyword = 36, + BoltMatchKeyword = 37, + BoltImportKeyword = 38, + BoltExportKeyword = 39, + BoltPubKeyword = 40, + BoltModKeyword = 41, + BoltMutKeyword = 42, + BoltEnumKeyword = 43, + BoltStructKeyword = 44, + BoltTypeKeyword = 45, + BoltTraitKeyword = 46, + BoltImplKeyword = 47, + BoltParenthesized = 49, + BoltBraced = 50, + BoltBracketed = 51, + BoltSourceFile = 52, + BoltQualName = 53, + BoltTypeOfExpression = 55, + BoltReferenceTypeExpression = 56, + BoltFunctionTypeExpression = 57, + BoltLiftedTypeExpression = 58, + BoltTypeParameter = 59, + BoltBindPattern = 61, + BoltTypePattern = 62, + BoltExpressionPattern = 63, + BoltTuplePatternElement = 64, + BoltTuplePattern = 65, + BoltRecordFieldPattern = 66, + BoltRecordPattern = 67, + BoltQuoteExpression = 69, + BoltTupleExpression = 70, + BoltReferenceExpression = 71, + BoltMemberExpression = 72, + BoltFunctionExpression = 73, + BoltCallExpression = 74, + BoltYieldExpression = 75, + BoltMatchArm = 76, + BoltMatchExpression = 77, + BoltCase = 78, + BoltCaseExpression = 79, + BoltBlockExpression = 80, + BoltConstantExpression = 81, + BoltReturnStatement = 83, + BoltConditionalCase = 84, + BoltConditionalStatement = 85, + BoltResumeStatement = 86, + BoltExpressionStatement = 87, + BoltParameter = 88, + BoltModule = 92, + BoltFunctionDeclaration = 95, + BoltVariableDeclaration = 96, + BoltPlainImportSymbol = 98, + BoltImportDirective = 99, + BoltExportSymbol = 100, + BoltPlainExportSymbol = 101, + BoltExportDirective = 102, + BoltTraitDeclaration = 103, + BoltImplDeclaration = 104, + BoltTypeAliasDeclaration = 105, + BoltRecordField = 107, + BoltRecordDeclaration = 108, + BoltMacroCall = 110, + JSIdentifier = 114, + JSString = 115, + JSInteger = 116, + JSFromKeyword = 117, + JSReturnKeyword = 118, + JSTryKeyword = 119, + JSFinallyKeyword = 120, + JSCatchKeyword = 121, + JSImportKeyword = 122, + JSAsKeyword = 123, + JSConstKeyword = 124, + JSLetKeyword = 125, + JSExportKeyword = 126, + JSFunctionKeyword = 127, + JSWhileKeyword = 128, + JSForKeyword = 129, JSCloseBrace = 131, JSCloseBracket = 132, JSCloseParen = 133, @@ -324,22 +323,22 @@ export const enum SyntaxKind { JSNewExpression = 160, JSSequenceExpression = 161, JSConditionalExpression = 162, - JSLiteralExpression = 164, - JSReferenceExpression = 165, - JSCatchBlock = 169, - JSTryCatchStatement = 170, - JSExpressionStatement = 171, - JSConditionalCase = 172, - JSConditionalStatement = 173, - JSReturnStatement = 174, - JSParameter = 175, - JSImportStarBinding = 179, - JSImportAsBinding = 180, - JSImportDeclaration = 181, - JSFunctionDeclaration = 182, - JSArrowFunctionDeclaration = 183, - JSLetDeclaration = 184, - JSSourceFile = 185, + JSLiteralExpression = 163, + JSReferenceExpression = 164, + JSCatchBlock = 168, + JSTryCatchStatement = 169, + JSExpressionStatement = 170, + JSConditionalCase = 171, + JSConditionalStatement = 172, + JSReturnStatement = 173, + JSParameter = 174, + JSImportStarBinding = 178, + JSImportAsBinding = 179, + JSImportDeclaration = 180, + JSFunctionDeclaration = 181, + JSArrowFunctionDeclaration = 182, + JSLetDeclaration = 183, + JSSourceFile = 184, } export interface EndOfFile extends SyntaxBase { @@ -354,6 +353,7 @@ export type EndOfFileParent export type EndOfFileAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -393,7 +393,6 @@ export type EndOfFileChild export type Token = EndOfFile - | JSOperator | JSIdentifier | JSString | JSInteger @@ -495,6 +494,96 @@ export type FunctionBodyAnyParent export type FunctionBodyChild = never +export type BoltSyntax + = BoltSourceFile + | BoltQualName + | BoltTypeParameter + | BoltTuplePatternElement + | BoltRecordFieldPattern + | BoltMatchArm + | BoltCase + | BoltConditionalCase + | BoltParameter + | BoltModule + | BoltExportSymbol + | BoltRecordField + | BoltMacroCall + | BoltPlainImportSymbol + | BoltTraitDeclaration + | BoltImplDeclaration + | BoltTypeAliasDeclaration + | BoltRecordDeclaration + | BoltFunctionDeclaration + | BoltVariableDeclaration + | BoltReturnStatement + | BoltConditionalStatement + | BoltResumeStatement + | BoltExpressionStatement + | BoltQuoteExpression + | BoltTupleExpression + | BoltReferenceExpression + | BoltMemberExpression + | BoltFunctionExpression + | BoltCallExpression + | BoltYieldExpression + | BoltMatchExpression + | BoltCaseExpression + | BoltBlockExpression + | BoltConstantExpression + | BoltBindPattern + | BoltTypePattern + | BoltExpressionPattern + | BoltTuplePattern + | BoltRecordPattern + | BoltTypeOfExpression + | BoltReferenceTypeExpression + | BoltFunctionTypeExpression + | BoltLiftedTypeExpression + | EndOfFile + | BoltStringLiteral + | BoltIntegerLiteral + | BoltAssignment + | BoltComma + | BoltSemi + | BoltColon + | BoltColonColon + | BoltDot + | BoltDotDot + | BoltRArrow + | BoltRArrowAlt + | BoltLArrow + | BoltEqSign + | BoltGtSign + | BoltExMark + | BoltLtSign + | BoltVBar + | BoltWhereKeyword + | BoltQuoteKeyword + | BoltFnKeyword + | BoltForeignKeyword + | BoltForKeyword + | BoltLetKeyword + | BoltReturnKeyword + | BoltLoopKeyword + | BoltYieldKeyword + | BoltMatchKeyword + | BoltImportKeyword + | BoltExportKeyword + | BoltPubKeyword + | BoltModKeyword + | BoltMutKeyword + | BoltEnumKeyword + | BoltStructKeyword + | BoltTypeKeyword + | BoltTraitKeyword + | BoltImplKeyword + | BoltParenthesized + | BoltBraced + | BoltBracketed + | BoltIdentifier + | BoltOperator + + export type BoltToken = EndOfFile | BoltStringLiteral @@ -554,6 +643,7 @@ export type BoltStringLiteralParent export type BoltStringLiteralAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -604,6 +694,7 @@ export type BoltIntegerLiteralParent export type BoltIntegerLiteralAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -679,6 +770,7 @@ export type BoltIdentifierAnyParent | BoltConditionalCase | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -744,6 +836,7 @@ export type BoltOperatorAnyParent | BoltConditionalCase | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -786,6 +879,7 @@ export type BoltAssignmentParent export type BoltAssignmentAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -835,6 +929,7 @@ export type BoltCommaParent export type BoltCommaAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -884,6 +979,7 @@ export type BoltSemiParent export type BoltSemiAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -933,6 +1029,7 @@ export type BoltColonParent export type BoltColonAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -982,6 +1079,7 @@ export type BoltColonColonParent export type BoltColonColonAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1031,6 +1129,7 @@ export type BoltDotParent export type BoltDotAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1080,6 +1179,7 @@ export type BoltDotDotParent export type BoltDotDotAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1129,6 +1229,7 @@ export type BoltRArrowParent export type BoltRArrowAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1178,6 +1279,7 @@ export type BoltRArrowAltParent export type BoltRArrowAltAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1227,6 +1329,7 @@ export type BoltLArrowParent export type BoltLArrowAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1276,6 +1379,7 @@ export type BoltEqSignParent export type BoltEqSignAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1341,6 +1445,7 @@ export type BoltGtSignAnyParent | BoltConditionalCase | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1398,6 +1503,7 @@ export type BoltExMarkAnyParent | BoltConditionalCase | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1455,6 +1561,7 @@ export type BoltLtSignAnyParent | BoltConditionalCase | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1512,6 +1619,7 @@ export type BoltVBarAnyParent | BoltConditionalCase | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1576,6 +1684,7 @@ export type BoltWhereKeywordParent export type BoltWhereKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1625,6 +1734,7 @@ export type BoltQuoteKeywordParent export type BoltQuoteKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1674,6 +1784,7 @@ export type BoltFnKeywordParent export type BoltFnKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1723,6 +1834,7 @@ export type BoltForeignKeywordParent export type BoltForeignKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1772,6 +1884,7 @@ export type BoltForKeywordParent export type BoltForKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1821,6 +1934,7 @@ export type BoltLetKeywordParent export type BoltLetKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1870,6 +1984,7 @@ export type BoltReturnKeywordParent export type BoltReturnKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1919,6 +2034,7 @@ export type BoltLoopKeywordParent export type BoltLoopKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -1968,6 +2084,7 @@ export type BoltYieldKeywordParent export type BoltYieldKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2017,6 +2134,7 @@ export type BoltMatchKeywordParent export type BoltMatchKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2066,6 +2184,7 @@ export type BoltImportKeywordParent export type BoltImportKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2115,6 +2234,7 @@ export type BoltExportKeywordParent export type BoltExportKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2164,6 +2284,7 @@ export type BoltPubKeywordParent export type BoltPubKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2213,6 +2334,7 @@ export type BoltModKeywordParent export type BoltModKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2262,6 +2384,7 @@ export type BoltMutKeywordParent export type BoltMutKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2311,6 +2434,7 @@ export type BoltEnumKeywordParent export type BoltEnumKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2360,6 +2484,7 @@ export type BoltStructKeywordParent export type BoltStructKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2409,6 +2534,7 @@ export type BoltTypeKeywordParent export type BoltTypeKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2458,6 +2584,7 @@ export type BoltTraitKeywordParent export type BoltTraitKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2507,6 +2634,7 @@ export type BoltImplKeywordParent export type BoltImplKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2563,6 +2691,7 @@ export type BoltParenthesizedParent export type BoltParenthesizedAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2613,6 +2742,7 @@ export type BoltBracedParent export type BoltBracedAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2663,6 +2793,7 @@ export type BoltBracketedParent export type BoltBracketedAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2735,29 +2866,73 @@ export type BoltQualNameAnyParent export type BoltQualNameChild = never -export interface BoltModulePath extends SyntaxBase { - kind: SyntaxKind.BoltModulePath; - isAbsolute: boolean; - elements: BoltIdentifier[]; - parentNode: BoltModulePathParent; - getChildNodes(): IterableIterator -} - -export type BoltModulePathParent -= never - -export type BoltModulePathAnyParent -= never - -export type BoltModulePathChild -= never - export type BoltTypeExpression - = BoltReferenceTypeExpression + = BoltTypeOfExpression + | BoltReferenceTypeExpression | BoltFunctionTypeExpression | BoltLiftedTypeExpression +export interface BoltTypeOfExpression extends SyntaxBase { + kind: SyntaxKind.BoltTypeOfExpression; + expression: BoltExpression; + parentNode: BoltTypeOfExpressionParent; + getChildNodes(): IterableIterator +} + +export type BoltTypeOfExpressionParent += BoltReferenceTypeExpression +| BoltFunctionTypeExpression +| BoltTypeParameter +| BoltTypePattern +| BoltRecordPattern +| BoltFunctionExpression +| BoltParameter +| BoltFunctionDeclaration +| BoltVariableDeclaration +| BoltImplDeclaration +| BoltTypeAliasDeclaration +| BoltRecordField +| never + +export type BoltTypeOfExpressionAnyParent += BoltReferenceTypeExpression +| BoltFunctionTypeExpression +| BoltTypeParameter +| BoltTypePattern +| BoltRecordPattern +| BoltFunctionExpression +| BoltParameter +| BoltFunctionDeclaration +| BoltVariableDeclaration +| BoltImplDeclaration +| BoltTypeAliasDeclaration +| BoltRecordField +| BoltRecordDeclaration +| BoltSourceFile +| BoltModule +| BoltTraitDeclaration +| BoltBlockExpression +| BoltConditionalCase +| BoltLiftedTypeExpression +| BoltExpressionPattern +| BoltTupleExpression +| BoltMemberExpression +| BoltCallExpression +| BoltYieldExpression +| BoltMatchArm +| BoltMatchExpression +| BoltCase +| BoltReturnStatement +| BoltResumeStatement +| BoltExpressionStatement +| BoltTuplePatternElement +| BoltRecordFieldPattern +| never + +export type BoltTypeOfExpressionChild += never + export interface BoltReferenceTypeExpression extends SyntaxBase { kind: SyntaxKind.BoltReferenceTypeExpression; name: BoltQualName; @@ -2799,6 +2974,7 @@ export type BoltReferenceTypeExpressionAnyParent | BoltTraitDeclaration | BoltBlockExpression | BoltConditionalCase +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2859,6 +3035,7 @@ export type BoltFunctionTypeExpressionAnyParent | BoltTraitDeclaration | BoltBlockExpression | BoltConditionalCase +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -2919,6 +3096,7 @@ export type BoltLiftedTypeExpressionAnyParent | BoltTraitDeclaration | BoltBlockExpression | BoltConditionalCase +| BoltTypeOfExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -2995,6 +3173,7 @@ export type BoltBindPatternAnyParent | BoltFunctionDeclaration | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -3049,6 +3228,7 @@ export type BoltTypePatternAnyParent | BoltFunctionDeclaration | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -3103,6 +3283,7 @@ export type BoltExpressionPatternAnyParent | BoltFunctionDeclaration | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltTupleExpression | BoltMemberExpression @@ -3173,6 +3354,7 @@ export type BoltTuplePatternAnyParent | BoltFunctionDeclaration | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -3246,6 +3428,7 @@ export type BoltRecordPatternAnyParent | BoltFunctionDeclaration | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -3291,7 +3474,8 @@ export interface BoltQuoteExpression extends SyntaxBase { } export type BoltQuoteExpressionParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3309,7 +3493,8 @@ export type BoltQuoteExpressionParent | never export type BoltQuoteExpressionAnyParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3354,7 +3539,8 @@ export interface BoltTupleExpression extends SyntaxBase { } export type BoltTupleExpressionParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3372,7 +3558,8 @@ export type BoltTupleExpressionParent | never export type BoltTupleExpressionAnyParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltMemberExpression | BoltCallExpression @@ -3416,7 +3603,8 @@ export interface BoltReferenceExpression extends SyntaxBase { } export type BoltReferenceExpressionParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3434,7 +3622,8 @@ export type BoltReferenceExpressionParent | never export type BoltReferenceExpressionAnyParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3480,7 +3669,8 @@ export interface BoltMemberExpression extends SyntaxBase { } export type BoltMemberExpressionParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3498,7 +3688,8 @@ export type BoltMemberExpressionParent | never export type BoltMemberExpressionAnyParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltCallExpression @@ -3544,7 +3735,8 @@ export interface BoltFunctionExpression extends SyntaxBase { } export type BoltFunctionExpressionParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3562,7 +3754,8 @@ export type BoltFunctionExpressionParent | never export type BoltFunctionExpressionAnyParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3607,7 +3800,8 @@ export interface BoltCallExpression extends SyntaxBase { } export type BoltCallExpressionParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3625,7 +3819,8 @@ export type BoltCallExpressionParent | never export type BoltCallExpressionAnyParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3669,7 +3864,8 @@ export interface BoltYieldExpression extends SyntaxBase { } export type BoltYieldExpressionParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3687,7 +3883,8 @@ export type BoltYieldExpressionParent | never export type BoltYieldExpressionAnyParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3749,7 +3946,8 @@ export interface BoltMatchExpression extends SyntaxBase { } export type BoltMatchExpressionParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3767,7 +3965,8 @@ export type BoltMatchExpressionParent | never export type BoltMatchExpressionAnyParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3828,7 +4027,8 @@ export interface BoltCaseExpression extends SyntaxBase { } export type BoltCaseExpressionParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3846,7 +4046,8 @@ export type BoltCaseExpressionParent | never export type BoltCaseExpressionAnyParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3891,7 +4092,8 @@ export interface BoltBlockExpression extends SyntaxBase { } export type BoltBlockExpressionParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3909,7 +4111,8 @@ export type BoltBlockExpressionParent | never export type BoltBlockExpressionAnyParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3953,7 +4156,8 @@ export interface BoltConstantExpression extends SyntaxBase { } export type BoltConstantExpressionParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -3971,7 +4175,8 @@ export type BoltConstantExpressionParent | never export type BoltConstantExpressionAnyParent -= BoltLiftedTypeExpression += BoltTypeOfExpression +| BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression | BoltMemberExpression @@ -4041,6 +4246,7 @@ export type BoltReturnStatementAnyParent | BoltFunctionDeclaration | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -4111,6 +4317,7 @@ export type BoltConditionalStatementAnyParent | BoltFunctionDeclaration | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -4165,6 +4372,7 @@ export type BoltResumeStatementAnyParent | BoltFunctionDeclaration | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -4218,6 +4426,7 @@ export type BoltExpressionStatementAnyParent | BoltFunctionDeclaration | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -4268,15 +4477,13 @@ export type BoltParameterChild export type BoltDeclaration = BoltFunctionDeclaration | BoltVariableDeclaration - | BoltTraitDeclaration - | BoltImplDeclaration - | BoltTypeAliasDeclaration | BoltRecordDeclaration | BoltMacroCall export type BoltTypeDeclaration = BoltTraitDeclaration + | BoltImplDeclaration | BoltTypeAliasDeclaration | BoltRecordDeclaration @@ -4305,6 +4512,15 @@ export type BoltModuleAnyParent export type BoltModuleChild = never +export type BoltDeclarationLike + = BoltFunctionDeclaration + | BoltVariableDeclaration + | BoltTraitDeclaration + | BoltImplDeclaration + | BoltTypeAliasDeclaration + | BoltRecordDeclaration + + export type BoltFunctionBodyElement = BoltFunctionDeclaration | BoltVariableDeclaration @@ -4347,6 +4563,7 @@ export type BoltFunctionDeclarationAnyParent | BoltModule | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -4406,6 +4623,7 @@ export type BoltVariableDeclarationAnyParent | BoltFunctionDeclaration | BoltTraitDeclaration | BoltImplDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -4463,7 +4681,7 @@ export interface BoltImportDirective extends SyntaxBase { kind: SyntaxKind.BoltImportDirective; modifiers: BoltModifiers; file: BoltStringLiteral; - symbols: BoltImportSymbol[]; + symbols: BoltImportSymbol[] | null; parentNode: BoltImportDirectiveParent; getChildNodes(): IterableIterator } @@ -4547,14 +4765,11 @@ export interface BoltTraitDeclaration extends SyntaxBase { export type BoltTraitDeclarationParent = BoltSourceFile | BoltModule -| BoltTraitDeclaration -| BoltImplDeclaration | never export type BoltTraitDeclarationAnyParent = BoltSourceFile | BoltModule -| BoltImplDeclaration | never export type BoltTraitDeclarationChild @@ -4574,14 +4789,11 @@ export interface BoltImplDeclaration extends SyntaxBase { export type BoltImplDeclarationParent = BoltSourceFile | BoltModule -| BoltTraitDeclaration -| BoltImplDeclaration | never export type BoltImplDeclarationAnyParent = BoltSourceFile | BoltModule -| BoltTraitDeclaration | never export type BoltImplDeclarationChild @@ -4600,15 +4812,11 @@ export interface BoltTypeAliasDeclaration extends SyntaxBase { export type BoltTypeAliasDeclarationParent = BoltSourceFile | BoltModule -| BoltTraitDeclaration -| BoltImplDeclaration | never export type BoltTypeAliasDeclarationAnyParent = BoltSourceFile | BoltModule -| BoltTraitDeclaration -| BoltImplDeclaration | never export type BoltTypeAliasDeclarationChild @@ -4674,11 +4882,11 @@ export type BoltSourceElement | BoltImportDirective | BoltExportDirective | BoltTraitDeclaration + | BoltImplDeclaration | BoltTypeAliasDeclaration | BoltRecordDeclaration | BoltFunctionDeclaration | BoltVariableDeclaration - | BoltImplDeclaration | BoltMacroCall | BoltReturnStatement | BoltConditionalStatement @@ -4696,6 +4904,7 @@ export interface BoltMacroCall extends SyntaxBase { export type BoltMacroCallParent = BoltSourceFile +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -4722,6 +4931,7 @@ export type BoltMacroCallParent export type BoltMacroCallAnyParent = BoltSourceFile +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -4758,9 +4968,30 @@ export type BoltMacroCallAnyParent export type BoltMacroCallChild = never -export type JSToken - = EndOfFile - | JSOperator +export type JSSyntax + = JSCatchBlock + | JSTryCatchStatement + | JSConditionalCase + | JSParameter + | JSSourceFile + | JSImportStarBinding + | JSImportAsBinding + | JSImportDeclaration + | JSFunctionDeclaration + | JSArrowFunctionDeclaration + | JSLetDeclaration + | JSConstantExpression + | JSMemberExpression + | JSCallExpression + | JSBinaryExpression + | JSUnaryExpression + | JSNewExpression + | JSSequenceExpression + | JSConditionalExpression + | JSLiteralExpression + | JSReferenceExpression + | JSBindPattern + | EndOfFile | JSIdentifier | JSString | JSInteger @@ -4800,55 +5031,60 @@ export type JSToken | JSNotOp -export interface JSOperator extends SyntaxBase { - kind: SyntaxKind.JSOperator; - text: string; - parentNode: JSOperatorParent; - getChildNodes(): IterableIterator -} +export type JSToken + = EndOfFile + | JSIdentifier + | JSString + | JSInteger + | JSFromKeyword + | JSReturnKeyword + | JSTryKeyword + | JSFinallyKeyword + | JSCatchKeyword + | JSImportKeyword + | JSAsKeyword + | JSConstKeyword + | JSLetKeyword + | JSExportKeyword + | JSFunctionKeyword + | JSWhileKeyword + | JSForKeyword + | JSCloseBrace + | JSCloseBracket + | JSCloseParen + | JSOpenBrace + | JSOpenBracket + | JSOpenParen + | JSSemi + | JSComma + | JSDot + | JSDotDotDot + | JSMulOp + | JSAddOp + | JSDivOp + | JSSubOp + | JSLtOp + | JSGtOp + | JSBOrOp + | JSBXorOp + | JSBAndOp + | JSBNotOp + | JSNotOp -export type JSOperatorParent -= BoltQuoteExpression -| never -export type JSOperatorAnyParent -= BoltQuoteExpression -| BoltLiftedTypeExpression -| BoltExpressionPattern -| BoltTupleExpression -| BoltMemberExpression -| BoltCallExpression -| BoltYieldExpression -| BoltMatchArm -| BoltMatchExpression -| BoltCase -| BoltReturnStatement -| BoltConditionalCase -| BoltResumeStatement -| BoltExpressionStatement -| BoltParameter -| BoltVariableDeclaration -| BoltSourceFile -| BoltFunctionExpression -| BoltBlockExpression -| BoltModule -| BoltFunctionDeclaration -| BoltTraitDeclaration -| BoltImplDeclaration -| BoltTypePattern -| BoltTuplePatternElement -| BoltRecordFieldPattern -| BoltReferenceTypeExpression -| BoltFunctionTypeExpression -| BoltTypeParameter -| BoltRecordPattern -| BoltTypeAliasDeclaration -| BoltRecordField -| BoltRecordDeclaration -| never +export type JSOperator + = JSMulOp + | JSAddOp + | JSDivOp + | JSSubOp + | JSLtOp + | JSGtOp + | JSBOrOp + | JSBXorOp + | JSBAndOp + | JSBNotOp + | JSNotOp -export type JSOperatorChild -= never export interface JSIdentifier extends SyntaxBase { kind: SyntaxKind.JSIdentifier; @@ -4863,6 +5099,7 @@ export type JSIdentifierParent export type JSIdentifierAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -4913,6 +5150,7 @@ export type JSStringParent export type JSStringAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -4963,6 +5201,7 @@ export type JSIntegerParent export type JSIntegerAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5012,6 +5251,7 @@ export type JSFromKeywordParent export type JSFromKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5061,6 +5301,7 @@ export type JSReturnKeywordParent export type JSReturnKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5110,6 +5351,7 @@ export type JSTryKeywordParent export type JSTryKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5159,6 +5401,7 @@ export type JSFinallyKeywordParent export type JSFinallyKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5208,6 +5451,7 @@ export type JSCatchKeywordParent export type JSCatchKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5257,6 +5501,7 @@ export type JSImportKeywordParent export type JSImportKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5306,6 +5551,7 @@ export type JSAsKeywordParent export type JSAsKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5355,6 +5601,7 @@ export type JSConstKeywordParent export type JSConstKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5404,6 +5651,7 @@ export type JSLetKeywordParent export type JSLetKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5453,6 +5701,7 @@ export type JSExportKeywordParent export type JSExportKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5502,6 +5751,7 @@ export type JSFunctionKeywordParent export type JSFunctionKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5551,6 +5801,7 @@ export type JSWhileKeywordParent export type JSWhileKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5600,6 +5851,7 @@ export type JSForKeywordParent export type JSForKeywordAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5637,6 +5889,20 @@ export type JSForKeywordAnyParent export type JSForKeywordChild = never +export type JSOperator + = JSMulOp + | JSAddOp + | JSDivOp + | JSSubOp + | JSLtOp + | JSGtOp + | JSBOrOp + | JSBXorOp + | JSBAndOp + | JSBNotOp + | JSNotOp + + export interface JSCloseBrace extends SyntaxBase { kind: SyntaxKind.JSCloseBrace; parentNode: JSCloseBraceParent; @@ -5649,6 +5915,7 @@ export type JSCloseBraceParent export type JSCloseBraceAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5698,6 +5965,7 @@ export type JSCloseBracketParent export type JSCloseBracketAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5747,6 +6015,7 @@ export type JSCloseParenParent export type JSCloseParenAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5796,6 +6065,7 @@ export type JSOpenBraceParent export type JSOpenBraceAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5845,6 +6115,7 @@ export type JSOpenBracketParent export type JSOpenBracketAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5894,6 +6165,7 @@ export type JSOpenParenParent export type JSOpenParenAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5943,6 +6215,7 @@ export type JSSemiParent export type JSSemiAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -5992,6 +6265,7 @@ export type JSCommaParent export type JSCommaAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -6041,6 +6315,7 @@ export type JSDotParent export type JSDotAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -6090,6 +6365,7 @@ export type JSDotDotDotParent export type JSDotDotDotAnyParent = BoltQuoteExpression +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -6135,10 +6411,30 @@ export interface JSMulOp extends SyntaxBase { export type JSMulOpParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression | never export type JSMulOpAnyParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression +| JSMemberExpression +| JSCallExpression +| JSNewExpression +| JSSequenceExpression +| JSConditionalExpression +| JSExpressionStatement +| JSConditionalCase +| JSReturnStatement +| JSParameter +| JSArrowFunctionDeclaration +| JSLetDeclaration +| JSCatchBlock +| JSTryCatchStatement +| JSSourceFile +| JSFunctionDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -6184,10 +6480,30 @@ export interface JSAddOp extends SyntaxBase { export type JSAddOpParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression | never export type JSAddOpAnyParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression +| JSMemberExpression +| JSCallExpression +| JSNewExpression +| JSSequenceExpression +| JSConditionalExpression +| JSExpressionStatement +| JSConditionalCase +| JSReturnStatement +| JSParameter +| JSArrowFunctionDeclaration +| JSLetDeclaration +| JSCatchBlock +| JSTryCatchStatement +| JSSourceFile +| JSFunctionDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -6233,10 +6549,30 @@ export interface JSDivOp extends SyntaxBase { export type JSDivOpParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression | never export type JSDivOpAnyParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression +| JSMemberExpression +| JSCallExpression +| JSNewExpression +| JSSequenceExpression +| JSConditionalExpression +| JSExpressionStatement +| JSConditionalCase +| JSReturnStatement +| JSParameter +| JSArrowFunctionDeclaration +| JSLetDeclaration +| JSCatchBlock +| JSTryCatchStatement +| JSSourceFile +| JSFunctionDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -6282,10 +6618,30 @@ export interface JSSubOp extends SyntaxBase { export type JSSubOpParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression | never export type JSSubOpAnyParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression +| JSMemberExpression +| JSCallExpression +| JSNewExpression +| JSSequenceExpression +| JSConditionalExpression +| JSExpressionStatement +| JSConditionalCase +| JSReturnStatement +| JSParameter +| JSArrowFunctionDeclaration +| JSLetDeclaration +| JSCatchBlock +| JSTryCatchStatement +| JSSourceFile +| JSFunctionDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -6331,10 +6687,30 @@ export interface JSLtOp extends SyntaxBase { export type JSLtOpParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression | never export type JSLtOpAnyParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression +| JSMemberExpression +| JSCallExpression +| JSNewExpression +| JSSequenceExpression +| JSConditionalExpression +| JSExpressionStatement +| JSConditionalCase +| JSReturnStatement +| JSParameter +| JSArrowFunctionDeclaration +| JSLetDeclaration +| JSCatchBlock +| JSTryCatchStatement +| JSSourceFile +| JSFunctionDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -6380,10 +6756,30 @@ export interface JSGtOp extends SyntaxBase { export type JSGtOpParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression | never export type JSGtOpAnyParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression +| JSMemberExpression +| JSCallExpression +| JSNewExpression +| JSSequenceExpression +| JSConditionalExpression +| JSExpressionStatement +| JSConditionalCase +| JSReturnStatement +| JSParameter +| JSArrowFunctionDeclaration +| JSLetDeclaration +| JSCatchBlock +| JSTryCatchStatement +| JSSourceFile +| JSFunctionDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -6429,10 +6825,30 @@ export interface JSBOrOp extends SyntaxBase { export type JSBOrOpParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression | never export type JSBOrOpAnyParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression +| JSMemberExpression +| JSCallExpression +| JSNewExpression +| JSSequenceExpression +| JSConditionalExpression +| JSExpressionStatement +| JSConditionalCase +| JSReturnStatement +| JSParameter +| JSArrowFunctionDeclaration +| JSLetDeclaration +| JSCatchBlock +| JSTryCatchStatement +| JSSourceFile +| JSFunctionDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -6478,10 +6894,30 @@ export interface JSBXorOp extends SyntaxBase { export type JSBXorOpParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression | never export type JSBXorOpAnyParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression +| JSMemberExpression +| JSCallExpression +| JSNewExpression +| JSSequenceExpression +| JSConditionalExpression +| JSExpressionStatement +| JSConditionalCase +| JSReturnStatement +| JSParameter +| JSArrowFunctionDeclaration +| JSLetDeclaration +| JSCatchBlock +| JSTryCatchStatement +| JSSourceFile +| JSFunctionDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -6527,10 +6963,30 @@ export interface JSBAndOp extends SyntaxBase { export type JSBAndOpParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression | never export type JSBAndOpAnyParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression +| JSMemberExpression +| JSCallExpression +| JSNewExpression +| JSSequenceExpression +| JSConditionalExpression +| JSExpressionStatement +| JSConditionalCase +| JSReturnStatement +| JSParameter +| JSArrowFunctionDeclaration +| JSLetDeclaration +| JSCatchBlock +| JSTryCatchStatement +| JSSourceFile +| JSFunctionDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -6576,10 +7032,30 @@ export interface JSBNotOp extends SyntaxBase { export type JSBNotOpParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression | never export type JSBNotOpAnyParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression +| JSMemberExpression +| JSCallExpression +| JSNewExpression +| JSSequenceExpression +| JSConditionalExpression +| JSExpressionStatement +| JSConditionalCase +| JSReturnStatement +| JSParameter +| JSArrowFunctionDeclaration +| JSLetDeclaration +| JSCatchBlock +| JSTryCatchStatement +| JSSourceFile +| JSFunctionDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -6625,10 +7101,30 @@ export interface JSNotOp extends SyntaxBase { export type JSNotOpParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression | never export type JSNotOpAnyParent = BoltQuoteExpression +| JSBinaryExpression +| JSUnaryExpression +| JSMemberExpression +| JSCallExpression +| JSNewExpression +| JSSequenceExpression +| JSConditionalExpression +| JSExpressionStatement +| JSConditionalCase +| JSReturnStatement +| JSParameter +| JSArrowFunctionDeclaration +| JSLetDeclaration +| JSCatchBlock +| JSTryCatchStatement +| JSSourceFile +| JSFunctionDeclaration +| BoltTypeOfExpression | BoltLiftedTypeExpression | BoltExpressionPattern | BoltTupleExpression @@ -7517,164 +8013,6 @@ export type JSSourceFileAnyParent export type JSSourceFileChild = never -export type BoltSyntax - = BoltStringLiteral - | BoltIntegerLiteral - | BoltIdentifier - | BoltOperator - | BoltAssignment - | BoltComma - | BoltSemi - | BoltColon - | BoltColonColon - | BoltDot - | BoltDotDot - | BoltRArrow - | BoltRArrowAlt - | BoltLArrow - | BoltEqSign - | BoltGtSign - | BoltExMark - | BoltLtSign - | BoltVBar - | BoltWhereKeyword - | BoltQuoteKeyword - | BoltFnKeyword - | BoltForeignKeyword - | BoltForKeyword - | BoltLetKeyword - | BoltReturnKeyword - | BoltLoopKeyword - | BoltYieldKeyword - | BoltMatchKeyword - | BoltImportKeyword - | BoltExportKeyword - | BoltPubKeyword - | BoltModKeyword - | BoltMutKeyword - | BoltEnumKeyword - | BoltStructKeyword - | BoltTypeKeyword - | BoltTraitKeyword - | BoltImplKeyword - | BoltParenthesized - | BoltBraced - | BoltBracketed - | BoltSourceFile - | BoltQualName - | BoltModulePath - | BoltReferenceTypeExpression - | BoltFunctionTypeExpression - | BoltLiftedTypeExpression - | BoltTypeParameter - | BoltBindPattern - | BoltTypePattern - | BoltExpressionPattern - | BoltTuplePatternElement - | BoltTuplePattern - | BoltRecordFieldPattern - | BoltRecordPattern - | BoltQuoteExpression - | BoltTupleExpression - | BoltReferenceExpression - | BoltMemberExpression - | BoltFunctionExpression - | BoltCallExpression - | BoltYieldExpression - | BoltMatchArm - | BoltMatchExpression - | BoltCase - | BoltCaseExpression - | BoltBlockExpression - | BoltConstantExpression - | BoltReturnStatement - | BoltConditionalCase - | BoltConditionalStatement - | BoltResumeStatement - | BoltExpressionStatement - | BoltParameter - | BoltModule - | BoltFunctionDeclaration - | BoltVariableDeclaration - | BoltPlainImportSymbol - | BoltImportDirective - | BoltExportSymbol - | BoltPlainExportSymbol - | BoltExportDirective - | BoltTraitDeclaration - | BoltImplDeclaration - | BoltTypeAliasDeclaration - | BoltRecordField - | BoltRecordDeclaration - | BoltMacroCall - - -export type JSSyntax - = JSOperator - | JSIdentifier - | JSString - | JSInteger - | JSFromKeyword - | JSReturnKeyword - | JSTryKeyword - | JSFinallyKeyword - | JSCatchKeyword - | JSImportKeyword - | JSAsKeyword - | JSConstKeyword - | JSLetKeyword - | JSExportKeyword - | JSFunctionKeyword - | JSWhileKeyword - | JSForKeyword - | JSCloseBrace - | JSCloseBracket - | JSCloseParen - | JSOpenBrace - | JSOpenBracket - | JSOpenParen - | JSSemi - | JSComma - | JSDot - | JSDotDotDot - | JSMulOp - | JSAddOp - | JSDivOp - | JSSubOp - | JSLtOp - | JSGtOp - | JSBOrOp - | JSBXorOp - | JSBAndOp - | JSBNotOp - | JSNotOp - | JSBindPattern - | JSConstantExpression - | JSMemberExpression - | JSCallExpression - | JSBinaryExpression - | JSUnaryExpression - | JSNewExpression - | JSSequenceExpression - | JSConditionalExpression - | JSLiteralExpression - | JSReferenceExpression - | JSCatchBlock - | JSTryCatchStatement - | JSExpressionStatement - | JSConditionalCase - | JSConditionalStatement - | JSReturnStatement - | JSParameter - | JSImportStarBinding - | JSImportAsBinding - | JSImportDeclaration - | JSFunctionDeclaration - | JSArrowFunctionDeclaration - | JSLetDeclaration - | JSSourceFile - - export type Syntax = EndOfFile | FunctionBody @@ -7722,7 +8060,7 @@ export type Syntax | BoltBracketed | BoltSourceFile | BoltQualName - | BoltModulePath + | BoltTypeOfExpression | BoltReferenceTypeExpression | BoltFunctionTypeExpression | BoltLiftedTypeExpression @@ -7767,7 +8105,6 @@ export type Syntax | BoltRecordField | BoltRecordDeclaration | BoltMacroCall - | JSOperator | JSIdentifier | JSString | JSInteger @@ -7880,7 +8217,7 @@ export function createBoltBraced(text: string, span?: TextSpan | null): BoltBrac export function createBoltBracketed(text: string, span?: TextSpan | null): BoltBracketed; export function createBoltSourceFile(elements: BoltSourceElement[], package: Package, span?: TextSpan | null): BoltSourceFile; export function createBoltQualName(isAbsolute: boolean, modulePath: BoltIdentifier[], name: BoltSymbol, span?: TextSpan | null): BoltQualName; -export function createBoltModulePath(isAbsolute: boolean, elements: BoltIdentifier[], span?: TextSpan | null): BoltModulePath; +export function createBoltTypeOfExpression(expression: BoltExpression, span?: TextSpan | null): BoltTypeOfExpression; export function createBoltReferenceTypeExpression(name: BoltQualName, arguments: BoltTypeExpression[] | null, span?: TextSpan | null): BoltReferenceTypeExpression; export function createBoltFunctionTypeExpression(params: BoltParameter[], returnType: BoltTypeExpression | null, span?: TextSpan | null): BoltFunctionTypeExpression; export function createBoltLiftedTypeExpression(expression: BoltExpression, span?: TextSpan | null): BoltLiftedTypeExpression; @@ -7915,7 +8252,7 @@ export function createBoltModule(modifiers: BoltModifiers, name: BoltIdentifier[ export function createBoltFunctionDeclaration(modifiers: BoltModifiers, target: string, name: BoltSymbol, params: BoltParameter[], returnType: BoltTypeExpression | null, typeParams: BoltTypeParameter[] | null, body: BoltFunctionBodyElement[], span?: TextSpan | null): BoltFunctionDeclaration; export function createBoltVariableDeclaration(modifiers: BoltModifiers, bindings: BoltPattern, typeExpr: BoltTypeExpression | null, value: BoltExpression | null, span?: TextSpan | null): BoltVariableDeclaration; export function createBoltPlainImportSymbol(remote: BoltQualName, local: BoltSymbol, span?: TextSpan | null): BoltPlainImportSymbol; -export function createBoltImportDirective(modifiers: BoltModifiers, file: BoltStringLiteral, symbols: BoltImportSymbol[], span?: TextSpan | null): BoltImportDirective; +export function createBoltImportDirective(modifiers: BoltModifiers, file: BoltStringLiteral, symbols: BoltImportSymbol[] | null, span?: TextSpan | null): BoltImportDirective; export function createBoltExportSymbol(span?: TextSpan | null): BoltExportSymbol; export function createBoltPlainExportSymbol(local: BoltQualName, remote: BoltSymbol, span?: TextSpan | null): BoltPlainExportSymbol; export function createBoltExportDirective(file: string, symbols: BoltExportSymbol[] | null, span?: TextSpan | null): BoltExportDirective; @@ -7925,7 +8262,6 @@ export function createBoltTypeAliasDeclaration(modifiers: BoltModifiers, name: B export function createBoltRecordField(name: BoltIdentifier, typeExpr: BoltTypeExpression, span?: TextSpan | null): BoltRecordField; export function createBoltRecordDeclaration(modifiers: BoltModifiers, name: BoltIdentifier, typeParms: BoltTypeParameter[] | null, members: BoltRecordMember[] | null, span?: TextSpan | null): BoltRecordDeclaration; export function createBoltMacroCall(name: BoltIdentifier, text: string, span?: TextSpan | null): BoltMacroCall; -export function createJSOperator(text: string, span?: TextSpan | null): JSOperator; export function createJSIdentifier(text: string, span?: TextSpan | null): JSIdentifier; export function createJSString(value: string, span?: TextSpan | null): JSString; export function createJSInteger(value: bigint, span?: TextSpan | null): JSInteger; @@ -7993,6 +8329,7 @@ export function isEndOfFile(value: any): value is EndOfFile; export function isToken(value: any): value is Token; export function isSourceFile(value: any): value is SourceFile; export function isFunctionBody(value: any): value is FunctionBody; +export function isBoltSyntax(value: any): value is BoltSyntax; export function isBoltToken(value: any): value is BoltToken; export function isBoltStringLiteral(value: any): value is BoltStringLiteral; export function isBoltIntegerLiteral(value: any): value is BoltIntegerLiteral; @@ -8042,8 +8379,8 @@ export function isBoltBraced(value: any): value is BoltBraced; export function isBoltBracketed(value: any): value is BoltBracketed; export function isBoltSourceFile(value: any): value is BoltSourceFile; export function isBoltQualName(value: any): value is BoltQualName; -export function isBoltModulePath(value: any): value is BoltModulePath; export function isBoltTypeExpression(value: any): value is BoltTypeExpression; +export function isBoltTypeOfExpression(value: any): value is BoltTypeOfExpression; export function isBoltReferenceTypeExpression(value: any): value is BoltReferenceTypeExpression; export function isBoltFunctionTypeExpression(value: any): value is BoltFunctionTypeExpression; export function isBoltLiftedTypeExpression(value: any): value is BoltLiftedTypeExpression; @@ -8080,6 +8417,7 @@ export function isBoltParameter(value: any): value is BoltParameter; export function isBoltDeclaration(value: any): value is BoltDeclaration; export function isBoltTypeDeclaration(value: any): value is BoltTypeDeclaration; export function isBoltModule(value: any): value is BoltModule; +export function isBoltDeclarationLike(value: any): value is BoltDeclarationLike; export function isBoltFunctionBodyElement(value: any): value is BoltFunctionBodyElement; export function isBoltFunctionDeclaration(value: any): value is BoltFunctionDeclaration; export function isBoltVariableDeclaration(value: any): value is BoltVariableDeclaration; @@ -8097,6 +8435,7 @@ export function isBoltRecordField(value: any): value is BoltRecordField; export function isBoltRecordDeclaration(value: any): value is BoltRecordDeclaration; export function isBoltSourceElement(value: any): value is BoltSourceElement; export function isBoltMacroCall(value: any): value is BoltMacroCall; +export function isJSSyntax(value: any): value is JSSyntax; export function isJSToken(value: any): value is JSToken; export function isJSOperator(value: any): value is JSOperator; export function isJSIdentifier(value: any): value is JSIdentifier; @@ -8115,6 +8454,7 @@ export function isJSExportKeyword(value: any): value is JSExportKeyword; export function isJSFunctionKeyword(value: any): value is JSFunctionKeyword; export function isJSWhileKeyword(value: any): value is JSWhileKeyword; export function isJSForKeyword(value: any): value is JSForKeyword; +export function isJSOperator(value: any): value is JSOperator; export function isJSCloseBrace(value: any): value is JSCloseBrace; export function isJSCloseBracket(value: any): value is JSCloseBracket; export function isJSCloseParen(value: any): value is JSCloseParen; diff --git a/src/bin/bolt.ts b/src/bin/bolt.ts index 9e4a722e4..bdcb43189 100644 --- a/src/bin/bolt.ts +++ b/src/bin/bolt.ts @@ -14,14 +14,16 @@ import { Program } from "../program" import { parseSourceFile } from "../parser" import { Frontend } from "../frontend" import { Package } from "../common" -import {hasOwnProperty} from "../util" +import {hasOwnProperty, upsearchSync, expandPath, FastStringMap, assert} from "../util" import {isString} from "util" -import {DiagnosticPrinter, E_FIELD_NOT_PRESENT, E_FIELD_MUST_BE_STRING, E_FIELD_HAS_INVALID_VERSION_NUMBER} from "../diagnostics" +import {DiagnosticPrinter, E_FIELD_NOT_PRESENT, E_FIELD_MUST_BE_BOOLEAN, E_FIELD_MUST_BE_STRING, E_FIELD_HAS_INVALID_VERSION_NUMBER} from "../diagnostics" //global.print = function (value: any) { // console.error(require('util').inspect(value, { depth: Infinity, colors: true })) //} +const BOLT_HOME = expandPath(process.env['BOLT_HOME'] ?? '~/.bolt-compiler') + function toArray(value: T | T[]): T[] { if (Array.isArray(value)) { return value as T[] @@ -49,6 +51,7 @@ function loadPackageMetadata(rootDir: string) { let name = null let version = null; + let autoImport = false; let hasVersionErrors = false; let hasNameErrors = false; @@ -90,6 +93,17 @@ function loadPackageMetadata(rootDir: string) { } } } + if (hasOwnProperty(data, 'auto-import')) { + if (typeof(data['auto-import']) !== 'boolean') { + diagnostics.add({ + message: E_FIELD_MUST_BE_BOOLEAN, + args: { name: 'auto-import' }, + severity: 'error', + }) + } else { + autoImport = data['auto-import']; + } + } } } @@ -111,35 +125,67 @@ function loadPackageMetadata(rootDir: string) { return { name, - version + version, + autoImport, }; } -function loadPackage(rootDir: string): Package { +function loadPackageFromPath(rootDir: string, isDependency: boolean): Package { rootDir = path.resolve(rootDir); const data = loadPackageMetadata(rootDir); - const pkg = new Package(rootDir, data.name, data.version, []); + const pkg = new Package(rootDir, data.name, data.version, [], data.autoImport, isDependency); for (const filepath of globSync(path.join(rootDir, '**/*.bolt'))) { pkg.addSourceFile(parseSourceFile(filepath, pkg)); } return pkg; } -function loadPackagesAndSourceFiles(filenames: string[], cwd = '.'): Package[] { +function error(message: string) { + console.error(`Error: ${message}`); +} + +function loadPackagesAndSourceFiles(filenames: string[], pkgResolver: PackageResolver, cwd = '.', useStd: boolean): Package[] { cwd = path.resolve(cwd); - const anonPkg = new Package(cwd, null, null, []); + const anonPkg = new Package(cwd, null, null, [], false, false); const pkgs = [ anonPkg ]; for (const filename of filenames) { if (fs.statSync(filename).isDirectory()) { - pkgs.push(loadPackage(filename)); + pkgs.push(loadPackageFromPath(filename, false)); } else { anonPkg.addSourceFile(parseSourceFile(filename, anonPkg)); } } + if (useStd && pkgs.find(pkg => pkg.name === 'stdlib') === undefined) { + const resolvedPath = pkgResolver.findPackagePath('stdlib'); + if (resolvedPath === null) { + error(`Package 'stdlib' is required to build the current source set but it was not found. Use --no-std if you know what you are doing.`); + process.exit(1); + } + const stdlibPkg = loadPackageFromPath(resolvedPath, true); + assert(stdlibPkg !== null); + pkgs.push(stdlibPkg); + } return pkgs; } +class PackagePathResolver { + + private packageNameToPath = new FastStringMap(); + + public findPackagePath(name: string): string | null { + if (this.packageNameToPath.has(name)) { + return this.packageNameToPath.get(name); + } + return null; + } + + public mapPackgeNameToPath(name: string, filepath: string): void { + this.packageNameToPath.set(name, filepath); + } + +} + yargs .command( @@ -160,9 +206,31 @@ yargs .command( 'check [files..]', 'Check the given files/packages for mistakes.', - yargs => yargs, + yargs => yargs + .string('work-dir') + .describe('work-dir', 'The working directory where files will be resolved against.') + .default('work-dir', '.') + .boolean('no-std') + .describe('no-std', 'Do not build using the standard library.') + .string('pkg'), args => { - const pkgs = loadPackagesAndSourceFiles(toArray(args.files as string[] | string)); + const useStd = args['std'] as boolean ?? true; + const cwd = process.cwd(); + const pkgResolver = new PackagePathResolver(); + for (const pkgMapping of toArray(args.pkg as string[] | string)) { + const [pkgName, pkgPath] = pkgMapping.split(':'); + pkgResolver.mapPackgeNameToPath(pkgName, pkgPath) + } + const files = toArray(args.files as string[] | string); + if (files.length === 0) { + const metadataPath = upsearchSync('Boltfile'); + if (metadataPath === null) { + error(`No source files specified on the command-line and no Boltfile found in ${cwd} or any of its parent directories.`) + process.exit(1); + } + files.push(metadataPath); + } + const pkgs = loadPackagesAndSourceFiles(files, pkgResolver, cwd, useStd); const program = new Program(pkgs); const frontend = new Frontend(); frontend.check(program); @@ -187,10 +255,20 @@ yargs , args => { - const pkgs = loadPackagesAndSourceFiles(toArray(args.files as string[] | string)); + const cwd = process.cwd(); + const files = toArray(args.files as string[] | string); + if (files.length === 0) { + const metadataPath = upsearchSync('Boltfile'); + if (metadataPath === null) { + error(`No source files specified on the command-line and no Boltfile found in ${cwd} or any of its parent directories.`) + process.exit(1); + } + files.push(metadataPath); + } + const pkgs = loadPackagesAndSourceFiles(files); const program = new Program(pkgs); const frontend = new Frontend(); - frontend.typeCheck(program); + frontend.check(program); if (frontend.diagnostics.hasErrors && !args.force) { process.exit(1); } diff --git a/src/checks.ts b/src/checks.ts index 72454b78f..cf672051d 100644 --- a/src/checks.ts +++ b/src/checks.ts @@ -1,4 +1,4 @@ -import { BoltImportDirective, Syntax, BoltParameter, BoltModulePath, BoltReferenceExpression, BoltReferenceTypeExpression, BoltSourceFile, BoltCallExpression, BoltReturnKeyword, BoltReturnStatement, SyntaxKind, NodeVisitor, BoltSyntax, BoltIdentifier } from "./ast"; +import { BoltImportDirective, Syntax, BoltParameter, BoltReferenceExpression, BoltReferenceTypeExpression, BoltSourceFile, BoltCallExpression, BoltReturnKeyword, BoltReturnStatement, SyntaxKind, NodeVisitor, BoltSyntax, BoltIdentifier } from "./ast"; import { Program } from "./program"; import { DiagnosticPrinter, E_FILE_NOT_FOUND, E_TYPES_NOT_ASSIGNABLE, E_DECLARATION_NOT_FOUND, E_TYPE_DECLARATION_NOT_FOUND, E_MUST_RETURN_A_VALUE, E_MAY_NOT_RETURN_A_VALUE } from "./diagnostics"; import { getSymbolPathFromNode } from "./resolver" @@ -140,16 +140,7 @@ export class CheckTypeAssignments extends NodeVisitor { protected visitSyntax(node: Syntax) { for (const error of node.errors) { - switch (error.type) { - case ErrorType.AssignmentError: - this.diagnostics.add({ - message: E_TYPES_NOT_ASSIGNABLE, - severity: 'error', - node: error.left, - }); - default: - throw new Error(`Could not add a diagnostic message for the error ${ErrorType[error.type]}`) - } + this.diagnostics.add({ node, ...error }); } } diff --git a/src/common.ts b/src/common.ts index 734e92987..a6904e390 100644 --- a/src/common.ts +++ b/src/common.ts @@ -18,6 +18,7 @@ import { BOLT_SUPPORTED_LANGUAGES } from "./constants" import {FastStringMap, enumerate, escapeChar, assert} from "./util"; import {TextSpan, TextPos, TextFile} from "./text"; import {Scanner} from "./scanner"; +import * as path from "path" export function getSourceFile(node: Syntax) { while (true) { @@ -41,17 +42,35 @@ export class Package { public id = nextPackageId++; + private sourceFilesByPath = new FastStringMap(); + constructor( public rootDir: string, public name: string | null, public version: string | null, - public sourceFiles: SourceFile[], + sourceFiles: SourceFile[], + public isAutoImported: boolean, + public isDependency: boolean, ) { + for (const sourceFile of sourceFiles) { + this.addSourceFile(sourceFile); + } + } + public getAllSourceFiles(): IterableIterator { + return this.sourceFilesByPath.values(); + } + + public getMainLibrarySourceFile(): SourceFile | null { + const fullPath = path.resolve(this.rootDir, 'lib.bolt'); + if (!this.sourceFilesByPath.has(fullPath)) { + return null; + } + return this.sourceFilesByPath.get(fullPath) } public addSourceFile(sourceFile: SourceFile) { - this.sourceFiles.push(sourceFile); + this.sourceFilesByPath.set(sourceFile.span!.file.fullPath, sourceFile); } } diff --git a/src/constants.ts b/src/constants.ts index c8aac4e41..048da686b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,3 +1,8 @@ export const BOLT_SUPPORTED_LANGUAGES = ['Bolt', 'JS']; +export const BOLT_DIAG_NUM_EXTRA_LINES = 1; + +export const BOLT_MAX_FIELDS_TO_PRINT = 3; + +export const LOG_DATETIME_FORMAT = 'YYYY-MM-DD HH:mm:ss' diff --git a/src/diagnostics.ts b/src/diagnostics.ts index 26ba05cbd..ab5d18f7e 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -1,7 +1,8 @@ import chalk from "chalk" import {Syntax} from "./ast"; -import {format, MapLike, FormatArg, countDigits} from "./util"; +import {format, MapLike, FormatArg, countDigits, mapValues, prettyPrint} from "./util"; +import { BOLT_DIAG_NUM_EXTRA_LINES } from "./constants"; export const E_MAY_NOT_RETURN_A_VALUE = "Returning a value inside a function that does not return values." export const E_MUST_RETURN_A_VALUE = "The function must return a value on all control paths.";;;; @@ -9,22 +10,29 @@ export const E_FILE_NOT_FOUND = "A file named {filename} was not found."; export const E_FIELD_HAS_INVALID_VERSION_NUMBER = "Field '{name}' contains an invalid version nunmber." export const E_FIELD_MUST_BE_STRING = "Field '{name}' must be a string." export const E_FIELD_NOT_PRESENT = "Field '{name}' is not present." +export const E_FIELD_MUST_BE_BOOLEAN = "Field '{name}' must be a either 'true' or 'false'." export const E_TYPE_DECLARATION_NOT_FOUND = "A type declaration named '{name}' was not found." export const E_DECLARATION_NOT_FOUND = "Reference to an undefined declaration '{name}'."; export const E_TYPES_NOT_ASSIGNABLE = "Types {left} and {right} are not assignable."; export const E_TOO_FEW_ARGUMENTS_FOR_FUNCTION_CALL = "Too few arguments for function call. Expected {expected} but got {actual}."; export const E_TOO_MANY_ARGUMENTS_FOR_FUNCTION_CALL = "Too many arguments for function call. Expected {expected} but got {actual}."; -export const E_INVALID_ARGUMENTS = "Invalid arguments passed to function '{name}'." +export const E_CANDIDATE_FUNCTION_REQUIRES_THIS_PARAMETER = "Candidate function requires this parameter." +export const E_ARGUMENT_HAS_NO_CORRESPONDING_PARAMETER = "Argument has no corresponding parameter." +export const E_INVALID_ARGUMENTS = "Invalid arguments passed to function '{name}'" +export const E_RECORD_MISSING_MEMBER = "Record {name} does not have a member declaration named {memberName}" +export const E_TYPES_MISSING_MEMBER = "Not all types resolve to a record with the a member named '{name}'." +export const E_NODE_DOES_NOT_CONTAIN_MEMBER = "This node does not contain the the member '{name}'." +export const E_MAY_NOT_RETURN_BECAUSE_TYPE_RESOLVES_TO_VOID = "May not return a value because the function's return type resolves to '()'" +export const E_MUST_RETURN_BECAUSE_TYPE_DOES_NOT_RESOLVE_TO_VOID = "Must return a value because the function's return type does not resolve to '()'" const BOLT_HARD_ERRORS = process.env['BOLT_HARD_ERRORS'] -const DIAG_NUM_EXTRA_LINES = 1; - export interface Diagnostic { message: string; severity: string; args?: MapLike; node?: Syntax; + nested?: Diagnostic[]; } function firstIndexOfNonEmpty(str: string) { @@ -78,7 +86,7 @@ export class DiagnosticPrinter { out += chalk.bold.yellow(`${span.file.origPath}:${span.start.line}:${span.start.column}: `); } if (diagnostic.args !== undefined) { - out += format(diagnostic.message, diagnostic.args) + '\n'; + out += format(diagnostic.message, mapValues(diagnostic.args, prettyPrint)) + '\n'; } else { out += diagnostic.message + '\n'; } @@ -87,9 +95,9 @@ export class DiagnosticPrinter { out += '\n' const span = diagnostic.node.span!; const content = span.file.getText(); - const startLine = Math.max(0, span.start.line-1-DIAG_NUM_EXTRA_LINES) + const startLine = Math.max(0, span.start.line-1-BOLT_DIAG_NUM_EXTRA_LINES) const lines = content.split('\n') - const endLine = Math.min(lines.length-1, (span.end !== undefined ? span.end.line : startLine)+DIAG_NUM_EXTRA_LINES) + const endLine = Math.min(lines.length-1, (span.end !== undefined ? span.end.line : startLine)+BOLT_DIAG_NUM_EXTRA_LINES) const gutterWidth = Math.max(2, countDigits(endLine+1)) for (let i = startLine; i < endLine; i++) { const line = lines[i]; diff --git a/src/emitter.ts b/src/emitter.ts index 3846ac756..fe2e4ee94 100644 --- a/src/emitter.ts +++ b/src/emitter.ts @@ -9,10 +9,6 @@ export class Emitter { switch (node.kind) { - case SyntaxKind.BoltModulePath: - out += node.elements.map(el => el.text).join('::'); - break; - case SyntaxKind.BoltQualName: if (node.modulePath !== null) { if (node.isAbsolute) { diff --git a/src/frontend.ts b/src/frontend.ts index fd35d3c99..1c5de6ddb 100644 --- a/src/frontend.ts +++ b/src/frontend.ts @@ -93,11 +93,17 @@ export class Frontend { const checkers = checks.map(check => container.createInstance(check)); for (const sourceFile of program.getAllSourceFiles()) { - checker.registerSourceFile(sourceFile); resolver.registerSourceFile(sourceFile); } for (const sourceFile of program.getAllSourceFiles()) { - sourceFile.visit(checkers) + checker.registerSourceFile(sourceFile); + } + for (const pkg of program.getAllPackages()) { + if (!pkg.isDependency) { + for (const sourceFile of pkg.getAllSourceFiles()) { + sourceFile.visit(checkers) + } + } } } diff --git a/src/parser.ts b/src/parser.ts index 8177582cf..4d0044488 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -81,6 +81,7 @@ import { BoltModulePath, isBoltSymbol, BoltIdentifierChild, + BoltDeclarationLike, } from "./ast" import { parseForeignLanguage } from "./foreign" @@ -1284,7 +1285,7 @@ export class Parser { return result; } - public parseDeclaration(tokens: BoltTokenStream): BoltDeclaration { + public parseDeclarationLike(tokens: BoltTokenStream): BoltDeclarationLike { let t0 = tokens.peek(1); let i = 1; if (t0.kind === SyntaxKind.BoltPubKeyword) { @@ -1365,7 +1366,7 @@ export class Parser { } else if (KIND_STATEMENT_T0.indexOf(t1.kind) !== -1) { return this.parseStatement(tokens); } else if (KIND_DECLARATION_KEYWORD.indexOf(t1.kind) !== -1) { - return this.parseDeclaration(tokens); + return this.parseDeclarationLike(tokens); } else { throw new ParseError(t0, KIND_SOURCEELEMENT_T0); } diff --git a/src/program.ts b/src/program.ts index d88157983..524200048 100644 --- a/src/program.ts +++ b/src/program.ts @@ -11,10 +11,13 @@ export class Program { private sourceFilesByFilePath = new FastStringMap(); constructor( - pkgs: Package[] + private pkgs: Package[] ) { for (const pkg of pkgs) { - for (const sourceFile of pkg.sourceFiles) { + if (pkg.name !== null) { + this.packagesByName.set(pkg.name, pkg); + } + for (const sourceFile of pkg.getAllSourceFiles()) { this.sourceFilesByFilePath.set(stripExtensions(sourceFile.span!.file.fullPath), sourceFile); } } @@ -32,6 +35,21 @@ export class Program { return this.sourceFilesByFilePath.get(filepath); } + public getAllPackages(): IterableIterator { + return this.pkgs[Symbol.iterator](); + } + + public *getAllGloballyDeclaredSourceFiles(): IterableIterator { + for (const pkg of this.getAllPackages()) { + if (pkg.isAutoImported) { + const mainLibrarySourceFile = pkg.getMainLibrarySourceFile(); + if (mainLibrarySourceFile !== null) { + yield mainLibrarySourceFile; + } + } + } + } + public getPackageNamed(name: string): Package { return this.packagesByName.get(name); } diff --git a/src/renamer.ts b/src/renamer.ts deleted file mode 100644 index b28b04f64..000000000 --- a/src/renamer.ts +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/resolver.ts b/src/resolver.ts index 35dbac02f..f63d3c5fa 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -42,12 +42,12 @@ export function getSymbolPathFromNode(node: BoltSyntax): SymbolPath { return new SymbolPath([], false, name); } return new SymbolPath(node.modulePath.map(id => id.text), false, name); - case SyntaxKind.BoltModulePath: - return new SymbolPath( - node.elements.slice(0, -1).map(el => el.text), - node.isAbsolute, - node.elements[node.elements.length-1].text - ); + //case SyntaxKind.BoltModulePath: + // return new SymbolPath( + // node.elements.slice(0, -1).map(el => el.text), + // node.isAbsolute, + // node.elements[node.elements.length-1].text + // ); default: throw new Error(`Could not extract a symbol path from the given node.`); } @@ -491,6 +491,21 @@ export class SymbolResolver { return scope.getSymbol(this.strategy.getSymbolName(node)); } + public resolveGlobalSymbol(name: string, kind: ScopeType) { + const symbolPath = new SymbolPath([], true, name); + for (const sourceFile of this.program.getAllGloballyDeclaredSourceFiles()) { + const scope = this.getScopeForNode(sourceFile, kind); + if (scope === null) { + continue; + } + const sym = scope.getLocalSymbol(name); + if (sym !== null) { + return sym + } + } + return null; + } + public resolveSymbolPath(path: SymbolPath, scope: Scope): SymbolInfo | null { if (path.hasParents()) { diff --git a/src/treegen/ast-template.js b/src/treegen/ast-template.js index cfb2a9011..8c1936a13 100644 --- a/src/treegen/ast-template.js +++ b/src/treegen/ast-template.js @@ -40,11 +40,15 @@ const nodeProto = { const stack = [this]; while (stack.length > 0) { const node = stack.pop(); - const key = `visit${kindToString(node.kind)}` + const kindName = kindToString(node.kind); + const kindNamesToVisit = [kindName, ...NODE_TYPES[kindName].parents]; for (const visitor of visitors) { - if (visitor[key] !== undefined) { - visitor[key](node); - } + for (const kindName of kindNamesToVisit) { + const key = `visit${kindName}` + if (visitor[key] !== undefined) { + visitor[key](node); + } + } } for (const childNode of node.getChildNodes()) { stack.push(childNode); diff --git a/src/treegen/ast.dts.template b/src/treegen/ast.dts.template index 84f3b1f8d..6f7d8658b 100644 --- a/src/treegen/ast.dts.template +++ b/src/treegen/ast.dts.template @@ -1,5 +1,6 @@ import { Type } from "./types" +import { Diagnostic } from "./diagnostics" import { Package } from "./common" import { TextSpan } from "./text" @@ -13,7 +14,7 @@ interface SyntaxBase { id: number; kind: SyntaxKind; type?: Type; - errors: CompileError[] + errors: Diagnostic[] parentNode: Syntax | null; span: TextSpan | null; visit(visitors: NodeVisitor[]): void; diff --git a/src/treegen/index.ts b/src/treegen/index.ts index 85675ac8f..43f8f1070 100644 --- a/src/treegen/index.ts +++ b/src/treegen/index.ts @@ -4,7 +4,7 @@ import * as path from "path" const PACKAGE_ROOT = path.resolve(__dirname, '..', '..'); -const CUSTOM_TYPES = ['Package']; +const CUSTOM_TYPES = ['Package', 'BoltValue', 'JSValue']; import { Syntax, Declaration, NodeDeclaration, TypeDeclaration, EnumDeclaration, TypeNode, NodeField } from "./ast" import { MapLike, assert } from "../util" @@ -21,7 +21,6 @@ export function generateAST(decls: Declaration[]) { const nodeDecls: NodeDeclaration[] = decls.filter(decl => decl.type === 'NodeDeclaration') as NodeDeclaration[]; const typeDecls: TypeDeclaration[] = decls.filter(decl => decl.type === 'TypeDeclaration') as TypeDeclaration[]; const enumDecls: EnumDeclaration[] = decls.filter(decl => decl.type === 'EnumDeclaration') as EnumDeclaration[]; - const langNames: string[] = decls.filter(decl => decl.type === 'LanguageDeclaration').map(decl => decl.name); const declByName: MapLike = Object.create(null); i = 0; @@ -57,6 +56,11 @@ export function generateAST(decls: Declaration[]) { jsFile.write(`'${decl.name}': {\n`); jsFile.indent(); jsFile.write(`index: ${decl.index},\n`); + jsFile.write(`parents: [`); + for (const parentName of getParentChain(decl.name)) { + jsFile.write(`'${decl.name}', `) + } + jsFile.write(`'Syntax'],\n`); jsFile.write(`fields: new Map([\n`); jsFile.indent(); for (const field of getAllFields(decl)) { @@ -189,20 +193,6 @@ export function generateAST(decls: Declaration[]) { //dtsFile.write(' never\n\n'); //} - for (const langName of langNames) { - dtsFile.write(`export type ${langName}Syntax\n`); - let first = true; - dtsFile.indent(); - for (const decl of finalNodes) { - if (decl.name.startsWith(langName)) { - dtsFile.write((first ? '=' : '|') + ' ' + decl.name + '\n'); - first = false; - } - } - dtsFile.dedent(); - dtsFile.write('\n\n'); - } - dtsFile.write(`export type Syntax\n`); let first = true; dtsFile.indent(); @@ -369,6 +359,17 @@ export function generateAST(decls: Declaration[]) { return children; } + function *getParentChain(nodeName: string) { + const stack = [ nodeName ]; + while (stack.length > 0) { + const nodeDecl = getDeclarationNamed(stack.pop()!) as NodeDeclaration; + for (const parentName of nodeDecl.parents) { + yield parentName; + stack.push(parentName); + } + } + } + function* getFinalNodes(declName: string): IterableIterator { const stack = [ declName ]; while (stack.length > 0) { diff --git a/src/types.ts b/src/types.ts index b95984754..3f9cb118e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,8 +1,15 @@ -import { FastStringMap, assert, isPlainObject } from "./util"; -import { SyntaxKind, Syntax, isBoltTypeExpression, BoltExpression, BoltFunctionDeclaration, BoltFunctionBodyElement, kindToString, SourceFile, isBoltExpression, isBoltMacroCall, BoltTypeExpression } from "./ast"; -import { getSymbolPathFromNode, ScopeType, SymbolResolver, SymbolInfo } from "./resolver"; +import { FastStringMap, assert, isPlainObject, some, prettyPrintTag } from "./util"; +import { SyntaxKind, Syntax, isBoltTypeExpression, BoltExpression, BoltFunctionDeclaration, BoltFunctionBodyElement, kindToString, SourceFile, isBoltExpression, isBoltMacroCall, BoltTypeExpression, BoltCallExpression, BoltSyntax, BoltMemberExpression, BoltDeclaration, isBoltDeclaration, isBoltTypeDeclaration, BoltTypeDeclaration, BoltReturnStatement, BoltIdentifier, BoltRecordDeclaration, isBoltRecordDeclaration, isBoltDeclarationLike } from "./ast"; +import { getSymbolPathFromNode, ScopeType, SymbolResolver, SymbolInfo, SymbolPath } from "./resolver"; import { Value, Record } from "./evaluator"; +import { SourceMap } from "module"; +import { timingSafeEqual } from "crypto"; +import { isRightAssoc, getReturnStatementsInFunctionBody, BoltFunctionBody, getModulePathToNode } from "./common"; +import { relativeTimeThreshold } from "moment"; +import { E_TOO_MANY_ARGUMENTS_FOR_FUNCTION_CALL, E_TOO_FEW_ARGUMENTS_FOR_FUNCTION_CALL, E_CANDIDATE_FUNCTION_REQUIRES_THIS_PARAMETER, E_ARGUMENT_HAS_NO_CORRESPONDING_PARAMETER, E_TYPES_NOT_ASSIGNABLE, E_TYPES_MISSING_MEMBER, E_NODE_DOES_NOT_CONTAIN_MEMBER, E_RECORD_MISSING_MEMBER, E_MUST_RETURN_A_VALUE, E_MAY_NOT_RETURN_BECAUSE_TYPE_RESOLVES_TO_VOID, E_MAY_NOT_RETURN_A_VALUE, E_MUST_RETURN_BECAUSE_TYPE_DOES_NOT_RESOLVE_TO_VOID } from "./diagnostics"; +import { emitNode } from "./emitter"; +import { BOLT_MAX_FIELDS_TO_PRINT } from "./constants"; // TODO For function bodies, we can do something special. // Sort the return types and find the largest types, eliminating types that fall under other types. @@ -29,15 +36,31 @@ export type Type | VariantType | TupleType | UnionType + | PlainRecordFieldType abstract class TypeBase { public abstract kind: TypeKind; - constructor(public symbol?: SymbolInfo) { + /** + * Holds the node that created this type, if any. + */ + public node?: Syntax + + constructor(public sym?: SymbolInfo) { } + public [prettyPrintTag](): string { + return prettyPrintType(this as Type); + } + +} + +export function isType(value: any) { + return typeof(value) === 'object' + && value !== null + && value.__IS_TYPE !== null; } export class OpaqueType extends TypeBase { @@ -94,17 +117,20 @@ export class VariantType extends TypeBase { export class UnionType extends TypeBase { + private elements: Type[] = []; + public kind: TypeKind.UnionType = TypeKind.UnionType; - constructor(private elements: Type[] = []) { + constructor(elements: Iterable = []) { super(); + this.elements = [...elements]; } public addElement(element: Type): void { this.elements.push(element); } - public getElements(): IterableIterator { + public getElementTypes(): IterableIterator { return this.elements[Symbol.iterator](); } @@ -123,7 +149,7 @@ class PlainRecordFieldType extends TypeBase { } -export class RecordType { +export class RecordType extends TypeBase { public kind: TypeKind.RecordType = TypeKind.RecordType; @@ -132,17 +158,26 @@ export class RecordType { constructor( iterable?: Iterable<[string, RecordFieldType]>, ) { + super(); if (iterable !== undefined) { for (const [name, type] of iterable) { this.fieldTypes.set(name, type); } } } + + public getFieldNames() { + return this.fieldTypes.keys(); + } public addField(name: string, type: RecordFieldType): void { this.fieldTypes.set(name, type); } + public getFields() { + return this.fieldTypes[Symbol.iterator](); + } + public hasField(name: string) { return name in this.fieldTypes; } @@ -157,8 +192,30 @@ export class RecordType { } +export class TupleType extends TypeBase { + + kind: TypeKind.TupleType = TypeKind.TupleType; + + constructor(public elementTypes: Type[] = []) { + super(); + } + +} + export enum ErrorType { AssignmentError, + NotARecord, + TypeMismatch, + TooFewArguments, + TooManyArguments, + MayNotReturnValue, + MustReturnValue, +} + +interface NotARecordError { + type: ErrorType.NotARecord; + node: Syntax; + candidate: Syntax; } interface AssignmentError { @@ -167,58 +224,105 @@ interface AssignmentError { right: Syntax; } -export type CompileError - = AssignmentError - -export class TupleType extends TypeBase { - - kind: TypeKind.TupleType = TypeKind.TupleType; - - constructor(public elementTypes: Type[]) { - super(); - } - +interface TypeMismatchError { + type: ErrorType.TypeMismatch; + left: Type; + right: Type; } -//export function narrowType(outer: Type, inner: Type): Type { -// if (isAnyType(outer) || isNeverType(inner)) { -// return inner; -// } -// // TODO cover the other cases -// return outer; -//} +interface TooManyArgumentsError { + type: ErrorType.TooManyArguments; + caller: Syntax; + callee: Syntax; + index: number; +} -//export function intersectTypes(a: Type, b: Type): Type { -// if (a.kind === TypeKind.NeverType && b.kind === TypeKind.NeverType) -// return new NeverType(); -// } -// if (a.kind == TypeKind.AnyType) { -// return a -// } -// if (isAnyType(a)) { -// return b; -// } -// if (a.kind === TypeKind.FunctionType && b.kind === TypeKind.FunctionType) { -// if (a.paramTypes.length !== b.paramTypes.length) { -// return new NeverType(); -// } -// const returnType = intersectTypes(a.returnType, b.returnType); -// const paramTypes = a.paramTypes -// .map((_, i) => intersectTypes(a.paramTypes[i], b.paramTypes[i])); -// return new FunctionType(paramTypes, returnType) -// } -// return new NeverType(); -//} +interface TooFewArgumentsError { + type: ErrorType.TooFewArguments; + caller: Syntax; + callee: Syntax; + index: number; +} + +interface MustReturnValueError { + type: ErrorType.MustReturnValue; +} + +interface MayNotReturnValueError { + type: ErrorType.MayNotReturnValue; +} + +export type CompileError + = AssignmentError + | TypeMismatchError + | TooManyArgumentsError + | TooFewArgumentsError + | NotARecordError + | MustReturnValueError + | MayNotReturnValueError + +export interface FunctionSignature { + paramTypes: Type[]; +} + +function* getAllPossibleElementTypes(type: Type): IterableIterator { + switch (type.kind) { + case TypeKind.UnionType: + { + for (const elementType of type.getElementTypes()) { + yield* getAllPossibleElementTypes(elementType); + } + break; + } + default: + yield type; + } +} + +export function prettyPrintType(type: Type): string { + let out = '' + let hasElementType = false; + for (const elementType of getAllPossibleElementTypes(type)) { + hasElementType = true; + if (elementType.sym !== undefined) { + out += elementType.sym.name; + } else { + switch (elementType.kind) { + case TypeKind.AnyType: + { + out += 'any'; + break; + } + case TypeKind.RecordType: + { + out += '{' + let i = 0; + for (const [fieldName, fieldType] of elementType.getFields()) { + out += fieldName + ': ' + prettyPrintType(fieldType); + i++; + if (i >= BOLT_MAX_FIELDS_TO_PRINT) { + break + } + } + out += '}' + break; + } + default: + throw new Error(`Could not pretty-print type ${TypeKind[elementType.kind]}`) + } + } + } + if (!hasElementType) { + out += '()' + } + return out; +} export class TypeChecker { private opaqueTypes = new FastStringMap(); private anyType = new AnyType(); - private stringType = new OpaqueType(); - private intType = new OpaqueType(); - private floatType = new OpaqueType(); - private voidType = new OpaqueType(); private syntaxType = new UnionType(); // FIXME @@ -228,11 +332,17 @@ export class TypeChecker { public getTypeOfValue(value: Value): Type { if (typeof(value) === 'string') { - return this.stringType; + const sym = this.resolver.resolveGlobalSymbol('String', ScopeType.Type); + assert(sym !== null); + return new OpaqueType(sym!); } else if (typeof(value) === 'bigint') { - return this.intType; + const sym = this.resolver.resolveGlobalSymbol('int', ScopeType.Type); + assert(sym !== null); + return new OpaqueType(sym!); } else if (typeof(value) === 'number') { - return this.floatType; + const sym = this.resolver.resolveGlobalSymbol('f64', ScopeType.Type); + assert(sym !== null); + return new OpaqueType(sym!); } else if (value instanceof Record) { const recordType = new RecordType() for (const [fieldName, fieldValue] of value.getFields()) { @@ -244,6 +354,67 @@ export class TypeChecker { } } + private checkTypeMatches(a: Type, b: Type) { + switch (b.kind) { + case TypeKind.FunctionType: + if (a.kind === TypeKind.AnyType) { + return true; + } + if (a.kind === TypeKind.FunctionType) { + if (b.getParameterCount() > a.getParameterCount()) { + a.node?.errors.push({ + message: E_TOO_MANY_ARGUMENTS_FOR_FUNCTION_CALL, + severity: 'error', + args: { + expected: a.getParameterCount(), + actual: a.getParameterCount(), + }, + nested: [{ + message: E_CANDIDATE_FUNCTION_REQUIRES_THIS_PARAMETER, + severity: 'error', + node: b.getTypeAtParameterIndex(a.getParameterCount()).node! + }] + }) + } + if (b.getParameterCount() < a.getParameterCount()) { + let nested = []; + for (let i = b.getParameterCount(); i < a.getParameterCount(); i++) { + nested.push({ + message: E_ARGUMENT_HAS_NO_CORRESPONDING_PARAMETER, + severity: 'error', + node: (a.node as BoltCallExpression).operands[i] + }); + } + a.node?.errors.push({ + message: E_TOO_FEW_ARGUMENTS_FOR_FUNCTION_CALL, + severity: 'error', + args: { + expected: a.getParameterCount(), + actual: b.getParameterCount(), + }, + nested, + }); + } + const paramCount = a.getParameterCount(); + for (let i = 0; i < paramCount; i++) { + const paramA = a.getTypeAtParameterIndex(i); + const paramB = b.getTypeAtParameterIndex(i); + if (this.isTypeAssignableTo(paramA, paramB)) { + a.node?.errors.push({ + message: E_TYPES_NOT_ASSIGNABLE, + severity: 'error', + args: { + left: a, + right: b, + }, + node: a.node, + }) + } + } + } + } + } + public registerSourceFile(sourceFile: SourceFile): void { for (const node of sourceFile.preorder()) { if (isBoltMacroCall(node)) { @@ -253,6 +424,12 @@ export class TypeChecker { node.type = this.createInitialTypeForExpression(node); } } + for (const callExpr of sourceFile.findAllChildrenOfKind(SyntaxKind.BoltCallExpression)) { + const callTypeSig = new FunctionType(callExpr.operands.map(op => op.type!), this.anyType); + for (const callableType of this.findTypesInExpression(callExpr.operator)) { + this.checkTypeMatches(callableType, callTypeSig); + } + } } private createInitialTypeForExpression(node: Syntax): Type { @@ -282,7 +459,7 @@ export class TypeChecker { if (this.opaqueTypes.has(recordSym!.id)) { resultType = this.opaqueTypes.get(recordSym!.id); } else { - const opaqueType = new OpaqueType(recordSym!); + const opaqueType = new OpaqueType(name, node); this.opaqueTypes.set(recordSym!.id, opaqueType); resultType = opaqueType; } @@ -346,67 +523,328 @@ export class TypeChecker { } public isVoidType(type: Type): boolean { - return type === this.voidType; + return this.isTypeAssignableTo(new TupleType, type); } - public getCallableFunctions(node: BoltExpression): BoltFunctionDeclaration[] { + private *getTypesForMember(origNode: Syntax, fieldName: string, type: Type): IterableIterator { + switch (type.kind) { + case TypeKind.UnionType: + { + const typesMissingMember = []; + for (const elementType of getAllPossibleElementTypes(type)) { + let foundType = false; + for (const recordType of this.getTypesForMemberNoUnionType(origNode, fieldName, elementType, false)) { + yield recordType; + foundType = true; + } + if (!foundType) { + origNode.errors.push({ + message: E_TYPES_MISSING_MEMBER, + severity: 'error', + }) + } + } + } + default: + return this.getTypesForMemberNoUnionType(origNode, fieldName, type, true); + } + } - const resolver = this.resolver; + private *getTypesForMemberNoUnionType(origNode: Syntax, fieldName: string, type: Type, hardError: boolean): IterableIterator { + switch (type.kind) { + case TypeKind.AnyType: + break; + case TypeKind.FunctionType: + if (hardError) { + origNode.errors.push({ + message: E_TYPES_MISSING_MEMBER, + severity: 'error', + args: { + name: fieldName, + }, + nested: [{ + message: E_NODE_DOES_NOT_CONTAIN_MEMBER, + severity: 'error', + node: type.node!, + }] + }); + } + break; + case TypeKind.RecordType: + { + if (type.hasField(fieldName)) { + const fieldType = type.getFieldType(fieldName); + assert(fieldType.kind === TypeKind.PlainRecordFieldType); + yield (fieldType as PlainRecordFieldType).type; + } else { + if (hardError) { + origNode.errors.push({ + message: E_TYPES_MISSING_MEMBER, + severity: 'error', + args: { + name: fieldName + } + }) + } + } + break; + } + default: + throw new Error(`I do not know how to find record member types for ${TypeKind[type.kind]}`) + } + } - const results: BoltFunctionDeclaration[] = []; - visitExpression(node); - return results; + private isTypeAlwaysCallable(type: Type) { + return type.kind === TypeKind.FunctionType; + } + + private *getAllNodesForType(type: Type): IterableIterator { + if (type.node !== undefined) { + yield type.node; + } + switch (type.kind) { + case TypeKind.UnionType: + for (const elementType of type.getElementTypes()) { + yield* this.getAllNodesForType(type); + } + break; + default: + } + } + + private *findTypesInTypeExpression(node: BoltTypeExpression): IterableIterator { + switch (node.kind) { + case SyntaxKind.BoltTypeOfExpression: + { + yield* this.findTypesInExpression(node.expression); + break; + } + case SyntaxKind.BoltReferenceTypeExpression: + { + const scope = this.resolver.getScopeSurroundingNode(node, ScopeType.Variable); + assert(scope !== null); + const symbolPath = getSymbolPathFromNode(node.name); + const resolvedSym = this.resolver.resolveSymbolPath(symbolPath, scope!); + if (resolvedSym !== null) { + for (const decl of resolvedSym.declarations) { + assert(isBoltTypeDeclaration(decl)); + this.findTypesInTypeDeclaration(decl as BoltTypeDeclaration); + } + } + break; + } + default: + throw new Error(`Unexpected node type ${kindToString(node.kind)}`); + } + } + + private *findTypesInExpression(node: BoltExpression): IterableIterator { - function visitExpression(node: BoltExpression) { switch (node.kind) { + case SyntaxKind.BoltMemberExpression: { - visitExpression(node.expression); - break; - } - case SyntaxKind.BoltQuoteExpression: - { - // TODO visit all unquote expressions - //visitExpression(node.tokens); - break; - } - case SyntaxKind.BoltCallExpression: - { - // TODO - break; - } - case SyntaxKind.BoltReferenceExpression: - { - const scope = resolver.getScopeForNode(node, ScopeType.Variable); - assert(scope !== null); - const resolvedSym = resolver.resolveSymbolPath(getSymbolPathFromNode(node), scope!); - if (resolvedSym !== null) { - for (const decl of resolvedSym.declarations) { - visitFunctionBodyElement(decl as BoltFunctionBodyElement); + for (const element of node.path) { + for (const memberType of this.getTypesForMember(element, element.text, node.expression.type!)) { + yield memberType; } } break; } - default: - throw new Error(`Unexpected node type ${kindToString(node.kind)}`); - } - } - function visitFunctionBodyElement(node: BoltFunctionBodyElement) { - switch (node.kind) { - case SyntaxKind.BoltFunctionDeclaration: - results.push(node); + case SyntaxKind.BoltMatchExpression: + { + const unionType = new UnionType(); + for (const matchArm of node.arms) { + unionType.addElement(this.createInitialTypeForExpression(matchArm.body)); + } + yield unionType; break; - case SyntaxKind.BoltVariableDeclaration: - if (node.value !== null) { - visitExpression(node.value); + } + + case SyntaxKind.BoltQuoteExpression: + { + break; + } + + case SyntaxKind.BoltCallExpression: + { + const nodeSignature = new FunctionType(node.operands.map(op => op.type!), this.anyType); + for (const callableType of this.findTypesInExpression(node.operator)) { + yield callableType; } break; + } + + case SyntaxKind.BoltReferenceExpression: + { + const scope = this.resolver.getScopeSurroundingNode(node, ScopeType.Variable); + assert(scope !== null); + const symbolPath = getSymbolPathFromNode(node.name); + const resolvedSym = this.resolver.resolveSymbolPath(symbolPath, scope!); + if (resolvedSym !== null) { + for (const decl of resolvedSym.declarations) { + assert(isBoltDeclaration(decl)); + yield* this.findTypesInDeclaration(decl as BoltDeclaration); + } + } + break; + } + default: throw new Error(`Unexpected node type ${kindToString(node.kind)}`); + } } + private *findTypesInTypeDeclaration(node: BoltTypeDeclaration): IterableIterator { + switch (node.kind) { + case SyntaxKind.BoltTypeAliasDeclaration: + { + yield* this.findTypesInTypeExpression(node.typeExpr); + break; + } + default: + throw new Error(`Unexpected node type ${kindToString(node.kind)}`); + } } + private *findTypesInDeclaration(node: BoltDeclaration) { + switch (node.kind) { + case SyntaxKind.BoltVariableDeclaration: + if (node.typeExpr !== null) { + yield* this.findTypesInTypeExpression(node.typeExpr); + } + if (node.value !== null) { + yield* this.findTypesInExpression(node.value); + } + break; + case SyntaxKind.BoltFunctionDeclaration: + { + yield this.getFunctionReturnType(node); + break; + } + default: + throw new Error(`Could not find callable expressions in declaration ${kindToString(node.kind)}`) + } + } + + private getTypeOfExpression(node: BoltExpression): Type { + return new UnionType(this.findTypesInExpression(node)); + } + + private getFunctionReturnType(node: BoltFunctionDeclaration): Type { + let returnType: Type = this.anyType; + if (node.returnType !== null) { + returnType = new UnionType(this.findTypesInTypeExpression(node.returnType)); + } + for (const returnStmt of this.getAllReturnStatementsInFunctionBody(node.body)) { + if (returnStmt.value === null) { + if (!this.isVoidType(returnType)) { + returnStmt.errors.push({ + message: E_MAY_NOT_RETURN_A_VALUE, + severity: 'error', + nested: [{ + message: E_MAY_NOT_RETURN_BECAUSE_TYPE_RESOLVES_TO_VOID, + severity: 'error', + node: node.returnType !== null ? node.returnType : node, + }] + }); + } + } else { + const stmtReturnType = this.getTypeOfExpression(returnStmt.value); + if (!this.isTypeAssignableTo(returnType, stmtReturnType)) { + if (this.isVoidType(stmtReturnType)) { + returnStmt.value.errors.push({ + message: E_MUST_RETURN_A_VALUE, + severity: 'error', + nested: [{ + message: E_MUST_RETURN_BECAUSE_TYPE_DOES_NOT_RESOLVE_TO_VOID, + severity: 'error', + node: node.returnType !== null ? node.returnType : node, + }] + }) + } else { + returnStmt.value.errors.push({ + message: E_TYPES_NOT_ASSIGNABLE, + severity: 'error', + args: { + left: returnType, + right: stmtReturnType, + } + }) + } + } + + } + } + return returnType; + } + + private *getAllReturnStatementsInFunctionBody(body: BoltFunctionBody): IterableIterator { + for (const element of body) { + switch (element.kind) { + case SyntaxKind.BoltReturnStatement: + { + yield element; + break; + } + case SyntaxKind.BoltConditionalStatement: + { + for (const caseNode of element.cases) { + yield* this.getAllReturnStatementsInFunctionBody(caseNode.body); + } + break; + } + case SyntaxKind.BoltExpressionStatement: + break; + default: + throw new Error(`I did not know how to find return statements in ${kindToString(node.kind)}`); + } + } + } + + private isTypeAssignableTo(left: Type, right: Type): boolean { + if (left.kind === TypeKind.NeverType || right.kind === TypeKind.NeverType) { + return false; + } + if (left.kind === TypeKind.AnyType || right.kind === TypeKind.AnyType) { + return true; + } + if (left.kind === TypeKind.OpaqueType && right.kind === TypeKind.OpaqueType) { + return left === right; + } + if (left.kind === TypeKind.RecordType && right.kind === TypeKind.RecordType) { + for (const fieldName of left.getFieldNames()) { + if (!right.hasField(fieldName)) { + return false; + } + } + for (const fieldName of right.getFieldNames()) { + if (!left.hasField(fieldName)) { + return false; + } + if (!this.isTypeAssignableTo(left.getFieldType(fieldName), right.getFieldType(fieldName))) { + return false; + } + } + return true; + } + if (left.kind === TypeKind.FunctionType && right.kind === TypeKind.FunctionType) { + if (left.getParameterCount() !== right.getParameterCount()) { + return false; + } + for (let i = 0; i < left.getParameterCount(); i++) { + if (!this.isTypeAssignableTo(left.getTypeAtParameterIndex(i), right.getTypeAtParameterIndex(i))) { + return false; + } + } + if (!this.isTypeAssignableTo(left.returnType, right.returnType)) { + return false; + } + return true; + } + return false; + } + } diff --git a/src/util.ts b/src/util.ts index d9b97f134..cd0195a73 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,14 +1,31 @@ import * as path from "path" import * as fs from "fs" +import * as os from "os" + import moment from "moment" import chalk from "chalk" +import { LOG_DATETIME_FORMAT } from "./constants" export function isPowerOf(x: number, n: number):boolean { const a = Math.log(x) / Math.log(n); return Math.pow(a, n) == x; } + +export function some(iterator: Iterator, pred: (value: T) => boolean): boolean { + while (true) { + const { value, done } = iterator.next(); + if (done) { + break; + } + if (pred(value)) { + return true; + } + } + return false; +} + export function every(iterator: Iterator, pred: (value: T) => boolean): boolean { while (true) { const { value, done } = iterator.next(); @@ -97,6 +114,23 @@ export function isPlainObject(value: any): value is object { return Object.getPrototypeOf(value) === proto } +export function mapValues(obj: T, func: (value: keyof T) => R): { [K in keyof T]: R } { + const newObj: any = {} + for (const key of Object.keys(obj)) { + newObj[key] = func((obj as any)[key]); + } + return newObj; +} + +export const prettyPrintTag = Symbol('pretty printer'); + +export function prettyPrint(value: any): string { + if (isObjectLike(value) && value[prettyPrintTag] !== undefined) { + return value[prettyPrintTag](); + } + return value.toString(); +} + export class FastStringMap { private mapping = Object.create(null); @@ -104,7 +138,13 @@ export class FastStringMap { public clear(): void { this.mapping.clear(); } - + + public *[Symbol.iterator](): IterableIterator<[K, V]> { + for (const key of Object.keys(this.mapping)) { + yield [key as K, this.mapping[key]]; + } + } + public get(key: K): V { if (!(key in this.mapping)) { throw new Error(`No value found for key '${key}'.`); @@ -112,6 +152,12 @@ export class FastStringMap { return this.mapping[key]; } + public *keys(): IterableIterator { + for (const key of Object.keys(this.mapping)) { + yield key as K; + } + } + public *values(): IterableIterator { for (const key of Object.keys(this.mapping)) { yield this.mapping[key]; @@ -230,16 +276,30 @@ export class StreamWrapper { } -const DATETIME_FORMAT = 'YYYY-MM-DD HH:mm:ss' +export function expandPath(filepath: string) { + let out = '' + for (const ch of filepath) { + if (ch === '~') { + out += os.homedir(); + } else { + out += ch; + } + } + return out; +} export function verbose(message: string) { - console.error(chalk.gray('[') + chalk.magenta('verb') + ' ' + chalk.gray(moment().format(DATETIME_FORMAT) + ']') + ' ' + message); + console.error(chalk.gray('[') + chalk.magenta('verb') + ' ' + chalk.gray(moment().format(LOG_DATETIME_FORMAT) + ']') + ' ' + message); } export function warn(message: string) { console.error(chalk.gray('[') + chalk.red('warn') + ' ' + chalk.gray(moment().format(DATETIME_FORMAT) + ']') + ' ' + message); } +export function error(message: string) { + console.error(chalk.gray('[') + chalk.red('erro') + ' ' + chalk.gray(moment().format(DATETIME_FORMAT) + ']') + ' ' + message); +} + export function upsearchSync(filename: string, startDir = '.') { let currDir = startDir; while (true) { diff --git a/stdlib/Boltfile b/stdlib/Boltfile index 8b1378917..2e234fef1 100644 --- a/stdlib/Boltfile +++ b/stdlib/Boltfile @@ -1 +1,3 @@ - +name: stdlib +version: 0.0.1 +auto-import: true \ No newline at end of file diff --git a/stdlib/io.bolt b/stdlib/io.bolt index f51bafece..6cd9910ea 100644 --- a/stdlib/io.bolt +++ b/stdlib/io.bolt @@ -1,11 +1,11 @@ -import "./numbers" -import "./either" -import "./vec" -import "./string" - pub mod IO { + import "./numbers" + import "./either" + import "./vec" + import "./string" + pub type Result = Either; pub foreign "JS" fn print(message: String) { diff --git a/stdlib/lib.bolt b/stdlib/lib.bolt index ad89f8c7a..a30694825 100644 --- a/stdlib/lib.bolt +++ b/stdlib/lib.bolt @@ -2,6 +2,7 @@ pub import "./option" pub import "./either" pub import "./string" +pub import "./numbers" pub import "./math" pub import "./vec" pub import "./lang/bolt" diff --git a/stdlib/math.bolt b/stdlib/math.bolt index 1ba6e9cc8..0324b088a 100644 --- a/stdlib/math.bolt +++ b/stdlib/math.bolt @@ -1,4 +1,6 @@ +import "./numbers.bolt"; + // precedence a + b < a * b; pub fn fac(n: I) -> I where I: int {