Created
October 9, 2019 11:30
-
-
Save appcypher/e1c748ad72fa966753ec6bff8b75c0a7 to your computer and use it in GitHub Desktop.
WASI WAT EXAMPLES
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(module | |
(import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) | |
(import "wasi_unstable" "fd_read" (func $fd_read (param i32 i32 i32 i32) (result i32))) | |
(memory 10) | |
(export "memory" (memory 0)) | |
;; prompt __wasi_ciovec_t struct | |
(data (i32.const 0) "\08\00\00\00") ;; buf: pointer to prompt string | |
(data (i32.const 4) "\02\00\00\00") ;; buf_len: 2 characters | |
;; string | |
(data (i32.const 8) "> ") | |
;; read buf __wasi_ciovec_t struct | |
(data (i32.const 16) "\18\00\00\00") ;; buf: pointer to string | |
(data (i32.const 20) "\64\00\00\00") ;; buf_len: 100 characters max | |
;; string | |
(data (i32.const 24) "\00") ;; buf (of 100 characters) to hold read in string | |
(func $main | |
(local $ret i32) | |
(block $done | |
(loop $loop | |
(drop (call $fd_write (i32.const 1) (i32.const 0) (i32.const 1) (i32.const 256))) | |
(local.set $ret (call $fd_read (i32.const 0) (i32.const 16) (i32.const 1) (i32.const 256))) | |
(if (i32.eqz (i32.load (i32.const 256)) (i32.const 0)) (br $done)) | |
(drop (call $fd_write (i32.const 0) (i32.const 16) (i32.const 1) (i32.const 256))) | |
(br $loop) | |
) | |
) | |
) | |
(export "_start" $main) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment