summaryrefslogtreecommitdiff
path: root/base/Factorial.vapor
blob: 28e1126ad0b56a2bae8e6efc2a996ef592104665 (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

const vmt_Fac
  :Fac.ComputeFac


func Main()
  t.0 = HeapAllocZ(4)
  [t.0] = :vmt_Fac
  if t.0 goto :null1
    Error("null pointer")
  null1:
  t.1 = [t.0]
  t.1 = [t.1+0]
  t.2 = call t.1(t.0 10)
  PrintIntS(t.2)
  ret

func Fac.ComputeFac(this num)
  t.0 = LtS(num 1)
  if0 t.0 goto :if1_else
    num_aux = 1
    goto :if1_end
  if1_else:
    t.1 = [this]
    t.1 = [t.1+0]
    t.2 = Sub(num 1)
    t.3 = call t.1(this t.2)
    num_aux = MulS(num t.3)
  if1_end:
  ret num_aux