* Add examples of linking and WASI This commit adds two example programs, one for linking two modules together and one for instantiating WASI. The linkage example additionally uses WASI to get some meaningful output at this time. cc #1272 * Add examples to the book as well * More links! * Ignore examples from rustdoc testsing * More example updates * More ignored
34 lines
816 B
Plaintext
34 lines
816 B
Plaintext
(module
|
|
(type $fd_write_ty (func (param i32 i32 i32 i32) (result i32)))
|
|
(import "wasi_snapshot_preview1" "fd_write" (func $fd_write (type $fd_write_ty)))
|
|
|
|
(func (export "double") (param i32) (result i32)
|
|
local.get 0
|
|
i32.const 2
|
|
i32.mul
|
|
)
|
|
|
|
(func (export "log") (param i32 i32)
|
|
;; store the pointer in the first iovec field
|
|
i32.const 4
|
|
local.get 0
|
|
i32.store
|
|
|
|
;; store the length in the first iovec field
|
|
i32.const 4
|
|
local.get 1
|
|
i32.store offset=4
|
|
|
|
;; call the `fd_write` import
|
|
i32.const 1 ;; stdout fd
|
|
i32.const 4 ;; iovs start
|
|
i32.const 1 ;; number of iovs
|
|
i32.const 0 ;; where to write nwritten bytes
|
|
call $fd_write
|
|
drop
|
|
)
|
|
|
|
(memory (export "memory") 2)
|
|
(global (export "memory_offset") i32 (i32.const 65536))
|
|
)
|