mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-14 16:35:03 +01:00
more item cleanup
This commit is contained in:
parent
b021a9e218
commit
73a369730b
12 changed files with 104 additions and 88 deletions
33
src/ast.ts
33
src/ast.ts
|
|
@ -98,12 +98,21 @@ export class ItemId {
|
|||
}
|
||||
|
||||
export type ItemKind<P extends Phase> =
|
||||
| ItemFunction<P>
|
||||
| ItemType<P>
|
||||
| ItemImport<P>
|
||||
| ItemMod<P>
|
||||
| ItemExtern
|
||||
| ItemGlobal<P>;
|
||||
| ItemKindFunction<P>
|
||||
| ItemKindType<P>
|
||||
| ItemKindImport<P>
|
||||
| ItemKindMod<P>
|
||||
| ItemKindExtern
|
||||
| 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> & {
|
||||
span: Span;
|
||||
|
|
@ -111,7 +120,7 @@ export type Item<P extends Phase> = ItemKind<P> & {
|
|||
name: string;
|
||||
} & P["defPath"];
|
||||
|
||||
export type ItemFunction<P extends Phase> = {
|
||||
export type ItemKindFunction<P extends Phase> = {
|
||||
kind: "function";
|
||||
params: FunctionArg<P>[];
|
||||
body: Expr<P>;
|
||||
|
|
@ -125,7 +134,7 @@ export type FunctionArg<P extends Phase> = {
|
|||
span: Span;
|
||||
};
|
||||
|
||||
export type ItemType<P extends Phase> = {
|
||||
export type ItemKindType<P extends Phase> = {
|
||||
kind: "type";
|
||||
type: TypeDefKind<P>;
|
||||
ty?: TyStruct;
|
||||
|
|
@ -146,7 +155,7 @@ export type FieldDef<P extends Phase> = {
|
|||
type: Type<P>;
|
||||
};
|
||||
|
||||
export type ItemImport<P extends Phase> = {
|
||||
export type ItemKindImport<P extends Phase> = {
|
||||
kind: "import";
|
||||
module: StringLiteral;
|
||||
func: StringLiteral;
|
||||
|
|
@ -155,14 +164,14 @@ export type ItemImport<P extends Phase> = {
|
|||
ty?: TyFn;
|
||||
};
|
||||
|
||||
export type ItemMod<P extends Phase> = {
|
||||
export type ItemKindMod<P extends Phase> = {
|
||||
kind: "mod";
|
||||
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";
|
||||
type: Type<P>;
|
||||
init: Expr<P>;
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ export function lower(gcx: GlobalContext): wasm.Module {
|
|||
return mod;
|
||||
}
|
||||
|
||||
function lowerImport(cx: Context, def: ItemImport<Typecked> & Item<Typecked>) {
|
||||
function lowerImport(cx: Context, def: ItemImport<Typecked>) {
|
||||
const existing = cx.mod.imports.findIndex(
|
||||
(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 });
|
||||
}
|
||||
|
||||
function lowerGlobal(cx: Context, def: ItemGlobal<Typecked> & Item<Typecked>) {
|
||||
function lowerGlobal(cx: Context, def: ItemGlobal<Typecked>) {
|
||||
const globalIdx = cx.mod.globals.length;
|
||||
|
||||
let valtype: "i32" | "i64";
|
||||
|
|
@ -320,7 +320,7 @@ function lowerGlobal(cx: Context, def: ItemGlobal<Typecked> & Item<Typecked>) {
|
|||
|
||||
type FuncContext = {
|
||||
cx: Context;
|
||||
func: Item<Typecked> & ItemFunction<Typecked>;
|
||||
func: ItemFunction<Typecked>;
|
||||
wasmType: wasm.FuncType;
|
||||
wasm: wasm.Func;
|
||||
varLocations: VarLocation[];
|
||||
|
|
@ -346,7 +346,7 @@ type StructLayout = {
|
|||
fields: StructFieldLayout[];
|
||||
};
|
||||
|
||||
function lowerFunc(cx: Context, func: Item<Typecked> & ItemFunction<Typecked>) {
|
||||
function lowerFunc(cx: Context, func: ItemFunction<Typecked>) {
|
||||
const abi = computeAbi(func.ty!);
|
||||
const { type: wasmType, paramLocations } = wasmTypeForAbi(abi, func.ty!);
|
||||
const type = internFuncType(cx, wasmType);
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ function parseItem(t: State): [State, Item<Parsed>] {
|
|||
[t, init] = parseExpr(t);
|
||||
[t] = expectNext(t, ";");
|
||||
|
||||
const global: ItemGlobal<Parsed> & Item<Parsed> = {
|
||||
const global: ItemGlobal<Parsed> = {
|
||||
kind: "global",
|
||||
name: name.ident,
|
||||
type,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
.map(({ name, type }) => `${name}: ${printType(type)}`)
|
||||
.join(", ");
|
||||
|
|
@ -62,7 +62,7 @@ function printFunction(func: ItemFunction<AnyPhase> & Item<AnyPhase>): string {
|
|||
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) {
|
||||
case "struct": {
|
||||
const { fields } = type.type;
|
||||
|
|
@ -92,7 +92,7 @@ function printImportDef(def: ItemImport<AnyPhase>): string {
|
|||
)}(${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 ")});`;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ function loadCrate(cx: Context, name: string, span: Span): Map<string, ItemId> {
|
|||
|
||||
function resolveModItem(
|
||||
cx: Context,
|
||||
mod: (ItemMod<Built> | ItemExtern) & Item<Built>,
|
||||
mod: ItemMod<Built> | ItemExtern<Built>,
|
||||
name: string,
|
||||
): ItemId | undefined {
|
||||
const cachedContents = cx.modContentsCache.get(mod.id);
|
||||
|
|
|
|||
20
vscode/.vscode/launch.json
vendored
20
vscode/.vscode/launch.json
vendored
|
|
@ -3,15 +3,13 @@
|
|||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}"
|
||||
]
|
||||
}
|
||||
]
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"args": ["--extensionDevelopmentPath=${workspaceFolder}"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,29 +1,29 @@
|
|||
{
|
||||
"comments": {
|
||||
// symbol used for single line comment. Remove this entry if your language does not support line comments
|
||||
"lineComment": "//",
|
||||
// symbols used for start and end a block comment. Remove this entry if your language does not support block comments
|
||||
"blockComment": [ "/*", "*/" ]
|
||||
},
|
||||
// symbols used as brackets
|
||||
"brackets": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"]
|
||||
],
|
||||
// symbols that are auto closed when typing
|
||||
"autoClosingPairs": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["\"", "\""],
|
||||
["'", "'"]
|
||||
],
|
||||
// symbols that can be used to surround a selection
|
||||
"surroundingPairs": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["\"", "\""],
|
||||
]
|
||||
"comments": {
|
||||
// symbol used for single line comment. Remove this entry if your language does not support line comments
|
||||
"lineComment": "//",
|
||||
// symbols used for start and end a block comment. Remove this entry if your language does not support block comments
|
||||
"blockComment": ["/*", "*/"]
|
||||
},
|
||||
// symbols used as brackets
|
||||
"brackets": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"]
|
||||
],
|
||||
// symbols that are auto closed when typing
|
||||
"autoClosingPairs": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["\"", "\""],
|
||||
["'", "'"]
|
||||
],
|
||||
// symbols that can be used to surround a selection
|
||||
"surroundingPairs": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["\"", "\""]
|
||||
]
|
||||
}
|
||||
|
|
@ -11,16 +11,25 @@
|
|||
"Programming Languages"
|
||||
],
|
||||
"contributes": {
|
||||
"languages": [{
|
||||
"id": "riverdelta",
|
||||
"aliases": ["riverdelta", "riverdelta"],
|
||||
"extensions": [".nil"],
|
||||
"configuration": "./language-configuration.json"
|
||||
}],
|
||||
"grammars": [{
|
||||
"language": "riverdelta",
|
||||
"scopeName": "source.nil",
|
||||
"path": "./syntaxes/riverdelta.tmLanguage.json"
|
||||
}]
|
||||
"languages": [
|
||||
{
|
||||
"id": "riverdelta",
|
||||
"aliases": [
|
||||
"riverdelta",
|
||||
"riverdelta"
|
||||
],
|
||||
"extensions": [
|
||||
".nil"
|
||||
],
|
||||
"configuration": "./language-configuration.json"
|
||||
}
|
||||
],
|
||||
"grammars": [
|
||||
{
|
||||
"language": "riverdelta",
|
||||
"scopeName": "source.nil",
|
||||
"path": "./syntaxes/riverdelta.tmLanguage.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,28 +2,28 @@
|
|||
|
||||
## What's in the folder
|
||||
|
||||
* 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.
|
||||
* `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.
|
||||
- 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.
|
||||
- `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.
|
||||
|
||||
## Get up and running straight away
|
||||
|
||||
* Make sure the language configuration settings in `language-configuration.json` are accurate.
|
||||
* Press `F5` to open a new window with your extension loaded.
|
||||
* 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.
|
||||
- Make sure the language configuration settings in `language-configuration.json` are accurate.
|
||||
- Press `F5` to open a new window with your extension loaded.
|
||||
- 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.
|
||||
|
||||
## Make changes
|
||||
|
||||
* 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 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.
|
||||
|
||||
## 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
|
||||
|
||||
* 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 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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue