hello
This commit is contained in:
+15
-20
@@ -1,27 +1,22 @@
|
||||
(module
|
||||
;; Correct module name: stdio, not stdout
|
||||
(import "wasi:cli/stdio@0.2.6" "get-stdout"
|
||||
(func $get_stdout (result i32)))
|
||||
(import "wasi:cli/stdout@0.2.6" "get-stdout"
|
||||
(func $get-stdout (result i32)))
|
||||
|
||||
;; Write and flush a buffer.
|
||||
(import "wasi:io/streams@0.2.0" "blocking-write-and-flush"
|
||||
(func $bwrite (param i32 i32 i32) (result i32)))
|
||||
(import
|
||||
"wasi:io/streams@0.2.6"
|
||||
"[method]output-stream.blocking-write-and-flush"
|
||||
(func $print (param i32 i32 i32 i32)))
|
||||
|
||||
(memory (export "memory") 1)
|
||||
(memory 1)
|
||||
(export "memory" (memory 0))
|
||||
|
||||
(data (i32.const 0) "Hello, World!\n")
|
||||
(data (i32.const 16) "hello worms\n")
|
||||
|
||||
(func (export "main")
|
||||
(local $stdout i32)
|
||||
;; Get the stdout stream handle
|
||||
call $get_stdout
|
||||
local.set $stdout
|
||||
|
||||
;; Write "Hello, World!\n" (14 bytes) to stdout
|
||||
local.get $stdout
|
||||
i32.const 0
|
||||
i32.const 14
|
||||
call $bwrite
|
||||
drop ;; ignore the return value (0 = success)
|
||||
)
|
||||
)
|
||||
(func $hello (export "hello")
|
||||
(call $print
|
||||
(call $get-stdout)
|
||||
(i32.const 16) ;; offset to print
|
||||
(i32.const 12) ;; length to print
|
||||
(i32.const 32)))) ;; offset for result
|
||||
|
||||
Reference in New Issue
Block a user