toilscript 0.1.5 → 0.1.7
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/dist/cli.js +529 -279
- package/dist/cli.js.map +2 -2
- package/dist/importmap.json +2 -2
- package/dist/web.js +3 -3
- package/package.json +3 -2
- package/std/assembly/bignum/NOTICE +5 -11
- package/std/assembly/bignum.ts +2 -2
- package/std/assembly/index.d.ts +1 -258
- package/std/assembly/json.ts +523 -0
- package/std/assembly/toilscript.d.ts +273 -0
- package/std/assembly/toilscript.ts +0 -16
package/dist/cli.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Copyright 2026 Daniel Wirtz / The ToilScript Authors
|
|
5
5
|
* SPDX-License-Identifier: Apache-2.0
|
|
6
6
|
*/
|
|
7
|
-
var se=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames;var Me=Object.prototype.hasOwnProperty;var fn=(e,t)=>()=>(e&&(t=e(e=0)),t);var Q=(e,t)=>{for(var n in t)se(e,n,{get:t[n],enumerable:!0})},ae=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ue(t))!Me.call(e,s)&&s!==n&&se(e,s,{get:()=>t[s],enumerable:!(a=Ne(t,s))||a.enumerable});return e},Dn=(e,t,n)=>(ae(e,t,"default"),n&&ae(n,t,"default"));var le={};Q(le,{promises:()=>Pe});var Pe,ue=fn(()=>{"use strict";Pe={}});var fe={};Q(fe,{createRequire:()=>Ve});function Ve(){return function(t){throw new Error(`Cannot find module: '${t}'`)}}var ce=fn(()=>{"use strict"});var On={};Q(On,{argv:()=>Xe,cwd:()=>In,exit:()=>He,hrtime:()=>qe,platform:()=>je,umask:()=>Ge});function In(){return"."}function Ge(){return 0}function He(e=0){throw Error(`exit ${e}`)}function qe(e){var t=Ke.call(de),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 je,Xe,de,Ke,Ln=fn(()=>{"use strict";je="linux";Xe=[];de=globalThis.performance||{},Ke=de.now||function(){return new Date().getTime()}});var Rn={};Q(Rn,{basename:()=>Qe,delimiter:()=>it,dirname:()
|
|
8
|
-
`,r={},u=[];Object.keys(e).forEach(b=>{var d=e[b];if(d.description!=null){for(var g="";g.length<n;)g+=" ";for(g+="--"+b,d.alias&&(g+=", -"+d.alias);g.length<a;)g+=" ";var y;!t.noCategories&&d.category?(y=r[d.category])||(r[d.category]=y=[]):y=u,Array.isArray(d.description)?y.push(g+d.description[0]+d.description.slice(1).map(m=>{for(let i=0;i<a;++i)m=" "+m;return s+m}).join("")):y.push(g+d.description)}});var f=[],p=!1;return Object.keys(r).forEach(b=>{p=!0,f.push(s+" "+_n.gray(b)+s),f.push(r[b].join(s))}),p&&u.length&&f.push(s+" "+_n.gray("Other")+s),f.push(u.join(s)),f.join(s)}function be(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 Un(e,t,n,a){let s={};for(let[r,{type:u,mutuallyExclusive:f,isPath:p,useNodeResolution:b,cliOnly:d}]of Object.entries(e)){let g=be(t[r],u),y=be(n[r],u);if(g==null){if(y!=null){if(d)continue;if(Array.isArray(y)){let m;p&&(y=y.map(i=>en(i,a,b))),f!=null&&(m=t[f])?s[r]=y.filter(i=>!m.includes(i)):s[r]=y.slice()}else p&&(y=en(y,a,b)),s[r]=y}}else if(y==null)Array.isArray(g)?s[r]=g.slice():s[r]=g;else if(Array.isArray(g)){if(d){s[r]=g.slice();continue}let m;p&&(y=y.map(i=>en(i,a,b))),f!=null&&(m=t[f])?s[r]=[...g,...y.filter(i=>!g.includes(i)&&!m.includes(i))]:s[r]=[...g,...y.filter(i=>!g.includes(i))]}else s[r]=g}return s}function Ft(e){let t=v.parse(e);return t.root||(t.root="./"),v.format(t)}function en(e,t,n=!1){return v.isAbsolute(e)?e:n&&!e.startsWith(".")&&me.resolve?me.resolve(e,{paths:[t]}):Ft(v.join(t,e))}function Mn(e,t){for(let[n,{default:a}]of Object.entries(e))t[n]==null&&a!=null&&(t[n]=a)}var ve="0.1.5",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},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},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}}},Ee="~lib/",Ae={array:`/// <reference path="./rt/index.d.ts" />
|
|
7
|
+
var se=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames;var Me=Object.prototype.hasOwnProperty;var fn=(e,t)=>()=>(e&&(t=e(e=0)),t);var Q=(e,t)=>{for(var n in t)se(e,n,{get:t[n],enumerable:!0})},ae=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ue(t))!Me.call(e,s)&&s!==n&&se(e,s,{get:()=>t[s],enumerable:!(a=Ne(t,s))||a.enumerable});return e},Dn=(e,t,n)=>(ae(e,t,"default"),n&&ae(n,t,"default"));var le={};Q(le,{promises:()=>Pe});var Pe,ue=fn(()=>{"use strict";Pe={}});var fe={};Q(fe,{createRequire:()=>Ve});function Ve(){return function(t){throw new Error(`Cannot find module: '${t}'`)}}var ce=fn(()=>{"use strict"});var On={};Q(On,{argv:()=>Xe,cwd:()=>In,exit:()=>He,hrtime:()=>qe,platform:()=>je,umask:()=>Ge});function In(){return"."}function Ge(){return 0}function He(e=0){throw Error(`exit ${e}`)}function qe(e){var t=Ke.call(de),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 je,Xe,de,Ke,Ln=fn(()=>{"use strict";je="linux";Xe=[];de=globalThis.performance||{},Ke=de.now||function(){return new Date().getTime()}});var Rn={};Q(Rn,{basename:()=>Qe,delimiter:()=>it,dirname:()=>$e,extname:()=>nt,format:()=>et,isAbsolute:()=>Ye,join:()=>Je,normalize:()=>pe,parse:()=>tt,relative:()=>Ze,resolve:()=>cn,sep:()=>kn,win32:()=>rt});function V(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function xe(e,t){for(var n="",a=0,s=-1,r=0,u,f=0;f<=e.length;++f){if(f<e.length)u=e.charCodeAt(f);else{if(u===47)break;u=47}if(u===47){if(!(s===f-1||r===1))if(s!==f-1&&r===2){if(n.length<2||a!==2||n.charCodeAt(n.length-1)!==46||n.charCodeAt(n.length-2)!==46){if(n.length>2){var p=n.lastIndexOf("/");if(p!==n.length-1){p===-1?(n="",a=0):(n=n.slice(0,p),a=n.length-1-n.lastIndexOf("/")),s=f,r=0;continue}}else if(n.length===2||n.length===1){n="",a=0,s=f,r=0;continue}}t&&(n.length>0?n+="/..":n="..",a=2)}else n.length>0?n+="/"+e.slice(s+1,f):n=e.slice(s+1,f),a=f-s-1;s=f,r=0}else u===46&&r!==-1?++r:r=-1}return n}function We(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 cn(){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=In()),s=n),V(s),s.length!==0&&(e=s+"/"+e,t=s.charCodeAt(0)===47)}return e=xe(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."}function pe(e){if(V(e),e.length===0)return".";var t=e.charCodeAt(0)===47,n=e.charCodeAt(e.length-1)===47;return e=xe(e,!t),e.length===0&&!t&&(e="."),e.length>0&&n&&(e+="/"),t?"/"+e:e}function Ye(e){return V(e),e.length>0&&e.charCodeAt(0)===47}function Je(){if(arguments.length===0)return".";for(var e,t=0;t<arguments.length;++t){var n=arguments[t];V(n),n.length>0&&(e===void 0?e=n:e+="/"+n)}return e===void 0?".":pe(e)}function Ze(e,t){if(V(e),V(t),e===t||(e=cn(e),t=cn(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,r=1;r<t.length&&t.charCodeAt(r)===47;++r);for(var u=t.length,f=u-r,p=s<f?s:f,b=-1,d=0;d<=p;++d){if(d===p){if(f>p){if(t.charCodeAt(r+d)===47)return t.slice(r+d+1);if(d===0)return t.slice(r+d)}else s>p&&(e.charCodeAt(n+d)===47?b=d:d===0&&(b=0));break}var g=e.charCodeAt(n+d),y=t.charCodeAt(r+d);if(g!==y)break;g===47&&(b=d)}var m="";for(d=n+b+1;d<=a;++d)(d===a||e.charCodeAt(d)===47)&&(m.length===0?m+="..":m+="/..");return m.length>0?m+t.slice(r+b):(r+=b,t.charCodeAt(r)===47&&++r,t.slice(r))}function $e(e){if(V(e),e.length===0)return".";for(var t=e.charCodeAt(0),n=t===47,a=-1,s=!0,r=e.length-1;r>=1;--r)if(t=e.charCodeAt(r),t===47){if(!s){a=r;break}}else s=!1;return a===-1?n?"/":".":n&&a===1?"//":e.slice(0,a)}function Qe(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');V(e);var n=0,a=-1,s=!0,r;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var u=t.length-1,f=-1;for(r=e.length-1;r>=0;--r){var p=e.charCodeAt(r);if(p===47){if(!s){n=r+1;break}}else f===-1&&(s=!1,f=r+1),u>=0&&(p===t.charCodeAt(u)?--u===-1&&(a=r):(u=-1,a=f))}return n===a?a=f:a===-1&&(a=e.length),e.slice(n,a)}else{for(r=e.length-1;r>=0;--r)if(e.charCodeAt(r)===47){if(!s){n=r+1;break}}else a===-1&&(s=!1,a=r+1);return a===-1?"":e.slice(n,a)}}function nt(e){V(e);for(var t=-1,n=0,a=-1,s=!0,r=0,u=e.length-1;u>=0;--u){var f=e.charCodeAt(u);if(f===47){if(!s){n=u+1;break}continue}a===-1&&(s=!1,a=u+1),f===46?t===-1?t=u:r!==1&&(r=1):t!==-1&&(r=-1)}return t===-1||a===-1||r===0||r===1&&t===a-1&&t===n+1?"":e.slice(t,a)}function et(e){if(e===null||typeof e!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return We("/",e)}function tt(e){V(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 r=-1,u=0,f=-1,p=!0,b=e.length-1,d=0;b>=s;--b){if(n=e.charCodeAt(b),n===47){if(!p){u=b+1;break}continue}f===-1&&(p=!1,f=b+1),n===46?r===-1?r=b:d!==1&&(d=1):r!==-1&&(d=-1)}return r===-1||f===-1||d===0||d===1&&r===f-1&&r===u+1?f!==-1&&(u===0&&a?t.base=t.name=e.slice(1,f):t.base=t.name=e.slice(u,f)):(u===0&&a?(t.name=e.slice(1,r),t.base=e.slice(1,f)):(t.name=e.slice(u,r),t.base=e.slice(u,f)),t.ext=e.slice(r,f)),u>0?t.dir=e.slice(0,u-1):a&&(t.dir="/"),t}var kn,it,rt,Nn=fn(()=>{"use strict";Ln();kn="/",it=":",rt=null});var he={};Q(he,{pathToFileURL:()=>at});function ot(e){return e.replace(/%/g,"%25").replace(/\\/g,"%5C").replace(/\n/g,"%0A").replace(/\r/g,"%0D").replace(/\t/g,"%09")}function at(e){let t=cn(e);e.charCodeAt(e.length-1)===47&&t[t.length-1]!==kn&&(t+="/");let n=new URL("file://");return n.pathname=ot(t),n}var ge=fn(()=>{"use strict";Nn()});var Wn={};Q(Wn,{Stats:()=>Cn,checkDiagnostics:()=>gn,compileString:()=>Bt,configToArguments:()=>qn,createMemoryStream:()=>Hn,default:()=>Wn,defaultOptimizeLevel:()=>Se,defaultShrinkLevel:()=>Be,definitionFiles:()=>St,libraryFiles:()=>X,libraryPrefix:()=>P,main:()=>we,options:()=>zt,tscOptions:()=>wt,version:()=>Xn});var st=Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]",G,sn,v,M,dn;st?(G=await import("fs"),sn=await import("module"),v=await import("path"),M=globalThis.process,dn=await import("url")):(G=await Promise.resolve().then(()=>(ue(),le)),sn=await Promise.resolve().then(()=>(ce(),fe)),v=await Promise.resolve().then(()=>(Nn(),Rn)),M=await Promise.resolve().then(()=>(Ln(),On)),dn=await Promise.resolve().then(()=>(ge(),he)));var An=typeof process<"u"&&process||{},lt=An.env&&"CI"in An.env,ut="\x1B[90m",ft="\x1B[91m",ct="\x1B[92m",dt="\x1B[93m",xt="\x1B[94m",pt="\x1B[95m",ht="\x1B[96m",gt="\x1B[97m",W="\x1B[0m",nn=class{constructor(t){this.stream=t,this.enabled=!!(this.stream&&this.stream.isTTY||lt)}gray(t){return this.enabled?ut+t+W:t}red(t){return this.enabled?ft+t+W:t}green(t){return this.enabled?ct+t+W:t}yellow(t){return this.enabled?dt+t+W:t}blue(t){return this.enabled?xt+t+W:t}magenta(t){return this.enabled?pt+t+W:t}cyan(t){return this.enabled?ht+t+W:t}white(t){return this.enabled?gt+t+W:t}},_n=new nn(An.stdout),Ot=new nn(An.stderr);function mt(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 bt(e,t,n){var a=n-t;if(a<1)return"";for(var s=null,r=[],u=0,f;t<n;)f=e[t++],f<128?r[u++]=f:f>191&&f<224?r[u++]=(f&31)<<6|e[t++]&63:f>239&&f<365?(f=((f&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,r[u++]=55296+(f>>10),r[u++]=56320+(f&1023)):r[u++]=(f&15)<<12|(e[t++]&63)<<6|e[t++]&63,u>=8192&&((s||(s=[])).push(String.fromCharCode(...r)),u=0);return s?(u&&s.push(String.fromCharCode(...r.slice(0,u))),s.join("")):String.fromCharCode(...r.slice(0,u))}function yt(e,t,n){for(var a=n,s=0,r=e.length;s<r;++s){let u=e.charCodeAt(s),f;u<128?t[n++]=u:u<2048?(t[n++]=u>>6|192,t[n++]=u&63|128):(u&64512)===55296&&s+1<r&&((f=e.charCodeAt(s+1))&64512)===56320?(u=65536+((u&1023)<<10)+(f&1023),++s,t[n++]=u>>18|240,t[n++]=u>>12&63|128,t[n++]=u>>6&63|128,t[n++]=u&63|128):(t[n++]=u>>12|224,t[n++]=u>>6&63|128,t[n++]=u&63|128)}return n-a}var Tn={length:mt,read:bt,write:yt};var me=sn.createRequire(import.meta.url);function ye(e,t,n=!0){var a={},s=[],r=[],u=[],f={};Object.keys(t).forEach(d=>{if(!d.startsWith(" ")){var g=t[d];g.alias!=null&&(typeof g.alias=="string"?f[g.alias]=d:Array.isArray(g.alias)&&g.alias.forEach(y=>f[y]=d)),n&&g.default!=null&&(a[d]=g.default)}});for(var p=0,b=(e=e.slice()).length;p<b;++p){let d=e[p];if(d=="--"){++p;break}let g=/^(?:(-\w)(?:=(.*))?|(--\w{2,})(?:=(.*))?)$/.exec(d),y,m;if(g)t[d]?y=t[m=d]:g[1]!=null?(y=t[m=f[g[1].substring(1)]],y&&g[2]!=null&&(e[p--]=g[2])):g[3]!=null&&(y=t[m=g[3].substring(2)],y&&g[4]!=null&&(e[p--]=g[4]));else if(d.charCodeAt(0)==45)y=t[m=d];else{r.push(d);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(p+1<e.length&&e[p+1].charCodeAt(0)!=45)switch(y.type){case"i":a[m]=parseInt(e[++p],10);break;case"I":a[m]=(a[m]||[]).concat(parseInt(e[++p],10));break;case"f":a[m]=parseFloat(e[++p]);break;case"F":a[m]=(a[m]||[]).concat(parseFloat(e[++p]));break;case"s":a[m]=String(e[++p]);break;case"S":a[m]=(a[m]||[]).concat(e[++p].split(","));break;default:s.push(d),--p}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(d)}else s.push(d)}for(;p<b;)u.push(e[p++]);return n&&Mn(t,a),{options:a,unknown:s,arguments:r,trailing:u}}function Fe(e,t){t||(t={});var n=t.indent||2,a=t.padding||24,s=t.eol||`
|
|
8
|
+
`,r={},u=[];Object.keys(e).forEach(b=>{var d=e[b];if(d.description!=null){for(var g="";g.length<n;)g+=" ";for(g+="--"+b,d.alias&&(g+=", -"+d.alias);g.length<a;)g+=" ";var y;!t.noCategories&&d.category?(y=r[d.category])||(r[d.category]=y=[]):y=u,Array.isArray(d.description)?y.push(g+d.description[0]+d.description.slice(1).map(m=>{for(let i=0;i<a;++i)m=" "+m;return s+m}).join("")):y.push(g+d.description)}});var f=[],p=!1;return Object.keys(r).forEach(b=>{p=!0,f.push(s+" "+_n.gray(b)+s),f.push(r[b].join(s))}),p&&u.length&&f.push(s+" "+_n.gray("Other")+s),f.push(u.join(s)),f.join(s)}function be(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 Un(e,t,n,a){let s={};for(let[r,{type:u,mutuallyExclusive:f,isPath:p,useNodeResolution:b,cliOnly:d}]of Object.entries(e)){let g=be(t[r],u),y=be(n[r],u);if(g==null){if(y!=null){if(d)continue;if(Array.isArray(y)){let m;p&&(y=y.map(i=>en(i,a,b))),f!=null&&(m=t[f])?s[r]=y.filter(i=>!m.includes(i)):s[r]=y.slice()}else p&&(y=en(y,a,b)),s[r]=y}}else if(y==null)Array.isArray(g)?s[r]=g.slice():s[r]=g;else if(Array.isArray(g)){if(d){s[r]=g.slice();continue}let m;p&&(y=y.map(i=>en(i,a,b))),f!=null&&(m=t[f])?s[r]=[...g,...y.filter(i=>!g.includes(i)&&!m.includes(i))]:s[r]=[...g,...y.filter(i=>!g.includes(i))]}else s[r]=g}return s}function Ft(e){let t=v.parse(e);return t.root||(t.root="./"),v.format(t)}function en(e,t,n=!1){return v.isAbsolute(e)?e:n&&!e.startsWith(".")&&me.resolve?me.resolve(e,{paths:[t]}):Ft(v.join(t,e))}function Mn(e,t){for(let[n,{default:a}]of Object.entries(e))t[n]==null&&a!=null&&(t[n]=a)}var ve="0.1.7",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},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},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}}},Ee="~lib/",Ae={array:`/// <reference path="./rt/index.d.ts" />
|
|
9
9
|
|
|
10
10
|
import { BLOCK_MAXSIZE } from "./rt/common";
|
|
11
11
|
import { Runtime } from "shared/runtime";
|
|
@@ -759,8 +759,8 @@ export namespace Atomics {
|
|
|
759
759
|
return size == 1 || size == 2 || size == 4;
|
|
760
760
|
}
|
|
761
761
|
}
|
|
762
|
-
`,bignum:`// Big integer types (u128 / i128 / u256),
|
|
763
|
-
//
|
|
762
|
+
`,bignum:`// Big integer types (u128 / i128 / u256), implemented under ./bignum
|
|
763
|
+
// (Apache-2.0; see ./bignum/LICENSE).
|
|
764
764
|
//
|
|
765
765
|
// This file is a top-level standard-library entry, so toilscript globalizes its
|
|
766
766
|
// named re-exports the same way it does Array/Map/String. That makes u128, i128
|
|
@@ -9138,6 +9138,529 @@ export abstract class Iterator<T> {
|
|
|
9138
9138
|
return <bool>(this & 1);
|
|
9139
9139
|
}
|
|
9140
9140
|
}
|
|
9141
|
+
`,json:`/**
|
|
9142
|
+
* JSON for the ToilScript standard library.
|
|
9143
|
+
*
|
|
9144
|
+
* \`JSON\` is a zero-import global (this is a top-level library entry). It is both
|
|
9145
|
+
* a dynamic value tree (\`JSON.obj().set(...)\`, \`JSON.arr().push(...)\`, returned
|
|
9146
|
+
* from a \`toJSON(): JSON\` method, or produced by \`JSON.parse\`), and the home of
|
|
9147
|
+
* the typed serializer \`JSON.stringify<T>\`.
|
|
9148
|
+
*
|
|
9149
|
+
* Booleans, integers (signed i64 and unsigned u64), floats (NaN/\xB1Infinity emit
|
|
9150
|
+
* \`null\`), strings, null, arrays and objects are supported. Malformed \`parse\`
|
|
9151
|
+
* input yields an error value (\`isError()\`), never a trap.
|
|
9152
|
+
*/
|
|
9153
|
+
|
|
9154
|
+
export class JSON {
|
|
9155
|
+
// ---- value kinds ----
|
|
9156
|
+
private static readonly NULL: u8 = 0;
|
|
9157
|
+
private static readonly BOOL: u8 = 1;
|
|
9158
|
+
private static readonly NUM: u8 = 2;
|
|
9159
|
+
private static readonly STR: u8 = 3;
|
|
9160
|
+
private static readonly ARR: u8 = 4;
|
|
9161
|
+
private static readonly OBJ: u8 = 5;
|
|
9162
|
+
private static readonly ERR: u8 = 6;
|
|
9163
|
+
|
|
9164
|
+
// number sub-kinds
|
|
9165
|
+
private static readonly N_I64: u8 = 0;
|
|
9166
|
+
private static readonly N_U64: u8 = 1;
|
|
9167
|
+
private static readonly N_F64: u8 = 2;
|
|
9168
|
+
|
|
9169
|
+
kind: u8 = JSON.NULL;
|
|
9170
|
+
private b: bool = false;
|
|
9171
|
+
private inum: i64 = 0;
|
|
9172
|
+
private unum: u64 = 0;
|
|
9173
|
+
private fnum: f64 = 0;
|
|
9174
|
+
private numKind: u8 = JSON.N_I64;
|
|
9175
|
+
private str: string = "";
|
|
9176
|
+
private items: Array<JSON> | null = null; // ARR
|
|
9177
|
+
private keys: Array<string> | null = null; // OBJ
|
|
9178
|
+
private vals: Array<JSON> | null = null; // OBJ
|
|
9179
|
+
|
|
9180
|
+
// ---- value factories ----
|
|
9181
|
+
|
|
9182
|
+
static nul(): JSON {
|
|
9183
|
+
return new JSON();
|
|
9184
|
+
}
|
|
9185
|
+
|
|
9186
|
+
/** Wrap a scalar (boolean, signed/unsigned integer, float or string). */
|
|
9187
|
+
static of<T>(value: T): JSON {
|
|
9188
|
+
const j = new JSON();
|
|
9189
|
+
if (isBoolean<T>()) {
|
|
9190
|
+
j.kind = JSON.BOOL;
|
|
9191
|
+
j.b = value;
|
|
9192
|
+
} else if (isInteger<T>()) {
|
|
9193
|
+
j.kind = JSON.NUM;
|
|
9194
|
+
if (isSigned<T>()) {
|
|
9195
|
+
j.numKind = JSON.N_I64;
|
|
9196
|
+
j.inum = <i64>value;
|
|
9197
|
+
} else {
|
|
9198
|
+
j.numKind = JSON.N_U64;
|
|
9199
|
+
j.unum = <u64>value;
|
|
9200
|
+
}
|
|
9201
|
+
} else if (isFloat<T>()) {
|
|
9202
|
+
j.kind = JSON.NUM;
|
|
9203
|
+
j.numKind = JSON.N_F64;
|
|
9204
|
+
j.fnum = <f64>value;
|
|
9205
|
+
} else if (isString<T>()) {
|
|
9206
|
+
j.kind = JSON.STR;
|
|
9207
|
+
j.str = changetype<string>(value);
|
|
9208
|
+
} else {
|
|
9209
|
+
ERROR("JSON.of: expected a boolean, number or string");
|
|
9210
|
+
}
|
|
9211
|
+
return j;
|
|
9212
|
+
}
|
|
9213
|
+
|
|
9214
|
+
static arr(): JSON {
|
|
9215
|
+
const j = new JSON();
|
|
9216
|
+
j.kind = JSON.ARR;
|
|
9217
|
+
j.items = new Array<JSON>();
|
|
9218
|
+
return j;
|
|
9219
|
+
}
|
|
9220
|
+
|
|
9221
|
+
static obj(): JSON {
|
|
9222
|
+
const j = new JSON();
|
|
9223
|
+
j.kind = JSON.OBJ;
|
|
9224
|
+
j.keys = new Array<string>();
|
|
9225
|
+
j.vals = new Array<JSON>();
|
|
9226
|
+
return j;
|
|
9227
|
+
}
|
|
9228
|
+
|
|
9229
|
+
// ---- builders (chainable) ----
|
|
9230
|
+
|
|
9231
|
+
push(value: JSON): JSON {
|
|
9232
|
+
this.items!.push(value);
|
|
9233
|
+
return this;
|
|
9234
|
+
}
|
|
9235
|
+
|
|
9236
|
+
set(key: string, value: JSON): JSON {
|
|
9237
|
+
this.keys!.push(key);
|
|
9238
|
+
this.vals!.push(value);
|
|
9239
|
+
return this;
|
|
9240
|
+
}
|
|
9241
|
+
|
|
9242
|
+
// ---- kind predicates ----
|
|
9243
|
+
isNull(): bool { return this.kind == JSON.NULL; }
|
|
9244
|
+
isBool(): bool { return this.kind == JSON.BOOL; }
|
|
9245
|
+
isNumber(): bool { return this.kind == JSON.NUM; }
|
|
9246
|
+
isString(): bool { return this.kind == JSON.STR; }
|
|
9247
|
+
isArray(): bool { return this.kind == JSON.ARR; }
|
|
9248
|
+
isObject(): bool { return this.kind == JSON.OBJ; }
|
|
9249
|
+
isError(): bool { return this.kind == JSON.ERR; }
|
|
9250
|
+
|
|
9251
|
+
/** The message of an error value, else "". */
|
|
9252
|
+
errorMessage(): string {
|
|
9253
|
+
return this.kind == JSON.ERR ? this.str : "";
|
|
9254
|
+
}
|
|
9255
|
+
|
|
9256
|
+
// ---- scalar accessors (0 / "" off-kind) ----
|
|
9257
|
+
asBool(): bool {
|
|
9258
|
+
return this.kind == JSON.BOOL ? this.b : false;
|
|
9259
|
+
}
|
|
9260
|
+
|
|
9261
|
+
asF64(): f64 {
|
|
9262
|
+
if (this.kind != JSON.NUM) return 0;
|
|
9263
|
+
if (this.numKind == JSON.N_I64) return <f64>this.inum;
|
|
9264
|
+
if (this.numKind == JSON.N_U64) return <f64>this.unum;
|
|
9265
|
+
return this.fnum;
|
|
9266
|
+
}
|
|
9267
|
+
|
|
9268
|
+
asI64(): i64 {
|
|
9269
|
+
if (this.kind != JSON.NUM) return 0;
|
|
9270
|
+
if (this.numKind == JSON.N_I64) return this.inum;
|
|
9271
|
+
if (this.numKind == JSON.N_U64) return <i64>this.unum;
|
|
9272
|
+
return <i64>this.fnum;
|
|
9273
|
+
}
|
|
9274
|
+
|
|
9275
|
+
asU64(): u64 {
|
|
9276
|
+
if (this.kind != JSON.NUM) return 0;
|
|
9277
|
+
if (this.numKind == JSON.N_U64) return this.unum;
|
|
9278
|
+
if (this.numKind == JSON.N_I64) return <u64>this.inum;
|
|
9279
|
+
return <u64>this.fnum;
|
|
9280
|
+
}
|
|
9281
|
+
|
|
9282
|
+
asString(): string {
|
|
9283
|
+
return this.kind == JSON.STR ? this.str : "";
|
|
9284
|
+
}
|
|
9285
|
+
|
|
9286
|
+
// ---- container accessors ----
|
|
9287
|
+
length(): i32 {
|
|
9288
|
+
if (this.kind == JSON.ARR) return this.items!.length;
|
|
9289
|
+
if (this.kind == JSON.OBJ) return this.keys!.length;
|
|
9290
|
+
return 0;
|
|
9291
|
+
}
|
|
9292
|
+
|
|
9293
|
+
/** Element of an array value, or a null value if out of range / not an array. */
|
|
9294
|
+
at(index: i32): JSON {
|
|
9295
|
+
if (this.kind == JSON.ARR) {
|
|
9296
|
+
const items = this.items!;
|
|
9297
|
+
if (index >= 0 && index < items.length) return items[index];
|
|
9298
|
+
}
|
|
9299
|
+
return JSON.nul();
|
|
9300
|
+
}
|
|
9301
|
+
|
|
9302
|
+
has(key: string): bool {
|
|
9303
|
+
if (this.kind == JSON.OBJ) {
|
|
9304
|
+
const keys = this.keys!;
|
|
9305
|
+
for (let i = 0, n = keys.length; i < n; i++) {
|
|
9306
|
+
if (keys[i] == key) return true;
|
|
9307
|
+
}
|
|
9308
|
+
}
|
|
9309
|
+
return false;
|
|
9310
|
+
}
|
|
9311
|
+
|
|
9312
|
+
/** Value of an object key, or a null value if absent / not an object. */
|
|
9313
|
+
get(key: string): JSON {
|
|
9314
|
+
if (this.kind == JSON.OBJ) {
|
|
9315
|
+
const keys = this.keys!;
|
|
9316
|
+
for (let i = 0, n = keys.length; i < n; i++) {
|
|
9317
|
+
if (keys[i] == key) return this.vals![i];
|
|
9318
|
+
}
|
|
9319
|
+
}
|
|
9320
|
+
return JSON.nul();
|
|
9321
|
+
}
|
|
9322
|
+
|
|
9323
|
+
/** Keys of an object value, else an empty array. */
|
|
9324
|
+
objectKeys(): Array<string> {
|
|
9325
|
+
return this.kind == JSON.OBJ ? this.keys! : new Array<string>();
|
|
9326
|
+
}
|
|
9327
|
+
|
|
9328
|
+
// ---- serialize this value to JSON text ----
|
|
9329
|
+
toString(): string {
|
|
9330
|
+
switch (this.kind) {
|
|
9331
|
+
case JSON.BOOL:
|
|
9332
|
+
return this.b ? "true" : "false";
|
|
9333
|
+
case JSON.NUM:
|
|
9334
|
+
if (this.numKind == JSON.N_I64) return this.inum.toString();
|
|
9335
|
+
if (this.numKind == JSON.N_U64) return this.unum.toString();
|
|
9336
|
+
return isFinite(this.fnum) ? this.fnum.toString() : "null";
|
|
9337
|
+
case JSON.STR:
|
|
9338
|
+
return JSON.quote(this.str);
|
|
9339
|
+
case JSON.ARR: {
|
|
9340
|
+
const items = this.items!;
|
|
9341
|
+
const parts = new Array<string>(items.length);
|
|
9342
|
+
for (let i = 0, n = items.length; i < n; i++) parts[i] = items[i].toString();
|
|
9343
|
+
return "[" + parts.join(",") + "]";
|
|
9344
|
+
}
|
|
9345
|
+
case JSON.OBJ: {
|
|
9346
|
+
const keys = this.keys!;
|
|
9347
|
+
const vals = this.vals!;
|
|
9348
|
+
const parts = new Array<string>(keys.length);
|
|
9349
|
+
for (let i = 0, n = keys.length; i < n; i++) {
|
|
9350
|
+
parts[i] = JSON.quote(keys[i]) + ":" + vals[i].toString();
|
|
9351
|
+
}
|
|
9352
|
+
return "{" + parts.join(",") + "}";
|
|
9353
|
+
}
|
|
9354
|
+
default:
|
|
9355
|
+
// NULL and ERR both serialize to null.
|
|
9356
|
+
return "null";
|
|
9357
|
+
}
|
|
9358
|
+
}
|
|
9359
|
+
|
|
9360
|
+
// ---- typed serializer: AS value -> JSON text, by compile-time type ----
|
|
9361
|
+
static stringify<T>(value: T): string {
|
|
9362
|
+
if (isBoolean<T>()) {
|
|
9363
|
+
return value ? "true" : "false";
|
|
9364
|
+
}
|
|
9365
|
+
if (isInteger<T>()) {
|
|
9366
|
+
return value.toString();
|
|
9367
|
+
}
|
|
9368
|
+
if (isFloat<T>()) {
|
|
9369
|
+
return isFinite(value) ? value.toString() : "null";
|
|
9370
|
+
}
|
|
9371
|
+
if (isString<T>()) {
|
|
9372
|
+
if (changetype<usize>(value) == 0) return "null";
|
|
9373
|
+
return JSON.quote(changetype<string>(value));
|
|
9374
|
+
}
|
|
9375
|
+
if (isArray<T>()) {
|
|
9376
|
+
if (changetype<usize>(value) == 0) return "null";
|
|
9377
|
+
const arr = changetype<Array<valueof<T>>>(value);
|
|
9378
|
+
const parts = new Array<string>(arr.length);
|
|
9379
|
+
for (let i = 0, n = arr.length; i < n; i++) parts[i] = JSON.stringify<valueof<T>>(arr[i]);
|
|
9380
|
+
return "[" + parts.join(",") + "]";
|
|
9381
|
+
}
|
|
9382
|
+
ERROR("JSON.stringify: unsupported type, booleans, numbers, strings, null and arrays only");
|
|
9383
|
+
return unreachable();
|
|
9384
|
+
}
|
|
9385
|
+
|
|
9386
|
+
// ---- parse: JSON text -> value tree ----
|
|
9387
|
+
static parse(text: string): JSON {
|
|
9388
|
+
const p = new Parser(text);
|
|
9389
|
+
const v = p.parseValue();
|
|
9390
|
+
if (p.err.length != 0) return JSON.errorValue(p.err);
|
|
9391
|
+
p.skipWs();
|
|
9392
|
+
if (!p.atEnd()) return JSON.errorValue("unexpected trailing characters");
|
|
9393
|
+
return v;
|
|
9394
|
+
}
|
|
9395
|
+
|
|
9396
|
+
static errorValue(message: string): JSON {
|
|
9397
|
+
const j = new JSON();
|
|
9398
|
+
j.kind = JSON.ERR;
|
|
9399
|
+
j.str = message;
|
|
9400
|
+
return j;
|
|
9401
|
+
}
|
|
9402
|
+
|
|
9403
|
+
// internal builders used by the parser to keep number sub-kind exact
|
|
9404
|
+
static fromI64(value: i64): JSON {
|
|
9405
|
+
const j = new JSON();
|
|
9406
|
+
j.kind = JSON.NUM;
|
|
9407
|
+
j.numKind = JSON.N_I64;
|
|
9408
|
+
j.inum = value;
|
|
9409
|
+
return j;
|
|
9410
|
+
}
|
|
9411
|
+
|
|
9412
|
+
static fromU64(value: u64): JSON {
|
|
9413
|
+
const j = new JSON();
|
|
9414
|
+
j.kind = JSON.NUM;
|
|
9415
|
+
j.numKind = JSON.N_U64;
|
|
9416
|
+
j.unum = value;
|
|
9417
|
+
return j;
|
|
9418
|
+
}
|
|
9419
|
+
|
|
9420
|
+
static fromF64(value: f64): JSON {
|
|
9421
|
+
const j = new JSON();
|
|
9422
|
+
j.kind = JSON.NUM;
|
|
9423
|
+
j.numKind = JSON.N_F64;
|
|
9424
|
+
j.fnum = value;
|
|
9425
|
+
return j;
|
|
9426
|
+
}
|
|
9427
|
+
|
|
9428
|
+
static fromString(value: string): JSON {
|
|
9429
|
+
const j = new JSON();
|
|
9430
|
+
j.kind = JSON.STR;
|
|
9431
|
+
j.str = value;
|
|
9432
|
+
return j;
|
|
9433
|
+
}
|
|
9434
|
+
|
|
9435
|
+
// ---- shared string escaping ----
|
|
9436
|
+
|
|
9437
|
+
private static quote(s: string): string {
|
|
9438
|
+
let out = "\\"";
|
|
9439
|
+
for (let i = 0, len = s.length; i < len; i++) {
|
|
9440
|
+
const c = s.charCodeAt(i);
|
|
9441
|
+
if (c == 0x22) out += "\\\\\\"";
|
|
9442
|
+
else if (c == 0x5c) out += "\\\\\\\\";
|
|
9443
|
+
else if (c == 0x08) out += "\\\\b";
|
|
9444
|
+
else if (c == 0x0c) out += "\\\\f";
|
|
9445
|
+
else if (c == 0x0a) out += "\\\\n";
|
|
9446
|
+
else if (c == 0x0d) out += "\\\\r";
|
|
9447
|
+
else if (c == 0x09) out += "\\\\t";
|
|
9448
|
+
else if (c < 0x20) out += "\\\\u" + JSON.hex4(c);
|
|
9449
|
+
else out += String.fromCharCode(c);
|
|
9450
|
+
}
|
|
9451
|
+
return out + "\\"";
|
|
9452
|
+
}
|
|
9453
|
+
|
|
9454
|
+
private static hex4(c: i32): string {
|
|
9455
|
+
const digits = "0123456789abcdef";
|
|
9456
|
+
let r = "";
|
|
9457
|
+
for (let shift = 12; shift >= 0; shift -= 4) r += digits.charAt((c >> shift) & 0xf);
|
|
9458
|
+
return r;
|
|
9459
|
+
}
|
|
9460
|
+
}
|
|
9461
|
+
|
|
9462
|
+
/** Recursive-descent parser producing a \`JSON\` value tree. Internal. */
|
|
9463
|
+
class Parser {
|
|
9464
|
+
private src: string;
|
|
9465
|
+
private pos: i32 = 0;
|
|
9466
|
+
err: string = "";
|
|
9467
|
+
|
|
9468
|
+
constructor(src: string) {
|
|
9469
|
+
this.src = src;
|
|
9470
|
+
}
|
|
9471
|
+
|
|
9472
|
+
atEnd(): bool {
|
|
9473
|
+
return this.pos >= this.src.length;
|
|
9474
|
+
}
|
|
9475
|
+
|
|
9476
|
+
// Always called after an atEnd() guard, so pos is in range.
|
|
9477
|
+
private peek(): i32 {
|
|
9478
|
+
return this.src.charCodeAt(this.pos);
|
|
9479
|
+
}
|
|
9480
|
+
|
|
9481
|
+
private take(): i32 {
|
|
9482
|
+
return this.pos < this.src.length ? this.src.charCodeAt(this.pos++) : -1;
|
|
9483
|
+
}
|
|
9484
|
+
|
|
9485
|
+
skipWs(): void {
|
|
9486
|
+
while (this.pos < this.src.length) {
|
|
9487
|
+
const c = this.src.charCodeAt(this.pos);
|
|
9488
|
+
if (c == 0x20 || c == 0x09 || c == 0x0a || c == 0x0d) this.pos++;
|
|
9489
|
+
else break;
|
|
9490
|
+
}
|
|
9491
|
+
}
|
|
9492
|
+
|
|
9493
|
+
// Callers return as soon as err is set, so fail is only reached with err empty.
|
|
9494
|
+
private fail(message: string): JSON {
|
|
9495
|
+
this.err = message;
|
|
9496
|
+
return JSON.nul();
|
|
9497
|
+
}
|
|
9498
|
+
|
|
9499
|
+
parseValue(): JSON {
|
|
9500
|
+
this.skipWs();
|
|
9501
|
+
if (this.atEnd()) return this.fail("unexpected end of input");
|
|
9502
|
+
const c = this.peek();
|
|
9503
|
+
if (c == 0x7b) return this.parseObject(); // {
|
|
9504
|
+
if (c == 0x5b) return this.parseArray(); // [
|
|
9505
|
+
if (c == 0x22) return JSON.fromString(this.readString()); // "
|
|
9506
|
+
if (c == 0x74) return this.parseLiteral("true", JSON.of<bool>(true)); // t
|
|
9507
|
+
if (c == 0x66) return this.parseLiteral("false", JSON.of<bool>(false)); // f
|
|
9508
|
+
if (c == 0x6e) return this.parseLiteral("null", JSON.nul()); // n
|
|
9509
|
+
if (c == 0x2d || (c >= 0x30 && c <= 0x39)) return this.parseNumber(); // - or digit
|
|
9510
|
+
return this.fail("unexpected character");
|
|
9511
|
+
}
|
|
9512
|
+
|
|
9513
|
+
private parseLiteral(word: string, value: JSON): JSON {
|
|
9514
|
+
for (let i = 0, n = word.length; i < n; i++) {
|
|
9515
|
+
if (this.take() != word.charCodeAt(i)) return this.fail("invalid literal");
|
|
9516
|
+
}
|
|
9517
|
+
return value;
|
|
9518
|
+
}
|
|
9519
|
+
|
|
9520
|
+
/** Read a quoted string starting at the current \`"\`. Sets err on failure. */
|
|
9521
|
+
private readString(): string {
|
|
9522
|
+
this.pos++; // opening "
|
|
9523
|
+
let out = "";
|
|
9524
|
+
while (true) {
|
|
9525
|
+
if (this.atEnd()) {
|
|
9526
|
+
this.fail("unterminated string");
|
|
9527
|
+
return "";
|
|
9528
|
+
}
|
|
9529
|
+
const c = this.take();
|
|
9530
|
+
if (c == 0x22) break; // closing "
|
|
9531
|
+
if (c == 0x5c) {
|
|
9532
|
+
if (this.atEnd()) {
|
|
9533
|
+
this.fail("unterminated escape");
|
|
9534
|
+
return "";
|
|
9535
|
+
}
|
|
9536
|
+
const e = this.take();
|
|
9537
|
+
if (e == 0x22) out += "\\"";
|
|
9538
|
+
else if (e == 0x5c) out += "\\\\";
|
|
9539
|
+
else if (e == 0x2f) out += "/";
|
|
9540
|
+
else if (e == 0x62) out += String.fromCharCode(0x08);
|
|
9541
|
+
else if (e == 0x66) out += String.fromCharCode(0x0c);
|
|
9542
|
+
else if (e == 0x6e) out += "\\n";
|
|
9543
|
+
else if (e == 0x72) out += "\\r";
|
|
9544
|
+
else if (e == 0x74) out += "\\t";
|
|
9545
|
+
else if (e == 0x75) {
|
|
9546
|
+
let code = 0;
|
|
9547
|
+
for (let k = 0; k < 4; k++) {
|
|
9548
|
+
const d = hexVal(this.take());
|
|
9549
|
+
if (d < 0) {
|
|
9550
|
+
this.fail("invalid \\\\u escape");
|
|
9551
|
+
return "";
|
|
9552
|
+
}
|
|
9553
|
+
code = (code << 4) | d;
|
|
9554
|
+
}
|
|
9555
|
+
out += String.fromCharCode(code);
|
|
9556
|
+
} else {
|
|
9557
|
+
this.fail("invalid escape");
|
|
9558
|
+
return "";
|
|
9559
|
+
}
|
|
9560
|
+
} else {
|
|
9561
|
+
out += String.fromCharCode(c);
|
|
9562
|
+
}
|
|
9563
|
+
}
|
|
9564
|
+
return out;
|
|
9565
|
+
}
|
|
9566
|
+
|
|
9567
|
+
private parseNumber(): JSON {
|
|
9568
|
+
const start = this.pos;
|
|
9569
|
+
let isFloating = false;
|
|
9570
|
+
if (this.peek() == 0x2d) this.pos++; // -
|
|
9571
|
+
let intDigits = 0;
|
|
9572
|
+
while (!this.atEnd() && this.peek() >= 0x30 && this.peek() <= 0x39) {
|
|
9573
|
+
this.pos++;
|
|
9574
|
+
intDigits++;
|
|
9575
|
+
}
|
|
9576
|
+
if (intDigits == 0) return this.fail("invalid number");
|
|
9577
|
+
if (!this.atEnd() && this.peek() == 0x2e) {
|
|
9578
|
+
isFloating = true;
|
|
9579
|
+
this.pos++;
|
|
9580
|
+
let frac = 0;
|
|
9581
|
+
while (!this.atEnd() && this.peek() >= 0x30 && this.peek() <= 0x39) {
|
|
9582
|
+
this.pos++;
|
|
9583
|
+
frac++;
|
|
9584
|
+
}
|
|
9585
|
+
if (frac == 0) return this.fail("invalid number");
|
|
9586
|
+
}
|
|
9587
|
+
if (!this.atEnd() && (this.peek() == 0x65 || this.peek() == 0x45)) {
|
|
9588
|
+
isFloating = true;
|
|
9589
|
+
this.pos++;
|
|
9590
|
+
if (!this.atEnd() && (this.peek() == 0x2b || this.peek() == 0x2d)) this.pos++;
|
|
9591
|
+
let exp = 0;
|
|
9592
|
+
while (!this.atEnd() && this.peek() >= 0x30 && this.peek() <= 0x39) {
|
|
9593
|
+
this.pos++;
|
|
9594
|
+
exp++;
|
|
9595
|
+
}
|
|
9596
|
+
if (exp == 0) return this.fail("invalid number");
|
|
9597
|
+
}
|
|
9598
|
+
const slice = this.src.substring(start, this.pos);
|
|
9599
|
+
if (isFloating) return JSON.fromF64(parseFloat(slice));
|
|
9600
|
+
if (slice.charCodeAt(0) == 0x2d) {
|
|
9601
|
+
let v: i64 = 0;
|
|
9602
|
+
for (let i = 1, n = slice.length; i < n; i++) v = v * 10 - <i64>(slice.charCodeAt(i) - 0x30);
|
|
9603
|
+
return JSON.fromI64(v);
|
|
9604
|
+
}
|
|
9605
|
+
let v: u64 = 0;
|
|
9606
|
+
for (let i = 0, n = slice.length; i < n; i++) v = v * 10 + <u64>(slice.charCodeAt(i) - 0x30);
|
|
9607
|
+
return JSON.fromU64(v);
|
|
9608
|
+
}
|
|
9609
|
+
|
|
9610
|
+
private parseArray(): JSON {
|
|
9611
|
+
this.pos++; // [
|
|
9612
|
+
const j = JSON.arr();
|
|
9613
|
+
this.skipWs();
|
|
9614
|
+
if (!this.atEnd() && this.peek() == 0x5d) {
|
|
9615
|
+
this.pos++;
|
|
9616
|
+
return j;
|
|
9617
|
+
}
|
|
9618
|
+
while (true) {
|
|
9619
|
+
const v = this.parseValue();
|
|
9620
|
+
if (this.err.length != 0) return j;
|
|
9621
|
+
j.push(v);
|
|
9622
|
+
this.skipWs();
|
|
9623
|
+
const c = this.take();
|
|
9624
|
+
if (c == 0x5d) break; // ]
|
|
9625
|
+
if (c != 0x2c) return this.fail("expected ',' or ']'"); // ,
|
|
9626
|
+
}
|
|
9627
|
+
return j;
|
|
9628
|
+
}
|
|
9629
|
+
|
|
9630
|
+
private parseObject(): JSON {
|
|
9631
|
+
this.pos++; // {
|
|
9632
|
+
const j = JSON.obj();
|
|
9633
|
+
this.skipWs();
|
|
9634
|
+
if (!this.atEnd() && this.peek() == 0x7d) {
|
|
9635
|
+
this.pos++;
|
|
9636
|
+
return j;
|
|
9637
|
+
}
|
|
9638
|
+
while (true) {
|
|
9639
|
+
this.skipWs();
|
|
9640
|
+
if (this.atEnd() || this.peek() != 0x22) return this.fail("expected string key");
|
|
9641
|
+
const key = this.readString();
|
|
9642
|
+
if (this.err.length != 0) return j;
|
|
9643
|
+
this.skipWs();
|
|
9644
|
+
if (this.take() != 0x3a) return this.fail("expected ':'"); // :
|
|
9645
|
+
const v = this.parseValue();
|
|
9646
|
+
if (this.err.length != 0) return j;
|
|
9647
|
+
j.set(key, v);
|
|
9648
|
+
this.skipWs();
|
|
9649
|
+
const c = this.take();
|
|
9650
|
+
if (c == 0x7d) break; // }
|
|
9651
|
+
if (c != 0x2c) return this.fail("expected ',' or '}'"); // ,
|
|
9652
|
+
}
|
|
9653
|
+
return j;
|
|
9654
|
+
}
|
|
9655
|
+
}
|
|
9656
|
+
|
|
9657
|
+
/** Hex digit value, or -1. Internal. */
|
|
9658
|
+
function hexVal(c: i32): i32 {
|
|
9659
|
+
if (c >= 0x30 && c <= 0x39) return c - 0x30;
|
|
9660
|
+
if (c >= 0x61 && c <= 0x66) return c - 0x61 + 10;
|
|
9661
|
+
if (c >= 0x41 && c <= 0x46) return c - 0x41 + 10;
|
|
9662
|
+
return -1;
|
|
9663
|
+
}
|
|
9141
9664
|
`,map:`/// <reference path="./rt/index.d.ts" />
|
|
9142
9665
|
|
|
9143
9666
|
import { HASH } from "./util/hash";
|
|
@@ -16945,22 +17468,6 @@ export namespace table {
|
|
|
16945
17468
|
throw new Error(E_NOTIMPLEMENTED);
|
|
16946
17469
|
}
|
|
16947
17470
|
}
|
|
16948
|
-
`,toilscript:`/**
|
|
16949
|
-
* ToilScript-native declarations.
|
|
16950
|
-
*
|
|
16951
|
-
* Compiler-level natives available everywhere with no import. \`@main\` is handled
|
|
16952
|
-
* directly by the ToilScript compiler \u2014 it exports the decorated top-level
|
|
16953
|
-
* function as the module's \`main\` entry \u2014 so this declaration exists only so
|
|
16954
|
-
* editors and type-checking recognize the decorator. Future zero-import toil
|
|
16955
|
-
* natives (globals/decorators) belong here too.
|
|
16956
|
-
*/
|
|
16957
|
-
|
|
16958
|
-
/**
|
|
16959
|
-
* Marks a single top-level function as the module entry point. The compiler
|
|
16960
|
-
* exports it as the WebAssembly export \`main\` \u2014 no \`export\` keyword needed.
|
|
16961
|
-
* Exactly one \`@main\` is allowed per module.
|
|
16962
|
-
*/
|
|
16963
|
-
declare function main(): void;
|
|
16964
17471
|
`,typedarray:`import { COMPARATOR, SORT } from "./util/sort";
|
|
16965
17472
|
import { E_INDEXOUTOFRANGE, E_INVALIDLENGTH, E_NOTIMPLEMENTED } from "./util/error";
|
|
16966
17473
|
import { joinIntegerArray, joinFloatArray } from "./util/string";
|
|
@@ -24596,7 +25103,7 @@ export abstract class V128 {
|
|
|
24596
25103
|
*//***/
|
|
24597
25104
|
|
|
24598
25105
|
/// <reference no-default-lib="true"/>
|
|
24599
|
-
/// <reference path="./toilscript.ts" />
|
|
25106
|
+
/// <reference path="./toilscript.d.ts" />
|
|
24600
25107
|
|
|
24601
25108
|
// Types
|
|
24602
25109
|
|
|
@@ -27482,263 +27989,6 @@ declare namespace external {
|
|
|
27482
27989
|
|
|
27483
27990
|
/** Annotates a global for lazy compilation. */
|
|
27484
27991
|
declare function lazy(...args: any[]): any;
|
|
27485
|
-
|
|
27486
|
-
// Big integers \u2014 native globals implemented in std/assembly/bignum (vendored
|
|
27487
|
-
// from @btc-vision/as-bignum). The arithmetic/bitwise/comparison operators
|
|
27488
|
-
// (+ - * / % & | ^ << >> == != < > <= >=) are operator overloads resolved by
|
|
27489
|
-
// the compiler; the equivalent static methods are listed for tooling.
|
|
27490
|
-
|
|
27491
|
-
/** A 128-bit unsigned integer. */
|
|
27492
|
-
declare class u128 {
|
|
27493
|
-
lo: u64;
|
|
27494
|
-
hi: u64;
|
|
27495
|
-
constructor(lo?: u64, hi?: u64);
|
|
27496
|
-
|
|
27497
|
-
static readonly Zero: u128;
|
|
27498
|
-
static readonly One: u128;
|
|
27499
|
-
static readonly Min: u128;
|
|
27500
|
-
static readonly Max: u128;
|
|
27501
|
-
|
|
27502
|
-
static fromString(value: string, radix?: i32): u128;
|
|
27503
|
-
static fromI256(value: i256): u128;
|
|
27504
|
-
static fromU256(value: u256): u128;
|
|
27505
|
-
static fromI128(value: i128): u128;
|
|
27506
|
-
static fromU128(value: u128): u128;
|
|
27507
|
-
static fromI64(value: i64): u128;
|
|
27508
|
-
static fromU64(value: u64): u128;
|
|
27509
|
-
static fromF64(value: f64): u128;
|
|
27510
|
-
static fromF32(value: f32): u128;
|
|
27511
|
-
static fromI32(value: i32): u128;
|
|
27512
|
-
static fromU32(value: u32): u128;
|
|
27513
|
-
static fromBool(value: bool): u128;
|
|
27514
|
-
static fromBits(lo1: u32, lo2: u32, hi1: u32, hi2: u32): u128;
|
|
27515
|
-
static fromBytes<T>(array: T, bigEndian?: bool): u128;
|
|
27516
|
-
static fromBytesLE(array: u8[]): u128;
|
|
27517
|
-
static fromBytesBE(array: u8[]): u128;
|
|
27518
|
-
static fromUint8ArrayLE(array: Uint8Array): u128;
|
|
27519
|
-
static fromUint8ArrayBE(array: Uint8Array): u128;
|
|
27520
|
-
static from<T>(value: T): u128;
|
|
27521
|
-
|
|
27522
|
-
static isEmpty(value: u128): bool;
|
|
27523
|
-
static or(a: u128, b: u128): u128;
|
|
27524
|
-
static xor(a: u128, b: u128): u128;
|
|
27525
|
-
static and(a: u128, b: u128): u128;
|
|
27526
|
-
static shl(value: u128, shift: i32): u128;
|
|
27527
|
-
static shr(value: u128, shift: i32): u128;
|
|
27528
|
-
static shr_u(value: u128, shift: i32): u128;
|
|
27529
|
-
static rotl(value: u128, shift: i32): u128;
|
|
27530
|
-
static rotr(value: u128, shift: i32): u128;
|
|
27531
|
-
static add(a: u128, b: u128): u128;
|
|
27532
|
-
static sub(a: u128, b: u128): u128;
|
|
27533
|
-
static mul(a: u128, b: u128): u128;
|
|
27534
|
-
static div(a: u128, b: u128): u128;
|
|
27535
|
-
static rem(a: u128, b: u128): u128;
|
|
27536
|
-
static div10(value: u128): u128;
|
|
27537
|
-
static rem10(value: u128): u128;
|
|
27538
|
-
static pow(base: u128, exponent: i32): u128;
|
|
27539
|
-
static sqrt(value: u128): u128;
|
|
27540
|
-
static sqr(value: u128): u128;
|
|
27541
|
-
static muldiv(a: u128, b: u128, c: u128): u128;
|
|
27542
|
-
static eq(a: u128, b: u128): bool;
|
|
27543
|
-
static ne(a: u128, b: u128): bool;
|
|
27544
|
-
static lt(a: u128, b: u128): bool;
|
|
27545
|
-
static gt(a: u128, b: u128): bool;
|
|
27546
|
-
static le(a: u128, b: u128): bool;
|
|
27547
|
-
static ge(a: u128, b: u128): bool;
|
|
27548
|
-
static ord(a: u128, b: u128): i32;
|
|
27549
|
-
static popcnt(value: u128): i32;
|
|
27550
|
-
static clz(value: u128): i32;
|
|
27551
|
-
static ctz(value: u128): i32;
|
|
27552
|
-
|
|
27553
|
-
set(value: u128): this;
|
|
27554
|
-
setI64(value: i64): this;
|
|
27555
|
-
setU64(value: u64): this;
|
|
27556
|
-
setI32(value: i32): this;
|
|
27557
|
-
setU32(value: u32): this;
|
|
27558
|
-
isZero(): bool;
|
|
27559
|
-
not(): u128;
|
|
27560
|
-
neg(): u128;
|
|
27561
|
-
pos(): u128;
|
|
27562
|
-
sqr(): this;
|
|
27563
|
-
preInc(): this;
|
|
27564
|
-
preDec(): this;
|
|
27565
|
-
postInc(): u128;
|
|
27566
|
-
postDec(): u128;
|
|
27567
|
-
clone(): u128;
|
|
27568
|
-
as<T>(): T;
|
|
27569
|
-
toI64(): i64;
|
|
27570
|
-
toU64(): u64;
|
|
27571
|
-
toI32(): i32;
|
|
27572
|
-
toU32(): u32;
|
|
27573
|
-
toBool(): bool;
|
|
27574
|
-
toF64(): f64;
|
|
27575
|
-
toF32(): f32;
|
|
27576
|
-
toI128(): i128;
|
|
27577
|
-
toU128(): this;
|
|
27578
|
-
toI256(): i256;
|
|
27579
|
-
toU256(): u256;
|
|
27580
|
-
toBytes(bigEndian?: bool): u8[];
|
|
27581
|
-
toStaticBytes(bigEndian?: bool): StaticArray<u8>;
|
|
27582
|
-
toUint8Array(bigEndian?: bool): Uint8Array;
|
|
27583
|
-
toString(radix?: i32): string;
|
|
27584
|
-
}
|
|
27585
|
-
|
|
27586
|
-
/** A 128-bit signed integer. */
|
|
27587
|
-
declare class i128 {
|
|
27588
|
-
lo: u64;
|
|
27589
|
-
hi: i64;
|
|
27590
|
-
constructor(lo?: u64, hi?: i64);
|
|
27591
|
-
|
|
27592
|
-
static readonly Zero: i128;
|
|
27593
|
-
static readonly One: i128;
|
|
27594
|
-
static readonly Min: i128;
|
|
27595
|
-
static readonly Max: i128;
|
|
27596
|
-
|
|
27597
|
-
static fromString(value: string, radix?: i32): i128;
|
|
27598
|
-
static fromI256(value: i256): i128;
|
|
27599
|
-
static fromU256(value: u256): i128;
|
|
27600
|
-
static fromI128(value: i128): i128;
|
|
27601
|
-
static fromU128(value: u128): i128;
|
|
27602
|
-
static fromI64(value: i64): i128;
|
|
27603
|
-
static fromU64(value: u64): i128;
|
|
27604
|
-
static fromF64(value: f64): i128;
|
|
27605
|
-
static fromF32(value: f32): i128;
|
|
27606
|
-
static fromI32(value: i32): i128;
|
|
27607
|
-
static fromU32(value: u32): i128;
|
|
27608
|
-
static fromBits(lo1: i32, lo2: i32, hi1: i32, hi2: i32): i128;
|
|
27609
|
-
static fromBytes<T>(array: T, bigEndian?: bool): i128;
|
|
27610
|
-
static fromBytesLE(array: u8[]): i128;
|
|
27611
|
-
static fromBytesBE(array: u8[]): i128;
|
|
27612
|
-
static fromUint8ArrayLE(array: Uint8Array): i128;
|
|
27613
|
-
static fromUint8ArrayBE(array: Uint8Array): i128;
|
|
27614
|
-
static from<T>(value: T): i128;
|
|
27615
|
-
|
|
27616
|
-
static isEmpty(value: i128): bool;
|
|
27617
|
-
static or(a: i128, b: i128): i128;
|
|
27618
|
-
static xor(a: i128, b: i128): i128;
|
|
27619
|
-
static and(a: i128, b: i128): i128;
|
|
27620
|
-
static shl(value: i128, shift: i32): i128;
|
|
27621
|
-
static shr_u(value: i128, shift: i32): i128;
|
|
27622
|
-
static add(a: i128, b: i128): i128;
|
|
27623
|
-
static sub(a: i128, b: i128): i128;
|
|
27624
|
-
static eq(a: i128, b: i128): bool;
|
|
27625
|
-
static ne(a: i128, b: i128): bool;
|
|
27626
|
-
static lt(a: i128, b: i128): bool;
|
|
27627
|
-
static gt(a: i128, b: i128): bool;
|
|
27628
|
-
static le(a: i128, b: i128): bool;
|
|
27629
|
-
static ge(a: i128, b: i128): bool;
|
|
27630
|
-
static ord(a: i128, b: i128): i32;
|
|
27631
|
-
static popcnt(value: i128): i32;
|
|
27632
|
-
static clz(value: i128): i32;
|
|
27633
|
-
static ctz(value: i128): i32;
|
|
27634
|
-
static abs(value: i128): i128;
|
|
27635
|
-
|
|
27636
|
-
isNeg(): bool;
|
|
27637
|
-
isPos(): bool;
|
|
27638
|
-
isZero(): bool;
|
|
27639
|
-
not(): i128;
|
|
27640
|
-
neg(): i128;
|
|
27641
|
-
pos(): i128;
|
|
27642
|
-
toBytes(bigEndian?: bool): u8[];
|
|
27643
|
-
toStaticBytes(bigEndian?: bool): StaticArray<u8>;
|
|
27644
|
-
toUint8Array(bigEndian?: bool): Uint8Array;
|
|
27645
|
-
}
|
|
27646
|
-
|
|
27647
|
-
/** A 256-bit unsigned integer. */
|
|
27648
|
-
declare class u256 {
|
|
27649
|
-
lo1: u64;
|
|
27650
|
-
lo2: u64;
|
|
27651
|
-
hi1: u64;
|
|
27652
|
-
hi2: u64;
|
|
27653
|
-
constructor(lo1?: u64, lo2?: u64, hi1?: u64, hi2?: u64);
|
|
27654
|
-
|
|
27655
|
-
static readonly Zero: u256;
|
|
27656
|
-
static readonly One: u256;
|
|
27657
|
-
static readonly Min: u256;
|
|
27658
|
-
static readonly Max: u256;
|
|
27659
|
-
|
|
27660
|
-
static fromU256(value: u256): u256;
|
|
27661
|
-
static fromU128(value: u128): u256;
|
|
27662
|
-
static fromU64(value: u64): u256;
|
|
27663
|
-
static fromI64(value: i64): u256;
|
|
27664
|
-
static fromU32(value: u32): u256;
|
|
27665
|
-
static fromI32(value: i32): u256;
|
|
27666
|
-
static fromBits(l0: u32, l1: u32, l2: u32, l3: u32, h0: u32, h1: u32, h2: u32, h3: u32): u256;
|
|
27667
|
-
static fromBytes<T>(array: T, bigEndian?: bool): u256;
|
|
27668
|
-
static fromBytesLE(array: u8[]): u256;
|
|
27669
|
-
static fromBytesBE(array: u8[]): u256;
|
|
27670
|
-
static fromUint8ArrayLE(array: Uint8Array): u256;
|
|
27671
|
-
static fromUint8ArrayBE(array: Uint8Array): u256;
|
|
27672
|
-
static fromF64(value: f64): u256;
|
|
27673
|
-
static fromF32(value: f32): u256;
|
|
27674
|
-
static from<T>(value: T): u256;
|
|
27675
|
-
static fromString(str: string, radix?: i32): u256;
|
|
27676
|
-
|
|
27677
|
-
static isEmpty(value: u256): bool;
|
|
27678
|
-
static add(a: u256, b: u256): u256;
|
|
27679
|
-
static sub(a: u256, b: u256): u256;
|
|
27680
|
-
static mul(a: u256, b: u256): u256;
|
|
27681
|
-
static or(a: u256, b: u256): u256;
|
|
27682
|
-
static xor(a: u256, b: u256): u256;
|
|
27683
|
-
static and(a: u256, b: u256): u256;
|
|
27684
|
-
static shr(value: u256, shift: i32): u256;
|
|
27685
|
-
static shr_u(value: u256, shift: i32): u256;
|
|
27686
|
-
static eq(a: u256, b: u256): bool;
|
|
27687
|
-
static ne(a: u256, b: u256): bool;
|
|
27688
|
-
static lt(a: u256, b: u256): bool;
|
|
27689
|
-
static gt(a: u256, b: u256): bool;
|
|
27690
|
-
static le(a: u256, b: u256): bool;
|
|
27691
|
-
static ge(a: u256, b: u256): bool;
|
|
27692
|
-
static popcnt(value: u256): i32;
|
|
27693
|
-
static clz(value: u256): i32;
|
|
27694
|
-
static ctz(value: u256): i32;
|
|
27695
|
-
|
|
27696
|
-
set(value: u256): this;
|
|
27697
|
-
setI64(value: i64): this;
|
|
27698
|
-
setU64(value: u64): this;
|
|
27699
|
-
setI32(value: i32): this;
|
|
27700
|
-
setU32(value: u32): this;
|
|
27701
|
-
setU128(value: u128): this;
|
|
27702
|
-
isZero(): bool;
|
|
27703
|
-
not(): u256;
|
|
27704
|
-
neg(): u256;
|
|
27705
|
-
pos(): u256;
|
|
27706
|
-
postInc(): u256;
|
|
27707
|
-
postDec(): u256;
|
|
27708
|
-
clone(): u256;
|
|
27709
|
-
as<T>(): T;
|
|
27710
|
-
toI64(): i64;
|
|
27711
|
-
toU64(): u64;
|
|
27712
|
-
toI32(): i32;
|
|
27713
|
-
toU32(): u32;
|
|
27714
|
-
toBool(): bool;
|
|
27715
|
-
toI128(): i128;
|
|
27716
|
-
toU128(): u128;
|
|
27717
|
-
toU256(): this;
|
|
27718
|
-
toBytes(bigEndian?: bool): u8[];
|
|
27719
|
-
toStaticBytes(bigEndian?: bool): StaticArray<u8>;
|
|
27720
|
-
toUint8Array(bigEndian?: bool): Uint8Array;
|
|
27721
|
-
toString(radix?: i32): string;
|
|
27722
|
-
}
|
|
27723
|
-
|
|
27724
|
-
/** A 256-bit signed integer (backs the signed conversions of the family). */
|
|
27725
|
-
declare class i256 {
|
|
27726
|
-
lo1: i64;
|
|
27727
|
-
lo2: i64;
|
|
27728
|
-
hi1: i64;
|
|
27729
|
-
hi2: i64;
|
|
27730
|
-
constructor(lo1?: i64, lo2?: i64, hi1?: i64, hi2?: i64);
|
|
27731
|
-
|
|
27732
|
-
static readonly Zero: i256;
|
|
27733
|
-
static readonly One: i256;
|
|
27734
|
-
static readonly Min: i256;
|
|
27735
|
-
static readonly Max: i256;
|
|
27736
|
-
|
|
27737
|
-
static isEmpty(value: i256): bool;
|
|
27738
|
-
|
|
27739
|
-
isNeg(): bool;
|
|
27740
|
-
isZero(): bool;
|
|
27741
|
-
}
|
|
27742
27992
|
`,portable:`/**
|
|
27743
27993
|
* Environment definitions for compiling ToilScript to JavaScript using tsc.
|
|
27744
27994
|
*
|
|
@@ -28202,5 +28452,5 @@ declare function offsetof<T>(fieldName?: string): usize;
|
|
|
28202
28452
|
declare function idof<T>(): u32;
|
|
28203
28453
|
`};var xn={};Q(xn,{default:()=>pn});Dn(xn,Mt);import*as Mt from"binaryen";import{default as pn}from"binaryen";import*as At from"toilscript";var h=At,Pn=M.argv.indexOf("--wasm");if(~Pn){let e=String(M.argv[Pn+1]);M.argv.splice(Pn,2),h=await import(new URL(e,dn.pathToFileURL(M.cwd()+"/")))}var Vn=sn.createRequire(import.meta.url),Kn=M.platform==="win32",E=Kn?`\r
|
|
28204
28454
|
`:`
|
|
28205
|
-
`,jn=Kn?"\\":"/",_=".ts",_t=`.d${_}`,hn=new RegExp("\\"+_+"$"),Tt=new RegExp("^(?!.*\\.d\\"+_+"$).*\\"+_+"$");function Te(e){return e.replace(/-/g,"_").toUpperCase()}function Ct(e){return typeof e=="string"&&e!==""}var Xn=ve,zt=Y,P=Ee,X=Ae,Bt=_e,Be=3,we=0;function qn(e,t=[]){return Object.keys(e||{}).forEach(n=>{let a=e[n],s=Y[n];s&&s.type==="b"?a&&t.push(`--${n}`):Array.isArray(a)?a.forEach(r=>{t.push(`--${n}`,String(r))}):t.push(`--${n}`,String(a))}),t}async function wt(e,t={}){typeof e=="string"&&(e={[`input${_}`]:e});let n=["--outFile","binary","--textFile","text"];qn(t,n);let a={},s=await Se(n.concat(Object.keys(e)),{readFile:r=>Object.prototype.hasOwnProperty.call(e,r)?e[r]:null,writeFile:(r,u)=>{a[r]=u},listFiles:()=>[]});return Object.assign(s,a)}async function Se(e,t){Array.isArray(e)||(e=qn(e)),t||(t={});let n=t.stats||new Cn,a=n.begin(),s=0,r=0,u=0,f=(Xn||"").split(".");f.length===3&&(r=parseInt(f[0])|0,s=parseInt(f[1])|0,u=parseInt(f[2])|0);let p=t.stdout||Hn(),b=t.stderr||Hn(),d=t.readFile||ee,g=t.writeFile||te,y=t.listFiles||ie,m=ye(e,Y,!1),i=m.options;e=m.arguments;let zn=new nn(p),j=new nn(b);i.noColors&&(zn.enabled=!1,j.enabled=!1);let Yn=m.unknown;Yn.length&&Yn.forEach(o=>{b.write(`${j.yellow("WARNING ")}Unknown option '${o}'${E}`)});let Zn=m.trailing;Zn.length&&b.write(`${j.yellow("WARNING ")}Unsupported trailing arguments: ${Zn.join(" ")}${E}`);let H=null,k=null,z=(o,l={})=>(o&&b.write(`${j.red("FAILURE ")}${o.stack.replace(/^ERROR: /i,"")}${E}`),k&&k.dispose(),n.total||(n.total=n.end(a)),Object.assign({error:o,stdout:p,stderr:b,stats:n},l));if(i.version)return p.write(`Version ${Xn}${E}`),z(null);let B=v.normalize(i.baseDir||"."),K=en(i.config||"toilconfig.json",B),Bn=v.basename(K),Z=v.dirname(K),R=await Ce(Bn,Z,d),De=R!=null&&Array.isArray(R.entries)&&R.entries.length;if(i.help||!e.length&&!De){let o=i.help?p:b,l=i.help?zn:j;return o.write([l.white("SYNTAX")," "+l.cyan("toilscript")+" [entryFile ...] [options]","",l.white("EXAMPLES")," "+l.cyan("toilscript")+" hello"+_," "+l.cyan("toilscript")+" hello"+_+" -o hello.wasm -t hello.wat"," "+l.cyan("toilscript")+" hello1"+_+" hello2"+_+" -o -O > hello.wasm"," "+l.cyan("toilscript")+" --config toilconfig.json --target release","",l.white("OPTIONS")].concat(Fe(Y,24,E)).join(E)+E),z(null)}if(!(G.promises&&G.promises.readFile)){if(d===ee)throw Error("'options.readFile' must be specified");if(g===te)throw Error("'options.writeFile' must be specified");if(y===ie)throw Error("'options.listFiles' must be specified")}let wn=new Set;wn.add(K);let Ie=i.target||"release";for(;R;){if(R.targets){let l=R.targets[Ie];l&&(i=Un(Y,i,l,Z))}let o=R.options;if(o&&(i=Un(Y,i,o,Z)),R.entries)for(let l of R.entries)e.push(en(l,Z));if(R.extends){if(K=en(R.extends,Z,!0),Bn=v.basename(K),Z=v.dirname(K),wn.has(K))break;wn.add(K),R=await Ce(Bn,Z,d)}else break}if(Mn(Y,i),i.showConfig)return b.write(JSON.stringify({options:i,entries:e},null,2)),z(null);function $n(o){return[...new Set(o)]}let w,tn,mn,T=h.newOptions();switch(i.runtime){case"stub":tn=0;break;case"minimal":tn=1;break;case"memory":tn=3;break;default:tn=2;break}switch(i.uncheckedBehavior){default:mn=0;break;case"never":mn=1;break;case"always":mn=2;break}if(h.setTarget(T,0),h.setDebugInfo(T,!!i.debug),h.setRuntime(T,tn),h.setNoAssert(T,i.noAssert),h.setExportMemory(T,!i.noExportMemory),h.setImportMemory(T,i.importMemory),h.setInitialMemory(T,i.initialMemory>>>0),h.setMaximumMemory(T,i.maximumMemory>>>0),h.setSharedMemory(T,i.sharedMemory),h.setImportTable(T,i.importTable),h.setExportTable(T,i.exportTable),i.exportStart!=null&&h.setExportStart(T,Ct(i.exportStart)?i.exportStart:"_start"),h.setMemoryBase(T,i.memoryBase>>>0),h.setTableBase(T,i.tableBase>>>0),h.setSourceMap(T,i.sourceMap!=null),h.setUncheckedBehavior(T,mn),h.setNoUnsafe(T,i.noUnsafe),h.setPedantic(T,i.pedantic),h.setLowMemoryLimit(T,i.lowMemoryLimit>>>0),h.setExportRuntime(T,i.exportRuntime),h.setBundleVersion(T,r,s,u),!i.stackSize&&tn===2&&(i.stackSize=h.DEFAULT_STACK_SIZE),h.setStackSize(T,i.stackSize),h.setBindingsHint(T,i.bindings&&i.bindings.length>0),i.use){let o=i.use;for(let l=0,c=o.length;l<c;++l){let x=o[l],A=x.indexOf("=");if(A<0)return z(Error(`Global alias '${x}' is invalid.`));let F=x.substring(0,A).trim(),C=x.substring(A+1).trim();if(!F.length)return z(Error(`Global alias '${x}' is invalid.`));h.addGlobalAlias(T,F,C)}}let N;if((N=i.disable)!=null){typeof N=="string"&&(N=N.split(","));for(let o=0,l=N.length;o<l;++o){let c=N[o].trim(),x=h[`FEATURE_${Te(c)}`];if(!x)return z(Error(`Feature '${c}' is unknown.`));h.setFeature(T,x,!1)}}if((N=i.enable)!=null){typeof N=="string"&&(N=N.split(","));for(let o=0,l=N.length;o<l;++o){let c=N[o].trim(),x=h[`FEATURE_${Te(c)}`];if(!x)return z(Error(`Feature '${c}' is unknown.`));h.setFeature(T,x,!0)}}let $=0,J=0;i.optimize&&($=Be,J=we),typeof i.optimizeLevel=="number"&&($=i.optimizeLevel),typeof i.shrinkLevel=="number"&&(J=i.shrinkLevel),$=Math.min(Math.max($,0),3),J=Math.min(Math.max(J,0),2),h.setOptimizeLevelHints(T,$,J),w=h.newProgram(T);let rn=[];if(Array.isArray(t.transforms)&&rn.push(...t.transforms),i.transform){let o=$n(i.transform);for(let l=0,c=o.length;l<c;++l){let x=o[l].trim(),A,F;if(Vn.resolve)try{A=Vn.resolve(x,{paths:[M.cwd(),B]}),F=await import(dn.pathToFileURL(A)),F.default&&(F=F.default)}catch(C){try{F=Vn(A)}catch{return z(C)}}else try{F=await import(new URL(x,import.meta.url)),F.default&&(F=F.default)}catch(C){return z(C)}if(!F||typeof F!="function"&&typeof F!="object")return z(Error("not a transform: "+o[l]));rn.push(F)}}try{rn=rn.map(o=>(typeof o=="function"&&(Object.assign(o.prototype,{program:w,binaryen:pn,baseDir:B,stdout:p,stderr:b,log:console.error,readFile:d,writeFile:g,listFiles:y}),o=new o),o))}catch(o){return z(o)}async function Sn(o,...l){for(let c=0,x=rn.length;c<x;++c){let A=rn[c];if(typeof A[o]=="function")try{let F=n.begin();n.transformCount++,await A[o](...l),n.transformTime+=n.end(F)}catch(F){return F}}}Object.keys(X).forEach(o=>{if(o.includes("/"))return;let l=n.begin();n.parseCount++,h.parse(w,X[o],P+o+_,!1),n.parseTime+=n.end(l)});let on=[];if(i.lib){let o=i.lib;typeof o=="string"&&(o=o.split(",")),on.push(...o.map(l=>l.trim())),on=$n(on);for(let l=0,c=on.length;l<c;++l){let x=on[l],A;x.endsWith(_)?(A=[v.basename(x)],x=v.dirname(x)):A=await y(x,B)||[];for(let F of A){let C=await d(F,x);if(C==null)return z(Error(`Library file '${F}' not found.`));X[F.replace(hn,"")]=C;let I=n.begin();n.parseCount++,h.parse(w,C,P+F,!1),n.parseTime+=n.end(I)}}}i.path=i.path||[];let bn=new Map;async function Oe(o,l){let c=null,x=null;if(!o.startsWith(P))(c=await d(x=o+_,B))==null&&(c=await d(x=o+"/index"+_,B))==null&&(x=o+_,c=await d(o+_t,B));else{let A=o.substring(P.length),F=`${A}/index`;if(Object.prototype.hasOwnProperty.call(X,A))c=X[A],x=P+A+_;else if(Object.prototype.hasOwnProperty.call(X,F))c=X[F],x=P+F+_;else{for(let C of on)if((c=await d(A+_,C))!=null){x=P+A+_;break}else if((c=await d(F+_,C))!=null){x=P+F+_;break}if(c==null){let C=o.match(/^~lib\/((?:@[^/]+\/)?[^/]+)(?:\/(.+))?/);if(C){let I=C[1],q=C[2]||"index",vn=bn.has(l)?bn.get(l):".",U=[],D=v.resolve(B,vn).split(jn);for(let S=D.length,O=Kn?1:0;S>=O;--S)D[S-1]!=="node_modules"&&U.push(`${D.slice(0,S).join(jn)}${jn}node_modules`);U.push(...i.path);for(let S of U.map(O=>v.relative(B,O))){let O=q;if((c=await d(v.join(S,I,O+_),B))!=null){x=`${P}${I}/${O}${_}`,bn.set(x.replace(hn,""),v.join(S,I));break}let un=`${q}/index`;if((c=await d(v.join(S,I,un+_),B))!=null){x=`${P}${I}/${un}${_}`,bn.set(x.replace(hn,""),v.join(S,I));break}}}}}}return c==null?null:{sourceText:c,sourcePath:x}}function Le(o=[]){do{let l=h.nextFile(w);if(l==null)break;o.push(l)}while(!0);return o}async function Jn(){let o;for(;(o=Le()).length;){let c=[];for(let x of o){let A=h.getDependee(w,x);c.push(Oe(x,A))}c=await Promise.all(c);for(let x=0,A=o.length;x<A;++x){let F=o[x],C=c[x],I=n.begin();n.parseCount++,C?h.parse(w,C.sourceText,C.sourcePath,!1):h.parse(w,null,F+_,!1),n.parseTime+=n.end(I)}}let l=gn(w,b,i.disableWarning,t.reportDiagnostic,j.enabled);if(l){let c=Error(`${l} parse error(s)`);return c.stack=c.message,z(c)}}{let o=String(i.runtime),l=`rt/index-${o}`,c=X[l];if(c==null){if(l=o,c=await d(l+_,B),c==null)return z(Error(`Runtime '${v.resolve(B,l+_)}' is not found.`))}else l=`~lib/${l}`;let x=n.begin();n.parseCount++,h.parse(w,c,l+_,!0),n.parseTime+=n.end(x)}for(let o=0,l=e.length;o<l;++o){let c=String(e[o]),x=v.isAbsolute(c)?v.relative(B,c):v.normalize(c);x=x.replace(/\\/g,"/").replace(hn,"").replace(/\/$/,"");let A=await d(x+_,B);if(A==null){let C=`${x}/index${_}`;A=await d(C,B),A!=null?x=C:x+=_}else x+=_;let F=n.begin();n.parseCount++,h.parse(w,A,x,!0),n.parseTime+=n.end(F)}{let o=await Jn();if(o)return o}{let o=await Sn("afterParse",w.parser);if(o)return z(o)}{let o=await Jn();if(o)return o}{let o=n.begin();n.initializeCount++;try{h.initializeProgram(w)}catch(l){L("initialize",l)}n.initializeTime+=n.end(o)}{let o=await Sn("afterInitialize",w);if(o)return z(o)}{let o=n.begin();n.compileCount++;try{H=h.compile(w)}catch(l){let c=gn(w,b,i.disableWarning,t.reportDiagnostic,j.enabled);if(c){let x=Error(`${c} compile error(s)`);return x.stack=x.message,z(x)}L("compile",l)}n.compileTime+=n.end(o)}k=pn.wrapModule(typeof H=="number"||H instanceof Number?h.getBinaryenModuleRef(H):H.ref);let ln=gn(w,b,i.disableWarning,t.reportDiagnostic,j.enabled);if(ln){let o=Error(`${ln} compile error(s)`);return o.stack=o.message,z(o)}{let o=await Sn("afterCompile",k);if(o)return z(o)}if(ln=gn(w,b,i.disableWarning,t.reportDiagnostic,j.enabled),ln){let o=Error(`${ln} afterCompile error(s)`);return o.stack=o.message,z(o)}if(!i.noValidate){let o=n.begin();n.validateCount++;let l=h.validate(H);if(n.validateTime+=n.end(o),!l)return z(Error("validate error"))}if(i.trapMode==="clamp"||i.trapMode==="js"){let o=n.begin();try{k.runPasses([`trap-mode-${i.trapMode}`])}catch(l){L("runPasses",l)}n.compileTime+=n.end(o)}else if(i.trapMode!=="allow")return z(Error("Unsupported trap mode"));let Qn=i.debug,ke=i.converge,ne=i.importMemory?i.zeroFilledMemory:!1,yn=[];i.runPasses&&(typeof i.runPasses=="string"&&(i.runPasses=i.runPasses.split(",")),i.runPasses.length&&i.runPasses.forEach(o=>{yn.includes(o=o.trim())||yn.push(o)}));{let o=n.begin();try{n.optimizeCount++,h.optimize(H,$,J,Qn,ne)}catch(l){L("optimize",l)}try{k.runPasses(yn)}catch(l){L("runPasses",l)}if(ke){let l;try{let c=n.begin();n.emitCount++,l=k.emitBinary(),n.emitTime+=n.end(c)}catch(c){L("emitBinary (converge)",c)}do{try{n.optimizeCount++,h.optimize(H,$,J,Qn,ne)}catch(x){L("optimize (converge)",x)}try{k.runPasses(yn)}catch(x){L("runPasses (converge)",x)}let c;try{let x=n.begin();n.emitCount++,c=k.emitBinary(),n.emitTime+=n.end(x)}catch(x){L("emitBinary (converge)",x)}if(c.length>=l.length){c.length>l.length&&b.write(`Last converge was suboptimal.${E}`);break}l=c}while(!0)}n.optimizeTime+=n.end(o)}let an=[];if(!i.noEmit){if(i.binaryFile)return z(Error("Usage of the --binaryFile compiler option is no longer supported. Use --outFile instead."));let o=i.bindings||[],l=!1,c=i.outFile!=null,x=i.textFile!=null,A=c||x,F=c&&i.outFile.length>0||x&&i.textFile.length>0,C=F?(i.outFile||i.textFile).replace(/\.\w+$/,""):null,I=F?v.basename(C):"output";if(h.setBasenameHint(T,I),i.outFile!=null){let U=i.sourceMap!=null?i.sourceMap.length?i.sourceMap:`./${I}.wasm.map`:null,D=n.begin();n.emitCount++;let S;try{S=k.emitBinary(U)}catch(O){L("emitBinary",O)}if(n.emitTime+=n.end(D),i.outFile.length?an.push(g(i.outFile,S.binary,B)):(l=!0,Fn(S.binary)),S.sourceMap!="")if(i.outFile.length){let O=JSON.parse(S.sourceMap);O.sourceRoot=`./${I}`;let un=[];for(let En=0,Re=O.sources.length;En<Re;++En){let re=O.sources[En],oe=h.getSource(w,re.replace(hn,""));if(oe==null)return z(Error(`Source of file '${re}' not found.`));un[En]=oe}O.sourcesContent=un,an.push(g(v.join(v.dirname(i.outFile),v.basename(U)).replace(/^\.\//,""),JSON.stringify(O),B))}else b.write(`Skipped source map (no output path)${E}`)}if(i.textFile!=null||!A){let U=n.begin();n.emitCount++;let D;try{pn.setOptimizeStackIR(!0),D=i.textFile?.endsWith(".wast")?k.emitText():k.emitStackIR()}catch(S){L("emitText",S)}n.emitTime+=n.end(U),i.textFile!=null&&i.textFile.length?an.push(g(i.textFile,D,B)):l||Fn(D)}let q=o.includes("esm"),vn=!q&&o.includes("raw");if(q||vn)if(C){let U=n.begin();n.emitCount++;let D;try{D=h.buildTSD(w,q)}catch(S){L("buildTSD",S)}n.emitTime+=n.end(U),an.push(g(C+".d.ts",D,B))}else b.write(`Skipped TypeScript binding (no output path)${E}`);if(q||vn)if(C){let U=n.begin();n.emitCount++;let D;try{D=h.buildJS(w,q)}catch(S){L("buildJS",S)}n.emitTime+=n.end(U),an.push(g(C+".js",D,B))}else b.write(`Skipped JavaScript binding (no output path)${E}`)}try{await Promise.all(an)}catch(o){return z(o)}return n.total=n.end(a),i.stats&&b.write(n.toString()),z(null);async function ee(o,l){let c=v.resolve(l,o);try{return n.readCount++,await G.promises.readFile(c,"utf8")}catch{return null}}async function te(o,l,c){try{n.writeCount++;let x=v.resolve(c,v.dirname(o)),A=v.join(x,v.basename(o));return await G.promises.mkdir(x,{recursive:!0}),await G.promises.writeFile(A,l),!0}catch{return!1}}async function ie(o,l){try{return n.readCount++,(await G.promises.readdir(v.join(l,o))).filter(c=>Tt.test(c))}catch{return null}}function Fn(o){Fn.used||(Fn.used=!0,n.writeCount++),p.write(o)}function L(o,l){let c=zn.red("\u258C ");console.error([E,c,"Whoops, the ToilScript compiler has crashed during ",o," :-(",E,c,E,(typeof l.stack=="string"?[c,"Here is the stack trace hinting at the problem, perhaps it's useful?",E,c,E,l.stack.replace(/^/mg,c),E]:[c,"There is no stack trace. Perhaps a Binaryen exception above / in console?",E,c,E,c,"> "+l.stack,E]).join(""),c,E,c,"If you see where the error is, feel free to send us a pull request. If not,",E,c,"please let us know: https://github.com/dacely-cloud/toilscript/issues",E,c,E,c,"Thank you!",E].join("")),M.exit(1)}}function Gn(e){return Object.prototype.toString.call(e)==="[object Object]"}async function Ce(e,t,n){let a=await n(e,t),s=v.join(t,e);if(!a)return null;let r;try{r=JSON.parse(a)}catch(u){throw new Error(`Toilconfig is not valid json: ${s}`,{cause:u})}if(r.options&&!Gn(r.options))throw new Error(`Toilconfig.options is not an object: ${s}`);if(r.include&&!Array.isArray(r.include))throw new Error(`Toilconfig.include is not an array: ${s}`);if(r.targets){if(!Gn(r.targets))throw new Error(`Toilconfig.targets is not an object: ${s}`);let u=Object.keys(r.targets);for(let f=0;f<u.length;f++){let p=u[f];if(!Gn(r.targets[p]))throw new Error(`Toilconfig.targets.${p} is not an object: ${s}`)}}if(r.extends&&typeof r.extends!="string")throw new Error(`Toilconfig.extends is not a string: ${s}`);return r}function gn(e,t,n,a,s){typeof s>"u"&&t&&(s=t.isTTY);let r=0;do{let p=h.nextDiagnostic(e);if(!p)break;if(t){let b=d=>{if(n==null)return!1;if(!n.length)return!0;let g=h.getDiagnosticCode(d);return n.includes(g)};(h.isError(p)||!b(p))&&t.write(h.formatDiagnostic(p,s,!0)+E+E)}if(a){let b=function(g){return g&&{start:h.getRangeStart(g),end:h.getRangeEnd(g),source:d(h.getRangeSource(g))}||null},d=function(g){return g&&{normalizedPath:h.getSourceNormalizedPath(g)}||null};var u=b,f=d;a({message:h.getDiagnosticMessage(p),code:h.getDiagnosticCode(p),category:h.getDiagnosticCategory(p),range:b(h.getDiagnosticRange(p)),relatedRange:b(h.getDiagnosticRelatedRange(p))})}h.isError(p)&&++r}while(!0);return r}var Cn=class{readCount=0;writeCount=0;parseTime=0;parseCount=0;initializeTime=0;initializeCount=0;compileTime=0;compileCount=0;emitTime=0;emitCount=0;validateTime=0;validateCount=0;optimizeTime=0;optimizeCount=0;transformTime=0;transformCount=0;begin(){return M.hrtime()}end(t){let n=M.hrtime(t);return n[0]*1e9+n[1]}toString(){let t=m=>m?`${(m/1e6).toFixed(3)} ms`:"n/a",n=Object.keys(this).filter(m=>m.endsWith("Time")).map(m=>m.substring(0,m.length-4)),a=n.map(m=>t(this[`${m}Time`])),s=n.map(m=>this[`${m}Count`].toString()),r=n.reduce((m,i)=>Math.max(i.length,m),0),u=a.reduce((m,i)=>Math.max(i.length,m),0),f=s.reduce((m,i)=>Math.max(i.length,m),0),p=r+u+f+6,b=[];b.push(`\u256D\u2500${"\u2500".repeat(p)}\u2500\u256E${E}`);let d="Stats";b.push(`\u2502 ${d}${" ".repeat(p-d.length)} \u2502${E}`),b.push(`\u255E\u2550${"\u2550".repeat(r)}\u2550\u2564\u2550${"\u2550".repeat(u)}\u2550\u2564\u2550${"\u2550".repeat(f)}\u2550\u2561${E}`);for(let m=0,i=n.length;m<i;++m)b.push(`\u2502 ${n[m].padEnd(r)} \u2502 ${a[m].padStart(u)} \u2502 ${s[m].padStart(f)} \u2502${E}`);b.push(`\u251C\u2500${"\u2500".repeat(r)}\u2500\u2534\u2500${"\u2500".repeat(u)}\u2500\u2534\u2500${"\u2500".repeat(f)}\u2500\u2524${E}`);let g=`Took ${t(this.total)}`;b.push(`\u2502 ${g}${" ".repeat(p-g.length)} \u2502${E}`);let y=`${this.readCount} reads, ${this.writeCount} writes`;return b.push(`\u2502 ${y}${" ".repeat(p-y.length)} \u2502${E}`),b.push(`\u2570\u2500${"\u2500".repeat(p)}\u2500\u256F${E}`),b.join("")}},ze=typeof global<"u"&&global.Buffer?global.Buffer.allocUnsafe||(e=>new global.Buffer(e)):e=>new Uint8Array(e);function Hn(e){let t=[];return t.write=function(n){if(e&&e(n),typeof n=="string"){let a=ze(Tn.length(n));Tn.write(n,a,0),n=a}this.push(n)},t.reset=function(){t.length=0},t.toBuffer=function(){let n=0,a=0,s=this.length;for(;a<s;)n+=this[a++].length;let r=ze(n);for(n=a=0;a<s;)r.set(this[a],n),n+=this[a].length,++a;return r},t.toString=function(){let n=this.toBuffer();return Tn.read(n,0,n.length)},t}var St={alwaysStrict:!0,strictNullChecks:!0,noImplicitAny:!0,noImplicitReturns:!0,noImplicitThis:!0,noEmitOnError:!0,noPropertyAccessFromIndexSignature:!0,experimentalDecorators:!0,target:"esnext",noLib:!0,types:[],allowJs:!1};export{Cn as Stats,gn as checkDiagnostics,wt as compileString,qn as configToArguments,Hn as createMemoryStream,Wn as default,Be as defaultOptimizeLevel,we as defaultShrinkLevel,Bt as definitionFiles,X as libraryFiles,P as libraryPrefix,Se as main,zt as options,St as tscOptions,Xn as version};
|
|
28455
|
+
`,jn=Kn?"\\":"/",_=".ts",_t=`.d${_}`,hn=new RegExp("\\"+_+"$"),Tt=new RegExp("^(?!.*\\.d\\"+_+"$).*\\"+_+"$");function Te(e){return e.replace(/-/g,"_").toUpperCase()}function Ct(e){return typeof e=="string"&&e!==""}var Xn=ve,zt=Y,P=Ee,X=Ae,St=_e,Se=3,Be=0;function qn(e,t=[]){return Object.keys(e||{}).forEach(n=>{let a=e[n],s=Y[n];s&&s.type==="b"?a&&t.push(`--${n}`):Array.isArray(a)?a.forEach(r=>{t.push(`--${n}`,String(r))}):t.push(`--${n}`,String(a))}),t}async function Bt(e,t={}){typeof e=="string"&&(e={[`input${_}`]:e});let n=["--outFile","binary","--textFile","text"];qn(t,n);let a={},s=await we(n.concat(Object.keys(e)),{readFile:r=>Object.prototype.hasOwnProperty.call(e,r)?e[r]:null,writeFile:(r,u)=>{a[r]=u},listFiles:()=>[]});return Object.assign(s,a)}async function we(e,t){Array.isArray(e)||(e=qn(e)),t||(t={});let n=t.stats||new Cn,a=n.begin(),s=0,r=0,u=0,f=(Xn||"").split(".");f.length===3&&(r=parseInt(f[0])|0,s=parseInt(f[1])|0,u=parseInt(f[2])|0);let p=t.stdout||Hn(),b=t.stderr||Hn(),d=t.readFile||ee,g=t.writeFile||te,y=t.listFiles||ie,m=ye(e,Y,!1),i=m.options;e=m.arguments;let zn=new nn(p),j=new nn(b);i.noColors&&(zn.enabled=!1,j.enabled=!1);let Yn=m.unknown;Yn.length&&Yn.forEach(o=>{b.write(`${j.yellow("WARNING ")}Unknown option '${o}'${E}`)});let Jn=m.trailing;Jn.length&&b.write(`${j.yellow("WARNING ")}Unsupported trailing arguments: ${Jn.join(" ")}${E}`);let H=null,k=null,z=(o,l={})=>(o&&b.write(`${j.red("FAILURE ")}${o.stack.replace(/^ERROR: /i,"")}${E}`),k&&k.dispose(),n.total||(n.total=n.end(a)),Object.assign({error:o,stdout:p,stderr:b,stats:n},l));if(i.version)return p.write(`Version ${Xn}${E}`),z(null);let S=v.normalize(i.baseDir||"."),K=en(i.config||"toilconfig.json",S),Sn=v.basename(K),J=v.dirname(K),R=await Ce(Sn,J,d),De=R!=null&&Array.isArray(R.entries)&&R.entries.length;if(i.help||!e.length&&!De){let o=i.help?p:b,l=i.help?zn:j;return o.write([l.white("SYNTAX")," "+l.cyan("toilscript")+" [entryFile ...] [options]","",l.white("EXAMPLES")," "+l.cyan("toilscript")+" hello"+_," "+l.cyan("toilscript")+" hello"+_+" -o hello.wasm -t hello.wat"," "+l.cyan("toilscript")+" hello1"+_+" hello2"+_+" -o -O > hello.wasm"," "+l.cyan("toilscript")+" --config toilconfig.json --target release","",l.white("OPTIONS")].concat(Fe(Y,24,E)).join(E)+E),z(null)}if(!(G.promises&&G.promises.readFile)){if(d===ee)throw Error("'options.readFile' must be specified");if(g===te)throw Error("'options.writeFile' must be specified");if(y===ie)throw Error("'options.listFiles' must be specified")}let Bn=new Set;Bn.add(K);let Ie=i.target||"release";for(;R;){if(R.targets){let l=R.targets[Ie];l&&(i=Un(Y,i,l,J))}let o=R.options;if(o&&(i=Un(Y,i,o,J)),R.entries)for(let l of R.entries)e.push(en(l,J));if(R.extends){if(K=en(R.extends,J,!0),Sn=v.basename(K),J=v.dirname(K),Bn.has(K))break;Bn.add(K),R=await Ce(Sn,J,d)}else break}if(Mn(Y,i),i.showConfig)return b.write(JSON.stringify({options:i,entries:e},null,2)),z(null);function Zn(o){return[...new Set(o)]}let B,tn,mn,T=h.newOptions();switch(i.runtime){case"stub":tn=0;break;case"minimal":tn=1;break;case"memory":tn=3;break;default:tn=2;break}switch(i.uncheckedBehavior){default:mn=0;break;case"never":mn=1;break;case"always":mn=2;break}if(h.setTarget(T,0),h.setDebugInfo(T,!!i.debug),h.setRuntime(T,tn),h.setNoAssert(T,i.noAssert),h.setExportMemory(T,!i.noExportMemory),h.setImportMemory(T,i.importMemory),h.setInitialMemory(T,i.initialMemory>>>0),h.setMaximumMemory(T,i.maximumMemory>>>0),h.setSharedMemory(T,i.sharedMemory),h.setImportTable(T,i.importTable),h.setExportTable(T,i.exportTable),i.exportStart!=null&&h.setExportStart(T,Ct(i.exportStart)?i.exportStart:"_start"),h.setMemoryBase(T,i.memoryBase>>>0),h.setTableBase(T,i.tableBase>>>0),h.setSourceMap(T,i.sourceMap!=null),h.setUncheckedBehavior(T,mn),h.setNoUnsafe(T,i.noUnsafe),h.setPedantic(T,i.pedantic),h.setLowMemoryLimit(T,i.lowMemoryLimit>>>0),h.setExportRuntime(T,i.exportRuntime),h.setBundleVersion(T,r,s,u),!i.stackSize&&tn===2&&(i.stackSize=h.DEFAULT_STACK_SIZE),h.setStackSize(T,i.stackSize),h.setBindingsHint(T,i.bindings&&i.bindings.length>0),i.use){let o=i.use;for(let l=0,c=o.length;l<c;++l){let x=o[l],A=x.indexOf("=");if(A<0)return z(Error(`Global alias '${x}' is invalid.`));let F=x.substring(0,A).trim(),C=x.substring(A+1).trim();if(!F.length)return z(Error(`Global alias '${x}' is invalid.`));h.addGlobalAlias(T,F,C)}}let N;if((N=i.disable)!=null){typeof N=="string"&&(N=N.split(","));for(let o=0,l=N.length;o<l;++o){let c=N[o].trim(),x=h[`FEATURE_${Te(c)}`];if(!x)return z(Error(`Feature '${c}' is unknown.`));h.setFeature(T,x,!1)}}if((N=i.enable)!=null){typeof N=="string"&&(N=N.split(","));for(let o=0,l=N.length;o<l;++o){let c=N[o].trim(),x=h[`FEATURE_${Te(c)}`];if(!x)return z(Error(`Feature '${c}' is unknown.`));h.setFeature(T,x,!0)}}let Z=0,$=0;i.optimize&&(Z=Se,$=Be),typeof i.optimizeLevel=="number"&&(Z=i.optimizeLevel),typeof i.shrinkLevel=="number"&&($=i.shrinkLevel),Z=Math.min(Math.max(Z,0),3),$=Math.min(Math.max($,0),2),h.setOptimizeLevelHints(T,Z,$),B=h.newProgram(T);let rn=[];if(Array.isArray(t.transforms)&&rn.push(...t.transforms),i.transform){let o=Zn(i.transform);for(let l=0,c=o.length;l<c;++l){let x=o[l].trim(),A,F;if(Vn.resolve)try{A=Vn.resolve(x,{paths:[M.cwd(),S]}),F=await import(dn.pathToFileURL(A)),F.default&&(F=F.default)}catch(C){try{F=Vn(A)}catch{return z(C)}}else try{F=await import(new URL(x,import.meta.url)),F.default&&(F=F.default)}catch(C){return z(C)}if(!F||typeof F!="function"&&typeof F!="object")return z(Error("not a transform: "+o[l]));rn.push(F)}}try{rn=rn.map(o=>(typeof o=="function"&&(Object.assign(o.prototype,{program:B,binaryen:pn,baseDir:S,stdout:p,stderr:b,log:console.error,readFile:d,writeFile:g,listFiles:y}),o=new o),o))}catch(o){return z(o)}async function wn(o,...l){for(let c=0,x=rn.length;c<x;++c){let A=rn[c];if(typeof A[o]=="function")try{let F=n.begin();n.transformCount++,await A[o](...l),n.transformTime+=n.end(F)}catch(F){return F}}}Object.keys(X).forEach(o=>{if(o.includes("/"))return;let l=n.begin();n.parseCount++,h.parse(B,X[o],P+o+_,!1),n.parseTime+=n.end(l)});let on=[];if(i.lib){let o=i.lib;typeof o=="string"&&(o=o.split(",")),on.push(...o.map(l=>l.trim())),on=Zn(on);for(let l=0,c=on.length;l<c;++l){let x=on[l],A;x.endsWith(_)?(A=[v.basename(x)],x=v.dirname(x)):A=await y(x,S)||[];for(let F of A){let C=await d(F,x);if(C==null)return z(Error(`Library file '${F}' not found.`));X[F.replace(hn,"")]=C;let I=n.begin();n.parseCount++,h.parse(B,C,P+F,!1),n.parseTime+=n.end(I)}}}i.path=i.path||[];let bn=new Map;async function Oe(o,l){let c=null,x=null;if(!o.startsWith(P))(c=await d(x=o+_,S))==null&&(c=await d(x=o+"/index"+_,S))==null&&(x=o+_,c=await d(o+_t,S));else{let A=o.substring(P.length),F=`${A}/index`;if(Object.prototype.hasOwnProperty.call(X,A))c=X[A],x=P+A+_;else if(Object.prototype.hasOwnProperty.call(X,F))c=X[F],x=P+F+_;else{for(let C of on)if((c=await d(A+_,C))!=null){x=P+A+_;break}else if((c=await d(F+_,C))!=null){x=P+F+_;break}if(c==null){let C=o.match(/^~lib\/((?:@[^/]+\/)?[^/]+)(?:\/(.+))?/);if(C){let I=C[1],q=C[2]||"index",vn=bn.has(l)?bn.get(l):".",U=[],D=v.resolve(S,vn).split(jn);for(let w=D.length,O=Kn?1:0;w>=O;--w)D[w-1]!=="node_modules"&&U.push(`${D.slice(0,w).join(jn)}${jn}node_modules`);U.push(...i.path);for(let w of U.map(O=>v.relative(S,O))){let O=q;if((c=await d(v.join(w,I,O+_),S))!=null){x=`${P}${I}/${O}${_}`,bn.set(x.replace(hn,""),v.join(w,I));break}let un=`${q}/index`;if((c=await d(v.join(w,I,un+_),S))!=null){x=`${P}${I}/${un}${_}`,bn.set(x.replace(hn,""),v.join(w,I));break}}}}}}return c==null?null:{sourceText:c,sourcePath:x}}function Le(o=[]){do{let l=h.nextFile(B);if(l==null)break;o.push(l)}while(!0);return o}async function $n(){let o;for(;(o=Le()).length;){let c=[];for(let x of o){let A=h.getDependee(B,x);c.push(Oe(x,A))}c=await Promise.all(c);for(let x=0,A=o.length;x<A;++x){let F=o[x],C=c[x],I=n.begin();n.parseCount++,C?h.parse(B,C.sourceText,C.sourcePath,!1):h.parse(B,null,F+_,!1),n.parseTime+=n.end(I)}}let l=gn(B,b,i.disableWarning,t.reportDiagnostic,j.enabled);if(l){let c=Error(`${l} parse error(s)`);return c.stack=c.message,z(c)}}{let o=String(i.runtime),l=`rt/index-${o}`,c=X[l];if(c==null){if(l=o,c=await d(l+_,S),c==null)return z(Error(`Runtime '${v.resolve(S,l+_)}' is not found.`))}else l=`~lib/${l}`;let x=n.begin();n.parseCount++,h.parse(B,c,l+_,!0),n.parseTime+=n.end(x)}for(let o=0,l=e.length;o<l;++o){let c=String(e[o]),x=v.isAbsolute(c)?v.relative(S,c):v.normalize(c);x=x.replace(/\\/g,"/").replace(hn,"").replace(/\/$/,"");let A=await d(x+_,S);if(A==null){let C=`${x}/index${_}`;A=await d(C,S),A!=null?x=C:x+=_}else x+=_;let F=n.begin();n.parseCount++,h.parse(B,A,x,!0),n.parseTime+=n.end(F)}{let o=await $n();if(o)return o}{let o=await wn("afterParse",B.parser);if(o)return z(o)}{let o=await $n();if(o)return o}{let o=n.begin();n.initializeCount++;try{h.initializeProgram(B)}catch(l){L("initialize",l)}n.initializeTime+=n.end(o)}{let o=await wn("afterInitialize",B);if(o)return z(o)}{let o=n.begin();n.compileCount++;try{H=h.compile(B)}catch(l){let c=gn(B,b,i.disableWarning,t.reportDiagnostic,j.enabled);if(c){let x=Error(`${c} compile error(s)`);return x.stack=x.message,z(x)}L("compile",l)}n.compileTime+=n.end(o)}k=pn.wrapModule(typeof H=="number"||H instanceof Number?h.getBinaryenModuleRef(H):H.ref);let ln=gn(B,b,i.disableWarning,t.reportDiagnostic,j.enabled);if(ln){let o=Error(`${ln} compile error(s)`);return o.stack=o.message,z(o)}{let o=await wn("afterCompile",k);if(o)return z(o)}if(ln=gn(B,b,i.disableWarning,t.reportDiagnostic,j.enabled),ln){let o=Error(`${ln} afterCompile error(s)`);return o.stack=o.message,z(o)}if(!i.noValidate){let o=n.begin();n.validateCount++;let l=h.validate(H);if(n.validateTime+=n.end(o),!l)return z(Error("validate error"))}if(i.trapMode==="clamp"||i.trapMode==="js"){let o=n.begin();try{k.runPasses([`trap-mode-${i.trapMode}`])}catch(l){L("runPasses",l)}n.compileTime+=n.end(o)}else if(i.trapMode!=="allow")return z(Error("Unsupported trap mode"));let Qn=i.debug,ke=i.converge,ne=i.importMemory?i.zeroFilledMemory:!1,yn=[];i.runPasses&&(typeof i.runPasses=="string"&&(i.runPasses=i.runPasses.split(",")),i.runPasses.length&&i.runPasses.forEach(o=>{yn.includes(o=o.trim())||yn.push(o)}));{let o=n.begin();try{n.optimizeCount++,h.optimize(H,Z,$,Qn,ne)}catch(l){L("optimize",l)}try{k.runPasses(yn)}catch(l){L("runPasses",l)}if(ke){let l;try{let c=n.begin();n.emitCount++,l=k.emitBinary(),n.emitTime+=n.end(c)}catch(c){L("emitBinary (converge)",c)}do{try{n.optimizeCount++,h.optimize(H,Z,$,Qn,ne)}catch(x){L("optimize (converge)",x)}try{k.runPasses(yn)}catch(x){L("runPasses (converge)",x)}let c;try{let x=n.begin();n.emitCount++,c=k.emitBinary(),n.emitTime+=n.end(x)}catch(x){L("emitBinary (converge)",x)}if(c.length>=l.length){c.length>l.length&&b.write(`Last converge was suboptimal.${E}`);break}l=c}while(!0)}n.optimizeTime+=n.end(o)}let an=[];if(!i.noEmit){if(i.binaryFile)return z(Error("Usage of the --binaryFile compiler option is no longer supported. Use --outFile instead."));let o=i.bindings||[],l=!1,c=i.outFile!=null,x=i.textFile!=null,A=c||x,F=c&&i.outFile.length>0||x&&i.textFile.length>0,C=F?(i.outFile||i.textFile).replace(/\.\w+$/,""):null,I=F?v.basename(C):"output";if(h.setBasenameHint(T,I),i.outFile!=null){let U=i.sourceMap!=null?i.sourceMap.length?i.sourceMap:`./${I}.wasm.map`:null,D=n.begin();n.emitCount++;let w;try{w=k.emitBinary(U)}catch(O){L("emitBinary",O)}if(n.emitTime+=n.end(D),i.outFile.length?an.push(g(i.outFile,w.binary,S)):(l=!0,Fn(w.binary)),w.sourceMap!="")if(i.outFile.length){let O=JSON.parse(w.sourceMap);O.sourceRoot=`./${I}`;let un=[];for(let En=0,Re=O.sources.length;En<Re;++En){let re=O.sources[En],oe=h.getSource(B,re.replace(hn,""));if(oe==null)return z(Error(`Source of file '${re}' not found.`));un[En]=oe}O.sourcesContent=un,an.push(g(v.join(v.dirname(i.outFile),v.basename(U)).replace(/^\.\//,""),JSON.stringify(O),S))}else b.write(`Skipped source map (no output path)${E}`)}if(i.textFile!=null||!A){let U=n.begin();n.emitCount++;let D;try{pn.setOptimizeStackIR(!0),D=i.textFile?.endsWith(".wast")?k.emitText():k.emitStackIR()}catch(w){L("emitText",w)}n.emitTime+=n.end(U),i.textFile!=null&&i.textFile.length?an.push(g(i.textFile,D,S)):l||Fn(D)}let q=o.includes("esm"),vn=!q&&o.includes("raw");if(q||vn)if(C){let U=n.begin();n.emitCount++;let D;try{D=h.buildTSD(B,q)}catch(w){L("buildTSD",w)}n.emitTime+=n.end(U),an.push(g(C+".d.ts",D,S))}else b.write(`Skipped TypeScript binding (no output path)${E}`);if(q||vn)if(C){let U=n.begin();n.emitCount++;let D;try{D=h.buildJS(B,q)}catch(w){L("buildJS",w)}n.emitTime+=n.end(U),an.push(g(C+".js",D,S))}else b.write(`Skipped JavaScript binding (no output path)${E}`)}try{await Promise.all(an)}catch(o){return z(o)}return n.total=n.end(a),i.stats&&b.write(n.toString()),z(null);async function ee(o,l){let c=v.resolve(l,o);try{return n.readCount++,await G.promises.readFile(c,"utf8")}catch{return null}}async function te(o,l,c){try{n.writeCount++;let x=v.resolve(c,v.dirname(o)),A=v.join(x,v.basename(o));return await G.promises.mkdir(x,{recursive:!0}),await G.promises.writeFile(A,l),!0}catch{return!1}}async function ie(o,l){try{return n.readCount++,(await G.promises.readdir(v.join(l,o))).filter(c=>Tt.test(c))}catch{return null}}function Fn(o){Fn.used||(Fn.used=!0,n.writeCount++),p.write(o)}function L(o,l){let c=zn.red("\u258C ");console.error([E,c,"Whoops, the ToilScript compiler has crashed during ",o," :-(",E,c,E,(typeof l.stack=="string"?[c,"Here is the stack trace hinting at the problem, perhaps it's useful?",E,c,E,l.stack.replace(/^/mg,c),E]:[c,"There is no stack trace. Perhaps a Binaryen exception above / in console?",E,c,E,c,"> "+l.stack,E]).join(""),c,E,c,"If you see where the error is, feel free to send us a pull request. If not,",E,c,"please let us know: https://github.com/dacely-cloud/toilscript/issues",E,c,E,c,"Thank you!",E].join("")),M.exit(1)}}function Gn(e){return Object.prototype.toString.call(e)==="[object Object]"}async function Ce(e,t,n){let a=await n(e,t),s=v.join(t,e);if(!a)return null;let r;try{r=JSON.parse(a)}catch(u){throw new Error(`Toilconfig is not valid json: ${s}`,{cause:u})}if(r.options&&!Gn(r.options))throw new Error(`Toilconfig.options is not an object: ${s}`);if(r.include&&!Array.isArray(r.include))throw new Error(`Toilconfig.include is not an array: ${s}`);if(r.targets){if(!Gn(r.targets))throw new Error(`Toilconfig.targets is not an object: ${s}`);let u=Object.keys(r.targets);for(let f=0;f<u.length;f++){let p=u[f];if(!Gn(r.targets[p]))throw new Error(`Toilconfig.targets.${p} is not an object: ${s}`)}}if(r.extends&&typeof r.extends!="string")throw new Error(`Toilconfig.extends is not a string: ${s}`);return r}function gn(e,t,n,a,s){typeof s>"u"&&t&&(s=t.isTTY);let r=0;do{let p=h.nextDiagnostic(e);if(!p)break;if(t){let b=d=>{if(n==null)return!1;if(!n.length)return!0;let g=h.getDiagnosticCode(d);return n.includes(g)};(h.isError(p)||!b(p))&&t.write(h.formatDiagnostic(p,s,!0)+E+E)}if(a){let b=function(g){return g&&{start:h.getRangeStart(g),end:h.getRangeEnd(g),source:d(h.getRangeSource(g))}||null},d=function(g){return g&&{normalizedPath:h.getSourceNormalizedPath(g)}||null};var u=b,f=d;a({message:h.getDiagnosticMessage(p),code:h.getDiagnosticCode(p),category:h.getDiagnosticCategory(p),range:b(h.getDiagnosticRange(p)),relatedRange:b(h.getDiagnosticRelatedRange(p))})}h.isError(p)&&++r}while(!0);return r}var Cn=class{readCount=0;writeCount=0;parseTime=0;parseCount=0;initializeTime=0;initializeCount=0;compileTime=0;compileCount=0;emitTime=0;emitCount=0;validateTime=0;validateCount=0;optimizeTime=0;optimizeCount=0;transformTime=0;transformCount=0;begin(){return M.hrtime()}end(t){let n=M.hrtime(t);return n[0]*1e9+n[1]}toString(){let t=m=>m?`${(m/1e6).toFixed(3)} ms`:"n/a",n=Object.keys(this).filter(m=>m.endsWith("Time")).map(m=>m.substring(0,m.length-4)),a=n.map(m=>t(this[`${m}Time`])),s=n.map(m=>this[`${m}Count`].toString()),r=n.reduce((m,i)=>Math.max(i.length,m),0),u=a.reduce((m,i)=>Math.max(i.length,m),0),f=s.reduce((m,i)=>Math.max(i.length,m),0),p=r+u+f+6,b=[];b.push(`\u256D\u2500${"\u2500".repeat(p)}\u2500\u256E${E}`);let d="Stats";b.push(`\u2502 ${d}${" ".repeat(p-d.length)} \u2502${E}`),b.push(`\u255E\u2550${"\u2550".repeat(r)}\u2550\u2564\u2550${"\u2550".repeat(u)}\u2550\u2564\u2550${"\u2550".repeat(f)}\u2550\u2561${E}`);for(let m=0,i=n.length;m<i;++m)b.push(`\u2502 ${n[m].padEnd(r)} \u2502 ${a[m].padStart(u)} \u2502 ${s[m].padStart(f)} \u2502${E}`);b.push(`\u251C\u2500${"\u2500".repeat(r)}\u2500\u2534\u2500${"\u2500".repeat(u)}\u2500\u2534\u2500${"\u2500".repeat(f)}\u2500\u2524${E}`);let g=`Took ${t(this.total)}`;b.push(`\u2502 ${g}${" ".repeat(p-g.length)} \u2502${E}`);let y=`${this.readCount} reads, ${this.writeCount} writes`;return b.push(`\u2502 ${y}${" ".repeat(p-y.length)} \u2502${E}`),b.push(`\u2570\u2500${"\u2500".repeat(p)}\u2500\u256F${E}`),b.join("")}},ze=typeof global<"u"&&global.Buffer?global.Buffer.allocUnsafe||(e=>new global.Buffer(e)):e=>new Uint8Array(e);function Hn(e){let t=[];return t.write=function(n){if(e&&e(n),typeof n=="string"){let a=ze(Tn.length(n));Tn.write(n,a,0),n=a}this.push(n)},t.reset=function(){t.length=0},t.toBuffer=function(){let n=0,a=0,s=this.length;for(;a<s;)n+=this[a++].length;let r=ze(n);for(n=a=0;a<s;)r.set(this[a],n),n+=this[a].length,++a;return r},t.toString=function(){let n=this.toBuffer();return Tn.read(n,0,n.length)},t}var wt={alwaysStrict:!0,strictNullChecks:!0,noImplicitAny:!0,noImplicitReturns:!0,noImplicitThis:!0,noEmitOnError:!0,noPropertyAccessFromIndexSignature:!0,experimentalDecorators:!0,target:"esnext",noLib:!0,types:[],allowJs:!1};export{Cn as Stats,gn as checkDiagnostics,Bt as compileString,qn as configToArguments,Hn as createMemoryStream,Wn as default,Se as defaultOptimizeLevel,Be as defaultShrinkLevel,St as definitionFiles,X as libraryFiles,P as libraryPrefix,we as main,zt as options,wt as tscOptions,Xn as version};
|
|
28206
28456
|
//# sourceMappingURL=cli.js.map
|