import ASModule from "../dist/wasm/optimized" ; declare const WebAssembly ; function addUtilityExports ( instance ) { const extendedExports = { } ; const exports = instance . exports ; const memory = exports . memory ; const alloc = exports [ "__alloc" ] ; const retain = exports [ "__retain" ] ; const rttiBase = exports [ "__rtti_base" ] || ~ 0 ; /** Gets the runtime type info for the given id. */ function getInfo ( id ) { const U32 = new Uint32Array ( memory . buffer ) ; return U32 [ ( ( rttiBase + 4 ) >>> 2 ) + id * 2 ] ; } /** Allocates a new array in the module's memory and returns its retained pointer. */ extendedExports . __allocArray = ( id , values ) => { const info = getInfo ( id ) ; const align = 31 - Math . clz32 ( ( info >>> 6 ) & 31 ) ; const length = values . length ; const buf = alloc ( length << align , 0 ) ; const arr = alloc ( 12 , id ) ; const U32 = new Uint32Array ( memory . buffer ) ; U32 [ ( arr + 0 ) >>> 2 ] = retain ( buf ) ; U32 [ ( arr + 4 ) >>> 2 ] = buf ; U32 [ ( arr + 8 ) >>> 2 ] = length << align ; const buffer = memory . buffer ; const view = new Uint8Array ( buffer ) ; if ( info & ( 1 << 14 ) ) { for ( let i = 0 ; i < length ; ++ i ) view [ ( buf >>> align ) + i ] = retain ( values [ i ] ) ; } else { view . set ( values , buf >>> align ) ; } return arr ; } ; extendedExports . __getUint8Array = ( ptr ) => { const U32 = new Uint32Array ( memory . buffer ) ; const bufPtr = U32 [ ( ptr + 4 ) >>> 2 ] ; return new Uint8Array ( memory . buffer , bufPtr , U32 [ ( bufPtr - 4 ) >>> 2 ] >>> 0 ) ; } ; return demangle ( exports , extendedExports ) ; } /** Demangles an AssemblyScript module's exports to a friendly object structure. */ function demangle ( exports , extendedExports = { } ) { const setArgumentsLength = exports [ "__argumentsLength" ] ? ( length ) => { exports [ "__argumentsLength" ] . value = length ; } : exports [ "__setArgumentsLength" ] || exports [ "__setargc" ] || ( ( ) => { return { } ; } ) ; for ( const internalName in exports ) { if ( ! Object . prototype . hasOwnProperty . call ( exports , internalName ) ) continue ; const elem = exports [ internalName ] ; const name = internalName . split ( "." ) [ 0 ] ; if ( typeof elem === "function" && elem !== setArgumentsLength ) { ( ( extendedExports [ name ] = ( ... args ) => { setArgumentsLength ( args . length ) ; return elem ( ... args ) ; } ) as any ) . original = elem ; } else { extendedExports [ name ] = elem ; } } return extendedExports ; } export async function instantiateWasmSolver ( module ) { const imports = { env : { abort ( ) { throw Error ( "Wasm aborted" ) ; } , } , } ; const result = await WebAssembly . instantiate ( module , imports ) ; const exports = addUtilityExports ( result ) ; return { exports } as any ; }