├── .DS_Store ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── LICENSE ├── README.md ├── examples ├── callback.v ├── memory.v ├── qjs.wasm ├── simple.v └── wasi.v ├── v.mod └── wasmer ├── include ├── README.md ├── wasm.h ├── wasmer.h └── wasmer_wasm.h ├── wasi.v ├── wasi_sys.v ├── wasmer.v ├── wasmer_sys.v └── wasmer_test.v /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vlang/wasmer/32e59af73364f83f56036854ee2c7c31edce857b/.DS_Store -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | ubuntu-fast-build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout Latest V 10 | uses: actions/checkout@v2 11 | with: 12 | repository: vlang/v 13 | path: v 14 | - name: Build V 15 | run: cd v && make && sudo ./v symlink && cd - 16 | - name: Install Wasmer 17 | run: curl https://get.wasmer.io -sSfL | sh -s "v3.0.0-rc.1" 18 | - name: Install Clang 19 | run: sudo apt install clang 20 | - name: Checkout wasmer 21 | uses: actions/checkout@v2 22 | with: 23 | path: wasmer 24 | - name: V doctor 25 | run: v doctor 26 | - name: Ensure everything is formatted 27 | run: cd wasmer && v fmt -verify . 28 | - name: Run tests 29 | run: echo $WASMER_DIR && cd wasmer && WASMER_DIR=$HOME/.wasmer v -cc clang test . -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Adel Prokurov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wasmer 2 | `wasmer` is a wrapper over Wasmer C API. This module not only provides access to the C API but it also strives to provide easy to use wrappers over the C API. 3 | 4 | # Example usage 5 | 6 | ```v 7 | import wasmer 8 | 9 | fn main() { 10 | engine := wasmer.engine() 11 | store := wasmer.store(engine) 12 | 13 | wasm := wasmer.wat2wasm('(module 14 | (func \$add (param \$lhs i32) (param \$rhs i32) (result i32) 15 | local.get \$lhs 16 | local.get \$rhs 17 | i32.add) 18 | (export "add" (func \$add)) 19 | 20 | )')? 21 | 22 | mod := wasmer.compile(store,wasm)? 23 | imports := wasmer.extern_vec_empty() 24 | mut trap := wasmer.Trap{} 25 | instance := wasmer.instance(store,mod,imports,mut trap) 26 | 27 | func := instance.exports().at(0).as_func()? 28 | mut results := [wasmer.val_i32(0)] 29 | trap = func.call([wasmer.val_i32(2),wasmer.val_i32(3)],mut results) 30 | if trap.is_set() { 31 | println(trap.message()?) 32 | } else { 33 | println(results[0]) 34 | } 35 | 36 | engine.delete() 37 | trap.delete() 38 | store.delete() 39 | } 40 | 41 | ``` -------------------------------------------------------------------------------- /examples/callback.v: -------------------------------------------------------------------------------- 1 | import wasmer 2 | 3 | fn callback(mut args wasmer.Arguments) ? { 4 | println('Hello from WASM! Argument 0: ${args.arg(0)}') 5 | args.set_result(0, wasmer.val_i32(42))? 6 | return 7 | } 8 | 9 | fn main() { 10 | mut config := wasmer.config() 11 | config.set_compiler(.cranelift) 12 | engine := wasmer.engine_with_config(config) 13 | defer { 14 | engine.delete() 15 | } 16 | 17 | store := wasmer.store(engine) 18 | defer { 19 | store.delete() 20 | } 21 | 22 | wasm := wasmer.wat2wasm(' 23 | (module 24 | (func \$host_function (import "" "host_function") (param i32) (result i32)) 25 | (func \$f (param \$arg i32) (result i32) 26 | (call \$host_function (local.get \$arg))) 27 | 28 | (export "f" (func \$f)) 29 | )')? 30 | 31 | mod := wasmer.compile(store, wasm)? 32 | 33 | ty := wasmer.func_type([wasmer.val_type(.wasm_i32)], [wasmer.val_type(.wasm_i32)]) 34 | defer { 35 | ty.delete() 36 | } 37 | func := wasmer.func(store, ty, callback) 38 | mut trap := wasmer.Trap{} 39 | defer { 40 | trap.delete() 41 | } 42 | instance := wasmer.instance(store, mod, [func.as_extern()], mut trap) 43 | exports := instance.exports() 44 | wasm_func := exports[0].as_func()? 45 | mut results := [wasmer.val_i32(0)] 46 | trap = wasm_func.call([wasmer.val_i32(44)], mut results) 47 | if trap.is_set() { 48 | panic(trap.message()?) 49 | } else { 50 | println(results[0]) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/memory.v: -------------------------------------------------------------------------------- 1 | import wasmer 2 | 3 | fn main() { 4 | mut config := wasmer.config() 5 | config.set_compiler(.cranelift) 6 | engine := wasmer.engine_with_config(config) 7 | defer { 8 | engine.delete() 9 | } 10 | 11 | store := wasmer.store(engine) 12 | defer { 13 | store.delete() 14 | } 15 | 16 | wasm := wasmer.wat2wasm(' 17 | (module 18 | (type \$mem_size_t (func (result i32))) 19 | (type \$get_at_t (func (param i32) (result i32))) 20 | (type \$set_at_t (func (param i32) (param i32))) 21 | (memory \$mem 1) 22 | (func \$get_at (type \$get_at_t) (param \$idx i32) (result i32) 23 | (i32.load (local.get \$idx))) 24 | (func \$set_at (type \$set_at_t) (param \$idx i32) (param \$val i32) 25 | (i32.store (local.get \$idx) (local.get \$val))) 26 | (func \$mem_size (type \$mem_size_t) (result i32) 27 | (memory.size)) 28 | (export "get_at" (func \$get_at)) 29 | (export "set_at" (func \$set_at)) 30 | (export "mem_size" (func \$mem_size)) 31 | (export "memory" (memory \$mem)))')? 32 | 33 | mod := wasmer.compile(store, wasm)? 34 | 35 | mut trap := wasmer.Trap{} 36 | defer { 37 | trap.delete() 38 | } 39 | instance := wasmer.instance(store, mod, [], mut trap) 40 | 41 | exports := instance.exports() 42 | 43 | get_at := exports[0].as_func()? 44 | set_at := exports[1].as_func()? 45 | memory := exports[3].as_memory()? 46 | 47 | mem_addr := int(0x2220) 48 | ptr := wasmer.wasm_ptr(u32(mem_addr)) 49 | val := 0xFEFEFFE 50 | mut results := []wasmer.Val{} 51 | trap = set_at.call([wasmer.val_i32(mem_addr), wasmer.val_i32(val)], mut results) 52 | results.clear() 53 | assert !trap.is_set() 54 | println(ptr.deref(memory)?) 55 | 56 | results << wasmer.val_i32(0) 57 | trap = get_at.call([wasmer.val_i32(mem_addr)], mut results) 58 | 59 | assert !trap.is_set() 60 | println(results[0].i32()) 61 | } 62 | -------------------------------------------------------------------------------- /examples/qjs.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vlang/wasmer/32e59af73364f83f56036854ee2c7c31edce857b/examples/qjs.wasm -------------------------------------------------------------------------------- /examples/simple.v: -------------------------------------------------------------------------------- 1 | import wasmer 2 | 3 | fn main() { 4 | engine := wasmer.engine() 5 | store := wasmer.store(engine) 6 | defer { 7 | store.delete() 8 | engine.delete() 9 | } 10 | 11 | wasm := wasmer.wat2wasm('(module 12 | (func \$add (param \$lhs i32) (param \$rhs i32) (result i32) 13 | local.get \$lhs 14 | local.get \$rhs 15 | i32.add) 16 | (export "add" (func \$add)) 17 | )')? 18 | 19 | mod := wasmer.compile(store, wasm)? 20 | imports := []wasmer.Extern{} 21 | mut trap := wasmer.Trap{} 22 | defer { 23 | trap.delete() 24 | } 25 | instance := wasmer.instance(store, mod, imports, mut trap) 26 | 27 | func := instance.exports()[0].as_func()? 28 | mut results := [wasmer.val_i32(0)] 29 | trap = func.call([wasmer.val_i32(2), wasmer.val_i32(3)], mut results) 30 | if trap.is_set() { 31 | println(trap.message()?) 32 | } else { 33 | println(results[0]) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/wasi.v: -------------------------------------------------------------------------------- 1 | import wasmer 2 | import os 3 | 4 | fn print_wasmer_error() { 5 | err := wasmer.get_wasmer_error() or { return } 6 | 7 | println('error: $err') 8 | } 9 | 10 | fn main() { 11 | println('Initializing...') 12 | engine := wasmer.engine() 13 | store := wasmer.store(engine) 14 | defer { 15 | store.delete() 16 | engine.delete() 17 | } 18 | 19 | println('Setting up WASI...') 20 | mut config := wasmer.wasi_config('example_program') 21 | 22 | config.arg('--eval') 23 | config.arg('function greet(name) { return JSON.stringify("Hello, " + name); }; print(greet("World"));') 24 | config.inherit_stdout() 25 | println('Compiling module...') 26 | 27 | file := os.read_bytes('examples/qjs.wasm')! 28 | mod := wasmer.compile(store, file)? 29 | 30 | wasi_env := wasmer.wasi_env(store, config)? 31 | 32 | imports := store.get_imports(mod, wasi_env)? 33 | 34 | mut trap := wasmer.null_trap() 35 | 36 | instance := wasmer.instance(store, mod, imports, mut trap) 37 | 38 | wasi_env.initialize_instance(store, instance)! 39 | 40 | exports := instance.exports() 41 | 42 | println('found $exports.len exports') 43 | 44 | run_func := instance.get_start_function()? 45 | 46 | println('Calling export\nEvaluating "function greet(name) { return JSON.stringify("Hello, " + name); }; print(greet("World"));"') 47 | mut results := []wasmer.Val{} 48 | _ = run_func.call([], mut results) 49 | 50 | println('Call completed') 51 | } 52 | -------------------------------------------------------------------------------- /v.mod: -------------------------------------------------------------------------------- 1 | Module { 2 | name: 'wasmer' 3 | description: 'Bindings to Wasmer C API.' 4 | version: '0.0.1' 5 | license: 'MIT' 6 | dependencies: [] 7 | } -------------------------------------------------------------------------------- /wasmer/include/README.md: -------------------------------------------------------------------------------- 1 | # `wasmer-c-api` [![Build Status](https://github.com/wasmerio/wasmer/workflows/build/badge.svg?style=flat-square)](https://github.com/wasmerio/wasmer/actions?query=workflow%3Abuild) [![Join Wasmer Slack](https://img.shields.io/static/v1?label=Slack&message=join%20chat&color=brighgreen&style=flat-square)](https://slack.wasmer.io) [![MIT License](https://img.shields.io/github/license/wasmerio/wasmer.svg?style=flat-square)](https://github.com/wasmerio/wasmer/blob/master/LICENSE) 2 | 3 | This crate exposes a C and a C++ API for the Wasmer runtime. It also fully supports the [wasm-c-api common API](https://github.com/WebAssembly/wasm-c-api). 4 | 5 | ## Usage 6 | 7 | Once you [install Wasmer in your system](https://github.com/wasmerio/wasmer-install), the *shared object files* and the *headers* are available **inside the Wasmer installed path**. 8 | 9 | ``` 10 | $WASMER_DIR/ 11 | lib/ 12 | libwasmer.{so,dylib,dll} 13 | include/ 14 | wasm.h 15 | wasmer.h 16 | wasmer.hh 17 | wasmer.h 18 | ``` 19 | 20 | Wasmer binary also ships with [`wasmer-config`](#wasmer-config) 21 | an utility tool that outputs config information needed to compile programs which use Wasmer. 22 | 23 | [The full C API documentation can be found here](https://wasmerio.github.io/wasmer/crates/doc/wasmer_c_api/). 24 | 25 | Here is a simple example to use the C API: 26 | 27 | ```c 28 | #include 29 | #include "wasmer.h" 30 | 31 | int main(int argc, const char* argv[]) { 32 | const char *wat_string = 33 | "(module\n" 34 | " (type $sum_t (func (param i32 i32) (result i32)))\n" 35 | " (func $sum_f (type $sum_t) (param $x i32) (param $y i32) (result i32)\n" 36 | " local.get $x\n" 37 | " local.get $y\n" 38 | " i32.add)\n" 39 | " (export \"sum\" (func $sum_f)))"; 40 | 41 | wasm_byte_vec_t wat; 42 | wasm_byte_vec_new(&wat, strlen(wat_string), wat_string); 43 | wasm_byte_vec_t wasm_bytes; 44 | wat2wasm(&wat, &wasm_bytes); 45 | wasm_byte_vec_delete(&wat); 46 | 47 | printf("Creating the store...\n"); 48 | wasm_engine_t* engine = wasm_engine_new(); 49 | wasm_store_t* store = wasm_store_new(engine); 50 | 51 | printf("Compiling module...\n"); 52 | wasm_module_t* module = wasm_module_new(store, &wasm_bytes); 53 | 54 | if (!module) { 55 | printf("> Error compiling module!\n"); 56 | return 1; 57 | } 58 | 59 | wasm_byte_vec_delete(&wasm_bytes); 60 | 61 | printf("Creating imports...\n"); 62 | wasm_extern_vec_t import_object = WASM_EMPTY_VEC; 63 | 64 | printf("Instantiating module...\n"); 65 | wasm_instance_t* instance = wasm_instance_new(store, module, &import_object, NULL); 66 | 67 | if (!instance) { 68 | printf("> Error instantiating module!\n"); 69 | return 1; 70 | } 71 | 72 | printf("Retrieving exports...\n"); 73 | wasm_extern_vec_t exports; 74 | wasm_instance_exports(instance, &exports); 75 | 76 | if (exports.size == 0) { 77 | printf("> Error accessing exports!\n"); 78 | return 1; 79 | } 80 | 81 | printf("Retrieving the `sum` function...\n"); 82 | wasm_func_t* sum_func = wasm_extern_as_func(exports.data[0]); 83 | 84 | if (sum_func == NULL) { 85 | printf("> Failed to get the `sum` function!\n"); 86 | return 1; 87 | } 88 | 89 | printf("Calling `sum` function...\n"); 90 | wasm_val_t args_val[2] = { WASM_I32_VAL(3), WASM_I32_VAL(4) }; 91 | wasm_val_t results_val[1] = { WASM_INIT_VAL }; 92 | wasm_val_vec_t args = WASM_ARRAY_VEC(args_val); 93 | wasm_val_vec_t results = WASM_ARRAY_VEC(results_val); 94 | 95 | if (wasm_func_call(sum_func, &args, &results)) { 96 | printf("> Error calling the `sum` function!\n"); 97 | 98 | return 1; 99 | } 100 | 101 | printf("Results of `sum`: %d\n", results_val[0].of.i32); 102 | 103 | wasm_module_delete(module); 104 | wasm_extern_vec_delete(&exports); 105 | wasm_instance_delete(instance); 106 | wasm_store_delete(store); 107 | wasm_engine_delete(engine); 108 | } 109 | ``` 110 | 111 | ## Building 112 | 113 | You can compile Wasmer shared library from source: 114 | 115 | ```text 116 | make build-capi 117 | ``` 118 | 119 | This will generate the shared library \(depending on your system\): 120 | 121 | * Windows: `target/release/libwasmer_c_api.dll` 122 | * macOS: `target/release/libwasmer_runtime_c_api.dylib` 123 | * Linux: `target/release/libwasmer_runtime_c_api.so` 124 | 125 | If you want to generate the library and headers in a friendly format as shown in [Usage](#usage), you can execute the following in Wasmer root: 126 | 127 | ```bash 128 | make package-capi 129 | ``` 130 | 131 | This command will generate a `package` directory, that you can then use easily in the [Wasmer C API examples](https://docs.wasmer.io/integrations/examples). 132 | 133 | 134 | ## Testing 135 | 136 | Tests are run using the release build of the library. If you make 137 | changes or compile with non-default features, please ensure you 138 | rebuild in release mode for the tests to see the changes. 139 | 140 | To run all the full suite of tests, enter Wasmer root directory 141 | and run the following commands: 142 | 143 | ```sh 144 | $ make test-capi 145 | ``` 146 | 147 | ## `wasmer config` 148 | 149 | `wasmer config` output various configuration information needed to compile programs which use Wasmer. 150 | 151 | ### `wasmer config --pkg-config` 152 | 153 | It outputs the necessary details for compiling and linking a program to Wasmer, 154 | using the `pkg-config` format: 155 | 156 | ```bash 157 | $ wasmer config --pkg-config > $PKG_CONFIG_PATH/wasmer.pc 158 | ``` 159 | 160 | ### `wasmer config --includedir` 161 | 162 | Directory containing Wasmer headers: 163 | 164 | ```bash 165 | $ wasmer config --includedir 166 | /users/myuser/.wasmer/include 167 | ``` 168 | 169 | ### `wasmer config --libdir` 170 | 171 | Directory containing Wasmer libraries: 172 | 173 | ```bash 174 | $ wasmer config --libdir 175 | /users/myuser/.wasmer/lib 176 | ``` 177 | 178 | ### `wasmer config --libs` 179 | 180 | Libraries needed to link against Wasmer components: 181 | 182 | ```bash 183 | $ wasmer config --libs 184 | -L/Users/myuser/.wasmer/lib -lwasmer 185 | ``` 186 | 187 | ### `wasmer config --libs` 188 | 189 | Libraries needed to link against Wasmer components: 190 | 191 | ```bash 192 | $ wasmer config --cflags 193 | -I/Users/myuser/.wasmer/include/wasmer 194 | ``` 195 | 196 | ## License 197 | 198 | Wasmer is primarily distributed under the terms of the [MIT 199 | license][mit-license] ([LICENSE][license]). 200 | 201 | 202 | [wasmer_h]: ./wasmer.h 203 | [wasmer_hh]: ./wasmer.hh 204 | [mit-license]: http://opensource.org/licenses/MIT 205 | [license]: https://github.com/wasmerio/wasmer/blob/master/LICENSE 206 | [Wasmer release page]: https://github.com/wasmerio/wasmer/releases 207 | -------------------------------------------------------------------------------- /wasmer/include/wasm.h: -------------------------------------------------------------------------------- 1 | // WebAssembly C API 2 | 3 | #ifndef WASM_H 4 | #define WASM_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #ifndef WASM_API_EXTERN 13 | #ifdef _WIN32 14 | #define WASM_API_EXTERN __declspec(dllimport) 15 | #else 16 | #define WASM_API_EXTERN 17 | #endif 18 | #endif 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | // Auxiliaries 26 | 27 | // Machine types 28 | 29 | 30 | typedef char byte_t; 31 | typedef float float32_t; 32 | typedef double float64_t; 33 | 34 | 35 | // Ownership 36 | 37 | #define own 38 | 39 | // The qualifier `own` is used to indicate ownership of data in this API. 40 | // It is intended to be interpreted similar to a `const` qualifier: 41 | // 42 | // - `own wasm_xxx_t*` owns the pointed-to data 43 | // - `own wasm_xxx_t` distributes to all fields of a struct or union `xxx` 44 | // - `own wasm_xxx_vec_t` owns the vector as well as its elements(!) 45 | // - an `own` function parameter passes ownership from caller to callee 46 | // - an `own` function result passes ownership from callee to caller 47 | // - an exception are `own` pointer parameters named `out`, which are copy-back 48 | // output parameters passing back ownership from callee to caller 49 | // 50 | // Own data is created by `wasm_xxx_new` functions and some others. 51 | // It must be released with the corresponding `wasm_xxx_delete` function. 52 | // 53 | // Deleting a reference does not necessarily delete the underlying object, 54 | // it merely indicates that this owner no longer uses it. 55 | // 56 | // For vectors, `const wasm_xxx_vec_t` is used informally to indicate that 57 | // neither the vector nor its elements should be modified. 58 | // TODO: introduce proper `wasm_xxx_const_vec_t`? 59 | 60 | 61 | #define WASM_DECLARE_OWN(name) \ 62 | typedef struct wasm_##name##_t wasm_##name##_t; \ 63 | \ 64 | WASM_API_EXTERN void wasm_##name##_delete(own wasm_##name##_t*); 65 | 66 | 67 | // Vectors 68 | 69 | #define WASM_DECLARE_VEC(name, ptr_or_none) \ 70 | typedef struct wasm_##name##_vec_t { \ 71 | size_t size; \ 72 | wasm_##name##_t ptr_or_none* data; \ 73 | } wasm_##name##_vec_t; \ 74 | \ 75 | WASM_API_EXTERN void wasm_##name##_vec_new_empty(own wasm_##name##_vec_t* out); \ 76 | WASM_API_EXTERN void wasm_##name##_vec_new_uninitialized( \ 77 | own wasm_##name##_vec_t* out, size_t); \ 78 | WASM_API_EXTERN void wasm_##name##_vec_new( \ 79 | own wasm_##name##_vec_t* out, \ 80 | size_t, own wasm_##name##_t ptr_or_none const[]); \ 81 | WASM_API_EXTERN void wasm_##name##_vec_copy( \ 82 | own wasm_##name##_vec_t* out, const wasm_##name##_vec_t*); \ 83 | WASM_API_EXTERN void wasm_##name##_vec_delete(own wasm_##name##_vec_t*); 84 | 85 | 86 | // Byte vectors 87 | 88 | typedef byte_t wasm_byte_t; 89 | WASM_DECLARE_VEC(byte, ) 90 | 91 | typedef wasm_byte_vec_t wasm_name_t; 92 | 93 | #define wasm_name wasm_byte_vec 94 | #define wasm_name_new wasm_byte_vec_new 95 | #define wasm_name_new_empty wasm_byte_vec_new_empty 96 | #define wasm_name_new_new_uninitialized wasm_byte_vec_new_uninitialized 97 | #define wasm_name_copy wasm_byte_vec_copy 98 | #define wasm_name_delete wasm_byte_vec_delete 99 | 100 | static inline void wasm_name_new_from_string( 101 | own wasm_name_t* out, own const char* s 102 | ) { 103 | wasm_name_new(out, strlen(s), s); 104 | } 105 | 106 | static inline void wasm_name_new_from_string_nt( 107 | own wasm_name_t* out, own const char* s 108 | ) { 109 | wasm_name_new(out, strlen(s) + 1, s); 110 | } 111 | 112 | 113 | /////////////////////////////////////////////////////////////////////////////// 114 | // Runtime Environment 115 | 116 | // Configuration 117 | 118 | WASM_DECLARE_OWN(config) 119 | 120 | WASM_API_EXTERN own wasm_config_t* wasm_config_new(); 121 | 122 | // Embedders may provide custom functions for manipulating configs. 123 | 124 | 125 | // Engine 126 | 127 | WASM_DECLARE_OWN(engine) 128 | 129 | // During testing, we use a custom implementation of wasm_engine_new 130 | #if defined(TEST_WASM) || defined(TEST_WASMER) 131 | wasm_engine_t* wasm_engine_new(); 132 | #else 133 | WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(); 134 | #endif 135 | WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(own wasm_config_t*); 136 | 137 | 138 | // Store 139 | 140 | WASM_DECLARE_OWN(store) 141 | 142 | WASM_API_EXTERN own wasm_store_t* wasm_store_new(wasm_engine_t*); 143 | 144 | /////////////////////////////////////////////////////////////////////////////// 145 | // Type Representations 146 | 147 | // Type attributes 148 | 149 | typedef uint8_t wasm_mutability_t; 150 | enum wasm_mutability_enum { 151 | WASM_CONST, 152 | WASM_VAR, 153 | }; 154 | 155 | typedef struct wasm_limits_t { 156 | uint32_t min; 157 | uint32_t max; 158 | } wasm_limits_t; 159 | 160 | static const uint32_t wasm_limits_max_default = 0xffffffff; 161 | 162 | 163 | // Generic 164 | 165 | #define WASM_DECLARE_TYPE(name) \ 166 | WASM_DECLARE_OWN(name) \ 167 | WASM_DECLARE_VEC(name, *) \ 168 | \ 169 | WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_copy(wasm_##name##_t*); 170 | 171 | 172 | // Value Types 173 | 174 | WASM_DECLARE_TYPE(valtype) 175 | 176 | typedef uint8_t wasm_valkind_t; 177 | enum wasm_valkind_enum { 178 | WASM_I32, 179 | WASM_I64, 180 | WASM_F32, 181 | WASM_F64, 182 | WASM_ANYREF = 128, 183 | WASM_FUNCREF, 184 | }; 185 | 186 | WASM_API_EXTERN own wasm_valtype_t* wasm_valtype_new(wasm_valkind_t); 187 | 188 | WASM_API_EXTERN wasm_valkind_t wasm_valtype_kind(const wasm_valtype_t*); 189 | 190 | static inline bool wasm_valkind_is_num(wasm_valkind_t k) { 191 | return k < WASM_ANYREF; 192 | } 193 | static inline bool wasm_valkind_is_ref(wasm_valkind_t k) { 194 | return k >= WASM_ANYREF; 195 | } 196 | 197 | static inline bool wasm_valtype_is_num(const wasm_valtype_t* t) { 198 | return wasm_valkind_is_num(wasm_valtype_kind(t)); 199 | } 200 | static inline bool wasm_valtype_is_ref(const wasm_valtype_t* t) { 201 | return wasm_valkind_is_ref(wasm_valtype_kind(t)); 202 | } 203 | 204 | 205 | // Function Types 206 | 207 | WASM_DECLARE_TYPE(functype) 208 | 209 | WASM_API_EXTERN own wasm_functype_t* wasm_functype_new( 210 | own wasm_valtype_vec_t* params, own wasm_valtype_vec_t* results); 211 | 212 | WASM_API_EXTERN const wasm_valtype_vec_t* wasm_functype_params(const wasm_functype_t*); 213 | WASM_API_EXTERN const wasm_valtype_vec_t* wasm_functype_results(const wasm_functype_t*); 214 | 215 | 216 | // Global Types 217 | 218 | WASM_DECLARE_TYPE(globaltype) 219 | 220 | WASM_API_EXTERN own wasm_globaltype_t* wasm_globaltype_new( 221 | own wasm_valtype_t*, wasm_mutability_t); 222 | 223 | WASM_API_EXTERN const wasm_valtype_t* wasm_globaltype_content(const wasm_globaltype_t*); 224 | WASM_API_EXTERN wasm_mutability_t wasm_globaltype_mutability(const wasm_globaltype_t*); 225 | 226 | 227 | // Table Types 228 | 229 | WASM_DECLARE_TYPE(tabletype) 230 | 231 | WASM_API_EXTERN own wasm_tabletype_t* wasm_tabletype_new( 232 | own wasm_valtype_t*, const wasm_limits_t*); 233 | 234 | WASM_API_EXTERN const wasm_valtype_t* wasm_tabletype_element(const wasm_tabletype_t*); 235 | WASM_API_EXTERN const wasm_limits_t* wasm_tabletype_limits(const wasm_tabletype_t*); 236 | 237 | 238 | // Memory Types 239 | 240 | WASM_DECLARE_TYPE(memorytype) 241 | 242 | WASM_API_EXTERN own wasm_memorytype_t* wasm_memorytype_new(const wasm_limits_t*); 243 | 244 | WASM_API_EXTERN const wasm_limits_t* wasm_memorytype_limits(const wasm_memorytype_t*); 245 | 246 | 247 | // Extern Types 248 | 249 | WASM_DECLARE_TYPE(externtype) 250 | 251 | typedef uint8_t wasm_externkind_t; 252 | enum wasm_externkind_enum { 253 | WASM_EXTERN_FUNC, 254 | WASM_EXTERN_GLOBAL, 255 | WASM_EXTERN_TABLE, 256 | WASM_EXTERN_MEMORY, 257 | }; 258 | 259 | WASM_API_EXTERN wasm_externkind_t wasm_externtype_kind(const wasm_externtype_t*); 260 | 261 | WASM_API_EXTERN wasm_externtype_t* wasm_functype_as_externtype(wasm_functype_t*); 262 | WASM_API_EXTERN wasm_externtype_t* wasm_globaltype_as_externtype(wasm_globaltype_t*); 263 | WASM_API_EXTERN wasm_externtype_t* wasm_tabletype_as_externtype(wasm_tabletype_t*); 264 | WASM_API_EXTERN wasm_externtype_t* wasm_memorytype_as_externtype(wasm_memorytype_t*); 265 | 266 | WASM_API_EXTERN wasm_functype_t* wasm_externtype_as_functype(wasm_externtype_t*); 267 | WASM_API_EXTERN wasm_globaltype_t* wasm_externtype_as_globaltype(wasm_externtype_t*); 268 | WASM_API_EXTERN wasm_tabletype_t* wasm_externtype_as_tabletype(wasm_externtype_t*); 269 | WASM_API_EXTERN wasm_memorytype_t* wasm_externtype_as_memorytype(wasm_externtype_t*); 270 | 271 | WASM_API_EXTERN const wasm_externtype_t* wasm_functype_as_externtype_const(const wasm_functype_t*); 272 | WASM_API_EXTERN const wasm_externtype_t* wasm_globaltype_as_externtype_const(const wasm_globaltype_t*); 273 | WASM_API_EXTERN const wasm_externtype_t* wasm_tabletype_as_externtype_const(const wasm_tabletype_t*); 274 | WASM_API_EXTERN const wasm_externtype_t* wasm_memorytype_as_externtype_const(const wasm_memorytype_t*); 275 | 276 | WASM_API_EXTERN const wasm_functype_t* wasm_externtype_as_functype_const(const wasm_externtype_t*); 277 | WASM_API_EXTERN const wasm_globaltype_t* wasm_externtype_as_globaltype_const(const wasm_externtype_t*); 278 | WASM_API_EXTERN const wasm_tabletype_t* wasm_externtype_as_tabletype_const(const wasm_externtype_t*); 279 | WASM_API_EXTERN const wasm_memorytype_t* wasm_externtype_as_memorytype_const(const wasm_externtype_t*); 280 | 281 | 282 | // Import Types 283 | 284 | WASM_DECLARE_TYPE(importtype) 285 | 286 | WASM_API_EXTERN own wasm_importtype_t* wasm_importtype_new( 287 | own wasm_name_t* module, own wasm_name_t* name, own wasm_externtype_t*); 288 | 289 | WASM_API_EXTERN const wasm_name_t* wasm_importtype_module(const wasm_importtype_t*); 290 | WASM_API_EXTERN const wasm_name_t* wasm_importtype_name(const wasm_importtype_t*); 291 | WASM_API_EXTERN const wasm_externtype_t* wasm_importtype_type(const wasm_importtype_t*); 292 | 293 | 294 | // Export Types 295 | 296 | WASM_DECLARE_TYPE(exporttype) 297 | 298 | WASM_API_EXTERN own wasm_exporttype_t* wasm_exporttype_new( 299 | own wasm_name_t*, own wasm_externtype_t*); 300 | 301 | WASM_API_EXTERN const wasm_name_t* wasm_exporttype_name(const wasm_exporttype_t*); 302 | WASM_API_EXTERN const wasm_externtype_t* wasm_exporttype_type(const wasm_exporttype_t*); 303 | 304 | 305 | /////////////////////////////////////////////////////////////////////////////// 306 | // Runtime Objects 307 | 308 | // Values 309 | 310 | struct wasm_ref_t; 311 | 312 | typedef struct wasm_val_t { 313 | wasm_valkind_t kind; 314 | union { 315 | int32_t i32; 316 | int64_t i64; 317 | float32_t f32; 318 | float64_t f64; 319 | struct wasm_ref_t* ref; 320 | } of; 321 | } wasm_val_t; 322 | 323 | WASM_API_EXTERN void wasm_val_delete(own wasm_val_t* v); 324 | WASM_API_EXTERN void wasm_val_copy(own wasm_val_t* out, const wasm_val_t*); 325 | 326 | WASM_DECLARE_VEC(val, ) 327 | 328 | 329 | // References 330 | 331 | #define WASM_DECLARE_REF_BASE(name) \ 332 | WASM_DECLARE_OWN(name) \ 333 | \ 334 | WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_copy(const wasm_##name##_t*); \ 335 | WASM_API_EXTERN bool wasm_##name##_same(const wasm_##name##_t*, const wasm_##name##_t*); \ 336 | \ 337 | WASM_API_EXTERN void* wasm_##name##_get_host_info(const wasm_##name##_t*); \ 338 | WASM_API_EXTERN void wasm_##name##_set_host_info(wasm_##name##_t*, void*); \ 339 | WASM_API_EXTERN void wasm_##name##_set_host_info_with_finalizer( \ 340 | wasm_##name##_t*, void*, void (*)(void*)); 341 | 342 | #define WASM_DECLARE_REF(name) \ 343 | WASM_DECLARE_REF_BASE(name) \ 344 | \ 345 | WASM_API_EXTERN wasm_ref_t* wasm_##name##_as_ref(wasm_##name##_t*); \ 346 | WASM_API_EXTERN wasm_##name##_t* wasm_ref_as_##name(wasm_ref_t*); \ 347 | WASM_API_EXTERN const wasm_ref_t* wasm_##name##_as_ref_const(const wasm_##name##_t*); \ 348 | WASM_API_EXTERN const wasm_##name##_t* wasm_ref_as_##name##_const(const wasm_ref_t*); 349 | 350 | #define WASM_DECLARE_SHARABLE_REF(name) \ 351 | WASM_DECLARE_REF(name) \ 352 | WASM_DECLARE_OWN(shared_##name) \ 353 | \ 354 | WASM_API_EXTERN own wasm_shared_##name##_t* wasm_##name##_share(const wasm_##name##_t*); \ 355 | WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_obtain(wasm_store_t*, const wasm_shared_##name##_t*); 356 | 357 | 358 | WASM_DECLARE_REF_BASE(ref) 359 | 360 | 361 | // Frames 362 | 363 | WASM_DECLARE_OWN(frame) 364 | WASM_DECLARE_VEC(frame, *) 365 | WASM_API_EXTERN own wasm_frame_t* wasm_frame_copy(const wasm_frame_t*); 366 | 367 | WASM_API_EXTERN struct wasm_instance_t* wasm_frame_instance(const wasm_frame_t*); 368 | WASM_API_EXTERN uint32_t wasm_frame_func_index(const wasm_frame_t*); 369 | WASM_API_EXTERN size_t wasm_frame_func_offset(const wasm_frame_t*); 370 | WASM_API_EXTERN size_t wasm_frame_module_offset(const wasm_frame_t*); 371 | 372 | 373 | // Traps 374 | 375 | typedef wasm_name_t wasm_message_t; // null terminated 376 | 377 | WASM_DECLARE_REF(trap) 378 | 379 | WASM_API_EXTERN own wasm_trap_t* wasm_trap_new(wasm_store_t* store, const wasm_message_t*); 380 | 381 | WASM_API_EXTERN void wasm_trap_message(const wasm_trap_t*, own wasm_message_t* out); 382 | WASM_API_EXTERN own wasm_frame_t* wasm_trap_origin(const wasm_trap_t*); 383 | WASM_API_EXTERN void wasm_trap_trace(const wasm_trap_t*, own wasm_frame_vec_t* out); 384 | 385 | 386 | // Foreign Objects 387 | 388 | WASM_DECLARE_REF(foreign) 389 | 390 | WASM_API_EXTERN own wasm_foreign_t* wasm_foreign_new(wasm_store_t*); 391 | 392 | 393 | // Modules 394 | 395 | WASM_DECLARE_SHARABLE_REF(module) 396 | 397 | WASM_API_EXTERN own wasm_module_t* wasm_module_new( 398 | wasm_store_t*, const wasm_byte_vec_t* binary); 399 | 400 | WASM_API_EXTERN bool wasm_module_validate(wasm_store_t*, const wasm_byte_vec_t* binary); 401 | 402 | WASM_API_EXTERN void wasm_module_imports(const wasm_module_t*, own wasm_importtype_vec_t* out); 403 | WASM_API_EXTERN void wasm_module_exports(const wasm_module_t*, own wasm_exporttype_vec_t* out); 404 | 405 | WASM_API_EXTERN void wasm_module_serialize(const wasm_module_t*, own wasm_byte_vec_t* out); 406 | WASM_API_EXTERN own wasm_module_t* wasm_module_deserialize(wasm_store_t*, const wasm_byte_vec_t*); 407 | 408 | 409 | // Function Instances 410 | 411 | WASM_DECLARE_REF(func) 412 | 413 | typedef own wasm_trap_t* (*wasm_func_callback_t)( 414 | const wasm_val_vec_t* args, own wasm_val_vec_t* results); 415 | typedef own wasm_trap_t* (*wasm_func_callback_with_env_t)( 416 | void* env, const wasm_val_vec_t* args, wasm_val_vec_t* results); 417 | 418 | WASM_API_EXTERN own wasm_func_t* wasm_func_new( 419 | wasm_store_t*, const wasm_functype_t*, wasm_func_callback_t); 420 | WASM_API_EXTERN own wasm_func_t* wasm_func_new_with_env( 421 | wasm_store_t*, const wasm_functype_t* type, wasm_func_callback_with_env_t, 422 | void* env, void (*finalizer)(void*)); 423 | 424 | WASM_API_EXTERN own wasm_functype_t* wasm_func_type(const wasm_func_t*); 425 | WASM_API_EXTERN size_t wasm_func_param_arity(const wasm_func_t*); 426 | WASM_API_EXTERN size_t wasm_func_result_arity(const wasm_func_t*); 427 | 428 | WASM_API_EXTERN own wasm_trap_t* wasm_func_call( 429 | const wasm_func_t*, const wasm_val_vec_t* args, wasm_val_vec_t* results); 430 | 431 | 432 | // Global Instances 433 | 434 | WASM_DECLARE_REF(global) 435 | 436 | WASM_API_EXTERN own wasm_global_t* wasm_global_new( 437 | wasm_store_t*, const wasm_globaltype_t*, const wasm_val_t*); 438 | 439 | WASM_API_EXTERN own wasm_globaltype_t* wasm_global_type(const wasm_global_t*); 440 | 441 | WASM_API_EXTERN void wasm_global_get(const wasm_global_t*, own wasm_val_t* out); 442 | WASM_API_EXTERN void wasm_global_set(wasm_global_t*, const wasm_val_t*); 443 | 444 | 445 | // Table Instances 446 | 447 | WASM_DECLARE_REF(table) 448 | 449 | typedef uint32_t wasm_table_size_t; 450 | 451 | WASM_API_EXTERN own wasm_table_t* wasm_table_new( 452 | wasm_store_t*, const wasm_tabletype_t*, wasm_ref_t* init); 453 | 454 | WASM_API_EXTERN own wasm_tabletype_t* wasm_table_type(const wasm_table_t*); 455 | 456 | WASM_API_EXTERN own wasm_ref_t* wasm_table_get(const wasm_table_t*, wasm_table_size_t index); 457 | WASM_API_EXTERN bool wasm_table_set(wasm_table_t*, wasm_table_size_t index, wasm_ref_t*); 458 | 459 | WASM_API_EXTERN wasm_table_size_t wasm_table_size(const wasm_table_t*); 460 | WASM_API_EXTERN bool wasm_table_grow(wasm_table_t*, wasm_table_size_t delta, wasm_ref_t* init); 461 | 462 | 463 | // Memory Instances 464 | 465 | WASM_DECLARE_REF(memory) 466 | 467 | typedef uint32_t wasm_memory_pages_t; 468 | 469 | static const size_t MEMORY_PAGE_SIZE = 0x10000; 470 | 471 | WASM_API_EXTERN own wasm_memory_t* wasm_memory_new(wasm_store_t*, const wasm_memorytype_t*); 472 | 473 | WASM_API_EXTERN own wasm_memorytype_t* wasm_memory_type(const wasm_memory_t*); 474 | 475 | WASM_API_EXTERN byte_t* wasm_memory_data(wasm_memory_t*); 476 | WASM_API_EXTERN size_t wasm_memory_data_size(const wasm_memory_t*); 477 | 478 | WASM_API_EXTERN wasm_memory_pages_t wasm_memory_size(const wasm_memory_t*); 479 | WASM_API_EXTERN bool wasm_memory_grow(wasm_memory_t*, wasm_memory_pages_t delta); 480 | 481 | 482 | // Externals 483 | 484 | WASM_DECLARE_REF(extern) 485 | WASM_DECLARE_VEC(extern, *) 486 | 487 | WASM_API_EXTERN wasm_externkind_t wasm_extern_kind(const wasm_extern_t*); 488 | WASM_API_EXTERN own wasm_externtype_t* wasm_extern_type(const wasm_extern_t*); 489 | 490 | WASM_API_EXTERN wasm_extern_t* wasm_func_as_extern(wasm_func_t*); 491 | WASM_API_EXTERN wasm_extern_t* wasm_global_as_extern(wasm_global_t*); 492 | WASM_API_EXTERN wasm_extern_t* wasm_table_as_extern(wasm_table_t*); 493 | WASM_API_EXTERN wasm_extern_t* wasm_memory_as_extern(wasm_memory_t*); 494 | 495 | WASM_API_EXTERN wasm_func_t* wasm_extern_as_func(wasm_extern_t*); 496 | WASM_API_EXTERN wasm_global_t* wasm_extern_as_global(wasm_extern_t*); 497 | WASM_API_EXTERN wasm_table_t* wasm_extern_as_table(wasm_extern_t*); 498 | WASM_API_EXTERN wasm_memory_t* wasm_extern_as_memory(wasm_extern_t*); 499 | 500 | WASM_API_EXTERN const wasm_extern_t* wasm_func_as_extern_const(const wasm_func_t*); 501 | WASM_API_EXTERN const wasm_extern_t* wasm_global_as_extern_const(const wasm_global_t*); 502 | WASM_API_EXTERN const wasm_extern_t* wasm_table_as_extern_const(const wasm_table_t*); 503 | WASM_API_EXTERN const wasm_extern_t* wasm_memory_as_extern_const(const wasm_memory_t*); 504 | 505 | WASM_API_EXTERN const wasm_func_t* wasm_extern_as_func_const(const wasm_extern_t*); 506 | WASM_API_EXTERN const wasm_global_t* wasm_extern_as_global_const(const wasm_extern_t*); 507 | WASM_API_EXTERN const wasm_table_t* wasm_extern_as_table_const(const wasm_extern_t*); 508 | WASM_API_EXTERN const wasm_memory_t* wasm_extern_as_memory_const(const wasm_extern_t*); 509 | 510 | 511 | // Module Instances 512 | 513 | WASM_DECLARE_REF(instance) 514 | 515 | WASM_API_EXTERN own wasm_instance_t* wasm_instance_new( 516 | wasm_store_t*, const wasm_module_t*, const wasm_extern_vec_t* imports, 517 | own wasm_trap_t** 518 | ); 519 | 520 | WASM_API_EXTERN void wasm_instance_exports(const wasm_instance_t*, own wasm_extern_vec_t* out); 521 | 522 | 523 | /////////////////////////////////////////////////////////////////////////////// 524 | // Convenience 525 | 526 | // Vectors 527 | 528 | #define WASM_EMPTY_VEC {0, NULL} 529 | #define WASM_ARRAY_VEC(array) {sizeof(array)/sizeof(*(array)), array} 530 | 531 | 532 | // Value Type construction short-hands 533 | 534 | static inline own wasm_valtype_t* wasm_valtype_new_i32() { 535 | return wasm_valtype_new(WASM_I32); 536 | } 537 | static inline own wasm_valtype_t* wasm_valtype_new_i64() { 538 | return wasm_valtype_new(WASM_I64); 539 | } 540 | static inline own wasm_valtype_t* wasm_valtype_new_f32() { 541 | return wasm_valtype_new(WASM_F32); 542 | } 543 | static inline own wasm_valtype_t* wasm_valtype_new_f64() { 544 | return wasm_valtype_new(WASM_F64); 545 | } 546 | 547 | static inline own wasm_valtype_t* wasm_valtype_new_anyref() { 548 | return wasm_valtype_new(WASM_ANYREF); 549 | } 550 | static inline own wasm_valtype_t* wasm_valtype_new_funcref() { 551 | return wasm_valtype_new(WASM_FUNCREF); 552 | } 553 | 554 | 555 | // Function Types construction short-hands 556 | 557 | static inline own wasm_functype_t* wasm_functype_new_0_0() { 558 | wasm_valtype_vec_t params, results; 559 | wasm_valtype_vec_new_empty(¶ms); 560 | wasm_valtype_vec_new_empty(&results); 561 | return wasm_functype_new(¶ms, &results); 562 | } 563 | 564 | static inline own wasm_functype_t* wasm_functype_new_1_0( 565 | own wasm_valtype_t* p 566 | ) { 567 | wasm_valtype_t* ps[1] = {p}; 568 | wasm_valtype_vec_t params, results; 569 | wasm_valtype_vec_new(¶ms, 1, ps); 570 | wasm_valtype_vec_new_empty(&results); 571 | return wasm_functype_new(¶ms, &results); 572 | } 573 | 574 | static inline own wasm_functype_t* wasm_functype_new_2_0( 575 | own wasm_valtype_t* p1, own wasm_valtype_t* p2 576 | ) { 577 | wasm_valtype_t* ps[2] = {p1, p2}; 578 | wasm_valtype_vec_t params, results; 579 | wasm_valtype_vec_new(¶ms, 2, ps); 580 | wasm_valtype_vec_new_empty(&results); 581 | return wasm_functype_new(¶ms, &results); 582 | } 583 | 584 | static inline own wasm_functype_t* wasm_functype_new_3_0( 585 | own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3 586 | ) { 587 | wasm_valtype_t* ps[3] = {p1, p2, p3}; 588 | wasm_valtype_vec_t params, results; 589 | wasm_valtype_vec_new(¶ms, 3, ps); 590 | wasm_valtype_vec_new_empty(&results); 591 | return wasm_functype_new(¶ms, &results); 592 | } 593 | 594 | static inline own wasm_functype_t* wasm_functype_new_0_1( 595 | own wasm_valtype_t* r 596 | ) { 597 | wasm_valtype_t* rs[1] = {r}; 598 | wasm_valtype_vec_t params, results; 599 | wasm_valtype_vec_new_empty(¶ms); 600 | wasm_valtype_vec_new(&results, 1, rs); 601 | return wasm_functype_new(¶ms, &results); 602 | } 603 | 604 | static inline own wasm_functype_t* wasm_functype_new_1_1( 605 | own wasm_valtype_t* p, own wasm_valtype_t* r 606 | ) { 607 | wasm_valtype_t* ps[1] = {p}; 608 | wasm_valtype_t* rs[1] = {r}; 609 | wasm_valtype_vec_t params, results; 610 | wasm_valtype_vec_new(¶ms, 1, ps); 611 | wasm_valtype_vec_new(&results, 1, rs); 612 | return wasm_functype_new(¶ms, &results); 613 | } 614 | 615 | static inline own wasm_functype_t* wasm_functype_new_2_1( 616 | own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* r 617 | ) { 618 | wasm_valtype_t* ps[2] = {p1, p2}; 619 | wasm_valtype_t* rs[1] = {r}; 620 | wasm_valtype_vec_t params, results; 621 | wasm_valtype_vec_new(¶ms, 2, ps); 622 | wasm_valtype_vec_new(&results, 1, rs); 623 | return wasm_functype_new(¶ms, &results); 624 | } 625 | 626 | static inline own wasm_functype_t* wasm_functype_new_3_1( 627 | own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3, 628 | own wasm_valtype_t* r 629 | ) { 630 | wasm_valtype_t* ps[3] = {p1, p2, p3}; 631 | wasm_valtype_t* rs[1] = {r}; 632 | wasm_valtype_vec_t params, results; 633 | wasm_valtype_vec_new(¶ms, 3, ps); 634 | wasm_valtype_vec_new(&results, 1, rs); 635 | return wasm_functype_new(¶ms, &results); 636 | } 637 | 638 | static inline own wasm_functype_t* wasm_functype_new_0_2( 639 | own wasm_valtype_t* r1, own wasm_valtype_t* r2 640 | ) { 641 | wasm_valtype_t* rs[2] = {r1, r2}; 642 | wasm_valtype_vec_t params, results; 643 | wasm_valtype_vec_new_empty(¶ms); 644 | wasm_valtype_vec_new(&results, 2, rs); 645 | return wasm_functype_new(¶ms, &results); 646 | } 647 | 648 | static inline own wasm_functype_t* wasm_functype_new_1_2( 649 | own wasm_valtype_t* p, own wasm_valtype_t* r1, own wasm_valtype_t* r2 650 | ) { 651 | wasm_valtype_t* ps[1] = {p}; 652 | wasm_valtype_t* rs[2] = {r1, r2}; 653 | wasm_valtype_vec_t params, results; 654 | wasm_valtype_vec_new(¶ms, 1, ps); 655 | wasm_valtype_vec_new(&results, 2, rs); 656 | return wasm_functype_new(¶ms, &results); 657 | } 658 | 659 | static inline own wasm_functype_t* wasm_functype_new_2_2( 660 | own wasm_valtype_t* p1, own wasm_valtype_t* p2, 661 | own wasm_valtype_t* r1, own wasm_valtype_t* r2 662 | ) { 663 | wasm_valtype_t* ps[2] = {p1, p2}; 664 | wasm_valtype_t* rs[2] = {r1, r2}; 665 | wasm_valtype_vec_t params, results; 666 | wasm_valtype_vec_new(¶ms, 2, ps); 667 | wasm_valtype_vec_new(&results, 2, rs); 668 | return wasm_functype_new(¶ms, &results); 669 | } 670 | 671 | static inline own wasm_functype_t* wasm_functype_new_3_2( 672 | own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3, 673 | own wasm_valtype_t* r1, own wasm_valtype_t* r2 674 | ) { 675 | wasm_valtype_t* ps[3] = {p1, p2, p3}; 676 | wasm_valtype_t* rs[2] = {r1, r2}; 677 | wasm_valtype_vec_t params, results; 678 | wasm_valtype_vec_new(¶ms, 3, ps); 679 | wasm_valtype_vec_new(&results, 2, rs); 680 | return wasm_functype_new(¶ms, &results); 681 | } 682 | 683 | 684 | // Value construction short-hands 685 | 686 | static inline void wasm_val_init_ptr(own wasm_val_t* out, void* p) { 687 | #if UINTPTR_MAX == UINT32_MAX 688 | out->kind = WASM_I32; 689 | out->of.i32 = (intptr_t)p; 690 | #elif UINTPTR_MAX == UINT64_MAX 691 | out->kind = WASM_I64; 692 | out->of.i64 = (intptr_t)p; 693 | #endif 694 | } 695 | 696 | static inline void* wasm_val_ptr(const wasm_val_t* val) { 697 | #if UINTPTR_MAX == UINT32_MAX 698 | return (void*)(intptr_t)val->of.i32; 699 | #elif UINTPTR_MAX == UINT64_MAX 700 | return (void*)(intptr_t)val->of.i64; 701 | #endif 702 | } 703 | 704 | #define WASM_I32_VAL(i) {.kind = WASM_I32, .of = {.i32 = i}} 705 | #define WASM_I64_VAL(i) {.kind = WASM_I64, .of = {.i64 = i}} 706 | #define WASM_F32_VAL(z) {.kind = WASM_F32, .of = {.f32 = z}} 707 | #define WASM_F64_VAL(z) {.kind = WASM_F64, .of = {.f64 = z}} 708 | #define WASM_REF_VAL(r) {.kind = WASM_ANYREF, .of = {.ref = r}} 709 | #define WASM_INIT_VAL {.kind = WASM_ANYREF, .of = {.ref = NULL}} 710 | 711 | 712 | /////////////////////////////////////////////////////////////////////////////// 713 | 714 | #undef own 715 | 716 | #ifdef __cplusplus 717 | } // extern "C" 718 | #endif 719 | 720 | #endif // #ifdef WASM_H 721 | -------------------------------------------------------------------------------- /wasmer/include/wasmer.h: -------------------------------------------------------------------------------- 1 | // The Wasmer C/C++ header file compatible with the [`wasm-c-api`] 2 | // standard API, as `wasm.h` (included here). 3 | // 4 | // This file is automatically generated by `lib/c-api/build.rs` of the 5 | // [`wasmer-c-api`] Rust crate. 6 | // 7 | // # Stability 8 | // 9 | // The [`wasm-c-api`] standard API is a _living_ standard. There is no 10 | // commitment for stability yet. We (Wasmer) will try our best to keep 11 | // backward compatibility as much as possible. Nonetheless, some 12 | // necessary API aren't yet standardized, and as such, we provide a 13 | // custom API, e.g. `wasi_*` types and functions. 14 | // 15 | // The documentation makes it clear whether a function is unstable. 16 | // 17 | // When a type or a function will be deprecated, it will be marked as 18 | // such with the appropriated compiler warning, and will be removed at 19 | // the next release round. 20 | // 21 | // # Documentation 22 | // 23 | // At the time of writing, the [`wasm-c-api`] standard has no 24 | // documentation. This file also does not include inline 25 | // documentation. However, we have made (and we continue to make) an 26 | // important effort to document everything. [See the documentation 27 | // online][documentation]. Please refer to this page for the real 28 | // canonical documentation. It also contains numerous examples. 29 | // 30 | // To generate the documentation locally, run `cargo doc --open` from 31 | // within the [`wasmer-c-api`] Rust crate. 32 | // 33 | // [`wasm-c-api`]: https://github.com/WebAssembly/wasm-c-api 34 | // [`wasmer-c-api`]: https://github.com/wasmerio/wasmer/tree/master/lib/c-api 35 | // [documentation]: https://wasmerio.github.io/wasmer/crates/wasmer_c_api/ 36 | 37 | #if !defined(WASMER_H_PRELUDE) 38 | 39 | #define WASMER_H_PRELUDE 40 | 41 | // Define the `ARCH_X86_X64` constant. 42 | #if defined(MSVC) && defined(_M_AMD64) 43 | # define ARCH_X86_64 44 | #elif (defined(GCC) || defined(__GNUC__) || defined(__clang__)) && defined(__x86_64__) 45 | # define ARCH_X86_64 46 | #endif 47 | 48 | // Compatibility with non-Clang compilers. 49 | #if !defined(__has_attribute) 50 | # define __has_attribute(x) 0 51 | #endif 52 | 53 | // Compatibility with non-Clang compilers. 54 | #if !defined(__has_declspec_attribute) 55 | # define __has_declspec_attribute(x) 0 56 | #endif 57 | 58 | // Define the `DEPRECATED` macro. 59 | #if defined(GCC) || defined(__GNUC__) || __has_attribute(deprecated) 60 | # define DEPRECATED(message) __attribute__((deprecated(message))) 61 | #elif defined(MSVC) || __has_declspec_attribute(deprecated) 62 | # define DEPRECATED(message) __declspec(deprecated(message)) 63 | #endif 64 | 65 | // The `compiler` feature has been enabled for this build. 66 | #define WASMER_UNIVERSAL_ENABLED 67 | 68 | // The `compiler` feature has been enabled for this build. 69 | #define WASMER_COMPILER_ENABLED 70 | 71 | // The `wasi` feature has been enabled for this build. 72 | #define WASMER_WASI_ENABLED 73 | 74 | // The `middlewares` feature has been enabled for this build. 75 | #define WASMER_MIDDLEWARES_ENABLED 76 | 77 | // This file corresponds to the following Wasmer version. 78 | #define WASMER_VERSION "3.0.0-rc.1" 79 | #define WASMER_VERSION_MAJOR 3 80 | #define WASMER_VERSION_MINOR 0 81 | #define WASMER_VERSION_PATCH 0 82 | #define WASMER_VERSION_PRE "rc.1" 83 | 84 | #endif // WASMER_H_PRELUDE 85 | 86 | 87 | // 88 | // OK, here we go. The code below is automatically generated. 89 | // 90 | 91 | 92 | #ifndef WASMER_H 93 | #define WASMER_H 94 | 95 | #include 96 | #include 97 | #include 98 | #include 99 | #include "wasm.h" 100 | 101 | #if defined(WASMER_WASI_ENABLED) 102 | typedef enum wasi_version_t { 103 | #if defined(WASMER_WASI_ENABLED) 104 | INVALID_VERSION = -1, 105 | #endif 106 | #if defined(WASMER_WASI_ENABLED) 107 | LATEST = 0, 108 | #endif 109 | #if defined(WASMER_WASI_ENABLED) 110 | SNAPSHOT0 = 1, 111 | #endif 112 | #if defined(WASMER_WASI_ENABLED) 113 | SNAPSHOT1 = 2, 114 | #endif 115 | #if defined(WASMER_WASI_ENABLED) 116 | WASIX32V1 = 3, 117 | #endif 118 | #if defined(WASMER_WASI_ENABLED) 119 | WASIX64V1 = 4, 120 | #endif 121 | } wasi_version_t; 122 | #endif 123 | 124 | #if (defined(WASMER_COMPILER_ENABLED) && defined(WASMER_COMPILER_ENABLED)) 125 | typedef enum wasmer_compiler_t { 126 | #if defined(WASMER_COMPILER_ENABLED) 127 | CRANELIFT = 0, 128 | #endif 129 | #if defined(WASMER_COMPILER_ENABLED) 130 | LLVM = 1, 131 | #endif 132 | #if defined(WASMER_COMPILER_ENABLED) 133 | SINGLEPASS = 2, 134 | #endif 135 | } wasmer_compiler_t; 136 | #endif 137 | 138 | #if defined(WASMER_COMPILER_ENABLED) 139 | typedef enum wasmer_engine_t { 140 | #if defined(WASMER_COMPILER_ENABLED) 141 | UNIVERSAL = 0, 142 | #endif 143 | } wasmer_engine_t; 144 | #endif 145 | 146 | #if defined(WASMER_COMPILER_ENABLED) 147 | typedef enum wasmer_parser_operator_t { 148 | #if defined(WASMER_COMPILER_ENABLED) 149 | Unreachable, 150 | #endif 151 | #if defined(WASMER_COMPILER_ENABLED) 152 | Nop, 153 | #endif 154 | #if defined(WASMER_COMPILER_ENABLED) 155 | Block, 156 | #endif 157 | #if defined(WASMER_COMPILER_ENABLED) 158 | Loop, 159 | #endif 160 | #if defined(WASMER_COMPILER_ENABLED) 161 | If, 162 | #endif 163 | #if defined(WASMER_COMPILER_ENABLED) 164 | Else, 165 | #endif 166 | #if defined(WASMER_COMPILER_ENABLED) 167 | Try, 168 | #endif 169 | #if defined(WASMER_COMPILER_ENABLED) 170 | Catch, 171 | #endif 172 | #if defined(WASMER_COMPILER_ENABLED) 173 | CatchAll, 174 | #endif 175 | #if defined(WASMER_COMPILER_ENABLED) 176 | Delegate, 177 | #endif 178 | #if defined(WASMER_COMPILER_ENABLED) 179 | Throw, 180 | #endif 181 | #if defined(WASMER_COMPILER_ENABLED) 182 | Rethrow, 183 | #endif 184 | #if defined(WASMER_COMPILER_ENABLED) 185 | Unwind, 186 | #endif 187 | #if defined(WASMER_COMPILER_ENABLED) 188 | End, 189 | #endif 190 | #if defined(WASMER_COMPILER_ENABLED) 191 | Br, 192 | #endif 193 | #if defined(WASMER_COMPILER_ENABLED) 194 | BrIf, 195 | #endif 196 | #if defined(WASMER_COMPILER_ENABLED) 197 | BrTable, 198 | #endif 199 | #if defined(WASMER_COMPILER_ENABLED) 200 | Return, 201 | #endif 202 | #if defined(WASMER_COMPILER_ENABLED) 203 | Call, 204 | #endif 205 | #if defined(WASMER_COMPILER_ENABLED) 206 | CallIndirect, 207 | #endif 208 | #if defined(WASMER_COMPILER_ENABLED) 209 | ReturnCall, 210 | #endif 211 | #if defined(WASMER_COMPILER_ENABLED) 212 | ReturnCallIndirect, 213 | #endif 214 | #if defined(WASMER_COMPILER_ENABLED) 215 | Drop, 216 | #endif 217 | #if defined(WASMER_COMPILER_ENABLED) 218 | Select, 219 | #endif 220 | #if defined(WASMER_COMPILER_ENABLED) 221 | TypedSelect, 222 | #endif 223 | #if defined(WASMER_COMPILER_ENABLED) 224 | LocalGet, 225 | #endif 226 | #if defined(WASMER_COMPILER_ENABLED) 227 | LocalSet, 228 | #endif 229 | #if defined(WASMER_COMPILER_ENABLED) 230 | LocalTee, 231 | #endif 232 | #if defined(WASMER_COMPILER_ENABLED) 233 | GlobalGet, 234 | #endif 235 | #if defined(WASMER_COMPILER_ENABLED) 236 | GlobalSet, 237 | #endif 238 | #if defined(WASMER_COMPILER_ENABLED) 239 | I32Load, 240 | #endif 241 | #if defined(WASMER_COMPILER_ENABLED) 242 | I64Load, 243 | #endif 244 | #if defined(WASMER_COMPILER_ENABLED) 245 | F32Load, 246 | #endif 247 | #if defined(WASMER_COMPILER_ENABLED) 248 | F64Load, 249 | #endif 250 | #if defined(WASMER_COMPILER_ENABLED) 251 | I32Load8S, 252 | #endif 253 | #if defined(WASMER_COMPILER_ENABLED) 254 | I32Load8U, 255 | #endif 256 | #if defined(WASMER_COMPILER_ENABLED) 257 | I32Load16S, 258 | #endif 259 | #if defined(WASMER_COMPILER_ENABLED) 260 | I32Load16U, 261 | #endif 262 | #if defined(WASMER_COMPILER_ENABLED) 263 | I64Load8S, 264 | #endif 265 | #if defined(WASMER_COMPILER_ENABLED) 266 | I64Load8U, 267 | #endif 268 | #if defined(WASMER_COMPILER_ENABLED) 269 | I64Load16S, 270 | #endif 271 | #if defined(WASMER_COMPILER_ENABLED) 272 | I64Load16U, 273 | #endif 274 | #if defined(WASMER_COMPILER_ENABLED) 275 | I64Load32S, 276 | #endif 277 | #if defined(WASMER_COMPILER_ENABLED) 278 | I64Load32U, 279 | #endif 280 | #if defined(WASMER_COMPILER_ENABLED) 281 | I32Store, 282 | #endif 283 | #if defined(WASMER_COMPILER_ENABLED) 284 | I64Store, 285 | #endif 286 | #if defined(WASMER_COMPILER_ENABLED) 287 | F32Store, 288 | #endif 289 | #if defined(WASMER_COMPILER_ENABLED) 290 | F64Store, 291 | #endif 292 | #if defined(WASMER_COMPILER_ENABLED) 293 | I32Store8, 294 | #endif 295 | #if defined(WASMER_COMPILER_ENABLED) 296 | I32Store16, 297 | #endif 298 | #if defined(WASMER_COMPILER_ENABLED) 299 | I64Store8, 300 | #endif 301 | #if defined(WASMER_COMPILER_ENABLED) 302 | I64Store16, 303 | #endif 304 | #if defined(WASMER_COMPILER_ENABLED) 305 | I64Store32, 306 | #endif 307 | #if defined(WASMER_COMPILER_ENABLED) 308 | MemorySize, 309 | #endif 310 | #if defined(WASMER_COMPILER_ENABLED) 311 | MemoryGrow, 312 | #endif 313 | #if defined(WASMER_COMPILER_ENABLED) 314 | I32Const, 315 | #endif 316 | #if defined(WASMER_COMPILER_ENABLED) 317 | I64Const, 318 | #endif 319 | #if defined(WASMER_COMPILER_ENABLED) 320 | F32Const, 321 | #endif 322 | #if defined(WASMER_COMPILER_ENABLED) 323 | F64Const, 324 | #endif 325 | #if defined(WASMER_COMPILER_ENABLED) 326 | RefNull, 327 | #endif 328 | #if defined(WASMER_COMPILER_ENABLED) 329 | RefIsNull, 330 | #endif 331 | #if defined(WASMER_COMPILER_ENABLED) 332 | RefFunc, 333 | #endif 334 | #if defined(WASMER_COMPILER_ENABLED) 335 | I32Eqz, 336 | #endif 337 | #if defined(WASMER_COMPILER_ENABLED) 338 | I32Eq, 339 | #endif 340 | #if defined(WASMER_COMPILER_ENABLED) 341 | I32Ne, 342 | #endif 343 | #if defined(WASMER_COMPILER_ENABLED) 344 | I32LtS, 345 | #endif 346 | #if defined(WASMER_COMPILER_ENABLED) 347 | I32LtU, 348 | #endif 349 | #if defined(WASMER_COMPILER_ENABLED) 350 | I32GtS, 351 | #endif 352 | #if defined(WASMER_COMPILER_ENABLED) 353 | I32GtU, 354 | #endif 355 | #if defined(WASMER_COMPILER_ENABLED) 356 | I32LeS, 357 | #endif 358 | #if defined(WASMER_COMPILER_ENABLED) 359 | I32LeU, 360 | #endif 361 | #if defined(WASMER_COMPILER_ENABLED) 362 | I32GeS, 363 | #endif 364 | #if defined(WASMER_COMPILER_ENABLED) 365 | I32GeU, 366 | #endif 367 | #if defined(WASMER_COMPILER_ENABLED) 368 | I64Eqz, 369 | #endif 370 | #if defined(WASMER_COMPILER_ENABLED) 371 | I64Eq, 372 | #endif 373 | #if defined(WASMER_COMPILER_ENABLED) 374 | I64Ne, 375 | #endif 376 | #if defined(WASMER_COMPILER_ENABLED) 377 | I64LtS, 378 | #endif 379 | #if defined(WASMER_COMPILER_ENABLED) 380 | I64LtU, 381 | #endif 382 | #if defined(WASMER_COMPILER_ENABLED) 383 | I64GtS, 384 | #endif 385 | #if defined(WASMER_COMPILER_ENABLED) 386 | I64GtU, 387 | #endif 388 | #if defined(WASMER_COMPILER_ENABLED) 389 | I64LeS, 390 | #endif 391 | #if defined(WASMER_COMPILER_ENABLED) 392 | I64LeU, 393 | #endif 394 | #if defined(WASMER_COMPILER_ENABLED) 395 | I64GeS, 396 | #endif 397 | #if defined(WASMER_COMPILER_ENABLED) 398 | I64GeU, 399 | #endif 400 | #if defined(WASMER_COMPILER_ENABLED) 401 | F32Eq, 402 | #endif 403 | #if defined(WASMER_COMPILER_ENABLED) 404 | F32Ne, 405 | #endif 406 | #if defined(WASMER_COMPILER_ENABLED) 407 | F32Lt, 408 | #endif 409 | #if defined(WASMER_COMPILER_ENABLED) 410 | F32Gt, 411 | #endif 412 | #if defined(WASMER_COMPILER_ENABLED) 413 | F32Le, 414 | #endif 415 | #if defined(WASMER_COMPILER_ENABLED) 416 | F32Ge, 417 | #endif 418 | #if defined(WASMER_COMPILER_ENABLED) 419 | F64Eq, 420 | #endif 421 | #if defined(WASMER_COMPILER_ENABLED) 422 | F64Ne, 423 | #endif 424 | #if defined(WASMER_COMPILER_ENABLED) 425 | F64Lt, 426 | #endif 427 | #if defined(WASMER_COMPILER_ENABLED) 428 | F64Gt, 429 | #endif 430 | #if defined(WASMER_COMPILER_ENABLED) 431 | F64Le, 432 | #endif 433 | #if defined(WASMER_COMPILER_ENABLED) 434 | F64Ge, 435 | #endif 436 | #if defined(WASMER_COMPILER_ENABLED) 437 | I32Clz, 438 | #endif 439 | #if defined(WASMER_COMPILER_ENABLED) 440 | I32Ctz, 441 | #endif 442 | #if defined(WASMER_COMPILER_ENABLED) 443 | I32Popcnt, 444 | #endif 445 | #if defined(WASMER_COMPILER_ENABLED) 446 | I32Add, 447 | #endif 448 | #if defined(WASMER_COMPILER_ENABLED) 449 | I32Sub, 450 | #endif 451 | #if defined(WASMER_COMPILER_ENABLED) 452 | I32Mul, 453 | #endif 454 | #if defined(WASMER_COMPILER_ENABLED) 455 | I32DivS, 456 | #endif 457 | #if defined(WASMER_COMPILER_ENABLED) 458 | I32DivU, 459 | #endif 460 | #if defined(WASMER_COMPILER_ENABLED) 461 | I32RemS, 462 | #endif 463 | #if defined(WASMER_COMPILER_ENABLED) 464 | I32RemU, 465 | #endif 466 | #if defined(WASMER_COMPILER_ENABLED) 467 | I32And, 468 | #endif 469 | #if defined(WASMER_COMPILER_ENABLED) 470 | I32Or, 471 | #endif 472 | #if defined(WASMER_COMPILER_ENABLED) 473 | I32Xor, 474 | #endif 475 | #if defined(WASMER_COMPILER_ENABLED) 476 | I32Shl, 477 | #endif 478 | #if defined(WASMER_COMPILER_ENABLED) 479 | I32ShrS, 480 | #endif 481 | #if defined(WASMER_COMPILER_ENABLED) 482 | I32ShrU, 483 | #endif 484 | #if defined(WASMER_COMPILER_ENABLED) 485 | I32Rotl, 486 | #endif 487 | #if defined(WASMER_COMPILER_ENABLED) 488 | I32Rotr, 489 | #endif 490 | #if defined(WASMER_COMPILER_ENABLED) 491 | I64Clz, 492 | #endif 493 | #if defined(WASMER_COMPILER_ENABLED) 494 | I64Ctz, 495 | #endif 496 | #if defined(WASMER_COMPILER_ENABLED) 497 | I64Popcnt, 498 | #endif 499 | #if defined(WASMER_COMPILER_ENABLED) 500 | I64Add, 501 | #endif 502 | #if defined(WASMER_COMPILER_ENABLED) 503 | I64Sub, 504 | #endif 505 | #if defined(WASMER_COMPILER_ENABLED) 506 | I64Mul, 507 | #endif 508 | #if defined(WASMER_COMPILER_ENABLED) 509 | I64DivS, 510 | #endif 511 | #if defined(WASMER_COMPILER_ENABLED) 512 | I64DivU, 513 | #endif 514 | #if defined(WASMER_COMPILER_ENABLED) 515 | I64RemS, 516 | #endif 517 | #if defined(WASMER_COMPILER_ENABLED) 518 | I64RemU, 519 | #endif 520 | #if defined(WASMER_COMPILER_ENABLED) 521 | I64And, 522 | #endif 523 | #if defined(WASMER_COMPILER_ENABLED) 524 | I64Or, 525 | #endif 526 | #if defined(WASMER_COMPILER_ENABLED) 527 | I64Xor, 528 | #endif 529 | #if defined(WASMER_COMPILER_ENABLED) 530 | I64Shl, 531 | #endif 532 | #if defined(WASMER_COMPILER_ENABLED) 533 | I64ShrS, 534 | #endif 535 | #if defined(WASMER_COMPILER_ENABLED) 536 | I64ShrU, 537 | #endif 538 | #if defined(WASMER_COMPILER_ENABLED) 539 | I64Rotl, 540 | #endif 541 | #if defined(WASMER_COMPILER_ENABLED) 542 | I64Rotr, 543 | #endif 544 | #if defined(WASMER_COMPILER_ENABLED) 545 | F32Abs, 546 | #endif 547 | #if defined(WASMER_COMPILER_ENABLED) 548 | F32Neg, 549 | #endif 550 | #if defined(WASMER_COMPILER_ENABLED) 551 | F32Ceil, 552 | #endif 553 | #if defined(WASMER_COMPILER_ENABLED) 554 | F32Floor, 555 | #endif 556 | #if defined(WASMER_COMPILER_ENABLED) 557 | F32Trunc, 558 | #endif 559 | #if defined(WASMER_COMPILER_ENABLED) 560 | F32Nearest, 561 | #endif 562 | #if defined(WASMER_COMPILER_ENABLED) 563 | F32Sqrt, 564 | #endif 565 | #if defined(WASMER_COMPILER_ENABLED) 566 | F32Add, 567 | #endif 568 | #if defined(WASMER_COMPILER_ENABLED) 569 | F32Sub, 570 | #endif 571 | #if defined(WASMER_COMPILER_ENABLED) 572 | F32Mul, 573 | #endif 574 | #if defined(WASMER_COMPILER_ENABLED) 575 | F32Div, 576 | #endif 577 | #if defined(WASMER_COMPILER_ENABLED) 578 | F32Min, 579 | #endif 580 | #if defined(WASMER_COMPILER_ENABLED) 581 | F32Max, 582 | #endif 583 | #if defined(WASMER_COMPILER_ENABLED) 584 | F32Copysign, 585 | #endif 586 | #if defined(WASMER_COMPILER_ENABLED) 587 | F64Abs, 588 | #endif 589 | #if defined(WASMER_COMPILER_ENABLED) 590 | F64Neg, 591 | #endif 592 | #if defined(WASMER_COMPILER_ENABLED) 593 | F64Ceil, 594 | #endif 595 | #if defined(WASMER_COMPILER_ENABLED) 596 | F64Floor, 597 | #endif 598 | #if defined(WASMER_COMPILER_ENABLED) 599 | F64Trunc, 600 | #endif 601 | #if defined(WASMER_COMPILER_ENABLED) 602 | F64Nearest, 603 | #endif 604 | #if defined(WASMER_COMPILER_ENABLED) 605 | F64Sqrt, 606 | #endif 607 | #if defined(WASMER_COMPILER_ENABLED) 608 | F64Add, 609 | #endif 610 | #if defined(WASMER_COMPILER_ENABLED) 611 | F64Sub, 612 | #endif 613 | #if defined(WASMER_COMPILER_ENABLED) 614 | F64Mul, 615 | #endif 616 | #if defined(WASMER_COMPILER_ENABLED) 617 | F64Div, 618 | #endif 619 | #if defined(WASMER_COMPILER_ENABLED) 620 | F64Min, 621 | #endif 622 | #if defined(WASMER_COMPILER_ENABLED) 623 | F64Max, 624 | #endif 625 | #if defined(WASMER_COMPILER_ENABLED) 626 | F64Copysign, 627 | #endif 628 | #if defined(WASMER_COMPILER_ENABLED) 629 | I32WrapI64, 630 | #endif 631 | #if defined(WASMER_COMPILER_ENABLED) 632 | I32TruncF32S, 633 | #endif 634 | #if defined(WASMER_COMPILER_ENABLED) 635 | I32TruncF32U, 636 | #endif 637 | #if defined(WASMER_COMPILER_ENABLED) 638 | I32TruncF64S, 639 | #endif 640 | #if defined(WASMER_COMPILER_ENABLED) 641 | I32TruncF64U, 642 | #endif 643 | #if defined(WASMER_COMPILER_ENABLED) 644 | I64ExtendI32S, 645 | #endif 646 | #if defined(WASMER_COMPILER_ENABLED) 647 | I64ExtendI32U, 648 | #endif 649 | #if defined(WASMER_COMPILER_ENABLED) 650 | I64TruncF32S, 651 | #endif 652 | #if defined(WASMER_COMPILER_ENABLED) 653 | I64TruncF32U, 654 | #endif 655 | #if defined(WASMER_COMPILER_ENABLED) 656 | I64TruncF64S, 657 | #endif 658 | #if defined(WASMER_COMPILER_ENABLED) 659 | I64TruncF64U, 660 | #endif 661 | #if defined(WASMER_COMPILER_ENABLED) 662 | F32ConvertI32S, 663 | #endif 664 | #if defined(WASMER_COMPILER_ENABLED) 665 | F32ConvertI32U, 666 | #endif 667 | #if defined(WASMER_COMPILER_ENABLED) 668 | F32ConvertI64S, 669 | #endif 670 | #if defined(WASMER_COMPILER_ENABLED) 671 | F32ConvertI64U, 672 | #endif 673 | #if defined(WASMER_COMPILER_ENABLED) 674 | F32DemoteF64, 675 | #endif 676 | #if defined(WASMER_COMPILER_ENABLED) 677 | F64ConvertI32S, 678 | #endif 679 | #if defined(WASMER_COMPILER_ENABLED) 680 | F64ConvertI32U, 681 | #endif 682 | #if defined(WASMER_COMPILER_ENABLED) 683 | F64ConvertI64S, 684 | #endif 685 | #if defined(WASMER_COMPILER_ENABLED) 686 | F64ConvertI64U, 687 | #endif 688 | #if defined(WASMER_COMPILER_ENABLED) 689 | F64PromoteF32, 690 | #endif 691 | #if defined(WASMER_COMPILER_ENABLED) 692 | I32ReinterpretF32, 693 | #endif 694 | #if defined(WASMER_COMPILER_ENABLED) 695 | I64ReinterpretF64, 696 | #endif 697 | #if defined(WASMER_COMPILER_ENABLED) 698 | F32ReinterpretI32, 699 | #endif 700 | #if defined(WASMER_COMPILER_ENABLED) 701 | F64ReinterpretI64, 702 | #endif 703 | #if defined(WASMER_COMPILER_ENABLED) 704 | I32Extend8S, 705 | #endif 706 | #if defined(WASMER_COMPILER_ENABLED) 707 | I32Extend16S, 708 | #endif 709 | #if defined(WASMER_COMPILER_ENABLED) 710 | I64Extend8S, 711 | #endif 712 | #if defined(WASMER_COMPILER_ENABLED) 713 | I64Extend16S, 714 | #endif 715 | #if defined(WASMER_COMPILER_ENABLED) 716 | I64Extend32S, 717 | #endif 718 | #if defined(WASMER_COMPILER_ENABLED) 719 | I32TruncSatF32S, 720 | #endif 721 | #if defined(WASMER_COMPILER_ENABLED) 722 | I32TruncSatF32U, 723 | #endif 724 | #if defined(WASMER_COMPILER_ENABLED) 725 | I32TruncSatF64S, 726 | #endif 727 | #if defined(WASMER_COMPILER_ENABLED) 728 | I32TruncSatF64U, 729 | #endif 730 | #if defined(WASMER_COMPILER_ENABLED) 731 | I64TruncSatF32S, 732 | #endif 733 | #if defined(WASMER_COMPILER_ENABLED) 734 | I64TruncSatF32U, 735 | #endif 736 | #if defined(WASMER_COMPILER_ENABLED) 737 | I64TruncSatF64S, 738 | #endif 739 | #if defined(WASMER_COMPILER_ENABLED) 740 | I64TruncSatF64U, 741 | #endif 742 | #if defined(WASMER_COMPILER_ENABLED) 743 | MemoryInit, 744 | #endif 745 | #if defined(WASMER_COMPILER_ENABLED) 746 | DataDrop, 747 | #endif 748 | #if defined(WASMER_COMPILER_ENABLED) 749 | MemoryCopy, 750 | #endif 751 | #if defined(WASMER_COMPILER_ENABLED) 752 | MemoryFill, 753 | #endif 754 | #if defined(WASMER_COMPILER_ENABLED) 755 | TableInit, 756 | #endif 757 | #if defined(WASMER_COMPILER_ENABLED) 758 | ElemDrop, 759 | #endif 760 | #if defined(WASMER_COMPILER_ENABLED) 761 | TableCopy, 762 | #endif 763 | #if defined(WASMER_COMPILER_ENABLED) 764 | TableFill, 765 | #endif 766 | #if defined(WASMER_COMPILER_ENABLED) 767 | TableGet, 768 | #endif 769 | #if defined(WASMER_COMPILER_ENABLED) 770 | TableSet, 771 | #endif 772 | #if defined(WASMER_COMPILER_ENABLED) 773 | TableGrow, 774 | #endif 775 | #if defined(WASMER_COMPILER_ENABLED) 776 | TableSize, 777 | #endif 778 | #if defined(WASMER_COMPILER_ENABLED) 779 | MemoryAtomicNotify, 780 | #endif 781 | #if defined(WASMER_COMPILER_ENABLED) 782 | MemoryAtomicWait32, 783 | #endif 784 | #if defined(WASMER_COMPILER_ENABLED) 785 | MemoryAtomicWait64, 786 | #endif 787 | #if defined(WASMER_COMPILER_ENABLED) 788 | AtomicFence, 789 | #endif 790 | #if defined(WASMER_COMPILER_ENABLED) 791 | I32AtomicLoad, 792 | #endif 793 | #if defined(WASMER_COMPILER_ENABLED) 794 | I64AtomicLoad, 795 | #endif 796 | #if defined(WASMER_COMPILER_ENABLED) 797 | I32AtomicLoad8U, 798 | #endif 799 | #if defined(WASMER_COMPILER_ENABLED) 800 | I32AtomicLoad16U, 801 | #endif 802 | #if defined(WASMER_COMPILER_ENABLED) 803 | I64AtomicLoad8U, 804 | #endif 805 | #if defined(WASMER_COMPILER_ENABLED) 806 | I64AtomicLoad16U, 807 | #endif 808 | #if defined(WASMER_COMPILER_ENABLED) 809 | I64AtomicLoad32U, 810 | #endif 811 | #if defined(WASMER_COMPILER_ENABLED) 812 | I32AtomicStore, 813 | #endif 814 | #if defined(WASMER_COMPILER_ENABLED) 815 | I64AtomicStore, 816 | #endif 817 | #if defined(WASMER_COMPILER_ENABLED) 818 | I32AtomicStore8, 819 | #endif 820 | #if defined(WASMER_COMPILER_ENABLED) 821 | I32AtomicStore16, 822 | #endif 823 | #if defined(WASMER_COMPILER_ENABLED) 824 | I64AtomicStore8, 825 | #endif 826 | #if defined(WASMER_COMPILER_ENABLED) 827 | I64AtomicStore16, 828 | #endif 829 | #if defined(WASMER_COMPILER_ENABLED) 830 | I64AtomicStore32, 831 | #endif 832 | #if defined(WASMER_COMPILER_ENABLED) 833 | I32AtomicRmwAdd, 834 | #endif 835 | #if defined(WASMER_COMPILER_ENABLED) 836 | I64AtomicRmwAdd, 837 | #endif 838 | #if defined(WASMER_COMPILER_ENABLED) 839 | I32AtomicRmw8AddU, 840 | #endif 841 | #if defined(WASMER_COMPILER_ENABLED) 842 | I32AtomicRmw16AddU, 843 | #endif 844 | #if defined(WASMER_COMPILER_ENABLED) 845 | I64AtomicRmw8AddU, 846 | #endif 847 | #if defined(WASMER_COMPILER_ENABLED) 848 | I64AtomicRmw16AddU, 849 | #endif 850 | #if defined(WASMER_COMPILER_ENABLED) 851 | I64AtomicRmw32AddU, 852 | #endif 853 | #if defined(WASMER_COMPILER_ENABLED) 854 | I32AtomicRmwSub, 855 | #endif 856 | #if defined(WASMER_COMPILER_ENABLED) 857 | I64AtomicRmwSub, 858 | #endif 859 | #if defined(WASMER_COMPILER_ENABLED) 860 | I32AtomicRmw8SubU, 861 | #endif 862 | #if defined(WASMER_COMPILER_ENABLED) 863 | I32AtomicRmw16SubU, 864 | #endif 865 | #if defined(WASMER_COMPILER_ENABLED) 866 | I64AtomicRmw8SubU, 867 | #endif 868 | #if defined(WASMER_COMPILER_ENABLED) 869 | I64AtomicRmw16SubU, 870 | #endif 871 | #if defined(WASMER_COMPILER_ENABLED) 872 | I64AtomicRmw32SubU, 873 | #endif 874 | #if defined(WASMER_COMPILER_ENABLED) 875 | I32AtomicRmwAnd, 876 | #endif 877 | #if defined(WASMER_COMPILER_ENABLED) 878 | I64AtomicRmwAnd, 879 | #endif 880 | #if defined(WASMER_COMPILER_ENABLED) 881 | I32AtomicRmw8AndU, 882 | #endif 883 | #if defined(WASMER_COMPILER_ENABLED) 884 | I32AtomicRmw16AndU, 885 | #endif 886 | #if defined(WASMER_COMPILER_ENABLED) 887 | I64AtomicRmw8AndU, 888 | #endif 889 | #if defined(WASMER_COMPILER_ENABLED) 890 | I64AtomicRmw16AndU, 891 | #endif 892 | #if defined(WASMER_COMPILER_ENABLED) 893 | I64AtomicRmw32AndU, 894 | #endif 895 | #if defined(WASMER_COMPILER_ENABLED) 896 | I32AtomicRmwOr, 897 | #endif 898 | #if defined(WASMER_COMPILER_ENABLED) 899 | I64AtomicRmwOr, 900 | #endif 901 | #if defined(WASMER_COMPILER_ENABLED) 902 | I32AtomicRmw8OrU, 903 | #endif 904 | #if defined(WASMER_COMPILER_ENABLED) 905 | I32AtomicRmw16OrU, 906 | #endif 907 | #if defined(WASMER_COMPILER_ENABLED) 908 | I64AtomicRmw8OrU, 909 | #endif 910 | #if defined(WASMER_COMPILER_ENABLED) 911 | I64AtomicRmw16OrU, 912 | #endif 913 | #if defined(WASMER_COMPILER_ENABLED) 914 | I64AtomicRmw32OrU, 915 | #endif 916 | #if defined(WASMER_COMPILER_ENABLED) 917 | I32AtomicRmwXor, 918 | #endif 919 | #if defined(WASMER_COMPILER_ENABLED) 920 | I64AtomicRmwXor, 921 | #endif 922 | #if defined(WASMER_COMPILER_ENABLED) 923 | I32AtomicRmw8XorU, 924 | #endif 925 | #if defined(WASMER_COMPILER_ENABLED) 926 | I32AtomicRmw16XorU, 927 | #endif 928 | #if defined(WASMER_COMPILER_ENABLED) 929 | I64AtomicRmw8XorU, 930 | #endif 931 | #if defined(WASMER_COMPILER_ENABLED) 932 | I64AtomicRmw16XorU, 933 | #endif 934 | #if defined(WASMER_COMPILER_ENABLED) 935 | I64AtomicRmw32XorU, 936 | #endif 937 | #if defined(WASMER_COMPILER_ENABLED) 938 | I32AtomicRmwXchg, 939 | #endif 940 | #if defined(WASMER_COMPILER_ENABLED) 941 | I64AtomicRmwXchg, 942 | #endif 943 | #if defined(WASMER_COMPILER_ENABLED) 944 | I32AtomicRmw8XchgU, 945 | #endif 946 | #if defined(WASMER_COMPILER_ENABLED) 947 | I32AtomicRmw16XchgU, 948 | #endif 949 | #if defined(WASMER_COMPILER_ENABLED) 950 | I64AtomicRmw8XchgU, 951 | #endif 952 | #if defined(WASMER_COMPILER_ENABLED) 953 | I64AtomicRmw16XchgU, 954 | #endif 955 | #if defined(WASMER_COMPILER_ENABLED) 956 | I64AtomicRmw32XchgU, 957 | #endif 958 | #if defined(WASMER_COMPILER_ENABLED) 959 | I32AtomicRmwCmpxchg, 960 | #endif 961 | #if defined(WASMER_COMPILER_ENABLED) 962 | I64AtomicRmwCmpxchg, 963 | #endif 964 | #if defined(WASMER_COMPILER_ENABLED) 965 | I32AtomicRmw8CmpxchgU, 966 | #endif 967 | #if defined(WASMER_COMPILER_ENABLED) 968 | I32AtomicRmw16CmpxchgU, 969 | #endif 970 | #if defined(WASMER_COMPILER_ENABLED) 971 | I64AtomicRmw8CmpxchgU, 972 | #endif 973 | #if defined(WASMER_COMPILER_ENABLED) 974 | I64AtomicRmw16CmpxchgU, 975 | #endif 976 | #if defined(WASMER_COMPILER_ENABLED) 977 | I64AtomicRmw32CmpxchgU, 978 | #endif 979 | #if defined(WASMER_COMPILER_ENABLED) 980 | V128Load, 981 | #endif 982 | #if defined(WASMER_COMPILER_ENABLED) 983 | V128Store, 984 | #endif 985 | #if defined(WASMER_COMPILER_ENABLED) 986 | V128Const, 987 | #endif 988 | #if defined(WASMER_COMPILER_ENABLED) 989 | I8x16Splat, 990 | #endif 991 | #if defined(WASMER_COMPILER_ENABLED) 992 | I8x16ExtractLaneS, 993 | #endif 994 | #if defined(WASMER_COMPILER_ENABLED) 995 | I8x16ExtractLaneU, 996 | #endif 997 | #if defined(WASMER_COMPILER_ENABLED) 998 | I8x16ReplaceLane, 999 | #endif 1000 | #if defined(WASMER_COMPILER_ENABLED) 1001 | I16x8Splat, 1002 | #endif 1003 | #if defined(WASMER_COMPILER_ENABLED) 1004 | I16x8ExtractLaneS, 1005 | #endif 1006 | #if defined(WASMER_COMPILER_ENABLED) 1007 | I16x8ExtractLaneU, 1008 | #endif 1009 | #if defined(WASMER_COMPILER_ENABLED) 1010 | I16x8ReplaceLane, 1011 | #endif 1012 | #if defined(WASMER_COMPILER_ENABLED) 1013 | I32x4Splat, 1014 | #endif 1015 | #if defined(WASMER_COMPILER_ENABLED) 1016 | I32x4ExtractLane, 1017 | #endif 1018 | #if defined(WASMER_COMPILER_ENABLED) 1019 | I32x4ReplaceLane, 1020 | #endif 1021 | #if defined(WASMER_COMPILER_ENABLED) 1022 | I64x2Splat, 1023 | #endif 1024 | #if defined(WASMER_COMPILER_ENABLED) 1025 | I64x2ExtractLane, 1026 | #endif 1027 | #if defined(WASMER_COMPILER_ENABLED) 1028 | I64x2ReplaceLane, 1029 | #endif 1030 | #if defined(WASMER_COMPILER_ENABLED) 1031 | F32x4Splat, 1032 | #endif 1033 | #if defined(WASMER_COMPILER_ENABLED) 1034 | F32x4ExtractLane, 1035 | #endif 1036 | #if defined(WASMER_COMPILER_ENABLED) 1037 | F32x4ReplaceLane, 1038 | #endif 1039 | #if defined(WASMER_COMPILER_ENABLED) 1040 | F64x2Splat, 1041 | #endif 1042 | #if defined(WASMER_COMPILER_ENABLED) 1043 | F64x2ExtractLane, 1044 | #endif 1045 | #if defined(WASMER_COMPILER_ENABLED) 1046 | F64x2ReplaceLane, 1047 | #endif 1048 | #if defined(WASMER_COMPILER_ENABLED) 1049 | I8x16Eq, 1050 | #endif 1051 | #if defined(WASMER_COMPILER_ENABLED) 1052 | I8x16Ne, 1053 | #endif 1054 | #if defined(WASMER_COMPILER_ENABLED) 1055 | I8x16LtS, 1056 | #endif 1057 | #if defined(WASMER_COMPILER_ENABLED) 1058 | I8x16LtU, 1059 | #endif 1060 | #if defined(WASMER_COMPILER_ENABLED) 1061 | I8x16GtS, 1062 | #endif 1063 | #if defined(WASMER_COMPILER_ENABLED) 1064 | I8x16GtU, 1065 | #endif 1066 | #if defined(WASMER_COMPILER_ENABLED) 1067 | I8x16LeS, 1068 | #endif 1069 | #if defined(WASMER_COMPILER_ENABLED) 1070 | I8x16LeU, 1071 | #endif 1072 | #if defined(WASMER_COMPILER_ENABLED) 1073 | I8x16GeS, 1074 | #endif 1075 | #if defined(WASMER_COMPILER_ENABLED) 1076 | I8x16GeU, 1077 | #endif 1078 | #if defined(WASMER_COMPILER_ENABLED) 1079 | I16x8Eq, 1080 | #endif 1081 | #if defined(WASMER_COMPILER_ENABLED) 1082 | I16x8Ne, 1083 | #endif 1084 | #if defined(WASMER_COMPILER_ENABLED) 1085 | I16x8LtS, 1086 | #endif 1087 | #if defined(WASMER_COMPILER_ENABLED) 1088 | I16x8LtU, 1089 | #endif 1090 | #if defined(WASMER_COMPILER_ENABLED) 1091 | I16x8GtS, 1092 | #endif 1093 | #if defined(WASMER_COMPILER_ENABLED) 1094 | I16x8GtU, 1095 | #endif 1096 | #if defined(WASMER_COMPILER_ENABLED) 1097 | I16x8LeS, 1098 | #endif 1099 | #if defined(WASMER_COMPILER_ENABLED) 1100 | I16x8LeU, 1101 | #endif 1102 | #if defined(WASMER_COMPILER_ENABLED) 1103 | I16x8GeS, 1104 | #endif 1105 | #if defined(WASMER_COMPILER_ENABLED) 1106 | I16x8GeU, 1107 | #endif 1108 | #if defined(WASMER_COMPILER_ENABLED) 1109 | I32x4Eq, 1110 | #endif 1111 | #if defined(WASMER_COMPILER_ENABLED) 1112 | I32x4Ne, 1113 | #endif 1114 | #if defined(WASMER_COMPILER_ENABLED) 1115 | I32x4LtS, 1116 | #endif 1117 | #if defined(WASMER_COMPILER_ENABLED) 1118 | I32x4LtU, 1119 | #endif 1120 | #if defined(WASMER_COMPILER_ENABLED) 1121 | I32x4GtS, 1122 | #endif 1123 | #if defined(WASMER_COMPILER_ENABLED) 1124 | I32x4GtU, 1125 | #endif 1126 | #if defined(WASMER_COMPILER_ENABLED) 1127 | I32x4LeS, 1128 | #endif 1129 | #if defined(WASMER_COMPILER_ENABLED) 1130 | I32x4LeU, 1131 | #endif 1132 | #if defined(WASMER_COMPILER_ENABLED) 1133 | I32x4GeS, 1134 | #endif 1135 | #if defined(WASMER_COMPILER_ENABLED) 1136 | I32x4GeU, 1137 | #endif 1138 | #if defined(WASMER_COMPILER_ENABLED) 1139 | I64x2Eq, 1140 | #endif 1141 | #if defined(WASMER_COMPILER_ENABLED) 1142 | I64x2Ne, 1143 | #endif 1144 | #if defined(WASMER_COMPILER_ENABLED) 1145 | I64x2LtS, 1146 | #endif 1147 | #if defined(WASMER_COMPILER_ENABLED) 1148 | I64x2GtS, 1149 | #endif 1150 | #if defined(WASMER_COMPILER_ENABLED) 1151 | I64x2LeS, 1152 | #endif 1153 | #if defined(WASMER_COMPILER_ENABLED) 1154 | I64x2GeS, 1155 | #endif 1156 | #if defined(WASMER_COMPILER_ENABLED) 1157 | F32x4Eq, 1158 | #endif 1159 | #if defined(WASMER_COMPILER_ENABLED) 1160 | F32x4Ne, 1161 | #endif 1162 | #if defined(WASMER_COMPILER_ENABLED) 1163 | F32x4Lt, 1164 | #endif 1165 | #if defined(WASMER_COMPILER_ENABLED) 1166 | F32x4Gt, 1167 | #endif 1168 | #if defined(WASMER_COMPILER_ENABLED) 1169 | F32x4Le, 1170 | #endif 1171 | #if defined(WASMER_COMPILER_ENABLED) 1172 | F32x4Ge, 1173 | #endif 1174 | #if defined(WASMER_COMPILER_ENABLED) 1175 | F64x2Eq, 1176 | #endif 1177 | #if defined(WASMER_COMPILER_ENABLED) 1178 | F64x2Ne, 1179 | #endif 1180 | #if defined(WASMER_COMPILER_ENABLED) 1181 | F64x2Lt, 1182 | #endif 1183 | #if defined(WASMER_COMPILER_ENABLED) 1184 | F64x2Gt, 1185 | #endif 1186 | #if defined(WASMER_COMPILER_ENABLED) 1187 | F64x2Le, 1188 | #endif 1189 | #if defined(WASMER_COMPILER_ENABLED) 1190 | F64x2Ge, 1191 | #endif 1192 | #if defined(WASMER_COMPILER_ENABLED) 1193 | V128Not, 1194 | #endif 1195 | #if defined(WASMER_COMPILER_ENABLED) 1196 | V128And, 1197 | #endif 1198 | #if defined(WASMER_COMPILER_ENABLED) 1199 | V128AndNot, 1200 | #endif 1201 | #if defined(WASMER_COMPILER_ENABLED) 1202 | V128Or, 1203 | #endif 1204 | #if defined(WASMER_COMPILER_ENABLED) 1205 | V128Xor, 1206 | #endif 1207 | #if defined(WASMER_COMPILER_ENABLED) 1208 | V128Bitselect, 1209 | #endif 1210 | #if defined(WASMER_COMPILER_ENABLED) 1211 | V128AnyTrue, 1212 | #endif 1213 | #if defined(WASMER_COMPILER_ENABLED) 1214 | I8x16Abs, 1215 | #endif 1216 | #if defined(WASMER_COMPILER_ENABLED) 1217 | I8x16Neg, 1218 | #endif 1219 | #if defined(WASMER_COMPILER_ENABLED) 1220 | I8x16AllTrue, 1221 | #endif 1222 | #if defined(WASMER_COMPILER_ENABLED) 1223 | I8x16Bitmask, 1224 | #endif 1225 | #if defined(WASMER_COMPILER_ENABLED) 1226 | I8x16Shl, 1227 | #endif 1228 | #if defined(WASMER_COMPILER_ENABLED) 1229 | I8x16ShrS, 1230 | #endif 1231 | #if defined(WASMER_COMPILER_ENABLED) 1232 | I8x16ShrU, 1233 | #endif 1234 | #if defined(WASMER_COMPILER_ENABLED) 1235 | I8x16Add, 1236 | #endif 1237 | #if defined(WASMER_COMPILER_ENABLED) 1238 | I8x16AddSatS, 1239 | #endif 1240 | #if defined(WASMER_COMPILER_ENABLED) 1241 | I8x16AddSatU, 1242 | #endif 1243 | #if defined(WASMER_COMPILER_ENABLED) 1244 | I8x16Sub, 1245 | #endif 1246 | #if defined(WASMER_COMPILER_ENABLED) 1247 | I8x16SubSatS, 1248 | #endif 1249 | #if defined(WASMER_COMPILER_ENABLED) 1250 | I8x16SubSatU, 1251 | #endif 1252 | #if defined(WASMER_COMPILER_ENABLED) 1253 | I8x16MinS, 1254 | #endif 1255 | #if defined(WASMER_COMPILER_ENABLED) 1256 | I8x16MinU, 1257 | #endif 1258 | #if defined(WASMER_COMPILER_ENABLED) 1259 | I8x16MaxS, 1260 | #endif 1261 | #if defined(WASMER_COMPILER_ENABLED) 1262 | I8x16MaxU, 1263 | #endif 1264 | #if defined(WASMER_COMPILER_ENABLED) 1265 | I8x16Popcnt, 1266 | #endif 1267 | #if defined(WASMER_COMPILER_ENABLED) 1268 | I16x8Abs, 1269 | #endif 1270 | #if defined(WASMER_COMPILER_ENABLED) 1271 | I16x8Neg, 1272 | #endif 1273 | #if defined(WASMER_COMPILER_ENABLED) 1274 | I16x8AllTrue, 1275 | #endif 1276 | #if defined(WASMER_COMPILER_ENABLED) 1277 | I16x8Bitmask, 1278 | #endif 1279 | #if defined(WASMER_COMPILER_ENABLED) 1280 | I16x8Shl, 1281 | #endif 1282 | #if defined(WASMER_COMPILER_ENABLED) 1283 | I16x8ShrS, 1284 | #endif 1285 | #if defined(WASMER_COMPILER_ENABLED) 1286 | I16x8ShrU, 1287 | #endif 1288 | #if defined(WASMER_COMPILER_ENABLED) 1289 | I16x8Add, 1290 | #endif 1291 | #if defined(WASMER_COMPILER_ENABLED) 1292 | I16x8AddSatS, 1293 | #endif 1294 | #if defined(WASMER_COMPILER_ENABLED) 1295 | I16x8AddSatU, 1296 | #endif 1297 | #if defined(WASMER_COMPILER_ENABLED) 1298 | I16x8Sub, 1299 | #endif 1300 | #if defined(WASMER_COMPILER_ENABLED) 1301 | I16x8SubSatS, 1302 | #endif 1303 | #if defined(WASMER_COMPILER_ENABLED) 1304 | I16x8SubSatU, 1305 | #endif 1306 | #if defined(WASMER_COMPILER_ENABLED) 1307 | I16x8Mul, 1308 | #endif 1309 | #if defined(WASMER_COMPILER_ENABLED) 1310 | I16x8MinS, 1311 | #endif 1312 | #if defined(WASMER_COMPILER_ENABLED) 1313 | I16x8MinU, 1314 | #endif 1315 | #if defined(WASMER_COMPILER_ENABLED) 1316 | I16x8MaxS, 1317 | #endif 1318 | #if defined(WASMER_COMPILER_ENABLED) 1319 | I16x8MaxU, 1320 | #endif 1321 | #if defined(WASMER_COMPILER_ENABLED) 1322 | I16x8ExtAddPairwiseI8x16S, 1323 | #endif 1324 | #if defined(WASMER_COMPILER_ENABLED) 1325 | I16x8ExtAddPairwiseI8x16U, 1326 | #endif 1327 | #if defined(WASMER_COMPILER_ENABLED) 1328 | I32x4Abs, 1329 | #endif 1330 | #if defined(WASMER_COMPILER_ENABLED) 1331 | I32x4Neg, 1332 | #endif 1333 | #if defined(WASMER_COMPILER_ENABLED) 1334 | I32x4AllTrue, 1335 | #endif 1336 | #if defined(WASMER_COMPILER_ENABLED) 1337 | I32x4Bitmask, 1338 | #endif 1339 | #if defined(WASMER_COMPILER_ENABLED) 1340 | I32x4Shl, 1341 | #endif 1342 | #if defined(WASMER_COMPILER_ENABLED) 1343 | I32x4ShrS, 1344 | #endif 1345 | #if defined(WASMER_COMPILER_ENABLED) 1346 | I32x4ShrU, 1347 | #endif 1348 | #if defined(WASMER_COMPILER_ENABLED) 1349 | I32x4Add, 1350 | #endif 1351 | #if defined(WASMER_COMPILER_ENABLED) 1352 | I32x4Sub, 1353 | #endif 1354 | #if defined(WASMER_COMPILER_ENABLED) 1355 | I32x4Mul, 1356 | #endif 1357 | #if defined(WASMER_COMPILER_ENABLED) 1358 | I32x4MinS, 1359 | #endif 1360 | #if defined(WASMER_COMPILER_ENABLED) 1361 | I32x4MinU, 1362 | #endif 1363 | #if defined(WASMER_COMPILER_ENABLED) 1364 | I32x4MaxS, 1365 | #endif 1366 | #if defined(WASMER_COMPILER_ENABLED) 1367 | I32x4MaxU, 1368 | #endif 1369 | #if defined(WASMER_COMPILER_ENABLED) 1370 | I32x4DotI16x8S, 1371 | #endif 1372 | #if defined(WASMER_COMPILER_ENABLED) 1373 | I32x4ExtAddPairwiseI16x8S, 1374 | #endif 1375 | #if defined(WASMER_COMPILER_ENABLED) 1376 | I32x4ExtAddPairwiseI16x8U, 1377 | #endif 1378 | #if defined(WASMER_COMPILER_ENABLED) 1379 | I64x2Abs, 1380 | #endif 1381 | #if defined(WASMER_COMPILER_ENABLED) 1382 | I64x2Neg, 1383 | #endif 1384 | #if defined(WASMER_COMPILER_ENABLED) 1385 | I64x2AllTrue, 1386 | #endif 1387 | #if defined(WASMER_COMPILER_ENABLED) 1388 | I64x2Bitmask, 1389 | #endif 1390 | #if defined(WASMER_COMPILER_ENABLED) 1391 | I64x2Shl, 1392 | #endif 1393 | #if defined(WASMER_COMPILER_ENABLED) 1394 | I64x2ShrS, 1395 | #endif 1396 | #if defined(WASMER_COMPILER_ENABLED) 1397 | I64x2ShrU, 1398 | #endif 1399 | #if defined(WASMER_COMPILER_ENABLED) 1400 | I64x2Add, 1401 | #endif 1402 | #if defined(WASMER_COMPILER_ENABLED) 1403 | I64x2Sub, 1404 | #endif 1405 | #if defined(WASMER_COMPILER_ENABLED) 1406 | I64x2Mul, 1407 | #endif 1408 | #if defined(WASMER_COMPILER_ENABLED) 1409 | F32x4Ceil, 1410 | #endif 1411 | #if defined(WASMER_COMPILER_ENABLED) 1412 | F32x4Floor, 1413 | #endif 1414 | #if defined(WASMER_COMPILER_ENABLED) 1415 | F32x4Trunc, 1416 | #endif 1417 | #if defined(WASMER_COMPILER_ENABLED) 1418 | F32x4Nearest, 1419 | #endif 1420 | #if defined(WASMER_COMPILER_ENABLED) 1421 | F64x2Ceil, 1422 | #endif 1423 | #if defined(WASMER_COMPILER_ENABLED) 1424 | F64x2Floor, 1425 | #endif 1426 | #if defined(WASMER_COMPILER_ENABLED) 1427 | F64x2Trunc, 1428 | #endif 1429 | #if defined(WASMER_COMPILER_ENABLED) 1430 | F64x2Nearest, 1431 | #endif 1432 | #if defined(WASMER_COMPILER_ENABLED) 1433 | F32x4Abs, 1434 | #endif 1435 | #if defined(WASMER_COMPILER_ENABLED) 1436 | F32x4Neg, 1437 | #endif 1438 | #if defined(WASMER_COMPILER_ENABLED) 1439 | F32x4Sqrt, 1440 | #endif 1441 | #if defined(WASMER_COMPILER_ENABLED) 1442 | F32x4Add, 1443 | #endif 1444 | #if defined(WASMER_COMPILER_ENABLED) 1445 | F32x4Sub, 1446 | #endif 1447 | #if defined(WASMER_COMPILER_ENABLED) 1448 | F32x4Mul, 1449 | #endif 1450 | #if defined(WASMER_COMPILER_ENABLED) 1451 | F32x4Div, 1452 | #endif 1453 | #if defined(WASMER_COMPILER_ENABLED) 1454 | F32x4Min, 1455 | #endif 1456 | #if defined(WASMER_COMPILER_ENABLED) 1457 | F32x4Max, 1458 | #endif 1459 | #if defined(WASMER_COMPILER_ENABLED) 1460 | F32x4PMin, 1461 | #endif 1462 | #if defined(WASMER_COMPILER_ENABLED) 1463 | F32x4PMax, 1464 | #endif 1465 | #if defined(WASMER_COMPILER_ENABLED) 1466 | F64x2Abs, 1467 | #endif 1468 | #if defined(WASMER_COMPILER_ENABLED) 1469 | F64x2Neg, 1470 | #endif 1471 | #if defined(WASMER_COMPILER_ENABLED) 1472 | F64x2Sqrt, 1473 | #endif 1474 | #if defined(WASMER_COMPILER_ENABLED) 1475 | F64x2Add, 1476 | #endif 1477 | #if defined(WASMER_COMPILER_ENABLED) 1478 | F64x2Sub, 1479 | #endif 1480 | #if defined(WASMER_COMPILER_ENABLED) 1481 | F64x2Mul, 1482 | #endif 1483 | #if defined(WASMER_COMPILER_ENABLED) 1484 | F64x2Div, 1485 | #endif 1486 | #if defined(WASMER_COMPILER_ENABLED) 1487 | F64x2Min, 1488 | #endif 1489 | #if defined(WASMER_COMPILER_ENABLED) 1490 | F64x2Max, 1491 | #endif 1492 | #if defined(WASMER_COMPILER_ENABLED) 1493 | F64x2PMin, 1494 | #endif 1495 | #if defined(WASMER_COMPILER_ENABLED) 1496 | F64x2PMax, 1497 | #endif 1498 | #if defined(WASMER_COMPILER_ENABLED) 1499 | I32x4TruncSatF32x4S, 1500 | #endif 1501 | #if defined(WASMER_COMPILER_ENABLED) 1502 | I32x4TruncSatF32x4U, 1503 | #endif 1504 | #if defined(WASMER_COMPILER_ENABLED) 1505 | F32x4ConvertI32x4S, 1506 | #endif 1507 | #if defined(WASMER_COMPILER_ENABLED) 1508 | F32x4ConvertI32x4U, 1509 | #endif 1510 | #if defined(WASMER_COMPILER_ENABLED) 1511 | I8x16Swizzle, 1512 | #endif 1513 | #if defined(WASMER_COMPILER_ENABLED) 1514 | I8x16Shuffle, 1515 | #endif 1516 | #if defined(WASMER_COMPILER_ENABLED) 1517 | V128Load8Splat, 1518 | #endif 1519 | #if defined(WASMER_COMPILER_ENABLED) 1520 | V128Load16Splat, 1521 | #endif 1522 | #if defined(WASMER_COMPILER_ENABLED) 1523 | V128Load32Splat, 1524 | #endif 1525 | #if defined(WASMER_COMPILER_ENABLED) 1526 | V128Load32Zero, 1527 | #endif 1528 | #if defined(WASMER_COMPILER_ENABLED) 1529 | V128Load64Splat, 1530 | #endif 1531 | #if defined(WASMER_COMPILER_ENABLED) 1532 | V128Load64Zero, 1533 | #endif 1534 | #if defined(WASMER_COMPILER_ENABLED) 1535 | I8x16NarrowI16x8S, 1536 | #endif 1537 | #if defined(WASMER_COMPILER_ENABLED) 1538 | I8x16NarrowI16x8U, 1539 | #endif 1540 | #if defined(WASMER_COMPILER_ENABLED) 1541 | I16x8NarrowI32x4S, 1542 | #endif 1543 | #if defined(WASMER_COMPILER_ENABLED) 1544 | I16x8NarrowI32x4U, 1545 | #endif 1546 | #if defined(WASMER_COMPILER_ENABLED) 1547 | I16x8ExtendLowI8x16S, 1548 | #endif 1549 | #if defined(WASMER_COMPILER_ENABLED) 1550 | I16x8ExtendHighI8x16S, 1551 | #endif 1552 | #if defined(WASMER_COMPILER_ENABLED) 1553 | I16x8ExtendLowI8x16U, 1554 | #endif 1555 | #if defined(WASMER_COMPILER_ENABLED) 1556 | I16x8ExtendHighI8x16U, 1557 | #endif 1558 | #if defined(WASMER_COMPILER_ENABLED) 1559 | I32x4ExtendLowI16x8S, 1560 | #endif 1561 | #if defined(WASMER_COMPILER_ENABLED) 1562 | I32x4ExtendHighI16x8S, 1563 | #endif 1564 | #if defined(WASMER_COMPILER_ENABLED) 1565 | I32x4ExtendLowI16x8U, 1566 | #endif 1567 | #if defined(WASMER_COMPILER_ENABLED) 1568 | I32x4ExtendHighI16x8U, 1569 | #endif 1570 | #if defined(WASMER_COMPILER_ENABLED) 1571 | I64x2ExtendLowI32x4S, 1572 | #endif 1573 | #if defined(WASMER_COMPILER_ENABLED) 1574 | I64x2ExtendHighI32x4S, 1575 | #endif 1576 | #if defined(WASMER_COMPILER_ENABLED) 1577 | I64x2ExtendLowI32x4U, 1578 | #endif 1579 | #if defined(WASMER_COMPILER_ENABLED) 1580 | I64x2ExtendHighI32x4U, 1581 | #endif 1582 | #if defined(WASMER_COMPILER_ENABLED) 1583 | I16x8ExtMulLowI8x16S, 1584 | #endif 1585 | #if defined(WASMER_COMPILER_ENABLED) 1586 | I16x8ExtMulHighI8x16S, 1587 | #endif 1588 | #if defined(WASMER_COMPILER_ENABLED) 1589 | I16x8ExtMulLowI8x16U, 1590 | #endif 1591 | #if defined(WASMER_COMPILER_ENABLED) 1592 | I16x8ExtMulHighI8x16U, 1593 | #endif 1594 | #if defined(WASMER_COMPILER_ENABLED) 1595 | I32x4ExtMulLowI16x8S, 1596 | #endif 1597 | #if defined(WASMER_COMPILER_ENABLED) 1598 | I32x4ExtMulHighI16x8S, 1599 | #endif 1600 | #if defined(WASMER_COMPILER_ENABLED) 1601 | I32x4ExtMulLowI16x8U, 1602 | #endif 1603 | #if defined(WASMER_COMPILER_ENABLED) 1604 | I32x4ExtMulHighI16x8U, 1605 | #endif 1606 | #if defined(WASMER_COMPILER_ENABLED) 1607 | I64x2ExtMulLowI32x4S, 1608 | #endif 1609 | #if defined(WASMER_COMPILER_ENABLED) 1610 | I64x2ExtMulHighI32x4S, 1611 | #endif 1612 | #if defined(WASMER_COMPILER_ENABLED) 1613 | I64x2ExtMulLowI32x4U, 1614 | #endif 1615 | #if defined(WASMER_COMPILER_ENABLED) 1616 | I64x2ExtMulHighI32x4U, 1617 | #endif 1618 | #if defined(WASMER_COMPILER_ENABLED) 1619 | V128Load8x8S, 1620 | #endif 1621 | #if defined(WASMER_COMPILER_ENABLED) 1622 | V128Load8x8U, 1623 | #endif 1624 | #if defined(WASMER_COMPILER_ENABLED) 1625 | V128Load16x4S, 1626 | #endif 1627 | #if defined(WASMER_COMPILER_ENABLED) 1628 | V128Load16x4U, 1629 | #endif 1630 | #if defined(WASMER_COMPILER_ENABLED) 1631 | V128Load32x2S, 1632 | #endif 1633 | #if defined(WASMER_COMPILER_ENABLED) 1634 | V128Load32x2U, 1635 | #endif 1636 | #if defined(WASMER_COMPILER_ENABLED) 1637 | V128Load8Lane, 1638 | #endif 1639 | #if defined(WASMER_COMPILER_ENABLED) 1640 | V128Load16Lane, 1641 | #endif 1642 | #if defined(WASMER_COMPILER_ENABLED) 1643 | V128Load32Lane, 1644 | #endif 1645 | #if defined(WASMER_COMPILER_ENABLED) 1646 | V128Load64Lane, 1647 | #endif 1648 | #if defined(WASMER_COMPILER_ENABLED) 1649 | V128Store8Lane, 1650 | #endif 1651 | #if defined(WASMER_COMPILER_ENABLED) 1652 | V128Store16Lane, 1653 | #endif 1654 | #if defined(WASMER_COMPILER_ENABLED) 1655 | V128Store32Lane, 1656 | #endif 1657 | #if defined(WASMER_COMPILER_ENABLED) 1658 | V128Store64Lane, 1659 | #endif 1660 | #if defined(WASMER_COMPILER_ENABLED) 1661 | I8x16RoundingAverageU, 1662 | #endif 1663 | #if defined(WASMER_COMPILER_ENABLED) 1664 | I16x8RoundingAverageU, 1665 | #endif 1666 | #if defined(WASMER_COMPILER_ENABLED) 1667 | I16x8Q15MulrSatS, 1668 | #endif 1669 | #if defined(WASMER_COMPILER_ENABLED) 1670 | F32x4DemoteF64x2Zero, 1671 | #endif 1672 | #if defined(WASMER_COMPILER_ENABLED) 1673 | F64x2PromoteLowF32x4, 1674 | #endif 1675 | #if defined(WASMER_COMPILER_ENABLED) 1676 | F64x2ConvertLowI32x4S, 1677 | #endif 1678 | #if defined(WASMER_COMPILER_ENABLED) 1679 | F64x2ConvertLowI32x4U, 1680 | #endif 1681 | #if defined(WASMER_COMPILER_ENABLED) 1682 | I32x4TruncSatF64x2SZero, 1683 | #endif 1684 | #if defined(WASMER_COMPILER_ENABLED) 1685 | I32x4TruncSatF64x2UZero, 1686 | #endif 1687 | #if defined(WASMER_COMPILER_ENABLED) 1688 | I8x16RelaxedSwizzle, 1689 | #endif 1690 | #if defined(WASMER_COMPILER_ENABLED) 1691 | I32x4RelaxedTruncSatF32x4S, 1692 | #endif 1693 | #if defined(WASMER_COMPILER_ENABLED) 1694 | I32x4RelaxedTruncSatF32x4U, 1695 | #endif 1696 | #if defined(WASMER_COMPILER_ENABLED) 1697 | I32x4RelaxedTruncSatF64x2SZero, 1698 | #endif 1699 | #if defined(WASMER_COMPILER_ENABLED) 1700 | I32x4RelaxedTruncSatF64x2UZero, 1701 | #endif 1702 | #if defined(WASMER_COMPILER_ENABLED) 1703 | F32x4Fma, 1704 | #endif 1705 | #if defined(WASMER_COMPILER_ENABLED) 1706 | F32x4Fms, 1707 | #endif 1708 | #if defined(WASMER_COMPILER_ENABLED) 1709 | F64x2Fma, 1710 | #endif 1711 | #if defined(WASMER_COMPILER_ENABLED) 1712 | F64x2Fms, 1713 | #endif 1714 | #if defined(WASMER_COMPILER_ENABLED) 1715 | I8x16LaneSelect, 1716 | #endif 1717 | #if defined(WASMER_COMPILER_ENABLED) 1718 | I16x8LaneSelect, 1719 | #endif 1720 | #if defined(WASMER_COMPILER_ENABLED) 1721 | I32x4LaneSelect, 1722 | #endif 1723 | #if defined(WASMER_COMPILER_ENABLED) 1724 | I64x2LaneSelect, 1725 | #endif 1726 | #if defined(WASMER_COMPILER_ENABLED) 1727 | F32x4RelaxedMin, 1728 | #endif 1729 | #if defined(WASMER_COMPILER_ENABLED) 1730 | F32x4RelaxedMax, 1731 | #endif 1732 | #if defined(WASMER_COMPILER_ENABLED) 1733 | F64x2RelaxedMin, 1734 | #endif 1735 | #if defined(WASMER_COMPILER_ENABLED) 1736 | F64x2RelaxedMax, 1737 | #endif 1738 | } wasmer_parser_operator_t; 1739 | #endif 1740 | 1741 | typedef struct Arc_Mutex_WasiPipeDataWithDestructor Arc_Mutex_WasiPipeDataWithDestructor; 1742 | 1743 | #if defined(WASMER_WASI_ENABLED) 1744 | typedef struct wasi_config_t wasi_config_t; 1745 | #endif 1746 | 1747 | #if defined(WASMER_WASI_ENABLED) 1748 | typedef struct wasi_env_t wasi_env_t; 1749 | #endif 1750 | 1751 | typedef struct wasmer_cpu_features_t wasmer_cpu_features_t; 1752 | 1753 | typedef struct wasmer_features_t wasmer_features_t; 1754 | 1755 | typedef struct wasmer_metering_t wasmer_metering_t; 1756 | 1757 | typedef struct wasmer_middleware_t wasmer_middleware_t; 1758 | 1759 | #if defined(WASMER_WASI_ENABLED) 1760 | typedef struct wasmer_named_extern_t wasmer_named_extern_t; 1761 | #endif 1762 | 1763 | typedef struct wasmer_target_t wasmer_target_t; 1764 | 1765 | typedef struct wasmer_triple_t wasmer_triple_t; 1766 | 1767 | #if defined(WASMER_WASI_ENABLED) 1768 | typedef int64_t (*WasiConsoleIoReadCallback)(const void*, char*, uintptr_t); 1769 | #endif 1770 | 1771 | #if defined(WASMER_WASI_ENABLED) 1772 | typedef int64_t (*WasiConsoleIoWriteCallback)(const void*, const char*, uintptr_t, bool); 1773 | #endif 1774 | 1775 | #if defined(WASMER_WASI_ENABLED) 1776 | typedef int64_t (*WasiConsoleIoSeekCallback)(const void*, char, int64_t); 1777 | #endif 1778 | 1779 | #if defined(WASMER_WASI_ENABLED) 1780 | typedef struct wasi_pipe_t { 1781 | WasiConsoleIoReadCallback read; 1782 | WasiConsoleIoWriteCallback write; 1783 | WasiConsoleIoSeekCallback seek; 1784 | struct Arc_Mutex_WasiPipeDataWithDestructor *data; 1785 | } wasi_pipe_t; 1786 | #endif 1787 | 1788 | #if defined(WASMER_WASI_ENABLED) 1789 | typedef struct wasmer_named_extern_vec_t { 1790 | uintptr_t size; 1791 | struct wasmer_named_extern_t **data; 1792 | } wasmer_named_extern_vec_t; 1793 | #endif 1794 | 1795 | #if defined(WASMER_WASI_ENABLED) 1796 | typedef int64_t (*WasiConsoleIoEnvDestructor)(const void*); 1797 | #endif 1798 | 1799 | typedef struct FunctionCEnv { 1800 | void *inner; 1801 | } FunctionCEnv; 1802 | 1803 | typedef struct wasmer_funcenv_t { 1804 | struct FunctionCEnv inner; 1805 | } wasmer_funcenv_t; 1806 | 1807 | typedef uint64_t (*wasmer_metering_cost_function_t)(enum wasmer_parser_operator_t wasm_operator); 1808 | 1809 | #ifdef __cplusplus 1810 | extern "C" { 1811 | #endif // __cplusplus 1812 | 1813 | #if defined(WASMER_WASI_ENABLED) 1814 | void wasi_config_arg(struct wasi_config_t *wasi_config, const char *arg); 1815 | #endif 1816 | 1817 | #if defined(WASMER_WASI_ENABLED) 1818 | void wasi_config_capture_stderr(struct wasi_config_t *wasi_config); 1819 | #endif 1820 | 1821 | #if defined(WASMER_WASI_ENABLED) 1822 | void wasi_config_capture_stdin(struct wasi_config_t *wasi_config); 1823 | #endif 1824 | 1825 | #if defined(WASMER_WASI_ENABLED) 1826 | void wasi_config_capture_stdout(struct wasi_config_t *wasi_config); 1827 | #endif 1828 | 1829 | #if defined(WASMER_WASI_ENABLED) 1830 | void wasi_config_env(struct wasi_config_t *wasi_config, const char *key, const char *value); 1831 | #endif 1832 | 1833 | #if defined(WASMER_WASI_ENABLED) 1834 | void wasi_config_inherit_stderr(struct wasi_config_t *wasi_config); 1835 | #endif 1836 | 1837 | #if defined(WASMER_WASI_ENABLED) 1838 | void wasi_config_inherit_stdin(struct wasi_config_t *wasi_config); 1839 | #endif 1840 | 1841 | #if defined(WASMER_WASI_ENABLED) 1842 | void wasi_config_inherit_stdout(struct wasi_config_t *wasi_config); 1843 | #endif 1844 | 1845 | #if defined(WASMER_WASI_ENABLED) 1846 | bool wasi_config_mapdir(struct wasi_config_t *wasi_config, const char *alias, const char *dir); 1847 | #endif 1848 | 1849 | #if defined(WASMER_WASI_ENABLED) 1850 | struct wasi_config_t *wasi_config_new(const char *program_name); 1851 | #endif 1852 | 1853 | #if defined(WASMER_WASI_ENABLED) 1854 | void wasi_config_overwrite_stderr(struct wasi_config_t *config_overwrite, 1855 | struct wasi_pipe_t *stderr_overwrite); 1856 | #endif 1857 | 1858 | #if defined(WASMER_WASI_ENABLED) 1859 | void wasi_config_overwrite_stdin(struct wasi_config_t *config_overwrite, 1860 | struct wasi_pipe_t *stdin_overwrite); 1861 | #endif 1862 | 1863 | #if defined(WASMER_WASI_ENABLED) 1864 | void wasi_config_overwrite_stdout(struct wasi_config_t *config_overwrite, 1865 | struct wasi_pipe_t *stdout_overwrite); 1866 | #endif 1867 | 1868 | #if defined(WASMER_WASI_ENABLED) 1869 | bool wasi_config_preopen_dir(struct wasi_config_t *wasi_config, const char *dir); 1870 | #endif 1871 | 1872 | #if defined(WASMER_WASI_ENABLED) 1873 | void wasi_env_delete(struct wasi_env_t *_state); 1874 | #endif 1875 | 1876 | #if defined(WASMER_WASI_ENABLED) 1877 | bool wasi_env_initialize_instance(struct wasi_env_t *wasi_env, 1878 | wasm_store_t *store, 1879 | wasm_instance_t *instance); 1880 | #endif 1881 | 1882 | #if defined(WASMER_WASI_ENABLED) 1883 | struct wasi_env_t *wasi_env_new(wasm_store_t *store, struct wasi_config_t *wasi_config); 1884 | #endif 1885 | 1886 | #if defined(WASMER_WASI_ENABLED) 1887 | intptr_t wasi_env_read_stderr(struct wasi_env_t *env, char *buffer, uintptr_t buffer_len); 1888 | #endif 1889 | 1890 | #if defined(WASMER_WASI_ENABLED) 1891 | intptr_t wasi_env_read_stdout(struct wasi_env_t *env, char *buffer, uintptr_t buffer_len); 1892 | #endif 1893 | 1894 | #if defined(WASMER_WASI_ENABLED) 1895 | void wasi_env_set_memory(struct wasi_env_t *env, const wasm_memory_t *memory); 1896 | #endif 1897 | 1898 | #if defined(WASMER_WASI_ENABLED) 1899 | bool wasi_get_imports(const wasm_store_t *_store, 1900 | struct wasi_env_t *wasi_env, 1901 | const wasm_module_t *module, 1902 | wasm_extern_vec_t *imports); 1903 | #endif 1904 | 1905 | #if defined(WASMER_WASI_ENABLED) 1906 | wasm_func_t *wasi_get_start_function(wasm_instance_t *instance); 1907 | #endif 1908 | 1909 | #if defined(WASMER_WASI_ENABLED) 1910 | bool wasi_get_unordered_imports(struct wasi_env_t *wasi_env, 1911 | const wasm_module_t *module, 1912 | struct wasmer_named_extern_vec_t *imports); 1913 | #endif 1914 | 1915 | #if defined(WASMER_WASI_ENABLED) 1916 | enum wasi_version_t wasi_get_wasi_version(const wasm_module_t *module); 1917 | #endif 1918 | 1919 | #if defined(WASMER_WASI_ENABLED) 1920 | bool wasi_pipe_delete(struct wasi_pipe_t *ptr); 1921 | #endif 1922 | 1923 | #if defined(WASMER_WASI_ENABLED) 1924 | void wasi_pipe_delete_str(char *buf); 1925 | #endif 1926 | 1927 | #if defined(WASMER_WASI_ENABLED) 1928 | int64_t wasi_pipe_flush(struct wasi_pipe_t *ptr); 1929 | #endif 1930 | 1931 | #if defined(WASMER_WASI_ENABLED) 1932 | struct wasi_pipe_t *wasi_pipe_new(struct wasi_pipe_t **ptr_user); 1933 | #endif 1934 | 1935 | #if defined(WASMER_WASI_ENABLED) 1936 | struct wasi_pipe_t *wasi_pipe_new_blocking(struct wasi_pipe_t **ptr_user); 1937 | #endif 1938 | 1939 | #if defined(WASMER_WASI_ENABLED) 1940 | struct wasi_pipe_t *wasi_pipe_new_internal(WasiConsoleIoReadCallback read, 1941 | WasiConsoleIoWriteCallback write, 1942 | WasiConsoleIoSeekCallback seek, 1943 | WasiConsoleIoEnvDestructor destructor, 1944 | const void *env_data, 1945 | uintptr_t env_data_len); 1946 | #endif 1947 | 1948 | #if defined(WASMER_WASI_ENABLED) 1949 | struct wasi_pipe_t *wasi_pipe_new_null(void); 1950 | #endif 1951 | 1952 | #if defined(WASMER_WASI_ENABLED) 1953 | int64_t wasi_pipe_read_bytes(const struct wasi_pipe_t *ptr, const char *buf, uintptr_t read); 1954 | #endif 1955 | 1956 | #if defined(WASMER_WASI_ENABLED) 1957 | int64_t wasi_pipe_read_str(const struct wasi_pipe_t *ptr, char **buf); 1958 | #endif 1959 | 1960 | #if defined(WASMER_WASI_ENABLED) 1961 | int64_t wasi_pipe_seek(struct wasi_pipe_t *ptr, char seek_dir, int64_t seek); 1962 | #endif 1963 | 1964 | #if defined(WASMER_WASI_ENABLED) 1965 | int64_t wasi_pipe_write_bytes(struct wasi_pipe_t *ptr, const char *buf, uintptr_t len); 1966 | #endif 1967 | 1968 | #if defined(WASMER_WASI_ENABLED) 1969 | int64_t wasi_pipe_write_str(const struct wasi_pipe_t *ptr, const char *buf); 1970 | #endif 1971 | 1972 | void wasm_config_canonicalize_nans(wasm_config_t *config, bool enable); 1973 | 1974 | void wasm_config_push_middleware(wasm_config_t *config, struct wasmer_middleware_t *middleware); 1975 | 1976 | #if (defined(WASMER_COMPILER_ENABLED) && defined(WASMER_COMPILER_ENABLED)) 1977 | void wasm_config_set_compiler(wasm_config_t *config, enum wasmer_compiler_t compiler); 1978 | #endif 1979 | 1980 | #if defined(WASMER_COMPILER_ENABLED) 1981 | void wasm_config_set_engine(wasm_config_t *config, enum wasmer_engine_t engine); 1982 | #endif 1983 | 1984 | void wasm_config_set_features(wasm_config_t *config, struct wasmer_features_t *features); 1985 | 1986 | void wasm_config_set_target(wasm_config_t *config, struct wasmer_target_t *target); 1987 | 1988 | bool wasmer_cpu_features_add(struct wasmer_cpu_features_t *cpu_features, 1989 | const wasm_name_t *feature); 1990 | 1991 | void wasmer_cpu_features_delete(struct wasmer_cpu_features_t *_cpu_features); 1992 | 1993 | struct wasmer_cpu_features_t *wasmer_cpu_features_new(void); 1994 | 1995 | bool wasmer_features_bulk_memory(struct wasmer_features_t *features, bool enable); 1996 | 1997 | void wasmer_features_delete(struct wasmer_features_t *_features); 1998 | 1999 | bool wasmer_features_memory64(struct wasmer_features_t *features, bool enable); 2000 | 2001 | bool wasmer_features_module_linking(struct wasmer_features_t *features, bool enable); 2002 | 2003 | bool wasmer_features_multi_memory(struct wasmer_features_t *features, bool enable); 2004 | 2005 | bool wasmer_features_multi_value(struct wasmer_features_t *features, bool enable); 2006 | 2007 | struct wasmer_features_t *wasmer_features_new(void); 2008 | 2009 | bool wasmer_features_reference_types(struct wasmer_features_t *features, bool enable); 2010 | 2011 | bool wasmer_features_simd(struct wasmer_features_t *features, bool enable); 2012 | 2013 | bool wasmer_features_tail_call(struct wasmer_features_t *features, bool enable); 2014 | 2015 | bool wasmer_features_threads(struct wasmer_features_t *features, bool enable); 2016 | 2017 | void wasmer_funcenv_delete(struct wasmer_funcenv_t *_funcenv); 2018 | 2019 | struct wasmer_funcenv_t *wasmer_funcenv_new(wasm_store_t *store, void *data); 2020 | 2021 | #if defined(WASMER_COMPILER_ENABLED) 2022 | bool wasmer_is_compiler_available(enum wasmer_compiler_t compiler); 2023 | #endif 2024 | 2025 | bool wasmer_is_engine_available(enum wasmer_engine_t engine); 2026 | 2027 | bool wasmer_is_headless(void); 2028 | 2029 | int wasmer_last_error_length(void); 2030 | 2031 | int wasmer_last_error_message(char *buffer, int length); 2032 | 2033 | struct wasmer_middleware_t *wasmer_metering_as_middleware(struct wasmer_metering_t *metering); 2034 | 2035 | void wasmer_metering_delete(struct wasmer_metering_t *_metering); 2036 | 2037 | uint64_t wasmer_metering_get_remaining_points(wasm_instance_t *instance); 2038 | 2039 | struct wasmer_metering_t *wasmer_metering_new(uint64_t initial_limit, 2040 | wasmer_metering_cost_function_t cost_function); 2041 | 2042 | bool wasmer_metering_points_are_exhausted(wasm_instance_t *instance); 2043 | 2044 | void wasmer_metering_set_remaining_points(wasm_instance_t *instance, uint64_t new_limit); 2045 | 2046 | void wasmer_module_name(const wasm_module_t *module, wasm_name_t *out); 2047 | 2048 | bool wasmer_module_set_name(wasm_module_t *module, const wasm_name_t *name); 2049 | 2050 | #if defined(WASMER_WASI_ENABLED) 2051 | const wasm_name_t *wasmer_named_extern_module(const struct wasmer_named_extern_t *named_extern); 2052 | #endif 2053 | 2054 | #if defined(WASMER_WASI_ENABLED) 2055 | const wasm_name_t *wasmer_named_extern_name(const struct wasmer_named_extern_t *named_extern); 2056 | #endif 2057 | 2058 | #if defined(WASMER_WASI_ENABLED) 2059 | const wasm_extern_t *wasmer_named_extern_unwrap(const struct wasmer_named_extern_t *named_extern); 2060 | #endif 2061 | 2062 | #if defined(WASMER_WASI_ENABLED) 2063 | void wasmer_named_extern_vec_copy(struct wasmer_named_extern_vec_t *out_ptr, 2064 | const struct wasmer_named_extern_vec_t *in_ptr); 2065 | #endif 2066 | 2067 | #if defined(WASMER_WASI_ENABLED) 2068 | void wasmer_named_extern_vec_delete(struct wasmer_named_extern_vec_t *ptr); 2069 | #endif 2070 | 2071 | #if defined(WASMER_WASI_ENABLED) 2072 | void wasmer_named_extern_vec_new(struct wasmer_named_extern_vec_t *out, 2073 | uintptr_t length, 2074 | struct wasmer_named_extern_t *const *init); 2075 | #endif 2076 | 2077 | #if defined(WASMER_WASI_ENABLED) 2078 | void wasmer_named_extern_vec_new_empty(struct wasmer_named_extern_vec_t *out); 2079 | #endif 2080 | 2081 | #if defined(WASMER_WASI_ENABLED) 2082 | void wasmer_named_extern_vec_new_uninitialized(struct wasmer_named_extern_vec_t *out, 2083 | uintptr_t length); 2084 | #endif 2085 | 2086 | void wasmer_target_delete(struct wasmer_target_t *_target); 2087 | 2088 | struct wasmer_target_t *wasmer_target_new(struct wasmer_triple_t *triple, 2089 | struct wasmer_cpu_features_t *cpu_features); 2090 | 2091 | void wasmer_triple_delete(struct wasmer_triple_t *_triple); 2092 | 2093 | struct wasmer_triple_t *wasmer_triple_new(const wasm_name_t *triple); 2094 | 2095 | struct wasmer_triple_t *wasmer_triple_new_from_host(void); 2096 | 2097 | const char *wasmer_version(void); 2098 | 2099 | uint8_t wasmer_version_major(void); 2100 | 2101 | uint8_t wasmer_version_minor(void); 2102 | 2103 | uint8_t wasmer_version_patch(void); 2104 | 2105 | const char *wasmer_version_pre(void); 2106 | 2107 | void wat2wasm(const wasm_byte_vec_t *wat, wasm_byte_vec_t *out); 2108 | 2109 | #ifdef __cplusplus 2110 | } // extern "C" 2111 | #endif // __cplusplus 2112 | 2113 | #endif /* WASMER_H */ 2114 | -------------------------------------------------------------------------------- /wasmer/include/wasmer_wasm.h: -------------------------------------------------------------------------------- 1 | #include "wasmer.h" 2 | 3 | #pragma message "The wasmer_wasm.h header file is being deprecated, please use wasmer.h instead." 4 | -------------------------------------------------------------------------------- /wasmer/wasi.v: -------------------------------------------------------------------------------- 1 | module wasmer 2 | 3 | pub fn (m &Module) wasi_version() WasiVersion { 4 | return wasi_version_from_int(C.wasi_get_wasi_version(m.inner)) 5 | } 6 | 7 | pub struct WasiConfig { 8 | pub: 9 | config &C.wasi_config_t 10 | } 11 | 12 | pub fn (c WasiConfig) arg(arg string) { 13 | C.wasi_config_arg(c.config, arg.str) 14 | } 15 | 16 | pub fn (c WasiConfig) capture_stderr() { 17 | C.wasi_config_capture_stderr(c.config) 18 | } 19 | 20 | pub fn (c WasiConfig) capture_stdout() { 21 | C.wasi_config_capture_stdout(c.config) 22 | } 23 | 24 | pub fn (c WasiConfig) env(key string, value string) { 25 | C.wasi_config_env(c.config, key.str, value.str) 26 | } 27 | 28 | pub fn (c WasiConfig) inherit_stdin() { 29 | C.wasi_config_inherit_stdin(c.config) 30 | } 31 | 32 | pub fn (c WasiConfig) inherit_stdout() { 33 | C.wasi_config_inherit_stdout(c.config) 34 | } 35 | 36 | pub fn (c WasiConfig) inherit_stderr() { 37 | C.wasi_config_inherit_stderr(c.config) 38 | } 39 | 40 | pub fn (c WasiConfig) mapdir(host_dir string, guest_dir string) { 41 | C.wasi_config_mapdir(c.config, host_dir.str, guest_dir.str) 42 | } 43 | 44 | pub fn (c WasiConfig) preopen_dir(dir string) { 45 | C.wasi_config_preopen_dir(c.config, dir.str) 46 | } 47 | 48 | pub fn wasi_config(program_name string) WasiConfig { 49 | return WasiConfig{ 50 | config: C.wasi_config_new(program_name.str) 51 | } 52 | } 53 | 54 | struct NamedExternVec { 55 | mut: 56 | inner C.wasmer_named_extern_vec_t 57 | } 58 | 59 | pub struct NamedExtern { 60 | mut: 61 | inner &C.wasmer_named_extern_t 62 | } 63 | 64 | fn named_extern_vec(x []NamedExtern) NamedExternVec { 65 | mut b := C.wasmer_named_extern_vec_t{} 66 | C.wasmer_named_extern_vec_new(&b, usize(x.len), x.data) 67 | return NamedExternVec{b} 68 | } 69 | 70 | fn (v NamedExternVec) at(i int) NamedExtern { 71 | unsafe { 72 | return NamedExtern{v.inner.data[i]} 73 | } 74 | } 75 | 76 | fn (v NamedExternVec) set_at(i int, val NamedExtern) { 77 | unsafe { 78 | v.inner.data[i] = val.inner 79 | } 80 | } 81 | 82 | fn (v NamedExternVec) delete() { 83 | C.wasmer_named_extern_vec_delete(&v.inner) 84 | } 85 | 86 | fn (v NamedExternVec) copy() NamedExternVec { 87 | mut new := NamedExternVec{} 88 | C.wasmer_named_extern_vec_copy(&v.inner, &new.inner) 89 | return new 90 | } 91 | 92 | pub struct WasiEnv { 93 | pub: 94 | env &C.wasi_env_t 95 | } 96 | 97 | pub fn wasi_env(store Store, config WasiConfig) ?WasiEnv { 98 | p := C.wasi_env_new(store.inner, config.config) 99 | 100 | if p == unsafe { nil } { 101 | return none 102 | } 103 | return WasiEnv{ 104 | env: p 105 | } 106 | } 107 | 108 | /// Reads the stderr of the WASI process into `buf`. Returns 109 | /// number of bytes successfully read, returns -1 if read failed 110 | pub fn (c WasiEnv) read_stderr(mut buf []u8) isize { 111 | return C.wasi_env_read_stderr(c.env, buf.data, buf.len) 112 | } 113 | 114 | /// Reads the stdout of the WASI process into `buf`. Returns 115 | /// number of bytes successfully read, returns -1 if read failed 116 | pub fn (c WasiEnv) read_stdout(mut buf []u8) isize { 117 | return C.wasi_env_read_stdout(c.env, buf.data, buf.len) 118 | } 119 | 120 | pub fn (c WasiEnv) initialize_instance(store Store, instance Instance) ! { 121 | if !C.wasi_env_initialize_instance(c.env, store.inner, instance.inner) { 122 | return error('Failed to initialize WASI instance') 123 | } 124 | } 125 | 126 | pub fn (c WasiEnv) delete() { 127 | C.wasi_env_delete(c.env) 128 | } 129 | 130 | pub fn (s Store) get_imports(mod &Module, env WasiEnv) ?[]Extern { 131 | mut raw := ExternVec{} 132 | 133 | result := C.wasi_get_imports(s.inner, env.env, mod.inner, &raw.inner) 134 | if !result { 135 | return none 136 | } 137 | 138 | mut result_vec := []Extern{} 139 | 140 | for i in 0 .. raw.inner.size { 141 | result_vec << raw.at(int(i)) 142 | } 143 | return result_vec 144 | } 145 | 146 | pub fn (i Instance) get_start_function() ?Func { 147 | f := C.wasi_get_start_function(i.inner) 148 | if f == unsafe { nil } { 149 | return none 150 | } 151 | return Func{f} 152 | } 153 | 154 | pub fn (n NamedExtern) mod() string { 155 | bvec := C.wasmer_named_extern_module(n.inner) 156 | return unsafe { 157 | bvec.data.vbytes(int(bvec.size)).bytestr() 158 | } 159 | } 160 | 161 | pub fn (n NamedExtern) name() string { 162 | bvec := C.wasmer_named_extern_name(n.inner) 163 | return unsafe { 164 | bvec.data.vbytes(int(bvec.size)).bytestr() 165 | } 166 | } 167 | 168 | pub fn (n NamedExtern) unwrap() Extern { 169 | return Extern{C.wasmer_named_extern_unwrap(n.inner)} 170 | } 171 | -------------------------------------------------------------------------------- /wasmer/wasi_sys.v: -------------------------------------------------------------------------------- 1 | module wasmer 2 | 3 | #flag -L $env('WASMER_DIR')/lib 4 | #flag -lwasmer 5 | #flag -I @VMODROOT 6 | #flag -I $env('WASMER_DIR')/include 7 | #flag -rpath $env('WASMER_DIR')/lib 8 | #include "wasmer/include/wasmer.h" 9 | 10 | pub enum WasiVersion { 11 | invalid 12 | latest 13 | snapshot0 14 | snapshot1 15 | } 16 | 17 | pub fn wasi_version_from_int(v int) WasiVersion { 18 | res := match v { 19 | -1 { 20 | WasiVersion.invalid 21 | } 22 | 0 { 23 | WasiVersion.latest 24 | } 25 | 1 { 26 | WasiVersion.snapshot0 27 | } 28 | 2 { 29 | WasiVersion.snapshot1 30 | } 31 | else { 32 | WasiVersion.invalid 33 | } 34 | } 35 | 36 | return res 37 | } 38 | 39 | pub fn wasi_version_to_int(v WasiVersion) int { 40 | res := match v { 41 | .invalid { 42 | -1 43 | } 44 | .latest { 45 | 0 46 | } 47 | .snapshot0 { 48 | 1 49 | } 50 | .snapshot1 { 51 | 2 52 | } 53 | } 54 | 55 | return res 56 | } 57 | 58 | pub struct C.wasi_config_t {} 59 | 60 | pub struct C.wasi_env_t {} 61 | 62 | pub struct C.wasmer_named_extern_t {} 63 | 64 | pub struct C.wasmer_named_extern_vec_t { 65 | pub mut: 66 | size usize 67 | data &&C.wasmer_named_extern_t = unsafe { 0 } 68 | } 69 | 70 | pub fn C.wasi_config_arg(config &C.wasi_config_t, arg &char) 71 | pub fn C.wasi_config_capture_stderr(config &C.wasi_config_t) 72 | pub fn C.wasi_config_capture_stdout(config &C.wasi_config_t) 73 | pub fn C.wasi_config_env(config &C.wasi_config_t, key &char, value &char) 74 | pub fn C.wasi_config_inherit_stderr(config &C.wasi_config_t) 75 | pub fn C.wasi_config_inherit_stdin(config &C.wasi_config_t) 76 | pub fn C.wasi_config_inherit_stdout(config &C.wasi_config_t) 77 | pub fn C.wasi_config_mapdir(config &C.wasi_config_t, alias &char, dir &char) 78 | pub fn C.wasi_config_new(program_name &char) &C.wasi_config_t 79 | pub fn C.wasi_config_preopen_dir(config &C.wasi_config_t, dir &char) 80 | pub fn C.wasi_env_delete(env &C.wasi_env_t) 81 | pub fn C.wasi_env_new(store &C.wasm_store_t, config &C.wasi_config_t) &C.wasi_env_t 82 | pub fn C.wasi_env_read_stderr(env &C.wasi_env_t, buf &byte, buf_len usize) isize 83 | pub fn C.wasi_env_read_stdout(env &C.wasi_env_t, buf &byte, buf_len usize) isize 84 | pub fn C.wasi_env_initialize_instance(env &C.wasi_env_t, store &C.wasm_store_t, instance &C.wasm_instance_t) bool 85 | pub fn C.wasi_get_imports(store &C.wasm_store_t, wasi_env &C.wasi_env_t, mod &C.wasm_module_t, imports &C.wasm_extern_vec_t) bool 86 | pub fn C.wasi_get_start_function(instance &C.wasm_instance_t) &C.wasm_func_t 87 | pub fn C.wasi_get_unordered_imports(store &C.wasm_store_t, mod &C.wasm_module_t, wasi_env &C.wasi_env_t, imports &C.wasmer_named_extern_t) bool 88 | pub fn C.wasi_get_wasi_version(mod &C.wasm_module_t) int 89 | 90 | pub fn C.wasmer_named_extern_module(named_extern &C.wasmer_named_extern_t) &C.wasm_byte_vec_t 91 | pub fn C.wasmer_named_extern_name(named_extern &C.wasmer_named_extern_t) &C.wasm_byte_vec_t 92 | pub fn C.wasmer_named_extern_unwrap(named_extern &C.wasmer_named_extern_t) &C.wasm_extern_t 93 | pub fn C.wasmer_named_extern_vec_copy(dst &C.wasmer_named_extern_vec_t, src &C.wasmer_named_extern_vec_t) 94 | pub fn C.wasmer_named_extern_vec_delete(vec &C.wasmer_named_extern_vec_t) 95 | pub fn C.wasmer_named_extern_vec_new(out &C.wasmer_named_extern_vec_t, len usize, init &&C.wasmer_named_extern_t) 96 | pub fn C.wasmer_named_extern_vec_new_empty(out &C.wasmer_named_extern_vec_t) 97 | pub fn C.wasmer_named_extern_vec_new_uninitialized(out &C.wasmer_named_extern_vec_t, len usize) 98 | -------------------------------------------------------------------------------- /wasmer/wasmer.v: -------------------------------------------------------------------------------- 1 | module wasmer 2 | 3 | import strings 4 | 5 | // An engine drives the compilation and the runtime. 6 | pub struct Engine { 7 | inner &C.wasm_engine_t 8 | } 9 | 10 | struct ValVec { 11 | mut: 12 | inner C.wasm_val_vec_t 13 | } 14 | 15 | struct ByteVec { 16 | mut: 17 | inner C.wasm_byte_vec_t 18 | } 19 | 20 | struct ExternVec { 21 | mut: 22 | inner C.wasm_extern_vec_t 23 | } 24 | 25 | pub struct Val { 26 | pub mut: 27 | inner C.wasm_val_t 28 | } 29 | 30 | pub struct Extern { 31 | inner &C.wasm_extern_t 32 | } 33 | 34 | pub struct Func { 35 | inner &C.wasm_func_t 36 | } 37 | 38 | pub struct Global { 39 | inner &C.wasm_global_t 40 | } 41 | 42 | pub struct Memory { 43 | inner &C.wasm_memory_t 44 | } 45 | 46 | pub struct Table { 47 | inner &C.wasm_table_t 48 | } 49 | 50 | pub struct ValType { 51 | inner &C.wasm_valtype_t 52 | } 53 | 54 | pub struct ExternType { 55 | inner &C.wasm_externtype_t 56 | } 57 | 58 | pub struct FuncType { 59 | inner &C.wasm_functype_t 60 | } 61 | 62 | pub struct GlobalType { 63 | inner &C.wasm_globaltype_t 64 | } 65 | 66 | pub struct MemoryType { 67 | inner &C.wasm_memorytype_t 68 | } 69 | 70 | pub struct TableType { 71 | inner &C.wasm_tabletype_t 72 | } 73 | 74 | pub struct ExportType { 75 | inner &C.wasm_exporttype_t 76 | } 77 | 78 | // A WebAssembly module contains stateless WebAssembly code that has already been compiled and can be instantiated multiple times. 79 | pub struct Module { 80 | inner &C.wasm_module_t 81 | } 82 | 83 | // A WebAssembly instance is a stateful, executable instance of a WebAssembly module. 84 | // 85 | // Instance objects contain all the exported WebAssembly functions, memories, tables and globals that allow interacting with WebAssembly. 86 | pub struct Instance { 87 | inner &C.wasm_instance_t 88 | } 89 | 90 | // A trap represents an error which stores trace message with backtrace 91 | pub struct Trap { 92 | inner &C.wasm_trap_t = unsafe { 0 } 93 | } 94 | 95 | // A configuration holds the compiler and the engine used by the store. 96 | pub struct Config { 97 | inner &C.wasm_config_t 98 | } 99 | 100 | // A store represents all global state that can be manipulated by WebAssembly programs. It consists of the runtime representation of all instances of functions, tables, memories, and globals that have been allocated during the lifetime of the abstract machine. 101 | // 102 | // The store holds the engine (that is —amonst many things— used to compile the Wasm bytes into a valid module artifact), in addition to extra private types. 103 | pub struct Store { 104 | inner &C.wasm_store_t 105 | } 106 | 107 | pub struct Frame { 108 | inner &C.wasm_frame_t 109 | } 110 | 111 | pub fn val_i32(v int) Val { 112 | return Val{wasm_i32_val(v)} 113 | } 114 | 115 | pub fn val_i64(v i64) Val { 116 | return Val{wasm_i64_val(v)} 117 | } 118 | 119 | pub fn val_f64(v f64) Val { 120 | return Val{wasm_f64_val(v)} 121 | } 122 | 123 | pub fn val_f32(v f32) Val { 124 | return Val{wasm_f32_val(v)} 125 | } 126 | 127 | pub fn val_ref(v voidptr) Val { 128 | return Val{wasm_ref_val(v)} 129 | } 130 | 131 | pub fn val_null() Val { 132 | return val_ref(unsafe { nil }) 133 | } 134 | 135 | pub fn (val Val) kind() WasmValKind { 136 | return val.inner.kind 137 | } 138 | 139 | pub fn (val Val) i32() i32 { 140 | return unsafe { 141 | val.inner.of.i32 142 | } 143 | } 144 | 145 | pub fn (val Val) i64() i64 { 146 | return unsafe { 147 | val.inner.of.i64 148 | } 149 | } 150 | 151 | pub fn (val Val) f32() f32 { 152 | return unsafe { 153 | val.inner.of.f32 154 | } 155 | } 156 | 157 | pub fn (val Val) f64() f64 { 158 | return unsafe { 159 | val.inner.of.f64 160 | } 161 | } 162 | 163 | pub fn (val Val) ref() voidptr { 164 | return unsafe { 165 | val.inner.of.ref 166 | } 167 | } 168 | 169 | pub fn (val Val) str() string { 170 | unsafe { 171 | match val.inner.kind { 172 | .wasm_i32 { 173 | return '$val.inner.of.i32' 174 | } 175 | .wasm_i64 { 176 | return '$val.inner.of.i64' 177 | } 178 | .wasm_f64 { 179 | return '$val.inner.of.f64' 180 | } 181 | .wasm_f32 { 182 | return '$val.inner.of.f32' 183 | } 184 | .wasm_anyref { 185 | return '${voidptr(val.inner.of.ref)}' 186 | } 187 | else { 188 | return 'unknown value' 189 | } 190 | } 191 | } 192 | } 193 | 194 | pub fn val_vec(x []Val) ValVec { 195 | mut b := C.wasm_val_vec_t{} 196 | C.wasm_val_vec_new(&b, usize(x.len), x.data) 197 | return ValVec{b} 198 | } 199 | 200 | pub fn val_vec_uninitialized(size usize) ValVec { 201 | mut b := C.wasm_val_vec_t{} 202 | C.wasm_val_vec_new_uninitialized(&b, size) 203 | return ValVec{b} 204 | } 205 | 206 | pub fn (v ValVec) at(i int) Val { 207 | unsafe { 208 | return Val{v.inner.data[i]} 209 | } 210 | } 211 | 212 | pub fn (v ValVec) set_at(i int, val Val) { 213 | unsafe { 214 | v.inner.data[i] = val.inner 215 | } 216 | } 217 | 218 | pub fn (v ValVec) delete() { 219 | C.wasm_val_vec_delete(&v.inner) 220 | } 221 | 222 | pub fn (v ValVec) str() string { 223 | mut builder := strings.new_builder(40) 224 | builder.write_string('ValVec{') 225 | for i in 0 .. v.inner.size { 226 | unsafe { 227 | val := Val{v.inner.data[i]} 228 | builder.write_string('$val') 229 | if i != v.inner.size - 1 { 230 | builder.write_string(',') 231 | } 232 | } 233 | } 234 | builder.write_string('}') 235 | return builder.str() 236 | } 237 | 238 | fn byte_vec(x []byte) ByteVec { 239 | mut b := C.wasm_byte_vec_t{} 240 | C.wasm_byte_vec_new(&b, usize(x.len), x.data) 241 | return ByteVec{b} 242 | } 243 | 244 | fn (v ByteVec) at(i int) u8 { 245 | unsafe { 246 | return v.inner.data[i] 247 | } 248 | } 249 | 250 | fn (v ByteVec) set_at(i int, val u8) { 251 | unsafe { 252 | v.inner.data[i] = val 253 | } 254 | } 255 | 256 | fn (v ByteVec) to_string() string { 257 | unsafe { 258 | return v.inner.data.vbytes(int(v.inner.size)).bytestr() 259 | } 260 | } 261 | 262 | fn (v ByteVec) delete() { 263 | C.wasm_byte_vec_delete(&v.inner) 264 | } 265 | 266 | pub fn (v ByteVec) str() string { 267 | mut builder := strings.new_builder(40) 268 | builder.write_string('ByteVec{') 269 | for i in 0 .. v.inner.size { 270 | unsafe { 271 | builder.write_string('${v.inner.data[i]}') 272 | if i != v.inner.size - 1 { 273 | builder.write_string(',') 274 | } 275 | } 276 | } 277 | builder.write_string('}') 278 | return builder.str() 279 | } 280 | 281 | pub fn (f Func) as_extern() Extern { 282 | return Extern{C.wasm_func_as_extern(f.inner)} 283 | } 284 | 285 | // returns the number of parameters that this function takes. 286 | pub fn (f Func) param_arity() usize { 287 | return C.wasm_func_param_arity(f.inner) 288 | } 289 | 290 | // result_arity returns the number of results this function produces. 291 | pub fn (f Func) result_arity() usize { 292 | return C.wasm_func_result_arity(f.inner) 293 | } 294 | 295 | // call invokes function with `args` as arguments and puts function returns to `results` array. Note that 296 | // results array must already be initialized to the size of `Func.result_arity()` so it can hold return values. 297 | pub fn (f Func) call(args []Val, mut results []Val) Trap { 298 | real_args := val_vec(args) 299 | 300 | mut out := val_vec_uninitialized(usize(results.len)) 301 | trap := Trap{C.wasm_func_call(f.inner, &real_args.inner, &out.inner)} 302 | for i in 0 .. out.inner.size { 303 | unsafe { 304 | results[i] = Val{out.inner.data[i]} 305 | } 306 | } 307 | out.delete() 308 | real_args.delete() 309 | return trap 310 | } 311 | 312 | pub fn (f Func) typ() FuncType { 313 | return FuncType{C.wasm_func_type(f.inner)} 314 | } 315 | 316 | pub fn func_raw(store Store, ftype FuncType, callback CWasmFuncCallback) Func { 317 | return Func{C.wasm_func_new(store.inner, ftype.inner, callback)} 318 | } 319 | 320 | pub fn func_raw_with_env(store Store, ftype FuncType, callback CWasmFuncCallbackWithEnv, env voidptr, env_finalizer fn (voidptr)) Func { 321 | return Func{C.wasm_func_new_with_env(store.inner, ftype.inner, callback, env, unsafe { nil })} 322 | } 323 | 324 | pub struct Arguments { 325 | args &C.wasm_val_vec_t 326 | env voidptr 327 | mut: 328 | results &C.wasm_val_vec_t 329 | } 330 | 331 | pub fn (args Arguments) arg(i int) ?Val { 332 | if i < 0 || i >= int(args.args.size) { 333 | return none 334 | } 335 | return unsafe { 336 | Val{args.args.data[i]} 337 | } 338 | } 339 | 340 | pub fn (args Arguments) env() voidptr { 341 | return args.env 342 | } 343 | 344 | pub fn (mut args Arguments) set_result(i int, val Val) ? { 345 | if i < 0 || i >= int(args.results.size) { 346 | return error('out of bounds while setting result value') 347 | } 348 | unsafe { 349 | args.results.data[i] = val.inner 350 | } 351 | } 352 | 353 | struct WasmVEnv { 354 | mut: 355 | callback WasmCallback 356 | store &C.wasm_store_t 357 | 358 | additional_env voidptr 359 | env_finalizer voidptr 360 | } 361 | 362 | pub type WasmFinalizer = fn (voidptr) 363 | 364 | pub type WasmCallback = fn (mut Arguments) ? 365 | 366 | fn invoke_v_func(env_ voidptr, args &C.wasm_val_vec_t, results &C.wasm_val_vec_t) &C.wasm_trap_t { 367 | unsafe { 368 | env := &WasmVEnv(env_) 369 | callback := env.callback 370 | 371 | store := env.store 372 | mut arguments := Arguments{args, env.additional_env, results} 373 | callback(mut arguments) or { 374 | env_finalizer(env_) 375 | bvec := byte_vec(err.msg().bytes()) 376 | trap := C.wasm_trap_new(store, &bvec.inner) 377 | return trap 378 | } 379 | env_finalizer(env_) 380 | } 381 | return &C.wasm_trap_t(0) 382 | } 383 | 384 | fn env_finalizer(env voidptr) { 385 | venv := &WasmVEnv(env) 386 | if !isnil(venv.additional_env) { 387 | if !isnil(venv.env_finalizer) { 388 | fin := WasmFinalizer(venv.env_finalizer) 389 | fin(venv.additional_env) 390 | } 391 | } 392 | C.free(venv) 393 | } 394 | 395 | pub fn func(store Store, ftype FuncType, callback WasmCallback) Func { 396 | unsafe { 397 | mut env := &WasmVEnv(C.malloc(sizeof(WasmVEnv))) 398 | env.callback = callback 399 | env.store = store.inner 400 | env.additional_env = nil 401 | return func_raw_with_env(store, ftype, invoke_v_func, voidptr(env), env_finalizer) 402 | } 403 | } 404 | 405 | pub fn func_with_env(store Store, ftype FuncType, callback WasmCallback, env_ voidptr, env_finalizer_ WasmFinalizer) Func { 406 | unsafe { 407 | mut env := &WasmVEnv(C.malloc(sizeof(WasmVEnv))) 408 | env.callback = callback 409 | env.store = store.inner 410 | env.additional_env = env_ 411 | env.env_finalizer = voidptr(env_finalizer_) 412 | 413 | return func_raw_with_env(store, ftype, invoke_v_func, voidptr(env), env_finalizer) 414 | } 415 | } 416 | 417 | pub fn (f Func) delete() { 418 | C.wasm_func_delete(f.inner) 419 | } 420 | 421 | pub fn (g Global) as_extern() Extern { 422 | return Extern{C.wasm_global_as_extern(g.inner)} 423 | } 424 | 425 | pub fn (m Memory) as_extern() Extern { 426 | return Extern{C.wasm_memory_as_extern(m.inner)} 427 | } 428 | 429 | pub fn (t Table) as_extern() Extern { 430 | return Extern{C.wasm_table_as_extern(t.inner)} 431 | } 432 | 433 | pub fn (g Global) copy() Global { 434 | return Global{C.wasm_global_copy(g.inner)} 435 | } 436 | 437 | pub fn (g Global) delete() { 438 | C.wasm_global_delete(g.inner) 439 | } 440 | 441 | pub fn (g Global) get() Val { 442 | mut out := val_null() 443 | C.wasm_global_get(g.inner, &out.inner) 444 | return out 445 | } 446 | 447 | pub fn (g Global) set(val Val) { 448 | C.wasm_global_set(g.inner, &val.inner) 449 | } 450 | 451 | pub fn (g Global) same(y Global) bool { 452 | return C.wasm_global_same(g.inner, y.inner) 453 | } 454 | 455 | pub fn (g Global) typ() GlobalType { 456 | return GlobalType{C.wasm_global_type(g.inner)} 457 | } 458 | 459 | pub fn global(store Store, typ GlobalType, val Val) Global { 460 | return Global{C.wasm_global_new(store.inner, typ.inner, &val.inner)} 461 | } 462 | 463 | pub fn (m Memory) copy() Memory { 464 | return Memory{C.wasm_memory_copy(m.inner)} 465 | } 466 | 467 | pub fn (m Memory) delete() { 468 | C.wasm_memory_delete(m.inner) 469 | } 470 | 471 | pub fn (m Memory) data() voidptr { 472 | return C.wasm_memory_data(m.inner) 473 | } 474 | 475 | pub fn (m Memory) data_size() usize { 476 | return C.wasm_memory_data_size(m.inner) 477 | } 478 | 479 | pub fn (m Memory) grow(delta u32) bool { 480 | return C.wasm_memory_grow(m.inner, delta) 481 | } 482 | 483 | pub fn (m Memory) memory_same(y Memory) bool { 484 | return C.wasm_memory_same(m.inner, y.inner) 485 | } 486 | 487 | pub fn (m Memory) size() u32 { 488 | return C.wasm_memory_size(m.inner) 489 | } 490 | 491 | pub fn (t Table) copy() Table { 492 | return Table{C.wasm_table_copy(t.inner)} 493 | } 494 | 495 | pub fn (t Table) delete() { 496 | C.wasm_table_delete(t.inner) 497 | } 498 | 499 | pub fn (t Table) grow(delta u32, init voidptr) bool { 500 | return C.wasm_table_grow(t.inner, delta, init) 501 | } 502 | 503 | pub fn (t Table) same(y Table) bool { 504 | return C.wasm_table_same(t.inner, y.inner) 505 | } 506 | 507 | pub fn (t Table) size() usize { 508 | return C.wasm_table_size(t.inner) 509 | } 510 | 511 | pub fn table(store Store, typ TableType, init voidptr) Table { 512 | return Table{C.wasm_table_new(store.inner, typ.inner, init)} 513 | } 514 | 515 | pub fn (m Memory) typ() MemoryType { 516 | return MemoryType{C.wasm_memory_type(m.inner)} 517 | } 518 | 519 | pub enum ExternKind { 520 | func 521 | global 522 | table 523 | memory 524 | } 525 | 526 | pub fn (e Extern) kind() ExternKind { 527 | return C.wasm_extern_kind(e.inner) 528 | } 529 | 530 | pub fn (e Extern) typ() ExternType { 531 | return ExternType{C.wasm_extern_type(e.inner)} 532 | } 533 | 534 | pub fn (e Extern) as_func() ?Func { 535 | x := C.wasm_extern_as_func(e.inner) 536 | if isnil(x) { 537 | return none 538 | } 539 | return Func{x} 540 | } 541 | 542 | pub fn (e Extern) as_global() ?Global { 543 | x := C.wasm_extern_as_global(e.inner) 544 | if isnil(x) { 545 | return none 546 | } 547 | return Global{x} 548 | } 549 | 550 | pub fn (e Extern) as_memory() ?Memory { 551 | x := C.wasm_extern_as_memory(e.inner) 552 | if isnil(x) { 553 | return none 554 | } 555 | return Memory{x} 556 | } 557 | 558 | pub fn (e Extern) as_table() ?Table { 559 | x := C.wasm_extern_as_table(e.inner) 560 | if isnil(x) { 561 | return none 562 | } 563 | return Table{x} 564 | } 565 | 566 | pub fn extern_vec(externs []Extern) ExternVec { 567 | mut v := C.wasm_extern_vec_t{} 568 | C.wasm_extern_vec_new(&v, usize(externs.len), externs.data) 569 | return ExternVec{v} 570 | } 571 | 572 | pub fn extern_vec_empty() ExternVec { 573 | mut v := C.wasm_extern_vec_t{} 574 | C.wasm_extern_vec_new_empty(&v) 575 | return ExternVec{v} 576 | } 577 | 578 | pub fn (v ExternVec) delete() { 579 | C.wasm_extern_vec_delete(&v.inner) 580 | } 581 | 582 | pub fn (v ExternVec) at(i int) Extern { 583 | unsafe { 584 | return Extern{v.inner.data[i]} 585 | } 586 | } 587 | 588 | pub fn (v ExternVec) set_at(i int, val Extern) { 589 | unsafe { 590 | v.inner.data[i] = val.inner 591 | } 592 | } 593 | 594 | // wat2wasm converts WAT to WASM bytecode. This function returns error 595 | // if source code is not valid WAT. 596 | pub fn wat2wasm(source string) ?[]byte { 597 | mut out := ByteVec{} 598 | src := byte_vec(source.bytes()) 599 | C.wat2wasm(&src.inner, &out.inner) 600 | src.delete() 601 | err := get_wasmer_error() or { 602 | mut bytes := []byte{} 603 | for i in 0 .. out.inner.size { 604 | unsafe { 605 | bytes << out.inner.data[i] 606 | } 607 | } 608 | 609 | out.delete() 610 | return bytes 611 | } 612 | out.delete() 613 | return error(err) 614 | } 615 | 616 | // engine creates new Wasmer engine 617 | pub fn engine() Engine { 618 | return Engine{C.wasm_engine_new()} 619 | } 620 | 621 | // engine_with_config will construct Wasmer engine with config from `c`. 622 | // Note: Config will be deallocated after this call automatically 623 | pub fn engine_with_config(c Config) Engine { 624 | e := Engine{C.wasm_engine_new_with_config(c.inner)} 625 | return e 626 | } 627 | 628 | // config creates new Config instance 629 | pub fn config() Config { 630 | return Config{C.wasm_config_new()} 631 | } 632 | 633 | pub fn (mut config Config) set_features(f Features) { 634 | C.wasm_config_set_features(config.inner, f.inner) 635 | } 636 | 637 | // set_compiler updates the configuration to specify a particular compiler to use. 638 | pub fn (mut config Config) set_compiler(cc WasmerCompiler) { 639 | C.wasm_config_set_compiler(config.inner, cc) 640 | } 641 | 642 | // set_engine updates the configuration to specify a particular engine to use. 643 | pub fn (mut config Config) set_engine(engine WasmerEngine) { 644 | C.wasm_config_set_engine(config.inner, engine) 645 | } 646 | 647 | pub fn (engine Engine) delete() { 648 | C.wasm_engine_delete(engine.inner) 649 | } 650 | 651 | pub fn (config Config) delete() { 652 | C.wasm_config_delete(config.inner) 653 | } 654 | 655 | pub fn (store Store) delete() { 656 | C.wasm_store_delete(store.inner) 657 | } 658 | 659 | // store creates a new WebAssembly store given a specific engine. 660 | pub fn store(engine Engine) Store { 661 | return Store{C.wasm_store_new(engine.inner)} 662 | } 663 | 664 | pub fn get_wasmer_error() ?string { 665 | if C.wasmer_last_error_length() == 0 { 666 | return none 667 | } 668 | 669 | buf := []byte{len: C.wasmer_last_error_length(), cap: C.wasmer_last_error_length(), init: 0} 670 | C.wasmer_last_error_message(buf.data, C.wasmer_last_error_length()) 671 | return buf.bytestr() 672 | } 673 | 674 | pub fn compile(store Store, wasm []byte) ?Module { 675 | wasm_ := byte_vec(wasm) 676 | mod := C.wasm_module_new(store.inner, &wasm_.inner) 677 | 678 | err := get_wasmer_error() or { return Module{mod} } 679 | 680 | return error(err) 681 | } 682 | 683 | pub fn (t Trap) is_set() bool { 684 | return !isnil(t.inner) 685 | } 686 | 687 | pub fn (t Trap) delete() { 688 | if t.is_set() { 689 | C.wasm_trap_delete(t.inner) 690 | } 691 | } 692 | 693 | pub fn (t Trap) origin() ?Frame { 694 | if !t.is_set() { 695 | return none 696 | } 697 | 698 | frame := C.wasm_trap_origin(t.inner) 699 | if isnil(frame) { 700 | return none 701 | } 702 | return Frame{frame} 703 | } 704 | 705 | pub fn (t Trap) message() ?string { 706 | if !t.is_set() { 707 | return none 708 | } 709 | 710 | mut bytes := ByteVec{} 711 | C.wasm_trap_message(t.inner, &bytes.inner) 712 | return bytes.to_string() 713 | } 714 | 715 | pub fn null_trap() Trap { 716 | return Trap{} 717 | } 718 | 719 | pub fn instance(store Store, mod Module, imports []Extern, mut trap Trap) Instance { 720 | rimports := extern_vec(imports) 721 | instance := Instance{C.wasm_instance_new(store.inner, mod.inner, &rimports.inner, 722 | &trap.inner)} 723 | rimports.delete() 724 | return instance 725 | } 726 | 727 | pub fn (instance Instance) exports() []Extern { 728 | mut x := extern_vec_empty() 729 | mut exports := []Extern{} 730 | C.wasm_instance_exports(instance.inner, &x.inner) 731 | 732 | for i in 0 .. x.inner.size { 733 | unsafe { 734 | exports << Extern{x.inner.data[i]} 735 | } 736 | } 737 | 738 | return exports 739 | } 740 | 741 | pub fn (ty FuncType) params() []ValType { 742 | params := C.wasm_functype_params(ty.inner) 743 | mut out := []ValType{} 744 | for i in 0 .. params.size { 745 | out << unsafe { ValType{params.data[i]} } 746 | } 747 | return out 748 | } 749 | 750 | pub fn (ty FuncType) results() []ValType { 751 | params := C.wasm_functype_results(ty.inner) 752 | mut out := []ValType{} 753 | for i in 0 .. params.size { 754 | out << unsafe { ValType{params.data[i]} } 755 | } 756 | return out 757 | } 758 | 759 | pub fn (ty FuncType) copy() FuncType { 760 | return FuncType{C.wasm_functype_copy(ty.inner)} 761 | } 762 | 763 | pub fn (ty FuncType) delete() { 764 | C.wasm_functype_delete(ty.inner) 765 | } 766 | 767 | pub fn func_type(params []ValType, results []ValType) FuncType { 768 | params_ := C.wasm_valtype_vec_t{} 769 | results_ := C.wasm_valtype_vec_t{} 770 | C.wasm_valtype_vec_new(¶ms_, usize(params.len), params.data) 771 | C.wasm_valtype_vec_new(&results_, usize(results.len), results.data) 772 | f := FuncType{C.wasm_functype_new(¶ms_, &results_)} 773 | C.wasm_valtype_vec_delete(¶ms_) 774 | C.wasm_valtype_vec_delete(&results_) 775 | return f 776 | } 777 | 778 | pub fn global_type(valtype ValType, mutability bool) GlobalType { 779 | return GlobalType{C.wasm_globaltype_new(valtype.inner, u8(mutability))} 780 | } 781 | 782 | pub fn val_type(kind WasmValKind) ValType { 783 | return ValType{C.wasm_valtype_new(kind)} 784 | } 785 | 786 | pub fn (v ValType) str() string { 787 | return '$v.kind()' 788 | } 789 | 790 | pub fn (v ValType) kind() WasmValKind { 791 | return C.wasm_valtype_kind(v.inner) 792 | } 793 | 794 | pub fn (g GlobalType) delete() { 795 | C.wasm_globaltype_delete(g.inner) 796 | } 797 | 798 | pub fn (g GlobalType) mutability() bool { 799 | return C.wasm_globaltype_mutability(g.inner) != 0 800 | } 801 | 802 | pub fn (g GlobalType) content() ValType { 803 | return ValType{C.wasm_globaltype_content(g.inner)} 804 | } 805 | 806 | pub fn (g GlobalType) as_extern_type() ExternType { 807 | return ExternType{C.wasm_globaltype_as_externtype(g.inner)} 808 | } 809 | 810 | pub fn new(min u32, max u32) MemoryType { 811 | limits := C.wasm_limits_t{min, max} 812 | return MemoryType{C.wasm_memorytype_new(&limits)} 813 | } 814 | 815 | pub fn (m MemoryType) limits() (u32, u32) { 816 | limits := C.wasm_memorytype_limits(m.inner) 817 | return limits.min, limits.max 818 | } 819 | 820 | pub fn (m MemoryType) delete() { 821 | C.wasm_memorytype_delete(m.inner) 822 | } 823 | 824 | pub fn (m MemoryType) as_extern_type() ExternType { 825 | return ExternType{C.wasm_memorytype_as_externtype(m.inner)} 826 | } 827 | 828 | pub fn (t TableType) limits() (u32, u32) { 829 | limits := C.wasm_tabletype_limits(t.inner) 830 | return limits.min, limits.max 831 | } 832 | 833 | pub fn (t TableType) element() ValType { 834 | return ValType{C.wasm_tabletype_element(t.inner)} 835 | } 836 | 837 | pub fn (t TableType) delete() { 838 | C.wasm_tabletype_delete(t.inner) 839 | } 840 | 841 | pub fn (t TableType) as_extern_type() ExternType { 842 | return ExternType{C.wasm_tabletype_as_externtype(t.inner)} 843 | } 844 | 845 | pub fn table_type(valtype ValType, min u32, max u32) TableType { 846 | limits := C.wasm_limits_t{min, max} 847 | return TableType{C.wasm_tabletype_new(valtype.inner, &limits)} 848 | } 849 | 850 | pub fn (e ExportType) copy() ExportType { 851 | return ExportType{C.wasm_exporttype_copy(e.inner)} 852 | } 853 | 854 | pub fn (e ExportType) delete() { 855 | C.wasm_exporttype_delete(e.inner) 856 | } 857 | 858 | pub fn (e ExportType) name() string { 859 | bvec := C.wasm_exporttype_name(e.inner) 860 | return unsafe { 861 | bvec.data.vbytes(int(bvec.size)).bytestr() 862 | } 863 | } 864 | 865 | pub fn (e ExportType) typ() ExternType { 866 | return ExternType{C.wasm_exporttype_type(e.inner)} 867 | } 868 | 869 | pub fn export_type(name string, extern_type ExternType) ExportType { 870 | name_bvec := byte_vec(name.bytes()) 871 | t := C.wasm_exporttype_new(&name_bvec.inner, extern_type.inner) 872 | name_bvec.delete() 873 | return ExportType{t} 874 | } 875 | 876 | pub fn (e ExternType) kind() u8 { 877 | return C.wasm_externtype_kind(e.inner) 878 | } 879 | 880 | pub fn (e ExternType) delete() { 881 | C.wasm_externtype_delete(e.inner) 882 | } 883 | 884 | pub fn (e ExternType) copy() ExternType { 885 | return ExternType{C.wasm_externtype_copy(e.inner)} 886 | } 887 | 888 | pub fn (e ExternType) as_global_type() ?GlobalType { 889 | t := C.wasm_externtype_as_globaltype(e.inner) 890 | if isnil(t) { 891 | return none 892 | } 893 | return GlobalType{t} 894 | } 895 | 896 | pub fn (e ExternType) as_func_type() ?FuncType { 897 | t := C.wasm_externtype_as_functype(e.inner) 898 | if isnil(t) { 899 | return none 900 | } 901 | return FuncType{t} 902 | } 903 | 904 | pub fn (e ExternType) as_memory_type() ?MemoryType { 905 | t := C.wasm_externtype_as_memorytype(e.inner) 906 | if isnil(t) { 907 | return none 908 | } 909 | return MemoryType{t} 910 | } 911 | 912 | pub fn (e ExternType) as_table_type() ?TableType { 913 | t := C.wasm_externtype_as_tabletype(e.inner) 914 | if isnil(t) { 915 | return none 916 | } 917 | return TableType{t} 918 | } 919 | 920 | pub fn (f Frame) delete() { 921 | C.wasm_frame_delete(f.inner) 922 | } 923 | 924 | pub fn (f Frame) copy() Frame { 925 | return Frame{C.wasm_frame_copy(f.inner)} 926 | } 927 | 928 | pub fn (f Frame) func_index() u32 { 929 | return C.wasm_frame_func_index(f.inner) 930 | } 931 | 932 | pub fn (f Frame) func_offset() usize { 933 | return C.wasm_frame_func_offset(f.inner) 934 | } 935 | 936 | pub fn (f Frame) instance() Instance { 937 | return Instance{C.wasm_frame_instance(f.inner)} 938 | } 939 | 940 | pub fn (f Frame) module_offset() usize { 941 | return C.wasm_frame_module_offset(f.inner) 942 | } 943 | 944 | pub struct Features { 945 | inner &C.wasmer_features_t 946 | } 947 | 948 | pub fn features() Features { 949 | return Features{C.wasmer_features_new()} 950 | } 951 | 952 | pub fn (mut f Features) module_linking(enable bool) bool { 953 | return C.wasmer_features_module_linking(f.inner, enable) 954 | } 955 | 956 | pub fn (mut f Features) bulk_memory(enable bool) bool { 957 | return C.wasmer_features_bulk_memory(f.inner, enable) 958 | } 959 | 960 | pub fn (mut f Features) tail_call(enable bool) bool { 961 | return C.wasmer_features_tail_call(f.inner, enable) 962 | } 963 | 964 | pub fn (mut f Features) memory64(enable bool) bool { 965 | return C.wasmer_features_memory64(f.inner, enable) 966 | } 967 | 968 | pub fn (mut f Features) multi_memory(enable bool) bool { 969 | return C.wasmer_features_multi_memory(f.inner, enable) 970 | } 971 | 972 | pub fn (mut f Features) multi_value(enable bool) bool { 973 | return C.wasmer_features_multi_value(f.inner, enable) 974 | } 975 | 976 | pub fn (mut f Features) simd(enable bool) bool { 977 | return C.wasmer_features_simd(f.inner, enable) 978 | } 979 | 980 | pub fn (mut f Features) threads(enable bool) bool { 981 | return C.wasmer_features_threads(f.inner, enable) 982 | } 983 | 984 | pub fn (mut f Features) reference_types(enable bool) bool { 985 | return C.wasmer_features_reference_types(f.inner, enable) 986 | } 987 | 988 | pub fn (e Extern) str() string { 989 | return 'Extern{}' 990 | } 991 | 992 | pub struct WasmPtr { 993 | offset u32 994 | } 995 | 996 | pub fn wasm_ptr(offset u32) WasmPtr { 997 | return WasmPtr{offset} 998 | } 999 | 1000 | pub fn (p WasmPtr) deref(memory &Memory) ?&T { 1001 | end := p.offset + sizeof(T) 1002 | if end > memory.data_size() || sizeof(T) == 0 { 1003 | return none 1004 | } 1005 | unsafe { 1006 | ptr := usize(memory.data()) + p.offset 1007 | return &T(ptr) 1008 | } 1009 | } 1010 | 1011 | pub fn (p WasmPtr) get_offset() u32 { 1012 | return p.offset 1013 | } 1014 | -------------------------------------------------------------------------------- /wasmer/wasmer_sys.v: -------------------------------------------------------------------------------- 1 | module wasmer 2 | 3 | #flag -L $env('WASMER_DIR')/lib 4 | #flag -lwasmer 5 | #flag -I @VMODROOT 6 | #flag -I $env('WASMER_DIR')/include 7 | #flag -rpath $env('WASMER_DIR')/lib 8 | #include "wasmer/include/wasm.h" 9 | #include "wasmer/include/wasmer.h" 10 | 11 | struct C.wasm_engine_t {} 12 | 13 | struct C.wasm_config_t {} 14 | 15 | struct C.wasmer_features_t {} 16 | 17 | struct C.wasm_instance_t {} 18 | 19 | struct C.wasm_store_t {} 20 | 21 | struct C.wasm_byte_vec_t { 22 | pub mut: 23 | size usize 24 | data &u8 = unsafe { 0 } 25 | } 26 | 27 | struct C.wasm_exporttype_t {} 28 | 29 | struct C.wasm_exporttype_vec_t { 30 | pub mut: 31 | size usize 32 | data &&C.wasm_exporttype_t = unsafe { 0 } 33 | } 34 | 35 | struct C.wasm_externtype_t {} 36 | 37 | struct C.wasm_externtype_vec_t { 38 | pub mut: 39 | size usize 40 | data &&C.wasm_externtype_t = unsafe { 0 } 41 | } 42 | 43 | struct C.wasm_frame_t {} 44 | 45 | struct C.wasm_frame_vec_t { 46 | pub mut: 47 | size usize 48 | data &&C.wasm_frame_t = unsafe { 0 } 49 | } 50 | 51 | struct C.wasm_functype_t {} 52 | 53 | struct C.wasm_functype_vec_t { 54 | pub mut: 55 | size usize 56 | data &&C.wasm_functype_t = unsafe { 0 } 57 | } 58 | 59 | struct C.wasm_globaltype_t {} 60 | 61 | struct C.wasm_globaltype_vec_t { 62 | pub mut: 63 | size usize 64 | data &&C.wasm_globaltype_vec_t = unsafe { 0 } 65 | } 66 | 67 | struct C.wasm_importtype_t {} 68 | 69 | struct C.wasm_importtype_vec_t { 70 | pub mut: 71 | size usize 72 | data &&C.wasm_importtype_vec_t = unsafe { 0 } 73 | } 74 | 75 | struct C.wasm_limits_t { 76 | pub mut: 77 | min u32 78 | max u32 79 | } 80 | 81 | struct C.wasm_memorytype_t {} 82 | 83 | struct C.wasm_memorytype_t_vec { 84 | pub mut: 85 | size usize 86 | data &&C.wasm_memorytype_t = unsafe { 0 } 87 | } 88 | 89 | struct C.wasm_ref_t {} 90 | 91 | struct C.wasm_tabletype_t {} 92 | 93 | struct C.wasm_tabletype_vec_t { 94 | pub mut: 95 | size usize 96 | data &&C.wasm_tabletype_t = unsafe { 0 } 97 | } 98 | 99 | pub struct C.wasm_valtype_t {} 100 | 101 | struct C.wasm_valtype_vec_t { 102 | pub mut: 103 | size usize 104 | data &&C.wasm_valtype_t = unsafe { 0 } 105 | } 106 | 107 | pub enum WasmerCompiler { 108 | cranelift = 0 109 | llvm 110 | singlepass 111 | } 112 | 113 | pub enum WasmerEngine { 114 | universal = 0 115 | dylib 116 | staticlib 117 | } 118 | 119 | pub enum WasmValKind { 120 | wasm_i32 = 0 121 | wasm_i64 122 | wasm_f32 123 | wasm_f64 124 | wasm_anyref 125 | wasm_funcref 126 | } 127 | 128 | fn C.wasm_config_delete(config &C.wasm_config_t) 129 | fn C.wasm_config_new() &C.wasm_config_t 130 | fn C.wasm_config_set_compiler(config &C.wasm_config_t, compiler WasmerCompiler) 131 | fn C.wasm_config_set_engine(config &C.wasm_config_t, engine WasmerEngine) 132 | fn C.wasm_config_set_features(config &C.wasm_config_t, features &C.wasmer_features_t) 133 | fn C.wasm_engine_new() &C.wasm_engine_t 134 | fn C.wasm_engine_new_with_config(config &C.wasm_config_t) &C.wasm_engine_t 135 | fn C.wasm_engine_delete(engien &C.wasm_engine_t) 136 | fn C.wasmer_is_compiler_available(compiler WasmerCompiler) bool 137 | fn C.wasmer_features_new() &C.wasmer_features_t 138 | fn C.wasmer_features_bulk_memory(f &C.wasmer_features_t, enable bool) bool 139 | fn C.wasmer_features_delete(f &C.wasmer_features_t) 140 | fn C.wasmer_features_memory64(f &C.wasmer_features_t, enable bool) bool 141 | fn C.wasmer_features_module_linking(f &C.wasmer_features_t, enable bool) bool 142 | fn C.wasmer_features_multi_memory(f &C.wasmer_features_t, enable bool) bool 143 | fn C.wasmer_features_multi_value(f &C.wasmer_features_t, enable bool) bool 144 | fn C.wasmer_features_tail_call(f &C.wasmer_features_t, enable bool) bool 145 | fn C.wasmer_features_simd(f &C.wasmer_features_t, enable bool) bool 146 | fn C.wasmer_features_threads(f &C.wasmer_features_t, enable bool) bool 147 | fn C.wasmer_features_reference_types(f &C.wasmer_features_t, enable bool) bool 148 | fn C.wasm_store_new(&C.wasm_engine_t) &C.wasm_store_t 149 | fn C.wasm_store_delete(&C.wasm_store_t) 150 | 151 | fn C.wasm_byte_vec_new(out &C.wasm_byte_vec_t, size usize, ptr &u8) 152 | fn C.wasm_byte_vec_delete(out &C.wasm_byte_vec_t) 153 | fn C.wasm_byte_vec_new_empty(out &C.wasm_byte_vec_t) 154 | fn C.wasm_byte_vec_new_uninitialized(out &C.wasm_byte_vec_t, size usize) 155 | fn C.wasm_byte_vec_copy(out &C.wasm_byte_vec_t, src &C.wasm_byte_vec_t) 156 | 157 | fn C.wasm_exporttype_vec_new(out &C.wasm_exporttype_vec_t, size usize, ptr &&C.wasm_exporttype_t) 158 | fn C.wasm_exporttype_vec_delete(out &C.wasm_exporttype_vec_t) 159 | fn C.wasm_exporttype_vec_new_empty(out &C.wasm_exporttype_vec_t) 160 | fn C.wasm_exporttype_vec_new_uninitialized(out &C.wasm_exporttype_vec_t, size usize) 161 | fn C.wasm_exporttype_vec_copy(out &C.wasm_exporttype_vec_t, src &C.wasm_exporttype_vec_t) 162 | 163 | fn C.wasm_frame_vec_new(out &C.wasm_frame_vec_t, size usize, ptr &&C.wasm_frame_t) 164 | fn C.wasm_frame_vec_delete(out &C.wasm_frame_vec_t) 165 | fn C.wasm_frame_vec_new_empty(out &C.wasm_frame_vec_t) 166 | fn C.wasm_frame_vec_new_uninitialized(out &C.wasm_frame_vec_t, size usize) 167 | fn C.wasm_frame_vec_copy(out &C.wasm_frame_vec_t, src &C.wasm_frame_vec_t) 168 | 169 | fn C.wasm_externtype_vec_new(out &C.wasm_externtype_vec_t, size usize, ptr &&C.wasm_externtype_t) 170 | fn C.wasm_externtype_vec_delete(out &C.wasm_externtype_vec_t) 171 | fn C.wasm_externtype_vec_new_empty(out &C.wasm_externtype_vec_t) 172 | fn C.wasm_externtype_vec_new_uninitialized(out &C.wasm_externtype_vec_t, size usize) 173 | fn C.wasm_externtype_vec_copy(out &C.wasm_externtype_vec_t, src &C.wasm_externtype_vec_t) 174 | 175 | fn C.wasm_functype_vec_new(out &C.wasm_functype_vec_t, size usize, ptr &&C.wasm_functype_t) 176 | fn C.wasm_functype_vec_delete(out &C.wasm_functype_vec_t) 177 | fn C.wasm_functype_vec_new_empty(out &C.wasm_functype_vec_t) 178 | fn C.wasm_functype_vec_new_uninitialized(out &C.wasm_functype_vec_t, size usize) 179 | fn C.wasm_functype_vec_copy(out &C.wasm_functype_vec_t, src &C.wasm_functype_vec_t) 180 | 181 | fn C.wasm_globaltype_vec_new(out &C.wasm_globaltype_vec_t, size usize, ptr &&C.wasm_globaltype_t) 182 | fn C.wasm_globaltype_vec_delete(out &C.wasm_globaltype_vec_t) 183 | fn C.wasm_globaltype_vec_new_empty(out &C.wasm_globaltype_vec_t) 184 | fn C.wasm_globaltype_vec_new_uninitialized(out &C.wasm_globaltype_vec_t, size usize) 185 | fn C.wasm_globaltype_vec_copy(out &C.wasm_globaltype_vec_t, src &C.wasm_globaltype_vec_t) 186 | 187 | fn C.wasm_importtype_vec_new(out &C.wasm_importtype_vec_t, size usize, ptr &&C.wasm_importtype_t) 188 | fn C.wasm_importtype_vec_delete(out &C.wasm_importtype_vec_t) 189 | fn C.wasm_importtype_vec_new_empty(out &C.wasm_importtype_vec_t) 190 | fn C.wasm_importtype_vec_new_uninitialized(out &C.wasm_importtype_vec_t, size usize) 191 | fn C.wasm_importtype_vec_copy(out &C.wasm_importtype_vec_t, src &C.wasm_importtype_vec_t) 192 | 193 | fn C.wasm_memorytype_vec_new(out &C.wasm_memorytype_vec_t, size usize, ptr &&C.wasm_memorytype_t) 194 | fn C.wasm_memorytype_vec_delete(out &C.wasm_memorytype_vec_t) 195 | fn C.wasm_memorytype_vec_new_empty(out &C.wasm_memorytype_vec_t) 196 | fn C.wasm_memorytype_vec_new_uninitialized(out &C.wasm_memorytype_vec_t, size usize) 197 | fn C.wasm_memorytype_vec_copy(out &C.wasm_memorytype_vec_t, src &C.wasm_memorytype_vec_t) 198 | 199 | fn C.wasm_tabletype_vec_new(out &C.wasm_tabletype_vec_t, size usize, ptr &&C.wasm_tabletype_t) 200 | fn C.wasm_tabletype_vec_delete(out &C.wasm_tabletype_vec_t) 201 | fn C.wasm_tabletype_vec_new_empty(out &C.wasm_tabletype_vec_t) 202 | fn C.wasm_tabletype_vec_new_uninitialized(out &C.wasm_tabletype_vec_t, size usize) 203 | fn C.wasm_tabletype_vec_copy(out &C.wasm_tabletype_vec_t, src &C.wasm_tabletype_vec_t) 204 | 205 | fn C.wasm_valtype_vec_new(out &C.wasm_valtype_vec_t, size usize, ptr &&C.wasm_valtype_t) 206 | fn C.wasm_valtype_vec_delete(out &C.wasm_valtype_vec_t) 207 | fn C.wasm_valtype_vec_new_empty(out &C.wasm_valtype_vec_t) 208 | fn C.wasm_valtype_vec_new_uninitialized(out &C.wasm_valtype_vec_t, size usize) 209 | fn C.wasm_valtype_vec_copy(out &C.wasm_valtype_vec_t, src &C.wasm_valtype_vec_t) 210 | 211 | fn C.wasm_valtype_new(kind WasmValKind) &C.wasm_valtype_t 212 | fn C.wasm_valtype_kind(valtype &C.wasm_valtype_t) WasmValKind 213 | 214 | struct C.wasm_trap_t {} 215 | 216 | fn C.wasm_trap_new(store &C.wasm_store_t, message &C.wasm_byte_vec_t) &C.wasm_trap_t 217 | fn C.wasm_trap_delete(trap &C.wasm_trap_t) 218 | fn C.wasm_trap_origin(trap &C.wasm_trap_t) &C.wasm_frame_t 219 | fn C.wasm_trap_message(trap &C.wasm_trap_t, out &C.wasm_byte_vec_t) 220 | fn C.wasm_trap_trace(trap &C.wasm_trap_t, out &C.wasm_frame_vec_t) 221 | 222 | pub struct C.wasm_val_t { 223 | pub mut: 224 | kind WasmValKind 225 | of C.wasm_val_inner 226 | } 227 | 228 | pub struct C.wasm_val_vec_t { 229 | pub mut: 230 | size usize 231 | data &C.wasm_val_t = unsafe { 0 } 232 | } 233 | 234 | pub union C.wasm_val_inner { 235 | pub mut: 236 | i32 int 237 | i64 i64 238 | f64 f64 239 | f32 f32 240 | ref &C.wasm_ref_t = unsafe { 0 } 241 | } 242 | 243 | pub fn wasm_i32_val(x int) C.wasm_val_t { 244 | mut val := C.wasm_val_t{} 245 | val.of.i32 = x 246 | val.kind = .wasm_i32 247 | return val 248 | } 249 | 250 | pub fn wasm_i64_val(x i64) C.wasm_val_t { 251 | mut val := C.wasm_val_t{} 252 | val.of.i64 = x 253 | val.kind = .wasm_i64 254 | return val 255 | } 256 | 257 | pub fn wasm_f32_val(x f32) C.wasm_val_t { 258 | mut val := C.wasm_val_t{} 259 | val.of.f32 = x 260 | val.kind = .wasm_f32 261 | return val 262 | } 263 | 264 | pub fn wasm_f64_val(x f64) C.wasm_val_t { 265 | mut val := C.wasm_val_t{} 266 | val.of.f64 = x 267 | val.kind = .wasm_f64 268 | return val 269 | } 270 | 271 | pub fn wasm_ref_val(x &C.wasm_ref_t) C.wasm_val_t { 272 | mut val := C.wasm_val_t{} 273 | unsafe { 274 | val.of.ref = x 275 | } 276 | val.kind = .wasm_anyref 277 | return val 278 | } 279 | 280 | pub fn wasm_init_val() C.wasm_val_t { 281 | mut val := C.wasm_val_t{} 282 | unsafe { 283 | val.of.ref = &C.wasm_ref_t(0) 284 | } 285 | val.kind = .wasm_anyref 286 | return val 287 | } 288 | 289 | fn C.wasm_val_vec_new(out &C.wasm_val_vec_t, size usize, ptr &C.wasm_val_t) 290 | fn C.wasm_val_vec_delete(out &C.wasm_val_vec_t) 291 | fn C.wasm_val_vec_new_empty(out &C.wasm_val_vec_t) 292 | fn C.wasm_val_vec_new_uninitialized(out &C.wasm_val_vec_t, size usize) 293 | fn C.wasm_val_vec_copy(out &C.wasm_val_vec_t, src &C.wasm_val_vec_t) 294 | 295 | struct C.wasm_module_t {} 296 | 297 | fn C.wasm_module_new(store &C.wasm_store_t, bytes &C.wasm_byte_vec_t) &C.wasm_module_t 298 | fn C.wasm_module_delete(mod &C.wasm_module_t) 299 | fn C.wasm_module_imports(mod &C.wasm_module_t, out &C.wasm_importtype_vec_t) 300 | fn C.wasm_module_exports(mod &C.wasm_module_t, out &C.wasm_exporttype_vec_t) 301 | fn C.wasm_module_serialize(mod &C.wasm_module_t, out &C.wasm_byte_vec_t) 302 | fn C.wasm_module_deserialize(store &C.wasm_store_t, bytes &C.wasm_byte_vec_t) &C.wasm_module_t 303 | 304 | struct C.wasm_extern_t {} 305 | 306 | struct C.wasm_extern_vec_t { 307 | pub mut: 308 | size usize 309 | data &&C.wasm_extern_t = unsafe { 0 } 310 | } 311 | 312 | fn C.wasm_extern_vec_new(out &C.wasm_extern_vec_t, size usize, ptr &C.wasm_extern_t) 313 | fn C.wasm_extern_vec_delete(out &C.wasm_extern_vec_t) 314 | fn C.wasm_extern_vec_new_empty(out &C.wasm_extern_vec_t) 315 | fn C.wasm_extern_vec_new_uninitialized(out &C.wasm_extern_vec_t, size usize) 316 | fn C.wasm_extern_vec_copy(out &C.wasm_extern_vec_t, src &C.wasm_extern_vec_t) 317 | 318 | struct C.wasm_func_t {} 319 | 320 | struct C.wasm_global_t {} 321 | 322 | struct C.wasm_memory_t {} 323 | 324 | struct C.wasm_table_t {} 325 | 326 | pub type CWasmFuncCallback = fn (args &C.wasm_val_vec_t, results C.wasm_val_vec_t) &C.wasm_trap_t 327 | 328 | pub type CWasmFuncCallbackWithEnv = fn (env voidptr, args &C.wasm_val_vec_t, mut results C.wasm_val_vec_t) &C.wasm_trap_t 329 | 330 | fn C.wasm_extern_as_func(extern &C.wasm_extern_t) &C.wasm_func_t 331 | fn C.wasm_extern_as_global(extern &C.wasm_extern_t) &C.wasm_global_t 332 | fn C.wasm_extern_as_memory(extern &C.wasm_extern_t) &C.wasm_memory_t 333 | fn C.wasm_extern_as_table(extern &C.wasm_extern_t) &C.wasm_table_t 334 | fn C.wasm_func_as_extern(f &C.wasm_func_t) &C.wasm_extern_t 335 | fn C.wasm_global_as_extern(g &C.wasm_global_t) &C.wasm_extern_t 336 | fn C.wasm_memory_as_extern(m &C.wasm_memory_t) &C.wasm_extern_t 337 | fn C.wasm_table_as_extern(t &C.wasm_table_t) &C.wasm_extern_t 338 | fn C.wasm_func_call(func &C.wasm_func_t, args &C.wasm_val_vec_t, results &C.wasm_val_vec_t) &C.wasm_trap_t 339 | fn C.wasm_func_copy(func &C.wasm_func) &C.wasm_func 340 | fn C.wasm_func_delete(func &C.wasm_func_t) 341 | fn C.wasm_func_new(store &C.wasm_store_t, ftype &C.wasm_functype_t, callback CWasmFuncCallback) &C.wasm_func_t 342 | fn C.wasm_func_new_with_env(store &C.wasm_store_t, ftype &C.wasm_functype_t, callback CWasmFuncCallbackWithEnv, env voidptr, env_finalizer fn (voidptr)) &C.wasm_func_t 343 | fn C.wasm_func_param_arity(func &C.wasm_func_t) usize 344 | fn C.wasm_func_result_arity(func &C.wasm_func_t) usize 345 | fn C.wasm_func_type(func &C.wasm_func_t) &C.wasm_functype_t 346 | 347 | fn C.wasm_global_copy(g &C.wasm_global_t) &C.wasm_global_t 348 | fn C.wasm_global_delete(g &C.wasm_global_t) 349 | fn C.wasm_global_get(g &C.wasm_global_t, out &C.wasm_val_t) 350 | fn C.wasm_global_new(store &C.wasm_store_t, global_type &C.wasm_globaltype_t, val &C.wasm_val_t) &C.wasm_global_t 351 | fn C.wasm_global_set(g &C.wasm_global_t, val &C.wasm_val_t) 352 | fn C.wasm_global_same(x &C.wasm_global_t, y &C.wasm_global_t) bool 353 | fn C.wasm_global_type(g &C.wasm_global_t) &C.wasm_globaltype_t 354 | 355 | fn C.wasm_memory_copy(m &C.wasm_memory_t) &C.wasm_memory_t 356 | fn C.wasm_memory_delete(m &C.wasm_memory_t) 357 | fn C.wasm_memory_data(m &C.wasm_memory_t) voidptr 358 | fn C.wasm_memory_data_size(m &C.wasm_memory_t) usize 359 | fn C.wasm_memory_grow(m &C.wasm_memory_t, delta u32) bool 360 | fn C.wasm_memory_new(store &C.wasm_store_t, memory_type &C.wasm_memorytype_t) &C.wasm_memory_t 361 | fn C.wasm_memory_same(x &C.wasm_memory_t, y &C.wasm_memory_t) bool 362 | fn C.wasm_memory_size(m &C.wasm_memory_t) u32 363 | fn C.wasm_memory_type(m &C.wasm_memory_t) &C.wasm_memorytype_t 364 | 365 | fn C.wasm_table_copy(g &C.wasm_table_t) &C.wasm_table_t 366 | fn C.wasm_table_delete(g &C.wasm_table_t) 367 | fn C.wasm_table_grow(t &C.wasm_table_t, delta u32, init &C.wasm_ref_t) bool 368 | fn C.wasm_table_new(t &C.wasm_store_t, table_type &C.wasm_tabletype_t, init &C.wasm_ref_t) &C.wasm_table_t 369 | fn C.wasm_table_same(x &C.wasm_table_t, y &C.wasm_table_t) bool 370 | fn C.wasm_table_size(t &C.wasm_table_t) usize 371 | 372 | fn C.wasm_instance_new(store &C.wasm_store_t, mod &C.wasm_module_t, imports &C.wasm_extern_vec_t, trap &&C.wasm_trap_t) &C.wasm_instance_new 373 | fn C.wasm_instance_exports(instance &C.wasm_instance_t, out &C.wasm_extern_vec_t) 374 | fn C.wasm_instance_delete(instance &C.wasm_instance_t) 375 | 376 | fn C.wat2wasm(wat &C.wasm_byte_vec_t, out &C.wasm_byte_vec_t) 377 | 378 | fn C.wasmer_last_error_length() int 379 | fn C.wasmer_last_error_message(buffer voidptr, length int) int 380 | 381 | fn C.wasm_functype_new(params &C.wasm_valtype_vec_t, results &C.wasm_valtype_vec_t) &C.wasm_functype_t 382 | fn C.wasm_functype_params(f &C.wasm_functype_t) &C.wasm_valtype_vec_t 383 | fn C.wasm_functype_results(f &C.wasm_functype_t) &C.wasm_valtype_vec_t 384 | fn C.wasm_functype_copy(f &C.wasm_functype_t) &C.wasm_functype_t 385 | fn C.wasm_functype_delete(f &C.wasm_functype_t) 386 | fn C.wasm_functype_as_externtype(f &C.wasm_functype_t) &C.wasm_externtype_t 387 | 388 | fn C.wasm_externtype_kind(ext &C.wasm_externtype_t) u8 389 | fn C.wasm_externtype_delete(ext &C.wasm_externtype_t) 390 | fn C.wasm_externtype_copy(ext &C.wasm_externtype_t) &C.wasm_externtype_t 391 | fn C.wasm_externtype_as_functype(ext &C.wasm_externtype_t) &C.wasm_functype_t 392 | fn C.wasm_externtype_as_globaltype(ext &C.wasm_externtype_t) &C.wasm_globaltype_t 393 | fn C.wasm_externtype_as_memorytype(ext &C.wasm_externtype_t) &C.wasm_memorytype_t 394 | fn C.wasm_externtype_as_tabletype(ext &C.wasm_externtype_t) &C.wasm_tabletype_t 395 | 396 | fn C.wasm_extern_kind(ext &C.wasm_extern_t) ExternKind 397 | fn C.wasm_extern_type(ext &C.wasm_extern_t) &C.wasm_externtype_t 398 | 399 | fn C.wasm_exporttype_copy(e &C.wasm_exporttype_t) &C.wasm_exporttype_t 400 | fn C.wasm_exporttype_delete(e &C.wasm_exporttype_t) 401 | fn C.wasm_exporttype_name(e &C.wasm_exporttype_t) &C.wasm_byte_vec_t 402 | fn C.wasm_exporttype_type(e &C.wasm_exporttype_t) &C.wasm_externtype_t 403 | fn C.wasm_exporttype_new(name &C.wasm_byte_vec_t, extern_type &C.wasm_externtype_t) &C.wasm_exporttype_t 404 | 405 | fn C.wasm_globaltype_as_externtype(g &C.wasm_globaltype_t) &C.wasm_externtype_t 406 | fn C.wasm_globaltype_content(g &C.wasm_globaltype_t) &C.wasm_valtype_t 407 | fn C.wasm_globaltype_delete(g &C.wasm_globaltype_t) 408 | fn C.wasm_globaltype_new(valtype &C.wasm_valtype_t, mutability u8) &C.wasm_globaltype_t 409 | fn C.wasm_globaltype_mutability(g &C.wasm_globaltype_t) u8 410 | 411 | fn C.wasm_importtype_copy(e &C.wasm_importtype_t) &C.wasm_exporttype_t 412 | fn C.wasm_importtype_delete(e &C.wasm_importtype_t) 413 | fn C.wasm_importtype_name(e &C.wasm_importtype_t) &C.wasm_byte_vec_t 414 | fn C.wasm_importtype_type(e &C.wasm_importtype_t) &C.wasm_externtype_t 415 | fn C.wasm_importtype_new(mod &C.wasm_byte_vec_t, name &C.wasm_byte_vec_t, extern_type &C.wasm_externtype_t) &C.wasm_exporttype_t 416 | fn C.wasm_importtype_module(e &C.wasm_importtype_t) &C.wasm_byte_vec_t 417 | 418 | fn C.wasm_memorytype_new(limits &C.wasm_limits_t) &C.wasm_memorytype_t 419 | fn C.wasm_memorytype_limits(m &C.wasm_memorytype_t) &C.wasm_limits_t 420 | fn C.wasm_memorytype_delete(m &C.wasm_memorytype_t) 421 | fn C.wasm_memorytype_as_externtype(m &C.wasm_memorytype_t) &C.wasm_externtype_t 422 | 423 | fn C.wasm_tabletype_limits(t &C.wasm_tabletype_t) &C.wasm_limits_t 424 | fn C.wasm_tabletype_new(valtype &C.wasm_valtype_t, limits &C.wasm_limits_t) &C.wasm_tabletype_t 425 | fn C.wasm_tabletype_element(t &C.wasm_tabletype_t) &C.wasm_valtype_t 426 | fn C.wasm_tabletype_delete(t &C.wasm_tabletype_t) 427 | fn C.wasm_tabletype_as_externtype(t &C.wasm_tabletype_t) &C.wasm_externtype_t 428 | 429 | fn C.wasm_frame_copy(f &C.wasm_frame_t) &C.wasm_frame_t 430 | fn C.wasm_frame_delete(f &C.wasm_frame_t) 431 | fn C.wasm_frame_func_index(f &C.wasm_frame_t) u32 432 | fn C.wasm_frame_func_offset(f &C.wasm_frame_t) usize 433 | fn C.wasm_frame_instance(f &C.wasm_frame_t) &C.wasm_instance_t 434 | fn C.wasm_frame_module_offset(f &C.wasm_frame_t) usize 435 | -------------------------------------------------------------------------------- /wasmer/wasmer_test.v: -------------------------------------------------------------------------------- 1 | import wasmer 2 | 3 | fn test_add() { 4 | engine := wasmer.engine() 5 | store := wasmer.store(engine) 6 | defer { 7 | store.delete() 8 | engine.delete() 9 | } 10 | 11 | wasm := wasmer.wat2wasm('(module 12 | (func \$add (param \$lhs i32) (param \$rhs i32) (result i32) 13 | local.get \$lhs 14 | local.get \$rhs 15 | i32.add) 16 | (export "add" (func \$add)) 17 | )')? 18 | 19 | mod := wasmer.compile(store, wasm)? 20 | imports := []wasmer.Extern{} 21 | mut trap := wasmer.Trap{} 22 | defer { 23 | trap.delete() 24 | } 25 | instance := wasmer.instance(store, mod, imports, mut trap) 26 | 27 | func := instance.exports()[0].as_func()? 28 | mut results := [wasmer.val_i32(0)] 29 | trap = func.call([wasmer.val_i32(2), wasmer.val_i32(3)], mut results) 30 | 31 | assert !trap.is_set() 32 | assert results[0].i32() == 5 33 | } 34 | 35 | fn callback(mut args wasmer.Arguments) ? { 36 | println('Hello from WASM! Argument 0: ${args.arg(0)}') 37 | args.set_result(0, wasmer.val_i32(42))? 38 | return 39 | } 40 | 41 | fn test_callback() { 42 | mut config := wasmer.config() 43 | config.set_compiler(.cranelift) 44 | engine := wasmer.engine_with_config(config) 45 | defer { 46 | engine.delete() 47 | } 48 | 49 | store := wasmer.store(engine) 50 | defer { 51 | store.delete() 52 | } 53 | 54 | wasm := wasmer.wat2wasm(' 55 | (module 56 | (func \$host_function (import "" "host_function") (param i32) (result i32)) 57 | (func \$f (param \$arg i32) (result i32) 58 | (call \$host_function (local.get \$arg))) 59 | 60 | (export "f" (func \$f)) 61 | )')? 62 | 63 | mod := wasmer.compile(store, wasm)? 64 | 65 | ty := wasmer.func_type([wasmer.val_type(.wasm_i32)], [wasmer.val_type(.wasm_i32)]) 66 | defer { 67 | ty.delete() 68 | } 69 | func := wasmer.func(store, ty, callback) 70 | mut trap := wasmer.Trap{} 71 | defer { 72 | trap.delete() 73 | } 74 | instance := wasmer.instance(store, mod, [func.as_extern()], mut trap) 75 | exports := instance.exports() 76 | wasm_func := exports[0].as_func()? 77 | mut results := [wasmer.val_i32(0)] 78 | trap = wasm_func.call([wasmer.val_i32(44)], mut results) 79 | assert !trap.is_set() 80 | assert results[0].i32() == 42 81 | } 82 | 83 | fn test_memory() { 84 | mut config := wasmer.config() 85 | config.set_compiler(.cranelift) 86 | engine := wasmer.engine_with_config(config) 87 | defer { 88 | engine.delete() 89 | } 90 | 91 | store := wasmer.store(engine) 92 | defer { 93 | store.delete() 94 | } 95 | 96 | wasm := wasmer.wat2wasm(' 97 | (module 98 | (type \$mem_size_t (func (result i32))) 99 | (type \$get_at_t (func (param i32) (result i32))) 100 | (type \$set_at_t (func (param i32) (param i32))) 101 | (memory \$mem 1) 102 | (func \$get_at (type \$get_at_t) (param \$idx i32) (result i32) 103 | (i32.load (local.get \$idx))) 104 | (func \$set_at (type \$set_at_t) (param \$idx i32) (param \$val i32) 105 | (i32.store (local.get \$idx) (local.get \$val))) 106 | (func \$mem_size (type \$mem_size_t) (result i32) 107 | (memory.size)) 108 | (export "get_at" (func \$get_at)) 109 | (export "set_at" (func \$set_at)) 110 | (export "mem_size" (func \$mem_size)) 111 | (export "memory" (memory \$mem)))')? 112 | 113 | mod := wasmer.compile(store, wasm)? 114 | 115 | mut trap := wasmer.Trap{} 116 | defer { 117 | trap.delete() 118 | } 119 | instance := wasmer.instance(store, mod, [], mut trap) 120 | 121 | exports := instance.exports() 122 | 123 | get_at := exports[0].as_func()? 124 | set_at := exports[1].as_func()? 125 | mem_size := exports[2].as_func()? 126 | memory := exports[3].as_memory()? 127 | 128 | mem_addr := int(0x2220) 129 | ptr := wasmer.wasm_ptr(u32(mem_addr)) 130 | val := 0xFEFEFFE 131 | mut results := []wasmer.Val{} 132 | trap = set_at.call([wasmer.val_i32(mem_addr), wasmer.val_i32(val)], mut results) 133 | results.clear() 134 | assert !trap.is_set() 135 | assert *ptr.deref(memory)? == val 136 | 137 | results << wasmer.val_i32(0) 138 | trap = get_at.call([wasmer.val_i32(mem_addr)], mut results) 139 | 140 | assert !trap.is_set() 141 | assert results[0].i32() == val 142 | } 143 | --------------------------------------------------------------------------------