Skip to content

Commit

Permalink
[new-syntax] stmts-next/ -- DefineType
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Sep 19, 2023
1 parent bf35e0f commit f9e9f54
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# new-syntax

extract `Parameter`
[new-syntax] `stmts-next/` -- `DefineRule`
[new-syntax] `stmts-next/` -- `DefineType`
[new-syntax] `stmts-next/` -- `DefineFunction`
[new-syntax] `stmts-next/` -- `TopLevelEvaluate`
[new-syntax] `stmts-next/` -- `TopLevelLet`
Expand Down
23 changes: 5 additions & 18 deletions src/lang/stmts-next/DefineNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,23 @@ import { Mod } from "../mod"
import { Span } from "../span"
import { Stmt } from "../stmt-next"

export type NodeParameter = {
export type Parameter = {
name: string
t: Exp
isPrincipal: boolean
isPrincipal?: boolean
}

export class DefineNode implements Stmt {
constructor(
public name: string,
public input: Array<NodeParameter>,
public output: Array<NodeParameter>,
public input: Array<Parameter>,
public output: Array<Parameter>,
public span: Span,
) {}

async execute(mod: Mod): Promise<void> {
try {
// const { inputPortExps, outputPortExps } = checkNode(
// mod,
// this.input,
// this.output,
// )
// define(mod, this.name, {
// "@type": "Definition",
// "@kind": "NodeDefinition",
// mod,
// span: this.span,
// name: this.name,
// input: inputPortExps,
// output: outputPortExps,
// })
// TODO
} catch (error) {
throw appendReport(error, {
message: [
Expand Down
37 changes: 37 additions & 0 deletions src/lang/stmts-next/DefineType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { appendReport } from "../errors/appendReport"
import { Exp } from "../exp"
import { Mod } from "../mod"
import { Span } from "../span"
import { Stmt } from "../stmt-next"

export type TypeParameter = {
name: string
t: Exp
}

export class DefineType implements Stmt {
constructor(
public name: string,
public input: Array<TypeParameter>,
public output: Array<TypeParameter>,
public span: Span,
) {}

async execute(mod: Mod): Promise<void> {
try {
// TODO
} catch (error) {
throw appendReport(error, {
message: [
`[DefineNode.execute] I fail to define node.`,
``,
` node name: ${this.name}`,
].join("\n"),
context: {
span: this.span,
text: mod.text,
},
})
}
}
}
1 change: 1 addition & 0 deletions src/lang/stmts-next/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./DefineNode"
export * from "./DefineType"

0 comments on commit f9e9f54

Please sign in to comment.