Skip to content

Commit

Permalink
cut -- LocalSet
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Aug 2, 2023
1 parent 5dd0d20 commit fd55018
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# type

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

Expand Down
2 changes: 1 addition & 1 deletion src/lang/compose/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function compose(
const port = net.ports.pop()
if (port === undefined) {
throw new Error(
`[LocalSet.compose] expect a port on the top of the stack`,
`[compose / LocalSet] expect a port on the top of the stack`,
)
}

Expand Down
10 changes: 9 additions & 1 deletion src/lang/ctx/Ctx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { Type } from "../type"

export type Sign = 1 | -1

export type SignedType = {
t: Type
sign: Sign
}

export type Ctx = {
types: Array<Type>
signedTypes: Array<SignedType>
localSignedTypes: Map<string, SignedType>
}
3 changes: 2 additions & 1 deletion src/lang/ctx/createCtx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Ctx } from "./Ctx"

export function createCtx(): Ctx {
return {
types: [],
signedTypes: [],
localSignedTypes: new Map(),
}
}
21 changes: 19 additions & 2 deletions src/lang/cut/cut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,28 @@ export function cut(
): void {
switch (word.kind) {
case "Call": {
//
const found = ctx.localSignedTypes.get(word.name)
if (found !== undefined) {
ctx.signedTypes.push(found)
ctx.localSignedTypes.delete(word.name)
return
} else {
//
return
}
}

case "LocalSet": {
//
const signedType = ctx.signedTypes.pop()

if (signedType === undefined) {
throw new Error(
`[cut / LocalSet] expect a signed type on the top of the stack`,
)
}

ctx.localSignedTypes.set(word.name, signedType)
return
}

case "PortPush": {
Expand Down

0 comments on commit fd55018

Please sign in to comment.