opam-2.0.0
Vova 3 years ago
commit 07f7735c50

@ -100,6 +100,26 @@ $ wasm3 hello.wasm
Hello, world!
```
### Zig C-code WASI app
Create `hello.c`:
```c
#include <stdio.h>
int main() {
printf("Hello, %s!\n", "world");
return 0;
}
```
Build and run:
```sh
$ zig build-exe -O ReleaseSmall -target wasm32-wasi hello.c -lc
$ wasm3 hello.wasm
Hello, world!
```
## Zig library
Create `add.zig`:

@ -139,7 +139,7 @@ namespace wasm3 {
/** @cond */
namespace detail {
void check_error(M3Result err) {
static inline void check_error(M3Result err) {
if (err != m3Err_none) {
throw error(err);
}
@ -378,23 +378,23 @@ namespace wasm3 {
M3Function *m_func = nullptr;
};
runtime environment::new_runtime(size_t stack_size_bytes) {
inline runtime environment::new_runtime(size_t stack_size_bytes) {
return runtime(m_env, stack_size_bytes);
}
module environment::parse_module(std::istream &in) {
inline module environment::parse_module(std::istream &in) {
return module(m_env, in);
}
module environment::parse_module(const uint8_t *data, size_t size) {
inline module environment::parse_module(const uint8_t *data, size_t size) {
return module(m_env, data, size);
}
void runtime::load(module &mod) {
inline void runtime::load(module &mod) {
mod.load_into(m_runtime.get());
}
function runtime::find_function(const char *name) {
inline function runtime::find_function(const char *name) {
return function(m_runtime, name);
}

@ -110,9 +110,9 @@ M3ImportContext, * IM3ImportContext;
// -------------------------------------------------------------------------------------------------------------------------------
# if defined(M3_IMPLEMENT_ERROR_STRINGS)
# define d_m3ErrorConst(LABEL, STRING) M3Result m3Err_##LABEL = { STRING };
# define d_m3ErrorConst(LABEL, STRING) extern const M3Result m3Err_##LABEL = { STRING };
# else
# define d_m3ErrorConst(LABEL, STRING) extern M3Result m3Err_##LABEL;
# define d_m3ErrorConst(LABEL, STRING) extern const M3Result m3Err_##LABEL;
# endif
// -------------------------------------------------------------------------------------------------------------------------------

Loading…
Cancel
Save