1 /* 2 * Wasm3 D - Wasm3 binding for D programming language 3 * Authors: Matheus Catarino França <matheus-catarino@hotmail.com> 4 * License: MIT 5 * Version: 0.1.0 6 */ 7 module wasm3; 8 public import wasm3.binding.binding; 9 10 struct Environment 11 { 12 IM3Environment env; 13 const(char)* result = null; 14 alias env this; 15 16 @disable this(); 17 this(scope IM3Environment e) @nogc nothrow 18 { 19 if (e is null) 20 { 21 env = m3_NewEnvironment(); 22 } 23 else 24 { 25 env = e; 26 } 27 } 28 29 ~this() @nogc nothrow 30 { 31 m3_FreeEnvironment(env); 32 } 33 34 Runtime newRuntime(uint stackSizeBytes) @nogc nothrow 35 { 36 return Runtime(m3_NewRuntime(env, stackSizeBytes, null)); 37 } 38 39 Module parseModule(ubyte[] data, size_t size) @nogc nothrow 40 { 41 IM3Module m_module; 42 result = m3_ParseModule(env, &m_module, data.ptr, cast(uint) size); 43 return Module(m_module); 44 } 45 } 46 47 struct Runtime 48 { 49 IM3Runtime runtime; 50 51 this(scope IM3Runtime rt) @nogc nothrow 52 { 53 runtime = rt; 54 } 55 56 void freeRuntime() @nogc nothrow 57 { 58 m3_FreeRuntime(runtime); 59 } 60 } 61 62 struct Module 63 { 64 IM3Module m_module; 65 66 this(IM3Module mod) @nogc nothrow 67 { 68 m_module = mod; 69 } 70 71 void freeModule() @nogc nothrow 72 { 73 m3_FreeModule(m_module); 74 } 75 }