mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-14 16:35:03 +01:00
rename AST items
This commit is contained in:
parent
f05e5520f3
commit
cdbb26352e
6 changed files with 44 additions and 44 deletions
|
|
@ -51,7 +51,7 @@ module.exports = {
|
||||||
// This lint is horrible with noisy false positives every time there are typescript errors.
|
// This lint is horrible with noisy false positives every time there are typescript errors.
|
||||||
"@typescript-eslint/no-unsafe-return": "off",
|
"@typescript-eslint/no-unsafe-return": "off",
|
||||||
"@typescript-eslint/no-unsafe-assignment": "off",
|
"@typescript-eslint/no-unsafe-assignment": "off",
|
||||||
"eslint@typescript-eslint/no-unsafe-argument": "off",
|
"@typescript-eslint/no-unsafe-argument": "off",
|
||||||
|
|
||||||
// Useful extra lints that are not on by default:
|
// Useful extra lints that are not on by default:
|
||||||
"@typescript-eslint/explicit-module-boundary-types": "warn",
|
"@typescript-eslint/explicit-module-boundary-types": "warn",
|
||||||
|
|
|
||||||
24
src/ast.ts
24
src/ast.ts
|
|
@ -100,27 +100,27 @@ export class ItemId {
|
||||||
export type ItemKind<P extends Phase> =
|
export type ItemKind<P extends Phase> =
|
||||||
| {
|
| {
|
||||||
kind: "function";
|
kind: "function";
|
||||||
node: FunctionDef<P>;
|
node: ItemFunction<P>;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
kind: "type";
|
kind: "type";
|
||||||
node: TypeDef<P>;
|
node: ItemType<P>;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
kind: "import";
|
kind: "import";
|
||||||
node: ImportDef<P>;
|
node: ItemImport<P>;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
kind: "mod";
|
kind: "mod";
|
||||||
node: ModItem<P>;
|
node: ItemMod<P>;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
kind: "extern";
|
kind: "extern";
|
||||||
node: ExternItem;
|
node: ItemExtern;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
kind: "global";
|
kind: "global";
|
||||||
node: GlobalItem<P>;
|
node: ItemGlobal<P>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Item<P extends Phase> = ItemKind<P> & {
|
export type Item<P extends Phase> = ItemKind<P> & {
|
||||||
|
|
@ -128,7 +128,7 @@ export type Item<P extends Phase> = ItemKind<P> & {
|
||||||
id: ItemId;
|
id: ItemId;
|
||||||
} & P["defPath"];
|
} & P["defPath"];
|
||||||
|
|
||||||
export type FunctionDef<P extends Phase> = {
|
export type ItemFunction<P extends Phase> = {
|
||||||
name: string;
|
name: string;
|
||||||
params: FunctionArg<P>[];
|
params: FunctionArg<P>[];
|
||||||
body: Expr<P>;
|
body: Expr<P>;
|
||||||
|
|
@ -142,7 +142,7 @@ export type FunctionArg<P extends Phase> = {
|
||||||
span: Span;
|
span: Span;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TypeDef<P extends Phase> = {
|
export type ItemType<P extends Phase> = {
|
||||||
name: string;
|
name: string;
|
||||||
type: TypeDefKind<P>;
|
type: TypeDefKind<P>;
|
||||||
ty?: TyStruct;
|
ty?: TyStruct;
|
||||||
|
|
@ -163,7 +163,7 @@ export type FieldDef<P extends Phase> = {
|
||||||
type: Type<P>;
|
type: Type<P>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ImportDef<P extends Phase> = {
|
export type ItemImport<P extends Phase> = {
|
||||||
module: StringLiteral;
|
module: StringLiteral;
|
||||||
func: StringLiteral;
|
func: StringLiteral;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -172,14 +172,14 @@ export type ImportDef<P extends Phase> = {
|
||||||
ty?: TyFn;
|
ty?: TyFn;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ModItem<P extends Phase> = {
|
export type ItemMod<P extends Phase> = {
|
||||||
name: string;
|
name: string;
|
||||||
contents: Item<P>[];
|
contents: Item<P>[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ExternItem = { name: string };
|
export type ItemExtern = { name: string };
|
||||||
|
|
||||||
export type GlobalItem<P extends Phase> = {
|
export type ItemGlobal<P extends Phase> = {
|
||||||
name: string;
|
name: string;
|
||||||
type: Type<P>;
|
type: Type<P>;
|
||||||
init: Expr<P>;
|
init: Expr<P>;
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ import {
|
||||||
Expr,
|
Expr,
|
||||||
ExprBlock,
|
ExprBlock,
|
||||||
Folder,
|
Folder,
|
||||||
FunctionDef,
|
ItemFunction,
|
||||||
GlobalItem,
|
ItemGlobal,
|
||||||
ImportDef,
|
ItemImport,
|
||||||
Item,
|
Item,
|
||||||
ItemId,
|
ItemId,
|
||||||
LoopId,
|
LoopId,
|
||||||
|
|
@ -261,7 +261,7 @@ export function lower(gcx: GlobalContext): wasm.Module {
|
||||||
function lowerImport(
|
function lowerImport(
|
||||||
cx: Context,
|
cx: Context,
|
||||||
item: Item<Typecked>,
|
item: Item<Typecked>,
|
||||||
def: ImportDef<Typecked>,
|
def: ItemImport<Typecked>,
|
||||||
) {
|
) {
|
||||||
const existing = cx.mod.imports.findIndex(
|
const existing = cx.mod.imports.findIndex(
|
||||||
(imp) => imp.module === def.module.value && imp.name === def.func.value,
|
(imp) => imp.module === def.module.value && imp.name === def.func.value,
|
||||||
|
|
@ -292,7 +292,7 @@ function lowerImport(
|
||||||
function lowerGlobal(
|
function lowerGlobal(
|
||||||
cx: Context,
|
cx: Context,
|
||||||
item: Item<Typecked>,
|
item: Item<Typecked>,
|
||||||
def: GlobalItem<Typecked>,
|
def: ItemGlobal<Typecked>,
|
||||||
) {
|
) {
|
||||||
const globalIdx = cx.mod.globals.length;
|
const globalIdx = cx.mod.globals.length;
|
||||||
|
|
||||||
|
|
@ -329,7 +329,7 @@ function lowerGlobal(
|
||||||
type FuncContext = {
|
type FuncContext = {
|
||||||
cx: Context;
|
cx: Context;
|
||||||
item: Item<Typecked>;
|
item: Item<Typecked>;
|
||||||
func: FunctionDef<Typecked>;
|
func: ItemFunction<Typecked>;
|
||||||
wasmType: wasm.FuncType;
|
wasmType: wasm.FuncType;
|
||||||
wasm: wasm.Func;
|
wasm: wasm.Func;
|
||||||
varLocations: VarLocation[];
|
varLocations: VarLocation[];
|
||||||
|
|
@ -358,7 +358,7 @@ type StructLayout = {
|
||||||
function lowerFunc(
|
function lowerFunc(
|
||||||
cx: Context,
|
cx: Context,
|
||||||
item: Item<Typecked>,
|
item: Item<Typecked>,
|
||||||
func: FunctionDef<Typecked>,
|
func: ItemFunction<Typecked>,
|
||||||
) {
|
) {
|
||||||
const abi = computeAbi(func.ty!);
|
const abi = computeAbi(func.ty!);
|
||||||
const { type: wasmType, paramLocations } = wasmTypeForAbi(abi, func.ty!);
|
const { type: wasmType, paramLocations } = wasmTypeForAbi(abi, func.ty!);
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,14 @@ import {
|
||||||
FieldDef,
|
FieldDef,
|
||||||
Folder,
|
Folder,
|
||||||
FunctionArg,
|
FunctionArg,
|
||||||
FunctionDef,
|
ItemFunction,
|
||||||
Ident,
|
Ident,
|
||||||
ImportDef,
|
ItemImport,
|
||||||
Item,
|
Item,
|
||||||
LOGICAL_KINDS,
|
LOGICAL_KINDS,
|
||||||
ModItem,
|
ItemMod,
|
||||||
Type,
|
Type,
|
||||||
TypeDef,
|
ItemType,
|
||||||
UNARY_KINDS,
|
UNARY_KINDS,
|
||||||
UnaryKind,
|
UnaryKind,
|
||||||
binaryExprPrecedenceClass,
|
binaryExprPrecedenceClass,
|
||||||
|
|
@ -27,9 +27,9 @@ import {
|
||||||
superFoldItem,
|
superFoldItem,
|
||||||
Built,
|
Built,
|
||||||
Parsed,
|
Parsed,
|
||||||
ExternItem,
|
ItemExtern,
|
||||||
ItemId,
|
ItemId,
|
||||||
GlobalItem,
|
ItemGlobal,
|
||||||
StructLiteralField,
|
StructLiteralField,
|
||||||
TypeDefKind,
|
TypeDefKind,
|
||||||
} from "./ast";
|
} from "./ast";
|
||||||
|
|
@ -89,7 +89,7 @@ function parseItem(t: State): [State, Item<Parsed>] {
|
||||||
|
|
||||||
[t] = expectNext(t, ";");
|
[t] = expectNext(t, ";");
|
||||||
|
|
||||||
const def: FunctionDef<Parsed> = {
|
const def: ItemFunction<Parsed> = {
|
||||||
...sig,
|
...sig,
|
||||||
body,
|
body,
|
||||||
};
|
};
|
||||||
|
|
@ -145,7 +145,7 @@ function parseItem(t: State): [State, Item<Parsed>] {
|
||||||
|
|
||||||
[t] = expectNext(t, ";");
|
[t] = expectNext(t, ";");
|
||||||
|
|
||||||
const def: TypeDef<Parsed> = {
|
const def: ItemType<Parsed> = {
|
||||||
name: name.ident,
|
name: name.ident,
|
||||||
type,
|
type,
|
||||||
};
|
};
|
||||||
|
|
@ -167,7 +167,7 @@ function parseItem(t: State): [State, Item<Parsed>] {
|
||||||
|
|
||||||
[t] = expectNext(t, ";");
|
[t] = expectNext(t, ";");
|
||||||
|
|
||||||
const def: ImportDef<Parsed> = {
|
const def: ItemImport<Parsed> = {
|
||||||
module: { kind: "str", value: module.value, span: module.span },
|
module: { kind: "str", value: module.value, span: module.span },
|
||||||
func: { kind: "str", value: func.value, span: func.span },
|
func: { kind: "str", value: func.value, span: func.span },
|
||||||
...sig,
|
...sig,
|
||||||
|
|
@ -182,7 +182,7 @@ function parseItem(t: State): [State, Item<Parsed>] {
|
||||||
let name;
|
let name;
|
||||||
[t, name] = expectNext<TokenIdent>(t, "identifier");
|
[t, name] = expectNext<TokenIdent>(t, "identifier");
|
||||||
|
|
||||||
const node: ExternItem = {
|
const node: ItemExtern = {
|
||||||
name: name.ident,
|
name: name.ident,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -221,7 +221,7 @@ function parseItem(t: State): [State, Item<Parsed>] {
|
||||||
|
|
||||||
[t] = expectNext(t, ";");
|
[t] = expectNext(t, ";");
|
||||||
|
|
||||||
const node: ModItem<Parsed> = {
|
const node: ItemMod<Parsed> = {
|
||||||
name: name.ident,
|
name: name.ident,
|
||||||
contents,
|
contents,
|
||||||
};
|
};
|
||||||
|
|
@ -238,7 +238,7 @@ function parseItem(t: State): [State, Item<Parsed>] {
|
||||||
[t, init] = parseExpr(t);
|
[t, init] = parseExpr(t);
|
||||||
[t] = expectNext(t, ";");
|
[t] = expectNext(t, ";");
|
||||||
|
|
||||||
const node: GlobalItem<Parsed> = {
|
const node: ItemGlobal<Parsed> = {
|
||||||
name: name.ident,
|
name: name.ident,
|
||||||
type,
|
type,
|
||||||
init,
|
init,
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,16 @@ import {
|
||||||
AnyPhase,
|
AnyPhase,
|
||||||
Crate,
|
Crate,
|
||||||
Expr,
|
Expr,
|
||||||
FunctionDef,
|
ItemFunction,
|
||||||
IdentWithRes,
|
IdentWithRes,
|
||||||
ImportDef,
|
ItemImport,
|
||||||
Item,
|
Item,
|
||||||
ModItem,
|
ItemMod,
|
||||||
Resolution,
|
Resolution,
|
||||||
StringLiteral,
|
StringLiteral,
|
||||||
Ty,
|
Ty,
|
||||||
Type,
|
Type,
|
||||||
TypeDef,
|
ItemType,
|
||||||
tyIsUnit,
|
tyIsUnit,
|
||||||
} from "./ast";
|
} from "./ast";
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ function printItem(item: Item<AnyPhase>): string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function printFunction(func: FunctionDef<AnyPhase>): string {
|
function printFunction(func: ItemFunction<AnyPhase>): string {
|
||||||
const args = func.params
|
const args = func.params
|
||||||
.map(({ name, type }) => `${name}: ${printType(type)}`)
|
.map(({ name, type }) => `${name}: ${printType(type)}`)
|
||||||
.join(", ");
|
.join(", ");
|
||||||
|
|
@ -62,7 +62,7 @@ function printFunction(func: FunctionDef<AnyPhase>): string {
|
||||||
return `function ${func.name}(${args})${ret} = ${printExpr(func.body, 0)};`;
|
return `function ${func.name}(${args})${ret} = ${printExpr(func.body, 0)};`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function printTypeDef(type: TypeDef<AnyPhase>): string {
|
function printTypeDef(type: ItemType<AnyPhase>): string {
|
||||||
switch (type.type.kind) {
|
switch (type.type.kind) {
|
||||||
case "struct": {
|
case "struct": {
|
||||||
const { fields } = type.type;
|
const { fields } = type.type;
|
||||||
|
|
@ -81,7 +81,7 @@ function printTypeDef(type: TypeDef<AnyPhase>): string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function printImportDef(def: ImportDef<AnyPhase>): string {
|
function printImportDef(def: ItemImport<AnyPhase>): string {
|
||||||
const args = def.params
|
const args = def.params
|
||||||
.map(({ name, type }) => `${name}: ${printType(type)}`)
|
.map(({ name, type }) => `${name}: ${printType(type)}`)
|
||||||
.join(", ");
|
.join(", ");
|
||||||
|
|
@ -92,7 +92,7 @@ function printImportDef(def: ImportDef<AnyPhase>): string {
|
||||||
)}(${args})${ret};`;
|
)}(${args})${ret};`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function printMod(mod: ModItem<AnyPhase>): string {
|
function printMod(mod: ItemMod<AnyPhase>): string {
|
||||||
return `mod ${mod.name} (\n${mod.contents.map(printItem).join("\n ")});`;
|
return `mod ${mod.name} (\n${mod.contents.map(printItem).join("\n ")});`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,14 @@ import {
|
||||||
Item,
|
Item,
|
||||||
ItemId,
|
ItemId,
|
||||||
LocalInfo,
|
LocalInfo,
|
||||||
ModItem,
|
ItemMod,
|
||||||
Resolution,
|
Resolution,
|
||||||
Resolved,
|
Resolved,
|
||||||
mkDefaultFolder,
|
mkDefaultFolder,
|
||||||
superFoldExpr,
|
superFoldExpr,
|
||||||
superFoldItem,
|
superFoldItem,
|
||||||
superFoldType,
|
superFoldType,
|
||||||
ExternItem,
|
ItemExtern,
|
||||||
} from "./ast";
|
} from "./ast";
|
||||||
import { GlobalContext } from "./context";
|
import { GlobalContext } from "./context";
|
||||||
import { CompilerError, Span } from "./error";
|
import { CompilerError, Span } from "./error";
|
||||||
|
|
@ -43,7 +43,7 @@ function loadCrate(cx: Context, name: string, span: Span): Map<string, ItemId> {
|
||||||
|
|
||||||
function resolveModItem(
|
function resolveModItem(
|
||||||
cx: Context,
|
cx: Context,
|
||||||
mod: ModItem<Built> | ExternItem,
|
mod: ItemMod<Built> | ItemExtern,
|
||||||
item: Item<Built>,
|
item: Item<Built>,
|
||||||
name: string,
|
name: string,
|
||||||
): ItemId | undefined {
|
): ItemId | undefined {
|
||||||
|
|
@ -204,7 +204,7 @@ function resolveModule(
|
||||||
|
|
||||||
loadCrate(cx, item.node.name, item.span);
|
loadCrate(cx, item.node.name, item.span);
|
||||||
|
|
||||||
const node: ExternItem = {
|
const node: ItemExtern = {
|
||||||
...item.node,
|
...item.node,
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue