Skip to content

Commit

Permalink
defrule -- check type -- cut -- words composition
Browse files Browse the repository at this point in the history
- `Defrule` pass `current.start` and `current.end` to `cutWords`
  • Loading branch information
xieyuheng committed Aug 2, 2023
1 parent 28ccf4b commit c1ffd3b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
6 changes: 3 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# type

extract `cut`
[definition] `Definition` as a type -- instead of class

`defrule` -- check type -- cut -- words composition
`composeDefinition`

`cut` -- `Call`
`cut` -- `LocalSet`
`cut` -- `PortPush`
`cut` -- `PortReconnect`

`Definition.cut`
`cutDefinition`

`freshenTypes` -- consistently add subscript to type variable names

Expand Down
24 changes: 22 additions & 2 deletions src/lang/cut/cut.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Ctx } from "../ctx"
import { NodeDefinition } from "../definitions"
import { Mod } from "../mod"
import { Word } from "../word"

export interface CutOptions {
//
current?: {
start: NodeDefinition
end: NodeDefinition
}
}

export function cut(
Expand All @@ -12,5 +16,21 @@ export function cut(
word: Word,
options?: CutOptions,
): void {
//
switch (word.kind) {
case "Call": {
//
}

case "LocalSet": {
//
}

case "PortPush": {
//
}

case "PortReconnect": {
//
}
}
}
14 changes: 10 additions & 4 deletions src/lang/cut/cutWords.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { Ctx } from "../ctx"
import { Mod } from "../mod"
import { Word } from "../word"
import { CutOptions, cut } from "./cut"

export function cutWords(mod: Mod, ctx: Ctx, words: Array<Word>): void {
// for (const word of words) {
// word.cut(mod, ctx)
// }
export function cutWords(
mod: Mod,
ctx: Ctx,
words: Array<Word>,
options?: CutOptions,
): void {
for (const word of words) {
cut(mod, ctx, word, options)
}
}
9 changes: 8 additions & 1 deletion src/lang/stmts/Defrule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createCtx } from "../ctx/createCtx"
import { cutWords } from "../cut/cutWords"
import { Mod } from "../mod"
import { defineRule } from "../mod/defineRule"
import { lookupNodeDefinitionOrFail } from "../mod/lookupNodeDefinitionOrFail"
import { Span } from "../span"
import { Stmt } from "../stmt"
import { Word } from "../word"
Expand All @@ -16,7 +17,13 @@ export class Defrule implements Stmt {

async execute(mod: Mod): Promise<void> {
const ctx = createCtx()
cutWords(mod, ctx, this.words)

const start = lookupNodeDefinitionOrFail(mod, this.start)
const end = lookupNodeDefinitionOrFail(mod, this.end)

cutWords(mod, ctx, this.words, {
current: { start, end },
})

defineRule(mod, this.start, this.end, this.words)
}
Expand Down

0 comments on commit c1ffd3b

Please sign in to comment.