Skip to content

Commit

Permalink
remove syntax of rearrange
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Sep 13, 2023
1 parent 2f64d4a commit adaa71a
Show file tree
Hide file tree
Showing 12 changed files with 5 additions and 242 deletions.
4 changes: 1 addition & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
remove syntax of rearrange

update docs about using `@spread` to do rearrange

`(cons)` -- unconnected node as value -- redesign syntax of rearrange
Expand Down Expand Up @@ -42,4 +40,4 @@ diff_append
diff_append
```

`(cons)-tail` -- in rule `(cons)` is like a linear store
[note] about `(cons)-tail` -- in rule `(cons)` is like a linear store
16 changes: 0 additions & 16 deletions src/lang/compose/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { unifyTypes } from "../unify/unifyTypes"
import { Word } from "../word"
import { formatWord } from "../word/formatWord"
import { composeDefinition } from "./composeDefinition"
import { composeNode } from "./composeNode"
import { findCurrentPortOrFail } from "./findCurrentPortOrFail"

export interface ComposeOptions {
Expand Down Expand Up @@ -177,21 +176,6 @@ export function compose(

return null
}

case "NodeRearrange": {
const definition = findDefinitionOrFail(mod, word.name)
composeNode(
env,
createNodeFromDefinition(env.net, definition),
options,
{
input: word.input,
output: word.output,
},
)

return null
}
}
} catch (error) {
throw appendReport(error, {
Expand Down
13 changes: 4 additions & 9 deletions src/lang/compose/composeNode.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import { connect } from "../connect/connect"
import { Env } from "../env"
import { refreshNode } from "../freshen/refreshNode"
import { findInputPorts } from "../net/findInputPorts"
import { findOutputPorts } from "../net/findOutputPorts"
import { Node } from "../node"
import { unifyTypes } from "../unify/unifyTypes"
import { ComposeOptions } from "./compose"
import { rearrangeNodePorts } from "./rearrangeNodePorts"

export function composeNode(
env: Env,
node: Node,
options: ComposeOptions,
rearrangement: {
input: Array<string>
output: Array<string>
} = {
input: [],
output: [],
},
): Node {
if (options.checking) {
refreshNode(env.net, options.checking.typeVarCounters, node)
}

const { input, output } = rearrangeNodePorts(env.net, node, rearrangement)
const input = findInputPorts(env.net, node)
const output = findOutputPorts(env.net, node)

// Be careful about the order:
// The first input port connects
Expand Down
87 changes: 0 additions & 87 deletions src/lang/compose/rearrangeNodePorts.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/lang/syntax/grammars/word.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ export const word = {
"word:generate_type_var": ['"\'"', { name: "variable_name" }],
"word:label": ['":"', { label: "variable_name" }],
"word:label_is_important": ['":"', { label: "variable_name" }, '"!"'],
"word:node_rearrange": [
'"("',
{ input: "labels" },
{ name: "variable_name" },
{ output: "labels" },
'")"',
],
},
}

Expand Down
9 changes: 0 additions & 9 deletions src/lang/syntax/matchers/word_matcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as pt from "@cicada-lang/partech"
import { Word } from "../../word"
import * as matchers from "../matchers"

export function word_matcher(tree: pt.Tree): Word {
return pt.matcher<Word>({
Expand Down Expand Up @@ -61,14 +60,6 @@ export function word_matcher(tree: pt.Tree): Word {
isImportant: true,
span,
}),
"word:node_rearrange": ({ input, name, output }, { span }) => ({
"@type": "Word",
"@kind": "NodeRearrange",
input: matchers.labels_matcher(input),
name: pt.str(name),
output: matchers.labels_matcher(output),
span,
}),
})(tree)
}

Expand Down
10 changes: 0 additions & 10 deletions src/lang/word/Word.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export type Word =
| PortReconnect
| GenrateSymbol
| Label
| NodeRearrange

export type Call = {
"@type": "Word"
Expand Down Expand Up @@ -69,12 +68,3 @@ export type Label = {
isImportant?: boolean
span: Span
}

export type NodeRearrange = {
"@type": "Word"
"@kind": "NodeRearrange"
name: string
input: Array<string>
output: Array<string>
span: Span
}
17 changes: 0 additions & 17 deletions src/lang/word/formatWord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,5 @@ export function formatWord(word: Word): string {
return `:${word.label}`
}
}

case "NodeRearrange": {
const input = word.input.map((name) => `:${name}`).join("")
const output = word.output.map((name) => `:${name}`).join("")

let s = word.name

if (input.length > 0) {
s = `${input} ${s}`
}

if (output.length > 0) {
s = `${s} ${output}`
}

return `(${s})`
}
}
}
18 changes: 0 additions & 18 deletions tests/checking/rearrange-duplicated-name.error.i

This file was deleted.

23 changes: 0 additions & 23 deletions tests/checking/rearrange-duplicated-name.error.i.err

This file was deleted.

18 changes: 0 additions & 18 deletions tests/checking/rearrange-undefined-name.error.i

This file was deleted.

25 changes: 0 additions & 25 deletions tests/checking/rearrange-undefined-name.error.i.err

This file was deleted.

0 comments on commit adaa71a

Please sign in to comment.