From d99a0cfae62e7ee078745f57afcded5335c3da14 Mon Sep 17 00:00:00 2001 From: Xie Yuheng Date: Wed, 2 Aug 2023 17:19:28 +0800 Subject: [PATCH] `cut` -- `Call` --- TODO.md | 5 +++-- src/lang/cut/cut.ts | 5 ++++- src/lang/cut/cutDefinition.ts | 25 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/lang/cut/cutDefinition.ts diff --git a/TODO.md b/TODO.md index 0672244a..d19591cd 100644 --- a/TODO.md +++ b/TODO.md @@ -1,10 +1,11 @@ # type -`cut` -- `Call` `cut` -- `PortPush` `cut` -- `PortReconnect` -`cutDefinition` +`cutDefinition` -- NodeDefinition +`cutDefinition` -- NetDefinition +`cutDefinition` -- OperatorDefinition `freshenTypes` -- consistently add subscript to type variable names diff --git a/src/lang/cut/cut.ts b/src/lang/cut/cut.ts index 3cdbbb81..b816ca43 100644 --- a/src/lang/cut/cut.ts +++ b/src/lang/cut/cut.ts @@ -1,7 +1,9 @@ import { Ctx } from "../ctx" import { NodeDefinition } from "../definition" import { Mod } from "../mod" +import { lookupDefinitionOrFail } from "../mod/lookupDefinitionOrFail" import { Word } from "../word" +import { cutDefinition } from "./cutDefinition" export interface CutOptions { current?: { @@ -24,7 +26,8 @@ export function cut( ctx.localSignedTypes.delete(word.name) return } else { - // + const definition = lookupDefinitionOrFail(mod, word.name) + cutDefinition(ctx, definition) return } } diff --git a/src/lang/cut/cutDefinition.ts b/src/lang/cut/cutDefinition.ts new file mode 100644 index 00000000..e6a9085a --- /dev/null +++ b/src/lang/cut/cutDefinition.ts @@ -0,0 +1,25 @@ +import { Ctx } from "../ctx" +import { Definition } from "../definition" + +export function cutDefinition(ctx: Ctx, definition: Definition): void { + switch (definition.kind) { + case "NodeDefinition": { + // + return + } + + case "NetDefinition": { + // + return + } + + case "OperatorDefinition": { + // + return + } + + case "TypeDefinition": { + throw new Error(`[cutDefinition] Can not cut a type: ${definition.name}`) + } + } +}