Skip to content

Commit

Permalink
wasm example
Browse files Browse the repository at this point in the history
  • Loading branch information
skyz1 committed Mar 24, 2024
1 parent c034aa9 commit 2717520
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Empty file added packages/Wasm/_.candy
Empty file.
Empty file added packages/Wasm/_package.candy
Empty file.
22 changes: 22 additions & 0 deletions packages/Wasm/example.candy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[print] = use "Builtins"
[struct, result] = use "Core"

main := { environment ->
wat = '"
(module
(type $t0 (func (param i32) (result i32)))
(func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32)
get_local $p0
i32.const 1
i32.add))
"'

module = wat | environment.wasm.compile | result.unwrap
instance = [] | module.instantiate | result.unwrap
add_one = instance | struct.get "add_one" | result.unwrap

num = 42
res = add_one num
(res,) = res | result.unwrap
print "{num} + 1 = {res}"
}

0 comments on commit 2717520

Please sign in to comment.