diff --git a/TODO.md b/TODO.md index dce6e03a..251fc7a4 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,3 @@ -`createTrivialTypes` - `Type` should be type instead of class [maybe] quit using `def/` and `defs/` diff --git a/docs/articles/design-of-new-syntax.md b/docs/articles/design-of-new-syntax.md index 15c1c0bc..61975ad5 100644 --- a/docs/articles/design-of-new-syntax.md +++ b/docs/articles/design-of-new-syntax.md @@ -85,7 +85,7 @@ end We use a simple type system like Haskell (for now). ```inet -defnode sole -- !Sole end +defnode sole -- !Trivial end defnode null -- !List('a) end diff --git a/src/lang/mod/builtInOperators.ts b/src/lang/mod/builtInOperators.ts index 6d1b9278..b6008d29 100644 --- a/src/lang/mod/builtInOperators.ts +++ b/src/lang/mod/builtInOperators.ts @@ -2,7 +2,7 @@ import { Mod } from "." import * as Defs from "../defs" import { Port } from "../graph" import { netConnect } from "../graph/netConnect" -import { buildTypes } from "../types" +import { createTrivialTypes } from "../type" export function builtInOperators(mod: Mod): void { mod.defineOperator("swap", (net) => { @@ -25,13 +25,8 @@ export function builtInOperators(mod: Mod): void { }) mod.defineOperator("wire", (net) => { - const def = new Defs.NodeDef( - mod, - "Cons", - "wire", - [], - buildTypes(["Any", "Any"]), - ) + const def = new Defs.NodeDef(mod, "Cons", "wire", [], createTrivialTypes(2)) + const node = def.build() net.portStack.push(...node.output) diff --git a/src/lang/stmts/DefconsStmt.ts b/src/lang/stmts/DefconsStmt.ts index 156c6807..4feed09a 100644 --- a/src/lang/stmts/DefconsStmt.ts +++ b/src/lang/stmts/DefconsStmt.ts @@ -2,7 +2,7 @@ import * as Defs from "../defs" import { Mod } from "../mod" import { Span } from "../span" import { Stmt } from "../stmt" -import { buildTypes } from "../types" +import { createTrivialTypes } from "../type" export class DefconsStmt extends Stmt { constructor( @@ -21,8 +21,8 @@ export class DefconsStmt extends Stmt { mod, "Cons", this.name, - buildTypes(Array(this.inputArity).fill("Any")), - buildTypes(Array(this.outputArity).fill("Any")), + createTrivialTypes(this.inputArity), + createTrivialTypes(this.outputArity), ), ) } diff --git a/src/lang/stmts/DefelimStmt.ts b/src/lang/stmts/DefelimStmt.ts index dfbba155..bd5d4e2f 100644 --- a/src/lang/stmts/DefelimStmt.ts +++ b/src/lang/stmts/DefelimStmt.ts @@ -2,7 +2,7 @@ import * as Defs from "../defs" import { Mod } from "../mod" import { Span } from "../span" import { Stmt } from "../stmt" -import { buildTypes } from "../types" +import { createTrivialTypes } from "../type" export class DefelimStmt extends Stmt { constructor( @@ -21,8 +21,8 @@ export class DefelimStmt extends Stmt { mod, "Elim", this.name, - buildTypes(Array(this.inputArity).fill("Any")), - buildTypes(Array(this.outputArity).fill("Any")), + createTrivialTypes(this.inputArity), + createTrivialTypes(this.outputArity), ), ) } diff --git a/src/lang/type/Type.ts b/src/lang/type/Type.ts index 4105ea34..522e40a9 100644 --- a/src/lang/type/Type.ts +++ b/src/lang/type/Type.ts @@ -1,7 +1 @@ -export abstract class Type { - abstract format(): string - - isPrincipal(): boolean { - return false - } -} +export type Type = {} diff --git a/src/lang/type/createTrivialTypes.ts b/src/lang/type/createTrivialTypes.ts new file mode 100644 index 00000000..54e5b9f4 --- /dev/null +++ b/src/lang/type/createTrivialTypes.ts @@ -0,0 +1,5 @@ +import { Type } from "./Type" + +export function createTrivialTypes(arity: number): Array { + return Array(arity).fill({}) +} diff --git a/src/lang/type/index.ts b/src/lang/type/index.ts index 586bcbda..af72814f 100644 --- a/src/lang/type/index.ts +++ b/src/lang/type/index.ts @@ -1 +1,2 @@ export * from "./Type" +export * from "./createTrivialTypes" diff --git a/src/lang/types/AtomType.ts b/src/lang/types/AtomType.ts deleted file mode 100644 index f56e029a..00000000 --- a/src/lang/types/AtomType.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Type } from "../type" - -export class AtomType extends Type { - name: string - - constructor(name: string) { - super() - this.name = name - } - - format(): string { - return this.name - } -} diff --git a/src/lang/types/TypeBuilder.ts b/src/lang/types/TypeBuilder.ts deleted file mode 100644 index 54d764d4..00000000 --- a/src/lang/types/TypeBuilder.ts +++ /dev/null @@ -1,34 +0,0 @@ -import * as Types from "." -import { Type } from "../type" - -export class TypeBuilder { - words: Array - - constructor(words: Array) { - this.words = words - } - - build(): Array { - const types: Array = [] - for (const word of this.words) { - if (word === "*") { - const t = types.pop() - if (t === undefined) { - throw new Error( - [ - `Fail to build type,`, - `I expect a type on the stack when applying *`, - ` words: ${this.words}`, - ].join("\n"), - ) - } else { - throw new Error() - } - } else { - types.push(new Types.AtomType(word)) - } - } - - return types - } -} diff --git a/src/lang/types/buildTypes.ts b/src/lang/types/buildTypes.ts deleted file mode 100644 index 10fcdd6e..00000000 --- a/src/lang/types/buildTypes.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { TypeBuilder } from "." -import { Type } from "../type" - -export function buildTypes(words: Array): Array { - return new TypeBuilder(words).build() -} diff --git a/src/lang/types/index.ts b/src/lang/types/index.ts deleted file mode 100644 index 786b20ab..00000000 --- a/src/lang/types/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -// organize-imports-ignore - -export * from "./AtomType" -export * from "./TypeBuilder" -export * from "./buildTypes"