This commit is contained in:
2026-06-22 03:48:04 -06:00
parent d13edd2ca0
commit 18dd53f02a
9 changed files with 56 additions and 65 deletions
+15 -20
View File
@@ -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