@sourceacademy/common-cse-machine 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/common.test.d.ts +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.mjs +1 -0
- package/package.json +34 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";exports.CSE_CHANNEL="__cse",exports.CSE_DIRECTORY_ID="cse-machine",exports.CSE_MESSAGE_TYPE_SNAPSHOTS="snapshots",exports.RUNNER_ID="__runner_cse",exports.WEB_ID="__web_cse";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared, language-agnostic protocol for the Source Academy CSE (Control–Stash–Environment)
|
|
3
|
+
* machine plugin pair.
|
|
4
|
+
*
|
|
5
|
+
* The CSE machine is split into:
|
|
6
|
+
* - a {@link https://github.com/source-academy/conductor | Conductor} **runner** plugin
|
|
7
|
+
* (`@sourceacademy/runner-cse-machine`) that an evaluator feeds serialized evaluation
|
|
8
|
+
* snapshots to, and
|
|
9
|
+
* - a **web/host** plugin (`@sourceacademy/web-cse-machine`) that renders those snapshots
|
|
10
|
+
* as the CSE machine visualization.
|
|
11
|
+
*
|
|
12
|
+
* They communicate over a single {@link CSE_CHANNEL} using {@link CseSnapshotMessage}.
|
|
13
|
+
* Everything that crosses the channel must be plain, structured-clone-able JSON — class
|
|
14
|
+
* instances with methods cannot survive a `MessageChannel`. Each language evaluator
|
|
15
|
+
* (js-slang, py-slang, ...) is responsible for serializing its own control/stash/environment
|
|
16
|
+
* into these shared shapes, keeping the protocol language-agnostic.
|
|
17
|
+
*/
|
|
18
|
+
/** The channel the CSE machine runner and host plugins communicate over. */
|
|
19
|
+
export declare const CSE_CHANNEL = "__cse";
|
|
20
|
+
/** The id of the runner (worker-side) CSE machine plugin. */
|
|
21
|
+
export declare const RUNNER_ID = "__runner_cse";
|
|
22
|
+
/** The id of the web/host (browser-side) CSE machine plugin. */
|
|
23
|
+
export declare const WEB_ID = "__web_cse";
|
|
24
|
+
/**
|
|
25
|
+
* The id used to look the CSE machine up in the plugin directory (i.e. the argument to
|
|
26
|
+
* `IRunnerPlugin.hostLoadPlugin`). The host resolves this to the web plugin's bundle URL.
|
|
27
|
+
*/
|
|
28
|
+
export declare const CSE_DIRECTORY_ID = "cse-machine";
|
|
29
|
+
/** The {@link CseSnapshotMessage.type} discriminator for a batch of snapshots. */
|
|
30
|
+
export declare const CSE_MESSAGE_TYPE_SNAPSHOTS = "snapshots";
|
|
31
|
+
/**
|
|
32
|
+
* A single value on the stash or bound in an environment, serialized to plain JSON.
|
|
33
|
+
*
|
|
34
|
+
* `displayValue` is the already-rendered string the visualizer shows; `label` is a coarse
|
|
35
|
+
* type tag (e.g. `"number"`, `"closure"`). `metadata` carries language-specific extras the
|
|
36
|
+
* web plugin may use (e.g. a closure's defining-frame id, array element refs).
|
|
37
|
+
*/
|
|
38
|
+
export interface CseSerializedValue {
|
|
39
|
+
/** Pre-rendered display string for the value. */
|
|
40
|
+
displayValue: string;
|
|
41
|
+
/** Coarse type label, e.g. `"number"`, `"closure"`, `"list"`. */
|
|
42
|
+
label: string;
|
|
43
|
+
/** Optional fine-grained tag for the visualizer. */
|
|
44
|
+
tag?: string;
|
|
45
|
+
/** Language-specific extra data (closure frame id, element refs, etc.). */
|
|
46
|
+
metadata?: unknown;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A single item on the control, serialized to plain JSON.
|
|
50
|
+
*
|
|
51
|
+
* `displayText` is what the control stack shows. `metadata` carries the typed info the
|
|
52
|
+
* animation/rendering system dispatches on (e.g. `instrType`, `symbol`, `numOfArgs`,
|
|
53
|
+
* `startLine`/`endLine`, `nodeType`).
|
|
54
|
+
*
|
|
55
|
+
* Unlike {@link CseSerializedValue}, instructions have no `label` field: they are operations
|
|
56
|
+
* (apply, branch, assignment, …), not typed values, so a coarse type-tag is not meaningful
|
|
57
|
+
* here. Renderers should use `displayText` for display and `metadata.instrType` (or equivalent)
|
|
58
|
+
* for dispatch.
|
|
59
|
+
*/
|
|
60
|
+
export interface CseSerializedInstruction {
|
|
61
|
+
/** Pre-rendered display text for the control item. */
|
|
62
|
+
displayText: string;
|
|
63
|
+
/** Optional fine-grained tag for the visualizer. */
|
|
64
|
+
tag?: string;
|
|
65
|
+
/** Typed metadata used for animation dispatch and source mapping. */
|
|
66
|
+
metadata?: unknown;
|
|
67
|
+
}
|
|
68
|
+
/** A name → value binding within an environment frame. */
|
|
69
|
+
export interface CseSerializedBinding {
|
|
70
|
+
/** The bound name. */
|
|
71
|
+
name: string;
|
|
72
|
+
/** The bound value. */
|
|
73
|
+
value: CseSerializedValue;
|
|
74
|
+
/** Whether the binding is a constant (e.g. `const` in Source). */
|
|
75
|
+
isConst?: boolean;
|
|
76
|
+
}
|
|
77
|
+
/** A single environment frame, serialized to plain JSON. */
|
|
78
|
+
export interface CseSerializedEnvFrame {
|
|
79
|
+
/** Stable id, unique within a run; referenced by `parentId`/`closureFrameId`. */
|
|
80
|
+
id: string;
|
|
81
|
+
/** Display name of the frame (e.g. function name, `"global"`, `"block"`). */
|
|
82
|
+
name: string;
|
|
83
|
+
/** Id of the lexical parent frame, or `null` for the root. */
|
|
84
|
+
parentId: string | null;
|
|
85
|
+
/** For a closure value's frame: the id of the frame the closure was defined in. */
|
|
86
|
+
closureFrameId?: string;
|
|
87
|
+
/** The name → value bindings in this frame. */
|
|
88
|
+
bindings: CseSerializedBinding[];
|
|
89
|
+
/** Closures/arrays in this frame's heap not bound to any name (anonymous heap objects). */
|
|
90
|
+
heapObjects?: CseSerializedValue[];
|
|
91
|
+
/** Whether this frame is the currently-active (innermost) frame at this step. */
|
|
92
|
+
isActive: boolean;
|
|
93
|
+
/** Whether this frame is currently on the call stack (vs only reachable via a closure). */
|
|
94
|
+
isOnCallStack?: boolean;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A complete snapshot of the CSE machine at a single evaluation step.
|
|
98
|
+
*
|
|
99
|
+
* The arrays are ordered for display (control/stash top-first). `currentLine` is the 1-based
|
|
100
|
+
* source line of the node most recently evaluated at this step (i.e. the language runtime's
|
|
101
|
+
* "current node"), used to drive the editor's current-line highlight; it is `undefined` when
|
|
102
|
+
* there is no current node.
|
|
103
|
+
*/
|
|
104
|
+
export interface CseSnapshot {
|
|
105
|
+
/** 0-based index of this step within the run. */
|
|
106
|
+
stepIndex: number;
|
|
107
|
+
/** Control items, top of control first. */
|
|
108
|
+
control: CseSerializedInstruction[];
|
|
109
|
+
/** Stash values, top of stash first. */
|
|
110
|
+
stash: CseSerializedValue[];
|
|
111
|
+
/** All (live) environment frames at this step. */
|
|
112
|
+
environments: CseSerializedEnvFrame[];
|
|
113
|
+
/** 1-based source line of the node most recently evaluated at this step. */
|
|
114
|
+
currentLine?: number;
|
|
115
|
+
}
|
|
116
|
+
/** The message sent over {@link CSE_CHANNEL} carrying a batch of snapshots for a run. */
|
|
117
|
+
export interface CseSnapshotMessage {
|
|
118
|
+
/** Discriminator; always {@link CSE_MESSAGE_TYPE_SNAPSHOTS}. */
|
|
119
|
+
type: typeof CSE_MESSAGE_TYPE_SNAPSHOTS;
|
|
120
|
+
/** All snapshots for the run, in step order. */
|
|
121
|
+
snapshots: CseSnapshot[];
|
|
122
|
+
/** Convenience count; equals `snapshots.length`. */
|
|
123
|
+
totalSteps: number;
|
|
124
|
+
}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e="__cse",s="__runner_cse",_="__web_cse",c="cse-machine",n="snapshots";export{e as CSE_CHANNEL,c as CSE_DIRECTORY_ID,n as CSE_MESSAGE_TYPE_SNAPSHOTS,s as RUNNER_ID,_ as WEB_ID};
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sourceacademy/common-cse-machine",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"packageManager": "yarn@4.6.0",
|
|
5
|
+
"description": "Shared protocol/types for the Source Academy CSE machine plugin pair",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rollup -c",
|
|
8
|
+
"prepack": "yarn build"
|
|
9
|
+
},
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"main": "dist/index.cjs",
|
|
15
|
+
"module": "dist/index.mjs",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"require": "./dist/index.cjs",
|
|
21
|
+
"types": "./dist/index.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
26
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
27
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
28
|
+
"@vitest/coverage-istanbul": "^4.1.9",
|
|
29
|
+
"rollup": "^4.60.2",
|
|
30
|
+
"tslib": "^2.8.1",
|
|
31
|
+
"typescript": "^6.0.3",
|
|
32
|
+
"vitest": "^4.1.9"
|
|
33
|
+
}
|
|
34
|
+
}
|