forked from replit/polygott
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebassembly.toml
59 lines (50 loc) · 1.88 KB
/
webassembly.toml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name = "WebAssembly"
entrypoint = "main.wat"
extensions = [
"wat"
]
packages = [
]
setup = [
"wget https://github.com/wasmerio/wasmer/releases/download/0.14.0/wasmer-linux-amd64.tar.gz -O /tmp/wasmer.tar.gz",
"mkdir /usr/local/wasmer",
"tar -xvf /tmp/wasmer.tar.gz -C /usr/local/wasmer --strip-components=1",
"ln -s /usr/local/wasmer/wasmer /usr/local/bin/wasmer",
"rm /tmp/wasmer.tar.gz"
]
[run]
command = [
"wasmer",
"run",
"main.wat"
]
[tests]
[tests.hello]
code = """;; wat2wasm main.wat
(module $hello
;; Import the required fd_write WASI function which will write the given io vectors to stdout
;; The function signature for fd_write is:
;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written
(import "wasi_unstable" "fd_write"
(func $fd_write (param i32 i32 i32 i32) (result i32))
)
(memory 1)
(export "memory" (memory 0))
;; Write 'hello world\\n' to memory at an offset of 8 bytes
;; Note the trailing newline which is required for the text to appear
(data (i32.const 8) "Hello, World")
(func $main (export "_start")
;; Creating a new io vector within linear memory
(i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\\n' string
(i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\\n' string
(call $fd_write
(i32.const 1) ;; file_descriptor - 1 for stdout
(i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0
(i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one.
(i32.const 20) ;; nwritten - A place in memory to store the number of bytes writen
)
drop ;; Discard the number of bytes written from the top the stack
)
)
"""
output = "Hello, World"