@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.
- package/README.md +5 -0
- package/dist/interpreter/strings.d.ts +21 -0
- package/dist/interpreter/strings.js +191 -0
- package/dist/interpreter/types.d.ts +2 -0
- package/dist/interpreter/unicode-data.d.ts +4 -0
- package/dist/interpreter/unicode-data.js +1673 -0
- package/dist/interpreter/unicode.d.ts +3 -0
- package/dist/interpreter/unicode.js +35 -0
- package/dist/interpreter/v1/actor-identity.d.ts +3 -0
- package/dist/interpreter/v1/actor-identity.js +7 -0
- package/dist/interpreter/v1/actor-waits.d.ts +6 -0
- package/dist/interpreter/v1/actor-waits.js +33 -0
- package/dist/interpreter/v1/codecs.js +6 -9
- package/dist/interpreter/v1/exec.js +1336 -320
- package/dist/interpreter/v1/package.d.ts +39 -4
- package/dist/interpreter/v1/pipes.d.ts +1 -0
- package/dist/interpreter/v1/pipes.js +9 -6
- package/dist/interpreter/v1/scheduler.d.ts +3 -0
- package/dist/interpreter/v1/scheduler.js +18 -8
- package/dist/interpreter/v1/shims.d.ts +10 -0
- package/dist/interpreter/v1/shims.js +226 -34
- package/dist/interpreter/v1/validate.js +103 -7
- package/dist/interpreter/v1/value-operations.d.ts +5 -2
- package/dist/interpreter/v1/value-operations.js +57 -12
- package/dist/interpreter/values.d.ts +26 -8
- package/dist/interpreter/values.js +25 -5
- package/package.json +4 -4
|
@@ -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,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,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
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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 = {
|