Skip to content

Instantly share code, notes, and snippets.

@tosuke
Created July 12, 2019 18:20
Show Gist options
  • Save tosuke/6b7b7d856d83c9411b8f86930bcc1c49 to your computer and use it in GitHub Desktop.
Save tosuke/6b7b7d856d83c9411b8f86930bcc1c49 to your computer and use it in GitHub Desktop.
AssemblyScript switch-case
export function test(c: u8): i32 {
switch(c) {
case 0:
return 0
case 1:
return 1
case 2:
return 2
case 3:
return 3
case 4:
return 4
default:
return -1
}
}
(module
(type $t0 (func (param i32) (result i32)))
(type $t1 (func))
(func $test (export "test") (type $t0) (param $p0 i32) (result i32)
block $B0
block $B1
block $B2
block $B3
block $B4
get_local $p0
i32.const 255
i32.and
tee_local $p0
if $I5
get_local $p0
i32.const 1
i32.sub
br_table $B4 $B3 $B2 $B1 $B0
end
i32.const 0
return
end
i32.const 1
return
end
i32.const 2
return
end
i32.const 3
return
end
i32.const 4
return
end
i32.const -1)
(func $f1 (type $t1)
nop)
(memory $memory (export "memory") 0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment