From cd56b176af08287eafc41c157c60d9d90b0e6684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madeleine=20Sydney=20=C5=9Alaga?= Date: Mon, 29 Jun 2026 15:39:13 -0600 Subject: [PATCH] wasi:cli/run --- examples/hello/Shakefile.hs | 3 ++- examples/hello/hello.wat | 5 ++-- examples/hello/hello.wit | 12 +++------ examples/silly/Shakefile.hs | 31 +++++++++++++++++++++++ examples/silly/silly.wat | 20 +++++++++++++++ examples/silly/silly.wit | 49 +++++++++++++++++++++++++++++++++++++ guile/cps/t.scm | 2 +- 7 files changed, 110 insertions(+), 12 deletions(-) create mode 100644 examples/silly/Shakefile.hs create mode 100644 examples/silly/silly.wat create mode 100644 examples/silly/silly.wit diff --git a/examples/hello/Shakefile.hs b/examples/hello/Shakefile.hs index dc4a1c5..1d25a9a 100644 --- a/examples/hello/Shakefile.hs +++ b/examples/hello/Shakefile.hs @@ -25,7 +25,8 @@ main = shakeArgs shakeOptions $ do [wit] [wat] "-o" [out] phony "run" $ do need ["hello.component.wasm"] - cmd_ "wasmtime run --invoke hello() hello.component.wasm" + -- cmd_ "wasmtime run --invoke hello() hello.component.wasm" + cmd_ "wasmtime run hello.component.wasm" phony "clean" $ do removeFilesAfter ".shake" ["//*"] liftIO $ removeFiles "." ["*.wasm"] diff --git a/examples/hello/hello.wat b/examples/hello/hello.wat index c4b9bf5..1ca72d1 100644 --- a/examples/hello/hello.wat +++ b/examples/hello/hello.wat @@ -14,9 +14,10 @@ (data (i32.const 16) "hello worms\n") - (func $hello (export "hello") + (func (export "wasi:cli/run@0.2.6#run") (result i32) (call $print (call $get-stdout) (i32.const 16) ;; offset to print (i32.const 12) ;; length to print - (i32.const 32)))) ;; offset for result + (i32.const 32)) ;; offset for result + (i32.const 0))) diff --git a/examples/hello/hello.wit b/examples/hello/hello.wit index e00606e..664bf72 100644 --- a/examples/hello/hello.wit +++ b/examples/hello/hello.wit @@ -5,8 +5,7 @@ world root { import wasi:cli/stdout@0.2.6; import wasi:io/streams@0.2.6; - // export wasi:cli/run@0.2.0; - export hello: func(); + export wasi:cli/run@0.2.6; } package wasi:cli@0.2.6 { @@ -17,14 +16,11 @@ package wasi:cli@0.2.6 { } interface stdin { } + interface run { + run: func () -> result; + } } -// package wasi:cli@0.2.0 { -// interface run { -// run: func() -> result; -// } -// } - package wasi:io@0.2.6 { interface poll { resource pollable { diff --git a/examples/silly/Shakefile.hs b/examples/silly/Shakefile.hs new file mode 100644 index 0000000..9b07d38 --- /dev/null +++ b/examples/silly/Shakefile.hs @@ -0,0 +1,31 @@ +import Development.Shake +import Development.Shake.Command +import Development.Shake.FilePath +import Development.Shake.Util + +main = shakeArgs shakeOptions $ do + -- action $ do + -- sourceFiles <- getDirectoryFiles "" ["//*.luasm"] + -- need $ (-<.> "luac") <$> sourceFiles + want ["silly.component.wasm"] + alternatives $ do + "*.component.wasm" %> \out -> do + let wasm = out `replaceExtensions` "wasm" + need [wasm] + cmd_ + "wasm-tools component new" + [wasm] + "-o" [out] + "*.wasm" %> \out -> do + let wit = out -<.> "wit" + let wat = out -<.> "wat" + need [wit,wat] + cmd_ + "wasm-tools component embed" + [wit] [wat] "-o" [out] + phony "run" $ do + need ["silly.component.wasm"] + cmd_ "wasmtime run --invoke silly() silly.component.wasm" + phony "clean" $ do + removeFilesAfter ".shake" ["//*"] + liftIO $ removeFiles "." ["*.wasm"] diff --git a/examples/silly/silly.wat b/examples/silly/silly.wat new file mode 100644 index 0000000..8f4f021 --- /dev/null +++ b/examples/silly/silly.wat @@ -0,0 +1,20 @@ +(module + (import "wasi:cli/stdout@0.2.6" "get-stdout" + (func $get-stdout (result i32))) + (import + "wasi:io/streams@0.2.6" + "[method]output-stream.blocking-write-and-flush" + (func $print (param i32 i32 i32 i32))) + + (memory 1) + (export "memory" (memory 0)) + + (data (i32.const 16) "hello worms\n") + + (func (export "wasi:cli/run@0.2.6#run") (result i32) + (call $print + (call $get-stdout) + (i32.const 16) ;; offset to print + (i32.const 12) ;; length to print + (i32.const 32)) ;; offset for result + (i32.const 0))) diff --git a/examples/silly/silly.wit b/examples/silly/silly.wit new file mode 100644 index 0000000..664bf72 --- /dev/null +++ b/examples/silly/silly.wit @@ -0,0 +1,49 @@ +package root:component; + +world root { + import wasi:cli/stdin@0.2.6; + import wasi:cli/stdout@0.2.6; + import wasi:io/streams@0.2.6; + + export wasi:cli/run@0.2.6; +} + +package wasi:cli@0.2.6 { + interface stdout { + use wasi:io/streams@0.2.6.{output-stream}; + + get-stdout: func() -> output-stream; + } + interface stdin { + } + interface run { + run: func () -> result; + } +} + +package wasi:io@0.2.6 { + interface poll { + resource pollable { + block: func(); + } + } + interface error { + resource error; + } + interface streams { + use error.{error}; + use poll.{pollable}; + + resource input-stream; + + resource output-stream { + write: func(contents: list) -> result<_, stream-error>; + blocking-write-and-flush: func(contents: list) ->result<_,stream-error>; + } + + variant stream-error { + last-operation-failed(error), + closed, + } + } +} \ No newline at end of file diff --git a/guile/cps/t.scm b/guile/cps/t.scm index 1c94464..4c83eb9 100644 --- a/guile/cps/t.scm +++ b/guile/cps/t.scm @@ -1,3 +1,3 @@ (display "the numberr is ... ") -(display (+ 1 (* 3 4))) +(display (+ 5 (* 3 4))) (newline)