@lakutata/ffi 0.0.0-stage → 3.1.2
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/LICENSE +23 -0
- package/README.md +163 -2
- package/README.zh-CN.md +140 -0
- package/dist/cjs/components/NativeLibrary.d.ts +229 -0
- package/dist/cjs/components/NativeLibrary.js +346 -0
- package/dist/cjs/decorators/Library.d.ts +61 -0
- package/dist/cjs/decorators/Library.js +44 -0
- package/dist/cjs/decorators/Native.d.ts +69 -0
- package/dist/cjs/decorators/Native.js +90 -0
- package/dist/cjs/exceptions/NativeDeclarationException.d.ts +12 -0
- package/dist/cjs/exceptions/NativeDeclarationException.js +19 -0
- package/dist/cjs/exceptions/NativeLibraryClosedException.d.ts +12 -0
- package/dist/cjs/exceptions/NativeLibraryClosedException.js +19 -0
- package/dist/cjs/exceptions/NativeLibraryNotFoundException.d.ts +11 -0
- package/dist/cjs/exceptions/NativeLibraryNotFoundException.js +18 -0
- package/dist/cjs/exceptions/NativeMemoryException.d.ts +11 -0
- package/dist/cjs/exceptions/NativeMemoryException.js +18 -0
- package/dist/cjs/exports/FFI.d.ts +12 -0
- package/dist/cjs/exports/FFI.js +40 -0
- package/dist/cjs/exports/Generator.d.ts +2 -0
- package/dist/cjs/exports/Generator.js +10 -0
- package/dist/cjs/lib/Memory.d.ts +188 -0
- package/dist/cjs/lib/Memory.js +227 -0
- package/dist/cjs/lib/Runtime.d.ts +98 -0
- package/dist/cjs/lib/Runtime.js +209 -0
- package/dist/cjs/lib/backend/Functions.d.ts +65 -0
- package/dist/cjs/lib/backend/Functions.js +214 -0
- package/dist/cjs/lib/backend/KoffiTypes.d.ts +53 -0
- package/dist/cjs/lib/backend/KoffiTypes.js +426 -0
- package/dist/cjs/lib/declarations/Builtins.d.ts +33 -0
- package/dist/cjs/lib/declarations/Builtins.js +179 -0
- package/dist/cjs/lib/declarations/Layout.d.ts +41 -0
- package/dist/cjs/lib/declarations/Layout.js +180 -0
- package/dist/cjs/lib/declarations/Lexer.d.ts +40 -0
- package/dist/cjs/lib/declarations/Lexer.js +325 -0
- package/dist/cjs/lib/declarations/Parser.d.ts +90 -0
- package/dist/cjs/lib/declarations/Parser.js +1425 -0
- package/dist/cjs/lib/declarations/Platform.d.ts +50 -0
- package/dist/cjs/lib/declarations/Platform.js +27 -0
- package/dist/cjs/lib/declarations/Types.d.ts +173 -0
- package/dist/cjs/lib/declarations/Types.js +179 -0
- package/dist/cjs/lib/generator/CText.d.ts +14 -0
- package/dist/cjs/lib/generator/CText.js +133 -0
- package/dist/cjs/lib/generator/Generator.d.ts +136 -0
- package/dist/cjs/lib/generator/Generator.js +395 -0
- package/dist/cjs/lib/generator/Preprocessor.d.ts +60 -0
- package/dist/cjs/lib/generator/Preprocessor.js +94 -0
- package/dist/cjs/lib/generator/TypeScriptTypes.d.ts +35 -0
- package/dist/cjs/lib/generator/TypeScriptTypes.js +153 -0
- package/dist/cjs/lib/library/NativeCallback.d.ts +44 -0
- package/dist/cjs/lib/library/NativeCallback.js +66 -0
- package/dist/cjs/lib/library/NativeLibraryHandle.d.ts +268 -0
- package/dist/cjs/lib/library/NativeLibraryHandle.js +540 -0
- package/dist/cjs/lib/library/Resolve.d.ts +49 -0
- package/dist/cjs/lib/library/Resolve.js +130 -0
- package/dist/cjs/lib/thread/NativeThreads.d.ts +80 -0
- package/dist/cjs/lib/thread/NativeThreads.js +384 -0
- package/dist/cjs/lib/thread/NativeWorker.d.ts +6 -0
- package/dist/cjs/lib/thread/NativeWorker.js +96 -0
- package/dist/cjs/lib/thread/NativeWorkerCode.d.ts +5 -0
- package/dist/cjs/lib/thread/NativeWorkerCode.js +4 -0
- package/dist/cjs/lib/thread/PackageRequire.d.ts +6 -0
- package/dist/cjs/lib/thread/PackageRequire.js +4 -0
- package/dist/cjs/lib/thread/ThreadProtocol.d.ts +77 -0
- package/dist/cjs/lib/thread/ThreadProtocol.js +2 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/components/NativeLibrary.js +338 -0
- package/dist/esm/decorators/Library.js +40 -0
- package/dist/esm/decorators/Native.js +85 -0
- package/dist/esm/exceptions/NativeDeclarationException.js +15 -0
- package/dist/esm/exceptions/NativeLibraryClosedException.js +15 -0
- package/dist/esm/exceptions/NativeLibraryNotFoundException.js +14 -0
- package/dist/esm/exceptions/NativeMemoryException.js +14 -0
- package/dist/esm/exports/FFI.js +10 -0
- package/dist/esm/exports/Generator.js +2 -0
- package/dist/esm/lib/Memory.js +210 -0
- package/dist/esm/lib/Runtime.js +192 -0
- package/dist/esm/lib/backend/Functions.js +206 -0
- package/dist/esm/lib/backend/KoffiTypes.js +418 -0
- package/dist/esm/lib/declarations/Builtins.js +174 -0
- package/dist/esm/lib/declarations/Layout.js +175 -0
- package/dist/esm/lib/declarations/Lexer.js +321 -0
- package/dist/esm/lib/declarations/Parser.js +1421 -0
- package/dist/esm/lib/declarations/Platform.js +23 -0
- package/dist/esm/lib/declarations/Types.js +170 -0
- package/dist/esm/lib/generator/CText.js +129 -0
- package/dist/esm/lib/generator/Generator.js +388 -0
- package/dist/esm/lib/generator/Preprocessor.js +87 -0
- package/dist/esm/lib/generator/TypeScriptTypes.js +149 -0
- package/dist/esm/lib/library/NativeCallback.js +59 -0
- package/dist/esm/lib/library/NativeLibraryHandle.js +532 -0
- package/dist/esm/lib/library/Resolve.js +122 -0
- package/dist/esm/lib/thread/NativeThreads.js +377 -0
- package/dist/esm/lib/thread/NativeWorker.js +93 -0
- package/dist/esm/lib/thread/NativeWorkerCode.js +1 -0
- package/dist/esm/lib/thread/PackageRequire.js +2 -0
- package/dist/esm/lib/thread/ThreadProtocol.js +1 -0
- package/dist/types/components/NativeLibrary.d.ts +229 -0
- package/dist/types/decorators/Library.d.ts +61 -0
- package/dist/types/decorators/Native.d.ts +69 -0
- package/dist/types/exceptions/NativeDeclarationException.d.ts +12 -0
- package/dist/types/exceptions/NativeLibraryClosedException.d.ts +12 -0
- package/dist/types/exceptions/NativeLibraryNotFoundException.d.ts +11 -0
- package/dist/types/exceptions/NativeMemoryException.d.ts +11 -0
- package/dist/types/exports/FFI.d.ts +12 -0
- package/dist/types/exports/Generator.d.ts +2 -0
- package/dist/types/lib/Memory.d.ts +188 -0
- package/dist/types/lib/Runtime.d.ts +98 -0
- package/dist/types/lib/backend/Functions.d.ts +65 -0
- package/dist/types/lib/backend/KoffiTypes.d.ts +53 -0
- package/dist/types/lib/declarations/Builtins.d.ts +33 -0
- package/dist/types/lib/declarations/Layout.d.ts +41 -0
- package/dist/types/lib/declarations/Lexer.d.ts +40 -0
- package/dist/types/lib/declarations/Parser.d.ts +90 -0
- package/dist/types/lib/declarations/Platform.d.ts +50 -0
- package/dist/types/lib/declarations/Types.d.ts +173 -0
- package/dist/types/lib/generator/CText.d.ts +14 -0
- package/dist/types/lib/generator/Generator.d.ts +136 -0
- package/dist/types/lib/generator/Preprocessor.d.ts +60 -0
- package/dist/types/lib/generator/TypeScriptTypes.d.ts +35 -0
- package/dist/types/lib/library/NativeCallback.d.ts +44 -0
- package/dist/types/lib/library/NativeLibraryHandle.d.ts +268 -0
- package/dist/types/lib/library/Resolve.d.ts +49 -0
- package/dist/types/lib/thread/NativeThreads.d.ts +80 -0
- package/dist/types/lib/thread/NativeWorker.d.ts +6 -0
- package/dist/types/lib/thread/NativeWorkerCode.d.ts +5 -0
- package/dist/types/lib/thread/PackageRequire.d.ts +6 -0
- package/dist/types/lib/thread/ThreadProtocol.d.ts +77 -0
- package/package.json +85 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const nativeWorkerCode = "var require=typeof require==='function'?require:process.getBuiltinModule('node:module').createRequire(process.cwd()+'/');globalThis[Symbol.for('lakutata.ffi.koffi')]=require(require('node:worker_threads').workerData.koffi);\nvar te=Object.create;var dt=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var ne=Object.getPrototypeOf;var se=Object.prototype.hasOwnProperty;var f=(s,t)=>dt(s,\"name\",{value:t,configurable:true});var re=(s,t)=>()=>{try{return t||s((t={exports:{}}).exports,t),t.exports}catch(e){throw t=0,e}};var oe=(s,t,e,i)=>{if(t&&typeof t===\"object\"||typeof t===\"function\"){for(let n of ie(t))if(!se.call(s,n)&&n!==e)dt(s,n,{get:()=>t[n],enumerable:!(i=ee(t,n))||i.enumerable})}return s};var S=(s,t,e)=>(e=s!=null?te(ne(s)):{},oe(t||!s||!s.__esModule?dt(e,\"default\",{value:s,enumerable:true}):e,s));var P=re((Be,$t)=>{\"use strict\";$t.exports=globalThis[Symbol.for(\"lakutata.ffi.koffi\")]});var lt=require(\"node:worker_threads\");var F=S(P(),1);var A=class extends Error{static{f(this,\"Exception\")}errno=\"E_EXCEPTION\";constructor(t){super(t);this.name=new.target.name}};var w=class extends A{static{f(this,\"NativeDeclarationException\")}constructor(){super(...arguments);this.errno=\"E_NATIVE_DECLARATION\"}};var L=class extends A{static{f(this,\"NativeLibraryClosedException\")}constructor(){super(...arguments);this.errno=\"E_NATIVE_LIBRARY_CLOSED\"}};var X=S(P(),1);function Tt(){return{types:new Map,tags:new Map,functions:new Map,variables:new Map,constants:new Map,macros:new Map}}f(Tt,\"emptyDeclarations\");var mt={kind:\"primitive\",name:\"void\"};function V(s,t){switch(s){case\"void\":return 0;case\"bool\":case\"char\":case\"schar\":case\"uchar\":case\"int8\":case\"uint8\":return 1;case\"short\":case\"ushort\":case\"int16\":case\"uint16\":case\"char16\":return 2;case\"int\":case\"uint\":case\"int32\":case\"uint32\":case\"char32\":case\"float\":return 4;case\"long\":case\"ulong\":return t.longSize;case\"longlong\":case\"ulonglong\":case\"int64\":case\"uint64\":case\"double\":return 8;case\"size\":case\"ssize\":case\"intptr\":case\"uintptr\":case\"ptrdiff\":return t.pointerSize;case\"wchar\":return t.wcharSize}}f(V,\"primitiveSize\");function nt(s,t){switch(s){case\"char\":return true;case\"schar\":case\"short\":case\"int\":case\"long\":case\"longlong\":case\"int8\":case\"int16\":case\"int32\":case\"int64\":case\"ssize\":case\"intptr\":case\"ptrdiff\":case\"float\":case\"double\":return true;case\"wchar\":return t.os!==\"win32\";default:return false}}f(nt,\"primitiveSigned\");function D(s){switch(s){case\"long\":case\"ulong\":case\"longlong\":case\"ulonglong\":case\"int64\":case\"uint64\":case\"size\":case\"ssize\":case\"intptr\":case\"uintptr\":case\"ptrdiff\":return true;default:return false}}f(D,\"primitiveBig\");function x(s){switch(s.kind){case\"primitive\":return ae[s.name];case\"pointer\":return`${s.constTarget?\"const \":\"\"}${x(s.to)} *`;case\"array\":return`${x(s.of)}[${s.length}]`;case\"struct\":case\"union\":return`${s.kind} ${s.tag??\"(anonymous)\"}`;case\"enum\":return`enum ${s.tag??\"(anonymous)\"}`;case\"function\":return`${x(s.result)} (${s.parameters.map(t=>x(t.type)).concat(s.variadic?[\"...\"]:[]).join(\", \")})`}}f(x,\"typeText\");var ae={void:\"void\",bool:\"bool\",char:\"char\",schar:\"signed char\",uchar:\"unsigned char\",short:\"short\",ushort:\"unsigned short\",int:\"int\",uint:\"unsigned int\",long:\"long\",ulong:\"unsigned long\",longlong:\"long long\",ulonglong:\"unsigned long long\",int8:\"int8_t\",uint8:\"uint8_t\",int16:\"int16_t\",uint16:\"uint16_t\",int32:\"int32_t\",uint32:\"uint32_t\",int64:\"int64_t\",uint64:\"uint64_t\",size:\"size_t\",ssize:\"ssize_t\",intptr:\"intptr_t\",uintptr:\"uintptr_t\",ptrdiff:\"ptrdiff_t\",char16:\"char16_t\",char32:\"char32_t\",wchar:\"wchar_t\",float:\"float\",double:\"double\"};var E=S(P(),1);var Et=new WeakMap;function j(s,t){switch(s.kind){case\"primitive\":return V(s.name,t);case\"pointer\":return t.pointerSize;case\"array\":return j(s.of,t)*s.length;case\"enum\":return V(s.base,t);case\"struct\":case\"union\":return U(s,t).size;case\"function\":throw new w(`A function has no size: ${x(s)}`)}}f(j,\"sizeOf\");function z(s,t){switch(s.kind){case\"primitive\":case\"enum\":{const e=V(s.kind===\"primitive\"?s.name:s.base,t);return e===8?t.int64Alignment:Math.max(e,1)}case\"pointer\":return t.pointerSize;case\"array\":return z(s.of,t);case\"struct\":case\"union\":return U(s,t).alignment;case\"function\":throw new w(`A function has no alignment: ${x(s)}`)}}f(z,\"alignmentOf\");function C(s,t){return Math.ceil(s/t)*t}f(C,\"alignUp\");function U(s,t){let e=Et.get(s);const i=e?.get(t);if(i)return i;if(!s.members)throw new w(`The ${s.kind} ${s.tag??\"(anonymous)\"} is declared but not defined: it is used through pointers only`);const n=s.kind===\"union\"?ce(s,t):ue(s,t);if(!e)Et.set(s,e=new Map);e.set(t,n);return n}f(U,\"layoutOf\");function Ot(s,t,e){const i=Math.max(z(s.type,e),s.align??1);return t.pack?Math.min(i,t.pack):i}f(Ot,\"memberAlignment\");function ce(s,t){let e=0;let i=s.align??1;const n=[];for(const r of s.members){if(r.bits!==void 0)throw new w(`The bitfield ${r.name||\"(unnamed)\"} of a union is not supported`);const o=j(r.type,t);i=Math.max(i,Ot(r,s,t));e=Math.max(e,o);n.push({member:r,offset:0,size:o})}return{size:C(e,i),alignment:i,members:n,bitfields:false}}f(ce,\"unionLayout\");function ue(s,t){let e=0;let i=s.align??1;let n=false;let r;const o=[];for(const a of s.members){if(a.bits===void 0){r=void 0;const y=Ot(a,s,t);const v=C(Math.ceil(e/8),y);const l=j(a.type,t);o.push({member:a,offset:v,size:l});e=(v+l)*8;i=Math.max(i,y);continue}n=true;if(s.pack!==void 0)throw new w(`The bitfield ${a.name||\"(unnamed)\"} of a packed struct is not supported`);if(a.type.kind!==\"primitive\"&&a.type.kind!==\"enum\")throw new w(`The bitfield ${a.name||\"(unnamed)\"} must have an integer type`);const c=j(a.type,t);const h=z(a.type,t);const p=a.bits;if(p>c*8)throw new w(`The bitfield ${a.name||\"(unnamed)\"} is wider than its type (${p} bits)`);if(t.bitfields===\"msvc\"){if(p===0){if(r){e=C((r.offset+r.size)*8,h*8);i=Math.max(i,h)}r=void 0;continue}if(!r||r.size!==c||r.used+p>c*8){const y=r?r.offset+r.size:Math.ceil(e/8);r={offset:C(y,h),size:c,used:0};i=Math.max(i,h)}o.push({member:a,offset:r.offset,size:c,bitOffset:r.offset*8+r.used,bits:p});r.used+=p;e=(r.offset+r.size)*8;continue}if(a.name||t.bitfields===\"aapcs\")i=Math.max(i,h);if(p===0){e=C(e,h*8);continue}if(e%(c*8)+p>c*8)e=C(e,h*8);o.push({member:a,offset:Math.floor(e/(c*8))*c,size:c,bitOffset:e,bits:p});e+=p}if(r)e=(r.offset+r.size)*8;return{size:C(Math.ceil(e/8),i),alignment:i,members:o,bitfields:n}}f(ue,\"structLayout\");var At={void:\"void\",bool:\"bool\",char:\"char\",schar:\"int8_t\",uchar:\"uchar\",short:\"short\",ushort:\"ushort\",int:\"int\",uint:\"uint\",long:\"long\",ulong:\"ulong\",longlong:\"longlong\",ulonglong:\"ulonglong\",int8:\"int8_t\",uint8:\"uint8_t\",int16:\"int16_t\",uint16:\"uint16_t\",int32:\"int32_t\",uint32:\"uint32_t\",int64:\"int64_t\",uint64:\"uint64_t\",size:\"size_t\",ssize:\"intptr_t\",intptr:\"intptr_t\",uintptr:\"uintptr_t\",ptrdiff:\"intptr_t\",char16:\"char16_t\",char32:\"char32_t\",wchar:\"wchar_t\",float:\"float\",double:\"double\"};var B=\"__lakutata_\";function pt(s){return typeof s===\"number\"?BigInt(s):s}f(pt,\"toBigInt\");function Lt(s){if(s.kind===\"primitive\")return s.name;if(s.kind===\"enum\")return s.base;return void 0}f(Lt,\"integerName\");function It(s,t){return Math.ceil(s/t)*t}f(It,\"alignUp\");var st=class{static{f(this,\"KoffiTypes\")}#r;#n=new WeakMap;#c=new WeakMap;#a=new WeakMap;constructor(t){this.#r=t}type(t){switch(t.kind){case\"primitive\":return At[t.name];case\"enum\":return At[t.base];case\"pointer\":return this.#o(t.to);case\"array\":return this.#u(t,()=>E.default.array(this.type(t.of),t.length));case\"struct\":case\"union\":if(t.tag===\"va_list\"&&!t.members)throw new w(\"A va_list cannot be passed: call the function of the library that takes the arguments themselves\");return this.#f(t);case\"function\":throw new w(`A function is not a value: use a pointer to it (${x(t)})`)}}prototype(t){const e=this.#a.get(t);if(e)return e;if(t.variadic)throw new w(`A callback cannot be variadic: ${x(t)}`);const i=E.default.proto(`__${t.convention}`,this.type(t.result),t.parameters.map(n=>this.type(n.type)));this.#a.set(t,i);return i}converter(t){const e=this.#c.get(t);if(e!==void 0)return e;let i=null;switch(t.kind){case\"primitive\":case\"enum\":if(D(Lt(t)))i={fromNative:pt};break;case\"array\":{const n=this.converter(t.of);if(n){i={...n.toNative?{toNative:f(r=>Array.isArray(r)?r.map(n.toNative):r,\"toNative\")}:{},...n.fromNative?{fromNative:f(r=>r&&typeof r!==\"string\"?Array.from(r,n.fromNative):r,\"fromNative\")}:{}}}break}case\"struct\":case\"union\":if(t.members){this.#c.set(t,null);i=this.#v(t)}break}this.#c.set(t,i);return i}#o(t){if(t.kind===\"primitive\"){if(t.name===\"char\")return\"char *\";if(t.name===\"char16\")return\"char16_t *\";if(t.name===\"wchar\")return\"wchar_t *\";if(t.name===\"void\")return\"void *\"}if(t.kind===\"function\")return this.#u(t,()=>E.default.pointer(this.prototype(t)));if((t.kind===\"struct\"||t.kind===\"union\")&&!t.members)return this.#u(t,()=>E.default.pointer(E.default.opaque()));return E.default.pointer(this.type(t))}#u(t,e){let i=this.#n.get(t);if(!i){i=e();this.#n.set(t,i)}return i}#f(t){const e=this.#n.get(t);if(e)return e;const i=U(t,this.#r);const n=E.default.opaque();this.#n.set(t,n);const r=this.#b(t,i);const o=t.kind===\"union\"?E.default.union(n,r):E.default.struct(n,r);this.#n.set(t,o);const a=t.kind===\"struct\"?i.members.find(c=>c.bits===void 0&&!!o.members?.[c.member.name]&&o.members[c.member.name].offset!==c.offset):void 0;if(o.size!==i.size||o.alignment!==i.alignment||a){throw new w(`The layout of ${x(t)} could not be given to koffi (${o.size} bytes aligned on ${o.alignment}, ${i.size} on ${i.alignment} expected${a?`, ${a.member.name} at ${o.members[a.member.name].offset}, ${a.offset} expected`:\"\"})`)}return o}#b(t,e){const i=[];if(t.kind===\"union\"){for(const c of e.members)i.push({name:c.member.name,type:this.type(c.member.type),offset:0,size:c.size,alignment:this.#h(c.member,t)})}else{let c=0;for(const h of this.#l(e)){if(\"bitfields\"in h){i.push({name:`${B}bits${c++}`,type:E.default.array(\"uint8_t\",h.size,\"Typed\"),offset:h.offset,size:h.size,alignment:1});continue}if(h.member.type.kind===\"array\"&&h.member.type.length===0)continue;i.push({name:h.member.name,type:this.type(h.member.type),offset:h.offset,size:h.size,alignment:this.#h(h.member,t)})}}const n={};let r=0;let o=1;let a=0;i.forEach((c,h)=>{if(t.kind===\"struct\"&&It(r,c.alignment)!==c.offset){n[`${B}pad${a++}`]=[1,E.default.array(\"uint8_t\",c.offset-r,\"Typed\")];r=c.offset}const p=h===0&&e.alignment>c.alignment&&this.#w(i,e)?e.alignment:c.alignment;n[c.name]=p===this.#p(c.type)?c.type:[p,c.type];o=Math.max(o,p);r=t.kind===\"struct\"?c.offset+c.size:Math.max(r,c.size)});if(!i.length)n[`${B}pad${a++}`]=[e.alignment,E.default.array(\"uint8_t\",e.size||1,\"Typed\")];else if(t.kind===\"struct\"&&It(r,Math.max(o,e.alignment))<e.size)n[`${B}pad${a++}`]=[1,E.default.array(\"uint8_t\",e.size-r,\"Typed\")];return n}#w(t,e){return Math.max(1,...t.map(i=>i.alignment))<e.alignment}#p(t){return E.default.type(t).alignment}#h(t,e){const i=Math.max(z(t.type,this.#r),t.align??1);return e.pack?Math.min(i,e.pack):i}#l(t){const e=[];for(const i of t.members){if(i.bits===void 0){e.push({member:i.member,offset:i.offset,size:i.size});continue}const n=Math.floor(i.bitOffset/8);const r=Math.ceil((i.bitOffset+i.bits)/8);const o=e[e.length-1];if(o&&\"bitfields\"in o&&n<=o.offset+o.size){o.bitfields.push(i);o.size=Math.max(o.size,r-o.offset)}else{e.push({bitfields:[i],offset:n,size:r-n})}}return e}#v(t){const e=U(t,this.#r);const i=t.kind===\"struct\"?this.#l(e):e.members.map(l=>({member:l.member,offset:0,size:l.size}));const n=this.#f(t);const r=Object.keys(n.members??{}).some(l=>l.startsWith(B));const o=[];const a=[];let c=0;for(const l of i){if(\"bitfields\"in l){const m=`${B}bits${c++}`;for(const u of l.bitfields){if(!u.member.name)continue;const d=Lt(u.member.type);a.push({name:u.member.name,chunk:m,offset:u.bitOffset-l.offset*8,bits:u.bits,signed:nt(d,this.#r),big:D(d)})}continue}if(l.member.type.kind===\"array\"&&l.member.type.length===0)continue;o.push({name:l.member.name,converter:this.converter(l.member.type)})}const h=o.filter(l=>!!l.converter);if(!h.length&&!a.length&&!r)return null;const p=new Map(i.filter(l=>\"bitfields\"in l).map((l,m)=>[`${B}bits${m}`,l.size]));const y=h.filter(l=>!!l.converter.toNative);const v=y.length>0||a.length>0;return{...v?{toNative:f(l=>{if(!l||typeof l!==\"object\"||ArrayBuffer.isView(l))return l;const m={...l};for(const u of y)if(u.name in m)m[u.name]=u.converter.toNative(m[u.name]);if(a.length){const u=new Map([...p].map(([d,g])=>[d,new Uint8Array(g)]));for(const d of a){const g=m[d.name];delete m[d.name];if(g===void 0||g===null)continue;he(u.get(d.chunk),d.offset,d.bits,BigInt(g))}for(const[d,g]of u)m[d]=g}return m},\"toNative\")}:{},fromNative:f(l=>{if(!l||typeof l!==\"object\")return l;const m={};for(const u of o)if(u.name in l)m[u.name]=u.converter?.fromNative?u.converter.fromNative(l[u.name]):l[u.name];for(const u of a){const d=fe(l[u.chunk],u.offset,u.bits,u.signed);m[u.name]=u.big?d:Number(d)}return m},\"fromNative\")}}};function fe(s,t,e,i){let n=0n;for(let r=e-1;r>=0;r--){const o=t+r;n=n<<1n|BigInt(s[o>>3]>>(o&7)&1)}return i?BigInt.asIntN(e,n):n}f(fe,\"readBits\");function he(s,t,e,i){const n=BigInt.asUintN(e,i);for(let r=0;r<e;r++){const o=t+r;if(n>>BigInt(r)&1n)s[o>>3]|=1<<(o&7);else s[o>>3]&=~(1<<(o&7))}}f(he,\"writeBits\");function zt(s){if(typeof s!==\"bigint\")return s;if(s>BigInt(Number.MAX_SAFE_INTEGER)||s<BigInt(Number.MIN_SAFE_INTEGER))throw new RangeError(`${s} is not a safe integer: declare the function without int64: 'number' to get a bigint`);return Number(s)}f(zt,\"toSafeNumber\");function St(s){return s.kind===\"pointer\"&&s.to.kind===\"primitive\"&&[\"char\",\"char16\",\"wchar\"].includes(s.to.name)}f(St,\"isString\");function Pt(s,t){const e=s.to.name;return X.default.disposable(e===\"char\"?\"char *\":e===\"char16\"?\"char16_t *\":\"wchar_t *\",t)}f(Pt,\"disposableString\");function Y(s,t,e){const i=s.parameters.map(r=>t.converter(r.type));const n=t.converter(s.result);if(!i.some(r=>!!r?.fromNative)&&!n?.toNative)return e;return(...r)=>{for(let a=0;a<i.length;a++)if(i[a]?.fromNative)r[a]=i[a].fromNative(r[a]);const o=e(...r);return n?.toNative?n.toNative(o):o}}f(Y,\"convertedCallback\");function le(s,t,e){const i=[];s.parameters.forEach((n,r)=>{const o=n.type.kind===\"pointer\"?n.type.to:void 0;if(n.direction===\"in\"){if(o?.kind===\"function\"){const h=o;const p=f(()=>void 0,\"probe\");if(Y(h,t,p)===p)return;i.push({index:r,before:f(y=>typeof y===\"function\"?Y(h,t,y):y,\"before\")});return}const c=t.converter(o&&(o.kind===\"struct\"||o.kind===\"union\")?o:n.type);if(c?.toNative&&(n.type.kind!==\"pointer\"||o?.kind===\"struct\"||o?.kind===\"union\")){i.push({index:r,before:f(h=>_t(h)?c.toNative(h):h,\"before\")})}return}if(!o)return;if(o.kind===\"primitive\"&&D(o.name)||o.kind===\"enum\"&&D(o.base)){const c=e.int64===\"number\"?zt:pt;i.push({index:r,after:f(h=>{if(Array.isArray(h))h[0]=c(h[0])},\"after\")});return}const a=t.converter(o);if(a&&(o.kind===\"struct\"||o.kind===\"union\")){i.push({index:r,before:f(c=>_t(c)?n.direction===\"inout\"&&a.toNative?a.toNative(c):{...c}:c,\"before\"),after:f((c,h)=>{if(_t(c)&&h!==c)Object.assign(c,a.fromNative?a.fromNative(h):h)},\"after\")})}});return i}f(le,\"argumentSteps\");function _t(s){return!!s&&typeof s===\"object\"&&!ArrayBuffer.isView(s)&&!Array.isArray(s)&&Object.getPrototypeOf(s)===Object.prototype}f(_t,\"isPlainObject\");function Rt(s,t,e,i,n={}){const r=t.type;if(n.async&&r.variadic)throw new w(`The variadic function ${t.name} cannot be called asynchronously`);const o=n.free&&St(r.result)?Pt(r.result,n.free):e.type(r.result);const a=r.parameters.map(m=>{const u=m.type.kind===\"pointer\"?m.type.to:void 0;if(m.direction===\"in\")return e.type(m.type);if(!u)throw new w(`The parameter ${m.name??\"\"} of ${t.name} is ${m.direction===\"out\"?\"_Out_\":\"_Inout_\"} but not a pointer (${x(m.type)})`.replace(\" \",\" \"));const d=n.free&&St(u)?X.default.pointer(Pt(u,n.free)):e.type(m.type);return m.direction===\"out\"?X.default.out(d):X.default.inout(d)});let c;try{c=s.func(`__${r.convention}`,t.symbol,o,r.variadic?[...a,\"...\"]:a)}catch(m){throw new w(`The function ${t.name} cannot be bound (${t.symbol}): ${m.message}`)}const h=le(r,e,n);const p=n.int64===\"number\"&&(r.result.kind===\"primitive\"&&D(r.result.name))?zt:e.converter(r.result)?.fromNative;const y=r.parameters.length;const v=f(m=>{const u=m.slice();for(const d of h)if(d.before)u[d.index]=d.before(m[d.index]);if(r.variadic){for(let d=y;d<u.length;d+=2)if(typeof u[d]===\"string\")u[d]=i(u[d])}return u},\"prepare\");const l=f((m,u,d)=>{for(const g of h)if(g.after)g.after(m[g.index],u[g.index]);return p?p(d):d},\"finish\");if(!n.async){if(!h.length&&!p&&!r.variadic)return c;return(...m)=>{const u=v(m);return l(m,u,c(...u))}}return(...m)=>{try{n.calls?.start()}catch(d){return Promise.reject(d)}let u;try{u=v(m)}catch(d){n.calls?.end();return Promise.reject(d)}return new Promise((d,g)=>{try{c.async(...u,(b,N)=>{n.calls?.end();if(b)return g(b);try{d(l(m,u,N))}catch(k){g(k)}})}catch(b){n.calls?.end();g(b)}})}}f(Rt,\"bindFunction\");var _=f(s=>({kind:\"primitive\",name:s}),\"primitive\");var $=f((s,t=false)=>({kind:\"pointer\",to:s,constTarget:t}),\"pointer\");var de={kind:\"struct\",tag:\"FILE\"};var me={kind:\"struct\",tag:\"va_list\"};var pe={kind:\"struct\",tag:\"_GUID\",members:[{name:\"Data1\",type:_(\"uint32\")},{name:\"Data2\",type:_(\"uint16\")},{name:\"Data3\",type:_(\"uint16\")},{name:\"Data4\",type:{kind:\"array\",of:_(\"uint8\"),length:8}}]};var _e=[\"HANDLE\",\"HWND\",\"HINSTANCE\",\"HMODULE\",\"HKEY\",\"HDC\",\"HGLOBAL\",\"HLOCAL\",\"HMENU\",\"HICON\",\"HBITMAP\",\"HBRUSH\",\"HFONT\",\"HPEN\",\"HRGN\",\"HCURSOR\",\"HMONITOR\",\"HRSRC\",\"HGDIOBJ\",\"HACCEL\",\"HDESK\",\"HWINSTA\",\"HHOOK\",\"HEVENT\",\"HKL\",\"HPALETTE\",\"HDROP\",\"HDEVINFO\",\"SC_HANDLE\",\"SERVICE_STATUS_HANDLE\",\"PSID\",\"HCRYPTPROV\"];function Mt(s){const t=s.os===\"win32\";const e=s.os===\"darwin\";const i=new Map;const n=f((r,o)=>{for(const a of typeof r===\"string\"?[r]:r)i.set(a,o)},\"set\");for(const r of[8,16,32,64]){n([`int${r}_t`,`int_least${r}_t`,`int_fast${r}_t`,`__int${r}_t`],_(`int${r}`));n([`uint${r}_t`,`uint_least${r}_t`,`uint_fast${r}_t`,`__uint${r}_t`,`u_int${r}_t`],_(`uint${r}`))}n([\"intmax_t\"],_(\"int64\"));n([\"uintmax_t\"],_(\"uint64\"));n([\"size_t\",\"rsize_t\"],_(\"size\"));n([\"ssize_t\"],_(\"ssize\"));n([\"intptr_t\"],_(\"intptr\"));n([\"uintptr_t\"],_(\"uintptr\"));n([\"ptrdiff_t\"],_(\"ptrdiff\"));n([\"wchar_t\"],_(\"wchar\"));n([\"char16_t\"],_(\"char16\"));n([\"char32_t\"],_(\"char32\"));n([\"bool\"],_(\"bool\"));n([\"time_t\"],_(t?\"int64\":\"long\"));n([\"suseconds_t\"],_(e?\"int32\":\"long\"));n([\"useconds_t\"],_(\"uint32\"));n([\"off_t\"],_(e?\"int64\":\"long\"));n([\"clock_t\"],_(e?\"ulong\":\"long\"));n([\"pid_t\"],_(\"int32\"));n([\"uid_t\",\"gid_t\",\"socklen_t\"],_(\"uint32\"));n([\"mode_t\"],_(e?\"uint16\":\"uint32\"));n([\"FILE\"],de);n([\"va_list\",\"__builtin_va_list\",\"__gnuc_va_list\",\"__darwin_va_list\",\"__va_list\"],me);n([\"u_char\"],_(\"uint8\"));n([\"u_short\"],_(\"uint16\"));n([\"u_int\"],_(\"uint32\"));n([\"u_long\"],_(\"ulong\"));n([\"u_quad_t\"],_(\"uint64\"));n([\"quad_t\"],_(\"int64\"));n([\"caddr_t\"],$(_(\"char\")));n([\"BYTE\",\"UCHAR\",\"BOOLEAN\",\"UINT8\"],_(\"uint8\"));n([\"CHAR\",\"CCHAR\"],_(\"char\"));n([\"INT8\"],_(\"int8\"));n([\"WCHAR\"],_(\"char16\"));n([\"SHORT\",\"INT16\"],_(\"int16\"));n([\"USHORT\",\"WORD\",\"ATOM\",\"LANGID\",\"UINT16\"],_(\"uint16\"));n([\"INT\",\"LONG\",\"BOOL\",\"HRESULT\",\"NTSTATUS\",\"LONG32\",\"INT32\",\"HFILE\"],_(\"int32\"));n([\"UINT\",\"ULONG\",\"DWORD\",\"DWORD32\",\"ULONG32\",\"UINT32\",\"COLORREF\",\"LCID\"],_(\"uint32\"));n([\"LONGLONG\",\"LONG64\",\"INT64\"],_(\"int64\"));n([\"ULONGLONG\",\"DWORDLONG\",\"QWORD\",\"DWORD64\",\"ULONG64\",\"UINT64\"],_(\"uint64\"));n([\"FLOAT\"],_(\"float\"));n([\"DOUBLE\"],_(\"double\"));n([\"INT_PTR\",\"LONG_PTR\",\"LPARAM\",\"LRESULT\",\"SSIZE_T\"],_(\"intptr\"));n([\"UINT_PTR\",\"ULONG_PTR\",\"DWORD_PTR\",\"WPARAM\",\"SIZE_T\"],_(\"uintptr\"));n(_e,$(_(\"void\")));n([\"PVOID\",\"LPVOID\"],$(_(\"void\")));n([\"LPCVOID\",\"PCVOID\"],$(_(\"void\"),true));n([\"LPSTR\",\"PSTR\",\"PCHAR\"],$(_(\"char\")));n([\"LPCSTR\",\"PCSTR\"],$(_(\"char\"),true));n([\"LPWSTR\",\"PWSTR\",\"PWCHAR\"],$(_(\"char16\")));n([\"LPCWSTR\",\"PCWSTR\"],$(_(\"char16\"),true));n([\"LPBYTE\",\"PBYTE\",\"PUCHAR\",\"PBOOLEAN\"],$(_(\"uint8\")));n([\"LPWORD\",\"PWORD\",\"PUSHORT\"],$(_(\"uint16\")));n([\"LPDWORD\",\"PDWORD\",\"PULONG\",\"PUINT\",\"LPUINT\"],$(_(\"uint32\")));n([\"LPLONG\",\"PLONG\",\"LPINT\",\"PINT\",\"LPBOOL\",\"PBOOL\"],$(_(\"int32\")));n([\"PULONGLONG\",\"PDWORD64\"],$(_(\"uint64\")));n([\"PLONGLONG\"],$(_(\"int64\")));n([\"PSIZE_T\",\"PULONG_PTR\",\"PDWORD_PTR\"],$(_(\"uintptr\")));n([\"PHANDLE\",\"LPHANDLE\"],$($(_(\"void\"))));n([\"GUID\",\"UUID\",\"CLSID\",\"IID\"],pe);return i}f(Mt,\"builtinTypes\");var Z=new Map([[\"__cdecl\",\"cdecl\"],[\"_cdecl\",\"cdecl\"],[\"__stdcall\",\"stdcall\"],[\"_stdcall\",\"stdcall\"],[\"__fastcall\",\"fastcall\"],[\"_fastcall\",\"fastcall\"],[\"__thiscall\",\"thiscall\"],[\"WINAPI\",\"stdcall\"],[\"APIENTRY\",\"stdcall\"],[\"CALLBACK\",\"stdcall\"],[\"PASCAL\",\"stdcall\"],[\"NTAPI\",\"stdcall\"],[\"STDMETHODCALLTYPE\",\"stdcall\"],[\"STDAPICALLTYPE\",\"stdcall\"],[\"WINAPIV\",\"cdecl\"],[\"CDECL\",\"cdecl\"]]);var q=new Set([\"volatile\",\"restrict\",\"__restrict\",\"__restrict__\",\"_Nullable\",\"_Nonnull\",\"_Null_unspecified\",\"__nullable\",\"__nonnull\",\"__null_unspecified\",\"_Nullable_result\",\"__unaligned\",\"__ptr32\",\"__ptr64\",\"__w64\",\"__sptr\",\"__uptr\",\"FAR\",\"NEAR\",\"far\",\"near\",\"OPTIONAL\",\"register\",\"auto\",\"__extension__\",\"_Noreturn\",\"noreturn\",\"__volatile__\",\"__kindof\",\"__cdecl__\",\"__weak\",\"__strong\",\"__autoreleasing\",\"__unsafe_unretained\"]);var W=new Set([\"const\",\"__const\",\"__const__\",\"CONST\"]);var Dt=new Set([\"inline\",\"__inline\",\"__inline__\",\"__forceinline\",\"_inline\",\"FORCEINLINE\"]);var ge=[\"_In_\",\"_Out\",\"_Inout\",\"_COM_Outptr\",\"_Ret_\",\"_Success_\",\"_Check_return_\",\"_Must_inspect_result_\",\"_Printf_format_string_\",\"_Scanf_format_string_\",\"_Field_\",\"_Frees_ptr_\",\"_Pre_\",\"_Post_\",\"_Deref_\",\"_Reserved_\",\"_Null_terminated_\",\"_NullNull_terminated_\",\"_Use_decl_annotations_\",\"_When_\",\"_At_\",\"_At_buffer_\",\"_Always_\",\"_Return_type_success_\",\"_Struct_size_bytes_\",\"_Readable_\",\"_Writable_\",\"__drv_\",\"_IRQL_\",\"_Kernel_\",\"_Function_class_\",\"_Callback_\",\"_Notnull_\",\"_Maybenull_\",\"_Const_\",\"_Translates_\",\"_Points_to_data_\",\"_Literal_\",\"_Notliteral_\",\"_Strict_type_match_\",\"_Analysis_\",\"_Acquires_\",\"_Releases_\",\"_Requires_\",\"_Guarded_by_\",\"_Interlocked_\",\"_Inexpressible_\",\"_Pre_satisfies_\",\"_Outref_\",\"_Ret_maybenull_\",\"_Result_\",\"_Group_\",\"_On_failure_\"];function Q(s){if(s===\"IN\")return\"in\";if(s===\"OUT\")return\"out\";if(!ge.some(t=>s.startsWith(t))&&![\"_In_\",\"_Out_\",\"_Inout_\"].includes(s))return void 0;if(s.startsWith(\"_Inout\"))return\"inout\";if(s.startsWith(\"_Out\")||s.startsWith(\"_COM_Outptr\"))return\"out\";if(s.startsWith(\"_In_\"))return\"in\";return null}f(Q,\"annotationDirection\");var be=[\"...\",\"<<=\",\">>=\",\"<<\",\">>\",\"<=\",\">=\",\"==\",\"!=\",\"&&\",\"||\",\"->\",\"++\",\"--\",\"##\",\"::\"];var we=\"{}()[];,*:=+-/%&|^~!?<>.#\";var ye={n:10,t:9,r:13,\"0\":0,a:7,b:8,f:12,v:11,\"\\\\\":92,\"'\":39,'\"':34,\"?\":63,e:27};var ve=[\"if\",\"ifdef\",\"ifndef\",\"elif\",\"elifdef\",\"elifndef\",\"else\",\"endif\"];function ke(s,t){let e=t;while(e<s.length&&s[e]!==\"\\n\"){const i=s[e];if(i===\"\\\\\"&&s[e+1]===\"\\n\"){e+=2}else if(i===\"\\\\\"&&s[e+1]===\"\\r\"&&s[e+2]===\"\\n\"){e+=3}else if(i===\"/\"&&s[e+1]===\"*\"){const n=s.indexOf(\"*/\",e+2);e=n<0?s.length:n+2}else if(i===\"/\"&&s[e+1]===\"/\"){while(e<s.length&&s[e]!==\"\\n\")e++}else if(i==='\"'||i===\"'\"){e++;while(e<s.length&&s[e]!==i&&s[e]!==\"\\n\")e+=s[e]===\"\\\\\"?2:1;if(s[e]===i)e++}else{e++}}return e}f(ke,\"directiveEnd\");function xe(s){let t=\"\";let e=0;while(e<s.length){const i=s[e];if(i===\"/\"&&s[e+1]===\"*\"){const n=s.indexOf(\"*/\",e+2);e=n<0?s.length:n+2;t+=\" \"}else if(i===\"/\"&&s[e+1]===\"/\"){while(e<s.length&&s[e]!==\"\\n\")e++}else if(i==='\"'||i===\"'\"){let n=e+1;while(n<s.length&&s[n]!==i&&s[n]!==\"\\n\")n+=s[n]===\"\\\\\"?2:1;t+=s.slice(e,Math.min(n+1,s.length));e=n+1}else if(i===\"\\\\\"&&(s[e+1]===\"\\n\"||s[e+1]===\"\\r\"&&s[e+2]===\"\\n\")){e+=s[e+1]===\"\\n\"?2:3;t+=\" \"}else{t+=i;e++}}return t.trim()}f(xe,\"withoutComments\");function Ne(s){const t=[0];for(let e=0;e<s.length;e++)if(s.charCodeAt(e)===10)t.push(e+1);return t}f(Ne,\"lineStartsOf\");function rt(s,t){let e=0;let i=s.length-1;while(e<i){const n=e+i+1>>1;if(s[n]<=t)e=n;else i=n-1}return{line:e+1,column:t-s[e]+1}}f(rt,\"positionOf\");function gt(s,t,e){return new w(`${s} (line ${t}, column ${e})`)}f(gt,\"declarationError\");function $e(s){const t=s.match(/^(?:line\\s+)?(\\d+)(?:\\s+\"((?:[^\"\\\\]|\\\\.)*)\")?/);if(!t)return void 0;return{line:Number(t[1]),...t[2]!==void 0?{file:t[2].replace(/\\\\(.)/g,\"$1\")}:{}}}f($e,\"lineMarker\");function H(s){const t=[];const e=s.length;let i=0;let n=true;const r=Ne(s);let o;let a=0;let c=false;const h=f((l,m)=>{const{line:u,column:d}=rt(r,m);throw gt(l,u,d)},\"fail\");const p=f((l,m,u,d={})=>{const{line:g,column:b}=rt(r,m);t.push({kind:l,text:d.text??s.slice(m,u),value:d.value,float:d.float,line:g,column:b,...c?{file:o,fileLine:g+a}:{},...d.source!==void 0?{source:d.source}:{}})},\"push\");while(i<e){const l=s[i];if(l===\"\\n\"){n=true;i++;continue}if(l===\" \"||l===\"\t\"||l===\"\\r\"||l===\"\\f\"||l===\"\\v\"){i++;continue}if(l===\"\\\\\"&&(s[i+1]===\"\\n\"||s[i+1]===\"\\r\"&&s[i+2]===\"\\n\")){i+=s[i+1]===\"\\n\"?2:3;continue}if(l===\"/\"&&s[i+1]===\"/\"){while(i<e&&s[i]!==\"\\n\")i++;continue}if(l===\"/\"&&s[i+1]===\"*\"){const u=s.indexOf(\"*/\",i+2);if(u<0)h(\"A comment is not closed\",i);i=u+2;continue}if(l===\"#\"&&n){const u=i;const d=ke(s,i);const g=xe(s.slice(u+1,d));const b=g.match(/^[A-Za-z_]\\w*/)?.[0]??\"\";if(ve.includes(b))h(`The directive #${b} is not supported: run the header through the preprocessor first (cc -E, cl /P)`,u);const N=b===\"\"||b===\"line\"?$e(g):void 0;if(N){c=true;if(N.file!==void 0)o=N.file;a=N.line-(rt(r,u).line+1)}const k=g.match(/^pragma\\s+pack\\s*\\(([^)]*)\\)/);if(k)p(\"pragma\",u,d,{text:`pack(${k[1].replace(/\\s+/g,\"\")})`});if(b===\"define\"||b===\"undef\")p(b,u,d,{text:g.slice(b.length).trim()});i=d;continue}n=false;if(/[A-Za-z_$]/.test(l)){let u=i+1;while(u<e&&/[\\w$]/.test(s[u]))u++;const d=s.slice(i,u);if((s[u]===\"'\"||s[u]==='\"')&&[\"L\",\"u\",\"U\",\"u8\"].includes(d)){i=u;continue}p(\"identifier\",i,u);i=u;continue}if(/[0-9]/.test(l)||l===\".\"&&/[0-9]/.test(s[i+1]??\"\")){let u=i;const d=/^0[xX]/.test(s.slice(i,i+2));if(d)u+=2;while(u<e&&(/[\\w.]/.test(s[u])||/[eEpP]/.test(s[u-1])&&/[+-]/.test(s[u])&&(!d||/[pP]/.test(s[u-1]))))u++;const g=s.slice(i,u);const b=g.replace(/(?:[uU](?:ll|LL|l|L)?|(?:ll|LL|l|L)[uU]?|[uU]?[iI](?:8|16|32|64))$/,\"\");const N=d?/[.pP]/.test(b):/[.eE]/.test(b)||/[fF]$/.test(g);if(N){p(\"number\",i,u,{float:true})}else{let k;try{if(/^0[bB]/.test(b))k=BigInt(b);else if(/^0[0-7]+$/.test(b))k=BigInt(`0o${b.slice(1)}`);else k=BigInt(b)}catch{return h(`The number ${g} is not valid`,i)}p(\"number\",i,u,{value:k})}i=u;continue}if(l===\"'\"||l==='\"'){let u=i+1;const d=[];while(u<e&&s[u]!==l){if(s[u]===\"\\n\")h(l==='\"'?\"A string is not closed\":\"A character is not closed\",i);if(s[u]===\"\\\\\"){const g=s[u+1];if(g===\"x\"){const b=s.slice(u+2).match(/^[0-9a-fA-F]+/)?.[0]??\"\";d.push(parseInt(b||\"0\",16));u+=2+b.length}else if(/[0-7]/.test(g)){const b=s.slice(u+1).match(/^[0-7]{1,3}/)[0];d.push(parseInt(b,8));u+=1+b.length}else{d.push(ye[g]??g.charCodeAt(0));u+=2}}else{d.push(s.codePointAt(u));u+=s.codePointAt(u)>65535?2:1}}if(u>=e)h(l==='\"'?\"A string is not closed\":\"A character is not closed\",i);if(l===\"'\")p(\"char\",i,u+1,{value:BigInt(d[0]??0)});else p(\"string\",i,u+1,{text:String.fromCodePoint(...d),source:s.slice(i,u+1)});i=u+1;continue}const m=be.find(u=>s.startsWith(u,i));if(m){p(\"punctuator\",i,i+m.length);i+=m.length;continue}if(we.includes(l)){p(\"punctuator\",i,i+1);i++;continue}h(`Unexpected character ${JSON.stringify(l)}`,i)}const{line:y,column:v}=rt(r,e);t.push({kind:\"end\",text:\"\",line:y,column:v});return t}f(H,\"tokenize\");var bt=new Set([\"void\",\"char\",\"short\",\"int\",\"long\",\"float\",\"double\",\"signed\",\"unsigned\",\"__signed\",\"__signed__\",\"_Bool\",\"__int8\",\"__int16\",\"__int32\",\"__int64\",\"__int128\",\"_Complex\",\"__complex__\",\"_Float16\",\"__fp16\",\"_Float128\",\"__float128\"]);var R=new Set([\"__attribute__\",\"__attribute\",\"__declspec\"]);var Ct=new Set([\"__asm__\",\"__asm\",\"asm\"]);var Te=new Set([\"_Alignas\",\"alignas\",\"__alignas\"]);var K=class{static{f(this,\"DeclarationParser\")}#r;#n;#c;#a=[];#o=0;#u;#f=[];#b;#w;#p;constructor(t,e=Tt()){this.#r=t;this.#n=e;this.#c=Mt(t)}get declarations(){return this.#n}parse(t){this.#a=this.#h(H(t));this.#o=0;while(!this.#y(\"end\"))this.#g();this.#O();return this.#n}readSource(t){const e=[];const i=new Map;this.#p=i;try{this.#a=this.#h(H(t))}finally{this.#p=void 0}this.#o=0;this.#b=e;try{while(!this.#y(\"end\"))this.#T()}finally{this.#b=void 0}this.#O();return{declarations:this.#n,items:e,macros:i}}prototype(t){this.#a=this.#h(H(t));this.#o=0;const e=this.#e();const i=this.#x(false);const n=this.#N(false);const{type:r}=n.build(i.base,i.constant);if(r.kind!==\"function\"||!n.name)throw this.#i(\"A function prototype is expected\",e);this.#m();const o=this.#M()??n.asm;if(this.#s(\";\"))this.#t();if(!this.#y(\"end\"))throw this.#i(`Unexpected ${this.#$(this.#e())} after the prototype`,this.#e());return{name:n.name,symbol:this.#L(n.name,o),type:this.#z(r,n.convention??i.convention)}}typeName(t){this.#a=this.#h(H(t));this.#o=0;const e=this.#x(false);const i=this.#N(true);if(i.name)throw this.#i(`A type is expected, not a declaration of ${i.name}`,i.token);if(!this.#y(\"end\"))throw this.#i(`Unexpected ${this.#$(this.#e())} after the type`,this.#e());return i.build(e.base,e.constant).type}constant(t){this.#a=this.#h(H(t));this.#o=0;const e=this.#D();if(!this.#y(\"end\"))throw this.#i(`Unexpected ${this.#$(this.#e())} after the expression`,this.#e());return e.value}#h(t){const e=this.#n.macros;const i=[];const n=f((r,o,a)=>{const c=r.kind===\"identifier\"&&!o.has(r.text)?e.get(r.text):void 0;if(c===null&&!this.#p)throw this.#i(`The macro ${r.text} takes arguments: the macros with arguments are not supported (write what it expands to)`,a);if(!c)return void i.push(r);const h=new Set(o).add(r.text);for(const p of c)n({...p,line:a.line,column:a.column,...a.file!==void 0?{file:a.file,fileLine:a.fileLine}:{}},h,a)},\"expandInto\");for(const r of t){if(r.kind===\"define\"){this.#v(r);continue}if(r.kind===\"undef\"){e.delete(r.text.match(/^[A-Za-z_]\\w*/)?.[0]??\"\");continue}n(r,new Set,r)}return this.#l(i)}#l(t){if(!t.some(i=>i.kind===\"identifier\"&&i.text===\"__pragma\"))return t;const e=[];for(let i=0;i<t.length;i++){const n=t[i];if(n.kind!==\"identifier\"||n.text!==\"__pragma\"||t[i+1]?.text!==\"(\"){e.push(n);continue}let r=0;let o=i+1;for(;o<t.length-1;o++){if(t[o].kind!==\"punctuator\")continue;if(t[o].text===\"(\")r++;else if(t[o].text===\")\"&&--r===0)break}const a=t.slice(i+2,o);if(a[0]?.text===\"pack\"&&a[1]?.text===\"(\")e.push({...n,kind:\"pragma\",text:`pack(${a.slice(2,-1).map(c=>c.text).join(\"\")})`});i=o}return e}#v(t){const e=t.text.match(/^[A-Za-z_]\\w*/)?.[0];if(!e)throw this.#i(\"#define without a name\",t);const i=t.text.slice(e.length);this.#p?.set(e,{...t.file!==void 0?{file:t.file}:{},...t.fileLine!==void 0?{line:t.fileLine}:{}});if(i.startsWith(\"(\")){this.#n.macros.set(e,null);return}const n=[];let r;try{r=H(i)}catch(o){if(!this.#p)throw o;this.#n.macros.set(e,null);return}for(const o of r){if(o.kind===\"end\")break;if(o.kind===\"pragma\"||o.kind===\"define\"||o.kind===\"undef\")continue;n.push({kind:o.kind,text:o.text,...o.value!==void 0?{value:o.value}:{},...o.float?{float:true}:{}})}this.#n.macros.set(e,n)}#O(){const t=this.#a;const e=this.#o;for(const[i,n]of this.#n.macros){if(!n?.length||this.#n.constants.has(i))continue;try{const r={kind:\"end\",text:\"\",line:0,column:0};this.#a=[...this.#h([{kind:\"identifier\",text:i,line:0,column:0}]),r];this.#o=0;const o=this.#k();if(this.#y(\"end\"))this.#n.constants.set(i,o.value)}catch{}}this.#a=t;this.#o=e}#T(){const t=this.#o;const e=this.#e();if(e.kind===\"identifier\"&&e.text===\"extern\"&&this.#e(1).kind===\"string\"&&this.#s(\"{\",2)){this.#o+=3;while(!this.#s(\"}\")&&!this.#y(\"end\"))this.#T();if(this.#s(\"}\"))this.#t();return}const i=this.#u;const n=[];this.#w=n;let r;try{this.#g()}catch(o){r=(o instanceof Error?o.message:String(o)).replace(/ \\(line \\d+, column \\d+\\)$/,\"\");this.#o=this.#A(t)}finally{this.#w=void 0}this.#b.push({...e.file!==void 0?{file:e.file}:{},...e.fileLine!==void 0?{line:e.fileLine}:{},tokens:this.#a.slice(t,this.#o),names:n,...i!==void 0?{pack:i}:{},...r!==void 0?{error:r}:{}})}#A(t){const e=this.#a;let i=0;let n=false;for(let r=t;r<e.length-1;r++){const o=e[r];if(o.kind===\"pragma\"&&i===0&&r>t)return r;if(o.kind!==\"punctuator\")continue;if(o.text===\"{\"&&i===0)n=r>t&&e[r-1].text===\")\";if(o.text===\"(\"||o.text===\"[\"||o.text===\"{\"){i++}else if(o.text===\")\"||o.text===\"]\"||o.text===\"}\"){i=Math.max(0,i-1);if(o.text===\"}\"&&i===0&&n)return e[r+1]?.text===\";\"?r+2:r+1}else if(o.text===\";\"&&i===0){return r+1}}return e.length-1}#_(t){this.#w?.push(t)}#g(){const t=this.#e();if(t.kind===\"pragma\"){this.#t();return this.#U(t)}if(this.#s(\";\")){this.#t();return}if(t.kind===\"identifier\"&&t.text===\"extern\"&&this.#e(1).kind===\"string\"){this.#t();this.#t();if(this.#s(\"{\")){this.#t();while(!this.#s(\"}\")){if(this.#y(\"end\"))throw this.#i('extern \"C\" { is not closed',t);this.#g()}this.#t()}return}if(t.kind===\"identifier\"&&[\"_Static_assert\",\"static_assert\"].includes(t.text)){this.#t();this.#E();this.#d(\";\");return}const e=this.#x(true);if(this.#s(\";\")){this.#t();return}for(;;){const i=this.#N(false);this.#m();const n=this.#M()??i.asm;this.#m();if(this.#s(\"{\")){this.#E();return}let r;if(this.#s(\"=\")){this.#t();r=this.#K()}this.#P(e,i,n,r);if(this.#s(\",\")){this.#t();continue}this.#d(\";\");return}}#P(t,e,i,n){if(!e.name)throw this.#i(\"A name is expected in the declaration\",this.#e());const r=e.name;const{type:o,constant:a}=e.build(t.base,t.constant);if(t.storage===\"typedef\"){const c=this.#n.types.get(r);if(c&&c!==o&&x(c)!==x(o))throw this.#i(`The type ${r} is declared again as another type (${x(c)}, then ${x(o)})`,e.token);this.#n.types.set(r,o);this.#_(`type ${r}`);return}if(o.kind===\"function\"){if(t.storage===\"static\")return;this.#n.functions.set(r,{name:r,symbol:this.#L(r,i),type:this.#z(o,e.convention??t.convention)});this.#_(`function ${r}`);return}if(t.storage===\"static\"){if(n&&a){this.#n.constants.set(r,n.value);this.#_(`constant ${r}`)}return}if(t.threadLocal)throw this.#i(`The variable ${r} is thread-local: it cannot be reached through the library`,e.token);this.#n.variables.set(r,{name:r,symbol:this.#L(r,i),type:o,constant:a});this.#_(`variable ${r}`)}#L(t,e){if(e===void 0)return t;return this.#r.underscoredSymbols&&e.startsWith(\"_\")?e.slice(1):e}#z(t,e){if(t.variadic)return t;return e&&e!==t.convention?{...t,convention:e}:t}#U(t){const e=t.text.slice(5,-1).split(\",\").filter(Boolean);const i=f(n=>{if(n===void 0)return void 0;const r=Number(n);if(![1,2,4,8,16].includes(r))throw this.#i(`#pragma pack(${n}) is not a packing of 1, 2, 4, 8 or 16`,t);return r>=16?void 0:r},\"value\");if(!e.length){this.#u=void 0}else if(e[0]===\"push\"){this.#f.push(this.#u);const n=e.slice(1).find(r=>/^\\d+$/.test(r));if(n!==void 0)this.#u=i(n)}else if(e[0]===\"pop\"){this.#u=this.#f.length?this.#f.pop():void 0}else{this.#u=i(e[0])}}#x(t){const e=this.#e();const i=[];let n;const r={base:mt,inline:false,constant:false,threadLocal:false};for(;;){const o=this.#e();if(o.kind!==\"identifier\"){if(this.#s(\"[\")&&this.#s(\"[\",1)){this.#E();continue}break}const a=o.text;if(W.has(a)){this.#t();r.constant=true;continue}if(q.has(a)){this.#t();continue}if(Dt.has(a)){this.#t();r.inline=true;continue}if(Z.has(a)){this.#t();r.convention=Z.get(a);continue}if(R.has(a)){const c=this.#m()?.align;if(c)r.align=c;continue}if(Te.has(a)){r.align=this.#q();continue}if(a===\"typedef\"||a===\"extern\"||a===\"static\"){if(!t)throw this.#i(`${a} is not allowed here`,o);this.#t();r.storage=a;continue}if(a===\"_Thread_local\"||a===\"__thread\"||a===\"thread_local\"){this.#t();r.threadLocal=true;continue}if(a===\"struct\"||a===\"union\"){if(n||i.length)throw this.#i(`${a} after another type`,o);n=this.#G(a);continue}if(a===\"enum\"){if(n||i.length)throw this.#i(`enum after another type`,o);n=this.#V();continue}if(bt.has(a)){if(n)throw this.#i(`${a} after another type`,o);this.#t();i.push(a);continue}if(!this.#I(a)){const c=Q(a);if(c!==void 0){this.#t();if(this.#s(\"(\"))this.#E();if(c)r.direction=c;continue}}if(!n&&!i.length){const c=this.#I(a);if(c){this.#t();n=c;continue}throw this.#B(o)}break}if(i.length)n=this.#F(i,e);if(!n)throw this.#e().kind===\"identifier\"?this.#B(this.#e()):this.#i(`A type is expected, not ${this.#$(this.#e())}`,this.#e());r.base=n;return r}#B(t){const e=/^[A-Z][A-Z0-9_]*$/.test(t.text)?\": a macro? give its #define with the declarations\":\"\";return this.#i(`Unknown type ${t.text}${e}`,t)}#F(t,e){const i=f(h=>t.filter(p=>p===h).length,\"count\");const n=i(\"unsigned\")>0;const r=i(\"signed\")+i(\"__signed\")+i(\"__signed__\")>0;const o=i(\"long\");const a=f(h=>({kind:\"primitive\",name:h}),\"name\");const c=f(h=>t.includes(h),\"has\");if([\"__int128\",\"_Complex\",\"__complex__\",\"_Float16\",\"__fp16\",\"_Float128\",\"__float128\"].some(c))throw this.#i(`The type ${t.join(\" \")} is not supported`,e);if(c(\"void\"))return mt;if(c(\"_Bool\"))return a(\"bool\");if(c(\"float\"))return a(\"float\");if(c(\"double\")){if(o)throw this.#i(\"long double is not supported\",e);return a(\"double\")}if(c(\"char\"))return a(n?\"uchar\":r?\"schar\":\"char\");if(c(\"__int8\"))return a(n?\"uint8\":\"int8\");if(c(\"__int16\"))return a(n?\"uint16\":\"int16\");if(c(\"__int32\"))return a(n?\"uint32\":\"int32\");if(c(\"__int64\"))return a(n?\"uint64\":\"int64\");if(c(\"short\"))return a(n?\"ushort\":\"short\");if(o>=2)return a(n?\"ulonglong\":\"longlong\");if(o===1)return a(n?\"ulong\":\"long\");return a(n?\"uint\":\"int\")}#I(t){return this.#n.types.get(t)??this.#c.get(t)}#G(t){const e=this.#t();let i=this.#m();let n;let r;if(this.#e().kind===\"identifier\"&&!R.has(this.#e().text)){r=this.#t();n=r.text;i=this.#m()??i}const o=`${t} ${n}`;let a;if(n){const l=this.#n.tags.get(o);if(l&&l.kind!==t)throw this.#i(`${n} is a ${l.kind}, not a ${t}`,r);a=l}if(!this.#s(\"{\")){if(!n)throw this.#i(`A ${t} without a name must be defined`,e);if(!a){a={kind:t,tag:n};this.#n.tags.set(o,a)}return a}if(a?.members)throw this.#i(`The ${t} ${n} is defined again`,r);if(!a){a={kind:t,tag:n};if(n)this.#n.tags.set(o,a)}this.#t();const c=[];let h=0;while(!this.#s(\"}\")){if(this.#y(\"end\"))throw this.#i(`The ${t} ${n??\"\"} is not closed`.replace(\" \",\" \"),e);if(this.#e().kind===\"pragma\"){this.#U(this.#t());continue}if(this.#s(\";\")){this.#t();continue}const l=this.#x(false);if(this.#s(\";\")){this.#t();if(l.base.kind===\"struct\"||l.base.kind===\"union\")c.push({name:`_${h++}`,type:l.base,align:l.align});continue}for(;;){let m;if(!this.#s(\":\"))m=this.#N(false);let u;if(this.#s(\":\")){this.#t();const N=this.#k();u=Number(N.value);if(u<0)throw this.#i(\"A bitfield has a negative width\",this.#e())}const d=this.#m();if(!m?.name&&u===void 0)throw this.#i(\"A member name is expected\",this.#e());const g=m?m.build(l.base,l.constant).type:l.base;if(g.kind===\"function\")throw this.#i(`The member ${m?.name} is a function: a pointer to a function is expected`,m?.token??this.#e());if(g.kind===\"struct\"||g.kind===\"union\"){if(!g.members)throw this.#i(`The member ${m?.name} has the type ${x(g)}, declared but not defined`,m?.token??this.#e())}const b=d?.align??m?.align??l.align;c.push({name:m?.name??\"\",type:g,...u!==void 0?{bits:u}:{},...b?{align:b}:{}});if(this.#s(\",\")){this.#t();continue}this.#d(\";\");break}}this.#t();const p=this.#m();const y=!!(i?.packed||p?.packed);a.members=c;if(n)this.#_(o);if(y)a.pack=1;else if(this.#u!==void 0)a.pack=this.#u;const v=p?.align??i?.align;if(v)a.align=v;return a}#V(){const t=this.#t();this.#m();let e;if(this.#e().kind===\"identifier\"&&!R.has(this.#e().text))e=this.#t().text;this.#m();let i;if(this.#s(\":\")){this.#t();const c=this.#x(false).base;if(c.kind!==\"primitive\"||c.name===\"void\"||c.name===\"float\"||c.name===\"double\")throw this.#i(\"The type of an enumeration must be an integer type\",t);i=c.name}const n=`enum ${e}`;if(!this.#s(\"{\")){const c=e?this.#n.tags.get(n):void 0;if(c?.kind===\"enum\")return c;if(!e)throw this.#i(\"An enumeration without a name must be defined\",t);const h={kind:\"enum\",tag:e,base:i??\"int\",values:new Map};this.#n.tags.set(n,h);return h}this.#t();const r=new Map;let o=0n;while(!this.#s(\"}\")){const c=this.#t();if(c.kind!==\"identifier\")throw this.#i(`An enumerator name is expected, not ${this.#$(c)}`,c);this.#m();if(this.#s(\"=\")){this.#t();o=this.#k().value}r.set(c.text,o);this.#n.constants.set(c.text,o);this.#_(`constant ${c.text}`);o++;if(this.#s(\",\"))this.#t();else if(!this.#s(\"}\"))throw this.#i(`, or } is expected, not ${this.#$(this.#e())}`,this.#e())}this.#t();this.#m();const a={kind:\"enum\",tag:e,base:i??this.#j([...r.values()]),values:r};if(e){this.#n.tags.set(n,a);this.#_(n)}return a}#j(t){const e=t.some(n=>n<0n);const i=f((n,r)=>t.every(o=>o>=n&&o<=r),\"fits\");if(i(-(2n**31n),2n**31n-1n))return\"int\";if(!e&&i(0n,2n**32n-1n))return\"uint\";if(this.#r.bitfields===\"msvc\")return\"int\";if(i(-(2n**63n),2n**63n-1n))return\"longlong\";return\"ulonglong\"}#N(t){const e=[];let i;let n;let r;for(;;){const l=this.#e();if(this.#s(\"*\")){this.#t();e.push(false);continue}if(l.kind!==\"identifier\")break;if(W.has(l.text)&&e.length){this.#t();e[e.length-1]=true;continue}if(W.has(l.text)||q.has(l.text)){this.#t();continue}if(Z.has(l.text)){this.#t();i=Z.get(l.text);continue}if(R.has(l.text)){r=this.#m()?.align??r;continue}const m=this.#I(l.text)?void 0:Q(l.text);if(m!==void 0){this.#t();if(this.#s(\"(\"))this.#E();if(m)n=m;continue}break}let o;let a;let c;if(this.#e().kind===\"identifier\"){a=this.#t();o=a.text}else if(this.#s(\"(\")&&this.#Y()){this.#t();c=this.#N(t);this.#d(\")\")}const h=[];for(;;){if(this.#s(\"[\")){this.#t();if(this.#s(\"]\")){this.#t();h.push({array:0});continue}while(this.#e().kind===\"identifier\"&&(this.#e().text===\"static\"||W.has(this.#e().text)||q.has(this.#e().text)))this.#t();const l=this.#k();this.#d(\"]\");if(l.value<0n)throw this.#i(\"An array has a negative length\",this.#e());h.push({array:Number(l.value)});continue}if(this.#s(\"(\")){h.push({function:this.#Z()});continue}break}while(this.#e().kind===\"identifier\"&&(R.has(this.#e().text)||q.has(this.#e().text))){if(R.has(this.#e().text))r=this.#m()?.align??r;else this.#t()}let p;if(this.#e().kind===\"identifier\"&&Ct.has(this.#e().text))p=this.#M();const y=c?.convention??i;const v={name:o??c?.name,token:a??c?.token,convention:c?i:void 0,asm:p??c?.asm,direction:n??c?.direction,align:r??c?.align,build:f((l,m)=>{let u=l;let d=m;for(const g of e){u={kind:\"pointer\",to:u,constTarget:d};d=g}for(let g=h.length-1;g>=0;g--){const b=h[g];if(\"array\"in b){if(u.kind===\"function\")throw this.#i(\"An array of functions is not allowed\",a??this.#e());u={kind:\"array\",of:u,length:b.array}}else{u={kind:\"function\",result:u,parameters:b.function.parameters,variadic:b.function.variadic,convention:(c&&!b.function.variadic?y:void 0)??\"cdecl\"}}}if(c)return c.build(u,d&&!h.length);return{type:u,constant:d}},\"build\")};if(!c&&i)v.convention=i;return v}#Y(){const t=this.#e(1);if(t.kind===\"punctuator\")return t.text===\"*\"||t.text===\"(\"||t.text===\"[\";if(t.kind!==\"identifier\")return false;if(Z.has(t.text)||R.has(t.text))return true;if(bt.has(t.text)||W.has(t.text)||[\"struct\",\"union\",\"enum\"].includes(t.text)||this.#I(t.text))return false;return Q(t.text)===void 0}#Z(){const t=this.#t();const e=[];let i=false;if(this.#s(\")\")){this.#t();return{parameters:e,variadic:false}}if(this.#e().text===\"void\"&&this.#s(\")\",1)){this.#t();this.#t();return{parameters:e,variadic:false}}if(this.#e().kind===\"identifier\"&&!this.#R(this.#e())&&(this.#s(\",\",1)||this.#s(\")\",1))){throw this.#i(`Unknown type ${this.#e().text} (a parameter needs a type: the declarations of the old style, names without types, are not supported)`,this.#e())}for(;;){if(this.#s(\"...\")){this.#t();i=true;this.#d(\")\");break}const n=this.#x(false);const r=this.#N(true);let{type:o}=r.build(n.base,n.constant);if(o.kind===\"array\")o={kind:\"pointer\",to:o.of,constTarget:n.constant};if(o.kind===\"function\")o={kind:\"pointer\",to:o,constTarget:false};if(o.kind===\"primitive\"&&o.name===\"void\")throw this.#i(\"A parameter cannot be void\",t);e.push({...r.name?{name:r.name}:{},type:o,direction:r.direction??n.direction??\"in\"});if(this.#s(\",\")){this.#t();continue}this.#d(\")\");break}return{parameters:e,variadic:i}}#R(t){if(t.kind!==\"identifier\")return false;const e=t.text;return bt.has(e)||W.has(e)||q.has(e)||[\"struct\",\"union\",\"enum\"].includes(e)||!!this.#I(e)||Q(e)!==void 0}#m(){let t;while(this.#e().kind===\"identifier\"&&R.has(this.#e().text)){const e=this.#t();if(!this.#s(\"(\"))throw this.#i(`( is expected after ${e.text}`,e);const i=this.#o;this.#E();const n=this.#a.slice(i+1,this.#o-1);t??={packed:false};for(let r=0;r<n.length;r++){const o=n[r].text.replace(/^__(.*)__$/,\"$1\");if(o===\"packed\")t.packed=true;if(o===\"aligned\"||o===\"align\"){if(n[r+1]?.text!==\"(\"){t.align=16}else{const a=n[r+2]?.value;if(a===void 0)throw this.#i(`The alignment of ${o} must be a number`,n[r]);t.align=Number(a)}}}if(t.align!==void 0&&![1,2,4,8].includes(t.align))throw this.#i(`An alignment of ${t.align} bytes is not supported (1, 2, 4 or 8)`,e)}return t}#q(){const t=this.#t();this.#d(\"(\");let e;if(this.#R(this.#e())){const i=this.#x(false);e=z(this.#N(true).build(i.base,i.constant).type,this.#r)}else{e=Number(this.#k().value)}this.#d(\")\");if(![1,2,4,8].includes(e))throw this.#i(`An alignment of ${e} bytes is not supported (1, 2, 4 or 8)`,t);return e}#M(){if(this.#e().kind!==\"identifier\"||!Ct.has(this.#e().text))return void 0;this.#t();this.#d(\"(\");let t=\"\";while(this.#e().kind===\"string\")t+=this.#t().text;this.#d(\")\");return t}#K(){if(this.#s(\"{\")){this.#E();return void 0}const t=this.#o;try{return this.#k()}catch{this.#o=t;let e=0;while(!this.#y(\"end\")){const i=this.#e();if(i.kind===\"punctuator\"&&\"([{\".includes(i.text))e++;if(i.kind===\"punctuator\"&&\")]}\".includes(i.text))e--;if(e<=0&&i.kind===\"punctuator\"&&(i.text===\",\"||i.text===\";\"))break;this.#t()}return void 0}}#D(){let t=this.#k();while(this.#s(\",\")){this.#t();t=this.#k()}return t}#k(){const t=this.#W(0);if(!this.#s(\"?\"))return t;this.#t();const e=this.#D();this.#d(\":\");const i=this.#k();return t.value!==0n?e:i}#W(t){let e=this.#C();for(;;){const i=this.#e();const n=i.kind===\"punctuator\"?Ee[i.text]:void 0;if(n===void 0||n<t)return e;this.#t();const r=this.#W(n+1);e=this.#J(i,e,r)}}#J(t,e,i){const n=Math.max(e.bits,i.bits);const r=e.unsigned&&e.bits>=i.bits||i.unsigned&&i.bits>=e.bits;const o=e.value;const a=i.value;const c=f((p,y={unsigned:r,bits:n})=>this.#S(p,y.unsigned,y.bits),\"result\");const h=f(p=>({value:p?1n:0n,unsigned:false,bits:32}),\"truth\");switch(t.text){case\"*\":return c(o*a);case\"/\":case\"%\":if(a===0n)throw this.#i(\"Division by zero in a constant expression\",t);return c(t.text===\"/\"?o/a:o%a);case\"+\":return c(o+a);case\"-\":return c(o-a);case\"<<\":return c(o<<a,e);case\">>\":return c(o>>a,e);case\"<\":return h(o<a);case\">\":return h(o>a);case\"<=\":return h(o<=a);case\">=\":return h(o>=a);case\"==\":return h(o===a);case\"!=\":return h(o!==a);case\"&\":return c(o&a);case\"^\":return c(o^a);case\"|\":return c(o|a);case\"&&\":return h(o!==0n&&a!==0n);case\"||\":return h(o!==0n||a!==0n)}throw this.#i(`The operator ${t.text} is not allowed in a constant expression`,t)}#S(t,e,i){if(e)return{value:BigInt.asUintN(i,t),unsigned:true,bits:i};return{value:t,unsigned:false,bits:i}}#C(){const t=this.#e();if(t.kind===\"punctuator\"){if([\"+\",\"-\",\"~\",\"!\"].includes(t.text)){this.#t();const e=this.#C();switch(t.text){case\"+\":return e;case\"-\":return this.#S(-e.value,e.unsigned,e.bits);case\"~\":return this.#S(~e.value,e.unsigned,e.bits);default:return{value:e.value===0n?1n:0n,unsigned:false,bits:32}}}if(t.text===\"(\"&&this.#R(this.#e(1))){this.#t();const e=this.#H();this.#d(\")\");return this.#X(this.#C(),e,t)}}if(t.kind===\"identifier\"&&(t.text===\"sizeof\"||[\"_Alignof\",\"alignof\",\"__alignof__\",\"__alignof\"].includes(t.text))){this.#t();this.#d(\"(\");if(!this.#R(this.#e()))throw this.#i(`${t.text} of an expression is not supported: give a type`,t);const e=this.#H();this.#d(\")\");const i=t.text===\"sizeof\"?j(e,this.#r):z(e,this.#r);return{value:BigInt(i),unsigned:true,bits:this.#r.pointerSize*8}}return this.#Q()}#H(){const t=this.#x(false);return this.#N(true).build(t.base,t.constant).type}#X(t,e,i){const n=e.kind===\"primitive\"?e.name:e.kind===\"enum\"?e.base:void 0;if(e.kind===\"pointer\")return this.#S(t.value,true,this.#r.pointerSize*8);if(!n||n===\"void\"||n===\"float\"||n===\"double\")throw this.#i(`A cast to ${x(e)} is not allowed in a constant expression`,i);const r=V(n,this.#r)*8;if(n===\"bool\")return{value:t.value===0n?0n:1n,unsigned:true,bits:8};const o=!nt(n,this.#r);return o?this.#S(t.value,true,r):{value:BigInt.asIntN(r,t.value),unsigned:false,bits:r}}#Q(){const t=this.#t();if(t.kind===\"number\"){if(t.float)throw this.#i(`The floating-point number ${t.text} is not allowed in an integer constant expression`,t);return this.#tt(t)}if(t.kind===\"char\")return{value:t.value,unsigned:false,bits:32};if(t.kind===\"identifier\"){const e=this.#n.constants.get(t.text);if(e===void 0)throw this.#i(`Unknown constant ${t.text}: a macro is not known (write its value)`,t);return{value:e,unsigned:e>2n**31n-1n,bits:e>2n**32n-1n||e<-(2n**31n)?64:32}}if(t.kind===\"punctuator\"&&t.text===\"(\"){const e=this.#D();this.#d(\")\");return e}throw this.#i(`A constant expression is expected, not ${this.#$(t)}`,t)}#tt(t){const e=t.value;const i=t.text.match(/[uUlL]+$/)?.[0].toLowerCase()??\"\";const n=i.includes(\"u\");const r=(i.match(/l/g)??[]).length;const o=!/^0/.test(t.text)||t.text===\"0\";const a=this.#r.longSize*8;const c=[];if(r===0)c.push({bits:32,unsigned:false},{bits:32,unsigned:true});if(r<=1)c.push({bits:a,unsigned:false},{bits:a,unsigned:true});c.push({bits:64,unsigned:false},{bits:64,unsigned:true});for(const h of c){if(n&&!h.unsigned)continue;if(o&&!n&&h.unsigned)continue;const p=h.unsigned?2n**BigInt(h.bits)-1n:2n**BigInt(h.bits-1)-1n;if(e<=p)return{value:e,unsigned:h.unsigned,bits:h.bits}}throw this.#i(`The number ${t.text} is too large`,t)}#E(){const t=this.#t();const e={\"(\":\")\",\"[\":\"]\",\"{\":\"}\"};const i=[e[t.text]];while(i.length){const n=this.#t();if(n.kind===\"end\")throw this.#i(`${t.text} is not closed`,t);if(n.kind!==\"punctuator\")continue;if(e[n.text])i.push(e[n.text]);else if(n.text===i[i.length-1])i.pop()}}#e(t=0){return this.#a[Math.min(this.#o+t,this.#a.length-1)]}#t(){const t=this.#e();if(this.#o<this.#a.length-1)this.#o++;return t}#y(t){return this.#e().kind===t}#s(t,e=0){const i=this.#e(e);return i.kind===\"punctuator\"&&i.text===t}#d(t){if(!this.#s(t))throw this.#i(`${t} is expected, not ${this.#$(this.#e())}`,this.#e());return this.#t()}#$(t){return t.kind===\"end\"?\"the end\":JSON.stringify(t.text)}#i(t,e){return gt(t,e.line,e.column)}};var Ee={\"||\":1,\"&&\":2,\"|\":3,\"^\":4,\"&\":5,\"==\":6,\"!=\":6,\"<\":7,\">\":7,\"<=\":7,\">=\":7,\"<<\":8,\">>\":8,\"+\":9,\"-\":9,\"*\":10,\"/\":10,\"%\":10};function Oe(s,t){const e=![\"ia32\",\"arm\",\"x32\"].includes(t);const i=s===\"win32\";return{os:s,arch:t,pointerSize:e?8:4,longSize:e&&!i?8:4,wcharSize:i?2:4,int64Alignment:!e&&!i&&t===\"ia32\"?4:8,bitfields:i?\"msvc\":(t===\"arm\"||t===\"arm64\")&&s!==\"darwin\"?\"aapcs\":\"sysv\",underscoredSymbols:s===\"darwin\"}}f(Oe,\"platformOf\");var J=Oe(process.platform,process.arch);var O=S(P(),1);var I=class extends A{static{f(this,\"NativeMemoryException\")}constructor(){super(...arguments);this.errno=\"E_NATIVE_MEMORY\"}};var at=require(\"node:fs\");var ot=S(require(\"node:path\"),1);var Bt=S(P(),1);var M=class extends A{static{f(this,\"NativeLibraryNotFoundException\")}constructor(){super(...arguments);this.errno=\"E_NATIVE_LIBRARY_NOT_FOUND\"}};function Ae(){try{const s=(0,at.readdirSync)(\"/lib\").find(t=>/^ld-musl-.*\\.so\\.1$/.test(t));return s?`/lib/${s}`:void 0}catch{return void 0}}f(Ae,\"muslLoader\");function Le(s,t){switch(t){case\"darwin\":return\"/usr/lib/libSystem.B.dylib\";case\"win32\":return\"ucrtbase.dll\";case\"linux\":return Ae()??(s===\"c\"?\"libc.so.6\":\"libm.so.6\");case\"freebsd\":return s===\"c\"?\"libc.so.7\":\"libm.so.5\";default:return s===\"c\"?\"libc.so\":\"libm.so\"}}f(Le,\"systemLibrary\");function Ut(s,t=process.platform){if(s===\"c\"||s===\"m\")return[Le(s,t)];if(/[/\\\\]/.test(s)||/\\.(dylib|dll|so)(\\.\\d+)*$/i.test(s))return[s];switch(t){case\"darwin\":return[`lib${s}.dylib`,`${s}.dylib`];case\"win32\":return[`${s}.dll`,`lib${s}.dll`];default:return[`lib${s}.so`,`${s}.so`]}}f(Ut,\"fileNames\");function Ie(s,t=process.platform){if(typeof s===\"string\")return Ut(s,t);const e=s[t]??s.default;if(e===void 0)throw new M(`The library has no name for ${t} (give one for ${t}, or a default)`);return(typeof e===\"string\"?[e]:e).flatMap(i=>Ut(i,t))}f(Ie,\"libraryNames\");function wt(s,t={}){const e=[];const i=f(a=>{try{return Bt.default.load(a)}catch(c){e.push(`${a}: ${c.message}`);return void 0}},\"attempt\");if(t.path){const a=ot.default.resolve(t.path);const c=i(a);if(c)return{library:c,file:a};throw new M(`The library cannot be loaded:\n${e.join(\"\\n\")}`)}const n=[...t.search??[],...t.packaged?[t.packaged]:[]].map(a=>ot.default.resolve(a));const r=Ie(s);for(const a of r){if(/[/\\\\]/.test(a)){const c=i(a);if(c)return{library:c,file:a};continue}for(const c of n){const h=ot.default.join(c,a);if(!(0,at.existsSync)(h)){e.push(`${h}: not found`);continue}const p=i(h);if(p)return{library:p,file:h}}}for(const a of r.filter(c=>!/[/\\\\]/.test(c))){const c=i(a);if(c)return{library:c,file:a}}const o=process.platform===\"linux\"&&r.some(a=>a.endsWith(\".so\"))?\"\\nOn Linux, the libraries of the system are often installed with their version only (libsqlite3.so.0): give that name.\":\"\";throw new M(`The library ${r.join(\" or \")} cannot be loaded:\n${e.join(\"\\n\")}${o}`)}f(wt,\"loadLibrary\");var T=new st(J);var tt=class{static{f(this,\"TypeNames\")}#r;#n=new Map;constructor(t){this.#r=t}type(t){let e=this.#n.get(t);if(!e){e=this.#r.typeName(t);this.#n.set(t,e)}return e}koffi(t){return T.type(this.type(t))}};var Ui=new tt(new K(J));function et(s,t){if(s===null||s===void 0||s===0n||s===0)throw new I(`${t}: the pointer is null`);if(typeof s===\"number\")return BigInt(s);if(typeof s!==\"bigint\")throw new I(`${t}: a pointer (a bigint) is expected, not ${typeof s}`);return s}f(et,\"checkedPointer\");function Se(s,t){if(!Number.isInteger(s)||s<0)throw new I(`${t}: the length must be a non-negative integer (${s})`);return s}f(Se,\"checkedLength\");function Ft(s,t,e,i){const n=s.type(e);const r=et(t,\"read\");const o=T.converter(n);if(i===void 0){const c=O.default.decode(r,T.type(n));return o?.fromNative?o.fromNative(c):c}const a=Array.from(O.default.decode(r,T.type(n),Se(i,\"readArray\")));return o?.fromNative?a.map(o.fromNative):a}f(Ft,\"readNative\");function Gt(s,t,e,i){const n=s.type(e);const r=T.converter(n);O.default.encode(et(t,\"write\"),T.type(n),r?.toNative?r.toNative(i):i)}f(Gt,\"writeNative\");function Vt(s,t,e=1){if(!Number.isInteger(e)||e<1)throw new I(`allocMemory: the count must be a positive integer (${e})`);const i=O.default.alloc(s.koffi(t),e);return typeof i===\"bigint\"?i:O.default.address(i)}f(Vt,\"allocateNative\");function yt(s){O.default.free(et(s,\"freeMemory\"))}f(yt,\"freeNative\");var Wt=new Map;var Ht;function jt(s=\"ucrtbase.dll\"){if(process.platform!==\"win32\")return O.default.errno();const t=s.toLowerCase();let e=Wt.get(t);if(!e){e=O.default.load(s).func(\"_errno\",\"int *\",[]);Wt.set(t,e)}return O.default.decode(e(),\"int\")}f(jt,\"nativeErrno\");function ct(){if(process.platform!==\"win32\")return void 0;Ht??=O.default.load(\"kernel32.dll\").func(\"__stdcall\",\"GetLastError\",\"uint32_t\",[]);return Ht()}f(ct,\"nativeWindowsError\");function Yt(s,t){const e=s.type(t);if(e.kind===\"function\")throw new w(`A function has no size: ${t}`);return O.default.sizeof(T.type(e))}f(Yt,\"typeSize\");var qt=require(\"node:worker_threads\");var it=S(P(),1);var vt=\"\";var kt=void 0;var Pe=5e3;function Zt(s){const t={NativeDeclarationException:w,NativeLibraryClosedException:L,NativeLibraryNotFoundException:M,NativeMemoryException:I,TypeError,RangeError};const e=new(t[s.name]??Error)(s.message);if(!t[s.name])e.name=s.name;return e}f(Zt,\"errorOf\");function ze(s){if(s.kind===\"primitive\")return s.name===\"void\"?void 0:s.name===\"bool\"?false:0;if(s.kind===\"enum\")return 0;if(s.kind===\"pointer\")return null;return{}}f(ze,\"zeroOf\");function Re(s){if(!s)return true;if(s.direction!==\"in\")return true;return s.type.kind===\"pointer\"&&!s.type.constTarget}f(Re,\"written\");var ut=class{static{f(this,\"NativeThreads\")}#r;#n;#c;#a=[];#o=1;#u=1;#f=false;constructor(t,e,i,n){if(!vt||!kt)throw new Error(\"The code of the worker threads of the libraries is not built (scripts/worker.mjs)\");this.#r={koffi:kt.resolve(\"koffi\"),file:t,declarations:e,...n?{crt:n}:{}};this.#n=i;this.#c=Array.from({length:i},()=>this.#v())}get ready(){return Promise.all(this.#c.map(t=>t?.ready??Promise.resolve())).then(()=>void 0)}get count(){return this.#n}declare(t){this.#a.push(t);for(const e of this.#c)if(e&&!e.exited)this.#l(e,{type:\"declare\",declarations:t})}bind(t){if(this.#f)return;for(const e of this.#c)if(e&&!e.exited)this.#p(e,t)}call(t,e){if(this.#f)return Promise.reject(new L(`The library ${this.#r.file} is closed`));const i=this.#h();const n=this.#p(i,t);const r=t.type.type;const o=e.slice();const a=[];const c=new Map;const h=[];const p=[];let y;for(let l=0;l<o.length;l++){const m=o[l];const u=r.parameters[l];if(typeof m===\"function\"){const d=u?.type.kind===\"pointer\"?u.type.to:void 0;if(!d||d.kind!==\"function\")return this.#w(p,new TypeError(`The argument ${l} of ${t.type.name} is a function, but its parameter is not a pointer to a function`));const g=d;const b=ze(g.result);const N=f((...G)=>{try{return m(...G)}catch(Qt){y??={error:Qt};return b}},\"safe\");const k=it.default.register(Y(g,T,N),it.default.pointer(T.prototype(g)));p.push(k);o[l]=k;continue}if(ArrayBuffer.isView(m)){const d=new Uint8Array(m.byteLength);d.set(new Uint8Array(m.buffer,m.byteOffset,m.byteLength));const g=Buffer.isBuffer(m)||m instanceof Uint8Array?d:m instanceof DataView?new DataView(d.buffer):new m.constructor(d.buffer);o[l]=g;h.push(d.buffer);if(Re(u)){a.push(l);c.set(l,m)}continue}if(u&&u.direction!==\"in\"&&m&&typeof m===\"object\")a.push(l)}const v=this.#u++;return new Promise((l,m)=>{const u=f(()=>{for(const d of p)it.default.unregister(d)},\"release\");i.calls.set(v,{resolve:l,reject:f(d=>{u();m(d)},\"reject\"),abandon:m,settle:f(d=>{u();a.forEach((g,b)=>{const N=e[g];const k=d.back[b];const G=c.get(g);if(G&&ArrayBuffer.isView(k))new Uint8Array(G.buffer,G.byteOffset,G.byteLength).set(new Uint8Array(k.buffer,k.byteOffset,k.byteLength));else if(Array.isArray(N)&&Array.isArray(k))N.splice(0,N.length,...k);else if(N&&typeof N===\"object\"&&k&&typeof k===\"object\")Object.assign(N,k)});if(y)return m(y.error);if(d.error)return m(Zt(d.error));l({value:d.value,errno:d.errno,...d.windowsError!==void 0?{windowsError:d.windowsError}:{}})},\"settle\")});try{this.#l(i,{type:\"call\",id:v,function:n,args:o,back:a},h)}catch(d){i.calls.delete(v);u();m(d)}})}async stopThread(t){await this.#c[t]?.worker.terminate()}async close(){if(this.#f)return;this.#f=true;await Promise.all(this.#c.map(async t=>{if(!t||t.exited)return;if(t.calls.size){const o=new L(`The library ${this.#r.file} is closed while a call runs in its thread`);for(const a of t.calls.values())a.abandon(o);t.calls.clear();this.#b(t);return}const e=new Promise(o=>{t.worker.once(\"exit\",()=>o())});this.#l(t,{type:\"close\"});let i;const n=new Promise(o=>{i=setTimeout(()=>o(true),Pe)});const r=await Promise.race([e,n]);clearTimeout(i);if(r)this.#b(t)}))}#b(t){t.worker.terminate().catch(()=>void 0)}#w(t,e){for(const i of t)it.default.unregister(i);return Promise.reject(e)}#p(t,e){let i=t.bound.get(e);if(i===void 0){i=this.#o++;t.bound.set(e,i);this.#l(t,{type:\"bind\",id:i,declaration:e.declaration,named:e.named,options:e.options})}return i}#h(){for(let e=0;e<this.#c.length;e++){if(!this.#c[e]||this.#c[e].exited)this.#c[e]=this.#v()}let t=this.#c[0];for(const e of this.#c)if(e.calls.size<t.calls.size)t=e;return t}#l(t,e,i=[]){t.worker.postMessage(e,i);if(e.type===\"call\")t.worker.ref()}#v(){const t=new qt.Worker(vt,{eval:true,workerData:{...this.#r,declarations:[this.#r.declarations,...this.#a].join(\"\\n\")}});let e=f(()=>void 0,\"readied\");let i=f(()=>void 0,\"failed\");const n=new Promise((c,h)=>{e=c;i=h});n.catch(()=>void 0);const r={worker:t,ready:n,calls:new Map,bound:new Map,exited:false};const o=f(()=>{if(!r.calls.size)t.unref()},\"refresh\");t.on(\"message\",c=>{switch(c.type){case\"ready\":e();o();return;case\"failed\":r.error=Zt(c.error);i(r.error);o();return;case\"result\":{const h=r.calls.get(c.id);r.calls.delete(c.id);o();h?.settle(c);return}case\"closed\":return}});const a=f(c=>{if(r.exited)return;r.exited=true;i(c);for(const h of r.calls.values())h.reject(r.error??c);r.calls.clear()},\"end\");t.on(\"error\",c=>a(c));t.on(\"exit\",c=>a(new Error(`The worker thread of the library ${this.#r.file} ended (exit code ${c})`)));return r}};var Kt=S(P(),1);var ft=class{static{f(this,\"NativeCallback\")}#r;#n;#c=false;constructor(t,e){this.#r=t;this.#n=e}get pointer(){return this.#r}get released(){return this.#c}release(){if(this.#c)return;this.#c=true;Kt.default.unregister(this.#r);this.#n(this)}};var xt=class{static{f(this,\"LibraryModel\")}#r;constructor(t){this.parser=new K(J);this.names=new tt(this.parser);this.#r=new Map;if(t)this.parser.parse(t)}prototype(t){let e=this.#r.get(t);if(!e){e=this.parser.prototype(t);this.#r.set(t,e)}return e}};var Jt=new Map;function Me(s){let t=Jt.get(s);if(!t){t=new xt(s);Jt.set(s,t)}return t}f(Me,\"modelOf\");function De(s){switch(s.kind){case\"primitive\":if(s.name===\"void\")return void 0;if(s.name===\"bool\")return false;return 0;case\"enum\":return 0;case\"pointer\":return null;default:return{}}}f(De,\"zeroOf\");var ht=class{static{f(this,\"NativeLibraryHandle\")}#r;#n;#c;#a;#o;#u;#f=new Map;#b=new Set;#w=new Set;#p=new Map;#h;#l;#v;#O;#T=0;#A=[];#_=false;constructor(t,e=\"\",i={}){this.#u=i;this.#c=Me(e);this.#a=this.#c.parser;this.#o=this.#c.names;const{library:n,file:r}=wt(t,i);this.#r=n;this.#n=r;if(i.threads!==void 0&&(!Number.isInteger(i.threads)||i.threads<0))throw new w(`The threads of a library are a number of threads (${i.threads})`);if(i.threads)this.#l=new ut(r,e,i.threads,i.crt);this.#h={start:f(()=>{if(this.#_)throw new L(`The library ${this.#n} is closed`);this.#T++},\"start\"),end:f(()=>{if(--this.#T>0)return;const o=this.#A;this.#A=[];for(const a of o)a()},\"end\")}}get file(){return this.#n}get closed(){return this.#_}get pending(){return this.#T}get threads(){return this.#l?.count??0}get ready(){return this.#l?.ready??Promise.resolve()}get constants(){return Object.fromEntries(this.#a.declarations.constants)}declare(t){this.#a.parse(t);this.#l?.declare(t)}func(t,e={}){this.#g();const i=`${t}\\0${JSON.stringify(e)}`;let n=this.#f.get(i);if(!n){n=this.#P(this.#c.prototype(t),e,t,false);this.#f.set(i,n)}return n}function(t,e={}){this.#g();const i=this.#a.declarations.functions.get(t);if(!i)throw new w(`The function ${t} is not declared`);const n=`\u0001${t}\\0${JSON.stringify(e)}`;let r=this.#f.get(n);if(!r){r=this.#P(i,e,t,true);this.#f.set(n,r)}return r}variable(t){this.#g();let e=t.trim();if(!/^[A-Za-z_]\\w*$/.test(e)){const c=new Set(this.#a.declarations.variables.keys());this.#a.parse(/;\\s*$/.test(e)?e:`${e};`);e=[...this.#a.declarations.variables.keys()].find(h=>!c.has(h))??e.match(/(\\w+)\\s*(\\[[^\\]]*\\])?\\s*;?\\s*$/)?.[1]??e}const i=this.#a.declarations.variables.get(e);if(!i)throw new w(`The variable ${e} is not declared`);let n;try{n=this.#r.symbol(i.symbol)}catch(c){throw new w(`The variable ${e} is not in the library (${i.symbol}): ${c.message}`)}const r=i.type;const o=r.kind===\"array\"&&r.length===0;const a=T.converter(r);return{address:n,get:f(()=>{this.#g();if(o){const h=r.of;return h.kind===\"primitive\"&&h.name===\"char\"?F.default.decode.string(n):n}const c=F.default.decode(n,T.type(r));return a?.fromNative?a.fromNative(c):c},\"get\"),set:f(c=>{this.#g();if(i.constant)throw new w(`The variable ${e} is const`);if(o)throw new w(`The array ${e} has no length: write its elements through its address`);F.default.encode(n,T.type(r),a?.toNative?a.toNative(c):c)},\"set\")}}callback(t,e){this.#g();let i;if(t.includes(\"(\")){i=this.#a.prototype(t).type}else{const h=this.#o.type(t);const p=h.kind===\"pointer\"?h.to:h;if(p.kind!==\"function\")throw new w(`The type ${t} is not a function type (${x(h)})`);i=p}const n=this.#u.onCallbackError??(h=>console.error(\"A callback of a native library threw:\",h));const r=De(i.result);const o=f((...h)=>{try{return e(...h)}catch(p){n(p);return r}},\"safe\");const a=F.default.register(Y(i,T,o),F.default.pointer(T.prototype(i)));const c=new ft(a,h=>this.#b.delete(h));this.#b.add(c);return c}read(t,e,i){this.#g();return Ft(this.#o,t,e,i)}write(t,e,i){this.#g();Gt(this.#o,t,e,i)}sizeOf(t){return Yt(this.#o,t)}offsetOf(t,e){const i=this.#o.type(t);if(i.kind!==\"struct\"&&i.kind!==\"union\")throw new w(`${t} is not a struct or a union`);const n=U(i,J).members.find(r=>r.member.name===e);if(!n)throw new w(`${t} has no member ${e}`);return n.offset}alloc(t,e=1){this.#g();const i=Vt(this.#o,t,e);this.#w.add(i);return i}free(t){const e=et(t,\"free\");this.#w.delete(e);yt(e)}errno(){return this.#v??jt(this.#u.crt)}windowsError(){return this.#O??ct()}drain(t=Infinity){if(!this.#T)return Promise.resolve(true);return new Promise(e=>{const i=Number.isFinite(t)?setTimeout(()=>e(false),t):void 0;this.#A.push(()=>{if(i)clearTimeout(i);e(true)})})}async close(t=1e4){if(this.#_)return;this.#_=true;const e=await this.drain(t);await this.#l?.close();this.#f.clear();if(!e)return;for(const i of[...this.#b])i.release();for(const i of this.#w)yt(i);this.#w.clear();if(!this.#u.keepLoaded)this.#r.unload()}#g(){if(this.#_)throw new L(`The library ${this.#n} is closed`)}#P(t,e,i,n){if(e.async&&this.#l)return this.#L(this.#l,{declaration:i,named:n,options:{free:e.free,int64:e.int64},type:t});return Rt(this.#r,t,T,r=>this.#o.koffi(r),{async:e.async,int64:e.int64,calls:this.#h,...e.free?{free:this.#z(e.free)}:{}})}#L(t,e){t.bind(e);return(...i)=>{try{this.#h.start()}catch(n){return Promise.reject(n)}return t.call(e,i).then(n=>{this.#v=n.errno;this.#O=n.windowsError;this.#h.end();return n.value},n=>{this.#h.end();throw n})}}#z(t){if(t===true)return i=>F.default.free(i);let e=this.#p.get(t);if(!e){try{e=this.#r.func(t,\"void\",[\"void *\"])}catch(i){throw new w(`The function ${t} freeing the strings is not in the library: ${i.message}`)}this.#p.set(t,e)}return e}};function Nt(s){return s instanceof Error?{name:s.name,message:s.message}:{name:\"Error\",message:String(s)}}f(Nt,\"threadError\");function Ce(s){const t=new Set;for(const e of s)if(ArrayBuffer.isView(e)&&e.buffer instanceof ArrayBuffer)t.add(e.buffer);return[...t]}f(Ce,\"transferables\");function Xt(){const s=lt.parentPort;const t=lt.workerData;const e=f((r,o=[])=>s.postMessage(r,o),\"post\");let i;try{i=new ht(t.file,t.declarations,{crt:t.crt})}catch(r){e({type:\"failed\",error:Nt(r)});s.close();return}const n=new Map;s.on(\"message\",r=>{switch(r.type){case\"bind\":try{n.set(r.id,r.named?i.function(r.declaration,r.options):i.func(r.declaration,r.options))}catch(o){n.set(r.id,Nt(o))}return;case\"declare\":try{i.declare(r.declarations)}catch{}return;case\"call\":{const o=n.get(r.function);let a;let c;if(typeof o!==\"function\"){c=o??{name:\"Error\",message:\"The function is not bound in the thread\"}}else{try{a=o(...r.args)}catch(v){c=Nt(v)}}const h=ct();const p=i.errno();const y=r.back.map(v=>r.args[v]);e({type:\"result\",id:r.id,...c?{error:c}:{value:a},back:y,errno:p,...h!==void 0?{windowsError:h}:{}},Ce(y));return}case\"close\":{const o=f(()=>{e({type:\"closed\"});s.close()},\"end\");i.close().then(o,o);return}}});e({type:\"ready\"})}f(Xt,\"runNativeWorker\");Xt();\n";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { Component, type ComponentOptions } from '@lakutata/core';
|
|
2
|
+
import type { NativeCallback } from '../lib/library/NativeCallback.js';
|
|
3
|
+
import { type NativeFunctionOptions, type NativeVariableAccessor } from '../lib/library/NativeLibraryHandle.js';
|
|
4
|
+
import type { Pointer } from '../lib/Runtime.js';
|
|
5
|
+
/**
|
|
6
|
+
* The options of a library in the configuration (see {@link buildNativeLibraryOptions}): where it is found, how it is
|
|
7
|
+
* closed
|
|
8
|
+
*/
|
|
9
|
+
export interface NativeLibraryConfig {
|
|
10
|
+
/**
|
|
11
|
+
* The file of the library: the only one tried when given (an alias of the application can start it).
|
|
12
|
+
*/
|
|
13
|
+
path?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Directories tried before the ones of `@Library`, in their order.
|
|
16
|
+
*/
|
|
17
|
+
search?: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Whether the library stays loaded once the component is destroyed.
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
keepLoaded?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* How long the destruction waits for the asynchronous calls running, in milliseconds. Calls still running then
|
|
25
|
+
* keep the library loaded, with its callbacks and its memory (a native call cannot be interrupted).
|
|
26
|
+
* @default 10000
|
|
27
|
+
*/
|
|
28
|
+
drainTimeout?: number;
|
|
29
|
+
/**
|
|
30
|
+
* The worker threads that run the asynchronous functions of the library, replacing the number of `@Library`: 0 for
|
|
31
|
+
* the thread pool of the runtime; 1 runs them one after the other.
|
|
32
|
+
*/
|
|
33
|
+
threads?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A native library: a component holding a library loaded with its C declarations (`@Library`), its functions on its
|
|
37
|
+
* properties (`@Native`), its variables (`@NativeVariable`). Write one subclass for each library and register it in the
|
|
38
|
+
* components of the application; it is loaded when it is created, and destroyed with the application: the asynchronous
|
|
39
|
+
* calls running are awaited, its callbacks released, the library unloaded.
|
|
40
|
+
*
|
|
41
|
+
* In a packaged application, the library is also looked for in the directory `native` of the resources (put it there
|
|
42
|
+
* with `lakutata.resources` of the package.json). The exceptions thrown by its persistent callbacks are its `error`
|
|
43
|
+
* events (written to the log of the application when nothing listens to them).
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import {Application} from 'lakutata'
|
|
47
|
+
* import {buildNativeLibraryOptions, Library, Native, NativeLibrary, type Out, type Pointer} from '@lakutata/ffi'
|
|
48
|
+
*
|
|
49
|
+
* @Library({
|
|
50
|
+
* names: {darwin: 'libsqlite3.dylib', linux: 'libsqlite3.so.0', win32: 'winsqlite3.dll'},
|
|
51
|
+
* declarations: `
|
|
52
|
+
* typedef struct sqlite3 sqlite3;
|
|
53
|
+
* #define SQLITE_OK 0
|
|
54
|
+
* `
|
|
55
|
+
* })
|
|
56
|
+
* export class SQLite extends NativeLibrary {
|
|
57
|
+
* @Native('const char *sqlite3_libversion(void)')
|
|
58
|
+
* public readonly libversion: () => string
|
|
59
|
+
*
|
|
60
|
+
* @Native('int sqlite3_open(const char *filename, _Out_ sqlite3 **db)')
|
|
61
|
+
* public readonly open: (filename: string, db: Out<Pointer>) => number
|
|
62
|
+
*
|
|
63
|
+
* @Native('int sqlite3_close(sqlite3 *db)')
|
|
64
|
+
* public readonly close: (db: Pointer) => number
|
|
65
|
+
* }
|
|
66
|
+
*
|
|
67
|
+
* Application
|
|
68
|
+
* .run(() => ({
|
|
69
|
+
* id: 'store.app',
|
|
70
|
+
* name: 'Store',
|
|
71
|
+
* components: {
|
|
72
|
+
* sqlite: buildNativeLibraryOptions(SQLite)
|
|
73
|
+
* }
|
|
74
|
+
* }))
|
|
75
|
+
* .onLaunched(async (app: Application): Promise<void> => {
|
|
76
|
+
* const sqlite: SQLite = await app.getObject('sqlite')
|
|
77
|
+
* console.log(sqlite.libversion())
|
|
78
|
+
* })
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare class NativeLibrary extends Component {
|
|
82
|
+
#private;
|
|
83
|
+
/**
|
|
84
|
+
* The file of the library: the only one tried when given.
|
|
85
|
+
*/
|
|
86
|
+
protected readonly path?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Directories tried before the ones of `@Library`.
|
|
89
|
+
*/
|
|
90
|
+
protected readonly search?: string[];
|
|
91
|
+
/**
|
|
92
|
+
* Whether the library stays loaded once the component is destroyed.
|
|
93
|
+
*/
|
|
94
|
+
protected readonly keepLoaded?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* How long the destruction waits for the asynchronous calls running, in milliseconds.
|
|
97
|
+
*/
|
|
98
|
+
protected readonly drainTimeout?: number;
|
|
99
|
+
/**
|
|
100
|
+
* The worker threads that run the asynchronous functions of the library.
|
|
101
|
+
*/
|
|
102
|
+
protected readonly threads?: number;
|
|
103
|
+
/**
|
|
104
|
+
* Load the library and bind its functions and variables to their properties.
|
|
105
|
+
* @protected
|
|
106
|
+
*/
|
|
107
|
+
protected init(): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Close the library: the asynchronous calls running awaited, the callbacks released, the library unloaded (kept,
|
|
110
|
+
* with its callbacks and its memory, when calls still run after `drainTimeout`); its properties throw from then on.
|
|
111
|
+
* @protected
|
|
112
|
+
*/
|
|
113
|
+
protected destroy(): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* The file the library was loaded from.
|
|
116
|
+
*/
|
|
117
|
+
get file(): string;
|
|
118
|
+
/**
|
|
119
|
+
* The asynchronous calls running.
|
|
120
|
+
*/
|
|
121
|
+
get pending(): number;
|
|
122
|
+
/**
|
|
123
|
+
* The worker threads of the library (0: its asynchronous calls run in the thread pool of the runtime).
|
|
124
|
+
*/
|
|
125
|
+
get threadCount(): number;
|
|
126
|
+
/**
|
|
127
|
+
* The constants of the declarations: the values of the enumerations, of the static constants and of the macros
|
|
128
|
+
* whose value is an integer.
|
|
129
|
+
*/
|
|
130
|
+
get constants(): Readonly<Record<string, bigint>>;
|
|
131
|
+
/**
|
|
132
|
+
* A function of the library bound from its prototype, besides the ones of the properties.
|
|
133
|
+
* @param prototype Its C prototype, with the types of the declarations.
|
|
134
|
+
* @param options Whether it is asynchronous, how its strings are freed, how its 64-bit integers are given.
|
|
135
|
+
* @returns The function.
|
|
136
|
+
*/
|
|
137
|
+
func<T extends (...args: any[]) => any = (...args: any[]) => any>(prototype: string, options?: NativeFunctionOptions): T;
|
|
138
|
+
/**
|
|
139
|
+
* A variable the library exports, besides the ones of the properties.
|
|
140
|
+
* @param declaration Its name in the declarations, or its declaration.
|
|
141
|
+
* @returns Its address, and the functions reading and writing its value.
|
|
142
|
+
*/
|
|
143
|
+
variable<T = unknown>(declaration: string): NativeVariableAccessor<T>;
|
|
144
|
+
/**
|
|
145
|
+
* A persistent callback: a JS function the library can call at any time, released by `release()` or when the
|
|
146
|
+
* component is destroyed. Its exceptions are `error` events of the component.
|
|
147
|
+
* @param type The name of a pointer-to-function type of the declarations, or its prototype.
|
|
148
|
+
* @param callback The JS function.
|
|
149
|
+
* @returns The callback, whose `pointer` is given to the library.
|
|
150
|
+
*/
|
|
151
|
+
callback(type: string, callback: (...args: any[]) => any): NativeCallback;
|
|
152
|
+
/**
|
|
153
|
+
* Read native memory as a type of the declarations: a value, or an array of values.
|
|
154
|
+
* @param pointer The address.
|
|
155
|
+
* @param type The type: `int`, `struct timeval`, `char *` (a string).
|
|
156
|
+
* @param count The number of values, for an array.
|
|
157
|
+
* @returns The value, or the array.
|
|
158
|
+
*/
|
|
159
|
+
read<T = unknown>(pointer: Pointer, type: string, count?: number): T;
|
|
160
|
+
/**
|
|
161
|
+
* Write a value to native memory as a type of the declarations.
|
|
162
|
+
* @param pointer The address.
|
|
163
|
+
* @param type The type.
|
|
164
|
+
* @param value The value.
|
|
165
|
+
*/
|
|
166
|
+
write(pointer: Pointer, type: string, value: unknown): void;
|
|
167
|
+
/**
|
|
168
|
+
* The size of a type of the declarations, in bytes.
|
|
169
|
+
* @param type The type.
|
|
170
|
+
*/
|
|
171
|
+
sizeOf(type: string): number;
|
|
172
|
+
/**
|
|
173
|
+
* The offset of a member of a struct of the declarations, in bytes.
|
|
174
|
+
* @param type The struct.
|
|
175
|
+
* @param member The member.
|
|
176
|
+
*/
|
|
177
|
+
offsetOf(type: string, member: string): number;
|
|
178
|
+
/**
|
|
179
|
+
* Allocate native memory for values of a type of the declarations, which the library can keep; freed by `free()`,
|
|
180
|
+
* or when the component is destroyed.
|
|
181
|
+
* @param type The type.
|
|
182
|
+
* @param count The number of values.
|
|
183
|
+
* @returns Its address.
|
|
184
|
+
*/
|
|
185
|
+
alloc(type: string, count?: number): Pointer;
|
|
186
|
+
/**
|
|
187
|
+
* Free memory allocated by `alloc()`.
|
|
188
|
+
* @param pointer Its address.
|
|
189
|
+
*/
|
|
190
|
+
free(pointer: Pointer): void;
|
|
191
|
+
/**
|
|
192
|
+
* The errno of the last call of this thread (on Windows, the one of the C library of `@Library`, ucrtbase.dll by
|
|
193
|
+
* default); with threads, the one of the thread of the last asynchronous call completed.
|
|
194
|
+
*/
|
|
195
|
+
errno(): number;
|
|
196
|
+
/**
|
|
197
|
+
* The last error of the Windows API after the last call of this thread; with threads, the one of the thread of the
|
|
198
|
+
* last asynchronous call completed; undefined on the other systems.
|
|
199
|
+
*/
|
|
200
|
+
windowsError(): number | undefined;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Build the declaration of a library component, for the `components` of an application.
|
|
204
|
+
* @param library The `NativeLibrary` subclass of the library.
|
|
205
|
+
* @param options Where it is found (a file, directories searched first), whether it stays loaded, how long its
|
|
206
|
+
* destruction waits for its asynchronous calls.
|
|
207
|
+
* @returns The component declaration.
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* import {Application} from 'lakutata'
|
|
211
|
+
* import {buildNativeLibraryOptions, Library, Native, NativeLibrary} from '@lakutata/ffi'
|
|
212
|
+
*
|
|
213
|
+
* @Library({names: 'vendor'})
|
|
214
|
+
* class Vendor extends NativeLibrary {
|
|
215
|
+
* @Native('int vendor_version(void)')
|
|
216
|
+
* public readonly version: () => number
|
|
217
|
+
* }
|
|
218
|
+
*
|
|
219
|
+
* Application.run(() => ({
|
|
220
|
+
* id: 'devices.app',
|
|
221
|
+
* name: 'Devices',
|
|
222
|
+
* components: {
|
|
223
|
+
* //The library shipped with the application: an alias, or a path relative to the working directory
|
|
224
|
+
* vendor: buildNativeLibraryOptions(Vendor, {search: ['@data/native']})
|
|
225
|
+
* }
|
|
226
|
+
* }))
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
export declare function buildNativeLibraryOptions(library: typeof NativeLibrary, options?: NativeLibraryConfig): ComponentOptions<NativeLibraryConfig>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { LibraryNames } from '../lib/library/Resolve.js';
|
|
2
|
+
/**
|
|
3
|
+
* What a library is: its file names, where it is looked for, its C declarations
|
|
4
|
+
*/
|
|
5
|
+
export interface LibraryOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Its file names: one (`sqlite3`, completed as each platform names libraries: `libsqlite3.dylib`, `libsqlite3.so`,
|
|
8
|
+
* `sqlite3.dll`), or one by platform (`{darwin: 'libsqlite3.dylib', linux: 'libsqlite3.so.0', win32:
|
|
9
|
+
* 'winsqlite3.dll'}`, `default` for the others); `c` for the C library, `m` for its mathematical functions.
|
|
10
|
+
*/
|
|
11
|
+
names: LibraryNames;
|
|
12
|
+
/**
|
|
13
|
+
* The directories it is looked for in before the ones of the system, in their order (aliases of the application
|
|
14
|
+
* allowed). The ones of the configuration come first.
|
|
15
|
+
*/
|
|
16
|
+
search?: string[];
|
|
17
|
+
/**
|
|
18
|
+
* Its C declarations, as its headers write them: the types its functions use, its functions, its variables, its
|
|
19
|
+
* constants (enumerations, #define of integers).
|
|
20
|
+
*/
|
|
21
|
+
declarations?: string;
|
|
22
|
+
/**
|
|
23
|
+
* On Windows, the C library its functions use, whose errno `errno()` reads.
|
|
24
|
+
* @default 'ucrtbase.dll'
|
|
25
|
+
*/
|
|
26
|
+
crt?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The worker threads that run its asynchronous functions (the configuration can give another number): 0 for the
|
|
29
|
+
* thread pool of the runtime; 1 runs them one after the other, for a library that is not thread-safe.
|
|
30
|
+
* @default 0
|
|
31
|
+
*/
|
|
32
|
+
threads?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Declare a native library on a `NativeLibrary` subclass: its file names, the directories it is looked for in, its C
|
|
36
|
+
* declarations. Its functions are declared on its properties by `@Native`, its variables by `@NativeVariable`.
|
|
37
|
+
* @param options Its names, its search directories, its declarations.
|
|
38
|
+
* @returns The class decorator.
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import {Library, Native, NativeLibrary} from '@lakutata/ffi'
|
|
42
|
+
*
|
|
43
|
+
* @Library({
|
|
44
|
+
* names: {darwin: 'libz.dylib', linux: 'libz.so.1', win32: 'zlib1.dll'},
|
|
45
|
+
* declarations: 'typedef unsigned long uLong;'
|
|
46
|
+
* })
|
|
47
|
+
* export class Zlib extends NativeLibrary {
|
|
48
|
+
* @Native('const char *zlibVersion(void)')
|
|
49
|
+
* public readonly zlibVersion: () => string
|
|
50
|
+
*
|
|
51
|
+
* @Native('uLong crc32(uLong crc, const unsigned char *buffer, unsigned int length)')
|
|
52
|
+
* public readonly crc32: (crc: bigint | number, buffer: Buffer, length: number) => bigint
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function Library(options: LibraryOptions): (target: Function) => void;
|
|
57
|
+
/**
|
|
58
|
+
* The library declared on a class or on the nearest of its parent classes
|
|
59
|
+
* @param target
|
|
60
|
+
*/
|
|
61
|
+
export declare function libraryOptionsOf(target: Function): LibraryOptions | undefined;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { NativeFunctionOptions } from '../lib/library/NativeLibraryHandle.js';
|
|
2
|
+
/**
|
|
3
|
+
* A member of a library class: a function, or a variable
|
|
4
|
+
*/
|
|
5
|
+
export type NativeMember = {
|
|
6
|
+
readonly kind: 'function';
|
|
7
|
+
readonly declaration?: string;
|
|
8
|
+
readonly options: NativeFunctionOptions;
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: 'variable';
|
|
11
|
+
readonly declaration?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Declare a function of the library on a property of a `NativeLibrary` subclass: the property gets the function once
|
|
15
|
+
* the component is created (the function of koffi itself when nothing is converted), and a function throwing once it
|
|
16
|
+
* is destroyed. The TypeScript type of the property is the one of the function.
|
|
17
|
+
* @param declaration Its C prototype (`int sqlite3_open(const char *filename, _Out_ sqlite3 **db)`), or the name of a
|
|
18
|
+
* function of the declarations of the library; by default the function of the declarations named as the property.
|
|
19
|
+
* @param options Whether it runs in a thread of the pool (returning a promise), the function freeing the strings it
|
|
20
|
+
* gives, its 64-bit integers as numbers.
|
|
21
|
+
* @returns The property decorator.
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import {Library, Native, NativeLibrary, type Out, type Pointer} from '@lakutata/ffi'
|
|
25
|
+
*
|
|
26
|
+
* @Library({
|
|
27
|
+
* names: {darwin: 'libsqlite3.dylib', linux: 'libsqlite3.so.0', win32: 'winsqlite3.dll'},
|
|
28
|
+
* declarations: `
|
|
29
|
+
* typedef struct sqlite3 sqlite3;
|
|
30
|
+
* int sqlite3_close(sqlite3 *db);
|
|
31
|
+
* `
|
|
32
|
+
* })
|
|
33
|
+
* export class SQLite extends NativeLibrary {
|
|
34
|
+
* @Native('int sqlite3_open(const char *filename, _Out_ sqlite3 **db)')
|
|
35
|
+
* public readonly open: (filename: string, db: Out<Pointer>) => number
|
|
36
|
+
*
|
|
37
|
+
* //The function of the declarations named as the property
|
|
38
|
+
* @Native()
|
|
39
|
+
* public readonly sqlite3_close: (db: Pointer) => number
|
|
40
|
+
*
|
|
41
|
+
* @Native('int sqlite3_exec(sqlite3 *db, const char *sql, void *callback, void *context, _Out_ char **error)', {async: true, free: 'sqlite3_free'})
|
|
42
|
+
* public readonly exec: (db: Pointer, sql: string, callback: null, context: null, error: Out<string>) => Promise<number>
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function Native(declaration?: string, options?: NativeFunctionOptions): (target: object, key: string | symbol) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Declare a variable the library exports on a property of a `NativeLibrary` subclass: reading the property reads the
|
|
49
|
+
* variable, writing it writes the variable (refused for a const one).
|
|
50
|
+
* @param declaration Its declaration (`extern const char sqlite3_version[]`), or the name of a variable of the
|
|
51
|
+
* declarations of the library; by default the variable of the declarations named as the property.
|
|
52
|
+
* @returns The property decorator.
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import {Library, NativeLibrary, NativeVariable} from '@lakutata/ffi'
|
|
56
|
+
*
|
|
57
|
+
* @Library({names: {darwin: 'libsqlite3.dylib', linux: 'libsqlite3.so.0', win32: 'winsqlite3.dll'}})
|
|
58
|
+
* export class SQLiteVersion extends NativeLibrary {
|
|
59
|
+
* @NativeVariable('extern const char sqlite3_version[]')
|
|
60
|
+
* public readonly version: string
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function NativeVariable(declaration?: string): (target: object, key: string | symbol) => void;
|
|
65
|
+
/**
|
|
66
|
+
* The native members of a class and of its parent classes (a subclass replacing a member of its parent)
|
|
67
|
+
* @param prototype
|
|
68
|
+
*/
|
|
69
|
+
export declare function nativeMembersOf(prototype: object): Map<string, NativeMember>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when C declarations or a function prototype cannot be read: its message gives the line and the column, what
|
|
4
|
+
* was found and what was expected (a type not declared, a construct not supported such as a macro or `long double`).
|
|
5
|
+
* Its `errno` is `'E_NATIVE_DECLARATION'`.
|
|
6
|
+
*/
|
|
7
|
+
export declare class NativeDeclarationException extends Exception {
|
|
8
|
+
/**
|
|
9
|
+
* `'E_NATIVE_DECLARATION'`.
|
|
10
|
+
*/
|
|
11
|
+
errno: string | number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when a function, a variable or a callback of a library is used once the library is closed (its component
|
|
4
|
+
* destroyed, or `close()` called): calling a function of an unloaded library would end the process. Its `errno` is
|
|
5
|
+
* `'E_NATIVE_LIBRARY_CLOSED'`.
|
|
6
|
+
*/
|
|
7
|
+
export declare class NativeLibraryClosedException extends Exception {
|
|
8
|
+
/**
|
|
9
|
+
* `'E_NATIVE_LIBRARY_CLOSED'`.
|
|
10
|
+
*/
|
|
11
|
+
errno: string | number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when a library cannot be loaded: its message lists each file tried and why it could not be loaded (not found,
|
|
4
|
+
* built for another architecture, a library it needs missing). Its `errno` is `'E_NATIVE_LIBRARY_NOT_FOUND'`.
|
|
5
|
+
*/
|
|
6
|
+
export declare class NativeLibraryNotFoundException extends Exception {
|
|
7
|
+
/**
|
|
8
|
+
* `'E_NATIVE_LIBRARY_NOT_FOUND'`.
|
|
9
|
+
*/
|
|
10
|
+
errno: string | number;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Exception } from '@lakutata/core';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when native memory cannot be read or written as asked: a null pointer, a negative length, a view of native
|
|
4
|
+
* memory where the runtime forbids it (Electron). Its `errno` is `'E_NATIVE_MEMORY'`.
|
|
5
|
+
*/
|
|
6
|
+
export declare class NativeMemoryException extends Exception {
|
|
7
|
+
/**
|
|
8
|
+
* `'E_NATIVE_MEMORY'`.
|
|
9
|
+
*/
|
|
10
|
+
errno: string | number;
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { NativeDeclarationException } from '../exceptions/NativeDeclarationException.js';
|
|
2
|
+
export { NativeLibraryNotFoundException } from '../exceptions/NativeLibraryNotFoundException.js';
|
|
3
|
+
export { NativeLibraryClosedException } from '../exceptions/NativeLibraryClosedException.js';
|
|
4
|
+
export { NativeMemoryException } from '../exceptions/NativeMemoryException.js';
|
|
5
|
+
export { type Pointer } from '../lib/Runtime.js';
|
|
6
|
+
export { type LibraryNames } from '../lib/library/Resolve.js';
|
|
7
|
+
export { NativeCallback } from '../lib/library/NativeCallback.js';
|
|
8
|
+
export { loadNativeLibrary, NativeLibraryHandle, type NativeFunctionOptions, type NativeLibraryOptions, type NativeVariableAccessor } from '../lib/library/NativeLibraryHandle.js';
|
|
9
|
+
export { allocMemory, freeMemory, lastErrno, lastWindowsError, type Out, readArray, readBuffer, readCString, readValue, readWString, sizeOf, viewBuffer, writeValue } from '../lib/Memory.js';
|
|
10
|
+
export { Library, type LibraryOptions } from '../decorators/Library.js';
|
|
11
|
+
export { Native, NativeVariable } from '../decorators/Native.js';
|
|
12
|
+
export { buildNativeLibraryOptions, NativeLibrary, type NativeLibraryConfig } from '../components/NativeLibrary.js';
|