@sccharts-lab/engine 0.0.0-stage → 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/LICENSE +277 -0
- package/README.md +125 -2
- package/dist/codegen/expr.d.ts +36 -0
- package/dist/codegen/expr.js +252 -0
- package/dist/codegen/expr.js.map +1 -0
- package/dist/codegen/index.d.ts +4 -0
- package/dist/codegen/index.js +238 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/layout.d.ts +57 -0
- package/dist/codegen/layout.js +306 -0
- package/dist/codegen/layout.js.map +1 -0
- package/dist/codegen/logic.d.ts +31 -0
- package/dist/codegen/logic.js +258 -0
- package/dist/codegen/logic.js.map +1 -0
- package/dist/codegen/methods.d.ts +17 -0
- package/dist/codegen/methods.js +242 -0
- package/dist/codegen/methods.js.map +1 -0
- package/dist/codegen/reset.d.ts +6 -0
- package/dist/codegen/reset.js +110 -0
- package/dist/codegen/reset.js.map +1 -0
- package/dist/codegen/types.d.ts +81 -0
- package/dist/codegen/types.js +3 -0
- package/dist/codegen/types.js.map +1 -0
- package/dist/format.d.ts +136 -0
- package/dist/format.js +872 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +120 -0
- package/dist/index.js +507 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +4 -0
- package/dist/internal.js.map +1 -0
- package/dist/parser/ids.d.ts +4 -0
- package/dist/parser/ids.js +172 -0
- package/dist/parser/ids.js.map +1 -0
- package/dist/parser/imports.d.ts +2 -0
- package/dist/parser/imports.js +28 -0
- package/dist/parser/imports.js.map +1 -0
- package/dist/parser/interface.d.ts +10 -0
- package/dist/parser/interface.js +93 -0
- package/dist/parser/interface.js.map +1 -0
- package/dist/parser/kielerWording.d.ts +2 -0
- package/dist/parser/kielerWording.js +196 -0
- package/dist/parser/kielerWording.js.map +1 -0
- package/dist/parser/lexer.d.ts +25 -0
- package/dist/parser/lexer.js +334 -0
- package/dist/parser/lexer.js.map +1 -0
- package/dist/parser/parser.d.ts +29 -0
- package/dist/parser/parser.js +3249 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/resolve.d.ts +46 -0
- package/dist/parser/resolve.js +919 -0
- package/dist/parser/resolve.js.map +1 -0
- package/dist/parser/source.d.ts +15 -0
- package/dist/parser/source.js +42 -0
- package/dist/parser/source.js.map +1 -0
- package/dist/parser/validate.d.ts +5 -0
- package/dist/parser/validate.js +1430 -0
- package/dist/parser/validate.js.map +1 -0
- package/dist/sim/abortRegions.d.ts +9 -0
- package/dist/sim/abortRegions.js +192 -0
- package/dist/sim/abortRegions.js.map +1 -0
- package/dist/sim/analysis.d.ts +113 -0
- package/dist/sim/analysis.js +1104 -0
- package/dist/sim/analysis.js.map +1 -0
- package/dist/sim/codegen.d.ts +30 -0
- package/dist/sim/codegen.js +730 -0
- package/dist/sim/codegen.js.map +1 -0
- package/dist/sim/compile.d.ts +43 -0
- package/dist/sim/compile.js +1062 -0
- package/dist/sim/compile.js.map +1 -0
- package/dist/sim/deps.d.ts +73 -0
- package/dist/sim/deps.js +481 -0
- package/dist/sim/deps.js.map +1 -0
- package/dist/sim/describe.d.ts +22 -0
- package/dist/sim/describe.js +272 -0
- package/dist/sim/describe.js.map +1 -0
- package/dist/sim/describePreemption.d.ts +22 -0
- package/dist/sim/describePreemption.js +90 -0
- package/dist/sim/describePreemption.js.map +1 -0
- package/dist/sim/describeStructure.d.ts +75 -0
- package/dist/sim/describeStructure.js +293 -0
- package/dist/sim/describeStructure.js.map +1 -0
- package/dist/sim/eval.d.ts +99 -0
- package/dist/sim/eval.js +644 -0
- package/dist/sim/eval.js.map +1 -0
- package/dist/sim/exec.d.ts +212 -0
- package/dist/sim/exec.js +874 -0
- package/dist/sim/exec.js.map +1 -0
- package/dist/sim/fold.d.ts +2 -0
- package/dist/sim/fold.js +40 -0
- package/dist/sim/fold.js.map +1 -0
- package/dist/sim/goblock.d.ts +16 -0
- package/dist/sim/goblock.js +171 -0
- package/dist/sim/goblock.js.map +1 -0
- package/dist/sim/guardIndices.d.ts +13 -0
- package/dist/sim/guardIndices.js +137 -0
- package/dist/sim/guardIndices.js.map +1 -0
- package/dist/sim/index.d.ts +43 -0
- package/dist/sim/index.js +138 -0
- package/dist/sim/index.js.map +1 -0
- package/dist/sim/lower.d.ts +33 -0
- package/dist/sim/lower.js +716 -0
- package/dist/sim/lower.js.map +1 -0
- package/dist/sim/memory.d.ts +47 -0
- package/dist/sim/memory.js +328 -0
- package/dist/sim/memory.js.map +1 -0
- package/dist/sim/model.d.ts +487 -0
- package/dist/sim/model.js +772 -0
- package/dist/sim/model.js.map +1 -0
- package/dist/sim/passes/abort.d.ts +2 -0
- package/dist/sim/passes/abort.js +269 -0
- package/dist/sim/passes/abort.js.map +1 -0
- package/dist/sim/passes/abortRegion.d.ts +10 -0
- package/dist/sim/passes/abortRegion.js +62 -0
- package/dist/sim/passes/abortRegion.js.map +1 -0
- package/dist/sim/passes/arrayAssignment.d.ts +2 -0
- package/dist/sim/passes/arrayAssignment.js +147 -0
- package/dist/sim/passes/arrayAssignment.js.map +1 -0
- package/dist/sim/passes/codeEffects.d.ts +2 -0
- package/dist/sim/passes/codeEffects.js +14 -0
- package/dist/sim/passes/codeEffects.js.map +1 -0
- package/dist/sim/passes/complexFinalState.d.ts +4 -0
- package/dist/sim/passes/complexFinalState.js +77 -0
- package/dist/sim/passes/complexFinalState.js.map +1 -0
- package/dist/sim/passes/connector.d.ts +2 -0
- package/dist/sim/passes/connector.js +18 -0
- package/dist/sim/passes/connector.js.map +1 -0
- package/dist/sim/passes/contained.d.ts +37 -0
- package/dist/sim/passes/contained.js +198 -0
- package/dist/sim/passes/contained.js.map +1 -0
- package/dist/sim/passes/context.d.ts +39 -0
- package/dist/sim/passes/context.js +3 -0
- package/dist/sim/passes/context.js.map +1 -0
- package/dist/sim/passes/countDelay.d.ts +2 -0
- package/dist/sim/passes/countDelay.js +51 -0
- package/dist/sim/passes/countDelay.js.map +1 -0
- package/dist/sim/passes/dataflow.d.ts +11 -0
- package/dist/sim/passes/dataflow.js +319 -0
- package/dist/sim/passes/dataflow.js.map +1 -0
- package/dist/sim/passes/deferred.d.ts +2 -0
- package/dist/sim/passes/deferred.js +345 -0
- package/dist/sim/passes/deferred.js.map +1 -0
- package/dist/sim/passes/detect.d.ts +10 -0
- package/dist/sim/passes/detect.js +33 -0
- package/dist/sim/passes/detect.js.map +1 -0
- package/dist/sim/passes/during.d.ts +2 -0
- package/dist/sim/passes/during.js +67 -0
- package/dist/sim/passes/during.js.map +1 -0
- package/dist/sim/passes/entry.d.ts +5 -0
- package/dist/sim/passes/entry.js +93 -0
- package/dist/sim/passes/entry.js.map +1 -0
- package/dist/sim/passes/enum.d.ts +2 -0
- package/dist/sim/passes/enum.js +22 -0
- package/dist/sim/passes/enum.js.map +1 -0
- package/dist/sim/passes/exit.d.ts +4 -0
- package/dist/sim/passes/exit.js +120 -0
- package/dist/sim/passes/exit.js.map +1 -0
- package/dist/sim/passes/finalRegion.d.ts +2 -0
- package/dist/sim/passes/finalRegion.js +21 -0
- package/dist/sim/passes/finalRegion.js.map +1 -0
- package/dist/sim/passes/followedBy.d.ts +2 -0
- package/dist/sim/passes/followedBy.js +78 -0
- package/dist/sim/passes/followedBy.js.map +1 -0
- package/dist/sim/passes/forRegion.d.ts +9 -0
- package/dist/sim/passes/forRegion.js +230 -0
- package/dist/sim/passes/forRegion.js.map +1 -0
- package/dist/sim/passes/history.d.ts +12 -0
- package/dist/sim/passes/history.js +115 -0
- package/dist/sim/passes/history.js.map +1 -0
- package/dist/sim/passes/hostCode.d.ts +2 -0
- package/dist/sim/passes/hostCode.js +152 -0
- package/dist/sim/passes/hostCode.js.map +1 -0
- package/dist/sim/passes/index.d.ts +4 -0
- package/dist/sim/passes/index.js +84 -0
- package/dist/sim/passes/index.js.map +1 -0
- package/dist/sim/passes/inheritance.d.ts +8 -0
- package/dist/sim/passes/inheritance.js +233 -0
- package/dist/sim/passes/inheritance.js.map +1 -0
- package/dist/sim/passes/initOperator.d.ts +2 -0
- package/dist/sim/passes/initOperator.js +68 -0
- package/dist/sim/passes/initOperator.js.map +1 -0
- package/dist/sim/passes/initialization.d.ts +2 -0
- package/dist/sim/passes/initialization.js +69 -0
- package/dist/sim/passes/initialization.js.map +1 -0
- package/dist/sim/passes/ode.d.ts +2 -0
- package/dist/sim/passes/ode.js +14 -0
- package/dist/sim/passes/ode.js.map +1 -0
- package/dist/sim/passes/period.d.ts +2 -0
- package/dist/sim/passes/period.js +106 -0
- package/dist/sim/passes/period.js.map +1 -0
- package/dist/sim/passes/prTransitions.d.ts +2 -0
- package/dist/sim/passes/prTransitions.js +12 -0
- package/dist/sim/passes/prTransitions.js.map +1 -0
- package/dist/sim/passes/pre.d.ts +4 -0
- package/dist/sim/passes/pre.js +326 -0
- package/dist/sim/passes/pre.js.map +1 -0
- package/dist/sim/passes/quirks.d.ts +2 -0
- package/dist/sim/passes/quirks.js +169 -0
- package/dist/sim/passes/quirks.js.map +1 -0
- package/dist/sim/passes/reference.d.ts +60 -0
- package/dist/sim/passes/reference.js +386 -0
- package/dist/sim/passes/reference.js.map +1 -0
- package/dist/sim/passes/regionActions.d.ts +2 -0
- package/dist/sim/passes/regionActions.js +56 -0
- package/dist/sim/passes/regionActions.js.map +1 -0
- package/dist/sim/passes/sequentialFollowedBy.d.ts +2 -0
- package/dist/sim/passes/sequentialFollowedBy.js +72 -0
- package/dist/sim/passes/sequentialFollowedBy.js.map +1 -0
- package/dist/sim/passes/signal.d.ts +2 -0
- package/dist/sim/passes/signal.js +230 -0
- package/dist/sim/passes/signal.js.map +1 -0
- package/dist/sim/passes/static.d.ts +5 -0
- package/dist/sim/passes/static.js +67 -0
- package/dist/sim/passes/static.js.map +1 -0
- package/dist/sim/passes/suspend.d.ts +10 -0
- package/dist/sim/passes/suspend.js +71 -0
- package/dist/sim/passes/suspend.js.map +1 -0
- package/dist/sim/passes/termination.d.ts +9 -0
- package/dist/sim/passes/termination.js +69 -0
- package/dist/sim/passes/termination.js.map +1 -0
- package/dist/sim/passes/timedAutomata.d.ts +10 -0
- package/dist/sim/passes/timedAutomata.js +437 -0
- package/dist/sim/passes/timedAutomata.js.map +1 -0
- package/dist/sim/passes/unpackClasses.d.ts +2 -0
- package/dist/sim/passes/unpackClasses.js +54 -0
- package/dist/sim/passes/unpackClasses.js.map +1 -0
- package/dist/sim/passes/userSchedule.d.ts +2 -0
- package/dist/sim/passes/userSchedule.js +43 -0
- package/dist/sim/passes/userSchedule.js.map +1 -0
- package/dist/sim/passes/weakSuspend.d.ts +2 -0
- package/dist/sim/passes/weakSuspend.js +145 -0
- package/dist/sim/passes/weakSuspend.js.map +1 -0
- package/dist/sim/preemptionLog.d.ts +41 -0
- package/dist/sim/preemptionLog.js +133 -0
- package/dist/sim/preemptionLog.js.map +1 -0
- package/dist/sim/random.d.ts +12 -0
- package/dist/sim/random.js +40 -0
- package/dist/sim/random.js.map +1 -0
- package/dist/sim/reasons.d.ts +29 -0
- package/dist/sim/reasons.js +168 -0
- package/dist/sim/reasons.js.map +1 -0
- package/dist/sim/scg.d.ts +124 -0
- package/dist/sim/scg.js +723 -0
- package/dist/sim/scg.js.map +1 -0
- package/dist/sim/sfr.d.ts +4 -0
- package/dist/sim/sfr.js +264 -0
- package/dist/sim/sfr.js.map +1 -0
- package/dist/sim/stringConditions.d.ts +3 -0
- package/dist/sim/stringConditions.js +42 -0
- package/dist/sim/stringConditions.js.map +1 -0
- package/dist/sim/structure/copy.d.ts +4 -0
- package/dist/sim/structure/copy.js +140 -0
- package/dist/sim/structure/copy.js.map +1 -0
- package/dist/sim/structure/delays.d.ts +30 -0
- package/dist/sim/structure/delays.js +127 -0
- package/dist/sim/structure/delays.js.map +1 -0
- package/dist/sim/structure/instance.d.ts +15 -0
- package/dist/sim/structure/instance.js +69 -0
- package/dist/sim/structure/instance.js.map +1 -0
- package/dist/sim/structure/methods.d.ts +19 -0
- package/dist/sim/structure/methods.js +550 -0
- package/dist/sim/structure/methods.js.map +1 -0
- package/dist/sim/structure/rewrite.d.ts +20 -0
- package/dist/sim/structure/rewrite.js +113 -0
- package/dist/sim/structure/rewrite.js.map +1 -0
- package/dist/sim/structure/track.d.ts +22 -0
- package/dist/sim/structure/track.js +123 -0
- package/dist/sim/structure/track.js.map +1 -0
- package/dist/sim/tracker.d.ts +77 -0
- package/dist/sim/tracker.js +265 -0
- package/dist/sim/tracker.js.map +1 -0
- package/dist/sim/values.d.ts +31 -0
- package/dist/sim/values.js +103 -0
- package/dist/sim/values.js.map +1 -0
- package/dist/types.d.ts +670 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +58 -3
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// The source-level configuration: which states of the chart as written are active. The executor runs KIELER's
|
|
2
|
+
// rewritten chart; every source transition carries a `take` mark there, and when one fires this tracker leaves
|
|
3
|
+
// its source state (with everything active inside, innermost first) and enters its target (with the initial
|
|
4
|
+
// states of its regions, recursively). That gives TickResult.active, entered and exited in source terms,
|
|
5
|
+
// whatever the passes did to the structure.
|
|
6
|
+
export class Tracker {
|
|
7
|
+
root;
|
|
8
|
+
report;
|
|
9
|
+
states = new Map();
|
|
10
|
+
regions = new Map();
|
|
11
|
+
transitions = new Map();
|
|
12
|
+
/** Active state per region id. */
|
|
13
|
+
active = new Map();
|
|
14
|
+
/** Last active state per region id (for history transitions). */
|
|
15
|
+
history = new Map();
|
|
16
|
+
/** States entered by a deferred transition whose regions are entered in the next tick (with this history). */
|
|
17
|
+
pending = new Map();
|
|
18
|
+
entered = [];
|
|
19
|
+
exited = [];
|
|
20
|
+
/** The states entered in this tick by their internal ids (a for-region copy's carry the copy key, structure/track.ts). */
|
|
21
|
+
enteredInternal = [];
|
|
22
|
+
/** Transitions taken as soon as their source is entered (scg.ts silentHops: KIELER merged the source away). */
|
|
23
|
+
autoTake = new Set();
|
|
24
|
+
/**
|
|
25
|
+
* `report`: the id a state is reported by (structure/track.ts: a for-region copy's states have internal ids
|
|
26
|
+
* with a copy key; they are reported, and drawn, as the source state).
|
|
27
|
+
*/
|
|
28
|
+
constructor(root, report = id => id) {
|
|
29
|
+
this.root = root;
|
|
30
|
+
this.report = report;
|
|
31
|
+
const visit = (s, parent) => {
|
|
32
|
+
const info = { state: s, parent };
|
|
33
|
+
this.states.set(s.id, info);
|
|
34
|
+
for (const t of s.transitions)
|
|
35
|
+
this.transitions.set(t.id, t);
|
|
36
|
+
for (const r of s.regions) {
|
|
37
|
+
if (r.regionType === 'dataflow')
|
|
38
|
+
continue;
|
|
39
|
+
const ri = { region: r, parent: info, initial: r.states.find(x => x.initial) };
|
|
40
|
+
this.regions.set(r.id, ri);
|
|
41
|
+
for (const c of r.states)
|
|
42
|
+
visit(c, ri);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
visit(root);
|
|
46
|
+
}
|
|
47
|
+
snapshot() {
|
|
48
|
+
return { active: new Map(this.active), history: new Map(this.history), pending: new Map(this.pending) };
|
|
49
|
+
}
|
|
50
|
+
restore(s) {
|
|
51
|
+
this.active = new Map(s.active);
|
|
52
|
+
this.history = new Map(s.history);
|
|
53
|
+
this.pending = new Map(s.pending ?? []);
|
|
54
|
+
}
|
|
55
|
+
reset() {
|
|
56
|
+
this.active.clear();
|
|
57
|
+
this.history.clear();
|
|
58
|
+
this.pending.clear();
|
|
59
|
+
}
|
|
60
|
+
beginTick() {
|
|
61
|
+
this.entered = [];
|
|
62
|
+
this.exited = [];
|
|
63
|
+
this.enteredInternal = [];
|
|
64
|
+
}
|
|
65
|
+
/** Tick 1: the root and its initial states are entered. */
|
|
66
|
+
start() {
|
|
67
|
+
const before = this.entered.length;
|
|
68
|
+
this.entered.push(this.root.id);
|
|
69
|
+
this.enteredInternal.push(this.root.id);
|
|
70
|
+
this.enterRegions(this.root, undefined);
|
|
71
|
+
this.settle();
|
|
72
|
+
return this.entered.slice(before);
|
|
73
|
+
}
|
|
74
|
+
/** A source transition fired: returns the exited and entered states (in order). */
|
|
75
|
+
take(id, options = {}) {
|
|
76
|
+
const t = this.transitions.get(id);
|
|
77
|
+
const e0 = this.entered.length;
|
|
78
|
+
const x0 = this.exited.length;
|
|
79
|
+
if (!t)
|
|
80
|
+
return { exited: [], entered: [] };
|
|
81
|
+
const source = this.states.get(t.source);
|
|
82
|
+
const target = t.target ? this.states.get(t.target) : undefined;
|
|
83
|
+
const history = options.history ?? t.history;
|
|
84
|
+
if (source)
|
|
85
|
+
this.exitState(source);
|
|
86
|
+
if (target && options.deferEntry) {
|
|
87
|
+
// Deferred entry one tick late: the state now, its regions when enterRegionsOf() is called.
|
|
88
|
+
this.entered.push(this.report(target.state.id));
|
|
89
|
+
this.enteredInternal.push(target.state.id);
|
|
90
|
+
if (target.parent)
|
|
91
|
+
this.active.set(target.parent.region.id, target.state.id);
|
|
92
|
+
this.pending.set(target.state.id, history === 'shallow' || history === 'deep' ? history : undefined);
|
|
93
|
+
}
|
|
94
|
+
else if (target) {
|
|
95
|
+
this.enterState(target, history, false, options.record);
|
|
96
|
+
}
|
|
97
|
+
this.settle();
|
|
98
|
+
return { exited: this.exited.slice(x0), entered: this.entered.slice(e0) };
|
|
99
|
+
}
|
|
100
|
+
/** The second tick of a deferred entry (passes/deferred.ts): the state's regions are entered now. */
|
|
101
|
+
enterRegionsOf(id, record) {
|
|
102
|
+
const info = this.states.get(id);
|
|
103
|
+
const e0 = this.entered.length;
|
|
104
|
+
if (!info || !this.pending.has(id))
|
|
105
|
+
return [];
|
|
106
|
+
const history = this.pending.get(id);
|
|
107
|
+
this.pending.delete(id);
|
|
108
|
+
if (info.parent && this.active.get(info.parent.region.id) !== id)
|
|
109
|
+
return [];
|
|
110
|
+
this.enterRegions(info.state, history, record);
|
|
111
|
+
this.settle();
|
|
112
|
+
return this.entered.slice(e0);
|
|
113
|
+
}
|
|
114
|
+
/** Follows the transitions KIELER merged away (autoTake) out of the active states. */
|
|
115
|
+
settle() {
|
|
116
|
+
if (!this.autoTake.size)
|
|
117
|
+
return;
|
|
118
|
+
for (let guard = 0; guard < 100; guard++) {
|
|
119
|
+
let moved = false;
|
|
120
|
+
for (const id of this.autoTake) {
|
|
121
|
+
const t = this.transitions.get(id);
|
|
122
|
+
const source = t ? this.states.get(t.source) : undefined;
|
|
123
|
+
if (!t || !source?.parent || this.active.get(source.parent.region.id) !== source.state.id)
|
|
124
|
+
continue;
|
|
125
|
+
const target = t.target ? this.states.get(t.target) : undefined;
|
|
126
|
+
if (!target || target === source)
|
|
127
|
+
continue;
|
|
128
|
+
this.exitState(source);
|
|
129
|
+
this.enterState(target);
|
|
130
|
+
moved = true;
|
|
131
|
+
}
|
|
132
|
+
if (!moved)
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Weak suspend's way back (passes/weakSuspend.ts, P-46): `id` is the active state of its region again, quietly
|
|
138
|
+
* (no entry actions); what the region moved on to in this tick is left, and the state's own regions are as they
|
|
139
|
+
* were. Returns the states that were left, or undefined if the region was in `id` all along.
|
|
140
|
+
*/
|
|
141
|
+
resume(id) {
|
|
142
|
+
const info = this.states.get(id);
|
|
143
|
+
if (!info?.parent)
|
|
144
|
+
return undefined;
|
|
145
|
+
const region = info.parent.region.id;
|
|
146
|
+
const current = this.active.get(region);
|
|
147
|
+
if (current === id)
|
|
148
|
+
return undefined;
|
|
149
|
+
const x0 = this.exited.length;
|
|
150
|
+
const ci = current !== undefined ? this.states.get(current) : undefined;
|
|
151
|
+
if (ci)
|
|
152
|
+
this.exitState(ci);
|
|
153
|
+
this.active.set(region, id);
|
|
154
|
+
const restore = (s) => {
|
|
155
|
+
for (const r of s.regions) {
|
|
156
|
+
const ri = this.regions.get(r.id);
|
|
157
|
+
if (!ri || this.active.has(r.id))
|
|
158
|
+
continue;
|
|
159
|
+
const remembered = this.history.get(r.id);
|
|
160
|
+
const next = (remembered ? this.states.get(remembered)?.state : undefined) ?? ri.initial;
|
|
161
|
+
if (!next)
|
|
162
|
+
continue;
|
|
163
|
+
this.active.set(r.id, next.id);
|
|
164
|
+
restore(next);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
restore(info.state);
|
|
168
|
+
return this.exited.slice(x0);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* A state's regions stop (the par-or join of a state with abort regions fired, preemption.md P-62): every state
|
|
172
|
+
* inside it is left, the state itself stays active. Returns the states that were left.
|
|
173
|
+
*/
|
|
174
|
+
stopRegions(id) {
|
|
175
|
+
const info = this.states.get(id);
|
|
176
|
+
if (!info)
|
|
177
|
+
return [];
|
|
178
|
+
const x0 = this.exited.length;
|
|
179
|
+
for (const r of info.state.regions) {
|
|
180
|
+
const current = this.active.get(r.id);
|
|
181
|
+
if (current === undefined)
|
|
182
|
+
continue;
|
|
183
|
+
const ci = this.states.get(current);
|
|
184
|
+
if (ci)
|
|
185
|
+
this.exitState(ci);
|
|
186
|
+
this.history.set(r.id, current);
|
|
187
|
+
}
|
|
188
|
+
return this.exited.slice(x0);
|
|
189
|
+
}
|
|
190
|
+
exitState(info) {
|
|
191
|
+
for (const r of info.state.regions) {
|
|
192
|
+
const ri = this.regions.get(r.id);
|
|
193
|
+
if (!ri)
|
|
194
|
+
continue;
|
|
195
|
+
const current = this.active.get(r.id);
|
|
196
|
+
if (current !== undefined) {
|
|
197
|
+
const ci = this.states.get(current);
|
|
198
|
+
if (ci)
|
|
199
|
+
this.exitState(ci);
|
|
200
|
+
this.history.set(r.id, current);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
this.exited.push(this.report(info.state.id));
|
|
204
|
+
this.pending.delete(info.state.id);
|
|
205
|
+
if (info.parent) {
|
|
206
|
+
if (this.active.get(info.parent.region.id) === info.state.id)
|
|
207
|
+
this.active.delete(info.parent.region.id);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
enterState(info, history, deep = false, record) {
|
|
211
|
+
this.entered.push(this.report(info.state.id));
|
|
212
|
+
this.enteredInternal.push(info.state.id);
|
|
213
|
+
if (info.parent)
|
|
214
|
+
this.active.set(info.parent.region.id, info.state.id);
|
|
215
|
+
this.enterRegions(info.state, history === 'shallow' || history === 'deep' ? history : deep ? 'deep' : undefined, record);
|
|
216
|
+
}
|
|
217
|
+
enterRegions(s, history, record) {
|
|
218
|
+
for (const r of s.regions) {
|
|
219
|
+
const ri = this.regions.get(r.id);
|
|
220
|
+
if (!ri)
|
|
221
|
+
continue;
|
|
222
|
+
// KIELER's record where the History pass made one (it is what KIELER resumes), else the last active state.
|
|
223
|
+
const remembered = history ? record?.(r.id) ?? this.history.get(r.id) : undefined;
|
|
224
|
+
const next = remembered ? this.states.get(remembered)?.state : ri.initial;
|
|
225
|
+
if (!next)
|
|
226
|
+
continue;
|
|
227
|
+
const ni = this.states.get(next.id);
|
|
228
|
+
this.enterState(ni, undefined, history === 'deep' && remembered !== undefined, record);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/** Ids of the active states, root first, each state before its children. */
|
|
232
|
+
activeStates() {
|
|
233
|
+
return [...new Set(this.activeInternal().map(this.report))];
|
|
234
|
+
}
|
|
235
|
+
/** The active states by their internal ids (a for-region copy's carry the copy key), root first. */
|
|
236
|
+
activeInternal() {
|
|
237
|
+
const out = [this.root.id];
|
|
238
|
+
const visit = (s) => {
|
|
239
|
+
for (const r of s.regions) {
|
|
240
|
+
const current = this.active.get(r.id);
|
|
241
|
+
if (current === undefined)
|
|
242
|
+
continue;
|
|
243
|
+
out.push(current);
|
|
244
|
+
const ci = this.states.get(current);
|
|
245
|
+
if (ci)
|
|
246
|
+
visit(ci.state);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
visit(this.root);
|
|
250
|
+
return out;
|
|
251
|
+
}
|
|
252
|
+
/** The state a source region was in when it was last left (for history notes). */
|
|
253
|
+
lastActive(regionId) {
|
|
254
|
+
const id = this.history.get(regionId);
|
|
255
|
+
return id === undefined ? undefined : this.report(id);
|
|
256
|
+
}
|
|
257
|
+
/** The active state of a source region (for "pause" log lines). */
|
|
258
|
+
activeIn(regionId) {
|
|
259
|
+
return this.active.get(regionId);
|
|
260
|
+
}
|
|
261
|
+
regionOf(stateId) {
|
|
262
|
+
return this.states.get(stateId)?.parent?.region.id;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracker.js","sourceRoot":"","sources":["../../src/sim/tracker.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,+GAA+G;AAC/G,4GAA4G;AAC5G,yGAAyG;AACzG,4CAA4C;AA+B5C,MAAM,OAAO,OAAO;IAqBa;IAA8B;IApB1C,MAAM,GAAG,IAAI,GAAG,EAAqB,CAAA;IACrC,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAA;IACvC,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAA;IAC5D,kCAAkC;IAC1B,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC1C,iEAAiE;IACzD,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC3C,8GAA8G;IACtG,OAAO,GAAG,IAAI,GAAG,EAA0C,CAAA;IACnE,OAAO,GAAa,EAAE,CAAA;IACtB,MAAM,GAAa,EAAE,CAAA;IACrB,0HAA0H;IAC1H,eAAe,GAAa,EAAE,CAAA;IAC9B,+GAA+G;IAC/G,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAA;IAE5B;;;OAGG;IACH,YAA6B,IAAW,EAAmB,SAAiC,EAAE,CAAC,EAAE,CAAC,EAAE;QAAvE,SAAI,GAAJ,IAAI,CAAO;QAAmB,WAAM,GAAN,MAAM,CAAmC;QAChG,MAAM,KAAK,GAAG,CAAC,CAAQ,EAAE,MAAmB,EAAE,EAAE;YAC5C,MAAM,IAAI,GAAc,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAA;YAC5C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EA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;gBACrC,IAAI,OAAO,KAAK,SAAS;oBAAE,SAAQ;gBACnC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;gBACjB,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;gBACnC,IAAI,EAAE;oBAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;YAC3B,CAAC;QACL,CAAC,CAAA;QACD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAChB,OAAO,GAAG,CAAA;IACd,CAAC;IAED,kFAAkF;IAClF,UAAU,CAAC,QAAgB;QACvB,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QACrC,OAAO,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACzD,CAAC;IAED,mEAAmE;IACnE,QAAQ,CAAC,QAAgB;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IACpC,CAAC;IAED,QAAQ,CAAC,OAAe;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;IACtD,CAAC;CACJ","sourcesContent":["// The source-level configuration: which states of the chart as written are active. The executor runs KIELER's\n// rewritten chart; every source transition carries a `take` mark there, and when one fires this tracker leaves\n// its source state (with everything active inside, innermost first) and enters its target (with the initial\n// states of its regions, recursively). That gives TickResult.active, entered and exited in source terms,\n// whatever the passes did to the structure.\n\nimport type { Region, State, Transition } from '../types'\n\ninterface StateInfo {\n state: State\n parent?: RegionInfo\n}\n\ninterface RegionInfo {\n region: Region\n parent: StateInfo\n initial?: State\n}\n\nexport interface TrackerSnapshot {\n active: Map<string, string>\n history: Map<string, string>\n pending?: Map<string, 'shallow' | 'deep' | undefined>\n}\n\n/** How a preemption pass refines a take (exec.ts passes the take mark's fields, model.ts `Mark`). */\nexport interface TakeOptions {\n /** The history KIELER applies (it ignores nested history keywords, preemption.md P-51). */\n history?: 'reset' | 'shallow' | 'deep'\n /** The target is entered now, its regions one tick later (deferred entry, P-54 a). */\n deferEntry?: boolean\n /** KIELER's history record of a source region: the state a history entry resumes there (passes/history.ts). */\n record?: (regionId: string) => string | undefined\n}\n\nexport class Tracker {\n private readonly states = new Map<string, StateInfo>()\n private readonly regions = new Map<string, RegionInfo>()\n private readonly transitions = new Map<string, Transition>()\n /** Active state per region id. */\n private active = new Map<string, string>()\n /** Last active state per region id (for history transitions). */\n private history = new Map<string, string>()\n /** States entered by a deferred transition whose regions are entered in the next tick (with this history). */\n private pending = new Map<string, 'shallow' | 'deep' | undefined>()\n entered: string[] = []\n exited: string[] = []\n /** The states entered in this tick by their internal ids (a for-region copy's carry the copy key, structure/track.ts). */\n enteredInternal: string[] = []\n /** Transitions taken as soon as their source is entered (scg.ts silentHops: KIELER merged the source away). */\n autoTake = new Set<string>()\n\n /**\n * `report`: the id a state is reported by (structure/track.ts: a for-region copy's states have internal ids\n * with a copy key; they are reported, and drawn, as the source state).\n */\n constructor(private readonly root: State, private readonly report: (id: string) => string = id => id) {\n const visit = (s: State, parent?: RegionInfo) => {\n const info: StateInfo = { state: s, parent }\n this.states.set(s.id, info)\n for (const t of s.transitions) this.transitions.set(t.id, t)\n for (const r of s.regions) {\n if (r.regionType === 'dataflow') continue\n const ri: RegionInfo = { region: r, parent: info, initial: r.states.find(x => x.initial) }\n this.regions.set(r.id, ri)\n for (const c of r.states) visit(c, ri)\n }\n }\n visit(root)\n }\n\n snapshot(): TrackerSnapshot {\n return { active: new Map(this.active), history: new Map(this.history), pending: new Map(this.pending) }\n }\n\n restore(s: TrackerSnapshot) {\n this.active = new Map(s.active)\n this.history = new Map(s.history)\n this.pending = new Map(s.pending ?? [])\n }\n\n reset() {\n this.active.clear()\n this.history.clear()\n this.pending.clear()\n }\n\n beginTick() {\n this.entered = []\n this.exited = []\n this.enteredInternal = []\n }\n\n /** Tick 1: the root and its initial states are entered. */\n start(): string[] {\n const before = this.entered.length\n this.entered.push(this.root.id)\n this.enteredInternal.push(this.root.id)\n this.enterRegions(this.root, undefined)\n this.settle()\n return this.entered.slice(before)\n }\n\n /** A source transition fired: returns the exited and entered states (in order). */\n take(id: string, options: TakeOptions = {}): { exited: string[]; entered: string[] } {\n const t = this.transitions.get(id)\n const e0 = this.entered.length\n const x0 = this.exited.length\n if (!t) return { exited: [], entered: [] }\n const source = this.states.get(t.source)\n const target = t.target ? this.states.get(t.target) : undefined\n const history = options.history ?? t.history\n if (source) this.exitState(source)\n if (target && options.deferEntry) {\n // Deferred entry one tick late: the state now, its regions when enterRegionsOf() is called.\n this.entered.push(this.report(target.state.id))\n this.enteredInternal.push(target.state.id)\n if (target.parent) this.active.set(target.parent.region.id, target.state.id)\n this.pending.set(target.state.id, history === 'shallow' || history === 'deep' ? history : undefined)\n } else if (target) {\n this.enterState(target, history, false, options.record)\n }\n this.settle()\n return { exited: this.exited.slice(x0), entered: this.entered.slice(e0) }\n }\n\n /** The second tick of a deferred entry (passes/deferred.ts): the state's regions are entered now. */\n enterRegionsOf(id: string, record?: TakeOptions['record']): string[] {\n const info = this.states.get(id)\n const e0 = this.entered.length\n if (!info || !this.pending.has(id)) return []\n const history = this.pending.get(id)\n this.pending.delete(id)\n if (info.parent && this.active.get(info.parent.region.id) !== id) return []\n this.enterRegions(info.state, history, record)\n this.settle()\n return this.entered.slice(e0)\n }\n\n /** Follows the transitions KIELER merged away (autoTake) out of the active states. */\n private settle() {\n if (!this.autoTake.size) return\n for (let guard = 0; guard < 100; guard++) {\n let moved = false\n for (const id of this.autoTake) {\n const t = this.transitions.get(id)\n const source = t ? this.states.get(t.source) : undefined\n if (!t || !source?.parent || this.active.get(source.parent.region.id) !== source.state.id) continue\n const target = t.target ? this.states.get(t.target) : undefined\n if (!target || target === source) continue\n this.exitState(source)\n this.enterState(target)\n moved = true\n }\n if (!moved) return\n }\n }\n\n /**\n * Weak suspend's way back (passes/weakSuspend.ts, P-46): `id` is the active state of its region again, quietly\n * (no entry actions); what the region moved on to in this tick is left, and the state's own regions are as they\n * were. Returns the states that were left, or undefined if the region was in `id` all along.\n */\n resume(id: string): string[] | undefined {\n const info = this.states.get(id)\n if (!info?.parent) return undefined\n const region = info.parent.region.id\n const current = this.active.get(region)\n if (current === id) return undefined\n const x0 = this.exited.length\n const ci = current !== undefined ? this.states.get(current) : undefined\n if (ci) this.exitState(ci)\n this.active.set(region, id)\n const restore = (s: State) => {\n for (const r of s.regions) {\n const ri = this.regions.get(r.id)\n if (!ri || this.active.has(r.id)) continue\n const remembered = this.history.get(r.id)\n const next = (remembered ? this.states.get(remembered)?.state : undefined) ?? ri.initial\n if (!next) continue\n this.active.set(r.id, next.id)\n restore(next)\n }\n }\n restore(info.state)\n return this.exited.slice(x0)\n }\n\n /**\n * A state's regions stop (the par-or join of a state with abort regions fired, preemption.md P-62): every state\n * inside it is left, the state itself stays active. Returns the states that were left.\n */\n stopRegions(id: string): string[] {\n const info = this.states.get(id)\n if (!info) return []\n const x0 = this.exited.length\n for (const r of info.state.regions) {\n const current = this.active.get(r.id)\n if (current === undefined) continue\n const ci = this.states.get(current)\n if (ci) this.exitState(ci)\n this.history.set(r.id, current)\n }\n return this.exited.slice(x0)\n }\n\n private exitState(info: StateInfo) {\n for (const r of info.state.regions) {\n const ri = this.regions.get(r.id)\n if (!ri) continue\n const current = this.active.get(r.id)\n if (current !== undefined) {\n const ci = this.states.get(current)\n if (ci) this.exitState(ci)\n this.history.set(r.id, current)\n }\n }\n this.exited.push(this.report(info.state.id))\n this.pending.delete(info.state.id)\n if (info.parent) {\n if (this.active.get(info.parent.region.id) === info.state.id) this.active.delete(info.parent.region.id)\n }\n }\n\n private enterState(info: StateInfo, history?: Transition['history'], deep = false, record?: TakeOptions['record']) {\n this.entered.push(this.report(info.state.id))\n this.enteredInternal.push(info.state.id)\n if (info.parent) this.active.set(info.parent.region.id, info.state.id)\n this.enterRegions(info.state, history === 'shallow' || history === 'deep' ? history : deep ? 'deep' : undefined, record)\n }\n\n private enterRegions(s: State, history: 'shallow' | 'deep' | undefined, record?: TakeOptions['record']) {\n for (const r of s.regions) {\n const ri = this.regions.get(r.id)\n if (!ri) continue\n // KIELER's record where the History pass made one (it is what KIELER resumes), else the last active state.\n const remembered = history ? record?.(r.id) ?? this.history.get(r.id) : undefined\n const next = remembered ? this.states.get(remembered)?.state : ri.initial\n if (!next) continue\n const ni = this.states.get(next.id)!\n this.enterState(ni, undefined, history === 'deep' && remembered !== undefined, record)\n }\n }\n\n /** Ids of the active states, root first, each state before its children. */\n activeStates(): string[] {\n return [...new Set(this.activeInternal().map(this.report))]\n }\n\n /** The active states by their internal ids (a for-region copy's carry the copy key), root first. */\n activeInternal(): string[] {\n const out: string[] = [this.root.id]\n const visit = (s: State) => {\n for (const r of s.regions) {\n const current = this.active.get(r.id)\n if (current === undefined) continue\n out.push(current)\n const ci = this.states.get(current)\n if (ci) visit(ci.state)\n }\n }\n visit(this.root)\n return out\n }\n\n /** The state a source region was in when it was last left (for history notes). */\n lastActive(regionId: string): string | undefined {\n const id = this.history.get(regionId)\n return id === undefined ? undefined : this.report(id)\n }\n\n /** The active state of a source region (for \"pause\" log lines). */\n activeIn(regionId: string): string | undefined {\n return this.active.get(regionId)\n }\n\n regionOf(stateId: string): string | undefined {\n return this.states.get(stateId)?.parent?.region.id\n }\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const INT_MIN = -2147483648;
|
|
2
|
+
export declare const INT_MAX = 2147483647;
|
|
3
|
+
/** A string as the C simulation sees it: its text and the identity of the pointer. */
|
|
4
|
+
export interface CString {
|
|
5
|
+
s: string;
|
|
6
|
+
id: number;
|
|
7
|
+
}
|
|
8
|
+
/** Run-time values: numbers for int, char (bool) and double, CString or null for strings, arrays nested. */
|
|
9
|
+
export type RValue = number | CString | null | RValue[];
|
|
10
|
+
/** Static C type of an expression or variable. */
|
|
11
|
+
export type CType = 'int' | 'bool' | 'float' | 'string' | 'null';
|
|
12
|
+
/** The pointer identity of a string literal: one per distinct text (gcc merges identical literals). */
|
|
13
|
+
export declare function literalString(text: string): CString;
|
|
14
|
+
/** A string received from the environment: never the same pointer as anything else. */
|
|
15
|
+
export declare function freshString(text: string): CString;
|
|
16
|
+
export declare function isCString(v: unknown): v is CString;
|
|
17
|
+
/** C's conversion of a double to int as gcc does it on x86-64 (cvttsd2si): truncation; out of range and NaN give INT_MIN. */
|
|
18
|
+
export declare function doubleToInt(x: number): number;
|
|
19
|
+
/** Conversion to C `char` (bool variables). */
|
|
20
|
+
export declare function toChar(x: number, fromFloat?: boolean): number;
|
|
21
|
+
/** Converts a value of static type `from` for storage in a variable of type `to` (C assignment conversion). */
|
|
22
|
+
export declare function convert(v: RValue, from: CType, to: CType): RValue;
|
|
23
|
+
/** The default value of a type (B-4): int 0, bool false, float 0.0, string NULL. */
|
|
24
|
+
export declare function defaultValue(type: CType): RValue;
|
|
25
|
+
/** Builds an array of the given dimensions filled with a value. */
|
|
26
|
+
export declare function makeArray(dims: number[], fill: () => RValue): RValue;
|
|
27
|
+
export declare function cloneValue(v: RValue): RValue;
|
|
28
|
+
/** The C type of a declared variable type. */
|
|
29
|
+
export declare function ctypeOf(type: string | undefined): CType;
|
|
30
|
+
/** printf of one print() argument (B-30): int %d, bool %x, float %f, string %s, anything else %X ('hex'). */
|
|
31
|
+
export declare function printfValue(v: RValue, type: CType | 'hex'): string;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// C value semantics of KIELER's netlist C simulation (basics.md B-3, B-20..B-28):
|
|
2
|
+
// int 32-bit two's complement, wraps; `/` truncates towards zero, `%` takes the dividend's sign
|
|
3
|
+
// bool a C `char`: an int stored in a bool keeps its char value (300 -> 44, 256 -> 0); reported as != 0
|
|
4
|
+
// float a C double; float literals are rounded to single precision when the chart is compiled (lower.ts)
|
|
5
|
+
// string a `char*`: == compares pointers. Identical literals share one pointer (gcc merges them); a string
|
|
6
|
+
// from the environment is a fresh pointer every tick; NULL is null.
|
|
7
|
+
export const INT_MIN = -2147483648;
|
|
8
|
+
export const INT_MAX = 2147483647;
|
|
9
|
+
const literalIds = new Map();
|
|
10
|
+
let freshId = 0;
|
|
11
|
+
/** The pointer identity of a string literal: one per distinct text (gcc merges identical literals). */
|
|
12
|
+
export function literalString(text) {
|
|
13
|
+
let id = literalIds.get(text);
|
|
14
|
+
if (id === undefined) {
|
|
15
|
+
id = ++freshId;
|
|
16
|
+
literalIds.set(text, id);
|
|
17
|
+
}
|
|
18
|
+
return { s: text, id };
|
|
19
|
+
}
|
|
20
|
+
/** A string received from the environment: never the same pointer as anything else. */
|
|
21
|
+
export function freshString(text) {
|
|
22
|
+
return { s: text, id: ++freshId + 1_000_000_000 };
|
|
23
|
+
}
|
|
24
|
+
export function isCString(v) {
|
|
25
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v) && typeof v.s === 'string';
|
|
26
|
+
}
|
|
27
|
+
/** C's conversion of a double to int as gcc does it on x86-64 (cvttsd2si): truncation; out of range and NaN give INT_MIN. */
|
|
28
|
+
export function doubleToInt(x) {
|
|
29
|
+
if (!(x > -2147483649 && x < 2147483648))
|
|
30
|
+
return INT_MIN;
|
|
31
|
+
return Math.trunc(x) | 0;
|
|
32
|
+
}
|
|
33
|
+
/** Conversion to C `char` (bool variables). */
|
|
34
|
+
export function toChar(x, fromFloat = false) {
|
|
35
|
+
const i = fromFloat ? doubleToInt(x) : x | 0;
|
|
36
|
+
return (i << 24) >> 24;
|
|
37
|
+
}
|
|
38
|
+
/** Converts a value of static type `from` for storage in a variable of type `to` (C assignment conversion). */
|
|
39
|
+
export function convert(v, from, to) {
|
|
40
|
+
if (typeof v !== 'number')
|
|
41
|
+
return v;
|
|
42
|
+
switch (to) {
|
|
43
|
+
case 'int': return from === 'float' ? doubleToInt(v) : v | 0;
|
|
44
|
+
case 'bool': return toChar(v, from === 'float');
|
|
45
|
+
case 'float': return v;
|
|
46
|
+
default: return v;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** The default value of a type (B-4): int 0, bool false, float 0.0, string NULL. */
|
|
50
|
+
export function defaultValue(type) {
|
|
51
|
+
return type === 'string' || type === 'null' ? null : 0;
|
|
52
|
+
}
|
|
53
|
+
/** Builds an array of the given dimensions filled with a value. */
|
|
54
|
+
export function makeArray(dims, fill) {
|
|
55
|
+
if (!dims.length)
|
|
56
|
+
return fill();
|
|
57
|
+
const [n, ...rest] = dims;
|
|
58
|
+
return Array.from({ length: Math.max(0, n) }, () => makeArray(rest, fill));
|
|
59
|
+
}
|
|
60
|
+
export function cloneValue(v) {
|
|
61
|
+
return Array.isArray(v) ? v.map(cloneValue) : v;
|
|
62
|
+
}
|
|
63
|
+
/** The C type of a declared variable type. */
|
|
64
|
+
export function ctypeOf(type) {
|
|
65
|
+
switch (type) {
|
|
66
|
+
case 'int': return 'int';
|
|
67
|
+
case 'float': return 'float';
|
|
68
|
+
case 'string': return 'string';
|
|
69
|
+
case 'bool':
|
|
70
|
+
case 'pure': return 'bool';
|
|
71
|
+
default: return 'int';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** printf of one print() argument (B-30): int %d, bool %x, float %f, string %s, anything else %X ('hex'). */
|
|
75
|
+
export function printfValue(v, type) {
|
|
76
|
+
if (type === 'hex' && typeof v === 'number')
|
|
77
|
+
return (doubleToInt(v) >>> 0).toString(16).toUpperCase();
|
|
78
|
+
if (v === null)
|
|
79
|
+
return '(null)';
|
|
80
|
+
if (isCString(v))
|
|
81
|
+
return v.s;
|
|
82
|
+
if (Array.isArray(v))
|
|
83
|
+
return '?';
|
|
84
|
+
switch (type) {
|
|
85
|
+
case 'bool': return (v >>> 0).toString(16);
|
|
86
|
+
case 'float': return cFixed(v);
|
|
87
|
+
default: return String(v | 0);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** C's `%f` of a double, as glibc prints it: `inf`, `-nan` (the NaN x86 makes, 0.0/0.0, has its sign bit set),
|
|
91
|
+
* `-0.000000`, and every digit of a large value (never an exponent, as toFixed has from 1e21). */
|
|
92
|
+
function cFixed(v) {
|
|
93
|
+
if (Number.isNaN(v))
|
|
94
|
+
return '-nan';
|
|
95
|
+
if (!Number.isFinite(v))
|
|
96
|
+
return v > 0 ? 'inf' : '-inf';
|
|
97
|
+
if (Object.is(v, -0))
|
|
98
|
+
return '-0.000000';
|
|
99
|
+
if (Math.abs(v) >= 1e21)
|
|
100
|
+
return `${BigInt(v)}.000000`;
|
|
101
|
+
return v.toFixed(6);
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.js","sourceRoot":"","sources":["../../src/sim/values.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,qGAAqG;AACrG,4GAA4G;AAC5G,4GAA4G;AAC5G,6GAA6G;AAC7G,6EAA6E;AAE7E,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,UAAU,CAAA;AAClC,MAAM,CAAC,MAAM,OAAO,GAAG,UAAU,CAAA;AAcjC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAA;AAC5C,IAAI,OAAO,GAAG,CAAC,CAAA;AAEf,uGAAuG;AACvG,MAAM,UAAU,aAAa,CAAC,IAAY;IACtC,IAAI,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7B,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;QACnB,EAAE,GAAG,EAAE,OAAO,CAAA;QACd,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IAC5B,CAAC;IACD,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAA;AAC1B,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,WAAW,CAAC,IAAY;IACpC,OAAO,EAAE,CAAC,E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simulation (basics.md B-3, B-20..B-28):\n// int 32-bit two's complement, wraps; `/` truncates towards zero, `%` takes the dividend's sign\n// bool a C `char`: an int stored in a bool keeps its char value (300 -> 44, 256 -> 0); reported as != 0\n// float a C double; float literals are rounded to single precision when the chart is compiled (lower.ts)\n// string a `char*`: == compares pointers. Identical literals share one pointer (gcc merges them); a string\n// from the environment is a fresh pointer every tick; NULL is null.\n\nexport const INT_MIN = -2147483648\nexport const INT_MAX = 2147483647\n\n/** A string as the C simulation sees it: its text and the identity of the pointer. */\nexport interface CString {\n s: string\n id: number\n}\n\n/** Run-time values: numbers for int, char (bool) and double, CString or null for strings, arrays nested. */\nexport type RValue = number | CString | null | RValue[]\n\n/** Static C type of an expression or variable. */\nexport type CType = 'int' | 'bool' | 'float' | 'string' | 'null'\n\nconst literalIds = new Map<string, number>()\nlet freshId = 0\n\n/** The pointer identity of a string literal: one per distinct text (gcc merges identical literals). */\nexport function literalString(text: string): CString {\n let id = literalIds.get(text)\n if (id === undefined) {\n id = ++freshId\n literalIds.set(text, id)\n }\n return { s: text, id }\n}\n\n/** A string received from the environment: never the same pointer as anything else. */\nexport function freshString(text: string): CString {\n return { s: text, id: ++freshId + 1_000_000_000 }\n}\n\nexport function isCString(v: unknown): v is CString {\n return typeof v === 'object' && v !== null && !Array.isArray(v) && typeof (v as CString).s === 'string'\n}\n\n/** C's conversion of a double to int as gcc does it on x86-64 (cvttsd2si): truncation; out of range and NaN give INT_MIN. */\nexport function doubleToInt(x: number): number {\n if (!(x > -2147483649 && x < 2147483648)) return INT_MIN\n return Math.trunc(x) | 0\n}\n\n/** Conversion to C `char` (bool variables). */\nexport function toChar(x: number, fromFloat = false): number {\n const i = fromFloat ? doubleToInt(x) : x | 0\n return (i << 24) >> 24\n}\n\n/** Converts a value of static type `from` for storage in a variable of type `to` (C assignment conversion). */\nexport function convert(v: RValue, from: CType, to: CType): RValue {\n if (typeof v !== 'number') return v\n switch (to) {\n case 'int': return from === 'float' ? doubleToInt(v) : v | 0\n case 'bool': return toChar(v, from === 'float')\n case 'float': return v\n default: return v\n }\n}\n\n/** The default value of a type (B-4): int 0, bool false, float 0.0, string NULL. */\nexport function defaultValue(type: CType): RValue {\n return type === 'string' || type === 'null' ? null : 0\n}\n\n/** Builds an array of the given dimensions filled with a value. */\nexport function makeArray(dims: number[], fill: () => RValue): RValue {\n if (!dims.length) return fill()\n const [n, ...rest] = dims\n return Array.from({ length: Math.max(0, n) }, () => makeArray(rest, fill))\n}\n\nexport function cloneValue(v: RValue): RValue {\n return Array.isArray(v) ? v.map(cloneValue) : v\n}\n\n/** The C type of a declared variable type. */\nexport function ctypeOf(type: string | undefined): CType {\n switch (type) {\n case 'int': return 'int'\n case 'float': return 'float'\n case 'string': return 'string'\n case 'bool': case 'pure': return 'bool'\n default: return 'int'\n }\n}\n\n/** printf of one print() argument (B-30): int %d, bool %x, float %f, string %s, anything else %X ('hex'). */\nexport function printfValue(v: RValue, type: CType | 'hex'): string {\n if (type === 'hex' && typeof v === 'number') return (doubleToInt(v) >>> 0).toString(16).toUpperCase()\n if (v === null) return '(null)'\n if (isCString(v)) return v.s\n if (Array.isArray(v)) return '?'\n switch (type) {\n case 'bool': return (v >>> 0).toString(16)\n case 'float': return cFixed(v)\n default: return String(v | 0)\n }\n}\n\n/** C's `%f` of a double, as glibc prints it: `inf`, `-nan` (the NaN x86 makes, 0.0/0.0, has its sign bit set),\n * `-0.000000`, and every digit of a large value (never an exponent, as toFixed has from 1e21). */\nfunction cFixed(v: number): string {\n if (Number.isNaN(v)) return '-nan'\n if (!Number.isFinite(v)) return v > 0 ? 'inf' : '-inf'\n if (Object.is(v, -0)) return '-0.000000'\n if (Math.abs(v) >= 1e21) return `${BigInt(v)}.000000`\n return v.toFixed(6)\n}\n"]}
|