summaryrefslogtreecommitdiff
path: root/testdata/later.ignore
diff options
context:
space:
mode:
authorCsaba Hruska <csaba.hruska@gmail.com>2016-01-19 15:59:35 +0100
committerCsaba Hruska <csaba.hruska@gmail.com>2016-01-19 16:10:49 +0100
commitcb69693769ebfcdac605c90f38a20c788b08eaf3 (patch)
tree3689094c7ff13f45cc928a7dfaafff2652ed4c03 /testdata/later.ignore
parentd5f3ef4a65218b966f7463511896fd901a4d1d77 (diff)
normalise paths and fix self export handling
Diffstat (limited to 'testdata/later.ignore')
-rw-r--r--testdata/later.ignore/DemoUtils.lc48
-rw-r--r--testdata/later.ignore/DepPrelude.lc568
-rw-r--r--testdata/later.ignore/ShadowMapping.lc223
-rw-r--r--testdata/later.ignore/fragment02tuple.lc21
-rw-r--r--testdata/later.ignore/fragment02vectorpattern.lc21
-rw-r--r--testdata/later.ignore/fragment05uniform.lc22
-rw-r--r--testdata/later.ignore/fragment06tailrecursion.lc24
-rw-r--r--testdata/later.ignore/fragmenttest.lc1
-rw-r--r--testdata/later.ignore/fragmenttest.out1
9 files changed, 929 insertions, 0 deletions
diff --git a/testdata/later.ignore/DemoUtils.lc b/testdata/later.ignore/DemoUtils.lc
new file mode 100644
index 00000000..bcde1467
--- /dev/null
+++ b/testdata/later.ignore/DemoUtils.lc
@@ -0,0 +1,48 @@
1module DemoUtils
2 ( module DemoUtils
3 , module Prelude
4 ) where
5
6time = Uniform "Time" :: Float
7
8--v3v4 = PrimV3FToV4F
9
10-- example combinators
11image color = FrameBuffer (DepthImage @1 1000.0, ColorImage @1 color)
12
13triangleRasterCtx = TriangleCtx CullNone PolygonFill NoOffset LastVertex
14colorFragmentCtx = accumulationContext (DepthOp Less True, ColorOp NoBlending (V4 True True True True))
15
16rasterizeWith = Rasterize
17triangles = triangleRasterCtx
18
19cubeVertexStream = fetch "stream4" Triangle (Attribute "position4" :: Vec 4 Float)
20mapFragments s fs bg = accumulate colorFragmentCtx PassAll (FragmentShaderRastDepth $ \a -> fs a) s bg
21transform s f = Transform (\v -> VertexOut (f v) 1.0 () (Smooth v)) s
22
23cube v f bg = (cubeVertexStream -- cube vertices
24 `transform` v -- scale them
25 & rasterizeWith triangles -- rasterize
26 `mapFragments` f) bg
27
28
29
30withCoords f a = f (a%x) (a%y)
31
32fragmentTest f = quadVertexStream
33 `transformQ` id
34 & rasterizeWith triangles
35 `mapFragmentsQ` withCoords f
36 where
37 clearQ = FrameBuffer $ ColorImage @1 $ V4 1 0 0 0.5
38
39 colorFragmentCtxQ = accumulationContext (ColorOp NoBlending (V4 True True True True))
40 mapFragmentsQ s fs = accumulate colorFragmentCtxQ PassAll (FragmentShader $ \a -> fs a) s clearQ
41
42 quadVertexStream = fetch "quad" Triangle (Attribute "position" :: Vec 2 Float)
43
44 tr :: Vec 2 Float -> Vec 4 Float
45 tr a = V4 a%x a%y 1 1
46
47 transformQ s f = Transform (\v -> VertexOut (tr $ f v ) 1 () (Smooth v)) s
48
diff --git a/testdata/later.ignore/DepPrelude.lc b/testdata/later.ignore/DepPrelude.lc
new file mode 100644
index 00000000..facb4b7b
--- /dev/null
+++ b/testdata/later.ignore/DepPrelude.lc
@@ -0,0 +1,568 @@
1{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE NoTypeNamespace #-}
3{-# LANGUAGE NoConstructorNamespace #-}
4-- contains the lambda-pi prelude (http://www.andres-loeh.de/LambdaPi/prelude.lp) adatpted to the lc compiler prototype
5builtintycons
6 Int :: Type
7
8data Unit = TT
9
10builtins
11 cstr :: Type -> Type -> Type -- TODO
12-- cstr :: forall (a :: Type) (b :: Type) -> a -> b -> Type
13-- reflCstr :: forall (a :: Type) -> cstr a a
14 coe :: forall (a :: Type) (b :: Type) -> cstr a b -> a -> b
15
16tyType (a :: Type) = a
17id a = a
18const x y = x
19const' :: forall a b . a -> b -> a
20const' x y = x
21const'' :: forall b a . a -> b -> a
22const'' x y = x
23id' a = id a
24id'' = id id
25app f x = f x
26comp f g x = f (g x)
27app2 f x y = f x y
28flip f x y = f y x
29scomb a b c = a c (b c)
30
31builtins fix :: forall a . (a -> a) -> a
32builtins f_i_x :: forall a . (a -> a) -> a
33
34data Sigma a (b :: a -> Type) = Pair (x :: a) (b x)
35
36-- undefined = undefined
37builtins
38 undefined :: forall (a :: Type) . a
39
40data Empty
41--data T2 a b = T2C a b
42builtins
43 T2 :: Type -> Type -> Type
44 T2C :: Unit -> Unit -> Unit
45
46-- identity function, used for type annotations internally
47typeAnn = \(A :: Type) (a :: A) -> a
48
49data Bool = False | True
50
51otherwise = True
52
53if' b t f = case b of True -> t
54 False -> f
55
56-- higher-order unification test
57htest b = if' b id
58htest' b = if' b id :: (forall a . a -> a) -> _
59htest'' b = if' b id :: _ -> (forall a . a -> a)
60
61data List a = Nil' | Cons' a (List a)
62
63builtins
64 primAdd, primSub, primMod
65 :: Int -> Int -> Int
66 primSqrt :: Int -> Int
67 primIntEq, primIntLess
68 :: Int -> Int -> Bool
69
70dcomp
71 (X :: Type)
72 (Y :: X -> Type)
73 (Z :: forall (x :: X) -> Y x -> Type)
74 (f :: forall x (y :: Y x) -> Z x y)
75 (g :: forall (x :: X) -> Y x)
76 (x :: X)
77 = f x (g x)
78dcomp'
79 @X
80 @(Y :: X -> _)
81 @(Z :: forall x -> Y x -> _)
82 (f :: forall x . forall y -> Z x y)
83 (g :: forall x -> Y x)
84 x
85 = f (g x)
86dcomp''
87 :: forall
88 X
89 (Y :: X -> _)
90 (Z :: forall x -> Y x -> _)
91 . forall
92 (f :: forall x . forall y -> Z x y)
93 (g :: forall x -> Y x) x
94 -> Z x (g x)
95dcomp'' f g x = f (g x)
96
97listMap f xs =
98 | Nil' <- xs -> Nil'
99 | Cons' x xs <- xs -> Cons' (f x) (listMap f xs)
100foldr c n xs = case xs of
101 Nil' -> n
102 Cons' x xs -> c x (foldr c n xs)
103
104concat xs ys = foldr Cons' ys xs
105
106from n = Cons' n (from (primAdd #1 n))
107head x = case x of
108 Nil' -> undefined
109 Cons' x _ -> x
110tail = listCase (\_ -> _) undefined (\_ xs -> xs)
111nth n xs =
112 | primIntEq #0 n -> head xs
113 | otherwise -> nth (primSub n #1) (tail xs)
114filter p xs =
115 | Nil' <- xs -> Nil'
116 | Cons' x xs <- xs ->
117 | p x -> Cons' x (filter p xs)
118 | otherwise -> filter p xs
119takeWhile p xs =
120 | Nil' <- xs -> Nil'
121 | Cons' x xs <- xs ->
122 | p x -> Cons' x (takeWhile p xs)
123 | otherwise -> Nil'
124and' a b = boolCase (\_ -> _) False b a
125or' a b = boolCase (\_ -> _) b True a
126not' = boolCase (\_ -> _) True False
127all p = listCase (\_ -> _) True (\x xs -> and' (p x) (all p xs))
128intLEq n m = or' (primIntLess n m) (primIntEq n m)
129{- todo
130primes =
131 Cons' #2 (Cons' #3 (filter (\x -> all (\i -> not' (primIntEq #0 (primMod x i))) (
132 takeWhile (\p -> (\m -> or' (primIntLess p m) (primIntEq p m)) (primSqrt x)) primes
133 )) (from #5)))
134
135nthPrimes n = nth n primes
136main = nthPrimes #10
137-}
138data Nat = Zero | Succ Nat
139data Fin :: Nat -> Type where
140 FZero :: Fin (Succ n)
141 FSucc :: Fin n -> Fin (Succ n)
142data Vec a :: Nat -> Type where
143 Nil :: Vec a Zero
144 Cons :: a -> Vec a n -> Vec a (Succ n)
145data Eq @a :: a -> a -> Type where
146 Refl :: Eq x x
147
148wrong
149 x = 1 1
150
151vec = Vec _
152
153builtins
154 natElim :: forall m -> m Zero -> (forall n -> m n -> m (Succ n)) -> forall b -> m b
155
156--natElim (m :: Nat -> Type) (z :: m Zero) (s :: forall n -> m n -> m (Succ n)) = fix (\natElim -> natCase m z (\n -> s n (natElim n)))
157
158builtins
159 finElim ::
160 forall (m :: forall n -> Fin n -> _)
161 -> (forall n . m (Succ n) FZero)
162 -> (forall n . forall f -> m n f -> m (Succ n) (FSucc f))
163 -> forall n f -> m n f
164
165-- addition of natural numbers
166plus =
167 natElim
168 (\_ -> _) -- motive
169 (\n -> n) -- case for Zero
170 (\p rec n -> Succ (rec n)) -- case for Succ
171
172-- predecessor, mapping 0 to 0
173pred =
174 natElim
175 (\_ -> _)
176 Zero
177 (\n' _ -> n')
178
179-- a simpler elimination scheme for natural numbers
180natFold =
181 \mz ms -> natElim
182 (\_ -> _)
183 mz
184 (\_ rec -> ms rec)
185
186-- an eliminator for natural numbers that has special
187-- cases for 0 and 1
188nat1Elim = \m m0 m1 ms -> natElim m m0
189 (\p rec -> natElim (\n -> m (Succ n)) m1 ms p)
190
191-- an eliminator for natural numbers that has special
192-- cases for 0, 1 and 2
193nat2Elim = \m m0 m1 m2 ms -> nat1Elim m m0 m1
194 (\p rec -> natElim (\n -> m (Succ (Succ n))) m2 ms p)
195
196-- increment by one
197inc = natFold (Succ Zero) Succ
198
199-- embed Fin into Nat
200finNat = finElim (\_ _ -> Nat)
201 Zero
202 (\_ rec -> Succ rec)
203
204-- unit type
205Unit' = Fin 1
206-- constructor
207U = FZero :: Unit'
208-- eliminator
209
210unitElim = \m mu -> finElim (nat1Elim (\n -> Fin n -> Type)
211 (\_ -> Unit')
212 (\x -> m x)
213 (\_ _ _ -> Unit'))
214 (\ @n -> natElim (\n -> natElim (\n -> Fin (Succ n) -> Type)
215 (\x -> m x)
216 (\_ _ _ -> Unit')
217 n FZero)
218 mu
219 (\_ _ -> U) n)
220 (\ @n f _ -> finElim (\n f -> natElim (\n -> Fin (Succ n) -> Type)
221 (\x -> m x)
222 (\_ _ _ -> Unit')
223 n (FSucc f))
224 U
225 (\_ _ -> U)
226 n f)
227 1
228
229-- empty type
230Void = Fin 0
231-- eliminator
232voidElim m = finElim (natElim (\n -> Fin n -> Type)
233 (\x -> m x)
234 (\_ _ _ -> _))
235 U
236 (\_ _ -> U)
237 0
238
239-- type of booleans
240Bool' = Fin 2
241-- constructors
242False' = FZero :: Bool'
243True' = FSucc FZero :: Bool'
244-- eliminator
245
246boolElim = \m mf mt -> finElim ( nat2Elim (\n -> Fin n -> Type)
247 (\_ -> Unit') (\_ -> Unit')
248 (\x -> m x)
249 (\_ _ _ -> Unit'))
250 (\ @n -> nat1Elim (\n -> nat1Elim (\n -> Fin (Succ n) -> Type)
251 (\_ -> Unit')
252 (\x -> m x)
253 (\_ _ _ -> Unit')
254 n FZero)
255 U mf (\_ _ -> U) n)
256 (\ @n f _ -> finElim (\n f -> nat1Elim (\n -> Fin (Succ n) -> Type)
257 (\_ -> Unit')
258 (\x -> m x)
259 (\_ _ _ -> Unit')
260 n (FSucc f))
261 (\ @n -> natElim
262 (\n -> natElim
263 (\n -> Fin (Succ (Succ n)) -> Type)
264 (\x -> m x)
265 (\_ _ _ -> Unit')
266 n (FSucc FZero))
267 mt (\_ _ -> U) n)
268 (\ @n f _ -> finElim
269 (\n f -> natElim
270 (\n -> Fin (Succ (Succ n)) -> Type)
271 (\x -> m x)
272 (\_ _ _ -> Unit')
273 n (FSucc (FSucc f)))
274 U
275 (\_ _ -> U)
276 n f)
277 n f)
278 2
279
280
281-- boolean not, and, or, equivalence, xor
282not = boolElim (\_ -> _) True' False'
283and = boolElim (\_ -> _) (const False') id
284or = boolElim (\_ -> _) id (const True')
285iff = boolElim (\_ -> _) not id
286xor = boolElim (\_ -> _) id not
287
288-- even, odd, isZero, isSucc
289even = natFold True' not
290odd = natFold False' not
291isZero = natFold True' (const False')
292isSucc = natFold False' (const True')
293
294-- equality on natural numbers
295natEq =
296 natElim
297 (\_ -> _)
298 (natElim
299 (\_ -> _)
300 True'
301 (\n' _ -> False'))
302 (\m' rec_m' -> natElim
303 (\_ -> _)
304 False'
305 (\n' _ -> rec_m' n'))
306
307-- "oh so true"
308Prop = boolElim (\_ -> _) Void Unit'
309
310-- reflexivity of equality on natural numbers
311pNatEqRefl =
312 natElim
313 (\n -> Prop (natEq n n))
314 U
315 (\_ rec -> rec)
316 -- :: forall (n :: Nat) -> Prop (natEq n n)
317
318-- alias for type-level negation
319Not a = a -> Void
320
321-- Leibniz prinicple: forall a b . (a -> b) -> forall (x :: a) (y :: a) -> Eq x y -> Eq (f x) (f y)
322leibniz f x y = eqCase
323 (\x y _ -> Eq (f x) (f y))
324 Refl @x @y
325
326-- symmetry of (general) equality
327symm x y = eqCase (\x y _ -> Eq y x) Refl @x @y
328
329-- transitivity of (general) equality
330tran eq_x_y = eqCase
331 (\x y _ -> forall z -> Eq y z -> Eq x z)
332 (\_ x -> x)
333 eq_x_y _
334
335-- apply an equality proof on two types
336apply = eqCase (\a b _ -> a -> b) id
337
338p1IsNot0 p = apply
339 (leibniz
340 (natElim (\_ -> _) Void (\_ _ -> Unit'))
341 1 0 p)
342 U
343
344-- proof that 0 is not 1
345p0IsNot1 p = p1IsNot0 (symm 0 1 p)
346
347-- proof that zero is not a successor
348p0IsNoSucc =
349 natElim
350 (\n -> Not (Eq 0 (Succ n)))
351 p0IsNot1
352 (\n' rec_n' eq_0_SSn' ->
353 rec_n' (leibniz pred Zero (Succ (Succ n')) eq_0_SSn'))
354
355-- generate a vector of given length from a specified element (replicate)
356
357replicate =
358 natElim
359 (\n -> forall a -> a -> Vec a n)
360 (\_ _ -> Nil)
361 (\n' rec_n' a x -> Cons x (rec_n' a x))
362
363-- alternative definition of replicate
364replicate' =
365 natElim
366 (\n -> _ -> vec n)
367 (\_ -> Nil)
368 (\n' rec_n' x -> Cons x (rec_n' x))
369
370replicate'' x = natElim vec Nil (\n' rec_n' -> Cons x rec_n')
371
372-- generate a vector of given length n, containing the natural numbers smaller than n
373fromto = natElim vec Nil (\n' rec_n' -> Cons n' rec_n')
374
375builtins
376 vecElim ::
377 forall (m :: forall k -> vec k -> _) ->
378 m Zero Nil
379 -> (forall l . forall x xs -> m l xs -> m (Succ l) (Cons x xs))
380 -> forall k xs -> m k xs
381
382-- append two vectors
383append = vecElim
384 (\m _ -> forall n -> vec n -> vec (plus m n))
385 (\_ v -> v)
386 (\v vs rec n w -> Cons v (rec n w))
387
388-- helper function for tail, see below
389tail' a = vecElim (\m v -> forall n -> Eq m (Succ n) -> Vec a n)
390 (\n eq_0_SuccN -> voidElim (\_ -> _)
391 (p0IsNoSucc n eq_0_SuccN))
392 (\ @m' v vs rec_m' n eq_SuccM'_SuccN ->
393 eqCase
394 (\m' n e -> Vec a m' -> Vec a n)
395 id
396 @m' @n
397 (leibniz pred (Succ m') (Succ n) eq_SuccM'_SuccN) vs)
398
399-- compute the tail of a vector
400tailVec = \n v -> tail' _ (Succ n) v n Refl
401
402-- projection out of a vector
403at =
404 vecElim (\n v -> Fin n -> _)
405 (\f -> voidElim (\_ -> _) f)
406 (\ @n' v vs rec_n' f_SuccN' ->
407 finElim (\n _ -> Eq n (Succ n') -> _)
408 (\e -> v)
409 (\ @n f_N _ eq_SuccN_SuccN' ->
410 rec_n' (eqCase
411 (\x y e -> Fin x -> Fin y)
412 id
413 @n @n'
414 (leibniz pred
415 (Succ n) (Succ n') eq_SuccN_SuccN')
416 f_N))
417 (Succ n')
418 f_SuccN'
419 Refl)
420
421-- head of a vector
422headVec n v = at (Succ n) v FZero
423
424-- vector map
425map f = vecElim (\n _ -> vec n) Nil (\x _ rec -> Cons (f x) rec)
426
427-- proofs that 0 is the neutral element of addition
428-- one direction is trivial by definition of plus:
429p0PlusNisN = Refl :: forall n . Eq (plus 0 n) n
430
431-- the other direction requires induction on N:
432pNPlus0isN =
433 natElim (\n -> Eq (plus n 0) n)
434 Refl
435 (\n' rec -> leibniz Succ (plus n' 0) n' rec)
436
437testNoNorm = Refl :: Eq (primIntEq #3 #3) True
438
439True'' = FSucc FZero :: Bool'
440
441
442data EqD a = EqDC (a -> a -> Bool)
443
444eqInt = EqDC primIntEq
445
446builtins
447 matchInt :: Type -> (Type -> Type) -> Type -> Type
448 matchList :: (Type -> Type) -> (Type -> Type) -> Type -> Type
449
450Eq_ :: Type -> Type
451Eq_ a = matchInt Unit (matchList Eq_ (\_ -> Empty)) a
452
453builtins eqD :: Eq_ a => EqD a
454
455eq = eqDCase (\_ -> _) id eqD
456
457eq' = eqDCase (\_ -> _) id
458
459eqList = EqDC (\as bs -> listCase (\_ -> _) (listCase (\_ -> _) True (\_ _ -> False) bs) (\a as -> listCase (\_ -> _) False (\b bs -> and' (eq a b) (eq as bs)) bs) as)
460
461main_ = eq' eqList (Cons' #3 Nil') Nil'
462main'' = eq (Cons' #3 Nil') Nil'
463
464data MonadD (m :: Type -> Type) = MonadDC (forall a . a -> m a) (forall a b . m a -> (a -> m b) -> m b)
465
466data Identity a = IdentityC a
467
468identityMonad = MonadDC IdentityC (\m f -> identityCase (\_ -> _) f m)
469
470Char = Int
471
472data IO a where
473 IORet :: a -> IO a
474 PutChar :: Char -> IO a -> IO a
475 GetChar :: (Char -> IO a) -> IO a
476
477data ReaderT r (m :: Type -> Type) a = ReaderTC (r -> m a)
478
479-----------------------------
480
481builtins
482 ifIdentity1 :: forall a . a -> ((Type -> Type) -> a) -> (Type -> Type) -> a
483 ifReaderT1 :: forall a . (Type -> (Type -> Type) -> a) -> ((Type -> Type) -> a) -> (Type -> Type) -> a
484
485builtins
486 Monad :: (Type -> Type) -> Type
487--let Monad = fix (\Monad -> ifIdentity1 Unit (ifReaderT1 (\r m -> Monad m) (\_ -> Empty)))
488
489----------------- recursive definition
490builtins monadD :: forall m . Monad m => MonadD m
491-- let monadD = fix (\monadD @t -> ifIdentity_1 identityMonad (ifReaderT_1 (\r m -> monadReaderT) undefined t))
492
493return = monadDCase (\_ -> _) (\r _ -> r) monadD
494bind = monadDCase (\_ -> _) (\_ b -> b) monadD
495
496monadReaderT = MonadDC (\a -> ReaderTC (\r -> return a))
497 (\m f -> ReaderTC (\r ->
498 readerTCase (\_ -> _)
499 (\g -> bind
500 (g r)
501 (\a -> readerTCase (\_ -> _) (\h -> h r) (f a)))
502 m))
503 -- :: forall r m . Monad m => MonadD (ReaderT r m)
504
505IOBind ma f = case ma of
506 IORet a -> f a
507 PutChar i r -> PutChar i (bind r f)
508 GetChar g -> GetChar (\i -> bind (g i) f)
509
510monadIO = MonadDC IORet IOBind
511-------------------------- end of recursive definition
512
513liftReaderT m = ReaderTC (\r -> m)
514
515bind' m m' = bind m (const m')
516fmap f m = bind m (comp return f)
517
518sequence = listCase (\_ -> _) (return Nil') (\x xs -> bind x (\vx -> fmap (Cons' vx) (sequence xs)))
519sequence_ = listCase (\_ -> _) (return TT) (\x xs -> bind' x (sequence_ xs))
520
521mapM f = comp sequence (listMap f)
522mapM_ f = comp sequence_ (listMap f)
523
524putChar i = PutChar i (return TT)
525getChar = GetChar return
526
527putStr = mapM_ putChar
528putStrLn = comp putStr (flip concat (Cons' #0 Nil'))
529
530-- todo -- getLine = bind getChar (\c -> boolCase (\_ -> _) (bind getLine (\cs -> return (Cons' c cs))) (return Nil') (eq c #0))
531
532--let mex_ = return' monadReaderT #3
533mex = return #3 :: IO Int
534mex' = return #3 :: ReaderT Bool IO Int
535
536-- todo -- main' = bind getLine putStrLn
537
538
539data Exp :: Type -> Type where
540 EInt :: Int -> Exp Int
541 EApp :: Exp (a -> b) -> Exp a -> Exp b
542 ECond :: Exp Bool -> Exp a -> Exp a -> Exp a
543
544expCase' :: forall
545 (c :: forall a -> Exp a -> Type)
546 -> (forall d -> c Int (EInt d))
547 -> (forall f g . forall i j -> c g (EApp @f @g i j))
548 -> (forall l . forall m n o -> c l (ECond @l m n o))
549 -> forall q
550 (r :: Exp q) -> c q r
551expCase' m i a c x e = expCase m i a c @x e
552
553expCase'' :: forall
554 (c :: forall a -> Exp a -> Type)
555 -> (forall d -> c Int (EInt d))
556 -> (forall f g . forall i j -> c g (EApp @f @g i j))
557 -> (forall l . forall m n o -> c l (ECond @l m n o))
558 -> forall q
559 . forall (r :: Exp q) -> c q r
560expCase'' m i a c @x e = expCase' m i a c x e
561
562-- todo -- eval :: forall a . Exp a -> a
563eval = expCase (\b _ -> b) -- todo: how to guess the motive
564 (\i -> i)
565 (\f a -> eval f (eval a))
566 (\b m n -> boolCase (\_ -> _) (eval n) (eval m) (eval b))
567 :: forall a . Exp a -> a
568
diff --git a/testdata/later.ignore/ShadowMapping.lc b/testdata/later.ignore/ShadowMapping.lc
new file mode 100644
index 00000000..e9bd2daa
--- /dev/null
+++ b/testdata/later.ignore/ShadowMapping.lc
@@ -0,0 +1,223 @@
1shadowMapSize = 512
2
3triangleCtx = TriangleCtx CullNone PolygonFill NoOffset LastVertex
4
5gaussFilter7 :: [(Float, Float)]
6gaussFilter7 =
7 [ (-3.0, 0.015625)
8 , (-2.0, 0.09375)
9 , (-1.0, 0.234375)
10 , (0.0, 0.3125)
11 , (1.0, 0.234375)
12 , (2.0, 0.09375)
13 , (3.0, 0.015625)
14 ]
15
16gaussFilter9 :: [(Float, Float)]
17gaussFilter9 =
18 [ (-4.0, 0.05)
19 , (-3.0, 0.09)
20 , (-2.0, 0.12)
21 , (-1.0, 0.15)
22 , (0.0, 0.16)
23 , (1.0, 0.15)
24 , (2.0, 0.12)
25 , (3.0, 0.09)
26 , (4.0, 0.05)
27 ]
28
29blurCoefficients :: [(Float, Float)]
30blurCoefficients = gaussFilter9
31
32blur :: [(Float, Float)] -> Image 1 (Color (Vec 4 Float)) -> FrameBuffer 1 (Color (Vec 4 Float))
33blur coefficients img = filter1D dirH (PrjImage (filter1D dirV img))
34 where
35 dirH v = V2 (v / shadowMapSize) 0.0
36 dirV v = V2 0.0 (v / shadowMapSize)
37
38 filter1D :: (Float -> Vec 2 Float) -> Image 1 (Color (Vec 4 Float)) -> FrameBuffer 1 (Color (Vec 4 Float))
39 filter1D dir img = accumulate accCtx PassAll frag
40 (Rasterize triangleCtx prims) clearBuf
41 where
42 accCtx = accumulationContext
43 (ColorOp NoBlending (V4 True True True True))
44 clearBuf = FrameBuffer (ColorImage @1 (V4 0 0 0 0.0))
45 vert :: Vec 2 Float -> VertexOut (Vec 2 Float)
46 vert uv = VertexOut pos 1 () (NoPerspective uv')
47 where
48 uv' = uv *! 0.5 +! 0.5
49 pos = V4 uv%x uv%y 1.0 1.0
50
51 prims = Transform vert (fetch "postSlot" Triangle (Attribute "position" :: Vec 2 Float))
52
53 frag :: FragmentShader (Vec 2 Float -> Color (Vec 4 Float))
54 frag = FragmentShader $ \uv -> sample
55 where
56 tex = Texture2D (V2 shadowMapSize shadowMapSize) img
57 smp = Sampler LinearFilter ClampToEdge tex
58 sample = foldr1 (\a b -> a + b) [ texture2D smp (uv + dir ofs) *! coeff
59 | (ofs, coeff) <- coefficients
60 ]
61
62moments :: FrameBuffer 1 (Depth Float, Color (Vec 4 Float))
63moments = accumulate accCtx PassAll frag (Rasterize triangleCtx prims) clearBuf
64 where
65 accCtx = accumulationContext (DepthOp Less True, ColorOp NoBlending (V4 True True True True))
66 clearBuf = FrameBuffer (DepthImage @1 1000, ColorImage @1 (V4 0.0 0.0 0.0 1.0{-todo: use 1-}))
67
68 lightMatrix = Uniform "lightMatrix" :: Mat 4 4 Float
69 modelMatrix = Uniform "modelMatrix" :: Mat 4 4 Float
70
71 vert :: Vec 3 Float -> VertexOut Float
72 vert pos = VertexOut lightPos 1 () (Smooth depth)
73 where
74 lightPos = lightMatrix *. modelMatrix *. v3FToV4F pos
75 depth = lightPos%z
76
77 prims = Transform vert (fetch "geometrySlot" Triangle (Attribute "position" :: Vec 3 Float))
78
79 frag :: FragmentShader (Float -> (Depth Float,Color (Vec 4 Float)))
80 frag = FragmentShaderRastDepth $ \depth -> (V4 moment1 moment2 0 1)
81 where
82 dx = dFdx depth
83 dy = dFdy depth
84 moment1 = depth
85 moment2 = depth *! depth +! 0.25 *! (dx *! dx +! dy *! dy)
86
87depth :: FrameBuffer 1 (Depth Float, Color (Vec 4 Float))
88depth = accumulate accCtx PassAll frag (Rasterize triangleCtx prims) clearBuf
89 where
90 accCtx = accumulationContext (DepthOp Less True, ColorOp NoBlending (V4 True True True True))
91 clearBuf = FrameBuffer (DepthImage @1 1000, ColorImage @1 (V4 0.0 0.0 0.0 1.0))
92
93 lightMatrix = Uniform "lightMatrix" :: Mat 4 4 Float
94 modelMatrix = Uniform "modelMatrix" :: Mat 4 4 Float
95
96 vert :: Vec 3 Float -> VertexOut Float
97 vert pos = VertexOut lightPos 1 () (Smooth depth)
98 where
99 lightPos = lightMatrix *. modelMatrix *. v3FToV4F pos
100 depth = lightPos%z
101
102 prims = Transform vert (fetch "geometrySlot" Triangle (Attribute "position" :: Vec 3 Float))
103
104 frag :: FragmentShader (Float -> (Depth Float, Color (Vec 4 Float)))
105 frag = FragmentShaderRastDepth $ \depth -> (V4 depth 0 0 1)
106
107failhere
108{- todo
109vsm :: FrameBuffer 1 (Depth Float, Color (Vec 4 Float))
110vsm = accumulate accCtx PassAll frag (Rasterize triangleCtx prims) clearBuf
111 where
112 accCtx = accumulationContext (DepthOp Less True, ColorOp NoBlending (V4 True True True True))
113 cameraMatrix = Uniform "cameraMatrix" :: Mat 4 4 Float
114 lightMatrix = Uniform "lightMatrix" :: Mat 4 4 Float
115 modelMatrix = Uniform "modelMatrix" :: Mat 4 4 Float
116 lightPosition = Uniform "lightPosition" :: Vec 3 Float
117
118 shadowMap = Texture2D (V2 shadowMapSize shadowMapSize) (PrjImageColor moments)
119 shadowMapBlur = Texture2D (V2 shadowMapSize shadowMapSize) (PrjImage blurredMoments)
120 where
121 blurredMoments = blur blurCoefficients (PrjImageColor moments)
122 sampler = Sampler LinearFilter ClampToEdge shadowMapBlur
123
124 frag :: FragmentShader ((Vec 3 Float, Vec 4 Float, Vec 3 Float) -> (Depth Float, Color (Vec 4 Float)))
125 frag = FragmentShaderRastDepth $ \(worldPos, lightPos, worldNormal) -> (luminance)
126 where
127 clampUV x = clampS x 0.0 1.0
128 scaleUV x = x *! 0.5 +! 0.5
129 lightU = lightPos%x
130 lightV = lightPos%y
131 lightDepth = lightPos%z
132 lightW = lightPos%w
133 uv = clampUV (scaleUV ((V2 lightU lightV) /! lightW))
134
135 val = texture2D sampler uv
136 moment1 = val%x
137 moment2 = val%y
138 variance = max 0.002 (moment2 -! moment1 *! moment1)
139 distance = max 0.0 (lightDepth -! moment1)
140 lightProbMax = variance /! (variance +! distance *! distance)
141
142 lambert = max 0.0 (dot worldNormal (normalize (lightPosition - worldPos)))
143
144 uv' = uv -! 0.5
145 spotShape = 1.0 -! length uv *! 4.0
146 intensity = max 0 (spotShape *! lambert)
147
148 val2 = scaleUV (round (uv' *! 10.0)) *! intensity
149 spotR = val2%x
150 spotG = val2%y
151
152 luminance = (V4 spotR spotG intensity 1.0) *! pow lightProbMax 2.0
153
154
155 clearBuf = FrameBuffer ( DepthImage @1 1000
156 , ColorImage @1 (V4 0.1 0.2 0.6 1))
157
158 vert :: (Vec 3 Float, Vec 3 Float) -> VertexOut (Vec 3 Float, Vec 4 Float, Vec 3 Float)
159 vert (localPos, localNormal) = VertexOut viewPos 1 () (Smooth worldPos%xyz, Smooth lightPos, Smooth worldNormal)
160 where
161 worldPos = modelMatrix *. v3FToV4F localPos
162 viewPos = cameraMatrix *. worldPos
163 lightPos = lightMatrix *. worldPos
164 worldNormal = normalize ((modelMatrix *. v3FToV4F localNormal)%xyz)
165
166 prims = Transform vert (fetch "geometrySlot" Triangle (Attribute "position" :: Vec 3 Float, Attribute "normal" :: Vec 3 Float))
167
168
169sm :: FrameBuffer 1 (Depth Float, Color (Vec 4 Float))
170sm = accumulate accCtx PassAll frag (Rasterize triangleCtx prims) clearBuf
171 where
172 accCtx = accumulationContext (DepthOp Less True, ColorOp NoBlending (V4 True True True True))
173 clearBuf = FrameBuffer (DepthImage @1 1000, ColorImage @1 (V4 0.1 0.2 0.6 1))
174 cameraMatrix = Uniform "cameraMatrix" :: Mat 4 4 Float
175 lightMatrix = Uniform "lightMatrix" :: Mat 4 4 Float
176 modelMatrix = Uniform "modelMatrix" :: Mat 4 4 Float
177 lightPosition = Uniform "lightPosition" :: Vec 3 Float
178
179 vert :: (Vec 3 Float, Vec 3 Float) -> VertexOut (Vec 3 Float, Vec 4 Float, Vec 3 Float)
180 vert (localPos, localNormal) = VertexOut viewPos 1 () (Smooth (worldPos%xyz), Smooth lightPos, Smooth worldNormal)
181 where
182 worldPos = modelMatrix *. v3FToV4F localPos
183 viewPos = cameraMatrix *. worldPos
184 lightPos = lightMatrix *. worldPos
185 worldNormal = normalize ((modelMatrix *. v3FToV4F localNormal)%xyz)
186
187 prims = Transform vert (fetch "geometrySlot" Triangle (Attribute "position" :: Vec 3 Float, Attribute "normal" :: Vec 3 Float))
188
189 --shadowMap :: Exp Obj (Texture Tex2D SingleTex (Regular Float) Red)
190 shadowMap = Texture2D (V2 shadowMapSize shadowMapSize) (PrjImageColor depth)
191 sampler = Sampler PointFilter ClampToEdge shadowMap
192
193 frag :: FragmentShader ((Vec 3 Float, Vec 4 Float, Vec 3 Float) -> (Depth Float, Color (Vec 4 Float)))
194 frag = FragmentShaderRastDepth $ \(worldPos, lightPos, worldNormal) -> (luminance)
195 where
196 lightU = lightPos%x
197 lightV = lightPos%y
198 lightDepth = lightPos%z
199 lightW = lightPos%w
200 clampUV x = clampS x 0 1
201 scaleUV x = x *! 0.5 +! 0.5
202 uv = clampUV (scaleUV ((V2 lightU lightV) /! lightW))
203
204 surfaceDistance = (texture2D sampler uv)%x
205 lightPortion = if (lightDepth <= surfaceDistance +! 0.01) then 1 else 0
206
207 lambert = max 0 (dot worldNormal (normalize (lightPosition - worldPos)))
208
209 --intensity = lambert @* lightPortion
210 --luminance = pack' (V4 intensity intensity intensity (floatF 1))
211
212 uv' = uv -! 0.5
213 spotShape = 1 -! length uv' *! 4
214 intensity = max 0 (spotShape *! lambert)
215
216 val = scaleUV (round (uv' *! 10)) *! intensity
217 spotR = val%x
218 spotG = val%y
219
220 luminance = (V4 spotR spotG intensity 1) *! lightPortion
221
222main = ScreenOut sm
223-}
diff --git a/testdata/later.ignore/fragment02tuple.lc b/testdata/later.ignore/fragment02tuple.lc
new file mode 100644
index 00000000..33a89b5d
--- /dev/null
+++ b/testdata/later.ignore/fragment02tuple.lc
@@ -0,0 +1,21 @@
1clear = FrameBuffer $ ColorImage @1 $ V4 1 0 0 0.5
2
3triangleRasterCtx = TriangleCtx CullNone PolygonFill NoOffset LastVertex
4colorFragmentCtx = accumulationContext (ColorOp NoBlending (V4 True True True True))
5
6rasterizeWith = Rasterize
7triangles = triangleRasterCtx
8
9quadVertexStream = fetch "quad" Triangle (Attribute "position" :: Vec 4 Float)
10
11transform s f = Transform (\v -> VertexOut v 1 () (f v)) s
12
13mapFragments s fs = accumulate colorFragmentCtx PassAll (FragmentShader $ \a -> fs a) s clear
14
15render f = quadVertexStream -- id vertices
16 `transform` (\a -> (Smooth a,Smooth a))
17 & rasterizeWith triangles -- rasterize
18 `mapFragments` f
19 & ScreenOut -- draw into screen
20
21main = render $ \(a,b) -> a `PrimAdd` b
diff --git a/testdata/later.ignore/fragment02vectorpattern.lc b/testdata/later.ignore/fragment02vectorpattern.lc
new file mode 100644
index 00000000..0e533a75
--- /dev/null
+++ b/testdata/later.ignore/fragment02vectorpattern.lc
@@ -0,0 +1,21 @@
1clear = FrameBuffer $ ColorImage @1 $ V4 1 0 0 0.5
2
3triangleRasterCtx = TriangleCtx CullNone PolygonFill NoOffset LastVertex
4colorFragmentCtx = accumulationContext (ColorOp NoBlending (V4 True True True True))
5
6rasterizeWith = Rasterize
7triangles = triangleRasterCtx
8
9quadVertexStream = fetch "quad" Triangle (Attribute "position" :: Vec 4 Float)
10
11transform s f = Transform (\v -> VertexOut (f v) 1 () (Smooth v)) s
12
13mapFragments s fs = accumulate colorFragmentCtx PassAll (FragmentShader $ \a -> fs a) s clear
14
15render f = quadVertexStream -- id vertices
16 `transform` id
17 & rasterizeWith triangles -- rasterize
18 `mapFragments` f
19 & ScreenOut -- draw into screen
20
21main = render $ \(V4 r g b a) -> V4 0 0 b 1
diff --git a/testdata/later.ignore/fragment05uniform.lc b/testdata/later.ignore/fragment05uniform.lc
new file mode 100644
index 00000000..7a8378f7
--- /dev/null
+++ b/testdata/later.ignore/fragment05uniform.lc
@@ -0,0 +1,22 @@
1time = Uniform "Time" :: Float
2clear = FrameBuffer $ ColorImage @1 $ V4 1 0 0 0.5
3
4triangleRasterCtx = TriangleCtx CullNone PolygonFill NoOffset LastVertex
5colorFragmentCtx = accumulationContext (ColorOp NoBlending (V4 True True True True))
6
7rasterizeWith = Rasterize
8triangles = triangleRasterCtx
9
10quadVertexStream = fetch "quad" Triangle (Attribute "position" :: Vec 4 Float)
11
12transform s f = Transform (\v -> VertexOut (f v) 1 () (Smooth v)) s
13
14mapFragments s fs = accumulate colorFragmentCtx PassAll (FragmentShader $ \a -> fs a) s clear
15
16render f = quadVertexStream -- id vertices
17 `transform` id
18 & rasterizeWith triangles -- rasterize
19 `mapFragments` f
20 & ScreenOut -- draw into screen
21
22main = render $ \(V4 r g b a) -> V4 0 (0.5 +! (0.5 *! sin time)) b 1
diff --git a/testdata/later.ignore/fragment06tailrecursion.lc b/testdata/later.ignore/fragment06tailrecursion.lc
new file mode 100644
index 00000000..2fa86d15
--- /dev/null
+++ b/testdata/later.ignore/fragment06tailrecursion.lc
@@ -0,0 +1,24 @@
1time = Uniform "Time" :: Float
2clear = FrameBuffer $ ColorImage @1 $ V4 1 0 0 0.5
3
4triangleRasterCtx = TriangleCtx CullNone PolygonFill NoOffset LastVertex
5colorFragmentCtx = accumulationContext (ColorOp NoBlending (V4 True True True True))
6
7rasterizeWith = Rasterize
8triangles = triangleRasterCtx
9
10quadVertexStream = fetch "quad" Triangle (Attribute "position" :: Vec 4 Float)
11
12transform s f = Transform (\v -> VertexOut (f v) 1 () (Smooth v)) s
13
14mapFragments s fs = accumulate colorFragmentCtx PassAll (FragmentShader $ \a -> fs a) s clear
15
16render f = quadVertexStream -- id vertices
17 `transform` id
18 & rasterizeWith triangles -- rasterize
19 `mapFragments` f
20 & ScreenOut -- draw into screen
21
22fun x = if x < 0 then 0 else x +! fun (x -! 0.3)
23
24main' = render $ \c -> if fun time < 0.5 then c else blue
diff --git a/testdata/later.ignore/fragmenttest.lc b/testdata/later.ignore/fragmenttest.lc
new file mode 100644
index 00000000..47ef3ebe
--- /dev/null
+++ b/testdata/later.ignore/fragmenttest.lc
@@ -0,0 +1 @@
main = ScreenOut $ fragmentTest $ \x y -> if x *! x +! y *! y > 0.5 then blue else green
diff --git a/testdata/later.ignore/fragmenttest.out b/testdata/later.ignore/fragmenttest.out
new file mode 100644
index 00000000..2034e78e
--- /dev/null
+++ b/testdata/later.ignore/fragmenttest.out
@@ -0,0 +1 @@
Pipeline {backend = WebGL1, textures = [], samplers = [], targets = [RenderTarget {renderTargets = [TargetItem {targetSemantic = Color, targetRef = Just (Framebuffer Color)}]}], programs = [Program {programUniforms = fromList [], programStreams = fromList [("v",Parameter {name = "position", ty = V2F})], programInTextures = fromList [], programOutput = [Parameter {name = "f0", ty = V4F}], vertexShader = "#version 100\nprecision highp float;\nprecision highp int;\nattribute vec2 v ;\nvarying vec2 v0 ;\nvoid main() {\nv0 = v;\ngl_Position = vec4 ( ( v ).x,( v ).y,1.0,1.0 );\ngl_PointSize = 1.0;\n}\n", geometryShader = Nothing, fragmentShader = "#version 100\nprecision highp float;\nprecision highp int;\nvarying vec2 v0 ;\nvoid main() {\ngl_FragColor = ( ( ( ( v0 ).x ) * ( ( v0 ).x ) ) + ( ( ( v0 ).y ) * ( ( v0 ).y ) ) ) > ( 0.5 ) ? vec4 ( 0.0,0.0,1.0,1.0 ) : vec4 ( 0.0,0.5,0.0,1.0 );\n}\n"}], slots = [Slot {slotName = "quad", slotStreams = fromList [("position",V2F)], slotUniforms = fromList [], slotPrimitive = Triangles, slotPrograms = [0]}], streams = [], commands = [SetRenderTarget 0,ClearRenderTarget [ClearImage {imageSemantic = Color, clearValue = VV4F (V4 1.0 0.0 0.0 0.5)}],SetProgram 0,SetRasterContext (TriangleCtx CullNone PolygonFill NoOffset LastVertex),SetAccumulationContext (AccumulationContext {accViewportName = Nothing, accOperations = [ColorOp NoBlending (VV4B (V4 True True True True))]}),RenderSlot 0]} \ No newline at end of file