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.
|
||||
"@typescript-eslint/no-unsafe-return": "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:
|
||||
"@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> =
|
||||
| {
|
||||
kind: "function";
|
||||
node: FunctionDef<P>;
|
||||
node: ItemFunction<P>;
|
||||
}
|
||||
| {
|
||||
kind: "type";
|
||||
node: TypeDef<P>;
|
||||
node: ItemType<P>;
|
||||
}
|
||||
| {
|
||||
kind: "import";
|
||||
node: ImportDef<P>;
|
||||
node: ItemImport<P>;
|
||||
}
|
||||
| {
|
||||
kind: "mod";
|
||||
node: ModItem<P>;
|
||||
node: ItemMod<P>;
|
||||
}
|
||||
| {
|
||||
kind: "extern";
|
||||
node: ExternItem;
|
||||
node: ItemExtern;
|
||||
}
|
||||
| {
|
||||
kind: "global";
|
||||
node: GlobalItem<P>;
|
||||
node: ItemGlobal<P>;
|
||||
};
|
||||
|
||||
export type Item<P extends Phase> = ItemKind<P> & {
|
||||
|
|
@ -128,7 +128,7 @@ export type Item<P extends Phase> = ItemKind<P> & {
|
|||
id: ItemId;
|
||||
} & P["defPath"];
|
||||
|
||||
export type FunctionDef<P extends Phase> = {
|
||||
export type ItemFunction<P extends Phase> = {
|
||||
name: string;
|
||||
params: FunctionArg<P>[];
|
||||
body: Expr<P>;
|
||||
|
|
@ -142,7 +142,7 @@ export type FunctionArg<P extends Phase> = {
|
|||
span: Span;
|
||||
};
|
||||
|
||||
export type TypeDef<P extends Phase> = {
|
||||
export type ItemType<P extends Phase> = {
|
||||
name: string;
|
||||
type: TypeDefKind<P>;
|
||||
ty?: TyStruct;
|
||||
|
|
@ -163,7 +163,7 @@ export type FieldDef<P extends Phase> = {
|
|||
type: Type<P>;
|
||||
};
|
||||
|
||||
export type ImportDef<P extends Phase> = {
|
||||
export type ItemImport<P extends Phase> = {
|
||||
module: StringLiteral;
|
||||
func: StringLiteral;
|
||||
name: string;
|
||||
|
|
@ -172,14 +172,14 @@ export type ImportDef<P extends Phase> = {
|
|||
ty?: TyFn;
|
||||
};
|
||||
|
||||
export type ModItem<P extends Phase> = {
|
||||
export type ItemMod<P extends Phase> = {
|
||||
name: string;
|
||||
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;
|
||||
type: Type<P>;
|
||||
init: Expr<P>;
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ import {
|
|||
Expr,
|
||||
ExprBlock,
|
||||
Folder,
|
||||
FunctionDef,
|
||||
GlobalItem,
|
||||
ImportDef,
|
||||
ItemFunction,
|
||||
ItemGlobal,
|
||||
ItemImport,
|
||||
Item,
|
||||
ItemId,
|
||||
LoopId,
|
||||
|
|
@ -261,7 +261,7 @@ export function lower(gcx: GlobalContext): wasm.Module {
|
|||
function lowerImport(
|
||||
cx: Context,
|
||||
item: Item<Typecked>,
|
||||
def: ImportDef<Typecked>,
|
||||
def: ItemImport<Typecked>,
|
||||
) {
|
||||
const existing = cx.mod.imports.findIndex(
|
||||
(imp) => imp.module === def.module.value && imp.name === def.func.value,
|
||||
|
|
@ -292,7 +292,7 @@ function lowerImport(
|
|||
function lowerGlobal(
|
||||
cx: Context,
|
||||
item: Item<Typecked>,
|
||||
def: GlobalItem<Typecked>,
|
||||
def: ItemGlobal<Typecked>,
|
||||
) {
|
||||
const globalIdx = cx.mod.globals.length;
|
||||
|
||||
|
|
@ -329,7 +329,7 @@ function lowerGlobal(
|
|||
type FuncContext = {
|
||||
cx: Context;
|
||||
item: Item<Typecked>;
|
||||
func: FunctionDef<Typecked>;
|
||||
func: ItemFunction<Typecked>;
|
||||
wasmType: wasm.FuncType;
|
||||
wasm: wasm.Func;
|
||||
varLocations: VarLocation[];
|
||||
|
|
@ -358,7 +358,7 @@ type StructLayout = {
|
|||
function lowerFunc(
|
||||
cx: Context,
|
||||
item: Item<Typecked>,
|
||||
func: FunctionDef<Typecked>,
|
||||
func: ItemFunction<Typecked>,
|
||||
) {
|
||||
const abi = computeAbi(func.ty!);
|
||||
const { type: wasmType, paramLocations } = wasmTypeForAbi(abi, func.ty!);
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@ import {
|
|||
FieldDef,
|
||||
Folder,
|
||||
FunctionArg,
|
||||
FunctionDef,
|
||||
ItemFunction,
|
||||
Ident,
|
||||
ImportDef,
|
||||
ItemImport,
|
||||
Item,
|
||||
LOGICAL_KINDS,
|
||||
ModItem,
|
||||
ItemMod,
|
||||
Type,
|
||||
TypeDef,
|
||||
ItemType,
|
||||
UNARY_KINDS,
|
||||
UnaryKind,
|
||||
binaryExprPrecedenceClass,
|
||||
|
|
@ -27,9 +27,9 @@ import {
|
|||
superFoldItem,
|
||||
Built,
|
||||
Parsed,
|
||||
ExternItem,
|
||||
ItemExtern,
|
||||
ItemId,
|
||||
GlobalItem,
|
||||
ItemGlobal,
|
||||
StructLiteralField,
|
||||
TypeDefKind,
|
||||
} from "./ast";
|
||||
|
|
@ -89,7 +89,7 @@ function parseItem(t: State): [State, Item<Parsed>] {
|
|||
|
||||
[t] = expectNext(t, ";");
|
||||
|
||||
const def: FunctionDef<Parsed> = {
|
||||
const def: ItemFunction<Parsed> = {
|
||||
...sig,
|
||||
body,
|
||||
};
|
||||
|
|
@ -145,7 +145,7 @@ function parseItem(t: State): [State, Item<Parsed>] {
|
|||
|
||||
[t] = expectNext(t, ";");
|
||||
|
||||
const def: TypeDef<Parsed> = {
|
||||
const def: ItemType<Parsed> = {
|
||||
name: name.ident,
|
||||
type,
|
||||
};
|
||||
|
|
@ -167,7 +167,7 @@ function parseItem(t: State): [State, Item<Parsed>] {
|
|||
|
||||
[t] = expectNext(t, ";");
|
||||
|
||||
const def: ImportDef<Parsed> = {
|
||||
const def: ItemImport<Parsed> = {
|
||||
module: { kind: "str", value: module.value, span: module.span },
|
||||
func: { kind: "str", value: func.value, span: func.span },
|
||||
...sig,
|
||||
|
|
@ -182,7 +182,7 @@ function parseItem(t: State): [State, Item<Parsed>] {
|
|||
let name;
|
||||
[t, name] = expectNext<TokenIdent>(t, "identifier");
|
||||
|
||||
const node: ExternItem = {
|
||||
const node: ItemExtern = {
|
||||
name: name.ident,
|
||||
};
|
||||
|
||||
|
|
@ -221,7 +221,7 @@ function parseItem(t: State): [State, Item<Parsed>] {
|
|||
|
||||
[t] = expectNext(t, ";");
|
||||
|
||||
const node: ModItem<Parsed> = {
|
||||
const node: ItemMod<Parsed> = {
|
||||
name: name.ident,
|
||||
contents,
|
||||
};
|
||||
|
|
@ -238,7 +238,7 @@ function parseItem(t: State): [State, Item<Parsed>] {
|
|||
[t, init] = parseExpr(t);
|
||||
[t] = expectNext(t, ";");
|
||||
|
||||
const node: GlobalItem<Parsed> = {
|
||||
const node: ItemGlobal<Parsed> = {
|
||||
name: name.ident,
|
||||
type,
|
||||
init,
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@ import {
|
|||
AnyPhase,
|
||||
Crate,
|
||||
Expr,
|
||||
FunctionDef,
|
||||
ItemFunction,
|
||||
IdentWithRes,
|
||||
ImportDef,
|
||||
ItemImport,
|
||||
Item,
|
||||
ModItem,
|
||||
ItemMod,
|
||||
Resolution,
|
||||
StringLiteral,
|
||||
Ty,
|
||||
Type,
|
||||
TypeDef,
|
||||
ItemType,
|
||||
tyIsUnit,
|
||||
} 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
|
||||
.map(({ name, type }) => `${name}: ${printType(type)}`)
|
||||
.join(", ");
|
||||
|
|
@ -62,7 +62,7 @@ function printFunction(func: FunctionDef<AnyPhase>): string {
|
|||
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) {
|
||||
case "struct": {
|
||||
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
|
||||
.map(({ name, type }) => `${name}: ${printType(type)}`)
|
||||
.join(", ");
|
||||
|
|
@ -92,7 +92,7 @@ function printImportDef(def: ImportDef<AnyPhase>): string {
|
|||
)}(${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 ")});`;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ import {
|
|||
Item,
|
||||
ItemId,
|
||||
LocalInfo,
|
||||
ModItem,
|
||||
ItemMod,
|
||||
Resolution,
|
||||
Resolved,
|
||||
mkDefaultFolder,
|
||||
superFoldExpr,
|
||||
superFoldItem,
|
||||
superFoldType,
|
||||
ExternItem,
|
||||
ItemExtern,
|
||||
} from "./ast";
|
||||
import { GlobalContext } from "./context";
|
||||
import { CompilerError, Span } from "./error";
|
||||
|
|
@ -43,7 +43,7 @@ function loadCrate(cx: Context, name: string, span: Span): Map<string, ItemId> {
|
|||
|
||||
function resolveModItem(
|
||||
cx: Context,
|
||||
mod: ModItem<Built> | ExternItem,
|
||||
mod: ItemMod<Built> | ItemExtern,
|
||||
item: Item<Built>,
|
||||
name: string,
|
||||
): ItemId | undefined {
|
||||
|
|
@ -204,7 +204,7 @@ function resolveModule(
|
|||
|
||||
loadCrate(cx, item.node.name, item.span);
|
||||
|
||||
const node: ExternItem = {
|
||||
const node: ItemExtern = {
|
||||
...item.node,
|
||||
};
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue