2021-04-19 01:39:04 -04:00
|
|
|
(with_import "./wasm.kp"
|
|
|
|
|
(let (
|
|
|
|
|
_ (println "args" *ARGV*)
|
2021-07-22 01:14:51 -04:00
|
|
|
(_ _ out) (cond (!= (len *ARGV*) 3) (error "wrong number of params to comp_wasm (please provide out)")
|
2021-04-19 01:39:04 -04:00
|
|
|
true *ARGV*)
|
2021-07-18 23:42:19 -04:00
|
|
|
_ (println "out" out)
|
|
|
|
|
wasm_code (module
|
2021-07-25 18:10:10 -04:00
|
|
|
(import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))
|
2021-07-20 00:37:27 -04:00
|
|
|
(func $add (param $num i32) (result i32)
|
|
|
|
|
(local $tmp1 i32)
|
|
|
|
|
(local $tmp2 i32)
|
2021-07-25 02:14:20 -04:00
|
|
|
(block $test
|
2021-07-22 01:14:51 -04:00
|
|
|
(i32.const 1337)
|
|
|
|
|
(i32.const 1338)
|
|
|
|
|
drop
|
|
|
|
|
drop
|
2021-07-25 02:14:20 -04:00
|
|
|
(block $inner_test
|
|
|
|
|
(br $inner_test)
|
|
|
|
|
(br $test)
|
|
|
|
|
)
|
|
|
|
|
(br $test)
|
2021-07-24 00:39:45 -04:00
|
|
|
drop
|
2021-07-25 18:10:10 -04:00
|
|
|
|
|
|
|
|
(call $fd_write
|
|
|
|
|
(i32.const 0) ;; file descriptor
|
|
|
|
|
(i32.const 8) ;; *iovs
|
|
|
|
|
(i32.const 1) ;; iovs_len
|
|
|
|
|
(i32.const 4) ;; nwritten
|
|
|
|
|
)
|
|
|
|
|
drop
|
2021-07-22 01:14:51 -04:00
|
|
|
)
|
2021-07-20 00:37:27 -04:00
|
|
|
(i32.const 11)
|
2021-07-20 23:36:03 -04:00
|
|
|
(local.get $tmp2)
|
2021-07-19 00:32:42 -04:00
|
|
|
i32.add
|
2021-07-20 00:37:27 -04:00
|
|
|
(i32.add (local.get $num))
|
2021-07-18 23:42:19 -04:00
|
|
|
)
|
2021-07-20 00:37:27 -04:00
|
|
|
; nothing
|
|
|
|
|
(export "add" (func $add))
|
2021-07-18 23:42:19 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2021-04-19 01:39:04 -04:00
|
|
|
_ (write_file out (wasm_to_binary wasm_code))
|
|
|
|
|
return_code 0
|
|
|
|
|
) return_code ))
|