Various codegen fixes

This commit is contained in:
Samuel Hammersberg 2023-05-01 22:50:22 +02:00
parent 45578a79b1
commit 22dcbc6a13
7 changed files with 99 additions and 77 deletions

View file

@ -16,8 +16,15 @@ insertionSort xs = case xs of
Nil => xs
Nil => Nil
main = head (insertionSort (Cons 5 (Cons 4 (Cons 3 (Cons 2 (Cons 1 Nil))))))
main = head (insertionSort (revRange 1250))
head xs = case xs of
Cons x _ => x
revRange x = case x of
0 => Cons x Nil
x => Cons x (revRange (x + minusOne))
-- represents minus one :)
minusOne : Int ;
minusOne = 9223372036854775807 + 9223372036854775807 + 1;

18
sample-programs/loop.crf Normal file
View file

@ -0,0 +1,18 @@
main = for 0 1000
for x n = case n of
0 => 0
n => for (revRange 1000) (n + minusOne)
data List (a) where
Nil : List (a)
Cons : a -> List (a) -> List (a)
-- create a list of x to 0
revRange x = case x of
0 => Cons x Nil
x => Cons x (revRange (x + minusOne))
-- represents minus one :)
minusOne : Int ;
minusOne = 9223372036854775807 + 9223372036854775807 + 1;