123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 Marigold <contact@marigold.dev> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openTezos_scoru_wasmmoduleMemory=Tezos_wasmer.MemorymoduleI32=Tezos_webassembly_interpreter.I32moduleWasmer:Host_funcs.Memory_accesswithtypet=Memory.t=structtypet=Memory.texceptionOut_of_bounds=Memory.Out_of_boundsletload_bytesmemoryaddresslength=letaddress=I32.to_int_uaddressinLwt.return(Memory.get_stringmemory~address~length)letstore_bytesmemoryaddressdata=letaddress=I32.to_int_uaddressinMemory.set_stringmemory~address~data;Lwt.return_unitletto_bits(num:Tezos_webassembly_interpreter.Values.num):int*int64=letopenTezos_webassembly_interpreterinletsize=Types.num_size@@Values.type_of_numnuminletbits=matchnumwith|Values.I32x->Int64.of_int32x|Values.I64x->x|Values.F32x->Int64.of_int32@@F32.to_bitsx|Values.F64x->F64.to_bitsxin(size,bits)letstore_nummemoryaddroffsetnum=letabs_addr=I32.to_int_u@@Int32.addaddroffsetinletnum_bytes,bits=to_bitsnuminletrecloopstepsaddrbits=ifsteps>0then(letlsb=Unsigned.UInt8.of_int@@(Int64.to_intbitsland0xff)inletbits=Int64.shift_rightbits8inMemory.setmemoryaddrlsb;loop(steps-1)(addr+1)bits)inloopnum_bytesabs_addrbits;Lwt.return_unitletbound(memory:Memory.t)=Int64.of_int(Memory.lengthmemory)letexn_to_error~default=function|Out_of_bounds->Host_funcs.Error.Memory_invalid_access|_->defaultend