MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / Val

Class Val

crates/c-api/include/wasm.hh:502–586  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

500// Values
501
502class Val {
503 ValKind kind_;
504 union impl {
505 int32_t i32;
506 int64_t i64;
507 float32_t f32;
508 float64_t f64;
509 Ref* ref;
510 } impl_;
511
512 Val(ValKind kind, impl impl) : kind_(kind), impl_(impl) {}
513
514public:
515 Val() : kind_(ValKind::EXTERNREF) { impl_.ref = nullptr; }
516 explicit Val(int32_t i) : kind_(ValKind::I32) { impl_.i32 = i; }
517 explicit Val(int64_t i) : kind_(ValKind::I64) { impl_.i64 = i; }
518 explicit Val(float32_t z) : kind_(ValKind::F32) { impl_.f32 = z; }
519 explicit Val(float64_t z) : kind_(ValKind::F64) { impl_.f64 = z; }
520 explicit Val(own<Ref>&& r) : kind_(ValKind::EXTERNREF) { impl_.ref = r.release(); }
521
522 Val(Val&& that) : kind_(that.kind_), impl_(that.impl_) {
523 if (is_ref()) that.impl_.ref = nullptr;
524 }
525
526 ~Val() {
527 reset();
528 }
529
530 auto is_num() const -> bool { return wasm::is_num(kind_); }
531 auto is_ref() const -> bool { return wasm::is_ref(kind_); }
532
533 static auto i32(int32_t x) -> Val { return Val(x); }
534 static auto i64(int64_t x) -> Val { return Val(x); }
535 static auto f32(float32_t x) -> Val { return Val(x); }
536 static auto f64(float64_t x) -> Val { return Val(x); }
537 static auto ref(own<Ref>&& x) -> Val { return Val(std::move(x)); }
538 template<class T> inline static auto make(T x) -> Val;
539 template<class T> inline static auto make(own<T>&& x) -> Val;
540
541 void reset() {
542 if (is_ref() && impl_.ref) {
543 destroyer()(impl_.ref);
544 impl_.ref = nullptr;
545 }
546 }
547
548 void reset(Val& that) {
549 reset();
550 kind_ = that.kind_;
551 impl_ = that.impl_;
552 if (is_ref()) that.impl_.ref = nullptr;
553 }
554
555 auto operator=(Val&& that) -> Val& {
556 reset(that);
557 return *this;
558 }
559

Callers 15

i32Method · 0.70
i64Method · 0.70
f32Method · 0.70
f64Method · 0.70
refMethod · 0.70
copyMethod · 0.70
make<int32_t>Method · 0.70
make<int64_t>Method · 0.70
make<float32_t>Method · 0.70
make<float64_t>Method · 0.70
make<Ref>Method · 0.70
make<uint32_t>Method · 0.70

Calls

no outgoing calls

Tested by 3

TESTFunction · 0.40
TESTFunction · 0.40
TESTFunction · 0.40