blob: 54ed9286ee272404ea3e1a1a2f4382bf23782c28 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
;;; TOOL: run-interp
;;; ARGS*: --enable-tail-call
(module
(func (export "fac10") (result i32)
i32.const 10
i32.const 1
call $fac
return)
(;; Tail call version of factorial ;;)
(;; fac(Ix,So) => Ix==0?So:fac(Ix-1,So*Ix) ;;)
(func $fac (param i32 i32) (result i32)
get_local 0
i32.const 0
i32.gt_s
if (result i32)
get_local 0
i32.const 1
i32.sub
get_local 1
get_local 0
i32.mul
return_call $fac
else
get_local 1
return
end)
)
(;; STDOUT ;;;
fac10() => i32:3628800
;;; STDOUT ;;)
|