aboutsummaryrefslogtreecommitdiff
path: root/src/op/i64_const.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/op/i64_const.c')
-rw-r--r--src/op/i64_const.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/op/i64_const.c b/src/op/i64_const.c
new file mode 100644
index 0000000..20d539b
--- /dev/null
+++ b/src/op/i64_const.c
@@ -0,0 +1,58 @@
+/*
+ * 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/.
+ */
+
+#include <nanowasm/nw.h>
+#include <nw/io.h>
+#include <nw/interp.h>
+#include <nw/log.h>
+#include <nw/ops.h>
+#include <nw/stack.h>
+
+static enum nw_state push(struct nw_interp *const i)
+{
+ struct nw_i_sm_i64_const *const c = &i->sm.i64_const;
+ const enum nw_state n = nwp_stack_push(i, &c->io);
+
+ if (n)
+ return n;
+
+ i->push_type = NW_TYPE_I64;
+ nwp_interp_resume(i);
+ return NW_AGAIN;
+}
+
+static enum nw_state get_value(struct nw_interp *const i)
+{
+ const struct nw_io_cfg *const cfg = &i->cfg.io;
+ struct nw_i_sm_i64_const *const c = &i->sm.i64_const;
+ struct nw_sm_leb128 *const l = &c->leb128;
+ const enum nw_state n = nwp_varuint64(cfg, l, &c->value, cfg->user);
+
+ if (n)
+ return n;
+ else
+ {
+ struct nw_sm_io io = {0};
+
+ io.buf = &c->value;
+ io.n = sizeof c->value;
+ c->io = io;
+ i->next = push;
+ }
+
+ return NW_AGAIN;
+}
+
+void nwp_op_i64_const(struct nw_interp *const i)
+{
+ const struct nw_i_sm_i64_const c = {{0}};
+
+ i->next = get_value;
+ i->sm.i64_const = c;
+}