Working hello world

main
Ashelyn Dawn 12 months ago
parent 397eaa13db
commit 1f502bed06

5
.gitignore vendored

@ -1,3 +1,2 @@
intermediate.wat
output.wasmu
src
./intermediate.wat
./output.wasmu

@ -31,4 +31,13 @@ echo "$EPILOGUE" >> $INTERMEDIATE
# test file
wasmer compile -o ./output.wasmu $INTERMEDIATE
result=$?
if [ 0 -ne $result ]; then
echo "Build failed, printing generated wasm:"
cat $INTERMEDIATE
exit $?
else
echo "Build succeeded, running:"
wasmer run ./output.wasmu
fi

Binary file not shown.

@ -1,19 +1,11 @@
(data $hello (i32.const 20) "Hello world.\0A")
(import "wasi_unstable" "proc_exit" (func $proc_exit (param i32)))
(func $start (export "_start") (result i32)
i32.const 5
i32.const 4
call $test
i32.load $memory i32.const 0
i32.const 20 ;; location
i32.const 13 ;; length
call $print
call $proc_exit
unreachable
)
(import "wasi_unstable" "proc_exit" (func $proc_exit (param i32)))
(func $test (param $a i32) (param $b i32) (result i32)
local.get $a
local.get $b
i32.add
)

@ -0,0 +1,27 @@
;; Currently using a hard-coded struct at location 0
(import "wasi_unstable" "fd_write" (func $fd_write (param $file_descriptor i32) (param $io_vectors i32) (param $io_vecnum i32) (param $num_written_ptr i32) (result i32)))
(func $print (param $location i32) (param $length i32) (result i32)
;; create struct at location 0
i32.const 0
local.get $location
i32.store
i32.const 4
local.get $length
i32.store
;; file descriptor
i32.const 1
;; iovs array pointer
i32.const 0
;; iovs array length
i32.const 1
;; where to write length written
i32.const 200
call $fd_write
)
Loading…
Cancel
Save