summaryrefslogtreecommitdiff
path: root/lc
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-02-05 07:36:00 +0100
committerPéter Diviánszky <divipp@gmail.com>2016-02-05 07:36:00 +0100
commite792c87dce446714d4fef938f0b6479ccb4ba1d9 (patch)
tree7286442cc29b823871cd6ca4138b0ff117b779fa /lc
parent1e99274564b711a161fd7cb812af3177626541b4 (diff)
experimental change: Stream -> List
Diffstat (limited to 'lc')
-rw-r--r--lc/Builtins.lc33
-rw-r--r--lc/Prelude.lc14
2 files changed, 20 insertions, 27 deletions
diff --git a/lc/Builtins.lc b/lc/Builtins.lc
index c1991a2b..414f0f6d 100644
--- a/lc/Builtins.lc
+++ b/lc/Builtins.lc
@@ -302,18 +302,26 @@ type family FragOps' a where
302 FragOps' (t1, t2, t3, t4, t5) = (FragmentOperation t1, FragmentOperation t2, FragmentOperation t3, FragmentOperation t4, FragmentOperation t5) 302 FragOps' (t1, t2, t3, t4, t5) = (FragmentOperation t1, FragmentOperation t2, FragmentOperation t3, FragmentOperation t4, FragmentOperation t5)
303 FragOps' t = (FragmentOperation t) 303 FragOps' t = (FragmentOperation t)
304 304
305data Stream a 305[] ++ ys = ys
306x:xs ++ ys = x : xs ++ ys
306 307
307mapStream :: (a -> b) -> Stream a -> Stream b 308foldr f e [] = e
308concatMapStream :: (a -> Stream b) -> Stream a -> Stream b 309foldr f e (x: xs) = f x (foldr f e xs)
309filterStream :: (a -> Bool) -> Stream a -> Stream a 310
311concat = foldr (++) []
312
313map _ [] = []
314map f (x:xs) = f x : map f xs
315
316concatMap :: (a -> [b]) -> [a] -> [b]
317concatMap f x = concat (map f x)
310 318
311data Primitive a :: PrimitiveType -> Type where 319data Primitive a :: PrimitiveType -> Type where
312 PrimPoint :: a -> Primitive a Point 320 PrimPoint :: a -> Primitive a Point
313 PrimLine :: a -> a -> Primitive a Line 321 PrimLine :: a -> a -> Primitive a Line
314 PrimTriangle :: a -> a -> a -> Primitive a Triangle 322 PrimTriangle :: a -> a -> a -> Primitive a Triangle
315 323
316type PrimitiveStream a t = Stream (Primitive t a) 324type PrimitiveStream a t = [Primitive t a]
317 325
318mapPrimitive :: (a -> b) -> Primitive a p -> Primitive b p 326mapPrimitive :: (a -> b) -> Primitive a p -> Primitive b p
319{- todo 327{- todo
@@ -326,7 +334,7 @@ fetch_ :: forall a t . (AttributeTuple t) => String -> t -> Primit
326fetchArrays_ :: forall a t t' . (AttributeTuple t, t ~ FTRepr' t') => t' -> PrimitiveStream a t 334fetchArrays_ :: forall a t t' . (AttributeTuple t, t ~ FTRepr' t') => t' -> PrimitiveStream a t
327 335
328mapPrimitives :: (t' -> t) -> PrimitiveStream a t' -> PrimitiveStream a t 336mapPrimitives :: (t' -> t) -> PrimitiveStream a t' -> PrimitiveStream a t
329mapPrimitives f = mapStream (mapPrimitive f) 337mapPrimitives f = map (mapPrimitive f)
330 338
331fetch s a t = fetch_ @a s t 339fetch s a t = fetch_ @a s t
332fetchArrays a t = fetchArrays_ @a t 340fetchArrays a t = fetchArrays_ @a t
@@ -360,22 +368,22 @@ data SimpleFragment t = SimpleFragment
360 , sFragmentValue :: t 368 , sFragmentValue :: t
361 } 369 }
362 370
363type FragmentStream n t = Stream (Fragment n t) 371type FragmentStream n t = [Fragment n t]
364 372
365customizeDepth :: (a -> Float) -> Fragment n a -> Fragment n a 373customizeDepth :: (a -> Float) -> Fragment n a -> Fragment n a
366 374
367customizeDepths :: (a -> Float) -> FragmentStream n a -> FragmentStream n a 375customizeDepths :: (a -> Float) -> FragmentStream n a -> FragmentStream n a
368customizeDepths f = mapStream (customizeDepth f) 376customizeDepths f = map (customizeDepth f)
369 377
370filterFragment :: (a -> Bool) -> Fragment n a -> Fragment n a 378filterFragment :: (a -> Bool) -> Fragment n a -> Fragment n a
371 379
372filterFragments :: (a -> Bool) -> FragmentStream n a -> FragmentStream n a 380filterFragments :: (a -> Bool) -> FragmentStream n a -> FragmentStream n a
373filterFragments p = mapStream (filterFragment p) 381filterFragments p = map (filterFragment p)
374 382
375mapFragment :: (a -> b) -> Fragment n a -> Fragment n b 383mapFragment :: (a -> b) -> Fragment n a -> Fragment n b
376 384
377mapFragments :: (a -> b) -> FragmentStream n a -> FragmentStream n b 385mapFragments :: (a -> b) -> FragmentStream n a -> FragmentStream n b
378mapFragments f = mapStream (mapFragment f) 386mapFragments f = map (mapFragment f)
379 387
380 388
381data Interpolated t where 389data Interpolated t where
@@ -397,8 +405,7 @@ rasterize
397 -> Primitive a x 405 -> Primitive a x
398 -> FragmentStream 1 b 406 -> FragmentStream 1 b
399 407
400rasterizePrimitives ctx is = concatMapStream (rasterize is ctx) 408rasterizePrimitives ctx is s = concat (map (rasterize is ctx) s)
401--rasterizePrimitivesWithPointSize ctx ps is = concatMapStream (rasterize ps is ctx)
402 409
403data Image :: Nat -> Type -> Type where 410data Image :: Nat -> Type -> Type where
404 ColorImage :: forall a d t color . (Num t, color ~ VecScalar d t) 411 ColorImage :: forall a d t color . (Num t, color ~ VecScalar d t)
@@ -429,7 +436,7 @@ instance (DefaultFragOp a, DefaultFragOp b) => DefaultFragOps (FragmentOperation
429 (defaultFragOp @a @_, defaultFragOp @b @_) 436 (defaultFragOp @a @_, defaultFragOp @b @_)
430-} 437-}
431data FrameBuffer (n :: Nat) b where 438data FrameBuffer (n :: Nat) b where
432 Accumulate :: FragOps' b -> (FragmentStream n (RemSemantics b)) -> FrameBuffer n b -> FrameBuffer n b 439 Accumulate :: FragOps' b -> FragmentStream n (RemSemantics b) -> FrameBuffer n b -> FrameBuffer n b
433 FrameBuffer :: (ValidFrameBuffer b, SameLayerCounts a, PreFrameBuffer n b ~ TFFrameBuffer a) => a -> FrameBuffer n b 440 FrameBuffer :: (ValidFrameBuffer b, SameLayerCounts a, PreFrameBuffer n b ~ TFFrameBuffer a) => a -> FrameBuffer n b
434 441
435accumulate ctx fshader fstr fb = Accumulate ctx (mapFragments fshader fstr) fb 442accumulate ctx fshader fstr fb = Accumulate ctx (mapFragments fshader fstr) fb
diff --git a/lc/Prelude.lc b/lc/Prelude.lc
index ee18d1e9..167d5d05 100644
--- a/lc/Prelude.lc
+++ b/lc/Prelude.lc
@@ -55,22 +55,8 @@ pairs v = zip v (tail v)
55foldl' f e [] = e 55foldl' f e [] = e
56foldl' f e (x: xs) = foldl' f (f e x) xs 56foldl' f e (x: xs) = foldl' f (f e x) xs
57 57
58foldr f e [] = e
59foldr f e (x: xs) = f x (foldr f e xs)
60
61foldr1 f (x: xs) = foldr f x xs 58foldr1 f (x: xs) = foldr f x xs
62 59
63[] ++ ys = ys
64x:xs ++ ys = x : xs ++ ys
65
66concat = foldr (++) []
67
68map _ [] = []
69map f (x:xs) = f x : map f xs
70
71concatMap :: (a -> [b]) -> [a] -> [b]
72concatMap f x = concat (map f x)
73
74split [] = ([], []) 60split [] = ([], [])
75split (x: xs) = (x: bs, as) where (as, bs) = split xs 61split (x: xs) = (x: bs, as) where (as, bs) = split xs
76 62