52 lines
1.6 KiB
Plaintext
52 lines
1.6 KiB
Plaintext
(with_import "./wasm.kp"
|
|
(let (
|
|
_ (println "args" *ARGV*)
|
|
(_ _ out) (cond (!= (len *ARGV*) 3) (error "wrong number of params to comp_wasm (please provide out)")
|
|
true *ARGV*)
|
|
_ (println "out" out)
|
|
wasm_code (module
|
|
(import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))
|
|
(memory $mem 1)
|
|
(data (i32.const 16) "HellH") ;; adder to put, then data
|
|
(func $add (param $num i32) (result i32)
|
|
(local $tmp1 i32)
|
|
(local $tmp2 i32)
|
|
(block $test
|
|
(i32.const 1337)
|
|
(i32.const 1338)
|
|
(i32.store (i32.const 8) (i32.const 16)) ;; adder of data
|
|
(i32.load (i32.const 8))
|
|
(i64.store (i32.const 8) (i64.const 16)) ;; adder of data
|
|
(i64.load (i32.const 8))
|
|
drop
|
|
drop
|
|
drop
|
|
(block $inner_test
|
|
(br $inner_test)
|
|
(br $test)
|
|
)
|
|
(br $test)
|
|
drop
|
|
|
|
(call $fd_write
|
|
(i32.const 0) ;; file descriptor
|
|
(i32.const 8) ;; *iovs
|
|
(i32.const 1) ;; iovs_len
|
|
(i32.const 4) ;; nwritten
|
|
)
|
|
drop
|
|
)
|
|
(i32.const 11)
|
|
(local.get $tmp2)
|
|
i32.add
|
|
(i32.add (local.get $num))
|
|
)
|
|
; nothing
|
|
(export "add" (func $add))
|
|
)
|
|
|
|
|
|
_ (write_file out (wasm_to_binary wasm_code))
|
|
return_code 0
|
|
) return_code ))
|