@scriptc/runtime 0.0.11 → 0.0.13

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/src/scr_dc.c CHANGED
@@ -1,13 +1,13 @@
1
1
  /* node:diagnostics_channel — the in-process pub/sub core (scr_runtime.h
2
2
  * has the API contract). Linked only when the IR carries dc.* libCalls
3
- * (cc.ts; the zlib gating precedent), pure data structure over the DOM
3
+ * (cc.ts; the zlib gating precedent), pure data structure over the checked-dynamic tree
4
4
  * no loop hooks, no platform seams, cross-compiles everywhere.
5
5
  *
6
6
  * - The registry is process-global and append-only (Node's channels are
7
7
  * process-lived too — its WeakRefMap only collects channels nothing
8
8
  * references, which a compiled program cannot observe). Handles are
9
9
  * 1-based indexes so a zeroed f64 can never alias channel 0.
10
- * - Subscribers are DOM FUNCTION values. unsubscribe matches by the
10
+ * - Subscribers are dyn FUNCTION values. unsubscribe matches by the
11
11
  * UNDERLYING closure when both sides are functions (boxing one function
12
12
  * twice yields distinct ScrDyn nodes sharing one ScrClosure, and JS has
13
13
  * ONE function object), falling back to node identity.
@@ -98,7 +98,7 @@ static ScrDcChannel *dc_of(double handle) {
98
98
  }
99
99
 
100
100
  /* Node's ERR_INVALID_ARG_TYPE for a non-function subscriber — the
101
- * "Received ..." tail covers the DOM kinds (determineSpecificType lite;
101
+ * "Received ..." tail covers the dyn kinds (determineSpecificType lite;
102
102
  * scr_dyn_handle.c's full renderer is not linked here). */
103
103
  static void dc_throw_bad_fn_arg(const ScrDyn *cb, const char *arg_name) {
104
104
  const char *received = "an instance of Object";
@@ -341,7 +341,7 @@ ScrDyn *scr_dc_chan_run_stores(double handle, ScrDyn *data, ScrDyn *fn, ScrDyn *
341
341
  /* ── TracingChannel ────────────────────────────────────────────────────
342
342
  * A registry entry of five channel indexes (start/end/asyncStart/asyncEnd/
343
343
  * error), handled as a 1-based f64 like Channel. The trace choreography
344
- * lives here in C over the DOM: publishes stash the pending traced-call /
344
+ * lives here in C over the checked-dynamic tree: publishes stash the pending traced-call /
345
345
  * subscriber exception in a ScrCaught box first (compiled subscriber
346
346
  * bodies run with a CLEAR cell — a pending flag would unwind them at
347
347
  * their first call) and re-raise after, so throws propagate exactly like
@@ -468,8 +468,8 @@ bool scr_dc_tc_unsubscribe(double h, ScrDyn *handlers) {
468
468
  return done;
469
469
  }
470
470
 
471
- /* The pending exception as a DOM value for ctx.error: scr_caught_to_dyn
472
- * (scr_json.c) — identity-preserving for DOM payloads and %Error
471
+ /* The pending exception as a dyn value for ctx.error: scr_caught_to_dyn
472
+ * (scr_json.c) — identity-preserving for dyn payloads and %Error
473
473
  * instances (the identity-cached crossing: the stamped ctx.error compares
474
474
  * reference-equal to the thrown error's other boxings). */
475
475
 
@@ -586,7 +586,7 @@ static void dc_tp_entry(ScrFiber *self, void *ap) {
586
586
  free(a);
587
587
  }
588
588
 
589
- /* The traced result as a promise (+1): a DOM promise unwraps, anything
589
+ /* The traced result as a promise (+1): a dyn promise unwraps, anything
590
590
  * else is PromiseResolve'd (Node converts non-promise returns; a raw
591
591
  * non-promise return on the NO-SUBSCRIBER path wraps too — the lowering
592
592
  * types the result Promise<unknown>, a wrap Node skips, SEMANTICS.md). */
@@ -728,7 +728,7 @@ ScrDyn *scr_dc_tc_trace_callback(double h, ScrDyn *fn, double position, ScrDyn *
728
728
  dc_throw_bad_fn_arg(cb, "callback");
729
729
  return NULL;
730
730
  }
731
- /* Splice the wrapper in (a fresh argument vector; the DOM array is
731
+ /* Splice the wrapper in (a fresh argument vector; the dyn array is
732
732
  * borrowed and Node's splice mutation is unobservable through it — the
733
733
  * caller rebuilt it from the call site's arguments). */
734
734
  ScrClosure *clo = scr_closure_new((void *)dc_tc_wrapped_cb, 3);
package/src/scr_dgram.c CHANGED
@@ -1020,7 +1020,7 @@ void scr_dgram_install(void) {
1020
1020
 
1021
1021
  /* ── the send argument-validation ladder (checked-dynamic lane) ─────────
1022
1022
  * Node's Socket.prototype.send signature shuffle and validation order
1023
- * over DOM arguments, byte-for-byte: the connected/unconnected split
1023
+ * over dyn arguments, byte-for-byte: the connected/unconnected split
1024
1024
  * decides whether (a1, a2) are an offset/length slice or the port/address
1025
1025
  * pair; sliceBuffer validates the buffer's type and bounds
1026
1026
  * (ERR_BUFFER_OUT_OF_BOUNDS); list payloads validate per element with the
@@ -1,10 +1,10 @@
1
1
  /* The checked-dynamic HANDLE support unit — everything the handle
2
2
  * dispatchers (scr_http.c / scr_net.c) and the emitter unit's dyn
3
- * registrations share BEYOND the DOM core: the listener gate over the
3
+ * registrations share BEYOND the dyn core: the listener gate over the
4
4
  * ERR_INVALID_ARG_TYPE throwers (the throwers themselves live in
5
- * scr_json.c beside the DOM core — the always-linked bytes/fs argument
5
+ * scr_json.c beside the dyn core — the always-linked bytes/fs argument
6
6
  * validators call them too), and the runtime-built listener adapter
7
- * closures whose fire thunks box event tuples back into the DOM. Split
7
+ * closures whose fire thunks box event tuples back into the checked-dynamic tree. Split
8
8
  * out of scr_json.c so handle-free binaries keep their exact size
9
9
  * class: cc.ts compiles this unit exactly when a user of it links (the
10
10
  * net or emitter gate — http implies net).
@@ -24,7 +24,7 @@ void scr_dyn_check_listener(const ScrDyn *cb, const char *argname) {
24
24
 
25
25
  /* ── runtime-built listener closures (the handle dispatchers' .on paths) ─
26
26
  * One capture: a box holding the retained dyn FUNCTION value. The fire
27
- * thunks box the event tuple back into the DOM and call through the
27
+ * thunks box the event tuple back into the checked-dynamic tree and call through the
28
28
  * checked-dynamic machinery (scr_dyn_call — per-arg validation lives in
29
29
  * the boxed thunk). A throw from the listener stays pending, exactly like
30
30
  * a compiler-emitted listener body. */
@@ -56,7 +56,7 @@ void scr_dyn_listener_fire_data(ScrClosure *cb, ScrBytes *chunk) {
56
56
 
57
57
  void scr_dyn_listener_fire_err(ScrClosure *cb, ScrStr *msg) {
58
58
  ScrDyn *fn = scr_dyn_listener_peek(cb);
59
- /* The DOM's error encoding (caughtToDyn's shape) — what a dyn 'error'
59
+ /* The checked-dynamic tree's error encoding (caughtToDyn's shape) — what a dyn 'error'
60
60
  * listener body can instanceof-test and read .message from. */
61
61
  ScrDyn *arg = scr_dyn_new_obj();
62
62
  scr_dyn_obj_set(arg, "%error", 6, scr_dyn_new_bool(true));
@@ -1,10 +1,10 @@
1
1
  /* Prototype-method dispatch on checked-dynamic receivers (scr_dyn_invoke)
2
- * and its companions: JS String() over the DOM (scr_dyn_display — join
2
+ * and its companions: JS String() over the checked-dynamic tree (scr_dyn_display — join
3
3
  * and the error texts need it standalone) and Object.defineProperties
4
- * over DOM values (scr_dyn_define_props). Linked only when the IR
4
+ * over dyn values (scr_dyn_define_props). Linked only when the IR
5
5
  * carries dynInvoke nodes or dyn.defineProps calls (cc.ts gates on
6
6
  * moduleUsesDynInvoke — the scr_assert.c precedent), so dispatch-free
7
- * binaries keep their exact size class. The DOM itself lives in
7
+ * binaries keep their exact size class. The checked-dynamic tree itself lives in
8
8
  * scr_json.c; this unit uses only its public surface plus ScrJsonBuf.
9
9
  */
10
10
  #include "scr_runtime.h"
@@ -16,8 +16,8 @@
16
16
 
17
17
  /* ── checked-dynamic METHOD DISPATCH (scr_dyn_invoke) ──────────────────
18
18
  *
19
- * `recv.m(args)` where recv is a DOM value and `m` is a name a
20
- * DOM-representable prototype declares (Array/String/Function shared
19
+ * `recv.m(args)` where recv is a dyn value and `m` is a name a
20
+ * dyn-representable prototype declares (Array/String/Function shared
21
21
  * names — push, slice, forEach, apply, ...): a stored-member read would
22
22
  * silently mis-answer real methods, so the dispatch runs HERE, over the
23
23
  * receiver's runtime kind. test/common's mustCall internals are the
@@ -38,10 +38,10 @@
38
38
  * recv/args are BORROWED; the result is owned (+1). MAY THROW (returns
39
39
  * NULL with the exception pending). */
40
40
 
41
- /* JS String() over a DOM value, runtime-side (join needs it standalone —
41
+ /* JS String() over a dyn value, runtime-side (join needs it standalone —
42
42
  * the emitted sc_ds walker exists only in programs that spell
43
43
  * String(unknown) themselves). Same rules: arrays join with "," and
44
- * null/undefined elements print empty, the DOM's error encoding renders
44
+ * null/undefined elements print empty, the checked-dynamic tree's error encoding renders
45
45
  * "name: message", functions render the native-code form, plain objects
46
46
  * are [object Object]. */
47
47
  static void scr_dyn_display_buf(ScrJsonBuf *b, const ScrDyn *d) {
@@ -192,7 +192,7 @@ static bool dyn_cb_check(ScrDyn *const *args, size_t argc) {
192
192
  ScrDyn *cb = argc > 0 ? args[0] : scr_dyn_undefined();
193
193
  if (cb->kind == SCR_DYN_FUNC) return true;
194
194
  /* An ENGINE function is callable — scr_dyn_call's JSVAL arm routes it
195
- * (the loops below call through scr_dyn_call, which converts the DOM
195
+ * (the loops below call through scr_dyn_call, which converts the checked-dynamic tree
196
196
  * element arguments per the uniform crossing). A wrapped NON-function
197
197
  * falls through to the display path: String(cb) renders through the
198
198
  * engine, exactly Node's message. */
@@ -215,7 +215,7 @@ static ScrDyn *scr_dynh_dispatch(ScrDyn *recv, const char *method, ScrDyn *const
215
215
  return ops->invoke(recv->v.handle.ptr, recv, method, args, argc, what);
216
216
  }
217
217
 
218
- /* JS Array.prototype.sort over a DOM array: the spec's snapshot-sort —
218
+ /* JS Array.prototype.sort over a dyn array: the spec's snapshot-sort —
219
219
  * elements copy (retained) into a work list, a stable merge sort orders
220
220
  * it (undefined elements sink to the end before any comparator runs),
221
221
  * and the ordered list writes back index by index, so a comparator that
@@ -339,7 +339,7 @@ ScrDyn *scr_dyn_invoke(ScrDyn *recv, const char *method, ScrDyn *const *args, si
339
339
  /* Island-held receivers: the ENGINE runs its own prototypes (JS-exact
340
340
  * flatMap/map/forEach/filter — Array.prototype is the engine's) through
341
341
  * scr_jsval_call_method; arguments cross per the uniform conversion
342
- * (wrapped cells by reference, DOM data deep-copied, FUNC boxes through
342
+ * (wrapped cells by reference, dyn data deep-copied, FUNC boxes through
343
343
  * the host shim), a missing member throws the engine's own TypeError,
344
344
  * and the result wraps back scalar-normalized. `what` is unused — the
345
345
  * engine's message names the failure. */
@@ -352,7 +352,7 @@ ScrDyn *scr_dyn_invoke(ScrDyn *recv, const char *method, ScrDyn *const *args, si
352
352
  if (recv->kind == SCR_DYN_OBJ) {
353
353
  ScrDyn *m = scr_dyn_obj_get(recv, method, strlen(method));
354
354
  if (m && (m->kind == SCR_DYN_FUNC ||
355
- /* a WRAPPED engine function stored as a DOM member: the
355
+ /* a WRAPPED engine function stored as a dyn member: the
356
356
  * routed call (scr_dyn_call's JSVAL arm) runs it. */
357
357
  (m->kind == SCR_DYN_JSVAL && scr_dyn_isl_typeof_is(m, "function")))) {
358
358
  /* JS binds the receiver for the call (`obj.method()` — this === obj):
@@ -584,8 +584,8 @@ ScrDyn *scr_dyn_invoke(ScrDyn *recv, const char *method, ScrDyn *const *args, si
584
584
  return scr_dyn_retain(scr_dyn_undefined()); /* forEach */
585
585
  }
586
586
  if (dyn_name_is(method, "flatMap")) {
587
- /* JS Array.prototype.flatMap over a DOM array: map + a depth-1
588
- * flatten. Native DOM-array results flatten element-by-element; a
587
+ /* JS Array.prototype.flatMap over a dyn array: map + a depth-1
588
+ * flatten. Native dyn-array results flatten element-by-element; a
589
589
  * WRAPPED engine array flattens through the routed keyed reads
590
590
  * (elements wrap back scalar-normalized); everything else pushes
591
591
  * as a single element (JS keeps non-array callback results whole).
@@ -671,9 +671,33 @@ ScrDyn *scr_dyn_invoke(ScrDyn *recv, const char *method, ScrDyn *const *args, si
671
671
  return NULL;
672
672
  }
673
673
 
674
- if (recv->kind == SCR_DYN_BYTES && dyn_bytes_proto_real(method)) {
675
- dyn_throw_unsupported("Uint8Array", method);
676
- return NULL;
674
+ if (recv->kind == SCR_DYN_BYTES) {
675
+ ScrBytes *bytes = recv->v.bytes;
676
+ size_t blen = bytes->len;
677
+ if (dyn_name_is(method, "at")) {
678
+ double iD = dyn_index_arg(args, argc, 0, 0, what);
679
+ if (scr_exc_pending()) return NULL;
680
+ double idx = iD < 0 ? (double)blen + iD : iD;
681
+ if (idx < 0 || idx >= (double)blen) return scr_dyn_retain(scr_dyn_undefined());
682
+ return scr_dyn_new_num((double)bytes->data[(size_t)idx]);
683
+ }
684
+ if (dyn_name_is(method, "slice") || dyn_name_is(method, "subarray")) {
685
+ /* Both COPY (no views in this runtime — the static lane's
686
+ * documented divergence for subarray/Buffer.slice); the result
687
+ * keeps the receiver's Buffer flavor. */
688
+ double startD = dyn_index_arg(args, argc, 0, 0, what);
689
+ if (scr_exc_pending()) return NULL;
690
+ double endD = dyn_index_arg(args, argc, 1, (double)blen, what);
691
+ if (scr_exc_pending()) return NULL;
692
+ ScrBytes *out = scr_bytes_slice(bytes, startD, endD);
693
+ ScrDyn *d = recv->buffer ? scr_dyn_new_buffer_copy(out) : scr_dyn_new_bytes_copy(out);
694
+ scr_bytes_release(out);
695
+ return d;
696
+ }
697
+ if (dyn_bytes_proto_real(method)) {
698
+ dyn_throw_unsupported("Uint8Array", method);
699
+ return NULL;
700
+ }
677
701
  }
678
702
 
679
703
  /* NUM/BOOL/BYTES-remainder: the name is no method of this kind — JS's
@@ -682,9 +706,9 @@ ScrDyn *scr_dyn_invoke(ScrDyn *recv, const char *method, ScrDyn *const *args, si
682
706
  return NULL;
683
707
  }
684
708
 
685
- /* Object.defineProperties over DOM values (see scr_runtime.h). Value
709
+ /* Object.defineProperties over dyn values (see scr_runtime.h). Value
686
710
  * descriptors only: writable/enumerable/configurable accepted and IGNORED
687
- * (DOM properties are plain data properties — SEMANTICS.md); get/set
711
+ * (dyn properties are plain data properties — SEMANTICS.md); get/set
688
712
  * throw the loud unsupported Error, never a silent drop. */
689
713
  ScrDyn *scr_dyn_define_props(ScrDyn *target, ScrDyn *descs) {
690
714
  /* Island-held operands ARE objects to Node — the non-object TypeError
package/src/scr_error.c CHANGED
@@ -44,9 +44,9 @@ static void scr_error_gcfree(void *obj) {
44
44
  scr_cyc_free(e);
45
45
  }
46
46
 
47
- /* DOMException teardown: the ScrError fields plus the owned cause DOM
47
+ /* DOMException teardown: the ScrError fields plus the owned cause dyn
48
48
  * value. The cause is a ScrDyn — scr_json.c territory — and this file
49
- * must stay linkable WITHOUT the DOM (the runtime C-unit tests link
49
+ * must stay linkable WITHOUT the checked-dynamic tree (the runtime C-unit tests link
50
50
  * subsets), so the drop goes through a hook scr_json.c installs before
51
51
  * any cause can exist (scr_domex_new is the only producer). */
52
52
  static void (*scr_domex_cause_drop)(void *obj) = NULL;
@@ -273,7 +273,7 @@ void scr_undef_global_read(ScrStr *name) {
273
273
  /* ── DOMException ─────────────────────────────────────────────────────
274
274
  * The web-standard error shape (a Node global since v17): the ScrError
275
275
  * prefix plus the WebIDL slots (legacy numeric code, the options form's
276
- * cause). Construction resolves WebIDL's optionality over borrowed DOM
276
+ * cause). Construction resolves WebIDL's optionality over borrowed dyn
277
277
  * arguments — one place, shared by the compiled `new DOMException(...)`
278
278
  * and the runtime's own throw sites (atob/btoa). */
279
279
 
@@ -466,7 +466,7 @@ ScrEmitter *scr_emitter_off_dyn(ScrEmitter *em, ScrStr *name, const ScrDyn *cb)
466
466
  * the simple '-quoted spelling — listener mistakes are words, not escape
467
467
  * zoos). */
468
468
  void scr_emitter_check_listener(const ScrDyn *cb) {
469
- /* The shared gate lives in the always-linked DOM core (scr_json.c) so
469
+ /* The shared gate lives in the always-linked dyn core (scr_json.c) so
470
470
  * the handle dispatchers' .on paths render the same shapes without
471
471
  * linking this unit. */
472
472
  scr_dyn_check_listener(cb, "listener");