more item cleanup

This commit is contained in:
nora 2023-08-03 13:50:14 +02:00
parent b021a9e218
commit 73a369730b
12 changed files with 104 additions and 88 deletions

View file

@ -4,4 +4,4 @@ The language is not well designed. It's just random garbage.
## vscode extension ## vscode extension
there's even a vscode extension! see [the readme](./vscode/README.md) there's even a vscode extension! see [the readme](./vscode/README.md)

View file

@ -98,12 +98,21 @@ export class ItemId {
} }
export type ItemKind<P extends Phase> = export type ItemKind<P extends Phase> =
| ItemFunction<P> | ItemKindFunction<P>
| ItemType<P> | ItemKindType<P>
| ItemImport<P> | ItemKindImport<P>
| ItemMod<P> | ItemKindMod<P>
| ItemExtern | ItemKindExtern
| ItemGlobal<P>; | ItemKindGlobal<P>;
type ItemVariant<Variant, P extends Phase> = Variant & Item<P>;
export type ItemFunction<P extends Phase> = ItemVariant<ItemKindFunction<P>, P>;
export type ItemType<P extends Phase> = ItemVariant<ItemKindType<P>, P>;
export type ItemImport<P extends Phase> = ItemVariant<ItemKindImport<P>, P>;
export type ItemMod<P extends Phase> = ItemVariant<ItemKindMod<P>, P>;
export type ItemExtern<P extends Phase> = ItemVariant<ItemKindExtern, P>;
export type ItemGlobal<P extends Phase> = ItemVariant<ItemKindGlobal<P>, P>;
export type Item<P extends Phase> = ItemKind<P> & { export type Item<P extends Phase> = ItemKind<P> & {
span: Span; span: Span;
@ -111,7 +120,7 @@ export type Item<P extends Phase> = ItemKind<P> & {
name: string; name: string;
} & P["defPath"]; } & P["defPath"];
export type ItemFunction<P extends Phase> = { export type ItemKindFunction<P extends Phase> = {
kind: "function"; kind: "function";
params: FunctionArg<P>[]; params: FunctionArg<P>[];
body: Expr<P>; body: Expr<P>;
@ -125,7 +134,7 @@ export type FunctionArg<P extends Phase> = {
span: Span; span: Span;
}; };
export type ItemType<P extends Phase> = { export type ItemKindType<P extends Phase> = {
kind: "type"; kind: "type";
type: TypeDefKind<P>; type: TypeDefKind<P>;
ty?: TyStruct; ty?: TyStruct;
@ -146,7 +155,7 @@ export type FieldDef<P extends Phase> = {
type: Type<P>; type: Type<P>;
}; };
export type ItemImport<P extends Phase> = { export type ItemKindImport<P extends Phase> = {
kind: "import"; kind: "import";
module: StringLiteral; module: StringLiteral;
func: StringLiteral; func: StringLiteral;
@ -155,14 +164,14 @@ export type ItemImport<P extends Phase> = {
ty?: TyFn; ty?: TyFn;
}; };
export type ItemMod<P extends Phase> = { export type ItemKindMod<P extends Phase> = {
kind: "mod"; kind: "mod";
contents: Item<P>[]; contents: Item<P>[];
}; };
export type ItemExtern = { kind: "extern" }; export type ItemKindExtern = { kind: "extern" };
export type ItemGlobal<P extends Phase> = { export type ItemKindGlobal<P extends Phase> = {
kind: "global"; kind: "global";
type: Type<P>; type: Type<P>;
init: Expr<P>; init: Expr<P>;

View file

@ -258,7 +258,7 @@ export function lower(gcx: GlobalContext): wasm.Module {
return mod; return mod;
} }
function lowerImport(cx: Context, def: ItemImport<Typecked> & Item<Typecked>) { function lowerImport(cx: Context, 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,
); );
@ -285,7 +285,7 @@ function lowerImport(cx: Context, def: ItemImport<Typecked> & Item<Typecked>) {
cx.funcIndices.set({ kind: "item", id: def.id }, { kind: "import", idx }); cx.funcIndices.set({ kind: "item", id: def.id }, { kind: "import", idx });
} }
function lowerGlobal(cx: Context, def: ItemGlobal<Typecked> & Item<Typecked>) { function lowerGlobal(cx: Context, def: ItemGlobal<Typecked>) {
const globalIdx = cx.mod.globals.length; const globalIdx = cx.mod.globals.length;
let valtype: "i32" | "i64"; let valtype: "i32" | "i64";
@ -320,7 +320,7 @@ function lowerGlobal(cx: Context, def: ItemGlobal<Typecked> & Item<Typecked>) {
type FuncContext = { type FuncContext = {
cx: Context; cx: Context;
func: Item<Typecked> & ItemFunction<Typecked>; func: ItemFunction<Typecked>;
wasmType: wasm.FuncType; wasmType: wasm.FuncType;
wasm: wasm.Func; wasm: wasm.Func;
varLocations: VarLocation[]; varLocations: VarLocation[];
@ -346,7 +346,7 @@ type StructLayout = {
fields: StructFieldLayout[]; fields: StructFieldLayout[];
}; };
function lowerFunc(cx: Context, func: Item<Typecked> & ItemFunction<Typecked>) { function lowerFunc(cx: Context, 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!);
const type = internFuncType(cx, wasmType); const type = internFuncType(cx, wasmType);

View file

@ -234,7 +234,7 @@ function parseItem(t: State): [State, Item<Parsed>] {
[t, init] = parseExpr(t); [t, init] = parseExpr(t);
[t] = expectNext(t, ";"); [t] = expectNext(t, ";");
const global: ItemGlobal<Parsed> & Item<Parsed> = { const global: ItemGlobal<Parsed> = {
kind: "global", kind: "global",
name: name.ident, name: name.ident,
type, type,

View file

@ -54,7 +54,7 @@ function printItem(item: Item<AnyPhase>): string {
} }
} }
function printFunction(func: ItemFunction<AnyPhase> & Item<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: ItemFunction<AnyPhase> & Item<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: ItemType<AnyPhase> & Item<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;
@ -92,7 +92,7 @@ function printImportDef(def: ItemImport<AnyPhase>): string {
)}(${args})${ret};`; )}(${args})${ret};`;
} }
function printMod(mod: ItemMod<AnyPhase> & Item<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 ")});`;
} }

View file

@ -43,7 +43,7 @@ function loadCrate(cx: Context, name: string, span: Span): Map<string, ItemId> {
function resolveModItem( function resolveModItem(
cx: Context, cx: Context,
mod: (ItemMod<Built> | ItemExtern) & Item<Built>, mod: ItemMod<Built> | ItemExtern<Built>,
name: string, name: string,
): ItemId | undefined { ): ItemId | undefined {
const cachedContents = cx.modContentsCache.get(mod.id); const cachedContents = cx.modContentsCache.get(mod.id);

View file

@ -3,15 +3,13 @@
// Hover to view descriptions of existing attributes. // Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{ {
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "Extension", "name": "Extension",
"type": "extensionHost", "type": "extensionHost",
"request": "launch", "request": "launch",
"args": [ "args": ["--extensionDevelopmentPath=${workspaceFolder}"]
"--extensionDevelopmentPath=${workspaceFolder}" }
] ]
} }
]
}

View file

@ -6,4 +6,4 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
## [Unreleased] ## [Unreleased]
- Initial release - Initial release

View file

@ -31,4 +31,4 @@ pkgs.vscode-utils.buildVscodeExtension {
} }
``` ```
which probably works i think (maybe you want to update the hash to something newer although its unlikey this extension will change that much) which probably works i think (maybe you want to update the hash to something newer although its unlikey this extension will change that much)

View file

@ -1,29 +1,29 @@
{ {
"comments": { "comments": {
// symbol used for single line comment. Remove this entry if your language does not support line comments // symbol used for single line comment. Remove this entry if your language does not support line comments
"lineComment": "//", "lineComment": "//",
// symbols used for start and end a block comment. Remove this entry if your language does not support block comments // symbols used for start and end a block comment. Remove this entry if your language does not support block comments
"blockComment": [ "/*", "*/" ] "blockComment": ["/*", "*/"]
}, },
// symbols used as brackets // symbols used as brackets
"brackets": [ "brackets": [
["{", "}"], ["{", "}"],
["[", "]"], ["[", "]"],
["(", ")"] ["(", ")"]
], ],
// symbols that are auto closed when typing // symbols that are auto closed when typing
"autoClosingPairs": [ "autoClosingPairs": [
["{", "}"], ["{", "}"],
["[", "]"], ["[", "]"],
["(", ")"], ["(", ")"],
["\"", "\""], ["\"", "\""],
["'", "'"] ["'", "'"]
], ],
// symbols that can be used to surround a selection // symbols that can be used to surround a selection
"surroundingPairs": [ "surroundingPairs": [
["{", "}"], ["{", "}"],
["[", "]"], ["[", "]"],
["(", ")"], ["(", ")"],
["\"", "\""], ["\"", "\""]
] ]
} }

View file

@ -11,16 +11,25 @@
"Programming Languages" "Programming Languages"
], ],
"contributes": { "contributes": {
"languages": [{ "languages": [
"id": "riverdelta", {
"aliases": ["riverdelta", "riverdelta"], "id": "riverdelta",
"extensions": [".nil"], "aliases": [
"configuration": "./language-configuration.json" "riverdelta",
}], "riverdelta"
"grammars": [{ ],
"language": "riverdelta", "extensions": [
"scopeName": "source.nil", ".nil"
"path": "./syntaxes/riverdelta.tmLanguage.json" ],
}] "configuration": "./language-configuration.json"
}
],
"grammars": [
{
"language": "riverdelta",
"scopeName": "source.nil",
"path": "./syntaxes/riverdelta.tmLanguage.json"
}
]
} }
} }

View file

@ -2,28 +2,28 @@
## What's in the folder ## What's in the folder
* This folder contains all of the files necessary for your extension. - This folder contains all of the files necessary for your extension.
* `package.json` - this is the manifest file in which you declare your language support and define the location of the grammar file that has been copied into your extension. - `package.json` - this is the manifest file in which you declare your language support and define the location of the grammar file that has been copied into your extension.
* `syntaxes/riverdelta.tmLanguage.json` - this is the Text mate grammar file that is used for tokenization. - `syntaxes/riverdelta.tmLanguage.json` - this is the Text mate grammar file that is used for tokenization.
* `language-configuration.json` - this is the language configuration, defining the tokens that are used for comments and brackets. - `language-configuration.json` - this is the language configuration, defining the tokens that are used for comments and brackets.
## Get up and running straight away ## Get up and running straight away
* Make sure the language configuration settings in `language-configuration.json` are accurate. - Make sure the language configuration settings in `language-configuration.json` are accurate.
* Press `F5` to open a new window with your extension loaded. - Press `F5` to open a new window with your extension loaded.
* Create a new file with a file name suffix matching your language. - Create a new file with a file name suffix matching your language.
* Verify that syntax highlighting works and that the language configuration settings are working. - Verify that syntax highlighting works and that the language configuration settings are working.
## Make changes ## Make changes
* You can relaunch the extension from the debug toolbar after making changes to the files listed above. - You can relaunch the extension from the debug toolbar after making changes to the files listed above.
* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. - You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes.
## Add more language features ## Add more language features
* To add features such as IntelliSense, hovers and validators check out the VS Code extenders documentation at https://code.visualstudio.com/docs - To add features such as IntelliSense, hovers and validators check out the VS Code extenders documentation at https://code.visualstudio.com/docs
## Install your extension ## Install your extension
* To start using your extension with Visual Studio Code copy it into the `<user home>/.vscode/extensions` folder and restart Code. - To start using your extension with Visual Studio Code copy it into the `<user home>/.vscode/extensions` folder and restart Code.
* To share your extension with the world, read on https://code.visualstudio.com/docs about publishing an extension. - To share your extension with the world, read on https://code.visualstudio.com/docs about publishing an extension.