@java-memory-playground/java-memory-playground 0.2.4 → 0.2.5

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/memory.d.ts CHANGED
@@ -11,6 +11,14 @@ export declare const numericDataTypes: string[];
11
11
  export declare const primitveDataTypes: string[];
12
12
  /** The class name of the heap objects that hold String values. */
13
13
  export declare const STRING_KLASS = "String";
14
+ export declare const ARRAY_KLASS = "Array";
15
+ /**
16
+ * The field holding an array's length.
17
+ *
18
+ * Java fixes it when the array is created and there is no assigning to it
19
+ * afterwards, so the diagram does not offer a field to type in either.
20
+ */
21
+ export declare const ARRAY_LENGTH = "length";
14
22
  /** Types always offered in a type picker, before the user's own classes. */
15
23
  export declare const builtInDataTypes: string[];
16
24
  /**
@@ -97,6 +105,14 @@ export type Step = {
97
105
  * they build against it.
98
106
  */
99
107
  exercise?: boolean;
108
+ /**
109
+ * Assignments the reader may run against this step, in an order they choose.
110
+ *
111
+ * Each is evaluated when it is pressed, against the diagram as it stands, so
112
+ * running them in the wrong order produces the broken picture rather than a
113
+ * wrong answer. They belong to the instruction, like the label and the note.
114
+ */
115
+ statements?: string[];
100
116
  objects: Objs;
101
117
  variables: Variables;
102
118
  methodCalls: MethodCalls;
@@ -0,0 +1,67 @@
1
+ import { CustomEdgeType, CustomNodeType } from "./types";
2
+ /**
3
+ * Assignments a reader can fire at the diagram, one at a time.
4
+ *
5
+ * Dragging an edge onto its target says where a reference should end up. It
6
+ * cannot say what `neu.next = current.next` means, because that depends on
7
+ * where `current.next` points *at the moment the line runs* — which is the
8
+ * whole difficulty of rewiring a linked list. An assignment executed against
9
+ * the current state says it: run the two lines the other way round and the
10
+ * reader watches the node point at itself.
11
+ *
12
+ * The right-hand side is read from the diagram on screen, never from the text,
13
+ * so a wrong order produces the broken picture rather than a wrong answer.
14
+ */
15
+ /** One side of an assignment: a root name followed by attribute steps. */
16
+ type Path = {
17
+ root: string;
18
+ attributes: string[];
19
+ };
20
+ /**
21
+ * A place a reference can be written to: an edge leaving `nodeId`. A global
22
+ * variable has one nameless outgoing edge; an object attribute and a local
23
+ * variable of a frame each have one per handle.
24
+ */
25
+ export type Slot = {
26
+ nodeId: string;
27
+ /** The source handle, or undefined for a global variable. */
28
+ handle?: string;
29
+ };
30
+ export type StatementError = {
31
+ code: "malformed";
32
+ } | {
33
+ code: "unknownName";
34
+ name: string;
35
+ } | {
36
+ code: "nullDereference";
37
+ path: string;
38
+ } | {
39
+ code: "unknownAttribute";
40
+ name: string;
41
+ klass: string;
42
+ } | {
43
+ code: "notAReference";
44
+ path: string;
45
+ };
46
+ export type StatementResult = {
47
+ ok: true;
48
+ edges: CustomEdgeType[];
49
+ } | {
50
+ ok: false;
51
+ error: StatementError;
52
+ };
53
+ /** Splits `a.b = c.d` into its two sides. */
54
+ export declare const parseStatement: (text: string) => {
55
+ target: Path;
56
+ source: Path | null;
57
+ } | null;
58
+ /**
59
+ * Runs one assignment against a diagram and returns the edges it leaves behind.
60
+ *
61
+ * Nothing is mutated: a caller that gets an error can show it without having
62
+ * half-applied the line.
63
+ */
64
+ export declare const executeStatement: (text: string, nodes: CustomNodeType[], edges: CustomEdgeType[]) => StatementResult;
65
+ /** Splits an authored list, so that a teacher may type them on one line. */
66
+ export declare const parseStatementList: (text: string) => string[];
67
+ export {};
package/dist/store.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { EdgeChange, NodeChange, Viewport } from "@xyflow/react";
2
2
  import { ExerciseResult } from "./canonical";
3
3
  import { Memory } from "./memory";
4
4
  import { Translations } from "./translations";
5
+ import { StatementError } from "./statements";
5
6
  import { CustomEdgeType, CustomNodeType } from "./types";
6
7
  export type Route = "view" | "config";
7
8
  /**
@@ -17,9 +18,16 @@ export type StoreStep = {
17
18
  label?: string;
18
19
  note?: string;
19
20
  exercise?: boolean;
21
+ statements?: string[];
20
22
  nodes: CustomNodeType[];
21
23
  edges: CustomEdgeType[];
22
24
  };
25
+ /** One line the reader ran, kept in the order they ran them. */
26
+ export type StatementEntry = {
27
+ text: string;
28
+ /** Why it could not run, when it could not. */
29
+ error?: StatementError;
30
+ };
23
31
  /**
24
32
  * Where a step stands for the reader, as the strip of dots shows it.
25
33
  *
@@ -64,6 +72,13 @@ export type RFState = {
64
72
  solutions: Record<number, StoreStep>;
65
73
  /** The last check of each exercise step, by step index. */
66
74
  exerciseResults: Record<number, CheckedAttempt>;
75
+ /** What the reader has run on each step, by step index. */
76
+ statementLog: Record<number, StatementEntry[]>;
77
+ /**
78
+ * The state each step was in before its first statement ran, so that the
79
+ * reader can start the sequence over without hunting for the undo key.
80
+ */
81
+ statementStart: Record<number, StoreStep>;
67
82
  /** Ids of the objects a prediction has marked as unreachable, while running. */
68
83
  gcPrediction: string[] | null;
69
84
  gcResult: GcPredictionResult | null;
@@ -78,6 +93,7 @@ export type RFState = {
78
93
  addStep: () => void;
79
94
  deleteStep: (index: number) => void;
80
95
  setStepLabel: (index: number, label: string) => void;
96
+ setStepNote: (index: number, note: string) => void;
81
97
  /** The nodes and edges of the step on screen. */
82
98
  getNodes: () => CustomNodeType[];
83
99
  getEdges: () => CustomEdgeType[];
@@ -100,6 +116,13 @@ export type RFState = {
100
116
  /** The check of the step on screen, or null if it has none or it is stale. */
101
117
  getExerciseResult: () => ExerciseResult | null;
102
118
  getStepStatus: (index: number) => StepStatus;
119
+ setStepStatements: (index: number, statements: string[]) => void;
120
+ /** Runs one line against the step on screen and records what it did. */
121
+ runStatement: (text: string) => void;
122
+ /** Puts the step back to where the first line found it. */
123
+ resetStatements: () => void;
124
+ getStatements: () => string[];
125
+ getStatementLog: () => StatementEntry[];
103
126
  startGcPrediction: () => void;
104
127
  toggleGcPrediction: (id: string) => void;
105
128
  cancelGcPrediction: () => void;
@@ -26,14 +26,31 @@ export interface Translations {
26
26
  deleteStep: string;
27
27
  stepLabel: string;
28
28
  stepLabelPlaceholder: string;
29
+ stepNote: string;
30
+ stepNotePlaceholder: string;
31
+ showHint: string;
32
+ hideHint: string;
29
33
  exerciseStep: string;
30
34
  exerciseStepHint: string;
31
35
  yourTurn: string;
36
+ exerciseBadge: string;
32
37
  checkAnswer: string;
33
38
  showSolution: string;
34
39
  exerciseCorrect: string;
35
40
  exerciseWrong: (wrong: string[]) => string;
36
41
  exerciseExtra: (extra: string[]) => string;
42
+ statements: string;
43
+ statementsPlaceholder: string;
44
+ statementsHint: string;
45
+ runStatement: (statement: string) => string;
46
+ statementLog: string;
47
+ resetStatements: string;
48
+ resetStatementsHint: string;
49
+ statementMalformed: string;
50
+ statementUnknownName: (name: string) => string;
51
+ statementNullDereference: (path: string) => string;
52
+ statementUnknownAttribute: (name: string, klass: string) => string;
53
+ statementNotAReference: (path: string) => string;
37
54
  stepOverview: string;
38
55
  stepStatusNone: (step: number) => string;
39
56
  stepStatusUntried: (step: number) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@java-memory-playground/java-memory-playground",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "author": "Mike Barkmin",
5
5
  "description": "React components for visualizing the Java stack and heap.",
6
6
  "homepage": "https://github.com/openpatch/java-memory-playground#readme",