hclang 0.47.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.
@@ -1,8 +1,6 @@
1
1
  import { Frame, FrameCount, FrameString, FrameSymbol, } from "../frames.js";
2
2
  // Installs the Demi class that `.####` constructs (011.20).
3
3
  import "./demi-prologue.js";
4
- // Installs the Denum class that the ranked hash `.#n` constructs (007.32).
5
- import "./denum-prologue.js";
6
4
  // Installs the RotorRouter class that list division answers (007.27c).
7
5
  import "./router-prologue.js";
8
6
  import { EvalPipe, makeSourcePipe } from "./eval-pipe.js";
@@ -373,7 +373,7 @@ export class FrameArray extends FrameList {
373
373
  /** A declared Count, Size or residual first; the list's own rule otherwise. */
374
374
  sizeFor(key) {
375
375
  const failure = this.observationError();
376
- if (failure && Frame.isSizeOperator(key))
376
+ if (failure && Frame.SIZE_OPERATORS.includes(key))
377
377
  return failure;
378
378
  return this.declaredObservation(key) ?? super.sizeFor(key);
379
379
  }
@@ -177,7 +177,7 @@ export class FrameExpr extends FrameList {
177
177
  continue;
178
178
  }
179
179
  if (index === 0 && value.isSymbol() && value.is.address &&
180
- Frame.isSizeOperator(value.spelling())) {
180
+ Frame.SIZE_OPERATORS.includes(value.spelling())) {
181
181
  sum = value;
182
182
  continue;
183
183
  }
@@ -185,7 +185,7 @@ export class FrameExpr extends FrameList {
185
185
  // is not a receiver, so a leading .## remains an address (#411).
186
186
  if (index > 0 && sum.is.void && value.isSymbol() &&
187
187
  value.is.address &&
188
- Frame.isSizeOperator(value.spelling())) {
188
+ Frame.SIZE_OPERATORS.includes(value.spelling())) {
189
189
  sum = value.called_by(sum);
190
190
  continue;
191
191
  }
@@ -553,7 +553,7 @@ export class FrameScoped extends Frame {
553
553
  /** Sizes as its term does, `.#`, `.##` and `.###`; anything else is applied. */
554
554
  call(argument, parameter = Frame.nil) {
555
555
  if (argument.isSymbol() && argument.is.address === true &&
556
- Frame.isSizeOperator(argument.spelling())) {
556
+ Frame.SIZE_OPERATORS.includes(argument.spelling())) {
557
557
  return this.sizeFor(argument.spelling());
558
558
  }
559
559
  return this.live().call(argument, parameter);
@@ -159,7 +159,7 @@ export class FrameLazy extends FrameExpr {
159
159
  */
160
160
  sizeOperator(argument) {
161
161
  if (argument instanceof FrameSymbol && argument.is.address === true &&
162
- Frame.isSizeOperator(argument.spelling())) {
162
+ Frame.SIZE_OPERATORS.includes(argument.spelling())) {
163
163
  return this.sizeFor(argument.spelling());
164
164
  }
165
165
  return undefined;
@@ -145,7 +145,7 @@ export class FrameList extends Frame {
145
145
  /** Immediate count is unchanged; Size and residual share native child sizes. */
146
146
  sizeFor(key) {
147
147
  const failure = this.observationError();
148
- if (failure && Frame.isSizeOperator(key))
148
+ if (failure && Frame.SIZE_OPERATORS.includes(key))
149
149
  return failure;
150
150
  if (key === Frame.kCOUNT) {
151
151
  const elements = this.sizeElements();
@@ -32,14 +32,6 @@ const recognizeName = (symbol, source = "") => {
32
32
  if (Frame.SIZE_OPERATORS.includes(source + char)) {
33
33
  return { disposition: ScanDisposition.Consume };
34
34
  }
35
- // A single hash followed by decimal digits is the ranked hash `.#n`
36
- // (occurrence/figure 007.32). Only the lone `#` takes digits: `.##2` is
37
- // `.##` and then the count 2, as before, and `.#2x` is `.#2` then `x`.
38
- // The spelling is canonical decimal, one name per rung: a zero ends the name,
39
- // so `.#05` is `.#0` and then the number 5.
40
- if (/^#(|[1-9][0-9]*)$/.test(source) && /^[0-9]$/.test(char)) {
41
- return { disposition: ScanDisposition.Consume };
42
- }
43
35
  if (source.startsWith(Frame.kCOUNT)) {
44
36
  return { disposition: ScanDisposition.CompleteRedispatch };
45
37
  }
@@ -289,7 +289,7 @@ export class FrameSymbol extends FrameAtom {
289
289
  // A size operator answers for the receiver itself rather than looking a
290
290
  // name up, so the scope a value was read from never answers for it (#411).
291
291
  // Only an address is one, since the lexer looks `#` up as the comment.
292
- if (this.is.address === true && Frame.isSizeOperator(this.data)) {
292
+ if (this.is.address === true && Frame.SIZE_OPERATORS.includes(this.data)) {
293
293
  return context.referent().sizeFor(this.data);
294
294
  }
295
295
  // A dotted arithmetic operator is the operator itself: `xs ./ 3` is
@@ -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 { installDenumConstructors, 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.47.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.47.0",
3
+ "version": "0.48.0",
4
4
  "description": "Homoiconic C command-line interpreter and REPL",
5
5
  "keywords": [
6
6
  "language",
@@ -1,117 +0,0 @@
1
- /**
2
- * The Denum class, loaded from HC for the ranked hash.
3
- *
4
- * `x.#n` answers a Denum, and the only public constructor is the HC class
5
- * `Denum` in `hc/denum.hc` (occurrence/figure 007.32, 007.36). The CD algebra
6
- * is a view derived by `d.cd ()`, not a second constructor. The frames package
7
- * derives the state natively but cannot run HC, so this module installs what
8
- * it calls (`installDenumConstructors`), exactly as `demi-prologue.ts` does for
9
- * `.####`. The `Denum` constructor builds every answer; the internal view
10
- * derivation `view-of` is installed only so a view source can be recognized
11
- * and refused. It is not a constructor of retained state and is never
12
- * exported.
13
- *
14
- * The class is read from the compiled-in bundle, not through a resource root,
15
- * so `.#n` works in a bare `evaluate`, which has no root and imports nothing.
16
- * The file is evaluated the first time a Denum is constructed, once per
17
- * process: its example lines are dropped and the first failure fails the whole.
18
- * It runs in a namespace of its own, with no host bindings and no root, so it
19
- * can read nothing but the global operators, among them the pure
20
- * `denum-engine`, and nothing a program declares can reach it. Its outcome is
21
- * kept, failure included, so it is never evaluated twice. A Denum requested
22
- * while the file is still loading is `$!.denum-prologue-reentrant`.
23
- *
24
- * @module
25
- */
26
- import { EvaluationScope, Frame, FrameArray, FrameCount, FrameExpr, installDenumConstructors, } from "../frames.js";
27
- import { HC_SOURCES } from "../bundle/hc-sources.js";
28
- import { evaluateSourceText } from "./resource-import.js";
29
- /** The bundled file that defines the class. */
30
- export const DENUM_SOURCE = "hc/denum.hc";
31
- /** The name the file declares its one public constructor under. */
32
- export const DENUM_CLASS = "Denum";
33
- /** The internal view derivation: `view-of d` is `d.cd ()`. Not a constructor. */
34
- export const VIEW_FACTORY = "view-of";
35
- let loaded;
36
- let loading = false;
37
- const failed = (frame) => frame.isFailedResult() || frame.observationError() !== undefined;
38
- /**
39
- * Evaluates class source in a namespace of its own, answering its `Denum`
40
- * constructor and `view-of` derivation or the failure. Uncached: `denumClasses` keeps the one
41
- * result the process uses.
42
- *
43
- * @param source The source text, or undefined when the bundle lacks it.
44
- * @returns The `Denum` constructor and the view derivation, or an error.
45
- */
46
- export function loadDenumClasses(source) {
47
- if (source === undefined) {
48
- return Frame.error(`$!.denum-prologue-missing ${DENUM_SOURCE}`);
49
- }
50
- const namespace = new FrameArray([]);
51
- const result = evaluateSourceText(source, EvaluationScope.root(namespace));
52
- if (failed(result))
53
- return result;
54
- const denum = namespace.getOwn(DENUM_CLASS);
55
- if (denum.is.missing) {
56
- return Frame.error(`$!.denum-prologue-missing ${DENUM_CLASS}`);
57
- }
58
- const view = namespace.getOwn(VIEW_FACTORY);
59
- if (view.is.missing) {
60
- return Frame.error(`$!.denum-prologue-missing ${VIEW_FACTORY}`);
61
- }
62
- return { denum, view };
63
- }
64
- /**
65
- * The `Denum` constructor and `view-of` closures, evaluated from the bundle on
66
- * first use.
67
- *
68
- * @returns The closures, or the error that loading them answered.
69
- */
70
- export function denumClasses() {
71
- if (loaded)
72
- return loaded;
73
- if (loading)
74
- return Frame.error("$!.denum-prologue-reentrant");
75
- loading = true;
76
- try {
77
- loaded = loadDenumClasses(HC_SOURCES.get(DENUM_SOURCE));
78
- }
79
- finally {
80
- loading = false;
81
- }
82
- return loaded;
83
- }
84
- const stateArgument = (state) => new FrameArray([
85
- new FrameCount(state.count),
86
- new FrameArray(state.loads.map((load) => new FrameCount(load))),
87
- ]);
88
- /**
89
- * Constructs a Denum with the HC class: `Denum [count, loads]`.
90
- *
91
- * @param state The Count and loads, already admissible.
92
- * @returns The new instance, or the class's failure.
93
- */
94
- export function constructDenum(state) {
95
- const classes = denumClasses();
96
- if (classes instanceof Frame)
97
- return classes;
98
- return FrameExpr.answeredValue(classes.denum.call(stateArgument(state)))
99
- .referent();
100
- }
101
- /**
102
- * Derives the CD view of the Denum the state builds, as `d.cd ()` does. Only
103
- * the ranked hash's recognition of a view source uses it.
104
- *
105
- * @param state The Count and loads, already admissible.
106
- * @returns The view instance, or the class's failure.
107
- */
108
- function deriveView(state) {
109
- const classes = denumClasses();
110
- if (classes instanceof Frame)
111
- return classes;
112
- const source = constructDenum(state);
113
- if (source.isFailedResult() || source.observationError())
114
- return source;
115
- return FrameExpr.answeredValue(classes.view.call(source)).referent();
116
- }
117
- installDenumConstructors({ denum: constructDenum, view: deriveView });
@@ -1,180 +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, promoteDenum, } from "./denum.js";
5
- let constructors;
6
- /**
7
- * Installs what `.#n` answers with and recognizes. The classes are HC, so the
8
- * frames package, which cannot run HC, takes them from the evaluator
9
- * (`lib/execute/denum-prologue.ts`), as `.####` takes its Demi. They are
10
- * installed as a pair: the Denum constructor builds every answer, and the view
11
- * derivation is used only to recognize a view source, which is refused.
12
- *
13
- * @param installed Both, called once per present observation.
14
- */
15
- export function installDenumConstructors(installed) {
16
- constructors = installed;
17
- }
18
- /** A Frame read as an exact nonnegative Count, or undefined. */
19
- function exactCount(frame) {
20
- const value = frame.referent();
21
- return value instanceof FrameCount && typeof value.data === "bigint" &&
22
- value.data >= 0n
23
- ? value.data
24
- : undefined;
25
- }
26
- /**
27
- * The stored state of a Denum instance: its own `count` and `loads` fields
28
- * (there is no stored rank). Only the instance's own fields are read (`get_here`), never a
29
- * declared parent or a method, and the loads are read as stored, so nothing
30
- * runs. Undefined when any field is absent or not an exact Count of the right
31
- * shape.
32
- */
33
- function storedState(host) {
34
- const count = exactCount(host.get_here("count"));
35
- const list = host.get_here("loads").referent();
36
- if (count === undefined)
37
- return undefined;
38
- if (!list.ownsIdentity())
39
- return undefined;
40
- const loads = list.elements().map(exactCount);
41
- if (loads.length === 0 || loads.some((load) => load === undefined)) {
42
- return undefined;
43
- }
44
- return { count, loads: loads };
45
- }
46
- /** True when `construct(state)` builds exactly `host` (same value and type). */
47
- function rebuilds(construct, state, host) {
48
- let candidate;
49
- try {
50
- candidate = construct(state);
51
- }
52
- catch (error) {
53
- if (error instanceof DenumError)
54
- return false;
55
- throw error;
56
- }
57
- if (candidate.isFailedResult() || candidate.observationError())
58
- return false;
59
- return candidate.typeEquals(host) === Frame.all;
60
- }
61
- /**
62
- * The intrinsic path, as `.####` has for a Demi. A source is a Denum (or a CD
63
- * view) exactly when its stored `count` and `loads` are a valid state and it is
64
- * `==` (same value and same type at every node, fields and methods included) to
65
- * the instance the shipped `Denum` constructor (or its `.cd ()` view) builds
66
- * from them. The answer is then built from that reconstruction, never from the
67
- * source: no observer, method or closure of the source runs, so a forged `#`,
68
- * `##` or `###` cannot steer it. A zero Count is therefore present, unlike a
69
- * host with no children. The arity decides nothing: a Denum with `2ⁿ` loads is
70
- * not a view, and a view is not rebuilt by the Denum constructor.
71
- *
72
- * @returns Which construction rebuilds the source, and its state; or undefined.
73
- */
74
- function intrinsicDenum(source) {
75
- if (!constructors)
76
- return undefined;
77
- const host = source.referent();
78
- if (!host.ownsIdentity())
79
- return undefined;
80
- const state = storedState(host);
81
- if (!state)
82
- return undefined;
83
- if (rebuilds(constructors.denum, state, host)) {
84
- return { kind: "denum", state };
85
- }
86
- if (rebuilds(constructors.view, state, host))
87
- return { kind: "view", state };
88
- return undefined;
89
- }
90
- /**
91
- * The ranked hash, `.#n` (occurrence/figure 007.32, 007.32b, 007.35b, 007.36):
92
- * a generic Denum of rung n, n from 0 to 5. It never answers a CD view, and
93
- * there is no `#n=`; the algebraic value is `d.coordinates ()` of a view
94
- * derived by `d.cd ()`.
95
- *
96
- * Three different cases answer it, and they are not the same:
97
- *
98
- * - **Construction from a host.** A host answers its Count C, Size s and
99
- * residual r only, so the Denum is built from those three observers with
100
- * the derivation of `.####` (`observeDemi`), at rank n (`fromHost`). A host
101
- * with no Count, or Count zero, has no Denum and answers nil, as it has no
102
- * Demi; rank 0 reads no residual. Failures are answered as they are, and
103
- * unusable observations are `$!.denum-count`, `$!.denum-observations` and
104
- * `$!.denum-coherence`.
105
- * - **Promotion of a Denum.** An instance of the shipped `Denum` class with a
106
- * shipped binary arity (1, 2, 4, 8, 16, 32) answers its own state under the
107
- * load-preserving embedding at rung n, keeping Count and every load, and
108
- * below its own derived rank `$!.denum-demotion`. The embedding is
109
- * structural: it does not invoke the CD interpretation, and the answer is a
110
- * Denum. A Denum of Count zero is present. Any other arity is
111
- * `$!.denum-unsupported-arity`: nothing is truncated, padded or read as
112
- * `2^rank`.
113
- * - **Refusal of a CD view.** A view derived by `d.cd ()` is never a source:
114
- * the answer is `$!.denum-view-source`, and it is not measured as a host from
115
- * its Count and Size either. Ask the Denum it views, `v.denum ()`.
116
- *
117
- * A multi-channel `RotorRouter` is not special-cased here as it is under
118
- * `.####` (`channelRouterDemi`): `.#n` reads only Count, Size and residual, so
119
- * `x.#1` equals `x.####` for ordinary and binary hosts, and for a router of
120
- * more than two channels is the binary projection while `.####` keeps its
121
- * channel Demi (pinned in `hc/denum.hc`).
122
- *
123
- * Nothing folds, executes or caches the source, and each observer is read at
124
- * most once. A rank above 5 is `$!.denum-rank`.
125
- *
126
- * @param source The observed Frame.
127
- * @param rank The rung n of `.#n`.
128
- * @returns A Denum, nil, or an error.
129
- */
130
- export function observeDenum(source, rank) {
131
- const failure = source.observationError();
132
- if (failure)
133
- return failure;
134
- if (!Number.isInteger(rank) || rank < 0 || rank > MAX_RANK) {
135
- return Frame.error("$!.denum-rank");
136
- }
137
- if (!constructors)
138
- return Frame.error("$!.denum-unavailable");
139
- const construct = constructors.denum;
140
- try {
141
- const intrinsic = intrinsicDenum(source);
142
- if (intrinsic?.kind === "view")
143
- return Frame.error("$!.denum-view-source");
144
- if (intrinsic)
145
- return construct(promoteDenum(intrinsic.state, rank));
146
- const n = source.sizeFor(Frame.kCOUNT);
147
- if (n.observationError())
148
- return n;
149
- if (n === Frame.nil)
150
- return Frame.nil; // no Count, no Denum
151
- if (!(n instanceof FrameCount) || typeof n.data !== "bigint" || n.data < 0n) {
152
- return Frame.error("$!.denum-count");
153
- }
154
- if (n.data === 0n)
155
- return Frame.nil;
156
- const s = source.sizeFor(Frame.kLEAVES);
157
- if (s.observationError())
158
- return s;
159
- if (!(s instanceof FrameCount) || typeof s.data !== "bigint") {
160
- return Frame.error("$!.denum-observations");
161
- }
162
- if (rank === 0)
163
- return construct(fromHost(0, n.data, s.data, 0n));
164
- const r = source.sizeFor(Frame.kRESIDUAL);
165
- if (r.observationError())
166
- return r;
167
- if (r === Frame.nil)
168
- return Frame.nil;
169
- if (!(r instanceof FrameInt) || typeof r.data !== "bigint") {
170
- return Frame.error("$!.denum-observations");
171
- }
172
- return construct(fromHost(rank, n.data, s.data, r.data));
173
- }
174
- catch (error) {
175
- if (error instanceof DenumError)
176
- return Frame.error(error.kind);
177
- throw error;
178
- }
179
- }
180
- Frame.denum = observeDenum;