@hew-lang/sandbox-vm 0.6.1 → 0.6.2

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.
@@ -0,0 +1,3 @@
1
+ /** The native Unicode operations, independent of the JavaScript host's version. */
2
+ export declare function charProperty(value: string, bit: number): boolean;
3
+ export declare function charCase(value: string, kind: "upper" | "lower" | "title"): string;
@@ -0,0 +1,35 @@
1
+ import { CATEGORY_RANGES, UPPER_MAPPING, LOWER_MAPPING, TITLE_MAPPING, } from "./unicode-data.js";
2
+ /** The native Unicode operations, independent of the JavaScript host's version. */
3
+ export function charProperty(value, bit) {
4
+ const scalar = value.codePointAt(0);
5
+ let low = 0, high = CATEGORY_RANGES.length / 3;
6
+ while (low < high) {
7
+ const middle = Math.floor((low + high) / 2);
8
+ if (CATEGORY_RANGES[middle * 3 + 1] < scalar)
9
+ low = middle + 1;
10
+ else
11
+ high = middle;
12
+ }
13
+ return (low * 3 < CATEGORY_RANGES.length &&
14
+ CATEGORY_RANGES[low * 3] <= scalar &&
15
+ (CATEGORY_RANGES[low * 3 + 2] & (1 << bit)) !== 0);
16
+ }
17
+ export function charCase(value, kind) {
18
+ const table = kind === "upper"
19
+ ? UPPER_MAPPING
20
+ : kind === "lower"
21
+ ? LOWER_MAPPING
22
+ : TITLE_MAPPING;
23
+ const scalar = value.codePointAt(0);
24
+ let low = 0, high = table.length / 2;
25
+ while (low < high) {
26
+ const middle = Math.floor((low + high) / 2);
27
+ if (table[middle * 2] < scalar)
28
+ low = middle + 1;
29
+ else
30
+ high = middle;
31
+ }
32
+ return table[low * 2] === scalar
33
+ ? String.fromCodePoint(table[low * 2 + 1])
34
+ : value;
35
+ }
@@ -0,0 +1,3 @@
1
+ import type { VmValue } from "../values.js";
2
+ /** Role handles retain their own identity independently of their occupant. */
3
+ export declare function actorIdentical(left: VmValue | undefined, right: VmValue | undefined): boolean;
@@ -0,0 +1,7 @@
1
+ /** Role handles retain their own identity independently of their occupant. */
2
+ export function actorIdentical(left, right) {
3
+ if ((left?.kind !== "actor" && left?.kind !== "supervisor") ||
4
+ (right?.kind !== "actor" && right?.kind !== "supervisor"))
5
+ throw new Error("actor identity requires actor or supervisor handles");
6
+ return left.kind === right.kind && left.id === right.id;
7
+ }
@@ -0,0 +1,6 @@
1
+ /** Pending strict actor turns. Keys identify incarnations, never role handles. */
2
+ export declare class ActorWaits<T> {
3
+ private readonly edges;
4
+ ready(owner: T): void;
5
+ pending(owner: T, targets: readonly T[]): T[] | null;
6
+ }
@@ -0,0 +1,33 @@
1
+ /** Pending strict actor turns. Keys identify incarnations, never role handles. */
2
+ export class ActorWaits {
3
+ edges = new Map();
4
+ ready(owner) {
5
+ this.edges.delete(owner);
6
+ }
7
+ pending(owner, targets) {
8
+ this.edges.set(owner, targets);
9
+ const blocked = new Set([...this.edges]
10
+ .filter(([, targets]) => targets.length > 0)
11
+ .map(([owner]) => owner));
12
+ for (;;) {
13
+ const escaped = [...blocked].filter((actor) => this.edges.get(actor).some((target) => !blocked.has(target)));
14
+ if (escaped.length === 0)
15
+ break;
16
+ for (const actor of escaped)
17
+ blocked.delete(actor);
18
+ }
19
+ if (!blocked.has(owner))
20
+ return null;
21
+ const path = [];
22
+ const seen = new Set();
23
+ let next = owner;
24
+ while (!seen.has(next)) {
25
+ seen.add(next);
26
+ path.push(next);
27
+ next = this.edges.get(next)[0];
28
+ }
29
+ path.push(next);
30
+ this.ready(owner);
31
+ return path;
32
+ }
33
+ }
@@ -1,4 +1,4 @@
1
- import { UNIT } from "../values.js";
1
+ import { UNIT, stringValue } from "../values.js";
2
2
  import { runtimeTag } from "./package.js";
3
3
  import { collectionOperation } from "./value-operations.js";
4
4
  class DecodeFailure extends Error {
@@ -102,7 +102,7 @@ function* fromBridge(pkg, shape, id, value, context) {
102
102
  if (node === "Bool")
103
103
  return { kind: "bool", value: Boolean(value) };
104
104
  if (node === "Char" || node === "String")
105
- return { kind: "string", value: String(value) };
105
+ return stringValue(String(value));
106
106
  if (node === "Bytes")
107
107
  return {
108
108
  kind: "vector",
@@ -216,13 +216,10 @@ export function* executeCodec(pkg, term, input, bridge, propertyInput) {
216
216
  elementType: "u8",
217
217
  items: bytes.map((byte) => ({ kind: "i64", value: BigInt(byte) })),
218
218
  }
219
- : {
220
- kind: "string",
221
- value: new TextDecoder("utf-8", {
222
- fatal: true,
223
- ignoreBOM: true,
224
- }).decode(new Uint8Array(bytes)),
225
- };
219
+ : stringValue(new TextDecoder("utf-8", {
220
+ fatal: true,
221
+ ignoreBOM: true,
222
+ }).decode(new Uint8Array(bytes)));
226
223
  }
227
224
  const root = result.ok ? shape.root : term.decoded.error_root;
228
225
  const context = {