toilscript 0.1.41 → 0.1.43

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.
@@ -2887,8 +2887,8 @@ declare module "types:toilscript/src/dbcatalog" {
2887
2887
  * toildb's `SchemaDescriptor::layout_hash` (the runtime side): the algorithm,
2888
2888
  * the `seen` add/remove, and the declaration-order traversal are pinned in lock
2889
2889
  * step. A FLAT type (no field whose type is in `typeMap`) hashes to the SAME
2890
- * value as the old flat hash, so existing pinned vectors stay green; an absent
2891
- * `typeMap` (undefined) is flat/back-compatible.
2890
+ * value as the flat hash; an absent `typeMap` (undefined) is treated as a flat
2891
+ * descriptor.
2892
2892
  *
2893
2893
  * `typeMap` MUST contain the SAME set of `@data` types as the runtime's
2894
2894
  * `toildb.types` registry (collection value types + their nested types, EXCLUDING
@@ -3003,6 +3003,23 @@ declare module "types:toilscript/src/dbcatalog" {
3003
3003
  * missing/non-string arg or an unparseable spec.
3004
3004
  */
3005
3005
  export function buildToilDaemonCatalog(program: Program): Uint8Array | null;
3006
+ /** Build the `toildb.derives` section bytes, or `null` if no `@database` class
3007
+ * declares a `@derive` materializer. The section wires each `@derive` method to
3008
+ * the database class that owns it, so the host runner can, after a write to one
3009
+ * of a database's source collections, re-run that database's derives (each
3010
+ * recomputes + `view.publish`es its materialized view). `derive_id` is assigned
3011
+ * globally in source-declaration order across every `@database` class, matching
3012
+ * the single module-level `derive_run(derive_id)` dispatcher synthesized by the
3013
+ * parser 1:1. Format (LE):
3014
+ *
3015
+ * u16 format_version = 1
3016
+ * u16 n_derives
3017
+ * per derive:
3018
+ * u16 derive_id (global declaration order in the hot/default module)
3019
+ * str db_name (the @database class name; the write -> derive key)
3020
+ * str method_name (the @derive method, for diagnostics)
3021
+ */
3022
+ export function buildToilDbDerives(program: Program): Uint8Array | null;
3006
3023
  /** Build the `toil.surface` section bytes (always emitted per artifact). Per
3007
3024
  * Part 5 (LE):
3008
3025
  *
@@ -3016,22 +3033,21 @@ declare module "types:toilscript/src/dbcatalog" {
3016
3033
  * u32 data_coherence_hash
3017
3034
  * u32 pair_coherence_hash
3018
3035
  *
3019
- * `targetMode` "cold" -> 1; "hot" or null (legacy single artifact, treated as
3020
- * hot per Part 5) -> 0. The two coherence hashes use the SAME `layoutHash` /
3036
+ * `targetMode` "cold" -> 1; "hot" or null (default request artifact, treated
3037
+ * as hot per Part 5) -> 0. The two coherence hashes use the SAME `layoutHash` /
3021
3038
  * `recursionTypeMap` machinery as the toildb catalog, so a hot pass and a cold
3022
3039
  * pass over the same sources compute identical `data_coherence_hash` and
3023
3040
  * `pair_coherence_hash` independently (doc 02 AN-4). `build_id` is empty and
3024
3041
  * `abi_version` is 1 in this increment (the toiljs build-identity plumbing and
3025
3042
  * the export-name fingerprint component land with the codegen increment).
3026
3043
  *
3027
- * Returns `null` (no section) for a bare AssemblyScript module compiled in
3028
- * LEGACY mode (`targetMode == null`) that declares NO Toil surface at all
3044
+ * Returns `null` (no section) for a bare AssemblyScript module compiled with
3045
+ * `targetMode == null` that declares NO Toil surface at all
3029
3046
  * (`@rest`/`@stream`/`@daemon`/`@scheduled`/`@database`/`@data`), so an ordinary
3030
3047
  * AS compile stays byte-identical (the same gating philosophy as the existing
3031
3048
  * `toildb.catalog`, which is absent without `@database`). Part 5 / doc 02 AN-2
3032
- * requires the section in every TOIL artifact (including a legacy single-artifact
3033
- * toil build, which always carries a toil surface); a non-toil module is not a
3034
- * toil artifact. An explicit `--targetMode hot|cold` always emits the section.
3049
+ * requires the section in every TOIL artifact; a non-toil module is not a toil
3050
+ * artifact. An explicit `--targetMode hot|cold` always emits the section.
3035
3051
  */
3036
3052
  export function buildToilSurface(program: Program, targetMode: string | null): Uint8Array | null;
3037
3053
  }
@@ -3089,6 +3105,8 @@ declare module "types:toilscript/src/parser" {
3089
3105
  toildbCodecClasses: Map<string, ClassDeclaration>;
3090
3106
  /** Guards `weaveDataMigrations` so it runs exactly once (before element creation). */
3091
3107
  toildbWoven: boolean;
3108
+ /** Guards `weaveDeriveHandlers` so the module-level `derive_run` export is emitted once. */
3109
+ toildbDerivesWoven: boolean;
3092
3110
  /** Current overridden module name. */
3093
3111
  currentModuleName: string | null;
3094
3112
  /** Compiler options. */
@@ -3111,6 +3129,12 @@ declare module "types:toilscript/src/parser" {
3111
3129
  getDependee(dependent: string): string | null;
3112
3130
  /** Finishes parsing. */
3113
3131
  finish(): void;
3132
+ /** Synthesize the hot/default module-level `derive_run(derive_id)` export for
3133
+ * `@database` classes with `@derive` methods. Runs before element creation
3134
+ * from `initializeProgram`, so generated members/exports are compiled as
3135
+ * ordinary program symbols. Cold artifacts intentionally do not export
3136
+ * request-path derive runners and do not emit `toildb.derives`. */
3137
+ weaveDeriveHandlers(): void;
3114
3138
  weaveDataMigrations(): void;
3115
3139
  /** Enforce the migration-file convention (folder AND extension): every `@migrate`
3116
3140
  * must live in a `*.migration.ts` file under a `migrations/` directory. Keeping
@@ -3284,6 +3308,25 @@ declare module "types:toilscript/src/parser" {
3284
3308
  * shape; gating already rejects a hook outside a `@stream`.
3285
3309
  */
3286
3310
  private injectStreamHandler;
3311
+ /** True if `node` is a non-nullable named type whose identifier is exactly `name`
3312
+ * (e.g. a `StreamPacket` parameter or a `StreamOutbound` return on a raw @message). */
3313
+ private isNamedType;
3314
+ /**
3315
+ * The injected stream ring runtime (spec 05 sections 5-6; byte layouts in 10), emitted once per
3316
+ * program under the `stream_dispatch` export gate. Provides two fixed 128 KiB rings in linear
3317
+ * memory (ingress host->guest, egress guest->host), each a 32-byte `RingControl` + frame region,
3318
+ * exported via `stream_ring_offset/capacity` + `stream_egress_offset/capacity` (the host reads
3319
+ * these at box build, stamps both RingControls, and owns the ingress write_cursor / egress
3320
+ * read_cursor; the guest owns the ingress read_cursor / egress write_cursor - SPSC on the one
3321
+ * resident-box thread). `StreamPacket` drains ONE ingress `RingFrame` (raw @message arg);
3322
+ * `StreamOutbound.reply` stages ONE DATA_RELIABLE frame into the egress ring (bounds-checked ->
3323
+ * `0x0205`); `__encode` lowers to the packed i64 (0 for accept/empty/reply; `-(0x10000 + 0x02xx)`
3324
+ * for a reject, normalized to `0x0208`). The `.d.ts` declares these for the editor only (not
3325
+ * compile-loaded); these injected `@global` classes are the real impls, like `AuthUser`.
3326
+ * RingControl(32B): u32 magic|u16 version|u16 flags|u32 capacity|u32 write|u32 read|u32 dropped|2xu32.
3327
+ * RingFrame(12B): u8 version|u8 type|u16 flags|u32 length|u32 msg_seq|payload.
3328
+ */
3329
+ private streamRuntimeSource;
3287
3330
  /** True if a function signature takes no parameters and returns `void` (the
3288
3331
  * required `@scheduled` handler shape, spec 03 section 3.5). A missing or
3289
3332
  * non-`void`-named return type, or any parameter, is false. */
@@ -8135,7 +8178,8 @@ declare module "types:toilscript/src/diagnosticMessages.generated" {
8135
8178
  Scheduled_requires_a_single_string_schedule_argument = 9010,
8136
8179
  Scheduled_spec_0_is_not_a_valid_interval_or_cron_expression = 9011,
8137
8180
  Scheduled_handler_0_must_take_no_arguments_and_return_void = 9012,
8138
- Stream_scope_must_be_a_StreamScope_enum_member = 9013
8181
+ Stream_scope_must_be_a_StreamScope_enum_member = 9013,
8182
+ Stream_connect_handler_0_has_an_invalid_signature = 9014
8139
8183
  }
8140
8184
  /** Translates a diagnostic code to its respective string. */
8141
8185
  export function diagnosticCodeToString(code: DiagnosticCode): string;
@@ -9395,8 +9439,8 @@ declare module "types:toilscript/src/compiler" {
9395
9439
  constructor();
9396
9440
  /** WebAssembly target. Defaults to {@link Target.Wasm32}. */
9397
9441
  target: Target;
9398
- /** Toil compile surface mode. null = legacy single-artifact build (all surfaces allowed,
9399
- * matching pre-split behavior). "hot" = request + stream surface. "cold" = daemon surface. */
9442
+ /** Toil compile surface mode. null = default request artifact. "hot" = request + stream surface.
9443
+ * "cold" = daemon surface. */
9400
9444
  targetMode: string | null;
9401
9445
  /** Runtime type. Defaults to Incremental GC. */
9402
9446
  runtime: Runtime;
@@ -10030,7 +10074,7 @@ declare module "types:toilscript/src/index-wasm" {
10030
10074
  export function setExportStart(options: Options, exportStart: string | null): void;
10031
10075
  /** Sets the `noUnsafe` option. */
10032
10076
  export function setNoUnsafe(options: Options, noUnsafe: boolean): void;
10033
- /** Sets the `targetMode` option ("hot", "cold", or null for legacy single-artifact). */
10077
+ /** Sets the `targetMode` option ("hot", "cold", or null for the default request artifact). */
10034
10078
  export function setTargetMode(options: Options, targetMode: string | null): void;
10035
10079
  /** Sets the `lowMemoryLimit` option. */
10036
10080
  export function setLowMemoryLimit(options: Options, lowMemoryLimit: number): void;
package/dist/cli.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * SPDX-License-Identifier: Apache-2.0
6
6
  */
7
7
  var le=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var Ve=Object.prototype.hasOwnProperty;var cn=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(a){throw n=[a],a}};var nn=(e,t)=>{for(var n in t)le(e,n,{get:t[n],enumerable:!0})},se=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Pe(t))!Ve.call(e,s)&&s!==n&&le(e,s,{get:()=>t[s],enumerable:!(a=Me(t,s))||a.enumerable});return e},In=(e,t,n)=>(se(e,t,"default"),n&&se(n,t,"default"));var ue={};nn(ue,{promises:()=>Ge});var Ge,fe=cn(()=>{"use strict";Ge={}});var ce={};nn(ce,{createRequire:()=>je});function je(){return function(t){throw new Error(`Cannot find module: '${t}'`)}}var de=cn(()=>{"use strict"});var Ln={};nn(Ln,{argv:()=>Xe,cwd:()=>On,exit:()=>qe,hrtime:()=>Ye,platform:()=>He,umask:()=>Ke});function On(){return"."}function Ke(){return 0}function qe(e=0){throw Error(`exit ${e}`)}function Ye(e){var t=We.call(pe),n=Math.floor(t*.001),a=Math.floor(t*1e6-n*1e9);return e&&(n-=e[0],a-=e[1],a<0&&(n--,a+=1e9)),[n,a]}var He,Xe,pe,We,kn=cn(()=>{"use strict";He="linux";Xe=[];pe=globalThis.performance||{},We=pe.now||function(){return new Date().getTime()}});var Nn={};nn(Nn,{basename:()=>et,delimiter:()=>at,dirname:()=>nt,extname:()=>tt,format:()=>it,isAbsolute:()=>Ze,join:()=>$e,normalize:()=>xe,parse:()=>rt,relative:()=>Qe,resolve:()=>dn,sep:()=>Rn,win32:()=>ot});function G(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function he(e,t){for(var n="",a=0,s=-1,o=0,f,c=0;c<=e.length;++c){if(c<e.length)f=e.charCodeAt(c);else{if(f===47)break;f=47}if(f===47){if(!(s===c-1||o===1))if(s!==c-1&&o===2){if(n.length<2||a!==2||n.charCodeAt(n.length-1)!==46||n.charCodeAt(n.length-2)!==46){if(n.length>2){var x=n.lastIndexOf("/");if(x!==n.length-1){x===-1?(n="",a=0):(n=n.slice(0,x),a=n.length-1-n.lastIndexOf("/")),s=c,o=0;continue}}else if(n.length===2||n.length===1){n="",a=0,s=c,o=0;continue}}t&&(n.length>0?n+="/..":n="..",a=2)}else n.length>0?n+="/"+e.slice(s+1,c):n=e.slice(s+1,c),a=c-s-1;s=c,o=0}else f===46&&o!==-1?++o:o=-1}return n}function Je(e,t){var n=t.dir||t.root,a=t.base||(t.name||"")+(t.ext||"");return n?n===t.root?n+a:n+e+a:a}function dn(){for(var e="",t=!1,n,a=arguments.length-1;a>=-1&&!t;a--){var s;a>=0?s=arguments[a]:(n===void 0&&(n=On()),s=n),G(s),s.length!==0&&(e=s+"/"+e,t=s.charCodeAt(0)===47)}return e=he(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."}function xe(e){if(G(e),e.length===0)return".";var t=e.charCodeAt(0)===47,n=e.charCodeAt(e.length-1)===47;return e=he(e,!t),e.length===0&&!t&&(e="."),e.length>0&&n&&(e+="/"),t?"/"+e:e}function Ze(e){return G(e),e.length>0&&e.charCodeAt(0)===47}function $e(){if(arguments.length===0)return".";for(var e,t=0;t<arguments.length;++t){var n=arguments[t];G(n),n.length>0&&(e===void 0?e=n:e+="/"+n)}return e===void 0?".":xe(e)}function Qe(e,t){if(G(e),G(t),e===t||(e=dn(e),t=dn(t),e===t))return"";if(e===".")return t;for(var n=1;n<e.length&&e.charCodeAt(n)===47;++n);for(var a=e.length,s=a-n,o=1;o<t.length&&t.charCodeAt(o)===47;++o);for(var f=t.length,c=f-o,x=s<c?s:c,b=-1,p=0;p<=x;++p){if(p===x){if(c>x){if(t.charCodeAt(o+p)===47)return t.slice(o+p+1);if(p===0)return t.slice(o+p)}else s>x&&(e.charCodeAt(n+p)===47?b=p:p===0&&(b=0));break}var g=e.charCodeAt(n+p),y=t.charCodeAt(o+p);if(g!==y)break;g===47&&(b=p)}var m="";for(p=n+b+1;p<=a;++p)(p===a||e.charCodeAt(p)===47)&&(m.length===0?m+="..":m+="/..");return m.length>0?m+t.slice(o+b):(o+=b,t.charCodeAt(o)===47&&++o,t.slice(o))}function nt(e){if(G(e),e.length===0)return".";for(var t=e.charCodeAt(0),n=t===47,a=-1,s=!0,o=e.length-1;o>=1;--o)if(t=e.charCodeAt(o),t===47){if(!s){a=o;break}}else s=!1;return a===-1?n?"/":".":n&&a===1?"//":e.slice(0,a)}function et(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');G(e);var n=0,a=-1,s=!0,o;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var f=t.length-1,c=-1;for(o=e.length-1;o>=0;--o){var x=e.charCodeAt(o);if(x===47){if(!s){n=o+1;break}}else c===-1&&(s=!1,c=o+1),f>=0&&(x===t.charCodeAt(f)?--f===-1&&(a=o):(f=-1,a=c))}return n===a?a=c:a===-1&&(a=e.length),e.slice(n,a)}else{for(o=e.length-1;o>=0;--o)if(e.charCodeAt(o)===47){if(!s){n=o+1;break}}else a===-1&&(s=!1,a=o+1);return a===-1?"":e.slice(n,a)}}function tt(e){G(e);for(var t=-1,n=0,a=-1,s=!0,o=0,f=e.length-1;f>=0;--f){var c=e.charCodeAt(f);if(c===47){if(!s){n=f+1;break}continue}a===-1&&(s=!1,a=f+1),c===46?t===-1?t=f:o!==1&&(o=1):t!==-1&&(o=-1)}return t===-1||a===-1||o===0||o===1&&t===a-1&&t===n+1?"":e.slice(t,a)}function it(e){if(e===null||typeof e!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return Je("/",e)}function rt(e){G(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return t;var n=e.charCodeAt(0),a=n===47,s;a?(t.root="/",s=1):s=0;for(var o=-1,f=0,c=-1,x=!0,b=e.length-1,p=0;b>=s;--b){if(n=e.charCodeAt(b),n===47){if(!x){f=b+1;break}continue}c===-1&&(x=!1,c=b+1),n===46?o===-1?o=b:p!==1&&(p=1):o!==-1&&(p=-1)}return o===-1||c===-1||p===0||p===1&&o===c-1&&o===f+1?c!==-1&&(f===0&&a?t.base=t.name=e.slice(1,c):t.base=t.name=e.slice(f,c)):(f===0&&a?(t.name=e.slice(1,o),t.base=e.slice(1,c)):(t.name=e.slice(f,o),t.base=e.slice(f,c)),t.ext=e.slice(o,c)),f>0?t.dir=e.slice(0,f-1):a&&(t.dir="/"),t}var Rn,at,ot,Un=cn(()=>{"use strict";kn();Rn="/",at=":",ot=null});var ge={};nn(ge,{pathToFileURL:()=>lt});function st(e){return e.replace(/%/g,"%25").replace(/\\/g,"%5C").replace(/\n/g,"%0A").replace(/\r/g,"%0D").replace(/\t/g,"%09")}function lt(e){let t=dn(e);e.charCodeAt(e.length-1)===47&&t[t.length-1]!==Rn&&(t+="/");let n=new URL("file://");return n.pathname=st(t),n}var me=cn(()=>{"use strict";Un()});var Yn={};nn(Yn,{Stats:()=>zn,checkDiagnostics:()=>mn,compileString:()=>Dt,configToArguments:()=>Wn,createMemoryStream:()=>Xn,default:()=>Yn,defaultOptimizeLevel:()=>we,defaultShrinkLevel:()=>Be,definitionFiles:()=>Bt,libraryFiles:()=>H,libraryPrefix:()=>V,main:()=>De,options:()=>wt,tscOptions:()=>It,version:()=>Kn});var ut=Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]",M,sn,A,P,pn;ut?(M=await import("fs"),sn=await import("module"),A=await import("path"),P=globalThis.process,pn=await import("url")):(M=await Promise.resolve().then(()=>(fe(),ue)),sn=await Promise.resolve().then(()=>(de(),ce)),A=await Promise.resolve().then(()=>(Un(),Nn)),P=await Promise.resolve().then(()=>(kn(),Ln)),pn=await Promise.resolve().then(()=>(me(),ge)));var _n=typeof process<"u"&&process||{},ft=_n.env&&"CI"in _n.env,ct="\x1B[90m",dt="\x1B[91m",pt="\x1B[92m",ht="\x1B[93m",xt="\x1B[94m",gt="\x1B[95m",mt="\x1B[96m",bt="\x1B[97m",W="\x1B[0m",en=class{constructor(t){this.stream=t,this.enabled=!!(this.stream&&this.stream.isTTY||ft)}gray(t){return this.enabled?ct+t+W:t}red(t){return this.enabled?dt+t+W:t}green(t){return this.enabled?pt+t+W:t}yellow(t){return this.enabled?ht+t+W:t}blue(t){return this.enabled?xt+t+W:t}magenta(t){return this.enabled?gt+t+W:t}cyan(t){return this.enabled?mt+t+W:t}white(t){return this.enabled?bt+t+W:t}},Tn=new en(_n.stdout),kt=new en(_n.stderr);function yt(e){for(var t=0,n=0,a=e.length;n<a;++n){let s=e.charCodeAt(n);s<128?t+=1:s<2048?t+=2:(s&64512)===55296&&n+1<a&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3}return t}function vt(e,t,n){var a=n-t;if(a<1)return"";for(var s=null,o=[],f=0,c;t<n;)c=e[t++],c<128?o[f++]=c:c>191&&c<224?o[f++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,o[f++]=55296+(c>>10),o[f++]=56320+(c&1023)):o[f++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,f>=8192&&((s||(s=[])).push(String.fromCharCode(...o)),f=0);return s?(f&&s.push(String.fromCharCode(...o.slice(0,f))),s.join("")):String.fromCharCode(...o.slice(0,f))}function Ft(e,t,n){for(var a=n,s=0,o=e.length;s<o;++s){let f=e.charCodeAt(s),c;f<128?t[n++]=f:f<2048?(t[n++]=f>>6|192,t[n++]=f&63|128):(f&64512)===55296&&s+1<o&&((c=e.charCodeAt(s+1))&64512)===56320?(f=65536+((f&1023)<<10)+(c&1023),++s,t[n++]=f>>18|240,t[n++]=f>>12&63|128,t[n++]=f>>6&63|128,t[n++]=f&63|128):(t[n++]=f>>12|224,t[n++]=f>>6&63|128,t[n++]=f&63|128)}return n-a}var Cn={length:yt,read:vt,write:Ft};var be=sn.createRequire(import.meta.url);function ve(e,t,n=!0){var a={},s=[],o=[],f=[],c={};Object.keys(t).forEach(p=>{if(!p.startsWith(" ")){var g=t[p];g.alias!=null&&(typeof g.alias=="string"?c[g.alias]=p:Array.isArray(g.alias)&&g.alias.forEach(y=>c[y]=p)),n&&g.default!=null&&(a[p]=g.default)}});for(var x=0,b=(e=e.slice()).length;x<b;++x){let p=e[x];if(p=="--"){++x;break}let g=/^(?:(-\w)(?:=(.*))?|(--\w{2,})(?:=(.*))?)$/.exec(p),y,m;if(g)t[p]?y=t[m=p]:g[1]!=null?(y=t[m=c[g[1].substring(1)]],y&&g[2]!=null&&(e[x--]=g[2])):g[3]!=null&&(y=t[m=g[3].substring(2)],y&&g[4]!=null&&(e[x--]=g[4]));else if(p.charCodeAt(0)==45)y=t[m=p];else{o.push(p);continue}if(y)if(y.value)Object.keys(y.value).forEach(i=>a[i]=y.value[i]);else if(y.type==null||y.type==="b")a[m]=!0;else if(x+1<e.length&&e[x+1].charCodeAt(0)!=45)switch(y.type){case"i":a[m]=parseInt(e[++x],10);break;case"I":a[m]=(a[m]||[]).concat(parseInt(e[++x],10));break;case"f":a[m]=parseFloat(e[++x]);break;case"F":a[m]=(a[m]||[]).concat(parseFloat(e[++x]));break;case"s":a[m]=String(e[++x]);break;case"S":a[m]=(a[m]||[]).concat(e[++x].split(","));break;default:s.push(p),--x}else switch(y.type){case"i":case"f":a[m]=y.default||0;break;case"s":a[m]=y.default||"";break;case"I":case"F":case"S":a[m]=y.default||[];break;default:s.push(p)}else s.push(p)}for(;x<b;)f.push(e[x++]);return n&&Pn(t,a),{options:a,unknown:s,arguments:o,trailing:f}}function Fe(e,t){t||(t={});var n=t.indent||2,a=t.padding||24,s=t.eol||`
8
- `,o={},f=[];Object.keys(e).forEach(b=>{var p=e[b];if(p.description!=null){for(var g="";g.length<n;)g+=" ";for(g+="--"+b,p.alias&&(g+=", -"+p.alias);g.length<a;)g+=" ";var y;!t.noCategories&&p.category?(y=o[p.category])||(o[p.category]=y=[]):y=f,Array.isArray(p.description)?y.push(g+p.description[0]+p.description.slice(1).map(m=>{for(let i=0;i<a;++i)m=" "+m;return s+m}).join("")):y.push(g+p.description)}});var c=[],x=!1;return Object.keys(o).forEach(b=>{x=!0,c.push(s+" "+Tn.gray(b)+s),c.push(o[b].join(s))}),x&&f.length&&c.push(s+" "+Tn.gray("Other")+s),c.push(f.join(s)),c.join(s)}function ye(e,t){if(e!=null)switch(t){case void 0:case"b":return!!e;case"i":return Math.trunc(e)||0;case"f":return Number(e)||0;case"s":return e===!0?"":e===!1?null:String(e);case"I":return Array.isArray(e)||(e=[e]),e.map(n=>Math.trunc(n)||0);case"F":return Array.isArray(e)||(e=[e]),e.map(n=>Number(n)||0);case"S":return Array.isArray(e)||(e=[e]),e.map(String)}}function Mn(e,t,n,a){let s={};for(let[o,{type:f,mutuallyExclusive:c,isPath:x,useNodeResolution:b,cliOnly:p}]of Object.entries(e)){let g=ye(t[o],f),y=ye(n[o],f);if(g==null){if(y!=null){if(p)continue;if(Array.isArray(y)){let m;x&&(y=y.map(i=>tn(i,a,b))),c!=null&&(m=t[c])?s[o]=y.filter(i=>!m.includes(i)):s[o]=y.slice()}else x&&(y=tn(y,a,b)),s[o]=y}}else if(y==null)Array.isArray(g)?s[o]=g.slice():s[o]=g;else if(Array.isArray(g)){if(p){s[o]=g.slice();continue}let m;x&&(y=y.map(i=>tn(i,a,b))),c!=null&&(m=t[c])?s[o]=[...g,...y.filter(i=>!g.includes(i)&&!m.includes(i))]:s[o]=[...g,...y.filter(i=>!g.includes(i))]}else s[o]=g}return s}function Et(e){let t=A.parse(e);return t.root||(t.root="./"),A.format(t)}function tn(e,t,n=!1){return A.isAbsolute(e)?e:n&&!e.startsWith(".")&&be.resolve?be.resolve(e,{paths:[t]}):Et(A.join(t,e))}function Pn(e,t){for(let[n,{default:a}]of Object.entries(e))t[n]==null&&a!=null&&(t[n]=a)}var Ee="0.1.41",Y={version:{category:"General",description:"Prints just the compiler's version and exits.",type:"b",alias:"v"},help:{category:"General",description:"Prints this message and exits.",type:"b",alias:"h"},config:{category:"General",description:"Configuration file to apply. CLI arguments take precedence.",type:"s",cliOnly:!0},target:{category:"General",description:"Configuration file target to use. Defaults to 'release'.",type:"s",cliOnly:!0},targetMode:{category:"General",description:"Toil compile surface mode: 'hot' (request/stream) or 'cold' (daemon). Omit for the legacy single-artifact build.",type:"s"},noConfigEntries:{category:"General",description:"Ignore the toilconfig 'entries' array and compile ONLY the entry files given on the command line. Used by the toiljs multi-artifact build, which hands each pass (request/stream/daemon) its own entry subset.",type:"b"},optimize:{category:"Optimization",description:["Optimizes the module. Typical shorthands are:",""," Default optimizations -O"," Make a release build -O --noAssert"," Make a debug build --debug"," Optimize for speed -Ospeed"," Optimize for size -Osize",""],type:"b",alias:"O"},optimizeLevel:{category:"Optimization",description:"How much to focus on optimizing code. [0-3]",type:"i"},shrinkLevel:{category:"Optimization",description:"How much to focus on shrinking code size. [0-2, s=1, z=2]",type:"i"},converge:{category:"Optimization",description:"Re-optimizes until no further improvements can be made.",type:"b",default:!1},noAssert:{category:"Optimization",description:"Replaces assertions with just their value without trapping.",type:"b",default:!1},outFile:{category:"Output",description:"Specifies the WebAssembly output file (.wasm).",type:"s",alias:"o",isPath:!0},textFile:{category:"Output",description:"Specifies the WebAssembly text output file (.wat).",type:"s",alias:"t",isPath:!0},rpcModule:{category:"Output",description:"Emits a .ts module: the @data codec + the typed client-callable Server surface.",type:"s",isPath:!0},rpcRuntime:{category:"Output",description:"Import specifier for the DataWriter/DataReader codec in the emitted RPC module.",type:"s",default:"toiljs/io"},bindings:{category:"Output",description:["Specifies the bindings to generate (.js + .d.ts).",""," esm JavaScript bindings & typings for ESM integration."," raw Like esm, but exports just the instantiate function."," Useful where modules are meant to be instantiated"," multiple times or non-ESM imports must be provided."],type:"S",alias:"b"},sourceMap:{category:"Debugging",description:["Enables source map generation. Optionally takes the URL","used to reference the source map from the binary file."],type:"s"},uncheckedBehavior:{category:"Debugging",description:["Changes the behavior of unchecked() expressions.","Using this option can potentially cause breakage.",""," default The default behavior: unchecked operations are"," only used inside of unchecked()."," never Unchecked operations are never used, even when"," inside of unchecked()."," always Unchecked operations are always used if possible,"," whether or not unchecked() is used."],type:"s",default:"default"},debug:{category:"Debugging",description:"Enables debug information in emitted binaries.",type:"b",default:!1},importMemory:{category:"Features",description:"Imports the memory from 'env.memory'.",type:"b",default:!1},noExportMemory:{category:"Features",description:"Does not export the memory as 'memory'.",type:"b",default:!1},initialMemory:{category:"Features",description:"Sets the initial memory size in pages.",type:"i",default:0},maximumMemory:{category:"Features",description:"Sets the maximum memory size in pages.",type:"i",default:0},sharedMemory:{category:"Features",description:"Declare memory as shared. Requires maximumMemory.",type:"b",default:!1},zeroFilledMemory:{category:"Features",description:"Assume imported memory is zeroed. Requires importMemory.",type:"b",default:!1},importTable:{category:"Features",description:"Imports the function table from 'env.table'.",type:"b",default:!1},exportTable:{category:"Features",description:"Exports the function table as 'table'.",type:"b",default:!1},exportStart:{category:"Features",description:["Exports the start function using the specified name instead","of calling it implicitly. Useful to obtain the exported memory","before executing any code accessing it."],type:"s"},runtime:{category:"Features",description:["Specifies the runtime variant to include in the program.",""," incremental TLSF + incremental GC (default)"," minimal TLSF + lightweight GC invoked externally"," stub Minimal runtime stub (never frees)"," ... Path to a custom runtime implementation",""],type:"s",default:"incremental"},exportRuntime:{category:"Features",description:["Always exports the runtime helpers (__new, __collect, __pin etc.).","Automatically determined when generation of --bindings is enabled."],type:"b",default:!1},stackSize:{category:"Features",description:["Overrides the stack size. Only relevant for incremental GC","or when using a custom runtime that requires stack space.","Defaults to 0 without and to 32768 with incremental GC."],default:0,type:"i"},enable:{category:"Features",description:["Enables WebAssembly features being disabled by default.",""," threads Threading and atomic operations."," simd SIMD types and operations."," reference-types Reference types and operations."," gc Garbage collection (WIP)."," stringref String reference types."," relaxed-simd Relaxed SIMD operations.",""],TODO_doesNothingYet:[" exception-handling Exception handling."," tail-calls Tail call operations."," multi-value Multi value types."," memory64 Memory64 operations."," extended-const Extended const expressions."],type:"S",mutuallyExclusive:"disable"},disable:{category:"Features",description:["Disables WebAssembly features being enabled by default.",""," mutable-globals Mutable global imports and exports."," sign-extension Sign-extension operations"," nontrapping-f2i Non-trapping float to integer ops."," bulk-memory Bulk memory operations.",""],type:"S",mutuallyExclusive:"enable"},use:{category:"Features",description:["Aliases a global object under another name, e.g., to switch","the default 'Math' implementation used: --use Math=JSMath","Can also be used to introduce an integer constant."],type:"S",alias:"u"},lowMemoryLimit:{category:"Features",description:"Enforces very low (<64k) memory constraints.",default:0,type:"i"},memoryBase:{category:"Linking",description:"Sets the start offset of emitted memory segments.",type:"i",default:0},tableBase:{category:"Linking",description:"Sets the start offset of emitted table elements.",type:"i",default:0},transform:{category:"API",description:"Specifies the path to a custom transform to load.",type:"S",isPath:!0,useNodeResolution:!0},trapMode:{category:"Binaryen",description:["Sets the trap mode to use.",""," allow Allow trapping operations. This is the default."," clamp Replace trapping operations with clamping semantics."," js Replace trapping operations with JS semantics.",""],type:"s",default:"allow"},runPasses:{category:"Binaryen",description:["Specifies additional Binaryen passes to run after other","optimizations, if any. See: Binaryen/src/passes/pass.cpp"],type:"s"},noValidate:{category:"Binaryen",description:"Skips validating the module using Binaryen.",type:"b",default:!1},baseDir:{description:"Specifies the base directory of input and output files.",type:"s",default:"."},noColors:{description:"Disables terminal colors.",type:"b",default:!1},noUnsafe:{description:["Disallows the use of unsafe features in user code.","Does not affect library files and external modules."],type:"b",default:!1},disableWarning:{description:["Disables warnings matching the given diagnostic code.","If no diagnostic code is given, all warnings are disabled."],type:"I"},noEmit:{description:"Performs compilation as usual but does not emit code.",type:"b",default:!1},showConfig:{description:"Print computed compiler options and exit.",type:"b",default:!1},stats:{description:"Prints statistics on I/O and compile times.",type:"b",default:!1},pedantic:{description:"Make yourself sad for no good reason.",type:"b",default:!1},lib:{description:["Adds one or multiple paths to custom library components and","uses exports of all top-level files at this path as globals."],type:"S",isPath:!0},path:{description:["Adds one or multiple paths to package resolution, similar","to node_modules. Prefers an 'ascMain' entry in a package's","package.json and falls back to an inner 'assembly/' folder."],type:"S",isPath:!0},wasm:{description:"Uses the specified Wasm binary of the compiler.",type:"s"}," ...":{description:"Specifies node.js options (CLI only). See: node --help"},"-Os":{value:{optimizeLevel:0,shrinkLevel:1}},"-Oz":{value:{optimizeLevel:0,shrinkLevel:2}},"-O0":{value:{optimizeLevel:0,shrinkLevel:0}},"-O1":{value:{optimizeLevel:1,shrinkLevel:0}},"-O2":{value:{optimizeLevel:2,shrinkLevel:0}},"-O3":{value:{optimizeLevel:3,shrinkLevel:0}},"-O0s":{value:{optimizeLevel:0,shrinkLevel:1}},"-O1s":{value:{optimizeLevel:1,shrinkLevel:1}},"-O2s":{value:{optimizeLevel:2,shrinkLevel:1}},"-O3s":{value:{optimizeLevel:3,shrinkLevel:1}},"-O0z":{value:{optimizeLevel:0,shrinkLevel:2}},"-O1z":{value:{optimizeLevel:1,shrinkLevel:2}},"-O2z":{value:{optimizeLevel:2,shrinkLevel:2}},"-O3z":{value:{optimizeLevel:3,shrinkLevel:2}},"-Ospeed":{value:{optimizeLevel:3,shrinkLevel:0}},"-Osize":{value:{optimizeLevel:0,shrinkLevel:2,converge:!0}},"--measure":{value:{stats:!0}}},Ae="~lib/",_e={array:`/// <reference path="./rt/index.d.ts" />
8
+ `,o={},f=[];Object.keys(e).forEach(b=>{var p=e[b];if(p.description!=null){for(var g="";g.length<n;)g+=" ";for(g+="--"+b,p.alias&&(g+=", -"+p.alias);g.length<a;)g+=" ";var y;!t.noCategories&&p.category?(y=o[p.category])||(o[p.category]=y=[]):y=f,Array.isArray(p.description)?y.push(g+p.description[0]+p.description.slice(1).map(m=>{for(let i=0;i<a;++i)m=" "+m;return s+m}).join("")):y.push(g+p.description)}});var c=[],x=!1;return Object.keys(o).forEach(b=>{x=!0,c.push(s+" "+Tn.gray(b)+s),c.push(o[b].join(s))}),x&&f.length&&c.push(s+" "+Tn.gray("Other")+s),c.push(f.join(s)),c.join(s)}function ye(e,t){if(e!=null)switch(t){case void 0:case"b":return!!e;case"i":return Math.trunc(e)||0;case"f":return Number(e)||0;case"s":return e===!0?"":e===!1?null:String(e);case"I":return Array.isArray(e)||(e=[e]),e.map(n=>Math.trunc(n)||0);case"F":return Array.isArray(e)||(e=[e]),e.map(n=>Number(n)||0);case"S":return Array.isArray(e)||(e=[e]),e.map(String)}}function Mn(e,t,n,a){let s={};for(let[o,{type:f,mutuallyExclusive:c,isPath:x,useNodeResolution:b,cliOnly:p}]of Object.entries(e)){let g=ye(t[o],f),y=ye(n[o],f);if(g==null){if(y!=null){if(p)continue;if(Array.isArray(y)){let m;x&&(y=y.map(i=>tn(i,a,b))),c!=null&&(m=t[c])?s[o]=y.filter(i=>!m.includes(i)):s[o]=y.slice()}else x&&(y=tn(y,a,b)),s[o]=y}}else if(y==null)Array.isArray(g)?s[o]=g.slice():s[o]=g;else if(Array.isArray(g)){if(p){s[o]=g.slice();continue}let m;x&&(y=y.map(i=>tn(i,a,b))),c!=null&&(m=t[c])?s[o]=[...g,...y.filter(i=>!g.includes(i)&&!m.includes(i))]:s[o]=[...g,...y.filter(i=>!g.includes(i))]}else s[o]=g}return s}function Et(e){let t=A.parse(e);return t.root||(t.root="./"),A.format(t)}function tn(e,t,n=!1){return A.isAbsolute(e)?e:n&&!e.startsWith(".")&&be.resolve?be.resolve(e,{paths:[t]}):Et(A.join(t,e))}function Pn(e,t){for(let[n,{default:a}]of Object.entries(e))t[n]==null&&a!=null&&(t[n]=a)}var Ee="0.1.43",Y={version:{category:"General",description:"Prints just the compiler's version and exits.",type:"b",alias:"v"},help:{category:"General",description:"Prints this message and exits.",type:"b",alias:"h"},config:{category:"General",description:"Configuration file to apply. CLI arguments take precedence.",type:"s",cliOnly:!0},target:{category:"General",description:"Configuration file target to use. Defaults to 'release'.",type:"s",cliOnly:!0},targetMode:{category:"General",description:"Toil compile surface mode: 'hot' (request/stream) or 'cold' (daemon). Omit for the default request artifact.",type:"s"},noConfigEntries:{category:"General",description:"Ignore the toilconfig 'entries' array and compile ONLY the entry files given on the command line. Used by the toiljs multi-artifact build, which hands each pass (request/stream/daemon) its own entry subset.",type:"b"},optimize:{category:"Optimization",description:["Optimizes the module. Typical shorthands are:",""," Default optimizations -O"," Make a release build -O --noAssert"," Make a debug build --debug"," Optimize for speed -Ospeed"," Optimize for size -Osize",""],type:"b",alias:"O"},optimizeLevel:{category:"Optimization",description:"How much to focus on optimizing code. [0-3]",type:"i"},shrinkLevel:{category:"Optimization",description:"How much to focus on shrinking code size. [0-2, s=1, z=2]",type:"i"},converge:{category:"Optimization",description:"Re-optimizes until no further improvements can be made.",type:"b",default:!1},noAssert:{category:"Optimization",description:"Replaces assertions with just their value without trapping.",type:"b",default:!1},outFile:{category:"Output",description:"Specifies the WebAssembly output file (.wasm).",type:"s",alias:"o",isPath:!0},textFile:{category:"Output",description:"Specifies the WebAssembly text output file (.wat).",type:"s",alias:"t",isPath:!0},rpcModule:{category:"Output",description:"Emits a .ts module: the @data codec + the typed client-callable Server surface.",type:"s",isPath:!0},rpcRuntime:{category:"Output",description:"Import specifier for the DataWriter/DataReader codec in the emitted RPC module.",type:"s",default:"toiljs/io"},bindings:{category:"Output",description:["Specifies the bindings to generate (.js + .d.ts).",""," esm JavaScript bindings & typings for ESM integration."," raw Like esm, but exports just the instantiate function."," Useful where modules are meant to be instantiated"," multiple times or non-ESM imports must be provided."],type:"S",alias:"b"},sourceMap:{category:"Debugging",description:["Enables source map generation. Optionally takes the URL","used to reference the source map from the binary file."],type:"s"},uncheckedBehavior:{category:"Debugging",description:["Changes the behavior of unchecked() expressions.","Using this option can potentially cause breakage.",""," default The default behavior: unchecked operations are"," only used inside of unchecked()."," never Unchecked operations are never used, even when"," inside of unchecked()."," always Unchecked operations are always used if possible,"," whether or not unchecked() is used."],type:"s",default:"default"},debug:{category:"Debugging",description:"Enables debug information in emitted binaries.",type:"b",default:!1},importMemory:{category:"Features",description:"Imports the memory from 'env.memory'.",type:"b",default:!1},noExportMemory:{category:"Features",description:"Does not export the memory as 'memory'.",type:"b",default:!1},initialMemory:{category:"Features",description:"Sets the initial memory size in pages.",type:"i",default:0},maximumMemory:{category:"Features",description:"Sets the maximum memory size in pages.",type:"i",default:0},sharedMemory:{category:"Features",description:"Declare memory as shared. Requires maximumMemory.",type:"b",default:!1},zeroFilledMemory:{category:"Features",description:"Assume imported memory is zeroed. Requires importMemory.",type:"b",default:!1},importTable:{category:"Features",description:"Imports the function table from 'env.table'.",type:"b",default:!1},exportTable:{category:"Features",description:"Exports the function table as 'table'.",type:"b",default:!1},exportStart:{category:"Features",description:["Exports the start function using the specified name instead","of calling it implicitly. Useful to obtain the exported memory","before executing any code accessing it."],type:"s"},runtime:{category:"Features",description:["Specifies the runtime variant to include in the program.",""," incremental TLSF + incremental GC (default)"," minimal TLSF + lightweight GC invoked externally"," stub Minimal runtime stub (never frees)"," ... Path to a custom runtime implementation",""],type:"s",default:"incremental"},exportRuntime:{category:"Features",description:["Always exports the runtime helpers (__new, __collect, __pin etc.).","Automatically determined when generation of --bindings is enabled."],type:"b",default:!1},stackSize:{category:"Features",description:["Overrides the stack size. Only relevant for incremental GC","or when using a custom runtime that requires stack space.","Defaults to 0 without and to 32768 with incremental GC."],default:0,type:"i"},enable:{category:"Features",description:["Enables WebAssembly features being disabled by default.",""," threads Threading and atomic operations."," simd SIMD types and operations."," reference-types Reference types and operations."," gc Garbage collection (WIP)."," stringref String reference types."," relaxed-simd Relaxed SIMD operations.",""],TODO_doesNothingYet:[" exception-handling Exception handling."," tail-calls Tail call operations."," multi-value Multi value types."," memory64 Memory64 operations."," extended-const Extended const expressions."],type:"S",mutuallyExclusive:"disable"},disable:{category:"Features",description:["Disables WebAssembly features being enabled by default.",""," mutable-globals Mutable global imports and exports."," sign-extension Sign-extension operations"," nontrapping-f2i Non-trapping float to integer ops."," bulk-memory Bulk memory operations.",""],type:"S",mutuallyExclusive:"enable"},use:{category:"Features",description:["Aliases a global object under another name, e.g., to switch","the default 'Math' implementation used: --use Math=JSMath","Can also be used to introduce an integer constant."],type:"S",alias:"u"},lowMemoryLimit:{category:"Features",description:"Enforces very low (<64k) memory constraints.",default:0,type:"i"},memoryBase:{category:"Linking",description:"Sets the start offset of emitted memory segments.",type:"i",default:0},tableBase:{category:"Linking",description:"Sets the start offset of emitted table elements.",type:"i",default:0},transform:{category:"API",description:"Specifies the path to a custom transform to load.",type:"S",isPath:!0,useNodeResolution:!0},trapMode:{category:"Binaryen",description:["Sets the trap mode to use.",""," allow Allow trapping operations. This is the default."," clamp Replace trapping operations with clamping semantics."," js Replace trapping operations with JS semantics.",""],type:"s",default:"allow"},runPasses:{category:"Binaryen",description:["Specifies additional Binaryen passes to run after other","optimizations, if any. See: Binaryen/src/passes/pass.cpp"],type:"s"},noValidate:{category:"Binaryen",description:"Skips validating the module using Binaryen.",type:"b",default:!1},baseDir:{description:"Specifies the base directory of input and output files.",type:"s",default:"."},noColors:{description:"Disables terminal colors.",type:"b",default:!1},noUnsafe:{description:["Disallows the use of unsafe features in user code.","Does not affect library files and external modules."],type:"b",default:!1},disableWarning:{description:["Disables warnings matching the given diagnostic code.","If no diagnostic code is given, all warnings are disabled."],type:"I"},noEmit:{description:"Performs compilation as usual but does not emit code.",type:"b",default:!1},showConfig:{description:"Print computed compiler options and exit.",type:"b",default:!1},stats:{description:"Prints statistics on I/O and compile times.",type:"b",default:!1},pedantic:{description:"Make yourself sad for no good reason.",type:"b",default:!1},lib:{description:["Adds one or multiple paths to custom library components and","uses exports of all top-level files at this path as globals."],type:"S",isPath:!0},path:{description:["Adds one or multiple paths to package resolution, similar","to node_modules. Prefers an 'ascMain' entry in a package's","package.json and falls back to an inner 'assembly/' folder."],type:"S",isPath:!0},wasm:{description:"Uses the specified Wasm binary of the compiler.",type:"s"}," ...":{description:"Specifies node.js options (CLI only). See: node --help"},"-Os":{value:{optimizeLevel:0,shrinkLevel:1}},"-Oz":{value:{optimizeLevel:0,shrinkLevel:2}},"-O0":{value:{optimizeLevel:0,shrinkLevel:0}},"-O1":{value:{optimizeLevel:1,shrinkLevel:0}},"-O2":{value:{optimizeLevel:2,shrinkLevel:0}},"-O3":{value:{optimizeLevel:3,shrinkLevel:0}},"-O0s":{value:{optimizeLevel:0,shrinkLevel:1}},"-O1s":{value:{optimizeLevel:1,shrinkLevel:1}},"-O2s":{value:{optimizeLevel:2,shrinkLevel:1}},"-O3s":{value:{optimizeLevel:3,shrinkLevel:1}},"-O0z":{value:{optimizeLevel:0,shrinkLevel:2}},"-O1z":{value:{optimizeLevel:1,shrinkLevel:2}},"-O2z":{value:{optimizeLevel:2,shrinkLevel:2}},"-O3z":{value:{optimizeLevel:3,shrinkLevel:2}},"-Ospeed":{value:{optimizeLevel:3,shrinkLevel:0}},"-Osize":{value:{optimizeLevel:0,shrinkLevel:2,converge:!0}},"--measure":{value:{stats:!0}}},Ae="~lib/",_e={array:`/// <reference path="./rt/index.d.ts" />
9
9
 
10
10
  import { BLOCK_MAXSIZE } from "./rt/common";
11
11
  import { Runtime } from "shared/runtime";