Skip to content

Commit

Permalink
assertValueKind
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Nov 16, 2023
1 parent 917b2b8 commit d7b6e48
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/lang/evaluate/evaluateBlockStmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { formatBlockStmt } from "../exp/formatBlockStmt"
import { Mod } from "../mod"
import { Value } from "../value"
import { EvaluateOptions } from "./evaluate"
import { evaluateOne } from "./evaluateOne"

export function evaluateBlockStmt(
mod: Mod,
Expand All @@ -15,6 +16,13 @@ export function evaluateBlockStmt(
try {
switch (stmt["@kind"]) {
case "Connect": {
const transition = evaluateOne(mod, env, stmt.transition, options)
const inputArgs = stmt.inputArgs.map((arg) =>
evaluateOne(mod, env, arg, options),
)
const outputArgs = stmt.outputArgs.map((arg) =>
evaluateOne(mod, env, arg, options),
)
throw new Error("TODO")
}

Expand Down
4 changes: 2 additions & 2 deletions src/lang/evaluate/evaluateParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Env } from "../env"
import { Mod } from "../mod"
import { Parameter, ParameterExp } from "../parameter"
import { EvaluateOptions } from "./evaluate"
import { evaluate } from "./evaluate"
import { evaluateOne } from "./evaluateOne"

export function evaluateParameters(
mod: Mod,
Expand All @@ -12,6 +12,6 @@ export function evaluateParameters(
): Array<Parameter> {
return parameterExps.map(({ name, t }) => ({
name,
t: evaluate(mod, env, t, options),
t: evaluateOne(mod, env, t, options),
}))
}
7 changes: 4 additions & 3 deletions src/lang/value/Value.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export type Value = {
//
}
import { Place } from "../place"
import { Transition } from "../transition"

export type Value = Place | Transition
16 changes: 16 additions & 0 deletions src/lang/value/assertValueKind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Value } from "../value"

export function assertValueKind<Kind extends Value["@kind"]>(
value: Value,
kind: Kind,
): asserts value is Extract<Value, { "@kind": Kind }> {
if (value["@kind"] !== kind) {
throw new Error(
[
`[assertValueKind] fail`,
`- expect kind: ${kind}`,
`- found kind: ${value["@kind"]}`,
].join("\n"),
)
}
}
1 change: 1 addition & 0 deletions src/lang/value/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./Value"
export * from "./formatValue"
export * from "./assertValueKind"

0 comments on commit d7b6e48

Please sign in to comment.