diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-02-05 07:36:00 +0100 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-02-05 07:36:00 +0100 |
commit | e792c87dce446714d4fef938f0b6479ccb4ba1d9 (patch) | |
tree | 7286442cc29b823871cd6ca4138b0ff117b779fa /lc | |
parent | 1e99274564b711a161fd7cb812af3177626541b4 (diff) |
experimental change: Stream -> List
Diffstat (limited to 'lc')
-rw-r--r-- | lc/Builtins.lc | 33 | ||||
-rw-r--r-- | lc/Prelude.lc | 14 |
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 | ||
305 | data Stream a | 305 | [] ++ ys = ys |
306 | x:xs ++ ys = x : xs ++ ys | ||
306 | 307 | ||
307 | mapStream :: (a -> b) -> Stream a -> Stream b | 308 | foldr f e [] = e |
308 | concatMapStream :: (a -> Stream b) -> Stream a -> Stream b | 309 | foldr f e (x: xs) = f x (foldr f e xs) |
309 | filterStream :: (a -> Bool) -> Stream a -> Stream a | 310 | |
311 | concat = foldr (++) [] | ||
312 | |||
313 | map _ [] = [] | ||
314 | map f (x:xs) = f x : map f xs | ||
315 | |||
316 | concatMap :: (a -> [b]) -> [a] -> [b] | ||
317 | concatMap f x = concat (map f x) | ||
310 | 318 | ||
311 | data Primitive a :: PrimitiveType -> Type where | 319 | data 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 | ||
316 | type PrimitiveStream a t = Stream (Primitive t a) | 324 | type PrimitiveStream a t = [Primitive t a] |
317 | 325 | ||
318 | mapPrimitive :: (a -> b) -> Primitive a p -> Primitive b p | 326 | mapPrimitive :: (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 | |||
326 | fetchArrays_ :: forall a t t' . (AttributeTuple t, t ~ FTRepr' t') => t' -> PrimitiveStream a t | 334 | fetchArrays_ :: forall a t t' . (AttributeTuple t, t ~ FTRepr' t') => t' -> PrimitiveStream a t |
327 | 335 | ||
328 | mapPrimitives :: (t' -> t) -> PrimitiveStream a t' -> PrimitiveStream a t | 336 | mapPrimitives :: (t' -> t) -> PrimitiveStream a t' -> PrimitiveStream a t |
329 | mapPrimitives f = mapStream (mapPrimitive f) | 337 | mapPrimitives f = map (mapPrimitive f) |
330 | 338 | ||
331 | fetch s a t = fetch_ @a s t | 339 | fetch s a t = fetch_ @a s t |
332 | fetchArrays a t = fetchArrays_ @a t | 340 | fetchArrays a t = fetchArrays_ @a t |
@@ -360,22 +368,22 @@ data SimpleFragment t = SimpleFragment | |||
360 | , sFragmentValue :: t | 368 | , sFragmentValue :: t |
361 | } | 369 | } |
362 | 370 | ||
363 | type FragmentStream n t = Stream (Fragment n t) | 371 | type FragmentStream n t = [Fragment n t] |
364 | 372 | ||
365 | customizeDepth :: (a -> Float) -> Fragment n a -> Fragment n a | 373 | customizeDepth :: (a -> Float) -> Fragment n a -> Fragment n a |
366 | 374 | ||
367 | customizeDepths :: (a -> Float) -> FragmentStream n a -> FragmentStream n a | 375 | customizeDepths :: (a -> Float) -> FragmentStream n a -> FragmentStream n a |
368 | customizeDepths f = mapStream (customizeDepth f) | 376 | customizeDepths f = map (customizeDepth f) |
369 | 377 | ||
370 | filterFragment :: (a -> Bool) -> Fragment n a -> Fragment n a | 378 | filterFragment :: (a -> Bool) -> Fragment n a -> Fragment n a |
371 | 379 | ||
372 | filterFragments :: (a -> Bool) -> FragmentStream n a -> FragmentStream n a | 380 | filterFragments :: (a -> Bool) -> FragmentStream n a -> FragmentStream n a |
373 | filterFragments p = mapStream (filterFragment p) | 381 | filterFragments p = map (filterFragment p) |
374 | 382 | ||
375 | mapFragment :: (a -> b) -> Fragment n a -> Fragment n b | 383 | mapFragment :: (a -> b) -> Fragment n a -> Fragment n b |
376 | 384 | ||
377 | mapFragments :: (a -> b) -> FragmentStream n a -> FragmentStream n b | 385 | mapFragments :: (a -> b) -> FragmentStream n a -> FragmentStream n b |
378 | mapFragments f = mapStream (mapFragment f) | 386 | mapFragments f = map (mapFragment f) |
379 | 387 | ||
380 | 388 | ||
381 | data Interpolated t where | 389 | data 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 | ||
400 | rasterizePrimitives ctx is = concatMapStream (rasterize is ctx) | 408 | rasterizePrimitives ctx is s = concat (map (rasterize is ctx) s) |
401 | --rasterizePrimitivesWithPointSize ctx ps is = concatMapStream (rasterize ps is ctx) | ||
402 | 409 | ||
403 | data Image :: Nat -> Type -> Type where | 410 | data 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 | -} |
431 | data FrameBuffer (n :: Nat) b where | 438 | data 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 | ||
435 | accumulate ctx fshader fstr fb = Accumulate ctx (mapFragments fshader fstr) fb | 442 | accumulate 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) | |||
55 | foldl' f e [] = e | 55 | foldl' f e [] = e |
56 | foldl' f e (x: xs) = foldl' f (f e x) xs | 56 | foldl' f e (x: xs) = foldl' f (f e x) xs |
57 | 57 | ||
58 | foldr f e [] = e | ||
59 | foldr f e (x: xs) = f x (foldr f e xs) | ||
60 | |||
61 | foldr1 f (x: xs) = foldr f x xs | 58 | foldr1 f (x: xs) = foldr f x xs |
62 | 59 | ||
63 | [] ++ ys = ys | ||
64 | x:xs ++ ys = x : xs ++ ys | ||
65 | |||
66 | concat = foldr (++) [] | ||
67 | |||
68 | map _ [] = [] | ||
69 | map f (x:xs) = f x : map f xs | ||
70 | |||
71 | concatMap :: (a -> [b]) -> [a] -> [b] | ||
72 | concatMap f x = concat (map f x) | ||
73 | |||
74 | split [] = ([], []) | 60 | split [] = ([], []) |
75 | split (x: xs) = (x: bs, as) where (as, bs) = split xs | 61 | split (x: xs) = (x: bs, as) where (as, bs) = split xs |
76 | 62 | ||