diff --git a/src/ast-spec.txt b/src/ast-spec.txt index d7e479668..abc81dfab 100644 --- a/src/ast-spec.txt +++ b/src/ast-spec.txt @@ -120,7 +120,7 @@ node BoltLiftedTypeExpression > BoltTypeExpression { node BoltTypeParameter { index: usize, name: BoltIdentifier, - typeNode: Option, + typeExpr: Option, defaultType: Option, } @@ -131,7 +131,7 @@ node BoltBindPattern > BoltPattern { } node BoltTypePattern > BoltPattern { - type: BoltTypeExpression, + typeExpr: BoltTypeExpression, nestedPattern: BoltPattern, } @@ -246,7 +246,7 @@ node BoltExpressionStatement > BoltStatement { node BoltParameter { index: usize, bindings: BoltPattern, - type: Option, + typeExpr: Option, defaultValue: Option, } @@ -280,7 +280,7 @@ node BoltFunctionDeclaration > BoltFunctionBodyElement, BoltDeclaration { node BoltVariableDeclaration > BoltFunctionBodyElement, BoltDeclaration { modifiers: BoltModifiers, bindings: BoltPattern, - type: Option, + typeExpr: Option, value: Option, } @@ -335,7 +335,7 @@ node BoltRecordMember; node BoltRecordField > BoltRecordMember { name: BoltIdentifier, - type: BoltTypeExpression, + typeExpr: BoltTypeExpression, } node BoltRecordDeclaration > BoltDeclaration, BoltTypeDeclaration { diff --git a/src/ast.d.ts b/src/ast.d.ts index e6ef1ea2d..09284b669 100644 --- a/src/ast.d.ts +++ b/src/ast.d.ts @@ -1,5 +1,5 @@ -import { Type } from "./checker" +import { Type } from "./types" import { Package } from "./common" import { TextSpan } from "./text" @@ -2941,7 +2941,7 @@ export interface BoltTypeParameter extends SyntaxBase { kind: SyntaxKind.BoltTypeParameter; index: number; name: BoltIdentifier; - typeNode: BoltTypeExpression | null; + typeExpr: BoltTypeExpression | null; defaultType: BoltTypeExpression | null; parentNode: BoltTypeParameterParent; getChildNodes(): IterableIterator @@ -3020,7 +3020,7 @@ export type BoltBindPatternChild export interface BoltTypePattern extends SyntaxBase { kind: SyntaxKind.BoltTypePattern; - type: BoltTypeExpression; + typeExpr: BoltTypeExpression; nestedPattern: BoltPattern; parentNode: BoltTypePatternParent; getChildNodes(): IterableIterator @@ -4250,7 +4250,7 @@ export interface BoltParameter extends SyntaxBase { kind: SyntaxKind.BoltParameter; index: number; bindings: BoltPattern; - type: BoltTypeExpression | null; + typeExpr: BoltTypeExpression | null; defaultValue: BoltExpression | null; parentNode: BoltParameterParent; getChildNodes(): IterableIterator @@ -4380,7 +4380,7 @@ export interface BoltVariableDeclaration extends SyntaxBase { kind: SyntaxKind.BoltVariableDeclaration; modifiers: BoltModifiers; bindings: BoltPattern; - type: BoltTypeExpression | null; + typeExpr: BoltTypeExpression | null; value: BoltExpression | null; parentNode: BoltVariableDeclarationParent; getChildNodes(): IterableIterator @@ -4622,7 +4622,7 @@ export type BoltRecordMember export interface BoltRecordField extends SyntaxBase { kind: SyntaxKind.BoltRecordField; name: BoltIdentifier; - type: BoltTypeExpression; + typeExpr: BoltTypeExpression; parentNode: BoltRecordFieldParent; getChildNodes(): IterableIterator } @@ -7884,9 +7884,9 @@ export function createBoltModulePath(isAbsolute: boolean, elements: BoltIdentifi 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; -export function createBoltTypeParameter(index: number, name: BoltIdentifier, typeNode: BoltTypeExpression | null, defaultType: BoltTypeExpression | null, span?: TextSpan | null): BoltTypeParameter; +export function createBoltTypeParameter(index: number, name: BoltIdentifier, typeExpr: BoltTypeExpression | null, defaultType: BoltTypeExpression | null, span?: TextSpan | null): BoltTypeParameter; export function createBoltBindPattern(name: BoltIdentifier, span?: TextSpan | null): BoltBindPattern; -export function createBoltTypePattern(type: BoltTypeExpression, nestedPattern: BoltPattern, span?: TextSpan | null): BoltTypePattern; +export function createBoltTypePattern(typeExpr: BoltTypeExpression, nestedPattern: BoltPattern, span?: TextSpan | null): BoltTypePattern; export function createBoltExpressionPattern(expression: BoltExpression, span?: TextSpan | null): BoltExpressionPattern; export function createBoltTuplePatternElement(index: number, pattern: BoltPattern, span?: TextSpan | null): BoltTuplePatternElement; export function createBoltTuplePattern(elements: BoltTuplePatternElement[], span?: TextSpan | null): BoltTuplePattern; @@ -7910,10 +7910,10 @@ export function createBoltConditionalCase(test: BoltExpression | null, body: Bol export function createBoltConditionalStatement(cases: BoltConditionalCase[], span?: TextSpan | null): BoltConditionalStatement; export function createBoltResumeStatement(value: BoltExpression, span?: TextSpan | null): BoltResumeStatement; export function createBoltExpressionStatement(expression: BoltExpression, span?: TextSpan | null): BoltExpressionStatement; -export function createBoltParameter(index: number, bindings: BoltPattern, type: BoltTypeExpression | null, defaultValue: BoltExpression | null, span?: TextSpan | null): BoltParameter; +export function createBoltParameter(index: number, bindings: BoltPattern, typeExpr: BoltTypeExpression | null, defaultValue: BoltExpression | null, span?: TextSpan | null): BoltParameter; export function createBoltModule(modifiers: BoltModifiers, name: BoltIdentifier[], elements: BoltSourceElement[], span?: TextSpan | null): BoltModule; 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, type: BoltTypeExpression | null, value: BoltExpression | null, span?: TextSpan | null): BoltVariableDeclaration; +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 createBoltExportSymbol(span?: TextSpan | null): BoltExportSymbol; @@ -7922,7 +7922,7 @@ export function createBoltExportDirective(file: string, symbols: BoltExportSymbo export function createBoltTraitDeclaration(modifiers: BoltModifiers, name: BoltIdentifier, typeParams: BoltTypeParameter[] | null, elements: BoltDeclaration[], span?: TextSpan | null): BoltTraitDeclaration; export function createBoltImplDeclaration(modifiers: BoltModifiers, name: BoltIdentifier, trait: BoltTypeExpression, typeParams: BoltTypeParameter[] | null, elements: BoltDeclaration[], span?: TextSpan | null): BoltImplDeclaration; export function createBoltTypeAliasDeclaration(modifiers: BoltModifiers, name: BoltIdentifier, typeParams: BoltTypeParameter[] | null, typeExpr: BoltTypeExpression, span?: TextSpan | null): BoltTypeAliasDeclaration; -export function createBoltRecordField(name: BoltIdentifier, type: BoltTypeExpression, span?: TextSpan | null): BoltRecordField; +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; diff --git a/src/checks.ts b/src/checks.ts index 97b343e14..72454b78f 100644 --- a/src/checks.ts +++ b/src/checks.ts @@ -23,7 +23,7 @@ export class CheckInvalidFilePaths extends NodeVisitor { const sourceFile = this.program.resolveToSourceFile(node.file.value, node); if (sourceFile === null) { this.diagnostics.add({ - severity: 'error', + severity: 'fatal', message: E_FILE_NOT_FOUND, args: { filename: node.file.value }, node: node.file, @@ -62,7 +62,7 @@ export class CheckReferences extends NodeVisitor { const sym = currScope!.getLocalSymbol(name.text);; if (sym === null) { failedToFindScope = true; - partiallyMatchingModules.push((currScope!.source) as NodeScopeSource).node); + partiallyMatchingModules.push(((currScope!.source) as NodeScopeSource).node); break; } assert(every(sym.declarations.values(), decl => decl.kind === SyntaxKind.BoltModule)); @@ -115,7 +115,7 @@ export class CheckReferences extends NodeVisitor { } protected visitBoltReferenceTypeExpression(node: BoltReferenceTypeExpression) { - const scope = this.resolver.getScopeForNode(node, ScopeType.Type); + const scope = this.resolver.getScopeSurroundingNode(node, ScopeType.Type); assert(scope !== null); const symbolPath = getSymbolPathFromNode(node.name); const resolvedSym = this.resolver.resolveSymbolPath(symbolPath, scope!); diff --git a/src/diagnostics.ts b/src/diagnostics.ts index 62d71deec..26ba05cbd 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -40,7 +40,8 @@ function firstIndexOfNonEmpty(str: string) { export class DiagnosticPrinter { - public hasErrors = false; + public hasErrors = false + public hasFatal = false; public add(diagnostic: Diagnostic): void { @@ -61,6 +62,9 @@ export class DiagnosticPrinter { this.hasErrors = true; out += chalk.bold.red('error: '); break; + case 'fatal': + this.hasFatal = true; + out += chalk.bold.red('fatal:' ); case 'warning': this.hasErrors = true; out += chalk.bold.red('warning: '); diff --git a/src/parser.ts b/src/parser.ts index 2c440840b..8177582cf 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -373,8 +373,8 @@ export class Parser { const t1 = tokens.get(); assertToken(t1, SyntaxKind.BoltStringLiteral); - const symbols: BoltImportSymbol[] = []; - const t2 = tokens.get(); + const symbols = null; + const t2 = tokens.peek(); if (t2.kind === SyntaxKind.BoltParenthesized) { // TODO implement grammar and parsing logic for symbols } diff --git a/src/resolver.ts b/src/resolver.ts index 90e38fb21..35dbac02f 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -518,13 +518,7 @@ export class SymbolResolver { // Once we've handled any module path that might have been present, // we resolve the actual symbol using a helper method. - const sym = scope.getSymbol(path.name); - - if (sym === null) { - return null; - } - - return sym; + return scope.getSymbol(path.name); } } diff --git a/src/transforms/index.ts b/src/transforms/index.ts index dd61b6363..7d6467bb5 100644 --- a/src/transforms/index.ts +++ b/src/transforms/index.ts @@ -1,6 +1,6 @@ import { Program } from "../program" -import { Container, Newable } from "../di" +import { Container, Newable } from "../ioc" import {SourceFile} from "../ast"; export interface Transformer { diff --git a/src/treegen/ast.dts.template b/src/treegen/ast.dts.template index 42e4826b4..84f3b1f8d 100644 --- a/src/treegen/ast.dts.template +++ b/src/treegen/ast.dts.template @@ -1,5 +1,5 @@ -import { Type } from "./checker" +import { Type } from "./types" import { Package } from "./common" import { TextSpan } from "./text" diff --git a/src/types.ts b/src/types.ts index 8b8c99f40..b95984754 100644 --- a/src/types.ts +++ b/src/types.ts @@ -292,20 +292,23 @@ export class TypeChecker { case SyntaxKind.BoltFunctionExpression: { const paramTypes = node.params.map(param => { - if (param.type === null) { + if (param.typeExpr === null) { return this.anyType; } - return this.createInitialTypeForTypeExpression(param.type); + return this.createInitialTypeForTypeExpression(param.typeExpr); }); let returnType = node.returnType === null ? this.anyType : this.createInitialTypeForTypeExpression(node.returnType); - const funcType = new FunctionType(paramTypes, returnType); + resultType = new FunctionType(paramTypes, returnType); break; } case SyntaxKind.BoltQuoteExpression: - return this.syntaxType; + { + resultType = this.syntaxType; + break + } case SyntaxKind.BoltMemberExpression: case SyntaxKind.BoltReferenceExpression: