Add wasi:cli component support, linear memory and globals
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cb1cec8b13
commit
05488c9783
11 files changed
+518
-52
No files matched your search
@@ -0,0 +1,16 @@
|
||||
;; Core module for a wasi:cli/command component.
|
||||
;; Build with: just run-component hello
|
||||
(module
|
||||
(import "wasi:cli/stdout@0.2.0" "get-stdout" (func $get_stdout (result i32)))
|
||||
(import "wasi:io/streams@0.2.0" "[method]output-stream.blocking-write-and-flush"
|
||||
(func $write (param i32 i32 i32 i32)))
|
||||
(memory (export "memory") 1)
|
||||
(data (i32.const 16) "Hello from wasi:cli!\0a")
|
||||
|
||||
(func (export "wasi:cli/run@0.2.0#run") (result i32)
|
||||
(call $write
|
||||
(call $get_stdout) ;; self: output-stream handle
|
||||
(i32.const 16) ;; ptr
|
||||
(i32.const 21) ;; len
|
||||
(i32.const 64)) ;; retptr for result<_, stream-error>
|
||||
(i32.load8_u (i32.const 64)))) ;; 0 = ok -> exit code 0
|
||||
@@ -0,0 +1,17 @@
|
||||
;; globals + linear memory: stores, sign/zero-extending loads, then an OOB trap
|
||||
(module
|
||||
(memory 1)
|
||||
(global $g (mut i32) (i32.const 40))
|
||||
(data (i32.const 0) "\ff\01")
|
||||
(func (export "main") (result i32)
|
||||
(global.set $g (i32.add (global.get $g) (i32.const 1)))
|
||||
(i32.store (i32.const 100) (i32.const 0x01020304))
|
||||
(if (i32.ne (i32.load8_u (i32.const 100)) (i32.const 4)) (then (return (i32.const 1))))
|
||||
(if (i32.ne (i32.load8_s (i32.const 0)) (i32.const -1)) (then (return (i32.const 2))))
|
||||
(if (i32.ne (i32.load16_u (i32.const 0)) (i32.const 0x01ff)) (then (return (i32.const 3))))
|
||||
(i32.store8 (i32.const 200) (i32.const 1))
|
||||
(global.set $g (i32.add (global.get $g) (i32.load8_u (i32.const 200))))
|
||||
(if (i32.ne (memory.size) (i32.const 1)) (then (return (i32.const 4))))
|
||||
(if (i32.ne (global.get $g) (i32.const 42)) (then (return (i32.const 5))))
|
||||
(drop (i32.load (i32.const 65533))) ;; 4-byte load straddling the end: traps
|
||||
(global.get $g)))
|
||||
@@ -0,0 +1,26 @@
|
||||
package wasi:cli@0.2.0;
|
||||
|
||||
interface stdout {
|
||||
use wasi:io/streams@0.2.0.{output-stream};
|
||||
get-stdout: func() -> output-stream;
|
||||
}
|
||||
|
||||
interface stderr {
|
||||
use wasi:io/streams@0.2.0.{output-stream};
|
||||
get-stderr: func() -> output-stream;
|
||||
}
|
||||
|
||||
interface exit {
|
||||
exit: func(status: result);
|
||||
}
|
||||
|
||||
interface run {
|
||||
run: func() -> result;
|
||||
}
|
||||
|
||||
world command {
|
||||
import stdout;
|
||||
import stderr;
|
||||
import exit;
|
||||
export run;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package wasi:io@0.2.0;
|
||||
|
||||
interface error {
|
||||
resource error {}
|
||||
}
|
||||
|
||||
interface streams {
|
||||
use error.{error};
|
||||
|
||||
variant stream-error {
|
||||
last-operation-failed(error),
|
||||
closed,
|
||||
}
|
||||
|
||||
resource output-stream {
|
||||
blocking-write-and-flush: func(contents: list<u8>) -> result<_, stream-error>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package local:examples;
|
||||
|
||||
world hello {
|
||||
include wasi:cli/command@0.2.0;
|
||||
}
|
||||
Reference in new issue
Block a user