diff --git a/doc/lang.md b/doc/lang.md index e54c5bc..7b6f24d 100644 --- a/doc/lang.md +++ b/doc/lang.md @@ -10,7 +10,7 @@ A Riverdelta program consists of many items, like functions. Every item ends wit semicolon. ```js -item = item_function | item_type | item_import | item_extern | item_mod +item = item_function | item_type | item_import | item_extern | item_mod; ``` ### Functions @@ -25,6 +25,7 @@ item_function := "function" function_sig "=" expr ";" ```js function helloWorld() = ; ``` + ```js function block() = ( 1; @@ -136,7 +137,6 @@ the module statement. `.nil` files cannot declare file submodules but only inline modules. If the current file is `a/a.mod.nil`, then `mod foo;` will look for `a/b.nil` or `a/b/b.mod.nil`. - ### Globals Globals are mutable values. @@ -153,4 +153,4 @@ They can be accessed like local variables. Their initial value must be literal e ## Expressions -there are many expressions and im not going to list a single one. \ No newline at end of file +there are many expressions and im not going to list a single one. diff --git a/src/resolve.ts b/src/resolve.ts index e288ad2..0827c99 100644 --- a/src/resolve.ts +++ b/src/resolve.ts @@ -133,7 +133,7 @@ function resolveModule( for (let i = tyParamScopes.length - 1; i >= 0; i--) { const candidate = tyParamScopes[i]; - + if (candidate === ident.name) { return { kind: "tyParam", @@ -228,7 +228,7 @@ function resolveModule( }; } case "type": { - tyParamScopes = item.generics.map(({name}) => name); + tyParamScopes = item.generics.map(({ name }) => name); const type = { ...superFoldItem(item, this) }; diff --git a/src/typeck/expr.ts b/src/typeck/expr.ts index 4fe35fc..f27b8e0 100644 --- a/src/typeck/expr.ts +++ b/src/typeck/expr.ts @@ -1,5 +1,5 @@ import { - BuiltinName, + BuiltinName, COMPARISON_KINDS, Crate, EQUALITY_KINDS, @@ -29,7 +29,15 @@ import { import { CompilerError, ErrorEmitted, Span, unreachable } from "../error"; import { printTy } from "../printer"; import { InferContext } from "./infer"; -import { TypeckCtx, emitError, lowerAstTy, mkTyFn, tyError, tyErrorFrom, typeOfItem } from "./item"; +import { + TypeckCtx, + emitError, + lowerAstTy, + mkTyFn, + tyError, + tyErrorFrom, + typeOfItem, +} from "./item"; export function exprError(err: ErrorEmitted, span: Span): Expr { return { @@ -41,36 +49,35 @@ export function exprError(err: ErrorEmitted, span: Span): Expr { } type FuncCtx = { - cx: TypeckCtx; - infcx: InferContext; - localTys: Ty[]; - loopState: LoopState[]; - checkExpr: (expr: Expr) => Expr; - }; - - type LoopState = { hasBreak: boolean; loopId: LoopId }; - - function typeOfValue(fcx: FuncCtx, res: Resolution, span: Span): Ty { - switch (res.kind) { - case "local": { - const idx = fcx.localTys.length - 1 - res.index; - return fcx.localTys[idx]; - } - case "item": { - return typeOfItem(fcx.cx, res.id, [], span); - } - case "builtin": - return typeOfBuiltinValue(fcx, res.name, span); - case "tyParam": - return tyError( - fcx.cx, - new CompilerError(`type parameter cannot be used as value`, span), - ); - case "error": - return tyErrorFrom(res); + cx: TypeckCtx; + infcx: InferContext; + localTys: Ty[]; + loopState: LoopState[]; + checkExpr: (expr: Expr) => Expr; +}; + +type LoopState = { hasBreak: boolean; loopId: LoopId }; + +function typeOfValue(fcx: FuncCtx, res: Resolution, span: Span): Ty { + switch (res.kind) { + case "local": { + const idx = fcx.localTys.length - 1 - res.index; + return fcx.localTys[idx]; } + case "item": { + return typeOfItem(fcx.cx, res.id, [], span); + } + case "builtin": + return typeOfBuiltinValue(fcx, res.name, span); + case "tyParam": + return tyError( + fcx.cx, + new CompilerError(`type parameter cannot be used as value`, span), + ); + case "error": + return tyErrorFrom(res); } - +} export function typeOfBuiltinValue( fcx: FuncCtx, diff --git a/src/typeck/index.ts b/src/typeck/index.ts index fb6dd25..a319520 100644 --- a/src/typeck/index.ts +++ b/src/typeck/index.ts @@ -1,4 +1,19 @@ -import { Crate, Expr, Folder, Item, ItemId, Resolved, TY_I32, TY_INT, Ty, TyFn, Typecked, foldAst, mkDefaultFolder, tyIsUnit } from "../ast"; +import { + Crate, + Expr, + Folder, + Item, + ItemId, + Resolved, + TY_I32, + TY_INT, + Ty, + TyFn, + Typecked, + foldAst, + mkDefaultFolder, + tyIsUnit, +} from "../ast"; import { GlobalContext } from "../context"; import { CompilerError, ErrorEmitted, Span } from "../error"; import { ComplexMap } from "../utils";