aboutsummaryrefslogtreecommitdiff
path: root/private_include
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2024-09-07 00:04:38 +0200
committerXavier Del Campo Romero <xavi92@disroot.org>2025-11-06 14:38:40 +0100
commit6d9d80362f9932bbc87e162b8ef7df06c73e27e1 (patch)
treee3e228c63fe26f07503f226de7fb5086b3dc2286 /private_include
First commit
Diffstat (limited to 'private_include')
-rw-r--r--private_include/nw/global.h20
-rw-r--r--private_include/nw/inst.h17
-rw-r--r--private_include/nw/interp.h39
-rw-r--r--private_include/nw/io.h40
-rw-r--r--private_include/nw/linear.h21
-rw-r--r--private_include/nw/log.h17
-rw-r--r--private_include/nw/mem.h20
-rw-r--r--private_include/nw/opcodes.h192
-rw-r--r--private_include/nw/ops.h90
-rw-r--r--private_include/nw/routines.h71
-rw-r--r--private_include/nw/stack.h24
-rw-r--r--private_include/nw/types.h19
12 files changed, 570 insertions, 0 deletions
diff --git a/private_include/nw/global.h b/private_include/nw/global.h
new file mode 100644
index 0000000..7f289d2
--- /dev/null
+++ b/private_include/nw/global.h
@@ -0,0 +1,20 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef GLOBAL_H
+#define GLOBAL_H
+
+#include <nanowasm/nw.h>
+
+enum nw_state nwp_global_load(struct nw_interp *i, struct nw_sm_io *io,
+ nw_varuint32 index);
+enum nw_state nwp_global_store(struct nw_interp *i, struct nw_sm_io *io,
+ nw_varuint32 index);
+
+#endif
diff --git a/private_include/nw/inst.h b/private_include/nw/inst.h
new file mode 100644
index 0000000..3a68440
--- /dev/null
+++ b/private_include/nw/inst.h
@@ -0,0 +1,17 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INST_H
+#define INST_H
+
+#include <nanowasm/nw.h>
+
+enum nw_state nwp_inst_run(struct nw_inst *i);
+
+#endif
diff --git a/private_include/nw/interp.h b/private_include/nw/interp.h
new file mode 100644
index 0000000..a6f0d74
--- /dev/null
+++ b/private_include/nw/interp.h
@@ -0,0 +1,39 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INTERP_H
+#define INTERP_H
+
+#include <nanowasm/nw.h>
+#include <nw/opcodes.h>
+#include <stddef.h>
+
+struct nwp_interp_set
+{
+ const enum opcode *opcodes;
+ size_t n;
+};
+
+struct nwp_ops
+{
+ void (*const *ops)(struct nw_interp *);
+ size_t n;
+};
+
+extern const struct nwp_interp_set nwp_interp_initexpr_set, nwp_interp_data_set;
+extern const struct nwp_ops nwp_ops;
+
+int nwp_interp_start(struct nw_interp *i,
+ const struct nw_interp_cfg *cfg, const struct nwp_interp_set *set);
+void nwp_interp_resume(struct nw_interp *i);
+void nwp_interp_limited(struct nw_interp *i);
+void nwp_interp_full(struct nw_interp *i);
+enum nw_state nwp_interp_run(struct nw_interp *i);
+
+#endif
diff --git a/private_include/nw/io.h b/private_include/nw/io.h
new file mode 100644
index 0000000..2b28847
--- /dev/null
+++ b/private_include/nw/io.h
@@ -0,0 +1,40 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef IO_H
+#define IO_H
+
+#include <nanowasm/nw.h>
+
+enum nw_state nwp_io_read(const struct nw_io_cfg *cfg, struct nw_sm_io *io,
+ void *user);
+enum nw_state nwp_varint1(const struct nw_io_cfg *cfg, struct nw_sm_leb128 *l,
+ nw_varint1 *out, void *user);
+enum nw_state nwp_varint7(const struct nw_io_cfg *cfg, struct nw_sm_leb128 *l,
+ nw_varint7 *out, void *user);
+enum nw_state nwp_varint32(const struct nw_io_cfg *cfg, struct nw_sm_leb128 *l,
+ nw_varint32 *out, void *user);
+enum nw_state nwp_varint64(const struct nw_io_cfg *cfg, struct nw_sm_leb128 *l,
+ nw_varint64 *out, void *user);
+enum nw_state nwp_varuint1(const struct nw_io_cfg *cfg, struct nw_sm_leb128 *l,
+ nw_varuint1 *out, void *user);
+enum nw_state nwp_varuint7(const struct nw_io_cfg *cfg, struct nw_sm_leb128 *l,
+ nw_varuint7 *out, void *user);
+enum nw_state nwp_varuint32(const struct nw_io_cfg *cfg, struct nw_sm_leb128 *l,
+ nw_varuint32 *out, void *user);
+enum nw_state nwp_varuint64(const struct nw_io_cfg *cfg, struct nw_sm_leb128 *l,
+ nw_varuint64 *out, void *user);
+enum nw_state nwp_leb128(const struct nw_io_cfg *cfg, struct nw_sm_leb128 *l,
+ unsigned maxbits, int sign, void *user);
+unsigned long nwp_leuint32(const struct nw_leuint32 *v);
+void nwp_toleuint32(unsigned long v, struct nw_leuint32 *out);
+void nwp_leuint64(const struct nw_leuint64 *v, struct nw_ull *out);
+void nwp_toleuint64(const struct nw_ull *v, struct nw_leuint64 *out);
+
+#endif
diff --git a/private_include/nw/linear.h b/private_include/nw/linear.h
new file mode 100644
index 0000000..a316e77
--- /dev/null
+++ b/private_include/nw/linear.h
@@ -0,0 +1,21 @@
+
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef LINEAR_H
+#define LINEAR_H
+
+#include <nanowasm/types.h>
+
+enum nw_state nwp_linear_load(struct nw_interp *i, struct nw_sm_io *io,
+ unsigned long offset);
+enum nw_state nwp_linear_store(struct nw_interp *i, struct nw_sm_io *io,
+ unsigned long offset);
+
+#endif
diff --git a/private_include/nw/log.h b/private_include/nw/log.h
new file mode 100644
index 0000000..c5e2870
--- /dev/null
+++ b/private_include/nw/log.h
@@ -0,0 +1,17 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef LOG_H
+#define LOG_H
+
+#ifdef NW_LOG
+int nwp_log(const char *fmt, ...);
+#endif
+
+#endif
diff --git a/private_include/nw/mem.h b/private_include/nw/mem.h
new file mode 100644
index 0000000..b1aa7ce
--- /dev/null
+++ b/private_include/nw/mem.h
@@ -0,0 +1,20 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef MEM_H
+#define MEM_H
+
+#include <nanowasm/nw.h>
+
+enum nw_state nwp_mem_store(const struct nw_mem_cfg *const cfg,
+ struct nw_sm_io *io, nw_varuint32 offset, void *user);
+enum nw_state nwp_mem_load(const struct nw_mem_cfg *const cfg,
+ struct nw_sm_io *io, nw_varuint32 offset, void *user);
+
+#endif
diff --git a/private_include/nw/opcodes.h b/private_include/nw/opcodes.h
new file mode 100644
index 0000000..410bd97
--- /dev/null
+++ b/private_include/nw/opcodes.h
@@ -0,0 +1,192 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef OPCODES_H
+#define OPCODES_H
+
+enum opcode
+{
+ OP_UNREACHABLE,
+ OP_NOP,
+ OP_BLOCK,
+ OP_LOOP,
+ OP_IF,
+ OP_ELSE,
+ OP_END = 0xb,
+ OP_BR,
+ OP_BR_IF,
+ OP_BR_TABLE,
+ OP_RETURN,
+ OP_CALL,
+ OP_CALL_INDIRECT,
+ OP_DROP = 0x1a,
+ OP_SELECT,
+ OP_GET_LOCAL = 0x20,
+ OP_SET_LOCAL,
+ OP_TEE_LOCAL,
+ OP_GET_GLOBAL,
+ OP_SET_GLOBAL,
+ OP_I32_LOAD = 0x28,
+ OP_I64_LOAD,
+ OP_F32_LOAD,
+ OP_F64_LOAD,
+ OP_I32_LOAD8_S,
+ OP_I32_LOAD8_U,
+ OP_I32_LOAD16_S,
+ OP_I32_LOAD16_U,
+ OP_I64_LOAD8_S,
+ OP_I64_LOAD8_U,
+ OP_I64_LOAD16_S,
+ OP_I64_LOAD16_U,
+ OP_I64_LOAD32_S,
+ OP_I64_LOAD32_U,
+ OP_I32_STORE,
+ OP_I64_STORE,
+ OP_F32_STORE,
+ OP_F64_STORE,
+ OP_I32_STORE8,
+ OP_I32_STORE16,
+ OP_I64_STORE8,
+ OP_I64_STORE16,
+ OP_I64_STORE32,
+ OP_CURRENT_MEMORY,
+ OP_GROW_MEMORY,
+ OP_I32_CONST,
+ OP_I64_CONST,
+ OP_F32_CONST,
+ OP_F64_CONST,
+ OP_I32_EQZ,
+ OP_I32_EQ,
+ OP_I32_NE,
+ OP_I32_LT_S,
+ OP_I32_LT_U,
+ OP_I32_GT_S,
+ OP_I32_GT_U,
+ OP_I32_LE_S,
+ OP_I32_LE_U,
+ OP_I32_GE_S,
+ OP_I32_GE_U,
+ OP_I64_EQZ,
+ OP_I64_EQ,
+ OP_I64_NE,
+ OP_I64_LT_S,
+ OP_I64_LT_U,
+ OP_I64_GT_S,
+ OP_I64_GT_U,
+ OP_I64_LE_S,
+ OP_I64_LE_U,
+ OP_I64_GE_S,
+ OP_I64_GE_U,
+ OP_F32_EQ,
+ OP_F32_NE,
+ OP_F32_LT,
+ OP_F32_GT,
+ OP_F32_LE,
+ OP_F32_GE,
+ OP_F64_EQ,
+ OP_F64_NE,
+ OP_F64_LT,
+ OP_F64_GT,
+ OP_F64_LE,
+ OP_F64_GE,
+ OP_I32_CLZ,
+ OP_I32_CTZ,
+ OP_I32_POPCNT,
+ OP_I32_ADD,
+ OP_I32_SUB,
+ OP_I32_MUL,
+ OP_I32_DIV_S,
+ OP_I32_DIV_U,
+ OP_I32_REM_S,
+ OP_I32_REM_U,
+ OP_I32_AND,
+ OP_I32_OR,
+ OP_I32_XOR,
+ OP_I32_SHL,
+ OP_I32_SHR_S,
+ OP_I32_SHR_U,
+ OP_I32_ROTL,
+ OP_I32_ROTR,
+ OP_I64_CLZ,
+ OP_I64_CTZ,
+ OP_I64_POPCNT,
+ OP_I64_ADD,
+ OP_I64_SUB,
+ OP_I64_MUL,
+ OP_I64_DIV_S,
+ OP_I64_DIV_U,
+ OP_I64_REM_S,
+ OP_I64_REM_U,
+ OP_I64_AND,
+ OP_I64_OR,
+ OP_I64_XOR,
+ OP_I64_SHL,
+ OP_I64_SHR_S,
+ OP_I64_SHR_U,
+ OP_I64_ROTL,
+ OP_I64_ROTR,
+ OP_F32_ABS,
+ OP_F32_NEG,
+ OP_F32_CEIL,
+ OP_F32_FLOOR,
+ OP_F32_TRUNC,
+ OP_F32_NEAREST,
+ OP_F32_SQRT,
+ OP_F32_ADD,
+ OP_F32_SUB,
+ OP_F32_MUL,
+ OP_F32_DIV,
+ OP_F32_MIN,
+ OP_F32_MAX,
+ OP_F32_COPYSIGN,
+ OP_F64_ABS,
+ OP_F64_NEG,
+ OP_F64_CEIL,
+ OP_F64_FLOOR,
+ OP_F64_TRUNC,
+ OP_F64_NEAREST,
+ OP_F64_SQRT,
+ OP_F64_ADD,
+ OP_F64_SUB,
+ OP_F64_MUL,
+ OP_F64_DIV,
+ OP_F64_MIN,
+ OP_F64_MAX,
+ OP_F64_COPYSIGN,
+ OP_I32_WRAP_I64,
+ OP_I32_TRUNC_S_F32,
+ OP_I32_TRUNC_U_F32,
+ OP_I32_TRUNC_S_F64,
+ OP_I32_TRUNC_U_F64,
+ OP_I64_EXTEND_S_I32,
+ OP_I64_EXTEND_U_I32,
+ OP_I64_TRUNC_S_F32,
+ OP_I64_TRUNC_U_F32,
+ OP_I64_TRUNC_S_F64,
+ OP_I64_TRUNC_U_F64,
+ OP_F32_CONVERT_S_I32,
+ OP_F32_CONVERT_U_I32,
+ OP_F32_CONVERT_S_I64,
+ OP_F32_CONVERT_U_I64,
+ OP_F32_DEMOTE_F64,
+ OP_F64_CONVERT_S_I32,
+ OP_F64_CONVERT_U_I32,
+ OP_F64_CONVERT_S_I64,
+ OP_F64_CONVERT_U_I64,
+ OP_F64_PROMOTE_F32,
+ OP_I32_REINTERPRET_F32,
+ OP_I64_REINTERPRET_F64,
+ OP_F32_REINTERPRET_I32,
+ OP_F64_REINTERPRET_I64,
+ OP_MISC = 0xfc
+};
+
+const char *nwp_op_tostr(enum opcode op);
+
+#endif
diff --git a/private_include/nw/ops.h b/private_include/nw/ops.h
new file mode 100644
index 0000000..dce95a6
--- /dev/null
+++ b/private_include/nw/ops.h
@@ -0,0 +1,90 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef OPS_H
+#define OPS_H
+
+#include <nanowasm/nw.h>
+#include <nw/opcodes.h>
+#include <nw/types.h>
+
+void nwp_op_unreachable(struct nw_interp *i);
+void nwp_op_nop(struct nw_interp *i);
+void nwp_op_block(struct nw_interp *i);
+void nwp_op_loop(struct nw_interp *i);
+void nwp_op_if(struct nw_interp *i);
+void nwp_op_else(struct nw_interp *i);
+void nwp_op_end(struct nw_interp *i);
+void nwp_op_br(struct nw_interp *i);
+void nwp_op_br_if(struct nw_interp *i);
+void nwp_op_br_table(struct nw_interp *i);
+void nwp_op_return(struct nw_interp *i);
+void nwp_op_call(struct nw_interp *i);
+void nwp_op_call_indirect(struct nw_interp *i);
+void nwp_op_drop(struct nw_interp *i);
+void nwp_op_get_local(struct nw_interp *i);
+void nwp_op_set_local(struct nw_interp *i);
+void nwp_op_tee_local(struct nw_interp *i);
+void nwp_op_set_global(struct nw_interp *i);
+void nwp_op_get_global(struct nw_interp *i);
+void nwp_op_set_global(struct nw_interp *i);
+void nwp_op_i32_load(struct nw_interp *i);
+void nwp_op_i32_load8_u(struct nw_interp *i);
+void nwp_op_i32_store(struct nw_interp *i);
+void nwp_op_i64_store(struct nw_interp *i);
+void nwp_op_current_memory(struct nw_interp *i);
+void nwp_op_i32_const(struct nw_interp *i);
+void nwp_op_i64_const(struct nw_interp *i);
+void nwp_op_f32_const(struct nw_interp *i);
+void nwp_op_f64_const(struct nw_interp *i);
+void nwp_op_i32_add(struct nw_interp *i);
+void nwp_op_i32_sub(struct nw_interp *i);
+void nwp_op_i32_mul(struct nw_interp *i);
+void nwp_op_i32_and(struct nw_interp *i);
+void nwp_op_i32_or(struct nw_interp *i);
+void nwp_op_i32_eqz(struct nw_interp *i);
+void nwp_op_i32_eq(struct nw_interp *i);
+void nwp_op_i32_ne(struct nw_interp *i);
+void nwp_op_i32_lt_s(struct nw_interp *i);
+void nwp_op_i32_ge_s(struct nw_interp *i);
+void nwp_op_i32_ge_u(struct nw_interp *i);
+
+void nwp_op_check_no_immediate(struct nw_mod *m);
+void nwp_op_check_block(struct nw_mod *m);
+void nwp_op_check_loop(struct nw_mod *m);
+void nwp_op_check_end(struct nw_mod *m);
+void nwp_op_check_relative_depth(struct nw_mod *m);
+void nwp_op_check_br_table(struct nw_mod *m);
+void nwp_op_check_call(struct nw_mod *m);
+void nwp_op_check_call_indirect(struct nw_mod *m);
+void nwp_op_check_local_index(struct nw_mod *m);
+void nwp_op_check_global_index(struct nw_mod *m);
+void nwp_op_check_memory_immediate(struct nw_mod *m);
+void nwp_op_check_varuint1(struct nw_mod *m);
+void nwp_op_check_varint32(struct nw_mod *m);
+void nwp_op_check_varint64(struct nw_mod *m);
+void nwp_op_check_uint32(struct nw_mod *m);
+void nwp_op_check_uint64(struct nw_mod *m);
+void nwp_op_check_misc(struct nw_mod *m);
+
+struct nwp_check_op
+{
+ enum opcode start, end;
+ void (*f)(struct nw_mod *);
+};
+
+struct nwp_check_ops
+{
+ const struct nwp_check_op *ops;
+ size_t n;
+};
+
+extern const struct nwp_check_ops nwp_check_ops;
+
+#endif
diff --git a/private_include/nw/routines.h b/private_include/nw/routines.h
new file mode 100644
index 0000000..974f6da
--- /dev/null
+++ b/private_include/nw/routines.h
@@ -0,0 +1,71 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef ROUTINES_H
+#define ROUTINES_H
+
+#include <nanowasm/nw.h>
+
+void nwp_check_magic(struct nw_mod *m);
+void nwp_check_version(struct nw_mod *m);
+void nwp_section(struct nw_mod *m);
+void nwp_section_custom(struct nw_mod *m);
+void nwp_section_type(struct nw_mod *m);
+void nwp_section_import(struct nw_mod *m);
+void nwp_section_function(struct nw_mod *m);
+void nwp_section_table(struct nw_mod *m);
+void nwp_section_memory(struct nw_mod *m);
+void nwp_section_global(struct nw_mod *m);
+void nwp_section_export(struct nw_mod *m);
+void nwp_section_start(struct nw_mod *m);
+void nwp_section_element(struct nw_mod *m);
+void nwp_section_code(struct nw_mod *m);
+void nwp_section_data(struct nw_mod *m);
+void nwp_section_data_count(struct nw_mod *m);
+void nwp_section_to(struct nw_mod *m);
+void nwp_section_fti(struct nw_mod *m);
+void nwp_section_fbo(struct nw_mod *m);
+void nwp_section_lo(struct nw_mod *m);
+void nwp_section_iti(struct nw_mod *m);
+void nwp_section_skip(struct nw_mod *m);
+enum nw_state nwp_section_exit(struct nw_mod *m);
+
+void nwp_init_globals(struct nw_inst *i,
+ enum nw_state (*next)(struct nw_inst *));
+void nwp_init_data(struct nw_inst *i,
+ enum nw_state (*next)(struct nw_inst *));
+
+enum nw_state nwp_execute(struct nw_interp *i);
+void nwp_find_export(struct nw_interp *i, const char *sym,
+ enum nw_state (*next)(struct nw_interp *));
+void nwp_call(struct nw_interp *i, nw_varuint32 index);
+void nwp_call_function(struct nw_interp *i, nw_varuint32 index);
+void nwp_call_import(struct nw_interp *i, nw_varuint32 index);
+void nwp_find_function(struct nw_interp *i, const struct nw_fn *fn,
+ void (*next)(struct nw_interp *));
+void nwp_get_function_type(struct nw_interp *i, nw_varuint32 index,
+ enum nw_state (*next)(struct nw_interp *));
+void nwp_get_import_type(struct nw_interp *i, struct nw_get_import_type *t,
+ nw_varuint32 index, enum nw_state (*next)(struct nw_interp *));
+void nwp_mem_imm(struct nw_interp *i, void (*next)(struct nw_interp *));
+void nwp_unwind(struct nw_interp *i);
+void nwp_break(struct nw_interp *i, nw_varuint32 relative_depth);
+void nwp_find_param(struct nw_interp *i, struct nw_find_param *f,
+ nw_varuint32 index, enum nw_state (*next)(struct nw_interp *), void *args);
+void nwp_find_local(struct nw_interp *i, struct nw_find_local *f,
+ nw_varuint32 index, enum nw_state (*next)(struct nw_interp *), void *args);
+void nwp_set_local(struct nw_interp *i,
+ enum nw_state (*next)(struct nw_interp *));
+void nwp_arithm(struct nw_interp *i, enum nw_type t,
+ int (*op)(const struct nw_i_sm_arithm_out *, union nw_value *));
+void nwp_unary(struct nw_interp *i, enum nw_type t,
+ int (*op)(const union nw_value *, union nw_value *));
+void nwp_start_block(struct nw_interp *i);
+
+#endif
diff --git a/private_include/nw/stack.h b/private_include/nw/stack.h
new file mode 100644
index 0000000..332b4f5
--- /dev/null
+++ b/private_include/nw/stack.h
@@ -0,0 +1,24 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef STACK_H
+#define STACK_H
+
+#include <nanowasm/nw.h>
+#include <stddef.h>
+
+size_t nwp_stack_ptr(const struct nw_interp *i);
+enum nw_state nwp_stack_push(struct nw_interp *i, struct nw_sm_io *io);
+enum nw_state nwp_stack_pop(struct nw_interp *i, struct nw_sm_io *io);
+enum nw_state nwp_stack_read(struct nw_interp *i, struct nw_sm_io *io,
+ size_t offset);
+enum nw_state nwp_stack_write(struct nw_interp *i, struct nw_sm_io *io,
+ size_t offset);
+
+#endif
diff --git a/private_include/nw/types.h b/private_include/nw/types.h
new file mode 100644
index 0000000..99e6f55
--- /dev/null
+++ b/private_include/nw/types.h
@@ -0,0 +1,19 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef TYPES_H
+#define TYPES_H
+
+#include <nanowasm/nw.h>
+#include <stddef.h>
+
+int nwp_get_type(nw_varint7 type, enum nw_type *vtype);
+int nwp_type_sz(enum nw_type type, size_t *sz);
+
+#endif