Skip to content

Instantly share code, notes, and snippets.

@kfl
Last active February 22, 2019 16:23
Show Gist options
  • Select an option

  • Save kfl/af8938855c48037847e0247790565563 to your computer and use it in GitHub Desktop.

Select an option

Save kfl/af8938855c48037847e0247790565563 to your computer and use it in GitHub Desktop.
even/odd in flat and sexp style
(module $evenodd
(export "even" (func $even))
(export "odd" (func $odd))
(func $even (param $n i32) (result i32)
get_local $n
i32.const 0
i32.eq
if (result i32)
i32.const 1
else
get_local $n
i32.const 1
i32.sub
call $odd
end)
(func $odd (param $n i32) (result i32)
(if (result i32)
(i32.eq
(get_local $n)
(i32.const 0))
(i32.const 0)
(call $even (i32.sub
(get_local $n)
(i32.const 1)))))
)
@kfl
Copy link
Copy Markdown
Author

kfl commented Feb 22, 2019

Use typed if

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment