works albeit comically inefficiently
This commit is contained in:
@@ -76,8 +76,7 @@ test_root = testGroup "stack machine"
|
||||
(tail-call 1))
|
||||
(define $square
|
||||
(pop! %x)
|
||||
(prim %x2 (* %x %x))
|
||||
(push! %x2)
|
||||
(prim (* %x %x))
|
||||
(return 1))
|
||||
|]
|
||||
, testGroup "factorial"
|
||||
@@ -90,20 +89,19 @@ test_root = testGroup "stack machine"
|
||||
(tail-call 1))
|
||||
(define $fac
|
||||
(load %n 0)
|
||||
(prim %x0 (zero? %n))
|
||||
(prim (zero? %n))
|
||||
(pop! %x0)
|
||||
(if %x0
|
||||
(then (push! 1)
|
||||
(return 1))
|
||||
(else (prim %x1 (- %n 1))
|
||||
(push! $fac-c0)
|
||||
(else (push! $fac-c0)
|
||||
(push! $fac)
|
||||
(push! %x1)
|
||||
(prim (- %n 1))
|
||||
(call 1))))
|
||||
(define $fac-c0
|
||||
(pop! %x2)
|
||||
(pop! %n)
|
||||
(prim %x3 (* %n %x2))
|
||||
(push! %x3)
|
||||
(prim (* %n %x2))
|
||||
(return 1))
|
||||
|]
|
||||
mkcase n = testCase [i|#{n}|] do
|
||||
|
||||
Reference in New Issue
Block a user