Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rossberg committed Mar 21, 2023
1 parent f4d055f commit c498c73
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion example/callback.c
Expand Up @@ -22,7 +22,7 @@ void wasm_val_print(wasm_val_t val) {
case WASM_F64: {
printf("%g", val.of.f64);
} break;
case WASM_ANYREF:
case WASM_EXTERNREF:
case WASM_FUNCREF: {
if (val.of.ref == NULL) {
printf("null");
Expand Down
2 changes: 1 addition & 1 deletion example/callback.cc
Expand Up @@ -21,7 +21,7 @@ auto operator<<(std::ostream& out, const wasm::Val& val) -> std::ostream& {
case wasm::ValKind::F64: {
out << val.f64();
} break;
case wasm::ValKind::ANYREF:
case wasm::ValKind::EXTERNREF:
case wasm::ValKind::FUNCREF: {
if (val.ref() == nullptr) {
out << "null";
Expand Down
8 changes: 4 additions & 4 deletions example/hostref.c
Expand Up @@ -159,7 +159,7 @@ int main(int argc, const char* argv[]) {
// Create external callback function.
printf("Creating callback...\n");
own wasm_functype_t* callback_type = wasm_functype_new_1_1(
wasm_valtype_new(WASM_ANYREF), wasm_valtype_new(WASM_ANYREF));
wasm_valtype_new(WASM_EXTERNREF), wasm_valtype_new(WASM_EXTERNREF));
own wasm_func_t* callback_func =
wasm_func_new(store, callback_type, callback);

Expand Down Expand Up @@ -207,7 +207,7 @@ int main(int argc, const char* argv[]) {
check(wasm_ref_copy(host2), host2);

own wasm_val_t val;
val.kind = WASM_ANYREF;
val.kind = WASM_EXTERNREF;
val.of.ref = wasm_ref_copy(host1);
check(wasm_ref_copy(val.of.ref), host1);
own wasm_ref_t* ref = val.of.ref;
Expand All @@ -225,13 +225,13 @@ int main(int argc, const char* argv[]) {
check(call_v_r(global_get), NULL);

wasm_global_get(global, &val);
assert(val.kind == WASM_ANYREF);
assert(val.kind == WASM_EXTERNREF);
check(val.of.ref, NULL);
val.of.ref = host2;
wasm_global_set(global, &val);
check(call_v_r(global_get), host2);
wasm_global_get(global, &val);
assert(val.kind == WASM_ANYREF);
assert(val.kind == WASM_EXTERNREF);
check(val.of.ref, host2);

printf("Accessing table...\n");
Expand Down
4 changes: 2 additions & 2 deletions example/hostref.cc
Expand Up @@ -144,8 +144,8 @@ void run() {
// Create external callback function.
std::cout << "Creating callback..." << std::endl;
auto callback_type = wasm::FuncType::make(
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::ValKind::ANYREF)),
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::ValKind::ANYREF))
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::ValKind::EXTERNREF)),
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::ValKind::EXTERNREF))
);
auto callback_func = wasm::Func::make(store, callback_type.get(), callback);

Expand Down
16 changes: 8 additions & 8 deletions example/hostref.wat
@@ -1,24 +1,24 @@
(module
(import "" "f" (func $fun (param anyref) (result anyref)))
(import "" "f" (func $fun (param externref) (result externref)))

(global $glob (export "global") (mut anyref) (ref.null))
(table $tab (export "table") 10 anyref)
(global $glob (export "global") (mut externref) (ref.null))
(table $tab (export "table") 10 externref)

(func (export "global.set") (param $r anyref)
(func (export "global.set") (param $r externref)
(global.set $glob (local.get $r))
)
(func (export "global.get") (result anyref)
(func (export "global.get") (result externref)
(global.get $glob)
)

(func (export "table.set") (param $i i32) (param $r anyref)
(func (export "table.set") (param $i i32) (param $r externref)
(table.set $tab (local.get $i) (local.get $r))
)
(func (export "table.get") (param $i i32) (result anyref)
(func (export "table.get") (param $i i32) (result externref)
(table.get $tab (local.get $i))
)

(func (export "func.call") (param $r anyref) (result anyref)
(func (export "func.call") (param $r externref) (result externref)
(call $fun (local.get $r))
)
)
2 changes: 1 addition & 1 deletion example/reflect.c
Expand Up @@ -25,7 +25,7 @@ void print_valtype(const wasm_valtype_t* type) {
case WASM_I64: printf("i64"); break;
case WASM_F32: printf("f32"); break;
case WASM_F64: printf("f64"); break;
case WASM_ANYREF: printf("anyref"); break;
case WASM_EXTERNREF: printf("externref"); break;
case WASM_FUNCREF: printf("funcref"); break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/reflect.cc
Expand Up @@ -27,7 +27,7 @@ auto operator<<(std::ostream& out, const wasm::ValType& type) -> std::ostream& {
case wasm::ValKind::I64: return out << "i64";
case wasm::ValKind::F32: return out << "f32";
case wasm::ValKind::F64: return out << "f64";
case wasm::ValKind::ANYREF: return out << "anyref";
case wasm::ValKind::EXTERNREF: return out << "externref";
case wasm::ValKind::FUNCREF: return out << "funcref";
}
return out;
Expand Down

0 comments on commit c498c73

Please sign in to comment.