hclang 0.46.0 → 0.48.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.
@@ -452,17 +452,6 @@ export function inspectFlags(flags) {
452
452
  * manipulating and interacting with frames.
453
453
  */
454
454
  export class Frame extends MetaFrame {
455
- /**
456
- * Whether `key` names an observer a Frame answers for itself: one of the four
457
- * fixed hashes `#`, `##`, `###`, `####`, or a ranked hash `#n`.
458
- */
459
- static isSizeOperator(key) {
460
- return Frame.SIZE_OPERATORS.includes(key) || Frame.RANKED_HASH.test(key);
461
- }
462
- /** The rung n of a ranked hash `#n`, or undefined for any other key. */
463
- static hashRank(key) {
464
- return Frame.RANKED_HASH.test(key) ? Number(key.slice(1)) : undefined;
465
- }
466
455
  /** Creates a runtime error value without coupling MetaFrame to FrameNote. */
467
456
  static error(source) {
468
457
  const error = new (class extends Frame {
@@ -735,7 +724,7 @@ export class Frame extends MetaFrame {
735
724
  * Nil has no Count, so no residual or Demi.
736
725
  */
737
726
  sizeFor(key) {
738
- if (!Frame.isSizeOperator(key))
727
+ if (!Frame.SIZE_OPERATORS.includes(key))
739
728
  return Frame.nil;
740
729
  const failure = this.observationError();
741
730
  if (failure)
@@ -762,10 +751,8 @@ export class Frame extends MetaFrame {
762
751
  }
763
752
  case Frame.kDEMI:
764
753
  return Frame.demi(this);
765
- default: {
766
- const rank = Frame.hashRank(key);
767
- return rank === undefined ? Frame.nil : Frame.denum(this, rank);
768
- }
754
+ default:
755
+ return Frame.nil;
769
756
  }
770
757
  }
771
758
  /** Nonnegative represented quantity; path tracks recursive containment only. */
@@ -1083,7 +1070,7 @@ export class Frame extends MetaFrame {
1083
1070
  return undefined;
1084
1071
  }
1085
1072
  const key = argument.spelling();
1086
- return Frame.isSizeOperator(key) ? key : undefined;
1073
+ return Frame.SIZE_OPERATORS.includes(key) ? key : undefined;
1087
1074
  }
1088
1075
  /**
1089
1076
  * Negation is decided by the symbol's name, never by how it prints.
@@ -1168,19 +1155,6 @@ Object.defineProperty(Frame, "SIZE_OPERATORS", {
1168
1155
  Frame.kDEMI,
1169
1156
  ]
1170
1157
  });
1171
- /**
1172
- * The ranked hash `.#n` (occurrence/figure 007.32): `#` and decimal digits,
1173
- * as `.#2`, in canonical decimal (no leading zero, so each rung has one
1174
- * spelling). Its n is the Cayley–Dickson rung and not a hash count, so it is
1175
- * not one of {@link SIZE_OPERATORS}, whose spellings are the four fixed
1176
- * hashes. Bare `.#` stays the Count.
1177
- */
1178
- Object.defineProperty(Frame, "RANKED_HASH", {
1179
- enumerable: true,
1180
- configurable: true,
1181
- writable: true,
1182
- value: /^#(0|[1-9][0-9]*)$/
1183
- });
1184
1158
  /**
1185
1159
  * BEGIN_EXPR is the symbol for the beginning of an expression.
1186
1160
  */
package/esm/lib/frames.js CHANGED
@@ -28,8 +28,6 @@ export { FrameNumeric, NUMERIC_RANK, } from "./frames/frame-numeric.js";
28
28
  export { FrameInt } from "./frames/frame-int.js";
29
29
  export { FrameCount } from "./frames/frame-count.js";
30
30
  export { installDemiConstructor, installRouterRecognizer, observeDemi, } from "./frames/fourth-hash.js";
31
- export { installDenumConstructor, observeDenum, } from "./frames/denum-hash.js";
32
- export * as denum from "./frames/denum.js";
33
31
  export { FrameDecimal } from "./frames/frame-decimal.js";
34
32
  export { FrameSequence } from "./frames/frame-sequence.js";
35
33
  export { FrameTypedNumber } from "./frames/frame-typed-number.js";
package/esm/lib/ops.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { IfElse, IfThen } from "./ops/conditionals.js";
2
- import { DenumEngine } from "./ops/denum.js";
3
2
  import { FrameOps } from "./ops/frame-ops.js";
4
3
  import { MapElements, MapMembers, ReduceElements, ReduceMembers, SpliceElements, } from "./ops/iterators.js";
5
4
  import { Add, Divide, Equals, GreaterThan, GreaterThanOrEqual, Identical, LessThan, LessThanOrEqual, Modulo, Multiply, Power, Subtract, TypeEquals, } from "./ops/math.js";
@@ -35,6 +34,4 @@ export const Ops = new FrameOps({
35
34
  "^": BindType,
36
35
  "^^": BindReturn,
37
36
  "->": Arrow,
38
- // The one native seam under `hc/denum.hc`: pure Cayley–Dickson arithmetic.
39
- "denum-engine": DenumEngine,
40
37
  });
@@ -1 +1 @@
1
- export const VERSION = "0.46.0";
1
+ export const VERSION = "0.48.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hclang",
3
- "version": "0.46.0",
3
+ "version": "0.48.0",
4
4
  "description": "Homoiconic C command-line interpreter and REPL",
5
5
  "keywords": [
6
6
  "language",
@@ -1,88 +0,0 @@
1
- /**
2
- * The Denum class, loaded from HC for the ranked hash.
3
- *
4
- * `x.#n` answers a Denum, and a Denum is an HC class, `Denum` in
5
- * `hc/denum.hc` (occurrence/figure 007.32). The frames package derives the
6
- * state natively but cannot run HC, so this module installs the constructor it
7
- * calls (`installDenumConstructor`), exactly as `demi-prologue.ts` does for
8
- * `.####`.
9
- *
10
- * The class is read from the compiled-in bundle, not through a resource root,
11
- * so `.#n` works in a bare `evaluate`, which has no root and imports nothing.
12
- * The file is evaluated the first time a Denum is constructed, once per
13
- * process: its example lines are dropped and the first failure fails the whole.
14
- * It runs in a namespace of its own, with no host bindings and no root, so it
15
- * can read nothing but the global operators, among them the pure
16
- * `denum-engine`, and nothing a program declares can reach it. Its outcome is
17
- * kept, failure included, so it is never evaluated twice. A Denum requested
18
- * while the file is still loading is `$!.denum-prologue-reentrant`.
19
- *
20
- * @module
21
- */
22
- import { EvaluationScope, Frame, FrameArray, FrameCount, FrameExpr, installDenumConstructor, } from "../frames.js";
23
- import { HC_SOURCES } from "../bundle/hc-sources.js";
24
- import { evaluateSourceText } from "./resource-import.js";
25
- /** The bundled file that defines the class. */
26
- export const DENUM_SOURCE = "hc/denum.hc";
27
- /** The name the file declares the constructor under. */
28
- export const DENUM_CLASS = "Denum";
29
- let loaded;
30
- let loading = false;
31
- /**
32
- * Evaluates class source in a namespace of its own, answering its `Denum` or
33
- * the failure. Uncached: `denumClass` keeps the one result the process uses.
34
- *
35
- * @param source The source text, or undefined when the bundle lacks it.
36
- * @returns The constructor, or an error.
37
- */
38
- export function loadDenumClass(source) {
39
- if (source === undefined) {
40
- return Frame.error(`$!.denum-prologue-missing ${DENUM_SOURCE}`);
41
- }
42
- const namespace = new FrameArray([]);
43
- const result = evaluateSourceText(source, EvaluationScope.root(namespace));
44
- if (result.isFailedResult() || result.observationError())
45
- return result;
46
- const constructor = namespace.getOwn(DENUM_CLASS);
47
- return constructor.is.missing
48
- ? Frame.error(`$!.denum-prologue-missing ${DENUM_CLASS}`)
49
- : constructor;
50
- }
51
- /**
52
- * The `Denum` constructor closure, evaluated from the bundle on first use.
53
- *
54
- * @returns The constructor, or the error that loading it answered.
55
- */
56
- export function denumClass() {
57
- if (loaded)
58
- return loaded;
59
- if (loading)
60
- return Frame.error("$!.denum-prologue-reentrant");
61
- loading = true;
62
- try {
63
- loaded = loadDenumClass(HC_SOURCES.get(DENUM_SOURCE));
64
- }
65
- finally {
66
- loading = false;
67
- }
68
- return loaded;
69
- }
70
- /**
71
- * Constructs a Denum with the HC class: `Denum [rank, count, loads]`.
72
- *
73
- * @param state The rank, Count and loads, already admissible.
74
- * @returns The new instance, or the class's failure.
75
- */
76
- export function constructDenum(state) {
77
- const constructor = denumClass();
78
- if (constructor.isFailedResult() || constructor.observationError()) {
79
- return constructor;
80
- }
81
- const argument = new FrameArray([
82
- new FrameCount(BigInt(state.rank)),
83
- new FrameCount(state.count),
84
- new FrameArray(state.loads.map((load) => new FrameCount(load))),
85
- ]);
86
- return FrameExpr.answeredValue(constructor.call(argument)).referent();
87
- }
88
- installDenumConstructor(constructDenum);
@@ -1,166 +0,0 @@
1
- import { Frame } from "./frame.js";
2
- import { FrameCount } from "./frame-count.js";
3
- import { FrameInt } from "./frame-int.js";
4
- import { DenumError, fromHost, MAX_RANK, promote, } from "./denum.js";
5
- let construct;
6
- /**
7
- * Installs what `.#n` answers a present Denum with. The Denum is an HC class,
8
- * so the frames package, which cannot run HC, takes its constructor from the
9
- * evaluator (`lib/execute/denum-prologue.ts`), as `.####` takes its Demi.
10
- *
11
- * @param constructor The constructor, called once per present observation.
12
- */
13
- export function installDenumConstructor(constructor) {
14
- construct = constructor;
15
- }
16
- /** A Frame read as an exact nonnegative Count, or undefined. */
17
- function exactCount(frame) {
18
- const value = frame.referent();
19
- return value instanceof FrameCount && typeof value.data === "bigint" &&
20
- value.data >= 0n
21
- ? value.data
22
- : undefined;
23
- }
24
- /**
25
- * The stored state of a Denum instance: its own `rank`, `count` and `loads`
26
- * fields. Only the instance's own fields are read (`get_here`), never a
27
- * declared parent or a method, and the loads are read as stored, so nothing
28
- * runs. Undefined when any field is absent or not an exact Count of the right
29
- * shape.
30
- */
31
- function storedState(host) {
32
- const rank = exactCount(host.get_here("rank"));
33
- const count = exactCount(host.get_here("count"));
34
- const list = host.get_here("loads").referent();
35
- if (rank === undefined || count === undefined || rank > BigInt(MAX_RANK)) {
36
- return undefined;
37
- }
38
- if (!list.ownsIdentity())
39
- return undefined;
40
- const loads = list.elements().map(exactCount);
41
- if (loads.some((load) => load === undefined))
42
- return undefined;
43
- try {
44
- return {
45
- rank: Number(rank),
46
- count,
47
- loads: loads,
48
- };
49
- }
50
- catch {
51
- return undefined;
52
- }
53
- }
54
- /**
55
- * The intrinsic path, as `.####` has for a Demi. A source is a Denum exactly
56
- * when its stored `rank`, `count` and `loads` are a valid state and it is `==`
57
- * (same value and same type at every node, fields and methods included) to the
58
- * Denum the shipped constructor builds from them. The answer is then built
59
- * from that reconstruction, never from the source: no observer, method or
60
- * closure of the source runs, so a forged `#`, `##` or `###` cannot steer it.
61
- * A Denum of Count zero is therefore present, unlike a host with no children.
62
- *
63
- * @returns The source's reconstruction as a state, or undefined.
64
- */
65
- function intrinsicDenum(source) {
66
- if (!construct)
67
- return undefined;
68
- const host = source.referent();
69
- if (!host.ownsIdentity())
70
- return undefined;
71
- const state = storedState(host);
72
- if (!state)
73
- return undefined;
74
- let candidate;
75
- try {
76
- candidate = construct(state);
77
- }
78
- catch (error) {
79
- if (error instanceof DenumError)
80
- return undefined;
81
- throw error;
82
- }
83
- if (candidate.isFailedResult() || candidate.observationError()) {
84
- return undefined;
85
- }
86
- return candidate.typeEquals(host) === Frame.all ? state : undefined;
87
- }
88
- /**
89
- * The ranked hash, `.#n` (occurrence/figure 007.32, 007.32b): the Denum of
90
- * rung n, n from 0 to 5. There is no `#n=`, and a Denum is not a scalar
91
- * observation; the algebraic value is `d.coordinates ()`.
92
- *
93
- * Two different operations answer it, and they are not the same:
94
- *
95
- * - **Construction from a host.** A host answers its Count C, Size s and
96
- * residual r only, so the Denum is built from those three observers with
97
- * the derivation of `.####` (`observeDemi`), at rank n (`fromHost`). A host
98
- * with no Count, or Count zero, has no Denum and answers nil, as it has no
99
- * Demi; rank 0 reads no residual. Failures are answered as they are, and
100
- * unusable observations are `$!.denum-count`, `$!.denum-observations` and
101
- * `$!.denum-coherence`.
102
- * - **Promotion of a Denum.** An instance of the shipped class answers its own
103
- * state promoted to rank n, keeping Count and every load, and below its own
104
- * rank `$!.denum-demotion`. A Denum of Count zero is present.
105
- *
106
- * A multi-channel `RotorRouter` is not special-cased here as it is under
107
- * `.####` (`channelRouterDemi`): `.#n` reads only Count, Size and residual, so
108
- * `x.#1` equals `x.####` for ordinary and binary hosts, and for a router of
109
- * more than two channels is the binary projection while `.####` keeps its
110
- * channel Demi (pinned in `hc/denum.hc`).
111
- *
112
- * Nothing folds, executes or caches the source, and each observer is read at
113
- * most once. A rank above 5 is `$!.denum-rank`.
114
- *
115
- * @param source The observed Frame.
116
- * @param rank The rung n of `.#n`.
117
- * @returns A Denum, nil, or an error.
118
- */
119
- export function observeDenum(source, rank) {
120
- const failure = source.observationError();
121
- if (failure)
122
- return failure;
123
- if (!Number.isInteger(rank) || rank < 0 || rank > MAX_RANK) {
124
- return Frame.error("$!.denum-rank");
125
- }
126
- if (!construct)
127
- return Frame.error("$!.denum-unavailable");
128
- try {
129
- const intrinsic = intrinsicDenum(source);
130
- if (intrinsic)
131
- return construct(promote(intrinsic, rank));
132
- const n = source.sizeFor(Frame.kCOUNT);
133
- if (n.observationError())
134
- return n;
135
- if (n === Frame.nil)
136
- return Frame.nil; // no Count, no Denum
137
- if (!(n instanceof FrameCount) || typeof n.data !== "bigint" || n.data < 0n) {
138
- return Frame.error("$!.denum-count");
139
- }
140
- if (n.data === 0n)
141
- return Frame.nil;
142
- const s = source.sizeFor(Frame.kLEAVES);
143
- if (s.observationError())
144
- return s;
145
- if (!(s instanceof FrameCount) || typeof s.data !== "bigint") {
146
- return Frame.error("$!.denum-observations");
147
- }
148
- if (rank === 0)
149
- return construct(fromHost(0, n.data, s.data, 0n));
150
- const r = source.sizeFor(Frame.kRESIDUAL);
151
- if (r.observationError())
152
- return r;
153
- if (r === Frame.nil)
154
- return Frame.nil;
155
- if (!(r instanceof FrameInt) || typeof r.data !== "bigint") {
156
- return Frame.error("$!.denum-observations");
157
- }
158
- return construct(fromHost(rank, n.data, s.data, r.data));
159
- }
160
- catch (error) {
161
- if (error instanceof DenumError)
162
- return Frame.error(error.kind);
163
- throw error;
164
- }
165
- }
166
- Frame.denum = observeDenum;