Skip to content

Commit 39d945e

Browse files
committed
[Not Tested][Squash][Sidetask] Meaningful names for components, mutations and reactions
[squashed] more thoughtful naming
1 parent cb13341 commit 39d945e

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

src/benchmark/Sieve.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Ramp extends Reactor {
2121
value = new OutPort<number>(this);
2222

2323
constructor(parent: Reactor, until = 100000, period: TimeValue) {
24-
super(parent);
24+
super(parent, "Ramp");
2525
this.until = new Parameter(until);
2626
this.next = new Action<number>(this, Origin.logical, period);
2727
this.addReaction(
@@ -56,7 +56,7 @@ class Filter extends Reactor {
5656
hasChild: State<boolean>;
5757

5858
constructor(parent: Reactor, startPrime: number, numberOfPrimes: number) {
59-
super(parent);
59+
super(parent, `FilterFor${startPrime}`);
6060
// console.log("Created filter with prime: " + prime)
6161
this.startPrime = new Parameter(startPrime);
6262
this.localPrimes = new State(new Array<number>());
@@ -126,7 +126,7 @@ class Sieve extends App {
126126
success?: () => void,
127127
fail?: () => void
128128
) {
129-
super(timeout, keepAlive, fast, success, fail);
129+
super(timeout, keepAlive, fast, success, fail, name);
130130
this.source = new Ramp(this, 100000, TimeValue.nsec(1));
131131
this.filter = new Filter(this, 2, 1000);
132132
this._connect(this.source.value, this.filter.inp);

src/core/component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {Runtime} from "./internal";
22
import {Reactor, App, MultiPort, IOPort, Bank} from "./internal";
3+
import {v4 as uuidv4} from "uuid";
34

45
/**
56
* Base class for named objects embedded in a hierarchy of reactors. Each
@@ -17,7 +18,7 @@ export abstract class Component {
1718
* A symbol that identifies this component, and it also used to selectively
1819
* grant access to its privileged functions.
1920
*/
20-
protected _key = Symbol("Unique component identifier");
21+
protected _key = Symbol(uuidv4());
2122

2223
/**
2324
* The container of this component. Each component is contained by a
@@ -26,6 +27,8 @@ export abstract class Component {
2627
*/
2728
private readonly _container: Reactor;
2829

30+
protected _name: string;
31+
2932
/**
3033
* Create a new component and register it with the given container.
3134
* @param container The reactor that will contain the new component,

src/core/reaction.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export class Reaction<T extends Variable[]>
6767
private deadline?: TimeValue,
6868
private readonly late: (...args: ArgList<T>) => void = () => {
6969
Log.global.warn("Deadline violation occurred!");
70-
}
70+
},
71+
readonly name?: string
7172
) {}
7273

7374
/**
@@ -181,9 +182,9 @@ export class Reaction<T extends Variable[]>
181182
* Return string representation of the reaction.
182183
*/
183184
public toString(): string {
184-
return `${this.reactor._getFullyQualifiedName()}[R${this.reactor._getReactionIndex(
185-
this as unknown as Reaction<Variable[]>
186-
)}]`;
185+
return `${this.reactor._getFullyQualifiedName()}` +
186+
((this.name != null) ? `${this.name} aka` : "") +
187+
`[R${this.reactor._getReactionIndex(this as unknown as Reaction<Variable[]>)}]`;
187188
}
188189
}
189190

@@ -199,18 +200,19 @@ export class Mutation<T extends Variable[]> extends Reaction<T> {
199200
args: [...ArgList<T>],
200201
react: (...args: ArgList<T>) => void,
201202
deadline?: TimeValue,
202-
late?: (...args: ArgList<T>) => void
203+
late?: (...args: ArgList<T>) => void,
204+
name?: string
203205
) {
204-
super(__parent__, sandbox, trigs, args, react, deadline, late);
206+
super(__parent__, sandbox, trigs, args, react, deadline, late, name);
205207
this.parent = __parent__;
206208
}
207209

208210
/**
209211
* @override
210212
*/
211213
public toString(): string {
212-
return `${this.parent._getFullyQualifiedName()}[M${this.parent._getReactionIndex(
213-
this as unknown as Reaction<Variable[]>
214-
)}]`;
214+
return `${this.parent._getFullyQualifiedName()}` +
215+
((this.name != null) ? `${this.name} aka` : "") +
216+
`[M${this.parent._getReactionIndex(this as unknown as Reaction<Variable[]>)}]`;
215217
}
216218
}

src/core/reactor.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,15 @@ export abstract class Reactor extends Component {
487487
}
488488
};
489489

490+
protected _name: string;
491+
490492
/**
491493
* Create a new reactor.
492494
* @param container The container of this reactor.
493495
*/
494-
constructor(container: Reactor | null) {
496+
constructor(container: Reactor | null, name? : string) {
495497
super(container);
498+
this._name = (name == null) ? this._key.description?.slice(0, 8) ?? "unknown reactor" : name;
496499
this._bankIndex = -1;
497500
if (container !== null) {
498501
const index = Bank.initializationMap.get(container);
@@ -2242,8 +2245,6 @@ export class App extends Reactor {
22422245

22432246
private readonly snooze: Action<Tag>;
22442247

2245-
readonly _name: string;
2246-
22472248
/**
22482249
* Create a new top-level reactor.
22492250
* @param executionTimeout Optional parameter to let the execution of the app time out.
@@ -2257,18 +2258,18 @@ export class App extends Reactor {
22572258
keepAlive = false,
22582259
fast = false,
22592260
public success: () => void = () => undefined,
2260-
public failure: () => void = () => undefined
2261+
public failure: () => void = () => undefined,
2262+
name?: string
22612263
) {
2262-
super(null);
2263-
2264-
let name = this.constructor.name;
2265-
if (name === "") {
2266-
name = "app";
2267-
} else {
2268-
name = name.charAt(0).toLowerCase() + name.slice(1);
2264+
super(null, name);
2265+
2266+
if (name == null) {
2267+
name = this.constructor.name;
2268+
if (name !== "") {
2269+
name = name.charAt(0).toLowerCase() + name.slice(1);
2270+
}
2271+
this._name = name;
22692272
}
2270-
this._name = name;
2271-
22722273
// Update pointer to runtime object for this reactor and
22732274
// its startup and shutdown action since the inner class
22742275
// instance this.__runtime isn't initialized up until here.

0 commit comments

Comments
 (0)