@tsplc/compiler 0.5.16 → 0.5.18

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.
@@ -383,13 +383,17 @@ class BoundedSet {
383
383
  yield* this.members.keys();
384
384
  }
385
385
  }
386
+ function enumRecord(members, create) {
387
+ return Object.fromEntries(Object.values(members).filter((member) => typeof member === "number").map((member) => [member, create(member)]));
388
+ }
386
389
  export {
387
390
  BoundedList,
388
391
  BoundedMap,
389
392
  BoundedQueue,
390
393
  BoundedSet,
394
+ enumRecord,
391
395
  linearLimit
392
396
  };
393
397
 
394
- //# debugId=4FC9E2DB2410051864756E2164756E21
398
+ //# debugId=380F8D6249FDCF9B64756E2164756E21
395
399
  //# sourceMappingURL=collections.js.map
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../stdlib/collections.ts"],
4
4
  "sourcesContent": [
5
- "// PLC implementation source: a plain TypeScript program's collections. Setup fixes each one's\n// capacity, so the PLC stores it in arrays allocated once, and every loop over it is bounded by\n// that capacity. The same classes run under Bun for setup, tests and simulation.\nimport type { UINT } from \"../types/index\";\n\n/** Bun's, at setup and in simulation; the PLC compiles it as the dialect's `copy`. */\ndeclare function structuredClone<T>(value: T): T;\n\n/** What a full collection does with one more item: refuse it, or make room by dropping the oldest. */\nexport type OnFull = \"reject\" | \"dropOldest\";\n\nexport interface BoundedOptions {\n\treadonly onFull: OnFull;\n}\n\n/** Above this capacity a map with number keys hashes them; at or below it, a scan of every slot is as quick. */\nexport const linearLimit = 32;\n\n/** A first-in, first-out queue of at most `capacity` items, in a ring. */\nexport class BoundedQueue<T> {\n\tprivate readonly items: T[];\n\tprivate first: UINT = 0;\n\tprivate count: UINT = 0;\n\t/** How many items the queue refused or dropped because it was full. */\n\toverflowed = 0;\n\n\t/** What an empty slot holds; reads fall back to it where TypeScript can't see the slot is filled. */\n\tprivate readonly blank: T;\n\n\tconstructor(\n\t\treadonly capacity: number,\n\t\tblank: () => T,\n\t\tprivate readonly options: BoundedOptions,\n\t) {\n\t\tthis.items = Array.from({ length: capacity }, blank);\n\t\tthis.blank = blank();\n\t}\n\n\tprivate item(slot: UINT): T {\n\t\treturn this.items[slot % this.capacity] ?? this.blank;\n\t}\n\n\tget length(): number {\n\t\treturn this.count;\n\t}\n\n\t/** Adds an item at the back; false when the queue is full and refuses it. */\n\tpush(item: T): boolean {\n\t\tif (this.count === this.capacity) {\n\t\t\tthis.overflowed += 1;\n\t\t\tif (this.options.onFull === \"reject\") {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis.first = (this.first + 1) % this.capacity;\n\t\t\tthis.count -= 1;\n\t\t}\n\t\tthis.items[(this.first + this.count) % this.capacity] = item;\n\t\tthis.count += 1;\n\t\treturn true;\n\t}\n\n\t/** Takes the item at the front, or undefined when empty. */\n\tshift(): T | undefined {\n\t\tif (this.count === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst item = this.item(this.first);\n\t\tthis.first = (this.first + 1) % this.capacity;\n\t\tthis.count -= 1;\n\t\treturn item;\n\t}\n\n\t/** Takes the item at the back, or undefined when empty. */\n\tpop(): T | undefined {\n\t\tif (this.count === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tthis.count -= 1;\n\t\treturn this.item(this.first + this.count);\n\t}\n\n\t/** The item at the front, left in place. */\n\tpeek(): T | undefined {\n\t\treturn this.count === 0 ? undefined : this.item(this.first);\n\t}\n\n\t/** The item `offset` from the front, or undefined past the back. */\n\tat(offset: UINT): T | undefined {\n\t\treturn offset < this.count ? this.item(this.first + offset) : undefined;\n\t}\n\n\t/** Changes the item `offset` from the front in place; false past the back. */\n\tupdate(offset: UINT, change: (item: T) => void): boolean {\n\t\tif (offset >= this.count) {\n\t\t\treturn false;\n\t\t}\n\t\tconst slot: UINT = (this.first + offset) % this.capacity;\n\t\t// A copy, changed and stored back: an element at a runtime slot can't be lent out.\n\t\tconst item = structuredClone(\n\t\t\tthis.items[slot % this.capacity] ?? this.blank,\n\t\t);\n\t\tchange(item);\n\t\tthis.items[slot % this.capacity] = item;\n\t\treturn true;\n\t}\n\n\tclear(): void {\n\t\tthis.first = 0;\n\t\tthis.count = 0;\n\t}\n\n\t*values(): Generator<T> {\n\t\tfor (let offset: UINT = 0; offset < this.capacity; offset++) {\n\t\t\tif (offset >= this.count) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// The stored item itself, so a loop that changes it changes the queue's.\n\t\t\tyield this.items[(this.first + offset) % this.capacity] ?? this.blank;\n\t\t}\n\t}\n}\n\n/** A list of at most `capacity` items in order, which can be removed from anywhere. */\nexport class BoundedList<T> {\n\tprivate readonly items: T[];\n\tprivate count: UINT = 0;\n\t/** How many items the list refused or dropped because it was full. */\n\toverflowed = 0;\n\n\t/** What an empty slot holds; reads fall back to it where TypeScript can't see the slot is filled. */\n\tprivate readonly blank: T;\n\n\tconstructor(\n\t\treadonly capacity: number,\n\t\tblank: () => T,\n\t\tprivate readonly options: BoundedOptions,\n\t) {\n\t\tthis.items = Array.from({ length: capacity }, blank);\n\t\tthis.blank = blank();\n\t}\n\n\tprivate item(slot: UINT): T {\n\t\treturn this.items[slot % this.capacity] ?? this.blank;\n\t}\n\n\tget length(): number {\n\t\treturn this.count;\n\t}\n\n\t/** Adds an item at the end; false when the list is full and refuses it. */\n\tpush(item: T): boolean {\n\t\tif (this.count === this.capacity) {\n\t\t\tthis.overflowed += 1;\n\t\t\tif (this.options.onFull === \"reject\") {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis.removeAt(0);\n\t\t}\n\t\tthis.items[this.count % this.capacity] = item;\n\t\tthis.count += 1;\n\t\treturn true;\n\t}\n\n\tat(index: UINT): T | undefined {\n\t\treturn index < this.count ? this.item(index) : undefined;\n\t}\n\n\t/** Changes the item at `index` in place; false past the end. */\n\tupdate(index: UINT, change: (item: T) => void): boolean {\n\t\tif (index >= this.count) {\n\t\t\treturn false;\n\t\t}\n\t\t// A copy, changed and stored back: an element at a runtime slot can't be lent out.\n\t\tconst item = structuredClone(\n\t\t\tthis.items[index % this.capacity] ?? this.blank,\n\t\t);\n\t\tchange(item);\n\t\tthis.items[index % this.capacity] = item;\n\t\treturn true;\n\t}\n\n\t/** Removes the item at `index`, moving the ones after it up; false past the end. */\n\tremoveAt(index: UINT): boolean {\n\t\tif (index >= this.count) {\n\t\t\treturn false;\n\t\t}\n\t\tfor (let slot: UINT = 0; slot < this.capacity; slot++) {\n\t\t\tif (slot >= index && slot + 1 < this.count) {\n\t\t\t\tthis.items[slot % this.capacity] = this.item(slot + 1);\n\t\t\t}\n\t\t}\n\t\tthis.count -= 1;\n\t\treturn true;\n\t}\n\n\t/** The index of the first item that passes, or -1. */\n\tfindIndex(test: (item: T) => boolean): number {\n\t\tfor (let slot: UINT = 0; slot < this.capacity; slot++) {\n\t\t\tif (slot < this.count && test(this.item(slot))) {\n\t\t\t\treturn slot;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\n\t/** Removes the first item that passes; false when none does. */\n\tremove(test: (item: T) => boolean): boolean {\n\t\tfor (let slot: UINT = 0; slot < this.capacity; slot++) {\n\t\t\tif (slot < this.count && test(this.item(slot))) {\n\t\t\t\treturn this.removeAt(slot);\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tclear(): void {\n\t\tthis.count = 0;\n\t}\n\n\t*values(): Generator<T> {\n\t\tfor (let slot: UINT = 0; slot < this.capacity; slot++) {\n\t\t\tif (slot >= this.count) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tyield this.items[slot % this.capacity] ?? this.blank;\n\t\t}\n\t}\n}\n\n/**\n * A map of at most `capacity` entries. Up to `linearLimit` entries, or with string keys, a lookup\n * scans every slot; a larger map with number keys hashes them into twice as many slots, probing\n * from each key's home slot and closing the gap a deletion leaves.\n */\nexport class BoundedMap<K extends number | string, V> {\n\tprivate readonly hashed: boolean;\n\tprivate readonly slots: number;\n\tprivate readonly slotKeys: K[];\n\tprivate readonly slotValues: V[];\n\tprivate readonly used: boolean[];\n\t/** When each slot's entry was added, for dropping the oldest. */\n\tprivate readonly ages: number[];\n\tprivate added = 0;\n\tprivate count = 0;\n\t/** What an empty slot holds; reads fall back to them where TypeScript can't see a slot is filled. */\n\tprivate readonly blankKey: K;\n\tprivate readonly blankValue: V;\n\t/** How many entries the map refused or dropped because it was full. */\n\toverflowed = 0;\n\n\tconstructor(\n\t\treadonly capacity: number,\n\t\tblankKey: K,\n\t\tblank: () => V,\n\t\tprivate readonly options: BoundedOptions,\n\t) {\n\t\tthis.hashed = capacity > linearLimit && typeof blankKey === \"number\";\n\t\tthis.slots = this.hashed ? capacity * 2 : capacity;\n\t\tthis.slotKeys = Array.from({ length: this.slots }, () => blankKey);\n\t\tthis.slotValues = Array.from({ length: this.slots }, blank);\n\t\tthis.used = Array.from({ length: this.slots }, () => false);\n\t\tthis.ages = Array.from({ length: this.slots }, () => 0);\n\t\tthis.blankKey = blankKey;\n\t\tthis.blankValue = blank();\n\t}\n\n\tprivate keyAt(slot: UINT): K {\n\t\treturn this.slotKeys[slot % this.slots] ?? this.blankKey;\n\t}\n\n\tprivate valueAt(slot: UINT): V {\n\t\treturn this.slotValues[slot % this.slots] ?? this.blankValue;\n\t}\n\n\tprivate usedAt(slot: UINT): boolean {\n\t\treturn this.used[slot % this.slots] ?? false;\n\t}\n\n\tprivate ageAt(slot: UINT): number {\n\t\treturn this.ages[slot % this.slots] ?? 0;\n\t}\n\n\tget size(): number {\n\t\treturn this.count;\n\t}\n\n\thas(key: K): boolean {\n\t\treturn this.slotOf(key) >= 0;\n\t}\n\n\t/** The entry for `key`, as a copy, or undefined. Change a stored entry with `update`. */\n\tget(key: K): V | undefined {\n\t\tconst found = this.slotOf(key);\n\t\tif (found < 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.valueAt(found);\n\t}\n\n\t/** Stores the entry for `key`; false when the map is full and refuses a new key. */\n\tset(key: K, value: V): boolean {\n\t\tconst found = this.slotOf(key);\n\t\tif (found >= 0) {\n\t\t\tconst slot: UINT = found;\n\t\t\tthis.slotValues[slot % this.slots] = value;\n\t\t\treturn true;\n\t\t}\n\t\tif (this.count === this.capacity) {\n\t\t\tthis.overflowed += 1;\n\t\t\tif (this.options.onFull === \"reject\") {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis.removeSlot(this.oldestSlot());\n\t\t}\n\t\tconst slot = this.freeSlot(key);\n\t\tthis.slotKeys[slot % this.slots] = key;\n\t\tthis.slotValues[slot % this.slots] = value;\n\t\tthis.used[slot % this.slots] = true;\n\t\tthis.ages[slot % this.slots] = this.added;\n\t\tthis.added += 1;\n\t\tthis.count += 1;\n\t\treturn true;\n\t}\n\n\t/** Changes the stored entry for `key` in place; false when there is none. */\n\tupdate(key: K, change: (entry: V) => void): boolean {\n\t\tconst found = this.slotOf(key);\n\t\tif (found < 0) {\n\t\t\treturn false;\n\t\t}\n\t\tconst slot: UINT = found;\n\t\t// A copy, changed and stored back: an element at a runtime slot can't be lent out.\n\t\tconst entry = structuredClone(\n\t\t\tthis.slotValues[slot % this.slots] ?? this.blankValue,\n\t\t);\n\t\tchange(entry);\n\t\tthis.slotValues[slot % this.slots] = entry;\n\t\treturn true;\n\t}\n\n\tdelete(key: K): boolean {\n\t\tconst found = this.slotOf(key);\n\t\tif (found < 0) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.removeSlot(found);\n\t\treturn true;\n\t}\n\n\tclear(): void {\n\t\tfor (let slot: UINT = 0; slot < this.slots; slot++) {\n\t\t\tthis.used[slot % this.slots] = false;\n\t\t}\n\t\tthis.count = 0;\n\t}\n\n\t*keys(): Generator<K> {\n\t\tfor (let slot: UINT = 0; slot < this.slots; slot++) {\n\t\t\tif (this.usedAt(slot)) {\n\t\t\t\tyield this.keyAt(slot);\n\t\t\t}\n\t\t}\n\t}\n\n\t*values(): Generator<V> {\n\t\tfor (let slot: UINT = 0; slot < this.slots; slot++) {\n\t\t\tif (this.usedAt(slot)) {\n\t\t\t\tyield this.slotValues[slot % this.slots] ?? this.blankValue;\n\t\t\t}\n\t\t}\n\t}\n\n\t/** The slot holding `key`, or -1. */\n\tprivate slotOf(key: K): number {\n\t\tif (!this.hashed) {\n\t\t\tfor (let slot: UINT = 0; slot < this.slots; slot++) {\n\t\t\t\tif (this.usedAt(slot) && this.keyAt(slot) === key) {\n\t\t\t\t\treturn slot;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn -1;\n\t\t}\n\t\tconst home: UINT = this.home(key);\n\t\tfor (let probe: UINT = 0; probe < this.slots; probe++) {\n\t\t\tconst slot: UINT = (home + probe) % this.slots;\n\t\t\tif (!this.usedAt(slot)) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif (this.keyAt(slot) === key) {\n\t\t\t\treturn slot;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\n\t/** The slot a new key goes in: the first free one, from its home slot when hashed. */\n\tprivate freeSlot(key: K): UINT {\n\t\tconst home: UINT = this.hashed ? this.home(key) : 0;\n\t\tfor (let probe: UINT = 0; probe < this.slots; probe++) {\n\t\t\tconst slot: UINT = (home + probe) % this.slots;\n\t\t\tif (!this.usedAt(slot)) {\n\t\t\t\treturn slot;\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/** The slot a number key hashes to. */\n\tprivate home(key: K): number {\n\t\tif (typeof key !== \"number\") {\n\t\t\treturn 0;\n\t\t}\n\t\tconst remainder = key % this.slots;\n\t\treturn remainder < 0 ? remainder + this.slots : remainder;\n\t}\n\n\t/** The slot whose entry was added first. */\n\tprivate oldestSlot(): number {\n\t\tlet oldest = -1;\n\t\tfor (let slot: UINT = 0; slot < this.slots; slot++) {\n\t\t\tif (\n\t\t\t\tthis.usedAt(slot) &&\n\t\t\t\t(oldest < 0 || this.ageAt(slot) - this.ageAt(oldest) < 0)\n\t\t\t) {\n\t\t\t\toldest = slot;\n\t\t\t}\n\t\t}\n\t\treturn oldest;\n\t}\n\n\t/**\n\t * Empties a slot. A hashed map then moves back each entry after it that could sit earlier, so no\n\t * lookup stops at the gap before reaching its key.\n\t */\n\tprivate removeSlot(found: number): void {\n\t\tif (found < 0) {\n\t\t\treturn;\n\t\t}\n\t\tconst removed: UINT = found;\n\t\tthis.used[removed % this.slots] = false;\n\t\tthis.count -= 1;\n\t\tif (!this.hashed) {\n\t\t\treturn;\n\t\t}\n\t\tlet hole: UINT = removed % this.slots;\n\t\tfor (let probe: UINT = 1; probe < this.slots; probe++) {\n\t\t\tconst next: UINT = (removed + probe) % this.slots;\n\t\t\tif (!this.usedAt(next)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst home: UINT = this.home(this.keyAt(next));\n\t\t\tconst stays =\n\t\t\t\thole <= next\n\t\t\t\t\t? home > hole && home <= next\n\t\t\t\t\t: home > hole || home <= next;\n\t\t\tif (!stays) {\n\t\t\t\tthis.slotKeys[hole % this.slots] = this.keyAt(next);\n\t\t\t\tthis.slotValues[hole % this.slots] = this.valueAt(next);\n\t\t\t\tthis.ages[hole % this.slots] = this.ageAt(next);\n\t\t\t\tthis.used[hole % this.slots] = true;\n\t\t\t\tthis.used[next % this.slots] = false;\n\t\t\t\thole = next;\n\t\t\t}\n\t\t}\n\t}\n}\n\n/** A set of at most `capacity` keys. */\nexport class BoundedSet<K extends number | string> {\n\tprivate readonly members: BoundedMap<K, boolean>;\n\n\tconstructor(\n\t\treadonly capacity: number,\n\t\tblankKey: K,\n\t\toptions: BoundedOptions,\n\t) {\n\t\tthis.members = new BoundedMap<K, boolean>(\n\t\t\tcapacity,\n\t\t\tblankKey,\n\t\t\t() => false,\n\t\t\toptions,\n\t\t);\n\t}\n\n\tget size(): number {\n\t\treturn this.members.size;\n\t}\n\n\t/** How many keys the set refused or dropped because it was full. */\n\tget overflowed(): number {\n\t\treturn this.members.overflowed;\n\t}\n\n\thas(key: K): boolean {\n\t\treturn this.members.has(key);\n\t}\n\n\t/** Adds the key; false when the set is full and refuses it. */\n\tadd(key: K): boolean {\n\t\treturn this.members.set(key, true);\n\t}\n\n\tdelete(key: K): boolean {\n\t\treturn this.members.delete(key);\n\t}\n\n\tclear(): void {\n\t\tthis.members.clear();\n\t}\n\n\t*values(): Generator<K> {\n\t\tyield* this.members.keys();\n\t}\n}\n"
5
+ "// PLC implementation source: a plain TypeScript program's collections. Setup fixes each one's\n// capacity, so the PLC stores it in arrays allocated once, and every loop over it is bounded by\n// that capacity. The same classes run under Bun for setup, tests and simulation.\nimport type { UINT } from \"../types/index\";\n\n/** Bun's, at setup and in simulation; the PLC compiles it as the dialect's `copy`. */\ndeclare function structuredClone<T>(value: T): T;\n\n/** What a full collection does with one more item: refuse it, or make room by dropping the oldest. */\nexport type OnFull = \"reject\" | \"dropOldest\";\n\nexport interface BoundedOptions {\n\treadonly onFull: OnFull;\n}\n\n/** Above this capacity a map with number keys hashes them; at or below it, a scan of every slot is as quick. */\nexport const linearLimit = 32;\n\n/** A first-in, first-out queue of at most `capacity` items, in a ring. */\nexport class BoundedQueue<T> {\n\tprivate readonly items: T[];\n\tprivate first: UINT = 0;\n\tprivate count: UINT = 0;\n\t/** How many items the queue refused or dropped because it was full. */\n\toverflowed = 0;\n\n\t/** What an empty slot holds; reads fall back to it where TypeScript can't see the slot is filled. */\n\tprivate readonly blank: T;\n\n\tconstructor(\n\t\treadonly capacity: number,\n\t\tblank: () => T,\n\t\tprivate readonly options: BoundedOptions,\n\t) {\n\t\tthis.items = Array.from({ length: capacity }, blank);\n\t\tthis.blank = blank();\n\t}\n\n\tprivate item(slot: UINT): T {\n\t\treturn this.items[slot % this.capacity] ?? this.blank;\n\t}\n\n\tget length(): number {\n\t\treturn this.count;\n\t}\n\n\t/** Adds an item at the back; false when the queue is full and refuses it. */\n\tpush(item: T): boolean {\n\t\tif (this.count === this.capacity) {\n\t\t\tthis.overflowed += 1;\n\t\t\tif (this.options.onFull === \"reject\") {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis.first = (this.first + 1) % this.capacity;\n\t\t\tthis.count -= 1;\n\t\t}\n\t\tthis.items[(this.first + this.count) % this.capacity] = item;\n\t\tthis.count += 1;\n\t\treturn true;\n\t}\n\n\t/** Takes the item at the front, or undefined when empty. */\n\tshift(): T | undefined {\n\t\tif (this.count === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst item = this.item(this.first);\n\t\tthis.first = (this.first + 1) % this.capacity;\n\t\tthis.count -= 1;\n\t\treturn item;\n\t}\n\n\t/** Takes the item at the back, or undefined when empty. */\n\tpop(): T | undefined {\n\t\tif (this.count === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tthis.count -= 1;\n\t\treturn this.item(this.first + this.count);\n\t}\n\n\t/** The item at the front, left in place. */\n\tpeek(): T | undefined {\n\t\treturn this.count === 0 ? undefined : this.item(this.first);\n\t}\n\n\t/** The item `offset` from the front, or undefined past the back. */\n\tat(offset: UINT): T | undefined {\n\t\treturn offset < this.count ? this.item(this.first + offset) : undefined;\n\t}\n\n\t/** Changes the item `offset` from the front in place; false past the back. */\n\tupdate(offset: UINT, change: (item: T) => void): boolean {\n\t\tif (offset >= this.count) {\n\t\t\treturn false;\n\t\t}\n\t\tconst slot: UINT = (this.first + offset) % this.capacity;\n\t\t// A copy, changed and stored back: an element at a runtime slot can't be lent out.\n\t\tconst item = structuredClone(\n\t\t\tthis.items[slot % this.capacity] ?? this.blank,\n\t\t);\n\t\tchange(item);\n\t\tthis.items[slot % this.capacity] = item;\n\t\treturn true;\n\t}\n\n\tclear(): void {\n\t\tthis.first = 0;\n\t\tthis.count = 0;\n\t}\n\n\t*values(): Generator<T> {\n\t\tfor (let offset: UINT = 0; offset < this.capacity; offset++) {\n\t\t\tif (offset >= this.count) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// The stored item itself, so a loop that changes it changes the queue's.\n\t\t\tyield this.items[(this.first + offset) % this.capacity] ?? this.blank;\n\t\t}\n\t}\n}\n\n/** A list of at most `capacity` items in order, which can be removed from anywhere. */\nexport class BoundedList<T> {\n\tprivate readonly items: T[];\n\tprivate count: UINT = 0;\n\t/** How many items the list refused or dropped because it was full. */\n\toverflowed = 0;\n\n\t/** What an empty slot holds; reads fall back to it where TypeScript can't see the slot is filled. */\n\tprivate readonly blank: T;\n\n\tconstructor(\n\t\treadonly capacity: number,\n\t\tblank: () => T,\n\t\tprivate readonly options: BoundedOptions,\n\t) {\n\t\tthis.items = Array.from({ length: capacity }, blank);\n\t\tthis.blank = blank();\n\t}\n\n\tprivate item(slot: UINT): T {\n\t\treturn this.items[slot % this.capacity] ?? this.blank;\n\t}\n\n\tget length(): number {\n\t\treturn this.count;\n\t}\n\n\t/** Adds an item at the end; false when the list is full and refuses it. */\n\tpush(item: T): boolean {\n\t\tif (this.count === this.capacity) {\n\t\t\tthis.overflowed += 1;\n\t\t\tif (this.options.onFull === \"reject\") {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis.removeAt(0);\n\t\t}\n\t\tthis.items[this.count % this.capacity] = item;\n\t\tthis.count += 1;\n\t\treturn true;\n\t}\n\n\tat(index: UINT): T | undefined {\n\t\treturn index < this.count ? this.item(index) : undefined;\n\t}\n\n\t/** Changes the item at `index` in place; false past the end. */\n\tupdate(index: UINT, change: (item: T) => void): boolean {\n\t\tif (index >= this.count) {\n\t\t\treturn false;\n\t\t}\n\t\t// A copy, changed and stored back: an element at a runtime slot can't be lent out.\n\t\tconst item = structuredClone(\n\t\t\tthis.items[index % this.capacity] ?? this.blank,\n\t\t);\n\t\tchange(item);\n\t\tthis.items[index % this.capacity] = item;\n\t\treturn true;\n\t}\n\n\t/** Removes the item at `index`, moving the ones after it up; false past the end. */\n\tremoveAt(index: UINT): boolean {\n\t\tif (index >= this.count) {\n\t\t\treturn false;\n\t\t}\n\t\tfor (let slot: UINT = 0; slot < this.capacity; slot++) {\n\t\t\tif (slot >= index && slot + 1 < this.count) {\n\t\t\t\tthis.items[slot % this.capacity] = this.item(slot + 1);\n\t\t\t}\n\t\t}\n\t\tthis.count -= 1;\n\t\treturn true;\n\t}\n\n\t/** The index of the first item that passes, or -1. */\n\tfindIndex(test: (item: T) => boolean): number {\n\t\tfor (let slot: UINT = 0; slot < this.capacity; slot++) {\n\t\t\tif (slot < this.count && test(this.item(slot))) {\n\t\t\t\treturn slot;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\n\t/** Removes the first item that passes; false when none does. */\n\tremove(test: (item: T) => boolean): boolean {\n\t\tfor (let slot: UINT = 0; slot < this.capacity; slot++) {\n\t\t\tif (slot < this.count && test(this.item(slot))) {\n\t\t\t\treturn this.removeAt(slot);\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tclear(): void {\n\t\tthis.count = 0;\n\t}\n\n\t*values(): Generator<T> {\n\t\tfor (let slot: UINT = 0; slot < this.capacity; slot++) {\n\t\t\tif (slot >= this.count) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tyield this.items[slot % this.capacity] ?? this.blank;\n\t\t}\n\t}\n}\n\n/**\n * A map of at most `capacity` entries. Up to `linearLimit` entries, or with string keys, a lookup\n * scans every slot; a larger map with number keys hashes them into twice as many slots, probing\n * from each key's home slot and closing the gap a deletion leaves.\n */\nexport class BoundedMap<K extends number | string, V> {\n\tprivate readonly hashed: boolean;\n\tprivate readonly slots: number;\n\tprivate readonly slotKeys: K[];\n\tprivate readonly slotValues: V[];\n\tprivate readonly used: boolean[];\n\t/** When each slot's entry was added, for dropping the oldest. */\n\tprivate readonly ages: number[];\n\tprivate added = 0;\n\tprivate count = 0;\n\t/** What an empty slot holds; reads fall back to them where TypeScript can't see a slot is filled. */\n\tprivate readonly blankKey: K;\n\tprivate readonly blankValue: V;\n\t/** How many entries the map refused or dropped because it was full. */\n\toverflowed = 0;\n\n\tconstructor(\n\t\treadonly capacity: number,\n\t\tblankKey: K,\n\t\tblank: () => V,\n\t\tprivate readonly options: BoundedOptions,\n\t) {\n\t\tthis.hashed = capacity > linearLimit && typeof blankKey === \"number\";\n\t\tthis.slots = this.hashed ? capacity * 2 : capacity;\n\t\tthis.slotKeys = Array.from({ length: this.slots }, () => blankKey);\n\t\tthis.slotValues = Array.from({ length: this.slots }, blank);\n\t\tthis.used = Array.from({ length: this.slots }, () => false);\n\t\tthis.ages = Array.from({ length: this.slots }, () => 0);\n\t\tthis.blankKey = blankKey;\n\t\tthis.blankValue = blank();\n\t}\n\n\tprivate keyAt(slot: UINT): K {\n\t\treturn this.slotKeys[slot % this.slots] ?? this.blankKey;\n\t}\n\n\tprivate valueAt(slot: UINT): V {\n\t\treturn this.slotValues[slot % this.slots] ?? this.blankValue;\n\t}\n\n\tprivate usedAt(slot: UINT): boolean {\n\t\treturn this.used[slot % this.slots] ?? false;\n\t}\n\n\tprivate ageAt(slot: UINT): number {\n\t\treturn this.ages[slot % this.slots] ?? 0;\n\t}\n\n\tget size(): number {\n\t\treturn this.count;\n\t}\n\n\thas(key: K): boolean {\n\t\treturn this.slotOf(key) >= 0;\n\t}\n\n\t/** The entry for `key`, as a copy, or undefined. Change a stored entry with `update`. */\n\tget(key: K): V | undefined {\n\t\tconst found = this.slotOf(key);\n\t\tif (found < 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.valueAt(found);\n\t}\n\n\t/** Stores the entry for `key`; false when the map is full and refuses a new key. */\n\tset(key: K, value: V): boolean {\n\t\tconst found = this.slotOf(key);\n\t\tif (found >= 0) {\n\t\t\tconst slot: UINT = found;\n\t\t\tthis.slotValues[slot % this.slots] = value;\n\t\t\treturn true;\n\t\t}\n\t\tif (this.count === this.capacity) {\n\t\t\tthis.overflowed += 1;\n\t\t\tif (this.options.onFull === \"reject\") {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis.removeSlot(this.oldestSlot());\n\t\t}\n\t\tconst slot = this.freeSlot(key);\n\t\tthis.slotKeys[slot % this.slots] = key;\n\t\tthis.slotValues[slot % this.slots] = value;\n\t\tthis.used[slot % this.slots] = true;\n\t\tthis.ages[slot % this.slots] = this.added;\n\t\tthis.added += 1;\n\t\tthis.count += 1;\n\t\treturn true;\n\t}\n\n\t/** Changes the stored entry for `key` in place; false when there is none. */\n\tupdate(key: K, change: (entry: V) => void): boolean {\n\t\tconst found = this.slotOf(key);\n\t\tif (found < 0) {\n\t\t\treturn false;\n\t\t}\n\t\tconst slot: UINT = found;\n\t\t// A copy, changed and stored back: an element at a runtime slot can't be lent out.\n\t\tconst entry = structuredClone(\n\t\t\tthis.slotValues[slot % this.slots] ?? this.blankValue,\n\t\t);\n\t\tchange(entry);\n\t\tthis.slotValues[slot % this.slots] = entry;\n\t\treturn true;\n\t}\n\n\tdelete(key: K): boolean {\n\t\tconst found = this.slotOf(key);\n\t\tif (found < 0) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.removeSlot(found);\n\t\treturn true;\n\t}\n\n\tclear(): void {\n\t\tfor (let slot: UINT = 0; slot < this.slots; slot++) {\n\t\t\tthis.used[slot % this.slots] = false;\n\t\t}\n\t\tthis.count = 0;\n\t}\n\n\t*keys(): Generator<K> {\n\t\tfor (let slot: UINT = 0; slot < this.slots; slot++) {\n\t\t\tif (this.usedAt(slot)) {\n\t\t\t\tyield this.keyAt(slot);\n\t\t\t}\n\t\t}\n\t}\n\n\t*values(): Generator<V> {\n\t\tfor (let slot: UINT = 0; slot < this.slots; slot++) {\n\t\t\tif (this.usedAt(slot)) {\n\t\t\t\tyield this.slotValues[slot % this.slots] ?? this.blankValue;\n\t\t\t}\n\t\t}\n\t}\n\n\t/** The slot holding `key`, or -1. */\n\tprivate slotOf(key: K): number {\n\t\tif (!this.hashed) {\n\t\t\tfor (let slot: UINT = 0; slot < this.slots; slot++) {\n\t\t\t\tif (this.usedAt(slot) && this.keyAt(slot) === key) {\n\t\t\t\t\treturn slot;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn -1;\n\t\t}\n\t\tconst home: UINT = this.home(key);\n\t\tfor (let probe: UINT = 0; probe < this.slots; probe++) {\n\t\t\tconst slot: UINT = (home + probe) % this.slots;\n\t\t\tif (!this.usedAt(slot)) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif (this.keyAt(slot) === key) {\n\t\t\t\treturn slot;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\n\t/** The slot a new key goes in: the first free one, from its home slot when hashed. */\n\tprivate freeSlot(key: K): UINT {\n\t\tconst home: UINT = this.hashed ? this.home(key) : 0;\n\t\tfor (let probe: UINT = 0; probe < this.slots; probe++) {\n\t\t\tconst slot: UINT = (home + probe) % this.slots;\n\t\t\tif (!this.usedAt(slot)) {\n\t\t\t\treturn slot;\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/** The slot a number key hashes to. */\n\tprivate home(key: K): number {\n\t\tif (typeof key !== \"number\") {\n\t\t\treturn 0;\n\t\t}\n\t\tconst remainder = key % this.slots;\n\t\treturn remainder < 0 ? remainder + this.slots : remainder;\n\t}\n\n\t/** The slot whose entry was added first. */\n\tprivate oldestSlot(): number {\n\t\tlet oldest = -1;\n\t\tfor (let slot: UINT = 0; slot < this.slots; slot++) {\n\t\t\tif (\n\t\t\t\tthis.usedAt(slot) &&\n\t\t\t\t(oldest < 0 || this.ageAt(slot) - this.ageAt(oldest) < 0)\n\t\t\t) {\n\t\t\t\toldest = slot;\n\t\t\t}\n\t\t}\n\t\treturn oldest;\n\t}\n\n\t/**\n\t * Empties a slot. A hashed map then moves back each entry after it that could sit earlier, so no\n\t * lookup stops at the gap before reaching its key.\n\t */\n\tprivate removeSlot(found: number): void {\n\t\tif (found < 0) {\n\t\t\treturn;\n\t\t}\n\t\tconst removed: UINT = found;\n\t\tthis.used[removed % this.slots] = false;\n\t\tthis.count -= 1;\n\t\tif (!this.hashed) {\n\t\t\treturn;\n\t\t}\n\t\tlet hole: UINT = removed % this.slots;\n\t\tfor (let probe: UINT = 1; probe < this.slots; probe++) {\n\t\t\tconst next: UINT = (removed + probe) % this.slots;\n\t\t\tif (!this.usedAt(next)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst home: UINT = this.home(this.keyAt(next));\n\t\t\tconst stays =\n\t\t\t\thole <= next\n\t\t\t\t\t? home > hole && home <= next\n\t\t\t\t\t: home > hole || home <= next;\n\t\t\tif (!stays) {\n\t\t\t\tthis.slotKeys[hole % this.slots] = this.keyAt(next);\n\t\t\t\tthis.slotValues[hole % this.slots] = this.valueAt(next);\n\t\t\t\tthis.ages[hole % this.slots] = this.ageAt(next);\n\t\t\t\tthis.used[hole % this.slots] = true;\n\t\t\t\tthis.used[next % this.slots] = false;\n\t\t\t\thole = next;\n\t\t\t}\n\t\t}\n\t}\n}\n\n/** A set of at most `capacity` keys. */\nexport class BoundedSet<K extends number | string> {\n\tprivate readonly members: BoundedMap<K, boolean>;\n\n\tconstructor(\n\t\treadonly capacity: number,\n\t\tblankKey: K,\n\t\toptions: BoundedOptions,\n\t) {\n\t\tthis.members = new BoundedMap<K, boolean>(\n\t\t\tcapacity,\n\t\t\tblankKey,\n\t\t\t() => false,\n\t\t\toptions,\n\t\t);\n\t}\n\n\tget size(): number {\n\t\treturn this.members.size;\n\t}\n\n\t/** How many keys the set refused or dropped because it was full. */\n\tget overflowed(): number {\n\t\treturn this.members.overflowed;\n\t}\n\n\thas(key: K): boolean {\n\t\treturn this.members.has(key);\n\t}\n\n\t/** Adds the key; false when the set is full and refuses it. */\n\tadd(key: K): boolean {\n\t\treturn this.members.set(key, true);\n\t}\n\n\tdelete(key: K): boolean {\n\t\treturn this.members.delete(key);\n\t}\n\n\tclear(): void {\n\t\tthis.members.clear();\n\t}\n\n\t*values(): Generator<K> {\n\t\tyield* this.members.keys();\n\t}\n}\n\n/**\n * A record holding what `create` makes for each member of a numeric enum, in the enum's order: the\n * PLC's array indexed by that enum. For setup, where a literal would list every member by hand.\n */\nexport function enumRecord<Key extends number, T>(\n\tmembers: Readonly<Record<string, Key | string>>,\n\tcreate: (member: Key) => T,\n): Record<Key, T>;\nexport function enumRecord(\n\tmembers: Readonly<Record<string, number | string>>,\n\tcreate: (member: number) => unknown,\n): Record<number, unknown> {\n\treturn Object.fromEntries(\n\t\tObject.values(members)\n\t\t\t// A numeric enum also maps each value back to its name.\n\t\t\t.filter((member) => typeof member === \"number\")\n\t\t\t.map((member) => [member, create(member)]),\n\t);\n}\n"
6
6
  ],
7
- "mappings": ";AAgBO,IAAM,cAAc;AAAA;AAGpB,MAAM,aAAgB;AAAA,EAWlB;AAAA,EAEQ;AAAA,EAZD;AAAA,EACT,QAAc;AAAA,EACd,QAAc;AAAA,EAEtB,aAAa;AAAA,EAGI;AAAA,EAEjB,WAAW,CACD,UACT,OACiB,SAChB;AAAA,IAHQ;AAAA,IAEQ;AAAA,IAEjB,KAAK,QAAQ,MAAM,KAAK,EAAE,QAAQ,SAAS,GAAG,KAAK;AAAA,IACnD,KAAK,QAAQ,MAAM;AAAA;AAAA,EAGZ,IAAI,CAAC,MAAe;AAAA,IAC3B,OAAO,KAAK,MAAM,OAAO,KAAK,aAAa,KAAK;AAAA;AAAA,MAG7C,MAAM,GAAW;AAAA,IACpB,OAAO,KAAK;AAAA;AAAA,EAIb,IAAI,CAAC,MAAkB;AAAA,IACtB,IAAI,KAAK,UAAU,KAAK,UAAU;AAAA,MACjC,KAAK,cAAc;AAAA,MACnB,IAAI,KAAK,QAAQ,WAAW,UAAU;AAAA,QACrC,OAAO;AAAA,MACR;AAAA,MACA,KAAK,SAAS,KAAK,QAAQ,KAAK,KAAK;AAAA,MACrC,KAAK,SAAS;AAAA,IACf;AAAA,IACA,KAAK,MAAO,MAAK,QAAQ,KAAK,SAAS,KAAK,YAAY;AAAA,IACxD,KAAK,SAAS;AAAA,IACd,OAAO;AAAA;AAAA,EAIR,KAAK,GAAkB;AAAA,IACtB,IAAI,KAAK,UAAU,GAAG;AAAA,MACrB;AAAA,IACD;AAAA,IACA,MAAM,OAAO,KAAK,KAAK,KAAK,KAAK;AAAA,IACjC,KAAK,SAAS,KAAK,QAAQ,KAAK,KAAK;AAAA,IACrC,KAAK,SAAS;AAAA,IACd,OAAO;AAAA;AAAA,EAIR,GAAG,GAAkB;AAAA,IACpB,IAAI,KAAK,UAAU,GAAG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AAK;AAAA;AAE3B;AAUO,SAAS,UAAU,CACzB,SACA,QAC0B;AAAA,EAC1B,OAAO,OAAO,YACb,OAAO,OAAO,OAAO,EAEnB,OAAO,CAAC,WAAW,OAAO,WAAW,QAAQ,EAC7C,IAAI,CAAC,WAAW,CAAC,QAAQ,OAAO,MAAM,CAAC,CAAC,CAC3C;AAAA;",
8
+ "debugId": "380F8D6249FDCF9B64756E2164756E21",
9
9
  "names": []
10
10
  }
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "url": "git+https://github.com/rip-technologies/tsplc.git",
18
18
  "directory": "packages/compiler"
19
19
  },
20
- "version": "0.5.16",
20
+ "version": "0.5.18",
21
21
  "type": "module",
22
22
  "exports": {
23
23
  ".": {
@@ -93,17 +93,17 @@
93
93
  "bun": ">=1.4.3"
94
94
  },
95
95
  "dependencies": {
96
- "@tsplc/agent": "0.5.16",
97
- "@tsplc/build": "0.5.16",
98
- "@tsplc/config": "0.5.16",
99
- "@tsplc/debug": "0.5.16",
100
- "@tsplc/opcua": "0.5.16",
101
- "@tsplc/typegen": "0.5.16",
96
+ "@tsplc/agent": "0.5.18",
97
+ "@tsplc/build": "0.5.18",
98
+ "@tsplc/config": "0.5.18",
99
+ "@tsplc/debug": "0.5.18",
100
+ "@tsplc/opcua": "0.5.18",
101
+ "@tsplc/typegen": "0.5.18",
102
102
  "typescript": "6.0.3",
103
103
  "zod": "4.3.6",
104
104
  "@types/bun": "1.4.2",
105
- "@tsplc/server": "0.5.16",
106
- "@tsplc/iec": "0.5.16"
105
+ "@tsplc/server": "0.5.18",
106
+ "@tsplc/iec": "0.5.18"
107
107
  },
108
108
  "bin": {
109
109
  "tsplc": "./dist/cli.js"
@@ -21,6 +21,7 @@ import { type CodesysPlan, isPlanned } from "./plan";
21
21
  import { emitScanProgram, emitTaskWrappers } from "./programs";
22
22
  import { publishedSymbols } from "./publication";
23
23
  import { emitRoutine } from "./routines";
24
+ import { emitScanClock } from "./scan-clock";
24
25
  import { serviceChannelsFile } from "./service-channels";
25
26
  import { Sources } from "./sources";
26
27
  import { type ObjectMapping, type PlacedObject, stFiles } from "./st-files";
@@ -75,6 +76,7 @@ function emissionContext(plan: CodesysPlan) {
75
76
  ...global.targetTypes.objects,
76
77
  ...globalLists.objects,
77
78
  ...ioList.objects,
79
+ ...(global.scanClock ? [emitScanClock(global.scanClock)] : []),
78
80
  ...(network ? [network] : []),
79
81
  ];
80
82
 
@@ -12,13 +12,13 @@ import {
12
12
  statementExpressions,
13
13
  subexpressions,
14
14
  } from "@tsplc/compiler/ir";
15
- import { scanClockType } from "@tsplc/debug/manifest";
16
15
  import {
17
16
  type BinaryOperator,
18
17
  type ElementaryFunction,
19
18
  floatMaximum,
20
19
  isElementary,
21
20
  } from "@tsplc/iec/arithmetic";
21
+ import { required } from "./required";
22
22
 
23
23
  /** The Structured Text function each elementary function is. */
24
24
  const elementaryNames: Readonly<Record<ElementaryFunction, string>> = {
@@ -58,9 +58,6 @@ const operatorTokens: Readonly<Record<InfixOperator, string>> = {
58
58
  const isInfix = (operator: BinaryOperator): operator is InfixOperator =>
59
59
  Object.hasOwn(operatorTokens, operator);
60
60
 
61
- /** Milliseconds since the runtime started; DINT wraps after 24.8 days, so subtract to compare. */
62
- export const scanClock = `TO_${scanClockType}(TIME_TO_UDINT(TIME()))`;
63
-
64
61
  export function scalarLiteral(value: Constant, type: string): string {
65
62
  if (value.kind === "bool") {
66
63
  return value.value ? "TRUE" : "FALSE";
@@ -85,6 +82,8 @@ export class NumericLowering {
85
82
  constructor(
86
83
  private readonly types: ReadonlyMap<string, PlcType>,
87
84
  private readonly allocate: (label: string) => string,
85
+ /** What a `now()` reads; undefined for a program that never calls it. */
86
+ private readonly scanClock: string | undefined,
88
87
  ) {}
89
88
 
90
89
  private prepare(value: CoreExpression): void {
@@ -131,7 +130,7 @@ export class NumericLowering {
131
130
  return `TIME_TO_UDINT(${operands[0]})`;
132
131
  }
133
132
  if (value.operator === "clock") {
134
- return scanClock;
133
+ return required(this.scanClock);
135
134
  }
136
135
  if (isElementary(value.operator)) {
137
136
  return `${elementaryNames[value.operator]}(${operands[0]})`;
@@ -5,9 +5,9 @@ import {
5
5
  type Task,
6
6
  } from "@tsplc/compiler/ir";
7
7
  import type { IoChannel } from "./global-lists";
8
- import { scanClock } from "./numeric";
9
8
  import type { CodesysPlan } from "./plan";
10
9
  import { required } from "./required";
10
+ import { latchScanClock, restoreScanClock, runtimeClock } from "./scan-clock";
11
11
  import { noResult } from "./statements";
12
12
  import type { EmissionContext } from "./symbols";
13
13
  import { accessedStorage } from "./task-access";
@@ -29,7 +29,8 @@ export function emitScanProgram(
29
29
  const channels = ioChannels.filter((channel) => used.has(channel.root));
30
30
  const stateful = symbols.programRoutines.has(program.entry);
31
31
  const call = `${required(symbols.functionNames.get(program.entry))}();`;
32
- // The first program of a task with a ring runs its sender first, which counts the scan and reads the clock.
32
+ // A task's first program starts its cycle: it reads the scan's clock before anything else runs,
33
+ // then a task with a ring runs its sender, which counts the scan.
33
34
  const task = plan.deployment.tasks.find(
34
35
  (item) => item.programs[0] === program.name,
35
36
  );
@@ -38,8 +39,15 @@ export function emitScanProgram(
38
39
  // The scan snapshots physical inputs before the authored routine and commits outputs
39
40
  // afterwards. RETURN in an authored routine cannot skip that epilogue.
40
41
  const lines = [
42
+ ...(task && symbols.scanClock
43
+ ? latchScanClock(symbols.scanClock, task.name)
44
+ : []),
41
45
  ...(ring ? [`${instrumentation.global}.${ring}();`] : []),
42
- ...(clock ? [`${instrumentation.global}.${clock} := ${scanClock};`] : []),
46
+ ...(clock
47
+ ? [
48
+ `${instrumentation.global}.${clock} := ${symbols.scanClock?.now ?? runtimeClock};`,
49
+ ]
50
+ : []),
43
51
  ...channels
44
52
  .filter((channel) => channel.input)
45
53
  .map(
@@ -90,7 +98,10 @@ export const taskPrograms = (plan: CodesysPlan, task: Task) => {
90
98
  };
91
99
  };
92
100
 
93
- /** Each task's wrapper PROGRAM, which calls the programs the compiler added to it in their order. */
101
+ /**
102
+ * Each task's wrapper PROGRAM, which calls the programs the compiler added to it in their order.
103
+ * It is the last program of the task's cycle, so it ends the scan's clock.
104
+ */
94
105
  export function emitTaskWrappers(
95
106
  { plan, symbols }: EmissionContext,
96
107
  objects: readonly GeneratedObject[],
@@ -108,9 +119,14 @@ export function emitTaskWrappers(
108
119
  return plan.deployment.tasks.map((task) => {
109
120
  const { wrapped, wrapper } = taskPrograms(plan, task);
110
121
  const name = symbols.names.allocateObject("PRG", wrapper.label);
111
- const calls = wrapped.map(
112
- (program) => `${required(programObjects.get(program)).name}();`,
113
- );
122
+ const calls = [
123
+ ...wrapped.map(
124
+ (program) => `${required(programObjects.get(program)).name}();`,
125
+ ),
126
+ ...(symbols.scanClock
127
+ ? restoreScanClock(symbols.scanClock, task.name)
128
+ : []),
129
+ ];
114
130
  return {
115
131
  id: wrapper.id,
116
132
  kind: "program",
@@ -0,0 +1,103 @@
1
+ import type {
2
+ CoreExpression,
3
+ CoreStatement,
4
+ GeneratedObject,
5
+ Task,
6
+ VerifiedCoreModule,
7
+ } from "@tsplc/compiler/ir";
8
+ import {
9
+ nestedBodies,
10
+ statementExpressions,
11
+ subexpressions,
12
+ } from "@tsplc/compiler/ir";
13
+ import { scanClockType } from "@tsplc/debug/manifest";
14
+ import { Names } from "./names";
15
+
16
+ /** Milliseconds since the runtime started; DINT wraps after 24.8 days, so subtract to compare. */
17
+ export const runtimeClock = `TO_${scanClockType}(TIME_TO_UDINT(TIME()))`;
18
+
19
+ /** The scan's clock of a program that calls `now()`: where a scan's time is held while the scan runs. */
20
+ export interface ScanClock {
21
+ /** The global list that holds the clock. */
22
+ list: string;
23
+ /** The time the running scan began, which every `now()` reads. */
24
+ now: string;
25
+ /**
26
+ * By task, where its scan keeps the clock of the scan it interrupted. A program with one task
27
+ * has none.
28
+ */
29
+ interrupted: ReadonlyMap<string, string>;
30
+ }
31
+
32
+ const readsClock = (value: CoreExpression): boolean =>
33
+ (value.kind === "unary" && value.operator === "clock") ||
34
+ subexpressions(value).some(readsClock);
35
+
36
+ const anyReadsClock = (items: readonly CoreStatement[]): boolean =>
37
+ items.some(
38
+ (item) =>
39
+ statementExpressions(item).some(readsClock) ||
40
+ nestedBodies(item).some(anyReadsClock),
41
+ );
42
+
43
+ /** The scan clock's names, for a program in which some routine calls `now()`. */
44
+ export function planScanClock(
45
+ core: VerifiedCoreModule,
46
+ tasks: readonly Task[],
47
+ objectNames: Names,
48
+ ): ScanClock | undefined {
49
+ if (
50
+ ![...core.functions, ...core.blocks].some((routine) =>
51
+ anyReadsClock(routine.body),
52
+ )
53
+ ) {
54
+ return undefined;
55
+ }
56
+ const list = objectNames.allocateObject("GVL", "TsplcScan");
57
+ const fields = new Names();
58
+ const now = fields.allocate("clock");
59
+ return {
60
+ list,
61
+ now: `${list}.${now}`,
62
+ interrupted: new Map(
63
+ tasks.length > 1
64
+ ? tasks.map((task) => [
65
+ task.name,
66
+ `${list}.${fields.allocate(`interrupted_${task.name}`)}`,
67
+ ])
68
+ : [],
69
+ ),
70
+ };
71
+ }
72
+
73
+ const field = (qualified: string) =>
74
+ qualified.slice(qualified.indexOf(".") + 1);
75
+
76
+ export const emitScanClock = (clock: ScanClock): GeneratedObject => ({
77
+ id: "tsplc:scanClock",
78
+ kind: "globalList",
79
+ name: clock.list,
80
+ declaration: `{attribute 'qualified_only'}
81
+ VAR_GLOBAL
82
+ ${[clock.now, ...clock.interrupted.values()].map((name) => ` ${field(name)} : ${scanClockType};\n`).join("")}END_VAR
83
+ `,
84
+ });
85
+
86
+ /**
87
+ * What a task's cycle starts with: it reads the runtime's clock once, so every `now()` of the scan
88
+ * returns one time. A task that interrupts another's scan runs to its end before that scan
89
+ * resumes, so it keeps the interrupted scan's time for `restoreScanClock` to put back.
90
+ */
91
+ export const latchScanClock = (clock: ScanClock, task: string): string[] => {
92
+ const interrupted = clock.interrupted.get(task);
93
+ return [
94
+ ...(interrupted ? [`${interrupted} := ${clock.now};`] : []),
95
+ `${clock.now} := ${runtimeClock};`,
96
+ ];
97
+ };
98
+
99
+ /** What a task's cycle ends with when it may have interrupted another task's scan. */
100
+ export const restoreScanClock = (clock: ScanClock, task: string): string[] => {
101
+ const interrupted = clock.interrupted.get(task);
102
+ return interrupted ? [`${clock.now} := ${interrupted};`] : [];
103
+ };
@@ -1,6 +1,7 @@
1
1
  import type { EmitResult } from "@tsplc/compiler/ir";
2
2
  import { emittedFiles } from "@tsplc/config/project-files";
3
3
  import { type ServiceChannel, serviceChannelSchema } from "@tsplc/server/wire";
4
+ import { publicComment } from "@tsplc/typegen";
4
5
  import { z } from "zod";
5
6
 
6
7
  /** `machines.ts`, which lists the service channels for the server and the Bun runtime to read back. */
@@ -8,7 +9,7 @@ export const serviceChannelsFile = (
8
9
  channels: readonly ServiceChannel[],
9
10
  ): EmitResult["artifacts"][number] => ({
10
11
  path: emittedFiles.machines,
11
- content: `// Generated service channels. Do not edit.\nexport const serviceChannels=${JSON.stringify(channels, null, 2)} as const;\n`,
12
+ content: `// Generated service channels. Do not edit.\n${publicComment}export const serviceChannels=${JSON.stringify(channels, null, 2)} as const;\n`,
12
13
  });
13
14
 
14
15
  /** The service channels a `machines.ts` lists. */
@@ -13,6 +13,7 @@ import { Names } from "./names";
13
13
  import { NumericLowering } from "./numeric";
14
14
  import type { CodesysPlan } from "./plan";
15
15
  import { required } from "./required";
16
+ import { planScanClock } from "./scan-clock";
16
17
  import { accessedStorage } from "./task-access";
17
18
 
18
19
  /** The names a routine's ST gives its parameters, locals and the block state it reaches. */
@@ -63,11 +64,19 @@ export function globalSymbols(plan: CodesysPlan) {
63
64
  .map((fn) => fn.id),
64
65
  );
65
66
  const globalNames = planGlobalNames(core, plan.programNames);
67
+ const scanClock = planScanClock(
68
+ core,
69
+ plan.deployment.tasks,
70
+ globalNames.names,
71
+ );
66
72
  return {
67
73
  ...globalNames,
68
74
  blocks: coreTables(core).blocks,
69
- numeric: new NumericLowering(globalNames.typeMap, (label) =>
70
- globalNames.names.allocate(label),
75
+ scanClock,
76
+ numeric: new NumericLowering(
77
+ globalNames.typeMap,
78
+ (label) => globalNames.names.allocate(label),
79
+ scanClock?.now,
71
80
  ),
72
81
  programRoutines,
73
82
  };
@@ -87,8 +87,16 @@ export const startRuntime = async (options: RuntimeOptions) => {
87
87
  slots?.transport ??
88
88
  (baseUrl === null ? null : httpTransport(http, baseUrl));
89
89
 
90
- /** The task whose scan runs, or last ran: continuations run in their caller's task. */
91
- const current = { task: tasks[0]?.name ?? "", scan: 0, scanning: false };
90
+ /**
91
+ * The task whose scan runs, or last ran: continuations run in their caller's task. `time` is
92
+ * the clock as that scan read it when it began.
93
+ */
94
+ const current = {
95
+ task: tasks[0]?.name ?? "",
96
+ scan: 0,
97
+ scanning: false,
98
+ time: 0,
99
+ };
92
100
  const diagnostics = { count: 0, lastError: 0 };
93
101
  const records = createTelemetry({
94
102
  build: manifest.build.id,
@@ -141,9 +149,10 @@ export const startRuntime = async (options: RuntimeOptions) => {
141
149
  ]),
142
150
  ),
143
151
  sdk: {
144
- "@tsplc/compiler/clock": { now } satisfies SdkModule<
145
- typeof import("../../types/clock")
146
- >,
152
+ "@tsplc/compiler/clock": {
153
+ // Awaited code resumes between scans here, where no scan's time stands, so it reads the clock itself.
154
+ now: () => (current.scanning ? current.time : now()),
155
+ } satisfies SdkModule<typeof import("../../types/clock")>,
147
156
  "@tsplc/compiler/retain": { persist, retain } satisfies SdkModule<
148
157
  typeof import("../../types/retain")
149
158
  >,
@@ -262,6 +271,7 @@ export const startRuntime = async (options: RuntimeOptions) => {
262
271
  task: task.name,
263
272
  scan: state.scan,
264
273
  scanning: true,
274
+ time: now(),
265
275
  });
266
276
  try {
267
277
  records.send(task.name, state.scan);
package/stdlib/clock.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import { plcTime } from "./plc-time";
2
2
 
3
- /** Milliseconds since the process started, as the PLC's `now()` counts them in a DINT; used when a program runs under Bun. */
3
+ /**
4
+ * Milliseconds since the process started, as the PLC's `now()` counts them in a DINT; used when a
5
+ * program runs under Bun. Each call reads the clock: holding one time for a scan is the Bun
6
+ * runtime's to do, as only it knows when a scan runs.
7
+ */
4
8
  export const now = (): number => plcTime() | 0;
@@ -512,3 +512,23 @@ export class BoundedSet<K extends number | string> {
512
512
  yield* this.members.keys();
513
513
  }
514
514
  }
515
+
516
+ /**
517
+ * A record holding what `create` makes for each member of a numeric enum, in the enum's order: the
518
+ * PLC's array indexed by that enum. For setup, where a literal would list every member by hand.
519
+ */
520
+ export function enumRecord<Key extends number, T>(
521
+ members: Readonly<Record<string, Key | string>>,
522
+ create: (member: Key) => T,
523
+ ): Record<Key, T>;
524
+ export function enumRecord(
525
+ members: Readonly<Record<string, number | string>>,
526
+ create: (member: number) => unknown,
527
+ ): Record<number, unknown> {
528
+ return Object.fromEntries(
529
+ Object.values(members)
530
+ // A numeric enum also maps each value back to its name.
531
+ .filter((member) => typeof member === "number")
532
+ .map((member) => [member, create(member)]),
533
+ );
534
+ }
package/types/clock.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import type { DINT } from "./index.d.ts";
2
2
 
3
- /** Milliseconds since the PLC runtime started. It wraps after 24.8 days, so compare times by subtracting: `now() - since >= 500`. */
3
+ /**
4
+ * The scan's clock: milliseconds since the PLC runtime started, read once when the scan began, so
5
+ * every call during one scan returns the same value. It wraps after 24.8 days, so compare times by
6
+ * subtracting: `now() - since >= 500`.
7
+ */
4
8
  export declare function now(): DINT;