summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testdata/hlist.ignore/Builtins.lc590
-rw-r--r--testdata/hlist.ignore/Internals.lc152
-rw-r--r--testdata/hlist.ignore/Prelude.lc362
3 files changed, 1104 insertions, 0 deletions
diff --git a/testdata/hlist.ignore/Builtins.lc b/testdata/hlist.ignore/Builtins.lc
new file mode 100644
index 00000000..190bc6eb
--- /dev/null
+++ b/testdata/hlist.ignore/Builtins.lc
@@ -0,0 +1,590 @@
1{-# LANGUAGE NoImplicitPrelude #-}
2
3module Builtins
4 ( module Internals
5 , module Builtins
6 ) where
7
8import Internals
9
10id x = x
11
12---------------------------------------
13
14class AttributeTuple a
15instance AttributeTuple a -- TODO
16class ValidOutput a
17instance ValidOutput a -- TODO
18
19data VecS (a :: Type) :: Nat -> Type where
20 V2 :: a -> a -> VecS a 2
21 V3 :: a -> a -> a -> VecS a 3
22 V4 :: a -> a -> a -> a -> VecS a 4
23
24type family Vec (n :: Nat) t where Vec n t = VecS t n
25
26type family VecScalar (n :: Nat) a where
27 VecScalar 1 a = a
28 VecScalar ('Succ ('Succ n)) a = Vec ('Succ ('Succ n)) a
29
30-- may be a data family?
31type family TFVec (n :: Nat) a where
32 TFVec n a = Vec n a -- TODO: check range: n = 2,3,4; a is Float, Int, Word, Bool
33
34-- todo: use less constructors with more parameters
35data Mat :: Nat -> Nat -> Type -> Type where
36 M22F :: Vec 2 Float -> Vec 2 Float -> Mat 2 2 Float
37 M32F :: Vec 3 Float -> Vec 3 Float -> Mat 3 2 Float
38 M42F :: Vec 4 Float -> Vec 4 Float -> Mat 4 2 Float
39 M23F :: Vec 2 Float -> Vec 2 Float -> Vec 2 Float -> Mat 2 3 Float
40 M33F :: Vec 3 Float -> Vec 3 Float -> Vec 3 Float -> Mat 3 3 Float
41 M43F :: Vec 4 Float -> Vec 4 Float -> Vec 4 Float -> Mat 4 3 Float
42 M24F :: Vec 2 Float -> Vec 2 Float -> Vec 2 Float -> Vec 2 Float -> Mat 2 4 Float
43 M34F :: Vec 3 Float -> Vec 3 Float -> Vec 3 Float -> Vec 3 Float -> Mat 3 4 Float
44 M44F :: Vec 4 Float -> Vec 4 Float -> Vec 4 Float -> Vec 4 Float -> Mat 4 4 Float
45
46type family MatVecScalarElem a where
47 MatVecScalarElem Float = Float
48 MatVecScalarElem Bool = Bool
49 MatVecScalarElem Int = Int
50 MatVecScalarElem (VecS a n) = a
51 MatVecScalarElem (Mat i j a) = a
52
53--------------------------------------- swizzling
54
55data Swizz = Sx | Sy | Sz | Sw
56
57-- todo: use pattern matching
58mapVec :: forall a b m . (a -> b) -> Vec m a -> Vec m b
59mapVec @a @b @m f v = 'VecSCase (\m _ -> 'Vec m b)
60 (\x y -> V2 (f x) (f y))
61 (\x y z -> V3 (f x) (f y) (f z))
62 (\x y z w -> V4 (f x) (f y) (f z) (f w))
63 @m
64 v
65
66-- todo: make it more type safe
67swizzscalar :: forall n . Vec n a -> Swizz -> a
68swizzscalar (V2 x y) Sx = x
69swizzscalar (V2 x y) Sy = y
70swizzscalar (V3 x y z) Sx = x
71swizzscalar (V3 x y z) Sy = y
72swizzscalar (V3 x y z) Sz = z
73swizzscalar (V4 x y z w) Sx = x
74swizzscalar (V4 x y z w) Sy = y
75swizzscalar (V4 x y z w) Sz = z
76swizzscalar (V4 x y z w) Sw = w
77
78-- used to prevent unfolding of swizzvector on variables (behind GPU lambda)
79definedVec :: forall a m . Vec m a -> Bool
80definedVec (V2 _ _) = True
81definedVec (V3 _ _ _) = True
82definedVec (V4 _ _ _ _) = True
83
84swizzvector :: forall n . forall m . Vec n a -> Vec m Swizz -> Vec m a
85swizzvector v w | definedVec v = mapVec (swizzscalar v) w
86
87
88--------------------------------------- type classes
89
90class Signed a
91
92instance Signed Int
93instance Signed Float
94
95class Component a where
96 zeroComp :: a
97 oneComp :: a
98
99instance Component Int where
100 zeroComp = 0 :: Int
101 oneComp = 1 :: Int
102instance Component Word where
103 zeroComp = 0 :: Word
104 oneComp = 1 :: Word
105instance Component Float where
106 zeroComp = 0.0
107 oneComp = 1.0
108instance Component (VecS Float 2) where
109 zeroComp = V2 0.0 0.0
110 oneComp = V2 1.0 1.0
111instance Component (VecS Float 3) where
112 zeroComp = V3 0.0 0.0 0.0
113 oneComp = V3 1.0 1.0 1.0
114instance Component (VecS Float 4) where
115 zeroComp = V4 0.0 0.0 0.0 0.0
116 oneComp = V4 1.0 1.0 1.0 1.0
117instance Component Bool where
118 zeroComp = False
119 oneComp = True
120instance Component (VecS Bool 2) where
121 zeroComp = V2 False False
122 oneComp = V2 True True
123instance Component (VecS Bool 3) where
124 zeroComp = V3 False False False
125 oneComp = V3 True True True
126instance Component (VecS Bool 4) where
127 zeroComp = V4 False False False False
128 oneComp = V4 True True True True
129
130class Integral a
131
132instance Integral Int
133instance Integral Word
134
135class Floating a
136
137instance Floating Float
138instance Floating (VecS Float 2) -- todo: use Vec
139instance Floating (VecS Float 3)
140instance Floating (VecS Float 4)
141instance Floating (Mat 2 2 Float)
142instance Floating (Mat 2 3 Float)
143instance Floating (Mat 2 4 Float)
144instance Floating (Mat 3 2 Float)
145instance Floating (Mat 3 3 Float)
146instance Floating (Mat 3 4 Float)
147instance Floating (Mat 4 2 Float)
148instance Floating (Mat 4 3 Float)
149instance Floating (Mat 4 4 Float)
150
151data BlendingFactor
152 = Zero' --- FIXME: modified
153 | One
154 | SrcColor
155 | OneMinusSrcColor
156 | DstColor
157 | OneMinusDstColor
158 | SrcAlpha
159 | OneMinusSrcAlpha
160 | DstAlpha
161 | OneMinusDstAlpha
162 | ConstantColor
163 | OneMinusConstantColor
164 | ConstantAlpha
165 | OneMinusConstantAlpha
166 | SrcAlphaSaturate
167
168data BlendEquation
169 = FuncAdd
170 | FuncSubtract
171 | FuncReverseSubtract
172 | Min
173 | Max
174
175data LogicOperation
176 = Clear
177 | And
178 | AndReverse
179 | Copy
180 | AndInverted
181 | Noop
182 | Xor
183 | Or
184 | Nor
185 | Equiv
186 | Invert
187 | OrReverse
188 | CopyInverted
189 | OrInverted
190 | Nand
191 | Set
192
193data StencilOperation
194 = OpZero
195 | OpKeep
196 | OpReplace
197 | OpIncr
198 | OpIncrWrap
199 | OpDecr
200 | OpDecrWrap
201 | OpInvert
202
203data ComparisonFunction
204 = Never
205 | Less
206 | Equal
207 | Lequal
208 | Greater
209 | Notequal
210 | Gequal
211 | Always
212
213data ProvokingVertex
214 = LastVertex
215 | FirstVertex
216
217data CullMode
218 = CullFront
219 | CullBack
220 | CullNone
221
222data PointSize a
223 = PointSize Float
224 | ProgramPointSize (a -> Float)
225
226data PolygonMode a
227 = PolygonFill
228 | PolygonPoint (PointSize a)
229 | PolygonLine Float
230
231data PolygonOffset
232 = NoOffset
233 | Offset Float Float
234
235data PointSpriteCoordOrigin
236 = LowerLeft
237 | UpperLeft
238
239data ImageSemantics = Depth Type | Stencil Type | Color Type
240
241data PrimitiveType
242 = Triangle
243 | Line
244 | Point
245 | TriangleAdjacency
246 | LineAdjacency
247
248-- builtin
249primTexture :: () -> Vec 2 Float -> Vec 4 Float
250
251-- builtins
252Uniform :: String -> t
253Attribute :: String -> t
254
255data RasterContext a :: PrimitiveType -> Type where
256 TriangleCtx :: CullMode -> PolygonMode a -> PolygonOffset -> ProvokingVertex -> RasterContext a Triangle
257 PointCtx :: PointSize a -> Float -> PointSpriteCoordOrigin -> RasterContext a Point
258 LineCtx :: Float -> ProvokingVertex -> RasterContext a Line
259
260map _ [] = []
261map f (x:xs) = f x : map f xs
262
263type family ListElem a
264type instance ListElem [a] = a
265
266type family FTRepr' a where
267 FTRepr' (HList l) = HList (map ListElem l)
268{-
269type family FTRepr' a where
270 -- TODO
271 FTRepr' [a] = a
272 FTRepr' ([a], [b]) = (a, b)
273-}
274data Blending :: Type -> Type where
275 NoBlending :: Blending t
276 BlendLogicOp :: (Integral t) => LogicOperation -> Blending t
277 Blend :: (BlendEquation, BlendEquation)
278 -> ((BlendingFactor, BlendingFactor), (BlendingFactor, BlendingFactor))
279 -> Vec 4 Float -> Blending Float
280
281{- TODO: more precise kinds
282 FragmentOperation :: Semantic -> *
283 FragmentOut :: Semantic -> *
284-}
285
286data StencilTests
287data StencilOps
288data Int32
289
290data FragmentOperation :: ImageSemantics -> Type where
291 ColorOp :: (mask ~ VecScalar d Bool, color ~ VecScalar d c, Num c) => Blending c -> mask
292 -> FragmentOperation (Color color)
293 DepthOp :: ComparisonFunction -> Bool -> FragmentOperation (Depth Float)
294 StencilOp :: StencilTests -> StencilOps -> StencilOps -> FragmentOperation (Stencil Int32)
295
296[] ++ ys = ys
297x:xs ++ ys = x : xs ++ ys
298
299foldr f e [] = e
300foldr f e (x: xs) = f x (foldr f e xs)
301
302concat = foldr (++) []
303
304concatMap :: (a -> [b]) -> [a] -> [b]
305concatMap f x = concat (map f x)
306
307data Primitive a :: PrimitiveType -> Type where
308 PrimPoint :: a -> Primitive a Point
309 PrimLine :: a -> a -> Primitive a Line
310 PrimTriangle :: a -> a -> a -> Primitive a Triangle
311
312type PrimitiveStream a t = [Primitive t a]
313
314mapPrimitive :: (a -> b) -> Primitive a p -> Primitive b p
315{- todo
316mapPrimitive f (PrimPoint a) = PrimPoint (f a)
317mapPrimitive f (PrimLine a b) = PrimLine (f a) (f b)
318mapPrimitive f (PrimTriangle a b c) = PrimTriangle (f a) (f b) (f c)
319-}
320
321fetch_ :: forall a t . (AttributeTuple t) => String -> t -> PrimitiveStream a t
322fetchArrays_ :: forall a t t' . (AttributeTuple t, t ~ FTRepr' t') => t' -> PrimitiveStream a t
323
324mapPrimitives :: (a -> b) -> PrimitiveStream p a -> PrimitiveStream p b
325mapPrimitives f = map (mapPrimitive f)
326
327fetch s a t = fetch_ @a s t
328fetchArrays a t = fetchArrays_ @a t
329
330-------------------
331
332data Maybe a
333 = Nothing
334 | Just a
335-- deriving (Eq, Ord, Show)
336
337data Vector (n :: Nat) t
338
339type Fragment n t = Vector n (Maybe (SimpleFragment t))
340
341data SimpleFragment t = SimpleFragment
342 { sFragmentCoords :: Vec 3 Float
343 , sFragmentValue :: t
344 }
345
346type FragmentStream n t = [Fragment n t]
347
348customizeDepth :: (a -> Float) -> Fragment n a -> Fragment n a
349
350customizeDepths :: (a -> Float) -> FragmentStream n a -> FragmentStream n a
351customizeDepths f = map (customizeDepth f)
352
353filterFragment :: (a -> Bool) -> Fragment n a -> Fragment n a
354
355filterFragments :: (a -> Bool) -> FragmentStream n a -> FragmentStream n a
356filterFragments p = map (filterFragment p)
357
358mapFragment :: (a -> b) -> Fragment n a -> Fragment n b
359
360mapFragments :: (a -> b) -> FragmentStream n a -> FragmentStream n b
361mapFragments f = map (mapFragment f)
362
363
364data Interpolated t where
365 Smooth, NoPerspective
366 :: (Floating t) => Interpolated t
367 Flat :: Interpolated t
368
369type family GetInterpolatedType a
370type instance GetInterpolatedType (Interpolated a) = a
371
372interpolatedType = map 'GetInterpolatedType
373{-
374type family InterpolatedType a where
375 InterpolatedType () = ()
376 InterpolatedType (Interpolated a) = a
377 InterpolatedType (Interpolated a, Interpolated b) = (a, b)
378 InterpolatedType (Interpolated a, Interpolated b, Interpolated c) = (a, b, c)
379-}
380
381
382rasterizePrimitive
383 :: ( map Interpolated b ~ interpolation
384 , a ~ '( '(Vec 4 Float) : b) )
385 => HList interpolation -- tuple of Smooth & Flat
386 -> RasterContext (HList a) x
387 -> Primitive (HList a) x
388 -> FragmentStream 1 (HList b)
389
390rasterizePrimitives ctx is s = concat (map (rasterizePrimitive is ctx) s)
391
392data Image (n :: Nat) (t :: ImageSemantics) -- = Vector n [[t]]
393
394ColorImage :: forall a d t color . (Num t, color ~ VecScalar d t)
395 => color -> Image a (Color color)
396DepthImage :: forall a . Float -> Image a (Depth Float)
397StencilImage :: forall a . Int -> Image a (Stencil Int)
398
399type family ImageLC a :: Nat
400type instance ImageLC (Image n t) = n
401
402allSame :: [a] -> Type
403allSame [] = 'Unit
404allSame [x] = 'Unit
405allSame (x: y: xs) = 'T2 (x ~ y) (allSame (y:xs))
406
407sameLayerCounts a = allSame (map 'ImageLC a)
408{-
409type family SameLayerCounts a where
410 SameLayerCounts (Image n1 t1) = Unit
411 SameLayerCounts (Image n1 t1, Image n2 t2) = EqCT Nat n1 n2
412 SameLayerCounts (Image n1 t1, Image n2 t2, Image n3 t3) = T2 (EqCT Nat n1 n2) (EqCT Nat n1 n3)
413-}
414
415{-
416class DefaultFragOp a where defaultFragOp :: FragmentOperation a
417instance DefaultFragOp (Color (VecS Float 4)) where defaultFragOp = ColorOp NoBlending (V4 True True True True)
418instance DefaultFragOp (Depth Float) where defaultFragOp = DepthOp Less True
419
420class DefaultFragOps a where defaultFragOps :: a
421instance (DefaultFragOp a, DefaultFragOp b) => DefaultFragOps (FragmentOperation a, FragmentOperation b) where
422 defaultFragOps = -- (undefined @(), undefined)
423 (defaultFragOp @a @_, defaultFragOp @b @_)
424-}
425data FrameBuffer (n :: Nat) (t :: [ImageSemantics])
426
427remSemantics :: ImageSemantics -> Type
428remSemantics (Color a) = a
429remSemantics (Depth a) = a
430remSemantics (Stencil a) = a
431
432remSemantics' :: [ImageSemantics] -> [Type]
433remSemantics' (Depth _: x) = map remSemantics x
434remSemantics' x = map remSemantics x
435
436type family FragmentOperationSem a :: ImageSemantics
437type instance FragmentOperationSem (FragmentOperation x) = x
438
439Accumulate :: forall (n :: Nat) (c :: [Type]) . (b ~ map FragmentOperationSem c) => HList c -> FragmentStream n (HList (remSemantics' b)) -> FrameBuffer n b -> FrameBuffer n b
440
441type family ImageSem a :: ImageSemantics
442type instance ImageSem (Image n t) = t
443
444tfFrameBuffer t = map 'ImageSem t
445{-
446type family TFFrameBuffer a where
447 TFFrameBuffer (Image n1 t1) = FrameBuffer n1 '[t1]
448 TFFrameBuffer (Image n1 t1, Image n2 t2) = FrameBuffer n1 '[t1, t2]
449 TFFrameBuffer (Image n1 t1, Image n2 t2, Image n3 t3) = FrameBuffer n1 '[t1, t2, t3]
450-}
451
452class ValidFrameBuffer (a :: [ImageSemantics])
453instance ValidFrameBuffer a -- TODO
454
455head (x: _) = x
456
457FrameBuffer :: forall (a :: [Type]) . (sameLayerCounts a) => HList a -> FrameBuffer (ImageLC (head a)) (tfFrameBuffer a)
458
459accumulate ctx fshader fstr fb = Accumulate ctx (mapFragments fshader fstr) fb
460
461accumulationContext x = x
462
463-- texture support
464PrjImage :: FrameBuffer 1 '[a] -> Image 1 a
465PrjImageColor :: FrameBuffer 1 '[Depth 'Float, Color '(Vec 4 Float)] -> Image 1 (Color (Vec 4 Float))
466
467data Output where
468 ScreenOut :: FrameBuffer a b -> Output
469
470-------------------------------------------------------------------
471-- * Builtin Primitive Functions *
472-- Arithmetic Functions (componentwise)
473
474PrimAdd, PrimSub, PrimMul :: Num (MatVecScalarElem a) => a -> a -> a
475PrimAddS, PrimSubS, PrimMulS :: (t ~ MatVecScalarElem a, Num t) => a -> t -> a
476PrimDiv, PrimMod :: (Num t, a ~ VecScalar d t) => a -> a -> a
477PrimDivS, PrimModS :: (Num t, a ~ VecScalar d t) => a -> t -> a
478PrimNeg :: Signed (MatVecScalarElem a) => a -> a
479-- Bit-wise Functions
480PrimBAnd, PrimBOr, PrimBXor :: (Integral t, a ~ VecScalar d t) => a -> a -> a
481PrimBAndS, PrimBOrS, PrimBXorS:: (Integral t, a ~ VecScalar d t) => a -> t -> a
482PrimBNot :: (Integral t, a ~ VecScalar d t) => a -> a
483PrimBShiftL, PrimBShiftR :: (Integral t, a ~ VecScalar d t, b ~ VecScalar d Word) => a -> b -> a
484PrimBShiftLS, PrimBShiftRS :: (Integral t, a ~ VecScalar d t) => a -> Word -> a
485-- Logic Functions
486PrimAnd, PrimOr, PrimXor :: Bool -> Bool -> Bool
487PrimNot :: forall a d . (a ~ VecScalar d Bool) => a -> a
488PrimAny, PrimAll :: VecScalar d Bool -> Bool
489
490-- Angle, Trigonometry and Exponential Functions
491PrimACos, PrimACosH, PrimASin, PrimASinH, PrimATan, PrimATanH, PrimCos, PrimCosH, PrimDegrees, PrimRadians, PrimSin, PrimSinH, PrimTan, PrimTanH, PrimExp, PrimLog, PrimExp2, PrimLog2, PrimSqrt, PrimInvSqrt
492 :: (a ~ VecScalar d Float) => a -> a
493PrimPow, PrimATan2 :: (a ~ VecScalar d Float) => a -> a -> a
494-- Common Functions
495PrimFloor, PrimTrunc, PrimRound, PrimRoundEven, PrimCeil, PrimFract
496 :: (a ~ VecScalar d Float) => a -> a
497PrimMin, PrimMax :: (Num t, a ~ VecScalar d t) => a -> a -> a
498PrimMinS, PrimMaxS :: (Num t, a ~ VecScalar d t) => a -> t -> a
499PrimIsNan, PrimIsInf :: (a ~ VecScalar d Float, b ~ VecScalar d Bool) => a -> b
500PrimAbs, PrimSign :: (Signed t, a ~ VecScalar d t) => a -> a
501PrimModF :: (a ~ VecScalar d Float) => a -> (a, a)
502PrimClamp :: (Num t, a ~ VecScalar d t) => a -> a -> a -> a
503PrimClampS :: (Num t, a ~ VecScalar d t) => a -> t -> t -> a
504PrimMix :: (a ~ VecScalar d Float) => a -> a -> a -> a
505PrimMixS :: (a ~ VecScalar d Float) => a -> a -> Float -> a
506PrimMixB :: (a ~ VecScalar d Float, b ~ VecScalar d Bool) => a -> a -> b -> a
507PrimStep :: (a ~ TFVec d Float) => a -> a -> a
508PrimStepS :: (a ~ VecScalar d Float) => Float -> a -> a
509PrimSmoothStep :: (a ~ TFVec d Float) => a -> a -> a -> a
510PrimSmoothStepS :: (a ~ VecScalar d Float) => Float -> Float -> a -> a
511
512-- Integer/Floatonversion Functions
513PrimFloatBitsToInt :: VecScalar d Float -> VecScalar d Int
514PrimFloatBitsToUInt :: VecScalar d Float -> VecScalar d Word
515PrimIntBitsToFloat :: VecScalar d Int -> VecScalar d Float
516PrimUIntBitsToFloat :: VecScalar d Word -> VecScalar d Float
517-- Geometric Functions
518PrimLength :: (a ~ VecScalar d Float) => a -> Float
519PrimDistance, PrimDot :: (a ~ VecScalar d Float) => a -> a -> Float
520PrimCross :: (a ~ VecScalar 3 Float) => a -> a -> a
521PrimNormalize :: (a ~ VecScalar d Float) => a -> a
522PrimFaceForward, PrimRefract :: (a ~ VecScalar d Float) => a -> a -> a -> a
523PrimReflect :: (a ~ VecScalar d Float) => a -> a -> a
524-- Matrix Functions
525PrimTranspose :: Mat h w a -> Mat w h a
526PrimDeterminant :: Mat s s a -> Float
527PrimInverse :: Mat s s a -> Mat s s a
528PrimOuterProduct :: Vec w a -> Vec h a -> Mat h w a
529PrimMulMatVec :: Mat h w a -> Vec w a -> Vec h a
530PrimMulVecMat :: Vec h a -> Mat h w a -> Vec w a
531PrimMulMatMat :: Mat i j a -> Mat j k a -> Mat i k a
532-- Vector and Scalar Relational Functions
533PrimLessThan, PrimLessThanEqual, PrimGreaterThan, PrimGreaterThanEqual, PrimEqualV, PrimNotEqualV
534 :: forall a d t b . (Num t, a ~ VecScalar d t, b ~ VecScalar d Bool) => a -> a -> b
535PrimEqual, PrimNotEqual :: forall a t . (t ~ MatVecScalarElem a) => a -> a -> Bool
536-- Fragment Processing Functions
537PrimDFdx, PrimDFdy, PrimFWidth
538 :: (a ~ VecScalar d Float) => a -> a
539-- Noise Functions
540PrimNoise1 :: VecScalar d Float -> Float
541PrimNoise2 :: VecScalar d Float -> Vec 2 Float
542PrimNoise3 :: VecScalar d Float -> Vec 3 Float
543PrimNoise4 :: VecScalar d Float -> Vec 4 Float
544
545{-
546-- Vec/Mat (de)construction
547PrimTupToV2 :: Component a => PrimFun stage ((a,a) -> V2 a)
548PrimTupToV3 :: Component a => PrimFun stage ((a,a,a) -> V3 a)
549PrimTupToV4 :: Component a => PrimFun stage ((a,a,a,a) -> V4 a)
550PrimV2ToTup :: Component a => PrimFun stage (V2 a -> (a,a))
551PrimV3ToTup :: Component a => PrimFun stage (V3 a -> (a,a,a))
552PrimV4ToTup :: Component a => PrimFun stage (V4 a -> (a,a,a,a))
553-}
554
555--------------------
556-- * Texture support
557-- FIXME: currently only Float RGBA 2D texture is supported
558
559data Texture where
560 Texture2DSlot :: String -- texture slot name
561 -> Texture
562
563 Texture2D :: Vec 2 Int -- FIXME: use Word here
564 -> Image 1 (Color (Vec 4 Float))
565 -> Texture
566
567data Filter
568 = PointFilter
569 | LinearFilter
570
571data EdgeMode
572 = Repeat
573 | MirroredRepeat
574 | ClampToEdge
575
576data Sampler = Sampler Filter EdgeMode Texture
577
578-- builtin
579texture2D :: Sampler -> Vec 2 Float -> Vec 4 Float
580
581
582accumulateWith ctx x = (ctx, x)
583overlay cl (ctx, str) = Accumulate ctx str cl
584renderFrame = ScreenOut
585imageFrame = FrameBuffer
586emptyDepthImage = DepthImage @1
587emptyColorImage = ColorImage @1
588
589infixl 0 `overlay`
590
diff --git a/testdata/hlist.ignore/Internals.lc b/testdata/hlist.ignore/Internals.lc
new file mode 100644
index 00000000..245a29d3
--- /dev/null
+++ b/testdata/hlist.ignore/Internals.lc
@@ -0,0 +1,152 @@
1{-# LANGUAGE NoImplicitPrelude #-}
2-- declarations of builtin functions and data types used by the compiler
3module Internals where
4
5-- used for type annotations
6typeAnn x = x
7
8undefined :: forall (a :: Type) . a
9
10primFix :: forall (a :: Type) . (a -> a) -> a
11
12data Unit = TT
13data String
14data Empty (a :: String)
15
16unsafeCoerce :: forall a b . a -> b
17
18-- equality constraints
19type family EqCT (t :: Type) (a :: t) (b :: t)
20{-
21coe :: forall (a :: Type) (b :: Type) -> EqCT Type a b -> a -> b
22coe a b TT x = unsafeCoerce @a @b x
23-}
24
25-- ... TODO
26
27-- builtin used for overlapping instances
28parEval :: forall a -> a -> a -> a
29
30-- conjuction of constraints
31type family T2 a b
32
33match'Type :: forall (m :: Type -> Type) -> m Type -> forall (t :: Type) -> m t -> m t
34
35type EqCTt = EqCT _
36
37-- builtin conjuction of constraint witnesses
38t2C :: Unit -> Unit -> Unit
39
40-- builtin type constructors
41data Int
42data Word
43data Float
44data Char
45
46data Bool = False | True
47
48data Ordering = LT | EQ | GT
49
50data Nat = Zero | Succ Nat
51
52-- builtin primitives
53primIntToWord :: Int -> Word
54primIntToFloat :: Int -> Float
55primIntToNat :: Int -> Nat
56primCompareInt :: Int -> Int -> Ordering
57primCompareWord :: Word -> Word -> Ordering
58primCompareFloat :: Float -> Float -> Ordering
59primCompareChar :: Char -> Char -> Ordering
60primCompareString :: String -> String -> Ordering
61primNegateInt :: Int -> Int
62primNegateWord :: Word -> Word
63primNegateFloat :: Float -> Float
64primAddInt :: Int -> Int -> Int
65primSubInt :: Int -> Int -> Int
66primModInt :: Int -> Int -> Int
67primSqrtFloat :: Float -> Float
68primRound :: Float -> Int
69
70
71primIfThenElse :: Bool -> a -> a -> a
72primIfThenElse True a b = a
73primIfThenElse False a b = b
74
75isEQ EQ = True
76isEQ _ = False
77
78-- fromInt is needed for integer literal
79class Num a where
80 fromInt :: Int -> a
81 compare :: a -> a -> Ordering
82 negate :: a -> a
83
84instance Num Int where
85 fromInt = \x -> x
86 compare = primCompareInt
87 negate = primNegateInt
88instance Num Word where
89 fromInt = primIntToWord
90 compare = primCompareWord
91 negate = primNegateWord
92instance Num Float where
93 fromInt = primIntToFloat
94 compare = primCompareFloat
95 negate = primNegateFloat
96instance Num Nat where
97 fromInt = primIntToNat --if isEQ (primCompareInt n zero') then Zero else Succ (fromInt (primSubInt n one'))
98 compare = undefined
99 negate = undefined
100
101class Eq a where
102 (==) :: a -> a -> Bool -- todo: use (==) sign
103
104infix 4 ==
105
106instance Eq String where a == b = isEQ (primCompareString a b)
107instance Eq Char where a == b = isEQ (primCompareChar a b)
108instance Eq Int where a == b = isEQ (primCompareInt a b)
109instance Eq Float where a == b = isEQ (primCompareFloat a b)
110instance Eq Bool where
111 True == True = True
112 False == False = True
113 _ == _ = False
114instance Eq Nat where
115 Zero == Zero = True
116 Succ a == Succ b = a == b
117 _ == _ = False
118
119data List a = Nil | Cons a (List a)
120
121infixr 5 :
122
123data HList :: [Type] -> Type where
124 HNil :: HList '[]
125 HCons :: x -> HList xs -> HList '(x: xs)
126
127-- TODO: generate?
128data Tuple0 = Tuple0
129data Tuple1 a = Tuple1 a
130data Tuple2 a b = Tuple2 a b
131data Tuple3 a b c = Tuple3 a b c
132data Tuple4 a b c d = Tuple4 a b c d
133data Tuple5 a b c d e = Tuple5 a b c d e
134
135--testmt :: forall (t :: Type) -> t -> t
136--testmt 'Type = \'Tuple0 -> 'Tuple0
137--testmt t x = (match'Type (\q -> (q -> q)) (\x -> match'Tuple0 (\q -> & 'Type) 'Tuple0 x undefined) t undefined) x
138--testmt t x = (match'Type (\q -> (q -> q)) (\x -> match'Tuple0 (\q -> 'Type) 'Tuple0 x undefined) t undefined) x
139
140--type instance EqCT Type = \'Type 'Type -> 'Unit
141--type instance EqCT Type = \'(a, b) '(JoinTupleType a' b') -> '(T2 (EqCT Type a a') (EqCT Type b b'))
142
143type family JoinTupleType t1 t2 where
144 -- TODO
145 JoinTupleType a () = a
146 JoinTupleType a (b, c) = (a, b, c)
147 JoinTupleType a (b, c, d) = (a, b, c, d)
148 JoinTupleType a (b, c, d, e) = (a, b, c, d, e)
149 JoinTupleType a b = (a, b)
150
151joinTupleType = HCons
152
diff --git a/testdata/hlist.ignore/Prelude.lc b/testdata/hlist.ignore/Prelude.lc
new file mode 100644
index 00000000..69ba3348
--- /dev/null
+++ b/testdata/hlist.ignore/Prelude.lc
@@ -0,0 +1,362 @@
1{-# LANGUAGE NoImplicitPrelude #-}
2module Prelude
3 ( module Prelude
4 , module Builtins
5 ) where
6
7import Builtins
8
9infixr 9 .
10infixl 7 `PrimMulMatVec`, `PrimDot`
11infixr 5 ++
12infixr 3 ***
13infixr 0 $
14--infixl 0 &
15
16const x y = x
17
18otherwise = True
19
20x & f = f x
21
22($) = \f x -> f x
23(.) = \f g x -> f (g x)
24
25uncurry f (x, y) = f x y
26
27(***) f g (x, y) = (f x, g y)
28
29pi = 3.14
30
31zip :: [a] -> [b] -> [(a,b)]
32zip [] xs = []
33zip xs [] = []
34zip (a: as) (b: bs) = (a,b): zip as bs
35
36unzip :: [(a,b)] -> ([a],[b])
37unzip [] = ([],[])
38unzip ((a,b):xs) = (a:as,b:bs)
39 where (as,bs) = unzip xs
40
41filter pred [] = []
42filter pred (x:xs) = case pred x of
43 True -> (x : filter pred xs)
44 False -> (filter pred xs)
45
46--head :: [a] -> a
47--head (a: _) = a
48
49tail :: [a] -> [a]
50tail (_: xs) = xs
51
52pairs :: [a] -> [(a, a)]
53pairs v = zip v (tail v)
54
55foldl' f e [] = e
56foldl' f e (x: xs) = foldl' f (f e x) xs
57
58foldr1 f (x: xs) = foldr f x xs
59
60split [] = ([], [])
61split (x: xs) = (x: bs, as) where (as, bs) = split xs
62
63mergeBy f (x:xs) (y:ys) = case f x y of
64 LT -> x: mergeBy f xs (y:ys)
65 _ -> y: mergeBy f (x:xs) ys
66mergeBy f [] xs = xs
67mergeBy f xs [] = xs
68
69sortBy f [] = []
70sortBy f [x] = [x]
71sortBy f xs = uncurry (mergeBy f) ((sortBy f *** sortBy f) (split xs))
72
73iterate :: (a -> a) -> a -> [a]
74iterate f x = x : iterate f (f x)
75
76fst (a, b) = a
77snd (a, b) = b
78
79tuptype :: [Type] -> Type
80tuptype [] = '()
81tuptype (x:xs) = '(x, tuptype xs)
82
83data RecordC (xs :: [(String, Type)])
84 = RecordCons (tuptype (map snd xs))
85
86False ||| x = x
87True ||| x = True
88
89infixr 2 |||
90
91True &&& x = x
92False &&& x = False
93
94infixr 3 &&&
95
96------------------------------------ Row polymorphism
97-- todo: sorted field names (more efficient & easier to use)
98
99{-
100isKey _ [] = False
101isKey s ((s', _): ss) = s == s' ||| isKey s ss
102
103subList [] _ = []
104subList ((s, t): xs) ys = if isKey s ys then subList xs ys else (s, t): subList xs ys
105
106addList [] ys = ys
107addList ((s, t): xs) ys = if isKey s ys then addList xs ys else (s, t): addList xs ys
108
109findEq x [] = 'Unit
110findEq (s, t) ((s', t'):xs) = if s == s' then 'T2 (t ~ t') (findEq (s, t) xs) else findEq (s, t) xs
111
112sameEq [] _ = 'Unit
113sameEq (x: xs) ys = 'T2 (findEq x ys) (sameEq xs ys)
114
115defined [] = True
116defined (x: xs) = defined xs
117
118type family Split a b c
119type instance Split (RecordC xs) (RecordC ys) z | defined xs &&& defined ys = T2 (sameEq xs ys) (z ~ RecordC (subList xs ys))
120type instance Split (RecordC xs) z (RecordC ys) | defined xs &&& defined ys = T2 (sameEq xs ys) (z ~ RecordC (subList xs ys))
121type instance Split z (RecordC xs) (RecordC ys) | defined xs &&& defined ys = T2 (sameEq xs ys) (z ~ RecordC (addList xs ys))
122
123-- builtin
124-- TODO
125record :: [(String, Type)] -> Type
126--record xs = RecordCons ({- TODO: sortBy fst-} xs)
127-}
128
129isKeyC _ _ [] = 'Empty ""
130isKeyC s t ((s', t'): ss) = if s == s' then t ~ t' else isKeyC s t ss
131
132-- todo: don't use unsafeCoerce
133project :: forall a (xs :: [(String, Type)]) . forall (s :: String) -> 'isKeyC s a xs => RecordC xs -> a
134project @a @((s', a'): xs) s @_ (RecordCons ts) | s == s' = fst (unsafeCoerce @_ @(a, tuptype (map snd xs)) ts)
135project @a @((s', a'): xs) s @_ (RecordCons ts) = project @a @xs s @(undefined @(isKeyC s a xs)) (RecordCons (snd (unsafeCoerce @_ @(a, tuptype (map snd xs)) ts)))
136
137--------------------------------------- HTML colors
138
139rgb r g b = V4 r g b 1.0
140
141black = rgb 0.0 0.0 0.0
142gray = rgb 0.5 0.5 0.5
143silver = rgb 0.75 0.75 0.75
144white = rgb 1.0 1.0 1.0
145maroon = rgb 0.5 0.0 0.0
146red = rgb 1.0 0.0 0.0
147olive = rgb 0.5 0.5 0.0
148yellow = rgb 1.0 1.0 0.0
149green = rgb 0.0 0.5 0.0
150lime = rgb 0.0 1.0 0.0
151teal = rgb 0.0 0.5 0.5
152aqua = rgb 0.0 1.0 1.0
153navy = rgb 0.0 0.0 0.5
154blue = rgb 0.0 0.0 1.0
155purple = rgb 0.5 0.0 0.5
156fuchsia = rgb 1.0 0.0 1.0
157
158colorImage1 = ColorImage @1
159colorImage2 = ColorImage @2
160
161depthImage1 = DepthImage @1
162
163v3FToV4F :: Vec 3 Float -> Vec 4 Float
164v3FToV4F v = V4 v%x v%y v%z 1
165
166------------
167-- * WebGL 1
168------------
169
170-- angle and trigonometric
171radians = PrimRadians
172degrees = PrimDegrees
173sin = PrimSin
174cos = PrimCos
175tan = PrimTan
176sinh = PrimSinH
177cosh = PrimCosH
178tanh = PrimTanH
179asin = PrimASin
180asinh = PrimASinH
181acos = PrimACos
182acosh = PrimACosH
183atan = PrimATan
184atanh = PrimATanH
185atan2 = PrimATan2
186
187-- exponential functions
188pow = PrimPow
189exp = PrimExp
190log = PrimLog
191exp2 = PrimExp2
192log2 = PrimLog2
193sqrt = PrimSqrt
194inversesqrt = PrimInvSqrt
195
196-- common functions
197abs = PrimAbs
198sign = PrimSign
199floor = PrimFloor
200trunc = PrimTrunc
201round = PrimRound
202roundEven = PrimRoundEven
203ceil = PrimCeil
204fract = PrimFract
205mod = PrimMod
206min = PrimMin
207max = PrimMax
208modF = PrimModF
209clamp = PrimClamp
210clampS = PrimClampS
211mix = PrimMix
212mixS = PrimMixS
213mixB = PrimMixB
214step = PrimStep
215stepS = PrimStepS
216smoothstep = PrimSmoothStep
217smoothstepS = PrimSmoothStepS
218isNan = PrimIsNan
219isInf = PrimIsInf
220
221dFdx = PrimDFdx
222dFdy = PrimDFdy
223fWidth = PrimFWidth
224
225noise1 = PrimNoise1
226noise2 = PrimNoise2
227noise3 = PrimNoise3
228noise4 = PrimNoise4
229
230-- geometric functions
231length = PrimLength
232distance = PrimDistance
233dot = PrimDot
234cross = PrimCross
235normalize = PrimNormalize
236faceforward = PrimFaceForward
237reflect = PrimReflect
238refract = PrimRefract
239
240transpose = PrimTranspose
241det = PrimDeterminant
242inv = PrimInverse
243outer = PrimOuterProduct
244
245-- operators
246infixl 7 *, /, %
247infixl 6 +, -
248infix 4 /=, <, <=, >=, >
249
250infixr 3 &&
251infixr 2 ||
252
253infix 7 `dot` -- dot
254infix 7 `cross` -- cross
255
256infixr 7 *. -- mulmv
257infixl 7 .* -- mulvm
258infixl 7 .*. -- mulmm
259
260-- arithemtic
261a + b = PrimAdd a b
262a - b = PrimSub a b
263a * b = PrimMul a b
264a / b = PrimDiv a b
265a % b = PrimMod a b
266
267neg a = PrimNeg a
268
269-- comparison
270--a == b = PrimEqual a b
271a /= b = PrimNotEqual a b
272a < b = PrimLessThan a b
273a <= b = PrimLessThanEqual a b
274a >= b = PrimGreaterThanEqual a b
275a > b = PrimGreaterThan a b
276
277-- logical
278a && b = PrimAnd a b
279a || b = PrimOr a b
280xor = PrimXor
281not a = PrimNot a
282any a = PrimAny a
283all a = PrimAll a
284
285-- matrix functions
286a .*. b = PrimMulMatMat a b
287a *. b = PrimMulMatVec a b
288a .* b = PrimMulVecMat a b
289
290-- temp hack for vector <---> scalar operators
291infixl 7 *!, /!, %!
292infixl 6 +!, -!
293
294-- arithemtic
295a +! b = PrimAddS a b
296a -! b = PrimSubS a b
297a *! b = PrimMulS a b
298a /! b = PrimDivS a b
299a %! b = PrimModS a b
300
301------------------
302-- common matrices
303------------------
304{-
305-- | Perspective transformation matrix in row major order.
306perspective :: Float -- ^ Near plane clipping distance (always positive).
307 -> Float -- ^ Far plane clipping distance (always positive).
308 -> Float -- ^ Field of view of the y axis, in radians.
309 -> Float -- ^ Aspect ratio, i.e. screen's width\/height.
310 -> Mat 4 4 Float
311perspective n f fovy aspect = --transpose $
312 M44F (V4F (2*n/(r-l)) 0 (-(r+l)/(r-l)) 0)
313 (V4F 0 (2*n/(t-b)) ((t+b)/(t-b)) 0)
314 (V4F 0 0 (-(f+n)/(f-n)) (-2*f*n/(f-n)))
315 (V4F 0 0 (-1) 0)
316 where
317 t = n*tan(fovy/2)
318 b = -t
319 r = aspect*t
320 l = -r
321-}
322rotMatrixZ a = M44F (V4 c s 0 0) (V4 (-s) c 0 0) (V4 0 0 1 0) (V4 0 0 0 1)
323 where
324 c = cos a
325 s = sin a
326
327rotMatrixY a = M44F (V4 c 0 (-s) 0) (V4 0 1 0 0) (V4 s 0 c 0) (V4 0 0 0 1)
328 where
329 c = cos a
330 s = sin a
331
332rotMatrixX a = M44F (V4 1 0 0 0) (V4 0 c s 0) (V4 0 (-s) c 0) (V4 0 0 0 1)
333 where
334 c = cos a
335 s = sin a
336
337rotationEuler a b c = rotMatrixY a .*. rotMatrixX b .*. rotMatrixZ c
338
339{-
340-- | Camera transformation matrix.
341lookat :: Vec 3 Float -- ^ Camera position.
342 -> Vec 3 Float -- ^ Target position.
343 -> Vec 3 Float -- ^ Upward direction.
344 -> M44F
345lookat pos target up = translateBefore4 (neg pos) (orthogonal $ toOrthoUnsafe r)
346 where
347 w = normalize $ pos - target
348 u = normalize $ up `cross` w
349 v = w `cross` u
350 r = transpose $ Mat3 u v w
351-}
352
353scale t v = v * V4 t t t 1.0
354
355fromTo :: Float -> Float -> [Float]
356fromTo a b = if a > b then [] else a: fromTo (a +! 1.0) b
357
358(!!) :: [a] -> Int -> a
359(x : _) !! 0 = x
360(_ : xs) !! n = xs !! (n-1)
361
362