From fa0271b72623d683386aa7c0bb229406789a5a6b Mon Sep 17 00:00:00 2001 From: Xie Yuheng Date: Fri, 17 Nov 2023 16:30:55 +0800 Subject: [PATCH] [net] `TransitionEntry` -- has optional `task` -- with any async callback function --- TODO.md | 4 ++-- package-lock.json | 32 +++++++++++++++++++++++++++++ package.json | 2 ++ src/lang/net/Net.ts | 2 ++ src/lang/net/fireTransitionEntry.ts | 8 ++++++++ src/lang/net/index.ts | 1 + src/lang/react/react.ts | 3 ++- src/lang/task/Task.ts | 5 +++++ src/lang/task/index.ts | 1 + 9 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/lang/net/fireTransitionEntry.ts create mode 100644 src/lang/task/Task.ts create mode 100644 src/lang/task/index.ts diff --git a/TODO.md b/TODO.md index 7b933b7..36c1a75 100644 --- a/TODO.md +++ b/TODO.md @@ -1,8 +1,8 @@ # net -[net] use vue `reactive` primitives +[net] `fireTransitionEntry` -- try to fire one transition entry -[net] `react` +[net] `run` - when we add a data into a place, all the neighboring transitions are checked for preparedness, diff --git a/package-lock.json b/package-lock.json index 4e6af9a..cb04339 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,8 +11,10 @@ "dependencies": { "@cicada-lang/framework": "^0.1.6", "@cicada-lang/partech": "^0.2.5", + "@vue/runtime-core": "^3.3.8", "@xieyuheng/command-line": "^0.0.13", "@xieyuheng/ty": "^0.1.26", + "events": "^3.3.0", "picocolors": "^1.0.0", "vitest": "^0.34.6" }, @@ -547,6 +549,28 @@ "url": "https://opencollective.com/vitest" } }, + "node_modules/@vue/reactivity": { + "version": "3.3.8", + "resolved": "https://registry.npmjs.org/@vue/reactivity/-/reactivity-3.3.8.tgz", + "integrity": "sha512-ctLWitmFBu6mtddPyOKpHg8+5ahouoTCRtmAHZAXmolDtuZXfjL2T3OJ6DL6ezBPQB1SmMnpzjiWjCiMYmpIuw==", + "dependencies": { + "@vue/shared": "3.3.8" + } + }, + "node_modules/@vue/runtime-core": { + "version": "3.3.8", + "resolved": "https://registry.npmjs.org/@vue/runtime-core/-/runtime-core-3.3.8.tgz", + "integrity": "sha512-qurzOlb6q26KWQ/8IShHkMDOuJkQnQcTIp1sdP4I9MbCf9FJeGVRXJFr2mF+6bXh/3Zjr9TDgURXrsCr9bfjUw==", + "dependencies": { + "@vue/reactivity": "3.3.8", + "@vue/shared": "3.3.8" + } + }, + "node_modules/@vue/shared": { + "version": "3.3.8", + "resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.3.8.tgz", + "integrity": "sha512-8PGwybFwM4x8pcfgqEQFy70NaQxASvOC5DJwLQfpArw1UDfUXrJkdxD3BhVTMS+0Lef/TU7YO0Jvr0jJY8T+mw==" + }, "node_modules/@xieyuheng/command-line": { "version": "0.0.13", "resolved": "https://registry.npmjs.org/@xieyuheng/command-line/-/command-line-0.0.13.tgz", @@ -841,6 +865,14 @@ "@esbuild/win32-x64": "0.18.20" } }, + "node_modules/events": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", + "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", + "engines": { + "node": ">=0.8.x" + } + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", diff --git a/package.json b/package.json index cab9818..84f28ab 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,10 @@ "dependencies": { "@cicada-lang/framework": "^0.1.6", "@cicada-lang/partech": "^0.2.5", + "@vue/runtime-core": "^3.3.8", "@xieyuheng/command-line": "^0.0.13", "@xieyuheng/ty": "^0.1.26", + "events": "^3.3.0", "picocolors": "^1.0.0", "vitest": "^0.34.6" }, diff --git a/src/lang/net/Net.ts b/src/lang/net/Net.ts index cf7769e..e89cf23 100644 --- a/src/lang/net/Net.ts +++ b/src/lang/net/Net.ts @@ -1,4 +1,5 @@ import { Parameter } from "../parameter" +import { Task } from "../task" import { Value } from "../value" /* @@ -24,6 +25,7 @@ export type TransitionEntry = { outputParameters: Array inputPlaceEntries: Array outputPlaceEntries: Array + task?: Task } export type PlaceEntry = { diff --git a/src/lang/net/fireTransitionEntry.ts b/src/lang/net/fireTransitionEntry.ts new file mode 100644 index 0000000..0f8cb77 --- /dev/null +++ b/src/lang/net/fireTransitionEntry.ts @@ -0,0 +1,8 @@ +import { Net, TransitionEntry } from "./Net" + +export async function fireTransitionEntry( + net: Net, + transitionEntry: TransitionEntry, +) { + // +} diff --git a/src/lang/net/index.ts b/src/lang/net/index.ts index 1fa8f0e..cd7b28d 100644 --- a/src/lang/net/index.ts +++ b/src/lang/net/index.ts @@ -1,4 +1,5 @@ export * from "./Net" +export * from "./fireTransitionEntry" export * from "./createNet" export * from "./addPlace" export * from "./addTransition" diff --git a/src/lang/react/react.ts b/src/lang/react/react.ts index 50470f0..4198eaf 100644 --- a/src/lang/react/react.ts +++ b/src/lang/react/react.ts @@ -1,5 +1,6 @@ +import { reactive } from "@vue/runtime-core" import { Net } from "../net" export function react(net: Net): void { - // + reactive } diff --git a/src/lang/task/Task.ts b/src/lang/task/Task.ts new file mode 100644 index 0000000..65d46da --- /dev/null +++ b/src/lang/task/Task.ts @@ -0,0 +1,5 @@ +export type TaskFunction = (...args: Array) => Promise> + +export type Task = { + fn: TaskFunction +} diff --git a/src/lang/task/index.ts b/src/lang/task/index.ts new file mode 100644 index 0000000..e96e850 --- /dev/null +++ b/src/lang/task/index.ts @@ -0,0 +1 @@ +export * from "./Task"