Debian Codegraph @

crates/wit-component/tests/components/adapt-export-with-post-return/adapt-old.wat

raw
1 ;; This example represents adapting modules which use an early version of the
2 ;; canonical ABI, back when `cabi_realloc` was named `canonical_abi_realloc` and
3 ;; had a friend named `canonical_abi_free`. Such modules are pretty easy to
4 ;; adapt since the adapter can use the main module's allocator for both lowering
5 ;; and post-return functions.
6 ;;
7 ;; See https://github.com/fermyon/spin-componentize for a real-world example.
8
9 (module
10 (import "__main_module__" "canonical_abi_realloc" (func $realloc (param i32 i32 i32 i32) (result i32)))
11 (import "__main_module__" "canonical_abi_free" (func $free (param i32 i32 i32)))
12 (import "env" "memory" (memory 0))
13 (global $__stack_pointer (mut i32) i32.const 0)
14 (global $allocation_state (mut i32) i32.const 0)
15
16 (func (export "foo:foo/new#foo") (result i32)
17 ;; This is a dummy, non-working implementation, just to make gc.rs do what
18 ;; we want, which is to treat this adapter as if it uses the main module's
19 ;; allocator to allocate and free memory.
20
21 global.get $__stack_pointer
22 global.get $allocation_state
23 (call $realloc (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0))
24 unreachable
25 )
26
27 (func (export "cabi_post_foo:foo/new#foo") (param i32)
28 ;; another dummy implementation
29
30 (call $free (i32.const 0) (i32.const 0) (i32.const 0))
31 unreachable
32 )
33 )