From 8bd7b4fa01915a4b8b8313f78935ca9762e7bcf9 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Sun, 17 Dec 2023 15:20:27 +0100 Subject: feat: if/else Signed-off-by: Henry Gressmann --- examples/wasm/call.wat | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'examples') diff --git a/examples/wasm/call.wat b/examples/wasm/call.wat index 247b976..9d00151 100644 --- a/examples/wasm/call.wat +++ b/examples/wasm/call.wat @@ -1,16 +1,15 @@ (module - (func $add_fn (param $a i32) (param $b i32) (result i32) - local.get $a - local.get $b - i32.add - ) - - (func $add (param $x i32) (param $y i32) (result i32) - local.get $x - local.get $y - call $add_fn - ) - - (export "add" (func $add)) -) + (func $check_input (param i32) (result i32) + local.get 0 + i32.const 10 + i32.lt_s ;; Check if input is less than 10 + if (result i32) ;; If so, + i32.const 1 ;; Set 1 to the stack + return ;; And return immediately + else ;; Otherwise, + i32.const 0 ;; Set 0 to the stack + return ;; And return immediately + end) ;; End of the if/else block + (export "check" (func $check_input)) +) \ No newline at end of file -- cgit v1.3.1