Skip to content

Commit

Permalink
PortExp take type
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Aug 1, 2023
1 parent 37f485b commit d295522
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
8 changes: 3 additions & 5 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# type

`PortExp` take `type`

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

`defnode` -- support type

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

`defnet` -- type check -- cut -- words composition

`defnode` -- check type -- arity of defined types

[maybe] `defdata`

```inet
Expand Down
3 changes: 3 additions & 0 deletions src/lang/graph/PortExp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Type } from "../type"

export type PortExp = {
name: string
t: Type
isPrincipal: boolean
}
16 changes: 11 additions & 5 deletions src/lang/mod/defineBuiltInOperators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Port } from "../graph"
import { connect } from "../graph/connect"
import { createNode } from "../graph/createNode"
import { Mod } from "../mod"
import * as Types from "../type"
import { defineOperator } from "./defineOperator"

export function defineBuiltInOperators(mod: Mod): void {
Expand Down Expand Up @@ -30,17 +31,22 @@ export function defineBuiltInOperators(mod: Mod): void {
"wire",
[],
[
{ name: "left", isPrincipal: false },
{ name: "right", isPrincipal: true },
{
name: "left",
t: Types.TypeVar("a"),
isPrincipal: false,
},
{
name: "right",
t: Types.TypeVar("a"),
isPrincipal: true,
},
],
)

net.ports.push(...node.output)

net.nodes.push(node)

const [start, end] = node.output

net.wires.push({ start, end })
})
}
3 changes: 3 additions & 0 deletions src/lang/syntax/matchers/port_matcher.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import * as pt from "@cicada-lang/partech"
import { PortExp } from "../../graph/PortExp"
import * as matchers from "../matchers"

export function port_matcher(tree: pt.Tree): PortExp {
return pt.matcher<PortExp>({
"port:normal": ({ name, type }, { span }) => ({
name: pt.str(name),
t: matchers.type_matcher(type),
isPrincipal: false,
}),
"port:principal": ({ name, type }, { span }) => ({
name: pt.str(name),
t: matchers.type_matcher(type),
isPrincipal: true,
}),
})(tree)
Expand Down

0 comments on commit d295522

Please sign in to comment.