Skip to content

Instantly share code, notes, and snippets.

@mafintosh
Last active June 9, 2018 10:32
Show Gist options
  • Save mafintosh/0ad0649ae768fb48ae93877fcb37c491 to your computer and use it in GitHub Desktop.
Save mafintosh/0ad0649ae768fb48ae93877fcb37c491 to your computer and use it in GitHub Desktop.
(module
(memory (export "memory") 10 10000)
(func (export "index_of") (param $start i32) (param $end i32) (param $needle i32) (result i32)
(block $end_loop
(br_if $end_loop (i32.eq (get_local $start) (get_local $end)))
(if (i32.eq (i32.load8_u (get_local $start)) (get_local $needle))
(then (return (get_local $start)))
)
(set_local $start (i32.add (i32.const 1) (get_local $start)))
)
(i32.const -1)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment