Skip to content

Commit

Permalink
execute -- DefineTransition -- call evaluate and define
Browse files Browse the repository at this point in the history
- Mod -- has env
  • Loading branch information
xieyuheng committed Nov 16, 2023
1 parent 9d567dc commit a8dbd84
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 12 deletions.
5 changes: 0 additions & 5 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
execute -- DefineTransition -- call evaluate and define
execute -- Begin -- `createEnv` and run

- [maybe] Mod -- has no env -- top level `evaluate`



[connect] connectTransitionToInputs(net: Net, transition: Transition, places: Array<Place>)
[connect] connectTransitionToOutputs(net: Net, transition: Transition, places: Array<Place>)

Expand Down
17 changes: 17 additions & 0 deletions src/lang/env/createEnv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Env } from "../env"
import { Mod } from "../mod"
import { Net } from "../net"
import { createNet } from "../net/createNet"

export function createEnv(
mod: Mod,
options?: {
net?: Net
},
): Env {
return {
mod,
net: options?.net || createNet(),
locals: new Map(),
}
}
1 change: 1 addition & 0 deletions src/lang/env/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./Env"
export * from "./createEnv"
30 changes: 26 additions & 4 deletions src/lang/execute/execute.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
import { appendReport } from "../errors"
// import { evaluate, evaluateOne, evaluateParameters } from "../evaluate"
import { Mod } from "../mod"
// import { Mod, define } from "../mod"
import { EvaluateOptions, evaluateParameters } from "../evaluate"
import { Mod, define } from "../mod"
import { Stmt } from "../stmt"

export async function execute(mod: Mod, stmt: Stmt): Promise<null> {
try {
const options: EvaluateOptions = {}

switch (stmt["@kind"]) {
case "DefineTransition": {
console.log("[execute / DefineTransition] TODO")
const inputParameters = evaluateParameters(
mod,
mod.env,
stmt.inputParameters,
options,
)
const outputParameters = evaluateParameters(
mod,
mod.env,
stmt.outputParameters,
options,
)
define(mod, stmt.name, {
"@type": "Definition",
"@kind": "TransitionDefinition",
mod,
name: stmt.name,
inputParameters,
outputParameters,
span: stmt.span,
body: stmt.body,
})
return null
}

Expand Down
2 changes: 2 additions & 0 deletions src/lang/mod/Mod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Stmt } from "../stmt"
import { Env } from "../env"
import { Definition } from "../definition"

export type Mod = {
env: Env
url: URL
text: string
stmts: Array<Stmt>
Expand Down
6 changes: 3 additions & 3 deletions src/lang/mod/createMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Loader } from "../../loader"
import { Stmt } from "../stmt"
// import { defineBuiltins } from "../builtins/defineBuiltins"
// import { createChecking } from "../checking/createChecking"
// import { createEnv } from "../env/createEnv"
import { createEnv } from "../env/createEnv"
import { Mod } from "./Mod"

export function createMod(options: {
Expand All @@ -19,9 +19,9 @@ export function createMod(options: {
definitions: new Map(),
// builtins: new Map(),
// requiredMods: new Map(),
} as Mod
} as unknown as Mod

// mod.env = createEnv(mod)
mod.env = createEnv(mod)
// mod.checking = createChecking()

// defineBuiltins(mod)
Expand Down

0 comments on commit a8dbd84

Please sign in to comment.